80 lines
2.1 KiB
C++
80 lines
2.1 KiB
C++
#include "precompile.h"
|
|
|
|
#include "mapmgr.h"
|
|
#include "room.h"
|
|
#include "mapinstance.h"
|
|
#include "metamgr.h"
|
|
#include "cs_proto.pb.h"
|
|
#include "roommgr.h"
|
|
|
|
void MapMgr::Init()
|
|
{
|
|
std::list<MetaData::Map>* maps = MetaMgr::Instance()->GetMaps();
|
|
if (maps) {
|
|
for (auto& map_meta : *maps) {
|
|
MapInstance* map_instance = new MapInstance();
|
|
map_instance->map_id = map_meta.i->map_id();
|
|
map_instance->Init();
|
|
instance_hash_[map_instance->map_id] = map_instance;
|
|
{
|
|
auto itr = mode_hash_.find(map_meta.i->map_mode());
|
|
if (itr != mode_hash_.end()) {
|
|
itr->second.push_back(map_instance);
|
|
} else {
|
|
mode_hash_[map_meta.i->map_mode()] = std::vector<MapInstance*>({map_instance});
|
|
}
|
|
}
|
|
}
|
|
} else {
|
|
abort();
|
|
}
|
|
#if 0
|
|
if (mode_hash_.find(kZombieMode) == mode_hash_.end()) {
|
|
abort();
|
|
}
|
|
#endif
|
|
if (mode_hash_.find(kChiJiMode) == mode_hash_.end()) {
|
|
abort();
|
|
}
|
|
}
|
|
|
|
void MapMgr::UnInit()
|
|
{
|
|
for (auto& pair : instance_hash_) {
|
|
pair.second->UnInit();
|
|
delete pair.second;
|
|
}
|
|
instance_hash_.clear();
|
|
}
|
|
|
|
void MapMgr::AttachRoom(Room* room, RoomInitInfo& init_info)
|
|
{
|
|
MapInstance* map_instance = init_info.init_map_id == 0 ?
|
|
RandMapInstance(init_info.room_mode) : GetMapInstance(init_info.init_map_id);
|
|
if (!map_instance) {
|
|
map_instance = RandMapInstance(init_info.room_mode);
|
|
} else if (map_instance->GetMapMeta()->i->map_mode() != init_info.room_mode) {
|
|
#ifdef DEBUG
|
|
#else
|
|
map_instance = RandMapInstance(init_info.room_mode);
|
|
#endif
|
|
}
|
|
|
|
if (!map_instance) {
|
|
abort();
|
|
}
|
|
map_instance->AttachRoom(room, init_info);
|
|
}
|
|
|
|
MapInstance* MapMgr::GetMapInstance(int map_id)
|
|
{
|
|
auto itr = instance_hash_.find(map_id);
|
|
return itr != instance_hash_.end() ? itr->second : nullptr;
|
|
}
|
|
|
|
MapInstance* MapMgr::RandMapInstance(int map_mode)
|
|
{
|
|
auto itr = mode_hash_.find(map_mode);
|
|
return itr != mode_hash_.end() ? itr->second[rand() % itr->second.size()] : nullptr;
|
|
}
|