How do I organize my game?
At a high level, I organize my game’s Python packages according to CCP (Common Closure Principle) - I put classes that will change together in the same package (or module, if they are very related). I then apply REP (Reuse/Release Equivalence Principle) to make sure that all the classes in the package will be re-used together (i.e, they are related in some manner).
For example, in my primary Panda project, OpenBlox (I have multiple Panda projects), my custom VFS and asynchronous frameworks each get their own packages, and utilities related to each framework go in that framework’s respective package. If the utility is not used by my project’s core engine (i.e, it is meant to be used by users), it goes in a plugin.
In general, my engine is organized into the following subsystems:
- VFS subsystem
- Asynchronous subsystem
- Plugin subsystem
- Lua scripting subsystem
- Configuration subsystem
Each subsystem works independently of the others. To get game-specific features (in OpenBlox’s case, Lego bricks), plugins are used. Plugins are a great way to abstract away various parts of your game (even my engine’s interface to Panda is a collection of plugins); because OpenBlox’s core is so resuable, I’m able to use most of its code for other projects I have.
What classes do you have and how do they interact?
I have 1 class for each single feature I need. For example, in OpenBlox (again, my primary Panda project), there are Lua scripts that can be run, and be put on the scene graph. That’s two separate features, and thus they each have separate classes to handle them: LuaEngine for the script runner, and LuaElement for the scene graph element. In general, OpenBlox classes interact on a per-instance basis; there are no globals, save for the plugin manager, which I’m refactoring. This not only makes them easier to test in isolation, it makes them easy to pull out and reuse with other projects.
How would you wish Panda to behave?
- I wish Panda were more plugin-oriented; this would make it both easier to extend and modify
- I wish Panda did away with all (or at least most) of its globals; it’s very hard to run unit tests on the parts of my code that uses Panda
- I wish ShowBase was broken up into several (non-global) classes, like RenderWindow (which would give a drawing surface to render on), ModelLoader, and so on. This would also make code easier to test
- I wish Panda’s Python interface conformed to PEP8; most of the Python libraries out there also follow PEP8, but this isn’t as important as the other things on my wishlist
Do you know of any engines behaving differently?
Crystal Space has a very plugin-oriented architecture, even more so than OpenBlox. Even the Crystal Space VFS is a plugin. Irrlicht uses a Singleton-based system, somewhat like Panda’s, but they hide their globals behind accessor functions. I don’t know what OGRE does.