Go Back  Xtreme Visual Basic Talk > Legacy Visual Basic (VB 4/5/6) > General > Saving data... lots of data... to a file.


Reply
 
Thread Tools Display Modes
  #1  
Old 06-11-2002, 01:20 PM
Mithrandel Mithrandel is offline
Junior Contributor
 
Join Date: Feb 2002
Location: They call me nowhere man.
Posts: 351
Unhappy 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. =)
Reply With Quote
  #2  
Old 06-11-2002, 01:34 PM
BillSoo's Avatar
BillSoo BillSoo is offline
Code Meister

Retired Moderator
* Guru *
 
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
Default

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
Reply With Quote
  #3  
Old 06-11-2002, 01:42 PM
Mithrandel Mithrandel is offline
Junior Contributor
 
Join Date: Feb 2002
Location: They call me nowhere man.
Posts: 351
Default

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?
Reply With Quote
  #4  
Old 06-11-2002, 02:35 PM
BillSoo's Avatar
BillSoo BillSoo is offline
Code Meister

Retired Moderator
* Guru *
 
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
Default

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
Reply With Quote
  #5  
Old 06-11-2002, 09:56 PM
loquin's Avatar
loquin loquin is offline
Google Hound

Retired Moderator
* Guru *
 
Join Date: Nov 2001
Location: Arizona, USA
Posts: 12,378
Default

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
Reply With Quote
  #6  
Old 06-12-2002, 01:03 AM
Flyguy's Avatar
Flyguy Flyguy is offline
Lost Soul

Super Moderator
* Guru *
 
Join Date: May 2001
Location: Vorlon
Posts: 18,882
Default

You could do some compression on the fly using the Zlib dll.
I've some samples on my website: http://www.relevant.nl/vb/compress.html
Reply With Quote
  #7  
Old 06-12-2002, 01:47 AM
BillSoo's Avatar
BillSoo BillSoo is offline
Code Meister

Retired Moderator
* Guru *
 
Join Date: Aug 2000
Location: Vancouver, BC, Canada
Posts: 10,441
Default

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
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
 
 
-->