SFML community forums
Help => Graphics => Topic started by: The Terminator on July 23, 2012, 11:54:51 pm
-
Hey guys, I'm making a tilemap game, and for the textures (player, tiles, etc) should I use a vector or a map to hold them? I want to assign all the tiles a specific value, like for example water's key would be 1. Which would be better for what I'm doing? I'm thinking map because you can hold the textures with a value, am I right?
-
There's no better or worse it's completly depends one your code design and what fits your needs best.
The advantages of a std::map over a std::vector is that the map isn't fixed to linearity (i.e. 0, 1, 2, 3, ...) but you can insert and remove elements whenever, where ever you want without creating any 'holes'. Additionally you can choose a key as you want (e.g. instead of int you can use std::string).
So that 'list' shows that a std::map has some nice features you maybe want to use, but if your game can deal better with a std:vector go with that one.
Additionally there's the std::unordered_map (needs a compiler that supports this part of C++11), which doesn't sort the objects after the keys and thus guarantees an insert and lookup of O(1) = constant (i.e. that is good!). ;)
-
Also, it's really easy to avoid duplicates with maps.
-
By the way: If you don't want to reinvent the wheel, you can use thor::ResourceCache of my library Thor. I also use maps internally.
-
I'll look into thor. Do you mean by "maps" tilemaps?
-
I'm developing on my mac, on xcode, do you know exactly how to link thor in? I have successfully made the libraries in Cmake.
-
it's the same for all libraries (https://developer.apple.com/library/ios/#recipes/xcode_help-project_editor/Articles/AddingaLibrarytoaTarget.html#//apple_ref/doc/uid/TP40010155-CH17-SW1)
-
Do you mean by "maps" tilemaps?
No, I mean std::maps that map keys like a filename to the actual resources (sf::Texture). I suggest to read the tutorial (http://www.bromeon.ch/libraries/thor/v2.0/tutorial-resources.html) and the API documentation (http://www.bromeon.ch/libraries/thor/v2.0/doc/group___resources.html).
I'm developing on my mac, on xcode, do you know exactly how to link thor in? I have successfully made the libraries in Cmake.
I don't know XCode, but I don't think there is something specific to Thor. Try it the way you linked SFML (and see Hiura's post) ;)
By the way, there are very few Mac users of Thor, so don't hesitate to give feedback when something doesn't work as expected.