I was thinking that it would be easier to save the number values as text, because then you don't have to worry about types. Arrays are saved as raw arrays, because they would take more space if saved in text mode (numbers separated by comma). The file mode is binary and it's always containing the next block size loaded in one piece.
I'm using a helper class named Tar_Ball to save and load data for objects. It's a low level class which makes load and save routines in object's class clean:
void Score::Save(K_File *f)
{
Tar_Ball tb;
for (int t=0; t<Max_Player_Name_Len; t++) tb.Put_Char(name[t]);
tb.Put(death_reason);
tb.Put(killed_by);
tb.Put(score);
tb.Save(f);
}
void Score::Load(K_File *f)
{
Tar_Ball tb;
tb.Load(f);
tb.Get_Next_String(name, Max_Player_Name_Len);
death_reason=tb.Get_Next_Value();
killed_by=tb.Get_Next_Value();
score=tb.Get_Next_Value();
}
Now I just have to save the world. Game world, to be more specific.
1 comment:
Good last sarcastic statement (about the world) ;)
Post a Comment