1
This commit is contained in:
parent
9b9b497ed2
commit
dd13708e6e
@ -115,7 +115,7 @@ namespace mc
|
|||||||
{
|
{
|
||||||
auto childs_arr = xobj->At("childs");
|
auto childs_arr = xobj->At("childs");
|
||||||
for (int i = 0; i < childs_arr->Size(); ++i) {
|
for (int i = 0; i < childs_arr->Size(); ++i) {
|
||||||
ColliderNode* node = new ColliderNode();
|
std::shared_ptr<ColliderNode> node = std::make_shared<ColliderNode>();
|
||||||
node->parent = this;
|
node->parent = this;
|
||||||
node->Read(childs_arr->At(i));
|
node->Read(childs_arr->At(i));
|
||||||
if (childs.find(node->name) != childs.end()) {
|
if (childs.find(node->name) != childs.end()) {
|
||||||
|
@ -101,7 +101,7 @@ namespace mc
|
|||||||
Bounds bounds;
|
Bounds bounds;
|
||||||
Transform transform;
|
Transform transform;
|
||||||
std::vector<Collider*> colliders;
|
std::vector<Collider*> colliders;
|
||||||
std::map<std::string, ColliderNode*> childs;
|
std::map<std::string, std::shared_ptr<ColliderNode>> childs;
|
||||||
|
|
||||||
void Read(std::shared_ptr<a8::XObject> xobj);
|
void Read(std::shared_ptr<a8::XObject> xobj);
|
||||||
};
|
};
|
||||||
|
@ -62,7 +62,8 @@ static float frand()
|
|||||||
return (float)rand()/(float)RAND_MAX;
|
return (float)rand()/(float)RAND_MAX;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void TraverseMapColliderNode(mc::ColliderNode* node, std::function<void (mc::ColliderNode*)> cb)
|
static void TraverseMapColliderNode(std::shared_ptr<mc::ColliderNode> node,
|
||||||
|
std::function<void (std::shared_ptr<mc::ColliderNode>)> cb)
|
||||||
{
|
{
|
||||||
for (auto& pair : node->childs) {
|
for (auto& pair : node->childs) {
|
||||||
cb(pair.second);
|
cb(pair.second);
|
||||||
@ -774,7 +775,7 @@ bool MapInstance::PtInHouse(const glm::vec3& pt, glm::vec3& nearest_pt)
|
|||||||
void MapInstance::LoadHouse()
|
void MapInstance::LoadHouse()
|
||||||
{
|
{
|
||||||
if (GetMapMeta()->collider_info) {
|
if (GetMapMeta()->collider_info) {
|
||||||
mc::ColliderNode* building_root = GetMapMeta()->collider_info->GetNode("building");
|
std::shared_ptr<mc::ColliderNode> building_root = GetMapMeta()->collider_info->GetNode("building");
|
||||||
if (building_root) {
|
if (building_root) {
|
||||||
for (auto& pair : building_root->childs) {
|
for (auto& pair : building_root->childs) {
|
||||||
auto node = pair.second;
|
auto node = pair.second;
|
||||||
@ -849,7 +850,7 @@ void MapInstance::LoadHouse()
|
|||||||
//求三角形min_y max_y
|
//求三角形min_y max_y
|
||||||
things_.reserve(1024 * 10);
|
things_.reserve(1024 * 10);
|
||||||
auto cb =
|
auto cb =
|
||||||
[this, box_tri_arr] (mc::ColliderNode* node)
|
[this, box_tri_arr] (std::shared_ptr<mc::ColliderNode> node)
|
||||||
{
|
{
|
||||||
if (!node->colliders.empty()) {
|
if (!node->colliders.empty()) {
|
||||||
for (auto c : node->colliders) {
|
for (auto c : node->colliders) {
|
||||||
@ -858,7 +859,7 @@ void MapInstance::LoadHouse()
|
|||||||
mesh_collider->mesh.triangles.reserve(mesh_collider->mesh.raw_triangles.size() / 3);
|
mesh_collider->mesh.triangles.reserve(mesh_collider->mesh.raw_triangles.size() / 3);
|
||||||
for (int i = 0; i < mesh_collider->mesh.raw_triangles.size(); i += 3) {
|
for (int i = 0; i < mesh_collider->mesh.raw_triangles.size(); i += 3) {
|
||||||
auto& tri = a8::FastAppend(mesh_collider->mesh.triangles);
|
auto& tri = a8::FastAppend(mesh_collider->mesh.triangles);
|
||||||
tri.node = node;
|
tri.node = node.get();
|
||||||
int v0 = mesh_collider->mesh.raw_triangles[i + 0];
|
int v0 = mesh_collider->mesh.raw_triangles[i + 0];
|
||||||
int v1 = mesh_collider->mesh.raw_triangles[i + 1];
|
int v1 = mesh_collider->mesh.raw_triangles[i + 1];
|
||||||
int v2 = mesh_collider->mesh.raw_triangles[i + 2];
|
int v2 = mesh_collider->mesh.raw_triangles[i + 2];
|
||||||
@ -905,7 +906,7 @@ void MapInstance::LoadHouse()
|
|||||||
box_collider->triangles.reserve(2 * 6);
|
box_collider->triangles.reserve(2 * 6);
|
||||||
for (int i = 0; i < 12; ++i) {
|
for (int i = 0; i < 12; ++i) {
|
||||||
auto& tri = a8::FastAppend(box_collider->triangles);
|
auto& tri = a8::FastAppend(box_collider->triangles);
|
||||||
tri.node = node;
|
tri.node = node.get();
|
||||||
tri.vert0 = new_points[box_tri_arr[i][0]];
|
tri.vert0 = new_points[box_tri_arr[i][0]];
|
||||||
tri.vert1 = new_points[box_tri_arr[i][1]];
|
tri.vert1 = new_points[box_tri_arr[i][1]];
|
||||||
tri.vert2 = new_points[box_tri_arr[i][2]];
|
tri.vert2 = new_points[box_tri_arr[i][2]];
|
||||||
|
@ -12,7 +12,7 @@ namespace mc
|
|||||||
|
|
||||||
struct HouseInfo
|
struct HouseInfo
|
||||||
{
|
{
|
||||||
mc::ColliderNode* node = nullptr;
|
std::shared_ptr<mc::ColliderNode> node;
|
||||||
std::vector<float> verts;
|
std::vector<float> verts;
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -77,7 +77,7 @@ class MapInstance : public std::enable_shared_from_this<MapInstance>
|
|||||||
|
|
||||||
std::list<HouseInfo> houses_;
|
std::list<HouseInfo> houses_;
|
||||||
|
|
||||||
std::vector<mc::ColliderNode*> things_;
|
std::vector<std::shared_ptr<mc::ColliderNode>> things_;
|
||||||
|
|
||||||
std::string map_tpl_name_;
|
std::string map_tpl_name_;
|
||||||
const mt::Map* map_meta_ = nullptr;
|
const mt::Map* map_meta_ = nullptr;
|
||||||
|
@ -34,7 +34,7 @@ namespace mt
|
|||||||
std::map<int, int> car_num_limit_;
|
std::map<int, int> car_num_limit_;
|
||||||
std::vector<int> safearea_list;
|
std::vector<int> safearea_list;
|
||||||
std::vector<std::shared_ptr<WorldObject>> _world_objects;
|
std::vector<std::shared_ptr<WorldObject>> _world_objects;
|
||||||
MapCollider* collider_info = nullptr;
|
std::shared_ptr<MapCollider> collider_info;
|
||||||
|
|
||||||
std::string RandTemplate() const;
|
std::string RandTemplate() const;
|
||||||
int GetCarLimit(int car_id) const;
|
int GetCarLimit(int car_id) const;
|
||||||
|
@ -9,13 +9,13 @@
|
|||||||
|
|
||||||
#include "navmesh.pb.h"
|
#include "navmesh.pb.h"
|
||||||
|
|
||||||
std::vector<mt::MapCollider*> mt::MapCollider::raw_list;
|
std::vector<std::shared_ptr<mt::MapCollider>> mt::MapCollider::raw_list;
|
||||||
std::map<std::string, mt::MapCollider*> mt::MapCollider::name_hash;
|
std::map<std::string, std::shared_ptr<mt::MapCollider>> mt::MapCollider::name_hash;
|
||||||
|
|
||||||
namespace mt
|
namespace mt
|
||||||
{
|
{
|
||||||
|
|
||||||
MapCollider* MapCollider::GetByName(const std::string& name)
|
std::shared_ptr<MapCollider> MapCollider::GetByName(const std::string& name)
|
||||||
{
|
{
|
||||||
auto itr = name_hash.find(name);
|
auto itr = name_hash.find(name);
|
||||||
return itr != name_hash.end() ? itr->second : nullptr;
|
return itr != name_hash.end() ? itr->second : nullptr;
|
||||||
@ -32,7 +32,7 @@ namespace mt
|
|||||||
"main3d_map.colliders.json"
|
"main3d_map.colliders.json"
|
||||||
};
|
};
|
||||||
for (auto& filename : files) {
|
for (auto& filename : files) {
|
||||||
MapCollider* p = new MapCollider();
|
std::shared_ptr<MapCollider> p = std::make_shared<MapCollider>();
|
||||||
p->Load(filename);
|
p->Load(filename);
|
||||||
p->LoadTerrain("map4_terrain.bin");
|
p->LoadTerrain("map4_terrain.bin");
|
||||||
raw_list.push_back(p);
|
raw_list.push_back(p);
|
||||||
@ -47,7 +47,7 @@ namespace mt
|
|||||||
auto xobj_nodes = xobj_root.At("nodes");
|
auto xobj_nodes = xobj_root.At("nodes");
|
||||||
for (int i = 0; i < xobj_nodes->Size(); ++i) {
|
for (int i = 0; i < xobj_nodes->Size(); ++i) {
|
||||||
auto xobj_node = xobj_nodes->At(i);
|
auto xobj_node = xobj_nodes->At(i);
|
||||||
mc::ColliderNode* node = new mc::ColliderNode();
|
std::shared_ptr<mc::ColliderNode> node = std::make_shared<mc::ColliderNode>();
|
||||||
node->Read(xobj_node);
|
node->Read(xobj_node);
|
||||||
if (nodes_.find(node->name) != nodes_.end()) {
|
if (nodes_.find(node->name) != nodes_.end()) {
|
||||||
abort();
|
abort();
|
||||||
@ -80,7 +80,7 @@ namespace mt
|
|||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
const std::string terrain_name = "_terrain_";
|
const std::string terrain_name = "_terrain_";
|
||||||
mc::ColliderNode* node = new mc::ColliderNode();
|
std::shared_ptr<mc::ColliderNode> node = std::make_shared<mc::ColliderNode>();
|
||||||
node->name = terrain_name;
|
node->name = terrain_name;
|
||||||
if (nodes_.find(node->name) != nodes_.end()) {
|
if (nodes_.find(node->name) != nodes_.end()) {
|
||||||
abort();
|
abort();
|
||||||
@ -127,7 +127,7 @@ namespace mt
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
mc::ColliderNode* MapCollider::GetNode(const std::string& name)
|
std::shared_ptr<mc::ColliderNode> MapCollider::GetNode(const std::string& name)
|
||||||
{
|
{
|
||||||
auto itr = nodes_.find(name);
|
auto itr = nodes_.find(name);
|
||||||
return itr != nodes_.end() ? itr->second : nullptr;
|
return itr != nodes_.end() ? itr->second : nullptr;
|
||||||
|
@ -13,12 +13,12 @@ namespace mt
|
|||||||
class MapCollider
|
class MapCollider
|
||||||
{
|
{
|
||||||
protected:
|
protected:
|
||||||
static std::vector<MapCollider*> raw_list;
|
static std::vector<std::shared_ptr<MapCollider>> raw_list;
|
||||||
static std::map<std::string, MapCollider*> name_hash;
|
static std::map<std::string, std::shared_ptr<MapCollider>> name_hash;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
static MapCollider* GetByName(const std::string& name);
|
static std::shared_ptr<MapCollider> GetByName(const std::string& name);
|
||||||
static void StaticPostInit();
|
static void StaticPostInit();
|
||||||
|
|
||||||
static void LoadAll();
|
static void LoadAll();
|
||||||
@ -28,11 +28,11 @@ namespace mt
|
|||||||
void Load(const std::string& filename);
|
void Load(const std::string& filename);
|
||||||
void LoadTerrain(const std::string& filename);
|
void LoadTerrain(const std::string& filename);
|
||||||
void SaveToObjFile(const std::string& filename, const navmesh::vertex& vert_pb);
|
void SaveToObjFile(const std::string& filename, const navmesh::vertex& vert_pb);
|
||||||
mc::ColliderNode* GetNode(const std::string& name);
|
std::shared_ptr<mc::ColliderNode> GetNode(const std::string& name);
|
||||||
std::map<std::string, mc::ColliderNode*>& GetNodes() { return nodes_; };
|
std::map<std::string, std::shared_ptr<mc::ColliderNode>>& GetNodes() { return nodes_; };
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::map<std::string, mc::ColliderNode*> nodes_;
|
std::map<std::string, std::shared_ptr<mc::ColliderNode>> nodes_;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user