Fix: Bug with spawning where it would get stuck after reaching max entities
Update: increase max entity count and increase spawn rate
This commit is contained in:
parent
26127dc35b
commit
f4a74ffbd7
10
becs.h
10
becs.h
|
|
@ -315,11 +315,6 @@ BECS_Entity BECS_EntityCreate(BECS_ECS *ecs)
|
|||
|
||||
BECS_Entity entity = BECS_NULL_ENTITY;
|
||||
|
||||
if (ecs->nextEntity + 1 > BECS_MAX_ENTITIES)
|
||||
{
|
||||
return entity;
|
||||
}
|
||||
|
||||
if (ecs->freeEntityCount)
|
||||
{
|
||||
/* Pop entity off the back of the free list */
|
||||
|
|
@ -327,14 +322,15 @@ BECS_Entity BECS_EntityCreate(BECS_ECS *ecs)
|
|||
ecs->entitySignatures[entity] = 0;
|
||||
ecs->aliveEntities[entity] = true;
|
||||
ecs->entityCount++;
|
||||
return entity;
|
||||
}
|
||||
|
||||
else if (ecs->nextEntity < BECS_MAX_ENTITIES)
|
||||
{
|
||||
entity = ecs->nextEntity;
|
||||
ecs->aliveEntities[entity] = true;
|
||||
ecs->entitySignatures[entity] = 0;
|
||||
ecs->nextEntity++;
|
||||
ecs->entityCount++;
|
||||
}
|
||||
return entity;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
#define BECS_MAX_ENTITIES 20
|
||||
#define BECS_MAX_ENTITIES 100000
|
||||
#define BECS_MAX_COMPONENTS 4
|
||||
#define BECS_IMPLEMENTATION
|
||||
#include "../../becs.h"
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include "external/raylib/src/raylib.h"
|
||||
|
||||
// Component structs
|
||||
|
|
@ -49,6 +50,7 @@ int main(void) {
|
|||
// Initialize ECS
|
||||
size_t componentSizes[4] = {sizeof(Position), sizeof(Velocity), sizeof(Acceleration), sizeof(ParticleData)};
|
||||
size_t memSize = BECS_GetMinMemoryArenaSize(componentSizes, 4);
|
||||
printf("%lu\n", memSize);
|
||||
char *memory = (char *)malloc(memSize);
|
||||
BECS_ECS ecs = BECS_InitECS(memory, memSize);
|
||||
|
||||
|
|
@ -58,7 +60,7 @@ int main(void) {
|
|||
BECS_ComponentID accID = BECS_ComponentRegister(&ecs, sizeof(Acceleration), BECS_MAX_ENTITIES);
|
||||
BECS_ComponentID dataID = BECS_ComponentRegister(&ecs, sizeof(ParticleData), BECS_MAX_ENTITIES);
|
||||
|
||||
InitWindow(800, 400, "2D Particle System with BECS");
|
||||
InitWindow(1600, 800, "2D Particle System with BECS");
|
||||
|
||||
while (!WindowShouldClose()) {
|
||||
float dt = GetFrameTime();
|
||||
|
|
@ -76,10 +78,13 @@ int main(void) {
|
|||
}
|
||||
|
||||
// Spawn particle on mouse click
|
||||
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) {
|
||||
if (IsMouseButtonDown(MOUSE_LEFT_BUTTON)) {
|
||||
Vector2 mousePos = GetMousePosition();
|
||||
for (uint32_t i = 0; i < 10; i++)
|
||||
{
|
||||
SpawnParticle(&ecs, posID, velID, accID, dataID, mousePos.x, mousePos.y);
|
||||
}
|
||||
}
|
||||
|
||||
// Physics system: update position and velocity
|
||||
for (BECS_Entity entity = 0; entity < BECS_MAX_ENTITIES; entity++) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue