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 3fc58da commit 41afa08
Show file tree
Hide file tree
Showing 7 changed files with 28 additions and 32 deletions.
2 changes: 1 addition & 1 deletion externals/cage
Submodule cage updated 78 files
+7 −22 .github/workflows/tests.yml
+3 −0 .gitmodules
+4 −5 cmake/cage_build_configuration.cmake
+1 −1 cmake/cage_copy_redist.cmake
+61 −82 data/cage/shader/engine/fragment.glsl
+10 −4 data/cage/shader/engine/uniforms.glsl
+2 −1 data/cage/shader/functions/attenuation.glsl
+2 −1 externals/CMakeLists.txt
+11 −0 externals/quickhull/CMakeLists.txt
+1 −0 externals/quickhull/quickhull
+0 −10 schemes/skeleton.scheme
+4 −2 sources/.clang-format
+8 −7 sources/CMakeLists.txt
+5 −15 sources/asset-processor/model.cpp
+0 −2 sources/asset-processor/skeleton.cpp
+1 −6 sources/include/cage-core/core.h
+8 −49 sources/include/cage-core/entities.h
+5 −0 sources/include/cage-core/entitiesCopy.h
+4 −8 sources/include/cage-core/entitiesVisitor.h
+5 −9 sources/include/cage-core/math.h
+14 −0 sources/include/cage-core/memoryAllocators.h
+5 −0 sources/include/cage-core/meshAlgorithms.h
+1 −1 sources/include/cage-core/networkGinnel.h
+9 −0 sources/include/cage-core/networkSteam.h
+1 −1 sources/include/cage-core/process.h
+9 −8 sources/include/cage-core/scheduler.h
+0 −19 sources/include/cage-core/sourceLocationDummy.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
+15 −4 sources/include/cage-engine/guiBuilder.h
+20 −9 sources/include/cage-engine/guiComponents.h
+1 −0 sources/include/cage-engine/guiManager.h
+5 −5 sources/include/cage-engine/scene.h
+4 −4 sources/include/cage-engine/shaderConventions.h
+1 −2 sources/include/cage-simple/engine.h
+9 −8 sources/include/cage-simple/guiInWorld.h
+15 −15 sources/include/cage-simple/statisticsGui.h
+12 −3 sources/libcore/concurrent/process.cpp
+86 −335 sources/libcore/entities.cpp
+58 −0 sources/libcore/entitiesCopy.cpp
+9 −9 sources/libcore/geometry/aabbCone.cpp
+21 −19 sources/libcore/geometry/spatialStructure.cpp
+1 −1 sources/libcore/image/tga.cpp
+7 −1 sources/libcore/ini.cpp
+4 −0 sources/libcore/math/vectors.cpp
+71 −2 sources/libcore/memory/allocators.cpp
+74 −30 sources/libcore/mesh/meshAlgorithms.cpp
+33 −0 sources/libcore/mesh/quickhull.cpp
+19 −5 sources/libcore/network/steam.cpp
+4 −4 sources/libcore/profiling.cpp
+54 −19 sources/libcore/scheduler.cpp
+132 −87 sources/libengine/graphics/renderPipeline.cpp
+2 −3 sources/libengine/gui/events.cpp
+1 −1 sources/libengine/gui/graphics.cpp
+13 −6 sources/libengine/gui/gui.cpp
+6 −0 sources/libengine/gui/guiBuilder.cpp
+12 −9 sources/libengine/gui/layouts/scrollbars.cpp
+2 −1 sources/libengine/gui/private.h
+2 −2 sources/libengine/gui/skin.cpp
+80 −46 sources/libengine/gui/tooltips.cpp
+104 −72 sources/libengine/gui/widgets/comboBox.cpp
+2 −2 sources/libengine/sound/speaker.cpp
+54 −27 sources/libsimple/gameloop.cpp
+2 −2 sources/libsimple/graphics.cpp
+4 −1 sources/libsimple/guiInWorld.cpp
+54 −162 sources/libsimple/statisticsGui.cpp
+9 −36 sources/test-core/entities.cpp
+2 −1 sources/test-core/entitiesSerialization.cpp
+0 −4 sources/test-core/exceptions.cpp
+27 −0 sources/test-core/flatSet.cpp
+114 −0 sources/test-core/memoryAllocators.cpp
+29 −2 sources/test-core/mesh.cpp
+5 −1 sources/test-core/networkSteam.cpp
+2 −2 sources/test-core/pointerRange.cpp
+15 −0 sources/test-core/scheduler.cpp
+523 −0 sources/test-entities/main.cpp
+0 −7 sources/tryCompileSourceLocation.cpp
4 changes: 3 additions & 1 deletion sources/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define ants_common_h_sdg456ds4hg6

#include <cage-core/entities.h>
#include <cage-core/entitiesVisitor.h>
#include <cage-core/math.h>
#include <cage-core/profiling.h>
#include <cage-engine/scene.h>
Expand Down Expand Up @@ -45,7 +46,8 @@ struct TimeoutComponent
sint32 ttl = 1;
};

