v1.4.4
This commit is contained in:
commit
9c94d113d3
10260 changed files with 1237388 additions and 0 deletions
77
source/game/StarGameTimers.hpp
Normal file
77
source/game/StarGameTimers.hpp
Normal file
|
@ -0,0 +1,77 @@
|
|||
#ifndef STAR_GAME_TIMERS_HPP
|
||||
#define STAR_GAME_TIMERS_HPP
|
||||
|
||||
#include "StarGameTypes.hpp"
|
||||
#include "StarJson.hpp"
|
||||
|
||||
namespace Star {
|
||||
|
||||
struct GameTimer {
|
||||
GameTimer();
|
||||
explicit GameTimer(float time);
|
||||
|
||||
float time;
|
||||
float timer;
|
||||
|
||||
bool tick(float dt = WorldTimestep); // returns true if time is up
|
||||
bool wrapTick(float dt = WorldTimestep); // auto resets
|
||||
void reset();
|
||||
void setDone();
|
||||
void invert();
|
||||
|
||||
bool ready() const;
|
||||
float percent() const;
|
||||
};
|
||||
|
||||
DataStream& operator>>(DataStream& ds, GameTimer& gt);
|
||||
DataStream& operator<<(DataStream& ds, GameTimer const& gt);
|
||||
|
||||
struct SlidingWindow {
|
||||
SlidingWindow();
|
||||
SlidingWindow(float windowSize, size_t resolution, float initialValue);
|
||||
|
||||
GameTimer sampleTimer;
|
||||
float windowSize;
|
||||
size_t resolution;
|
||||
|
||||
float currentMin;
|
||||
float currentMax;
|
||||
float currentAverage;
|
||||
|
||||
size_t currentIndex;
|
||||
std::vector<float> window;
|
||||
|
||||
void reset(float initialValue);
|
||||
void update(function<float()> sampleFunction);
|
||||
void update(float newValue);
|
||||
void processUpdate(float newValue);
|
||||
|
||||
float min();
|
||||
float max();
|
||||
float average();
|
||||
};
|
||||
|
||||
// Keeps long term track of elapsed time based on epochTime.
|
||||
class EpochTimer {
|
||||
public:
|
||||
EpochTimer();
|
||||
explicit EpochTimer(Json json);
|
||||
|
||||
Json toJson() const;
|
||||
|
||||
void update(double newEpochTime);
|
||||
|
||||
double elapsedTime() const;
|
||||
void setElapsedTime(double elapsedTime);
|
||||
|
||||
friend DataStream& operator>>(DataStream& ds, EpochTimer& et);
|
||||
friend DataStream& operator<<(DataStream& ds, EpochTimer const& et);
|
||||
|
||||
private:
|
||||
Maybe<double> m_lastSeenEpochTime;
|
||||
double m_elapsedTime;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue