ID:156935
 
Heya Everyone.

I got another question about save files. (please note i have read the Pitfalls of save files by Lummox.

Now by going off that guide mentioned above it tells you to delete icons overlays etc because they bloat the save file, so i did just that, Deleted them. and have procs inplace which on load grab the info and piece humpty dumpty back together again.

But my .savs are still 32kb (the same in which it would be without removing icons)

for the sake of showing purposes. ill post my code in which enacts this.

Code: The Saver
mob/proc/Save_Slot_1()
var/savefile/F = new("Player Saves/[copytext(key,1,2)]/[usr.key]/Slot-1.sav")
Write(F)
F["icon"] << null
F["overlays"] << null
F["underlays"] << null


Code:The Loader
mob/proc/Load_Slot_1()
if(fexists("Player Saves/[copytext(key,1,2)]/[usr.key]/Slot-1.sav"))
var/savefile/F = new("Player Saves/[copytext(key,1,2)]/[usr.key]/Slot-1.sav")
Read(F)
usr.Load_Base()
usr.Load_Overlays()
world << output("[name]/[key] has successfully logged in", "balog")
LoadedChangeProc(usr.client)


Code:The Save (Inbetween)
Affinity = "Cloud"
hair_red = 40
hair_green = 12
hair_type = 1
base_type = 4
save_file_1 = 1
name = "Test"
icon = null
overlays = null
gender = "male"
key = "Midgetbuster"
underlays = null
midgetbuster = object(".0")
.0
type = /mob
name = "Midgetbuster"
gender = "male"
key = "Midgetbuster"


So by looking at that, is there any reason why the non overlay/icon delete and the overlay/icon delete are the same size. i was under the impression it would reduce the size in which saves are.


Help + Thoughts are appreciated
By calling Write() and Read() directly, you've managed to mangle your savefile. You need to use the << and >> operators instead. Like so:

client/proc
Save()
var/savefile/F = new("[key].sav")
F["mob"] << mob
Load()
if(fexists("[key].sav"))
var/savefile/F = new("[key].sav")
F["mob"] << mob

mob
Write(var/savefile/F)
..()
F.dir.Remove("icon","overlays","underlays")
Read(var/savefile/F)
..()
// Reconstruct the removed data here

In response to Garthor
Thanks Garthor, Just a follow up on that though.

I see that the "mob" write and read things overwrite the predefined ones and as a result remove the entire directory of those 3 things to then be recreated.


But im not quite understanding what is meant by the Save() and Load() thing (the first ones) and how to get them to work properly to reduce the save size
In response to Midgetbuster
They're examples of how to save and load from a savefile correctly, namely by using the << and >> operators. Calling Read() and Write() directly causes major issues with savefiles if you have any references back to the mob. The << and >> operators will call Read() and Write() and will handle the references properly.
In response to Garthor
Yeah, i understand all that (i think).

But my save still seems to be "Mangled" as it is still 32kb no change there. (im looking for ways to achieve the infamous low save sizes)

//load
client/proc/Load_Slot_1()
if(fexists("Player Saves/[copytext(key,1,2)]/[usr.key]/Slot-1.sav"))
var/savefile/F = new("Player Saves/[copytext(key,1,2)]/[usr.key]/Slot-1.sav")
src.mob.Read(F)
world << output("[usr.name]/[key] has successfully logged in", "balog")
LoadedChangeProc(usr.client)

//save
client/proc/Save_Slot_1()
var/savefile/F = new("Player Saves/[copytext(key,1,2)]/[usr.key]/Slot-1.sav")
src.mob.Write(F)

//mob write/load
mob
Write(var/savefile/F)
..()
F.dir.Remove("icon","overlays","underlays")
Read(var/savefile/F)
..()
usr.Load_Base()
usr.Load_Overlays()


I must be doing something wrong. Is there any way you can define more =\ cause i really dont know right now
In response to Midgetbuster
        src.mob.Read(F)


This is calling Read() directly. Don't do this. Use the >> operator instead, as I have shown in my example.

    src.mob.Write(F)


This is calling Write() directly. Don't do this. Use the << operator instead, as I have shown in my example.
In response to Garthor
OK so yeah. i added your F[mob} w.e stuff..

And looky no surprise.. still 32kb save files. this is getting to be a real pain in the ass.

client/proc/Save_Slot_1()
var/savefile/F = new("Player Saves/[copytext(key,1,2)]/[usr.key]/Slot-1.sav")
F["mob"] << mob

client/proc/Load_Slot_1()
if(fexists("Player Saves/[copytext(key,1,2)]/[usr.key]/Slot-1.sav"))
var/savefile/F = new("Player Saves/[copytext(key,1,2)]/[usr.key]/Slot-1.sav")
F["mob"] >> mob
world << output("[usr.name]/[key] has successfully logged in", "balog")
LoadedChangeProc(usr.client)


also adding those in fucks up my screen changing proc and god knows what else.

/sigh.
In response to Midgetbuster
Have you tried deleting the savefiles? This isn't going to remove data from them, only prevent extra data from being added. If the savefiles are already bloated, they'll stay that way.
In response to Garthor
Yea, i delete them after each test of the save system, to prevent that.

Could there be any other reason as to why this may be happening?
In response to Midgetbuster
Posting a full copy of the ExportText() of a savefile would be helpful. Can't say for sure what the issue is without that.
In response to Garthor
Umm i went into the ref and pulled the basic exporttext code when writing that shows you it. but yeah. here is what it send to my output, i think this is what you were after.


mob = object(".0")
        .0
                type = /mob
                Family = "Cavallone"
                Affinity = "Cloud"
                hair_red = 60
                hair_blue = 1
                hair_green = 39
                hair_type = 1
                base_type = 4
                save_file_1 = 1
                name = "test"
                gender = "male"
                key = "Midgetbuster"
midgetbuster = object(".0")
        .0
                type = /mob
                Family = "Cavallone"
                Affinity = "Cloud"
                hair_red = 60
                hair_blue = 1
                hair_green = 39
                hair_type = 1
                base_type = 4
                save_file_1 = 1
                name = "test"
                gender = "male"
                key = "Midgetbuster"


by lookin at that it makes 2 copies of the actual object when using that F Mob thingy.
In response to Midgetbuster
You are saving a copy of the mob somewhere else in your code. Look for F["[ckey]"] << mob or something of the sort.

Regardless, that savefile would not be 32kb in size. Either there's a major glitch or the file isn't actually 32kb.
In response to Garthor
So, i looked over my save some more and that dual mob write thing was simply cause by me copy and pasting the exporttext thing straight from the ref (and not removing the part that also saves)

I looked more into it and regardless of what i did it always returned a 32kb save file.

The only other option i can see atm would be making the file manually save each variable i want saved by using F["family" << bla bla.

Unless of course someone can reply to me with a Demo/Code paste that they know will achieve small save files of 1KB (as seen by various games)


Thanks Again
~Midget
In response to Midgetbuster
In the past i would have save files at 25KB reason was because we only save users key name and location and race using numbers then have a proc load everything up and the base we would re ask him to choose again.


try to make the save data short as possible with almost nothing < :)


quote: might be what you said earlyer you tried but i don't member after reading everything.
In response to Jub369
Yeah, i remove all forms of icon and overlay saving with the f.dir.remove thing (which is a more streamlined method Garthor showed me then what i previously used)

And then i have a number of vars that save the colour of the hair, each hair is type is given a number and each base is also given a number. these numbers are then recalled by a proc on load which piece humpty dumpty back together again.

But even with that info being removed im somehow still getting 32kb saves which should not be happening..
In response to Midgetbuster
hmmm may sound stupid but why not find a way to make a combo VAR

like

mob/var/combo

in save make it like combo = 9395939 or something then location name

and then a proc to read that Combo instead of all the other vars


or
i use this
        Save()
var/savefile/save
save = new ("Save Files/[src.mob.ckey]")
save["mob"] << src.mob
save["x"] << src.mob.x
save["y"] << src.mob.y
save["z"] << src.mob.z
In response to Midgetbuster
Are you sure it's not just a filesystem cluster size issue? Most filesystems and HDDs have a minimum unit of data they can allocate. Is it perhaps 32 kb for whatever combination of OS and HDD you're using?
In response to Jp
Jp wrote:
Are you sure it's not just a filesystem cluster size issue? Most filesystems and HDDs have a minimum unit of data they can allocate. Is it perhaps 32 kb for whatever combination of OS and HDD you're using?

JP but wouldn't that make any file he downloads under 32KB make it into 32KB O.o if it's a OS/HDD issue
In response to Jp
That could be possible. But i have run previous demos that ave very small icon sizes that save the entire icon that pull a 8kb save file (and on change of the icon it makes a larger file) but yea..

and @jub
I do all that already, please read the thread before repeating something already said. >_>

EDIT: Weird.. I added the same things as my save into the save demo. (the f.dir.remove) thing and it does the same thing.. showing a large save without the icons etc in the actual save
In response to Midgetbuster
Create a test datum, with a single test variable set to 1. Save the object. Check the size and read the content.

Create a second datum with the same test variable, set to 1 and an additional icon file. Save the object and remove the directory containing the icon. Check the size and read the content.

Compare results.

I guess that removing the folder doesn't actually remove the data, but instead just removes the directory information, which this test would prove. If this is the case, clean compile and package (source code - option), then provide it as test case in a bug report for Lummox JR.
Page: 1 2