ROUGE_2 : 01
Written on June 19th, 2024 by AsianMario
ROUGE_2 : 01
Continuing my revival of my game engine ROUGE_2 after using an ‘integrated’ game engine to create Open_Pong using OpenGL, ROUGE_2 is planned out to be a fully fleshed out game engine with working UI’s, Lighting, .fbx/.obj imports etc. For this article I am going to be delving into how I implemented several features in ROUGE_2 after revisiting and continuing this project.
Logging
Logging is essential, not only for bug fixing but also to keep track of event triggers which are crucial in making a game, I have decided to use spdlog which can be found in this repo. First, I prepared a new Log class and created two seperate logger entities, one for the CORE (Engine Side) and one for the CLIENT/USER (User Side / Editor in the future). Using spdlog makes it extremely easy to implement fast and efficient logging, although instead of using spdlog purely I integrated it into the ROUGE2 API by using macros, not only to make it easier to call log functions but also gives the engine a faster execution time when running the log system.
Macros:
//log macros - core
#define R2_CORE_LOG_FATAL(...) ::ROUGE2::Log::GetCoreLogger()->fatal(__VA_ARGS__)
#define R2_CORE_LOG_ERROR(...) ::ROUGE2::Log::GetCoreLogger()->error(__VA_ARGS__)
#define R2_CORE_LOG_WARN(...) ::ROUGE2::Log::GetCoreLogger()->warn(__VA_ARGS__)
#define R2_CORE_LOG_INFO(...) ::ROUGE2::Log::GetCoreLogger()->info(__VA_ARGS__)
#define R2_CORE_LOG_TRACE(...) ::ROUGE2::Log::GetCoreLogger()->trace(__VA_ARGS__)
//log macros - app
#define R2_FATAL(...) ::ROUGE2::Log::GetClientLogger()->fatal(__VA_ARGS__)
#define R2_ERROR(...) ::ROUGE2::Log::GetClientLogger()->error(__VA_ARGS__)
#define R2_WARN(...) ::ROUGE2::Log::GetClientLogger()->warn(__VA_ARGS__)
#define R2_INFO(...) ::ROUGE2::Log::GetClientLogger()->info(__VA_ARGS__)
#define R2_TRACE(...) ::ROUGE2::Log::GetClientLogger()->trace(__VA_ARGS__)
Testing:
ROUGE2::Log::Init();
R2_CORE_LOG_WARN("Initialized Logging");
int a = 2422;
R2_INFO("Logging Started Var={0}", a);
Premake
Recently, every instance where I had to re-build the engine it produces .dll’s in the .bin folder of the ROUGE2 engine directory but it does not directly update the .dll in the Sandbox directory, I decided to implement a build system using premake5 where I created a .lua file which allowed me to set include directories, copying files etc. for a VS2017 project (as I am using premake 5 alpha 15 it only supports VS2017 configurations at the latest).
Events
An event system is the absoloute backbone of any Game Engine as it determines actions taken by the user and actions taken in the application, I decided to create my own system event system which is currently using a ‘blocking’ method which means the game engine stops function until the event is handled, although its highly inefficient at the moment I am planning to use Buffers in the near future in order to handle events asynchronously for a much more superior performance.
In order to do this I first needed to create an “Event.h” header file where I could create different Event Type’s and Event Categories for identification, for the Event Category I created a bit shift method in Core.h in order to be able to assign multiple categories in one event, e.g EventCategoryKeyboard
and EventCategoryInput
.
enum class EventType {
None = 0,
WindowClose, WindowResize, WindowFocus, WindowLostFocus, WindowMoved,
AppTick, AppUpdate, AppRender,
KeyPressed, KeyReleased,
MouseButtonPressed, MouseButtonReleased, MouseMoved, MouseScrolled
};
enum EventCategory {
//category + BIT allows multiple category ammendment (see Core.h)
None = 0,
EventCategoryApplication = BIT(0),
EventCategoryInput = BIT(1),
EventCategoryKeyboard = BIT(2),
EventCategoryMouse = BIT(3),
EventCategoryMouseButton = BIT(4)
};
After creating Event Dispatchers and an Event Class with Category Flags, Event Names etc. I set up three other header files for Keyboard, Mouse and Application events, most of these are not notable except for the Keyboard events where I had to take in key repeat counts when a user presses a key for an extended period of time, additionally I used key codes from the system instead of defining every key myself which would be a waste of time.
Hopefully you’ve enjoyed this read and stay tuned for more progress.