Project Frontier: Source

By Shamus Posted Thursday May 3, 2012

Filed under: Programming 124 comments


The source for Project Frontier is now available on BitBucket. I’m really hoping you find it to be useful. I’m very sorry to see I left the codebase in such shabby shape.

The program defaults to re-loading the last save you played. If you’re running it for the first time, then it doesn’t do anything. Bring down the console with ~ and type:

game new 1

You can replace the 1 with any number you like. That’s the seed number used to create the world. Different numbers will lead to different worlds. (The screenshot above is from right near the spawn point in world #1.)

Looks like it also defaults to wireframe on, textures off, shaders off. That’s dumb. Sorry. In the console:


That should put you in a good place. Also use:


If you’re a mouse-inverter. Use




To turn flying on and off. The WASD keys move you around. Right-click enters and exits mouselook.

Missing textures are represented with a checkerboard pattern.

Please let me know if you have any other problems.


From The Archives:

124 thoughts on “Project Frontier: Source

  1. rmt says:

    So why try to put the thing on GitHub if you used a Mercurial repository all along?
    Also, thanks! I’ve been looking forward to this =)

    1. He actually forgot he had used Mercuirial.

      1. rmt says:

        Ah, thanks. Reading edits FTW

        1. BeamSplashX says:

          I think he forgot about having used Mercurial.

          1. Andrew B says:

            So why did he try and use GitHub?

            1. rmt says:

              Because he didn’t remember that he had the code on BitBucket :P

    2. Volatar says:

      Simple: Because he didn’t remember that he had used Mercurial.

    3. Luke Maciak says:

      Cause we all were like GITHUB GITHUB GITHUB in the comments. He tried to accommodate us.

  2. atma says:


    I think it is a very good thing; i won’t have time to delve in the code but i think it will definitely benefit the community (i’m thinking in particular about your river code, which i find very interesting)

    Don’t hesitate to keep us posted about what spawns from your code.

  3. Otakun says:

    Thank you, Shamus!

    I’ve usually done most of my (scientific) program on a unix account, but am now starting to re-teach myself C/C++ at home on my Windows box. Anyone have any suggestions on a free IDE to use? If I can get Frontier to compile that will be a major achieve for me :P

    1. rmt says:

      There is a free version of Visual Studio available here. Alternatives are CodeBlocks or the QtCreator, which are both also cross-platform.

      1. psivamp says:

        I would love to recommend QtCreator (cross-platform development without splitting your codebase), but it just stopped compiling my project by trying to link to things that don’t exist that I didn’t intentionally ask it to. My OpenGL demo code doesn’t depend on an installation of some SQL library that I’ve never heard of or had installed. Grr…

        Edit: Managed to get rid of it by manually removing it from my Makefiles. It would be nice to have found some documentation on how to change that inside QtCreator, but I can compile again…

    2. Simperin' Fool says:

      I’ve used Dev C++ and found it to be quite nice.

      1. Don’t use Dev-C++. The compiler it ships with is a beyond ancient version of MinGW that can’t handle modern C++ or libraries. You can install a newer version of MinGW for it, but it’s not worth the trouble.
        Using Dev-C++, you’ll run into lots of code that doesn’t compile, but when you ask for help everyone will say there is no problem on their end…it’s simply Dev-C++ being unable to handle C++.

        Instead, use the freely available VC++ Express or Qt Creator or anything else that integrates properly with the debugger and autocomplete (which so far only VC++ and Qt Creator do on Windows).

        1. Nick says:

          You know there is a new fork of Dev-C++?

          You can use MinGW or TDM-GCC. I have no idea how good each of these are, but they appear to be the latest versions.

  4. Dev Null says:

    We need a post – this one would do fine, really – for people to post their favorite world seeds.

    Haven’t played with it yet myself (yeah well; I really should do _some_ work today) so I don’t have any favorites… yet.

  5. nmichaels says:

    If nobody does it before this weekend, I might hack up some makefiles to get this thing building on Linux. Of course, I’d probably have to remember all the C++ I’ve forgotten and then learn the rest. Maybe not though!

    1. Deadfast says:

      I’m afraid porting this will require much more effort than just a makefile. Assuming all the libraries used have a matching Linux alternative there are still the WinAPI calls I spotted during my quick look.

      1. nmichaels says:

        I haven’t scanned the source yet, so maybe you’re right, but it’ll get done one way or another.

        1. Deadfast says:

          It would hardly surprise me. I looked at the libraries used and all of them are indeed available for Linux. So in the end it really is just about stripping out windows.h.

      2. ferryman says:

        I don’t think there are that many ties to windows. SDL takes care of opengl and input, and along with cg, it’s cross platform. The biggest worry, though, is the .ini settings parsing system. Maybe we could get Shamus to switch to xml and use, say, tinyXML.

        In the mean time, I’m sure WINE will run a visual studio or mingw binary.

    2. Bryan says:

      IIRC it took me about a week and some change (hacking on it nights and weekends, when not working) to port over pixel city. This should be mostly similar in terms of the windows api calls, except probably many many fewer of them. (And no four days’ worth of trying to figure out freetype or fontconfig or whatever it was, to get the bitmaps for the fonts used on buildings. Probably.)

      Not sure if I’ll get time in the next day or two to install mercurial and fork the repo, and get started, but maybe.

      The INI parsing code really wasn’t hard to port over; there was an entire separate Ini.{h,cpp} file pair that made it really self-contained.

      1. Bryan says:

        Got maybe a third of the way through (when counting by files), or possibly up to half, making the .cpp files compile into .o before needing sleep. We’ll see how much farther I get tomorrow.

        My forked repo, FWIW:

  6. thegrinner says:

    Seeing as this is a public repository, I feel the need to ask whether you prefer we fork before doing any playing with the code or if direct changes are acceptable?

    1. Rick C says:

      I would think it’s best to leave the original codebase alone and fork it if you want to do anything with it.

    2. BeamSplashX says:

      Quit forkin’ around.

    3. Luke Maciak says:

      Mercurial is distributed. Fork, make changes. Then create a pull request… Wait, does Mercurial have pull requests?

      I would say fork, hack, then figure out how to contribute back upstream later. You won’t be able to write directly to his bitbucket anyway unless he gives you write access.

      1. nmichaels says:

        Yes, bitbucket has pull requests and Mercurial is functionally very similar to git.

        1. Psithief says:

          I read that bitbucket also added git support. ( Is that a per-repository thing, or do all repositories now somehow support both – leading to the novelty situation where we can clone frontier through git?

          1. Bryan says:

            It’s set per repository, unfortunately:


            Step 2, sub-step 6. “Check Git for the Repository type. You can’t change this value later.”

  7. MichaelG says:

    So what do we need to install in order to get this code and run it?

    1. Dave B says:

      So far, I went to the Bitbucket page, used “Download Source”, downloaded the .zip. Then I got extracted the .zip onto my hard drive and then downloaded Visual Studio C++ 2010 Express. I opened “Frontier.sln” and pressed “build”. Then the compiler choked because I seem to be missing something called “glConsole.”

        1. Dave B says:

          Well, I got GLConsole, then I got GLUT, then I got SDL, then I got lots of new errors, and I decided to wait for someone else to upload the binaries. This is just too many new things for me to figure out all at once.

          1. Simon Buchan says:

            I’ve mostly got that figured out – I’m cleaning it up a bit so it’s easier to build, then I’ll put it up (and put a pull request, in case that’s a thing Shamus wants to do). I’m swapping out the NVidia specific Cg shaders for regular GLSL so everyone can run it, after that.

    2. Neery says:

      I’d be really grateful if someone would be willing to post some sort of tutorial for non-coders on how to turn the github file into an executable game. I just want to walk around in the world, not play around with the source files, but to be honest I’m a little stumped. (I should probably try this again when I’m not half-delirious from exhaustion.)

      1. anaphysik says:

        Indeed. As a follower of Shamus’ work, I’d love to be able to traipse about the procedural worlds his code can generate and check out the scenery. As a non-coder, I have no idea how to go about this. :/

  8. Ed Lu says:

    Maaan, when I saw this title for a second I thought you meant you’d ported Project Frontier to Valve’s Source engine.
    Which, in theory, may be conceivable since it also uses C++ – however, probably still a ridiculous amount of work.

    EDIT: Shamus, what exactly was in your “H:/sdk/cg/” folder? From the compile errors, I assumed it was just SDL, but apparently I was wrong – I’m still missing a couple files, “cg.h” and “cggl.h”. I’m assuming they’re the libraries that you yourself wrote? Nevermind, looking into it more, it’s probably a third party library. However, just doing google searches, I can’t find it. Any way I could get some help with this?

    1. Ed Lu says:

      Whoop, nevermind, I got it. CG is from here:
      And you’ve got to change all of Shamus’ H-Drive references to wherever you’re keeping your libraries. I did this by opening up the .vcxproj file, finding “H:” and changing all the references to wherever my stuff was. Also, there’s a “pragma comment” you have to change within “main.cpp.”
      If anyone wants, I can post a couple of compiled binaries so you can look at PF without having to compile it yourself.

      One last thing though: it looks like the trees are using the entire leaf texture without clipping it. You can see what I mean here:

      1. Adam Fuller says:

        I’d love a compiled version, doing it myself is a bit outside my capabilities.

      2. Adam Fuller says:

        Yeah, looks like that purple should be transparent. But looking at it, not all trees are affected.

      3. Ambitious Sloth says:

        Compiled binaries would be nice. I assume there’s a good amount of people who just want to play around and look at things without needing anymore access than what the console provides. And they probably don’t want to look into setting up visual studio or whatever program they choose to build and run the code.

        1. Jjkaybomb says:

          Yeah, I just kinda want to run around and see the sights. I dont know a thing about coding, or how I could actually get this to work… XD;

      4. Otakun says:

        thats really helpful, thank you!

      5. Luke Maciak says:

        Seems like it might need some serious re-factoring.

      6. Ed Lu says:
        Ok, here’s a binary I compiled in Visual Studio 2010 with Windows 7. This one includes purple trees and, now for some reason, no animations. It works fine when I run it within the directories I set up, but does not when I copy it out of that directory. Very odd.
        Anyway, I figured I’d post it since my edit time is running out (The last one, I posted and forgot to include any of the textures/anims).

        1. MichaelG says:

          I see landscape and a black avatar, but there’s a constant green noise flickering over everything (bad grass?) and the trees are purple.

          1. Ed Lu says:

            That’s odd. The purple trees are to be expected – after I got it compiled, I’ve been trying to figure out why that’s happening.
            Unfortunately, I can’t really troubleshoot this stuff effectively because I only have a vague outline of what the code’s doing. Hopefully someone else posts a binary as well, so we can compare notes.

              1. Piflik says:

                I do have the purple trees, but the grass is ok. No flickering noise. And animations are working, too.

                But I have encountered some strange floating polygons…might be a desired effect, though (fog?). (World Seed: 2)

                1. Shamus says:

                  Yeah, that’s “fog”. Or would be, if the texture was available. I went through the source and added everything *.bmp and *.png that I found to the repository. Looks like some things are still missing, though.

                  1. Bryan says:

                    Texture files used in the code (as in: files referred to in TextureFromName or TextureIdFromName calls), sorted by filename and then unique-ified:


                    Diffing this with the Textures directory’s contents, I can see the files referred to in code that don’t exist in the repo:

                    -clouds3.bmp (but there’s a clouds.pspimage; possibly relevant?)

                    There are a bunch of other files that exist in the repo that aren’t used in code (AFAICT), but that’s less relevant.

                    However, there’s one call, in CEmitter::Render, that calls TextureIdFromName(_settings.texture.c_str()). It *looks* like all of those “texture” entries come from .prt files in the Particles directory, and it *looks* like the list of files is thus:


                    Of those, there’s one more that doesn’t exist:


                2. Ed Lu says:

                  Yeah, I figured out what was wrong with the animations – a “frontier.ini” was included that had a bunch of necessary info, but was also created when the program ran, so I kind of skipped over it.
                  Going to continue to unravel this mystery. I noticed the fog, too – going to try to come up with a suitable replacement texture. Will update the wiki as things progress. I made a place for people to post their compiled binaries.

  9. DrMcCoy says:

    One question: What license is this code under?

    1. Luke Maciak says:

      Good question. I would like to know this too.

      1. zlib/PNG/BSD is what I’d recommend, alternatively pick an appropriate license.

        Note that the license would apply only to Shamus’s code,
        any 3rd party code used is subject to their own license. (GPL and LGPL can be a real pain in the ass, which is why I recommended zlib/PNG/BSD style license or CC)

  10. Luke Maciak says:

    Awesome! Thanks for doing this.

    I hate to give you more work, but if you find a free minute could you perhaps put a small README with the code that outlines:

    – What are the basic system requirements: (ie which Visual Studio version you used, what additional tools might be needed).

    – Few sentences on how to compile (if there are any steps other than hitting compile button)

    – All the stuff you just explained above (or link to this post)

    This way if someone stumbles upon your source code six months from now, they can build and play with the game without actually having to dig out this post to learn how.

    Once again, thanks for open sourcing it. :)

    1. DrMcCoy says:

      I wish he would also free (as in freedom) the code, by giving it a free license (copyleft or not).

      Right now, though the code is open, we’re not actually allowed to do anything with it beyond reading, when you’re pedantic about copyright law.

      1. nmichaels says:

        Actually, that’s not true. We’re allowed to do all sorts of things to it, just not distribute the result. In fact, we’re not allowed to distribute it at all. Not even to put up on bitbucket.

        Fortunately, that only applies if Shamus is a litigious jerk, which he is not.

        Incidentally, the libraries may be under different licenses that need to be included.

      2. Luke Maciak says:

        Very good point.

        Shamus, if you don’t care I would recommend the WTFPL license: :P

        If you don’t want people making for-profit copies then just go with GPL.

        1. DrMcCoy says:

          Copyleft licenses like the GPL still allow people to monetize your work, they just require them to also free any changes they made.

        2. nmichaels says:

          BSD is good and short, if you don’t care what people do with it. If you want PF to only form the core of money-making games when you approve, the GPL (with an option to commercially license) will get you there. Of course, if you go that route you’ll have to get approval from anyone who contributes to it. The GNU approach of requiring anyone who contributes to assign copyright to you can work, but it’s not very practical if you want to encourage people to work on it.

          Short version:
          Do you care if other people internalize this into commercial products?
          Yes -> GPL
          No -> BSD

          The other thing to consider is the license for the various libraries you’re using. SDL is LGPL’d, so as long as you don’t make changes to SDL itself you’re clear. I don’t know about all the other things you’re using, but if you link with something that’s GPL’d, and distribute the resulting binary, you have to GPL it.

          That can help.

          And you thought open sourcing stuff would be easy!

          1. Shamus says:

            I’ve placed the BSD license on the Wiki.

            1. Shamus says:

              And now I’ve changed it to the WTFPL.

              1. harborpirate says:

                I’ve seen some developers multi-license stuff.

                Thus far, Apache and MIT were the two most “free” license types that I’d seen – this is the first I’ve heard of WTFPL, so I’ll be interested to check that out.

                I’m just thrilled that you decided to open up the code, I think this is of great benefit to the development community at large.

                Thank you!

                1. My personal favourite license to use (if I feel like I’ve been remotely creative in some way) is
                  In a binary release, at minimum a copyright line crediting the original author is only needed (but apparently optional).
                  So no TEXT BLOCK OF DOOM to annoy people with.

                  And in the cases where I don’t feel like I did anything remotely creative I just “license” it public domain. (Just a line of textg stating I place it in the public domain).

                  Though Creative Commons is kinda neat as they have a more standardized way of creating your licensed. (both zlib’ish and PD’ing your work) so I might use that in the future, we’ll see.

                  EDIT: Actually after looking quickly at the longform CC, and the BSD and MIT licenses. I find that the zlib license is probably the most straight forward and and simple license I’ve seen.

  11. Luke Maciak says:

    Guys, can we start a list of dependencies for this? Maybe Shamus can add it to a REAMDE later.

    So far from the comments I gather you need:

    GL Console:
    CG Tookit:

    Anything else?

    Shamus, can you enable the Wiki on the Bitbucket page? Maybe we can pull resources and write some documentation for you. Crowdsourcing man! :)

    1. Zukhramm says:


      The one seeming to give me problems is GL Console, the others I’ve just hooked up to their include-folders, but this one I have no idea what to do with.

    2. Shamus says:

      Boom! Wiki is public.

    3. Simon Buchan says:

      Actual GLUT is super crappy, grab FreeGLUT (it comes with binaries for lazy people like me, even)

      1. Bryan says:

        Note that FreeGLUT will barf an error and die the first time a glut* function is called in the current state of the code, since nothing ever calls glutInit() at startup. (Or, at least, my version of freeglut does this.)

        fixed this for me, although I have no idea how to get an argc / argv out of WinMain for the #ifdef WINDOWS branch. Shrug. :-)

    4. Bryan says:

      Be aware that if you try to build GLConsole from source, it does *not* use the standard autoconf procedure (./configure / make / make install). It uses cmake instead. So if, like me, you don’t have cmake installed because you’ve never needed to build anything that requires it before, it’ll be a bit of an experience.

      (Not that it matters all that much, but still…)

  12. Exetera says:

    Uh… is File.cpp supposed to have Activeworlds Inc. copyright info at the top? (Related: is Cg.cpp supposed to have a header claiming to be CTerrain.cpp?)

    That and I kinda disapprove of File.cpp in general. Yuck, Microsoft-specific stuff… curse you, File.cpp, you’ve probably just wasted fifteen minutes of porting time. It also stores timestamps in 32-bit integers.

    Ini.cpp also makes me sad.

    1. MichaelG says:

      Shhh…. this is why programmers don’t like to release their code to the net.

      1. Ed Lu says:

        Also, why I’m trying to learn as much as I can about this kind of stuff (portability, open source software, third-party libraries, etc) as I can before I get out of college. This is all stuff they don’t teach you about, folks.

    2. Shamus says:

      Wow. That means I’d originally copied something from Activeworlds source.


      Looking at it… it’s clear it’s not this file. It’s obvious I copy that block header around. Still, that’s sort of alarming.

      And like Goodfellow said, this is exactly the sort of thing I worry about when releasing code.

      EDIT: Okay, I’ve looked over the source. I no longer have Activeworlds code to compare to, but I think we’re in the clear.

    3. DrMcCoy says:

      Somewhat related, I could try to start flamewars about how I hate his use of spaces instead of tabs for indenting and his {-placement… :P

      But yes, File.cpp and Ini.cpp are not really tutorials on portability.

      When Shamus settles on a license, I’d probably be willing to relicense my INI reading class as a replacement, if that’s helpful to people.
      It might be too complex for this use-case, though, and has certain other dependencies that need to be replaced, that I can’t relicense (for example, the Stream classes come from ScummVM and are GPLv2+).

      1. Shamus says:

        I’ll go ahead and say File.cpp and Ini.cpp are pretty horrible. Yes, I knew all along they would need to be replaced at some point. You know how it is when you’re prototyping.

        1. Exetera says:

          I’ve got a File.cpp working on POSIX, but I suspect it wouldn’t run on Windows. (Also, I didn’t actually check that some of the directory code actually worked… it looked kinda gnarly.) Now to fix my pesky texture bugs… It loads the sun, the stars, dust puffs, and absolutely nothing else. (Not even the console font!) Any suggestions would be appreciated…

          1. MichaelG says:

            You know, looking at the dependencies and portability issues, I have to say there are some advantages to being anal and writing all your own code like I’ve been doing. Too bad it’s only taken me a year to do what Shamus does with his libraries.

            1. Exetera says:

              Meh, aside from the INI stuff (which I ended up hackily patching out) I haven’t had too much trouble porting to POSIX, aside from this texture thing… and as best as I can tell, that’s not a library issue. (Shamus’ chosen image library seems to be loading images fine, it’s just OpenGL doesn’t render ’em for whatever reason. Still trying to figure out why that is…)

              Of course, I’m of the “write your own code” sort myself, though that’s mostly as regards algorithms… I’m gonna have to implement Fortune’s Algorithm soon, which will naturally be a blast.

              1. Ben says:

                Good luck. A friend and I spent the better part of two weeks trying to get Fortune’s Algorithm for some robotics work. That is one of the most complex algorithms I’ve ever tried to get my head around and implement.

              2. Bryan says:

                Instead of patching out the INI stuff, you could try pulling these from pixelcity:


                Not sure if they’ll continue to work with frontier (going to find out once I get all the $*(@#)”%&)(#$ nonsense introduced by case-insensitive filesystems cleaned up), but maybe.

                1. Exetera says:

                  There wasn’t really that much that depended on the INI code, though. If I were going to replace it with anything, I would probably just rewrite the code using it to depend on CVars instead.

                  1. Bryan says:

                    Well, it’s one of the age-old tradeoffs — between reusing something that has worked previously, even if written for a different source, and just changing around the rest of the program to not require it.

                    Depends on how much you want to do. I have the pixelcity sources sitting on this machine, so I’ll most likely just copy those two files in and — assuming they work — call it an hg commit. :-)

                    1. Bryan says:

                      Hmm, nope. Looks like a few things changed in Shamus’s Ini files. Wheee.

                      They got overloads for specifying a section explicitly, and adding that support will be … interesting. I can probably make it work with a multi-way map: “map<string, map >” where the first is the section and the second is the entry. Hopefully this is reasonably easy to save and parse back. Whee.

          2. Shamus says:

            You know, I’ve got a huge 2k post tomorrow about how much Qt bothers me, but seeing these porting headaches is making it all look reeeeally attractive.

          3. Exetera says:

            Here’s an in-progress screenshot showing [a] that it’s mostly running natively under Mac OS X (POSIX) and [b] that only the stars have any texture.

            1. Exetera says:

              OK, I’m fairly sure that the issue is in the shader system. Shamus, do you remember any issues that you had with the shaders which might be helpful here? Alternately, do you have any suggestions on how to eliminate them entirely? The way it’s set up right now, when I tried to sloppily eliminate shaders, I ended up with a permanently overcast sky and non-colored grass and flowers.

      2. Shamus says:

        The thing is, I HATE a lot of the coding styles I use.

        For years I worked on Activeworlds. That began in ANSI C in 1994. It used the old-school styles favored by its originator. All lowercase. Underscores. Spaces, not tabs. Indents are 2 spaces. Braces open on same line.

        Everyone else followed these standards. Even after the original guy left, it was generally agreed that consistency was king, and nobody wanted to convert all those 100k lines of code from

        void do_a_thing ()


        void DoAThing ()

        When I moved on, I was free to use styles that I favored, but after all those years it was hard to get out of those old habits – even the ones I disliked. I’m looking at frontier, and at my current project, and I’m seeing a lot of worrisome inconsistencies of style. I really do need to pick a set of conventions and stick with them.

        However, I really am a fan of

        //I'm not paid for my code based on the square yard.
        for () {
        do {
        } while (thing);

        I dislike throwing away a lot of vertical space on curly braces. I can understand why people like the symmetry of matching braces, but I’d rather have the screen space.

        1. MichaelG says:

          Tell me about it! I learned all that Microsoft cruft — m_lpzString and then gradually let most of it fade away.

          I was reading someone else’s coding standards the other day, and it was “yes, yes, that too! I do all of that! Finally, someone with the same style as me!” But after the first five points, it went insane and I had to stop reading…. sigh.

          1. Bryan says:

            Ugh, m_lpz prefixes. :-(

            There is, of course, a much better way to do them:


            Apps Hungarian had very useful, meaningful prefixes like “ix” to mean an index into an array, “c” to mean a count, “d” to mean the difference between two numbers (for example “dx” meant “width”), and so forth.

            Systems Hungarian had far less useful prefixes like “l” for long and “ul” for “unsigned long” and “dw” for double word, which is, actually, uh, an unsigned long. In Systems Hungarian, the only thing that the prefix told you was the actual data type of the variable.

            This was a subtle but complete misunderstanding of Simonyi's intention and practice, and it just goes to show you that if you write convoluted, dense academic prose nobody will understand it and your ideas will be misinterpreted and then the misinterpreted ideas will be ridiculed even when they weren't your ideas. So in Systems Hungarian you got a lot of dwFoo meaning “double word foo,” and doggone it, the fact that a variable is a double word tells you darn near nothing useful at all. So it's no wonder people rebelled against Systems Hungarian.

        2. DrMcCoy says:

          Went right the other way round for me.
          I used to put the { on their own line. Instead I was more stingy with the horizontal space “for(i=0;i<10;i++)".

          Then I joined the ScummVM team in 2006, and adjusted to their coding style. And I kept with it. Hugging braces, "for (i = 0; i < 10; i++)" and all.

          The only thing I always did was tabs for indent, spaces for alignment. Spaces for indenting just never made sense to me.

          1. Benjamin says:

            You don’t replace tabs with spaces? MADNESS

        3. Chiller says:

          I prefer to open curly braces on a new line. Not as much for symmetry, but for with being able to easily tell where the blocks start and end.

        4. Neko says:

          For my work, we settled on an unconventional braces style – a mix of K&R style vertically aligned braces for class and method blocks, but with BSD KNF style opening braces on the same line for ifs and loops and anything else. It was weird at first, but I’ve since adopted it as my own – it kind of makes sense that you don’t need to waste whitespace on a 3-line if statement, but you want to keep your functions and methods nicely spaced out.

          Let’s see if I can’t screw up a ‘code’ tag to illustrate my own odd style:-

          TES3::Record *
          QDataStream &data_stream)
          static const QByteArray tes3 = QByteArray("TES3");

          // Check TES3.
          QByteArray magic = data_stream.device()->peek(4);
          if (magic != tes3) {
          qDebug() << "This does not look like a TES3 format file - header magic is wrong.";
          TES3::NotTES3FormatException ex = { magic };
          throw ex;
          return read_record(data_stream);

          1. Neko says:

            Okay, how can I edit comments? I just keep managing to screw up the formatting. I don’t see an obvious ‘edit’ link.

          2. WJS says:

            Given the nature of the blog and audience, I really don’t get why Shamus doesn’t have proper support for code samples in comments. Surely it can’t be that hard? Of course, I’m coming from the direction of having written my own website code from scratch to do exactly what I want it to, so I have no idea how to do things in WordPress-land. Still, it seems like it should come up enough that someone should have worked out a solution by now.

  13. Neery says:

    Thank you for posting this, I appreciate it a lot!

  14. Zukhramm says:

    I guess now’s as good a time as any to learn C++.

  15. Rohit says:

    Thanks for releasing the source, Shamus. My final project in my graphics class last semester was a terrain generator that was inspired by Project Frontier. Your series also helped me implemented a mostly working quadtree simplification algorithm. The code is here, though it’s not nearly as impressive as yours.

    Can’t wait to see what you come up with in Project Octant.

  16. Bryan says:

    Your trees look like cubes. Is that a reference to minecraft, or a result of more traditional tree designs being difficult to program?

    1. Shamus says:

      When textured properly, they should look more like a World of Warcraft-ish kind of thing. I don’t know about “difficult to program”. One tree is about as easy as another until you start getting close to photorealism.

  17. Lachlan the Mad says:

    Speaking as a programming noob; How me make this go?

    1. Ed Lu says:

      Easiest and cheapest way is to get Visual Studio Express. Then, download all the libraries noted here. Download Shamus’ source. Open up the .sln file with Visual Studio. There should be two “frontier”s on the left pane; right click the second one (the one tabbed over on the hierarchy) and hit properties. Look through all the categories; every time you see something like “H:\SDK\…” replace it with the location you downloaded and unzipped the libraries to. Now, you should be good to compile.
      It’s a bit more nuanced than that. Maybe someday I’ll do a long writeup on how to compile other people’s source, but for now, it’s late.

      1. Lachlan the Mad says:

        Nnnnnnnnope, too computer-geeky for me. I’ll wait for a compiled version where the trees work.

  18. Rohit says:

    If anyone wants to run the program in first person view, my .exe is available here.

    Download Ed Lu’s archive and replace the exe with mine, and change the CameraDistance in Frontier.ini to 0.

    If you don’t trust my .exe, I simply reduced CAM_MIN to 0 and commented out the code that renders the player model and the code that handles the mouse-wheel. It works well enough, I think.

  19. Simplex says:

    Could someone please post the executable version of Project Frontier for the n00bs that have no idea how to compile code (i.e: me)?

  20. Doctor Broccoli says:

    Okay, here’s what happened today:

    – I started reading your code
    – Two hours pass
    – I forgot to eat dinner and now have 20+ tabs open in notepad++

    Congratulations Shamus! You created your very own TV Tropes!

    Seriously though, I am learning a LOT from this stuff. I study computer science and although it’s all fine and dandy to hear how this stuff works in theory it can be so much more educational to see how it’s actually applied in practice.
    Thank you for this.

  21. Bryan says:

    Well, I think there’s a bug. :-)

    In World.cpp, both in WorldWaterLevel and WorldBiasLevel, the code calculates an origin.x and origin.y value from the passed-in world_x and world_y values. Then it clamps them to the range [0, WORLD_SIZE-1] (inclusive).

    Then, it tries to get the region at four different points: (origin.x, origin.y), (origin.x, origin.y+1), (origin.x+1, origin.y), and (origin.x+1, origin.y+1).

    However, that last one (just to focus on one of them), up in WorldRegionGet, tries to dereference[WORLD_SIZE][WORLD_SIZE] when the code calls WorldWaterLevel(max_x, max_y) (whatever the maximum world coordinates are). Since the valid indices into C and C++ arrays start at 0 and go to [array size]-1, and since map was declared as “Region map[WORLD_SIZE][WORLD_SIZE]”, you can’t dereference that entry.

    The program segfaults for me partway through building a world (the first time it tries to walk off the end of the — pretty large — block of memory reserved for map). It works fine (or, well, gets past this crash anyway :-) ) if I replace the “clamp” calls in both those functions with clamp calls that limit the range to [0, WORLD_SIZE-2] instead.

    See — though I don’t know if there’s any easy way in mercurial to pull this individual patch.

    1. Bryan says:

      …Except that last commit doesn’t fix all the cases where the code tries to overrun the size of[][] — there’s one more (known so far) in WorldColorGet().

      See for that fix.

      I don’t see any more in World.cpp at least…

      1. Bryan says:

        Another bug. None of the GridData-derived classes are actually calling the GridData constructor. They’re all simply creating a temporary (of type GridData), then throwing it away. :-)

        For instance, in CTerrain.cpp:

        CTerrain::CTerrain ()
          //Call parent constructor
          GridData ();

        Well, er … no, actually, that’s not what that does. :-) That’s what this does:

        CTerrain::CTerrain ()
          : GridData()

        (Note that you can use the initializer list after the colon to set the initial values of class fields, as well, though I think there are some restrictions on the usable values, and I know you have to initialize fields in the order they were declared in the header file. Elements in this list are separated by commas. But that’s a bigger change.)

        1. Bryan says:

          Last bug. I think. :-) This change actually makes it *show* the ground when shaders are enabled:

          (It’s possible that one of my other changes made this particular enum value stop working, but I think it’s unlikely.)

          Now I can finally see stuff. And reverting all the local changes to the .cg programs (that I added to try to figure out why I couldn’t see anything before), makes all the other effects show back up again, as well. :-)

          No purple trees — the surrounding night makes it a little hard to tell, but I do see green. No green noise all over for the fog, either (although again, it’s night, so maybe the fog isn’t present or something; have to wait about ten minutes to see).

          Crap, never mind, the fog isn’t working. (Large checkerboard patterns along the ground instead of actual fog.) Most likely because of the missing fog.png texture I mentioned earlier. Well, everything but that is pretty good, I think. :-)

    2. WJS says:

      Wait, what? Bounds errors and segfaults? How did this ever run?

  22. Troy says:

    I got problems with the binaries Ed Lu offered. Problem: Window keeps black (even after 5mins of waiting), both with on board Intel and normal Nvidia graphics card. Any solutions?

    1. Shamus says:

      Hit the tilde key ~ to bring up the console. Type “game new 1”. That will begin a new game. Replace the #1 with some other number to use as a seed, if you like.

      1. Troy says:

        Thanks :)
        I should read the posts more carefully in the future.. Now its working :)
        Interesting fact: with on board intel gpu: no purple trees, but weird grass effect, like MichaelG mentioned. With nvidia gpu: purple trees, but everything else works fine :)

        1. Troy says:

          Interesting fact #2: with on board intel gpu: clouds, stars (at night) and trees are beeing displayed correctly, with nvidia gpu i don’t see any clouds or stars. Maybe that helps fixing the problem :)

  23. Tharwen says:


    It compiles! It runs!

    I mean, sure, my desktop is covered in assorted source files and binaries which I’ll never be able to reassemble if something goes wrong, and GLConsole doesn’t recognise any commands I put into it, and the trees are all purple, and I have absolutely no knowledge of C++ which I could put to use debugging this stuff, but IT COMPILES! AHAHAHAHAHAHAHAHA BOW BEFORE ME MORTALS.

    EDIT: Oh. It keeps crashing randomly.

  24. Neil Roy says:

    Thanks for releasing the source. I have actually created a similar program, or at least started to, but it’s not nearly as good as what you have done. I have some terrain rendered from a heightmap, some simple trees, a huge water texture like yours (only animated so it is moving and transparent). I added in ambient sound (wind, birds, water when swimming). I done mine like Battlefield 1942 mostly, I copied the terrain so that it basically goes on forever. You keep walking/flying and when you reach the edge it wraps around, but because I copied the terrain and it is designed to the edges all match up (wraps around) it just seems to go on forever. I wanted to try something like you have done, with different terrain in sections and eventually have the world wrap around, opposite sides would match up and you could walk around the world literally.

    I love the idea of procedurally generated worlds, I got the idea from the old game Elite which generated the entire universe at runtime, which led me to your page here when searching. We have the same interests, you just have far more skill! ;)

    As for your coding STYLE, we’re alike I think. K&R seems to suit me, and it looks like your style as well. I also use underscores for my variables, I don’t like the look of MyVariable, I prefer my_variable, it’s more readable in my opinion and I hate Microsoft’s style. Like you I see no need in wasting vertical space on brackets. Some people say it helps them know where the block is, well, you can tell easily by the indented lines…

    if(a == b) {
    c = d + 5;

    As anyone can see, the indented lines make it obvious, but no wasted space. I also can’t stand things like:

    if(a == b)
    d = 1;

    when it could be written:

    if(a == b) d = 1;

    But everyone’s different. If you want to get truly portable, a good compiler to pick is Code::Blocks, it has many of the same look and feel of Dev-C++ for those that liked it, but it is maintained still. It can now (with the latest nightly build) import VC2010 solutions as well as Dev-C++ projects, but most importantly, it is also available on other platforms like Linux, so you can completely port your projects, code and all to Linux, using the same compiler and compile away. Code::Blocks uses the MinGW (Windows version of the GNU GCC) compiler.

    A library I use that is similar in portability as SDL is Allegro (specifically, Allegro 5, which is more up to date). It supports JPG, PNG, OGG, OpenGL etc and is very flexible with nice sound, TTF etc… support as well.

  25. David says:

    Hi! I have been a long time lurker, just reading an article now and then.

    Recently, after a normal bing of your LOTR comic, I started reading the other posts, and just stumbled on this series.

    It’s been a very interesting read, and gave me an itch to look how you coded the project, since I have been always interested on 3D programming. However, the Bitbucket repository seems missing? Was it deleted/removed and I haven’t seen that post or is there is some other reason?

Thanks for joining the discussion. Be nice, don't post angry, and enjoy yourself. This is supposed to be fun. Your email address will not be published. Required fields are marked*

You can enclose spoilers in <strike> tags like so:
<strike>Darth Vader is Luke's father!</strike>

You can make things italics like this:
Can you imagine having Darth Vader as your <i>father</i>?

You can make things bold like this:
I'm <b>very</b> glad Darth Vader isn't my father.

You can make links like this:
I'm reading about <a href="">Darth Vader</a> on Wikipedia!

You can quote someone like this:
Darth Vader said <blockquote>Luke, I am your father.</blockquote>

Leave a Reply

Your email address will not be published.