This commit is contained in:
Isuru Samarathunga
2025-10-10 13:30:29 +05:30
parent 96bad30f15
commit 8afe023901
471 changed files with 137902 additions and 210 deletions

View File

@ -27,13 +27,13 @@
#include <IAEngine/Engine.hpp>
#include <IAEngine/EngineLibraryInterface.hpp>
#include <backends/imgui_impl_sdl3.h>
#include <backends/imgui_impl_sdlgpu3.h>
GameFunctionTable g_gameFunctions{};
#include <IAEngine/imgui/backends/imgui_impl_sdl3.h>
#include <IAEngine/imgui/backends/imgui_impl_sdlgpu3.h>
namespace ia::iae
{
GameFunctionTable g_gameFunctions{};
SDL_Window *g_windowHandle;
VOID __Internal_Engine::Initialize()
@ -45,10 +45,11 @@ namespace ia::iae
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_GAMEPAD))
THROW_UNKNOWN("Failed to intialize SDL: ", SDL_GetError());
if (!(g_windowHandle = SDL_CreateWindow(g_gameFunctions.GetName(), config.ScreenWidth, config.ScreenHeight, SDL_WINDOW_RESIZABLE)))
if (!(g_windowHandle = SDL_CreateWindow(g_gameFunctions.GetName(), config.ScreenWidth, config.ScreenHeight,
SDL_WINDOW_RESIZABLE)))
THROW_UNKNOWN("Failed to create the SDL window: ", SDL_GetError());
//SDL_SetWindowResizable(g_windowHandle, false);
// SDL_SetWindowResizable(g_windowHandle, false);
const auto gameVersion = g_gameFunctions.GetVersion();
SDL_SetAppMetadata(g_gameFunctions.GetName(), BuildString(gameVersion).c_str(),
@ -118,59 +119,59 @@ namespace ia::iae
{
return (FLOAT32) m_value + ((FLOAT32) m_value * (Random::Get() * m_randomAdjustment) / 100.0f);
}
BOOL ValidateGameFunctionTable(IN GameFunctionTable gameFunctionTable)
{
if (!gameFunctionTable.GetConfigRequest)
return false;
if (!gameFunctionTable.OnInitialize)
return false;
if (!gameFunctionTable.OnTerminate)
return false;
if (!gameFunctionTable.OnDebugDraw)
return false;
if (!gameFunctionTable.OnFixedUpdate)
return false;
if (!gameFunctionTable.OnUpdate)
return false;
if (!gameFunctionTable.OnResize)
return false;
if (!gameFunctionTable.GetName)
return false;
if (!gameFunctionTable.GetVersion)
return false;
if (!gameFunctionTable.GetPackageName)
return false;
if (!gameFunctionTable.GetDeveloperName)
return false;
if (!gameFunctionTable.GetPublisherName)
return false;
return true;
}
INT32 Run(IN GameFunctionTable gameFunctionTable)
{
if (!ValidateGameFunctionTable(gameFunctionTable))
{
IAE_LOG_ERROR("Invalid game function table was passed to the engine. Exiting..");
return -1;
}
g_gameFunctions = gameFunctionTable;
__Internal_Engine::Initialize();
SDL_Event event{};
while (true)
{
SDL_PollEvent(&event);
if (event.type == SDL_EVENT_QUIT)
break;
__Internal_Engine::ProcessEvent(&event);
__Internal_Engine::Iterate();
}
__Internal_Engine::Terminate();
return 0;
}
} // namespace ia::iae
BOOL ValidateGameFunctionTable(IN GameFunctionTable gameFunctionTable)
{
if (!gameFunctionTable.GetConfigRequest)
return false;
if (!gameFunctionTable.OnInitialize)
return false;
if (!gameFunctionTable.OnTerminate)
return false;
if (!gameFunctionTable.OnDebugDraw)
return false;
if (!gameFunctionTable.OnFixedUpdate)
return false;
if (!gameFunctionTable.OnUpdate)
return false;
if (!gameFunctionTable.OnResize)
return false;
if (!gameFunctionTable.GetName)
return false;
if (!gameFunctionTable.GetVersion)
return false;
if (!gameFunctionTable.GetPackageName)
return false;
if (!gameFunctionTable.GetDeveloperName)
return false;
if (!gameFunctionTable.GetPublisherName)
return false;
return true;
}
C_DECL(IAE_DLL_API INT32 IAEngine_Run(IN GameFunctionTable gameFunctionTable))
{
if (!ValidateGameFunctionTable(gameFunctionTable))
{
IAE_LOG_ERROR("Invalid game function table was passed to the engine. Exiting..");
return -1;
}
g_gameFunctions = gameFunctionTable;
__Internal_Engine::Initialize();
SDL_Event event{};
while(true)
{
SDL_PollEvent(&event);
if (event.type == SDL_EVENT_QUIT)
break;
__Internal_Engine::ProcessEvent(&event);
__Internal_Engine::Iterate();
}
__Internal_Engine::Terminate();
return 0;
}