1
This commit is contained in:
parent
cf915d9d37
commit
3b40d03bf8
@ -7,6 +7,104 @@
|
||||
|
||||
IMPL_TABLE(mt::Map)
|
||||
|
||||
static void LoadWorldObjects(const std::string& world_object_file,
|
||||
std::vector<std::shared_ptr<mt::WorldObject>>& world_objects,
|
||||
std::map<int, std::vector<std::shared_ptr<mt::WorldObject>>>& group_world_objects)
|
||||
{
|
||||
auto parse_func =
|
||||
[] (std::shared_ptr<a8::XObject> node, std::shared_ptr<mt::WorldObject> obj)
|
||||
{
|
||||
obj->object_id = node->At("id")->AsXValue();
|
||||
auto bounds = node->At("bounds");
|
||||
auto center = bounds->At("center");
|
||||
auto size = bounds->At("size");
|
||||
obj->pos.x = center->At("x")->AsXValue().GetDouble();
|
||||
obj->pos.y = center->At("y")->AsXValue().GetDouble();
|
||||
obj->pos.z = center->At("z")->AsXValue().GetDouble();
|
||||
|
||||
obj->size.x = size->At("x")->AsXValue().GetDouble();
|
||||
obj->size.y = size->At("y")->AsXValue().GetDouble();
|
||||
obj->size.z = size->At("z")->AsXValue().GetDouble();
|
||||
};
|
||||
|
||||
auto parse_human_func =
|
||||
[] (std::shared_ptr<a8::XObject> node, std::shared_ptr<mt::WorldObject> obj)
|
||||
{
|
||||
auto pos = node->At("pos");
|
||||
obj->pos.x = pos->At("x")->AsXValue().GetDouble();
|
||||
obj->pos.y = pos->At("y")->AsXValue().GetDouble();
|
||||
obj->pos.z = pos->At("z")->AsXValue().GetDouble();
|
||||
};
|
||||
|
||||
a8::XObject root;
|
||||
if (!world_object_file.empty() &&
|
||||
root.ReadFromFile(mt::MetaMgr::Instance()->GetResDir() + world_object_file)) {
|
||||
{
|
||||
auto thing = root.At("thing");
|
||||
for (int i = 0; i < thing->Size(); ++i) {
|
||||
auto obj = std::make_shared<mt::WorldObject>();
|
||||
obj->object_type = WorldObjectType_e::kBoxType;
|
||||
parse_func(thing->At(i), obj);
|
||||
world_objects.push_back(obj);
|
||||
}
|
||||
}
|
||||
{
|
||||
auto thing = root.At("loot");
|
||||
for (int i = 0; i < thing->Size(); ++i) {
|
||||
auto obj = std::make_shared<mt::WorldObject>();
|
||||
obj->object_type = WorldObjectType_e::kLootType;
|
||||
parse_func(thing->At(i), obj);
|
||||
world_objects.push_back(obj);
|
||||
}
|
||||
}
|
||||
{
|
||||
auto thing = root.At("car");
|
||||
for (int i = 0; i < thing->Size(); ++i) {
|
||||
auto obj = std::make_shared<mt::WorldObject>();
|
||||
obj->object_type = WorldObjectType_e::kCarType;
|
||||
parse_func(thing->At(i), obj);
|
||||
world_objects.push_back(obj);
|
||||
}
|
||||
}
|
||||
{
|
||||
auto thing = root.At("human");
|
||||
for (int i = 0; i < thing->Size(); ++i) {
|
||||
auto obj = std::make_shared<mt::WorldObject>();
|
||||
obj->object_type = WorldObjectType_e::kBornPointType;
|
||||
parse_human_func(thing->At(i), obj);
|
||||
world_objects.push_back(obj);
|
||||
}
|
||||
}
|
||||
{
|
||||
auto group = root.At("group");
|
||||
for (int i = 0; i < group->Size(); ++i) {
|
||||
auto group_obj = group->At(i);
|
||||
std::vector<std::string> keys;
|
||||
group_obj->GetKeys(keys);
|
||||
for (auto key : keys) {
|
||||
int ikey = a8::XValue(key);
|
||||
if (group_world_objects.find(ikey) != group_world_objects.end()) {
|
||||
abort();
|
||||
}
|
||||
std::vector<std::shared_ptr<mt::WorldObject>> objects;
|
||||
auto items = group_obj->At(key);
|
||||
for (int iii = 0; iii < items->Size(); ++iii) {
|
||||
auto item_obj = items->At(iii);
|
||||
auto obj = std::make_shared<mt::WorldObject>();
|
||||
{
|
||||
obj->pos.x = item_obj->At("x")->AsXValue().GetDouble();
|
||||
obj->pos.y = item_obj->At("y")->AsXValue().GetDouble();
|
||||
obj->pos.z = item_obj->At("z")->AsXValue().GetDouble();
|
||||
}
|
||||
objects.push_back(obj);
|
||||
}
|
||||
group_world_objects[ikey] = objects;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
namespace mt
|
||||
{
|
||||
|
||||
@ -127,7 +225,9 @@ namespace mt
|
||||
A8_ABORT();
|
||||
}
|
||||
collider_info = MapCollider::GetByName(map_collider());
|
||||
LoadWorldObjects();
|
||||
LoadWorldObjects(world_object_file(),
|
||||
_world_objects,
|
||||
_group_world_objects);
|
||||
PostProcess();
|
||||
}
|
||||
|
||||
@ -184,102 +284,6 @@ namespace mt
|
||||
return map_id() >= 1002 && map_id() <= 1003;
|
||||
}
|
||||
|
||||
void Map::LoadWorldObjects()
|
||||
{
|
||||
auto parse_func =
|
||||
[] (std::shared_ptr<a8::XObject> node, std::shared_ptr<WorldObject> obj)
|
||||
{
|
||||
obj->object_id = node->At("id")->AsXValue();
|
||||
auto bounds = node->At("bounds");
|
||||
auto center = bounds->At("center");
|
||||
auto size = bounds->At("size");
|
||||
obj->pos.x = center->At("x")->AsXValue().GetDouble();
|
||||
obj->pos.y = center->At("y")->AsXValue().GetDouble();
|
||||
obj->pos.z = center->At("z")->AsXValue().GetDouble();
|
||||
|
||||
obj->size.x = size->At("x")->AsXValue().GetDouble();
|
||||
obj->size.y = size->At("y")->AsXValue().GetDouble();
|
||||
obj->size.z = size->At("z")->AsXValue().GetDouble();
|
||||
};
|
||||
|
||||
auto parse_human_func =
|
||||
[] (std::shared_ptr<a8::XObject> node, std::shared_ptr<WorldObject> obj)
|
||||
{
|
||||
auto pos = node->At("pos");
|
||||
obj->pos.x = pos->At("x")->AsXValue().GetDouble();
|
||||
obj->pos.y = pos->At("y")->AsXValue().GetDouble();
|
||||
obj->pos.z = pos->At("z")->AsXValue().GetDouble();
|
||||
};
|
||||
|
||||
a8::XObject root;
|
||||
if (!world_object_file().empty() &&
|
||||
root.ReadFromFile(MetaMgr::Instance()->GetResDir() + world_object_file())) {
|
||||
{
|
||||
auto thing = root.At("thing");
|
||||
for (int i = 0; i < thing->Size(); ++i) {
|
||||
auto obj = std::make_shared<WorldObject>();
|
||||
obj->object_type = WorldObjectType_e::kBoxType;
|
||||
parse_func(thing->At(i), obj);
|
||||
_world_objects.push_back(obj);
|
||||
}
|
||||
}
|
||||
{
|
||||
auto thing = root.At("loot");
|
||||
for (int i = 0; i < thing->Size(); ++i) {
|
||||
auto obj = std::make_shared<WorldObject>();
|
||||
obj->object_type = WorldObjectType_e::kLootType;
|
||||
parse_func(thing->At(i), obj);
|
||||
_world_objects.push_back(obj);
|
||||
}
|
||||
}
|
||||
{
|
||||
auto thing = root.At("car");
|
||||
for (int i = 0; i < thing->Size(); ++i) {
|
||||
auto obj = std::make_shared<WorldObject>();
|
||||
obj->object_type = WorldObjectType_e::kCarType;
|
||||
parse_func(thing->At(i), obj);
|
||||
_world_objects.push_back(obj);
|
||||
}
|
||||
}
|
||||
{
|
||||
auto thing = root.At("human");
|
||||
for (int i = 0; i < thing->Size(); ++i) {
|
||||
auto obj = std::make_shared<WorldObject>();
|
||||
obj->object_type = WorldObjectType_e::kBornPointType;
|
||||
parse_human_func(thing->At(i), obj);
|
||||
_world_objects.push_back(obj);
|
||||
}
|
||||
}
|
||||
{
|
||||
auto group = root.At("group");
|
||||
for (int i = 0; i < group->Size(); ++i) {
|
||||
auto group_obj = group->At(i);
|
||||
std::vector<std::string> keys;
|
||||
group_obj->GetKeys(keys);
|
||||
for (auto key : keys) {
|
||||
int ikey = a8::XValue(key);
|
||||
if (_group_world_objects.find(ikey) != _group_world_objects.end()) {
|
||||
abort();
|
||||
}
|
||||
std::vector<std::shared_ptr<WorldObject>> objects;
|
||||
auto items = group_obj->At(key);
|
||||
for (int iii = 0; iii < items->Size(); ++iii) {
|
||||
auto item_obj = items->At(iii);
|
||||
auto obj = std::make_shared<WorldObject>();
|
||||
{
|
||||
obj->pos.x = item_obj->At("x")->AsXValue().GetDouble();
|
||||
obj->pos.y = item_obj->At("y")->AsXValue().GetDouble();
|
||||
obj->pos.z = item_obj->At("z")->AsXValue().GetDouble();
|
||||
}
|
||||
objects.push_back(obj);
|
||||
}
|
||||
_group_world_objects[ikey] = objects;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
bool Map::IsOpen() const
|
||||
{
|
||||
return is_open();
|
||||
|
@ -53,7 +53,6 @@ namespace mt
|
||||
private:
|
||||
glm::vec3 sampling_pos_;
|
||||
|
||||
void LoadWorldObjects();
|
||||
void PostProcess();
|
||||
};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user