Crossfire Server, Trunk
swap.cpp File Reference
#include "global.h"
#include <string.h>
#include "object.h"
#include "output_file.h"
#include "sproto.h"
#include "stats.h"
+ Include dependency graph for swap.cpp:

Go to the source code of this file.

Functions

void check_active_maps (void)
 
void flush_old_maps (void)
 
bool map_can_reset (const mapstruct *map, long current_time)
 
static bool map_can_reset_no_group (const mapstruct *map, long current_time)
 
int players_on_map (mapstruct *m, int show_all)
 
void read_map_log (void)
 
int swap_map (mapstruct *map)
 
static void write_map_log (void)
 

Detailed Description

Functions that deal with swapping maps to disk to reclaim memory.

Definition in file swap.cpp.

Function Documentation

◆ check_active_maps()

void check_active_maps ( void  )

Finds maps in memory to swap.

Definition at line 201 of file swap.cpp.

References first_map, disinfect::map, MAP_IN_MEMORY, give::next, and swap_map().

Referenced by server_main().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ flush_old_maps()

void flush_old_maps ( void  )

Reset maps that need to, remove their swap file. This is very useful if the tmp-disk is very full.

Definition at line 291 of file swap.cpp.

References clean_tmp_map(), delete_map(), EVENT_MAPRESET, events_execute_global_event(), first_map, llevDebug, LOG(), m, map_can_reset(), MAP_IN_MEMORY, MAP_SWAPPED, players_on_map(), seconds(), set_map_timeout(), and TRUE.

Referenced by command_reset(), do_specials(), and START_TEST().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ map_can_reset()

bool map_can_reset ( const mapstruct map,
long  current_time 
)

Returns whether a map can be reset, including all other maps in the same reset group.

Parameters
mapmap to consider.
current_timecurrent time.
Returns
false if the map can't be reset, true if the map can be reset.

Definition at line 266 of file swap.cpp.

References first_map, disinfect::map, map_can_reset_no_group(), mapstruct::next, and mapstruct::reset_group.

Referenced by flush_old_maps().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ map_can_reset_no_group()

static bool map_can_reset_no_group ( const mapstruct map,
long  current_time 
)
static

Returns whether a map can be reset, without taking its reset group into account.

Parameters
mapmap to consider.
current_timecurrent time.
Returns
false if the map can't be reset, true if the map can be reset.

Definition at line 253 of file swap.cpp.

References disinfect::map, and MAP_SWAPPED.

Referenced by map_can_reset().

+ Here is the caller graph for this function:

◆ players_on_map()

int players_on_map ( mapstruct m,
int  show_all 
)

Returns the count of players on a map, calculated from player list.

Parameters
mmap we want the count of players on.
show_allif true, show everyone. If not, don't show hidden players (dms)
Returns
player count.
Todo:
this doesn't take into account transports. Should be removed when mapstruct::players is valid.

Definition at line 234 of file swap.cpp.

References first_player, FLAG_REMOVED, m, altar_valkyrie::pl, and QUERY_FLAG.

Referenced by flush_old_maps().

+ Here is the caller graph for this function:

◆ read_map_log()

void read_map_log ( void  )

Reads temporary maps information from disk.

Will LOG() in case of error.

Definition at line 71 of file swap.cpp.

References buf, get_linked_map(), llevDebug, Settings::localdir, LOG(), disinfect::map, MAP_MAXRESET, MAP_SWAPPED, MAX_BUF, safe_strncpy, seconds(), settings, split_string(), strdup_local, and Ice::tmp.

Referenced by init().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ swap_map()

int swap_map ( mapstruct map)

Swaps a map to disk.

After calling this function, the map will be:

  • swapped to disk
  • kept in memory in case of save error
Parameters
mapmap to swap.
Returns
one of SAVE_ERROR_xxx.

Definition at line 136 of file swap.cpp.

References delete_map(), draw_ext_info_format(), EVENT_MAPRESET, events_execute_global_event(), first_player, FLAG_REMOVED, free_map(), llevDebug, llevError, LOG(), disinfect::map, MAP_IN_MEMORY, maps_swapped_total, MSG_TYPE_ADMIN, MSG_TYPE_ADMIN_LOADSAVE, NDI_ALL_DMS, NDI_RED, NDI_UNIQUE, pets_attempt_follow(), altar_valkyrie::pl, QUERY_FLAG, Settings::recycle_tmp_maps, altar_valkyrie::res, rndm(), SAVE_ERROR_NOT_IN_MEMORY, SAVE_ERROR_OK, SAVE_ERROR_PLAYER, save_map(), SAVE_MODE_NORMAL, seconds(), set_map_reset_time(), settings, TRUE, and write_map_log().

Referenced by check_active_maps(), clean_tmp_files(), and command_reset().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ write_map_log()

static void write_map_log ( void  )
static

Writes out information on all the temporary maps. It is called by swap_map().

Will LOG() in case of error.

Definition at line 34 of file swap.cpp.

References buf, first_map, Settings::localdir, disinfect::map, MAP_IN_MEMORY, MAX_BUF, of_close(), of_open(), and settings.

Referenced by swap_map().

+ Here is the call graph for this function:
+ Here is the caller graph for this function: