Skip to content

Commit

Permalink
show created cells per second
Browse files Browse the repository at this point in the history
  • Loading branch information
chrxh committed Aug 2, 2024
1 parent 7e841b1 commit 6750c40
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 13 deletions.
4 changes: 2 additions & 2 deletions source/Gui/StatisticsWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,10 +242,10 @@ void _StatisticsWindow::processTablesTab()

ImGui::TableNextRow();
ImGui::TableSetColumnIndex(0);
AlienImGui::Text(StringHelper::format(_tableLiveStatistics.getCreatedCells()));
AlienImGui::Text(StringHelper::format(_tableLiveStatistics.getCreatedCellsPerSecond()));

ImGui::TableSetColumnIndex(1);
AlienImGui::Text("Created cells");
AlienImGui::Text("Created cells / sec");


ImGui::EndTable();
Expand Down
38 changes: 31 additions & 7 deletions source/Gui/TableLiveStatistics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

bool TableLiveStatistics::isDataAvailable() const
{
return _lastData.has_value();
return _currentData.has_value();
}

namespace
Expand All @@ -17,15 +17,39 @@ namespace
}
}

uint64_t TableLiveStatistics::getCreatedCells() const
float TableLiveStatistics::getCreatedCellsPerSecond() const
{
return sum(_lastData->accumulated.numCreatedCells);
if (!_lastDataTimepoint.has_value()) {
return 0;
}

auto currentCreatedCells = sum(_currentData->accumulated.numCreatedCells);
auto lastCreatedCells = sum(_lastData->accumulated.numCreatedCells);
return (toFloat(currentCreatedCells) - toFloat(lastCreatedCells))
/ toFloat(std::chrono::duration_cast<std::chrono::milliseconds>(*_currentDataTimepoint - *_lastDataTimepoint).count()) * 5000;
}

float TableLiveStatistics::getReplicatorsPerSecond() const
{
return 0;
}

void TableLiveStatistics::update(TimelineStatistics const& data)
{
_lastData = data;
//auto timepoint = std::chrono::steady_clock::now();
//auto duration =
// _lastTimepoint.has_value() ? static_cast<int>(std::chrono::duration_cast<std::chrono::milliseconds>(timepoint - *_lastTimepoint).count()) : 0;
auto timepoint = std::chrono::steady_clock::now();

if (!_currentDataTimepoint.has_value()) {
_currentData = data;
_currentDataTimepoint = timepoint;
return;
}

auto duration = static_cast<int>(std::chrono::duration_cast<std::chrono::milliseconds>(timepoint - *_currentDataTimepoint).count());
if (duration > 5000) {
_lastData = _currentData;
_lastDataTimepoint = _currentDataTimepoint;

_currentData = data;
_currentDataTimepoint = timepoint;
}
}
10 changes: 6 additions & 4 deletions source/Gui/TableLiveStatistics.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ class TableLiveStatistics
public:
bool isDataAvailable() const;

uint64_t getCreatedCells() const;
uint64_t getCreatedCellsPerSecond() const;
float getCreatedCellsPerSecond() const;
float getReplicatorsPerSecond() const;

void update(TimelineStatistics const& data);

private:
std::optional<TimelineStatistics> _currentData;
std::optional<std::chrono::steady_clock::time_point> _currentDataTimepoint;

std::optional<TimelineStatistics> _lastData;
std::optional<TimelineStatistics> _lastSecondData;
std::optional<std::chrono::steady_clock::time_point> _lastSecondTimepoint;
std::optional<std::chrono::steady_clock::time_point> _lastDataTimepoint;
};

0 comments on commit 6750c40

Please sign in to comment.