10 #include <GLFW/glfw3.h> 43 float accumulator = 0.0f;
57 while (accumulator >= interval) {
60 accumulator -= interval;
64 float alpha = accumulator / interval;
94 double TimeUtil::lastLoopTime = 0.0;
95 float TimeUtil::timeCount = 0.0f;
96 int TimeUtil::fps = 0;
97 int TimeUtil::fpsCount = 0;
98 int TimeUtil::ups = 0;
99 int TimeUtil::upsCount = 0;
101 TimeUtil::TimeUtil(
void) {
106 lastLoopTime = getTime();
110 return glfwGetTime();
115 double now = getTime();
116 float delta = float(now - lastLoopTime);
127 if (timeCount > 1.0f) {
151 return fps > 0 ? fps : fpsCount;
156 return ups > 0 ? ups : upsCount;
static void incUPS()
Increments the UPS counter by one.
~Application(void)
Destroys the application.
void update()
Convenience method to swap buffers and poll events in one call.
void sync(int fps)
Syncs the window framerate to specified FPS.
void showInfoTitle()
Shows informations in the title.
void run()
Starts the application.
virtual void renderScene(float alpha)=0
This method is intended to used for drawing the scene.
static void clearEvents()
Clears the event list, this should be called after every loop.
void mainLoop()
The main loop is a fixed timestep loop.
Window * window
The window of this application.
static void init()
Initializes the time utility.
virtual void updateScene(float delta)=0
This method is intended to update objects of the application.
Generic namespace for the SimpleGL framework.
Application(void)
Initializes a new application.
static float getDelta()
Returns the time that have passed since the last loop.
static void incFPS()
Increments the FPS counter by one.
bool shouldClose()
Checks the close flag for the window.
virtual void clear()=0
This method is intended to clear the color and depth buffers.
static int getFPS()
Returns the current frames per second.
int targetUps
Stores the desired UPS.
static void update()
Updates FPS and UPS if a whole second has passed.
virtual void handleEvents(std::vector< Event * > events)=0
This method is intended to handle events like user input.
bool running
Tells if the application is running.
static int getUPS()
Returns the current updates per second.
static double getLastLoopTime()
Returns the last loop time.
virtual void dispose()
Disposes the application.
void init()
Initializes the application.
static void terminate()
Terminates GLFW, this should only be called at the end of the application.
static std::vector< Event * > getEvents()
Returns the list of events.
int targetFps
Stores the desired FPS.
static double getTime()
Returns the application time in seconds.