naev 0.11.5
ntime.c File Reference

Handles the Naev time. More...

#include "ntime.h"
#include "economy.h"
#include "hook.h"
#include "nstring.h"

Go to the source code of this file.

Data Structures

struct  NTimeUpdate_t
 Used for storing time increments to not trigger hooks during Lua calls and such. More...
 

Macros

#define NT_SECONDS_DIV   (1000) /* Divider for extracting seconds. */
 
#define NT_SECONDS_DT   (30) /* Update rate, how many seconds are in a real second. */
 
#define NT_CYCLE_SECONDS   ((ntime_t)NT_CYCLE_PERIODS*(ntime_t)NT_PERIOD_SECONDS) /* Seconds in a cycle */
 
#define NT_PERIODS_DIV   ((ntime_t)NT_PERIOD_SECONDS*(ntime_t)NT_SECONDS_DIV) /* Divider for extracting periods. */
 
#define NT_CYCLES_DIV   ((ntime_t)NT_CYCLE_SECONDS*(ntime_t)NT_SECONDS_DIV) /* Divider for extracting cycles. */
 

Functions

void ntime_update (double dt)
 Updatse the time based on realtime.
 
ntime_t ntime_create (int scu, int stp, int stu)
 Creates a time structure.
 
ntime_t ntime_get (void)
 Gets the current time.
 
void ntime_getR (int *cycles, int *periods, int *seconds, double *rem)
 Gets the current time broken into individual components.
 
int ntime_getCycles (ntime_t t)
 Gets the cycles of a time.
 
int ntime_getPeriods (ntime_t t)
 Gets the periods of a time.
 
int ntime_getSeconds (ntime_t t)
 Gets the seconds of a time.
 
double ntime_convertSeconds (ntime_t t)
 Converts the time to seconds.
 
double ntime_getRemainder (ntime_t t)
 Gets the remainder.
 
char * ntime_pretty (ntime_t t, int d)
 Gets the time in a pretty human readable format.
 
void ntime_prettyBuf (char *str, int max, ntime_t t, int d)
 Gets the time in a pretty human readable format filling a preset buffer.
 
void ntime_set (ntime_t t)
 Sets the time absolutely, does NOT generate an event, used at init.
 
void ntime_setR (int cycles, int periods, int seconds, double rem)
 Loads time including remainder.
 
void ntime_inc (ntime_t t)
 Sets the time relatively.
 
void ntime_allowUpdate (int enable)
 Allows the time to update when the game is updating.
 
void ntime_incLagged (ntime_t t)
 Sets the time relatively.
 
void ntime_refresh (void)
 Checks to see if ntime has any hooks pending to run.
 

Variables

static NTimeUpdate_tntime_inclist = NULL
 
static ntime_t naev_time = 0
 
static double naev_remainder = 0.
 
static int ntime_enable = 1
 

Detailed Description

Handles the Naev time.

1 cycle = 5e3 periods = 50e6 seconds 1 period = 10e3 seconds

Generally displayed as: UST <cycles>:<periods>.<seconds> The number of seconds digits can be variable, for example:

UST 630:3726.1 UST 630:3726.12 UST 630:3726.124 UST 630:3726.1248 UST 630:3726.12489

Are all valid.

Definitions / abbreviations:

  • UST: Universal Synchronized Time, the name of the time system.
  • seconds: Smallest named time unit. Equal to the Earth second.
  • periods: Most commonly used time unit. Periods are the new hours. 1 period = 10,000 seconds (about 2.8 Earth hours).
  • cycles: Used for long-term time periods. 1 cycle = 5000 periods (about 579 Earth days).

Definition in file ntime.c.

Macro Definition Documentation

◆ NT_CYCLE_SECONDS

#define NT_CYCLE_SECONDS   ((ntime_t)NT_CYCLE_PERIODS*(ntime_t)NT_PERIOD_SECONDS) /* Seconds in a cycle */

Definition at line 48 of file ntime.c.

◆ NT_CYCLES_DIV

#define NT_CYCLES_DIV   ((ntime_t)NT_CYCLE_SECONDS*(ntime_t)NT_SECONDS_DIV) /* Divider for extracting cycles. */

Definition at line 50 of file ntime.c.

◆ NT_PERIODS_DIV

#define NT_PERIODS_DIV   ((ntime_t)NT_PERIOD_SECONDS*(ntime_t)NT_SECONDS_DIV) /* Divider for extracting periods. */

