Functions | Variables
timer.h File Reference


#include "localconsts.h"

Go to the source code of this file.


void startTimers ()
void stopTimers ()
int get_elapsed_time (const int startTime)
int get_elapsed_time1 (const int startTime)


volatile int fps
volatile int lps
volatile int tick_time
volatile time_t cur_time
volatile int frame_count
volatile int logic_count

Function Documentation

◆ get_elapsed_time()

int get_elapsed_time ( const int  startTime)

Returns elapsed time. (Warning: supposes the delay is always < 100 seconds)

the elapsed time in milliseconds between two tick values.

Definition at line 94 of file timer.cpp.

95 {
96  const int time = tick_time;
97  if (startTime <= time)
98  {
99  return (time - startTime) * MILLISECONDS_IN_A_TICK;
100  }
101  return (time + (MAX_TICK_VALUE - startTime))
103 }
static const int MILLISECONDS_IN_A_TICK
Definition: timer.h:30
static const int MAX_TICK_VALUE
Definition: timer.cpp:51
volatile int tick_time
Definition: timer.cpp:53

References MAX_TICK_VALUE, MILLISECONDS_IN_A_TICK, and tick_time.

Referenced by Palette::advanceGradient(), Being::getOffset(), Being::logic(), LocalPlayer::logic(), SkillDialog::slowLogic(), and Map::updateAmbientLayers().

◆ get_elapsed_time1()

int get_elapsed_time1 ( const int  startTime)

Definition at line 105 of file timer.cpp.

106 {
107  const int time = tick_time;
108  if (startTime <= time)
109  return time - startTime;
110  return time + (MAX_TICK_VALUE - startTime);
111 }

References MAX_TICK_VALUE, and tick_time.

Referenced by Being::logic(), Game::slowLogic(), and CompoundSprite::updateImages().

◆ startTimers()

void startTimers ( )

Definition at line 113 of file timer.cpp.

114 {
115  // Initialize logic and seconds counters
116  tick_time = 0;
117  mLogicCounterId = SDL_AddTimer(MILLISECONDS_IN_A_TICK, nextTick, nullptr);
118  mSecondsCounterId = SDL_AddTimer(1000, nextSecond, nullptr);
119 }
static uint32_t nextTick(uint32_t interval, void *param)
Definition: timer.cpp:68
static uint32_t nextSecond(uint32_t interval, void *param)
Definition: timer.cpp:80

References MILLISECONDS_IN_A_TICK, anonymous_namespace{timer.cpp}::mLogicCounterId(), anonymous_namespace{timer.cpp}::mSecondsCounterId(), nextSecond(), nextTick(), and tick_time.

Referenced by Client::gameInit().

◆ stopTimers()

void stopTimers ( )

Definition at line 121 of file timer.cpp.

122 {
123  SDL_RemoveTimer(mLogicCounterId);
124  SDL_RemoveTimer(mSecondsCounterId);
125 }

References anonymous_namespace{timer.cpp}::mLogicCounterId(), and anonymous_namespace{timer.cpp}::mSecondsCounterId().

Referenced by Client::gameClear().

Variable Documentation

◆ cur_time

volatile time_t cur_time

Definition at line 58 of file timer.cpp.

◆ fps

volatile int fps

Frames counted in the last second

Definition at line 54 of file timer.cpp.

Referenced by Game::adjustPerfomance(), MapDebugTab::logic(), and nextSecond().

◆ frame_count

volatile int frame_count

Counts the frames during one second

Definition at line 56 of file timer.cpp.

Referenced by Client::gameExec(), and nextSecond().

◆ logic_count

volatile int logic_count

Counts the logic during one second

Definition at line 57 of file timer.cpp.

Referenced by Client::gameExec(), and nextSecond().

◆ lps

volatile int lps

Logic processed per second

Definition at line 55 of file timer.cpp.

Referenced by StatDebugTab::logic(), and nextSecond().

◆ tick_time

volatile int tick_time

Tick counter

Definition at line 53 of file timer.cpp.

Referenced by get_elapsed_time(), get_elapsed_time1(), nextTick(), and startTimers().