Crossfire Server, Trunk  1.75.0
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)
 Finds maps in memory to swap. More...
 
void flush_old_maps (void)
 Reset maps that need to, remove their swap file. More...
 
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. More...
 
static bool map_can_reset_no_group (const mapstruct *map, long current_time)
 Returns whether a map can be reset, without taking its reset group into account. More...
 
int players_on_map (mapstruct *m, int show_all)
 Returns the count of players on a map, calculated from player list. More...
 
void read_map_log (void)
 Reads temporary maps information from disk. More...
 
int swap_map (mapstruct *map)
 Swaps a map to disk. More...
 
static void write_map_log (void)
 Writes out information on all the temporary maps. More...
 

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, mapstruct::in_memory, MAP_IN_MEMORY, mapstruct::next, swap_map(), and mapstruct::timeout.

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(), and do_specials().

+ 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, 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 mapstruct::in_memory, MAP_SWAPPED, mapstruct::reset_time, and mapstruct::tmpname.

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, object::map, object::next, unpaid_count::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, mapstruct::darkness, mapstruct::difficulty, get_linked_map(), mapstruct::in_memory, llevDebug, Settings::localdir, LOG(), MAP_MAXRESET, MAP_SWAPPED, MAX_BUF, mapstruct::path, mapstruct::reset_time, safe_strncpy, seconds(), settings, split_string(), strdup_local, mapstruct::timeout, and mapstruct::tmpname.

Referenced by init().

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

◆ swap_map()

◆ 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, mapstruct::darkness, mapstruct::difficulty, first_map, mapstruct::in_memory, Settings::localdir, MAP_IN_MEMORY, MAX_BUF, mapstruct::next, of_close(), of_open(), mapstruct::path, mapstruct::reset_time, settings, time, and mapstruct::tmpname.

Referenced by swap_map().

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