Hello people, I just have another silly question, I need to store data, and be able to load and modify it later...
think as if I needed to store x,y,z,color,refraction,hardness,materialtype
My biggest problem is that not all values store data the same way...
x,y,z: Store world coordinates, integers infinite
color: Indexed value, positive integer, max 4228250625
refraction: float -1 to +1
hardness: 0 to 255
materialtype: integer. from 0 to 65535
How would I approach as setting these value tipes as a single "string" of data, and decompose it afterwards ?
What are your recommendations? How can I approach this problem?
All comments are well received !!!
Thanks in advance!
Gamedata structure
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Gamedata structure
Save each item of data to a text file, as a string ( WriteStringN() ) That makes it easy to read back, line-by-line, converting to the data type as you go.
Example:
Edit: In your case, you will be reading into the relevent Structure values
Example:
Code: Select all
Procedure SaveSettings()
;-----------------------
igStep = GetGadgetState(#SpinStep)
If CreateFile(#FileIO, sgSettingsFile)
WriteStringN(#FileIO,sgDefaultFolder,#PB_UTF8) ;01
WriteStringN(#FileIO,Str(igStep),#PB_UTF8) ;02
WriteStringN(#FileIO,Str(igDelim),#PB_UTF8) ;03
CloseFile(#FileIO)
EndIf
EndProcedure
Procedure ReadSettings()
;-----------------------
If ReadFile(#FileIO, sgSettingsFile)
sgDefaultFolder = ReadString(#FileIO,#PB_UTF8) ;01
igStep = Val(ReadString(#FileIO,#PB_UTF8)) ;02
igDelim = Val(ReadString(#FileIO,#PB_UTF8)) ;03
CloseFile(#FileIO)
Select(igDelim)
Case 0: sgDelim = Chr(44) : igExt = 0: sgExt = ".CSV" ;COMMA
Case 1: sgDelim = Chr(9) : igExt = 1: sgExt = ".DAT" ;TAB
Case 2: sgDelim = Chr(32) : igExt = 2: sgExt = ".TXT" ;SPACE
EndSelect
EndIf
EndProcedure
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: Gamedata structure
Can't you put all of them in a structure and save the whole structure to file in a single step ?
Code: Select all
Macro dump
Debug var\x
Debug var\y
Debug var\z
Debug var\f1
Debug var\f2
EndMacro
Structure MyStructure
x.i
y.i
z.i
f1.f
f2.f
EndStructure
var.MyStructure
var\x = 1
var\y = 2
var\z = 3
var\f1 = 1.125
var\f2 = 1.5
dump
CreateFile(0, "file.dat")
WriteData(0, @var, SizeOf(MyStructure))
CloseFile(0)
ClearStructure(@var, MyStructure)
dump
ReadFile(0, "file.dat")
ReadData(0, @var, SizeOf(MyStructure))
CloseFile(0)
dump
"Have you tried turning it off and on again ?"
Re: Gamedata structure
I just thought It would be a good idea to see how voxel engines store their data.
Ken Silverman wrote an awesome voxel engine back in the 90s, released the source in 2000
I´ll check out the code to see if I can grasp some of it´s complexity...
Crazy idea, but can I store "game world information" on a database, lets say something like sql?
I know its used on some MMORPG to handle accounts, items and stats, but it is unknown to me if I can constantly "stream" querys to a
database... at least for a big chunk of data...
Thank you guys, keep the ideas coming!
Ken Silverman wrote an awesome voxel engine back in the 90s, released the source in 2000
I´ll check out the code to see if I can grasp some of it´s complexity...
Crazy idea, but can I store "game world information" on a database, lets say something like sql?
I know its used on some MMORPG to handle accounts, items and stats, but it is unknown to me if I can constantly "stream" querys to a
database... at least for a big chunk of data...
Thank you guys, keep the ideas coming!
-
- Always Here
- Posts: 6426
- Joined: Fri Oct 23, 2009 2:33 am
- Location: Wales, UK
- Contact:
Re: Gamedata structure
Of course you can. It's all about the amount of data you have, where it is to be stored (local drive/network/internet server etc), the number of players that need access to the same data simultaneously. So, you need to start with the game play criteria before you can narrow-down the best data saving strategy. After that, create some representative data samples and just try out the possible solutions.Crazy idea, but can I store "game world information" on a database, lets say something like sql?
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
If it sounds simple, you have not grasped the complexity.
Re: Gamedata structure
Thanks IdeasVacuum, ideally what I´m trying to do is to save a "voxel" x, y, z, red, green, blue, alpha, reflection, refraction, hardness, glow.
I´ve checked yesterday Ken Silverman´s VoxLap engine, and I haven´t discovered yet how he saves the world, or even the size of the chunks he loads... Also his renderer is beatiful, but it has lots of assembler and I don´t understand it yet.
Meanwhile, I´m making a object editor, so I can start doing torches, chairs, etc. It uses the embedded Ogre engine.
I´ve checked yesterday Ken Silverman´s VoxLap engine, and I haven´t discovered yet how he saves the world, or even the size of the chunks he loads... Also his renderer is beatiful, but it has lots of assembler and I don´t understand it yet.
Meanwhile, I´m making a object editor, so I can start doing torches, chairs, etc. It uses the embedded Ogre engine.
Re: Gamedata structure
Thank you Luis, I guess your approach is more elegant for my code now, but when I get to it (i.e. Map chunk loader) I´ll have a better understanding of what I need to achieve.
Thank you guys !!!
Thank you guys !!!
Re: Gamedata structure
That's the most simple and direct if you have to save the type of data you mentioned: basic data types that are "confined" inside the structure's space. If you will ever have more complex fields (dynamic strings, lists, etc) you will have to make some kind of procedure more or less automatic (*less* in PB I fear) to serialize/deserialize the data to/from file.
http://en.wikipedia.org/wiki/Serialization
http://en.wikipedia.org/wiki/Serialization
"Have you tried turning it off and on again ?"
Re: Gamedata structure
Yes, thats pretty much what structures are for, organizing of data.
A structure represents a mask for a data set. Just save the number of data sets to the file and after that all data sets. To keep track of data types use structures. Thats the common and fast way to save and load binary data.
For voxels a pretty fancy way to store voxel data is a octree.
A structure represents a mask for a data set. Just save the number of data sets to the file and after that all data sets. To keep track of data types use structures. Thats the common and fast way to save and load binary data.
For voxels a pretty fancy way to store voxel data is a octree.