Welcome back to my series of posts on starting a game engine. In part 2 i will go over setting up a visual studio solution with a dll engine project and a console application for Unit Tests.
First of all I am using UnitTest++ for my unit testing framework. So you can get that here(along with a tutorial to get you started), or you can try to port the guide to the framework of your choosing, or you can skip unit testing all together and just make the console application run like a normal app. Unzip UnitTest++ to the directory of your choosing, load up the build solution, and build it. In the UnitTest++ debug directory there should now be a file called UnitTest++.vsnet2005.lib.
Step 1. Now that that is done you can create the projects. Create an empty dll project(this will be the engine so name it correctly) and select create directory for solution. To the same solution add a empty console application(for either the unit tests or just as a test game). Open up the directory where the dll project is located. Add three folders: src, include, and lib. Open the directory where the console application is located. Add a src and an include folder. Now open visual studio again and to the dll project add EngineRoot.cpp and EngineRoot.h(make sure that you add the .cpp to the src folder and the .h to the include folder). To the console app add either Tests.h/.cpp or Main.h/.cpp(same as before with the folders).
If this will be a Unit Test project also add a 3rd_party folder in the console application directory alongside src and include, to that 3rd_party folder add a include and lib folder. Now go to the location where you built UnitTest++ and copy the .lib file from the Debug folder to the 3rd_party lib folder, now copy the entire contents of the UnitTest++ src directory the the 3rd_party include folder.
Step 2. Time to setup both projects settings. First to setup the dll project settings. In Configuration Properties->General set both Output Directory and Intermediate Directory to _Debug for the debug build and _Release for the release build. In Configuration Properties->C/C++->General add include\ to Additional Include Directories. Under Linker->General set Output File to ..\_Build\$(OutDir)\$(ProjectName).dll.
Now time to setup the console application. To start right click on the console app and select Set as Startup project, then go into the console app properties. Under Common Properties->Framework and References press Add New Reference and select the dll project. In Configuration Properties->General set both Output Directory and Intermediate Directory to _Debug for the debug build and _Release for the release build. In Configuration Properties->Debugging set the Environment to PATH=..\_Build\$(OutDir) . Next you will need to go into C/C++->General and under Additional Include Directories add ..\(dll project name)\include;3rd_party\include. Then under Linker->General change Output File to ..\_Build\$(OutDir)\$(ProjectName).exe and Additional Library Directories to 3rd_party\lib. Don’t worry almost finished, now you need to go into Linker->Input and under Additional Dependencies add UnitTest++.vsnet2005.lib. Lastly you will want these tests to automatically run after you build so go to Build Events->Post-Build Event and under Command Line enter $(TargetPath) and under Description enter in a description like Running Unit Tests…
Step 3. Now you should probably test everything out with some prerequisite code. Open up EngineRoot.h and enter in the following code(or equivilant):
#ifndef ENGINE_ROOT_H
#define ENGINE_ROOT_H
class __declspec(dllexport) EngineRoot
{
public:
bool Run(){return true;}
};
#endif
Open up EngineRoot.cpp and enter:
#include "EngineRoot.h"
And then open up Tests.cpp and enter:
#include "UnitTest++.h"
#include "EngineRoot.h"
TEST(HelloUnitTest++)
{
CHECK(true);
}
int main()
{
return UnitTest::RunAllTests();
};
If you build this it should compile and there should be output similar to this in the visual studio output window:
1>Running Unit Tests...
1>Success: 1 tests passed.
1>Test time: 0.00 seconds.
If there are any problems just post a comment and i will try and help.
Thanks for visiting my blog and i hope you are enjoying my guide to starting a game engine. Please give feedback and come again.
PART 1 OF THIS GUIDE.