20#ifndef HEADER_MAIN_LOOP_HPP
21#define HEADER_MAIN_LOOP_HPP
23#include "utils/synchronised.hpp"
33 using TimePoint = std::chrono::steady_clock::time_point;
37 std::atomic_bool m_request_abort;
39 std::atomic_bool m_paused;
47 bool m_frame_before_loading_world;
49 bool m_download_assets;
53 TimePoint m_curr_time;
54 TimePoint m_prev_time;
55 unsigned m_parent_pid;
58 double convertToTime(
const TimePoint& cur,
const TimePoint& prev)
const
60 auto duration = cur - prev;
62 std::chrono::duration_cast<std::chrono::nanoseconds>(duration);
63 return value.count() / (1000.0 * 1000.0);
66 MainLoop(
unsigned parent_pid,
bool download_assets =
false);
71 void requestAbort() { m_request_abort =
true; }
74 void renderGUI(
int phase,
int loop_index=-1,
int loop_size=-1);
79 void setFrameBeforeLoadingWorld() { m_frame_before_loading_world =
true; }
81 void setTicksAdjustment(
int ticks)
83 m_ticks_adjustment.
lock();
84 m_ticks_adjustment.
getData() += ticks;
85 m_ticks_adjustment.
unlock();
88 void setPaused(
bool val) { m_paused.store(val); }
90 bool isPaused()
const {
return m_paused.load(); }
Management class for the whole gameflow, this is where the main-loop is.
Definition: main_loop.hpp:31
void run()
Run the actual main loop.
Definition: main_loop.cpp:400
void updateRace(int ticks, bool fast_forward)
Updates all race related objects.
Definition: main_loop.cpp:320
double getLimitedDt()
Returns the current dt, which guarantees a limited frame rate.
Definition: main_loop.cpp:196
std::atomic_bool m_abort
True if the main loop should exit.
Definition: main_loop.hpp:35
bool m_throttle_fps
True if the frame rate should be throttled.
Definition: main_loop.hpp:42
void abort()
Set the abort flag, causing the mainloop to be left.
Definition: main_loop.hpp:70
bool m_allow_large_dt
True if dt is not decreased for low fps.
Definition: main_loop.hpp:45
void renderGUI(int phase, int loop_index=-1, int loop_size=-1)
Renders the GUI.
Definition: main_loop.cpp:756
bool isAborted() const
Returns true if STK is to be stoppe.
Definition: main_loop.hpp:77
A variable that is automatically synchronised using pthreads mutex.
Definition: synchronised.hpp:28
TYPE & getData()
Returns a reference to the original data file.
Definition: synchronised.hpp:82
void lock() const
Locks the mutex.
Definition: synchronised.hpp:95
void unlock() const
Unlocks the mutex.
Definition: synchronised.hpp:99
Declares the general types that are used by the network.