From dd2d2e1ae8634444c65afd488ced9890ad6c6fce Mon Sep 17 00:00:00 2001 From: Isuru Samarathunga Date: Sat, 1 Nov 2025 01:23:31 +0530 Subject: [PATCH] Scripts: Srcgen --- CMakeLists.txt | 4 +- Resources/Fonts/Credits.txt | 1 + .../Fonts/{Roboto-Black.ttf => Roboto.ttf} | Bin Resources/Shaders/Geometry.frag | 26 ++++ Resources/Shaders/Geometry.vert | 26 ++++ Samples/CMakeLists.txt | 2 + Samples/RPG/CMakeLists.txt | 9 ++ Samples/RPG/Src/imp/cpp/Main.cpp | 6 + Src/IAEngine/CMakeLists.txt | 11 ++ Src/IAEngine/imp/cpp/IAEngine.cpp | 30 +++++ Src/IAEngine/inc/IAEngine/Base.hpp | 22 ++++ Src/IAEngine/inc/IAEngine/IAEngine.hpp | 31 +++++ Tools/Scripts/AddClass.py | 2 - Tools/Scripts/AddHeaderFile.py | 2 - Tools/Scripts/AddSourceFile.py | 2 - Tools/Scripts/Builder/Build.py | 26 ++++ Tools/Scripts/EmbedResources.py | 1 - Tools/Scripts/Srcgen/AddClass.py | 120 ++++++++++++++++++ Tools/Scripts/Srcgen/AddHeaderFile.py | 67 ++++++++++ Tools/Scripts/Srcgen/AddSourceFile.py | 59 +++++++++ Tools/Scripts/Srcgen/EmbedResources.py | 18 +++ 21 files changed, 456 insertions(+), 9 deletions(-) create mode 100644 Resources/Fonts/Credits.txt rename Resources/Fonts/{Roboto-Black.ttf => Roboto.ttf} (100%) create mode 100644 Resources/Shaders/Geometry.frag create mode 100644 Resources/Shaders/Geometry.vert create mode 100644 Samples/RPG/CMakeLists.txt create mode 100644 Samples/RPG/Src/imp/cpp/Main.cpp create mode 100644 Src/IAEngine/imp/cpp/IAEngine.cpp create mode 100644 Src/IAEngine/inc/IAEngine/Base.hpp create mode 100644 Src/IAEngine/inc/IAEngine/IAEngine.hpp delete mode 100644 Tools/Scripts/AddClass.py delete mode 100644 Tools/Scripts/AddHeaderFile.py delete mode 100644 Tools/Scripts/AddSourceFile.py create mode 100644 Tools/Scripts/Builder/Build.py delete mode 100644 Tools/Scripts/EmbedResources.py create mode 100644 Tools/Scripts/Srcgen/AddClass.py create mode 100644 Tools/Scripts/Srcgen/AddHeaderFile.py create mode 100644 Tools/Scripts/Srcgen/AddSourceFile.py create mode 100644 Tools/Scripts/Srcgen/EmbedResources.py diff --git a/CMakeLists.txt b/CMakeLists.txt index d0bebb1..568e5f8 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,11 +11,11 @@ project(IAEngine) if(CMAKE_BUILD_TYPE STREQUAL "Debug") message(STATUS "Configuring IAEngine for Debug..") - add_compile_options(-O0) + #add_compile_options(-O0) add_compile_definitions("__IA_DEBUG=1") elseif(CMAKE_BUILD_TYPE STREQUAL "Release") message(STATUS "Configuring IAEngine for Release..") - add_compile_options(-O3) + #add_compile_options(-O3) add_compile_definitions("__IA_DEBUG=0") else() message(FATAL_ERROR "Unknown CMAKE_BUILD_TYPE \"${CMAKE_BUILD_TYPE}\"") diff --git a/Resources/Fonts/Credits.txt b/Resources/Fonts/Credits.txt new file mode 100644 index 0000000..4ed8acb --- /dev/null +++ b/Resources/Fonts/Credits.txt @@ -0,0 +1 @@ +Roboto.ttf was downloaded from Google Fonts (Original Filename: Roboto-Black.ttf) diff --git a/Resources/Fonts/Roboto-Black.ttf b/Resources/Fonts/Roboto.ttf similarity index 100% rename from Resources/Fonts/Roboto-Black.ttf rename to Resources/Fonts/Roboto.ttf diff --git a/Resources/Shaders/Geometry.frag b/Resources/Shaders/Geometry.frag new file mode 100644 index 0000000..a6928f3 --- /dev/null +++ b/Resources/Shaders/Geometry.frag @@ -0,0 +1,26 @@ +#version 450 +#extension GL_ARB_separate_shader_objects : enable + +layout(location = 0) in vec2 inTexCoord; +layout(location = 1) in vec4 inVertexColor; + +layout(location = 0) out vec4 outColor; + +layout(set = 2, binding = 0) uniform sampler2D texSampler; +layout(set = 3, binding = 0) uniform UniformBufferObject { + bool flippedH; + bool flippedV; + vec2 uvOffset; + vec4 colorOverlay; +} ubo; + +void main() +{ + vec2 uv = inTexCoord; + uv += ubo.uvOffset; + if(ubo.flippedH) uv.x = 1.0 - uv.x; + if(ubo.flippedV) uv.y = 1.0 - uv.y; + outColor = texture(texSampler, uv) * inVertexColor * ubo.colorOverlay; + if(outColor.w < 0.1) + discard; +} \ No newline at end of file diff --git a/Resources/Shaders/Geometry.vert b/Resources/Shaders/Geometry.vert new file mode 100644 index 0000000..086ddd8 --- /dev/null +++ b/Resources/Shaders/Geometry.vert @@ -0,0 +1,26 @@ +#version 450 +#extension GL_ARB_separate_shader_objects : enable + +layout (location = 0) in vec2 inPosition; +layout (location = 1) in vec2 inTexCoord; +layout (location = 2) in vec4 inVertexColor; + +layout(location = 0) out vec2 outTexCoord; +layout(location = 1) out vec4 outVertexColor; + +layout(set = 1, binding = 0) uniform UBO_Vertex_PerScene { + mat4 projection; +} uboPerScene; +layout(set = 1, binding = 1) uniform UBO_Vertex_PerFrame { + mat4 view; +} uboPerFrame; +layout(set = 1, binding = 2) uniform UBO_Vertex_PerDraw { + mat4 model; +} uboPerDraw; + +void main() +{ + gl_Position = uboPerScene.projection * uboPerFrame.view * uboPerDraw.model * vec4(inPosition, 0.0f, 1.0f); + outTexCoord = inTexCoord; + outVertexColor = inVertexColor; +} \ No newline at end of file diff --git a/Samples/CMakeLists.txt b/Samples/CMakeLists.txt index e69de29..147929f 100644 --- a/Samples/CMakeLists.txt +++ b/Samples/CMakeLists.txt @@ -0,0 +1,2 @@ + +add_subdirectory(RPG/) diff --git a/Samples/RPG/CMakeLists.txt b/Samples/RPG/CMakeLists.txt new file mode 100644 index 0000000..6e3eafb --- /dev/null +++ b/Samples/RPG/CMakeLists.txt @@ -0,0 +1,9 @@ +set(SRC_FILES + "Src/imp/cpp/Main.cpp" +) + +add_executable(IAERPG ${SRC_FILES}) + +target_include_directories(IAERPG PRIVATE Src/imp/hpp) + +target_link_libraries(IAERPG PRIVATE IAEngine) diff --git a/Samples/RPG/Src/imp/cpp/Main.cpp b/Samples/RPG/Src/imp/cpp/Main.cpp new file mode 100644 index 0000000..283db6d --- /dev/null +++ b/Samples/RPG/Src/imp/cpp/Main.cpp @@ -0,0 +1,6 @@ + +int main(int agrc, char** argv) +{ + + return 0; +} \ No newline at end of file diff --git a/Src/IAEngine/CMakeLists.txt b/Src/IAEngine/CMakeLists.txt index e69de29..bede631 100644 --- a/Src/IAEngine/CMakeLists.txt +++ b/Src/IAEngine/CMakeLists.txt @@ -0,0 +1,11 @@ +set(SRC_FILES + "imp/cpp/IAEngine.cpp" +) + +add_library(IAEngine STATIC ${SRC_FILES}) + +target_include_directories(IAEngine PUBLIC inc) +target_include_directories(IAEngine PRIVATE imp/hpp) + +target_link_libraries(IAEngine PUBLIC IACore) +target_link_libraries(IAEngine PRIVATE ZLIB::ZLIBSTATIC SDL3::SDL3 SDL3_mixer::SDL3_mixer Freetype::Freetype) diff --git a/Src/IAEngine/imp/cpp/IAEngine.cpp b/Src/IAEngine/imp/cpp/IAEngine.cpp new file mode 100644 index 0000000..83c9cf6 --- /dev/null +++ b/Src/IAEngine/imp/cpp/IAEngine.cpp @@ -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 . + +#include + +namespace ia::iae +{ + IAEngine::IAEngine() + { + + } + + IAEngine::~IAEngine() + { + + } +} diff --git a/Src/IAEngine/inc/IAEngine/Base.hpp b/Src/IAEngine/inc/IAEngine/Base.hpp new file mode 100644 index 0000000..bdfd54a --- /dev/null +++ b/Src/IAEngine/inc/IAEngine/Base.hpp @@ -0,0 +1,22 @@ +// 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 + +namespace ia::iae +{ + +} diff --git a/Src/IAEngine/inc/IAEngine/IAEngine.hpp b/Src/IAEngine/inc/IAEngine/IAEngine.hpp new file mode 100644 index 0000000..2f7f176 --- /dev/null +++ b/Src/IAEngine/inc/IAEngine/IAEngine.hpp @@ -0,0 +1,31 @@ +// 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 +{ + class IAEngine + { + public: + IAEngine(); + ~IAEngine(); + + private: + }; +} diff --git a/Tools/Scripts/AddClass.py b/Tools/Scripts/AddClass.py deleted file mode 100644 index 50eb159..0000000 --- a/Tools/Scripts/AddClass.py +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/python3 - diff --git a/Tools/Scripts/AddHeaderFile.py b/Tools/Scripts/AddHeaderFile.py deleted file mode 100644 index 50eb159..0000000 --- a/Tools/Scripts/AddHeaderFile.py +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/python3 - diff --git a/Tools/Scripts/AddSourceFile.py b/Tools/Scripts/AddSourceFile.py deleted file mode 100644 index 50eb159..0000000 --- a/Tools/Scripts/AddSourceFile.py +++ /dev/null @@ -1,2 +0,0 @@ -#!/bin/python3 - diff --git a/Tools/Scripts/Builder/Build.py b/Tools/Scripts/Builder/Build.py new file mode 100644 index 0000000..8185f30 --- /dev/null +++ b/Tools/Scripts/Builder/Build.py @@ -0,0 +1,26 @@ +#!/bin/python3 + +# 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 . + +import os +import sys + +def main(args: list[str]): + os.system("cmake -S. -B./Build/Windows -DCMAKE_BUILD_TYPE=Debug -DBUILD_SAMPLES=ON") + os.system("cmake --build ./Build/Windows") + +main(sys.argv) \ No newline at end of file diff --git a/Tools/Scripts/EmbedResources.py b/Tools/Scripts/EmbedResources.py deleted file mode 100644 index d8dbf66..0000000 --- a/Tools/Scripts/EmbedResources.py +++ /dev/null @@ -1 +0,0 @@ -#!/bin/python3 diff --git a/Tools/Scripts/Srcgen/AddClass.py b/Tools/Scripts/Srcgen/AddClass.py new file mode 100644 index 0000000..9979bea --- /dev/null +++ b/Tools/Scripts/Srcgen/AddClass.py @@ -0,0 +1,120 @@ +#!/bin/python3 + +# 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 . + +import sys + +def get_header_file_content(className: str): + return f"""// 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 +{{ + class {className} + {{ + public: + {className}(); + ~{className}(); + + private: + }}; +}} +""" + +def get_source_file_content(className: str, headerPath: str): + return f"""// 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 <{headerPath}> + +namespace ia::iae +{{ + {className}::{className}() + {{ + + }} + + {className}::~{className}() + {{ + + }} +}} +""" + +def add_header_file(className: str, fileName: str, fileDirectory: str): + print(f"\033[32mAdding Header File '{fileName}' to '{fileDirectory}'..\033[39m") + with open(f"{fileDirectory}/{fileName}", 'w') as f: + f.write(get_header_file_content(className)) + +def add_source_file(className: str, headerPath: str, fileName: str, fileDirectory: str): + print(f"\033[32mAdding Source File '{fileName}' to '{fileDirectory}'..\033[39m") + with open(f"{fileDirectory}/{fileName}", 'w') as f: + f.write(get_source_file_content(className, headerPath)) + +def on_invalid_args(): + print(f"\033[33mUsage: {sys.argv[0]} \033[39m") + exit(1) + +def main(args: list[str]): + if (len(args) < 4) or ((args[2] != "PUBLIC") and (args[2] != "PRIVATE")): + on_invalid_args() + fileName = f"{args[3]}.hpp" + headerPath = "" + fileDirectory = "" + if args[2] == "PUBLIC": + headerPath = f"{args[1]}/{fileName}" + fileDirectory = f"Src/{args[1]}/inc/{args[1]}" + else: + headerPath = f"{fileName}" + fileDirectory = f"Src/{args[1]}/imp/hpp" + add_header_file(args[3], fileName, fileDirectory) + fileName = f"{args[3]}.cpp" + fileDirectory = f"Src/{args[1]}/imp/cpp" + add_source_file(args[3], headerPath, fileName, fileDirectory) + + +main(sys.argv) \ No newline at end of file diff --git a/Tools/Scripts/Srcgen/AddHeaderFile.py b/Tools/Scripts/Srcgen/AddHeaderFile.py new file mode 100644 index 0000000..3630e13 --- /dev/null +++ b/Tools/Scripts/Srcgen/AddHeaderFile.py @@ -0,0 +1,67 @@ +#!/bin/python3 + +# 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 . + +import sys + +FILE_TEMPLATE = """// 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 +{ + +} +""" + +def on_invalid_args(): + print(f"\033[33mUsage: {sys.argv[0]} \033[39m") + exit(1) + +def add_header_file(fileName: str, fileDirectory: str): + print(f"\033[32mAdding Header File '{fileName}' to '{fileDirectory}'..\033[39m") + with open(f"{fileDirectory}/{fileName}", 'w') as f: + f.write(FILE_TEMPLATE) + +def main(args: list[str]): + if (len(args) < 4) or ((args[2] != "PUBLIC") and (args[2] != "PRIVATE")): + on_invalid_args() + fileName = f"{args[3]}.hpp" + fileDirectory = "" + if args[2] == "PUBLIC": + fileDirectory = f"Src/{args[1]}/inc/{args[1]}" + else: + fileDirectory = f"Src/{args[1]}/imp/hpp" + add_header_file(fileName, fileDirectory) + +main(sys.argv) diff --git a/Tools/Scripts/Srcgen/AddSourceFile.py b/Tools/Scripts/Srcgen/AddSourceFile.py new file mode 100644 index 0000000..b3395a8 --- /dev/null +++ b/Tools/Scripts/Srcgen/AddSourceFile.py @@ -0,0 +1,59 @@ +#!/bin/python3 + +# 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 . + +import sys + +FILE_TEMPLATE = """// 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 . + +namespace ia::iae +{ + +} +""" + +def on_invalid_args(): + print(f"\033[33mUsage: {sys.argv[0]} \033[39m") + exit(1) + +def add_source_file(fileName: str, fileDirectory: str): + print(f"\033[32mAdding Source File '{fileName}' to '{fileDirectory}'..\033[39m") + with open(f"{fileDirectory}/{fileName}", 'w') as f: + f.write(FILE_TEMPLATE) + +def main(args: list[str]): + if len(args) < 3: + on_invalid_args() + fileName = f"{args[3]}.cpp" + fileDirectory = f"Src/{args[1]}/imp/cpp" + add_source_file(fileName, fileDirectory) + +main(sys.argv) diff --git a/Tools/Scripts/Srcgen/EmbedResources.py b/Tools/Scripts/Srcgen/EmbedResources.py new file mode 100644 index 0000000..11934c0 --- /dev/null +++ b/Tools/Scripts/Srcgen/EmbedResources.py @@ -0,0 +1,18 @@ +#!/bin/python3 + +# 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 . +