Setting Up A Sample Project With libtcod-net From SVN

After posting my little drooling plug for libtcod-net, the maintainer, Chris, welcomed me to contribute some code. So I did, dumping a 182KB patch in his lap the next day to start refactoring stuff and streamlining the API. So now I guess I should recommend it even more strongly, eh?

Smok on the libtcod-net forum asked for a step-by-step on how to set up the library for use in a C# project. Since I’m expecting there to be more breaking API changes in the future, I’m going to describe the process using the libtcod-net Subversion repository on Google Code in order to stay up to date with any changes. (This does mean that your code will occasionally break in new and exciting ways until the API stabilizes. If that’s not your bag, go download the source packages available here and start following these instructions at step 6.) I’ll be assuming that you’re using Windows and Visual Studio as well, mostly because I figure that if you’re using Linux you probably already know how to deal with this stuff. The instructions are after the jump.

Before we begin, you’re going to need a few tools. You’re going to need a C# environment. I recommend Visual Studio; college students can get VS2008 Professional for free via Microsoft’s Dreamspark program and anybody can get Visual C# Express. You will also need a Subversion client; I recommend TortoiseSVN because it’s a nifty shell extension and remarkably easy to use.

Alright, ready to move on? Rock.

  • Create a directory somewhere, wherever you keep your projects or libraries, and name it libtcod-net.
  • Go into that directory. Then right-click and select SVN Checkout.
  • TortoiseSVN will present you with a dialog box.

    You'll see something more or less like this.

    You'll see something more or less like this.

  • In the dialog box, verify that the checkout directory is the one you’ve just created and enter http://libtcod-net.googlecode.com/svn/trunk as the repository URL. The checkout depth and revision should be already set for you. Click OK.
  • TortoiseSVN will do its magic for you and download the source for the library for you. This might take a minute or two.
  • In the root of the libtcod-net directory, you’ll see a Visual Studio solution file, libtcodWrapper.sln. Open it in VS2008/VC# Express.
  • If you’re using Visual C# Express, you’re going to need to enable advanced build configurations. Go to Tools->Options, check Show All Settings, and check Projects->General->Show Advanced Build Configurations.
  • In the Solution Explorer, right-click TCODTestLib and click Unload Project; you probably don’t have NUnit installed, so that project will throw approximately eight bajillion errors if you try to build it. (If you want to help develop libtcod-net, I’ll assume you already know how to deal with NUnit.)
  • Make sure that Release is selected in the Solution Configurations dropdown (it may be on Debug by default) and then press F6 (or, via the menu, Build->Build Solution). VS will build the library and the sample project. If you’d like, you can dig around the demo project’s sample.cs and see how things work, but we’ll cover most of that here.
  • Now, create a new solution in Visual C# Express, of type Empty Project. Make sure that you create a directory for the solution as well.
  • Copy all the files in libtcod-net/bin/Release (there should be three files, an .xml file, a .pdb, and a .dll) to the root directory of your solution. Also copy Demo\libSDL.so, Demo\SDL.dll, Demo\libtcod.dll, Demo\libtcod.so, and Demo\terminal.bmp to the root directory of your solution. (While you don’t have to copy the files to your own solution right away, it’s easier to do so, so you have them all in one place when you need to access them.)
  • Go back to Visual Studio and your project. Right-click on the “References” item in the Solution Explorer, then click Add Reference. Select “System” and “System.Drawing” from the NET tab and click OK. Go to Add Reference again, click “Browse”, and navigate to the root of your solution, then select libtcodWrapper.dll.
  • You’re ready to write some code. Create a new code file, Program.cs, and input the following (my indentations have been mashed by WordPress, but Visual Studio will correctly handle them):

    using System;
    using libtcodWrapper;
    using Console = libtcodWrapper.Console;

    public class Program
    {
    public static void Main(String[] args)
    {
    CustomFontRequest fontReq = new
    CustomFontRequest(”terminal.bmp”,
    8, 8, 16, 16, false, ColorPresets.Black);

    RootConsole.Width = 80;
    RootConsole.Height = 50;
    RootConsole.WindowTitle = "Hello World!";
    RootConsole.Fullscreen = false;
    RootConsole.Font = fontReq;

    RootConsole rootConsole = RootConsole.GetInstance();

    rootConsole.PrintLine("Hello world!", 30, 30,
    LineAlignment.Left);
    rootConsole.Flush();

    Keyboard.WaitForKeyPress(true);
    }
    }

  • Select Debug in the Solution Configurations dropdown, if it’s not already selected, and press F6 to build it. It should build correctly without error.
  • Remember those files I had you copy into the root of your solution? Copy libSDL.so, libtcod.so, SDL.dll, libtcod.dll, and terminal.bmp into $PROJECT\bin\Debug (substituting your project’s directory for $PROJECT).
  • Go back into Visual Studio and run your program with F5.
  • Now get hacking! If you have any issues, feel free to post in the libtcod-net forum and people will try to help.
