1 #ifndef NONBLOCKING_GAME_3D_H
2 #define NONBLOCKING_GAME_3D_H
26 typedef std::chrono::steady_clock localclock;
32 localclock::time_point timeOfLastFrame;
34 void handleFrameRate() {
35 using std::chrono::seconds;
36 using std::chrono::microseconds;
37 using std::chrono::duration_cast;
39 microseconds frametime = duration_cast<microseconds>(seconds(1l)) / (int)fps;
41 localclock::time_point theoretical_next_frame = timeOfLastFrame + frametime;
43 auto wait_time = theoretical_next_frame - localclock::now();
45 if (wait_time.count() > 0) {
46 microseconds wait_time_in_us = duration_cast<microseconds>(wait_time);
47 usleep(wait_time_in_us.count());
50 timeOfLastFrame = localclock::now();
64 registerKeyListener(&ih);
72 timeOfLastFrame = localclock::now();
80 char* str_limit = getenv(
"FORCE_BRIDGES_FRAMELIMIT");
81 if (str_limit !=
nullptr) {
85 std::cerr <<
"Setting framelimit to " << framelimit << std::endl;
94 if (framelimit > 0 && frame > framelimit)
This class extends the GameBase class to 3D environments.
Definition: GameBase3D.h:22
void render()
Renders the game.
Definition: GameBase3D.h:90
void registerKeyListener(KeypressListener *p)
register a new KeypressListener
Definition: GameBase3D.h:82
void quit()
calling this function causes the game to end.
Definition: GameBase3D.h:107
bool gameover() const
Definition: GameBase3D.h:138
virtual void gameLoop()=0
This function is called once per frame of the game.
virtual void initialize()=0
This function is called once when the game starts.
This class is an extension of the NonBlockingGame class to 3D game environments.
Definition: NonBlockingGame3D.h:21
double getFrameRate() const
What frame rate is the game running at?
Definition: NonBlockingGame3D.h:105
bool keyS()
Is S currently pressed?
Definition: NonBlockingGame3D.h:154
bool keyLeft()
Is Left currently pressed?
Definition: NonBlockingGame3D.h:112
NonBlockingGame3D(int assignmentID, std::string username, std::string apikey)
Definition: NonBlockingGame3D.h:60
bool keyD()
Is D currently pressed?
Definition: NonBlockingGame3D.h:161
bool keySpace()
Is Space currently pressed?
Definition: NonBlockingGame3D.h:175
void start()
Call this function from main to start the game. Runs exactly once.
Definition: NonBlockingGame3D.h:71
bool keyRight()
Is Right currently pressed?
Definition: NonBlockingGame3D.h:119
bool keyW()
Is W currently pressed?
Definition: NonBlockingGame3D.h:140
bool keyQ()
Is Q currently pressed?
Definition: NonBlockingGame3D.h:168
bool keyA()
Is A currently pressed?
Definition: NonBlockingGame3D.h:147
virtual ~NonBlockingGame3D()=default
bool keyDown()
Is Down currently pressed?
Definition: NonBlockingGame3D.h:133
bool keyUp()
Is Up currently pressed?
Definition: NonBlockingGame3D.h:126
Support for drawing Bar charts.
Definition: alltypes.h:4