Usable Engine
2
.vscode/launch.json
vendored
@ -11,7 +11,7 @@
|
|||||||
"program": "${workspaceFolder}/build/bin/Debug/IAERuntime.exe",
|
"program": "${workspaceFolder}/build/bin/Debug/IAERuntime.exe",
|
||||||
"args": [],
|
"args": [],
|
||||||
"stopAtEntry": false,
|
"stopAtEntry": false,
|
||||||
"cwd": "${workspaceFolder}",
|
"cwd": "${workspaceFolder}/Samples/SpaceInvaders",
|
||||||
"environment": [],
|
"environment": [],
|
||||||
"console": "externalTerminal",
|
"console": "externalTerminal",
|
||||||
"preLaunchTask": "CMake: build"
|
"preLaunchTask": "CMake: build"
|
||||||
|
|||||||
@ -1,5 +1,6 @@
|
|||||||
set(SRC_FILES
|
set(SRC_FILES
|
||||||
"Src/Imp/CPP/Time.cpp"
|
"Src/Imp/CPP/Time.cpp"
|
||||||
|
"Src/Imp/CPP/Scene.cpp"
|
||||||
"Src/Imp/CPP/Random.cpp"
|
"Src/Imp/CPP/Random.cpp"
|
||||||
"Src/Imp/CPP/Engine.cpp"
|
"Src/Imp/CPP/Engine.cpp"
|
||||||
"Src/Imp/CPP/InternalEngine.cpp"
|
"Src/Imp/CPP/InternalEngine.cpp"
|
||||||
@ -15,6 +16,17 @@ set(SRC_FILES
|
|||||||
"Src/Imp/CPP/Renderer/Renderer.cpp"
|
"Src/Imp/CPP/Renderer/Renderer.cpp"
|
||||||
"Src/Imp/CPP/Renderer/UIRenderer.cpp"
|
"Src/Imp/CPP/Renderer/UIRenderer.cpp"
|
||||||
"Src/Imp/CPP/Renderer/GPUResourceManager.cpp"
|
"Src/Imp/CPP/Renderer/GPUResourceManager.cpp"
|
||||||
|
|
||||||
|
"Src/Imp/CPP/Nodes/Node2D.cpp"
|
||||||
|
"Src/Imp/CPP/Nodes/TextureNode.cpp"
|
||||||
|
"Src/Imp/CPP/Nodes/CameraNode.cpp"
|
||||||
|
|
||||||
|
"Src/Imp/CPP/Components/CameraComponent.cpp"
|
||||||
|
"Src/Imp/CPP/Components/PhysicsComponent.cpp"
|
||||||
|
"Src/Imp/CPP/Components/SpriteComponent.cpp"
|
||||||
|
"Src/Imp/CPP/Components/TextureComponent.cpp"
|
||||||
|
"Src/Imp/CPP/Components/TileMapComponent.cpp"
|
||||||
|
"Src/Imp/CPP/Components/SoundEmitterComponent.cpp"
|
||||||
)
|
)
|
||||||
|
|
||||||
add_library(IAEngine SHARED ${SRC_FILES})
|
add_library(IAEngine SHARED ${SRC_FILES})
|
||||||
|
|||||||
53
Engine/Src/Imp/CPP/Components/CameraComponent.cpp
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
// 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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include <IAEngine/Components/CameraComponent.hpp>
|
||||||
|
|
||||||
|
#include <Renderer/Renderer.hpp>
|
||||||
|
|
||||||
|
namespace ia::iae
|
||||||
|
{
|
||||||
|
CameraComponent::CameraComponent(IN Node2D *node) : IComponent(node)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID CameraComponent::SetViewport(IN INT32 width, IN INT32 height)
|
||||||
|
{
|
||||||
|
m_viewport.x = 0;
|
||||||
|
m_viewport.y = 0;
|
||||||
|
m_viewport.z = width;
|
||||||
|
m_viewport.w = height;
|
||||||
|
|
||||||
|
m_projectionMatrix =
|
||||||
|
glm::orthoLH(0.0f, (FLOAT32) width, (FLOAT32) height, 0.0f, Renderer::MIN_DEPTH, Renderer::MAX_DEPTH);
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID CameraComponent::Draw()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID CameraComponent::DebugDraw()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID CameraComponent::Update()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID CameraComponent::FixedUpdate()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
} // namespace ia::iae
|
||||||
0
Engine/Src/Imp/CPP/Components/PhysicsComponent.cpp
Normal file
0
Engine/Src/Imp/CPP/Components/SpriteComponent.cpp
Normal file
60
Engine/Src/Imp/CPP/Components/TextureComponent.cpp
Normal file
@ -0,0 +1,60 @@
|
|||||||
|
// 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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include <IAEngine/Components/TextureComponent.hpp>
|
||||||
|
#include <IAEngine/Engine.hpp>
|
||||||
|
|
||||||
|
namespace ia::iae
|
||||||
|
{
|
||||||
|
TextureComponent::TextureComponent(IN Node2D *node) : IComponent(node)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID TextureComponent::SetTexture(IN Handle image)
|
||||||
|
{
|
||||||
|
const auto t = Engine::GetImageExtent(image);
|
||||||
|
|
||||||
|
m_texture = image;
|
||||||
|
m_textureExtent = {t.x, t.y};
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID TextureComponent::Draw()
|
||||||
|
{
|
||||||
|
m_drawnSize = m_node->GetScale() * m_textureExtent * m_scaleOffset;
|
||||||
|
|
||||||
|
Engine::SetRenderState_Texture(m_texture);
|
||||||
|
Engine::SetRenderState_FlippedH(m_isFlippedH);
|
||||||
|
Engine::SetRenderState_FlippedV(m_isFlippedV);
|
||||||
|
Engine::SetRenderState_ColorOverlay(m_colorOverlay);
|
||||||
|
Engine::SetRenderState_TextureOffset(m_textureOffset);
|
||||||
|
Engine::SetRenderState_CameraRelative(m_isCameraRelative);
|
||||||
|
Engine::SetRenderState_Transform(m_node->GetPosition() + m_positionOffset, m_drawnSize, m_node->GetRotation() + m_rotationOffset, m_node->Layer(), m_node->SortIndex());
|
||||||
|
|
||||||
|
Engine::DrawGeometry(Engine::GetGeometry_Quad());
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID TextureComponent::DebugDraw()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID TextureComponent::Update()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID TextureComponent::FixedUpdate()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
} // namespace ia::iae
|
||||||
0
Engine/Src/Imp/CPP/Components/TileMapComponent.cpp
Normal file
@ -17,6 +17,8 @@
|
|||||||
#include <IAEngine/Engine.hpp>
|
#include <IAEngine/Engine.hpp>
|
||||||
#include <Renderer/Renderer.hpp>
|
#include <Renderer/Renderer.hpp>
|
||||||
|
|
||||||
|
#include <IACore/File.hpp>
|
||||||
|
|
||||||
#include <IAEngine/EngineLibraryInterface.hpp>
|
#include <IAEngine/EngineLibraryInterface.hpp>
|
||||||
|
|
||||||
EXTERN GameFunctionTable g_gameFunctions;
|
EXTERN GameFunctionTable g_gameFunctions;
|
||||||
@ -37,4 +39,22 @@ namespace ia::iae
|
|||||||
Renderer::OnScreenResize(newWidth, newHeight);
|
Renderer::OnScreenResize(newWidth, newHeight);
|
||||||
g_gameFunctions.OnResize(newWidth, newHeight);
|
g_gameFunctions.OnResize(newWidth, newHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Handle Engine::CreateImageFromFile(IN CONST String &path)
|
||||||
|
{
|
||||||
|
const auto data = File::ReadToVector(path.c_str());
|
||||||
|
return CreateImage(data.data(), data.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
Handle Engine::CreateSoundFromFile(IN CONST String &path)
|
||||||
|
{
|
||||||
|
const auto data = File::ReadToVector(path.c_str());
|
||||||
|
return CreateSound(data.data(), data.size());
|
||||||
|
}
|
||||||
|
|
||||||
|
Handle Engine::CreateSceneFromFile(IN CONST String &path)
|
||||||
|
{
|
||||||
|
const auto data = File::ReadToString(path.c_str());
|
||||||
|
return CreateScene(data);
|
||||||
|
}
|
||||||
} // namespace ia::iae
|
} // namespace ia::iae
|
||||||
|
|||||||
@ -85,6 +85,9 @@ namespace ia::iae
|
|||||||
VOID __Internal_Engine::Iterate()
|
VOID __Internal_Engine::Iterate()
|
||||||
{
|
{
|
||||||
WorldManager::Update();
|
WorldManager::Update();
|
||||||
|
WorldManager::FixedUpdate();
|
||||||
|
g_gameFunctions.OnUpdate(Time::GetFrameDeltaTime());
|
||||||
|
g_gameFunctions.OnFixedUpdate();
|
||||||
|
|
||||||
Renderer::BeginFrame();
|
Renderer::BeginFrame();
|
||||||
WorldManager::Draw();
|
WorldManager::Draw();
|
||||||
|
|||||||
25
Engine/Src/Imp/CPP/Nodes/CameraNode.cpp
Normal file
@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include <IAEngine/Engine.hpp>
|
||||||
|
#include <IAEngine/Nodes/CameraNode.hpp>
|
||||||
|
|
||||||
|
namespace ia::iae
|
||||||
|
{
|
||||||
|
CameraNode::CameraNode(IN CONST String &name) : Node2D(name), m_cameraComponent(AddComponent<CameraComponent>())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
} // namespace ia::iae
|
||||||
63
Engine/Src/Imp/CPP/Nodes/Node2D.cpp
Normal file
@ -0,0 +1,63 @@
|
|||||||
|
// 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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include <IAEngine/Engine.hpp>
|
||||||
|
#include <IAEngine/Nodes/Node2D.hpp>
|
||||||
|
|
||||||
|
namespace ia::iae
|
||||||
|
{
|
||||||
|
Node2D::Node2D(IN CONST String &name) : INode(name)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Node2D::~Node2D()
|
||||||
|
{
|
||||||
|
for(auto& t: m_components)
|
||||||
|
delete t;
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID Node2D::Draw()
|
||||||
|
{
|
||||||
|
for(auto& t: m_components)
|
||||||
|
t->Draw();
|
||||||
|
for(auto& t: m_children)
|
||||||
|
t->Draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID Node2D::DebugDraw()
|
||||||
|
{
|
||||||
|
for(auto& t: m_components)
|
||||||
|
t->DebugDraw();
|
||||||
|
for(auto& t: m_children)
|
||||||
|
t->DebugDraw();
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID Node2D::Update()
|
||||||
|
{
|
||||||
|
for(auto& t: m_components)
|
||||||
|
t->Update();
|
||||||
|
for(auto& t: m_children)
|
||||||
|
t->Update();
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID Node2D::FixedUpdate()
|
||||||
|
{
|
||||||
|
for(auto& t: m_components)
|
||||||
|
t->FixedUpdate();
|
||||||
|
for(auto& t: m_children)
|
||||||
|
t->FixedUpdate();
|
||||||
|
}
|
||||||
|
} // namespace ia::iae
|
||||||
25
Engine/Src/Imp/CPP/Nodes/TextureNode.cpp
Normal file
@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include <IAEngine/Engine.hpp>
|
||||||
|
#include <IAEngine/Nodes/TextureNode.hpp>
|
||||||
|
|
||||||
|
namespace ia::iae
|
||||||
|
{
|
||||||
|
TextureNode::TextureNode(IN CONST String &name) : Node2D(name), m_textureComponent(AddComponent<TextureComponent>())
|
||||||
|
{
|
||||||
|
}
|
||||||
|
} // namespace ia::iae
|
||||||
@ -23,6 +23,9 @@
|
|||||||
#include <backends/imgui_impl_sdl3.h>
|
#include <backends/imgui_impl_sdl3.h>
|
||||||
#include <backends/imgui_impl_sdlgpu3.h>
|
#include <backends/imgui_impl_sdlgpu3.h>
|
||||||
|
|
||||||
|
#include <IAEngine/GameLibraryInterface.hpp>
|
||||||
|
EXTERN GameFunctionTable g_gameFunctions;
|
||||||
|
|
||||||
namespace ia::iae
|
namespace ia::iae
|
||||||
{
|
{
|
||||||
EXTERN SDL_Window *g_windowHandle;
|
EXTERN SDL_Window *g_windowHandle;
|
||||||
@ -67,6 +70,7 @@ namespace ia::iae
|
|||||||
ImGui::NewFrame();
|
ImGui::NewFrame();
|
||||||
|
|
||||||
WorldManager::DebugDraw();
|
WorldManager::DebugDraw();
|
||||||
|
g_gameFunctions.OnDebugDraw();
|
||||||
|
|
||||||
ImGui::Render();
|
ImGui::Render();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -144,10 +144,12 @@ namespace ia::iae
|
|||||||
&s_state.DepthStencilTargetInfo);
|
&s_state.DepthStencilTargetInfo);
|
||||||
|
|
||||||
SDL_BindGPUGraphicsPipeline(s_state.ActiveRenderPass, s_geometryPipeline->GetHandle());
|
SDL_BindGPUGraphicsPipeline(s_state.ActiveRenderPass, s_geometryPipeline->GetHandle());
|
||||||
SDL_PushGPUVertexUniformData(s_state.ActiveCommandBuffer, 0, &s_state.ProjectionMatrix, sizeof(Mat4));
|
SDL_PushGPUVertexUniformData(
|
||||||
|
s_state.ActiveCommandBuffer, 0,
|
||||||
|
s_state.ActiveCamera ? s_state.ActiveCamera->GetProjectionMatrix() : &IdentityMatrix, sizeof(Mat4));
|
||||||
SDL_PushGPUVertexUniformData(
|
SDL_PushGPUVertexUniformData(
|
||||||
s_state.ActiveCommandBuffer, 1,
|
s_state.ActiveCommandBuffer, 1,
|
||||||
(s_state.ActiveCamera && !s_state.CameraRelative) ? s_state.ActiveCamera->GetMatrix() : &IdentityMatrix,
|
(s_state.ActiveCamera && !s_state.CameraRelative) ? s_state.ActiveCamera->GetViewMatrix() : &IdentityMatrix,
|
||||||
sizeof(Mat4));
|
sizeof(Mat4));
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -210,8 +212,17 @@ namespace ia::iae
|
|||||||
SDL_GPU_TEXTUREUSAGE_COLOR_TARGET | SDL_GPU_TEXTUREUSAGE_SAMPLER, s_screenWidth, s_screenHeight, nullptr,
|
SDL_GPU_TEXTUREUSAGE_COLOR_TARGET | SDL_GPU_TEXTUREUSAGE_SAMPLER, s_screenWidth, s_screenHeight, nullptr,
|
||||||
SDL_GetGPUSwapchainTextureFormat(s_gpuDevice, g_windowHandle));
|
SDL_GetGPUSwapchainTextureFormat(s_gpuDevice, g_windowHandle));
|
||||||
|
|
||||||
s_state.ProjectionMatrix =
|
s_state.Scissor = {0, 0, newWidth, newHeight};
|
||||||
glm::orthoLH(0.0f, (FLOAT32) s_screenWidth, (FLOAT32) s_screenHeight, 0.0f, -2097152.0f, 2097152.0f);
|
|
||||||
|
s_state.ActiveViewport.x = 0;
|
||||||
|
s_state.ActiveViewport.y = 0;
|
||||||
|
s_state.ActiveViewport.w = newWidth;
|
||||||
|
s_state.ActiveViewport.h = newHeight;
|
||||||
|
s_state.ActiveViewport.min_depth = 0.0f;
|
||||||
|
s_state.ActiveViewport.max_depth = 1.0f;
|
||||||
|
|
||||||
|
if (s_state.ActiveCamera)
|
||||||
|
s_state.ActiveCamera->SetViewport(newWidth, newHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
SDL_GPUTextureFormat Renderer::GetRenderTargetFormat()
|
SDL_GPUTextureFormat Renderer::GetRenderTargetFormat()
|
||||||
@ -233,6 +244,8 @@ namespace ia::iae
|
|||||||
|
|
||||||
VOID Renderer::DestroyGeometry(IN Geometry *handle)
|
VOID Renderer::DestroyGeometry(IN Geometry *handle)
|
||||||
{
|
{
|
||||||
|
GPUResourceManager::DestroyBuffer(handle->VertexBuffer);
|
||||||
|
GPUResourceManager::DestroyBuffer(handle->IndexBuffer);
|
||||||
delete handle;
|
delete handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -250,8 +263,7 @@ namespace ia::iae
|
|||||||
|
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
|
||||||
s_fragmentUniform.ColorOverlay = Vec4(s_state.ColorOverlay.R / 255.0f, s_state.ColorOverlay.G / 255.0f,
|
s_fragmentUniform.ColorOverlay = s_state.ColorOverlay.GetAsFloatVec();
|
||||||
s_state.ColorOverlay.B / 255.0f, s_state.ColorOverlay.A / 255.0f);
|
|
||||||
s_fragmentUniform.FlippedH = s_state.FlippedH;
|
s_fragmentUniform.FlippedH = s_state.FlippedH;
|
||||||
s_fragmentUniform.FlippedV = s_state.FlippedV;
|
s_fragmentUniform.FlippedV = s_state.FlippedV;
|
||||||
s_fragmentUniform.TextureOffset = s_state.TextureOffset;
|
s_fragmentUniform.TextureOffset = s_state.TextureOffset;
|
||||||
@ -261,6 +273,7 @@ namespace ia::iae
|
|||||||
SDL_PushGPUFragmentUniformData(s_state.ActiveCommandBuffer, 0, &s_fragmentUniform, sizeof(s_fragmentUniform));
|
SDL_PushGPUFragmentUniformData(s_state.ActiveCommandBuffer, 0, &s_fragmentUniform, sizeof(s_fragmentUniform));
|
||||||
|
|
||||||
SDL_SetGPUScissor(s_state.ActiveRenderPass, &s_state.Scissor);
|
SDL_SetGPUScissor(s_state.ActiveRenderPass, &s_state.Scissor);
|
||||||
|
SDL_SetGPUViewport(s_state.ActiveRenderPass, &s_state.ActiveViewport);
|
||||||
|
|
||||||
SDL_GPUBufferBinding bufferBindings[] = {{.buffer = handle->VertexBuffer, .offset = 0},
|
SDL_GPUBufferBinding bufferBindings[] = {{.buffer = handle->VertexBuffer, .offset = 0},
|
||||||
{.buffer = handle->IndexBuffer, .offset = 0}};
|
{.buffer = handle->IndexBuffer, .offset = 0}};
|
||||||
@ -272,9 +285,10 @@ namespace ia::iae
|
|||||||
|
|
||||||
namespace ia::iae
|
namespace ia::iae
|
||||||
{
|
{
|
||||||
VOID Engine::SetActiveCamera(IN ICameraComponent *cameraComponent)
|
VOID Engine::SetActiveCamera(IN CameraComponent *cameraComponent)
|
||||||
{
|
{
|
||||||
Renderer::s_state.ActiveCamera = cameraComponent;
|
Renderer::s_state.ActiveCamera = cameraComponent;
|
||||||
|
Renderer::OnScreenResize(Renderer::s_screenWidth, Renderer::s_screenHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
Handle Engine::CreateGeometry(IN CONST Vector<GeometryVertex> &vertices, IN CONST Vector<INT32> &indices)
|
Handle Engine::CreateGeometry(IN CONST Vector<GeometryVertex> &vertices, IN CONST Vector<INT32> &indices)
|
||||||
@ -354,6 +368,6 @@ namespace ia::iae
|
|||||||
|
|
||||||
Handle Engine::GetGeometry_Quad()
|
Handle Engine::GetGeometry_Quad()
|
||||||
{
|
{
|
||||||
return (Handle)Renderer::s_quadGeometry;
|
return (Handle) Renderer::s_quadGeometry;
|
||||||
}
|
}
|
||||||
} // namespace ia::iae
|
} // namespace ia::iae
|
||||||
@ -27,6 +27,8 @@
|
|||||||
|
|
||||||
namespace ia::iae
|
namespace ia::iae
|
||||||
{
|
{
|
||||||
|
Vector<Handle> ResourceManager::s_images;
|
||||||
|
Vector<Handle> ResourceManager::s_sounds;
|
||||||
Map<Handle, UINT64> ResourceManager::s_imageExtents;
|
Map<Handle, UINT64> ResourceManager::s_imageExtents;
|
||||||
|
|
||||||
VOID ResourceManager::Initialize()
|
VOID ResourceManager::Initialize()
|
||||||
@ -35,6 +37,10 @@ namespace ia::iae
|
|||||||
|
|
||||||
VOID ResourceManager::Terminate()
|
VOID ResourceManager::Terminate()
|
||||||
{
|
{
|
||||||
|
for (const auto &t : s_images)
|
||||||
|
GPUResourceManager::DestroyTexture((SDL_GPUTexture *) t);
|
||||||
|
for (const auto &t : s_sounds)
|
||||||
|
AudioManager::DestoryAudio(t);
|
||||||
}
|
}
|
||||||
|
|
||||||
Handle ResourceManager::CreateImage(IN PCUINT8 encodedData, IN SIZE_T encodedDataSize)
|
Handle ResourceManager::CreateImage(IN PCUINT8 encodedData, IN SIZE_T encodedDataSize)
|
||||||
@ -51,12 +57,15 @@ namespace ia::iae
|
|||||||
const auto handle = (Handle) GPUResourceManager::CreateTexture(SDL_GPU_TEXTUREUSAGE_SAMPLER, width, height,
|
const auto handle = (Handle) GPUResourceManager::CreateTexture(SDL_GPU_TEXTUREUSAGE_SAMPLER, width, height,
|
||||||
rgbaData, SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM);
|
rgbaData, SDL_GPU_TEXTUREFORMAT_R8G8B8A8_UNORM);
|
||||||
s_imageExtents[handle] = (((UINT64) width) << 32) | height;
|
s_imageExtents[handle] = (((UINT64) width) << 32) | height;
|
||||||
|
s_images.pushBack(handle);
|
||||||
return handle;
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
Handle ResourceManager::CreateSound(IN PCUINT8 encodedData, IN SIZE_T encodedDataSize)
|
Handle ResourceManager::CreateSound(IN PCUINT8 encodedData, IN SIZE_T encodedDataSize)
|
||||||
{
|
{
|
||||||
return AudioManager::CreateAudio(encodedData, encodedDataSize);
|
const auto handle = AudioManager::CreateAudio(encodedData, encodedDataSize);
|
||||||
|
s_sounds.pushBack(handle);
|
||||||
|
return handle;
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID ResourceManager::DestroyImage(IN Handle image)
|
VOID ResourceManager::DestroyImage(IN Handle image)
|
||||||
@ -80,7 +89,6 @@ namespace ia::iae
|
|||||||
const auto currentExtent = GetImageExtent(image);
|
const auto currentExtent = GetImageExtent(image);
|
||||||
const auto pixelData =
|
const auto pixelData =
|
||||||
GPUResourceManager::GetTexturePixelData((SDL_GPUTexture *) image, currentExtent.x, currentExtent.y);
|
GPUResourceManager::GetTexturePixelData((SDL_GPUTexture *) image, currentExtent.x, currentExtent.y);
|
||||||
GPUResourceManager::DestroyTexture((SDL_GPUTexture *) image);
|
|
||||||
const auto newPixelData =
|
const auto newPixelData =
|
||||||
stbir_resize_uint8_linear(pixelData.data(), currentExtent.x, currentExtent.y, currentExtent.x * 4, nullptr,
|
stbir_resize_uint8_linear(pixelData.data(), currentExtent.x, currentExtent.y, currentExtent.x * 4, nullptr,
|
||||||
newWidth, newHeight, newWidth * 4, stbir_pixel_layout::STBIR_RGBA);
|
newWidth, newHeight, newWidth * 4, stbir_pixel_layout::STBIR_RGBA);
|
||||||
@ -92,7 +100,8 @@ namespace ia::iae
|
|||||||
Handle ResourceManager::CombineImages(IN CONST Vector<Handle> &images, IN INT32 unitWidth, IN INT32 unitHeight,
|
Handle ResourceManager::CombineImages(IN CONST Vector<Handle> &images, IN INT32 unitWidth, IN INT32 unitHeight,
|
||||||
IN INT32 unitCountX, IN INT32 unitCountY)
|
IN INT32 unitCountX, IN INT32 unitCountY)
|
||||||
{
|
{
|
||||||
return (Handle)GPUResourceManager::CombineTextures((SDL_GPUTexture**)images.data(), unitWidth, unitHeight, unitCountX, unitCountY);
|
return (Handle) GPUResourceManager::CombineTextures((SDL_GPUTexture **) images.data(), unitWidth, unitHeight,
|
||||||
|
unitCountX, unitCountY);
|
||||||
}
|
}
|
||||||
} // namespace ia::iae
|
} // namespace ia::iae
|
||||||
|
|
||||||
|
|||||||
77
Engine/Src/Imp/CPP/Scene.cpp
Normal file
@ -0,0 +1,77 @@
|
|||||||
|
// 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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#include <IAEngine/Engine.hpp>
|
||||||
|
#include <Scene.hpp>
|
||||||
|
|
||||||
|
namespace ia::iae
|
||||||
|
{
|
||||||
|
Scene *Scene::Create()
|
||||||
|
{
|
||||||
|
return new Scene();
|
||||||
|
}
|
||||||
|
|
||||||
|
Scene *Scene::Create(IN CONST String &sceneXML)
|
||||||
|
{
|
||||||
|
const auto scene = new Scene();
|
||||||
|
|
||||||
|
return scene;
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID Scene::Destroy(IN Scene *scene)
|
||||||
|
{
|
||||||
|
delete scene;
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID Scene::Draw()
|
||||||
|
{
|
||||||
|
for (auto &t : m_nodes)
|
||||||
|
t->Value->Draw();
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID Scene::DebugDraw()
|
||||||
|
{
|
||||||
|
for (auto &t : m_nodes)
|
||||||
|
t->Value->DebugDraw();
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID Scene::FixedUpdate()
|
||||||
|
{
|
||||||
|
for (auto &t : m_nodes)
|
||||||
|
t->Value->FixedUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID Scene::Update()
|
||||||
|
{
|
||||||
|
for (auto &t : m_nodes)
|
||||||
|
t->Value->Update();
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID Scene::AddNode(IN RefPtr<INode> node)
|
||||||
|
{
|
||||||
|
m_nodes[node->GetName()] = node;
|
||||||
|
}
|
||||||
|
|
||||||
|
INode *Scene::GetNode(IN CONST String &name)
|
||||||
|
{
|
||||||
|
return m_nodes[name].get();
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID Scene::RemoveNode(IN CONST String &name)
|
||||||
|
{
|
||||||
|
m_nodes[name] = nullptr;
|
||||||
|
}
|
||||||
|
} // namespace ia::iae
|
||||||
@ -19,74 +19,104 @@
|
|||||||
|
|
||||||
namespace ia::iae
|
namespace ia::iae
|
||||||
{
|
{
|
||||||
|
Scene *WorldManager::m_activeScene{};
|
||||||
|
|
||||||
VOID WorldManager::Initialize()
|
VOID WorldManager::Initialize()
|
||||||
{
|
{
|
||||||
|
m_activeScene = Scene::Create();
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID WorldManager::Terminate()
|
VOID WorldManager::Terminate()
|
||||||
{
|
{
|
||||||
|
if (m_activeScene)
|
||||||
|
Scene::Destroy(m_activeScene);
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID WorldManager::Draw()
|
VOID WorldManager::Draw()
|
||||||
{
|
{
|
||||||
|
m_activeScene->Draw();
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID WorldManager::DebugDraw()
|
VOID WorldManager::DebugDraw()
|
||||||
{
|
{
|
||||||
|
m_activeScene->DebugDraw();
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID WorldManager::Update()
|
VOID WorldManager::Update()
|
||||||
{
|
{
|
||||||
|
m_activeScene->Update();
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID WorldManager::FixedUpdate()
|
||||||
|
{
|
||||||
|
m_activeScene->FixedUpdate();
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID WorldManager::ChangeActiveScene(IN Scene *scene)
|
||||||
|
{
|
||||||
|
m_activeScene = scene;
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID WorldManager::AddNodeToActiveScene(IN RefPtr<INode> node)
|
||||||
|
{
|
||||||
|
m_activeScene->AddNode(node);
|
||||||
|
}
|
||||||
|
|
||||||
|
INode *WorldManager::GetNodeFromActiveScene(IN CONST String &name)
|
||||||
|
{
|
||||||
|
return m_activeScene->GetNode(name);
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID WorldManager::RemoveNodeFromActiveScene(IN CONST String &name)
|
||||||
|
{
|
||||||
|
m_activeScene->RemoveNode(name);
|
||||||
}
|
}
|
||||||
} // namespace ia::iae
|
} // namespace ia::iae
|
||||||
|
|
||||||
namespace ia::iae
|
namespace ia::iae
|
||||||
{
|
{
|
||||||
Handle Engine::CreatePhysicsBody()
|
Handle Engine::CreateScene(IN CONST String &sceneXML)
|
||||||
{
|
|
||||||
return INVALID_HANDLE;
|
|
||||||
}
|
|
||||||
|
|
||||||
VOID Engine::DestroyPhysicsBody(IN Handle body)
|
|
||||||
{
|
{
|
||||||
|
return (Handle) Scene::Create(sceneXML);
|
||||||
}
|
}
|
||||||
|
|
||||||
Handle Engine::CreateEmptyScene()
|
Handle Engine::CreateEmptyScene()
|
||||||
{
|
{
|
||||||
return INVALID_HANDLE;
|
return (Handle) Scene::Create();
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID Engine::DestroyScene(IN Handle handle)
|
VOID Engine::DestroyScene(IN Handle handle)
|
||||||
{
|
{
|
||||||
|
Scene::Destroy((Scene *) handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID Engine::ChangeActiveScene(IN Handle scene)
|
VOID Engine::ChangeActiveScene(IN Handle scene)
|
||||||
{
|
{
|
||||||
|
WorldManager::ChangeActiveScene((Scene *) scene);
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID Engine::AddNodeToActiveScene(IN RefPtr<INode> node)
|
VOID Engine::AddNodeToActiveScene(IN RefPtr<INode> node)
|
||||||
{
|
{
|
||||||
|
WorldManager::AddNodeToActiveScene(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
INode *Engine::GetNodeFromActiveScene(IN CONST String &name)
|
INode *Engine::GetNodeFromActiveScene(IN CONST String &name)
|
||||||
{
|
{
|
||||||
return nullptr;
|
return WorldManager::GetNodeFromActiveScene(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID Engine::RemoveNodeFromActiveScene(IN CONST String &name)
|
VOID Engine::RemoveNodeFromActiveScene(IN CONST String &name)
|
||||||
{
|
{
|
||||||
|
WorldManager::RemoveNodeFromActiveScene(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID Engine::AddNodeToScene(IN Handle scene, IN RefPtr<INode> node)
|
VOID Engine::AddNodeToScene(IN Handle scene, IN RefPtr<INode> node)
|
||||||
{
|
{
|
||||||
|
((Scene *) scene)->AddNode(node);
|
||||||
}
|
}
|
||||||
|
|
||||||
VOID Engine::RemoveNodeFromScene(IN Handle scene, IN CONST String &name)
|
VOID Engine::RemoveNodeFromScene(IN Handle scene, IN CONST String &name)
|
||||||
{
|
{
|
||||||
}
|
((Scene *) scene)->RemoveNode(name);
|
||||||
|
|
||||||
Handle Engine::CreateScene(IN CONST String& sceneXML)
|
|
||||||
{
|
|
||||||
return INVALID_HANDLE;
|
|
||||||
}
|
}
|
||||||
} // namespace ia::iae
|
} // namespace ia::iae
|
||||||
@ -24,6 +24,9 @@ namespace ia::iae
|
|||||||
class Renderer
|
class Renderer
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
STATIC CONSTEXPR FLOAT32 MIN_DEPTH = -2097152.0f;
|
||||||
|
STATIC CONSTEXPR FLOAT32 MAX_DEPTH = 2097152.0f;
|
||||||
|
|
||||||
struct Geometry
|
struct Geometry
|
||||||
{
|
{
|
||||||
INT32 IndexCount{};
|
INT32 IndexCount{};
|
||||||
@ -41,16 +44,16 @@ namespace ia::iae
|
|||||||
Vec2 TextureOffset{0.0f, 0.0f};
|
Vec2 TextureOffset{0.0f, 0.0f};
|
||||||
SDL_Rect Scissor{0, 0, 0, 0};
|
SDL_Rect Scissor{0, 0, 0, 0};
|
||||||
SDL_GPUTexture* ActiveTexture{nullptr};
|
SDL_GPUTexture* ActiveTexture{nullptr};
|
||||||
|
SDL_GPUViewport ActiveViewport{};
|
||||||
|
|
||||||
Mat4 ModelMatrix{1.0f};
|
Mat4 ModelMatrix{1.0f};
|
||||||
Mat4 ProjectionMatrix{1.0f};
|
|
||||||
|
|
||||||
SDL_GPURenderPass* ActiveRenderPass{};
|
SDL_GPURenderPass* ActiveRenderPass{};
|
||||||
SDL_GPUCommandBuffer* ActiveCommandBuffer{};
|
SDL_GPUCommandBuffer* ActiveCommandBuffer{};
|
||||||
SDL_GPUColorTargetInfo ColorTargetInfo{};
|
SDL_GPUColorTargetInfo ColorTargetInfo{};
|
||||||
SDL_GPUDepthStencilTargetInfo DepthStencilTargetInfo{};
|
SDL_GPUDepthStencilTargetInfo DepthStencilTargetInfo{};
|
||||||
|
|
||||||
class ICameraComponent *ActiveCamera{};
|
class CameraComponent *ActiveCamera{};
|
||||||
};
|
};
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|||||||
@ -46,6 +46,8 @@ namespace ia::iae
|
|||||||
IN INT32 unitCountX, IN INT32 unitCountY);
|
IN INT32 unitCountX, IN INT32 unitCountY);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
STATIC Vector<Handle> s_images;
|
||||||
|
STATIC Vector<Handle> s_sounds;
|
||||||
STATIC Map<Handle, UINT64> s_imageExtents;
|
STATIC Map<Handle, UINT64> s_imageExtents;
|
||||||
};
|
};
|
||||||
} // namespace ia::iae
|
} // namespace ia::iae
|
||||||
48
Engine/Src/Imp/HPP/Scene.hpp
Normal file
@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <IAEngine/Nodes/INode.hpp>
|
||||||
|
|
||||||
|
#include <SDL3/SDL.h>
|
||||||
|
|
||||||
|
namespace ia::iae
|
||||||
|
{
|
||||||
|
class Scene
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
STATIC Scene *Create();
|
||||||
|
STATIC Scene *Create(IN CONST String &sceneXML);
|
||||||
|
|
||||||
|
STATIC VOID Destroy(IN Scene *scene);
|
||||||
|
|
||||||
|
public:
|
||||||
|
VOID Draw();
|
||||||
|
VOID DebugDraw();
|
||||||
|
|
||||||
|
VOID FixedUpdate();
|
||||||
|
VOID Update();
|
||||||
|
|
||||||
|
public:
|
||||||
|
VOID AddNode(IN RefPtr<INode> node);
|
||||||
|
INode *GetNode(IN CONST String &name);
|
||||||
|
VOID RemoveNode(IN CONST String &name);
|
||||||
|
|
||||||
|
private:
|
||||||
|
Map<String, RefPtr<INode>> m_nodes;
|
||||||
|
};
|
||||||
|
} // namespace ia::iae
|
||||||
@ -17,6 +17,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <IAEngine/Base.hpp>
|
#include <IAEngine/Base.hpp>
|
||||||
|
#include <Scene.hpp>
|
||||||
|
|
||||||
#include <SDL3/SDL.h>
|
#include <SDL3/SDL.h>
|
||||||
|
|
||||||
@ -24,7 +25,7 @@ namespace ia::iae
|
|||||||
{
|
{
|
||||||
class WorldManager
|
class WorldManager
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
STATIC VOID Initialize();
|
STATIC VOID Initialize();
|
||||||
STATIC VOID Terminate();
|
STATIC VOID Terminate();
|
||||||
|
|
||||||
@ -32,5 +33,15 @@ namespace ia::iae
|
|||||||
STATIC VOID DebugDraw();
|
STATIC VOID DebugDraw();
|
||||||
|
|
||||||
STATIC VOID Update();
|
STATIC VOID Update();
|
||||||
|
STATIC VOID FixedUpdate();
|
||||||
|
|
||||||
|
public:
|
||||||
|
STATIC VOID ChangeActiveScene(IN Scene* scene);
|
||||||
|
STATIC VOID AddNodeToActiveScene(IN RefPtr<INode> node);
|
||||||
|
STATIC INode *GetNodeFromActiveScene(IN CONST String &name);
|
||||||
|
STATIC VOID RemoveNodeFromActiveScene(IN CONST String &name);
|
||||||
|
|
||||||
|
private:
|
||||||
|
STATIC Scene *m_activeScene;
|
||||||
};
|
};
|
||||||
}
|
} // namespace ia::iae
|
||||||
@ -16,6 +16,12 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#if defined(__BUILDING_IAENGINE) && (__BUILDING_IAENGINE)
|
||||||
|
#define IAE_DLL_API IA_DLL_EXPORT
|
||||||
|
#else
|
||||||
|
#define IAE_DLL_API IA_DLL_IMPORT
|
||||||
|
#endif
|
||||||
|
|
||||||
#include <IACore/Map.hpp>
|
#include <IACore/Map.hpp>
|
||||||
#include <IACore/Logger.hpp>
|
#include <IACore/Logger.hpp>
|
||||||
#include <IACore/Memory.hpp>
|
#include <IACore/Memory.hpp>
|
||||||
@ -108,6 +114,11 @@ namespace ia::iae
|
|||||||
UINT8 G{0xFF};
|
UINT8 G{0xFF};
|
||||||
UINT8 B{0xFF};
|
UINT8 B{0xFF};
|
||||||
UINT8 A{0xFF};
|
UINT8 A{0xFF};
|
||||||
|
|
||||||
|
Vec4 GetAsFloatVec() CONST
|
||||||
|
{
|
||||||
|
return {(FLOAT32)R/255.0f, (FLOAT32)G/255.0f, (FLOAT32)B/255.0f, (FLOAT32)A/255.0f};
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Adopted from SDL3 */
|
/* Adopted from SDL3 */
|
||||||
|
|||||||
@ -20,8 +20,39 @@
|
|||||||
|
|
||||||
namespace ia::iae
|
namespace ia::iae
|
||||||
{
|
{
|
||||||
struct ICameraComponent: public IComponent
|
class CameraComponent : public IComponent
|
||||||
{
|
{
|
||||||
PURE_VIRTUAL(Mat4* GetMatrix() CONST);
|
public:
|
||||||
|
CameraComponent(IN Node2D *node);
|
||||||
|
|
||||||
|
public:
|
||||||
|
VOID Draw();
|
||||||
|
VOID DebugDraw();
|
||||||
|
|
||||||
|
VOID Update();
|
||||||
|
VOID FixedUpdate();
|
||||||
|
|
||||||
|
public:
|
||||||
|
VOID SetViewport(IN INT32 width, IN INT32 height);
|
||||||
|
|
||||||
|
Vec4 GetViewport() CONST
|
||||||
|
{
|
||||||
|
return m_viewport;
|
||||||
|
}
|
||||||
|
|
||||||
|
CONST Mat4 *GetViewMatrix() CONST
|
||||||
|
{
|
||||||
|
return &m_viewMatrix;
|
||||||
|
}
|
||||||
|
|
||||||
|
CONST Mat4 *GetProjectionMatrix() CONST
|
||||||
|
{
|
||||||
|
return &m_projectionMatrix;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
Vec4 m_viewport{};
|
||||||
|
Mat4 m_viewMatrix{1.0f};
|
||||||
|
Mat4 m_projectionMatrix{1.0f};
|
||||||
};
|
};
|
||||||
}
|
} // namespace ia::iae
|
||||||
|
|||||||
@ -20,10 +20,32 @@
|
|||||||
|
|
||||||
namespace ia::iae
|
namespace ia::iae
|
||||||
{
|
{
|
||||||
class INode;
|
class Node2D;
|
||||||
|
|
||||||
struct IComponent
|
class IComponent
|
||||||
{
|
{
|
||||||
INode* Node{};
|
public:
|
||||||
|
PURE_VIRTUAL(VOID Draw());
|
||||||
|
PURE_VIRTUAL(VOID DebugDraw());
|
||||||
|
PURE_VIRTUAL(VOID Update());
|
||||||
|
PURE_VIRTUAL(VOID FixedUpdate());
|
||||||
|
|
||||||
|
public:
|
||||||
|
IComponent(IN Node2D *node) : m_node(node)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
Node2D *GetNode()
|
||||||
|
{
|
||||||
|
return m_node;
|
||||||
|
}
|
||||||
|
|
||||||
|
CONST Node2D *GetNode() CONST
|
||||||
|
{
|
||||||
|
return m_node;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
Node2D *CONST m_node{};
|
||||||
};
|
};
|
||||||
}
|
} // namespace ia::iae
|
||||||
102
Engine/Src/Inc/IAEngine/Components/TextureComponent.hpp
Normal file
@ -0,0 +1,102 @@
|
|||||||
|
// 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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <IAEngine/Components/IComponent.hpp>
|
||||||
|
|
||||||
|
namespace ia::iae
|
||||||
|
{
|
||||||
|
class TextureComponent : public IComponent
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
IAE_DLL_API TextureComponent(IN Node2D *node);
|
||||||
|
|
||||||
|
public:
|
||||||
|
VOID Draw();
|
||||||
|
VOID DebugDraw();
|
||||||
|
|
||||||
|
VOID Update();
|
||||||
|
VOID FixedUpdate();
|
||||||
|
|
||||||
|
public:
|
||||||
|
IAE_DLL_API VOID SetTexture(IN Handle image);
|
||||||
|
|
||||||
|
Handle GetTexture() CONST
|
||||||
|
{
|
||||||
|
return m_texture;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vec2 &PositionOffset()
|
||||||
|
{
|
||||||
|
return m_positionOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vec2 &ScaleOffset()
|
||||||
|
{
|
||||||
|
return m_scaleOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
FLOAT32 &RotationOffset()
|
||||||
|
{
|
||||||
|
return m_rotationOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vec2 &TextureOffset()
|
||||||
|
{
|
||||||
|
return m_textureOffset;
|
||||||
|
}
|
||||||
|
|
||||||
|
Color &ColorOverlay()
|
||||||
|
{
|
||||||
|
return m_colorOverlay;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL &IsFlippedH()
|
||||||
|
{
|
||||||
|
return m_isFlippedH;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL &IsFlippedV()
|
||||||
|
{
|
||||||
|
return m_isFlippedV;
|
||||||
|
}
|
||||||
|
|
||||||
|
BOOL &IsCameraRelative()
|
||||||
|
{
|
||||||
|
return m_isCameraRelative;
|
||||||
|
}
|
||||||
|
|
||||||
|
Vec2 &DrawnSize()
|
||||||
|
{
|
||||||
|
return m_drawnSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
BOOL m_isFlippedH{};
|
||||||
|
BOOL m_isFlippedV{};
|
||||||
|
BOOL m_isCameraRelative{true};
|
||||||
|
Vec2 m_positionOffset{};
|
||||||
|
Vec2 m_textureOffset{};
|
||||||
|
Vec2 m_scaleOffset{1.0f, 1.0f};
|
||||||
|
FLOAT32 m_rotationOffset{};
|
||||||
|
Color m_colorOverlay{};
|
||||||
|
Vec2 m_drawnSize{};
|
||||||
|
|
||||||
|
Vec2 m_textureExtent{};
|
||||||
|
Handle m_texture{INVALID_HANDLE};
|
||||||
|
};
|
||||||
|
} // namespace ia::iae
|
||||||
@ -16,8 +16,13 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <IAEngine/Nodes/INode.hpp>
|
#include <IAEngine/Nodes/CameraNode.hpp>
|
||||||
|
#include <IAEngine/Nodes/TileMapNode.hpp>
|
||||||
|
#include <IAEngine/Nodes/SpriteObjectNode.hpp>
|
||||||
|
#include <IAEngine/Nodes/TextureObjectNode.hpp>
|
||||||
|
|
||||||
#include <IAEngine/Components/CameraComponent.hpp>
|
#include <IAEngine/Components/CameraComponent.hpp>
|
||||||
|
#include <IAEngine/Components/SoundEmitterComponent.hpp>
|
||||||
|
|
||||||
namespace ia::iae
|
namespace ia::iae
|
||||||
{
|
{
|
||||||
@ -25,96 +30,95 @@ namespace ia::iae
|
|||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
// Event Functions
|
// Event Functions
|
||||||
STATIC Handle CreateEvent(IN CONST String& name);
|
STATIC IAE_DLL_API Handle CreateEvent(IN CONST String& name);
|
||||||
STATIC VOID DestroyEvent(IN Handle event);
|
STATIC IAE_DLL_API VOID DestroyEvent(IN Handle event);
|
||||||
STATIC Handle GetEventByName(IN CONST String& name);
|
STATIC IAE_DLL_API Handle GetEventByName(IN CONST String& name);
|
||||||
STATIC VOID AddEventListener(IN Handle event, IN std::function<VOID()> callback);
|
STATIC IAE_DLL_API VOID AddEventListener(IN Handle event, IN std::function<VOID()> callback);
|
||||||
STATIC VOID AddEventListener(IN CONST String& eventName, IN std::function<VOID()> callback);
|
STATIC IAE_DLL_API VOID AddEventListener(IN CONST String& eventName, IN std::function<VOID()> callback);
|
||||||
STATIC VOID BroadcastEvent(IN Handle event);
|
STATIC IAE_DLL_API VOID BroadcastEvent(IN Handle event);
|
||||||
STATIC VOID BroadcastEvent(IN CONST String& eventName);
|
STATIC IAE_DLL_API VOID BroadcastEvent(IN CONST String& eventName);
|
||||||
|
|
||||||
// Physics Functions
|
|
||||||
STATIC Handle CreatePhysicsBody();
|
|
||||||
STATIC VOID DestroyPhysicsBody(IN Handle body);
|
|
||||||
|
|
||||||
// Renderer Functions
|
// Renderer Functions
|
||||||
STATIC Handle GetGeometry_Quad();
|
STATIC IAE_DLL_API Handle GetGeometry_Quad();
|
||||||
STATIC Handle CreateGeometry(IN CONST Vector<GeometryVertex>& vertices, IN CONST Vector<INT32>& indices);
|
STATIC IAE_DLL_API Handle CreateGeometry(IN CONST Vector<GeometryVertex>& vertices, IN CONST Vector<INT32>& indices);
|
||||||
STATIC VOID DestroyGeometry(IN Handle geometry);
|
STATIC IAE_DLL_API VOID DestroyGeometry(IN Handle geometry);
|
||||||
STATIC VOID DrawGeometry(IN Handle handle);
|
STATIC IAE_DLL_API VOID DrawGeometry(IN Handle handle);
|
||||||
STATIC VOID ResizeDisplay(IN INT32 newWidth, IN INT32 newHeight);
|
STATIC IAE_DLL_API VOID ResizeDisplay(IN INT32 newWidth, IN INT32 newHeight);
|
||||||
|
|
||||||
// Renderer State Functions
|
// Renderer State Functions
|
||||||
STATIC VOID SetRenderState_Scissor(IN IVec4 rect);
|
STATIC IAE_DLL_API VOID SetRenderState_Scissor(IN IVec4 rect);
|
||||||
STATIC VOID SetRenderState_FlippedH(IN BOOL value);
|
STATIC IAE_DLL_API VOID SetRenderState_FlippedH(IN BOOL value);
|
||||||
STATIC VOID SetRenderState_FlippedV(IN BOOL value);
|
STATIC IAE_DLL_API VOID SetRenderState_FlippedV(IN BOOL value);
|
||||||
STATIC VOID SetRenderState_TextureOffset(IN Vec2 off);
|
STATIC IAE_DLL_API VOID SetRenderState_TextureOffset(IN Vec2 off);
|
||||||
STATIC VOID SetRenderState_YSortingEnabled(IN BOOL value);
|
STATIC IAE_DLL_API VOID SetRenderState_YSortingEnabled(IN BOOL value);
|
||||||
STATIC VOID SetRenderState_ColorOverlay(IN Color color);
|
STATIC IAE_DLL_API VOID SetRenderState_ColorOverlay(IN Color color);
|
||||||
STATIC VOID SetRenderState_CameraRelative(IN BOOL value);
|
STATIC IAE_DLL_API VOID SetRenderState_CameraRelative(IN BOOL value);
|
||||||
STATIC VOID SetRenderState_Texture(IN Handle image);
|
STATIC IAE_DLL_API VOID SetRenderState_Texture(IN Handle image);
|
||||||
STATIC VOID SetRenderState_Transform(IN Vec2 position, IN Vec2 scale, IN FLOAT32 rotation, IN UINT8 layer, IN INT16 sortIndex);
|
STATIC IAE_DLL_API VOID SetRenderState_Transform(IN Vec2 position, IN Vec2 scale, IN FLOAT32 rotation, IN UINT8 layer, IN INT16 sortIndex);
|
||||||
|
|
||||||
// Debug Draw Functions
|
// Debug Draw Functions
|
||||||
STATIC VOID DebugDraw_SetColor(IN Color color);
|
STATIC IAE_DLL_API VOID DebugDraw_SetColor(IN Color color);
|
||||||
STATIC VOID DebugDraw_StrokeWidth(IN FLOAT32 width);
|
STATIC IAE_DLL_API VOID DebugDraw_StrokeWidth(IN FLOAT32 width);
|
||||||
STATIC VOID DebugDraw_Line(IN Vec2 from, IN Vec2 to);
|
STATIC IAE_DLL_API VOID DebugDraw_Line(IN Vec2 from, IN Vec2 to);
|
||||||
STATIC VOID DebugDraw_FillRect(IN Vec2 position, IN Vec2 size);
|
STATIC IAE_DLL_API VOID DebugDraw_FillRect(IN Vec2 position, IN Vec2 size);
|
||||||
STATIC VOID DebugDraw_StrokeRect(IN Vec2 position, IN Vec2 size);
|
STATIC IAE_DLL_API VOID DebugDraw_StrokeRect(IN Vec2 position, IN Vec2 size);
|
||||||
|
|
||||||
// Resource Functions
|
// Resource Functions
|
||||||
STATIC Handle CreateImage(IN PCUINT8 encodedData, IN SIZE_T encodedDataSize);
|
STATIC IAE_DLL_API Handle CreateImageFromFile(IN CONST String& path);
|
||||||
STATIC Handle CreateImage(IN PCUINT8 rgbaData, IN INT32 width, IN INT32 height);
|
STATIC IAE_DLL_API Handle CreateSoundFromFile(IN CONST String& path);
|
||||||
STATIC Handle CreateSound(IN PCUINT8 encodedData, IN SIZE_T encodedDataSize);
|
STATIC IAE_DLL_API Handle CreateImage(IN PCUINT8 encodedData, IN SIZE_T encodedDataSize);
|
||||||
STATIC VOID DestroyImage(IN Handle image);
|
STATIC IAE_DLL_API Handle CreateImage(IN PCUINT8 rgbaData, IN INT32 width, IN INT32 height);
|
||||||
STATIC VOID DestroySound(IN Handle sound);
|
STATIC IAE_DLL_API Handle CreateSound(IN PCUINT8 encodedData, IN SIZE_T encodedDataSize);
|
||||||
STATIC IVec2 GetImageExtent(IN Handle image);
|
STATIC IAE_DLL_API VOID DestroyImage(IN Handle image);
|
||||||
STATIC Handle RescaleImage(IN Handle image, IN INT32 newWidth, IN INT32 newHeight);
|
STATIC IAE_DLL_API VOID DestroySound(IN Handle sound);
|
||||||
STATIC Handle CombineImages(IN CONST Vector<Handle>& images, IN INT32 unitWidth, IN INT32 unitHeight, IN INT32 unitCountX, IN INT32 unitCountY);
|
STATIC IAE_DLL_API IVec2 GetImageExtent(IN Handle image);
|
||||||
|
STATIC IAE_DLL_API Handle RescaleImage(IN Handle image, IN INT32 newWidth, IN INT32 newHeight);
|
||||||
|
STATIC IAE_DLL_API Handle CombineImages(IN CONST Vector<Handle>& images, IN INT32 unitWidth, IN INT32 unitHeight, IN INT32 unitCountX, IN INT32 unitCountY);
|
||||||
|
|
||||||
// Game Functions
|
// Game Functions
|
||||||
STATIC VOID SetTimeScale(IN FLOAT32 scale);
|
STATIC IAE_DLL_API VOID SetTimeScale(IN FLOAT32 scale);
|
||||||
STATIC VOID SetActiveCamera(IN ICameraComponent* cameraComponent);
|
STATIC IAE_DLL_API VOID SetActiveCamera(IN CameraComponent* cameraComponent);
|
||||||
|
|
||||||
// Scene Functions
|
// Scene Functions
|
||||||
STATIC Handle CreateScene(IN CONST String& sceneXML);
|
STATIC IAE_DLL_API Handle CreateSceneFromFile(IN CONST String& path);
|
||||||
STATIC Handle CreateEmptyScene();
|
STATIC IAE_DLL_API Handle CreateScene(IN CONST String& sceneXML);
|
||||||
STATIC VOID DestroyScene(IN Handle handle);
|
STATIC IAE_DLL_API Handle CreateEmptyScene();
|
||||||
STATIC VOID ChangeActiveScene(IN Handle scene);
|
STATIC IAE_DLL_API VOID DestroyScene(IN Handle handle);
|
||||||
STATIC VOID AddNodeToActiveScene(IN RefPtr<INode> node);
|
STATIC IAE_DLL_API VOID ChangeActiveScene(IN Handle scene);
|
||||||
STATIC INode* GetNodeFromActiveScene(IN CONST String& name);
|
STATIC IAE_DLL_API VOID AddNodeToActiveScene(IN RefPtr<INode> node);
|
||||||
STATIC VOID RemoveNodeFromActiveScene(IN CONST String& name);
|
STATIC IAE_DLL_API INode* GetNodeFromActiveScene(IN CONST String& name);
|
||||||
STATIC VOID AddNodeToScene(IN Handle scene, IN RefPtr<INode> node);
|
STATIC IAE_DLL_API VOID RemoveNodeFromActiveScene(IN CONST String& name);
|
||||||
STATIC VOID RemoveNodeFromScene(IN Handle scene, IN CONST String& name);
|
STATIC IAE_DLL_API VOID AddNodeToScene(IN Handle scene, IN RefPtr<INode> node);
|
||||||
|
STATIC IAE_DLL_API VOID RemoveNodeFromScene(IN Handle scene, IN CONST String& name);
|
||||||
|
|
||||||
// Input Functions
|
// Input Functions
|
||||||
STATIC Vec2 GetInputAxis();
|
STATIC IAE_DLL_API Vec2 GetInputAxis();
|
||||||
STATIC VOID SwitchInputModeToText();
|
STATIC IAE_DLL_API VOID SwitchInputModeToText();
|
||||||
STATIC VOID SwitchInputModeToAction();
|
STATIC IAE_DLL_API VOID SwitchInputModeToAction();
|
||||||
STATIC Vec2 GetInputPointerPosition();
|
STATIC IAE_DLL_API Vec2 GetInputPointerPosition();
|
||||||
STATIC BOOL IsInputKeyDown(IN InputKey key);
|
STATIC IAE_DLL_API BOOL IsInputKeyDown(IN InputKey key);
|
||||||
STATIC BOOL WasInputKeyPressed(IN InputKey key);
|
STATIC IAE_DLL_API BOOL WasInputKeyPressed(IN InputKey key);
|
||||||
STATIC BOOL WasInputKeyReleased(IN InputKey key);
|
STATIC IAE_DLL_API BOOL WasInputKeyReleased(IN InputKey key);
|
||||||
STATIC BOOL IsInputActionDown(IN Handle action);
|
STATIC IAE_DLL_API BOOL IsInputActionDown(IN Handle action);
|
||||||
STATIC BOOL WasInputActionPressed(IN Handle action);
|
STATIC IAE_DLL_API BOOL WasInputActionPressed(IN Handle action);
|
||||||
STATIC BOOL WasInputActionReleased(IN Handle action);
|
STATIC IAE_DLL_API BOOL WasInputActionReleased(IN Handle action);
|
||||||
STATIC BOOL IsInputActionDown(IN CONST String& action);
|
STATIC IAE_DLL_API BOOL IsInputActionDown(IN CONST String& action);
|
||||||
STATIC BOOL WasInputActionPressed(IN CONST String& action);
|
STATIC IAE_DLL_API BOOL WasInputActionPressed(IN CONST String& action);
|
||||||
STATIC BOOL WasInputActionReleased(IN CONST String& action);
|
STATIC IAE_DLL_API BOOL WasInputActionReleased(IN CONST String& action);
|
||||||
STATIC Handle BindInputAction(IN CONST String& name, IN InputKey key);
|
STATIC IAE_DLL_API Handle BindInputAction(IN CONST String& name, IN InputKey key);
|
||||||
STATIC VOID BindInputAxis(IN InputKey upKey, IN InputKey downKey, IN InputKey leftKey, IN InputKey rightKey);
|
STATIC IAE_DLL_API VOID BindInputAxis(IN InputKey upKey, IN InputKey downKey, IN InputKey leftKey, IN InputKey rightKey);
|
||||||
|
|
||||||
// Random Functions
|
// Random Functions
|
||||||
STATIC FLOAT32 GetRandomFloat();
|
STATIC IAE_DLL_API FLOAT32 GetRandomFloat();
|
||||||
STATIC INT32 GetRandomInRange(IN INT32 min, IN INT32 max);
|
STATIC IAE_DLL_API INT32 GetRandomInRange(IN INT32 min, IN INT32 max);
|
||||||
|
|
||||||
// Time Functions
|
// Time Functions
|
||||||
STATIC INT64 GetTickCount();
|
STATIC IAE_DLL_API INT64 GetTickCount();
|
||||||
STATIC INT64 GetUnixSecond();
|
STATIC IAE_DLL_API INT64 GetUnixSecond();
|
||||||
STATIC INT64 GetUnixMillisecond();
|
STATIC IAE_DLL_API INT64 GetUnixMillisecond();
|
||||||
STATIC FLOAT32 GetFrameDeltaTime();
|
STATIC IAE_DLL_API FLOAT32 GetFrameDeltaTime();
|
||||||
|
|
||||||
// Engine Functions
|
// Engine Functions
|
||||||
STATIC BOOL IsDebugMode();
|
STATIC IAE_DLL_API BOOL IsDebugMode();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
@ -18,10 +18,4 @@
|
|||||||
|
|
||||||
#include <IAEngine/GameLibraryInterface.hpp>
|
#include <IAEngine/GameLibraryInterface.hpp>
|
||||||
|
|
||||||
#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 INT32 IAEngine_Run(IN GameFunctionTable gameFunctionTable));
|
C_DECL(IAE_DLL_API INT32 IAEngine_Run(IN GameFunctionTable gameFunctionTable));
|
||||||
|
|||||||
38
Engine/Src/Inc/IAEngine/Nodes/CameraNode.hpp
Normal file
@ -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 <https://www.gnu.org/licenses/>.
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <IAEngine/Components/CameraComponent.hpp>
|
||||||
|
#include <IAEngine/Nodes/Node2D.hpp>
|
||||||
|
|
||||||
|
namespace ia::iae
|
||||||
|
{
|
||||||
|
class CameraNode : public Node2D
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
IAE_DLL_API CameraNode(IN CONST String &name);
|
||||||
|
|
||||||
|
public:
|
||||||
|
CameraComponent *GetCameraComponent()
|
||||||
|
{
|
||||||
|
return m_cameraComponent;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
CameraComponent *CONST m_cameraComponent{};
|
||||||
|
};
|
||||||
|
} // namespace ia::iae
|
||||||
@ -20,8 +20,25 @@
|
|||||||
|
|
||||||
namespace ia::iae
|
namespace ia::iae
|
||||||
{
|
{
|
||||||
struct INode
|
class INode
|
||||||
{
|
{
|
||||||
String Name{};
|
public:
|
||||||
|
INode(IN CONST String &name) : m_name(name)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
PURE_VIRTUAL(VOID Draw());
|
||||||
|
PURE_VIRTUAL(VOID DebugDraw());
|
||||||
|
PURE_VIRTUAL(VOID Update());
|
||||||
|
PURE_VIRTUAL(VOID FixedUpdate());
|
||||||
|
|
||||||
|
public:
|
||||||
|
CONST String &GetName() CONST
|
||||||
|
{
|
||||||
|
return m_name;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
CONST String m_name;
|
||||||
};
|
};
|
||||||
}
|
} // namespace ia::iae
|
||||||
@ -16,9 +16,185 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <IAEngine/Components/IComponent.hpp>
|
||||||
#include <IAEngine/Nodes/INode.hpp>
|
#include <IAEngine/Nodes/INode.hpp>
|
||||||
|
|
||||||
namespace ia::iae
|
namespace ia::iae
|
||||||
{
|
{
|
||||||
|
class Node2D : public INode
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
IAE_DLL_API Node2D(IN CONST String &name);
|
||||||
|
IAE_DLL_API ~Node2D();
|
||||||
|
|
||||||
}
|
public:
|
||||||
|
template<typename _component_type> _component_type *AddComponent()
|
||||||
|
{
|
||||||
|
const auto t = new _component_type(this);
|
||||||
|
m_components.pushBack(t);
|
||||||
|
return t;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename _component_type> _component_type *GetComponent()
|
||||||
|
{
|
||||||
|
for (auto &c : m_components)
|
||||||
|
{
|
||||||
|
_component_type *comp = dynamic_cast<_component_type *>(c.get());
|
||||||
|
if (comp)
|
||||||
|
return comp;
|
||||||
|
}
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
|
template<typename _component_type> Vector<_component_type *> GetComponents()
|
||||||
|
{
|
||||||
|
Vector<_component_type *> result;
|
||||||
|
for (auto &c : m_components)
|
||||||
|
{
|
||||||
|
_component_type *comp = dynamic_cast<_component_type *>(c.get());
|
||||||
|
if (comp)
|
||||||
|
result.pushBack(comp);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
VOID Translate(IN Vec2 v)
|
||||||
|
{
|
||||||
|
m_local.Position += v;
|
||||||
|
RecalculatePosition();
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID Scale(IN FLOAT32 v)
|
||||||
|
{
|
||||||
|
m_local.Scale *= v;
|
||||||
|
RecalculateScale();
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID Scale(IN Vec2 v)
|
||||||
|
{
|
||||||
|
m_local.Scale *= v;
|
||||||
|
RecalculateScale();
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID Rotate(IN FLOAT32 v)
|
||||||
|
{
|
||||||
|
m_local.Rotation += v;
|
||||||
|
RecalculateRotation();
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID SetLocalPosition(IN CONST Vec2 &v)
|
||||||
|
{
|
||||||
|
m_local.Position = v;
|
||||||
|
RecalculatePosition();
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID SetLocalScale(IN CONST Vec2 &v)
|
||||||
|
{
|
||||||
|
m_local.Scale = v;
|
||||||
|
RecalculateScale();
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID SetLocalRotation(IN FLOAT32 v)
|
||||||
|
{
|
||||||
|
m_local.Rotation = v;
|
||||||
|
RecalculateRotation();
|
||||||
|
}
|
||||||
|
|
||||||
|
public:
|
||||||
|
CONST Vec2 &GetPosition() CONST
|
||||||
|
{
|
||||||
|
return m_global.Position;
|
||||||
|
}
|
||||||
|
|
||||||
|
CONST Vec2 &GetScale() CONST
|
||||||
|
{
|
||||||
|
return m_global.Scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
CONST FLOAT32 &GetRotation() CONST
|
||||||
|
{
|
||||||
|
return m_global.Rotation;
|
||||||
|
}
|
||||||
|
|
||||||
|
CONST Vec2 &GetLocalPosition() CONST
|
||||||
|
{
|
||||||
|
return m_local.Position;
|
||||||
|
}
|
||||||
|
|
||||||
|
CONST Vec2 &GetLocalScale() CONST
|
||||||
|
{
|
||||||
|
return m_local.Scale;
|
||||||
|
}
|
||||||
|
|
||||||
|
CONST FLOAT32 &GetLocalRotation() CONST
|
||||||
|
{
|
||||||
|
return m_local.Rotation;
|
||||||
|
}
|
||||||
|
|
||||||
|
UINT8 &Layer()
|
||||||
|
{
|
||||||
|
return m_layer;
|
||||||
|
}
|
||||||
|
|
||||||
|
INT16 &SortIndex()
|
||||||
|
{
|
||||||
|
return m_sortIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
CONST UINT8 &Layer() CONST
|
||||||
|
{
|
||||||
|
return m_layer;
|
||||||
|
}
|
||||||
|
|
||||||
|
CONST INT16 &SortIndex() CONST
|
||||||
|
{
|
||||||
|
return m_sortIndex;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
VOID RecalculatePosition()
|
||||||
|
{
|
||||||
|
m_global.Position = (m_parent ? m_parent->GetPosition() : Vec2{}) + m_local.Position;
|
||||||
|
for (auto &c : m_children)
|
||||||
|
c->RecalculatePosition();
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID RecalculateRotation()
|
||||||
|
{
|
||||||
|
m_global.Rotation = (m_parent ? m_parent->GetRotation() : 0) + m_local.Rotation;
|
||||||
|
for (auto &c : m_children)
|
||||||
|
c->RecalculateRotation();
|
||||||
|
}
|
||||||
|
|
||||||
|
VOID RecalculateScale()
|
||||||
|
{
|
||||||
|
m_global.Scale = (m_parent ? m_parent->GetScale() : Vec2{}) + m_local.Scale;
|
||||||
|
for (auto &c : m_children)
|
||||||
|
c->RecalculateScale();
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
RefPtr<Node2D> m_parent{};
|
||||||
|
Vector<IComponent *> m_components;
|
||||||
|
Vector<RefPtr<Node2D>> m_children{};
|
||||||
|
|
||||||
|
private:
|
||||||
|
struct
|
||||||
|
{
|
||||||
|
FLOAT32 Rotation{0.0f};
|
||||||
|
Vec2 Position{0.0f, 0.0f};
|
||||||
|
Vec2 Scale{1.0f, 1.0f};
|
||||||
|
} m_local{}, m_global{};
|
||||||
|
|
||||||
|
UINT8 m_layer{};
|
||||||
|
INT16 m_sortIndex{};
|
||||||
|
|
||||||
|
public:
|
||||||
|
VOID Draw();
|
||||||
|
VOID DebugDraw();
|
||||||
|
|
||||||
|
VOID Update();
|
||||||
|
VOID FixedUpdate();
|
||||||
|
};
|
||||||
|
} // namespace ia::iae
|
||||||
@ -16,7 +16,8 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <IAEngine/Nodes/INode.hpp>
|
#include <IAEngine/Nodes/Node2D.hpp>
|
||||||
|
#include <IAEngine/Components/SpriteComponent.hpp>
|
||||||
|
|
||||||
namespace ia::iae
|
namespace ia::iae
|
||||||
{
|
{
|
||||||
|
|||||||
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <IAEngine/Nodes/INode.hpp>
|
#include <IAEngine/Nodes/SpriteNode.hpp>
|
||||||
|
|
||||||
namespace ia::iae
|
namespace ia::iae
|
||||||
{
|
{
|
||||||
|
|||||||
@ -16,9 +16,23 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <IAEngine/Nodes/INode.hpp>
|
#include <IAEngine/Components/TextureComponent.hpp>
|
||||||
|
#include <IAEngine/Nodes/Node2D.hpp>
|
||||||
|
|
||||||
namespace ia::iae
|
namespace ia::iae
|
||||||
{
|
{
|
||||||
|
class TextureNode : public Node2D
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
IAE_DLL_API TextureNode(IN CONST String &name);
|
||||||
|
|
||||||
}
|
public:
|
||||||
|
TextureComponent *GetTextureComponent()
|
||||||
|
{
|
||||||
|
return m_textureComponent;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected:
|
||||||
|
TextureComponent *CONST m_textureComponent{};
|
||||||
|
};
|
||||||
|
} // namespace ia::iae
|
||||||
@ -16,7 +16,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <IAEngine/Nodes/INode.hpp>
|
#include <IAEngine/Nodes/TextureNode.hpp>
|
||||||
|
|
||||||
namespace ia::iae
|
namespace ia::iae
|
||||||
{
|
{
|
||||||
|
|||||||
0
Engine/Src/Inc/IAEngine/Nodes/TileMapNode.hpp
Normal file
1
Samples/SpaceInvaders/Resources/Sprites/LICENCE
Normal file
@ -0,0 +1 @@
|
|||||||
|
Shout out to Anim86 for this amazing sprite pack! https://anim86.itch.io/space-shoter-starter-pack
|
||||||
BIN
Samples/SpaceInvaders/Resources/Sprites/SpaceShip.png
Normal file
|
After Width: | Height: | Size: 21 KiB |
BIN
Samples/SpaceInvaders/Resources/Sprites/Stars-A.png
Normal file
|
After Width: | Height: | Size: 44 KiB |
BIN
Samples/SpaceInvaders/Resources/Sprites/Stars-B.png
Normal file
|
After Width: | Height: | Size: 20 KiB |
BIN
Samples/SpaceInvaders/Resources/Sprites/bg.png
Normal file
|
After Width: | Height: | Size: 86 KiB |
BIN
Samples/SpaceInvaders/Resources/Sprites/bonus_life.png
Normal file
|
After Width: | Height: | Size: 6.0 KiB |
BIN
Samples/SpaceInvaders/Resources/Sprites/bonus_shield.png
Normal file
|
After Width: | Height: | Size: 6.5 KiB |
BIN
Samples/SpaceInvaders/Resources/Sprites/bonus_time.png
Normal file
|
After Width: | Height: | Size: 7.8 KiB |
BIN
Samples/SpaceInvaders/Resources/Sprites/bullet-1.png
Normal file
|
After Width: | Height: | Size: 1.9 KiB |
BIN
Samples/SpaceInvaders/Resources/Sprites/bullet-2.png
Normal file
|
After Width: | Height: | Size: 1.9 KiB |
BIN
Samples/SpaceInvaders/Resources/Sprites/bullet.png
Normal file
|
After Width: | Height: | Size: 1.8 KiB |
BIN
Samples/SpaceInvaders/Resources/Sprites/fire.png
Normal file
|
After Width: | Height: | Size: 4.8 KiB |
BIN
Samples/SpaceInvaders/Resources/Sprites/insect-1.png
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
Samples/SpaceInvaders/Resources/Sprites/insect-2.png
Normal file
|
After Width: | Height: | Size: 15 KiB |
BIN
Samples/SpaceInvaders/Resources/Sprites/large-A.png
Normal file
|
After Width: | Height: | Size: 23 KiB |
BIN
Samples/SpaceInvaders/Resources/Sprites/large-B.png
Normal file
|
After Width: | Height: | Size: 20 KiB |
BIN
Samples/SpaceInvaders/Resources/Sprites/laser-1.png
Normal file
|
After Width: | Height: | Size: 3.1 KiB |
BIN
Samples/SpaceInvaders/Resources/Sprites/laser-2.png
Normal file
|
After Width: | Height: | Size: 3.0 KiB |
BIN
Samples/SpaceInvaders/Resources/Sprites/laser-3.png
Normal file
|
After Width: | Height: | Size: 3.0 KiB |
BIN
Samples/SpaceInvaders/Resources/Sprites/medium-A.png
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
Samples/SpaceInvaders/Resources/Sprites/medium-B.png
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
Samples/SpaceInvaders/Resources/Sprites/plasm.png
Normal file
|
After Width: | Height: | Size: 4.9 KiB |
BIN
Samples/SpaceInvaders/Resources/Sprites/rocket.png
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
BIN
Samples/SpaceInvaders/Resources/Sprites/shield.png
Normal file
|
After Width: | Height: | Size: 19 KiB |
BIN
Samples/SpaceInvaders/Resources/Sprites/small-A.png
Normal file
|
After Width: | Height: | Size: 8.0 KiB |
BIN
Samples/SpaceInvaders/Resources/Sprites/small-B.png
Normal file
|
After Width: | Height: | Size: 7.2 KiB |
BIN
Samples/SpaceInvaders/Resources/Sprites/support.png
Normal file
|
After Width: | Height: | Size: 4.9 KiB |
@ -16,14 +16,24 @@
|
|||||||
|
|
||||||
#include <Game.hpp>
|
#include <Game.hpp>
|
||||||
|
|
||||||
|
Handle g_spriteBG;
|
||||||
|
RefPtr<TextureNode> backgroundNode;
|
||||||
|
RefPtr<CameraNode> mainCamera;
|
||||||
|
|
||||||
C_DECL(IA_DLL_EXPORT VOID Game_OnInitialize())
|
C_DECL(IA_DLL_EXPORT VOID Game_OnInitialize())
|
||||||
{
|
{
|
||||||
GAME_LOG_INFO("Booting Game");
|
g_spriteBG = Engine::RescaleImage(Engine::CreateImageFromFile("Resources/Sprites/bg.png"), 800, 600);
|
||||||
|
|
||||||
|
mainCamera = MakeRefPtr<CameraNode>("MainCamera");
|
||||||
|
Engine::SetActiveCamera(mainCamera->GetCameraComponent());
|
||||||
|
|
||||||
|
backgroundNode = MakeRefPtr<TextureNode>("BG");
|
||||||
|
backgroundNode->GetTextureComponent()->SetTexture(g_spriteBG);
|
||||||
|
Engine::AddNodeToActiveScene(backgroundNode);
|
||||||
}
|
}
|
||||||
|
|
||||||
C_DECL(IA_DLL_EXPORT VOID Game_OnTerminate())
|
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_OnDebugDraw())
|
||||||
|
|||||||