summaryrefslogtreecommitdiff
path: root/src/common.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/common.hpp')
-rw-r--r--src/common.hpp24
1 files changed, 19 insertions, 5 deletions
diff --git a/src/common.hpp b/src/common.hpp
index 846b166..df9c8d1 100644
--- a/src/common.hpp
+++ b/src/common.hpp
@@ -35,6 +35,11 @@ extern bool debug_draw_paths;
extern bool debug_draw_tile_coords;
extern bool debug_AI;
+// time in nanoseconds
+// nclock() never returns 0, so it can be used as a null value
+typedef uint64_t ntime_t;
+ntime_t nclock(void);
+
namespace procgen {
class prng_t {
uint32_t state = 0;
@@ -240,15 +245,23 @@ namespace game {
public:
world::world_t world;
interface::state_t *interface;
- double now = 0.0, dt;
- bool paused = false;
procgen::prng_t dice_prng;
std::unordered_set<entity_t*> awake_entities;
std::unordered_set<unit_t*> selected_units;
+ ntime_t time; // game time
+ double now, dt; // FIXME: refactor the code, use ntime_t everywhere
+
+ // frame timing data (game runs at a different frequency than the renderer)
+ bool paused;
+ ntime_t t0;
+ size_t frames = 0, frames_since_t0, frames_behind = 0;
+
void start(void);
void stop(void);
- void tick(double now_, double dt_);
+ void tick(ntime_t time);
+ void pause(void);
+ void resume(void);
// These are called by the interface.
void select(rectf_t rect);
@@ -355,14 +368,15 @@ namespace render {
void drender_text(rectf_t rect, std::string str);
void drender_entity(world::entity_t *ent);
public:
- double now, dt;
+ ntime_t time;
+ double dt;
struct {
size_t sectors, tiles, entities;
} stats;
state_t(sf::RenderWindow *window_);
- void begin_frame(double time_, double dt_);
+ void begin_frame(ntime_t time_, double dt);
void end_frame(void);
void render(game::state_t *game);