extern EntityGroup *entitiesToDestroy;
struct DestroyingComponent
{};

uint32 pickTargetPlanet(uint32 shipOwner);

Expand Down
3 changes: 2 additions & 1 deletion sources/components.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace
engineEntities()->defineComponent(ShipComponent());
engineEntities()->defineComponent(PlanetComponent());
engineEntities()->defineComponent(TimeoutComponent());
engineEntities()->defineComponent(DestroyingComponent());
},
-100);
-1000);
}
28 changes: 14 additions & 14 deletions sources/physics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@ namespace
const auto engineUpdateListener = controlThread().update.listen(
[]()
{
ProfilingScope profiling("physics");
for (Entity *e : engineEntities()->component<PhysicsComponent>()->entities())
{
TransformComponent &t = e->value<TransformComponent>();
PhysicsComponent &p = e->value<PhysicsComponent>();
CAGE_ASSERT(p.acceleration.valid() && p.velocity.valid() && t.position.valid());
CAGE_ASSERT(p.rotation.valid() && t.orientation.valid());
p.velocity += p.acceleration;
if (lengthSquared(p.velocity) > sqr(p.maxSpeed))
p.velocity = normalize(p.velocity) * p.maxSpeed;
p.acceleration = Vec3();
t.position += p.velocity;
t.orientation = p.rotation * t.orientation;
}
const ProfilingScope profiling("physics");
entitiesVisitor(
[](TransformComponent &t, PhysicsComponent &p)
{
CAGE_ASSERT(p.acceleration.valid() && p.velocity.valid() && t.position.valid());
CAGE_ASSERT(p.rotation.valid() && t.orientation.valid());
p.velocity += p.acceleration;
if (lengthSquared(p.velocity) > sqr(p.maxSpeed))
p.velocity = normalize(p.velocity) * p.maxSpeed;
p.acceleration = Vec3();
t.position += p.velocity;
t.orientation = p.rotation * t.orientation;
},
engineEntities(), false);
},
100);
}
2 changes: 1 addition & 1 deletion sources/planets.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ namespace
const auto engineUpdateListener = controlThread().update.listen(
[]()
{
ProfilingScope profiling("planets");
const ProfilingScope profiling("planets");
uint32 shipsCount = engineEntities()->component<ShipComponent>()->count();
uint32 planetsCount = engineEntities()->component<PlanetComponent>()->count();
uint32 currentIndex = 0;
Expand Down
5 changes: 2 additions & 3 deletions sources/ships.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#include "common.h"

#include <cage-core/concurrent.h>
#include <cage-core/entitiesVisitor.h>
#include <cage-core/geometry.h>
#include <cage-core/hashString.h>
#include <cage-core/random.h>
Expand Down Expand Up @@ -198,7 +197,7 @@ namespace
// add all physics objects into spatial data
clock->reset();
{
ProfilingScope profiling("spatial data");
const ProfilingScope profiling("spatial data");
spatialSearchData->clear();
entitiesVisitor(
[&](Entity *e, const PhysicsComponent &, const TransformComponent &t)
Expand All @@ -214,7 +213,7 @@ namespace
// update ships
clock->reset();
{
ProfilingScope profiling("update");
const ProfilingScope profiling("update");
std::vector<ShipUpdater> ships;
ships.reserve(10000);
entitiesVisitor([&](Entity *e, TransformComponent &t, ShipComponent &s, OwnerComponent &owner, PhysicsComponent &phys, LifeComponent &life) { ships.push_back({ e, t, s, owner, phys, life }); }, engineEntities(), false);
Expand Down
16 changes: 5 additions & 11 deletions sources/timeout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
#include <cage-core/color.h>
#include <cage-core/hashString.h>

EntityGroup *entitiesToDestroy;

namespace
{
Vec3 colorVariation(const Vec3 &c)
Expand Down Expand Up @@ -49,32 +47,28 @@ namespace
[]()
{
{
ProfilingScope profiling("timeout");
const ProfilingScope profiling("timeout");
for (Entity *e : engineEntities()->component<TimeoutComponent>()->entities())
{
TimeoutComponent &t = e->value<TimeoutComponent>();
if (t.ttl-- <= 0)
e->add(entitiesToDestroy);
e->value<DestroyingComponent>();
}
}
{
ProfilingScope profiling("explosions");
const ProfilingScope profiling("explosions");
for (Entity *e : engineEntities()->component<LifeComponent>()->entities())
{
LifeComponent &l = e->value<LifeComponent>();
if (l.life <= 0)
{
e->add(entitiesToDestroy);
e->value<DestroyingComponent>();
if (e->has<ShipComponent>())
shipExplode(e);
}
}
}
{
entitiesToDestroy->destroy();
}
engineEntities()->component<DestroyingComponent>()->destroy();
},
90);

const auto engineInitListener = controlThread().initialize.listen([]() { entitiesToDestroy = engineEntities()->defineGroup(); }, -90);
}

0 comments on commit 41afa08

Please sign in to comment.