Jump to content

View more

Image of the Day

Boxes as reward for our ranking mode. ヾ(☆▽☆)
#indiedev #gamedev #gameart #screenshotsaturday https://t.co/ALF1InmM7K
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

How to write game-data into file?

4: Adsense

Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.


  • You cannot reply to this topic
2 replies to this topic

#1 Aliii   Members   

1456
Like
0Likes
Like

Posted 01 September 2014 - 11:32 AM

When saving game data, how should one write floats for example into the file? Someone quicksaves the game then later loads it back. Should I assume that the save-load will be on the same device or on devices with the same float format/size, same endianness, ...and write it in binary? Or divide it into two integers - mantissa and exponent - and save those in binary? Or convert it to text and parse back to float when loading?



#2 haegarr   Members   

7358
Like
1Likes
Like

Posted 01 September 2014 - 11:49 AM

Saving a floating point number can losslessly be done only without conversion to a decimal number format. This means: Store it either binary "as is" or else the equivalent bit pattern, perhaps hex number, as text. The latter one can be done by reading a float as uint32_t, and a double as uint64_t, perhaps by using a union.

 

It is very likely that a stored game will be reloaded on the same machine. If you want to be safe, you can write an endianess mark at the beginning of the file (so do I). The format of binary floating point number should be no problem, as long as you stick with the 32 and 64 bit numbers and don't try to use any extended format (e.g. the 80 bit internal format).

 

My preference is saving binary data, if possible even loadable "in-place".



#3 Glass_Knife   Moderators   

8624
Like
0Likes
Like

Posted 01 September 2014 - 11:50 AM

See this for a discussion of testing endianness:

 

http://stackoverflow.com/questions/4239993/determining-endianness-at-compile-time

 

Since many languages like Java always assume big-endian, and everything sent over the network is assumed big-endian, I would always save the file in big-endian, the then check if the current machine needs to convert the values.  


I think, therefore I am. I think? - "George Carlin"
My Website: Indie Game Programming

My Twitter: https://twitter.com/indieprogram

My Book: http://amzn.com/1305076532





Old topic!

Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.