Sep 20

GAME-ENGINE: getting started

GAME-ENGINE: getting started

Hi there,
as learning project I decided to create a simple game engine. Let me explain, I am not crazy or mad, what I am trying to do is, hopefully, a subset of a game engine, starting as small as possible and then build on top of that.

The first goal I have is to have a 2D sprite jumping around the screen in a Mario style. Which is not that hard if you hardcode your way out of it putting everything in a rigid loop etc, doing it by trying to have a basic pipeline running is a hole another story. Here I will try to explain what I designed and trying to build. Most likely a game developer will see this and have an hart attack, but I will try to have not a uber terrible bunch of code.

Here is how I see a basic game loop happening:



Let me try to explain it.
We have the event loop which has a standard series of call. First we process the inputs, to know what has been pressed. Next step is to update the game state, right now I am only updating the position of the game objects.
The game object is assembled with components, one components is in charge to update it’s position, by swapping the component I can change the wanted behaviour.  For example a component can read the user input and update accordingly, another type of component might be controlled from AI or just replay older user inputs etc. The input class is also quite useful to abstract away the windowing system, in this way hopefully if  the windowing library needs to be changed wont be super painful. Last step would be resolving collisions but that part is being designed right now, probably I will write a post about it in the future.

Next is the rendering step, before this step (or even before world update) we can build a subset of entity to render, again there are different rendering components in charge of different type of rendering, more about it later.

Here a scheme more focused on rendering:

Rendering pipeline

This is an old picture of the design (pre components) but should still give an idea.
The renderer is nothing more then a container grouping together a glsl_program with the shaders, a camera pointer and a series of resources to render. You register to a renderer a resource you wish to render, this can be for example built on the fly after a camera frustum culling pass.

A resource is called GameEntity,  which again is noting more then a container of different other resources, in the latest iteration it is filled with components,  a move , collision and render component. Now the buffers and render data is encapsulated in the render components. Some resources are at entity level like the position or velocity, I will need to find the right balance between encapsulation and shared resources. All the resources should be allocated with custom allocators to avoid memory fragmentation and ensure memory locality.

This was a super quick run trough of the engine structure, surely will change a lot while working on it. It has been super exciting so far!

Here is what I got:



By no means this is a tutorial on how a game engine should be structured, this is just a report of a programmer trying to get into game development. For this reason comment or critique are more then welcome, anything that can make the “engine wanna be” better.


Leave a Reply