Rapid prototyping when making games

Started by
4 comments, last by Cornstalks 11 years, 10 months ago
I had fun in this weekend's 72 hour game making competition. I started from scratch (on a clean Windows partition, even), and the whole time I wish I could rapidly prototype. However, some issues that make prototyping not rapid are:

  • Compile times
  • Restarting the game (i.e. you're not in the middle of that battle anymore)


I want to try and mitigate these slow downs so I can make my prototyping more rapid, and that's what my question is all about. I've come up with the following list of things (some inspired by Hodgman's awesome post) that can help with rapid prototyping:

  • Dynamic configuration variable values

    • XML file has various values (i.e. update rate, gravity vector, etc.). This XML file can be watched for changes, and reloaded if necessary.
  • Using more content files

    • In my hasty programming, I hardcoded things I normally wouldn't hardcode, like the Kraken's tentacle length or base tentacle size. These content files are kind of like the one file talked about above, but more specific and less global. They can also be things like a map file, or a texture image. Just things that aren't hardcoded. I can watch for changes in these files and reload if necessary.



  • Now my two big questions are:

    • How can I reduce compile times?

      • I know there isn't a silver bullet for this, but there are some things that need to be tweaked (like behavior or steering algorithms, where a small change in the algorithm (not just a change in a variable) can have a noticeable effect) until they're just right. It sucks recompiling (mostly because or relinking) for tiny algorithmic changes. I've thought of using scripting languages, but that leads into my next question:
  • How can I save state after making changes?

    • Nobody likes replaying the first 10 seconds (or more) of the game every time the recompile. Whether I'm using scripting languages or reloading a map or character file, how can I save state the best? The only thing I've really come up with is making every object serializable, and then saving the game as a whole in a file (kind of like saving a game like you normally would, but more verbose so things like menus and stuff can be reloaded if you're working on the menus, for example). Is that overkill?
    • I'm not sure how to preserve the state of things that change. Oxymoron, I know; let me explain. Basically, I might make a change to some object that affects a portion of it, but not all of it. Is it worthwhile trying to preserve the part that didn't change (assuming that doing so wouldn't put the object in an invalid/corrupt state), or is that just too much of a pain the butt?


  • I know, I basically just described Lisp, Lua, Python, Ruby, etc with some of the things above. And I'm seriously going to start looking at integrating a dynamic scripting language in my future C++ games (one reason I haven't gotten around to doing so yet is because I love my Visual Studio C++ debugger, and mixing C++ with a scripting language just doesn't sound fun to debug; but I'm going to get over that, don't worry).

    But in addition to that, are there any advices you have for rapid prototyping when developing a game (particularly when the primary language is C, C++, or any other non-dynamic language)? Any advices on clean/beautiful ways to integrate scripting languages (it's one thing to integrate a scripting language; it's another thing to do it well). Because I'd love to hear them.
    [size=2][ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]
    Advertisement
    Visual Studio's edit-and-continue feature helps with both those problems. As long as you are modifying existing function you simply need to stop it in the debugger, you simply make the changes and continue running.

    Reducing compile time is a bane of C and C++. You can break dependencies, reduce and eliminate headers, use the PImpl idiom, and do everything in your power to prevent header files from changing. Many books have been written about it, and the poor design costs enterprise-size developers millions of hours every year. Unfortunately the design of the language requires the full type to be known at compile time, so changing one byte in a single header could theoretically cause almost your entire app to rebuild. Switching to a language like C# or Java, or one of the other languages you mentioned, can dramatically improve this problem; you change one file, only one file gets recompiled.


    As for state changes, and avoiding loading, if you come up with a solution I'd love to know. On one online title I worked on it could take a half hour or more to reconstruct an exact bug in the debugger (or debuggers plural, when dealing with multiple online players), and being able to save the state of everything would be great. Sometimes you can save the game close to the point you need. Other times due to the design of the game engine you cannot. As far as I can tell, that is just a part of regular debugging.
    For the restarting issue I just hack the code.
    Another thing I do is use globals like a nut, and printing the states' values (I may misunderstood the question), then hard code the states for example.

    Anyway, I think I did well with fast prototyping in this contest. My experience is that for rapid prototyping, forget about clean code. Totally forget it. I mean really. My code is so horrible that probably anyone who would see the code would commit suicide.

    I tend to hack, but I became a master at it now. Don't try to be smart at all. My code has tons of code repetition. Even trivially functionizable parts are repeated, because there's no time to think in advance what you might need to reuse, if you realize it, then there's no time to functionize it then rewrite the calling stuff etc. Making the interface of the function, thinking about a good name and calling the function is extra time compared to in situ coding.

    I prefer doing stuff with functions instead of smart data structures too for prototyping. Lots of things could have been solved with semi-smart data structures in the game (for arms' path finding for example), but inventing this data structure takes more time than explicitly coding what to do in a monster if-else-series or switch case.

    Don't implement everything the program needs. Just implement what is needed visually. Hard to explain. For example, in my game, I only implemented the sliding the rows/columns, but not the arms' path finding and not the winning conditions for a long time. But this was just enough to try if it would be good gameplay wise, even if reaching a ship did absolutely nothing.

    I repeated stuff to the extent of totally meaningless repeats, like highlighting the cell that the mouse hovers is totally separate from the actual cell selection. It has its separate "x,y" global variables, and it's only there for rendering. Of course, it could have been integrated to the actual selection mechanism, but it would have required to modify the program flow a bit, which may have caused bugs and would have needed testing.
    There are also some other repeats of this kind, where instead of modifying the program flow to add a visual feature I just introduced dummy variables and functions.


    Not technical, but making detailed TODO lists, FIXME lists, desired features' list and forcing yourself to check their items helps a lot too, but that's obvious I guess.

    But in addition to that, are there any advices you have for rapid prototyping when developing a game (particularly when the primary language is C, C++, or any other non-dynamic language)? Any advices on clean/beautiful ways to integrate scripting languages (it's one thing to integrate a scripting language; it's another thing to do it well). Because I'd love to hear them.


    The games I've seen that don't have a dynamic scripting language usually end up with some kind of Quake-style console or 'tweaks menu'. Something that can be easily accessed in-game and gives you the ability to play around with whatever tweakable things you expose to it. If these tweakables are content then saving the changes that you make's a lot simpler too.

    You may be interested in checking out this GDC presentation; the Bitsquid guys provide some excellent techniques and ideas for reducing content iteration times. I also like the way that they have integrated Lua into their engine. All of their stuff is worth a read.
    How can I save state after making changes?[/quote]
    Depends on what your game state is. As an example, if you were using Lua [to script] you could follow in Fable 3's footsteps and leverage Pluto (http://lua-users.org/wiki/PlutoLibrary) to, essentially, save your entire Lua "universe" to a flat file and be able to reload it on boot. There was an entire article written [by Fable's devs] on the subject but I cannot seem to find it amongst my bookmarks currently; I apologize.

    The only thing I've really come up with is making every object serializable, and then saving the game as a whole in a file (kind of like saving a game like you normally would, but more verbose so things like menus and stuff can be reloaded if you're working on the menus, for example). Is that overkill?[/quote]
    No, that's the basic gist of what most "high level" language serialization libraries support; it's basic, works reasonably well for minimal effort, and is generally performant for small/medium loads. Just be careful and plan how you want to handle versioning.

    Secondly, divide-and-conquer is an excellent strategy in situations like this. Per your example, why not save the "menu" (e.g. GUI) state in a separate file and ram the objects in another? This will be the case anyway if you use a dedicated GUI library (that likely comes with it's own designer + custom formats).

    one reason I haven't gotten around to doing so yet is because I love my Visual Studio C++ debugger, and mixing C++ with a scripting language just doesn't sound fun to debug; but I'm going to get over that, don't worry)[/quote]
    Most of the popular languages have their own debuggers (and their own debug/error callbacks and symbols) you can use. It's true that debugging both can be somewhat aggravating, but the time (and convenience) you save from using a scripting language tends to be worth it. I was under the impression that Lua had a VS debugger plugin, but I don't know if that's still the case.

    But in addition to that, are there any advices you have for rapid prototyping when developing a game (particularly when the primary language is C, C++, or any other non-dynamic language)? Any advices on clean/beautiful ways to integrate scripting languages (it's one thing to integrate a scripting language; it's another thing to do it well). Because I'd love to hear them.[/quote]
    As is mentioned in the link Teutonicus posted but I'd like to reiterate: network consoles are a beautiful, beautiful thing [when done right]. Since (obviously) the relationship between your game and your console is of the server/client persuasion, your console never needs to be "shut down" and can function as a mini-IDE if you need it to (save snippets, inject scripts, etc).

    However, the biggest boon by far - and what I would say is one of the keys to prototyping (and is even mentioned by Hodge in his post, albeit indirectly) - is that you don't have to write [the console] in C++. C++ is nice a language for some things, but for a lot of others (e.g. GUIs) it's just a tremendous pain. With the advent of .Net and the JVM, scripting languages are now first-class citizens in their ability to seamlessly integrate with their "hosts" (C# and Java, respectively) and their associated libraries - use them.

    As for "beautiful integration" between C++ and scripting languages ... most people's idea of that consists of using C++ as little as strictly necessary. If you're looking to boost your productivity for prototyping, porting (or "binding") your personal libraries to your language of choice can be immensely helpful (typically as a DLL extension). Just be aware that a lot of the binding libraries (such as Luabind and Boost::Python) work very well but you'll never get the kind of first-class experience you'll find elsewhere (there's no drop-in and "oh hey my language magically understands C++"). I don't say that to deter you, but it's just a fact that you need more time (than, say, in C# or Java) to see returns on your scripting investment. If you're looking for a "quick fix" to your scripting needs odds are you'll be very disappointed.

    That said, if you're willing to put in the effort scripting can be very rewarding.

    TLDR: Moar scripting, less C++. Also, no handwritten XML - your time is valuable, don't waste it closing tags.
    Thank you guys for your awesome feedback. I really appreciate it! I'm going to be trying lots of things like these, as now I'm working on an Android/iOS game and this'll help a lot with that.
    [size=2][ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]

    This topic is closed to new replies.

    Advertisement