diff --git a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Core/Compression/FastLZ.cs b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Core/Compression/FastLZ.cs index 2afd6aa..c56d4b9 100644 --- a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Core/Compression/FastLZ.cs +++ b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Core/Compression/FastLZ.cs @@ -1,693 +1,663 @@ /* - * Copyright 2014 The Netty Project - * - * The Netty Project licenses this file to you under the Apache License, - * version 2.0 (the "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at: - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT - * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the - * License for the specific language governing permissions and limitations - * under the License. - */ + FastLZ - Byte-aligned LZ77 compression library + Copyright (C) 2005-2020 Ariya Hidayat + Copyright (C) 2023 Choi Ikpil https://github.com/ikpil/DotFastLZ + + 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: + + The above copyright notice and this permission notice shall be included in + all copies or substantial portions of the Software. + + 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. +*/ using System; namespace DotRecast.Core.Compression { - /** - * Core of FastLZ compression algorithm. - * - * This class provides methods for compression and decompression of buffers and saves - * constants which use by FastLzFrameEncoder and FastLzFrameDecoder. - * - * This is refactored code of jfastlz - * library written by William Kinney. - */ public static class FastLZ { - private const int MAX_DISTANCE = 8191; - private const int MAX_FARDISTANCE = 65535 + MAX_DISTANCE - 1; + public const int FASTLZ_VERSION = 0x000500; + public const int FASTLZ_VERSION_MAJOR = 0; + public const int FASTLZ_VERSION_MINOR = 5; + public const int FASTLZ_VERSION_REVISION = 0; + public const string FASTLZ_VERSION_STRING = "0.5.0"; + + public const int MAX_COPY = 32; + public const int MAX_LEN = 264; /* 256 + 8 */ + public const int MAX_L1_DISTANCE = 8192; + public const int MAX_L2_DISTANCE = 8191; + public const int MAX_FARDISTANCE = (65535 + MAX_L2_DISTANCE - 1); + public const int HASH_LOG = 13; + public const int HASH_SIZE = (1 << HASH_LOG); + public const int HASH_MASK = (HASH_SIZE - 1); - private const int HASH_LOG = 13; - private const int HASH_SIZE = 1 << HASH_LOG; // 8192 - private const int HASH_MASK = HASH_SIZE - 1; + /** + Compress a block of data in the input buffer and returns the size of + compressed block. The size of input buffer is specified by length. The + minimum input buffer size is 16. - private const int MAX_COPY = 32; - private const int MAX_LEN = 256 + 8; + The output buffer must be at least 5% larger than the input buffer + and can not be smaller than 66 bytes. - private const int MIN_RECOMENDED_LENGTH_FOR_LEVEL_2 = 1024 * 64; + If the input is not compressible, the return value might be larger than + length (input buffer size). - private const int MAGIC_NUMBER = 'F' << 16 | 'L' << 8 | 'Z'; + The input buffer and the output buffer can not overlap. - private const byte BLOCK_TYPE_NON_COMPRESSED = 0x00; - private const byte BLOCK_TYPE_COMPRESSED = 0x01; - private const byte BLOCK_WITHOUT_CHECKSUM = 0x00; - private const byte BLOCK_WITH_CHECKSUM = 0x10; + Compression level can be specified in parameter level. At the moment, + only level 1 and level 2 are supported. + Level 1 is the fastest compression and generally useful for short data. + Level 2 is slightly slower but it gives better compression ratio. - private const int OPTIONS_OFFSET = 3; - private const int CHECKSUM_OFFSET = 4; + Note that the compressed data, regardless of the level, can always be + decompressed using the function fastlz_decompress below. + */ + // fastlz_compress + public static long CompressLevel(int level, byte[] input, long length, byte[] output) + { + return CompressLevel(level, input, 0, length, output); + } - private const int MAX_CHUNK_LENGTH = 0xFFFF; + public static long CompressLevel(int level, byte[] input, long inputOffset, long length, byte[] output) + { + if (level == 1) + { + return CompressLevel1(input, inputOffset, length, output); + } - /** - * Do not call {@link #Compress(byte[], int, int, byte[], int, int)} for input buffers - * which length less than this value. - */ - private const int MIN_LENGTH_TO_COMPRESSION = 32; + if (level == 2) + { + return CompressLevel2(input, inputOffset, length, output); + } - /** - * In this case {@link #Compress(byte[], int, int, byte[], int, int)} will choose level - * automatically depending on the length of the input buffer. If length less than - * {@link #MIN_RECOMENDED_LENGTH_FOR_LEVEL_2} {@link #LEVEL_1} will be choosen, - * otherwise {@link #LEVEL_2}. - */ - private const int LEVEL_AUTO = 0; + throw new Exception($"invalid level: {level} (expected: 1 or 2)"); + } - /** - * Level 1 is the fastest compression and generally useful for short data. - */ - private const int LEVEL_1 = 1; + // fastlz1_compress + public static long CompressLevel1(byte[] input, long inputOffset, long length, byte[] output) + { + long ip = inputOffset; + long ip_start = ip; + long ip_bound = ip + length - 4; + long ip_limit = ip + length - 12 - 1; - /** - * Level 2 is slightly slower but it gives better compression ratio. - */ - private const int LEVEL_2 = 2; + long op = 0; - /** - * The output buffer must be at least 6% larger than the input buffer and can not be smaller than 66 bytes. - * @param inputLength length of input buffer - * @return Maximum output buffer length - */ - public static int CalculateOutputBufferLength(int inputLength) - { - int tempOutputLength = (int)(inputLength * 1.06); - return Math.Max(tempOutputLength, 66); - } + long[] htab = new long[HASH_SIZE]; + long seq, hash; - /** - * Compress a block of data in the input buffer and returns the size of compressed block. - * The size of input buffer is specified by length. The minimum input buffer size is 32. - * - * If the input is not compressible, the return value might be larger than length (input buffer size). - */ - public static int Compress(byte[] input, int inOffset, int inLength, - byte[] output, int outOffset, int proposedLevel) - { - int level; - if (proposedLevel == LEVEL_AUTO) - { - level = inLength < MIN_RECOMENDED_LENGTH_FOR_LEVEL_2 ? LEVEL_1 : LEVEL_2; - } - else + // Initializes hash table + for (hash = 0; hash < HASH_SIZE; ++hash) { - level = proposedLevel; + htab[hash] = 0; } - int ip = 0; - int ipBound = ip + inLength - 2; - int ipLimit = ip + inLength - 12; - - int op = 0; - - // const flzuint8* htab[HASH_SIZE]; - int[] htab = new int[HASH_SIZE]; - // const flzuint8** hslot; - int hslot; - // flzuint32 hval; - // int OK b/c address starting from 0 - int hval; - // flzuint32 copy; - // int OK b/c address starting from 0 - int copy; - - /* sanity check */ - if (inLength < 4) + // We start with literal copy + long anchor = ip; + ip += 2; + + // Main loop + while (ip < ip_limit) { - if (inLength != 0) + long refIdx; + long distance, cmp; + + // Find potential match + do { - // *op++ = length-1; - output[outOffset + op++] = (byte)(inLength - 1); - ipBound++; - while (ip <= ipBound) + seq = ReadUInt32(input, ip) & 0xffffff; + hash = Hash(seq); + refIdx = ip_start + htab[hash]; + htab[hash] = ip - ip_start; + distance = ip - refIdx; + cmp = distance < MAX_L1_DISTANCE + ? ReadUInt32(input, refIdx) & 0xffffff + : 0x1000000; + + if (ip >= ip_limit) { - output[outOffset + op++] = input[inOffset + ip++]; + break; } - return inLength + 1; + ++ip; + } while (seq != cmp); + + if (ip >= ip_limit) + { + break; + } + + --ip; + + if (ip > anchor) + { + op = Literals(ip - anchor, input, anchor, output, op); } - // else - return 0; + long len = MemCompare(input, refIdx + 3, input, ip + 3, ip_bound); + op = MatchLevel1(len, distance, output, op); + + // Update the hash at the match boundary + ip += len; + seq = ReadUInt32(input, ip); + hash = Hash(seq & 0xffffff); + htab[hash] = ip++ - ip_start; + seq >>= 8; + hash = Hash(seq); + htab[hash] = ip++ - ip_start; + + anchor = ip; } + long copy = length - anchor; + op = Literals(copy, input, anchor, output, op); + return op; + } + + // fastlz2_compress + public static long CompressLevel2(byte[] input, long inputOffset, long length, byte[] output) + { + long ip = inputOffset; + long ip_start = ip; + long ip_bound = ip + length - 4; /* because readU32 */ + long ip_limit = ip + length - 12 - 1; + + long op = 0; + + long[] htab = new long[HASH_SIZE]; + long seq, hash; + /* initializes hash table */ - // for (hslot = htab; hslot < htab + HASH_SIZE; hslot++) - for (hslot = 0; hslot < HASH_SIZE; hslot++) + for (hash = 0; hash < HASH_SIZE; ++hash) { - //*hslot = ip; - htab[hslot] = ip; + htab[hash] = 0; } /* we start with literal copy */ - copy = 2; - output[outOffset + op++] = (byte)(MAX_COPY - 1); - output[outOffset + op++] = input[inOffset + ip++]; - output[outOffset + op++] = input[inOffset + ip++]; + long anchor = ip; + ip += 2; /* main loop */ - while (ip < ipLimit) + while (ip < ip_limit) { - int refs = 0; - - long distance = 0; - - /* minimum match length */ - // flzuint32 len = 3; - // int OK b/c len is 0 and octal based - int len = 3; + long refs; + long distance, cmp; - /* comparison starting-point */ - int anchor = ip; - - bool matchLabel = false; - - /* check for a run */ - if (level == LEVEL_2) - { - //If(ip[0] == ip[-1] && FASTLZ_READU16(ip-1)==FASTLZ_READU16(ip+1)) - if (input[inOffset + ip] == input[inOffset + ip - 1] && - ReadU16(input, inOffset + ip - 1) == ReadU16(input, inOffset + ip + 1)) - { - distance = 1; - ip += 3; - refs = anchor - 1 + 3; - - /* - * goto match; - */ - matchLabel = true; - } - } - - if (!matchLabel) + /* find potential match */ + do { - /* find potential match */ - // HASH_FUNCTION(hval,ip); - hval = HashFunction(input, inOffset + ip); - // hslot = htab + hval; - hslot = hval; - // refs = htab[hval]; - refs = htab[hval]; - - /* calculate distance to the match */ - distance = anchor - refs; - - /* update hash table */ - //*hslot = anchor; - htab[hslot] = anchor; - - /* is this a match? check the first 3 bytes */ - if (distance == 0 - || (level == LEVEL_1 ? distance >= MAX_DISTANCE : distance >= MAX_FARDISTANCE) - || input[inOffset + refs++] != input[inOffset + ip++] - || input[inOffset + refs++] != input[inOffset + ip++] - || input[inOffset + refs++] != input[inOffset + ip++]) + seq = ReadUInt32(input, ip) & 0xffffff; + hash = Hash(seq); + refs = ip_start + htab[hash]; + htab[hash] = ip - ip_start; + distance = ip - refs; + cmp = distance < MAX_FARDISTANCE + ? ReadUInt32(input, refs) & 0xffffff + : 0x1000000; + + if (ip >= ip_limit) { - /* - * goto literal; - */ - output[outOffset + op++] = input[inOffset + anchor++]; - ip = anchor; - copy++; - if (copy == MAX_COPY) - { - copy = 0; - output[outOffset + op++] = (byte)(MAX_COPY - 1); - } - - continue; + break; } - if (level == LEVEL_2) - { - /* far, needs at least 5-byte match */ - if (distance >= MAX_DISTANCE) - { - if (input[inOffset + ip++] != input[inOffset + refs++] - || input[inOffset + ip++] != input[inOffset + refs++]) - { - /* - * goto literal; - */ - output[outOffset + op++] = input[inOffset + anchor++]; - ip = anchor; - copy++; - if (copy == MAX_COPY) - { - copy = 0; - output[outOffset + op++] = (byte)(MAX_COPY - 1); - } - - continue; - } - - len += 2; - } - } - } // end If(!matchLabel) + ++ip; + } while (seq != cmp); - /* - * match: - */ - /* last matched byte */ - ip = anchor + len; + if (ip >= ip_limit) + { + break; + } - /* distance is biased */ - distance--; + --ip; - if (distance == 0) + /* far, needs at least 5-byte match */ + if (distance >= MAX_L2_DISTANCE) { - /* zero distance means a run */ - //flzuint8 x = ip[-1]; - byte x = input[inOffset + ip - 1]; - while (ip < ipBound) + if (input[refs + 3] != input[ip + 3] || input[refs + 4] != input[ip + 4]) { - if (input[inOffset + refs++] != x) - { - break; - } - else - { - ip++; - } + ++ip; + continue; } } - else + + if (ip > anchor) { - for (;;) - { - /* safe because the outer check against ip limit */ - if (input[inOffset + refs++] != input[inOffset + ip++]) - { - break; - } + op = Literals(ip - anchor, input, anchor, output, op); + } - if (input[inOffset + refs++] != input[inOffset + ip++]) - { - break; - } + long len = MemCompare(input, refs + 3, input, ip + 3, ip_bound); + op = MatchLevel2(len, distance, output, op); - if (input[inOffset + refs++] != input[inOffset + ip++]) - { - break; - } + /* update the hash at match boundary */ + ip += len; + seq = ReadUInt32(input, ip); + hash = Hash(seq & 0xffffff); + htab[hash] = ip++ - ip_start; + seq >>= 8; + hash = Hash(seq); + htab[hash] = ip++ - ip_start; + + anchor = ip; + } - if (input[inOffset + refs++] != input[inOffset + ip++]) - { - break; - } + long copy = length - anchor; + op = Literals(copy, input, anchor, output, op); - if (input[inOffset + refs++] != input[inOffset + ip++]) - { - break; - } + /* marker for fastlz2 */ + output[inputOffset] |= (1 << 5); - if (input[inOffset + refs++] != input[inOffset + ip++]) - { - break; - } + return op; + } - if (input[inOffset + refs++] != input[inOffset + ip++]) - { - break; - } + /** + Decompress a block of compressed data and returns the size of the + decompressed block. If error occurs, e.g. the compressed data is + corrupted or the output buffer is not large enough, then 0 (zero) + will be returned instead. + + The input buffer and the output buffer can not overlap. + + Decompression is memory safe and guaranteed not to write the output buffer + more than what is specified in maxout. + + Note that the decompression will always work, regardless of the + compression level specified in fastlz_compress_level above (when + producing the compressed block). + */ + // fastlz_decompress + public static long Decompress(byte[] input, long length, byte[] output, long maxout) + { + return Decompress(input, 0, length, output, 0, maxout); + } - if (input[inOffset + refs++] != input[inOffset + ip++]) - { - break; - } + public static long Decompress(byte[] input, long inputOffset, long length, byte[] output, long outputOffset, long maxout) + { + /* magic identifier for compression level */ + int level = (input[inputOffset] >> 5) + 1; - while (ip < ipBound) - { - if (input[inOffset + refs++] != input[inOffset + ip++]) - { - break; - } - } + if (level == 1) + { + return DecompressLevel1(input, inputOffset, length, output, outputOffset, maxout); + } - break; - } - } + if (level == 2) + { + return DecompressLevel2(input, inputOffset, length, output, outputOffset, maxout); + } - /* if we have copied something, adjust the copy count */ - if (copy != 0) - { - /* copy is biased, '0' means 1 byte copy */ - // *(op-copy-1) = copy-1; - output[outOffset + op - copy - 1] = (byte)(copy - 1); - } - else - { - /* back, to overwrite the copy count */ - op--; - } + throw new Exception($"invalid level: {level} (expected: 1 or 2)"); + } - /* reset literal counter */ - copy = 0; + // fastlz1_decompress + public static long DecompressLevel1(byte[] input, long inputOffset, long length, byte[] output, long outputOffset, long maxout) + { + long ip = inputOffset; + long ip_limit = ip + length; + long ip_bound = ip_limit - 2; - /* length is biased, '1' means a match of 3 bytes */ - ip -= 3; - len = ip - anchor; + long op = outputOffset; + long op_limit = op + maxout; + long ctrl = input[ip++] & 31; - /* encode the match */ - if (level == LEVEL_2) + while (true) + { + if (ctrl >= 32) { - if (distance < MAX_DISTANCE) + long len = (ctrl >> 5) - 1; + long ofs = (ctrl & 31) << 8; + long refs = op - ofs - 1; + if (len == 7 - 1) { - if (len < 7) + if (!(ip <= ip_bound)) { - output[outOffset + op++] = (byte)((len << 5) + (int)((ulong)distance >> 8)); - output[outOffset + op++] = (byte)(distance & 255); + return 0; } - else - { - output[outOffset + op++] = (byte)((7 << 5) + ((ulong)distance >> 8)); - for (len -= 7; len >= 255; len -= 255) - { - output[outOffset + op++] = (byte)255; - } - output[outOffset + op++] = (byte)len; - output[outOffset + op++] = (byte)(distance & 255); - } + len += input[ip++]; } - else + + refs -= input[ip++]; + len += 3; + if (!(op + len <= op_limit)) { - /* far away, but not yet in the another galaxy... */ - if (len < 7) - { - distance -= MAX_DISTANCE; - output[outOffset + op++] = (byte)((len << 5) + 31); - output[outOffset + op++] = (byte)255; - output[outOffset + op++] = (byte)((ulong)distance >> 8); - output[outOffset + op++] = (byte)(distance & 255); - } - else - { - distance -= MAX_DISTANCE; - output[outOffset + op++] = (byte)((7 << 5) + 31); - for (len -= 7; len >= 255; len -= 255) - { - output[outOffset + op++] = (byte)255; - } + return 0; + } - output[outOffset + op++] = (byte)len; - output[outOffset + op++] = (byte)255; - output[outOffset + op++] = (byte)((ulong)distance >> 8); - output[outOffset + op++] = (byte)(distance & 255); - } + if (!(refs >= outputOffset)) + { + return 0; } + + MemMove(output, op, output, refs, len); + op += len; } else { - if (len > MAX_LEN - 2) + ctrl++; + if (!(op + ctrl <= op_limit)) { - while (len > MAX_LEN - 2) - { - output[outOffset + op++] = (byte)((7 << 5) + ((ulong)distance >> 8)); - output[outOffset + op++] = (byte)(MAX_LEN - 2 - 7 - 2); - output[outOffset + op++] = (byte)(distance & 255); - len -= MAX_LEN - 2; - } + return 0; } - if (len < 7) + if (!(ip + ctrl <= ip_limit)) { - output[outOffset + op++] = (byte)((len << 5) + (int)((ulong)distance >> 8)); - output[outOffset + op++] = (byte)(distance & 255); - } - else - { - output[outOffset + op++] = (byte)((7 << 5) + (int)((ulong)distance >> 8)); - output[outOffset + op++] = (byte)(len - 7); - output[outOffset + op++] = (byte)(distance & 255); + return 0; } - } - /* update the hash at match boundary */ - //HASH_FUNCTION(hval,ip); - hval = HashFunction(input, inOffset + ip); - htab[hval] = ip++; - - //HASH_FUNCTION(hval,ip); - hval = HashFunction(input, inOffset + ip); - htab[hval] = ip++; - - /* assuming literal copy */ - output[outOffset + op++] = (byte)(MAX_COPY - 1); - - continue; - - // Moved to be inline, with a 'continue' - /* - * literal: - * - output[outOffset + op++] = input[inOffset + anchor++]; - ip = anchor; - copy++; - If(copy == MAX_COPY){ - copy = 0; - output[outOffset + op++] = MAX_COPY-1; - } - */ - } + Array.Copy(input, ip, output, op, ctrl); + ip += ctrl; + op += ctrl; + } - /* left-over as literal copy */ - ipBound++; - while (ip <= ipBound) - { - output[outOffset + op++] = input[inOffset + ip++]; - copy++; - if (copy == MAX_COPY) + if (ip > ip_bound) { - copy = 0; - output[outOffset + op++] = (byte)(MAX_COPY - 1); + break; } - } - /* if we have copied something, adjust the copy length */ - if (copy != 0) - { - //*(op-copy-1) = copy-1; - output[outOffset + op - copy - 1] = (byte)(copy - 1); - } - else - { - op--; - } - - if (level == LEVEL_2) - { - /* marker for fastlz2 */ - output[outOffset] |= 1 << 5; + ctrl = input[ip++]; } return op; } - /** - * Decompress a block of compressed data and returns the size of the decompressed block. - * If error occurs, e.g. the compressed data is corrupted or the output buffer is not large - * enough, then 0 (zero) will be returned instead. - * - * Decompression is memory safe and guaranteed not to write the output buffer - * more than what is specified in outLength. - */ - public static int Decompress(byte[] input, int inOffset, int inLength, - byte[] output, int outOffset, int outLength) + // fastlz2_decompress + public static long DecompressLevel2(byte[] input, long inputOffset, long length, byte[] output, long outputOffset, long maxout) { - //int level = ((*(const flzuint8*)input) >> 5) + 1; - int level = (input[inOffset] >> 5) + 1; - if (level != LEVEL_1 && level != LEVEL_2) - { - throw new Exception($"invalid level: {level} (expected: {LEVEL_1} or {LEVEL_2})"); - } + long ip = inputOffset; + long ip_limit = ip + length; + long ip_bound = ip_limit - 2; - // const flzuint8* ip = (const flzuint8*) input; - int ip = 0; - // flzuint8* op = (flzuint8*) output; - int op = 0; - // flzuint32 ctrl = (*ip++) & 31; - long ctrl = input[inOffset + ip++] & 31; + long op = outputOffset; + long op_limit = op + maxout; + long ctrl = input[ip++] & 31; - int loop = 1; - do + while (true) { - // const flzuint8* refs = op; - int refs = op; - // flzuint32 len = ctrl >> 5; - long len = ctrl >> 5; - // flzuint32 ofs = (ctrl & 31) << 8; - long ofs = (ctrl & 31) << 8; - if (ctrl >= 32) { - len--; - // refs -= ofs; - refs -= (int)ofs; + long len = (ctrl >> 5) - 1; + long ofs = (ctrl & 31) << 8; + long refIdx = op - ofs - 1; - int code; - if (len == 6) + long code; + if (len == 7 - 1) { - if (level == LEVEL_1) - { - // len += *ip++; - len += input[inOffset + ip++] & 0xFF; - } - else + do { - do + if (!(ip <= ip_bound)) { - code = input[inOffset + ip++] & 0xFF; - len += code; - } while (code == 255); - } - } + return 0; + } - if (level == LEVEL_1) - { - // refs -= *ip++; - refs -= input[inOffset + ip++] & 0xFF; + code = input[ip++]; + len += code; + } while (code == 255); } - else - { - code = input[inOffset + ip++] & 0xFF; - refs -= code; - /* match from 16-bit distance */ - // If(FASTLZ_UNEXPECT_CONDITIONAL(code==255)) - // If(FASTLZ_EXPECT_CONDITIONAL(ofs==(31 << 8))) - if (code == 255 && ofs == 31 << 8) + code = input[ip++]; + refIdx -= code; + len += 3; + + /* match from 16-bit distance */ + if (code == 255) + { + if (ofs == (31 << 8)) { - ofs = (input[inOffset + ip++] & 0xFF) << 8; - ofs += input[inOffset + ip++] & 0xFF; + if (!(ip < ip_bound)) + { + return 0; + } - refs = (int)(op - ofs - MAX_DISTANCE); + ofs = input[ip++] << 8; + ofs += input[ip++]; + refIdx = op - ofs - MAX_L2_DISTANCE - 1; } } - // if the output index + length of Block(?) + 3(?) is over the output limit? - if (op + len + 3 > outLength) + if (!(op + len <= op_limit)) { return 0; } - // if (FASTLZ_UNEXPECT_CONDITIONAL(refs-1 < (flzuint8 *)output)) - // if the address space of refs-1 is < the address of output? - // if we are still at the beginning of the output address? - if (refs - 1 < 0) + if (!(refIdx >= outputOffset)) { return 0; } - if (ip < inLength) - { - ctrl = input[inOffset + ip++] & 0xFF; - } - else - { - loop = 0; - } - - if (refs == op) - { - /* optimize copy for a run */ - // flzuint8 b = refs[-1]; - byte b = output[outOffset + refs - 1]; - output[outOffset + op++] = b; - output[outOffset + op++] = b; - output[outOffset + op++] = b; - while (len != 0) - { - output[outOffset + op++] = b; - --len; - } - } - else - { - /* copy from reference */ - refs--; - - // *op++ = *refs++; - output[outOffset + op++] = output[outOffset + refs++]; - output[outOffset + op++] = output[outOffset + refs++]; - output[outOffset + op++] = output[outOffset + refs++]; - - while (len != 0) - { - output[outOffset + op++] = output[outOffset + refs++]; - --len; - } - } + MemMove(output, op, output, refIdx, len); + op += len; } else { ctrl++; - - if (op + ctrl > outLength) + if (!(op + ctrl <= op_limit)) { return 0; } - if (ip + ctrl > inLength) + if (!(ip + ctrl <= ip_limit)) { return 0; } - //*op++ = *ip++; - output[outOffset + op++] = input[inOffset + ip++]; + Array.Copy(input, ip, output, op, ctrl); + ip += ctrl; + op += ctrl; + } + + if (ip >= ip_limit) + { + break; + } + + ctrl = input[ip++]; + } + + return op; + } + + // flz_readu32 + public static uint ReadUInt32(byte[] data, long offset) + { + return ((uint)data[offset + 3] & 0xff) << 24 | + ((uint)data[offset + 2] & 0xff) << 16 | + ((uint)data[offset + 1] & 0xff) << 8 | + ((uint)data[offset + 0] & 0xff); + } + + public static ushort ReadUInt16(byte[] data, long offset) + { + var u16 = ((uint)data[offset + 1] << 8) | + ((uint)data[offset + 0]); + return (ushort)u16; + } - for (--ctrl; ctrl != 0; ctrl--) + // flz_hash + public static ushort Hash(long v) + { + ulong h = ((ulong)v * 2654435769UL) >> (32 - HASH_LOG); + return (ushort)(h & HASH_MASK); + } + + // special case of memcpy: at most MAX_COPY bytes + // flz_smallcopy + public static void SmallCopy(byte[] dest, long destOffset, byte[] src, long srcOffset, long count) + { + // if (count >= 4) + // { + // count -= count % 4; + // Array.Copy(src, srcOffset, dest, destOffset, count); + // } + Array.Copy(src, srcOffset, dest, destOffset, count); + } + + // special case of memcpy: exactly MAX_COPY bytes + // flz_maxcopy + static void MaxCopy(byte[] dest, long destOffset, byte[] src, long secOffset) + { + Array.Copy(src, secOffset, dest, destOffset, MAX_COPY); + } + + // flz_literals + public static long Literals(long runs, byte[] src, long srcOffset, byte[] dest, long destOffset) + { + while (runs >= MAX_COPY) + { + dest[destOffset++] = MAX_COPY - 1; + MaxCopy(dest, destOffset, src, srcOffset); + srcOffset += MAX_COPY; + destOffset += MAX_COPY; + runs -= MAX_COPY; + } + + if (runs > 0) + { + dest[destOffset++] = (byte)(runs - 1); + SmallCopy(dest, destOffset, src, srcOffset, runs); + destOffset += runs; + } + + return destOffset; + } + + // flz1_match + public static long MatchLevel1(long len, long distance, byte[] output, long op) + { + --distance; + if (len > MAX_LEN - 2) + { + while (len > MAX_LEN - 2) + { + output[op++] = (byte)((7 << 5) + (distance >> 8)); + output[op++] = (byte)(MAX_LEN - 2 - 7 - 2); + output[op++] = (byte)(distance & 255); + len -= MAX_LEN - 2; + } + } + + if (len < 7) + { + output[op++] = (byte)((len << 5) + (distance >> 8)); + output[op++] = (byte)(distance & 255); + } + else + { + output[op++] = (byte)((7 << 5) + (distance >> 8)); + output[op++] = (byte)(len - 7); + output[op++] = (byte)((distance & 255)); + } + + return op; + } + + // flz2_match + public static long MatchLevel2(long len, long distance, byte[] output, long op) + { + --distance; + if (distance < MAX_L2_DISTANCE) + { + if (len < 7) + { + output[op++] = (byte)((len << 5) + (distance >> 8)); + output[op++] = (byte)((distance & 255)); + } + else + { + output[op++] = (byte)((7 << 5) + (distance >> 8)); + for (len -= 7; len >= 255; len -= 255) { - // *op++ = *ip++; - output[outOffset + op++] = input[inOffset + ip++]; + output[op++] = 255; } - loop = ip < inLength ? 1 : 0; - if (loop != 0) + output[op++] = (byte)(len); + output[op++] = (byte)((distance & 255)); + } + } + else + { + /* far away, but not yet in the another galaxy... */ + if (len < 7) + { + distance -= MAX_L2_DISTANCE; + output[op++] = (byte)((len << 5) + 31); + output[op++] = (byte)(255); + output[op++] = (byte)(distance >> 8); + output[op++] = (byte)(distance & 255); + } + else + { + distance -= MAX_L2_DISTANCE; + output[op++] = (7 << 5) + 31; + for (len -= 7; len >= 255; len -= 255) { - // ctrl = *ip++; - ctrl = input[inOffset + ip++] & 0xFF; + output[op++] = 255; } - } - // While(FASTLZ_EXPECT_CONDITIONAL(loop)); - } while (loop != 0); + output[op++] = (byte)(len); + output[op++] = (byte)(255); + output[op++] = (byte)(distance >> 8); + output[op++] = (byte)(distance & 255); + } + } - // return op - (flzuint8*)output; return op; } - private static int HashFunction(byte[] p, int offset) + // flz_cmp + public static long MemCompare(byte[] p, long pOffset, byte[] q, long qOffset, long r) { - int v = ReadU16(p, offset); - v ^= ReadU16(p, offset + 1) ^ v >> 16 - HASH_LOG; - v &= HASH_MASK; - return v; + long start = pOffset; + + if (4 <= r && ReadUInt32(p, pOffset) == ReadUInt32(q, qOffset)) + { + pOffset += 4; + qOffset += 4; + } + + while (qOffset < r) + { + if (p[pOffset++] != q[qOffset++]) + break; + } + + return pOffset - start; } - private static int ReadU16(byte[] data, int offset) + // fastlz_memmove + public static void MemMove(byte[] dest, long destOffset, byte[] src, long srcOffset, long count) { - if (offset + 1 >= data.Length) + if (dest.Length < destOffset + count) { - return data[offset] & 0xff; + throw new IndexOutOfRangeException($"{dest.Length} < {destOffset} + {count}"); } - return (data[offset + 1] & 0xff) << 8 | data[offset] & 0xff; + if (src.Length < srcOffset + count) + { + throw new IndexOutOfRangeException($"{src.Length} < {srcOffset} + {count}"); + } + + for (long i = 0; i < count; ++i) + { + dest[destOffset + i] = src[srcOffset + i]; + } + } + + public static long EstimateCompressedSize(long size) + { + long estimatedSize = (long)Math.Ceiling(size * 1.06f); + return Math.Max(estimatedSize, 66); } } } \ No newline at end of file diff --git a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Core/RcArrayUtils.cs b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Core/RcArrayUtils.cs index b308de0..1961251 100644 --- a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Core/RcArrayUtils.cs +++ b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Core/RcArrayUtils.cs @@ -15,7 +15,7 @@ public static T[] CopyOf(T[] source, int startIdx, int length) return deatArr; } - public static T[] CopyOf(T[] source, int length) + public static T[] CopyOf(T[] source, long length) { var deatArr = new T[length]; var count = Math.Max(0, Math.Min(source.Length, length)); diff --git a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Core/Intersections.cs b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Core/RcIntersections.cs similarity index 97% rename from src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Core/Intersections.cs rename to src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Core/RcIntersections.cs index 8ec2ab7..bfe0b59 100644 --- a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Core/Intersections.cs +++ b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Core/RcIntersections.cs @@ -1,4 +1,5 @@ /* +Copyright (c) 2009-2010 Mikko Mononen memon@inside.org recast4j copyright (c) 2021 Piotr Piastucki piotr@jtilia.org DotRecast Copyright (c) 2023 Choi Ikpil ikpil@naver.com @@ -21,7 +22,7 @@ 3. This notice may not be removed or altered from any source distribution. namespace DotRecast.Core { - public static class Intersections + public static class RcIntersections { public static bool IntersectSegmentTriangle(RcVec3f sp, RcVec3f sq, RcVec3f a, RcVec3f b, RcVec3f c, out float t) { diff --git a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Core/RcMatrix4x4f.cs b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Core/RcMatrix4x4f.cs index 65f90f0..a6287a9 100644 --- a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Core/RcMatrix4x4f.cs +++ b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Core/RcMatrix4x4f.cs @@ -1,4 +1,5 @@ using System; +using System.Runtime.CompilerServices; namespace DotRecast.Core { @@ -107,6 +108,7 @@ public void CopyTo(float[] m) M31 == 0f && M32 == 0f && M34 == 0f && M41 == 0f && M42 == 0f && M43 == 0f; + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static RcMatrix4x4f Mul(ref RcMatrix4x4f left, ref RcMatrix4x4f right) { float m11 = left.M11 * right.M11 + left.M21 * right.M12 + left.M31 * right.M13 + left.M41 * right.M14; @@ -147,6 +149,7 @@ public static RcMatrix4x4f Mul(ref RcMatrix4x4f left, ref RcMatrix4x4f right) return dest; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static RcMatrix4x4f Mul(float[] left, float[] right) { float m00 = left[0] * right[0] + left[4] * right[1] + left[8] * right[2] + left[12] * right[3]; @@ -174,6 +177,7 @@ public static RcMatrix4x4f Mul(float[] left, float[] right) ); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static RcMatrix4x4f CreateFromRotate(float a, float x, float y, float z) { var matrix = new RcMatrix4x4f(); diff --git a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Core/FRand.cs b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Core/RcRand.cs similarity index 78% rename from src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Core/FRand.cs rename to src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Core/RcRand.cs index c57c563..c1fc36b 100644 --- a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Core/FRand.cs +++ b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Core/RcRand.cs @@ -2,16 +2,16 @@ namespace DotRecast.Core { - public class FRand : IRcRand + public class RcRand : IRcRand { private readonly Random _r; - public FRand() + public RcRand() { _r = new Random(); } - public FRand(long seed) + public RcRand(long seed) { _r = new Random((int)seed); // TODO : 랜덤 시드 확인 필요 } diff --git a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Core/RcVec3f.cs b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Core/RcVec3f.cs index 9092892..1c1d4f0 100644 --- a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Core/RcVec3f.cs +++ b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Core/RcVec3f.cs @@ -554,11 +554,13 @@ public static bool IsFinite2D(RcVec3f v) } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Copy(ref RcVec3f @out, float[] @in, int i) { Copy(ref @out, 0, @in, i); } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Copy(float[] @out, int n, float[] @in, int m) { @out[n] = @in[m]; @@ -566,6 +568,7 @@ public static void Copy(float[] @out, int n, float[] @in, int m) @out[n + 2] = @in[m + 2]; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Copy(float[] @out, int n, RcVec3f @in, int m) { @out[n] = @in[m]; @@ -573,6 +576,7 @@ public static void Copy(float[] @out, int n, RcVec3f @in, int m) @out[n + 2] = @in[m + 2]; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Copy(ref RcVec3f @out, int n, float[] @in, int m) { @out[n] = @in[m]; @@ -580,6 +584,7 @@ public static void Copy(ref RcVec3f @out, int n, float[] @in, int m) @out[n + 2] = @in[m + 2]; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Add(ref RcVec3f e0, RcVec3f a, float[] verts, int i) { e0.x = a.x + verts[i]; @@ -588,6 +593,7 @@ public static void Add(ref RcVec3f e0, RcVec3f a, float[] verts, int i) } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Sub(ref RcVec3f e0, float[] verts, int i, int j) { e0.x = verts[i] - verts[j]; @@ -596,6 +602,7 @@ public static void Sub(ref RcVec3f e0, float[] verts, int i, int j) } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Sub(ref RcVec3f e0, RcVec3f i, float[] verts, int j) { e0.x = i.x - verts[j]; @@ -604,6 +611,7 @@ public static void Sub(ref RcVec3f e0, RcVec3f i, float[] verts, int j) } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Cross(float[] dest, float[] v1, float[] v2) { dest[0] = v1[1] * v2[2] - v1[2] * v2[1]; @@ -611,6 +619,7 @@ public static void Cross(float[] dest, float[] v1, float[] v2) dest[2] = v1[0] * v2[1] - v1[1] * v2[0]; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Cross(float[] dest, RcVec3f v1, RcVec3f v2) { dest[0] = v1.y * v2.z - v1.z * v2.y; @@ -618,6 +627,7 @@ public static void Cross(float[] dest, RcVec3f v1, RcVec3f v2) dest[2] = v1.x * v2.y - v1.y * v2.x; } + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Cross(ref RcVec3f dest, RcVec3f v1, RcVec3f v2) { dest.x = v1.y * v2.z - v1.z * v2.y; @@ -626,14 +636,7 @@ public static void Cross(ref RcVec3f dest, RcVec3f v1, RcVec3f v2) } - public static void Normalize(float[] v) - { - float d = (float)(1.0f / Math.Sqrt(v[0] * v[0] + v[1] * v[1] + v[2] * v[2])); - v[0] *= d; - v[1] *= d; - v[2] *= d; - } - + [MethodImpl(MethodImplOptions.AggressiveInlining)] public static void Normalize(ref RcVec3f v) { float d = (float)(1.0f / Math.Sqrt(v.x * v.x + v.y * v.y + v.z * v.z)); diff --git a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour.Crowd/DtCrowdAgent.cs b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour.Crowd/DtCrowdAgent.cs index 67e8267..060003e 100644 --- a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour.Crowd/DtCrowdAgent.cs +++ b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour.Crowd/DtCrowdAgent.cs @@ -76,7 +76,7 @@ public class DtCrowdAgent public DtCrowdAgentParams option; /// The local path corridor corners for the agent. - public List corners = new List(); + public List corners = new List(); public DtMoveRequestState targetState; diff --git a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour.Crowd/DtPathCorridor.cs b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour.Crowd/DtPathCorridor.cs index d77ace4..9166541 100644 --- a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour.Crowd/DtPathCorridor.cs +++ b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour.Crowd/DtPathCorridor.cs @@ -114,14 +114,14 @@ public void Reset(long refs, RcVec3f pos) * @param[in] navquery The query object used to build the corridor. * @return Corners */ - public int FindCorners(ref List corners, int maxCorners, DtNavMeshQuery navquery, IDtQueryFilter filter) + public int FindCorners(ref List corners, int maxCorners, DtNavMeshQuery navquery, IDtQueryFilter filter) { var result = navquery.FindStraightPath(m_pos, m_target, m_path, ref corners, maxCorners, 0); if (result.Succeeded()) { // Prune points in the beginning of the path which are too close. int start = 0; - foreach (StraightPathItem spi in corners) + foreach (DtStraightPath spi in corners) { if ((spi.flags & DtNavMeshQuery.DT_STRAIGHTPATH_OFFMESH_CONNECTION) != 0 || RcVec3f.Dist2DSqr(spi.pos, m_pos) > MIN_TARGET_DIST) @@ -136,7 +136,7 @@ public int FindCorners(ref List corners, int maxCorners, DtNav // Prune points after an off-mesh connection. for (int i = start; i < corners.Count; i++) { - StraightPathItem spi = corners[i]; + DtStraightPath spi = corners[i]; if ((spi.flags & DtNavMeshQuery.DT_STRAIGHTPATH_OFFMESH_CONNECTION) != 0) { end = i + 1; @@ -201,7 +201,7 @@ public void OptimizePathVisibility(RcVec3f next, float pathOptimizationRange, Dt { if (rayHit.path.Count > 1 && rayHit.t > 0.99f) { - m_path = PathUtils.MergeCorridorStartShortcut(m_path, rayHit.path); + m_path = DtPathUtils.MergeCorridorStartShortcut(m_path, rayHit.path); } } } @@ -236,7 +236,7 @@ public bool OptimizePathTopology(DtNavMeshQuery navquery, IDtQueryFilter filter, if (status.Succeeded() && res.Count > 0) { - m_path = PathUtils.MergeCorridorStartShortcut(m_path, res); + m_path = DtPathUtils.MergeCorridorStartShortcut(m_path, res); return true; } @@ -307,7 +307,7 @@ public bool MovePosition(RcVec3f npos, DtNavMeshQuery navquery, IDtQueryFilter f var status = navquery.MoveAlongSurface(m_path[0], m_pos, npos, filter, out var result, ref visited); if (status.Succeeded()) { - m_path = PathUtils.MergeCorridorStartMoved(m_path, visited); + m_path = DtPathUtils.MergeCorridorStartMoved(m_path, visited); // Adjust the position to stay on top of the navmesh. m_pos = result; @@ -347,7 +347,7 @@ public bool MoveTargetPosition(RcVec3f npos, DtNavMeshQuery navquery, IDtQueryFi var status = navquery.MoveAlongSurface(m_path[m_path.Count - 1], m_target, npos, filter, out var result, ref visited); if (status.Succeeded()) { - m_path = PathUtils.MergeCorridorEndMoved(m_path, visited); + m_path = DtPathUtils.MergeCorridorEndMoved(m_path, visited); // TODO: should we do that? // Adjust the position to stay on top of the navmesh. /* diff --git a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour.Extras/PolyUtils.cs b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour.Extras/DtPolyUtils.cs similarity index 93% rename from src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour.Extras/PolyUtils.cs rename to src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour.Extras/DtPolyUtils.cs index 37f18a5..5f11915 100644 --- a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour.Extras/PolyUtils.cs +++ b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour.Extras/DtPolyUtils.cs @@ -16,13 +16,13 @@ misrepresented as being the original software. 3. This notice may not be removed or altered from any source distribution. */ +using System; + namespace DotRecast.Detour.Extras { - public static class PolyUtils + public static class DtPolyUtils { - /** - * Find edge shared by 2 polygons within the same tile - */ + // Find edge shared by 2 polygons within the same tile public static int FindEdge(DtPoly node, DtPoly neighbour, DtMeshData tile, DtMeshData neighbourTile) { // Compare indices first assuming there are no duplicate vertices @@ -64,7 +64,7 @@ private static bool SamePosition(float[] verts, int v, float[] verts2, int v2) { for (int i = 0; i < 3; i++) { - if (verts[3 * v + i] != verts2[3 * v2 + 1]) + if (Math.Abs(verts[3 * v + i] - verts2[3 * v2 + 1]) > float.Epsilon) { return false; } @@ -73,9 +73,7 @@ private static bool SamePosition(float[] verts, int v, float[] verts2, int v2) return true; } - /** - * Find edge closest to the given coordinate - */ + // Find edge closest to the given coordinate public static int FindEdge(DtPoly node, DtMeshData tile, float value, int comp) { float error = float.MaxValue; diff --git a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour.Extras/Unity/Astar/LinkBuilder.cs b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour.Extras/Unity/Astar/LinkBuilder.cs index 8dad5eb..1107dc6 100644 --- a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour.Extras/Unity/Astar/LinkBuilder.cs +++ b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour.Extras/Unity/Astar/LinkBuilder.cs @@ -49,7 +49,7 @@ public void Build(int nodeOffset, GraphMeshData graphData, List connectio private void BuildInternalLink(DtMeshData tile, DtPoly node, DtMeshData neighbourTile, DtPoly neighbour) { - int edge = PolyUtils.FindEdge(node, neighbour, tile, neighbourTile); + int edge = DtPolyUtils.FindEdge(node, neighbour, tile, neighbourTile); if (edge >= 0) { node.neis[edge] = neighbour.index + 1; @@ -65,19 +65,19 @@ private void BuildExternalLink(DtMeshData tile, DtPoly node, DtMeshData neighbou { if (neighbourTile.header.bmin.x > tile.header.bmin.x) { - node.neis[PolyUtils.FindEdge(node, tile, neighbourTile.header.bmin.x, 0)] = DtNavMesh.DT_EXT_LINK; + node.neis[DtPolyUtils.FindEdge(node, tile, neighbourTile.header.bmin.x, 0)] = DtNavMesh.DT_EXT_LINK; } else if (neighbourTile.header.bmin.x < tile.header.bmin.x) { - node.neis[PolyUtils.FindEdge(node, tile, tile.header.bmin.x, 0)] = DtNavMesh.DT_EXT_LINK | 4; + node.neis[DtPolyUtils.FindEdge(node, tile, tile.header.bmin.x, 0)] = DtNavMesh.DT_EXT_LINK | 4; } else if (neighbourTile.header.bmin.z > tile.header.bmin.z) { - node.neis[PolyUtils.FindEdge(node, tile, neighbourTile.header.bmin.z, 2)] = DtNavMesh.DT_EXT_LINK | 2; + node.neis[DtPolyUtils.FindEdge(node, tile, neighbourTile.header.bmin.z, 2)] = DtNavMesh.DT_EXT_LINK | 2; } else { - node.neis[PolyUtils.FindEdge(node, tile, tile.header.bmin.z, 2)] = DtNavMesh.DT_EXT_LINK | 6; + node.neis[DtPolyUtils.FindEdge(node, tile, tile.header.bmin.z, 2)] = DtNavMesh.DT_EXT_LINK | 6; } } } diff --git a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour.TileCache/Io/Compress/DtTileCacheFastLzCompressor.cs b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour.TileCache/Io/Compress/DtTileCacheFastLzCompressor.cs index 4caff89..ff4c246 100644 --- a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour.TileCache/Io/Compress/DtTileCacheFastLzCompressor.cs +++ b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour.TileCache/Io/Compress/DtTileCacheFastLzCompressor.cs @@ -45,8 +45,8 @@ public byte[] Decompress(byte[] buf, int offset, int len, int outputlen) public byte[] Compress(byte[] buf) { - byte[] output = new byte[FastLZ.CalculateOutputBufferLength(buf.Length)]; - int len = FastLZ.Compress(buf, 0, buf.Length, output, 0, output.Length); + byte[] output = new byte[FastLZ.EstimateCompressedSize(buf.Length)]; + long len = FastLZ.CompressLevel(2, buf, 0, buf.Length, output); return RcArrayUtils.CopyOf(output, len); } } diff --git a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/InFlag.cs b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/DtConvexConvexInFlag.cs similarity index 70% rename from src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/InFlag.cs rename to src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/DtConvexConvexInFlag.cs index bdf29d3..cbfe2ea 100644 --- a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/InFlag.cs +++ b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/DtConvexConvexInFlag.cs @@ -1,6 +1,6 @@ namespace DotRecast.Detour { - public enum InFlag + public enum DtConvexConvexInFlag { Pin, Qin, diff --git a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/Intersection.cs b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/DtConvexConvexIntersection.cs similarity index 68% rename from src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/Intersection.cs rename to src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/DtConvexConvexIntersection.cs index 319288e..a53f8ac 100644 --- a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/Intersection.cs +++ b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/DtConvexConvexIntersection.cs @@ -1,6 +1,6 @@ namespace DotRecast.Detour { - public enum Intersection + public enum DtConvexConvexIntersection { None, Single, diff --git a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/ConvexConvexIntersection.cs b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/DtConvexConvexIntersections.cs similarity index 78% rename from src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/ConvexConvexIntersection.cs rename to src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/DtConvexConvexIntersections.cs index 2561ada..56df886 100644 --- a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/ConvexConvexIntersection.cs +++ b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/DtConvexConvexIntersections.cs @@ -25,7 +25,7 @@ namespace DotRecast.Detour /** * Convex-convex intersection based on "Computational Geometry in C" by Joseph O'Rourke */ - public static class ConvexConvexIntersection + public static class DtConvexConvexIntersections { private static readonly float EPSILON = 0.0001f; @@ -46,8 +46,8 @@ public static float[] Intersect(float[] p, float[] q) int ai = 0; int bi = 0; - InFlag f = InFlag.Unknown; - bool FirstPoint = true; + DtConvexConvexInFlag f = DtConvexConvexInFlag.Unknown; + bool firstPoint = true; RcVec3f ip = new RcVec3f(); RcVec3f iq = new RcVec3f(); @@ -70,13 +70,13 @@ public static float[] Intersect(float[] p, float[] q) } bool parallel = cross == 0f; - Intersection code = parallel ? ParallelInt(a1, a, b1, b, ref ip, ref iq) : SegSegInt(a1, a, b1, b, ref ip, ref iq); + DtConvexConvexIntersection code = parallel ? ParallelInt(a1, a, b1, b, ref ip, ref iq) : SegSegInt(a1, a, b1, b, ref ip, ref iq); - if (code == Intersection.Single) + if (code == DtConvexConvexIntersection.Single) { - if (FirstPoint) + if (firstPoint) { - FirstPoint = false; + firstPoint = false; aa = ba = 0; } @@ -87,7 +87,7 @@ public static float[] Intersect(float[] p, float[] q) /*-----Advance rules-----*/ /* Special case: A & B overlap and oppositely oriented. */ - if (code == Intersection.Overlap && A.Dot2D(B) < 0) + if (code == DtConvexConvexIntersection.Overlap && A.Dot2D(B) < 0) { ii = AddVertex(inters, ii, ip); ii = AddVertex(inters, ii, iq); @@ -103,7 +103,7 @@ public static float[] Intersect(float[] p, float[] q) else if (parallel && Math.Abs(aHB) < EPSILON && Math.Abs(bHA) < EPSILON) { /* Advance but do not output point. */ - if (f == InFlag.Pin) + if (f == DtConvexConvexInFlag.Pin) { ba++; bi++; @@ -119,7 +119,7 @@ public static float[] Intersect(float[] p, float[] q) { if (bHA > 0) { - if (f == InFlag.Pin) + if (f == DtConvexConvexInFlag.Pin) { ii = AddVertex(inters, ii, a); } @@ -129,7 +129,7 @@ public static float[] Intersect(float[] p, float[] q) } else { - if (f == InFlag.Qin) + if (f == DtConvexConvexInFlag.Qin) { ii = AddVertex(inters, ii, b); } @@ -142,7 +142,7 @@ public static float[] Intersect(float[] p, float[] q) { if (aHB > 0) { - if (f == InFlag.Qin) + if (f == DtConvexConvexInFlag.Qin) { ii = AddVertex(inters, ii, b); } @@ -152,7 +152,7 @@ public static float[] Intersect(float[] p, float[] q) } else { - if (f == InFlag.Pin) + if (f == DtConvexConvexInFlag.Pin) { ii = AddVertex(inters, ii, a); } @@ -165,7 +165,7 @@ public static float[] Intersect(float[] p, float[] q) } while ((aa < n || ba < m) && aa < 2 * n && ba < 2 * m); /* Deal with special cases: not implemented. */ - if (f == InFlag.Unknown) + if (f == DtConvexConvexInFlag.Unknown) { return null; } @@ -175,27 +175,6 @@ public static float[] Intersect(float[] p, float[] q) return copied; } - private static int AddVertex(float[] inters, int ii, float[] p) - { - if (ii > 0) - { - if (inters[ii - 3] == p[0] && inters[ii - 2] == p[1] && inters[ii - 1] == p[2]) - { - return ii; - } - - if (inters[0] == p[0] && inters[1] == p[1] && inters[2] == p[2]) - { - return ii; - } - } - - inters[ii] = p[0]; - inters[ii + 1] = p[1]; - inters[ii + 2] = p[2]; - return ii + 3; - } - private static int AddVertex(float[] inters, int ii, RcVec3f p) { if (ii > 0) @@ -218,21 +197,21 @@ private static int AddVertex(float[] inters, int ii, RcVec3f p) } - private static InFlag InOut(InFlag inflag, float aHB, float bHA) + private static DtConvexConvexInFlag InOut(DtConvexConvexInFlag inflag, float aHB, float bHA) { if (aHB > 0) { - return InFlag.Pin; + return DtConvexConvexInFlag.Pin; } else if (bHA > 0) { - return InFlag.Qin; + return DtConvexConvexInFlag.Qin; } return inflag; } - private static Intersection SegSegInt(RcVec3f a, RcVec3f b, RcVec3f c, RcVec3f d, ref RcVec3f p, ref RcVec3f q) + private static DtConvexConvexIntersection SegSegInt(RcVec3f a, RcVec3f b, RcVec3f c, RcVec3f d, ref RcVec3f p, ref RcVec3f q) { if (DtUtils.IntersectSegSeg2D(a, b, c, d, out var s, out var t)) { @@ -241,58 +220,58 @@ private static Intersection SegSegInt(RcVec3f a, RcVec3f b, RcVec3f c, RcVec3f d p.x = a.x + (b.x - a.x) * s; p.y = a.y + (b.y - a.y) * s; p.z = a.z + (b.z - a.z) * s; - return Intersection.Single; + return DtConvexConvexIntersection.Single; } } - return Intersection.None; + return DtConvexConvexIntersection.None; } - private static Intersection ParallelInt(RcVec3f a, RcVec3f b, RcVec3f c, RcVec3f d, ref RcVec3f p, ref RcVec3f q) + private static DtConvexConvexIntersection ParallelInt(RcVec3f a, RcVec3f b, RcVec3f c, RcVec3f d, ref RcVec3f p, ref RcVec3f q) { if (Between(a, b, c) && Between(a, b, d)) { p = c; q = d; - return Intersection.Overlap; + return DtConvexConvexIntersection.Overlap; } if (Between(c, d, a) && Between(c, d, b)) { p = a; q = b; - return Intersection.Overlap; + return DtConvexConvexIntersection.Overlap; } if (Between(a, b, c) && Between(c, d, b)) { p = c; q = b; - return Intersection.Overlap; + return DtConvexConvexIntersection.Overlap; } if (Between(a, b, c) && Between(c, d, a)) { p = c; q = a; - return Intersection.Overlap; + return DtConvexConvexIntersection.Overlap; } if (Between(a, b, d) && Between(c, d, b)) { p = d; q = b; - return Intersection.Overlap; + return DtConvexConvexIntersection.Overlap; } if (Between(a, b, d) && Between(c, d, a)) { p = d; q = a; - return Intersection.Overlap; + return DtConvexConvexIntersection.Overlap; } - return Intersection.None; + return DtConvexConvexIntersection.None; } private static bool Between(RcVec3f a, RcVec3f b, RcVec3f c) diff --git a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/DefaultQueryHeuristic.cs b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/DtDefaultQueryHeuristic.cs similarity index 85% rename from src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/DefaultQueryHeuristic.cs rename to src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/DtDefaultQueryHeuristic.cs index 21c2f87..9e5a222 100644 --- a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/DefaultQueryHeuristic.cs +++ b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/DtDefaultQueryHeuristic.cs @@ -22,14 +22,14 @@ 3. This notice may not be removed or altered from any source distribution. namespace DotRecast.Detour { - public class DefaultQueryHeuristic : IQueryHeuristic + public class DtDefaultQueryHeuristic : IDtQueryHeuristic { public const float H_SCALE = 0.999f; // Search heuristic scale. - public static readonly DefaultQueryHeuristic Default = new DefaultQueryHeuristic(H_SCALE); + public static readonly DtDefaultQueryHeuristic Default = new DtDefaultQueryHeuristic(H_SCALE); private readonly float scale; - public DefaultQueryHeuristic(float scale) + public DtDefaultQueryHeuristic(float scale) { this.scale = scale; } diff --git a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/DtFindPathOption.cs b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/DtFindPathOption.cs index bc130b1..7c119d9 100644 --- a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/DtFindPathOption.cs +++ b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/DtFindPathOption.cs @@ -2,16 +2,16 @@ { public readonly struct DtFindPathOption { - public static readonly DtFindPathOption NoOption = new DtFindPathOption(DefaultQueryHeuristic.Default, 0, 0); + public static readonly DtFindPathOption NoOption = new DtFindPathOption(DtDefaultQueryHeuristic.Default, 0, 0); - public static readonly DtFindPathOption AnyAngle = new DtFindPathOption(DefaultQueryHeuristic.Default, DtNavMeshQuery.DT_FINDPATH_ANY_ANGLE, float.MaxValue); - public static readonly DtFindPathOption ZeroScale = new DtFindPathOption(new DefaultQueryHeuristic(0.0f), 0, 0); + public static readonly DtFindPathOption AnyAngle = new DtFindPathOption(DtDefaultQueryHeuristic.Default, DtNavMeshQuery.DT_FINDPATH_ANY_ANGLE, float.MaxValue); + public static readonly DtFindPathOption ZeroScale = new DtFindPathOption(new DtDefaultQueryHeuristic(0.0f), 0, 0); - public readonly IQueryHeuristic heuristic; + public readonly IDtQueryHeuristic heuristic; public readonly int options; public readonly float raycastLimit; - public DtFindPathOption(IQueryHeuristic heuristic, int options, float raycastLimit) + public DtFindPathOption(IDtQueryHeuristic heuristic, int options, float raycastLimit) { this.heuristic = heuristic; this.options = options; @@ -19,7 +19,7 @@ public DtFindPathOption(IQueryHeuristic heuristic, int options, float raycastLim } public DtFindPathOption(int options, float raycastLimit) - : this(DefaultQueryHeuristic.Default, options, raycastLimit) + : this(DtDefaultQueryHeuristic.Default, options, raycastLimit) { } } diff --git a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/DtNavMeshQuery.cs b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/DtNavMeshQuery.cs index 4827a6e..d19ec32 100644 --- a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/DtNavMeshQuery.cs +++ b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/DtNavMeshQuery.cs @@ -1024,15 +1024,15 @@ public DtStatus FindPath(long startRef, long endRef, RcVec3f startPos, RcVec3f e */ public DtStatus InitSlicedFindPath(long startRef, long endRef, RcVec3f startPos, RcVec3f endPos, IDtQueryFilter filter, int options) { - return InitSlicedFindPath(startRef, endRef, startPos, endPos, filter, options, DefaultQueryHeuristic.Default, -1.0f); + return InitSlicedFindPath(startRef, endRef, startPos, endPos, filter, options, DtDefaultQueryHeuristic.Default, -1.0f); } public DtStatus InitSlicedFindPath(long startRef, long endRef, RcVec3f startPos, RcVec3f endPos, IDtQueryFilter filter, int options, float raycastLimit) { - return InitSlicedFindPath(startRef, endRef, startPos, endPos, filter, options, DefaultQueryHeuristic.Default, raycastLimit); + return InitSlicedFindPath(startRef, endRef, startPos, endPos, filter, options, DtDefaultQueryHeuristic.Default, raycastLimit); } - public DtStatus InitSlicedFindPath(long startRef, long endRef, RcVec3f startPos, RcVec3f endPos, IDtQueryFilter filter, int options, IQueryHeuristic heuristic, float raycastLimit) + public DtStatus InitSlicedFindPath(long startRef, long endRef, RcVec3f startPos, RcVec3f endPos, IDtQueryFilter filter, int options, IDtQueryHeuristic heuristic, float raycastLimit) { // Init path state. m_query = new DtQueryData(); @@ -1431,20 +1431,20 @@ public virtual DtStatus FinalizeSlicedFindPathPartial(List existing, ref L return DtStatus.DT_SUCCSESS | details; } - protected DtStatus AppendVertex(RcVec3f pos, int flags, long refs, ref List straightPath, + protected DtStatus AppendVertex(RcVec3f pos, int flags, long refs, ref List straightPath, int maxStraightPath) { if (straightPath.Count > 0 && DtUtils.VEqual(straightPath[straightPath.Count - 1].pos, pos)) { // The vertices are equal, update flags and poly. - straightPath[straightPath.Count - 1] = new StraightPathItem(straightPath[straightPath.Count - 1].pos, flags, refs); + straightPath[straightPath.Count - 1] = new DtStraightPath(straightPath[straightPath.Count - 1].pos, flags, refs); } else { if (straightPath.Count < maxStraightPath) { // Append new vertex. - straightPath.Add(new StraightPathItem(pos, flags, refs)); + straightPath.Add(new DtStraightPath(pos, flags, refs)); } // If reached end of path or there is no space to append more vertices, return. @@ -1458,7 +1458,7 @@ protected DtStatus AppendVertex(RcVec3f pos, int flags, long refs, ref List path, - ref List straightPath, int maxStraightPath, int options) + ref List straightPath, int maxStraightPath, int options) { var startPos = straightPath[straightPath.Count - 1].pos; // Append or update last vertex @@ -1537,7 +1537,7 @@ protected DtStatus AppendPortals(int startIdx, int endIdx, RcVec3f endPos, List< /// @param[in] options Query options. (see: #dtStraightPathOptions) /// @returns The status flags for the query. public virtual DtStatus FindStraightPath(RcVec3f startPos, RcVec3f endPos, List path, - ref List straightPath, + ref List straightPath, int maxStraightPath, int options) { if (!RcVec3f.IsFinite(startPos) || !RcVec3f.IsFinite(endPos) || null == straightPath diff --git a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/DtNavMeshRaycast.cs b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/DtNavMeshRaycast.cs index f46a76c..869efdb 100644 --- a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/DtNavMeshRaycast.cs +++ b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/DtNavMeshRaycast.cs @@ -80,7 +80,7 @@ private static bool Raycast(DtMeshTile tile, RcVec3f sp, RcVec3f sq, out float h } } - if (Intersections.IntersectSegmentTriangle(sp, sq, verts[0], verts[1], verts[2], out hitTime)) + if (RcIntersections.IntersectSegmentTriangle(sp, sq, verts[0], verts[1], verts[2], out hitTime)) { return true; } diff --git a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/PathUtils.cs b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/DtPathUtils.cs similarity index 98% rename from src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/PathUtils.cs rename to src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/DtPathUtils.cs index c46989f..5243135 100644 --- a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/PathUtils.cs +++ b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/DtPathUtils.cs @@ -24,7 +24,7 @@ 3. This notice may not be removed or altered from any source distribution. namespace DotRecast.Detour { - public static class PathUtils + public static class DtPathUtils { private const int MAX_STEER_POINTS = 3; @@ -38,7 +38,7 @@ public static bool GetSteerTarget(DtNavMeshQuery navQuery, RcVec3f startPos, RcV steerPosRef = 0; // Find steer target. - var straightPath = new List(MAX_STEER_POINTS); + var straightPath = new List(MAX_STEER_POINTS); var result = navQuery.FindStraightPath(startPos, endPos, path, ref straightPath, MAX_STEER_POINTS, 0); if (result.Failed()) { diff --git a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/DtQueryData.cs b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/DtQueryData.cs index 8a872bf..ea925c2 100644 --- a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/DtQueryData.cs +++ b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/DtQueryData.cs @@ -34,6 +34,6 @@ public struct DtQueryData public IDtQueryFilter filter; public int options; public float raycastLimitSqr; - public IQueryHeuristic heuristic; + public IDtQueryHeuristic heuristic; } } \ No newline at end of file diff --git a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/StraightPathItem.cs b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/DtStraightPath.cs similarity index 92% rename from src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/StraightPathItem.cs rename to src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/DtStraightPath.cs index d675bf4..a04d740 100644 --- a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/StraightPathItem.cs +++ b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/DtStraightPath.cs @@ -23,13 +23,13 @@ 3. This notice may not be removed or altered from any source distribution. namespace DotRecast.Detour { //TODO: (PP) Add comments - public readonly struct StraightPathItem + public readonly struct DtStraightPath { public readonly RcVec3f pos; public readonly int flags; public readonly long refs; - public StraightPathItem(RcVec3f pos, int flags, long refs) + public DtStraightPath(RcVec3f pos, int flags, long refs) { this.pos = pos; this.flags = flags; diff --git a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/DtStrictDtPolygonByCircleConstraint.cs b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/DtStrictDtPolygonByCircleConstraint.cs index d2e7c64..1278b58 100644 --- a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/DtStrictDtPolygonByCircleConstraint.cs +++ b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/DtStrictDtPolygonByCircleConstraint.cs @@ -51,7 +51,7 @@ public float[] Apply(float[] verts, RcVec3f center, float radius) } float[] qCircle = Circle(center, radius); - float[] intersection = ConvexConvexIntersection.Intersect(verts, qCircle); + float[] intersection = DtConvexConvexIntersections.Intersect(verts, qCircle); if (intersection == null && DtUtils.PointInPolygon(center, verts, verts.Length / 3)) { // circle inside polygon diff --git a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/IQueryHeuristic.cs b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/IDtQueryHeuristic.cs similarity index 96% rename from src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/IQueryHeuristic.cs rename to src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/IDtQueryHeuristic.cs index 8b60e48..8a5c051 100644 --- a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/IQueryHeuristic.cs +++ b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Detour/IDtQueryHeuristic.cs @@ -21,7 +21,7 @@ 3. This notice may not be removed or altered from any source distribution. namespace DotRecast.Detour { - public interface IQueryHeuristic + public interface IDtQueryHeuristic { float GetCost(RcVec3f neighbourPos, RcVec3f endPos); } diff --git a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Recast.Toolset/Geom/DemoInputGeomProvider.cs b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Recast.Toolset/Geom/DemoInputGeomProvider.cs index 56ae2f2..d9e3313 100644 --- a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Recast.Toolset/Geom/DemoInputGeomProvider.cs +++ b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Recast.Toolset/Geom/DemoInputGeomProvider.cs @@ -143,7 +143,7 @@ public bool RaycastMesh(RcVec3f src, RcVec3f dst, out float tmin) tmin = 1.0f; // Prune hit ray. - if (!Intersections.IsectSegAABB(src, dst, bmin, bmax, out var btmin, out var btmax)) + if (!RcIntersections.IsectSegAABB(src, dst, bmin, bmax, out var btmin, out var btmax)) { return false; } @@ -183,7 +183,7 @@ public bool RaycastMesh(RcVec3f src, RcVec3f dst, out float tmin) vertices[tris[j + 2] * 3 + 1], vertices[tris[j + 2] * 3 + 2] ); - if (Intersections.IntersectSegmentTriangle(src, dst, v1, v2, v3, out var t)) + if (RcIntersections.IntersectSegmentTriangle(src, dst, v1, v2, v3, out var t)) { if (t < tmin) { diff --git a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Recast.Toolset/Tools/RcCrowdAgentProfilingTool.cs b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Recast.Toolset/Tools/RcCrowdAgentProfilingTool.cs index 556e3b5..a975e4c 100644 --- a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Recast.Toolset/Tools/RcCrowdAgentProfilingTool.cs +++ b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Recast.Toolset/Tools/RcCrowdAgentProfilingTool.cs @@ -17,7 +17,7 @@ public class RcCrowdAgentProfilingTool : IRcToolable private DtNavMesh navMesh; - private FRand rnd; + private RcRand rnd; private readonly List _polyPoints; private long crowdUpdateTime; @@ -162,7 +162,7 @@ public void StartProfiling(float agentRadius, float agentHeight, float agentMaxA if (null == navMesh) return; - rnd = new FRand(_cfg.randomSeed); + rnd = new RcRand(_cfg.randomSeed); CreateCrowd(); CreateZones(); DtNavMeshQuery navquery = new DtNavMeshQuery(navMesh); diff --git a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Recast.Toolset/Tools/RcCrowdTool.cs b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Recast.Toolset/Tools/RcCrowdTool.cs index ee48eff..9124726 100644 --- a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Recast.Toolset/Tools/RcCrowdTool.cs +++ b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Recast.Toolset/Tools/RcCrowdTool.cs @@ -222,7 +222,7 @@ public DtCrowdAgent HitTestAgents(RcVec3f s, RcVec3f p) RcVec3f bmin = new RcVec3f(); RcVec3f bmax = new RcVec3f(); GetAgentBounds(ag, ref bmin, ref bmax); - if (Intersections.IsectSegAABB(s, p, bmin, bmax, out var tmin, out var tmax)) + if (RcIntersections.IsectSegAABB(s, p, bmin, bmax, out var tmin, out var tmax)) { if (tmin > 0 && tmin < tsel) { diff --git a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Recast.Toolset/Tools/RcObstacleTool.cs b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Recast.Toolset/Tools/RcObstacleTool.cs index 592db77..39df464 100644 --- a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Recast.Toolset/Tools/RcObstacleTool.cs +++ b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Recast.Toolset/Tools/RcObstacleTool.cs @@ -162,7 +162,7 @@ public long HitTestObstacle(RcVec3f sp, RcVec3f sq) RcVec3f bmax = RcVec3f.Zero; _tc.GetObstacleBounds(ob, ref bmin, ref bmax); - if (Intersections.IsectSegAABB(sp, sq, bmin, bmax, out var t0, out var t1)) + if (RcIntersections.IsectSegAABB(sp, sq, bmin, bmax, out var t0, out var t1)) { if (t0 < tmin) { diff --git a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Recast.Toolset/Tools/RcTestNavMeshTool.cs b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Recast.Toolset/Tools/RcTestNavMeshTool.cs index 35bab9c..f08511c 100644 --- a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Recast.Toolset/Tools/RcTestNavMeshTool.cs +++ b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Recast.Toolset/Tools/RcTestNavMeshTool.cs @@ -58,7 +58,7 @@ public DtStatus FindFollowPath(DtNavMesh navMesh, DtNavMeshQuery navQuery, long while (0 < polys.Count && smoothPath.Count < MAX_SMOOTH) { // Find location to steer towards. - if (!PathUtils.GetSteerTarget(navQuery, iterPos, targetPos, SLOP, + if (!DtPathUtils.GetSteerTarget(navQuery, iterPos, targetPos, SLOP, polys, out var steerPos, out var steerPosFlag, out var steerPosRef)) { break; @@ -91,8 +91,8 @@ public DtStatus FindFollowPath(DtNavMesh navMesh, DtNavMeshQuery navQuery, long iterPos = result; - polys = PathUtils.MergeCorridorStartMoved(polys, visited); - polys = PathUtils.FixupShortcuts(polys, navQuery); + polys = DtPathUtils.MergeCorridorStartMoved(polys, visited); + polys = DtPathUtils.FixupShortcuts(polys, navQuery); var status = navQuery.GetPolyHeight(polys[0], result, out var h); if (status.Succeeded()) @@ -101,7 +101,7 @@ public DtStatus FindFollowPath(DtNavMesh navMesh, DtNavMeshQuery navQuery, long } // Handle end of path and off-mesh links when close enough. - if (endOfPath && PathUtils.InRange(iterPos, steerPos, SLOP, 1.0f)) + if (endOfPath && DtPathUtils.InRange(iterPos, steerPos, SLOP, 1.0f)) { // Reached end of path. iterPos = targetPos; @@ -112,7 +112,7 @@ public DtStatus FindFollowPath(DtNavMesh navMesh, DtNavMeshQuery navQuery, long break; } - else if (offMeshConnection && PathUtils.InRange(iterPos, steerPos, SLOP, 1.0f)) + else if (offMeshConnection && DtPathUtils.InRange(iterPos, steerPos, SLOP, 1.0f)) { // Reached off-mesh connection. RcVec3f startPos = RcVec3f.Zero; @@ -163,7 +163,7 @@ public DtStatus FindFollowPath(DtNavMesh navMesh, DtNavMeshQuery navQuery, long } public DtStatus FindStraightPath(DtNavMeshQuery navQuery, long startRef, long endRef, RcVec3f startPt, RcVec3f endPt, IDtQueryFilter filter, bool enableRaycast, - ref List polys, ref List straightPath, int straightPathOptions) + ref List polys, ref List straightPath, int straightPathOptions) { if (startRef == 0 || endRef == 0) { @@ -171,7 +171,7 @@ public DtStatus FindStraightPath(DtNavMeshQuery navQuery, long startRef, long en } polys ??= new List(); - straightPath ??= new List(); + straightPath ??= new List(); polys.Clear(); straightPath.Clear(); @@ -212,7 +212,7 @@ public DtStatus InitSlicedFindPath(DtNavMeshQuery navQuery, long startRef, long } public DtStatus UpdateSlicedFindPath(DtNavMeshQuery navQuery, int maxIter, long endRef, RcVec3f startPos, RcVec3f endPos, - ref List path, ref List straightPath) + ref List path, ref List straightPath) { var status = navQuery.UpdateSlicedFindPath(maxIter, out _); @@ -237,7 +237,7 @@ public DtStatus UpdateSlicedFindPath(DtNavMeshQuery navQuery, int maxIter, long } } - straightPath = new List(MAX_POLYS); + straightPath = new List(MAX_POLYS); navQuery.FindStraightPath(startPos, epos, path, ref straightPath, MAX_POLYS, DtNavMeshQuery.DT_STRAIGHTPATH_ALL_CROSSINGS); } @@ -246,7 +246,7 @@ public DtStatus UpdateSlicedFindPath(DtNavMeshQuery navQuery, int maxIter, long public DtStatus Raycast(DtNavMeshQuery navQuery, long startRef, long endRef, RcVec3f startPos, RcVec3f endPos, IDtQueryFilter filter, - ref List polys, ref List straightPath, ref RcVec3f hitPos, ref RcVec3f hitNormal, ref bool hitResult) + ref List polys, ref List straightPath, ref RcVec3f hitPos, ref RcVec3f hitNormal, ref bool hitResult) { if (startRef == 0 || endRef == 0) { @@ -289,10 +289,10 @@ public DtStatus Raycast(DtNavMeshQuery navQuery, long startRef, long endRef, RcV } } - straightPath ??= new List(); + straightPath ??= new List(); straightPath.Clear(); - straightPath.Add(new StraightPathItem(startPos, 0, 0)); - straightPath.Add(new StraightPathItem(hitPos, 0, 0)); + straightPath.Add(new DtStraightPath(startPos, 0, 0)); + straightPath.Add(new DtStraightPath(hitPos, 0, 0)); return status; } @@ -422,7 +422,7 @@ public DtStatus FindRandomPointAroundCircle(DtNavMeshQuery navQuery, long startR ? DtStrictDtPolygonByCircleConstraint.Shared : DtNoOpDtPolygonByCircleConstraint.Shared; - var frand = new FRand(); + var frand = new RcRand(); int prevCnt = points.Count; points = new List(); diff --git a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Recast/RcPolyMeshRaycast.cs b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Recast/RcPolyMeshRaycast.cs index f959029..fdab28e 100644 --- a/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Recast/RcPolyMeshRaycast.cs +++ b/src/UniRecast.Unity/Assets/Plugins/DotRecast/src/DotRecast.Recast/RcPolyMeshRaycast.cs @@ -64,7 +64,7 @@ private static bool Raycast(RcPolyMesh poly, RcPolyMeshDetail meshDetail, RcVec3 vs[k].z = meshDetail.verts[verts + meshDetail.tris[tris + j * 4 + k] * 3 + 2]; } - if (Intersections.IntersectSegmentTriangle(sp, sq, vs[0], vs[1], vs[2], out hitTime)) + if (RcIntersections.IntersectSegmentTriangle(sp, sq, vs[0], vs[1], vs[2], out hitTime)) { return true; } diff --git a/src/UniRecast.Unity/Assets/Plugins/UniRecast/Editor/UniRcCrowdToolEditor.cs b/src/UniRecast.Unity/Assets/Plugins/UniRecast/Editor/UniRcCrowdToolEditor.cs index 7f5347d..5b75389 100644 --- a/src/UniRecast.Unity/Assets/Plugins/UniRecast/Editor/UniRcCrowdToolEditor.cs +++ b/src/UniRecast.Unity/Assets/Plugins/UniRecast/Editor/UniRcCrowdToolEditor.cs @@ -57,13 +57,13 @@ protected override void Layout() { UniRcGui.Text($"Crowd Tool Mode"); UniRcGui.Separator(); - UniRcGui.RadioButton(CrowdToolMode.CREATE.Label, _mode, CrowdToolMode.CREATE.Idx); - UniRcGui.RadioButton(CrowdToolMode.MOVE_TARGET.Label, _mode, CrowdToolMode.MOVE_TARGET.Idx); - UniRcGui.RadioButton(CrowdToolMode.SELECT.Label, _mode, CrowdToolMode.SELECT.Idx); - UniRcGui.RadioButton(CrowdToolMode.TOGGLE_POLYS.Label, _mode, CrowdToolMode.TOGGLE_POLYS.Idx); + UniRcGui.RadioButton(RcCrowdToolMode.CREATE.Label, _mode, RcCrowdToolMode.CREATE.Idx); + UniRcGui.RadioButton(RcCrowdToolMode.MOVE_TARGET.Label, _mode, RcCrowdToolMode.MOVE_TARGET.Idx); + UniRcGui.RadioButton(RcCrowdToolMode.SELECT.Label, _mode, RcCrowdToolMode.SELECT.Idx); + UniRcGui.RadioButton(RcCrowdToolMode.TOGGLE_POLYS.Label, _mode, RcCrowdToolMode.TOGGLE_POLYS.Idx); UniRcGui.NewLine(); - CrowdToolMode mode = CrowdToolMode.Values[_mode.intValue]; + RcCrowdToolMode mode = RcCrowdToolMode.Values[_mode.intValue]; UniRcGui.Text("Options"); UniRcGui.Separator(); diff --git a/src/UniRecast.Unity/Assets/Plugins/UniRecast/Scenes/SampleScene.unity b/src/UniRecast.Unity/Assets/Plugins/UniRecast/Scenes/SampleScene.unity index 1f74ff4..76e54a3 100644 --- a/src/UniRecast.Unity/Assets/Plugins/UniRecast/Scenes/SampleScene.unity +++ b/src/UniRecast.Unity/Assets/Plugins/UniRecast/Scenes/SampleScene.unity @@ -176,6 +176,10 @@ PrefabInstance: propertyPath: m_Name value: nav_test objectReference: {fileID: 0} + - target: {fileID: 919132149155446097, guid: 561964b985803e84da1e40e19b44707d, type: 3} + propertyPath: m_TagString + value: NavMesh + objectReference: {fileID: 0} m_RemovedComponents: [] m_RemovedGameObjects: [] m_AddedGameObjects: []