aozhiwei c572332f5f 1
2023-06-14 19:56:08 +08:00

68 lines
1.9 KiB
C++

#include "precompile.h"
#include "mt/SafeArea.h"
IMPL_TABLE(mt::SafeArea)
std::map<int, std::vector<mt::SafeArea*>> mt::SafeArea::type_hash_;
namespace mt
{
void SafeArea::Init1()
{
{
auto itr = type_hash_.find(type());
if (itr == type_hash_.end()) {
type_hash_[type()] = std::vector<mt::SafeArea*>({this});
} else {
if (itr->second.empty()) {
abort();
}
if (itr->second.at(itr->second.size() - 1)->id() + 1 != id()) {
abort();
}
itr->second.push_back(this);
}
}
if (!boss().empty()) {
std::vector<std::string> strings;
a8::Split(boss(), strings, ':');
if (strings.size() != 5) {
abort();
}
_boss = std::make_shared<std::tuple<glm::vec3, float, int>>
(
glm::vec3((float)a8::XValue(strings[0]).GetDouble(),
(float)a8::XValue(strings[1]).GetDouble(),
(float)a8::XValue(strings[2]).GetDouble()
),
(float)a8::XValue(strings[3]).GetDouble(),
a8::XValue(strings[4]).GetInt()
);
}
}
void SafeArea::StaticPostInit()
{
for (auto& pair : type_hash_) {
if (pair.second.size() < 1) {
abort();
}
int ring_count = pair.second.size() - 1;
auto last_area = pair.second.at(pair.second.size() - 1);
for (auto& meta : pair.second) {
meta->small_ring_count_ = ring_count--;
meta->last_area_ = last_area;
}
}
}
const SafeArea* SafeArea::GetByType(int type)
{
auto itr = type_hash_.find(type);
return itr != type_hash_.end() ? itr->second.at(0) : nullptr;
}
}