1
This commit is contained in:
parent
eea6cbdeec
commit
68b35769ac
@ -6,7 +6,7 @@
|
||||
#include "player.h"
|
||||
#include "app.h"
|
||||
|
||||
static bool EnableDebug()
|
||||
bool DebugCmd::Enable()
|
||||
{
|
||||
return App::Instance()->instance_id == 6;
|
||||
}
|
||||
@ -17,7 +17,7 @@ void DebugCmd::CreateSphere(Creature* c,
|
||||
int uniid)
|
||||
|
||||
{
|
||||
if (c->IsPlayer() && EnableDebug()) {
|
||||
if (c->IsPlayer() && Enable()) {
|
||||
cs::SMDebugCmd msg;
|
||||
msg.set_cmd("create_sphere");
|
||||
msg.add_params(pos.x);
|
||||
@ -40,7 +40,7 @@ void DebugCmd::CreateCube(Creature* c,
|
||||
const glm::quat& rotation,
|
||||
int uniid)
|
||||
{
|
||||
if (c->IsPlayer() && EnableDebug()) {
|
||||
if (c->IsPlayer() && Enable()) {
|
||||
cs::SMDebugCmd msg;
|
||||
msg.set_cmd("create_cube");
|
||||
msg.add_params(pos.x);
|
||||
@ -64,7 +64,7 @@ void DebugCmd::CreateCube(Creature* c,
|
||||
|
||||
void DebugCmd::DestoryGameObject(Creature* c, int uniid)
|
||||
{
|
||||
if (c->IsPlayer() && EnableDebug()) {
|
||||
if (c->IsPlayer() && Enable()) {
|
||||
cs::SMDebugCmd msg;
|
||||
msg.set_cmd("destory_gameobject");
|
||||
|
||||
|
@ -10,6 +10,8 @@ class DebugCmd
|
||||
{
|
||||
public:
|
||||
|
||||
static bool Enable();
|
||||
|
||||
static void CreateSphere(Creature* c,
|
||||
const glm::vec3& pos,
|
||||
const glm::vec3& scale,
|
||||
|
@ -16,10 +16,10 @@ namespace mc
|
||||
|
||||
static void Quat_Read(glm::quat& v, std::shared_ptr<a8::XObject> xobj)
|
||||
{
|
||||
v.x = xobj->At("x")->AsXValue().GetDouble() * MAP_SCALE;
|
||||
v.y = xobj->At("y")->AsXValue().GetDouble() * MAP_SCALE;
|
||||
v.z = xobj->At("z")->AsXValue().GetDouble() * MAP_SCALE;
|
||||
v.w = xobj->At("w")->AsXValue().GetDouble() * MAP_SCALE;
|
||||
v.x = xobj->At("x")->AsXValue().GetDouble();
|
||||
v.y = xobj->At("y")->AsXValue().GetDouble();
|
||||
v.z = xobj->At("z")->AsXValue().GetDouble();
|
||||
v.w = xobj->At("w")->AsXValue().GetDouble();
|
||||
}
|
||||
|
||||
static void Bounds_Read(Bounds& v, std::shared_ptr<a8::XObject> xobj)
|
||||
|
@ -20,7 +20,6 @@ namespace mc
|
||||
kCA_Roof = 2,//屋顶
|
||||
kCA_FloororRoof = 3,//屋顶+上层地板
|
||||
kCA_Stairs = 4,//楼梯
|
||||
kCA_NoJump = 4,//不可跳伞
|
||||
kCA_Window = 9,//窗,主要为了射击穿透
|
||||
kCA_Other = 10,//其他,装饰品
|
||||
};
|
||||
|
@ -26,8 +26,6 @@
|
||||
|
||||
#include "navmesh.pb.h"
|
||||
|
||||
const int MAP_HEIGHT_GRID_SIZE = 64;
|
||||
|
||||
static const int NAV_ERROR_NEARESTPOLY = -2;
|
||||
|
||||
static const int NAV_ERROR = -1;
|
||||
@ -170,6 +168,7 @@ void MapInstance::Init()
|
||||
navmesh_query_ = new dtNavMeshQuery();
|
||||
navmesh_query_->init(navmesh_, 1024);
|
||||
MarkMapAreaPolys();
|
||||
LoadHouse();
|
||||
}
|
||||
|
||||
void MapInstance::UnInit()
|
||||
@ -722,3 +721,80 @@ void MapInstance::CheckTerrain(Creature* c, int same_poly_flags, const std::vect
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void MapInstance::TraverseHouseList(std::function<void (HouseInfo*)> func)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
bool MapInstance::PtInHouse(const glm::vec3& pt, glm::vec3& nearest_pt)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void MapInstance::LoadHouse()
|
||||
{
|
||||
if (GetMapMeta()->collider_info) {
|
||||
mc::ColliderNode* building_root = GetMapMeta()->collider_info->GetNode("building");
|
||||
if (building_root) {
|
||||
for (auto& pair : building_root->childs) {
|
||||
auto node = pair.second;
|
||||
std::vector<glm::vec3> points;
|
||||
{
|
||||
glm::vec3 center = node->bounds.center;
|
||||
glm::vec3 size = node->bounds.size;
|
||||
points.push_back
|
||||
(glm::vec3
|
||||
(
|
||||
center.x - size.x / 2,
|
||||
center.y - size.y / 2,
|
||||
center.z - size.z / 2
|
||||
)
|
||||
);
|
||||
points.push_back
|
||||
(glm::vec3
|
||||
(
|
||||
center.x + size.x / 2,
|
||||
center.y - size.y / 2,
|
||||
center.z - size.z / 2
|
||||
)
|
||||
);
|
||||
points.push_back
|
||||
(glm::vec3
|
||||
(
|
||||
center.x + size.x / 2,
|
||||
center.y - size.y / 2,
|
||||
center.z + size.z / 2
|
||||
)
|
||||
);
|
||||
points.push_back
|
||||
(glm::vec3
|
||||
(
|
||||
center.x - size.x / 2,
|
||||
center.y - size.y / 2,
|
||||
center.z + size.z / 2
|
||||
)
|
||||
);
|
||||
}
|
||||
{
|
||||
std::string data = "old: " + node->name + " ";
|
||||
for (auto& point : points) {
|
||||
data += a8::Format("%f,%f,%f ", {point.x, point.y, point.z});
|
||||
}
|
||||
for (auto& point : points) {
|
||||
point = node->transform.local_rotation * point;
|
||||
}
|
||||
data += "\nnew:";
|
||||
for (auto& point : points) {
|
||||
data += a8::Format("%f,%f,%f ", {point.x, point.y, point.z});
|
||||
}
|
||||
a8::XPrintf("%s\n", {data});
|
||||
}
|
||||
|
||||
HouseInfo p;
|
||||
p.node = node;
|
||||
houses_.push_back(p);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -5,6 +5,17 @@
|
||||
|
||||
const int MAX_POLYS = 256;
|
||||
|
||||
namespace mc
|
||||
{
|
||||
class ColliderNode;
|
||||
};
|
||||
|
||||
struct HouseInfo
|
||||
{
|
||||
mc::ColliderNode* node = nullptr;
|
||||
std::vector<float> verts;
|
||||
};
|
||||
|
||||
class Entity;
|
||||
class Obstacle;
|
||||
class MapService;
|
||||
@ -44,9 +55,12 @@ class MapInstance : public std::enable_shared_from_this<MapInstance>
|
||||
void UnScale(glm::vec3& v);
|
||||
glm::vec3 UnScaleEx(const glm::vec3& v);
|
||||
void CheckTerrain(Creature* c, int same_poly_flags, const std::vector<dtPolyRef>& spec_polys);
|
||||
void TraverseHouseList(std::function<void (HouseInfo*)> func);
|
||||
bool PtInHouse(const glm::vec3& pt, glm::vec3& nearest_pt);
|
||||
|
||||
private:
|
||||
void CreateThings();
|
||||
void LoadHouse();
|
||||
int AllocUniid();
|
||||
void MarkMapAreaPolys();
|
||||
|
||||
@ -63,6 +77,8 @@ class MapInstance : public std::enable_shared_from_this<MapInstance>
|
||||
|
||||
std::vector<int> poly_ext_datas_;
|
||||
|
||||
std::list<HouseInfo> houses_;
|
||||
|
||||
std::string map_tpl_name_;
|
||||
const mt::Map* map_meta_ = nullptr;
|
||||
MapService* map_service_ = nullptr;
|
||||
|
@ -1,6 +1,7 @@
|
||||
#include "precompile.h"
|
||||
|
||||
#include "mt/Map.h"
|
||||
#include "mt/MapCollider.h"
|
||||
#include "mt/SafeArea.h"
|
||||
|
||||
IMPL_TABLE(mt::Map)
|
||||
@ -117,6 +118,7 @@ namespace mt
|
||||
if (!IsPveMap() && player() < 10) {
|
||||
A8_ABORT();
|
||||
}
|
||||
collider_info = MapCollider::GetByName(map_collider());
|
||||
}
|
||||
|
||||
void Map::Init2()
|
||||
|
@ -5,6 +5,7 @@
|
||||
|
||||
namespace mt
|
||||
{
|
||||
class MapCollider;
|
||||
|
||||
DECLARE_ID_TABLE(Map, mtb::Map,
|
||||
"map@map.json",
|
||||
@ -22,6 +23,7 @@ namespace mt
|
||||
glm::vec3 first_safearea_center_;
|
||||
std::map<int, int> car_num_limit_;
|
||||
std::vector<int> safearea_list;
|
||||
MapCollider* collider_info = nullptr;
|
||||
|
||||
std::string RandTemplate() const;
|
||||
int GetCarLimit(int car_id) const;
|
||||
|
@ -51,4 +51,10 @@ namespace mt
|
||||
}
|
||||
}
|
||||
|
||||
mc::ColliderNode* MapCollider::GetNode(const std::string& name)
|
||||
{
|
||||
auto itr = nodes_.find(name);
|
||||
return itr != nodes_.end() ? itr->second : nullptr;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -21,6 +21,7 @@ namespace mt
|
||||
public:
|
||||
|
||||
void Load(const std::string& filename);
|
||||
mc::ColliderNode* GetNode(const std::string& name);
|
||||
|
||||
private:
|
||||
std::map<std::string, mc::ColliderNode*> nodes_;
|
||||
|
@ -28,6 +28,7 @@ namespace mtb
|
||||
const std::string airraids() const { return airraids_; };
|
||||
const std::string car_num_limit() const { return car_num_limit_; };
|
||||
float scale() const { return scale_; };
|
||||
const std::string map_collider() const { return map_collider_; };
|
||||
|
||||
bool has_map_id() const { return __flags__.test(0);};
|
||||
bool has_template_list() const { return __flags__.test(1);};
|
||||
@ -47,6 +48,7 @@ namespace mtb
|
||||
bool has_airraids() const { return __flags__.test(15);};
|
||||
bool has_car_num_limit() const { return __flags__.test(16);};
|
||||
bool has_scale() const { return __flags__.test(17);};
|
||||
bool has_map_collider() const { return __flags__.test(18);};
|
||||
|
||||
protected:
|
||||
|
||||
@ -68,9 +70,10 @@ namespace mtb
|
||||
std::string airraids_;
|
||||
std::string car_num_limit_;
|
||||
float scale_ = 0.0f;
|
||||
std::string map_collider_;
|
||||
|
||||
public:
|
||||
std::bitset<18> __flags__;
|
||||
std::bitset<19> __flags__;
|
||||
};
|
||||
|
||||
};
|
||||
|
@ -64,7 +64,7 @@ namespace mtb
|
||||
{
|
||||
a8::reflect::Class* meta_class = nullptr;
|
||||
if (!meta_class) {
|
||||
meta_class = new a8::reflect::Class("Map", 18, 0);
|
||||
meta_class = new a8::reflect::Class("Map", 19, 0);
|
||||
meta_class->SetSimpleField(0, "map_id", a8::reflect::ET_INT32, my_offsetof2(Map, map_id_));
|
||||
meta_class->SetSimpleField(1, "template_list", a8::reflect::ET_STRING, my_offsetof2(Map, template_list_));
|
||||
meta_class->SetSimpleField(2, "map_name", a8::reflect::ET_STRING, my_offsetof2(Map, map_name_));
|
||||
@ -83,6 +83,7 @@ namespace mtb
|
||||
meta_class->SetSimpleField(15, "airraids", a8::reflect::ET_STRING, my_offsetof2(Map, airraids_));
|
||||
meta_class->SetSimpleField(16, "car_num_limit", a8::reflect::ET_STRING, my_offsetof2(Map, car_num_limit_));
|
||||
meta_class->SetSimpleField(17, "scale", a8::reflect::ET_FLOAT, my_offsetof2(Map, scale_));
|
||||
meta_class->SetSimpleField(18, "map_collider", a8::reflect::ET_STRING, my_offsetof2(Map, map_collider_));
|
||||
}
|
||||
return meta_class;
|
||||
}
|
||||
|
@ -33,6 +33,7 @@ message Map
|
||||
optional string airraids = 16;
|
||||
optional string car_num_limit = 17;
|
||||
optional float scale = 18;
|
||||
optional string map_collider = 19;
|
||||
}
|
||||
|
||||
message MapArea
|
||||
|
Loading…
x
Reference in New Issue
Block a user