[Slashdot] [Digg] [Reddit] [del.icio.us] [Facebook] [Technorati] [Google] [StumbleUpon]
This entry was posted in Open Source, libtcod-net and tagged , , , , . Bookmark the permalink. Post a comment or leave a trackback: Trackback URL.

10 Comments

  1. Posted August 15, 2008 at 4:11 pm | Permalink

    Two notes:

    When you open the project it might complain about properties it can’t parse; feel free to ignore it.

    When you copy libtcod-net into your project, you won’t need the .pdb unless you are planning on debugging into it, nor the xml unless your planning on updating my documentation. :)

  2. Jordan
    Posted August 19, 2008 at 12:02 am | Permalink

    Well, I’m not entirely sure what’s going wrong here, but I can’t get that to compile. It keeps throwing some error about “side-by-side configuration” along with a more standard “libtcod.dll not found” sort of error. I’m very confused. I’m going to assume it has to do with Vista in some way because I can’t even get the precompiled demo to run. Sigh… I’d post this at the forums but they seem to be down right now. Do you think you could help me, please?

  3. Jordan
    Posted August 19, 2008 at 12:04 am | Permalink

    Just tested the older 0.11 demo and that ran… odd. No idea what the problem could be with the new one. =(

  4. Ed
    Posted August 19, 2008 at 9:10 am | Permalink

    I’m in Canada at the moment and can’t access dev stuff ATM. I’ll shoot a link to Chris, maybe he can help.

  5. Chris
    Posted August 19, 2008 at 9:25 am | Permalink

    Hmm. I’m running vista and it works for me. Please make sure you have the .net 3.5 framework installed. e-mail me at chris _dot_ hamons _at_ gmail _dot_ com if that does not help.

    Thanks,
    –Chris

  6. Liz
    Posted September 9, 2008 at 3:46 am | Permalink

    I found this and went to http://code.google.com/p/libtcod-net/downloads/list to download the sources, but the sln file is NOT in it. Meaning I cant follow the instructions which is a little disapointing.

    I too am embarking on a roguelike creation and this looks spot on.

  7. Ed
    Posted September 9, 2008 at 11:39 am | Permalink

    Wow, yeah. That’s a problem. I’ll ping Chris.

    As it is, just use the SVN release, it’s more up to date.

  8. Anonymous
    Posted September 16, 2008 at 4:26 pm | Permalink

    There is no reason to provide a GNU/Linux version of this anyway, since we can’t use .Net! Yet another reason to avoid .Net like the plague.

    REPLY: Right, because there’s no such thing as that little “Mono Project”. Stay in your basement, cretin, it’s safer for you there.

  9. Aaron
    Posted October 29, 2008 at 1:55 pm | Permalink

    I had to replace Color.Black with ColorPresets.Black to get it to compile. The demo seems to use ColorPresets when it is getting hard-coded color values, so I assume it is simply a typo in the code above.

  10. Ed
    Posted October 29, 2008 at 5:07 pm | Permalink

    That’s correct. This was from before we started cleaning the code. I’m idle on the project now because of a lack of time, but I fixed that in the above code. Thanks!

Post a Comment

Your email is never published nor shared. Required fields are marked *

*
*