From 35ecd108ab415400183b4a25732a4ed5ce19d92e Mon Sep 17 00:00:00 2001 From: Isuru Samarathunga Date: Sun, 12 Oct 2025 23:03:39 +0530 Subject: [PATCH] Android Fixes --- Engine/Src/Imp/CPP/Engine.cpp | 21 +++++++++++++++++-- Engine/Src/Imp/CPP/InternalEngine.cpp | 4 +++- Engine/Src/Inc/IAEngine/Engine.hpp | 1 + .../Inc/IAEngine/EngineLibraryInterface.hpp | 4 ++-- Engine/Src/Inc/IAEngine/Nodes/Node2D.hpp | 4 ++-- 5 files changed, 27 insertions(+), 7 deletions(-) diff --git a/Engine/Src/Imp/CPP/Engine.cpp b/Engine/Src/Imp/CPP/Engine.cpp index 5e62547..a508d64 100644 --- a/Engine/Src/Imp/CPP/Engine.cpp +++ b/Engine/Src/Imp/CPP/Engine.cpp @@ -22,6 +22,8 @@ #include +#include + namespace ia::iae { EXTERN SDL_Window *g_windowHandle; @@ -36,10 +38,25 @@ namespace ia::iae #endif } + Vector Engine::ReadBinaryAsset(IN CONST String &path) + { + SDL_IOStream* f = SDL_IOFromFile(path.c_str(), "rb"); + if(!f) + THROW_FILE_OPEN_READ(path); + Vector result; + SDL_SeekIO(f, 0, SDL_IO_SEEK_END); + result.resize(SDL_TellIO(f)); + SDL_SeekIO(f, 0, SDL_IO_SEEK_SET); + SDL_ReadIO(f, result.data(), result.size()); + SDL_CloseIO(f); + return result; + } + Direction Engine::GetVectorPointingDirection(IN Vec2 v) { - STATIC CONSTEXPR Direction DIRECTION_MAP[] = {Direction::RIGHT, Direction::DOWN_RIGHT, Direction::DOWN, Direction::DOWN_LEFT, - Direction::LEFT, Direction::UP_LEFT, Direction::UP, Direction::UP_RIGHT}; + STATIC CONSTEXPR Direction DIRECTION_MAP[] = {Direction::RIGHT, Direction::DOWN_RIGHT, Direction::DOWN, + Direction::DOWN_LEFT, Direction::LEFT, Direction::UP_LEFT, + Direction::UP, Direction::UP_RIGHT}; if ((abs(v.x) <= FLOAT32_EPSILON) && (abs(v.y) <= FLOAT32_EPSILON)) return Direction::NONE; diff --git a/Engine/Src/Imp/CPP/InternalEngine.cpp b/Engine/Src/Imp/CPP/InternalEngine.cpp index b11f2b9..827df71 100644 --- a/Engine/Src/Imp/CPP/InternalEngine.cpp +++ b/Engine/Src/Imp/CPP/InternalEngine.cpp @@ -47,10 +47,12 @@ namespace ia::iae IAE_LOG_INFO("Booting IAEngine for ", g_gameName); + SDL_SetHint(SDL_HINT_ORIENTATIONS, "LandscapeRight"); + 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_gameName.c_str(), config.ScreenWidth, config.ScreenHeight, + if (!(g_windowHandle = SDL_CreateWindow(g_gameName.c_str(), config->ScreenWidth, config->ScreenHeight, SDL_WINDOW_RESIZABLE))) THROW_UNKNOWN("Failed to create the SDL window: ", SDL_GetError()); diff --git a/Engine/Src/Inc/IAEngine/Engine.hpp b/Engine/Src/Inc/IAEngine/Engine.hpp index 7a2c157..a6e6543 100644 --- a/Engine/Src/Inc/IAEngine/Engine.hpp +++ b/Engine/Src/Inc/IAEngine/Engine.hpp @@ -119,6 +119,7 @@ namespace ia::iae // Utility Functions STATIC Direction GetVectorPointingDirection(IN Vec2 v); + STATIC Vector ReadBinaryAsset(IN CONST String& path); // Random Functions STATIC FLOAT32 GetRandomFloat(); diff --git a/Engine/Src/Inc/IAEngine/EngineLibraryInterface.hpp b/Engine/Src/Inc/IAEngine/EngineLibraryInterface.hpp index c621429..933c5c7 100644 --- a/Engine/Src/Inc/IAEngine/EngineLibraryInterface.hpp +++ b/Engine/Src/Inc/IAEngine/EngineLibraryInterface.hpp @@ -27,7 +27,7 @@ struct GameRequestedConfig INT32 ScreenHeight{}; }; -C_DECL(GameRequestedConfig Game_GetConfigRequest()); +C_DECL(GameRequestedConfig* Game_GetConfigRequest()); C_DECL(VOID Game_OnInitialize()); C_DECL(VOID Game_OnTerminate()); C_DECL(VOID Game_OnDebugDraw()); @@ -41,7 +41,7 @@ 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)); } +#define IAENGINE_RUN(name, packageName, developerName, publisherName, versionMajor, versionMinor, versionPatch) extern "C" 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 diff --git a/Engine/Src/Inc/IAEngine/Nodes/Node2D.hpp b/Engine/Src/Inc/IAEngine/Nodes/Node2D.hpp index 1ac792a..1fd18dd 100644 --- a/Engine/Src/Inc/IAEngine/Nodes/Node2D.hpp +++ b/Engine/Src/Inc/IAEngine/Nodes/Node2D.hpp @@ -39,7 +39,7 @@ namespace ia::iae { for (auto &c : m_components) { - _component_type *comp = dynamic_cast<_component_type *>(c.get()); + _component_type *comp = dynamic_cast<_component_type *>(c); if (comp) return comp; } @@ -51,7 +51,7 @@ namespace ia::iae Vector<_component_type *> result; for (auto &c : m_components) { - _component_type *comp = dynamic_cast<_component_type *>(c.get()); + _component_type *comp = dynamic_cast<_component_type *>(c); if (comp) result.pushBack(comp); }