mirror of
https://gitee.com/jisol/jisol-game/
synced 2025-12-31 11:08:09 +00:00
提交Unity 联机Pro
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
<Project Sdk="Microsoft.NET.Sdk">
|
||||
|
||||
<PropertyGroup>
|
||||
<TargetFrameworks>netstandard2.1;net6.0;net7.0;net8.0</TargetFrameworks>
|
||||
<PackageId>DotRecast.Detour.TileCache</PackageId>
|
||||
<PackageReadmeFile>README.md</PackageReadmeFile>
|
||||
<Authors>ikpil</Authors>
|
||||
<Description>DotRecast - a port of Recast Detour, Industry-standard navigation mesh toolset for .NET, C#, Unity3D, games, servers</Description>
|
||||
<RepositoryType>git</RepositoryType>
|
||||
<PackageProjectUrl>https://github.com/ikpil/DotRecast</PackageProjectUrl>
|
||||
<RepositoryUrl>https://github.com/ikpil/DotRecast</RepositoryUrl>
|
||||
<PackageTags>game gamedev ai csharp server unity navigation game-development unity3d pathfinding pathfinder recast detour navmesh crowd-simulation recastnavigation</PackageTags>
|
||||
<PackageReleaseNotes>https://github.com/ikpil/DotRecast/blob/main/CHANGELOG.md</PackageReleaseNotes>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<None Include="../../README.md" Pack="true" PackagePath="\"/>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\DotRecast.Recast\DotRecast.Recast.csproj"/>
|
||||
<ProjectReference Include="..\DotRecast.Detour\DotRecast.Detour.csproj"/>
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 573dcdd1ed014fc68e7debf013f844d0
|
||||
timeCreated: 1715335346
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
|
||||
recast4j copyright (c) 2015-2019 Piotr Piastucki piotr@jtilia.org
|
||||
DotRecast Copyright (c) 2023 Choi Ikpil ikpil@naver.com
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
namespace DotRecast.Detour.TileCache
|
||||
{
|
||||
public class DtCompressedTile
|
||||
{
|
||||
public readonly int index;
|
||||
public int salt; // Counter describing modifications to the tile.
|
||||
public DtTileCacheLayerHeader header;
|
||||
|
||||
public byte[] data;
|
||||
public int compressed; // offset of compressed data
|
||||
public int flags;
|
||||
public DtCompressedTile next;
|
||||
|
||||
public DtCompressedTile(int index)
|
||||
{
|
||||
this.index = index;
|
||||
salt = 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 37a1310e7d78417fa4eaacb43012463a
|
||||
timeCreated: 1715335345
|
||||
@@ -0,0 +1,8 @@
|
||||
namespace DotRecast.Detour.TileCache
|
||||
{
|
||||
/// Flags for addTile
|
||||
public class DtCompressedTileFlags
|
||||
{
|
||||
public const int DT_COMPRESSEDTILE_FREE_DATA = 0x01; //< Navmesh owns the tile memory and should free it. In C#, it is not used.
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7fabfbe05dce4546b4ebac51ad3c571b
|
||||
timeCreated: 1715335346
|
||||
@@ -0,0 +1,14 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace DotRecast.Detour.TileCache
|
||||
{
|
||||
public class DtLayerMonotoneRegion
|
||||
{
|
||||
public const int DT_LAYER_MAX_NEIS = 16;
|
||||
|
||||
public int area;
|
||||
public List<int> neis = new List<int>(DT_LAYER_MAX_NEIS);
|
||||
public int regId;
|
||||
public int areaId;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4c5d34b8cd444d9ba6c14143a8e10406
|
||||
timeCreated: 1715335346
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
|
||||
recast4j copyright (c) 2015-2019 Piotr Piastucki piotr@jtilia.org
|
||||
DotRecast Copyright (c) 2023 Choi Ikpil ikpil@naver.com
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
namespace DotRecast.Detour.TileCache
|
||||
{
|
||||
public readonly struct DtObstacleRequest
|
||||
{
|
||||
public readonly DtObstacleRequestAction action;
|
||||
public readonly long refs;
|
||||
|
||||
public DtObstacleRequest(DtObstacleRequestAction action, long refs)
|
||||
{
|
||||
this.action = action;
|
||||
this.refs = refs;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 82fe7b7aa18d4af297eac88d0f717a7f
|
||||
timeCreated: 1715335345
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
|
||||
recast4j copyright (c) 2015-2019 Piotr Piastucki piotr@jtilia.org
|
||||
DotRecast Copyright (c) 2023 Choi Ikpil ikpil@naver.com
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
namespace DotRecast.Detour.TileCache
|
||||
{
|
||||
public enum DtObstacleRequestAction
|
||||
{
|
||||
REQUEST_ADD,
|
||||
REQUEST_REMOVE
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 3d3ee8ca7f2a4f89b6829c66fa9463af
|
||||
timeCreated: 1715335346
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
|
||||
recast4j copyright (c) 2015-2019 Piotr Piastucki piotr@jtilia.org
|
||||
DotRecast Copyright (c) 2023 Choi Ikpil ikpil@naver.com
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
namespace DotRecast.Detour.TileCache
|
||||
{
|
||||
public enum DtObstacleState
|
||||
{
|
||||
DT_OBSTACLE_EMPTY,
|
||||
DT_OBSTACLE_PROCESSING,
|
||||
DT_OBSTACLE_PROCESSED,
|
||||
DT_OBSTACLE_REMOVING
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 31a0156f8dff4567a88c6ffbae57ac26
|
||||
timeCreated: 1715335345
|
||||
@@ -0,0 +1,29 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace DotRecast.Detour.TileCache
|
||||
{
|
||||
public class DtTempContour
|
||||
{
|
||||
public List<int> verts;
|
||||
public int nverts;
|
||||
public List<int> poly;
|
||||
|
||||
public DtTempContour()
|
||||
{
|
||||
verts = new List<int>();
|
||||
nverts = 0;
|
||||
poly = new List<int>();
|
||||
}
|
||||
|
||||
public int Npoly()
|
||||
{
|
||||
return poly.Count;
|
||||
}
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
nverts = 0;
|
||||
verts.Clear();
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 78dc071c2d62440295d88015cdbef78f
|
||||
timeCreated: 1715335345
|
||||
@@ -0,0 +1,748 @@
|
||||
/*
|
||||
Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
|
||||
recast4j copyright (c) 2015-2019 Piotr Piastucki piotr@jtilia.org
|
||||
DotRecast Copyright (c) 2023 Choi Ikpil ikpil@naver.com
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using DotRecast.Core;
|
||||
using DotRecast.Core.Numerics;
|
||||
using DotRecast.Detour.TileCache.Io;
|
||||
using JNGame.Math;
|
||||
|
||||
namespace DotRecast.Detour.TileCache
|
||||
{
|
||||
public class DtTileCache
|
||||
{
|
||||
private int m_tileLutSize; // < Tile hash lookup size (must be pot).
|
||||
private int m_tileLutMask; // < Tile hash lookup mask.
|
||||
private readonly DtCompressedTile[] m_posLookup; // < Tile hash lookup.
|
||||
|
||||
private DtCompressedTile m_nextFreeTile; // < Freelist of tiles.
|
||||
private readonly DtCompressedTile[] m_tiles; // < List of tiles. // TODO: (PP) replace with list
|
||||
|
||||
private readonly int m_saltBits; // < Number of salt bits in the tile ID.
|
||||
private readonly int m_tileBits; // < Number of tile bits in the tile ID.
|
||||
private readonly DtNavMesh m_navmesh;
|
||||
|
||||
private readonly DtTileCacheParams m_params;
|
||||
private readonly DtTileCacheStorageParams m_storageParams;
|
||||
|
||||
private readonly IRcCompressor m_tcomp;
|
||||
private readonly IDtTileCacheMeshProcess m_tmproc;
|
||||
|
||||
private readonly List<DtTileCacheObstacle> m_obstacles = new List<DtTileCacheObstacle>();
|
||||
private DtTileCacheObstacle m_nextFreeObstacle;
|
||||
|
||||
private readonly List<DtObstacleRequest> m_reqs = new List<DtObstacleRequest>();
|
||||
private readonly List<long> m_update = new List<long>();
|
||||
|
||||
private readonly DtTileCacheBuilder builder = new DtTileCacheBuilder();
|
||||
private readonly DtTileCacheLayerHeaderReader tileReader = new DtTileCacheLayerHeaderReader();
|
||||
|
||||
public DtTileCache(DtTileCacheParams option, DtTileCacheStorageParams storageParams, DtNavMesh navmesh, IRcCompressor tcomp, IDtTileCacheMeshProcess tmprocs)
|
||||
{
|
||||
m_params = option;
|
||||
m_storageParams = storageParams;
|
||||
m_navmesh = navmesh;
|
||||
m_tcomp = tcomp;
|
||||
m_tmproc = tmprocs;
|
||||
|
||||
m_tileLutSize = DtUtils.NextPow2(m_params.maxTiles / 4);
|
||||
if (m_tileLutSize == 0)
|
||||
{
|
||||
m_tileLutSize = 1;
|
||||
}
|
||||
|
||||
m_tileLutMask = m_tileLutSize - 1;
|
||||
m_tiles = new DtCompressedTile[m_params.maxTiles];
|
||||
m_posLookup = new DtCompressedTile[m_tileLutSize];
|
||||
for (int i = m_params.maxTiles - 1; i >= 0; --i)
|
||||
{
|
||||
m_tiles[i] = new DtCompressedTile(i);
|
||||
m_tiles[i].next = m_nextFreeTile;
|
||||
m_nextFreeTile = m_tiles[i];
|
||||
}
|
||||
|
||||
m_tileBits = DtUtils.Ilog2(DtUtils.NextPow2(m_params.maxTiles));
|
||||
m_saltBits = LMath.Min(31, 32 - m_tileBits);
|
||||
if (m_saltBits < 10)
|
||||
{
|
||||
throw new Exception("Too few salt bits: " + m_saltBits);
|
||||
}
|
||||
}
|
||||
|
||||
private bool Contains(List<long> a, long v)
|
||||
{
|
||||
return a.Contains(v);
|
||||
}
|
||||
|
||||
/// Encodes a tile id.
|
||||
private long EncodeTileId(int salt, int it)
|
||||
{
|
||||
return ((long)salt << m_tileBits) | (long)it;
|
||||
}
|
||||
|
||||
/// Decodes a tile salt.
|
||||
private int DecodeTileIdSalt(long refs)
|
||||
{
|
||||
long saltMask = (1L << m_saltBits) - 1;
|
||||
return (int)((refs >> m_tileBits) & saltMask);
|
||||
}
|
||||
|
||||
/// Decodes a tile id.
|
||||
private int DecodeTileIdTile(long refs)
|
||||
{
|
||||
long tileMask = (1L << m_tileBits) - 1;
|
||||
return (int)(refs & tileMask);
|
||||
}
|
||||
|
||||
/// Encodes an obstacle id.
|
||||
private long EncodeObstacleId(int salt, int it)
|
||||
{
|
||||
return ((long)salt << 16) | (long)it;
|
||||
}
|
||||
|
||||
/// Decodes an obstacle salt.
|
||||
private int DecodeObstacleIdSalt(long refs)
|
||||
{
|
||||
long saltMask = ((long)1 << 16) - 1;
|
||||
return (int)((refs >> 16) & saltMask);
|
||||
}
|
||||
|
||||
/// Decodes an obstacle id.
|
||||
private int DecodeObstacleIdObstacle(long refs)
|
||||
{
|
||||
long tileMask = ((long)1 << 16) - 1;
|
||||
return (int)(refs & tileMask);
|
||||
}
|
||||
|
||||
|
||||
public DtCompressedTile GetTileByRef(long refs)
|
||||
{
|
||||
if (refs == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
int tileIndex = DecodeTileIdTile(refs);
|
||||
int tileSalt = DecodeTileIdSalt(refs);
|
||||
if (tileIndex >= m_params.maxTiles)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
DtCompressedTile tile = m_tiles[tileIndex];
|
||||
if (tile.salt != tileSalt)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return tile;
|
||||
}
|
||||
|
||||
public List<long> GetTilesAt(int tx, int ty)
|
||||
{
|
||||
List<long> tiles = new List<long>();
|
||||
|
||||
// Find tile based on hash.
|
||||
int h = DtNavMesh.ComputeTileHash(tx, ty, m_tileLutMask);
|
||||
DtCompressedTile tile = m_posLookup[h];
|
||||
while (tile != null)
|
||||
{
|
||||
if (tile.header != null && tile.header.tx == tx && tile.header.ty == ty)
|
||||
{
|
||||
tiles.Add(GetTileRef(tile));
|
||||
}
|
||||
|
||||
tile = tile.next;
|
||||
}
|
||||
|
||||
return tiles;
|
||||
}
|
||||
|
||||
DtCompressedTile GetTileAt(int tx, int ty, int tlayer)
|
||||
{
|
||||
// Find tile based on hash.
|
||||
int h = DtNavMesh.ComputeTileHash(tx, ty, m_tileLutMask);
|
||||
DtCompressedTile tile = m_posLookup[h];
|
||||
while (tile != null)
|
||||
{
|
||||
if (tile.header != null && tile.header.tx == tx && tile.header.ty == ty && tile.header.tlayer == tlayer)
|
||||
{
|
||||
return tile;
|
||||
}
|
||||
|
||||
tile = tile.next;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public long GetTileRef(DtCompressedTile tile)
|
||||
{
|
||||
if (tile == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int it = tile.index;
|
||||
return EncodeTileId(tile.salt, it);
|
||||
}
|
||||
|
||||
public long GetObstacleRef(DtTileCacheObstacle ob)
|
||||
{
|
||||
if (ob == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int idx = ob.index;
|
||||
return EncodeObstacleId(ob.salt, idx);
|
||||
}
|
||||
|
||||
public DtTileCacheObstacle GetObstacleByRef(long refs)
|
||||
{
|
||||
if (refs == 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
int idx = DecodeObstacleIdObstacle(refs);
|
||||
if (idx >= m_obstacles.Count)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
DtTileCacheObstacle ob = m_obstacles[idx];
|
||||
int salt = DecodeObstacleIdSalt(refs);
|
||||
if (ob.salt != salt)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return ob;
|
||||
}
|
||||
|
||||
public long AddTile(byte[] data, int flags)
|
||||
{
|
||||
// Make sure the data is in right format.
|
||||
RcByteBuffer buf = new RcByteBuffer(data);
|
||||
buf.Order(m_storageParams.Order);
|
||||
DtTileCacheLayerHeader header = tileReader.Read(buf, m_storageParams.Compatibility);
|
||||
// Make sure the location is free.
|
||||
if (GetTileAt(header.tx, header.ty, header.tlayer) != null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Allocate a tile.
|
||||
DtCompressedTile tile = null;
|
||||
if (m_nextFreeTile != null)
|
||||
{
|
||||
tile = m_nextFreeTile;
|
||||
m_nextFreeTile = tile.next;
|
||||
tile.next = null;
|
||||
}
|
||||
|
||||
// Make sure we could allocate a tile.
|
||||
if (tile == null)
|
||||
{
|
||||
throw new Exception("Out of storage");
|
||||
}
|
||||
|
||||
// Insert tile into the position lut.
|
||||
int h = DtNavMesh.ComputeTileHash(header.tx, header.ty, m_tileLutMask);
|
||||
tile.next = m_posLookup[h];
|
||||
m_posLookup[h] = tile;
|
||||
|
||||
// Init tile.
|
||||
tile.header = header;
|
||||
tile.data = data;
|
||||
tile.compressed = Align4(buf.Position());
|
||||
tile.flags = flags;
|
||||
|
||||
return GetTileRef(tile);
|
||||
}
|
||||
|
||||
private int Align4(int i)
|
||||
{
|
||||
return (i + 3) & (~3);
|
||||
}
|
||||
|
||||
public void RemoveTile(long refs)
|
||||
{
|
||||
if (refs == 0)
|
||||
{
|
||||
throw new Exception("Invalid tile ref");
|
||||
}
|
||||
|
||||
int tileIndex = DecodeTileIdTile(refs);
|
||||
int tileSalt = DecodeTileIdSalt(refs);
|
||||
if (tileIndex >= m_params.maxTiles)
|
||||
{
|
||||
throw new Exception("Invalid tile index");
|
||||
}
|
||||
|
||||
DtCompressedTile tile = m_tiles[tileIndex];
|
||||
if (tile.salt != tileSalt)
|
||||
{
|
||||
throw new Exception("Invalid tile salt");
|
||||
}
|
||||
|
||||
// Remove tile from hash lookup.
|
||||
int h = DtNavMesh.ComputeTileHash(tile.header.tx, tile.header.ty, m_tileLutMask);
|
||||
DtCompressedTile prev = null;
|
||||
DtCompressedTile cur = m_posLookup[h];
|
||||
while (cur != null)
|
||||
{
|
||||
if (cur == tile)
|
||||
{
|
||||
if (prev != null)
|
||||
{
|
||||
prev.next = cur.next;
|
||||
}
|
||||
else
|
||||
{
|
||||
m_posLookup[h] = cur.next;
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
|
||||
prev = cur;
|
||||
cur = cur.next;
|
||||
}
|
||||
|
||||
tile.header = null;
|
||||
tile.data = null;
|
||||
tile.compressed = 0;
|
||||
tile.flags = 0;
|
||||
|
||||
// Update salt, salt should never be zero.
|
||||
tile.salt = (tile.salt + 1) & ((1 << m_saltBits) - 1);
|
||||
if (tile.salt == 0)
|
||||
{
|
||||
tile.salt++;
|
||||
}
|
||||
|
||||
// Add to free list.
|
||||
tile.next = m_nextFreeTile;
|
||||
m_nextFreeTile = tile;
|
||||
}
|
||||
|
||||
// Cylinder obstacle
|
||||
public long AddObstacle(RcVec3f pos, LFloat radius, LFloat height)
|
||||
{
|
||||
DtTileCacheObstacle ob = AllocObstacle();
|
||||
ob.type = DtTileCacheObstacleType.CYLINDER;
|
||||
|
||||
ob.pos = pos;
|
||||
ob.radius = radius;
|
||||
ob.height = height;
|
||||
|
||||
return AddObstacleRequest(ob).refs;
|
||||
}
|
||||
|
||||
// Aabb obstacle
|
||||
public long AddBoxObstacle(RcVec3f bmin, RcVec3f bmax)
|
||||
{
|
||||
DtTileCacheObstacle ob = AllocObstacle();
|
||||
ob.type = DtTileCacheObstacleType.BOX;
|
||||
|
||||
ob.bmin = bmin;
|
||||
ob.bmax = bmax;
|
||||
|
||||
return AddObstacleRequest(ob).refs;
|
||||
}
|
||||
|
||||
// Box obstacle: can be rotated in Y
|
||||
public long AddBoxObstacle(RcVec3f center, RcVec3f extents, LFloat yRadians)
|
||||
{
|
||||
DtTileCacheObstacle ob = AllocObstacle();
|
||||
ob.type = DtTileCacheObstacleType.ORIENTED_BOX;
|
||||
ob.center = center;
|
||||
ob.extents = extents;
|
||||
LFloat coshalf = LMath.Cos((LFloat)0.5f * yRadians);
|
||||
LFloat sinhalf = LMath.Sin(-(LFloat)0.5f * yRadians);
|
||||
ob.rotAux[0] = coshalf * sinhalf;
|
||||
ob.rotAux[1] = coshalf * coshalf - (LFloat)0.5f;
|
||||
return AddObstacleRequest(ob).refs;
|
||||
}
|
||||
|
||||
private DtObstacleRequest AddObstacleRequest(DtTileCacheObstacle ob)
|
||||
{
|
||||
DtObstacleRequest req = new DtObstacleRequest(DtObstacleRequestAction.REQUEST_ADD, GetObstacleRef(ob));
|
||||
m_reqs.Add(req);
|
||||
return req;
|
||||
}
|
||||
|
||||
public void RemoveObstacle(long refs)
|
||||
{
|
||||
if (refs == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
DtObstacleRequest req = new DtObstacleRequest(DtObstacleRequestAction.REQUEST_REMOVE, refs);
|
||||
m_reqs.Add(req);
|
||||
}
|
||||
|
||||
private DtTileCacheObstacle AllocObstacle()
|
||||
{
|
||||
DtTileCacheObstacle o = m_nextFreeObstacle;
|
||||
if (o == null)
|
||||
{
|
||||
o = new DtTileCacheObstacle(m_obstacles.Count);
|
||||
m_obstacles.Add(o);
|
||||
}
|
||||
else
|
||||
{
|
||||
m_nextFreeObstacle = o.next;
|
||||
}
|
||||
|
||||
o.state = DtObstacleState.DT_OBSTACLE_PROCESSING;
|
||||
o.touched.Clear();
|
||||
o.pending.Clear();
|
||||
o.next = null;
|
||||
return o;
|
||||
}
|
||||
|
||||
public int GetObstacleCount()
|
||||
{
|
||||
return m_obstacles.Count;
|
||||
}
|
||||
|
||||
public DtTileCacheObstacle GetObstacle(int i)
|
||||
{
|
||||
if (0 > i || i >= m_obstacles.Count)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return m_obstacles[i];
|
||||
}
|
||||
|
||||
private List<long> QueryTiles(RcVec3f bmin, RcVec3f bmax)
|
||||
{
|
||||
List<long> results = new List<long>();
|
||||
LFloat tw = m_params.width * m_params.cs;
|
||||
LFloat th = m_params.height * m_params.cs;
|
||||
int tx0 = (int)LMath.Floor((bmin.X - m_params.orig.X) / tw);
|
||||
int tx1 = (int)LMath.Floor((bmax.X - m_params.orig.X) / tw);
|
||||
int ty0 = (int)LMath.Floor((bmin.Z - m_params.orig.Z) / th);
|
||||
int ty1 = (int)LMath.Floor((bmax.Z - m_params.orig.Z) / th);
|
||||
for (int ty = ty0; ty <= ty1; ++ty)
|
||||
{
|
||||
for (int tx = tx0; tx <= tx1; ++tx)
|
||||
{
|
||||
List<long> tiles = GetTilesAt(tx, ty);
|
||||
foreach (long i in tiles)
|
||||
{
|
||||
DtCompressedTile tile = m_tiles[DecodeTileIdTile(i)];
|
||||
RcVec3f tbmin = new RcVec3f();
|
||||
RcVec3f tbmax = new RcVec3f();
|
||||
CalcTightTileBounds(tile.header, ref tbmin, ref tbmax);
|
||||
if (DtUtils.OverlapBounds(bmin, bmax, tbmin, tbmax))
|
||||
{
|
||||
results.Add(i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the tile cache by rebuilding tiles touched by unfinished obstacle requests.
|
||||
*
|
||||
* @return Returns true if the tile cache is fully up to date with obstacle requests and tile rebuilds. If the tile
|
||||
* cache is up to date another (immediate) call to update will have no effect; otherwise another call will
|
||||
* continue processing obstacle requests and tile rebuilds.
|
||||
*/
|
||||
public bool Update()
|
||||
{
|
||||
if (0 == m_update.Count)
|
||||
{
|
||||
// Process requests.
|
||||
foreach (DtObstacleRequest req in m_reqs)
|
||||
{
|
||||
int idx = DecodeObstacleIdObstacle(req.refs);
|
||||
if (idx >= m_obstacles.Count)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
DtTileCacheObstacle ob = m_obstacles[idx];
|
||||
int salt = DecodeObstacleIdSalt(req.refs);
|
||||
if (ob.salt != salt)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (req.action == DtObstacleRequestAction.REQUEST_ADD)
|
||||
{
|
||||
// Find touched tiles.
|
||||
RcVec3f bmin = new RcVec3f();
|
||||
RcVec3f bmax = new RcVec3f();
|
||||
GetObstacleBounds(ob, ref bmin, ref bmax);
|
||||
ob.touched = QueryTiles(bmin, bmax);
|
||||
// Add tiles to update list.
|
||||
ob.pending.Clear();
|
||||
foreach (long j in ob.touched)
|
||||
{
|
||||
if (!Contains(m_update, j))
|
||||
{
|
||||
m_update.Add(j);
|
||||
}
|
||||
|
||||
ob.pending.Add(j);
|
||||
}
|
||||
}
|
||||
else if (req.action == DtObstacleRequestAction.REQUEST_REMOVE)
|
||||
{
|
||||
// Prepare to remove obstacle.
|
||||
ob.state = DtObstacleState.DT_OBSTACLE_REMOVING;
|
||||
// Add tiles to update list.
|
||||
ob.pending.Clear();
|
||||
foreach (long j in ob.touched)
|
||||
{
|
||||
if (!Contains(m_update, j))
|
||||
{
|
||||
m_update.Add(j);
|
||||
}
|
||||
|
||||
ob.pending.Add(j);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
m_reqs.Clear();
|
||||
}
|
||||
|
||||
// Process updates
|
||||
if (0 < m_update.Count)
|
||||
{
|
||||
long refs = m_update[0];
|
||||
m_update.RemoveAt(0);
|
||||
// Build mesh
|
||||
BuildNavMeshTile(refs);
|
||||
|
||||
// Update obstacle states.
|
||||
for (int i = 0; i < m_obstacles.Count; ++i)
|
||||
{
|
||||
DtTileCacheObstacle ob = m_obstacles[i];
|
||||
if (ob.state == DtObstacleState.DT_OBSTACLE_PROCESSING
|
||||
|| ob.state == DtObstacleState.DT_OBSTACLE_REMOVING)
|
||||
{
|
||||
// Remove handled tile from pending list.
|
||||
ob.pending.Remove(refs);
|
||||
|
||||
// If all pending tiles processed, change state.
|
||||
if (0 == ob.pending.Count)
|
||||
{
|
||||
if (ob.state == DtObstacleState.DT_OBSTACLE_PROCESSING)
|
||||
{
|
||||
ob.state = DtObstacleState.DT_OBSTACLE_PROCESSED;
|
||||
}
|
||||
else if (ob.state == DtObstacleState.DT_OBSTACLE_REMOVING)
|
||||
{
|
||||
ob.state = DtObstacleState.DT_OBSTACLE_EMPTY;
|
||||
// Update salt, salt should never be zero.
|
||||
ob.salt = (ob.salt + 1) & ((1 << 16) - 1);
|
||||
if (ob.salt == 0)
|
||||
{
|
||||
ob.salt++;
|
||||
}
|
||||
|
||||
// Return obstacle to free list.
|
||||
ob.next = m_nextFreeObstacle;
|
||||
m_nextFreeObstacle = ob;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0 == m_update.Count && 0 == m_reqs.Count;
|
||||
}
|
||||
|
||||
public void BuildNavMeshTile(long refs)
|
||||
{
|
||||
int idx = DecodeTileIdTile(refs);
|
||||
if (idx > m_params.maxTiles)
|
||||
{
|
||||
throw new Exception("Invalid tile index");
|
||||
}
|
||||
|
||||
DtCompressedTile tile = m_tiles[idx];
|
||||
int salt = DecodeTileIdSalt(refs);
|
||||
if (tile.salt != salt)
|
||||
{
|
||||
throw new Exception("Invalid tile salt");
|
||||
}
|
||||
|
||||
int walkableClimbVx = (int)(m_params.walkableClimb / m_params.ch);
|
||||
|
||||
// Decompress tile layer data.
|
||||
DtTileCacheLayer layer = DecompressTile(tile);
|
||||
|
||||
// Rasterize obstacles.
|
||||
for (int i = 0; i < m_obstacles.Count; ++i)
|
||||
{
|
||||
DtTileCacheObstacle ob = m_obstacles[i];
|
||||
if (ob.state == DtObstacleState.DT_OBSTACLE_EMPTY || ob.state == DtObstacleState.DT_OBSTACLE_REMOVING)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (Contains(ob.touched, refs))
|
||||
{
|
||||
if (ob.type == DtTileCacheObstacleType.CYLINDER)
|
||||
{
|
||||
builder.MarkCylinderArea(layer, tile.header.bmin, m_params.cs, m_params.ch, ob.pos, ob.radius, ob.height, 0);
|
||||
}
|
||||
else if (ob.type == DtTileCacheObstacleType.BOX)
|
||||
{
|
||||
builder.MarkBoxArea(layer, tile.header.bmin, m_params.cs, m_params.ch, ob.bmin, ob.bmax, 0);
|
||||
}
|
||||
else if (ob.type == DtTileCacheObstacleType.ORIENTED_BOX)
|
||||
{
|
||||
builder.MarkBoxArea(layer, tile.header.bmin, m_params.cs, m_params.ch, ob.center, ob.extents, ob.rotAux, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Build navmesh
|
||||
builder.BuildTileCacheRegions(layer, walkableClimbVx);
|
||||
DtTileCacheContourSet lcset = builder.BuildTileCacheContours(layer, walkableClimbVx,
|
||||
m_params.maxSimplificationError);
|
||||
DtTileCachePolyMesh polyMesh = builder.BuildTileCachePolyMesh(lcset, m_navmesh.GetMaxVertsPerPoly());
|
||||
// Early out if the mesh tile is empty.
|
||||
if (polyMesh.npolys == 0)
|
||||
{
|
||||
m_navmesh.RemoveTile(m_navmesh.GetTileRefAt(tile.header.tx, tile.header.ty, tile.header.tlayer));
|
||||
return;
|
||||
}
|
||||
|
||||
DtNavMeshCreateParams option = new DtNavMeshCreateParams();
|
||||
option.verts = polyMesh.verts;
|
||||
option.vertCount = polyMesh.nverts;
|
||||
option.polys = polyMesh.polys;
|
||||
option.polyAreas = polyMesh.areas;
|
||||
option.polyFlags = polyMesh.flags;
|
||||
option.polyCount = polyMesh.npolys;
|
||||
option.nvp = m_navmesh.GetMaxVertsPerPoly();
|
||||
option.walkableHeight = m_params.walkableHeight;
|
||||
option.walkableRadius = m_params.walkableRadius;
|
||||
option.walkableClimb = m_params.walkableClimb;
|
||||
option.tileX = tile.header.tx;
|
||||
option.tileZ = tile.header.ty;
|
||||
option.tileLayer = tile.header.tlayer;
|
||||
option.cs = m_params.cs;
|
||||
option.ch = m_params.ch;
|
||||
option.buildBvTree = false;
|
||||
option.bmin = tile.header.bmin;
|
||||
option.bmax = tile.header.bmax;
|
||||
if (m_tmproc != null)
|
||||
{
|
||||
m_tmproc.Process(option);
|
||||
}
|
||||
|
||||
DtMeshData meshData = DtNavMeshBuilder.CreateNavMeshData(option);
|
||||
// Remove existing tile.
|
||||
m_navmesh.RemoveTile(m_navmesh.GetTileRefAt(tile.header.tx, tile.header.ty, tile.header.tlayer));
|
||||
// Add new tile, or leave the location empty. if (navData) { // Let the
|
||||
if (meshData != null)
|
||||
{
|
||||
m_navmesh.AddTile(meshData, 0, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public DtTileCacheLayer DecompressTile(DtCompressedTile tile)
|
||||
{
|
||||
DtTileCacheLayer layer = builder.DecompressTileCacheLayer(m_tcomp, tile.data, m_storageParams.Order, m_storageParams.Compatibility);
|
||||
return layer;
|
||||
}
|
||||
|
||||
void CalcTightTileBounds(DtTileCacheLayerHeader header, ref RcVec3f bmin, ref RcVec3f bmax)
|
||||
{
|
||||
LFloat cs = m_params.cs;
|
||||
bmin.X = header.bmin.X + header.minx * cs;
|
||||
bmin.Y = header.bmin.Y;
|
||||
bmin.Z = header.bmin.Z + header.miny * cs;
|
||||
bmax.X = header.bmin.X + (header.maxx + 1) * cs;
|
||||
bmax.Y = header.bmax.Y;
|
||||
bmax.Z = header.bmin.Z + (header.maxy + 1) * cs;
|
||||
}
|
||||
|
||||
public void GetObstacleBounds(DtTileCacheObstacle ob, ref RcVec3f bmin, ref RcVec3f bmax)
|
||||
{
|
||||
if (ob.type == DtTileCacheObstacleType.CYLINDER)
|
||||
{
|
||||
bmin.X = ob.pos.X - ob.radius;
|
||||
bmin.Y = ob.pos.Y;
|
||||
bmin.Z = ob.pos.Z - ob.radius;
|
||||
bmax.X = ob.pos.X + ob.radius;
|
||||
bmax.Y = ob.pos.Y + ob.height;
|
||||
bmax.Z = ob.pos.Z + ob.radius;
|
||||
}
|
||||
else if (ob.type == DtTileCacheObstacleType.BOX)
|
||||
{
|
||||
bmin = ob.bmin;
|
||||
bmax = ob.bmax;
|
||||
}
|
||||
else if (ob.type == DtTileCacheObstacleType.ORIENTED_BOX)
|
||||
{
|
||||
LFloat maxr = (LFloat)1.41f * LMath.Max(ob.extents.X, ob.extents.Z);
|
||||
bmin.X = ob.center.X - maxr;
|
||||
bmax.X = ob.center.X + maxr;
|
||||
bmin.Y = ob.center.Y - ob.extents.Y;
|
||||
bmax.Y = ob.center.Y + ob.extents.Y;
|
||||
bmin.Z = ob.center.Z - maxr;
|
||||
bmax.Z = ob.center.Z + maxr;
|
||||
}
|
||||
}
|
||||
|
||||
public ref readonly DtTileCacheParams GetParams()
|
||||
{
|
||||
return ref m_params;
|
||||
}
|
||||
|
||||
public IRcCompressor GetCompressor()
|
||||
{
|
||||
return m_tcomp;
|
||||
}
|
||||
|
||||
public int GetTileCount()
|
||||
{
|
||||
return m_params.maxTiles;
|
||||
}
|
||||
|
||||
public DtCompressedTile GetTile(int i)
|
||||
{
|
||||
return m_tiles[i];
|
||||
}
|
||||
|
||||
public DtNavMesh GetNavMesh()
|
||||
{
|
||||
return m_navmesh;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7e06ee5482524624b127935faca0f759
|
||||
timeCreated: 1715335345
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d33dd314a8874f449e352dec374dda17
|
||||
timeCreated: 1715335345
|
||||
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
|
||||
recast4j copyright (c) 2015-2019 Piotr Piastucki piotr@jtilia.org
|
||||
DotRecast Copyright (c) 2023 Choi Ikpil ikpil@naver.com
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
namespace DotRecast.Detour.TileCache
|
||||
{
|
||||
public class DtTileCacheContour
|
||||
{
|
||||
public int nverts;
|
||||
public int[] verts;
|
||||
public int reg;
|
||||
public int area;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e359fd87aa1d4118b59747207d4546e1
|
||||
timeCreated: 1715335345
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
|
||||
recast4j copyright (c) 2015-2019 Piotr Piastucki piotr@jtilia.org
|
||||
DotRecast Copyright (c) 2023 Choi Ikpil ikpil@naver.com
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
namespace DotRecast.Detour.TileCache
|
||||
{
|
||||
public class DtTileCacheContourSet
|
||||
{
|
||||
public int nconts;
|
||||
public DtTileCacheContour[] conts;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 520b8d248bc746fc994244eca52b8dd7
|
||||
timeCreated: 1715335346
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
|
||||
recast4j copyright (c) 2015-2019 Piotr Piastucki piotr@jtilia.org
|
||||
DotRecast Copyright (c) 2023 Choi Ikpil ikpil@naver.com
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
namespace DotRecast.Detour.TileCache
|
||||
{
|
||||
public class DtTileCacheLayer
|
||||
{
|
||||
public DtTileCacheLayerHeader header;
|
||||
public int regCount;
|
||||
|
||||
/// < Region count.
|
||||
public short[] heights; // char
|
||||
|
||||
public short[] areas; // char
|
||||
public short[] cons; // char
|
||||
public short[] regs; // char
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5b4379b3ffd24fbab717848188da002d
|
||||
timeCreated: 1715335345
|
||||
@@ -0,0 +1,18 @@
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace DotRecast.Detour.TileCache
|
||||
{
|
||||
public class DtTileCacheLayerBuildResult
|
||||
{
|
||||
public readonly int tx;
|
||||
public readonly int ty;
|
||||
public readonly List<byte[]> layers;
|
||||
|
||||
public DtTileCacheLayerBuildResult(int tx, int ty, List<byte[]> layers)
|
||||
{
|
||||
this.tx = tx;
|
||||
this.ty = ty;
|
||||
this.layers = layers;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7acf846eddc1417f9593ca15341daa52
|
||||
timeCreated: 1715335346
|
||||
@@ -0,0 +1,142 @@
|
||||
/*
|
||||
Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
|
||||
recast4j copyright (c) 2015-2019 Piotr Piastucki piotr@jtilia.org
|
||||
DotRecast Copyright (c) 2023 Choi Ikpil ikpil@naver.com
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using DotRecast.Core.Numerics;
|
||||
using DotRecast.Detour.TileCache.Io.Compress;
|
||||
using DotRecast.Recast;
|
||||
using DotRecast.Recast.Geom;
|
||||
|
||||
namespace DotRecast.Detour.TileCache
|
||||
{
|
||||
public class DtTileCacheLayerBuilder
|
||||
{
|
||||
private readonly IDtTileCacheCompressorFactory _compFactory;
|
||||
|
||||
public DtTileCacheLayerBuilder(IDtTileCacheCompressorFactory compFactory)
|
||||
{
|
||||
_compFactory = compFactory;
|
||||
}
|
||||
|
||||
public List<DtTileCacheLayerBuildResult> Build(IInputGeomProvider geom, RcConfig cfg, DtTileCacheStorageParams storageParams, int threads, int tw, int th)
|
||||
{
|
||||
//帧同步 禁止使用多线程
|
||||
|
||||
// if (threads == 1)
|
||||
// {
|
||||
// return BuildSingleThread(geom, cfg, storageParams, tw, th);
|
||||
// }
|
||||
//
|
||||
// return BuildMultiThread(geom, cfg, storageParams, tw, th, threads);
|
||||
|
||||
return BuildSingleThread(geom, cfg, storageParams, tw, th);
|
||||
}
|
||||
|
||||
private List<DtTileCacheLayerBuildResult> BuildSingleThread(IInputGeomProvider geom, RcConfig cfg, DtTileCacheStorageParams storageParams, int tw, int th)
|
||||
{
|
||||
var results = new List<DtTileCacheLayerBuildResult>();
|
||||
for (int y = 0; y < th; ++y)
|
||||
{
|
||||
for (int x = 0; x < tw; ++x)
|
||||
{
|
||||
var result = BuildTileCacheLayer(geom, cfg, x, y, storageParams);
|
||||
results.Add(result);
|
||||
}
|
||||
}
|
||||
|
||||
return results;
|
||||
}
|
||||
|
||||
|
||||
// private List<DtTileCacheLayerBuildResult> BuildMultiThread(IInputGeomProvider geom, RcConfig cfg, DtTileCacheStorageParams storageParams, int tw, int th, int threads)
|
||||
// {
|
||||
// var results = new List<Task<DtTileCacheLayerBuildResult>>();
|
||||
// for (int y = 0; y < th; ++y)
|
||||
// {
|
||||
// for (int x = 0; x < tw; ++x)
|
||||
// {
|
||||
// int tx = x;
|
||||
// int ty = y;
|
||||
// var task = Task.Run(() => BuildTileCacheLayer(geom, cfg, tx, ty, storageParams));
|
||||
// results.Add(task);
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// return results
|
||||
// .Select(x => x.Result)
|
||||
// .ToList();
|
||||
// }
|
||||
|
||||
protected virtual RcHeightfieldLayerSet BuildHeightfieldLayerSet(IInputGeomProvider geom, RcConfig cfg, int tx, int ty)
|
||||
{
|
||||
RcBuilder rcBuilder = new RcBuilder();
|
||||
RcVec3f bmin = geom.GetMeshBoundsMin();
|
||||
RcVec3f bmax = geom.GetMeshBoundsMax();
|
||||
RcBuilderConfig builderCfg = new RcBuilderConfig(cfg, bmin, bmax, tx, ty);
|
||||
RcHeightfieldLayerSet lset = rcBuilder.BuildLayers(geom, builderCfg);
|
||||
return lset;
|
||||
}
|
||||
|
||||
protected virtual DtTileCacheLayerBuildResult BuildTileCacheLayer(IInputGeomProvider geom, RcConfig cfg, int tx, int ty, DtTileCacheStorageParams storageParams)
|
||||
{
|
||||
RcHeightfieldLayerSet lset = BuildHeightfieldLayerSet(geom, cfg, tx, ty);
|
||||
List<byte[]> result = new List<byte[]>();
|
||||
if (lset != null)
|
||||
{
|
||||
DtTileCacheBuilder builder = new DtTileCacheBuilder();
|
||||
for (int i = 0; i < lset.layers.Length; ++i)
|
||||
{
|
||||
RcHeightfieldLayer layer = lset.layers[i];
|
||||
|
||||
// Store header
|
||||
DtTileCacheLayerHeader header = new DtTileCacheLayerHeader();
|
||||
header.magic = DtTileCacheLayerHeader.DT_TILECACHE_MAGIC;
|
||||
header.version = DtTileCacheLayerHeader.DT_TILECACHE_VERSION;
|
||||
|
||||
// Tile layer location in the navmesh.
|
||||
header.tx = tx;
|
||||
header.ty = ty;
|
||||
header.tlayer = i;
|
||||
header.bmin = layer.bmin;
|
||||
header.bmax = layer.bmax;
|
||||
|
||||
// Tile info.
|
||||
header.width = layer.width;
|
||||
header.height = layer.height;
|
||||
header.minx = layer.minx;
|
||||
header.maxx = layer.maxx;
|
||||
header.miny = layer.miny;
|
||||
header.maxy = layer.maxy;
|
||||
header.hmin = layer.hmin;
|
||||
header.hmax = layer.hmax;
|
||||
|
||||
var comp = _compFactory.Create(storageParams.Compatibility ? 0 : 1);
|
||||
var bytes = builder.CompressTileCacheLayer(header, layer.heights, layer.areas, layer.cons, storageParams.Order, storageParams.Compatibility, comp);
|
||||
result.Add(bytes);
|
||||
}
|
||||
}
|
||||
|
||||
return new DtTileCacheLayerBuildResult(tx, ty, result);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ae90ad50bba64bd9a20a9ce0110f79a7
|
||||
timeCreated: 1715335346
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
|
||||
recast4j copyright (c) 2015-2019 Piotr Piastucki piotr@jtilia.org
|
||||
DotRecast Copyright (c) 2023 Choi Ikpil ikpil@naver.com
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
using DotRecast.Core.Numerics;
|
||||
|
||||
namespace DotRecast.Detour.TileCache
|
||||
{
|
||||
public class DtTileCacheLayerHeader
|
||||
{
|
||||
public const int DT_TILECACHE_MAGIC = 'D' << 24 | 'T' << 16 | 'L' << 8 | 'R'; // < 'DTLR';
|
||||
public const int DT_TILECACHE_VERSION = 1;
|
||||
|
||||
public int magic; // < Data magic
|
||||
public int version; // < Data version
|
||||
public int tx, ty, tlayer;
|
||||
|
||||
public RcVec3f bmin = new RcVec3f();
|
||||
public RcVec3f bmax = new RcVec3f();
|
||||
public int hmin, hmax; // < Height min/max range
|
||||
public int width, height; // < Dimension of the layer.
|
||||
public int minx, maxx, miny, maxy; // < Usable sub-region.
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 8502e27c6fcb44b49ab8976953a0145a
|
||||
timeCreated: 1715335346
|
||||
@@ -0,0 +1,51 @@
|
||||
/*
|
||||
Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
|
||||
recast4j copyright (c) 2015-2019 Piotr Piastucki piotr@jtilia.org
|
||||
DotRecast Copyright (c) 2023 Choi Ikpil ikpil@naver.com
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
using System.Collections.Generic;
|
||||
using DotRecast.Core.Numerics;
|
||||
using JNGame.Math;
|
||||
|
||||
namespace DotRecast.Detour.TileCache
|
||||
{
|
||||
public class DtTileCacheObstacle
|
||||
{
|
||||
public readonly int index;
|
||||
public DtTileCacheObstacleType type;
|
||||
public RcVec3f pos = new RcVec3f();
|
||||
public RcVec3f bmin = new RcVec3f();
|
||||
public RcVec3f bmax = new RcVec3f();
|
||||
public LFloat radius, height;
|
||||
public RcVec3f center = new RcVec3f();
|
||||
public RcVec3f extents = new RcVec3f();
|
||||
public readonly LFloat[] rotAux = new LFloat[2]; // { Cos(0.5f*angle)*Sin(-0.5f*angle); Cos(0.5f*angle)*Cos(0.5f*angle) - 0.5 }
|
||||
|
||||
public List<long> touched = new List<long>();
|
||||
public readonly List<long> pending = new List<long>();
|
||||
public int salt;
|
||||
public DtObstacleState state = DtObstacleState.DT_OBSTACLE_EMPTY;
|
||||
public DtTileCacheObstacle next;
|
||||
|
||||
public DtTileCacheObstacle(int index)
|
||||
{
|
||||
salt = 1;
|
||||
this.index = index;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 137e5b3619404a7ea00dcd3f9c896b1b
|
||||
timeCreated: 1715335346
|
||||
@@ -0,0 +1,9 @@
|
||||
namespace DotRecast.Detour.TileCache
|
||||
{
|
||||
public enum DtTileCacheObstacleType
|
||||
{
|
||||
CYLINDER,
|
||||
BOX,
|
||||
ORIENTED_BOX
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 1dc954afc5a94385ab8d96c79506eb97
|
||||
timeCreated: 1715335346
|
||||
@@ -0,0 +1,38 @@
|
||||
/*
|
||||
Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
|
||||
recast4j copyright (c) 2015-2019 Piotr Piastucki piotr@jtilia.org
|
||||
DotRecast Copyright (c) 2023 Choi Ikpil ikpil@naver.com
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
using DotRecast.Core.Numerics;
|
||||
using JNGame.Math;
|
||||
|
||||
namespace DotRecast.Detour.TileCache
|
||||
{
|
||||
public struct DtTileCacheParams
|
||||
{
|
||||
public RcVec3f orig;
|
||||
public LFloat cs, ch;
|
||||
public int width, height;
|
||||
public LFloat walkableHeight;
|
||||
public LFloat walkableRadius;
|
||||
public LFloat walkableClimb;
|
||||
public LFloat maxSimplificationError;
|
||||
public int maxTiles;
|
||||
public int maxObstacles;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0e7b14aeac4f4729b996324f89375d3a
|
||||
timeCreated: 1715335345
|
||||
@@ -0,0 +1,49 @@
|
||||
/*
|
||||
Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
|
||||
recast4j copyright (c) 2015-2019 Piotr Piastucki piotr@jtilia.org
|
||||
DotRecast Copyright (c) 2023 Choi Ikpil ikpil@naver.com
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
namespace DotRecast.Detour.TileCache
|
||||
{
|
||||
public class DtTileCachePolyMesh
|
||||
{
|
||||
public int nvp;
|
||||
public int nverts;
|
||||
|
||||
/// < Number of vertices.
|
||||
public int npolys;
|
||||
|
||||
/// < Number of polygons.
|
||||
public int[] verts;
|
||||
|
||||
/// < Vertices of the mesh, 3 elements per vertex.
|
||||
public int[] polys;
|
||||
|
||||
/// < Polygons of the mesh, nvp*2 elements per polygon.
|
||||
public int[] flags;
|
||||
|
||||
/// < Per polygon flags.
|
||||
public int[] areas;
|
||||
|
||||
/// < Area ID of polygons.
|
||||
public DtTileCachePolyMesh(int nvp)
|
||||
{
|
||||
this.nvp = nvp;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5e85f60ca5744bfc922d30207ac7dd46
|
||||
timeCreated: 1715335346
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
|
||||
recast4j copyright (c) 2015-2019 Piotr Piastucki piotr@jtilia.org
|
||||
DotRecast Copyright (c) 2023 Choi Ikpil ikpil@naver.com
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
using DotRecast.Core;
|
||||
|
||||
namespace DotRecast.Detour.TileCache
|
||||
{
|
||||
public readonly struct DtTileCacheStorageParams
|
||||
{
|
||||
public readonly RcByteOrder Order;
|
||||
public readonly bool Compatibility;
|
||||
|
||||
public DtTileCacheStorageParams(RcByteOrder order, bool compatibility)
|
||||
{
|
||||
Order = order;
|
||||
Compatibility = compatibility;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f97c7afecb9c472c809a4d52156f38fa
|
||||
timeCreated: 1715335346
|
||||
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
|
||||
recast4j copyright (c) 2015-2019 Piotr Piastucki piotr@jtilia.org
|
||||
DotRecast Copyright (c) 2023 Choi Ikpil ikpil@naver.com
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
namespace DotRecast.Detour.TileCache
|
||||
{
|
||||
public interface IDtTileCacheMeshProcess
|
||||
{
|
||||
void Process(DtNavMeshCreateParams option);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f062f64b8af346c2bf9fb05c16d7e6ff
|
||||
timeCreated: 1715335346
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b81b1859bd474b64bbe166eede7dc4da
|
||||
timeCreated: 1715335343
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 67abedc34f3b47e9b1ad7fa394da4925
|
||||
timeCreated: 1715335343
|
||||
@@ -0,0 +1,37 @@
|
||||
using System.Collections.Generic;
|
||||
using DotRecast.Core;
|
||||
|
||||
namespace DotRecast.Detour.TileCache.Io.Compress
|
||||
{
|
||||
public class DtTileCacheCompressorFactory : IDtTileCacheCompressorFactory
|
||||
{
|
||||
public static readonly DtTileCacheCompressorFactory Shared = new DtTileCacheCompressorFactory();
|
||||
|
||||
private readonly Dictionary<int, IRcCompressor> _compressors = new Dictionary<int, IRcCompressor>();
|
||||
|
||||
public bool TryAdd(int type, IRcCompressor compressor)
|
||||
{
|
||||
if (0 == type)
|
||||
return false;
|
||||
|
||||
_compressors[type] = compressor;
|
||||
return true;
|
||||
}
|
||||
|
||||
public IRcCompressor Create(int compatibility)
|
||||
{
|
||||
// default
|
||||
if (0 == compatibility)
|
||||
{
|
||||
return DtTileCacheFastLzCompressor.Shared;
|
||||
}
|
||||
|
||||
if (!_compressors.TryGetValue(compatibility, out var comp))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return comp;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 19d45e7232474c3cb28e6f88ebc132ae
|
||||
timeCreated: 1715335343
|
||||
@@ -0,0 +1,53 @@
|
||||
/*
|
||||
Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
|
||||
recast4j copyright (c) 2015-2019 Piotr Piastucki piotr@jtilia.org
|
||||
DotRecast Copyright (c) 2023 Choi Ikpil ikpil@naver.com
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
using DotRecast.Core;
|
||||
using DotRecast.Core.Compression;
|
||||
|
||||
namespace DotRecast.Detour.TileCache.Io.Compress
|
||||
{
|
||||
public class DtTileCacheFastLzCompressor : IRcCompressor
|
||||
{
|
||||
public static readonly DtTileCacheFastLzCompressor Shared = new DtTileCacheFastLzCompressor();
|
||||
|
||||
private DtTileCacheFastLzCompressor()
|
||||
{
|
||||
}
|
||||
|
||||
public byte[] Decompress(byte[] buf)
|
||||
{
|
||||
return Decompress(buf, 0, buf.Length, buf.Length * 3);
|
||||
}
|
||||
|
||||
public byte[] Decompress(byte[] buf, int offset, int len, int outputlen)
|
||||
{
|
||||
byte[] output = new byte[outputlen];
|
||||
FastLZ.Decompress(buf, offset, len, output, 0, outputlen);
|
||||
return output;
|
||||
}
|
||||
|
||||
public byte[] Compress(byte[] buf)
|
||||
{
|
||||
byte[] output = new byte[FastLZ.EstimateCompressedSize(buf.Length)];
|
||||
long len = FastLZ.CompressLevel(2, buf, 0, buf.Length, output);
|
||||
return RcArrays.CopyOf(output, len);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6cb30bd7bb984794af0206b31c4be29c
|
||||
timeCreated: 1715335343
|
||||
@@ -0,0 +1,29 @@
|
||||
/*
|
||||
Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
|
||||
recast4j copyright (c) 2015-2019 Piotr Piastucki piotr@jtilia.org
|
||||
DotRecast Copyright (c) 2023 Choi Ikpil ikpil@naver.com
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
using DotRecast.Core;
|
||||
|
||||
namespace DotRecast.Detour.TileCache.Io.Compress
|
||||
{
|
||||
public interface IDtTileCacheCompressorFactory
|
||||
{
|
||||
IRcCompressor Create(int compatibility);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f4c624c11f654884ba8d8076bffc3233
|
||||
timeCreated: 1715335343
|
||||
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
|
||||
recast4j copyright (c) 2015-2019 Piotr Piastucki piotr@jtilia.org
|
||||
DotRecast Copyright (c) 2023 Choi Ikpil ikpil@naver.com
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
using System.IO;
|
||||
using DotRecast.Core;
|
||||
|
||||
namespace DotRecast.Detour.TileCache.Io
|
||||
{
|
||||
public class DtTileCacheLayerHeaderReader
|
||||
{
|
||||
public DtTileCacheLayerHeader Read(RcByteBuffer data, bool cCompatibility)
|
||||
{
|
||||
DtTileCacheLayerHeader header = new DtTileCacheLayerHeader();
|
||||
header.magic = data.GetInt();
|
||||
header.version = data.GetInt();
|
||||
|
||||
if (header.magic != DtTileCacheLayerHeader.DT_TILECACHE_MAGIC)
|
||||
throw new IOException("Invalid magic");
|
||||
if (header.version != DtTileCacheLayerHeader.DT_TILECACHE_VERSION)
|
||||
throw new IOException("Invalid version");
|
||||
|
||||
header.tx = data.GetInt();
|
||||
header.ty = data.GetInt();
|
||||
header.tlayer = data.GetInt();
|
||||
|
||||
header.bmin.X = data.GetFloat();
|
||||
header.bmin.Y = data.GetFloat();
|
||||
header.bmin.Z = data.GetFloat();
|
||||
header.bmax.X = data.GetFloat();
|
||||
header.bmax.Y = data.GetFloat();
|
||||
header.bmax.Z = data.GetFloat();
|
||||
|
||||
header.hmin = data.GetShort() & 0xFFFF;
|
||||
header.hmax = data.GetShort() & 0xFFFF;
|
||||
header.width = data.Get() & 0xFF;
|
||||
header.height = data.Get() & 0xFF;
|
||||
header.minx = data.Get() & 0xFF;
|
||||
header.maxx = data.Get() & 0xFF;
|
||||
header.miny = data.Get() & 0xFF;
|
||||
header.maxy = data.Get() & 0xFF;
|
||||
if (cCompatibility)
|
||||
{
|
||||
data.GetShort(); // C struct padding
|
||||
}
|
||||
|
||||
return header;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fe471fde5358464b98ae2950b4a20f5a
|
||||
timeCreated: 1715335343
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
|
||||
recast4j copyright (c) 2015-2019 Piotr Piastucki piotr@jtilia.org
|
||||
DotRecast Copyright (c) 2023 Choi Ikpil ikpil@naver.com
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
using System.IO;
|
||||
using DotRecast.Core;
|
||||
using DotRecast.Detour.Io;
|
||||
|
||||
namespace DotRecast.Detour.TileCache.Io
|
||||
{
|
||||
public class DtTileCacheLayerHeaderWriter : DtWriter
|
||||
{
|
||||
public void Write(BinaryWriter stream, DtTileCacheLayerHeader header, RcByteOrder order, bool cCompatibility)
|
||||
{
|
||||
Write(stream, header.magic, order);
|
||||
Write(stream, header.version, order);
|
||||
Write(stream, header.tx, order);
|
||||
Write(stream, header.ty, order);
|
||||
Write(stream, header.tlayer, order);
|
||||
|
||||
Write(stream, header.bmin.X, order);
|
||||
Write(stream, header.bmin.Y, order);
|
||||
Write(stream, header.bmin.Z, order);
|
||||
Write(stream, header.bmax.X, order);
|
||||
Write(stream, header.bmax.Y, order);
|
||||
Write(stream, header.bmax.Z, order);
|
||||
|
||||
Write(stream, (short)header.hmin, order);
|
||||
Write(stream, (short)header.hmax, order);
|
||||
Write(stream, (byte)header.width);
|
||||
Write(stream, (byte)header.height);
|
||||
Write(stream, (byte)header.minx);
|
||||
Write(stream, (byte)header.maxx);
|
||||
Write(stream, (byte)header.miny);
|
||||
Write(stream, (byte)header.maxy);
|
||||
if (cCompatibility)
|
||||
{
|
||||
Write(stream, (short)0, order); // C struct padding
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 15ae40fae08a49df92c42e5d8240b393
|
||||
timeCreated: 1715335343
|
||||
@@ -0,0 +1,118 @@
|
||||
/*
|
||||
Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
|
||||
recast4j copyright (c) 2015-2019 Piotr Piastucki piotr@jtilia.org
|
||||
DotRecast Copyright (c) 2023 Choi Ikpil ikpil@naver.com
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
using System.IO;
|
||||
using DotRecast.Core;
|
||||
using DotRecast.Detour.Io;
|
||||
using DotRecast.Detour.TileCache.Io.Compress;
|
||||
|
||||
namespace DotRecast.Detour.TileCache.Io
|
||||
{
|
||||
public class DtTileCacheReader
|
||||
{
|
||||
private readonly DtNavMeshParamsReader paramReader = new DtNavMeshParamsReader();
|
||||
private readonly IDtTileCacheCompressorFactory _compFactory;
|
||||
|
||||
public DtTileCacheReader(IDtTileCacheCompressorFactory compFactory)
|
||||
{
|
||||
_compFactory = compFactory;
|
||||
}
|
||||
|
||||
public DtTileCache Read(BinaryReader @is, int maxVertPerPoly, IDtTileCacheMeshProcess meshProcessor)
|
||||
{
|
||||
RcByteBuffer bb = IOUtils.ToByteBuffer(@is);
|
||||
return Read(bb, maxVertPerPoly, meshProcessor);
|
||||
}
|
||||
|
||||
public DtTileCache Read(RcByteBuffer bb, int maxVertPerPoly, IDtTileCacheMeshProcess meshProcessor)
|
||||
{
|
||||
DtTileCacheSetHeader header = new DtTileCacheSetHeader();
|
||||
header.magic = bb.GetInt();
|
||||
if (header.magic != DtTileCacheSetHeader.TILECACHESET_MAGIC)
|
||||
{
|
||||
header.magic = IOUtils.SwapEndianness(header.magic);
|
||||
if (header.magic != DtTileCacheSetHeader.TILECACHESET_MAGIC)
|
||||
{
|
||||
throw new IOException("Invalid magic");
|
||||
}
|
||||
|
||||
bb.Order(bb.Order() == RcByteOrder.BIG_ENDIAN ? RcByteOrder.LITTLE_ENDIAN : RcByteOrder.BIG_ENDIAN);
|
||||
}
|
||||
|
||||
header.version = bb.GetInt();
|
||||
if (header.version != DtTileCacheSetHeader.TILECACHESET_VERSION)
|
||||
{
|
||||
if (header.version != DtTileCacheSetHeader.TILECACHESET_VERSION_RECAST4J)
|
||||
{
|
||||
throw new IOException("Invalid version");
|
||||
}
|
||||
}
|
||||
|
||||
bool cCompatibility = header.version == DtTileCacheSetHeader.TILECACHESET_VERSION;
|
||||
header.numTiles = bb.GetInt();
|
||||
header.meshParams = paramReader.Read(bb);
|
||||
header.cacheParams = ReadCacheParams(bb, cCompatibility);
|
||||
DtNavMesh mesh = new DtNavMesh(header.meshParams, maxVertPerPoly);
|
||||
IRcCompressor comp = _compFactory.Create(cCompatibility ? 0 : 1);
|
||||
DtTileCacheStorageParams storageParams = new DtTileCacheStorageParams(bb.Order(), cCompatibility);
|
||||
DtTileCache tc = new DtTileCache(header.cacheParams, storageParams, mesh, comp, meshProcessor);
|
||||
// Read tiles.
|
||||
for (int i = 0; i < header.numTiles; ++i)
|
||||
{
|
||||
long tileRef = bb.GetInt();
|
||||
int dataSize = bb.GetInt();
|
||||
if (tileRef == 0 || dataSize == 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
|
||||
byte[] data = bb.ReadBytes(dataSize).ToArray();
|
||||
long tile = tc.AddTile(data, 0);
|
||||
if (tile != 0)
|
||||
{
|
||||
tc.BuildNavMeshTile(tile);
|
||||
}
|
||||
}
|
||||
|
||||
return tc;
|
||||
}
|
||||
|
||||
private DtTileCacheParams ReadCacheParams(RcByteBuffer bb, bool cCompatibility)
|
||||
{
|
||||
DtTileCacheParams option = new DtTileCacheParams();
|
||||
|
||||
option.orig.X = bb.GetFloat();
|
||||
option.orig.Y = bb.GetFloat();
|
||||
option.orig.Z = bb.GetFloat();
|
||||
|
||||
option.cs = bb.GetFloat();
|
||||
option.ch = bb.GetFloat();
|
||||
option.width = bb.GetInt();
|
||||
option.height = bb.GetInt();
|
||||
option.walkableHeight = bb.GetFloat();
|
||||
option.walkableRadius = bb.GetFloat();
|
||||
option.walkableClimb = bb.GetFloat();
|
||||
option.maxSimplificationError = bb.GetFloat();
|
||||
option.maxTiles = bb.GetInt();
|
||||
option.maxObstacles = bb.GetInt();
|
||||
return option;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 046dadf784bc4db49d606f42d0cfe3f3
|
||||
timeCreated: 1715335343
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
|
||||
recast4j copyright (c) 2015-2019 Piotr Piastucki piotr@jtilia.org
|
||||
DotRecast Copyright (c) 2023 Choi Ikpil ikpil@naver.com
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
namespace DotRecast.Detour.TileCache.Io
|
||||
{
|
||||
public struct DtTileCacheSetHeader
|
||||
{
|
||||
public const int TILECACHESET_MAGIC = 'T' << 24 | 'S' << 16 | 'E' << 8 | 'T'; // 'TSET';
|
||||
public const int TILECACHESET_VERSION = 1;
|
||||
public const int TILECACHESET_VERSION_RECAST4J = 0x8801;
|
||||
|
||||
public int magic;
|
||||
public int version;
|
||||
public int numTiles;
|
||||
public DtNavMeshParams meshParams;
|
||||
public DtTileCacheParams cacheParams;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5ab42f38fa074d788433d07508edebf1
|
||||
timeCreated: 1715335343
|
||||
@@ -0,0 +1,91 @@
|
||||
/*
|
||||
Copyright (c) 2009-2010 Mikko Mononen memon@inside.org
|
||||
recast4j copyright (c) 2015-2019 Piotr Piastucki piotr@jtilia.org
|
||||
DotRecast Copyright (c) 2023 Choi Ikpil ikpil@naver.com
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
arising from the use of this software.
|
||||
Permission is granted to anyone to use this software for any purpose,
|
||||
including commercial applications, and to alter it and redistribute it
|
||||
freely, subject to the following restrictions:
|
||||
1. The origin of this software must not be misrepresented; you must not
|
||||
claim that you wrote the original software. If you use this software
|
||||
in a product, an acknowledgment in the product documentation would be
|
||||
appreciated but is not required.
|
||||
2. Altered source versions must be plainly marked as such, and must not be
|
||||
misrepresented as being the original software.
|
||||
3. This notice may not be removed or altered from any source distribution.
|
||||
*/
|
||||
|
||||
using System.IO;
|
||||
using DotRecast.Core;
|
||||
using DotRecast.Detour.Io;
|
||||
using DotRecast.Detour.TileCache.Io.Compress;
|
||||
|
||||
namespace DotRecast.Detour.TileCache.Io
|
||||
{
|
||||
public class DtTileCacheWriter : DtWriter
|
||||
{
|
||||
private readonly DtNavMeshParamWriter paramWriter = new DtNavMeshParamWriter();
|
||||
private readonly DtTileCacheBuilder builder = new DtTileCacheBuilder();
|
||||
private readonly IDtTileCacheCompressorFactory _compFactory;
|
||||
|
||||
public DtTileCacheWriter(IDtTileCacheCompressorFactory compFactory)
|
||||
{
|
||||
_compFactory = compFactory;
|
||||
}
|
||||
|
||||
|
||||
public void Write(BinaryWriter stream, DtTileCache cache, RcByteOrder order, bool cCompatibility)
|
||||
{
|
||||
Write(stream, DtTileCacheSetHeader.TILECACHESET_MAGIC, order);
|
||||
Write(stream, cCompatibility
|
||||
? DtTileCacheSetHeader.TILECACHESET_VERSION
|
||||
: DtTileCacheSetHeader.TILECACHESET_VERSION_RECAST4J, order);
|
||||
int numTiles = 0;
|
||||
for (int i = 0; i < cache.GetTileCount(); ++i)
|
||||
{
|
||||
DtCompressedTile tile = cache.GetTile(i);
|
||||
if (tile == null || tile.data == null)
|
||||
continue;
|
||||
numTiles++;
|
||||
}
|
||||
|
||||
Write(stream, numTiles, order);
|
||||
paramWriter.Write(stream, cache.GetNavMesh().GetParams(), order);
|
||||
WriteCacheParams(stream, cache.GetParams(), order);
|
||||
for (int i = 0; i < cache.GetTileCount(); i++)
|
||||
{
|
||||
DtCompressedTile tile = cache.GetTile(i);
|
||||
if (tile == null || tile.data == null)
|
||||
continue;
|
||||
Write(stream, (int)cache.GetTileRef(tile), order);
|
||||
byte[] data = tile.data;
|
||||
DtTileCacheLayer layer = cache.DecompressTile(tile);
|
||||
var comp = _compFactory.Create(cCompatibility ? 0 : 1);
|
||||
data = builder.CompressTileCacheLayer(comp, layer, order, cCompatibility);
|
||||
Write(stream, data.Length, order);
|
||||
stream.Write(data);
|
||||
}
|
||||
}
|
||||
|
||||
private void WriteCacheParams(BinaryWriter stream, DtTileCacheParams option, RcByteOrder order)
|
||||
{
|
||||
Write(stream, option.orig.X, order);
|
||||
Write(stream, option.orig.Y, order);
|
||||
Write(stream, option.orig.Z, order);
|
||||
|
||||
Write(stream, option.cs, order);
|
||||
Write(stream, option.ch, order);
|
||||
Write(stream, option.width, order);
|
||||
Write(stream, option.height, order);
|
||||
Write(stream, option.walkableHeight, order);
|
||||
Write(stream, option.walkableRadius, order);
|
||||
Write(stream, option.walkableClimb, order);
|
||||
Write(stream, option.maxSimplificationError, order);
|
||||
Write(stream, option.maxTiles, order);
|
||||
Write(stream, option.maxObstacles, order);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 19bea2de84384db295c95cfeefb31867
|
||||
timeCreated: 1715335343
|
||||
Reference in New Issue
Block a user