my game engine

under construction

Main source of info where Game Code Complete 4, Game Engine Architecture, Unity (as reference.. its pretty clear all sources end up somewhat like Unity in the end..*) and Hodgman posts on GameDev.net (for the render system).

* Its funny, I had the same feeling when I was building a physics engine, in the end, everything was derived from David Baraff. Today game engines pretty much end up like Unity.

The source can be find at github, here.

The idea was to build it alongside with a game (a start to end game), so that it would "YAGNI-ze" my engine. So I would stay focus on things that really makes difference, and the game would show it is working as it should. Mentle is that game - it had to be a simple game, so that I would actually finish things in small steps, and gradually improve, instead of getting in a never ending implementation.

The engine, as its current state, is a bunch of loose systems, there's no higher level linking the low-level systems together. This means that at now, it's users job to tie things together. The systems are: game, render, win, sound, net, sprite, text and gen. Each system is a namespace on the engine.

I purposely let custom memory management out of it, cause it was too much to build a game engine considering it, as both affect each other too much.. I did start using pools for the components, and I want to gradually start using other custom allocators for everything, mainly for the render. I avoided at all costs allocating memory at other places than initialization, so the only problem would be growing vectors.

The render system is based on a queue of drawing commands, where pipeline state changers (called Binders) are sorted to eliminate redundancy, before being submitted to D3D.

It has no concept of models, 2D or 3D, it only receive the commands paired with draw calls, those are called Drawables.

The sprite system is the one siting on top of the render, this one deals with "2D", holding the BindVertexShader command, BindInputLayout, a cache for texture binders, etc.. It takes a sprite component and optionally a camera, creates a drawable from it, and submits to the render queue. The text system sits on sprite, using its base pipeline binders, but have its own render methods for creating a list of drawables (at this exact moment, I'm adding instancing to the sprite render, so the text render will manage to create a single drawable for an entire text, instead of a drawable for each glyph, as it is now). Truth is the text render is really hackish at now, I'm not happy with it.

Text system also provides reading data from Gfig files, a text description file format I created. Its basic a truly readable XML ([rant] cause xml fails at being readable[/rant]).

The game system is responsible for 2 things: Sate control and game objects control.

States are exclusive (only one can be running), they are composed of layers (parallel, can have many), which is where lies the game objects.

Game objects are composed of components (transform, sprite, button..), the functionality of the components are implemented by systems, who works on component pools making the necessary updates.

Each component have factories that can create components from Gfigs.

The game system also provides an Event and a Task machine.

The Event machine job is distribute queued events to registered handlers (that are delegates).

The Task machine job is to run tasks: objects that executes an update function, with can terminate themselves, be terminated, and chain another task at termination. This is awesome for temporary tasks, avoiding that annoying mess of 'ifs' on the code that will be executed only at really specific moments

Win system handles windows management, messages, input.

Sound only provides basic functionality for loading, caching and playing waves. It is implemented using XAudio2, part of the DirectX SDK.

Net provides a P2P "connection" object, it uses UDP. This was really fun to implement. It provides sending of reliable and unreliable packets, but have no control of flux yet, it will always send packets at the same specified frequency.

Gen is where I put everything else, like tweening functions, delegate classes, etc..