SAMURAI ENGINE
An Lightweight, Highly Customizable Game Engine
SAMURAI ENGINE
-
SAMURAI ENGINE is a light weight, highly customizable game engine written purely in C++ and allows for the creation of 2D games.
- Theroetically, the engine is designed to be able to run any 2D game written with SDL2 renderer and most of the game renderer is written in OpenGL3.3 or higher version.
- The engine supports hot reloading of gameplay logic with optimized compile time, allows for actively change logic of game while running. Faster prototyping than using scriptable languages, such as Lua and python.
- The engine is designed to be able to run on Windows.
- 3 scenes are made as demos to show the feature of the engine.
Features
-
[☑] Multi Renderer Support: The engine supports both SDL2 and OpenGL3.3 renderer.
- [☑] High Compatibility: The engine is designed to be able to run any 2D game written with SDL2 renderer.
- [☑] Hot Reloading: The engine supports hot reloading of gameplay logic with optimized compile time.
- [☑] Asset Management: The engine is implemented with a asset manage system.
- [☑] Gui-based Editor: Using ImGui to create a simple editor.
- [☑] Scene Editor: Scene editor is implemented and allow user to create scene with Gui while running to play the game in real time.
- [☑] Data Driven: The engine is designed to be data driven. Everthing is loaded on the fly.
- [☑] Multi-Game Instance: Allows user to run multiple game instance at the same time.
- [☑] Short Cut Customizable: Allows user to configure the short cut of the engine.
- [☑] Memory Consumption Demo: Real time memory consumption is shown in the engine.
Prerequisites
- SDL2: Simple Direct Media Layer is a cross-platform development library.
- glad: OpenGL loader
- gl2d: simple 2D rendering library made with OpenGL
- glm: header only C++ mathematics library for graphics software based on the OpenGL Shading Language (GLSL) specifications.
- ImGui: Bloat-free Immediate Mode Graphical User interface for C++ with minimal dependencies
- glfw: A multi-platform library for OpenGL, OpenGL ES, Vulkan, window and input
- stb: single-file public domain libraries for C/C++
Luckily you only need to download the sdl2 and cmake needs to find config files of sdl2 to build. Other libraries are included in the project.
How To Build
- Build By CMake
cmake -S . -B build # Only Support Windows right nowHow To Run
-
Run the engine with OpenGL renderer :
-
In core/CoreConfig.h, set the SAMURAI_SDL to 0
- Open Visual Studio and build the project.
- set the startup project to [core] and build the project.
- build the project [gameplay].
- go to the build directory and run the engine.
-
-
Run the engine with SDL2 renderer :
-
In core/CoreConfig.h, set the SAMURAI_SDL to 1
-
Repeat the steps above.
-
Important: Make sure all compiled .dll file is in the std::filesystem::path::current_path() directory.
DEMO
Demo of the engine is shown in the video below:
CITES AND CREDITS
- ChatGPT : I made a good friend with ChatGPT while developing the engine. It helped me a lot when I was stuck in the development.
- Cherno’s Game Engine Series : The engine is inspired by Cherno’s Game Engine Series, I followed his series to build the core of the engine. I have to say I learned a lot from his series. The ImGui editor part and hot reloading part is referenced from his series.
- Mike Shah’s Game Engine Series : The Data Driven design of the engine is inspired by Mike Shah’s Game Engine Series while reuse the code from his course.
- CS107 Stanford : The memory allocator part in cpp is inspired by CS107 Stanford. And I reused my code from the final assignment I submitted of CS107.
-
Low Level Learning C++ Series : The memory allocator part in cpp is inspired by Low Level Learning C++ Series.
- OpenGL Tutorial : The OpenGL part of the engine is inspired by OpenGL Tutorial.
- ImGui and SDL2 Setup Tutorial: The ImGui and SDL2 setup part is learned and applied with this tutorial.
Repository
Repository: CLICK HERE AND I TAKE YOU TO THE RABBIT HOLE
Engine Structure
Project Documentation
Documentation is generated by Doxygen
Project Hieararchy
Engine Directory Organization
- Docs
- Source Code Documentation
- Resources
- Art assets (With the Sub directories music, sound, images, and anything else)
- Editor
- ImGui Editor
- Gameplay
- Game Logic
- Runtime
- Controller during the runtime and solely for editor
- Shared
- Controller and renderer shared between editor and gameplay
- ThirdParty
- Code that you have not written if any.
Post Mortem
TODO: SDL_INPUT: SDL_Event is a poll event system while the glfw is using the callback event system. This two system’s difference lead to the reflection of keyboard is hard when switch the compile mode manually. The reflection of keyboard is not working well when using the SDL renderer and compile.
TODO: 3D_Renderer capability is not implemented. In future, I could using the Vulkan realtime ray tracing renderer I made before to implement into the engine.
TODO: Cotainer information refactor, right now I made two custom class that could create so called static string in the container to ensure the information won’t be lose when I close the container window or reload the .dll file. Maybe I could use another way to refactor the code inorder to simplify the code.
