Removed the old Memory Arena and converted all to the new one
This commit is contained in:
@@ -47,15 +47,18 @@ namespace Game
|
||||
requires EntityConcept<EntityType>
|
||||
EntityType* MakeEntity(EntityManager& manager, float x, float y)
|
||||
{
|
||||
auto* arena = Juliet::GetGameArena();
|
||||
EntityType* result = Juliet::ArenaPushType<EntityType>(arena, ConstString("EntityType"));
|
||||
Entity* base = result->Base = Juliet::ArenaPushType<Entity>(arena, ConstString("Entity"));
|
||||
base->X = x;
|
||||
base->Y = y;
|
||||
base->Derived = result;
|
||||
base->Kind = EntityType::Kind;
|
||||
auto* arena = manager.Arena;
|
||||
EntityType* result = Juliet::ArenaPushStruct<EntityType>(arena);
|
||||
Entity base;
|
||||
base.X = x;
|
||||
base.Y = y;
|
||||
base.Derived = result;
|
||||
base.Kind = EntityType::Kind;
|
||||
manager.Entities.PushBack(base);
|
||||
|
||||
RegisterEntity(manager, base);
|
||||
result->Base = manager.Entities.Back();
|
||||
|
||||
RegisterEntity(manager, &base);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,16 @@ namespace Game
|
||||
|
||||
EntityID EntityManager::ID = 0;
|
||||
|
||||
void InitEntityManager() {}
|
||||
void InitEntityManager(Juliet::NonNullPtr<Juliet::Arena> arena)
|
||||
{
|
||||
Manager.Arena = arena.Get();
|
||||
Manager.Entities.Create(arena);
|
||||
}
|
||||
|
||||
void ShutdownEntityManager()
|
||||
{
|
||||
Manager.Entities.Destroy();
|
||||
}
|
||||
|
||||
EntityManager& GetEntityManager()
|
||||
{
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#pragma once
|
||||
|
||||
#include <Core/Common/CoreTypes.h>
|
||||
#include <Core/Container/Vector.h>
|
||||
|
||||
namespace Game
|
||||
{
|
||||
@@ -10,10 +11,14 @@ namespace Game
|
||||
struct EntityManager
|
||||
{
|
||||
static EntityID ID;
|
||||
// May be this should contains the allocator for each entity types
|
||||
|
||||
Juliet::Arena* Arena;
|
||||
// TODO: Should be a pool
|
||||
Juliet::VectorArena<Entity, 1024> Entities;
|
||||
};
|
||||
|
||||
void InitEntityManager();
|
||||
void InitEntityManager(Juliet::NonNullPtr<Juliet::Arena> arena);
|
||||
void ShutdownEntityManager();
|
||||
EntityManager& GetEntityManager();
|
||||
void RegisterEntity(EntityManager& manager, Entity* entity);
|
||||
} // namespace Game
|
||||
|
||||
@@ -31,7 +31,7 @@ namespace Game
|
||||
|
||||
using namespace Juliet;
|
||||
|
||||
extern "C" JULIET_API void GameInit(GameInitParams* /*params*/)
|
||||
extern "C" JULIET_API void GameInit(GameInitParams* params)
|
||||
{
|
||||
// Example allocation in GameArena
|
||||
struct GameState
|
||||
@@ -40,7 +40,7 @@ extern "C" JULIET_API void GameInit(GameInitParams* /*params*/)
|
||||
int Score;
|
||||
};
|
||||
|
||||
auto* gameState = ArenaPushType<GameState>(GetGameArena(), ConstString("GameState"));
|
||||
auto* gameState = ArenaPushStruct<GameState>(params->GameArena);
|
||||
gameState->TotalTime = 0.0f;
|
||||
gameState->Score = 0;
|
||||
|
||||
@@ -49,7 +49,7 @@ extern "C" JULIET_API void GameInit(GameInitParams* /*params*/)
|
||||
using namespace Game;
|
||||
|
||||
// Entity Use case
|
||||
InitEntityManager();
|
||||
InitEntityManager(params->GameArena);
|
||||
auto& manager = GetEntityManager();
|
||||
Door* door = MakeEntity<Door>(manager, 10.0f, 2.0f);
|
||||
door->IsOpened = true;
|
||||
@@ -69,6 +69,10 @@ extern "C" JULIET_API void GameInit(GameInitParams* /*params*/)
|
||||
extern "C" JULIET_API void __cdecl GameShutdown()
|
||||
{
|
||||
printf("Shutting down game...\n");
|
||||
|
||||
using namespace Game;
|
||||
|
||||
ShutdownEntityManager();
|
||||
}
|
||||
|
||||
extern "C" JULIET_API void __cdecl GameUpdate([[maybe_unused]] float deltaTime)
|
||||
|
||||
Reference in New Issue
Block a user