Angband
Macros | Functions | Variables
savefile.h File Reference

Savefile loading and saving main routines. More...

Go to the source code of this file.

Macros

#define FINISHED_CODE   255
 
#define ITEM_VERSION   5
 
#define EGO_ART_KNOWN   0xffffffff
 

Functions

bool savefile_save (const char *path)
 Save to the given location. More...
 
bool savefile_load (const char *path, bool cheat_death)
 Load the savefile given. More...
 
const char * savefile_get_description (const char *path)
 Try to get a description for this savefile. More...
 
void note (const char *msg)
 

Detailed saving and loading functions

More...
 
void wr_byte (byte v)
 

Accessor functions

More...
 
void wr_u16b (u16b v)
 
void wr_s16b (s16b v)
 
void wr_u32b (u32b v)
 
void wr_s32b (s32b v)
 
void wr_string (const char *str)
 
void pad_bytes (int n)
 
void rd_byte (byte *ip)
 
void rd_u16b (u16b *ip)
 
void rd_s16b (s16b *ip)
 
void rd_u32b (u32b *ip)
 
void rd_s32b (s32b *ip)
 
void rd_string (char *str, int max)
 
void strip_bytes (int n)
 
int rd_randomizer (void)
 Read RNG state. More...
 
int rd_options (void)
 Read options. More...
 
int rd_messages (void)
 Read the saved messages. More...
 
int rd_monster_memory (void)
 Read monster memory. More...
 
int rd_object_memory (void)
 
int rd_quests (void)
 
int rd_artifacts (void)
 
int rd_player (void)
 Read the player information. More...
 
int rd_ignore (void)
 Read ignore and autoinscription submenu for all known objects. More...
 
int rd_misc (void)
 
int rd_player_hp (void)
 
int rd_player_spells (void)
 Read the player spells. More...
 
int rd_gear (void)
 Read the player gear - wrapper functions. More...
 
int rd_stores (void)
 Read the stores - wrapper functions. More...
 
int rd_dungeon (void)
 
int rd_chunks (void)
 Read the chunk list. More...
 
int rd_objects (void)
 Read the objects - wrapper functions. More...
 
int rd_monsters (void)
 Read the monster list - wrapper functions. More...
 
int rd_history (void)
 
int rd_traps (void)
 Read the traps - wrapper functions. More...
 
int rd_null (void)
 For blocks that don't need loading anymore. More...
 
void wr_description (void)
 Write a description of the character. More...
 
void wr_randomizer (void)
 Write RNG state. More...
 
void wr_options (void)
 Write the "options". More...
 
void wr_messages (void)
 
void wr_monster_memory (void)
 
void wr_object_memory (void)
 
void wr_quests (void)
 
void wr_artifacts (void)
 
void wr_player (void)
 
void wr_ignore (void)
 
void wr_misc (void)
 
void wr_player_hp (void)
 
void wr_player_spells (void)
 
void wr_randarts (void)
 
void wr_gear (void)
 
void wr_stores (void)
 
void wr_dungeon (void)
 
void wr_chunks (void)
 
void wr_objects (void)
 
void wr_monsters (void)
 
void wr_ghost (void)
 
void wr_history (void)
 
void wr_traps (void)
 

Variables

bool character_saved
 

Savefile API

More...
 

Detailed Description

Savefile loading and saving main routines.

Copyright (c) 2009 Andi Sidwell andi@.nosp@m.takk.nosp@m.aria..nosp@m.org

This work is free software; you can redistribute it and/or modify it under the terms of either:

a) the GNU General Public License as published by the Free Software Foundation, version 2, or

b) the "Angband licence": This software may be copied and distributed for educational, research, and not for profit purposes provided that this copyright and statement are included in all such copies. Other copyrights may also apply.

Macro Definition Documentation

#define EGO_ART_KNOWN   0xffffffff
#define FINISHED_CODE   255

Referenced by rd_gear_aux(), and wr_gear_aux().

#define ITEM_VERSION   5

Referenced by wr_item().

Function Documentation

void note ( const char *  message)
void pad_bytes ( int  n)

References wr_byte().

int rd_artifacts ( void  )
void rd_byte ( byte ip)
int rd_chunks ( void  )
int rd_dungeon ( void  )
int rd_gear ( void  )
int rd_history ( void  )
int rd_ignore ( void  )
int rd_messages ( void  )

Read the saved messages.

References buf, i, message_add(), num, rd_s16b(), rd_string(), and rd_u16b().

int rd_misc ( void  )
int rd_monster_memory ( void  )
int rd_monsters ( void  )

Read the monster list - wrapper functions.

References cave, player::cave, i, player::is_dead, object::known, chunk::obj_max, chunk::objects, and rd_monsters_aux().

int rd_null ( void  )

For blocks that don't need loading anymore.

