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

From The Powder Toy
Jump to: navigation, search
(fix python link, remove outdated sentence)
(Updated required libraries / VS 2013 project file, static build is now actually static and guide uses lua 5.2)
Line 16: Line 16:
 
===  Setup  ===
 
===  Setup  ===
  
* Download [http://www.visualstudio.com/en-us/downloads/download-visual-studio-vs#DownloadFamilies_2 Visual C++ 2013 Express for Windows Desktop] because of it's great debugging and auto-code tools. It is completely free, if it asks for a license see the next list item. You will need a Microsoft account to download this.
+
* Download [http://www.visualstudio.com/en-us/downloads/download-visual-studio-vs#DownloadFamilies_2 Visual C++ 2013 Express for Windows Desktop] because of it's great debugging and auto-code tools. It is completely free, if it asks for a license see the next list item. You will need a Microsoft account to download this. VS 2015 is out and will almost certainly work, but this guide is written for VS 2013.
  
 
* Open Visual Studio. You should register it (you don't have to pay anything; it's free) with your Microsoft account if you plan on using it for more than 30 days.
 
* Open Visual Studio. You should register it (you don't have to pay anything; it's free) with your Microsoft account if you plan on using it for more than 30 days.
Line 28: Line 28:
  
 
Instead of going through all the steps of setting up the code, it is much easier to use a project already set up for you. You can get that here: https://dl.dropboxusercontent.com/u/43784416/PowderToy/vs%202013%20project.zip
 
Instead of going through all the steps of setting up the code, it is much easier to use a project already set up for you. You can get that here: https://dl.dropboxusercontent.com/u/43784416/PowderToy/vs%202013%20project.zip
It has all the options described here, plus the tpt++ source is organized in a way that makes it easier to find useful files and gets the useless ones out of the way. This is up to date fully as of September 5th, 2014.
+
It has all the options described here, plus the tpt++ source is organized in a way that makes it easier to find useful files and gets the useless ones out of the way. This is up to date fully as of December 25th, 2015.
  
 
====  Manual Setup ====
 
====  Manual Setup ====
Line 40: Line 40:
 
* Choose Windows application project if it isn't selected already and leave everything unchecked. 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, IGNORE_UPDATES, _SCL_SECURE_NO_WARNINGS" without the quotes. That last one is only recommended if you are using VS2013, to prevent some warnings.
+
* Under Preprocessor definitions, type "WIN, X86, X86_SSE2, USE_SDL, STABLE, GRAVFFT, LUACONSOLE, LUA_COMPAT_ALL, IGNORE_UPDATES, _SCL_SECURE_NO_WARNINGS" without the quotes.
  
 
* Click Finish. The project will be created
 
* 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).
 
* 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).
** '''If you are on Visual Studio 2010 and you cannot see the Build menu''' then, under Tools > Settings change from "Basic Settings" to "Expert Settings"
 
  
 
* Go to Project > Properties.
 
* Go to Project > Properties.
Line 63: Line 62:
 
  $(ProjectDir)includes
 
  $(ProjectDir)includes
 
  $(ProjectDir)includes/SDL
 
  $(ProjectDir)includes/SDL
  $(ProjectDir)includes/lua5.1
+
  $(ProjectDir)includes/lua5.2
 
  $(ProjectDir)data
 
  $(ProjectDir)data
 
  $(ProjectDir)src
 
  $(ProjectDir)src
Line 74: Line 73:
 
* Go to Configuration Properties > C/C++.
 
* 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 "General", open the drop-down menu for "Warning Level" and choose "Level1 (/W1)". 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 will get you a noticeable speed improvement). Also, right above it, change "Enable Enhanced Instruction Set" to SSE2.
 
* Under "Code Generation", open up the drop-down menu for "Floating Point Model" and set it to Fast. (this will get you a noticeable speed improvement). Also, right above it, change "Enable Enhanced Instruction Set" to SSE2.
Line 88: Line 87:
 
  libbz2.lib
 
  libbz2.lib
 
  pthreadVC2.lib
 
  pthreadVC2.lib
  lua5.1.lib
+
  lua5.2.lib
 
  libfftw3f-3.lib
 
  libfftw3f-3.lib
 
  zlib.lib
 
  zlib.lib
Line 96: Line 95:
 
* Hit the F7 key on your keyboard, or click Build > Build Solution. You can also click the green "Start Debugging" arrow.
 
