This commit is contained in:
aozhiwei 2020-09-02 13:50:42 +08:00
parent d116fc41df
commit 3a1f732d38
5 changed files with 64 additions and 4 deletions

View File

@ -532,3 +532,4 @@ void MapService::UpdateNavmesh(FindPathStatus* find_status)
find_status->navmesh_search_state = kNavMesh_SearchFailed; find_status->navmesh_search_state = kNavMesh_SearchFailed;
} }
} }

View File

@ -2,6 +2,8 @@
#include <string.h> #include <string.h>
#include <a8/udplog.h>
#include "navmeshbuilder.h" #include "navmeshbuilder.h"
#include "mapinstance.h" #include "mapinstance.h"
#include "collider.h" #include "collider.h"
@ -40,6 +42,7 @@ void NavMeshBuilder::Build(MapInstance* map_instance)
BuildMapObstalce(builder_params); BuildMapObstalce(builder_params);
#endif #endif
map_instance->navmesh_ = builder_params.navmesh; map_instance->navmesh_ = builder_params.navmesh;
Save(builder_params);
} }
void NavMeshBuilder::InitBuilderParams(BuilderParams& builder_params) void NavMeshBuilder::InitBuilderParams(BuilderParams& builder_params)
@ -465,3 +468,58 @@ void NavMeshBuilder::BuildMapObstalce(BuilderParams& builder_params)
} }
}//end for pair }//end for pair
} }
void NavMeshBuilder::Save(BuilderParams& builder_params)
{
FILE* fp = fopen("map.bin", "wb");
if (!fp) {
abort();
}
static const int TILECACHESET_MAGIC = 'T'<<24 | 'S'<<16 | 'E'<<8 | 'T'; //'TSET';
static const int TILECACHESET_VERSION = 1;
struct TileCacheSetHeader
{
int magic;
int version;
int numTiles;
dtNavMeshParams meshParams;
dtTileCacheParams cacheParams;
};
struct TileCacheTileHeader
{
dtCompressedTileRef tileRef;
int dataSize;
};
TileCacheSetHeader header;
header.magic = TILECACHESET_MAGIC;
header.version = TILECACHESET_VERSION;
header.numTiles = 0;
for (int i = 0; i < builder_params.tile_cache->getTileCount(); ++i) {
const dtCompressedTile* tile = builder_params.tile_cache->getTile(i);
if (!tile || !tile->header || !tile->dataSize) continue;
header.numTiles++;
}
memcpy(&header.cacheParams, builder_params.tile_cache->getParams(), sizeof(dtTileCacheParams));
memcpy(&header.meshParams, builder_params.navmesh->getParams(), sizeof(dtNavMeshParams));
fwrite(&header, sizeof(TileCacheSetHeader), 1, fp);
// Store tiles.
for (int i = 0; i < builder_params.tile_cache->getTileCount(); ++i) {
const dtCompressedTile* tile = builder_params.tile_cache->getTile(i);
if (!tile || !tile->header || !tile->dataSize) continue;
TileCacheTileHeader tileHeader;
tileHeader.tileRef = builder_params.tile_cache->getTileRef(tile);
tileHeader.dataSize = tile->dataSize;
fwrite(&tileHeader, sizeof(tileHeader), 1, fp);
fwrite(tile->data, tile->dataSize, 1, fp);
}
fclose(fp);
a8::UdpLog::Instance()->Debug("Save OK", {});
}

View File

@ -33,4 +33,5 @@ public:
bool CreateTileCache(BuilderParams& builder_params); bool CreateTileCache(BuilderParams& builder_params);
bool CreateNavMesh(BuilderParams& builder_params); bool CreateNavMesh(BuilderParams& builder_params);
void BuildMapObstalce(BuilderParams& builder_params); void BuildMapObstalce(BuilderParams& builder_params);
void Save(BuilderParams& builder_params);
}; };

View File

@ -92,8 +92,8 @@ void NavMeshHelper::OutputObjFile(MapInstance* map_instance)
faces.clear(); faces.clear();
{ {
a8::Vec2 vert; a8::Vec2 vert;
vert.x = 0 - map_instance->map_meta_->i->map_width() / 2.0f; //vert.x = 0 - map_instance->map_meta_->i->map_width() / 2.0f;
vert.y = 0 - map_instance->map_meta_->i->map_height() / 2.0f; //vert.y = 0 - map_instance->map_meta_->i->map_height() / 2.0f;
vertexs.push_back(vert); vertexs.push_back(vert);
vert.y += map_instance->map_meta_->i->map_height(); vert.y += map_instance->map_meta_->i->map_height();
@ -126,7 +126,7 @@ void NavMeshHelper::OutputObjFile(MapInstance* map_instance)
std::string data = a8::Format("v %f %f %f\r\n", std::string data = a8::Format("v %f %f %f\r\n",
{ {
vert.x, vert.x,
-10, 0,
vert.y, vert.y,
}); });
fwrite(data.data(), 1, data.size(), fp); fwrite(data.data(), 1, data.size(), fp);

View File

@ -12,7 +12,7 @@ package cs;
msghead + msgbody msghead + msgbody
msghead: packagelen + msgid + seqid + magiccode + reserved = 2 + 2 + 4 + 2 + 2 = 12 msghead: packagelen + msgid + seqid + magiccode + reserved = 2 + 2 + 4 + 2 + 2 = 12
msgbody protobuf数据 n msgbody protobuf数据
msghead说明 msghead说明
packagelenunsigned short packagelenunsigned short
msgid(unsigned short): id msgid(unsigned short): id