Game Engine written in C++ and OpenGL.
Up to this point, my journey of game development has been mostly non-technical flash games. I’ve worked with some brilliant programmers 1 who inspired me to get a deeper understanding of computer science, maths, and game engines.
What better way to do it than to build your own game engine!
Books
Some of the great books I’ve read to get started.
The Engine
The engine code ended up being a collection of sub-systems scattered across multiple repositories. It wasn’t really usable in any meaningful capacity but it was a definitely great learning experience.
Code Example
// Foundation
class Application
{
IMachine* _machine;
Game* _game;
EventBus* _eventBus;
ScriptManager* _scriptManager;
ResourceCache* _resourceCache;
Window* _window;
Driver* _driver;
Renderer* _renderer;
}
// Initialization
if(!_machine->isOnlyInstance()){ /*throw error*/ }
// Requirements
const DWORDLONG CPU = 1.5 * GIGAHERTZ;
const DWORDLONG RAM = 512 * MEGABYTE;
const DWORDLONG HDD = 50 * MEGABYTE;
if(_machine->getCycles() < CPU){ /*throw error*/ }
if(_machine->getMemory() < RAM){ /*throw error*/ }
if(_machine->getStorage() < HDD){ /*throw error*/ }
// Asset Loading & Cache
ResourceZipFile* zipFile = new ResourceZipFile("assets.zip");
_resourceCache = new ResourceCache(50 * MEGABYTE, zipFile);
// Main loop
void loop()
{
while(_window->isOpen())
{
if(_game)
{
_eventBus->update(20);
_socketManager->select(0);
_game->update(dt);
}
}
};
Sub-Systems
- OpenGL Renderer
- Asset Management
- Memory Cache System
- Scene Management
- Networking System
- Game Event Queue
- Scripting Layer (LUA)
OpenGL
Graphical aspects of the engine took the majority of my attention, and it turned out to be one of my favorite topics. Down the line, I’ve built a software renderer to get a deeper understand of the concepts.
There was a lot here:
- Loading models and textures
- Instancing Models & Assets
- Matrix & Quaternion Transformations
- 3D Animations
- Programs & Shaders
- Sky Boxes
Shaders
UI & Inspection
I remember implementing UI and inspector visualization was particularly cumbersome. Everything was defined in code, so you only see the results once you build and run the program.
Networking
The engine assumed that all events would either be a request or a response. When implemented this way a single-player game could easily be turned into a multiplayer game. The network manager subscribes to the same gameplay events and transmits them across the net. The rest of the systems, don’t know and don’t care where the event came from – works like a charm!
Gameplay
When it came to building an actual game, it all kind of just fell apart. The project was focused so heavily on the technical aspects that building a production-ready game with it felt like a massive chore. Most game engines are built with a game side by side.
This was also a moment where I realized my ability as a game designer was lacking. After this project, I’ve spent a lot of time learning how to design games, and I have concluded that the technicals of a product are not nearly as important as the product itself.
Takeaways
- Build a game engine if you want to learn how game engines work.
- If you want to make games, just use an existing game engine.