2019-11-23 20:27:39 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2015-2016 Chukong Technologies Inc.
|
|
|
|
Copyright (c) 2017-2018 Xiamen Yaji Software Co., Ltd.
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
http://www.cocos2d-x.org
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
2021-12-25 10:04:45 +08:00
|
|
|
|
2019-11-23 20:27:39 +08:00
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#ifndef __CCNAV_MESH_TOOL_H__
|
|
|
|
#define __CCNAV_MESH_TOOL_H__
|
|
|
|
|
|
|
|
#include "base/ccConfig.h"
|
|
|
|
#if CC_USE_NAVMESH
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
# include "platform/CCPlatformMacros.h"
|
|
|
|
# include "math/CCMath.h"
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
# include "recast/DetourCommon.h"
|
|
|
|
# include "recast/DetourNavMesh.h"
|
|
|
|
# include "recast/DetourNavMeshQuery.h"
|
|
|
|
# include "recast/DetourTileCache.h"
|
|
|
|
# include "recast/DetourTileCacheBuilder.h"
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @addtogroup 3d
|
|
|
|
* @{
|
|
|
|
*/
|
|
|
|
|
|
|
|
struct LinearAllocator : public dtTileCacheAlloc
|
|
|
|
{
|
|
|
|
unsigned char* buffer;
|
|
|
|
int capacity;
|
|
|
|
int top;
|
|
|
|
int high;
|
|
|
|
|
|
|
|
LinearAllocator(const int cap);
|
|
|
|
|
|
|
|
~LinearAllocator();
|
|
|
|
|
|
|
|
void resize(const int cap);
|
|
|
|
|
|
|
|
virtual void reset();
|
|
|
|
|
|
|
|
virtual void* alloc(const int size);
|
|
|
|
|
|
|
|
virtual void free(void* /*ptr*/);
|
|
|
|
};
|
|
|
|
|
2021-05-05 19:49:30 +08:00
|
|
|
struct LZ4Compressor : public dtTileCacheCompressor
|
2019-11-23 20:27:39 +08:00
|
|
|
{
|
|
|
|
virtual int maxCompressedSize(const int bufferSize);
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
virtual dtStatus compress(const unsigned char* buffer,
|
|
|
|
const int bufferSize,
|
|
|
|
unsigned char* compressed,
|
|
|
|
const int /*maxCompressedSize*/,
|
|
|
|
int* compressedSize);
|
|
|
|
|
|
|
|
virtual dtStatus decompress(const unsigned char* compressed,
|
|
|
|
const int compressedSize,
|
|
|
|
unsigned char* buffer,
|
|
|
|
const int maxBufferSize,
|
|
|
|
int* bufferSize);
|
2019-11-23 20:27:39 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
struct GeomData
|
|
|
|
{
|
|
|
|
static const int MAX_OFFMESH_CONNECTIONS = 256;
|
|
|
|
float offMeshConVerts[MAX_OFFMESH_CONNECTIONS * 3 * 2];
|
|
|
|
float offMeshConRads[MAX_OFFMESH_CONNECTIONS];
|
|
|
|
unsigned char offMeshConDirs[MAX_OFFMESH_CONNECTIONS];
|
|
|
|
unsigned char offMeshConAreas[MAX_OFFMESH_CONNECTIONS];
|
|
|
|
unsigned short offMeshConFlags[MAX_OFFMESH_CONNECTIONS];
|
|
|
|
unsigned int offMeshConId[MAX_OFFMESH_CONNECTIONS];
|
|
|
|
int offMeshConCount;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct MeshProcess : public dtTileCacheMeshProcess
|
|
|
|
{
|
2021-12-25 10:04:45 +08:00
|
|
|
const GeomData* data;
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
MeshProcess(const GeomData* geom);
|
2019-11-23 20:27:39 +08:00
|
|
|
virtual ~MeshProcess();
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
// void init(InputGeom* geom)
|
2019-11-23 20:27:39 +08:00
|
|
|
//{
|
|
|
|
// m_geom = geom;
|
2021-12-25 10:04:45 +08:00
|
|
|
// }
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
virtual void process(struct dtNavMeshCreateParams* params,
|
2021-12-25 10:04:45 +08:00
|
|
|
unsigned char* polyAreas,
|
|
|
|
unsigned short* polyFlags) override;
|
2019-11-23 20:27:39 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
bool inRange(const float* v1, const float* v2, const float r, const float h);
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
int fixupCorridor(dtPolyRef* path, const int npath, const int maxPath, const dtPolyRef* visited, const int nvisited);
|
2019-11-23 20:27:39 +08:00
|
|
|
|
|
|
|
// This function checks if the path has a small U-turn, that is,
|
|
|
|
// a polygon further in the path is adjacent to the first polygon
|
|
|
|
// in the path. If that happens, a shortcut is taken.
|
|
|
|
// This can happen if the target (T) location is at tile boundary,
|
|
|
|
// and we're (S) approaching it parallel to the tile edge.
|
2021-12-25 10:04:45 +08:00
|
|
|
// The choice at the vertex can be arbitrary,
|
2019-11-23 20:27:39 +08:00
|
|
|
// +---+---+
|
|
|
|
// |:::|:::|
|
|
|
|
// +-S-+-T-+
|
|
|
|
// |:::| | <-- the step can end up in here, resulting U-turn path.
|
|
|
|
// +---+---+
|
|
|
|
int fixupShortcuts(dtPolyRef* path, int npath, dtNavMeshQuery* navQuery);
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
bool getSteerTarget(dtNavMeshQuery* navQuery,
|
|
|
|
const float* startPos,
|
|
|
|
const float* endPos,
|
|
|
|
const float minTargetDist,
|
|
|
|
const dtPolyRef* path,
|
|
|
|
const int pathSize,
|
|
|
|
float* steerPos,
|
|
|
|
unsigned char& steerPosFlag,
|
|
|
|
dtPolyRef& steerPosRef,
|
|
|
|
float* outPoints = nullptr,
|
|
|
|
int* outPointCount = nullptr);
|
2019-11-23 20:27:39 +08:00
|
|
|
/** @} */
|
|
|
|
|
|
|
|
NS_CC_END
|
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
#endif // CC_USE_NAVMESH
|
2019-11-23 20:27:39 +08:00
|
|
|
|
2021-12-25 10:04:45 +08:00
|
|
|
#endif // __CCNAV_MESH_H__
|