Recast: move file types to main header

Need to be available to everything.
This commit is contained in:
Amos 2024-07-21 21:46:22 +02:00
parent b56649facb
commit 79cbf2e1dd
6 changed files with 38 additions and 40 deletions

View File

@ -38,7 +38,6 @@ add_sources( SOURCE_GROUP "IO"
add_sources( SOURCE_GROUP "IO/Include"
"include/Filelist.h"
"include/FileTypes.h"
"include/MeshLoaderBsp.h"
"include/MeshLoaderObj.h"
"include/MeshLoaderPly.h"

View File

@ -25,7 +25,6 @@
#include "DetourCrowd/Include/DetourCrowd.h"
#include "DebugUtils/Include/RecastDebugDraw.h"
#include "DebugUtils/Include/DetourDebugDraw.h"
#include "NavEditor/Include/FileTypes.h"
#include "NavEditor/Include/GameUtils.h"
#include "NavEditor/Include/InputGeom.h"
#include "NavEditor/Include/Editor.h"
@ -554,19 +553,19 @@ dtNavMesh* Editor::loadAll(std::string path)
return 0;
// Read header.
NavMeshSetHeader header;
size_t readLen = fread(&header, sizeof(NavMeshSetHeader), 1, fp);
dtNavMeshSetHeader header;
size_t readLen = fread(&header, sizeof(dtNavMeshSetHeader), 1, fp);
if (readLen != 1)
{
fclose(fp);
return 0;
}
if (header.magic != NAVMESHSET_MAGIC) // todo(amos) check for tool mode since tilecache uses different constants!
if (header.magic != DT_NAVMESH_SET_MAGIC) // todo(amos) check for tool mode since tilecache uses different constants!
{
fclose(fp);
return 0;
}
if (header.version != NAVMESHSET_VERSION) // todo(amos) check for tool mode since tilecache uses different constants!
if (header.version != DT_NAVMESH_SET_VERSION) // todo(amos) check for tool mode since tilecache uses different constants!
{
fclose(fp);
return 0;
@ -590,7 +589,7 @@ dtNavMesh* Editor::loadAll(std::string path)
// Read tiles.
for (int i = 0; i < header.numTiles; ++i)
{
NavMeshTileHeader tileHeader;
dtNavMeshTileHeader tileHeader;
readLen = fread(&tileHeader, sizeof(tileHeader), 1, fp);
if (readLen != 1)
{
@ -664,9 +663,9 @@ void Editor::saveAll(std::string path, const dtNavMesh* mesh)
return;
// Store header.
NavMeshSetHeader header;
header.magic = NAVMESHSET_MAGIC;
header.version = NAVMESHSET_VERSION;
dtNavMeshSetHeader header;
header.magic = DT_NAVMESH_SET_MAGIC;
header.version = DT_NAVMESH_SET_VERSION;
header.numTiles = 0;
for (int i = 0; i < mesh->getMaxTiles(); ++i)
@ -681,7 +680,7 @@ void Editor::saveAll(std::string path, const dtNavMesh* mesh)
const dtNavMeshParams* params = mesh->getParams();
memcpy(&header.params, params, sizeof(dtNavMeshParams));
fwrite(&header, sizeof(NavMeshSetHeader), 1, fp);
fwrite(&header, sizeof(dtNavMeshSetHeader), 1, fp);
// Store tiles.
for (int i = 0; i < mesh->getMaxTiles(); ++i)
@ -690,7 +689,7 @@ void Editor::saveAll(std::string path, const dtNavMesh* mesh)
if (!tile || !tile->header || !tile->dataSize)
continue;
NavMeshTileHeader tileHeader;
dtNavMeshTileHeader tileHeader;
tileHeader.tileRef = mesh->getTileRef(tile);
tileHeader.dataSize = tile->dataSize;

View File

@ -17,7 +17,6 @@
//
#include "NavEditor/include/GameUtils.h"
#include "NavEditor/include/FileTypes.h"
void coordGameSwap(float* c)
{
@ -39,11 +38,11 @@ void coordShortGameUnswap(unsigned short* c)
c[2] = std::numeric_limits<unsigned short>::max() - c[2];
std::swap(c[1], c[2]);
}
void patchHeaderGame(NavMeshSetHeader& h)
void patchHeaderGame(dtNavMeshSetHeader& h)
{
coordGameSwap(h.params.orig);
}
void unpatchHeaderGame(NavMeshSetHeader& h)
void unpatchHeaderGame(dtNavMeshSetHeader& h)
{
coordGameUnswap(h.params.orig);
}

View File

@ -1,22 +0,0 @@
#ifndef FILETYPES_H
#define FILETYPES_H
#include "Detour/Include/DetourNavMesh.h"
static const int NAVMESHSET_MAGIC = 'M' << 24 | 'S' << 16 | 'E' << 8 | 'T'; //'MSET';
static const int NAVMESHSET_VERSION = 8;
struct NavMeshSetHeader
{
int magic;
int version;
int numTiles;
dtNavMeshParams params;
};
struct NavMeshTileHeader
{
dtTileRef tileRef;
int dataSize;
};
#endif // FILETYPES_H

View File

@ -1,6 +1,6 @@
#ifndef GAMEUTILS_H
#define GAMEUTILS_H
#include "NavEditor/Include/FileTypes.h"
#include "Detour/Include/DetourNavMesh.h"
void coordGameSwap(float* c);
void coordGameUnswap(float* c);
@ -8,8 +8,8 @@ void coordGameUnswap(float* c);
void coordShortGameSwap(unsigned short* c);
void coordShortGameUnswap(unsigned short* c);
void patchHeaderGame(NavMeshSetHeader& h);
void unpatchHeaderGame(NavMeshSetHeader& h);
void patchHeaderGame(dtNavMeshSetHeader& h);
void unpatchHeaderGame(dtNavMeshSetHeader& h);
void patchTileGame(dtMeshTile* t);
void unpatchTileGame(dtMeshTile* t);

View File

@ -22,6 +22,11 @@
#include "Shared/Include/SharedAlloc.h"
#include "Detour/Include/DetourStatus.h"
// NOTE: these are defines as we need to be able to switch between code that is
// dedicated for each version, during compile time.
#define DT_NAVMESH_SET_VERSION 8 // Public versions: 5,7,8,9.
#define DT_NAVMESH_SET_MAGIC ('M'<<24 | 'S'<<16 | 'E'<<8 | 'T')
// Undefine (or define in a build config) the following line to use 64bit polyref.
// Generally not needed, useful for very large worlds.
// Note: tiles build using 32bit refs are not compatible with 64bit refs!
@ -846,6 +851,24 @@ int calcTraversalTableCellIndex(const int numPolyGroups,
/// @ingroup detour
int calcTraversalTableSize(const int numPolyGroups);
/// Defines a navigation mesh tile data block.
/// @ingroup detour
struct dtNavMeshTileHeader
{
dtTileRef tileRef; ///< The tile reference for this tile.
int dataSize; ///< The total size of this tile.
};
/// Defines a navigation mesh set data block.
/// @ingroup detour
struct dtNavMeshSetHeader
{
int magic; ///< Set magic number. (Used to identify the data format.)
int version; ///< Set data format version number.
int numTiles; ///< The total number of tiles in this set.
dtNavMeshParams params; ///< The initialization parameters for this set.
};
/// Allocates a navigation mesh object using the Detour allocator.
/// @return A navigation mesh that is ready for initialization, or null on failure.
/// @ingroup detour