30.06.2012, 15:42
I have a mapping system on my server and maps are saved in raw data in this format:
model x y z rx ry rz group
But I'd like to implement saving for material textures and text. I need help working out the best way to do this.
Obviously only material indexes that HAVE materials changed need to be saved - no need to waste space. The thing is the format will be different for textures and text - textures have this data to be saved:
materialindex, &modelid, txdname[], texturename[], &materialcolor
while text has:
materialindex, text[], &materialsize, fontface[], &fontsize, &bold, &fontcolor, &backcolor, &textalignment
So obviously I would need to identify in the data what type of material is applied - texture or text.
I have a rough idea how to do this, just not sure how to implement it with sscanf. Also a problem is spaces - there may be spaces in the material text and the material text font. Would there be a better option than sscanf or what? Would I have to use a different delimiter? I don't want to edit the format of the model x y z rx ry rz group part because then players lose their old maps. It seems very complicated to me (not sscanf - trying to save all this data on one line).
Thoughts please.
Here is one of my theories:
Write the line like so, for text at least, material textures are easier:
model x y z rx ry rz group materialindex materialtype text[?] materialsize fontface[?] fontsize, bold, fontcolor backcolor textalignment
By changing the delimiter in sscanf you could find the end of the text/fontface. Ugh. I'm really confused about this for some reason. Another thing I need to stress is that materials can either be textures or text - so sscanf would need to be used twice - one to read the 'material type' then again to get the data for that ONE material index, and do the same for them all on that line.
Theory #2
Perhaps materials should go down on to the next line?
model x y z rx ry rz group
But I'd like to implement saving for material textures and text. I need help working out the best way to do this.
Obviously only material indexes that HAVE materials changed need to be saved - no need to waste space. The thing is the format will be different for textures and text - textures have this data to be saved:
materialindex, &modelid, txdname[], texturename[], &materialcolor
while text has:
materialindex, text[], &materialsize, fontface[], &fontsize, &bold, &fontcolor, &backcolor, &textalignment
So obviously I would need to identify in the data what type of material is applied - texture or text.
I have a rough idea how to do this, just not sure how to implement it with sscanf. Also a problem is spaces - there may be spaces in the material text and the material text font. Would there be a better option than sscanf or what? Would I have to use a different delimiter? I don't want to edit the format of the model x y z rx ry rz group part because then players lose their old maps. It seems very complicated to me (not sscanf - trying to save all this data on one line).
Thoughts please.
Here is one of my theories:
Write the line like so, for text at least, material textures are easier:
model x y z rx ry rz group materialindex materialtype text[?] materialsize fontface[?] fontsize, bold, fontcolor backcolor textalignment
By changing the delimiter in sscanf you could find the end of the text/fontface. Ugh. I'm really confused about this for some reason. Another thing I need to stress is that materials can either be textures or text - so sscanf would need to be used twice - one to read the 'material type' then again to get the data for that ONE material index, and do the same for them all on that line.
Theory #2
Perhaps materials should go down on to the next line?