This commit is contained in:
aozhiwei 2022-12-25 17:11:02 +08:00
parent 7e67bc5f5e
commit 90770e10ff
2 changed files with 20 additions and 1 deletions

View File

@ -3,6 +3,7 @@
#include "mt/AirLine.h"
IMPL_TABLE(mt::AirLine)
std::map<int, std::vector<const mt::AirLine*>> mt::AirLine::mapid_hash_;
namespace mt
{
@ -21,6 +22,21 @@ namespace mt
_end_point_x = a8::XValue(strings[0]).GetDouble();
_end_point_y = a8::XValue(strings[1]).GetDouble();
}
{
auto itr = map_id_hash_.find(map_id());
if (itr != map_id_hash_.end()) {
itr->second.push_back(this);
} else {
map_id_hash_[map_id()] = std::vector<const mt::AirLine*>({this});
}
}
}
const AirLine* AirLine::RandAirLine(int map_id)
{
auto itr = mapid_hash_.find(map_ida);
return itr != mapid_hash_.end && &itr->second.empty() ?
itr->second.at(rand() % itr->second.size()) : nullptr;
}
}

View File

@ -18,7 +18,10 @@ namespace mt
void Init1();
static const AirLine* RandAirLine(int map_id) {};
static const AirLine* RandAirLine(int map_id);
private:
static std::map<int, std::vector<const mt::AirLine*>> mapid_hash_;
};
}