Browse Source

remove PerfCounter, rely on tracy

opengl-renderer-broken
Martin Dørum 3 years ago
parent
commit
9dd2bc1337
5 changed files with 0 additions and 122 deletions
  1. 0
    1
      libswan/CMakeLists.txt
  2. 0
    55
      libswan/include/swan/PerfCounter.h
  3. 0
    1
      libswan/include/swan/swan.h
  4. 0
    52
      libswan/src/PerfCounter.cc
  5. 0
    13
      src/main.cc

+ 0
- 1
libswan/CMakeLists.txt View File

@@ -13,7 +13,6 @@ add_library(libswan SHARED
src/ItemStack.cc
src/Mod.cc
src/OS.cc
src/PerfCounter.cc
src/Resource.cc
src/Tile.cc
src/World.cc

+ 0
- 55
libswan/include/swan/PerfCounter.h View File

@@ -1,55 +0,0 @@
#include "util.h"

#include <array>

namespace Swan {

class PerfCounter {
public:
template<typename T = double, size_t size = 64>
class Counter {
public:
void count(T val) {
buf_[idx_] = val;
idx_ = (idx_ + 1) % size;
}

// Fill a buffer with data, in the order they were written
template<typename DestT = T>
void fill(std::array<DestT, size> &buf) {
size_t r = idx_;
size_t w = 0;
do {
buf[w++] = (DestT)buf_[r];
r = (r + 1) % size;
} while (r != idx_);
}

private:
T buf_[size] = {};
size_t idx_ = 0;
};

void render();

void countTotalTime(double secs) { total_time_.count(secs); }
void countFrameTime(double secs) { frame_time_.count(secs); }
void countGameUpdate(double secs) { game_update_.count(secs); }
void countGameTick(double secs) { game_tick_.count(secs); }
void countGameDraw(double secs) { game_draw_.count(secs); }
void countGameUpdatesPerFrame(double count) { game_updates_per_frame_.count(count); }
void countRenderPresent(double secs) { render_present_.count(secs); }
void countMemoryUsage(double bytes) { memory_usage_.count(bytes); }

private:
Counter<> total_time_;
Counter<> frame_time_;
Counter<> game_update_;
Counter<> game_tick_;
Counter<> game_draw_;
Counter<> game_updates_per_frame_;
Counter<> render_present_;
Counter<> memory_usage_;
};

}

+ 0
- 1
libswan/include/swan/swan.h View File

@@ -11,7 +11,6 @@
#include <swan/Item.h>
#include <swan/ItemStack.h>
#include <swan/Mod.h>
#include <swan/PerfCounter.h>
#include <swan/OS.h>
#include <swan/Resource.h>
#include <swan/SlotVector.h>

+ 0
- 52
libswan/src/PerfCounter.cc View File

@@ -1,52 +0,0 @@
#include "PerfCounter.h"

#include <imgui.h>
#include <imgui_plot.h>

#include "util.h"

namespace Swan {

void PerfCounter::render() {
Deferred<ImGui::End> win;
if (!ImGui::Begin("Perf Stats"))
return;

std::array<float, 64> buf;
ImGui::PlotConfig conf;

conf.values = { .ys = buf.data(), .count = 64 };
conf.scale = { 0, 1 / 30.0 };
conf.frame_size = { ImGui::GetWindowContentRegionWidth(), 30 },

total_time_.fill(buf);
ImGui::Text("Total Time");
ImGui::Plot("Total Time", conf);

render_present_.fill(buf);
ImGui::Text("Render Present");
ImGui::Plot("Render Present", conf);

frame_time_.fill(buf);
ImGui::Text("Frame Times");
ImGui::Plot("Frame Times", conf);

game_update_.fill(buf);
ImGui::Text("Game Update");
ImGui::Plot("Game Update", conf);

game_draw_.fill(buf);
ImGui::Text("Game Draw");
ImGui::Plot("Game Draw", conf);

game_tick_.fill(buf);
ImGui::Text("Game Tick");
ImGui::Plot("Game Tick", conf);

game_updates_per_frame_.fill(buf);
conf.scale = { 0, 3 };
ImGui::Text("Game Updates Per Frame");
ImGui::Plot("Game Updates Per Frame", conf);
}

}

+ 0
- 13
src/main.cc View File

@@ -113,8 +113,6 @@ int main(int argc, char **argv) {
std::vector<std::string> mods{ "core.mod" };
game.createWorld("core::default", mods);

PerfCounter pcounter;

auto prev_time = std::chrono::steady_clock::now();

float fps_acc = 0;
@@ -210,13 +208,11 @@ int main(int argc, char **argv) {
RTClock update_clock;
if (dt <= 1 / 25.0) {
ZoneScopedN("game update");
pcounter.countGameUpdatesPerFrame(1);
game.update(dt);

// Complex case: run multiple steps this iteration
} else {
int count = (int)ceil(dt / (1/30.0));
pcounter.countGameUpdatesPerFrame(count);
float delta = dt / (float)count;
info << "Delta time " << dt << "s. Running " << count
<< " updates in one frame, with a delta as if we had "
@@ -226,7 +222,6 @@ int main(int argc, char **argv) {
game.update(delta);
}
}
pcounter.countGameUpdate(update_clock.duration());

// Tick at a consistent TICK_RATE
tick_acc += dt;
@@ -235,7 +230,6 @@ int main(int argc, char **argv) {
tick_acc -= 1.0 / TICK_RATE;
RTClock tick_clock;
game.tick(1.0 / TICK_RATE);
pcounter.countGameTick(tick_clock.duration());
}

{
@@ -252,12 +246,8 @@ int main(int argc, char **argv) {
ZoneScopedN("game draw");
RTClock draw_clock;
game.draw();
pcounter.countGameDraw(draw_clock.duration());
}

pcounter.countFrameTime(total_time_clock.duration());
pcounter.render();

// Render ImGUI
{
ZoneScopedN("imgui render");
@@ -271,9 +261,6 @@ int main(int argc, char **argv) {
SDL_RenderPresent(renderer.get());
}
FrameMark
pcounter.countRenderPresent(present_clock.duration());

pcounter.countTotalTime(total_time_clock.duration());
}

exit:

Loading…
Cancel
Save