During my exchange semester at the IT-University of Copenhagen we’ve learned how to structure an engine and build it using different existing libraries like Box2D for the physics simulation. In the end we were asked to build a game. I’ve decided to go the harder way of additionally implementing a very simple but reusable engine with some neat features like automatic object management.
The destructible terrain was for sure the biggest challenge in this project:
Boost represents the terrain and the floating islands using a polygon and whenever explosions occur it is as simple as subtracting a circle representing the explosion from the polygons. Of course the the affected polygons need to update their physical and visual representation. Box2D can’t handle polygons with more than a static number of vertices (8 by default) so we switched to a b2Chain which worked perfectly.
Due to the fact that renderers always want triangles in the end, it was necessary to triangulate the polygons. But because our shapes are almost always concave and can become very complicated we couldn’t simply use a triangle fan or similar methods of triangulation. The choice was to use a constrained delaunay triangulation which worked like a charm.
In all the exercises we did during the semester the most annoying and error prone task was to not forget to unregister/delete the objects used by the game. To tackle this problem the engine contains an object manager that handles the creation and deleting as well as the registering and unregistering with the engine system (e.g. physics) when an object is instantiated or deleted. This is done using flags of the object and proved to work really well.
There were obviously a lot more components in the game and engine but the destructible terrain and the automatic object management were the most notable.