diff --git a/Engine/CMakeLists.txt b/Engine/CMakeLists.txt
index c75e01d..fa148d7 100644
--- a/Engine/CMakeLists.txt
+++ b/Engine/CMakeLists.txt
@@ -22,6 +22,7 @@ set(SRC_FILES
"Src/Imp/CPP/Nodes/CameraNode.cpp"
"Src/Imp/CPP/Nodes/SpriteNode.cpp"
"Src/Imp/CPP/Nodes/TextureNode.cpp"
+ "Src/Imp/CPP/Nodes/TileMapNode.cpp"
"Src/Imp/CPP/Components/CameraComponent.cpp"
"Src/Imp/CPP/Components/PhysicsComponent.cpp"
diff --git a/Engine/Src/Imp/CPP/Components/CameraComponent.cpp b/Engine/Src/Imp/CPP/Components/CameraComponent.cpp
index 6a24724..8ac3930 100644
--- a/Engine/Src/Imp/CPP/Components/CameraComponent.cpp
+++ b/Engine/Src/Imp/CPP/Components/CameraComponent.cpp
@@ -15,6 +15,7 @@
// along with this program. If not, see .
#include
+#include
#include
@@ -45,6 +46,8 @@ namespace ia::iae
VOID CameraComponent::Update()
{
+ const auto pos = m_node->GetPosition();
+ m_viewMatrix = glm::lookAtLH(glm::vec3{pos, -2.0f}, {pos, 0.0f}, {0.0f, 1.0f, 0.0f});
}
VOID CameraComponent::FixedUpdate()
diff --git a/Engine/Src/Imp/CPP/Components/TileMapComponent.cpp b/Engine/Src/Imp/CPP/Components/TileMapComponent.cpp
index e69de29..cfe2800 100644
--- a/Engine/Src/Imp/CPP/Components/TileMapComponent.cpp
+++ b/Engine/Src/Imp/CPP/Components/TileMapComponent.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
+
+namespace ia::iae
+{
+ STATIC Vector TileTextures;
+
+ TileMapComponent::TileMapComponent(IN Node2D *node) : TextureComponent(node)
+ {
+ }
+
+ VOID TileMapComponent::Draw()
+ {
+ TextureComponent::Draw();
+ }
+
+ VOID TileMapComponent::DebugDraw()
+ {
+ TextureComponent::DebugDraw();
+ }
+
+ VOID TileMapComponent::Update()
+ {
+ TextureComponent::Update();
+ }
+
+ VOID TileMapComponent::FixedUpdate()
+ {
+ TextureComponent::FixedUpdate();
+ }
+
+ VOID TileMapComponent::BeginGridSetup(IN INT32 tileWidth, IN INT32 tileHeight, IN INT32 tileCountX,
+ IN INT32 tileCountY)
+ {
+ m_tileWidth = tileWidth;
+ m_tileHeight = tileHeight;
+ m_tileCountX = tileCountX;
+ m_tileCountY = tileCountY;
+ TileTextures.resize(m_tileCountX * m_tileCountY);
+ }
+
+ VOID TileMapComponent::SetupGridTile(IN INT32 index, IN Handle texture)
+ {
+ TileTextures[index] = texture;
+ }
+
+ VOID TileMapComponent::SetupGridTile(IN INT32 x, IN INT32 y, IN Handle texture)
+ {
+ TileTextures[x + y * m_tileCountX] = texture;
+ }
+
+ VOID TileMapComponent::EndGridSetup()
+ {
+ m_mapTexture = Engine::CombineImages(TileTextures, m_tileWidth, m_tileHeight, m_tileCountX, m_tileCountY);
+ SetTexture(m_mapTexture);
+ TileTextures.reset();
+ }
+} // namespace ia::iae
\ No newline at end of file
diff --git a/Engine/Src/Imp/CPP/InputManager.cpp b/Engine/Src/Imp/CPP/InputManager.cpp
index 8bb1691..eabc26b 100644
--- a/Engine/Src/Imp/CPP/InputManager.cpp
+++ b/Engine/Src/Imp/CPP/InputManager.cpp
@@ -63,8 +63,8 @@ namespace ia::iae
Vec2 InputManager::GetAxis()
{
return Vec2{
- IsKeyDown(s_axisInputs[1]) + IsKeyDown(s_axisInputs[0]) * -1,
- IsKeyDown(s_axisInputs[3]) + IsKeyDown(s_axisInputs[2]) * -1
+ IsKeyDown(s_axisInputs[3]) + IsKeyDown(s_axisInputs[2]) * -1,
+ IsKeyDown(s_axisInputs[1]) + IsKeyDown(s_axisInputs[0]) * -1
};
}
diff --git a/Engine/Src/Imp/CPP/Nodes/TileMapNode.cpp b/Engine/Src/Imp/CPP/Nodes/TileMapNode.cpp
new file mode 100644
index 0000000..d288974
--- /dev/null
+++ b/Engine/Src/Imp/CPP/Nodes/TileMapNode.cpp
@@ -0,0 +1,25 @@
+// 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
+
+namespace ia::iae
+{
+ TileMapNode::TileMapNode(IN CONST String &name) : Node2D(name), m_tilemapComponent(AddComponent())
+ {
+ }
+} // namespace ia::iae
\ No newline at end of file
diff --git a/Engine/Src/Imp/CPP/Renderer/Renderer.cpp b/Engine/Src/Imp/CPP/Renderer/Renderer.cpp
index a63a946..4000ed6 100644
--- a/Engine/Src/Imp/CPP/Renderer/Renderer.cpp
+++ b/Engine/Src/Imp/CPP/Renderer/Renderer.cpp
@@ -154,7 +154,7 @@ namespace ia::iae
s_state.ActiveCamera ? s_state.ActiveCamera->GetProjectionMatrix() : &IdentityMatrix, sizeof(Mat4));
SDL_PushGPUVertexUniformData(
s_state.ActiveCommandBuffer, 1,
- (s_state.ActiveCamera && !s_state.CameraRelative) ? s_state.ActiveCamera->GetViewMatrix() : &IdentityMatrix,
+ (s_state.ActiveCamera && s_state.CameraRelative) ? s_state.ActiveCamera->GetViewMatrix() : &IdentityMatrix,
sizeof(Mat4));
}
diff --git a/Engine/Src/Imp/CPP/ResourceManager.cpp b/Engine/Src/Imp/CPP/ResourceManager.cpp
index 300eeb3..63ec53a 100644
--- a/Engine/Src/Imp/CPP/ResourceManager.cpp
+++ b/Engine/Src/Imp/CPP/ResourceManager.cpp
@@ -18,8 +18,8 @@
#include
#include
-#include
#include
+#include
#define STB_IMAGE_IMPLEMENTATION
#define STB_IMAGE_RESIZE_IMPLEMENTATION
@@ -28,7 +28,7 @@
namespace ia::iae
{
- Vector ResourceManager::s_imageHandles;
+ Vector ResourceManager::s_imageHandles;
Map ResourceManager::s_images;
Map ResourceManager::s_sounds;
Map ResourceManager::s_imageExtents;
@@ -37,8 +37,8 @@ namespace ia::iae
VOID ResourceManager::Initialize()
{
{ // Set Texture Handle 0 to a pure white image
- const auto data = new UINT8[100*100*4];
- ia_memset(data, 0xFF, 100* 100* 4);
+ const auto data = new UINT8[100 * 100 * 4];
+ ia_memset(data, 0xFF, 100 * 100 * 4);
CreateImage(Engine::GetUniqueResourceName(), data, 100, 100);
delete[] data;
}
@@ -63,8 +63,8 @@ namespace ia::iae
Handle ResourceManager::CreateImage(IN CONST String &name, IN PCUINT8 rgbaData, IN INT32 width, IN INT32 height)
{
- const auto texture = GPUResourceManager::CreateTexture(SDL_GPU_TEXTUREUSAGE_SAMPLER, width, height,
- rgbaData, SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM);
+ const auto texture = GPUResourceManager::CreateTexture(SDL_GPU_TEXTUREUSAGE_SAMPLER, width, height, rgbaData,
+ SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM);
s_imageHandles.pushBack(texture);
Handle handle = s_imageHandles.size() - 1;
s_images[name] = handle;
@@ -138,7 +138,7 @@ namespace ia::iae
stbir_resize_uint8_linear(pixelData.data(), currentExtent.x, currentExtent.y, currentExtent.x * 4, nullptr,
newWidth, newHeight, newWidth * 4, stbir_pixel_layout::STBIR_RGBA);
const auto texture = GPUResourceManager::CreateTexture(SDL_GPU_TEXTUREUSAGE_SAMPLER, newWidth, newHeight,
- newPixelData, SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM);
+ newPixelData, SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM);
s_imageExtents[image] = (((UINT64) newWidth) << 32) | newHeight;
GPUResourceManager::DestroyTexture(s_imageHandles[image]);
s_imageHandles[image] = texture;
@@ -149,16 +149,24 @@ namespace ia::iae
Handle ResourceManager::CombineImages(IN CONST Vector &images, IN INT32 unitWidth, IN INT32 unitHeight,
IN INT32 unitCountX, IN INT32 unitCountY)
{
- Vector textures;
- for(const auto& t: images)
+ const auto w = unitWidth * unitCountX;
+ const auto h = unitHeight * unitCountY;
+ Vector textures;
+ for (const auto &t : images)
textures.pushBack(s_imageHandles[t]);
- return (Handle) GPUResourceManager::CombineTextures(textures.data(), unitWidth, unitHeight,
- unitCountX, unitCountY);
+ const auto texture =
+ GPUResourceManager::CombineTextures(textures.data(), unitWidth, unitHeight, unitCountX, unitCountY);
+ s_imageHandles.pushBack(texture);
+ Handle handle = s_imageHandles.size() - 1;
+ s_images[Engine::GetUniqueResourceName()] = handle;
+ s_imageExtents[handle] = (((UINT64) w) << 32) | h;
+ s_nonScaledImageExtents[handle] = s_imageExtents[handle];
+ return handle;
}
VOID ResourceManager::RescaleAllImages(IN FLOAT32 factorX, IN FLOAT32 factorY)
{
- for(auto& t: s_images)
+ for (auto &t : s_images)
{
const auto p = s_nonScaledImageExtents[t->Value];
t->Value = ResizeImage(t->Value, ((INT32) (p >> 32)) * factorX, ((INT32) p) * factorY);
diff --git a/Engine/Src/Inc/IAEngine/Components/TileMapComponent.hpp b/Engine/Src/Inc/IAEngine/Components/TileMapComponent.hpp
index e69de29..5987955 100644
--- a/Engine/Src/Inc/IAEngine/Components/TileMapComponent.hpp
+++ b/Engine/Src/Inc/IAEngine/Components/TileMapComponent.hpp
@@ -0,0 +1,48 @@
+// 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 TileMapComponent : public TextureComponent
+ {
+ public:
+ TileMapComponent(IN Node2D *node);
+
+ public:
+ VIRTUAL VOID Draw();
+ VIRTUAL VOID DebugDraw();
+
+ VIRTUAL VOID Update();
+ VIRTUAL VOID FixedUpdate();
+
+ public:
+ VOID BeginGridSetup(IN INT32 tileWidth, IN INT32 tileHeight, IN INT32 tileCountX, IN INT32 tileCountY);
+ VOID SetupGridTile(IN INT32 index, IN Handle texture);
+ VOID SetupGridTile(IN INT32 x, IN INT32 y, IN Handle texture);
+ VOID EndGridSetup();
+
+ private:
+ INT32 m_tileWidth{};
+ INT32 m_tileHeight{};
+ INT32 m_tileCountX{};
+ INT32 m_tileCountY{};
+ Handle m_mapTexture{INVALID_HANDLE};
+ };
+} // 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
index 2f68a27..990d547 100644
--- a/Engine/Src/Inc/IAEngine/Engine.hpp
+++ b/Engine/Src/Inc/IAEngine/Engine.hpp
@@ -26,6 +26,7 @@
#include
#include
+#include
namespace ia::iae
{
diff --git a/Engine/Src/Inc/IAEngine/Nodes/Node2D.hpp b/Engine/Src/Inc/IAEngine/Nodes/Node2D.hpp
index 495c3d0..1ac792a 100644
--- a/Engine/Src/Inc/IAEngine/Nodes/Node2D.hpp
+++ b/Engine/Src/Inc/IAEngine/Nodes/Node2D.hpp
@@ -58,6 +58,11 @@ namespace ia::iae
return result;
}
+ VOID AddChild(IN RefPtr node)
+ {
+ m_children.pushBack(node);
+ }
+
public:
VOID Translate(IN Vec2 v)
{
diff --git a/Engine/Src/Inc/IAEngine/Nodes/TileMapNode.hpp b/Engine/Src/Inc/IAEngine/Nodes/TileMapNode.hpp
index e69de29..28a8a87 100644
--- a/Engine/Src/Inc/IAEngine/Nodes/TileMapNode.hpp
+++ b/Engine/Src/Inc/IAEngine/Nodes/TileMapNode.hpp
@@ -0,0 +1,38 @@
+// 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
+
+namespace ia::iae
+{
+ class TileMapNode : public Node2D
+ {
+ public:
+ TileMapNode(IN CONST String &name);
+
+ public:
+ TileMapComponent *GetTileMapComponent()
+ {
+ return m_tilemapComponent;
+ }
+
+ protected:
+ TileMapComponent *CONST m_tilemapComponent{};
+ };
+} // namespace ia::iae
\ No newline at end of file