Compiling tpt with Visual Studio (old)

From The Powder Toy
Revision as of 19:44, 19 May 2012 by Ximon (talk | contribs)
Jump to: navigation, search

Original author: Triclops200

Main contributors: raj.k, HolyExLxF, FacialTurd(Simon), Jacob1

"Small" authors: wikku9 (added quotations marks to Additional Dependecies list and other) ,Pyromaniac555 (fixed lists, checked spelling and grammar, etc. (still checking)), Me4502 (added pthread link)


This guide is for Windows

The GNU/Linux guide to setup is here.

Contributors are welcome to port this tutorial to Mac OS X (or improve the existing tutorials).




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.

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!


GitHub Set-up

GitHub set-up can be skipped, just go to 'Visual Studio (Windows)'

Doing these steps in order is highly recommended.


  • Create an account at this site: [[1]].
  • Download and install MySysGit.
  • Download and install SmartGit.
  • Set up SmartGit:
  • Choose Non Commercial so you can get unlimited use.
  • Insert as much information as you can.
  • Your API token is at GitHub.com > Account Settings > Account Admin.
  • Give your email to GitHub (necessary [[2]] under email addresses).
  • Open GitBash (from the first program you installed) and type this then hit enter:
  • ssh-keygen -t rsa -C "<yourgithubusernamewithout<>signs>@github.com"
  • Leave the file location blank when it prompts you.
  • Type a strong passphrase and confirm the passphrase (they will not show up, so don't be surprised it looks blank).
  • Open this with notepad: C:\WINDOWS\Users\<username>\.ssh\id_rsa.pub. Make sure to have the File Type setting on All Files, instead of Text Documents.
  • Go to [[3]] > SSH Public Keys. Copy the entire file contents into the the "Key" box. Make sure you don't add any extra spaces or lines (there IS an extra line at the end, though). Leave the Title text box blank and hit "Add key".
  • Open GitBash and type: $ ssh git@gitbash.com
  • Type your passphrase you made earlier and click Yes. If it doesn't work, try
  • $ ssh git@github.com
  • If it still doesn't work, verify you did step 6 right (set another file location or overwrite).
  • Go to [[4]] and click the "Fork" button. This will create a copy of The Powder Toy in your account.
  • Download the source code.
  • Open SmartGit, and go to File > Clone.
  • Press "Select from GitHub" and choose your repository.
  • If your rsa_pub file (the one you made in step # isn't highlighted and the program asks, choose it.
  • Type in your passphrase if the program prompts you.
  • Choose the directory where you want to store the source files.
  • Congratulations! You now have an easy way to make changes to the code and upload it to GitHub.
  • To make changes and send a request to Simon to have it implemented in the official code, open SmartGit (make sure you've saved your changes in Visual Studio).
  • powder.c and any other files you may have changed should be listed as "Modified".
  • Press "Commit" at the top, list the things you have changed in the text box, and press "Commit".
  • Press "Push" at the top, and press "Push" again.
  • Go to your Powder Toy repository page on GitHub and press "Pull Request" at the top.
  • Send the request to facialturd (Simon's username) and you should be done. Verify that the code has been changed if you like.
  • If Simon decides to accept your request, your code will be in the official Powder Toy source code. Congratulations!



If something goes wrong, go to GitHub forums for git help or ask on The Powder Toy forums for powder toy help.




Visual Studio (Windows)

If you can't be arsed to do any of this yourself, then I have uploaded a complete visual studio 2010 project with source (for v66.2 of Powder Toy). http://www.box.net/shared/xzarykzoraiorpi41iy1 It has all the libraries and headers you need to compile this version, it statically links everything so no .dll's needed! It also has a git repository in it, which you *should* be able to pull from. It doesn't run quite as fast as the official, and setting floats from Lua/PROP may crash... but you can easily add things for testing :)

  • Download Visual Studio Express 2010 C++ because of it's great debugging and auto-code tools. It is completely free.
  • Open Visual Studio. If you didn't get a product key, go to Visual Studio Keys (this isn't pirating, Visual Studio is free.)
  • 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.
  • Press File > New > New Project from Existing Code.
  • Choose the folder from your source code folder.
  • Choose Windows application project and leave everything unchecked. Press "Finish". (You don't need to change any of the other options)
  • 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.
  • 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 and add
$(ProjectDir)Includes

(type that exactly -- also note that there is no backslash between "$(ProjectDir)" and "Includes")

  • Open the drop down menu for Library Directories 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 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 "Preprocessor", open the drop-down for "Preprocessor Definitions" and add:
LUACONSOLE
GRAVFFT
  • Adding GRAVFFT is optional and adds a speed increase when Newtonian gravity is on but also increases the size of the exe by a lot (but only if linking statically to the fftw library, otherwise it doesn't change the exe size by much but does add an extra dll that it needs for it to run).
  • If for some reason the libfftw3f-3.lib included in the Libraries folder doesn't work (it should), try using this one (and follow the instructions on the site).
  • Under "Code Generation", change "Floating Point Model" to Fast. (this'll get you a noticeable speed improvement)
  • 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
regex.lib
pthreadVC2.lib
lua5.1.lib
libfftw3f-3.lib
  • Only type in the last one if you enabled GRAVFFT
  • Press OK until you close the project properties.
  • Hit the F7 key on your keyboard, or click Build > Build Solution.
  • 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. (note that you won't need libfftw3f-3.dll if you didn't enable GRAVFFT)