1
This commit is contained in:
parent
d5abdfbc95
commit
ab8e7eee21
@ -45,6 +45,7 @@ class Entity
|
|||||||
float GetY() { return pos_.y; }
|
float GetY() { return pos_.y; }
|
||||||
void SetX(float x) { pos_.x = x; }
|
void SetX(float x) { pos_.x = x; }
|
||||||
void SetY(float y) { pos_.y = y; }
|
void SetY(float y) { pos_.y = y; }
|
||||||
|
std::list<ColliderComponent*>* GetColliders() { return &colliders_; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
bool IsClientCached(Human* hum);
|
bool IsClientCached(Human* hum);
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include "metamgr.h"
|
#include "metamgr.h"
|
||||||
#include "room.h"
|
#include "room.h"
|
||||||
#include "entityfactory.h"
|
#include "entityfactory.h"
|
||||||
|
#include "collider.h"
|
||||||
|
|
||||||
#ifdef FIND_PATH_TEST
|
#ifdef FIND_PATH_TEST
|
||||||
const int MAP_GRID_WIDTH = 40;
|
const int MAP_GRID_WIDTH = 40;
|
||||||
@ -57,6 +58,9 @@ void MapInstance::Init()
|
|||||||
if (current_uniid_ >= FIXED_OBJECT_MAXID) {
|
if (current_uniid_ >= FIXED_OBJECT_MAXID) {
|
||||||
abort();
|
abort();
|
||||||
}
|
}
|
||||||
|
#ifdef DEBUG
|
||||||
|
OutputObjFile();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void MapInstance::UnInit()
|
void MapInstance::UnInit()
|
||||||
@ -272,3 +276,60 @@ int MapInstance::AllocUniid()
|
|||||||
}
|
}
|
||||||
return current_uniid_;
|
return current_uniid_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void MapInstance::OutputObjFile()
|
||||||
|
{
|
||||||
|
std::vector<a8::Vec2> vertexs;
|
||||||
|
std::vector<std::tuple<int, int, int, int>> faces;
|
||||||
|
vertexs.reserve(10000);
|
||||||
|
for (auto& pair : uniid_hash_) {
|
||||||
|
for (ColliderComponent* collider : *pair.second->GetColliders()) {
|
||||||
|
if (collider->type == CT_Aabb) {
|
||||||
|
AabbCollider* aabb_box = (AabbCollider*)collider;
|
||||||
|
{
|
||||||
|
a8::Vec2 vert = collider->owner->GetPos() + aabb_box->_min;
|
||||||
|
vert.x = vert.x - map_meta_->i->map_width() / 2.0f;
|
||||||
|
vert.y = vert.y - map_meta_->i->map_height() / 2.0f;
|
||||||
|
|
||||||
|
vertexs.push_back(vert);
|
||||||
|
vert.y += aabb_box->_max.y - aabb_box->_min.y;
|
||||||
|
vertexs.push_back(vert);
|
||||||
|
vert.x += aabb_box->_max.x - aabb_box->_min.x;
|
||||||
|
vertexs.push_back(vert);
|
||||||
|
vert.y -= aabb_box->_max.y - aabb_box->_min.y;
|
||||||
|
vertexs.push_back(vert);
|
||||||
|
}
|
||||||
|
faces.push_back
|
||||||
|
(std::make_tuple
|
||||||
|
(
|
||||||
|
vertexs.size() - 1,
|
||||||
|
vertexs.size() - 2,
|
||||||
|
vertexs.size() - 3,
|
||||||
|
vertexs.size() - 4
|
||||||
|
));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
{
|
||||||
|
std::string filename = a8::Format("%s.obj", {map_tpl_name_});
|
||||||
|
FILE* fp = fopen(filename.c_str(), "wb");
|
||||||
|
for (auto& vert : vertexs) {
|
||||||
|
std::string data = a8::Format("v %f %f %f\r\n",
|
||||||
|
{
|
||||||
|
vert.x,
|
||||||
|
vert.y,
|
||||||
|
0
|
||||||
|
});
|
||||||
|
fwrite(data.data(), 1, data.size(), fp);
|
||||||
|
}
|
||||||
|
for (auto& tuple : faces) {
|
||||||
|
std::string data = a8::Format("f %d %d %d %d\r\n",
|
||||||
|
{
|
||||||
|
std::get<0>(tuple),
|
||||||
|
std::get<1>(tuple),
|
||||||
|
});
|
||||||
|
fwrite(data.data(), 1, data.size(), fp);
|
||||||
|
}
|
||||||
|
fclose(fp);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
@ -31,6 +31,7 @@ class MapInstance
|
|||||||
std::function<void (Obstacle*)> on_precreate);
|
std::function<void (Obstacle*)> on_precreate);
|
||||||
Entity* GetEntityByUniId(int uniid);
|
Entity* GetEntityByUniId(int uniid);
|
||||||
int AllocUniid();
|
int AllocUniid();
|
||||||
|
void OutputObjFile();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int current_uniid_ = 0;
|
int current_uniid_ = 0;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user