Crossfire Server, Trunk
|
#include "global.h"
#include <assert.h>
#include <math.h>
#include "tod.h"
#include <stdio.h>
#include <sys/types.h>
#include <sys/time.h>
Go to the source code of this file.
Macros | |
#define | PBUFLEN 100 |
Functions | |
const char * | get_month_name (const int index) |
const char * | get_periodofday (const int index) |
const char * | get_season_name (const int index) |
long | get_sleep_remaining () |
void | get_tod (timeofday_t *tod) |
const char * | get_weekday (const int index) |
void | jump_time () |
static void | log_time (uint32_t process_utime) |
static void | print_tod (object *op) |
void | reset_sleep (void) |
long | seconds (void) |
void | set_tick_duration (long t) |
void | tick_game_time () |
unsigned int | tick_length (float seconds) |
const char * | time_format_time (const timeofday_t *tod, char *buf, size_t bufsize) |
void | time_info (object *op) |
static void | timespec_add (struct timespec *time, long usec) |
long | timespec_diff (struct timespec *end, struct timespec *start) |
Variables | |
static struct timespec | game_time |
uint32_t | last_time |
static const char *const | month_name [MONTHS_PER_YEAR] |
static const char *const | periodsofday [PERIODS_PER_DAY] |
static uint32_t | process_max_utime = 0 |
static uint32_t | process_min_utime = 999999999 |
static uint32_t | process_tot_mtime |
static uint32_t | process_utime_long_count |
static uint32_t | process_utime_save [PBUFLEN] |
static uint32_t | psaveind |
uint32_t | pticks |
static const char *const | season_name [SEASONS_PER_YEAR+1] |
uint32_t | tick_duration = MAX_TIME |
unsigned long | todtick |
static const char *const | weekdays [DAYS_PER_WEEK] |
In-game time functions.
Definition in file time.cpp.
const char* get_month_name | ( | const int | index | ) |
give access to month names
Definition at line 113 of file time.cpp.
References npc_dialog::index, month_name, and MONTHS_PER_YEAR.
Referenced by cfapi_get_month_name(), and START_TEST().
const char* get_periodofday | ( | const int | index | ) |
give access to weekday names
Definition at line 106 of file time.cpp.
References npc_dialog::index, PERIODS_PER_DAY, and periodsofday.
Referenced by cfapi_get_periodofday_name().
const char* get_season_name | ( | const int | index | ) |
give access to season names
Definition at line 127 of file time.cpp.
References npc_dialog::index, season_name, and SEASONS_PER_YEAR.
Referenced by cfapi_get_season_name(), and START_TEST().
long get_sleep_remaining | ( | ) |
Definition at line 189 of file time.cpp.
References game_time, log_time(), tick_duration, and timespec_diff().
Referenced by do_server().
void get_tod | ( | timeofday_t * | tod | ) |
Computes the ingame time of the day.
[out] | tod | where to store information. Must not be NULL. |
Definition at line 219 of file time.cpp.
References timeofday_t::day, timeofday_t::dayofweek, DAYS_PER_MONTH, DAYS_PER_WEEK, timeofday_t::hour, HOURS_PER_DAY, HOURS_PER_MONTH, HOURS_PER_YEAR, timeofday_t::minute, timeofday_t::month, MONTHS_PER_YEAR, timeofday_t::periodofday, pticks, PTICKS_PER_CLOCK, timeofday_t::season, todtick, timeofday_t::weekofmonth, WEEKS_PER_MONTH, and timeofday_t::year.
Referenced by cfapi_get_time(), cfcitybell_init(), clock_listener(), clock_type_apply(), print_tod(), set_darkness_map(), and tick_the_clock().
const char* get_weekday | ( | const int | index | ) |
give access to weekday names
Definition at line 120 of file time.cpp.
References DAYS_PER_WEEK, npc_dialog::index, and weekdays.
Referenced by cfapi_get_weekday_name(), and START_TEST().
void jump_time | ( | ) |
Definition at line 198 of file time.cpp.
References game_time, and process_utime_long_count.
Referenced by do_server().
|
static |
Adds time to our history list.
Definition at line 151 of file time.cpp.
References last_time, PBUFLEN, process_max_utime, process_min_utime, process_tot_mtime, process_utime_save, and psaveind.
Referenced by get_sleep_remaining().
|
static |
Prints the time.
op | player who requested time. |
Definition at line 262 of file time.cpp.
References timeofday_t::day, timeofday_t::dayofweek, draw_ext_info_format(), get_tod(), timeofday_t::month, month_name, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_INFO, NDI_UNIQUE, give::op, timeofday_t::season, season_name, time_format_time(), weekdays, and timeofday_t::year.
Referenced by time_info().
void reset_sleep | ( | void | ) |
Initialise all variables used in the timing routines.
Definition at line 134 of file time.cpp.
References game_time, PBUFLEN, process_max_utime, process_min_utime, process_tot_mtime, process_utime_save, psaveind, and pticks.
Referenced by command_speed(), init(), and setup().
long seconds | ( | void | ) |
Return wall clock time in seconds.
Definition at line 348 of file time.cpp.
Referenced by cftimer_create(), cftimer_process_timers(), command_statistics(), flush_old_maps(), generate_random_map(), map_info(), metaserver2_thread(), read_map_log(), ready_map_name(), set_map_reset_time(), START_TEST(), swap_map(), and tick_length().
void set_tick_duration | ( | long | t | ) |
Sets the tick duration. Can be called by a DM through the speed command.
t | new duration. |
Definition at line 209 of file time.cpp.
References Floor::t, and tick_duration.
Referenced by command_speed().
void tick_game_time | ( | ) |
Definition at line 184 of file time.cpp.
References game_time, pticks, tick_duration, and timespec_add().
Referenced by server_main().
unsigned int tick_length | ( | float | seconds | ) |
Calculate the number of ticks that correspond to real time.
Definition at line 382 of file time.cpp.
References seconds(), and tick_duration.
Referenced by connection_alive().
const char* time_format_time | ( | const timeofday_t * | tod, |
char * | buf, | ||
size_t | bufsize | ||
) |
Formats a timestamp in Crossfire time.
tod | the timestamp to format |
buf | the buffer to fill |
bufsize | the size of buf in bytes |
Definition at line 369 of file time.cpp.
References buf, timeofday_t::hour, and timeofday_t::minute.
Referenced by clock_type_apply(), and print_tod().
void time_info | ( | object * | op | ) |
Players wants to know the time. Called through the 'time' command.
op | player who requested time. |
Definition at line 298 of file time.cpp.
References draw_ext_info_format(), FLAG_WIZ, MIN, MSG_TYPE_COMMAND, MSG_TYPE_COMMAND_DEBUG, NDI_UNIQUE, give::op, PBUFLEN, print_tod(), process_max_utime, process_min_utime, process_tot_mtime, process_utime_long_count, process_utime_save, pticks, QUERY_FLAG, and tick_duration.
Referenced by command_time().
|
static |
Add 'usec' microseconds to the given timespec.
Definition at line 175 of file time.cpp.
Referenced by tick_game_time().
long timespec_diff | ( | struct timespec * | end, |
struct timespec * | start | ||
) |
Return the difference between two timespec's in microseconds.
Definition at line 166 of file time.cpp.
Referenced by get_sleep_remaining().
|
static |
Definition at line 36 of file time.cpp.
Referenced by get_sleep_remaining(), jump_time(), reset_sleep(), and tick_game_time().
uint32_t last_time |
Definition at line 50 of file time.cpp.
Referenced by do_server(), and log_time().
|
static |
Months.
Definition at line 74 of file time.cpp.
Referenced by get_month_name(), and print_tod().
|
static |
Definition at line 94 of file time.cpp.
Referenced by get_periodofday().
|
static |
Longest cycle time.
Definition at line 44 of file time.cpp.
Referenced by log_time(), reset_sleep(), and time_info().
|
static |
Shortest cycle time.
Definition at line 45 of file time.cpp.
Referenced by log_time(), reset_sleep(), and time_info().
|
static |
|
static |
Number of times server couldn't keep up with game time (tried to sleep for a negative time)
Definition at line 48 of file time.cpp.
Referenced by jump_time(), and time_info().
|
static |
Historic data.
Definition at line 42 of file time.cpp.
Referenced by log_time(), reset_sleep(), and time_info().
|
static |
Index in process_utime_save.
Definition at line 43 of file time.cpp.
Referenced by log_time(), and reset_sleep().
uint32_t pticks |
Number of ticks since time reset
Definition at line 47 of file time.cpp.
Referenced by apply_race_and_class(), check_login(), do_specials(), get_tod(), handle_newcs_player(), key_change_class(), monster_stand_in_light(), process_players1(), reset_sleep(), send_tick(), test_stand_in_light(), tick_game_time(), and time_info().
|
static |
Ingame seasons.
Definition at line 53 of file time.cpp.
Referenced by get_season_name(), and print_tod().
uint32_t tick_duration = MAX_TIME |
Gloabal variables:
Definition at line 35 of file time.cpp.
Referenced by command_speed(), command_statistics(), get_sleep_remaining(), set_tick_duration(), tick_game_time(), tick_length(), and time_info().
unsigned long todtick |
Game world time, in in-game hours. See PTICKS_PER_CLOCK.
Definition at line 38 of file time.cpp.
Referenced by get_tod(), init_clocks(), tick_the_clock(), and write_todclock().
|
static |
Days of the week.
Definition at line 63 of file time.cpp.
Referenced by get_weekday(), and print_tod().