int rd_object_memory ( void  )
int rd_objects ( void  )

Read the objects - wrapper functions.

References cave, player::cave, player::is_dead, rd_item(), and rd_objects_aux().

int rd_options ( void  )
int rd_player ( void  )
int rd_player_hp ( void  )
int rd_player_spells ( void  )
int rd_quests ( void  )
int rd_randomizer ( void  )

Read RNG state.

There were originally 64 bytes of randomizer saved. Now we only need 32 + 5 bytes saved, so we'll read an extra 27 bytes at the end which won't be used.

References i, RAND_DEG, Rand_quick, Rand_value, rd_u32b(), STATE, state_i, z0, z1, and z2.

void rd_s16b ( s16b ip)
void rd_s32b ( s32b ip)

References rd_u32b().

Referenced by rd_dungeon_aux(), rd_history(), rd_misc(), and rd_player().

int rd_stores ( void  )

Read the stores - wrapper functions.

References player::is_dead, rd_item(), and rd_stores_aux().

void rd_string ( char *  str,
int  max 
)
int rd_traps ( void  )

Read the traps - wrapper functions.

References cave, player::cave, player::is_dead, and rd_traps_aux().

void rd_u16b ( u16b ip)
void rd_u32b ( u32b ip)
const char* savefile_get_description ( const char *  path)

Try to get a description for this savefile.

Try to get a description for this savefile.

Fail gracefully.

References check_header(), file_close(), file_open(), FTYPE_TEXT, get_desc(), load_block(), MODE_READ, my_strcpy(), blockheader::name, next_blockheader(), NULL, savefile_desc, skip_block(), and streq.

Referenced by list_saves().

bool savefile_load ( const char *  path,
bool  cheat_death 
)
bool savefile_save ( const char *  path)
void strip_bytes ( int  n)

References rd_byte().

Referenced by rd_ignore(), and rd_player().

void wr_artifacts ( void  )
void wr_byte ( byte  v)
void wr_chunks ( void  )
void wr_description ( void  )
void wr_dungeon ( void  )
void wr_gear ( void  )
void wr_ghost ( void  )
void wr_history ( void  )
void wr_ignore ( void  )
void wr_messages ( void  )
void wr_misc ( void  )
void wr_monster_memory ( void  )
void wr_monsters ( void  )
void wr_object_memory ( void  )
void wr_objects ( void  )
void wr_options ( void  )
void wr_player ( void  )
void wr_player_hp ( void  )
void wr_player_spells ( void  )
void wr_quests ( void  )
void wr_randarts ( void  )
void wr_randomizer ( void  )

Write RNG state.

There were originally 64 bytes of randomizer saved. Now we only need 32 + 5 bytes saved, so we'll write an extra 27 bytes at the end which won't be used.

References i, RAND_DEG, Rand_value, STATE, state_i, wr_u32b(), z0, z1, and z2.

void wr_s16b ( s16b  v)
void wr_s32b ( s32b  v)

References wr_u32b().

Referenced by wr_dungeon_aux(), wr_history(), and wr_misc().

void wr_stores ( void  )
void wr_string ( const char *  str)
void wr_traps ( void  )
void wr_u16b ( u16b  v)
void wr_u32b ( u32b  v)

Variable Documentation

bool character_saved


Savefile API

Global "we've just saved" variable


Savefile API

Savefiles since ~3.1 have used a block-based system. Each savefile consists of an 8-byte header, the first four bytes of which mark this as a savefile, the second four bytes provide a variant ID.

After that, each block has the format:

  • 16-byte string giving the type of block
  • 4-byte block version
  • 4-byte block size
  • 4-byte block checksum ... data ... padding so that block is a multiple of 4 bytes

The savefile deosn't contain the version number of that game that saved it; versioning is left at the individual block level. The current code keeps a list of savefile blocks to save in savers[] below, along with their current versions.

For each block type and version, there is a loading function to load that type/version combination. For example, there may be a loader for v1 and v2 of the RNG block; these must be different functions. It has been done this way since it allows easier maintenance; after each release, you need simply remove old loaders and you will not have to disentangle lots of code with "if (version > 3)" and its like everywhere.

Savefile loading and saving is done by keeping the current block in memory, which is accessed using the wr_* and rd_* functions. This is then written out, whole, to disk, with the appropriate header.

So, if you want to make a savefile compat-breaking change, then there are a few things you should do:

  • increment the version in 'savers' below
  • add a loading function that accepts the new version (in addition to the previous loading function) to 'loaders'
  • and watch the magic happen.

TODO:

  • wr_ and rd_ should be passed a buffer to work with, rather than using the rd_ and wr_ functions with a universal buffer
  • Global "we've just saved" variable

Referenced by handle_signal_abort(), handle_signal_simple(), inkey_ex(), and savefile_save().