Files
IAEngine/Engine/Src/Imp/CPP/Engine.cpp
Isuru Samarathunga 5408f07e97 Engine Interface
2025-10-04 02:21:36 +05:30

127 lines
3.2 KiB
C++

// IAEngine: 2D Game Engine by IA
// Copyright (C) 2025 IASoft (PVT) LTD (oss@iasoft.dev)
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
#include <Engine.hpp>
#include <IAEngine/Engine.hpp>
#include <SDL3/SDL.h>
#include <IAEngine/EngineInterface.hpp>
GameFunctionTable g_gameFunctions{};
namespace ia::iae
{
String GetStringVersion(IN UINT64 version)
{
return "";
}
VOID __Internal_Engine::Initialize()
{
IAE_LOG_INFO("Booting IAEngine for ", g_gameFunctions.GetName());
SDL_SetAppMetadata(g_gameFunctions.GetName(), GetStringVersion(g_gameFunctions.GetVersion()).c_str(),
g_gameFunctions.GetPackageName());
g_gameFunctions.OnInitialize();
}
VOID __Internal_Engine::Terminate()
{
g_gameFunctions.OnTerminate();
IAE_LOG_INFO("Shutting down IAEngine");
}
VOID __Internal_Engine::Iterate()
{
}
VOID __Internal_Engine::ProcessEvent(IN SDL_Event *event)
{
switch (event->type)
{
case SDL_EVENT_WINDOW_RESIZED:
break;
}
}
} // namespace ia::iae
namespace ia::iae
{
}
BOOL ValidateGameFunctionTable(IN GameFunctionTable gameFunctionTable)
{
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 ia::BOOL IAEngine_OnInitialize(IN GameFunctionTable gameFunctionTable))
{
if (!ValidateGameFunctionTable(gameFunctionTable))
{
IAE_LOG_ERROR("Invalid game function table was passed to the engine. Exiting..");
return false;
}
g_gameFunctions = gameFunctionTable;
__Internal_Engine::Initialize();
return true;
}
C_DECL(IAE_DLL_API ia::VOID IAEngine_OnTerminate())
{
__Internal_Engine::Terminate();
}
C_DECL(IAE_DLL_API ia::BOOL IAEngine_OnIterate())
{
__Internal_Engine::Iterate();
return true;
}
C_DECL(IAE_DLL_API ia::VOID IAEngine_OnEvent(IN PVOID event))
{
__Internal_Engine::ProcessEvent((SDL_Event *) event);
}