• Listen to a special audio message from Bill Roper to the Hive Workshop community (Bill is a former Vice President of Blizzard Entertainment, Producer, Designer, Musician, Voice Actor) 🔗Click here to hear his message!
  • Read Evilhog's interview with Gregory Alper, the original composer of the music for WarCraft: Orcs & Humans 🔗Click here to read the full interview.

[Spell] Any Save/Load system that can load Integer or Real Variables?

Status
Not open for further replies.

Dr Super Good

Spell Reviewer
Level 65
Joined
Jan 18, 2005
Messages
27,290
By very definition of what a save/load system does, they must all be capable of it. They operate by converting everything to save into integers which are then encoded into a string. Loading works by decoding the string into integers which are then converted back into the things that were saved.

Reals can be saved by abusing type casting. A real is nothing more than a single precision float (32 bit), which is the same length as an integer (32 bit). As such you can losslessly typecast them to and from integer with a bit of hacky code. Be warned that typecasting may be fixed in future patches so you may have to fix such code in the future.

In theory it may be possible to write a more secure typecast function for reals. However it will perform a lot slower.

Since 32bits is several characters of code space, it is usually recommended to save a lossy version of a real. For example you could reduce its precision, encode it as a fixed point or even use a gamma based curve for value distribution.
 
Status
Not open for further replies.
Top