 |

06-11-2002, 01:20 PM
|
|
Junior Contributor
|
|
Join Date: Feb 2002
Location: They call me nowhere man.
Posts: 351
|
|
Saving data... lots of data... to a file.
|
I spent the last three weeks building up a pretty complicated tool for creating 2d levels - 20x20 tiles in each level. Now, I've come to the point where the last thing I need to implement is a save and load routine... and this is where things go downhill.
You see, I'm not sure how to save all this data, unless I do it by the standard "load everything into a string and spit that string out into #1" method. And when I do it like that, not only is the map file *huge* (say, around 150kb), but the file itself isn't too pretty - it's something along the lines of:
@1
You enter the tile
0
0
0
1
False
True
@end_1
Except much, much more data per tile, and with 400 tiles, plus extraneous information such as the author name, area level, et cetra.
I'm using classes to store all my data... and here's my question: is it possible to just load all the binary data from the collection of tile classes - basically, grab the values that make up the collection in ram - and spit THAT out into a file? And if I do so, is it possible to load that data back into the classes?
Thankee kindly. =)
|
|

06-11-2002, 01:34 PM
|
 |
Code Meister
Retired Moderator * Guru *
|
|
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
|
|
|
If it were me, I would have a Header type structure to store the info like authour, date, names etc. Then the actual leval data would be a simple array of longs.
Suppose I did that and had a header type named hdr and an array named aData(). I could then save the data like this:
dim ff as integer
ff=freefile
open "mylevel.dat" for BINARY as #ff
put #ff,1,hdr 'save the header
put #ff,,aData 'save the data
Close #ff
Loading is just as easy:
dim ff as integer
ff=freefile
open "mylevel.dat" for binary as #ff
get #ff,1,hdr
get #ff,,aData
close #ff
This assumes aData is a STATIC array, if it is dynamic, you have to preload the size first. You can do this by storing the size in the hdr.
I don't know if this method will work with an array of OBJECTS, but it seems to work fine for simple numbers.
|
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
|

06-11-2002, 01:42 PM
|
|
Junior Contributor
|
|
Join Date: Feb 2002
Location: They call me nowhere man.
Posts: 351
|
|
|
Ah, but my problem is that each of my objects contains booleans, bytes, and strings... if I did what you're suggesting, I'd have to save the strings in the HEADER, and turn the booleans into bytes and then save the new array of bytes into the DATA section... a painful process...
My main concern is that the map files are ugly and huge... perhaps I could compress them after saving, and uncompress them before loading?
The thing is, I've never even touched compression before... is this feasible?
|
|

06-11-2002, 02:35 PM
|
 |
Code Meister
Retired Moderator * Guru *
|
|
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
|
|
|
If you used an array of UDT, I'm pretty sure you could store that using the above method. The strings would have to be fixed length though.
As for compression, you could ZIP the file after it is saved. There are some 3rd party tools for that.
|
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
|

06-11-2002, 09:56 PM
|
 |
Google Hound
Retired Moderator * Guru *
|
|
Join Date: Nov 2001
Location: Arizona, USA
Posts: 12,378
|
|
|
With UDT, you might also consider random files.
|
__________________
Lou
"I have my standards. They may be low, but I have them!" ~ Bette Middler
"It's a book about a Spanish guy called Manual. You should read it." ~ Dilbert
"To understand recursion, you must first understand recursion." ~ unknown
|

06-12-2002, 01:03 AM
|
 |
Lost Soul
Super Moderator * Guru *
|
|
Join Date: May 2001
Location: Vorlon
Posts: 18,882
|
|
|

06-12-2002, 01:47 AM
|
 |
Code Meister
Retired Moderator * Guru *
|
|
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
|
|
Quote:
Originally posted by loquin
With UDT, you might also consider random files.
|
I don't think you could use RANDOM if there is supposed to be a header structure at the start of the file.
|
__________________
"I have a plan so cunning you could put a tail on it and call it a weasel!" - Edmund Blackadder
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
|
|
| Display Modes |
Linear Mode
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|
|