Project Frontier: Source

  By Shamus   May 3, 2012   121 comments

frontier_source1.jpg

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:

render.shaders=1
render.wireframe=0
render.textured=1

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

mouse.invert=1

If you’re a mouse-inverter. Use

flying=1

Or:

flying=0

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.


A Hundred!201There are 121 comments here. I really hope you like reading.


  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 =)

  2. atma says:

    Hooray!

    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

    • rmt says:

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

      • 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…

    • Simperin' Fool says:

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

      http://www.bloodshed.net/devcpp.html

      • 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).

  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!

    • 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.

      • nmichaels says:

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

        • 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.

      • 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.

    • 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.

  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?

  7. MichaelG says:

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

    • 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.”

    • 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.)

      • 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?

    • Ed Lu says:

      Whoop, nevermind, I got it. CG is from here:
      http://developer.nvidia.com/cg-toolkit
      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: http://inarticulateloquence.com/wp-content/uploads/2012/05/trees.png

      • Adam Fuller says:

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

      • Adam Fuller says:

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

      • 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.

      • Otakun says:

        thats really helpful, thank you!

      • Luke Maciak says:

        Seems like it might need some serious re-factoring.

      • Ed Lu says:

        http://inarticulateloquence.com/wp-content/uploads/2012/05/Frontier1.zip
        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).

        • 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.

          • 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.

              • 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)

                • 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.

                  • 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:

                    avatar.png
                    bark1.bmp
                    clouds3.bmp
                    clouds.png
                    foliage.png
                    font.png
                    grass3.png
                    stars2.bmp
                    sun.bmp
                    sunrise.bmp
                    terrain.png
                    terrain_rock.png
                    terrain_shading.png
                    vines.png
                    water1.bmp
                    water4.bmp
                    water.bmp

                    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?)
                    -water4.bmp
                    -water.bmp

                    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:

                    fog.png
                    particle_dot.png
                    particle_flower.png
                    sand.png

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

                    -fog.png

                • 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?

  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. :)

    • 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.

      • 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.

      • Luke Maciak says:

        Very good point.

        Shamus, if you don’t care I would recommend the WTFPL license: http://sam.zoy.org/wtfpl/ :P

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

        • 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.

        • 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.

          http://www.opensource.org/licenses/category
          That can help.

          And you thought open sourcing stuff would be easy!

          • Shamus says:

            I’ve placed the BSD license on the Wiki.

            • Shamus says:

              And now I’ve changed it to the WTFPL.

              • 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!

                • My personal favourite license to use (if I feel like I’ve been remotely creative in some way) is http://en.wikipedia.org/wiki/Zlib_License
                  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: http://www.robots.ox.ac.uk/~gsibley/GLConsole/
    CG Tookit: http://developer.nvidia.com/cg-toolkit
    SDL: http://www.libsdl.org/
    GLUT: http://www.opengl.org/resources/libraries/glut/

    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! :)

  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.

    • MichaelG says:

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

      • 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.

    • Shamus says:

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

      YIKES!

      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.

    • 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+).

      • 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.

        • 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…

          • 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.

            • 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.

              • 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.

              • Bryan says:

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

                https://github.com/BryanKadzban/pixelcity/blob/master/Ini.h
                https://github.com/BryanKadzban/pixelcity/blob/master/Ini.cpp

                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.

                • 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.

                  • 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. :-)

                    • 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.

          • 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.

          • 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.

            • 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.

      • 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 ()

        to

        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 () {
          stuff;
        }
         
        do {
          stuff;
        } 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.

        • 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.

          • Bryan says:

            Ugh, m_lpz prefixes. :-(

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

            http://www.joelonsoftware.com/articles/Wrong.html

            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.

        • 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.

        • 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.

        • 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 *
          TES3::Reader::read_header(
          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);
          }

  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?

    • 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?

    • 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.

  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.map[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 https://bitbucket.org/bryankadzban/frontier/changeset/f63e6721682e — though I don’t know if there’s any easy way in mercurial to pull this individual patch.

    • Bryan says:

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

      See https://bitbucket.org/bryankadzban/frontier/changeset/413c5c8430a6 for that fix.

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

      • 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.)

        • Bryan says:

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

          https://bitbucket.org/bryankadzban/frontier/changeset/efa4181223a2

          (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. :-)

  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?

    • 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.

      • 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 :)

        • 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:

    I AM AN INVINCIBLE GOD OF PROGRAMMING

    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. […] week Shamus Young has decided to open source his excellent proof of concept, procedural world generation project codenamed […]

  25. 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) {
    do_some_stuff();
    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.

  26. […] worked a bit on Shamus Young‘s project Frontier, fixed a few things, and someone in the comments asked what I did exactly. After writing it up, I […]

2 Trackbacks

  1. […] week Shamus Young has decided to open source his excellent proof of concept, procedural world generation project codenamed […]

  2. By Project Frontier fixes | Csirke blog on September 17, 2013 at 8:17 am

    […] worked a bit on Shamus Young‘s project Frontier, fixed a few things, and someone in the comments asked what I did exactly. After writing it up, I […]

Leave a Reply

Comments are moderated and may not be posted immediately. Required fields are marked *

*
*

Thanks for joining the discussion. Be nice, don't post angry, and enjoy yourself. This is supposed to be fun.

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="http://en.wikipedia.org/wiki/Darth_Vader">Darth Vader</a> on Wikipedia!