src/saveload.cpp
branchgamebalance
changeset 9908 0fa543611bbe
parent 9901 a922f277ebfd
child 9909 dce9a6923bb7
equal deleted inserted replaced
9907:3b068c3a1c74 9908:0fa543611bbe
   410 }
   410 }
   411 
   411 
   412 /** Write the value of a setting
   412 /** Write the value of a setting
   413  * @param ptr pointer to the variable
   413  * @param ptr pointer to the variable
   414  * @param conv type of variable, can be a non-clean type, eg
   414  * @param conv type of variable, can be a non-clean type, eg
   415  * with other flags. It is parsed upon read
   415  *             with other flags. It is parsed upon read
   416  * @param var the new value being given to the variable */
   416  * @param val the new value being given to the variable */
   417 void WriteValue(void *ptr, VarType conv, int64 val)
   417 void WriteValue(void *ptr, VarType conv, int64 val)
   418 {
   418 {
   419 	switch (GetVarMemType(conv)) {
   419 	switch (GetVarMemType(conv)) {
   420 	case SLE_VAR_BL:  *(bool  *)ptr = (val != 0);  break;
   420 	case SLE_VAR_BL:  *(bool  *)ptr = (val != 0);  break;
   421 	case SLE_VAR_I8:  *(int8  *)ptr = val; break;
   421 	case SLE_VAR_I8:  *(int8  *)ptr = val; break;
   496 /** Calculate the gross length of the string that it
   496 /** Calculate the gross length of the string that it
   497  * will occupy in the savegame. This includes the real length, returned
   497  * will occupy in the savegame. This includes the real length, returned
   498  * by SlCalcNetStringLen and the length that the index will occupy.
   498  * by SlCalcNetStringLen and the length that the index will occupy.
   499  * @param ptr pointer to the stringbuffer
   499  * @param ptr pointer to the stringbuffer
   500  * @param length maximum length of the string (buffer size, etc.)
   500  * @param length maximum length of the string (buffer size, etc.)
       
   501  * @param conv type of data been used
   501  * @return return the gross length of the string */
   502  * @return return the gross length of the string */
   502 static inline size_t SlCalcStringLen(const void *ptr, size_t length, VarType conv)
   503 static inline size_t SlCalcStringLen(const void *ptr, size_t length, VarType conv)
   503 {
   504 {
   504 	size_t len;
   505 	size_t len;
   505 	const char *str;
   506 	const char *str;
   523 }
   524 }
   524 
   525 
   525 /**
   526 /**
   526  * Save/Load a string.
   527  * Save/Load a string.
   527  * @param ptr the string being manipulated
   528  * @param ptr the string being manipulated
   528  * @param the length of the string (full length)
   529  * @param length of the string (full length)
   529  * @param conv must be SLE_FILE_STRING */
   530  * @param conv must be SLE_FILE_STRING */
   530 static void SlString(void *ptr, size_t length, VarType conv)
   531 static void SlString(void *ptr, size_t length, VarType conv)
   531 {
   532 {
   532 	size_t len;
   533 	size_t len;
   533 
   534 
   648 	return false;
   649 	return false;
   649 }
   650 }
   650 
   651 
   651 /**
   652 /**
   652  * Calculate the size of an object.
   653  * Calculate the size of an object.
       
   654  * @param object to be measured
   653  * @param sld The SaveLoad description of the object so we know how to manipulate it
   655  * @param sld The SaveLoad description of the object so we know how to manipulate it
       
   656  * @return size of given objetc
   654  */
   657  */
   655 static size_t SlCalcObjLength(const void *object, const SaveLoad *sld)
   658 static size_t SlCalcObjLength(const void *object, const SaveLoad *sld)
   656 {
   659 {
   657 	size_t length = 0;
   660 	size_t length = 0;
   658 
   661 
   766 	}
   769 	}
   767 }
   770 }
   768 
   771 
   769 /**
   772 /**
   770  * Save or Load (a list of) global variables
   773  * Save or Load (a list of) global variables
   771  * @param desc The global variable that is being loaded or saved
   774  * @param sldg The global variable that is being loaded or saved
   772  */
   775  */
   773 void SlGlobList(const SaveLoadGlobVarList *sldg)
   776 void SlGlobList(const SaveLoadGlobVarList *sldg)
   774 {
   777 {
   775 	if (_sl.need_length != NL_NONE) {
   778 	if (_sl.need_length != NL_NONE) {
   776 		SlSetLength(SlCalcObjLength(NULL, (const SaveLoad*)sldg));
   779 		SlSetLength(SlCalcObjLength(NULL, (const SaveLoad*)sldg));