Difference between revisions of "Compiling tpt++ with Visual studio"

From The Powder Toy
Jump to: navigation, search
m (moved Compiling tpt with Visual studio to Compiling tpt++ with Visual studio: this is a tpt++ tutorial only)
(Add link to github setup and old compiling tutorial)
Line 1: Line 1:
This is a guide to get you started on coding for The Powder Toy. If you have any questions, just ask in the Discussion section on [https://powdertoy.co.uk/Forum.html The Powder Toy forums].
+
This is a guide to get you started on coding for The Powder Toy. If you have any questions, just ask in the Discussion section on [https://powdertoy.co.uk/Forum.html The Powder Toy forums]. If you want to use the old tpt compiling tutorial, not the tpt++ one, find it [[Compiling_for_Windows|here]]
  
 
It would help if you have programmed before, but it is fine if you never have.
 
It would help if you have programmed before, but it is fine if you never have.
Line 9: Line 9:
 
Good luck!
 
Good luck!
  
====  Visual Studio (Windows)  ====
+
===  Visual Studio (Windows)  ===
  
 
* Download [http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-cpp-express Visual C++ 2010 Express] because of it's great debugging and auto-code tools. It is completely free.
 
* Download [http://www.microsoft.com/visualstudio/en-us/products/2010-editions/visual-cpp-express Visual C++ 2010 Express] because of it's great debugging and auto-code tools. It is completely free.
Line 87: Line 87:
 
* The resulting executable and its required DLLs can be found in the "Build" folder in your source code directory.
 
* The resulting executable and its required DLLs can be found in the "Build" folder in your source code directory.
  
===== Optional: Statically Compile tpt: =====
+
=== Optional: Statically Compile tpt: ===
  
 
When statically compiling tpt, you do not need to have the dlls to run it. The official tpt does it this way. It takes longer to compile though, so you might only want to do this for release versions.
 
When statically compiling tpt, you do not need to have the dlls to run it. The official tpt does it this way. It takes longer to compile though, so you might only want to do this for release versions.
Line 112: Line 112:
  
 
You will now be able to easily change between compiling in "Release" mode, for quick, normal testing, and "Static" mode, for when you want to release an exe for people to use.
 
You will now be able to easily change between compiling in "Release" mode, for quick, normal testing, and "Static" mode, for when you want to release an exe for people to use.
 +
 +
=== Optional: Set Up Git ===
 +
 +
If you use github, you can easily keep up to date with the current changes. This way, your mod won't be out of date, and you won't have to copy everything over just to update to a newer version.
 +
You can find the tutorial [[Github_Setup|here]].
 +
 +
===  Done ===
  
 
[[Category:Development]]
 
[[Category:Development]]
 
[[Category:Compiling]]
 
[[Category:Compiling]]

Revision as of 22:39, 21 October 2012

This is a guide to get you started on coding for The Powder Toy. If you have any questions, just ask in the Discussion section on The Powder Toy forums. If you want to use the old tpt compiling tutorial, not the tpt++ one, find it here

It would help if you have programmed before, but it is fine if you never have.

This takes a while to setup, so be patient and follow the instructions carefully.

Its not recommended to begin coding elements until you are able to compile a clean source.

Good luck!

Visual Studio (Windows)

  • Download Visual C++ 2010 Express because of it's great debugging and auto-code tools. It is completely free.
  • Open Visual Studio. You should register it (you don't have to pay anything; it's free) if you plan on using it for more than 30 days. You need a Microsoft account to do this
  • If you wish, (this should already be on by default), turn on line numbers by going to Tools > Options > Text Editor > C/C++, and turn on "Line numbers" in the Display subsection.
  • Delete the tptlibrary folder, it just causes errors and isn't used.
  • Open Visual Studio and press Press File > New > New Project from Existing Code.
  • Choose the folder from your source code folder, and name the project. Click Next
  • Choose Windows application project if it isn't selected already and leave everything unchecked. Click Next.
  • Under Preprocessor definitions, type "WIN, X86, X86_SSE2, USE_SDL, STABLE, GRAVFFT, LUACONSOLE" without the quotes.
  • Click Finish. The project will be created
  • Under Build > Configuration Manager, open the drop-down box under "Active Solution Configuration:" and change it to "Release". (unless you have a good reason to keep it as Debug, which runs slower than Release). Compiling with DEBUG is currently very glitchy in tpt++, and you will get many crashes.
  • Go to Project > (Name of your project) Properties.
  • On the very top, where it says Configuration: Active(Release), open the dropdown and change it to All Configurations. This will make it easier if you want to switch to debug mode. If you don't ever want to, this step is optional
  • Under Configuration Properties > General:
  • Change Output Directory from
$(SolutionDir)$(Configuration)\

to

$(SolutionDir)Build\

(notice that there is no backslash between "$(SolutionDir)" and "Build\").

  • Change Target Name to whatever name you want the compiled file to have, minus the ".exe" extension. (or just leave it be to have the file named as the project name)
  • Under Configuration Properties > VC++ Directories:
  • Open the drop down menu for Include Directories (if you don't see the arrow that opens the drop-down menu, try clicking on the line), click "<Edit...>", and add
$(ProjectDir)includes
$(ProjectDir)includes/SDL
$(ProjectDir)includes/lua5.1
$(ProjectDir)data
$(ProjectDir)src
$(ProjectDir)generated

(type that exactly -- also note that there is no backslash between "$(ProjectDir)" and "Includes", and that they are all on separate lines)

  • Open the drop down menu for Library Directories, click "<Edit...>", and add
$(ProjectDir)Libraries

(note that there is no backslash between "$(ProjectDir)" and "Libraries")

  • Go to Configuration Properties > C/C++.
  • Under "General", open the drop-down menu for "Warning Level" and choose the option to turn off all warnings. (This will make it easier if you get any errors during compiling, as you won't have to dig through a bunch of unimportant warnings to get to the errors.)
  • Under "Code Generation", open up the drop-down menu for "Floating Point Model" and set it to Fast. (this'll get you a noticeable speed improvement). Also, right above it, change "Enable Enhanced Instruction Set" to SSE2.
  • Go to Configuration Properties > Linker > Input.
  • Open the drop down menu for "Additional Dependencies," click "<Edit...>", and enter the following text
shell32.lib
ws2_32.lib
wsock32.lib
SDL.lib
SDLmain.lib
libbz2.lib
pthreadVC2.lib
lua5.1.lib
libfftw3f-3.lib
regex.lib
zdll.lib
  • Press OK until you close the project properties.
  • Hit the F7 key on your keyboard, or click Build > Build Solution. You can also click the green "Start Debugging" arrow.
  • If something goes wrong (i.e. you get an error of some sort), ask on The Powder Toy forums.
  • There is currently a problem in DMG.cpp, change the 2's in the pow functions to 2.0f, and the atan2 error to atan2((float)nxj, nxi); if it isn't fixed yet (should fixed be shortly)
  • The resulting executable and its required DLLs can be found in the "Build" folder in your source code directory.

Optional: Statically Compile tpt:

When statically compiling tpt, you do not need to have the dlls to run it. The official tpt does it this way. It takes longer to compile though, so you might only want to do this for release versions.

  • Under Build > Configuration Manager, go under Active Solution Configuration and hit new. Name it Static (or whatever you want to call it), and select to Copy the settings from Release.
  • Under Configuration Properties > VC++ Directories, open the drop down menu for Library Directories, click "<Edit...>", and change it from $(ProjectDir)Libraries to:
$(ProjectDir)Staticlibs
  • Go to Configuration Properties > Linker > Input, open the drop down menu for "Additional Dependencies," and click "<Edit...>", and add these to the list:
user32.lib
gdi32.lib
winmm.lib
dxguid.lib
  • Go to Configuration Properties > C/C++. Under Preprocessor, open the drop down menu for Preprocessor definitions, click "<Edit...>", and add this to the list:
PTW32_STATIC_LIB
REGEX_STATIC
  • Under Configuration Properties > General:
  • Change "Whole Program Optimization" (on the bottom) to "Use Link Time Code Generation"

You will now be able to easily change between compiling in "Release" mode, for quick, normal testing, and "Static" mode, for when you want to release an exe for people to use.

Optional: Set Up Git

If you use github, you can easily keep up to date with the current changes. This way, your mod won't be out of date, and you won't have to copy everything over just to update to a newer version. You can find the tutorial here.

Done