p0ly.com

📂 projects/chik/

Chik Game Engine

To preface this, I worked on this project primarily from 2022-2023.

When I was first learning to program in 2020, I decided to learn by programming a game engine from scratch. This game engine is the product of a lot of revisions since those initial lines of code I wrote years ago.

Thirty second history: I first started by using SDL's framebuffer to render 2D sprites of characters I designed. Then, I wanted the system to be more robust so I switched to Vulkan. Then, I got a friend who's interested in 3D rendering to assist in cleaning up my Vulkan implementation and soon, I had a basic game engine that could host a first-person shooter just fine. This engine was named Chocolate Engine, because I was eating chocolate when I created the repository.

Chocolate Engine grew to be very messy, and I wanted to do a big refactor, so I did exactly that, and named it Chik Engine. Instead of being in C++, I wrote it in C, to scrape as much performance as I can. I also like C's more simple syntax over C++'s OOP.

Chik Engine also didn't neccessarily begin as a direct refactor of Chocolate Engine, but instead as a software demo I made for a homemade software renderer.

The software renderer is really the star of the show, but I will detail the other features of Chik Engine at the end of this page.

I first started by using Bresenham Rasterization to draw triangles to the screen. Then, I multiplied their position vectors by a controllable translation matrix, and then by a perspective projection matrix I found online. Already, I had a simple first-person shooter, where you could float around a black void with a white triangle at the center. Then, I implemented perspective-corrected texture mapping, and the white triangle could now be a BMP file of your choice. The most pains-taking process was implementing culling, so that projected triangles behind the user's view frustum wouldn't render. This took a lot of trial and error, because the algorithm isn't exactly the most straightforward. Finally, I implemented simple point-lights to spice up the scenes.

And with just that, I had satisfied my urge to do everything from scratch to learn how everything works at its fundamentals. I felt so much joy working on this project, and moving around a non-anti-aliased scene gave me nostalgia of playing first-person shooters on weak video hardware in 2012.

Of course, to really call it a game engine, I implemented some other stuff: - A modular client/server based game loader - Game paths for loading content easily with lookup directories - A directional soundsystem - A robust platform-independent module system - A homemade scripting system named Kappa, which spiraled into its own project.

I'm thinking of taking a crack at refactoring this game engine once again, in Rust, as an application framework, rather than a library tailored for game development. It will support different backends for scripting systems and renderers, so that I can port my own implementations as fun experiments in creating actual programs, while also supporting standard libraries to maximize performance. College has kept me busy, and I've only made minimal effort in creating this Rust port.

Here is a link to the repository with all the code I wrote.

Below is a showcase of all the fun I had working on Chik: