Added a basic MemoryArena.

Added one scratch, one engine and one game arena.
Converted the game alloc to arena + the display stuff.
WIP

Made using Antigravity+gemini
This commit is contained in:
2026-01-17 21:09:23 -05:00
parent 98783b7e8f
commit f95ba51c13
28 changed files with 462 additions and 59 deletions

View File

@@ -3,6 +3,7 @@
#include <concepts>
#include <Core/Common/CoreUtils.h>
#include <Core/Memory/Allocator.h>
#include <Core/Memory/MemoryArena.h>
#include <Engine/Class.h>
#include <Entity/EntityManager.h>
#include <type_traits>
@@ -17,6 +18,8 @@
constexpr Juliet::Class entityKind##entity(#entity, sizeof(#entity) / sizeof(char)); \
const Juliet::Class* entity::Kind = &entityKind##entity;
namespace Game
{
using DerivedType = void*;
@@ -46,8 +49,9 @@ namespace Game
requires EntityConcept<EntityType>
EntityType* MakeEntity(EntityManager& manager, float x, float y)
{
EntityType* result = static_cast<EntityType*>(Juliet::Calloc(1, sizeof(EntityType)));
Entity* base = result->Base = static_cast<Entity*>(Juliet::Calloc(1, sizeof(Entity)));
auto* arena = Juliet::GetGameArena();
EntityType* result = Juliet::ArenaPushType<EntityType>(arena);
Entity* base = result->Base = Juliet::ArenaPushType<Entity>(arena);
base->X = x;
base->Y = y;
base->Derived = result;

View File

@@ -38,7 +38,7 @@
// Extra Compiler Options
.CompilerOptions + ' "-IJuliet/include"'
+ ' "-IGame"'
// + ' -DGAME_EXPORT' // I'm just always exporting anyway but just in case
.CompilerOptions + ' -DJULIET_EXPORT'
#if __WINDOWS__
.CompilerOptions + ' -DJULIET_WIN32'

View File

@@ -4,11 +4,11 @@
#undef max
#include <Core/HAL/Filesystem/Filesystem.h>
#include <Core/JulietInit.h>
#include <Core/Logging/LogManager.h>
#include <Core/Logging/LogTypes.h>
#include <Core/Memory/MemoryArena.h>
#include <Entity/Entity.h>
#include <Entity/EntityManager.h>
#include <Graphics/Graphics.h>
// Test code
namespace Game
@@ -31,8 +31,21 @@ namespace Game
using namespace Juliet;
extern "C" __declspec(dllexport) void __cdecl GameInit()
extern "C" JULIET_API void GameInit(GameInitParams* /*params*/)
{
// Example allocation in GameArena
struct GameState
{
float TotalTime;
int Score;
};
auto* gameState = ArenaPushType<GameState>(GetGameArena());
gameState->TotalTime = 0.0f;
gameState->Score = 0;
printf("Game Arena Allocated: %p\n", gameState);
using namespace Game;
// Entity Use case
@@ -41,8 +54,8 @@ extern "C" __declspec(dllexport) void __cdecl GameInit()
Door* door = MakeEntity<Door>(manager, 10.0f, 2.0f);
door->IsOpened = true;
Entity* ent = door->Base;
[[maybe_unused]] Door* stillDoor = DownCast<Door>(ent);
Entity* ent = door->Base;
[[maybe_unused]] Door* stillDoor = DownCast<Door>(ent);
Assert(door == stillDoor);
Rock* rock = MakeEntity<Rock>(manager, 1.f, 2.f);
@@ -51,20 +64,14 @@ extern "C" __declspec(dllexport) void __cdecl GameInit()
printf("Door is %s\n", door->IsOpened ? "Opened" : "Closed");
printf("Rock has %d health points\n", rock->Health);
// Have to manually free for now because im not using arenas or anything
free(door->Base);
free(door);
free(rock->Base);
free(rock);
}
extern "C" __declspec(dllexport) void __cdecl GameShutdown()
extern "C" JULIET_API void __cdecl GameShutdown()
{
printf("Shutting down game...\n");
}
extern "C" __declspec(dllexport) void __cdecl GameUpdate([[maybe_unused]] float deltaTime)
extern "C" JULIET_API void __cdecl GameUpdate([[maybe_unused]] float deltaTime)
{
//printf("Updating game...\n");
// printf("Updating game...\n");
}