general improvements
This commit is contained in:
@@ -2,20 +2,35 @@
|
||||
#include "../engine/Shared.h"
|
||||
#include "Global.h"
|
||||
#include "Log.h"
|
||||
#include "rendering/Rendering.h"
|
||||
#include <bgfx/bgfx.h>
|
||||
#include <cstdint>
|
||||
|
||||
namespace Game
|
||||
{
|
||||
struct EntityRenderData
|
||||
{
|
||||
float TestColor[4]{1.0f, 1.0f, 1.0f, 1.0f};
|
||||
Transform Transform;
|
||||
uint16_t MaterialHandle = UINT16_MAX;
|
||||
uint16_t ModelHandle = UINT16_MAX;
|
||||
|
||||
typedef uint16_t CubeHandle;
|
||||
void Render(const Model* models, const Material* materials);
|
||||
};
|
||||
|
||||
struct Cube
|
||||
{
|
||||
int32_t TestX = -1;
|
||||
int32_t TestY = -1;
|
||||
Transform Transform;
|
||||
uint16_t MaterialIdx = 0;
|
||||
uint16_t ModelIdx = 0;
|
||||
EntityRenderData EData;
|
||||
|
||||
void Setup();
|
||||
void Update();
|
||||
};
|
||||
|
||||
struct TestEntity
|
||||
{
|
||||
EntityRenderData EData;
|
||||
|
||||
void Setup();
|
||||
void Update();
|
||||
@@ -29,15 +44,19 @@ namespace Game
|
||||
uint32_t EntitySize = 0;
|
||||
|
||||
public:
|
||||
uint64_t Setup(void* ptr)
|
||||
// Returns true if size changed
|
||||
bool Setup(void*& ptr, bool forceReset)
|
||||
{
|
||||
if (EntitySize != sizeof(T))
|
||||
bool changed = false;
|
||||
if (EntitySize != sizeof(T) || forceReset)
|
||||
{
|
||||
Count = 0;
|
||||
changed = true;
|
||||
}
|
||||
EntitySize = sizeof(T);
|
||||
Data = reinterpret_cast<T*>(ptr);
|
||||
return C * sizeof(T);
|
||||
ptr = (uint8_t*)ptr + (C * EntitySize);
|
||||
return changed;
|
||||
}
|
||||
|
||||
T* New()
|
||||
@@ -76,12 +95,22 @@ namespace Game
|
||||
Data[i].Update();
|
||||
}
|
||||
}
|
||||
|
||||
void Render(const Model* models, const Material* materials)
|
||||
{
|
||||
for (int32_t i = 0; i < Count; ++i)
|
||||
{
|
||||
T* c = Get(i);
|
||||
if (c) c->EData.Render(models, materials);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
class Level
|
||||
{
|
||||
public:
|
||||
EntityManager<Cube, 1024> Cubes;
|
||||
EntityManager<TestEntity, 32> Tests;
|
||||
|
||||
public:
|
||||
void Setup(GameData& data);
|
||||
|
||||
Reference in New Issue
Block a user