Fixes
This commit is contained in:
@ -24,7 +24,6 @@
|
|||||||
|
|
||||||
namespace ia::iae
|
namespace ia::iae
|
||||||
{
|
{
|
||||||
EXTERN GameFunctionTable g_gameFunctions;
|
|
||||||
EXTERN SDL_Window *g_windowHandle;
|
EXTERN SDL_Window *g_windowHandle;
|
||||||
SIZE_T g_resourceNameCounter = 1;
|
SIZE_T g_resourceNameCounter = 1;
|
||||||
|
|
||||||
@ -57,7 +56,7 @@ namespace ia::iae
|
|||||||
SDL_SetWindowSize(g_windowHandle, newWidth, newHeight);
|
SDL_SetWindowSize(g_windowHandle, newWidth, newHeight);
|
||||||
Renderer::OnScreenResize(newWidth, newHeight);
|
Renderer::OnScreenResize(newWidth, newHeight);
|
||||||
UI::OnScreenResize(newWidth, newHeight);
|
UI::OnScreenResize(newWidth, newHeight);
|
||||||
g_gameFunctions.OnResize(newWidth, newHeight);
|
Game_OnResize(newWidth, newHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
Handle Engine::CreateImageFromFile(IN CONST String &name, IN CONST String &path, IN INT32 resizeToWidth,
|
Handle Engine::CreateImageFromFile(IN CONST String &name, IN CONST String &path, IN INT32 resizeToWidth,
|
||||||
|
|||||||
@ -33,28 +33,32 @@
|
|||||||
|
|
||||||
namespace ia::iae
|
namespace ia::iae
|
||||||
{
|
{
|
||||||
GameFunctionTable g_gameFunctions{};
|
String g_gameName;
|
||||||
|
String g_gamePackageName;
|
||||||
|
String g_gameDeveloperName;
|
||||||
|
String g_gamePublisherName;
|
||||||
|
IA_VERSION_TYPE g_gameVersion{};
|
||||||
|
|
||||||
SDL_Window *g_windowHandle;
|
SDL_Window *g_windowHandle;
|
||||||
|
|
||||||
VOID __Internal_Engine::Initialize()
|
VOID __Internal_Engine::Initialize()
|
||||||
{
|
{
|
||||||
const auto config = g_gameFunctions.GetConfigRequest();
|
const auto config = Game_GetConfigRequest();
|
||||||
|
|
||||||
IAE_LOG_INFO("Booting IAEngine for ", g_gameFunctions.GetName());
|
IAE_LOG_INFO("Booting IAEngine for ", g_gameName);
|
||||||
|
|
||||||
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_GAMEPAD))
|
if (!SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO | SDL_INIT_GAMEPAD))
|
||||||
THROW_UNKNOWN("Failed to intialize SDL: ", SDL_GetError());
|
THROW_UNKNOWN("Failed to intialize SDL: ", SDL_GetError());
|
||||||
|
|
||||||
if (!(g_windowHandle = SDL_CreateWindow(g_gameFunctions.GetName(), config.ScreenWidth, config.ScreenHeight,
|
if (!(g_windowHandle = SDL_CreateWindow(g_gameName.c_str(), config.ScreenWidth, config.ScreenHeight,
|
||||||
SDL_WINDOW_RESIZABLE)))
|
SDL_WINDOW_RESIZABLE)))
|
||||||
THROW_UNKNOWN("Failed to create the SDL window: ", SDL_GetError());
|
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();
|
const auto gameVersion = g_gameVersion;
|
||||||
SDL_SetAppMetadata(g_gameFunctions.GetName(), BuildString(gameVersion).c_str(),
|
SDL_SetAppMetadata(g_gameName.c_str(), IA_STRINGIFY_VERSION(gameVersion).c_str(),
|
||||||
g_gameFunctions.GetPackageName());
|
g_gamePackageName.c_str());
|
||||||
|
|
||||||
Time::Initialize();
|
Time::Initialize();
|
||||||
Random::Initialize();
|
Random::Initialize();
|
||||||
@ -67,12 +71,12 @@ namespace ia::iae
|
|||||||
UI::Initialize();
|
UI::Initialize();
|
||||||
Physics::Initialize();
|
Physics::Initialize();
|
||||||
|
|
||||||
g_gameFunctions.OnInitialize();
|
Game_OnInitialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID __Internal_Engine::Terminate()
|
VOID __Internal_Engine::Terminate()
|
||||||
{
|
{
|
||||||
g_gameFunctions.OnTerminate();
|
Game_OnTerminate();
|
||||||
|
|
||||||
Physics::Terminate();
|
Physics::Terminate();
|
||||||
UI::Terminate();
|
UI::Terminate();
|
||||||
@ -96,8 +100,8 @@ namespace ia::iae
|
|||||||
Physics::Update();
|
Physics::Update();
|
||||||
WorldManager::Update();
|
WorldManager::Update();
|
||||||
WorldManager::FixedUpdate();
|
WorldManager::FixedUpdate();
|
||||||
g_gameFunctions.OnUpdate(Time::GetFrameDeltaTime());
|
Game_OnUpdate(Time::GetFrameDeltaTime());
|
||||||
g_gameFunctions.OnFixedUpdate();
|
Game_OnFixedUpdate();
|
||||||
|
|
||||||
Renderer::BeginFrame();
|
Renderer::BeginFrame();
|
||||||
WorldManager::Draw();
|
WorldManager::Draw();
|
||||||
@ -124,43 +128,13 @@ namespace ia::iae
|
|||||||
return (FLOAT32) m_value + ((FLOAT32) m_value * (Random::Get() * m_randomAdjustment) / 100.0f);
|
return (FLOAT32) m_value + ((FLOAT32) m_value * (Random::Get() * m_randomAdjustment) / 100.0f);
|
||||||
}
|
}
|
||||||
|
|
||||||
BOOL ValidateGameFunctionTable(IN GameFunctionTable gameFunctionTable)
|
INT32 Run(IN CONST String& name, IN CONST String& packageName, IN CONST String& developerName, IN CONST String& publisherName, IN IA_VERSION_TYPE version)
|
||||||
{
|
{
|
||||||
if (!gameFunctionTable.GetConfigRequest)
|
g_gameName = name;
|
||||||
return false;
|
g_gameVersion = version;
|
||||||
if (!gameFunctionTable.OnInitialize)
|
g_gamePackageName = packageName;
|
||||||
return false;
|
g_gameDeveloperName = developerName;
|
||||||
if (!gameFunctionTable.OnTerminate)
|
g_gamePublisherName = publisherName;
|
||||||
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();
|
__Internal_Engine::Initialize();
|
||||||
|
|
||||||
|
|||||||
@ -28,7 +28,6 @@
|
|||||||
|
|
||||||
namespace ia::iae
|
namespace ia::iae
|
||||||
{
|
{
|
||||||
EXTERN GameFunctionTable g_gameFunctions;
|
|
||||||
EXTERN SDL_Window *g_windowHandle;
|
EXTERN SDL_Window *g_windowHandle;
|
||||||
|
|
||||||
ImGuiIO g_imGUIIO{};
|
ImGuiIO g_imGUIIO{};
|
||||||
@ -72,7 +71,7 @@ namespace ia::iae
|
|||||||
|
|
||||||
Physics::DebugDraw();
|
Physics::DebugDraw();
|
||||||
WorldManager::DebugDraw();
|
WorldManager::DebugDraw();
|
||||||
g_gameFunctions.OnDebugDraw();
|
Game_OnDebugDraw();
|
||||||
|
|
||||||
ImGui::Render();
|
ImGui::Render();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -18,32 +18,30 @@
|
|||||||
|
|
||||||
#include <IAEngine/Engine.hpp>
|
#include <IAEngine/Engine.hpp>
|
||||||
|
|
||||||
namespace ia::iae
|
using namespace ia;
|
||||||
{
|
using namespace ia::iae;
|
||||||
|
|
||||||
struct GameRequestedConfig
|
struct GameRequestedConfig
|
||||||
{
|
{
|
||||||
INT32 ScreenWidth{};
|
INT32 ScreenWidth{};
|
||||||
INT32 ScreenHeight{};
|
INT32 ScreenHeight{};
|
||||||
};
|
};
|
||||||
|
|
||||||
struct GameFunctionTable
|
C_DECL(GameRequestedConfig Game_GetConfigRequest());
|
||||||
{
|
C_DECL(VOID Game_OnInitialize());
|
||||||
GameRequestedConfig (*GetConfigRequest)(){nullptr};
|
C_DECL(VOID Game_OnTerminate());
|
||||||
|
C_DECL(VOID Game_OnDebugDraw());
|
||||||
|
C_DECL(VOID Game_OnFixedUpdate());
|
||||||
|
C_DECL(VOID Game_OnUpdate(IN FLOAT32 deltaTime));
|
||||||
|
C_DECL(VOID Game_OnResize(IN INT32 newWidth, IN INT32 newHeight));
|
||||||
|
|
||||||
VOID (*OnInitialize)(){nullptr};
|
namespace ia::iae
|
||||||
VOID (*OnTerminate)(){nullptr};
|
{
|
||||||
VOID (*OnDebugDraw)(){nullptr};
|
INT32 Run(IN CONST String& name, IN CONST String& packageName, IN CONST String& developerName, IN CONST String& publisherName, IN IA_VERSION_TYPE version);
|
||||||
VOID (*OnFixedUpdate)(){nullptr};
|
|
||||||
VOID (*OnUpdate)(IN FLOAT32 deltaTime){nullptr};
|
|
||||||
VOID (*OnResize)(IN INT32 newWidth, IN INT32 newHeight){nullptr};
|
|
||||||
|
|
||||||
PCCHAR (*GetName)(){nullptr};
|
|
||||||
UINT64 (*GetVersion)(){nullptr};
|
|
||||||
PCCHAR (*GetPackageName)(){nullptr};
|
|
||||||
PCCHAR (*GetDeveloperName)(){nullptr};
|
|
||||||
PCCHAR (*GetPublisherName)(){nullptr};
|
|
||||||
};
|
|
||||||
|
|
||||||
INT32 Run(IN GameFunctionTable gameFunctionTable);
|
|
||||||
} // namespace ia::iae
|
} // namespace ia::iae
|
||||||
|
|
||||||
|
#if defined(__ANDROID__)
|
||||||
|
#define IAENGINE_RUN(name, packageName, developerName, publisherName, versionMajor, versionMinor, versionPatch) int SDL_main(int argc, char *argv[]) { return ia::iae::Run(name, packageName, developerName, publisherName, IA_MAKE_VERSION(versionMajor, versionMinor, versionPatch)); }
|
||||||
|
#else
|
||||||
|
#define IAENGINE_RUN(name, packageName, developerName, publisherName, versionMajor, versionMinor, versionPatch) int main(int argc, char *argv[]) { return ia::iae::Run(name, packageName, developerName, publisherName, IA_MAKE_VERSION(versionMajor, versionMinor, versionPatch)); }
|
||||||
|
#endif
|
||||||
|
|||||||
Reference in New Issue
Block a user