142 lines
2.6 KiB
C++
142 lines
2.6 KiB
C++
#pragma once
|
|
|
|
#include <cstdint>
|
|
|
|
#include <volk.h>
|
|
|
|
#include <vma/vk_mem_alloc.h>
|
|
|
|
#include <DirectXMath.h>
|
|
#include <span>
|
|
|
|
// TODO: Remove this dependency
|
|
#include "TextureManager.h"
|
|
|
|
struct RenderDevice;
|
|
struct GlobalMemory;
|
|
|
|
struct Vertex
|
|
{
|
|
DirectX::XMFLOAT3 position;
|
|
DirectX::XMFLOAT3 color;
|
|
DirectX::XMFLOAT2 texCoord0;
|
|
};
|
|
|
|
struct Transform
|
|
{
|
|
DirectX::XMFLOAT3 position;
|
|
float scale;
|
|
DirectX::XMVECTOR rotation;
|
|
};
|
|
|
|
struct Mesh
|
|
{
|
|
VkBuffer vertexBuffer;
|
|
VmaAllocation vertexBufferAllocation;
|
|
uint32_t vertexBufferSize;
|
|
uint32_t vertexCount;
|
|
};
|
|
|
|
struct Material
|
|
{
|
|
TextureID texture;
|
|
VkSampler sampler; // TODO: Reuse
|
|
};
|
|
|
|
struct Entity
|
|
{
|
|
private:
|
|
Transform m_transform;
|
|
Mesh m_mesh;
|
|
Material m_material;
|
|
|
|
public:
|
|
[[nodiscard]] Transform& transform()
|
|
{
|
|
return m_transform;
|
|
}
|
|
|
|
[[nodiscard]] Transform const& transform() const
|
|
{
|
|
return m_transform;
|
|
}
|
|
|
|
[[nodiscard]] Mesh& mesh()
|
|
{
|
|
return m_mesh;
|
|
}
|
|
|
|
[[nodiscard]] Mesh const& mesh() const
|
|
{
|
|
return m_mesh;
|
|
}
|
|
|
|
[[nodiscard]] Material& material()
|
|
{
|
|
return m_material;
|
|
}
|
|
|
|
[[nodiscard]] Material const& material() const
|
|
{
|
|
return m_material;
|
|
}
|
|
|
|
[[nodiscard]] bool isInit() const
|
|
{
|
|
return m_mesh.vertexBuffer or m_material.texture;
|
|
}
|
|
|
|
Entity( Transform const& transform, Mesh const& mesh, Material&& material )
|
|
: m_transform{ transform }, m_mesh{ mesh }, m_material{ std::forward<Material>( material ) }
|
|
{}
|
|
};
|
|
|
|
struct EntityManager
|
|
{
|
|
struct Iterable
|
|
{
|
|
private:
|
|
Entity* m_begin;
|
|
Entity* m_end;
|
|
|
|
public:
|
|
Iterable( Entity* begin, uint32_t const count ) : m_begin{ begin }, m_end{ begin + count }
|
|
{}
|
|
|
|
// Iterator
|
|
[[nodiscard]] Entity* begin() const
|
|
{
|
|
return m_begin;
|
|
}
|
|
[[nodiscard]] Entity* end() const
|
|
{
|
|
return m_end;
|
|
}
|
|
};
|
|
|
|
RenderDevice* pRenderDevice;
|
|
Entity* entities;
|
|
uint32_t count;
|
|
uint32_t capacity;
|
|
|
|
EntityManager( RenderDevice* renderDevice, Entity* data, uint32_t const capacity )
|
|
: pRenderDevice{ renderDevice }, entities{ data }, count{ 0 }, capacity{ capacity }
|
|
{}
|
|
|
|
[[nodiscard]] Iterable iter() const
|
|
{
|
|
return Iterable{ entities, count };
|
|
}
|
|
|
|
// Make Entities return ID, make it a sparse indexing system.
|
|
Entity* createEntity( Transform const& transform, std::span<Vertex> vertices, const char* textureFile );
|
|
|
|
void destroyEntity( Entity* entity );
|
|
|
|
void destroy();
|
|
|
|
~EntityManager();
|
|
};
|
|
|
|
EntityManager* EntityManager_Create( GlobalMemory* mem, RenderDevice* renderDevice, uint32_t capacity );
|