Please note that this guide is intended as a supplement to the main video series for users who would rather use Sublime Text than Emacs, and does not cover all aspects of setting up your development environment. Namely the Visual Studio setup, which is the same regardless of what editor you are using. However, I have attempted to be as thorough as possible. If there are any errors or glaring omissions in this guide, please contact me on twitter @mvandevander and I will resolve them as soon as possible. Once again, although Sublime Text is cross-platform, this guide is not. I would appreciate any tips that would help the guide to be more cross-platform as well. :)
Setting Up the Command Line
Download Handmade Hero and put the source code inside a directory somewhere that you will remember. I put mine in “C:\Users\Matthew\Documents\Programming”, but anywhere is fine.
Create a batch file named startup.bat and place it in the Windows “Startup” folder, which can be found in the start menu or at “C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup”
Inside the startup.bat file, you will want to put the following, replacing the directory on the right-hand side with the directory which contains the “build” and “handmade” folders:
subst w: C:\Users\Matthew\Documents\Programming
Now after this batch file is run, W:\ will point directly to that directory. Double click the file to run it. Since we put the batch file inside the Startup folder, it will run every time windows is booted and we won’t have to worry about setting it again.
Note for Windows 8 users: Once again Microsoft has seen fit to make things harder and more complex for users who want to get things done. On Windows 8, when you “run as administrator”, it is considered a different user than your base account. Therefore subst will take effect under the “user” that you ran it from. If it is run from cmd as admin, you have it there but it doesn’t show up in explorer normally, and if you just run it without the admin privileges, it won’t show up if you run cmd as administrator. So be sure that you are not running cmd from a shortcut set to launch it as administrator. We will never need a command prompt with admin privileges. Also be aware that there appear to be issues if you actually do subst the same directory under both and admin and a normal user account.
Create a new shortcut on your desktop (Right Click->New->Shortcut) and paste the following into the location box:
C:\Windows\System32\cmd.exe /k w:\handmade\misc\shell.bat
Name it “cmd” or whatever you like.
Right click on the new shortcut and hit Properties to edit it. On the Shortcut tab, under “Start In”, Put W:\. Feel free to go to the Colors tab and change the text and background colors to whatever you like. Here are some nice values:
Screen text: 200, 180, 100
Screen background: 20, 20, 20
Pop-up text: 20, 20, 20
Pop-up background: 200, 180, 100
While we’re at it, let’s go to the Font tab and change that awful default font to something nice. I chose Lucida Console at size 14.
Adding Sublime Text to the Mix
Download Sublime Text 3 and extract it into a directory you will remember. I put mine in C:\sublimetext
Inside W:\handmade\misc, add a new batch file called “edit.bat” which we will use to launch Sublime Text.
Put the following code inside edit.bat, changing the directory to the one you put Sublime Text in:
start C:\sublimetext\sublime_text %1
Now if we click our desktop shortcut, we can open Sublime Text by typing “edit” and hitting return. We can even open up files by appending them to the edit command like so:
If Microsoft Visual Studio is installed, we should also be able to build our game from that command line, by typing “build” and hitting return. Magnifico!
Integrating Our Build System with Sublime Text
But what would be really awesome is if we could get our builds working from inside Sublime Text with just a keypress!
Open Sublime Text. Go to Tools->Build System->New Build System
The contents of the file should look like this.
"file_regex": "^ *([A-z]:.*)[(]([0-9]+)[)]"
Save the build system file as “handmade.sublime-build”, and make sure it saves into the User subdirectory of Sublime Text. (It should by default)
Now if we open win32_handmade.cpp inside Sublime Text. We can build the project by pressing F7 or Ctrl+B. We can even jump between any build errors by using F4 and Shift+F4. Neat!
So far, this is all going pretty great. But we can make it a little better by installing a couple of packages. In order to make installing packages easy, we will want to first install a plugin called Package Control. We can do that by going to this website and following the instructions there.
After you have installed Package Control, go to Preferences->Package Control, and on the pop-up click Install Package. You will want to get SublimeLinter, SublimeLinter-annotations, and Highlight Build Errors.
Exit and reload Sublime.
Now all of our TODOs will be marked, and we will get line highlights for every build error.
If you would like to change the settings for the highlighting, there are lots of options that you can access simply by right clicking in any code window and going under the SublimeLinter submenu.
I would suggest changing the Gutter Theme to None to remove the dots in the sidebar, and changing the Mark Style to Fill. Keep in mind though, that if you want to use the other linting features of SublimeLinter, most of those require those Gutter marks.
You can also edit the JSON file directly by either clicking Open User Settings from that menu, or you can go to Preferences->Package Settings->SublimeLinter->Settings – User. I am not sure why (probably a bug), but for some reason the settings file will be blank unless you have made changes to it from the right-click menu. To get the file to fill out, you have to save it and reload it.
I would suggest tweaking the file by adding “NOTE” to the list of warnings, so that NOTE is highlighted in our code. So that section will read like this:
We’re all set and ready to rock now! Happy heroing!