Skip to content

Commit

Permalink
[Application] Started instrumenting the code
Browse files Browse the repository at this point in the history
- Each frame and application cycle are reported and displayed independently

- Application::runOnce() & relevant World's functions have zones to be profiled
  • Loading branch information
Razakhel committed Mar 9, 2024
1 parent 5ce72c5 commit 131ec46
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 0 deletions.
10 changes: 10 additions & 0 deletions src/RaZ/Application.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include "RaZ/Application.hpp"
#include "RaZ/Utils/Logger.hpp"

#include "tracy/Tracy.hpp"

#if defined(RAZ_PLATFORM_EMSCRIPTEN)
#include <emscripten.h>
#endif
Expand All @@ -26,6 +28,8 @@ void Application::run() {
}

bool Application::runOnce() {
ZoneScopedN("Application::runOnce");

const auto currentTime = std::chrono::system_clock::now();
m_timeInfo.deltaTime = std::chrono::duration<float>(currentTime - m_lastFrameTime).count();
m_timeInfo.globalTime += m_timeInfo.deltaTime;
Expand All @@ -47,6 +51,12 @@ bool Application::runOnce() {
m_activeWorlds.setBit(worldIndex, false);
}

// Adding a frame mark registers the past frame
// TODO: the application setup (everything up until Application::run() is called, hence including the main function) is merged with the very first frame
// A "fix" would be to add another FrameMark at the top of the run function, but the currently templated callback overload being in a header,
// including Tracy to be used in there wouldn't be a good idea
FrameMark;

return (m_isRunning && !m_activeWorlds.isEmpty());
}

Expand Down
10 changes: 10 additions & 0 deletions src/RaZ/World.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "RaZ/World.hpp"

#include "tracy/Tracy.hpp"

namespace Raz {

Entity& World::addEntity(bool enabled) {
Expand All @@ -22,6 +24,8 @@ void World::removeEntity(const Entity& entity) {
}

bool World::update(const FrameTimeInfo& timeInfo) {
ZoneScopedN("World::update");

refresh();

for (std::size_t systemIndex = 0; systemIndex < m_systems.size(); ++systemIndex) {
Expand All @@ -38,6 +42,8 @@ bool World::update(const FrameTimeInfo& timeInfo) {
}

void World::refresh() {
ZoneScopedN("World::refresh");

if (m_entities.empty())
return;

Expand Down Expand Up @@ -71,6 +77,8 @@ void World::refresh() {
}

void World::destroy() {
ZoneScopedN("World::destroy");

// Entities must be released before the systems, since their destruction may depend on those
m_entities.clear();
m_activeEntityCount = 0;
Expand All @@ -88,6 +96,8 @@ void World::destroy() {
}

void World::sortEntities() {
ZoneScopedN("World::sortEntities");

// Reorganizing the entites, swapping enabled & disabled ones so that the enabled ones are in front
auto firstEntity = m_entities.begin();
auto lastEntity = m_entities.end() - 1;
Expand Down

0 comments on commit 131ec46

Please sign in to comment.