Author Topic: Setting Up Op2 Sdk With Vs2012 + Project Templates  (Read 3471 times)

Offline Angellus Mortis

  • Full Member
  • ***
  • Posts: 138
Setting Up Op2 Sdk With Vs2012 + Project Templates
« on: February 26, 2013, 12:10:00 AM »
I am back guys. I have almost 3 more years of programming experience and now I actually know what I am doing (scary thought). I made this tutorial for anyone that wants to use the newest version of Microsoft Visual Studio to do OP2 stuff. Since VS2010, I have really liked VS, VS2012 is a really cool IDE for development.

N.B.: I am using Visual Studio 2012 Ultimate on a Windows 8 Pro 64-bit OS for my development, so I apologize if anything does not work or is not in the right place. If any of this is the case, just say so. (:

Getting VS 2012 Express
Visual Studio 2012 Express for Desktop is free for anyone with a Windows computer.  The system requirements are more on the new side. You have to have Windows 7 or newer with 1GB + of RAM and 5GB+ of harddrive space. If you have all of these, you can download and install it from this link. Download the installer for this and then install it.

Directories
Once you get VS2012 install, you can put everything where it goes. Lets go over the different directories I will refer to.

OP2Development
 Download the OP2Development.zip file. In this ZIP, is a solution with everything you need to do development for OP2. Extract this files to anywhere you want. To make things easy, I am going to call the folder you put files in OP2Development.

VS2012Dir
This directory is the one that your VS2012 was installed to, on my machine it is "C:\Program Files (x86)\Microsoft Visual Studio 11.0". Yours should be somewhere similar.

VS2012TemplateDir
This directory is located in your user folder. It should be at "B:\Users\{USER}\Documents\Visual Studio 2012\Templates\ProjectTemplates", where [USER} is your username.

Putting things in the Right Place

SDK Files (required)
Copy the folders "Include" and "Lib" from OP2Development\API\Outpost2DLL to VS2012Dir\VC. Also copy the "Include" and "Lib" folders from OP2Development\API\OP2Helper to VS2012Dir\VC.

Project Templates (optional)
This part is optional, but if you do it, it will add the three simple project templates to your list of templates. This will allow you to quickly and easily create new OP2 projects. In OP2Development\Templates there are the three template projects. In each project, there is a ZIP folder with the template in it. So there is OP2Development\Templates\Blank\OP2 Blank.zip, OP2Development\Templates\Blank-WithComments\OP2 Blank-WithComments.zip, and OP2Development\Templates\Hooville\OP2 Hooville.zip. To install each of these, copy this ZIP file to VS2012TemplateDir. Once you do this, restart VS2012 (if it is running) and create a new project. This should be under Visual C++ at the very bottom.

Testing Everything
Once you get VS2012 installed and all the SDK files copied to the right place, open OP2Development\Outpost2.sln. VS2012 should open and in the Solution Explorer on the right, you will see three folders: "API", "Templates", and "Tutorials". Each of these folders have projects that are self-explanatory. I got all of these projects from the GIT repo. If you see no errors in the Solution Explorer, click "BUILD -> Build Solution" or press F9. If everything went okay, you should see "Build succeeded" in the bottom left-hand corner. If this is not working, make sure you did everything right, if it is still not working, post below.

Customizing Projects
If you are using the templates I supplied, you can very easily change the output location and file name of the compiled DLL. This is useful if you want to compile the DLL and place it directly into your OP2 game directory to test it :D To do this, create a project with one of the templates, then in the Solution Explorer, right-click on the project and goto Properties. Under "Configuration Properties -> General", there is two options you can change, "Output Directory" and "Target Name". Output Directory is the location that the DLL will compiled too and Target Name is what the DLL will be named, which by default is the project name. The Output Directory can be relative or absolute. If you are using relative, ".\" means current directory, and "..\" means previous directory. For example, if have the file structure like this
  • Outpost2
    • Dev
      • API
      • Templates
      • Tutorials
      • Some Project
    • Game
The game files are located at "Outpost2\Game" and the project is at "Outpost2\Dev\Some Project". If you want the DLL to be directly compile as a tutorial mission named "tTest.dll", you would change Output Directory to "..\..\Game\" and Target Name would be "tTest".

Importing Visual C++ 6 Project (.dsp) to VS2012
First, find the .dsp file. Rename it to whatever you want the project to be named (this allowes you to have mutliple OP2 projects in on Solution, not required). Then, either goto "FILE -> Open -> Project/Solution" or "FILE -> Add -> Existing Project..." and select the .dsp file, or just double-click the .dsp file. Follow the prompts to import the project. You should have a couple of minor errors for the solution import. You can ignore these. Once you import them, you need to modify them a bit to make them compile for the new version of VS. In the Solution Explorer, right-click the project name, goto Properties. In the Properties window, goto "Configuration Properties -> Linker -> Advanced". Look for the option "Image Has Safe Exception Handlers" and set it to "No (/SAFESEH:NO)".

Changes made to Outpost2DLL SDK
This is technical stuff that is boring and most people probably do not care about. These are the changes I had to made to the Outpost2DLL.h file to work with the new setup. In previous setups, it was assumed that the user manually included the .h and .lib files per project. I made everyone's life easier by adding these files to the include directories for VS itself, so there is no problem with trying to use the API functions. I also had to update the check for the CRT replacement. Anyways, I changed lines 4-10 in Outpost2DLL.h to

Code: [Select]
#pragma comment(lib, "../../Lib/Outpost2DLL")

// Use smaller runtime if MSVC 6.0 is being used
// Note: Later compilers have issues with this.
#if _MSC_VER >= 1200
// Replace the C-RunTime (CRT) with a customized smaller one
#pragma comment(lib, "../../Lib/LibCTiny")
« Last Edit: February 26, 2013, 12:30:21 AM by angellus »

Offline TH300

  • Hero Member
  • *****
  • Posts: 1404
    • http://op3game.net
Setting Up Op2 Sdk With Vs2012 + Project Templates
« Reply #1 on: February 26, 2013, 03:02:48 AM »
Thanks. This will hopefully get more people into op2 coding.

However, I have to question your practice of copying the SDK files into the VC directory. That may lead to confusion if MSVC is reinstalled (e.g. replaced by a new version) or if the developer decides to use a different IDE. It would also be nice if projects could be moved to other computers without change. With templates there should be no problem with keeping the SDK files in the SDK directory.

I also find hardcoding of the linked libraries a bad idea (at least LibCTiny), since there may be cases in which the developer wants to use different libraries (with the same or similar functionality). For example, LibCTiny doesn't provide a complete runtime and I have to use the default CRT, to compile one of my projects.

Offline Angellus Mortis

  • Full Member
  • ***
  • Posts: 138
Setting Up Op2 Sdk With Vs2012 + Project Templates
« Reply #2 on: February 26, 2013, 07:50:31 AM »
Quote
However, I have to question your practice of copying the SDK files into the VC directory. That may lead to confusion if MSVC is reinstalled (e.g. replaced by a new version) or if the developer decides to use a different IDE.

I also find hardcoding of the linked libraries a bad idea (at least LibCTiny), since there may be cases in which the developer wants to use different libraries (with the same or similar functionality).
Copying the SDK files into the VC directory is standard practice. I also started doing OpenGL development and all the tutorials for that tell you to do the same thing.

The linked libraries are already hardcoded. If you open the original OutpostDLL.h file and compare it to the one I modified, I only changed the relative path.  

Offline TH300

  • Hero Member
  • *****
  • Posts: 1404
    • http://op3game.net
Setting Up Op2 Sdk With Vs2012 + Project Templates
« Reply #3 on: February 26, 2013, 05:06:51 PM »
Quote
Copying the SDK files into the VC directory is standard practice. I also started doing OpenGL development and all the tutorials for that tell you to do the same thing.
I guess, I'm too used to the Linux way of programming. On Linux, headers and libs are stored in an application-independent location and any dev tool can use them.

Quote
The linked libraries are already hardcoded. If you open the original OutpostDLL.h file and compare it to the one I modified, I only changed the relative path.
I realized that I am using an old version of the SDK (its version 2 and only the version in our svn repository is newer, so I think, its not too outdated).