From ff73221cae1e1c0ef08dcd68b5ff5f47d447b97a Mon Sep 17 00:00:00 2001 From: Isuru Samarathunga Date: Fri, 3 Oct 2025 21:20:05 +0530 Subject: [PATCH] Project Skeleton 1/2 --- .vscode/launch.json | 21 ++++++ CMakeLists.txt | 3 + Engine/CMakeLists.txt | 13 ++++ Engine/Src/Imp/CPP/Engine.cpp | 74 +++++++++++++++++++++ Engine/Src/Imp/HPP/Engine.hpp | 24 +++++++ Engine/Src/Inc/IAEngine/Base.hpp | 43 ++++++++++++ Engine/Src/Inc/IAEngine/Engine.hpp | 24 +++++++ Engine/Src/Inc/IAEngine/EngineInterface.hpp | 30 +++++++++ Engine/Src/Inc/IAEngine/GameInterface.hpp | 62 +++++++++++++++++ Runtime/Windows/CMakeLists.txt | 7 ++ Runtime/Windows/Src/Imp/CPP/Main.cpp | 61 +++++++++++++++++ Samples/CMakeLists.txt | 2 + Samples/SpaceInvaders/CMakeLists.txt | 11 +++ Samples/SpaceInvaders/Src/Imp/CPP/Game.cpp | 68 +++++++++++++++++++ Samples/SpaceInvaders/Src/Imp/HPP/Game.hpp | 20 ++++++ Vendor/IACore | 2 +- 16 files changed, 464 insertions(+), 1 deletion(-) create mode 100644 .vscode/launch.json create mode 100644 Engine/Src/Imp/CPP/Engine.cpp create mode 100644 Engine/Src/Imp/HPP/Engine.hpp create mode 100644 Engine/Src/Inc/IAEngine/Base.hpp create mode 100644 Engine/Src/Inc/IAEngine/Engine.hpp create mode 100644 Engine/Src/Inc/IAEngine/EngineInterface.hpp create mode 100644 Engine/Src/Inc/IAEngine/GameInterface.hpp create mode 100644 Runtime/Windows/Src/Imp/CPP/Main.cpp create mode 100644 Samples/CMakeLists.txt create mode 100644 Samples/SpaceInvaders/CMakeLists.txt create mode 100644 Samples/SpaceInvaders/Src/Imp/CPP/Game.cpp create mode 100644 Samples/SpaceInvaders/Src/Imp/HPP/Game.hpp diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..b048367 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,21 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [ + { + "name": "(Windows) Launch", + "type": "cppvsdbg", + "request": "launch", + "program": "${workspaceFolder}/build/bin/Debug/IAEngineRuntimeWin.exe", + "args": [], + "stopAtEntry": false, + "cwd": "${fileDirname}", + "environment": [], + "console": "externalTerminal", + "preLaunchTask": "CMake: build" + } + + ] +} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 8220c30..f7b221b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -25,4 +25,7 @@ add_subdirectory(Vendor/) add_subdirectory(Engine/) add_subdirectory(Runtime/) add_subdirectory(Editor/) + add_subdirectory(Tests/) + +add_subdirectory(Samples/) diff --git a/Engine/CMakeLists.txt b/Engine/CMakeLists.txt index e69de29..377182c 100644 --- a/Engine/CMakeLists.txt +++ b/Engine/CMakeLists.txt @@ -0,0 +1,13 @@ +set(SRC_FILES + "Src/Imp/CPP/Engine.cpp" +) + +add_library(IAEngine SHARED ${SRC_FILES}) + +target_compile_definitions(IAEngine PRIVATE "__BUILDING_IAENGINE=1") + +target_include_directories(IAEngine PUBLIC Src/Inc) +target_include_directories(IAEngine PRIVATE Src/Imp/HPP) + +target_link_libraries(IAEngine PUBLIC IACore ImGui glm::glm) +target_link_libraries(IAEngine PRIVATE SDL3::SDL3 SDL3_mixer::SDL3_mixer RmlUi::RmlUi) diff --git a/Engine/Src/Imp/CPP/Engine.cpp b/Engine/Src/Imp/CPP/Engine.cpp new file mode 100644 index 0000000..50e92e1 --- /dev/null +++ b/Engine/Src/Imp/CPP/Engine.cpp @@ -0,0 +1,74 @@ +// 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 . + +#include +#include + +GameFunctionTable g_gameFunctions{}; + +//SDL_SetAppMetadata("SDL Hello World Example", "1.0", "com.example.sdl-hello-world"); + +namespace ia::iae +{ + +} + +#include + +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; + + IAE_LOG_INFO("Booting IAEngine for ", gameFunctionTable.GetName()); + + return true; +} + +C_DECL(IAE_DLL_API ia::VOID IAEngine_OnTerminate()) +{ + IAE_LOG_INFO("Shutting down IAEngine"); +} + +C_DECL(IAE_DLL_API ia::BOOL IAEngine_OnIterate()) +{ + return true; +} + +C_DECL(IAE_DLL_API ia::VOID IAEngine_OnEvent(IN PVOID event)) +{ +} \ No newline at end of file diff --git a/Engine/Src/Imp/HPP/Engine.hpp b/Engine/Src/Imp/HPP/Engine.hpp new file mode 100644 index 0000000..27bf167 --- /dev/null +++ b/Engine/Src/Imp/HPP/Engine.hpp @@ -0,0 +1,24 @@ +// 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 . + +#pragma once + +#include + +namespace ia::iae +{ + +} \ No newline at end of file diff --git a/Engine/Src/Inc/IAEngine/Base.hpp b/Engine/Src/Inc/IAEngine/Base.hpp new file mode 100644 index 0000000..60724f2 --- /dev/null +++ b/Engine/Src/Inc/IAEngine/Base.hpp @@ -0,0 +1,43 @@ +// 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 . + +#pragma once + +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include + +#define IAE_LOG_TAG "[IAE]: " + +#define IAE_LOG_INFO(...) ia::Logger::Info(IAE_LOG_TAG, __VA_ARGS__) +#define IAE_LOG_WARN(...) ia::Logger::Warn(IAE_LOG_TAG, __VA_ARGS__) +#define IAE_LOG_ERROR(...) ia::Logger::Error(IAE_LOG_TAG, __VA_ARGS__) + +namespace ia::iae +{ + using Handle = INT64; + STATIC CONSTEXPR Handle INVALID_HANDLE = -1; +} // namespace ia::iae \ No newline at end of file diff --git a/Engine/Src/Inc/IAEngine/Engine.hpp b/Engine/Src/Inc/IAEngine/Engine.hpp new file mode 100644 index 0000000..27bf167 --- /dev/null +++ b/Engine/Src/Inc/IAEngine/Engine.hpp @@ -0,0 +1,24 @@ +// 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 . + +#pragma once + +#include + +namespace ia::iae +{ + +} \ No newline at end of file diff --git a/Engine/Src/Inc/IAEngine/EngineInterface.hpp b/Engine/Src/Inc/IAEngine/EngineInterface.hpp new file mode 100644 index 0000000..6713d34 --- /dev/null +++ b/Engine/Src/Inc/IAEngine/EngineInterface.hpp @@ -0,0 +1,30 @@ +// 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 . + +#pragma once + +#include + +#if defined(__BUILDING_IAENGINE) && (__BUILDING_IAENGINE) + #define IAE_DLL_API IA_DLL_EXPORT +#else + #define IAE_DLL_API IA_DLL_IMPORT +#endif + +C_DECL(IAE_DLL_API ia::BOOL IAEngine_OnInitialize(IN GameFunctionTable gameFunctionTable)); +C_DECL(IAE_DLL_API ia::VOID IAEngine_OnTerminate()); +C_DECL(IAE_DLL_API ia::BOOL IAEngine_OnIterate()); +C_DECL(IAE_DLL_API ia::VOID IAEngine_OnEvent(IN PVOID event)); diff --git a/Engine/Src/Inc/IAEngine/GameInterface.hpp b/Engine/Src/Inc/IAEngine/GameInterface.hpp new file mode 100644 index 0000000..8001ada --- /dev/null +++ b/Engine/Src/Inc/IAEngine/GameInterface.hpp @@ -0,0 +1,62 @@ +// 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 . + +#pragma once + +#include + +using namespace ia; +using namespace ia::iae; + +#if defined(__BUILDING_IAENGINE_GAME) && (__BUILDING_IAENGINE_GAME) + + #define GAME_LOG_TAG "[GAME]: " + #define GAME_LOG_INFO(...) ia::Logger::Info(IAE_LOG_TAG, __VA_ARGS__) + #define GAME_LOG_WARN(...) ia::Logger::Warn(IAE_LOG_TAG, __VA_ARGS__) + #define GAME_LOG_ERROR(...) ia::Logger::Error(IAE_LOG_TAG, __VA_ARGS__) + + C_DECL(IA_DLL_EXPORT VOID Game_OnInitialize()); + C_DECL(IA_DLL_EXPORT VOID Game_OnTerminate()); + C_DECL(IA_DLL_EXPORT VOID Game_OnDebugDraw()); + C_DECL(IA_DLL_EXPORT VOID Game_OnFixedUpdate()); + C_DECL(IA_DLL_EXPORT VOID Game_OnUpdate(IN FLOAT32 deltaTime)); + C_DECL(IA_DLL_EXPORT VOID Game_OnResize(IN INT32 newWidth, IN INT32 newHeight)); + C_DECL(IA_DLL_EXPORT PCCHAR Game_GetName()); + C_DECL(IA_DLL_EXPORT UINT64 Game_GetVersion()); + C_DECL(IA_DLL_EXPORT PCCHAR Game_GetPackageName()); + C_DECL(IA_DLL_EXPORT PCCHAR Game_GetDeveloperName()); + C_DECL(IA_DLL_EXPORT PCCHAR Game_GetPublisherName()); + +#else + + struct GameFunctionTable + { + VOID (*OnInitialize)() {nullptr}; + VOID (*OnTerminate)() {nullptr}; + VOID (*OnDebugDraw)() {nullptr}; + 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}; + }; + +#endif + diff --git a/Runtime/Windows/CMakeLists.txt b/Runtime/Windows/CMakeLists.txt index e69de29..9ac2cfa 100644 --- a/Runtime/Windows/CMakeLists.txt +++ b/Runtime/Windows/CMakeLists.txt @@ -0,0 +1,7 @@ +set(SRC_FILES + "Src/Imp/CPP/Main.cpp" +) + +add_executable(IAEngineRuntimeWin ${SRC_FILES}) + +target_link_libraries(IAEngineRuntimeWin PRIVATE IAEngine nlohmann_json SDL3::SDL3) diff --git a/Runtime/Windows/Src/Imp/CPP/Main.cpp b/Runtime/Windows/Src/Imp/CPP/Main.cpp new file mode 100644 index 0000000..ab4e3ab --- /dev/null +++ b/Runtime/Windows/Src/Imp/CPP/Main.cpp @@ -0,0 +1,61 @@ +#define WIN32_LEAN_AND_MEAN +#include + +#define SDL_MAIN_USE_CALLBACKS + +#include +#include + +#include + +SDL_AppResult SDL_AppIterate(void *appstate) +{ + IAEngine_OnIterate(); + return SDL_APP_CONTINUE; +} + +SDL_AppResult SDL_AppEvent(void *appstate, SDL_Event *event) +{ + switch (event->type) { + case SDL_EVENT_QUIT: + return SDL_APP_SUCCESS; + } + IAEngine_OnEvent(event); + return SDL_APP_CONTINUE; +} + +SDL_AppResult SDL_AppInit(void **appstate, int argc, char *argv[]) +{ + GameFunctionTable gameFunctionTable{}; + + const auto gameLib = LoadLibrary("Game.dll"); + if(!gameLib) + { + IAE_LOG_ERROR("Failed to load the dynamic library \"Game.dll\". Please make sure it exists."); + return SDL_APP_FAILURE; + } + + gameFunctionTable.OnInitialize = (VOID(*)())GetProcAddress(gameLib, "Game_OnInitialize"); + gameFunctionTable.OnTerminate = (VOID(*)())GetProcAddress(gameLib, "Game_OnTerminate"); + gameFunctionTable.OnDebugDraw = (VOID(*)())GetProcAddress(gameLib, "Game_OnDebugDraw"); + gameFunctionTable.OnFixedUpdate = (VOID(*)())GetProcAddress(gameLib, "Game_OnFixedUpdate"); + gameFunctionTable.OnUpdate = (VOID(*)(IN FLOAT32 deltaTime))GetProcAddress(gameLib, "Game_OnUpdate"); + gameFunctionTable.OnResize = (VOID(*)(IN INT32 newWidth, IN INT32 newHeight))GetProcAddress(gameLib, "Game_OnResize"); + + gameFunctionTable.GetName = (PCCHAR(*)())GetProcAddress(gameLib, "Game_GetName"); + gameFunctionTable.GetVersion = (UINT64(*)())GetProcAddress(gameLib, "Game_GetVersion"); + gameFunctionTable.GetPackageName = (PCCHAR(*)())GetProcAddress(gameLib, "Game_GetPackageName"); + gameFunctionTable.GetDeveloperName = (PCCHAR(*)())GetProcAddress(gameLib, "Game_GetDeveloperName"); + gameFunctionTable.GetPublisherName = (PCCHAR(*)())GetProcAddress(gameLib, "Game_GetPublisherName"); + + if(!IAEngine_OnInitialize(gameFunctionTable)) + return SDL_APP_FAILURE; + + return SDL_APP_CONTINUE; +} + +void SDL_AppQuit(void *appstate, SDL_AppResult result) +{ + IAEngine_OnTerminate(); + SDL_Quit(); +} \ No newline at end of file diff --git a/Samples/CMakeLists.txt b/Samples/CMakeLists.txt new file mode 100644 index 0000000..8d3998d --- /dev/null +++ b/Samples/CMakeLists.txt @@ -0,0 +1,2 @@ + +add_subdirectory(SpaceInvaders/) diff --git a/Samples/SpaceInvaders/CMakeLists.txt b/Samples/SpaceInvaders/CMakeLists.txt new file mode 100644 index 0000000..bb99171 --- /dev/null +++ b/Samples/SpaceInvaders/CMakeLists.txt @@ -0,0 +1,11 @@ +set(SRC_FILES + "Src/Imp/CPP/Game.cpp" +) + +add_library(Game SHARED ${SRC_FILES}) + +target_compile_definitions(Game PRIVATE "__BUILDING_IAENGINE_GAME=1") + +target_include_directories(Game PRIVATE "Src/Imp/HPP") + +target_link_libraries(Game PUBLIC IAEngine) diff --git a/Samples/SpaceInvaders/Src/Imp/CPP/Game.cpp b/Samples/SpaceInvaders/Src/Imp/CPP/Game.cpp new file mode 100644 index 0000000..615f6f3 --- /dev/null +++ b/Samples/SpaceInvaders/Src/Imp/CPP/Game.cpp @@ -0,0 +1,68 @@ +// 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 . + +#include + +C_DECL(IA_DLL_EXPORT VOID Game_OnInitialize()) +{ + GAME_LOG_INFO("Booting Game"); +} + +C_DECL(IA_DLL_EXPORT VOID Game_OnTerminate()) +{ + GAME_LOG_INFO("Shutting down Game"); +} + +C_DECL(IA_DLL_EXPORT VOID Game_OnDebugDraw()) +{ +} + +C_DECL(IA_DLL_EXPORT VOID Game_OnFixedUpdate()) +{ +} + +C_DECL(IA_DLL_EXPORT VOID Game_OnUpdate(IN FLOAT32 deltaTime)) +{ +} + +C_DECL(IA_DLL_EXPORT VOID Game_OnResize(IN INT32 newWidth, IN INT32 newHeight)) +{ +} + +C_DECL(IA_DLL_EXPORT PCCHAR Game_GetName()) +{ + return "Space Invaders"; +} + +C_DECL(IA_DLL_EXPORT UINT64 Game_GetVersion()) +{ + return IA_MAKE_VERSION(1, 0, 0); +} + +C_DECL(IA_DLL_EXPORT PCCHAR Game_GetPackageName()) +{ + return "com.iasoft.iaenginesamples.spaceinvaders"; +} + +C_DECL(IA_DLL_EXPORT PCCHAR Game_GetDeveloperName()) +{ + return "IASoft (PVT) LTD"; +} + +C_DECL(IA_DLL_EXPORT PCCHAR Game_GetPublisherName()) +{ + return "IASoft (PVT) LTD"; +} diff --git a/Samples/SpaceInvaders/Src/Imp/HPP/Game.hpp b/Samples/SpaceInvaders/Src/Imp/HPP/Game.hpp new file mode 100644 index 0000000..b87c3f4 --- /dev/null +++ b/Samples/SpaceInvaders/Src/Imp/HPP/Game.hpp @@ -0,0 +1,20 @@ +// 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 . + +#pragma once + +#include + diff --git a/Vendor/IACore b/Vendor/IACore index 0fd33d9..b38dc22 160000 --- a/Vendor/IACore +++ b/Vendor/IACore @@ -1 +1 @@ -Subproject commit 0fd33d958e626a605d5d8629329383fda45b380c +Subproject commit b38dc220be3948778e3c9233a42da5269aa02600