Thursday, June 19, 2014

The supporting libraries of a custom game engine

While creating my own game engine, it became pretty apparent fairly quickly that I couldn't possibly do everything that would be required of me to reprogram "from scratch".  We are talking about stuff like opening PNG files and extracting the RGB data out of them!  (As a side note, I DID actually read the RFC  and realized very quickly this isn't something I wanted to do).

PNG files weren't the only thing I wasn't interested in figuring out myself.  There are perfectly good libraries out there that have weathered the long haul and perform very well.  Let's go ahead and admit we can use some help from others in our ambitious goals of writing a game engine from the ground up.

Oh, and a caveat, it had to be free.  I'm sure there are some great commercial libraries out there, but that's not my fancy.  Of all the years gaming technology has existed, there just HAS to be free solutions out there somewhere just for this adventure!

The libraries that I have thus settled for (at least for now!) are:

  • libcurl - CURL is a useful library for dealing with network data transfer over various protocols.  This is useful for stuff like downloading things from HTTP, FTP, and many, many others.  For my intents and purposes, I found it useful that I could post, say, patch files on a webserver and have my game clients download those patches using features of this library.  Technically, my game engine has "enough" features to be able to talk HTTP with a server but I never got around to formalizing it to be as robust as libcurl.
  • lua - Lua is a fantastic and powerful scripting language and feature to integrate in to a game engine.  What better way to extend games than allowing other people, or even the public, to create, modify, and execute their own scripts!  We integrated liblua in to the game engine and can now embed scripts directly (the engine incorporated the lua parser so it can run lua scripts in the engine!)
  • OpenAL - Really, when it comes to sound, it becomes excessively problematic dealing with the tons of options out there; many of which are platform specific.  OpenAL was kind of the only sane way of dealing with audio output in a cross-platform setup.  I attempted to write my own audio mixer and all that, got pretty far, but then I realized I needed more than just mixing, I would need to somehow talk to the sound driver(s) on each target platform as well -- way over my head and just too much to learn and do well. 
  • libpng - This one is a granddaddy library that fuels a surprising number of applications out there, may as well adopt it!  What can I say, it let's us load up PNG files and extract the much-needed RGB data from them.  It took a little while to learn how to interact with the API, but eventually I got it - perhaps I'll make an article just for this someday.  At the end of the day, this is a fantastic library to integrate with a game engine.
  • zlib - Similar to libpng, zlib is almost everywhere on the planet.  It's in your smartphones, in your computer, and in almost every application and Operating System out there!  In fact, I'd be surprised if you haven't interacted with something zlib related, even today!  It deals with compression of data files and data streams.  As well, of course, with inflating data from compressed states -- something insanely useful.
  • btrxml - An XML parser I wrote with a constrained memory footprint in mind while retaining cross-platform capabilities.  I open sourced it under the zlib license so other people can use it for whatever they want (permissable with the license, of course).  Originally this was going to be part of the game engine itself after I looked in to other XML parsers, but at the end of the day, I opened it up and generalized it in to its own project!
That's it!

Using the libraries mentioned above, combined with the other engine code, everything I can do is made possible.  There may be some additional libraries to consider in the future.  I've dabbled with a couple 3d data libraries like lib3ds and things like that to help with handling 3d data (models, animation, etc), but I haven't quite figured out how I want to handle many things yet with that aspect.  Plus, for now, my engine really only caters to 2d games.  It does have super basic support for 3d things, can even render cubes, spheres, etc, but anything beyond that is no go yet.

Speaking of new libraries to consider, I think the next library to incorporate is likely ffmpeg or some of its dependency libraries to help with audio/video playback in a cross-platform manner.



No comments:

Post a Comment