Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Loading Tile info from disk

This topic is 5640 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

My problem is this. I represent a nearly unlimitedly sized world with tiles. I declared a structure wich holds the tile type, a pointer to what ever is on the tile, and a descriptive byte describing what is on the tile. SOmetimes these pointers to things become Linked lists. Now, I made my own world editor, of modest desgin, and I want to be able to add items on the tiles from it. However, I am having difficulty being able to save and load the information to a file, since the tiles with their items can vary in length. Does anyone know any elegant solution to reading and writing structures and their pointed at items to disk? Thanks for your help!

Share this post

Link to post
Share on other sites
Okay, I think I''ve refined my problem. Basically what I need is a way to store the locations of all item caches and doors and monsters and other stuff like that to disk. I was thinking of implementing a sparse matrix (for those of you who have any idea of what that is), but decided against it since RAM limitations aren''t such a HUGE concern, but rather the need for able storage on the hard disk. SO what I need to know is this: how do people store the locations of sparsely located items on a tile based world? Obviously if I were to make a flat out array, most of the array elements would be Null. And, add to that the fact that some of the elements could grow atleast 250 fold (Since I could have multiple items stacked on the same tile). So what I need is some kind of method for saving and loading sparse array like things to and from disk. Certainly, if there is a better way of implementing this, I''d be willing to hear that too.

Thanks for your help!

Share this post

Link to post
Share on other sites
Something you might want to try/think about:

Before tackling a problem, I like to state the problem as simplistically as possible. Basically, I think your problem boils down to the following:

Design a system in which object type and position are stored, while using minimal disk space with minimal save time and minimal load time.

I''m going to assume you can represent an object type with a simple number like an int or something. If not, it''s not a big deal, but the processing overhead is increased a bit.

I thought about two similar solutions for this problem, characterized by two different ways of expressing types of objects and their locations in the english language.

Method One:

"There are three types of items in the room: swords, healing potions, and shields. There are swords at three locations: (1,5), (2,9), and (3,4). There are healing potions at one location: (0,2). There are shields at three locations: (0,2), (2,9), and (5,7)."

Method Two:

"There are 5 locations that contain items: (0,2), (1,5), (2,9), (3,4), and (5,7). At location (0,2) there are two items: a healing potion and a shield. At location (1,5) there is one item: a sword. At location (2,9) there are two items: a sword and a shield. At location (3,4) there is one item: a sword. At location (5,7) there is one item: a shield."

Both describe exactly the same situation. Representing the second would be shorter, provided you can represent an item in a single int(or something similar). If you need to represent a Sword +1 as a sword with a postop code of 1, and a normal sword as a sword with a 0 postop code, then method one might be shorter.

Now, lets say you wanted to go with method one, the numeric encoding would look like the following:
(sword==0, healing potion==1, shield==2)

3 //three types of items
0 3 1 5 2 9 3 4 //sword(0), three coordinate pairs(3), then coordinate pairs
1 1 0 2 //potion(1), one coordinate pair(1), then coordinate pair
2 3 0 2 2 9 5 7 //shield(2), three coordinate pairs(3), then cooridinate pairs

and this just boils down to one big stream of numbers:

3 0 3 1 5 2 9 3 4 1 1 0 2 2 3 0 2 2 9 5 7

21 numbers
7 items @ 3 numbers per item
5 locaions @ 4.25 numbers per item
adding a new type of item would add at least 4 numbers
adding a new location for an existing item would add 2 numbers

method two:

5 //five locations
0 2 2 1 2 //at location (0,2) two items(2) a healing potion(1) and shield(2)
1 5 1 0 //at location (1,5) one item(1) a sword(0)
2 9 2 0 2 //at location (2,9) two items(2) a sword(0) and a shield(2)
3 4 1 0 //at location (3,4) one item(1) a sword(0)
5 7 1 2 //at location (5,7) one item(1) a shield(2)

turns into another stream of numbers
5 0 2 2 1 2 1 5 1 0 2 9 2 0 2 3 4 1 0 5 7 1 2

23 numbers
7 items @ 3.28 numbers per item
5 locations @ 4.75 numbers per location
adding a new location for items adds at least 4 numbers
adding a new type of item at an existing location adds 1 number

method two only seems less efficient because we only have three types of items. were we to add two additional types of items, one of each, method twos representation would only add 2 (making it 25) numbers, whereas method one''s would add 8(making it 29). if you have a large number of item types (compared to how many locations), method two is the way to go.

also, a way to cram the location x and y values into a single number would help, but moreso in method one.

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!