Definition at line 49 of file ntime.c.

◆ NT_SECONDS_DIV

#define NT_SECONDS_DIV   (1000) /* Divider for extracting seconds. */

Definition at line 46 of file ntime.c.

◆ NT_SECONDS_DT

#define NT_SECONDS_DT   (30) /* Update rate, how many seconds are in a real second. */

Definition at line 47 of file ntime.c.

Function Documentation

◆ ntime_allowUpdate()

void ntime_allowUpdate ( int enable)

Allows the time to update when the game is updating.

Parameters
enableWhether or not to enable time updating.

Definition at line 251 of file ntime.c.

◆ ntime_convertSeconds()

double ntime_convertSeconds ( ntime_t t)

Converts the time to seconds.

Parameters
tTime to convert.
Returns
Time in seconds.

Definition at line 153 of file ntime.c.

◆ ntime_create()

ntime_t ntime_create ( int scu,
int stp,
int stu )

Creates a time structure.

Definition at line 94 of file ntime.c.

◆ ntime_get()

ntime_t ntime_get ( void )

Gets the current time.

Returns
The current time in milliseconds.

Definition at line 108 of file ntime.c.

◆ ntime_getCycles()

int ntime_getCycles ( ntime_t t)

Gets the cycles of a time.

Definition at line 127 of file ntime.c.

◆ ntime_getPeriods()

int ntime_getPeriods ( ntime_t t)

Gets the periods of a time.

Definition at line 135 of file ntime.c.

◆ ntime_getR()

void ntime_getR ( int * cycles,
int * periods,
int * seconds,
double * rem )

Gets the current time broken into individual components.

Definition at line 116 of file ntime.c.

◆ ntime_getRemainder()

double ntime_getRemainder ( ntime_t t)

Gets the remainder.

Definition at line 161 of file ntime.c.

◆ ntime_getSeconds()

int ntime_getSeconds ( ntime_t t)

Gets the seconds of a time.

Definition at line 143 of file ntime.c.

◆ ntime_inc()

void ntime_inc ( ntime_t t)

Sets the time relatively.

Parameters
tTime modifier in seconds.

Definition at line 236 of file ntime.c.

◆ ntime_incLagged()

void ntime_incLagged ( ntime_t t)

Sets the time relatively.

This does NOT call hooks and such, they must be run with ntime_refresh manually later.

Parameters
tTime modifier in seconds.

Definition at line 264 of file ntime.c.

◆ ntime_pretty()

char * ntime_pretty ( ntime_t t,
int d )

Gets the time in a pretty human readable format.

Parameters
tTime to print (in seconds), if 0 it'll use the current time.
dNumber of digits to use.
Returns
The time in a human readable format (must free).

Definition at line 173 of file ntime.c.

◆ ntime_prettyBuf()

void ntime_prettyBuf ( char * str,
int max,
ntime_t t,
int d )

Gets the time in a pretty human readable format filling a preset buffer.

Parameters
[out]strBuffer to use.
maxMaximum length of the buffer (recommended 64).
tTime to print (in seconds), if 0 it'll use the current time.
dNumber of digits to use.

Definition at line 188 of file ntime.c.

◆ ntime_refresh()

void ntime_refresh ( void )

Checks to see if ntime has any hooks pending to run.

Definition at line 288 of file ntime.c.

◆ ntime_set()

void ntime_set ( ntime_t t)

Sets the time absolutely, does NOT generate an event, used at init.

Parameters
tAbsolute time to set to in seconds.

Definition at line 215 of file ntime.c.

◆ ntime_setR()

void ntime_setR ( int cycles,
int periods,
int seconds,
double rem )

Loads time including remainder.

Definition at line 224 of file ntime.c.

◆ ntime_update()

void ntime_update ( double dt)

Updatse the time based on realtime.

Allow updates?

Definition at line 69 of file ntime.c.

Variable Documentation

◆ naev_remainder

double naev_remainder = 0.
static

Remainder when updating, to try to keep in perfect sync.

Definition at line 63 of file ntime.c.

◆ naev_time

ntime_t naev_time = 0
static

Contains the current time in milliseconds.

Definition at line 62 of file ntime.c.

◆ ntime_enable

int ntime_enable = 1
static

Definition at line 64 of file ntime.c.

◆ ntime_inclist

NTimeUpdate_t* ntime_inclist = NULL
static

Time increment list.

Definition at line 60 of file ntime.c.