diff --git a/rwengine/src/core/Profiler.hpp b/rwengine/src/core/Profiler.hpp index b3312dae..ee4d47b8 100644 --- a/rwengine/src/core/Profiler.hpp +++ b/rwengine/src/core/Profiler.hpp @@ -6,6 +6,7 @@ #define RW_PROFILE_THREAD(name) MicroProfileOnThreadCreate(name) #define RW_PROFILE_FRAME_BOUNDARY() MicroProfileFlip(nullptr) #define RW_PROFILE_SCOPE(label) MICROPROFILE_SCOPEI("Default", label, MP_YELLOW) +#define RW_PROFILE_SCOPEC(label, colour) MICROPROFILE_SCOPEI("Default", label, colour) #define RW_PROFILE_COUNTER_ADD(name, qty) MICROPROFILE_COUNTER_ADD(name, qty) #define RW_PROFILE_COUNTER_SET(name, qty) MICROPROFILE_COUNTER_SET(name, qty) #define RW_TIMELINE_ENTER(name, color) MICROPROFILE_TIMELINE_ENTER_STATIC(color, name) @@ -14,6 +15,7 @@ #define RW_PROFILE_THREAD(name) do {} while (0) #define RW_PROFILE_FRAME_BOUNDARY() do {} while (0) #define RW_PROFILE_SCOPE(label) do {} while (0) +#define RW_PROFILE_SCOPEC(label, colour) do {} while (0) #define RW_PROFILE_COUNTER_ADD(name, qty) do {} while (0) #define RW_PROFILE_COUNTER_SET(name, qty) do {} while (0) #define RW_TIMELINE_ENTER(name, color) do {} while (0) diff --git a/rwengine/src/engine/GameWorld.cpp b/rwengine/src/engine/GameWorld.cpp index 27c4d54a..4c02c163 100644 --- a/rwengine/src/engine/GameWorld.cpp +++ b/rwengine/src/engine/GameWorld.cpp @@ -7,6 +7,7 @@ #include +#include "core/Profiler.hpp" #include "core/Logger.hpp" #include "engine/GameData.hpp" @@ -653,6 +654,7 @@ void handleInstanceResponse(InstanceObject* instance, const btManifoldPoint& mp, bool GameWorld::ContactProcessedCallback(btManifoldPoint& mp, void* body0, void* body1) { + RW_PROFILE_SCOPEC(__func__, MP_GOLDENROD1); auto obA = static_cast(body0); auto obB = static_cast(body1); @@ -689,18 +691,24 @@ bool GameWorld::ContactProcessedCallback(btManifoldPoint& mp, void* body0, void GameWorld::PhysicsTickCallback(btDynamicsWorld* physWorld, btScalar timeStep) { + RW_PROFILE_SCOPEC(__func__, MP_CYAN); GameWorld* world = static_cast(physWorld->getWorldUserInfo()); + RW_PROFILE_COUNTER_SET("physicsTick/vehiclePool", world->vehiclePool.objects.size()); for (auto& p : world->vehiclePool.objects) { + RW_PROFILE_SCOPEC("VehicleObject", MP_THISTLE1); VehicleObject* object = static_cast(p.second); object->tickPhysics(timeStep); } + RW_PROFILE_COUNTER_SET("physicsTick/pedestrianPool", world->pedestrianPool.objects.size()); for (auto& p : world->pedestrianPool.objects) { + RW_PROFILE_SCOPEC("CharacterObject", MP_THISTLE1); CharacterObject* object = static_cast(p.second); object->tickPhysics(timeStep); } + RW_PROFILE_COUNTER_SET("physicsTick/instancePool", world->instancePool.objects.size()); for (auto& p : world->instancePool.objects) { InstanceObject* object = static_cast(p.second); object->tickPhysics(timeStep); diff --git a/rwengine/src/script/ScriptMachine.cpp b/rwengine/src/script/ScriptMachine.cpp index bd6fcb20..25ea79ee 100644 --- a/rwengine/src/script/ScriptMachine.cpp +++ b/rwengine/src/script/ScriptMachine.cpp @@ -6,6 +6,7 @@ #include "ai/PlayerController.hpp" #include "core/Logger.hpp" +#include "core/Profiler.hpp" #include "engine/GameState.hpp" #include "engine/GameWorld.hpp" #include "script/SCMFile.hpp" @@ -226,6 +227,7 @@ SCMByte* ScriptMachine::getGlobals() { } void ScriptMachine::execute(float dt) { + RW_PROFILE_SCOPEC(__func__, MP_ORANGERED); int ms = dt * 1000.f; for (auto t = _activeThreads.begin(); t != _activeThreads.end(); ++t) { auto& thread = *t; diff --git a/rwgame/RWGame.cpp b/rwgame/RWGame.cpp index d348a341..77c3ce76 100644 --- a/rwgame/RWGame.cpp +++ b/rwgame/RWGame.cpp @@ -370,6 +370,7 @@ int RWGame::run() { bool running = true; while (StateManager::currentState() && running) { RW_PROFILE_FRAME_BOUNDARY(); + RW_PROFILE_SCOPE("Main Loop"); running = updateInput(); @@ -405,7 +406,7 @@ int RWGame::run() { } float RWGame::tickWorld(const float deltaTime, float accumulatedTime) { - RW_PROFILE_SCOPE(__func__); + RW_PROFILE_SCOPEC(__func__, MP_GREEN); auto deltaTimeWithTimeScale = deltaTime * world->state->basic.timeScale; @@ -414,8 +415,11 @@ float RWGame::tickWorld(const float deltaTime, float accumulatedTime) { break; } - world->dynamicsWorld->stepSimulation( - deltaTimeWithTimeScale, kMaxPhysicsSubSteps, deltaTime); + { + RW_PROFILE_SCOPEC("stepSimulation", MP_DARKORANGE1); + world->dynamicsWorld->stepSimulation( + deltaTimeWithTimeScale, kMaxPhysicsSubSteps, deltaTime); + } StateManager::get().tick(deltaTimeWithTimeScale); @@ -521,22 +525,7 @@ void RWGame::tick(float dt) { } } - world->updateEffects(); - - for (auto& object : world->allObjects) { - object->_updateLastTransform(); - object->tick(dt); - } - - for (auto& g : world->garages) { - g->tick(dt); - } - - for (auto& p : world->payphones) { - p->tick(dt); - } - - world->destroyQueuedObjects(); + tickObjects(dt); state.text.tick(dt); @@ -564,8 +553,38 @@ void RWGame::tick(float dt) { } } +void RWGame::tickObjects(float dt) const { + RW_PROFILE_SCOPEC(__func__, MP_MAGENTA1); + world->updateEffects(); + + { + RW_PROFILE_SCOPEC("allObjects", MP_HOTPINK1); + RW_PROFILE_COUNTER_SET("tickObjects/allObjects", world->allObjects.size()); + for (auto &object : world->allObjects) { + object->_updateLastTransform(); + object->tick(dt); + } + } + + { + RW_PROFILE_SCOPEC("garages", MP_HOTPINK2); + for (auto &g : world->garages) { + g->tick(dt); + } + } + + { + RW_PROFILE_SCOPEC("payphones", MP_HOTPINK3); + for (auto &p : world->payphones) { + p->tick(dt); + } + } + + world->destroyQueuedObjects(); +} + void RWGame::render(float alpha, float time) { - RW_PROFILE_SCOPE(__func__); + RW_PROFILE_SCOPEC(__func__, MP_CORNFLOWERBLUE); lastDraws = getRenderer().getRenderer()->getDrawCount(); diff --git a/rwgame/RWGame.hpp b/rwgame/RWGame.hpp index 8eab6aff..e9d553ab 100644 --- a/rwgame/RWGame.hpp +++ b/rwgame/RWGame.hpp @@ -137,6 +137,8 @@ private: float tickWorld(const float deltaTime, float accumulatedTime); void renderDebugView(float time, ViewCamera &viewCam); + + void tickObjects(float dt) const; }; #endif