Adapted more debugging with Tracy, characters update

This commit is contained in:
2026-02-13 18:14:09 +03:00
parent 71b7f47bcd
commit a85152a675
23 changed files with 814 additions and 133 deletions

View File

@@ -35,6 +35,7 @@ struct TriggerBody {
};
PhysicsModule::PhysicsModule(flecs::world &ecs)
{
ZoneScoped;
ecs.module<PhysicsModule>();
ecs.import <EventModule>();
ecs.import <EventTriggerModule>();
@@ -75,7 +76,7 @@ PhysicsModule::PhysicsModule(flecs::world &ecs)
ecs.system<EngineData, Physics>("physics_update")
.kind(PhysicsUpdate)
.each([&](EngineData &e, Physics &ph) {
ZoneScopedN("physics");
ZoneScopedN("physics_update");
ph.physics->update(e.delta);
});
ecs.observer<const EngineData, PhysicsMeshName>(
@@ -86,6 +87,7 @@ PhysicsModule::PhysicsModule(flecs::world &ecs)
.write<PhysicsShape>()
.each([&](flecs::entity e, const EngineData &eng,
PhysicsMeshName &name) {
ZoneScopedN("create_shape_mesh_name");
Ogre::DefaultHardwareBufferManagerBase dmgr;
Ogre::MeshPtr mesh =
Ogre::MeshManager::getSingleton().getByName(
@@ -106,7 +108,8 @@ PhysicsModule::PhysicsModule(flecs::world &ecs)
.write<PhysicsShape>()
.each([&](flecs::entity e, const EngineData &eng,
PhysicsMeshPtr &meshPtr) {
Ogre::DefaultHardwareBufferManager dmgr;
ZoneScopedN("create_shape_mesh_ptr");
Ogre::DefaultHardwareBufferManager dmgr;
Ogre::MeshPtr mesh = meshPtr.mesh;
if (!mesh->isLoaded()) {
mesh->setHardwareBufferManager(&dmgr);
@@ -127,7 +130,8 @@ PhysicsModule::PhysicsModule(flecs::world &ecs)
.write<PhysicsShape>()
.each([&](flecs::entity e, const EngineData &eng,
PhysicsHeightfieldData &hfd) {
JPH::ShapeRefC shape =
ZoneScopedN("create_shape_heightfield");
JPH::ShapeRefC shape =
JoltPhysicsWrapper::getSingleton()
.createHeightfieldShape(
hfd.samples, hfd.offset,
@@ -148,7 +152,8 @@ PhysicsModule::PhysicsModule(flecs::world &ecs)
.each([&](flecs::entity e, const EngineData &eng,
const PhysicsShape &shape, const PhysicsNode &node,
const PhysicsBody &body) {
JPH::BodyID id =
ZoneScopedN("create_body_from_shape");
JPH::BodyID id =
JoltPhysicsWrapper::getSingleton().createBody(
shape.shape.GetPtr(), 0.0f, node.node,
(JPH::EMotionType)body.motion,
@@ -161,7 +166,8 @@ PhysicsModule::PhysicsModule(flecs::world &ecs)
ecs.observer<const JPH::BodyID>("remove_body")
.event(flecs::OnRemove)
.each([&](flecs::entity e, const JPH::BodyID &id) {
JoltPhysicsWrapper::getSingleton().removeBody(id);
ZoneScopedN("remove_body");
JoltPhysicsWrapper::getSingleton().removeBody(id);
if (e.has<CharacterBase>() || e.has<Character>())
return;
if (JoltPhysicsWrapper::getSingleton().bodyIsCharacter(
@@ -199,7 +205,8 @@ PhysicsModule::PhysicsModule(flecs::world &ecs)
.without<JPH::BodyID>()
.each([](flecs::entity e, const EngineData &eng,
const EventTrigger &trigger) {
JPH::ShapeRefC shape =
ZoneScopedN("CreateTriggerPhysics");
JPH::ShapeRefC shape =
JoltPhysicsWrapper::getSingleton()
.createCylinderShape(trigger.halfheight,
trigger.radius);
@@ -621,6 +628,7 @@ flecs::entity PhysicsModule::createTerrainChunkBody(Ogre::SceneNode *node,
const Ogre::Vector3 &scale,
int sampleCount)
{
ZoneScoped;
flecs::entity e = ECS::get().entity();
e.set<PhysicsHeightfieldData>({ samples, offset, scale, sampleCount });
e.set<PhysicsBody>({ (uint32_t)JPH::EMotionType::Static,
@@ -631,6 +639,7 @@ flecs::entity PhysicsModule::createTerrainChunkBody(Ogre::SceneNode *node,
}
void PhysicsModule::controlPhysics(flecs::entity e, bool enable)
{
ZoneScoped;
if (enable) {
if (e.has<CharacterBase>()) {
e.remove<CharacterDisablePhysics>();
@@ -678,6 +687,7 @@ bool PhysicsModule::raycastQuery(const Ogre::Vector3 &startPos,
const Ogre::Vector3 &endPos,
Ogre::Vector3 &position, JPH::BodyID &id)
{
ZoneScoped;
return JoltPhysicsWrapper::getSingleton().raycastQuery(startPos, endPos,
position, id);
}
@@ -689,6 +699,7 @@ void PhysicsModule::setDebugDraw(bool enable)
bool WaterBody::isInWater(const JPH::BodyID &id) const
{
ZoneScoped;
#if 0
flecs::entity e =
ECS::get().query_builder<const JPH::BodyID>().build().find(