Friday, March 18, 2011

Context Creation, Input Management, Joysticks Done Right?

One of the most core thing any engine needs, or rather any program needs is a context. The Context is our interface to communicate visually and physically with our engine, also knonw as the window.  You would assume you could forget about it, only because it seems like such a simple thing.  I can assure you that you're incorrect.  Every operating system has it's own method to manage a window, the keyboard events, mouse events, mouse acceleration, etc etc.  But what are your options as a engine developer if you want to support an array of different operating systems?  Luckily for you there are libraries for this, the two most popular would be SDL  & SFML These are viable options but at some point you will be forced to implement a context for a system that these libraries do not support, perhaps HaikuOS or perhaps a game console.

So my advice as a engine developer is abstraction.  Instead of relying on a specific library like SDL, abstract it so a back-end replacement will be easy on your behalf to tie-in.  I started my personal engine project off with SFML due to its extreme simplicity, however due to lack of support for Direct3D I was forced to migrate over to SDL, which I can validate does allows both OpenGL and Direct3D contexts.

So today I made a bold decision to implement a context management wrapper so I can tie in additional implementations for things SDL does not support.  I had a workable wrapper in about two hours, and I found it so easy to use I decided to implement fall-back methods for X11 and Windows.  Perhaps I don't need it, but it's a good feature to support.  Some companies don't allow the use of SDL because of it's license, the Apple store is an example of this, now thanks to my wrapper and my own individual implementations any game created with my engine can be sold in the Apple store.

The best part is I can still support SDL internally and it will be invisible to anyone using my engine.  So in the sitation where someone does have SDL and would like to use it, it's there for their disposal, all the have to do is #define CONTEXT_SDL

No comments:

Post a Comment