windows - How to create a game save file format in c++ using STL -


i learned i/o part of stl, more fstream. although can save binary info , classes i've made hard drive, not sure how define how info should read.

i saw answer making file format this post:

typically define lot of records/structures, such bitmapinfoheader, , specify in order should come, how should nestled, , might need write lot of indices , look-up tables. such files consists of number of records (maybe nestled), look-up tables, magic words (indicating structure begin, structures end, etc.) , strings in custom-defined format.

what want know how the stl , c++... since format meant use of game think easier though. format should:

  • be traversable (i can through , find start of structure , maybe check name
  • be able hold multiple classes , data in single file
  • have identifiable starts , ends sections: such space in text files
  • maybe have it's own icon represent it??

how do in c++ ?

the first stage in determining how structure save-file determining information needs stored. presumably, have list of entities, each of generic information (probably derived 1 of few base classes), such position, velocity etc.

one of best things can implement map format have save-parser each class (some can derive base class' save-parser). instance, if have player class, derives cbasenpc, most-likely derive cbasenpc, override parser, calling base-class function, , adding other necessary fields, example, if had (pseudocode):

void cbasenpc::save() {      savetofile( health );      savetofile( armor );      savetofile( weapons );      savetofile( position );      savetofile( angles ); } 

then player class:

void cplayer::save() {      cbasenpc::save();      savetofile( achievement_progress ); } 

obviously, simple example, , no doubt saving parsers have more fields etc. deal with.

dealing structure of file itself, main thing need worry delimiters, how main load-parser recognise each field corresponds to?

i suppose best way explain example, following simple start save-file:

map: {mapname} gametime: {gametime}  ===player=== health: {health} armor: {armor} weapons: {wep1 (wep1ammo), wep2 (wep2ammo), wep3 (wep3ammo)} position: {x, y, z} angles: {yaw, pitch, roll} // quaternion instead. achievementprogress: {arbritrarydata} ===player===  ===npc-npc_name=== health: {health} armor: {armor} weapons: {wep1 (wep1ammo), wep2 (wep2ammo), wep3 (wep3ammo)} position: {x, y, z} angles: {yaw, pitch, roll} // quaternion instead. ===npc-npc_name===  ===entity-item_name=== position: {x, y, z} angles: {yaw, pitch, roll} model: {modelname} ===entity-item_name=== 

here have used "===" string delimiter start of class's parameters, , new line delimiter parameters within each class.

it relatively simple matter of structuring parser reads in map name, , loads it. sets game-time value specified in save-file.

it looks through file until finds "===" reads string encounters, , looks dictionary (possibly std::map or std::unordered_map) determine class create (or edit) information in file. once has determined class type, can proceed call load() function class, retrieve information contained. parser looks next instance of "==={string encountered}===" , closes class. proceeds following same procedure next class encountered.

sorry length of post, , i'm sure made briefer , there things have missed, wrote off top of head, there may erroneous things here, hope puts on right path getting workable save-file format. :)

if still have problems or questions regarding post, please comment, i'll best answer promptly.


Comments

Popular posts from this blog

c# - How to set Z index when using WPF DrawingContext? -

razor - Is this a bug in WebMatrix PageData? -

android - layout with fragment and framelayout replaced by another fragment and framelayout -