diff options
author | Andrei Karas <akaras@inbox.ru> | 2013-03-12 13:32:49 +0300 |
---|---|---|
committer | Andrei Karas <akaras@inbox.ru> | 2013-03-17 14:53:41 +0300 |
commit | 8571843f1405e676142e7bb289f9879d10a888ed (patch) | |
tree | e414c90b31979372220fa5c78f9ebb6cc05cd024 /src/resources | |
parent | 3d8682618f0b46a334f9db5dd0c780f671e7f072 (diff) | |
download | manaverse-8571843f1405e676142e7bb289f9879d10a888ed.tar.gz manaverse-8571843f1405e676142e7bb289f9879d10a888ed.tar.bz2 manaverse-8571843f1405e676142e7bb289f9879d10a888ed.tar.xz manaverse-8571843f1405e676142e7bb289f9879d10a888ed.zip |
add walkmaps support.
Fast detecting between two targets is they in same walkable area.
Diffstat (limited to 'src/resources')
-rw-r--r-- | src/resources/mapreader.cpp | 5 | ||||
-rw-r--r-- | src/resources/mapreader.h | 1 | ||||
-rw-r--r-- | src/resources/resourcemanager.cpp | 28 | ||||
-rw-r--r-- | src/resources/resourcemanager.h | 4 |
4 files changed, 37 insertions, 1 deletions
diff --git a/src/resources/mapreader.cpp b/src/resources/mapreader.cpp index 6a149c6fd..464680620 100644 --- a/src/resources/mapreader.cpp +++ b/src/resources/mapreader.cpp @@ -279,13 +279,15 @@ Map *MapReader::readMap(XmlNodePtr node, const std::string &path) const std::string fileName = path.substr(path.rfind("/") + 1); map->setProperty("shortName", fileName); + ResourceManager *const resman = ResourceManager::getInstance(); + #ifdef USE_OPENGL if (graphicsManager.getUseAtlases()) { const MapDB::MapInfo *const info = MapDB::getMapAtlas(fileName); if (info) { - map->setAtlas(ResourceManager::getInstance()->getAtlas( + map->setAtlas(resman->getAtlas( info->atlas, *info->files)); } } @@ -393,6 +395,7 @@ Map *MapReader::readMap(XmlNodePtr node, const std::string &path) map->clearIndexedTilesets(); map->setActorsFix(0, atoi(map->getProperty("actorsfix").c_str())); map->reduce(); + map->setWalkLayer(resman->getWalkLayer(fileName, map)); return map; } diff --git a/src/resources/mapreader.h b/src/resources/mapreader.h index 26e47a74c..63805ac60 100644 --- a/src/resources/mapreader.h +++ b/src/resources/mapreader.h @@ -29,6 +29,7 @@ class Map; class Properties; +class Resource; class Tileset; /** diff --git a/src/resources/resourcemanager.cpp b/src/resources/resourcemanager.cpp index 9a4d1c3f1..43092e28d 100644 --- a/src/resources/resourcemanager.cpp +++ b/src/resources/resourcemanager.cpp @@ -26,6 +26,9 @@ #include "client.h" #include "configuration.h" #include "logger.h" +#include "map.h" +#include "navigationmanager.h" +#include "walklayer.h" #include "resources/atlasmanager.h" #include "resources/dye.h" @@ -740,6 +743,31 @@ Resource *ResourceManager::getAtlas(const std::string &name, } #endif +struct WalkLayerLoader +{ + const std::string name; + Map *map; + + static Resource *load(const void *const v) + { + if (!v) + return nullptr; + + const WalkLayerLoader *const rl = static_cast<const + WalkLayerLoader *const>(v); + Resource *const resource = NavigationManager::loadWalkLayer(rl->map); + return resource; + } +}; + +WalkLayer *ResourceManager::getWalkLayer(const std::string &name, + Map *const map) +{ + WalkLayerLoader rl = {name, map}; + return static_cast<WalkLayer*>(get("map_" + name, + WalkLayerLoader::load, &rl)); +} + struct SpriteDefLoader { std::string path; diff --git a/src/resources/resourcemanager.h b/src/resources/resourcemanager.h index 0248aeda2..72efe8693 100644 --- a/src/resources/resourcemanager.h +++ b/src/resources/resourcemanager.h @@ -37,10 +37,12 @@ class AnimationDelayLoad; class Image; class ImageSet; +class Map; class SDLMusic; class Resource; class SoundEffect; class SpriteDef; +class WalkLayer; struct SDL_Surface; struct SDL_RWops; @@ -222,6 +224,8 @@ class ResourceManager final const StringVect &files) A_WARN_UNUSED; #endif + WalkLayer *getWalkLayer(const std::string &name, Map *const map); + /** * Creates a sprite definition based on a given path and the supplied * variant. |