Crossfire Server, Trunk  R20513
Macros | Functions | Variables
time.c File Reference

In-game time functions. More...

#include "global.h"
#include <assert.h>
#include <math.h>
#include "tod.h"
#include <stdio.h>
#include <sys/types.h>
#include <sys/time.h>
Include dependency graph for time.c:

Go to the source code of this file.

Macros

#define PBUFLEN   100
 Size of history buffer. More...
 

Functions

const char * get_month_name (const int index)
 give access to month names More...
 
const char * get_periodofday (const int index)
 give access to weekday names More...
 
const char * get_season_name (const int index)
 give access to season names More...
 
void get_tod (timeofday_t *tod)
 Computes the ingame time of the day. More...
 
const char * get_weekday (const int index)
 give access to weekday names More...
 
static void log_time (uint32_t process_utime)
 Adds time to our history list. More...
 
static void print_tod (object *op)
 Prints the time. More...
 
void reset_sleep (void)
 Initialise all variables used in the timing routines. More...
 
long seconds (void)
 Return wall clock time in seconds. More...
 
void set_max_time (long t)
 Sets the max speed. More...
 
void sleep_delta (void)
 Sleep until the next tick. More...
 
int tick_length (float seconds)
 Calculate the number of ticks that correspond to real time. More...
 
const char * time_format_time (const timeofday_t *tod, char *buf, size_t bufsize)
 Formats a timestamp in Crossfire time. More...
 
void time_info (object *op)
 Players wants to know the time. More...
 
static void timespec_add (struct timespec *time, long usec)
 Add 'usec' microseconds to the given timespec. More...
 
static long timespec_diff (struct timespec *end, struct timespec *start)
 Return the difference between two timespec's in microseconds. More...
 

Variables

static struct timespec game_time
 
uint32_t max_time = MAX_TIME
 Gloabal variables: More...
 
static const char *const month_name [MONTHS_PER_YEAR]
 Months. More...
 
static const char *const periodsofday [PERIODS_PER_DAY]
 
static uint32_t process_max_utime = 0
 Longest cycle time. More...
 
static uint32_t process_min_utime = 999999999
 Shortest cycle time. More...
 
static uint32_t process_tot_mtime
 ? More...
 
static uint32_t process_utime_long_count
 ? More...
 
static uint32_t process_utime_save [PBUFLEN]
 Historic data. More...
 
static uint32_t psaveind
 Index in process_utime_save. More...
 
uint32_t pticks
 ? More...
 
static const char *const season_name [SEASONS_PER_YEAR+1]
 Ingame seasons. More...
 
unsigned long todtick
 Ingame time. More...
 
static const char *const weekdays [DAYS_PER_WEEK]
 Days of the week. More...
 

Detailed Description

In-game time functions.

Definition in file time.c.

Macro Definition Documentation

#define PBUFLEN   100

Size of history buffer.

Definition at line 39 of file time.c.

Referenced by log_time(), reset_sleep(), and time_info().

Function Documentation

const char* get_month_name ( const int  index)

give access to month names

Definition at line 109 of file time.c.

References month_name, and MONTHS_PER_YEAR.

Referenced by cfapi_get_month_name(), and START_TEST().

Here is the caller graph for this function:

const char* get_periodofday ( const int  index)

give access to weekday names

Definition at line 102 of file time.c.

References PERIODS_PER_DAY, and periodsofday.

Referenced by cfapi_get_periodofday_name().

Here is the caller graph for this function:

const char* get_season_name ( const int  index)

give access to season names

Definition at line 123 of file time.c.

References season_name, and SEASONS_PER_YEAR.

Referenced by cfapi_get_season_name(), and START_TEST().

Here is the caller graph for this function:

void get_tod ( timeofday_t tod)

Computes the ingame time of the day.

Parameters
[out]todwhere to store information. Must not be NULL.

Definition at line 215 of file time.c.

