From 5c145e84d8c26773d91e6030b7f7a329a173f9cd Mon Sep 17 00:00:00 2001 From: aozhiwei Date: Sun, 25 Dec 2022 13:34:53 +0800 Subject: [PATCH] 1 --- server/gameserver/mapmgr.cc | 23 ++++++++++------------- server/gameserver/mt/Map.cc | 11 +++++++++++ server/gameserver/mt/Map.h | 2 ++ 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/server/gameserver/mapmgr.cc b/server/gameserver/mapmgr.cc index 754c6e5e..934367cb 100644 --- a/server/gameserver/mapmgr.cc +++ b/server/gameserver/mapmgr.cc @@ -5,29 +5,27 @@ #include "mapinstance.h" #include "roommgr.h" +#include "mt/Map.h" + void MapMgr::Init() { - // 111 - #if 0 - std::list* maps = MetaMgr::Instance()->GetMaps(); - if (maps) { - for (auto& map_meta : *maps) { + mt::Map::Traverse + ( + [this] (const mt::Map* map_meta, bool& stop) + { MapInstance* map_instance = new MapInstance(); - map_instance->map_id = map_meta.pb->map_id(); + map_instance->map_id = map_meta->map_id(); map_instance->Init(); instance_hash_[map_instance->map_id] = map_instance; { - auto itr = mode_hash_.find(map_meta.pb->map_mode()); + auto itr = mode_hash_.find(map_meta->map_mode()); if (itr != mode_hash_.end()) { itr->second.push_back(map_instance); } else { - mode_hash_[map_meta.pb->map_mode()] = std::vector({map_instance}); + mode_hash_[map_meta->map_mode()] = std::vector({map_instance}); } } - } - } else { - A8_ABORT(); - } + }); #if 0 if (mode_hash_.find(kZombieMode) == mode_hash_.end()) { A8_ABORT(); @@ -39,7 +37,6 @@ void MapMgr::Init() #ifdef DMAP3D MetaMgr::Instance()->CheckMapSpawnPoint(); #endif - #endif } void MapMgr::UnInit() diff --git a/server/gameserver/mt/Map.cc b/server/gameserver/mt/Map.cc index e2ad25a9..9f3ef648 100644 --- a/server/gameserver/mt/Map.cc +++ b/server/gameserver/mt/Map.cc @@ -173,4 +173,15 @@ namespace mt return map_id() >= 1002 && map_id() <= 1003; } + void Map::Traverse(std::function cb) + { + bool stop = false; + for (auto& itr : raw_list) { + cb(itr, stop); + if (stop) { + break; + } + } + } + } diff --git a/server/gameserver/mt/Map.h b/server/gameserver/mt/Map.h index 6ed521fc..9d203240 100644 --- a/server/gameserver/mt/Map.h +++ b/server/gameserver/mt/Map.h @@ -31,6 +31,8 @@ namespace mt void Init1(); void Init2(); + + static void Traverse(std::function cb); }; }