Initiative Engine [WIP]

Go Back
Github

This game engine was made as a way for me to understand 3 topics that I am not familiar of. These topics are (1) How Entity Component Systems work under the hood, (2) How to use the Vulkan API in order to render 3D graphics in real-time, and (3) to understand how games implement multi-threading through job systems.


This project is still a work in progress. At the moment of writing, only the first and second topic have been explored.


Some of the notable features of this project are described below:

1. Archetype ECS Implementation

There are a number of approaches to Entity Component Systems. In my case, I decided to choose the Archetype ECS approach.


This approach was chosen because of the performance potential it offers since it enables components to be stored in contiguous data structures (such as std::vector) which then enables a programmer to access data in a way that reduces cache misses.


The archetype ECS approach is also much easier to multithread later on due to the fact that entities with the same components are grouped together into one archetype. This means that one thread can execute functionA on one archetype and another thread can execute that same function on another archetype. Because of the way that archetype store components, i.e in separate contiguous arrays, we can also by default avoid problems of false sharing.


The following are code snippets that represent the API created to use the ECS System:


1.1 Adding components


Test Image

In order to make the API easy to use, I decided to opt for the GameObject-Component Style where components can be added through a function call to the Entity in question.


1.2 Accessing components


Accessing components can be done by first creating a query and initializing it using a (variadic) templated function.


Test Image

This query can then be accessed through an iterator which contains the archetypes which then contain the entities that have the queried components.


(1) Iterating through the query to get the archetypes with the queried components


(2) The archetype can be accessed to get a specific component array


(3) The component can then be individually accessed through this component array.


Test Image

2. The Event System

The event system is based on the observer pattern. This event system can be used for communication between engine modules and/or communication between entities.


My implementation involves a templated Observer and a non templated Subject. The idea here is that a certain subject can raise any event through a templated function and only observers with that specific templated function will receive that event.


An example use is given below, where the event system is used to get input events from the window.


Test Image
Test Image