ID:156249
 
Allo. So ive been fiddling with my saves and loads and pretty much made a standard save and load system (wiping out icons etc to reduce size)

On average my save files measure from 1kb for your basic freshly made newbie to 25kb for a character with over 200 "objects" in their invent (per slot) each save holds 3 slots (so anywhere from 1kb-70kb++) but now i want to be able to show the player their character inside a grid above the load button so they can see it rather then having popups with generic text.

So anyways
Question 1: Are their more ways to save that could reduce the save file size even further? im trying to get the lowest possible save file sizes while having a large amount of "objects" in the user (using .move etc) (These range from verbs, skills and actual items). i also have a skills "list" that holds all the skills the player has learned as opposed to storing them "inside" the mobs "contents". -if you want to view the way im currently saving just scroll down past next question to the code snip.-

Question 2: The next question is how would i go about reading a savefile "slot" specific to each players slot without -actually- loading the player. all my current attempts have left me with a loaded mob and rendering all my client verbs that change the screen useless cause of the mob being changed. I need to be able to load several vars from the file and then run them through the "Builder" proc i use to recreate images from those vars. so i can then display it. (Ive seen people just save a copy of the players icon to the savefile. but that bloats the files and would conflict with Q1)


--Codes
mob/var
colour_hair = "#000000"
colour_eye = "#000000"
type_hair = "bald"
type_base = "pale"

var/list/types_hair = list("bald" = 'Icons/blank.dmi',"test1" = 'Icons/NOICON.dmi')
var/list/types_base = list("pale" = 'Icons/Base_Tan.dmi',"tan" = 'Icons/NOICON.dmi',"medium" = 'Icons/NOICON.dmi',"pallid" = 'Icons/NOICON.dmi')
mob/proc/Builder_Player()
src.icon = types_base[type_base || "pale"]
var/olays[0]
var/hair = types_hair[type_hair || "bald"] + colour_hair; olays += hair
// var/eye = 'Icons/NOICON.dmi' + colour_eye; olays += eye
for(var/A in equipment)
var/cr1
var/obj/cr2
var/icon/cr3
var/items/Equipment/B = equipment[A]
cr1 = B.reference
cr2 = new cr1()
cr3 = cr2.icon + B.colour
cr2.icon = cr3
olays += cr2
src.overlays = olays

/*End--
Char Builder proc */


client/proc/Load(playerslot)
var/savefile/F = new(savedir)
F["/Slot[playerslot]"] >> src.mob

client/proc/Saver()
spawn() mob.Save()

mob
Write(var/savefile/F) //writes the file pretty straight forward
F["savefile_version"] << SVER
..()
F.dir.Remove("icon","overlays","underlays")
F["SavedX"] << x
F["SavedY"] << y
F["SavedZ"] << z

Read(var/savefile/F)
loc = locate(F["SavedX"],F["SavedY"],F["SavedZ"])
var/version
F["savefile_version"] >> version
if(isnull(version)) version = 0
..()
if(src.trading | src.shopping)
for(var/items/o in objholder1)
objholder1 -= o
contents += o
src.trading = 0
src.shopping = 0


mob/proc/Save()
if(!src.cur_created)
return
if(!istype(src,/mob/human/player))
return

var/txtfile = file(savedirtxt)
var/savefile/F = new(savedir)
src.icon = null
src.overlays = null
F["Slot[src.cur_slot]"] << src
fdel(txtfile)
F.ExportText("/",txtfile)
src.Builder_Player()
Question 1:
Save individual variables, not whole mob (Health, Mana, etc).
var/list/save = list("Health", "Mana", "x", "y", "z")
for(var/S in save)
F["Slot[cur_slot]_[S]"] << vars[S]

On top of that, you could save names of objects, either their paths, instead of whole object (I'm talking about objects in src.contents), it might save icon of it, or some other information.

Question 2:
If you'll save only individual variables, you could easily read what icon player should have, what he is wearing, etc. then build virtual character and show it.
Other way is to set client to null before saving (if I remember correctly), this way when you load it won't automatically assign mob to player.
In response to Ripiz
With the first one. i want to make my items have stats and inside the game their will be rare tokens you can obtain that you take to certain npcs which then random you an equipment and give that equipment random stats based on the level of the token.

E.g. Token Lev 1 and Token lev 5. lev 1 will give you a random amount of total stats to the equipment to a total of 35 combined (str,agi,def,int) whereas 5 would give 100. due to this my objects will almost entirely be unique any thoughts on this?

As for the second questions response.
so inside say the save proc. id just go (this uses a mob argument to avoid usr in procs. usr is X).
mob/verb/Saver()
Save(usr)
mob/proc/Save(mob/X)
x.client = null
F["Slot[X.cur_slot]"] << X //cur slot being a var for the slot its saved in.
In response to Midgetbuster
Yes if I remember correctly. Make few tests to be sure.

Edit:
I checked my code:
        Save()
var/savefile/F = new("savefiles/chars/[name]")
icon = null
underlays = null
overlays = null
key = null
ckey = null
client = null
F["char"] << src
F["x"] << x
F["y"] << y
F["z"] << z

        CharLoad()
set hidden = 1
if(!toLoad)
return
mobs = null
var/savefile/F = new("savefiles/chars/[toLoad]")
winset(src, "main.main", "left = map")
var/player/P
F["char"] >> P
var
xx
yy
zz
F["x"] >> xx
F["y"] >> yy
F["z"] >> zz
P.loc = locate(xx, yy, zz)
client.mob = P // if I don't set mob here, it's just black map
// so I guess you could easily display it on screen/interface
for(var/i = 1; i <= 11; i++)
var/Skill/S = P.vars["grid[i]"]
if(S)
P << output(S, "grid[i]")
for(var/Skill/S in P)
S.Cooldown()
For the first question, there's not much you can reasonably do to reduce the savefile size. Objects already only write data that's changed from the default. If you mark everything that should be temp as temp, and use reasonable default values, and scrub icons and overlays and underlays if needed, you should be good.

For the second question, the best solution is just to remove "key" from the savefile as well, as it's reading the key that causes the client to automatically log into the mob. F >> mob is in fact redundant if you don't do this. Ideally, you would also have some means of only reading the required graphical data, but the difference between the two shouldn't be too severe.
In response to Garthor
When removing the key from the file, would their need to be any further steps taken when loading.

As it stands i just launch the client and then i click load and it usually just plops me in. but thats most likely due to the key in the file.
In response to Midgetbuster
Loading directly into the client's mob variable will log the client into the mob.