Skip to content

Commit

Permalink
update cage (optimize entities)
Browse files Browse the repository at this point in the history
  • Loading branch information
malytomas committed Jan 5, 2024
1 parent 2f0e225 commit 1ef3b0e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 16 deletions.
2 changes: 1 addition & 1 deletion externals/cage
Submodule cage updated 35 files
+3 −0 .gitmodules
+4 −5 cmake/cage_build_configuration.cmake
+1 −1 cmake/cage_copy_redist.cmake
+2 −1 externals/CMakeLists.txt
+11 −0 externals/quickhull/CMakeLists.txt
+1 −0 externals/quickhull/quickhull
+8 −1 sources/CMakeLists.txt
+8 −49 sources/include/cage-core/entities.h
+5 −0 sources/include/cage-core/entitiesCopy.h
+4 −8 sources/include/cage-core/entitiesVisitor.h
+14 −0 sources/include/cage-core/memoryAllocators.h
+5 −0 sources/include/cage-core/meshAlgorithms.h
+9 −8 sources/include/cage-core/scheduler.h
+3 −1 sources/include/cage-core/spatialStructure.h
+1 −1 sources/include/cage-core/string.h
+9 −8 sources/include/cage-core/variableSmoothingBuffer.h
+9 −8 sources/include/cage-simple/statisticsGui.h
+86 −335 sources/libcore/entities.cpp
+58 −0 sources/libcore/entitiesCopy.cpp
+21 −19 sources/libcore/geometry/spatialStructure.cpp
+71 −2 sources/libcore/memory/allocators.cpp
+74 −30 sources/libcore/mesh/meshAlgorithms.cpp
+33 −0 sources/libcore/mesh/quickhull.cpp
+4 −4 sources/libcore/profiling.cpp
+54 −19 sources/libcore/scheduler.cpp
+1 −1 sources/libengine/gui/gui.cpp
+48 −21 sources/libsimple/gameloop.cpp
+6 −3 sources/libsimple/statisticsGui.cpp
+9 −36 sources/test-core/entities.cpp
+2 −1 sources/test-core/entitiesSerialization.cpp
+27 −0 sources/test-core/flatSet.cpp
+114 −0 sources/test-core/memoryAllocators.cpp
+29 −2 sources/test-core/mesh.cpp
+15 −0 sources/test-core/scheduler.cpp
+523 −0 sources/test-entities/main.cpp
2 changes: 1 addition & 1 deletion sources/scenes/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ void sceneReload()
f->readLine(rotLine);
ts.orientation = Quat(Rads(), Rads(toFloat(rotLine)), Rads());
}
CAGE_LOG(SeverityEnum::Info, "scenes", Stringizer() + "scene contains " + (engineEntities()->group()->count()) + " entities");
CAGE_LOG(SeverityEnum::Info, "scenes", Stringizer() + "scene contains " + (engineEntities()->count()) + " entities");
}
catch (...)
{
Expand Down
13 changes: 9 additions & 4 deletions sources/simple/explosions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ constexpr uint32 assetsName = HashString("cage-tests/explosion/explosion.pack");
constexpr const uint32 assetsExplosions[] = { HashString("cage-tests/explosion/sprite.obj;explosion_1"), HashString("cage-tests/explosion/sprite.obj;explosion_2"), HashString("cage-tests/explosion/sprite.obj;explosion_3") };
constexpr const uint32 assetsSmokes[] = { HashString("cage-tests/explosion/sprite.obj;smoke_1"), HashString("cage-tests/explosion/sprite.obj;smoke_2") };
constexpr const uint32 assetsSparks[] = { HashString("cage-tests/explosion/sprite.obj;spark_1") };
EntityGroup *entitiesToDestroy;

uint32 pickExplosion()
{
Expand Down Expand Up @@ -53,7 +52,13 @@ struct Particle
uint32 ttl = 0;
};

struct DestroyingComponent
{
static EntityComponent *component;
};

EntityComponent *Particle::component;
EntityComponent *DestroyingComponent::component;

Entity *makeParticle(const Vec3 &position, Real scale, uint32 object, uint32 ttl)
{
Expand Down Expand Up @@ -164,7 +169,7 @@ void update()
Particle &p = e->value<Particle>(Particle::component);
if (p.ttl-- == 0)
{
entitiesToDestroy->add(e);
e->value<DestroyingComponent>();
continue;
}
TransformComponent &t = e->value<TransformComponent>();
Expand All @@ -184,7 +189,7 @@ void update()
for (const Vec4 &s : newSmokes)
makeSmoke(Vec3(s), s[3]);

entitiesToDestroy->destroy();
DestroyingComponent::component->destroy();
}

int main(int argc, char *args[])
Expand All @@ -209,7 +214,7 @@ int main(int argc, char *args[])

// entities
EntityManager *ents = engineEntities();
entitiesToDestroy = ents->defineGroup();
DestroyingComponent::component = ents->defineComponent(DestroyingComponent());
Particle::component = ents->defineComponent<Particle>(Particle());
{ // camera
Entity *e = ents->create(1);
Expand Down
24 changes: 14 additions & 10 deletions sources/simple/screamers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,15 @@ struct ParticleComponent
Real dimming = Real::Nan();
};

struct DestroyingComponent
{
static EntityComponent *component;
};

EntityComponent *ScreamerComponent::component;
EntityComponent *TtlComponent::component;
EntityComponent *ParticleComponent::component;

EntityGroup *entsToDestroy;
EntityComponent *DestroyingComponent::component;

uint32 arrayPick(PointerRange<const uint32> arr)
{
Expand Down Expand Up @@ -199,20 +203,20 @@ void updateScreamers()
CAGE_LOG(SeverityEnum::Info, "screamers", "more screamers!");
}

if (ScreamerComponent::component->group()->count() < screamersCapacity && randomChance() / screamersCapacity < 0.01)
if (ScreamerComponent::component->count() < screamersCapacity && randomChance() / screamersCapacity < 0.01)
spawnScreamer();

const Line cursorRay = cameraMouseRay(engineEntities()->get(1));

std::vector<Vec3> newSmokes, newExplosions;
for (Entity *e : ScreamerComponent::component->group()->entities())
for (Entity *e : ScreamerComponent::component->entities())
{
TransformComponent &tr = e->value<TransformComponent>();

if (intersects(cursorRay, +collider, tr))
{ // hit the screamer
CAGE_LOG(SeverityEnum::Info, "screamers", "poof");
e->add(entsToDestroy);
e->value<DestroyingComponent>();
newExplosions.push_back(tr.position);
continue;
}
Expand All @@ -221,7 +225,7 @@ void updateScreamers()
if (dist < 2)
{ // hit the player
CAGE_LOG(SeverityEnum::Info, "screamers", "hit");
e->add(entsToDestroy);
e->value<DestroyingComponent>();
continue;
}

Expand Down Expand Up @@ -257,14 +261,14 @@ void update()
updateParticles();

// ttl
for (Entity *e : TtlComponent::component->group()->entities())
for (Entity *e : TtlComponent::component->entities())
{
TtlComponent &ttl = e->value<TtlComponent>(TtlComponent::component);
if (ttl.ttl-- == 0)
e->add(entsToDestroy);
e->value<DestroyingComponent>();
}

entsToDestroy->destroy();
DestroyingComponent::component->destroy();
}

int main(int argc, char *args[])
Expand All @@ -291,7 +295,7 @@ int main(int argc, char *args[])
ScreamerComponent::component = ents->defineComponent(ScreamerComponent());
TtlComponent::component = ents->defineComponent(TtlComponent());
ParticleComponent::component = ents->defineComponent(ParticleComponent());
entsToDestroy = ents->defineGroup();
DestroyingComponent::component = ents->defineComponent(DestroyingComponent());
{ // camera
Entity *e = ents->create(1);
e->value<TransformComponent>().position = cameraCenter;
Expand Down

0 comments on commit 1ef3b0e

Please sign in to comment.