References _timeofday::day, _timeofday::dayofweek, DAYS_PER_MONTH, DAYS_PER_WEEK, _timeofday::hour, HOURS_PER_DAY, HOURS_PER_MONTH, HOURS_PER_YEAR, _timeofday::minute, _timeofday::month, MONTHS_PER_YEAR, _timeofday::periodofday, pticks, PTICKS_PER_CLOCK, _timeofday::season, todtick, _timeofday::weekofmonth, WEEKS_PER_MONTH, and _timeofday::year.

Referenced by cfapi_get_time(), clock_type_apply(), print_tod(), set_darkness_map(), and tick_the_clock().

Here is the caller graph for this function:

const char* get_weekday ( const int  index)

give access to weekday names

Definition at line 116 of file time.c.

References DAYS_PER_WEEK, and weekdays.

Referenced by cfapi_get_weekday_name(), and START_TEST().

Here is the caller graph for this function:

static void log_time ( uint32_t  process_utime)
static

Adds time to our history list.

Definition at line 147 of file time.c.

References PBUFLEN, process_max_utime, process_min_utime, process_tot_mtime, process_utime_save, psaveind, and pticks.

Referenced by sleep_delta().

Here is the caller graph for this function:

static void print_tod ( object op)
static

Prints the time.

Parameters
opplayer who requested time.

Definition at line 258 of file time.c.

References _timeofday::day, _timeofday::dayofweek, draw_ext_info_format(), get_tod(), _timeofday::month, month_name, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_INFO, NDI_UNIQUE, _timeofday::season, season_name, time_format_time(), weekdays, and _timeofday::year.

Referenced by time_info().

Here is the call graph for this function:

Here is the caller graph for this function:

void reset_sleep ( void  )

Initialise all variables used in the timing routines.

Definition at line 130 of file time.c.

References game_time, PBUFLEN, process_max_utime, process_min_utime, process_tot_mtime, process_utime_save, psaveind, and pticks.

Referenced by block_until_new_connection(), command_speed(), init(), and setup().

Here is the caller graph for this function:

long seconds ( void  )

Return wall clock time in seconds.

Definition at line 344 of file time.c.

Referenced by cftimer_create(), cftimer_process_timers(), command_statistics(), flush_old_maps(), generate_random_map(), map_info(), read_map_log(), ready_map_name(), set_map_reset_time(), and swap_map().

Here is the caller graph for this function:

void set_max_time ( long  t)

Sets the max speed.

Can be called by a DM through the speed command.

Parameters
tnew speed.

Definition at line 203 of file time.c.

References max_time, and todtick.

Referenced by command_speed().

Here is the caller graph for this function:

void sleep_delta ( void  )

Sleep until the next tick.

Definition at line 180 of file time.c.

References game_time, log_time(), max_time, process_utime_long_count, timespec_add(), and timespec_diff().

Referenced by server_main().

Here is the call graph for this function:

Here is the caller graph for this function:

int tick_length ( float  seconds)

Calculate the number of ticks that correspond to real time.

Definition at line 378 of file time.c.

References max_time.

Referenced by connection_alive().

Here is the caller graph for this function:

const char* time_format_time ( const timeofday_t tod,
char *  buf,
size_t  bufsize 
)

Formats a timestamp in Crossfire time.

Parameters
todthe timestamp to format
bufthe buffer to fill
bufsizethe size of buf in bytes
Returns
buf

Definition at line 365 of file time.c.

References _timeofday::hour, _timeofday::minute, and snprintf.

Referenced by clock_type_apply(), and print_tod().

Here is the caller graph for this function:

void time_info ( object op)

Players wants to know the time.

Called through the 'time' command.

Parameters
opplayer who requested time.

Definition at line 294 of file time.c.

References draw_ext_info_format(), FLAG_WIZ, max_time, MIN, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DEBUG, NDI_UNIQUE, PBUFLEN, print_tod(), process_max_utime, process_min_utime, process_tot_mtime, process_utime_long_count, process_utime_save, pticks, and QUERY_FLAG.

