Difference between revisions of "Talk:Data structures for the map"
(→Re:Talk:Data structures for the map: new section) |
|||
Line 5: | Line 5: | ||
== Re:Talk:Data structures for the map == | == Re:Talk:Data structures for the map == | ||
Store the objects that way may look good if you think about display since you need "get objects at x y" method, but iterating every monster to make it move would be a real pain without a list-like structure ; who would like to iterate the whole map every time you need to check which monster it is the turn to act ? You can duplicate the reference using a 2d map plus the list, but double referencing data structures | Store the objects that way may look good if you think about display since you need "get objects at x y" method, but iterating every monster to make it move would be a real pain without a list-like structure ; who would like to iterate the whole map every time you need to check which monster it is the turn to act ? You can duplicate the reference using a 2d map plus the list, but double referencing data structures look like uneeded complexity to me ; i'm more comfortable iterating the list at every coordinate request. | ||
Here is another reasonable way to proceed if you want to, though : you can use hash table of objects with coordinates as keys, so you can both iterate all and have the get object in linear time. In case you want to stack items, you just have to make the hash table work with lists of objects. However, depending on programming language, hash tables may not be easily avaible. | Here is another reasonable way to proceed if you want to, though : you can use hash table of objects with coordinates as keys, so you can both iterate all and have the get object in linear time. In case you want to stack items, you just have to make the hash table work with lists of objects. However, depending on programming language, hash tables may not be easily avaible. |
Latest revision as of 13:39, 29 December 2010
"So, there are lists of Objects, Items and Monsters on the given level. Every element of these lists must also store the position. Every time you want to know what items lie on given square, you have to iterate trough the list of all items and take the ones with proper position set. It might seem slow, but you won't have to do it often."
Why shouldn't we use pointers (or some sort of reference if in a non C language) to reference objects in our 2d array. Some of the coding is done a certain way to make it all fast, and then we have to scan through arrays to find all nearby objects and mobs.
Re:Talk:Data structures for the map
Store the objects that way may look good if you think about display since you need "get objects at x y" method, but iterating every monster to make it move would be a real pain without a list-like structure ; who would like to iterate the whole map every time you need to check which monster it is the turn to act ? You can duplicate the reference using a 2d map plus the list, but double referencing data structures look like uneeded complexity to me ; i'm more comfortable iterating the list at every coordinate request.
Here is another reasonable way to proceed if you want to, though : you can use hash table of objects with coordinates as keys, so you can both iterate all and have the get object in linear time. In case you want to stack items, you just have to make the hash table work with lists of objects. However, depending on programming language, hash tables may not be easily avaible.