Skip to content

Commit

Permalink
Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
Eirenliel committed Dec 7, 2024
1 parent 1f87604 commit 9642b38
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 35 deletions.
22 changes: 7 additions & 15 deletions src/status/TPSCounter.cpp
Original file line number Diff line number Diff line change
@@ -1,34 +1,26 @@
#include "TPSCounter.h"

void TPSCounter::reset()
{
void TPSCounter::reset() {
_lastUpdate = _lastAverageUpdate = millis();
_tps = _averagedTps = 0.0;
_averageUpdatesCounter = 0;
}

void TPSCounter::update()
{
void TPSCounter::update() {
long time = millis();
long sinceLastUpdate = millis() - _lastUpdate;
long sinceAvgLastUpdate = millis() - _lastAverageUpdate;
_lastUpdate = time;
_tps = 1000.0 / static_cast<float>(sinceLastUpdate);
if(sinceAvgLastUpdate > 1000)
{
if (sinceAvgLastUpdate > 1000) {
_lastAverageUpdate = time;
_averagedTps = 1000.0 / static_cast<float>(sinceAvgLastUpdate) * _averageUpdatesCounter;
_averagedTps
= 1000.0 / static_cast<float>(sinceAvgLastUpdate) * _averageUpdatesCounter;
_averageUpdatesCounter = 0;
}
_averageUpdatesCounter++;
}

float TPSCounter::getAveragedTPS()
{
return _averagedTps;
}
float TPSCounter::getAveragedTPS() { return _averagedTps; }

float TPSCounter::getTPS()
{
return _tps;
}
float TPSCounter::getTPS() { return _tps; }
40 changes: 20 additions & 20 deletions src/status/TPSCounter.h
Original file line number Diff line number Diff line change
@@ -1,37 +1,37 @@
/*
SlimeVR Code is placed under the MIT license
Copyright (c) 2024 Eiren Rain & SlimeVR contributors
SlimeVR Code is placed under the MIT license
Copyright (c) 2024 Eiren Rain & SlimeVR contributors
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#ifndef _H_TPS_COUNTER_
#define _H_TPS_COUNTER_

#include <Arduino.h>

class TPSCounter
{
class TPSCounter {
public:
virtual void reset();
virtual void update();
virtual float getAveragedTPS();
virtual float getTPS();

private:
long _lastUpdate;
long _lastAverageUpdate;
Expand All @@ -40,4 +40,4 @@ class TPSCounter
float _tps;
};

#endif // _H_TPS_COUNTER_
#endif // _H_TPS_COUNTER_

0 comments on commit 9642b38

Please sign in to comment.