Usable Engine
This commit is contained in:
@ -16,6 +16,12 @@
|
||||
|
||||
#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/Logger.hpp>
|
||||
#include <IACore/Memory.hpp>
|
||||
@ -108,6 +114,11 @@ namespace ia::iae
|
||||
UINT8 G{0xFF};
|
||||
UINT8 B{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 */
|
||||
|
||||
@ -20,8 +20,39 @@
|
||||
|
||||
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
|
||||
{
|
||||
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
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
|
||||
|
||||
#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/SoundEmitterComponent.hpp>
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
@ -25,96 +30,95 @@ namespace ia::iae
|
||||
{
|
||||
public:
|
||||
// Event Functions
|
||||
STATIC Handle CreateEvent(IN CONST String& name);
|
||||
STATIC VOID DestroyEvent(IN Handle event);
|
||||
STATIC Handle GetEventByName(IN CONST String& name);
|
||||
STATIC VOID AddEventListener(IN Handle event, IN std::function<VOID()> callback);
|
||||
STATIC VOID AddEventListener(IN CONST String& eventName, IN std::function<VOID()> callback);
|
||||
STATIC VOID BroadcastEvent(IN Handle event);
|
||||
STATIC VOID BroadcastEvent(IN CONST String& eventName);
|
||||
|
||||
// Physics Functions
|
||||
STATIC Handle CreatePhysicsBody();
|
||||
STATIC VOID DestroyPhysicsBody(IN Handle body);
|
||||
STATIC IAE_DLL_API Handle CreateEvent(IN CONST String& name);
|
||||
STATIC IAE_DLL_API VOID DestroyEvent(IN Handle event);
|
||||
STATIC IAE_DLL_API Handle GetEventByName(IN CONST String& name);
|
||||
STATIC IAE_DLL_API VOID AddEventListener(IN Handle event, IN std::function<VOID()> callback);
|
||||
STATIC IAE_DLL_API VOID AddEventListener(IN CONST String& eventName, IN std::function<VOID()> callback);
|
||||
STATIC IAE_DLL_API VOID BroadcastEvent(IN Handle event);
|
||||
STATIC IAE_DLL_API VOID BroadcastEvent(IN CONST String& eventName);
|
||||
|
||||
// Renderer Functions
|
||||
STATIC Handle GetGeometry_Quad();
|
||||
STATIC Handle CreateGeometry(IN CONST Vector<GeometryVertex>& vertices, IN CONST Vector<INT32>& indices);
|
||||
STATIC VOID DestroyGeometry(IN Handle geometry);
|
||||
STATIC VOID DrawGeometry(IN Handle handle);
|
||||
STATIC VOID ResizeDisplay(IN INT32 newWidth, IN INT32 newHeight);
|
||||
STATIC IAE_DLL_API Handle GetGeometry_Quad();
|
||||
STATIC IAE_DLL_API Handle CreateGeometry(IN CONST Vector<GeometryVertex>& vertices, IN CONST Vector<INT32>& indices);
|
||||
STATIC IAE_DLL_API VOID DestroyGeometry(IN Handle geometry);
|
||||
STATIC IAE_DLL_API VOID DrawGeometry(IN Handle handle);
|
||||
STATIC IAE_DLL_API VOID ResizeDisplay(IN INT32 newWidth, IN INT32 newHeight);
|
||||
|
||||
// Renderer State Functions
|
||||
STATIC VOID SetRenderState_Scissor(IN IVec4 rect);
|
||||
STATIC VOID SetRenderState_FlippedH(IN BOOL value);
|
||||
STATIC VOID SetRenderState_FlippedV(IN BOOL value);
|
||||
STATIC VOID SetRenderState_TextureOffset(IN Vec2 off);
|
||||
STATIC VOID SetRenderState_YSortingEnabled(IN BOOL value);
|
||||
STATIC VOID SetRenderState_ColorOverlay(IN Color color);
|
||||
STATIC VOID SetRenderState_CameraRelative(IN BOOL value);
|
||||
STATIC 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_Scissor(IN IVec4 rect);
|
||||
STATIC IAE_DLL_API VOID SetRenderState_FlippedH(IN BOOL value);
|
||||
STATIC IAE_DLL_API VOID SetRenderState_FlippedV(IN BOOL value);
|
||||
STATIC IAE_DLL_API VOID SetRenderState_TextureOffset(IN Vec2 off);
|
||||
STATIC IAE_DLL_API VOID SetRenderState_YSortingEnabled(IN BOOL value);
|
||||
STATIC IAE_DLL_API VOID SetRenderState_ColorOverlay(IN Color color);
|
||||
STATIC IAE_DLL_API VOID SetRenderState_CameraRelative(IN BOOL value);
|
||||
STATIC IAE_DLL_API VOID SetRenderState_Texture(IN Handle image);
|
||||
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
|
||||
STATIC VOID DebugDraw_SetColor(IN Color color);
|
||||
STATIC VOID DebugDraw_StrokeWidth(IN FLOAT32 width);
|
||||
STATIC VOID DebugDraw_Line(IN Vec2 from, IN Vec2 to);
|
||||
STATIC 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_SetColor(IN Color color);
|
||||
STATIC IAE_DLL_API VOID DebugDraw_StrokeWidth(IN FLOAT32 width);
|
||||
STATIC IAE_DLL_API VOID DebugDraw_Line(IN Vec2 from, IN Vec2 to);
|
||||
STATIC IAE_DLL_API VOID DebugDraw_FillRect(IN Vec2 position, IN Vec2 size);
|
||||
STATIC IAE_DLL_API VOID DebugDraw_StrokeRect(IN Vec2 position, IN Vec2 size);
|
||||
|
||||
// Resource Functions
|
||||
STATIC Handle CreateImage(IN PCUINT8 encodedData, IN SIZE_T encodedDataSize);
|
||||
STATIC Handle CreateImage(IN PCUINT8 rgbaData, IN INT32 width, IN INT32 height);
|
||||
STATIC Handle CreateSound(IN PCUINT8 encodedData, IN SIZE_T encodedDataSize);
|
||||
STATIC VOID DestroyImage(IN Handle image);
|
||||
STATIC VOID DestroySound(IN Handle sound);
|
||||
STATIC IVec2 GetImageExtent(IN Handle image);
|
||||
STATIC Handle RescaleImage(IN Handle image, IN INT32 newWidth, IN INT32 newHeight);
|
||||
STATIC Handle CombineImages(IN CONST Vector<Handle>& images, IN INT32 unitWidth, IN INT32 unitHeight, IN INT32 unitCountX, IN INT32 unitCountY);
|
||||
STATIC IAE_DLL_API Handle CreateImageFromFile(IN CONST String& path);
|
||||
STATIC IAE_DLL_API Handle CreateSoundFromFile(IN CONST String& path);
|
||||
STATIC IAE_DLL_API Handle CreateImage(IN PCUINT8 encodedData, IN SIZE_T encodedDataSize);
|
||||
STATIC IAE_DLL_API Handle CreateImage(IN PCUINT8 rgbaData, IN INT32 width, IN INT32 height);
|
||||
STATIC IAE_DLL_API Handle CreateSound(IN PCUINT8 encodedData, IN SIZE_T encodedDataSize);
|
||||
STATIC IAE_DLL_API VOID DestroyImage(IN Handle image);
|
||||
STATIC IAE_DLL_API VOID DestroySound(IN Handle sound);
|
||||
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
|
||||
STATIC VOID SetTimeScale(IN FLOAT32 scale);
|
||||
STATIC VOID SetActiveCamera(IN ICameraComponent* cameraComponent);
|
||||
STATIC IAE_DLL_API VOID SetTimeScale(IN FLOAT32 scale);
|
||||
STATIC IAE_DLL_API VOID SetActiveCamera(IN CameraComponent* cameraComponent);
|
||||
|
||||
// Scene Functions
|
||||
STATIC Handle CreateScene(IN CONST String& sceneXML);
|
||||
STATIC Handle CreateEmptyScene();
|
||||
STATIC VOID DestroyScene(IN Handle handle);
|
||||
STATIC VOID ChangeActiveScene(IN Handle scene);
|
||||
STATIC VOID AddNodeToActiveScene(IN RefPtr<INode> node);
|
||||
STATIC INode* GetNodeFromActiveScene(IN CONST String& name);
|
||||
STATIC VOID RemoveNodeFromActiveScene(IN CONST String& name);
|
||||
STATIC VOID AddNodeToScene(IN Handle scene, IN RefPtr<INode> node);
|
||||
STATIC VOID RemoveNodeFromScene(IN Handle scene, IN CONST String& name);
|
||||
STATIC IAE_DLL_API Handle CreateSceneFromFile(IN CONST String& path);
|
||||
STATIC IAE_DLL_API Handle CreateScene(IN CONST String& sceneXML);
|
||||
STATIC IAE_DLL_API Handle CreateEmptyScene();
|
||||
STATIC IAE_DLL_API VOID DestroyScene(IN Handle handle);
|
||||
STATIC IAE_DLL_API VOID ChangeActiveScene(IN Handle scene);
|
||||
STATIC IAE_DLL_API VOID AddNodeToActiveScene(IN RefPtr<INode> node);
|
||||
STATIC IAE_DLL_API INode* GetNodeFromActiveScene(IN CONST String& name);
|
||||
STATIC IAE_DLL_API VOID RemoveNodeFromActiveScene(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
|
||||
STATIC Vec2 GetInputAxis();
|
||||
STATIC VOID SwitchInputModeToText();
|
||||
STATIC VOID SwitchInputModeToAction();
|
||||
STATIC Vec2 GetInputPointerPosition();
|
||||
STATIC BOOL IsInputKeyDown(IN InputKey key);
|
||||
STATIC BOOL WasInputKeyPressed(IN InputKey key);
|
||||
STATIC BOOL WasInputKeyReleased(IN InputKey key);
|
||||
STATIC BOOL IsInputActionDown(IN Handle action);
|
||||
STATIC BOOL WasInputActionPressed(IN Handle action);
|
||||
STATIC BOOL WasInputActionReleased(IN Handle action);
|
||||
STATIC BOOL IsInputActionDown(IN CONST String& action);
|
||||
STATIC BOOL WasInputActionPressed(IN CONST String& action);
|
||||
STATIC BOOL WasInputActionReleased(IN CONST String& action);
|
||||
STATIC 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 Vec2 GetInputAxis();
|
||||
STATIC IAE_DLL_API VOID SwitchInputModeToText();
|
||||
STATIC IAE_DLL_API VOID SwitchInputModeToAction();
|
||||
STATIC IAE_DLL_API Vec2 GetInputPointerPosition();
|
||||
STATIC IAE_DLL_API BOOL IsInputKeyDown(IN InputKey key);
|
||||
STATIC IAE_DLL_API BOOL WasInputKeyPressed(IN InputKey key);
|
||||
STATIC IAE_DLL_API BOOL WasInputKeyReleased(IN InputKey key);
|
||||
STATIC IAE_DLL_API BOOL IsInputActionDown(IN Handle action);
|
||||
STATIC IAE_DLL_API BOOL WasInputActionPressed(IN Handle action);
|
||||
STATIC IAE_DLL_API BOOL WasInputActionReleased(IN Handle action);
|
||||
STATIC IAE_DLL_API BOOL IsInputActionDown(IN CONST String& action);
|
||||
STATIC IAE_DLL_API BOOL WasInputActionPressed(IN CONST String& action);
|
||||
STATIC IAE_DLL_API BOOL WasInputActionReleased(IN CONST String& action);
|
||||
STATIC IAE_DLL_API Handle BindInputAction(IN CONST String& name, IN InputKey key);
|
||||
STATIC IAE_DLL_API VOID BindInputAxis(IN InputKey upKey, IN InputKey downKey, IN InputKey leftKey, IN InputKey rightKey);
|
||||
|
||||
// Random Functions
|
||||
STATIC FLOAT32 GetRandomFloat();
|
||||
STATIC INT32 GetRandomInRange(IN INT32 min, IN INT32 max);
|
||||
STATIC IAE_DLL_API FLOAT32 GetRandomFloat();
|
||||
STATIC IAE_DLL_API INT32 GetRandomInRange(IN INT32 min, IN INT32 max);
|
||||
|
||||
// Time Functions
|
||||
STATIC INT64 GetTickCount();
|
||||
STATIC INT64 GetUnixSecond();
|
||||
STATIC INT64 GetUnixMillisecond();
|
||||
STATIC FLOAT32 GetFrameDeltaTime();
|
||||
STATIC IAE_DLL_API INT64 GetTickCount();
|
||||
STATIC IAE_DLL_API INT64 GetUnixSecond();
|
||||
STATIC IAE_DLL_API INT64 GetUnixMillisecond();
|
||||
STATIC IAE_DLL_API FLOAT32 GetFrameDeltaTime();
|
||||
|
||||
// Engine Functions
|
||||
STATIC BOOL IsDebugMode();
|
||||
STATIC IAE_DLL_API BOOL IsDebugMode();
|
||||
};
|
||||
}
|
||||
@ -18,10 +18,4 @@
|
||||
|
||||
#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));
|
||||
|
||||
38
Engine/Src/Inc/IAEngine/Nodes/CameraNode.hpp
Normal file
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
|
||||
{
|
||||
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
|
||||
|
||||
#include <IAEngine/Components/IComponent.hpp>
|
||||
#include <IAEngine/Nodes/INode.hpp>
|
||||
|
||||
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
|
||||
|
||||
#include <IAEngine/Nodes/INode.hpp>
|
||||
#include <IAEngine/Nodes/Node2D.hpp>
|
||||
#include <IAEngine/Components/SpriteComponent.hpp>
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
|
||||
@ -16,7 +16,7 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <IAEngine/Nodes/INode.hpp>
|
||||
#include <IAEngine/Nodes/SpriteNode.hpp>
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
|
||||
@ -16,9 +16,23 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <IAEngine/Nodes/INode.hpp>
|
||||
#include <IAEngine/Components/TextureComponent.hpp>
|
||||
#include <IAEngine/Nodes/Node2D.hpp>
|
||||
|
||||
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
|
||||
|
||||
#include <IAEngine/Nodes/INode.hpp>
|
||||
#include <IAEngine/Nodes/TextureNode.hpp>
|
||||
|
||||
namespace ia::iae
|
||||
{
|
||||
|
||||
0
Engine/Src/Inc/IAEngine/Nodes/TileMapNode.hpp
Normal file
0
Engine/Src/Inc/IAEngine/Nodes/TileMapNode.hpp
Normal file
Reference in New Issue
Block a user