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

From The Powder Toy
Jump to: navigation, search
m (fix broken link)
(add warning that this guide is obsolete)
 
(53 intermediate revisions by 12 users not shown)
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 Development assistance section on [https://powdertoy.co.uk/Discussions/Categories/Topics.html?Category=5 The Powder Toy forums]. If you want to use the old tpt compiling tutorial, not the tpt++ one, find it [[Compiling_tpt_with_Visual_Studio_(old)|here]]
+
{{Languages|Compiling tpt++ with Visual studio}}
  
It would help if you have programmed before, but it is fine if you never have.
+
'''ATTENTION: This guide is outdated as of 2021. Please use this guide for building any recent version of the game: [[Building TPT with Meson]]'''
 +
 
 +
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 [https://powdertoy.co.uk/Discussions/Categories/Topics.html?Category=5 The Powder Toy forums]. If you want to use the old tpt compiling tutorial (which you probably don't), not the tpt++ one, find it [[Compiling_tpt_with_Visual_Studio_(old)|here]].
  
 
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.
 
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.
+
Do not begin coding elements until you are able to compile a clean source.
  
 
Good luck!
 
Good luck!
  
=== Get the Source ===
+
=== Getting the source ===
  
* Go to http://github.com/FacialTurd/The-Powder-Toy/
+
* Go to http://github.com/The-Powder-Toy/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.
+
* There should be a green button somewhere that says "Clone or download". Clicking it presents you with a popup with "Download ZIP". This is a direct link to a .zip of the source. Download it and extract it to a location you will compile it from.
  
=== Visual Studio (Windows)  ===
+
=== Setup ===
  
* Download [http://www.microsoft.com/visualstudio/eng/downloads#d-2010-express Visual C++ 2010 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.
+
* Download [https://visualstudio.microsoft.com/downloads/ Visual C++ 2019 Community] 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.
Note however that you probably can '''not''' use VS C++ 2012 Express, because it lacks the "Project from Existing Code" option we need. VS C++ 2012 '''Ultimate''' however will work.  
+
* On the Workloads tab, select "Desktop development with C++".
 +
* Go into the Individual components tab, scroll down to the "Compilers, build tools, and runtimes" section, and select "Windows XP support for C++".
 +
* In the same area, select "Windows 10 SDK".
 +
* Open Visual Studio. You should register it (you don't have to pay anything; it's free) with your [https://signup.live.com/ Microsoft account] if you plan on using it for more than 30 days.
 +
* Download [https://starcatcher.us/TPT/Required%20Libraries.zip Required Libraries.zip]. Extract contents into project root (same level as the vsproject.py file).
 +
* You now need Python installed to run SCons and other scripts. Get Python 3 [https://www.python.org/ftp/python/3.9.0/python-3.9.0-amd64.exe here].
  
* 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
+
==== Using the premade project (recommended) ====
* 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.
+
* Double click the vsproject.py file and it should show a console window for a second and then close. After that, three Visual Studio files should appear.
 +
* Open the Visual Studio solution file (the one whose name ends with .sln). If you are using the latest version of Visual Studio Community (eg. 2019), ensure the "Treat Warnings As Errors" option is set to 'No'. You can find this option in Properties -> C/C++ -> General.
 +
* Hit F5. This should compile (takes some time) and also launch TPT, which will ask all the questions it usually asks when run for the first time. Familiar files and folders such as Saves, stamps and powder.pref will appear in your source code folder.
 +
* If you got this far, you've successfully compiled a clean source and can start modding, hurray!
  
* Download this: [https://dl.dropbox.com/u/43784416/PowderToy/Required%20Libraries.zip Required Libraries], and extract it right into your source code folder.
+
==== Making your own project (not recommended) ====
  
* You now need python installed to run generator.py. Get python [http://www.python.org/getit/ here], download version 2.7.4, probably [http://www.python.org/ftp/python/2.7.4/python-2.7.4.msi this one]. After you have it installed, just double click the generator.py 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, if you get an error relating to an element after updating the source try running it.
+
It is not recommended that you manually set up the project. It is easy to make mistakes and have compiling errors.
 
 
* <b>Delete the tptlibrary folder</b>, it just causes errors and isn't used. If you forgot this step, you will have to remove file.c from the solution later, because it causes compiling errors, it wasn't meant to be compiled.
 
  
 +
* '''Make sure''' you have done everything in the Setup step correctly.
 
* Open Visual Studio and press Press File > New > New Project from Existing Code.
 
* 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 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.
 
* 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" without the quotes.
+
* Under Preprocessor definitions, type without quotes
 
+
"WIN,
 +
X86,
 +
X86_SSE2,
 +
STABLE,
 +
GRAVFFT,
 +
LUACONSOLE,
 +
IGNORE_UPDATES,
 +
_SCL_SECURE_NO_WARNINGS"
 +
NOTE:If it gives errors while compiling try to type them manually instead of copy-pasting.
 
* 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). Compiling with DEBUG is sometimes glitchy in tpt++, and may cause crashes.
+
* 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 > (Name of your project) Properties.
+
* 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
+
* 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.
  
 
* Under Configuration Properties > General:
 
* Under Configuration Properties > General:
Line 55: Line 70:
 
* 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
 
* 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
  $(ProjectDir)includes/SDL
+
  $(ProjectDir)includes\SDL2
  $(ProjectDir)includes/lua5.1
+
  $(ProjectDir)includes\luajit-2.0
 
  $(ProjectDir)data
 
  $(ProjectDir)data
 
  $(ProjectDir)src
 
  $(ProjectDir)src
 
  $(ProjectDir)generated
 
  $(ProjectDir)generated
(type that exactly -- also note that there is no backslash between "$(ProjectDir)" and "Includes", and that they are all on separate lines)
+
$(ProjectDir)resources
 +
(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
 
* Open the drop down menu for Library Directories, click "<Edit...>", and add
 
  $(ProjectDir)Libraries
 
  $(ProjectDir)Libraries
Line 67: Line 83:
 
* 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 "General", open the drop-down menu for "Multi-processor compilation" and choose "Yes (/MP)". This will make the compiler use multiple cores instead of just one which will help speed up compile times.
 +
 
 +
* If you are using the latest version of Visual Studio Community (eg. 2019), ensure the "Treat Warnings As Errors" option under "General" is set to 'No'.
  
 
* 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 77: Line 97:
 
  shell32.lib
 
  shell32.lib
 
  ws2_32.lib
 
  ws2_32.lib
  SDL.lib
+
  SDL2.lib
  SDLmain.lib
+
  SDL2main.lib
 
  libbz2.lib
 
  libbz2.lib
 
  pthreadVC2.lib
 
  pthreadVC2.lib
  lua5.1.lib
+
  luajit2.0.lib
 
  libfftw3f-3.lib
 
  libfftw3f-3.lib
regex.lib
 
 
  zlib.lib
 
  zlib.lib
  
Line 90: Line 109:
 
* 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.
  
=== Optional: Statically Compile tpt: ===
+
=== Optional: Compile statically ===
  
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 msvcr100.dll with the exe for people without visual studio / the visual studio libraries. It is in the /build folder
+
If you are using the premade project, it already has the Static option built in. On the top bar, click the dropdown that says "Debug" and select "Static", then hit F7 to compile TPT again with this new setting. That's it, you're done; only continue reading this section if you made your own project.
  
* 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. Also don't forget to change the default mode from X64 to X86.
  
 
* Under Configuration Properties > VC++ Directories, open the drop down menu for Library Directories, click "<Edit...>", and change it from $(ProjectDir)Libraries to:
 
* Under Configuration Properties > VC++ Directories, open the drop down menu for Library Directories, click "<Edit...>", and change it from $(ProjectDir)Libraries to:
Line 108: Line 126:
  
 
  winmm.lib
 
  winmm.lib
  dxguid.lib
+
  imm32.lib
 +
version.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 these to the list:
  
 
  PTW32_STATIC_LIB
 
  PTW32_STATIC_LIB
  REGEX_STATIC
+
  ZLIB_WINAPI
 +
 
 +
* Under "Code Generation", change "Runtime Library" to "Multi-Threaded (/MT)"
  
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.
+
* Go to Configuration Properties > Linker > Advanced, change "Image Has Safe Exception Handlers" to "No (/SAFESEH:NO)"
  
=== Optional: Set Up Git ===
+
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.
  
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.
+
=== 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|with this link]].
 
You can find the tutorial [[Github_Setup|with this link]].
  
=== Done ===
+
=== Adding a new element ===
 +
 
 +
* '''Double click''' newelement.py. This will open a console window asking for an element name, which should only contain uppercase letters, digits and hyphens (you can have a more exotic name show up in the menus, but it's not recommended). Type the name of the element and press Enter. You'll be asked to add a piece of code to src/simulation/ElementNumbers.h; when you're done with that and press Enter, the window will close and your element will be created: its source will appear as src/simulation/elements/NAME.cpp.
 +
* In Visual Studio, navigate to The-Powder-Toy/src/simulation/elements in the Solution Explorer and add the newly created .cpp file (preferably to the correct subfolder) (see [https://powdertoy.co.uk/Wiki/W/Coding-tutorial.html#Step_One:_Defining_the_Element here] for how to do it.), then hit F7 to compile TPT again with the new element. This will take relatively long.
 +
* Every time you change something in that file, hit F7 to compile (or F5 to compile and run) TPT. If you only change this file, the compilation step will take significantly shorter than when adding a new element.
 +
 
 +
=== Removing a new element ===
 +
 
 +
* Right click the .cpp file of your element in the Solution Explorer, click Remove and select Delete in the dialog that pops up.
 +
* Undo the change newelement.py made you apply when creating the element; in other words, remove the relevant piece of code from src/simulation/ElementNumbers.h.
 +
* In Visual Studio, hit F7 to compile TPT again without the element.
 +
 
 +
=== Making TPT faster ===
 +
 
 +
You may have noticed that the performance of your freshly compiled TPT is, to say the least, abysmal. To fix this, click the dropdown on the top bar that says "Debug" and select "Release", then hit F7 to compile TPT again.
 +
 
 +
With this you essentially trade ease of debugging for speed, meaning that while TPT will become faster, if there's a serious bug and Visual Studio happens to catch a crash, you won't be able to figure out why it happened, at least not easily. When that happens, just switch back to Debug, compile again and try to reproduce the crash.
 +
 
 +
=== 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)
  
 
[[Category:Development]]
 
[[Category:Development]]
 
[[Category:Compiling]]
 
[[Category:Compiling]]

Latest revision as of 16:00, 12 June 2021

Language: English  • 中文

ATTENTION: This guide is outdated as of 2021. Please use this guide for building any recent version of the game: Building TPT with Meson

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 (which you probably don't), not the tpt++ one, find it here.

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.

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

Good luck!

Getting the source

  • Go to http://github.com/The-Powder-Toy/The-Powder-Toy/
  • There should be a green button somewhere that says "Clone or download". Clicking it presents you with a popup with "Download ZIP". 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++ 2019 Community 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.
  • On the Workloads tab, select "Desktop development with C++".
  • Go into the Individual components tab, scroll down to the "Compilers, build tools, and runtimes" section, and select "Windows XP support for C++".
  • In the same area, select "Windows 10 SDK".
  • 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.
  • Download Required Libraries.zip. Extract contents into project root (same level as the vsproject.py file).
  • You now need Python installed to run SCons and other scripts. Get Python 3 here.

Using the premade project (recommended)

  • Double click the vsproject.py file and it should show a console window for a second and then close. After that, three Visual Studio files should appear.
  • Open the Visual Studio solution file (the one whose name ends with .sln). If you are using the latest version of Visual Studio Community (eg. 2019), ensure the "Treat Warnings As Errors" option is set to 'No'. You can find this option in Properties -> C/C++ -> General.
  • Hit F5. This should compile (takes some time) and also launch TPT, which will ask all the questions it usually asks when run for the first time. Familiar files and folders such as Saves, stamps and powder.pref will appear in your source code folder.
  • If you got this far, you've successfully compiled a clean source and can start modding, hurray!

Making your own project (not recommended)

It is not recommended that you manually set up the project. It is easy to make mistakes and have compiling errors.

  • Make sure you have done everything in the Setup step correctly.
  • 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 without quotes

"WIN, X86, X86_SSE2, STABLE, GRAVFFT, LUACONSOLE, IGNORE_UPDATES, _SCL_SECURE_NO_WARNINGS" NOTE:If it gives errors while compiling try to type them manually instead of copy-pasting.

  • 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.
  • 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\SDL2
$(ProjectDir)includes\luajit-2.0
$(ProjectDir)data
$(ProjectDir)src
$(ProjectDir)generated
$(ProjectDir)resources

(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 "General", open the drop-down menu for "Multi-processor compilation" and choose "Yes (/MP)". This will make the compiler use multiple cores instead of just one which will help speed up compile times.
  • If you are using the latest version of Visual Studio Community (eg. 2019), ensure the "Treat Warnings As Errors" option under "General" is set to 'No'.
  • 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
SDL2.lib
SDL2main.lib
libbz2.lib
pthreadVC2.lib
luajit2.0.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: Compile statically

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.

If you are using the premade project, it already has the Static option built in. On the top bar, click the dropdown that says "Debug" and select "Static", then hit F7 to compile TPT again with this new setting. That's it, you're done; only continue reading this section if you made your own project.

  • 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. Also don't forget to change the default mode from X64 to X86.
  • 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
imm32.lib
version.lib
  • Go to Configuration Properties > C/C++ > Preprocessor, open the drop down menu for Preprocessor definitions, click "<Edit...>", and add these to the list:
PTW32_STATIC_LIB
ZLIB_WINAPI
  • 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.

Adding a new element

  • Double click newelement.py. This will open a console window asking for an element name, which should only contain uppercase letters, digits and hyphens (you can have a more exotic name show up in the menus, but it's not recommended). Type the name of the element and press Enter. You'll be asked to add a piece of code to src/simulation/ElementNumbers.h; when you're done with that and press Enter, the window will close and your element will be created: its source will appear as src/simulation/elements/NAME.cpp.
  • In Visual Studio, navigate to The-Powder-Toy/src/simulation/elements in the Solution Explorer and add the newly created .cpp file (preferably to the correct subfolder) (see here for how to do it.), then hit F7 to compile TPT again with the new element. This will take relatively long.
  • Every time you change something in that file, hit F7 to compile (or F5 to compile and run) TPT. If you only change this file, the compilation step will take significantly shorter than when adding a new element.

Removing a new element

  • Right click the .cpp file of your element in the Solution Explorer, click Remove and select Delete in the dialog that pops up.
  • Undo the change newelement.py made you apply when creating the element; in other words, remove the relevant piece of code from src/simulation/ElementNumbers.h.
  • In Visual Studio, hit F7 to compile TPT again without the element.

Making TPT faster

You may have noticed that the performance of your freshly compiled TPT is, to say the least, abysmal. To fix this, click the dropdown on the top bar that says "Debug" and select "Release", then hit F7 to compile TPT again.

With this you essentially trade ease of debugging for speed, meaning that while TPT will become faster, if there's a serious bug and Visual Studio happens to catch a crash, you won't be able to figure out why it happened, at least not easily. When that happens, just switch back to Debug, compile again and try to reproduce the crash.

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)