* 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 [https://powdertoy.co.uk/Discussions/Categories/Topics.html?Category=5 The Powder Toy forums].
 
* If something goes wrong (i.e. you get an error of some sort), ask on [https://powdertoy.co.uk/Discussions/Categories/Topics.html?Category=5 The Powder Toy forums].
* One common error people seem to get with Visual Studio 2010 while having .NET 4.5 installed is the error "1>LINK : fatal error LNK1123: failure during conversion to COFF: file invalid or corrupt". If you get this, either uninstall .NET 4.5 and get 4.0 instead, or download Visual Studio 2012 and use that instead. This is not a problem with tpt.
 
  
 
* 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.
Line 102: Line 100:
 
=== Optional: Statically Compile tpt: ===
 
=== Optional: Statically Compile tpt: ===
  
If you are using the premade project, it already has the Static option built in. On the top bar, select the dropdown that says "Debug" and select "Static". This way, you will only need to distribute one dll with your project and not all of them, msvcr120.dll.
+
If you are using the premade project, it already has the Static option built in. On the top bar, select the dropdown that says "Debug" and select "Static".
  
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, or distribute them with your project. The official tpt does it this way. It takes longer to compile though, so you might only want to do this for release versions.
 
 
NOTE: you actually will need to include msvcr120.dll with the exe for people without visual studio / the visual studio libraries. It is in the build\ folder
 
  
 
* 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 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.
Line 118: Line 114:
 
  dxguid.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:
+
* Go to Configuration Properties > C/C++ > Preprocessor, open the drop down menu for Preprocessor definitions, click "<Edit...>", and add this to the list:
  
 
  PTW32_STATIC_LIB
 
  PTW32_STATIC_LIB
  
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.
+
* Under "Code Generation", change "Runtime Library" to "Multi-Threaded (/MT)"
 +
 
 +
* Go to Configuration Properties > Linker > Advanced, change "Image Has Safe Exception Handlers" to "No (/SAFESEH:NO)"
 +
 
 +
You will now be able to easily change between compiling in "Debug" mode, for quick, normal testing, and "Static" mode, for when you want to release an exe for people to use.
  
  

Revision as of 04:39, 26 December 2015

This is a guide to get you started on coding for The Powder Toy. If you have any questions, just ask in the Development assistance 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. If you get any errors, 90% of the time that means you missed a step or did something incorrectly.

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

Good luck!

Get the Source

  • Go to http://github.com/simtr/The-Powder-Toy/
  • There should be a button that says "zip" with a cloud on it. This is a direct link to a .zip of the source. Download it and extract it to a location you will compile it from.

Setup

  • Download Visual C++ 2013 Express for Windows Desktop because of it's great debugging and auto-code tools. It is completely free, if it asks for a license see the next list item. You will need a Microsoft account to download this. VS 2015 is out and will almost certainly work, but this guide is written for VS 2013.
  • Open Visual Studio. You should register it (you don't have to pay anything; it's free) with your Microsoft account if you plan on using it for more than 30 days.
  • 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.
  • You now need python installed to run generator.py. Get python here. Python 3 also works, but it will not work if you decide to use SCons later. After you have it installed, just double click the generator.py file and it should show a console window for a second and then close. This means it worked. You need to run generator.py again every time a new element is added.

Premade project

Instead of going through all the steps of setting up the code, it is much easier to use a project already set up for you. You can get that here: https://dl.dropboxusercontent.com/u/43784416/PowderToy/vs%202013%20project.zip It has all the options described here, plus the tpt++ source is organized in a way that makes it easier to find useful files and gets the useless ones out of the way. This is up to date fully as of December 25th, 2015.

Manual Setup

It is not recommended that you manually set up the project. It is easy to make mistakes and have compiling errors. Also, step one "New Project from Existing Code" is only available in Visual Studio 2010 or earlier, unless you download the Community edition or buy the full version. The Premade project should work fine in newer versions of Visual Studio.

  • Make sure you have done the past two steps correctly, if not you will have to edit the solution later. Open Visual Studio and press Press File > New > New Project from Existing Code.
  • Choose the folder that contains the source code, not src/, but the folder that contains src/, build/, includes/, and a few others. Name the project whatever you want. 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, LUA_COMPAT_ALL, IGNORE_UPDATES, _SCL_SECURE_NO_WARNINGS" 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).
  • Go to 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.2
$(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 "Level1 (/W1)". 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 will 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
SDL.lib
SDLmain.lib
libbz2.lib
pthreadVC2.lib
lua5.2.lib
libfftw3f-3.lib
zlib.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.
  • The resulting executable and its required DLLs can be found in the "Build" folder in your source code directory.

Optional: Statically Compile tpt:

If you are using the premade project, it already has the Static option built in. On the top bar, select the dropdown that says "Debug" and select "Static".

When statically compiling tpt, you do not need to have the dlls to run it, or distribute them with your project. 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:
winmm.lib
dxguid.lib
  • Go to Configuration Properties > C/C++ > Preprocessor, open the drop down menu for Preprocessor definitions, click "<Edit...>", and add this to the list:
PTW32_STATIC_LIB
  • Under "Code Generation", change "Runtime Library" to "Multi-Threaded (/MT)"
  • Go to Configuration Properties > Linker > Advanced, change "Image Has Safe Exception Handlers" to "No (/SAFESEH:NO)"

You will now be able to easily change between compiling in "Debug" 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 with this link.

SCons

You can use SCons from the command line to compile with the visual studio compiler. This option probably isn't useful in most cases but is still there. Use the command "scons.py --msvc" and it will attempt to find and use a 32 bit msvc compiler. It supports most of the options in the SConscript, including --static which should generate completely static binaries (not even needing msvcr120.dll like this guide needs)