Skip to content

Commit d1757a2

Browse files
committed
fix tps display
1 parent ee572e5 commit d1757a2

File tree

8 files changed

+14
-13
lines changed

8 files changed

+14
-13
lines changed

src/backend/evaluator/evalSimulator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ class EvalSimulator {
5454
inline void removeConnection(SimPauseGuard& pauseGuard, EvalConnection connection) {
5555
gateSubstituter.removeConnection(pauseGuard, connection);
5656
}
57-
inline float getAverageTickrate() const {
57+
inline double getAverageTickrate() const {
5858
return gateSubstituter.getAverageTickrate();
5959
}
6060
private:

src/backend/evaluator/evaluator.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ class Evaluator {
9393
unsigned long long getTickrate() const { return evalConfig.getTargetTickrate(); }
9494
void setUseTickrate(bool useTickrate) { evalConfig.setTickrateLimiter(useTickrate); }
9595
bool getUseTickrate() const { return evalConfig.isTickrateLimiterEnabled(); }
96-
float getRealTickrate() const { return evalSimulator.getAverageTickrate(); }
96+
double getRealTickrate() const { return evalSimulator.getAverageTickrate(); }
9797
void makeEdit(DifferenceSharedPtr difference, circuit_id_t circuitId);
9898
logic_state_t getState(const Address& address);
9999
bool getBoolState(const Address& address) {

src/backend/evaluator/gateSubstituter.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ class GateSubstituter {
191191
}
192192
}
193193

194-
inline float getAverageTickrate() const {
194+
inline double getAverageTickrate() const {
195195
return replacer.getAverageTickrate();
196196
}
197197

src/backend/evaluator/logicSimulator.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ LogicSimulator::~LogicSimulator() {
3232

3333
void LogicSimulator::clearState() { }
3434

35-
float LogicSimulator::getAverageTickrate() const {
35+
double LogicSimulator::getAverageTickrate() const {
3636
return averageTickrate.load(std::memory_order_acquire);
3737
}
3838

@@ -74,11 +74,11 @@ void LogicSimulator::simulationLoop() {
7474
// Calculate current tickrate in Hz (ticks per second)
7575
double currentTickrate = 1.0e9 / static_cast<double>(deltaTime.count());
7676
double dtSeconds = std::chrono::duration<double>(deltaTime).count();
77-
float alpha = 1.0 - std::exp(-dtSeconds * std::log(2.0) / tickrateHalflife);
77+
double alpha = 1.0 - std::exp(-dtSeconds * std::log(2.0) / tickrateHalflife);
7878

7979
// Apply EMA: EMA_new = alpha * current + (1 - alpha) * EMA_old
80-
float currentEMA = averageTickrate.load(std::memory_order_acquire);
81-
float newEMA = alpha * static_cast<float>(currentTickrate) + (1.0f - alpha) * currentEMA;
80+
double currentEMA = averageTickrate.load(std::memory_order_acquire);
81+
double newEMA = alpha * currentTickrate + (1.0 - alpha) * currentEMA;
8282
averageTickrate.store(newEMA, std::memory_order_release);
8383
}
8484
} else {

src/backend/evaluator/logicSimulator.h

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ friend class SimPauseGuard;
2929
std::vector<simulator_id_t>& dirtySimulatorIds);
3030
~LogicSimulator();
3131
void clearState();
32-
float getAverageTickrate() const;
32+
double getAverageTickrate() const;
3333
void setState(simulator_id_t id, logic_state_t state);
3434
void setStates(const std::vector<simulator_id_t>& ids, const std::vector<logic_state_t>& states);
3535

@@ -117,8 +117,9 @@ friend class SimPauseGuard;
117117
void addOutputDependency(simulator_id_t outputId, simulator_id_t dependentGateId);
118118
void removeOutputDependency(simulator_id_t outputId, simulator_id_t dependentGateId);
119119

120-
std::atomic<float> averageTickrate { 0.0 };
121-
float tickrateHalflife { 0.25 };
120+
// Use double precision internally to avoid float rounding sticking near 2^23 (~8,388,608)
121+
std::atomic<double> averageTickrate { 0.0 };
122+
double tickrateHalflife { 0.25 };
122123

123124
std::vector<simulator_id_t>& dirtySimulatorIds;
124125
};

src/backend/evaluator/replacer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ class Replacer {
249249
simulatorOptimizer.removeConnection(pauseGuard, connection);
250250
}
251251

252-
inline float getAverageTickrate() const {
252+
inline double getAverageTickrate() const {
253253
return simulatorOptimizer.getAverageTickrate();
254254
}
255255

src/backend/evaluator/simulatorOptimizer.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -207,7 +207,7 @@ class SimulatorOptimizer {
207207
return GateType::NONE;
208208
}
209209

210-
inline float getAverageTickrate() const {
210+
inline double getAverageTickrate() const {
211211
return simulator.getAverageTickrate();
212212
}
213213

src/gui/mainWindow/circuitView/circuitViewWidget.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ void CircuitViewWidget::render() {
222222
Evaluator* evaluator = circuitView->getEvaluator();
223223
std::string tpsText = "Real tps: N/A";
224224
if (evaluator) {
225-
tpsText = "Real tps: " + std::format("{:.2f}", (double)(evaluator->getRealTickrate()));
225+
tpsText = "Real tps: " + std::format("{:.2f}", evaluator->getRealTickrate());
226226
}
227227
Rml::Element* realTpsDisplay = document->GetElementById("real-tps-display");
228228
if (realTpsDisplay) {

0 commit comments

Comments
 (0)