Referenced by command_time().

Here is the call graph for this function:

Here is the caller graph for this function:

static void timespec_add ( struct timespec *  time,
long  usec 
)
static

Add 'usec' microseconds to the given timespec.

Definition at line 171 of file time.c.

Referenced by sleep_delta().

Here is the caller graph for this function:

static long timespec_diff ( struct timespec *  end,
struct timespec *  start 
)
static

Return the difference between two timespec's in microseconds.

Definition at line 162 of file time.c.

Referenced by sleep_delta().

Here is the caller graph for this function:

Variable Documentation

struct timespec game_time
static

Definition at line 36 of file time.c.

Referenced by reset_sleep(), and sleep_delta().

uint32_t max_time = MAX_TIME

Gloabal variables:

Definition at line 35 of file time.c.

Referenced by command_speed(), command_statistics(), set_max_time(), sleep_delta(), tick_length(), and time_info().

const char* const month_name[MONTHS_PER_YEAR]
static
Initial value:
= {
"Month of Winter",
"Month of the Ice Dragon",
"Month of the Frost Giant",
"Month of Valriel",
"Month of Lythander",
"Month of the Harvest",
"Month of Gaea",
"Month of Futility",
"Month of the Dragon",
"Month of the Sun",
"Month of the Great Infernus",
"Month of Ruggilli",
"Month of the Dark Shades",
"Month of the Devourers",
"Month of Sorig",
"Month of the Ancient Darkness",
"Month of Gorokh"
}

Months.

Definition at line 70 of file time.c.

Referenced by get_month_name(), and print_tod().

const char* const periodsofday[PERIODS_PER_DAY]
static
Initial value:
= {
"Night",
"Dawn",
"Morning",
"Noon",
"Evening",
"Dusk"
}

Definition at line 90 of file time.c.

Referenced by get_periodofday().

uint32_t process_max_utime = 0
static

Longest cycle time.

Definition at line 42 of file time.c.

Referenced by log_time(), reset_sleep(), and time_info().

uint32_t process_min_utime = 999999999
static

Shortest cycle time.

Definition at line 43 of file time.c.

Referenced by log_time(), reset_sleep(), and time_info().

uint32_t process_tot_mtime
static

?

Definition at line 44 of file time.c.

Referenced by log_time(), reset_sleep(), and time_info().

uint32_t process_utime_long_count
static

?

Definition at line 46 of file time.c.

Referenced by sleep_delta(), and time_info().

uint32_t process_utime_save[PBUFLEN]
static

Historic data.

Definition at line 40 of file time.c.

Referenced by log_time(), reset_sleep(), and time_info().

uint32_t psaveind
static

Index in process_utime_save.

Definition at line 41 of file time.c.

Referenced by log_time(), and reset_sleep().

uint32_t pticks

?

Used by various function to determine how often to save the character.

Definition at line 45 of file time.c.

Referenced by apply_race_and_class(), check_login(), do_specials(), get_tod(), handle_newcs_player(), key_change_class(), log_time(), process_players1(), reset_sleep(), send_tick(), and time_info().

const char* const season_name[SEASONS_PER_YEAR+1]
static
Initial value:
= {
"The Season of New Year",
"The Season of Growth",
"The Season of Harvest",
"The Season of Decay",
"The Season of the Blizzard",
"\n"
}

Ingame seasons.

Definition at line 49 of file time.c.

Referenced by get_season_name(), and print_tod().

unsigned long todtick

Ingame time.

Definition at line 440 of file init.c.

Referenced by get_tod(), and set_max_time().

const char* const weekdays[DAYS_PER_WEEK]
static
Initial value:
= {
"the Day of the Moon",
"the Day of the Bull",
"the Day of the Deception",
"the Day of Thunder",
"the Day of Freedom",
"the Day of the Great Gods",
"the Day of the Sun"
}

Days of the week.

Definition at line 59 of file time.c.

Referenced by get_weekday(), and print_tod().