diff --git a/Duin/Duin.vcxproj b/Duin/Duin.vcxproj
index a4f78a0..f94d50d 100644
--- a/Duin/Duin.vcxproj
+++ b/Duin/Duin.vcxproj
@@ -161,7 +161,14 @@ IF EXIST ..\bin\Dist-windows-x86_64\Duin\Duin.dll\ (xcopy /Q /E /Y /I ..\bin\Dis
+
+
+
+
+
+
+
@@ -180,6 +187,8 @@ IF EXIST ..\bin\Dist-windows-x86_64\Duin\Duin.dll\ (xcopy /Q /E /Y /I ..\bin\Dis
+
+
@@ -193,19 +202,27 @@ IF EXIST ..\bin\Dist-windows-x86_64\Duin\Duin.dll\ (xcopy /Q /E /Y /I ..\bin\Dis
-
-
+
+
+
+
+
+
+
+
+
+
@@ -214,10 +231,8 @@ IF EXIST ..\bin\Dist-windows-x86_64\Duin\Duin.dll\ (xcopy /Q /E /Y /I ..\bin\Dis
-
-
Create
diff --git a/Duin/Duin.vcxproj.filters b/Duin/Duin.vcxproj.filters
index 3a5a8e1..8722eda 100644
--- a/Duin/Duin.vcxproj.filters
+++ b/Duin/Duin.vcxproj.filters
@@ -136,21 +136,24 @@
Duin\Events
-
- Duin\Graphics
-
Duin\Object
Duin\Object\Node
-
- Duin\Object
-
+
+
+
+
+
+
+
+
+
@@ -192,19 +195,23 @@
Duin\Events
-
- Duin\Graphics
-
Duin\Object
Duin\Object\Node
-
- Duin\Object
-
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/Duin/src/Duin.h b/Duin/src/Duin.h
index d2fff36..3bedb55 100644
--- a/Duin/src/Duin.h
+++ b/Duin/src/Duin.h
@@ -18,14 +18,16 @@
#include "Duin/Core/Structures/RenderStructs.h"
#include "Duin/Core/Structures/QuadTree.h"
#include "Duin/Core/Structures/Delaunay.h"
+#include "Duin/Core/Scene/Object.h"
#include "Duin/Core/Scene/SceneManager.h"
// ---------- Events -----------
#include "Duin/Events/InputEvent.h"
#include "Duin/Events/InputMap.h"
-// ---------- Graphics -----------
+// ---------- Assets -----------
#include "Duin/Assets/TextureResource.h"
+#include "Duin/Assets/AssetManager.h"
// ---------- Entities -----------
#include "Duin/Entity/Entity.h"
@@ -38,7 +40,6 @@
// ---------- [DEPRECIATED] -----------
// ---------- Objects -----------
-#include "Duin/Object/Object.h"
#include "Duin/Object/Node.h"
#include "Duin/Object/Blackboard.h"
diff --git a/Duin/src/Duin/Assets/AnimatedSprite2D.cpp b/Duin/src/Duin/Assets/AnimatedSprite2D.cpp
new file mode 100644
index 0000000..111966d
--- /dev/null
+++ b/Duin/src/Duin/Assets/AnimatedSprite2D.cpp
@@ -0,0 +1,8 @@
+#include "dnpch.h"
+
+#include "AnimatedSprite2D.h"
+
+namespace Duin
+{
+
+}
\ No newline at end of file
diff --git a/Duin/src/Duin/Assets/AnimatedSprite2D.h b/Duin/src/Duin/Assets/AnimatedSprite2D.h
new file mode 100644
index 0000000..a7144c5
--- /dev/null
+++ b/Duin/src/Duin/Assets/AnimatedSprite2D.h
@@ -0,0 +1,15 @@
+#pragma once
+
+#include "Duin/Core/Core.h"
+#include "Duin/Core/Scene/Object.h"
+
+namespace Duin
+{
+ class DUIN_API AnimatedSprite2D : public Object
+ {
+ public:
+
+ private:
+
+ };
+}
\ No newline at end of file
diff --git a/Duin/src/Duin/Assets/Asset.cpp b/Duin/src/Duin/Assets/Asset.cpp
new file mode 100644
index 0000000..c1bb84e
--- /dev/null
+++ b/Duin/src/Duin/Assets/Asset.cpp
@@ -0,0 +1,30 @@
+#include "dnpch.h"
+
+#include "Asset.h"
+#include "Duin/Assets/AssetManager.h"
+
+namespace Duin
+{
+ Asset::Asset()
+ {
+ }
+
+ Asset::Asset(AssetManager* assetManager)
+ : assetManager(assetManager)
+ {
+ }
+
+ Asset::~Asset()
+ {
+ }
+
+ void Asset::SetAssetManager(AssetManager* assetManager)
+ {
+ this->assetManager = assetManager;
+ }
+
+ AssetManager* Asset::GetAssetManager()
+ {
+ return assetManager;
+ }
+}
\ No newline at end of file
diff --git a/Duin/src/Duin/Assets/Asset.h b/Duin/src/Duin/Assets/Asset.h
new file mode 100644
index 0000000..c6d8011
--- /dev/null
+++ b/Duin/src/Duin/Assets/Asset.h
@@ -0,0 +1,28 @@
+#pragma once
+
+#include "Duin/Core/Core.h"
+#include "Duin/Core/UUID.h"
+
+namespace Duin
+{
+ class AssetManager;
+
+ /*
+ * A wrapper for the _Asset class.
+ * The client will interact with this class, and children.
+ */
+ class DUIN_API Asset
+ {
+ public:
+ Asset();
+ Asset(AssetManager* assetManager);
+ ~Asset();
+
+ void SetAssetManager(AssetManager* assetManager);
+ AssetManager* GetAssetManager();
+
+ private:
+ UUID uuid;
+ AssetManager* assetManager = nullptr;
+ };
+}
\ No newline at end of file
diff --git a/Duin/src/Duin/Assets/AssetManager.cpp b/Duin/src/Duin/Assets/AssetManager.cpp
index d0f9bec..ba7e365 100644
--- a/Duin/src/Duin/Assets/AssetManager.cpp
+++ b/Duin/src/Duin/Assets/AssetManager.cpp
@@ -12,7 +12,13 @@ namespace Duin
{
}
- void AssetManager::LoadTexture(const char* texturePath)
+ void AssetManager::AddToAssetRegistry(std::shared_ptr<_Asset> asset)
{
+ assetRegistry[asset->guid] = asset;
+ }
+
+ void AssetManager::RemoveFromAssetRegistry(GUID guid)
+ {
+ assetRegistry.erase(guid);
}
}
\ No newline at end of file
diff --git a/Duin/src/Duin/Assets/AssetManager.h b/Duin/src/Duin/Assets/AssetManager.h
index 337002f..7fd2e8e 100644
--- a/Duin/src/Duin/Assets/AssetManager.h
+++ b/Duin/src/Duin/Assets/AssetManager.h
@@ -3,10 +3,13 @@
#include "Duin/Core/Core.h"
#include "Duin/Core/UUID.h"
#include "Duin/Core/Structures/RenderStructs.h"
+#include "Duin/Assets/GUID.h"
+#include "Duin/Assets/AssetStructs.h"
#include "RLImGuiComponent.h"
#include
+#include
namespace Duin
{
@@ -16,9 +19,34 @@ namespace Duin
AssetManager();
~AssetManager();
- void LoadTexture(const char* texturePath);
+ template
+ std::shared_ptr LoadAsset(const char* path);
+
+ void AddToAssetRegistry(std::shared_ptr<_Asset> asset);
+ void RemoveFromAssetRegistry(GUID guid);
private:
- std::unordered_map> textureMap;
+ std::unordered_map> assetRegistry;
};
+
+ template
+ inline std::shared_ptr AssetManager::LoadAsset(const char* path)
+ {
+ static_assert(std::is_base_of<_Asset, ASSET>::value, "ASSET must be a _Asset derived struct!");
+ static_assert(std::is_base_of<_AssetFactory, FACTORY>::value, "FACTORY must be a _AssetFactory derived class!");
+
+ // Check for existing Asset
+ GUID guid(path);
+ auto it = assetRegistry.find(guid);
+ if (it != assetRegistry.end())
+ {
+ return std::dynamic_pointer_cast(it->second);
+ }
+
+ // Else load/create Asset
+ FACTORY* factory = new FACTORY();
+ std::shared_ptr<_Asset> asset = factory->CreateAsset(this, path);
+ AddToAssetRegistry(asset);
+ return std::dynamic_pointer_cast(asset);
+ }
}
\ No newline at end of file
diff --git a/Duin/src/Duin/Assets/AssetStructs.cpp b/Duin/src/Duin/Assets/AssetStructs.cpp
new file mode 100644
index 0000000..5796bb7
--- /dev/null
+++ b/Duin/src/Duin/Assets/AssetStructs.cpp
@@ -0,0 +1,25 @@
+#include "dnpch.h"
+
+#include "AssetStructs.h"
+#include "AssetManager.h"
+
+namespace Duin
+{
+ std::shared_ptr<_Asset> _TextureAssetFactory::CreateAsset(AssetManager* assetManager, const char* path)
+ {
+ // TODO
+ ::Texture rlTexture = ::LoadTexture(path);
+ std::shared_ptr<_TextureAsset> textureAsset = std::make_shared<_TextureAsset>(rlTexture);
+
+ return textureAsset;
+ }
+
+ std::shared_ptr<_Asset> _ImageAssetFactory::CreateAsset(AssetManager* assetManager, const char* path)
+ {
+ // TODO
+ ::Image rlImage = ::LoadImage(path);
+ std::shared_ptr<_ImageAsset> imageAsset = std::make_shared<_ImageAsset>(rlImage);
+
+ return imageAsset;
+ }
+}
\ No newline at end of file
diff --git a/Duin/src/Duin/Assets/AssetStructs.h b/Duin/src/Duin/Assets/AssetStructs.h
new file mode 100644
index 0000000..20ec110
--- /dev/null
+++ b/Duin/src/Duin/Assets/AssetStructs.h
@@ -0,0 +1,96 @@
+#pragma once
+
+#include "Duin/Core/Core.h"
+#include "Duin/Assets/GUID.h"
+#include "Duin/Core/Maths/DuinMaths.h"
+
+#include
+
+namespace Duin
+{
+ class AssetManager;
+
+ /*
+ * Base Asset structs
+ *
+ * These structs are used by the engine to store the assets loaded from storage.
+ *
+ */
+
+ struct DUIN_API _Asset
+ {
+ virtual ~_Asset() = default;
+ GUID guid; // Base resource GUID
+
+ _Asset() {}
+ _Asset(const char* path) : guid(path) {}
+ };
+
+ class DUIN_API _AssetFactory
+ {
+ _AssetFactory() = default;
+ ~_AssetFactory() = default;
+
+ virtual std::shared_ptr<_Asset> CreateAsset(AssetManager* assetManager, const char* path) = 0;
+ };
+
+
+
+ // Texture, tex data stored in GPU memory (VRAM)
+ struct DUIN_API _TextureAsset : public _Asset
+ {
+ unsigned int id; // OpenGL texture id
+ int width; // Texture base width
+ int height; // Texture base height
+ int mipmaps; // Mipmap levels, 1 by default
+ int format; // Data format (PixelFormat type)
+
+ _TextureAsset(const char* path)
+ : _Asset(path), id(0), width(0), height(0), mipmaps(1), format(0) {} // Default constructor
+
+ _TextureAsset(const ::Texture& texture, const char* path) // Conversion constructor from raylib::Texture
+ : _Asset(path), id(texture.id), width(texture.width), height(texture.height),
+ mipmaps(texture.mipmaps), format(texture.format) {}
+
+ ::Texture ToRaylibTexture() const // Method to convert back to raylib::Texture
+ {
+ return { id, width, height, mipmaps, format };
+ }
+ };
+
+ class DUIN_API _TextureAssetFactory : public _AssetFactory
+ {
+ public:
+ std::shared_ptr<_Asset> CreateAsset(AssetManager* assetManager, const char* path) override;
+ };
+
+
+
+ // Image, pixel data stored in CPU memory (RAM)
+ struct DUIN_API _ImageAsset : public _Asset
+ {
+ void* data; // Image raw data
+ int width; // Image base width
+ int height; // Image base height
+ int mipmaps; // Mipmap levels, 1 by default
+ int format; // Data format (PixelFormat type)
+
+ _ImageAsset(const char* path)
+ : _Asset(path), data(nullptr), width(0), height(0), mipmaps(1), format(0) {} // Default constructor
+
+ _ImageAsset(const ::Image& image, const char* path) // Conversion constructor from raylib::Image
+ : _Asset(path), data(image.data), width(image.width), height(image.height),
+ mipmaps(image.mipmaps), format(image.format) {}
+
+ ::Image ToRaylibImage() const // Method to convert back to raylib::Image
+ {
+ return { data, width, height, mipmaps, format };
+ }
+ };
+
+ class DUIN_API _ImageAssetFactory : public _AssetFactory
+ {
+ public:
+ std::shared_ptr<_Asset> CreateAsset(AssetManager* assetManager, const char* path) override;
+ };
+}
\ No newline at end of file
diff --git a/Duin/src/Duin/Assets/GUID.cpp b/Duin/src/Duin/Assets/GUID.cpp
new file mode 100644
index 0000000..b26e40e
--- /dev/null
+++ b/Duin/src/Duin/Assets/GUID.cpp
@@ -0,0 +1,29 @@
+#include "dnpch.h"
+
+#include "GUID.h"
+
+namespace Duin
+{
+ GUID::GUID()
+ {
+ }
+
+ GUID::GUID(const std::string& path)
+ {
+ Generate(path);
+ }
+ GUID::GUID(const char* path)
+ {
+ Generate(std::string(path));
+ }
+
+ void GUID::Generate(const std::string& path)
+ {
+ guid = std::hash{}(path);
+ }
+
+ size_t GUID::Get() const
+ {
+ return guid;
+ }
+}
\ No newline at end of file
diff --git a/Duin/src/Duin/Assets/GUID.h b/Duin/src/Duin/Assets/GUID.h
new file mode 100644
index 0000000..9661819
--- /dev/null
+++ b/Duin/src/Duin/Assets/GUID.h
@@ -0,0 +1,50 @@
+#pragma once
+
+#include "Duin/Core/Core.h"
+
+#include
+#include
+
+namespace Duin
+{
+ class DUIN_API GUID
+ {
+ public:
+ GUID();
+ GUID(const std::string& path);
+ GUID(const char* path);
+
+ void Generate(const std::string& path);
+
+ size_t Get() const;
+
+ bool operator==(const GUID& other) const
+ {
+ return guid == other.guid;
+ }
+
+ bool operator!=(const GUID& other) const
+ {
+ return guid != other.guid;
+ }
+
+ bool operator<(const GUID& other) const
+ {
+ return guid < other.guid;
+ }
+ private:
+ size_t guid = 0;
+ };
+}
+
+namespace std
+{
+ template <>
+ struct hash
+ {
+ size_t operator()(const Duin::GUID& guid) const
+ {
+ return guid.Get();
+ }
+ };
+}
\ No newline at end of file
diff --git a/Duin/src/Duin/Assets/Image.cpp b/Duin/src/Duin/Assets/Image.cpp
new file mode 100644
index 0000000..b87525e
--- /dev/null
+++ b/Duin/src/Duin/Assets/Image.cpp
@@ -0,0 +1,14 @@
+#include "dnpch.h"
+
+#include "Image.h"
+
+namespace Duin
+{
+ Image::Image()
+ {
+ }
+
+ Image::~Image()
+ {
+ }
+}
\ No newline at end of file
diff --git a/Duin/src/Duin/Assets/Image.h b/Duin/src/Duin/Assets/Image.h
new file mode 100644
index 0000000..995aa97
--- /dev/null
+++ b/Duin/src/Duin/Assets/Image.h
@@ -0,0 +1,20 @@
+#pragma once
+
+#include "Duin/Core/Core.h"
+#include "Duin/Core/Scene/Object.h"
+#include "Duin/Assets/AssetStructs.h"
+
+#include
+
+namespace Duin
+{
+ class DUIN_API Image : public Object
+ {
+ public:
+ Image();
+ ~Image();
+
+ private:
+ std::shared_ptr<_ImageAsset> imageAsset;
+ };
+}
\ No newline at end of file
diff --git a/Duin/src/Duin/Assets/Particle2D.cpp b/Duin/src/Duin/Assets/Particle2D.cpp
new file mode 100644
index 0000000..a7becaf
--- /dev/null
+++ b/Duin/src/Duin/Assets/Particle2D.cpp
@@ -0,0 +1,8 @@
+#include "dnpch.h"
+
+#include "Particle2D.h"
+
+namespace Duin
+{
+
+}
\ No newline at end of file
diff --git a/Duin/src/Duin/Assets/Particle2D.h b/Duin/src/Duin/Assets/Particle2D.h
index 03c8620..b935971 100644
--- a/Duin/src/Duin/Assets/Particle2D.h
+++ b/Duin/src/Duin/Assets/Particle2D.h
@@ -1,10 +1,11 @@
#pragma once
#include "Duin/Core/Core.h"
+#include "Duin/Core/Scene/Object.h"
namespace Duin
{
- class DUIN_API Particle2D
+ class DUIN_API Particle2D : public Object
{
public:
diff --git a/Duin/src/Duin/Assets/Sprite2D.cpp b/Duin/src/Duin/Assets/Sprite2D.cpp
new file mode 100644
index 0000000..d7ceb20
--- /dev/null
+++ b/Duin/src/Duin/Assets/Sprite2D.cpp
@@ -0,0 +1,29 @@
+#include "dnpch.h"
+
+#include "Sprite2D.h"
+
+namespace Duin
+{
+ Sprite2D::Sprite2D()
+ {
+ }
+
+ Sprite2D::Sprite2D(std::shared_ptr texture)
+ : texture(texture)
+ {
+ }
+
+ Sprite2D::~Sprite2D()
+ {
+ }
+
+ void Sprite2D::SetTexture(std::shared_ptr texture)
+ {
+ this->texture = texture;
+ }
+
+ std::shared_ptr Sprite2D::GetTexture()
+ {
+ return texture;
+ }
+}
\ No newline at end of file
diff --git a/Duin/src/Duin/Assets/Sprite2D.h b/Duin/src/Duin/Assets/Sprite2D.h
new file mode 100644
index 0000000..9541fb9
--- /dev/null
+++ b/Duin/src/Duin/Assets/Sprite2D.h
@@ -0,0 +1,24 @@
+#pragma once
+
+#include "Duin/Core/Core.h"
+#include "Duin/Core/Scene/Object.h"
+#include "Duin/Assets/Texture.h"
+#include "Duin/Core/Maths/DuinMaths.h"
+
+namespace Duin
+{
+ class DUIN_API Sprite2D : public Object
+ {
+ public:
+ Sprite2D();
+ Sprite2D(std::shared_ptr texture);
+ ~Sprite2D();
+
+ void SetTexture(std::shared_ptr texture);
+ std::shared_ptr GetTexture();
+
+ private:
+ std::shared_ptr texture;
+ Transform2D transform;
+ };
+}
\ No newline at end of file
diff --git a/Duin/src/Duin/Assets/Texture.cpp b/Duin/src/Duin/Assets/Texture.cpp
new file mode 100644
index 0000000..97ac333
--- /dev/null
+++ b/Duin/src/Duin/Assets/Texture.cpp
@@ -0,0 +1,37 @@
+#include "dnpch.h"
+
+#include "Texture.h"
+#include "Duin/Assets/AssetManager.h"
+
+
+namespace Duin
+{
+ Texture::Texture()
+ {
+ }
+
+ Texture::Texture(AssetManager* assetManager, const char* path)
+ : Asset(assetManager)
+ {
+ _textureAsset = assetManager->LoadAsset<_TextureAsset, _TextureAssetFactory>(path);
+ }
+
+ Texture::~Texture()
+ {
+ }
+
+ Vector2 Texture::GetTextureSize()
+ {
+ return Vector2{ (int)_textureAsset->width, (int)_textureAsset->height };
+ }
+
+ void Texture::SetCentered(bool centered)
+ {
+ this->centered = centered;
+ }
+
+ void Texture::Draw(Vector2 position, float rotation)
+ {
+ // TODO
+ }
+}
\ No newline at end of file
diff --git a/Duin/src/Duin/Assets/Texture.h b/Duin/src/Duin/Assets/Texture.h
new file mode 100644
index 0000000..3821ae9
--- /dev/null
+++ b/Duin/src/Duin/Assets/Texture.h
@@ -0,0 +1,37 @@
+#pragma once
+
+#include "Duin/Core/Core.h"
+#include "Duin/Assets/AssetStructs.h"
+#include "Duin/Assets/Asset.h"
+#include "Duin/Assets/GUID.h"
+#include "Duin/Core/Maths/DuinMaths.h"
+
+#include
+
+namespace Duin
+{
+ class AssetManager;
+
+ /*
+ * Wrapper class for the _TextureAsset struct.
+ * The client will interact with the textures through this class.
+ */
+ class DUIN_API Texture : public Asset
+ {
+ public:
+ Texture();
+ Texture(AssetManager* assetManager, const char* path);
+ ~Texture();
+
+ Vector2 GetTextureSize();
+
+ void SetCentered(bool centered);
+
+ void Draw(Vector2 position, float rotation);
+
+ private:
+ std::shared_ptr<_TextureAsset> _textureAsset;
+ bool centered = false;
+
+ };
+}
\ No newline at end of file
diff --git a/Duin/src/Duin/Assets/TextureResource.cpp b/Duin/src/Duin/Assets/TextureResource.cpp
deleted file mode 100644
index 0f312b2..0000000
--- a/Duin/src/Duin/Assets/TextureResource.cpp
+++ /dev/null
@@ -1,113 +0,0 @@
-#include "dnpch.h"
-
-#include "TextureResource.h"
-
-namespace Duin
-{
- TextureResource::TextureResource()
- {
- }
-
- TextureResource::TextureResource(const char* texturePath)
- {
-
- LoadTexture(texturePath);
- SetTextureSize(texturePtr->width, texturePtr->height);
- }
-
- TextureResource::TextureResource(const char* texturePath, float width, float height)
- {
- LoadTexture(texturePath);
- SetTextureSize(width, height);
- }
-
- TextureResource::TextureResource(const char* texturePath, Vector2 size)
- {
- LoadTexture(texturePath);
- SetTextureSize(size);
- }
-
- TextureResource::~TextureResource()
- {
-
- }
-
- TextureResource& TextureResource::LoadTexture(const char* texturePath)
- {
- ::Texture texture = ::LoadTexture(texturePath); // supposed to call Raylib's LoadTexture()
- texturePtr.reset(new ::Texture(texture), [](::Texture* ptr) {
- UnloadTexture(*ptr); // Custom deleter that calls Raylib's UnloadTexture
- delete ptr; // Delete the pointer after unloading the texture
- });
- return *this;
- }
-
- TextureResource& TextureResource::SetTextureSize(float width, float height)
- {
- textureSize = Vector2(width, height);
- return *this;
- }
-
- TextureResource& TextureResource::SetTextureSize(Vector2 size)
- {
- textureSize = size;
- return *this;
- }
-
- TextureResource& TextureResource::Draw(float posX, float posY, float rotation_deg)
- {
- if (!texturePtr)
- {
- DN_CORE_WARN("TextureRes texture pointer not set!");
- return *this;
- }
-
- Draw(Vector2{ posX, posY }, rotation_deg);
- return *this;
- }
-
- TextureResource& TextureResource::Draw(Vector2 position, float rotation_deg)
- {
- if (!texturePtr)
- {
- DN_CORE_WARN("TextureRes texture pointer not set!");
- return *this;
- }
-
- Vector2 origin = Vector2::ZERO;
- if (isCentered)
- {
- position -= textureSize / 2;
- origin += textureSize / 2;
- }
-
- ::DrawTexturePro
- (
- *(texturePtr),
- { 0, 0, (float)texturePtr->width, (float)texturePtr->height },
- { position.x, position.y, textureSize.x, textureSize.y },
- { origin.x, origin.y },
- rotation_deg,
- { tintColor.r, tintColor.g, tintColor.b, tintColor.a }
- );
- //std::cout << "Drawing texture with size: " << textureSize.x << ", " << textureSize.y << "\n";
- return *this;
- }
-
- TextureResource& TextureResource::SetCentered(bool centered)
- {
- isCentered = centered;
- return *this;
- }
-
- TextureResource& TextureResource::SetTintColor(Color color)
- {
- tintColor = color;
- return *this;
- }
-
- void TextureResource::ClearTexture()
- {
- texturePtr.reset();
- }
-}
\ No newline at end of file
diff --git a/Duin/src/Duin/Assets/TextureResource.h b/Duin/src/Duin/Assets/TextureResource.h
deleted file mode 100644
index 1798901..0000000
--- a/Duin/src/Duin/Assets/TextureResource.h
+++ /dev/null
@@ -1,41 +0,0 @@
-#pragma once
-#include "dnpch.h"
-
-#include "Duin/Core/Core.h"
-#include "Duin/Core/Debug/Log.h"
-#include "Duin/Core/Maths/DuinMaths.h"
-#include "Duin/Core/Structures/RenderStructs.h"
-
-#include
-
-namespace Duin
-{
- class DUIN_API TextureResource
- {
- public:
- TextureResource();
- TextureResource(const char* texturePath);
- TextureResource(const char* texturePath, float width, float height);
- TextureResource(const char* texturePath, Vector2 size);
- ~TextureResource();
-
-
- TextureResource& LoadTexture(const char* texturePath);
- TextureResource& SetTextureSize(float width, float height);
- TextureResource& SetTextureSize(Vector2 size);
-
- TextureResource& Draw(float posX, float posY, float rotation_deg);
- TextureResource& Draw(Vector2 position, float rotation_deg);
-
- TextureResource& SetCentered(bool centered);
- TextureResource& SetTintColor(Color color);
-
- void ClearTexture();
-
- private:
- std::shared_ptr<::Texture> texturePtr;
- Vector2 textureSize;
- bool isCentered = false;
- Color tintColor = WHITE;
- };
-}
\ No newline at end of file
diff --git a/Duin/src/Duin/Core/Maths/src/Mat2x2.h b/Duin/src/Duin/Core/Maths/src/Mat2x2.h
index bb9fc99..d3b5104 100644
--- a/Duin/src/Duin/Core/Maths/src/Mat2x2.h
+++ b/Duin/src/Duin/Core/Maths/src/Mat2x2.h
@@ -5,11 +5,15 @@
namespace Duin
{
- struct DUIN_MATHS_API Matrix2x2
+ struct DUIN_MATHS_API Mat2x2
{
+ #define Mat2x2_ZERO Mat2x2(0, 0, 0, 0)
+ #define Mat2x2_IDENTITY Mat2x2(1, 0, 0, 1)
+ #define Mat2x2_ONE Mat2x2(1, 1, 1, 1)
+
float m[2][2];
- Matrix2x2()
+ Mat2x2()
{
for (int i = 0; i < 2; ++i)
{
@@ -20,7 +24,7 @@ namespace Duin
}
}
- Matrix2x2(float a, float b, float c, float d)
+ Mat2x2(float a, float b, float c, float d)
{
m[0][0] = a;
m[0][1] = b;
@@ -28,21 +32,21 @@ namespace Duin
m[1][1] = d;
}
- static Matrix2x2 Rotate(float angle)
+ static Mat2x2 Rotate(float angle)
{
float c = cos(angle);
float s = sin(angle);
- return Matrix2x2(c, -s, s, c);
+ return Mat2x2(c, -s, s, c);
}
- static Matrix2x2 Scale(float sx, float sy)
+ static Mat2x2 Scale(float sx, float sy)
{
- return Matrix2x2(sx, 0, 0, sy);
+ return Mat2x2(sx, 0, 0, sy);
}
- Matrix2x2 operator+(const Matrix2x2& other) const
+ Mat2x2 operator+(const Mat2x2& other) const
{
- return Matrix2x2(
+ return Mat2x2(
m[0][0] + other.m[0][0],
m[0][1] + other.m[0][1],
m[1][0] + other.m[1][0],
@@ -50,9 +54,9 @@ namespace Duin
);
}
- Matrix2x2 operator-(const Matrix2x2& other) const
+ Mat2x2 operator-(const Mat2x2& other) const
{
- return Matrix2x2(
+ return Mat2x2(
m[0][0] - other.m[0][0],
m[0][1] - other.m[0][1],
m[1][0] - other.m[1][0],
@@ -60,13 +64,13 @@ namespace Duin
);
}
- Matrix2x2 operator+=(const Matrix2x2& other)
+ Mat2x2 operator+=(const Mat2x2& other)
{
m[0][0] += other.m[0][0];
m[0][1] += other.m[0][1];
m[1][0] += other.m[1][0];
m[1][1] += other.m[1][1];
- return Matrix2x2(
+ return Mat2x2(
m[0][0],
m[0][1],
m[1][0],
@@ -74,13 +78,13 @@ namespace Duin
);
}
- Matrix2x2 operator-=(const Matrix2x2& other)
+ Mat2x2 operator-=(const Mat2x2& other)
{
m[0][0] -= other.m[0][0];
m[0][1] -= other.m[0][1];
m[1][0] -= other.m[1][0];
m[1][1] -= other.m[1][1];
- return Matrix2x2(
+ return Mat2x2(
m[0][0],
m[0][1],
m[1][0],
@@ -88,9 +92,9 @@ namespace Duin
);
}
- Matrix2x2 operator*(const Matrix2x2& other) const
+ Mat2x2 operator*(const Mat2x2& other) const
{
- return Matrix2x2(
+ return Mat2x2(
m[0][0] * other.m[0][0] + m[0][1] * other.m[1][0],
m[0][0] * other.m[0][1] + m[0][1] * other.m[1][1],
m[1][0] * other.m[0][0] + m[1][1] * other.m[1][0],
diff --git a/Duin/src/Duin/Core/Maths/src/Transform2D.h b/Duin/src/Duin/Core/Maths/src/Transform2D.h
index d595f86..4e1d17c 100644
--- a/Duin/src/Duin/Core/Maths/src/Transform2D.h
+++ b/Duin/src/Duin/Core/Maths/src/Transform2D.h
@@ -11,19 +11,29 @@ namespace Duin
struct DUIN_MATHS_API Transform2D
{
Vector2 origin;
- Matrix2x2 transform;
+ Mat2x2 transform;
Transform2D()
: origin(0, 0), transform()
{}
- Transform2D(const Vector2& origin, const Matrix2x2& transform)
+ Transform2D(const Vector2& origin, const Mat2x2& transform)
: origin(origin), transform(transform)
{}
static Transform2D Identity()
{
- return Transform2D(Vector2(0, 0), Matrix2x2());
+ return Transform2D(Vector2(0, 0), Mat2x2());
+ }
+
+ Vector2 GetScale() const
+ {
+ return Vector2::ZERO;
+ }
+
+ float GetRotation() const
+ {
+ return 0.0f;
}
Transform2D Translated(const Vector2& offset) const
@@ -33,10 +43,10 @@ namespace Duin
return result;
}
- Transform2D Rotated(float angle) const
+ Transform2D Rotated(float angle_rads) const
{
Transform2D result = *this;
- Matrix2x2 rotation = Matrix2x2::Rotate(angle);
+ Mat2x2 rotation = Mat2x2::Rotate(angle_rads);
result.transform = result.transform * rotation;
return result;
}
@@ -44,7 +54,7 @@ namespace Duin
Transform2D Scaled(float sx, float sy) const
{
Transform2D result = *this;
- Matrix2x2 scale = Matrix2x2::Scale(sx, sy);
+ Mat2x2 scale = Mat2x2::Scale(sx, sy);
result.transform = result.transform * scale;
return result;
}
diff --git a/Duin/src/Duin/Object/Object.cpp b/Duin/src/Duin/Core/Scene/Object.cpp
similarity index 92%
rename from Duin/src/Duin/Object/Object.cpp
rename to Duin/src/Duin/Core/Scene/Object.cpp
index 5113db1..02b987e 100644
--- a/Duin/src/Duin/Object/Object.cpp
+++ b/Duin/src/Duin/Core/Scene/Object.cpp
@@ -1,18 +1,18 @@
-#include "dnpch.h"
-
-#include "Object.h"
-
-namespace Duin
-{
- Object::Object()
- {
- }
-
- Object::~Object()
- {
- }
- bool Object::operator==(Object& other)
- {
- return this->GetUUID() == other.GetUUID();
- }
+#include "dnpch.h"
+
+#include "Object.h"
+
+namespace Duin
+{
+ Object::Object()
+ {
+ }
+
+ Object::~Object()
+ {
+ }
+ bool Object::operator==(Object& other)
+ {
+ return this->GetUUID() == other.GetUUID();
+ }
}
\ No newline at end of file
diff --git a/Duin/src/Duin/Object/Object.h b/Duin/src/Duin/Core/Scene/Object.h
similarity index 92%
rename from Duin/src/Duin/Object/Object.h
rename to Duin/src/Duin/Core/Scene/Object.h
index 5220f41..5f9d2b7 100644
--- a/Duin/src/Duin/Object/Object.h
+++ b/Duin/src/Duin/Core/Scene/Object.h
@@ -1,29 +1,29 @@
-#pragma once
-
-#include "Duin/Core/Core.h"
-#include "Duin/Core/UUID.h"
-#include "Duin/Core/Signal.h"
-#include "Duin/Events/InputEvent.h"
-
-#include