
My 2D Game Engine
This is a project that was completed a long time ago. I am currently reviewing it and trying to create a brief and intuitive description.
C++ VS Project
Github Link: https://github.com/WatchPigs/My2DGameEngine
Introduction
This is a personal independent work of a simple 2D game engine.
It's based on ECS architecture and includes the following features and systems:
Game loop(with start-up and shutdown), Math(Vector/Matrix 2/3/4), Custom Smart Pointer, World, GameObject & Factory, Job System, Render System, Collision System, Physics System, etc..
ECS Architecture
-
The framework design of the engine follows the ECS architecture. Lightweight game objects only contain necessary information representing entities in the world.
-
The components(movable, renderable, and collideable) needed by game objects are not owned by game objects (but include pointers to the game objects they belong to) and are maintained in the containers. They contain the data needed for their features.
-
All systems implement the logic of their features, and they will process the data of the components they are concerned about.
Game loop(with start-up and shutdown)
This system provides a basic framework for the game:
-
A main game loop to update all subsystems (by calling Ticks).
-
Provide frame time by using the timing module.
-
Provide Bootstrapper for calling initializations and cleanups of all the subsystems
Math
This module provides basic math types and operations, such as vectors and matrices and their operations, as well as some commonly used operations (whether floats are equal, degree/radian conversion, etc.).
Some operations are accelerated using SIMD, such as using SSE intrinsics for inverse and multiplication of Matrix4.
Custom Smart Pointer
We need to create a mechanism to manage sharing data (such as a game object that may be referenced or maintained by multiple components or systems) to ensure that it is properly released and make no stale pointers when not in use.
Here, I created two kinds of pointers:
-
SmartPtr (like std::shared_ptr): All smart pointers pointing to the same data share a reference count. When a new smart pointer gains ownership of this data, the reference count increases by 1 (in the copy constructor or assignment operator). When the smart pointer goes away(destructed, out of scope), the reference count decreases by 1. When the reference count is 0, the resource will be properly released.
-
WeakPtr (like std::weak_ptr): While a smart pointer has shared ownership of the underlying object, a Weak Pointer can be considered a user or observer. Weak pointers won't affect the reference count of smart pointers and resource releases.
I'm still updating descriptions for the features down below; please come back and check them later.
Job System
GameObject & Factory
Render System
Physics System
Collision System