Refactor to match style
This commit is contained in:
parent
edaae98a38
commit
2f3cc2d820
|
@ -226,7 +226,11 @@ add_executable(fallout2-ce WIN32
|
|||
"src/world_map.h"
|
||||
"src/xfile.cc"
|
||||
"src/xfile.h"
|
||||
"src/FpsLimiter.cc"
|
||||
)
|
||||
|
||||
target_sources(fallout2-ce PUBLIC
|
||||
"src/fps_limiter.cc"
|
||||
"src/fps_limiter.h"
|
||||
)
|
||||
|
||||
target_compile_definitions(fallout2-ce PUBLIC
|
||||
|
|
|
@ -1,18 +0,0 @@
|
|||
#include "FpsLimiter.h"
|
||||
|
||||
FpsLimiter::FpsLimiter(size_t fps):
|
||||
_Fps(fps),
|
||||
_Ticks(0)
|
||||
{
|
||||
}
|
||||
|
||||
void FpsLimiter::Begin()
|
||||
{
|
||||
_Ticks = SDL_GetTicks();
|
||||
}
|
||||
|
||||
void FpsLimiter::End()
|
||||
{
|
||||
if (1000 / _Fps > SDL_GetTicks() - _Ticks)
|
||||
SDL_Delay(1000 / _Fps - (SDL_GetTicks() - _Ticks));
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
#ifndef Fallout2_RE_FpsLimiter_h_
|
||||
#define Fallout2_RE_FpsLimiter_h_
|
||||
|
||||
#include <SDL.h>
|
||||
|
||||
class FpsLimiter
|
||||
{
|
||||
public:
|
||||
FpsLimiter(size_t fps = 60);
|
||||
void Begin();
|
||||
void End();
|
||||
|
||||
private:
|
||||
size_t _Fps;
|
||||
size_t _Ticks;
|
||||
};
|
||||
|
||||
#endif
|
|
@ -0,0 +1,21 @@
|
|||
#include "fps_limiter.h"
|
||||
|
||||
#include <SDL.h>
|
||||
|
||||
FpsLimiter::FpsLimiter(size_t fps)
|
||||
: _fps(fps)
|
||||
, _ticks(0)
|
||||
{
|
||||
}
|
||||
|
||||
void FpsLimiter::mark()
|
||||
{
|
||||
_ticks = SDL_GetTicks();
|
||||
}
|
||||
|
||||
void FpsLimiter::throttle() const
|
||||
{
|
||||
if (1000 / _fps > SDL_GetTicks() - _ticks) {
|
||||
SDL_Delay(1000 / _fps - (SDL_GetTicks() - _ticks));
|
||||
}
|
||||
}
|
|
@ -0,0 +1,15 @@
|
|||
#ifndef FPS_LIMITER_H
|
||||
#define FPS_LIMITER_H
|
||||
|
||||
class FpsLimiter {
|
||||
public:
|
||||
FpsLimiter(size_t fps = 60);
|
||||
void mark();
|
||||
void throttle() const;
|
||||
|
||||
private:
|
||||
const size_t _fps;
|
||||
size_t _ticks;
|
||||
};
|
||||
|
||||
#endif /* FPS_LIMITER_H */
|
|
@ -312,7 +312,7 @@ void mainLoop(FpsLimiter& fpsLimiter)
|
|||
scriptsEnable();
|
||||
|
||||
while (_game_user_wants_to_quit == 0) {
|
||||
fpsLimiter.Begin();
|
||||
fpsLimiter.mark();
|
||||
|
||||
int keyCode = _get_input();
|
||||
gameHandleKey(keyCode, false);
|
||||
|
@ -331,7 +331,7 @@ void mainLoop(FpsLimiter& fpsLimiter)
|
|||
_game_user_wants_to_quit = 2;
|
||||
}
|
||||
|
||||
fpsLimiter.End();
|
||||
fpsLimiter.throttle();
|
||||
}
|
||||
|
||||
scriptsDisable();
|
||||
|
@ -778,7 +778,7 @@ int mainMenuWindowHandleEvents(FpsLimiter& fpsLimiter)
|
|||
|
||||
int rc = -1;
|
||||
while (rc == -1) {
|
||||
fpsLimiter.Begin();
|
||||
fpsLimiter.mark();
|
||||
|
||||
int keyCode = _get_input();
|
||||
|
||||
|
@ -827,7 +827,7 @@ int mainMenuWindowHandleEvents(FpsLimiter& fpsLimiter)
|
|||
}
|
||||
}
|
||||
|
||||
fpsLimiter.End();
|
||||
fpsLimiter.throttle();
|
||||
}
|
||||
|
||||
if (oldCursorIsHidden) {
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
#define MAIN_H
|
||||
|
||||
#include "art.h"
|
||||
#include "FpsLimiter.h"
|
||||
#include "fps_limiter.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
|
|
Loading…
Reference in New Issue