fase 1: jail i game a c++ idiomàtic (raii, info::ctx, cheats arreglats)
This commit is contained in:
@@ -1,42 +1,54 @@
|
||||
#include "core/jail/jgame.hpp"
|
||||
|
||||
bool eixir = false;
|
||||
Uint32 updateTicks = 0;
|
||||
Uint32 updateTime = 0;
|
||||
Uint32 cycle_counter = 0;
|
||||
|
||||
void JG_Init() {
|
||||
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);
|
||||
// SDL_WM_SetCaption( title, NULL );
|
||||
updateTime = SDL_GetTicks();
|
||||
}
|
||||
|
||||
void JG_Finalize() {
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
void JG_QuitSignal() {
|
||||
eixir = true;
|
||||
}
|
||||
|
||||
bool JG_Quitting() {
|
||||
return eixir;
|
||||
}
|
||||
|
||||
void JG_SetUpdateTicks(Uint32 milliseconds) {
|
||||
updateTicks = milliseconds;
|
||||
}
|
||||
|
||||
bool JG_ShouldUpdate() {
|
||||
if (SDL_GetTicks() - updateTime > updateTicks) {
|
||||
updateTime = SDL_GetTicks();
|
||||
cycle_counter++;
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Uint32 JG_GetCycleCounter() {
|
||||
return cycle_counter;
|
||||
}
|
||||
#include "core/jail/jgame.hpp"
|
||||
|
||||
namespace {
|
||||
|
||||
bool quitting = false;
|
||||
Uint32 update_ticks = 0;
|
||||
Uint32 update_time = 0;
|
||||
Uint32 cycle_counter = 0;
|
||||
Uint32 last_delta_time = 0;
|
||||
|
||||
} // namespace
|
||||
|
||||
void JG_Init() {
|
||||
SDL_Init(SDL_INIT_VIDEO | SDL_INIT_AUDIO);
|
||||
update_time = SDL_GetTicks();
|
||||
last_delta_time = update_time;
|
||||
}
|
||||
|
||||
void JG_Finalize() {
|
||||
SDL_Quit();
|
||||
}
|
||||
|
||||
void JG_QuitSignal() {
|
||||
quitting = true;
|
||||
}
|
||||
|
||||
bool JG_Quitting() {
|
||||
return quitting;
|
||||
}
|
||||
|
||||
void JG_SetUpdateTicks(Uint32 milliseconds) {
|
||||
update_ticks = milliseconds;
|
||||
}
|
||||
|
||||
bool JG_ShouldUpdate() {
|
||||
const Uint32 now = SDL_GetTicks();
|
||||
if (now - update_time > update_ticks) {
|
||||
update_time = now;
|
||||
cycle_counter++;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
Uint32 JG_GetCycleCounter() {
|
||||
return cycle_counter;
|
||||
}
|
||||
|
||||
Uint32 JG_GetDeltaMs() {
|
||||
const Uint32 now = SDL_GetTicks();
|
||||
const Uint32 delta = now - last_delta_time;
|
||||
last_delta_time = now;
|
||||
return delta;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user