performance

This commit is contained in:
ikpil 2023-07-22 18:40:41 +09:00
parent 2efa16eee7
commit 9334315610
6 changed files with 16 additions and 4 deletions

View File

@ -6,7 +6,7 @@ namespace DotRecast.Core
{
public static byte[] ToBytes(string filename)
{
var filepath = ToRPath(filename);
var filepath = FindParentPath(filename);
using var fs = new FileStream(filepath, FileMode.Open, FileAccess.Read);
byte[] buffer = new byte[fs.Length];
fs.Read(buffer, 0, buffer.Length);
@ -14,7 +14,7 @@ namespace DotRecast.Core
return buffer;
}
public static string ToRPath(string filename)
public static string FindParentPath(string filename)
{
string filePath = Path.Combine("resources", filename);
for (int i = 0; i < 10; ++i)

View File

@ -10,6 +10,7 @@ namespace DotRecast.Core
public static RcVec2f Zero { get; } = new RcVec2f { x = 0, y = 0 };
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public float Get(int idx)
{
if (0 == idx)
@ -36,6 +37,7 @@ namespace DotRecast.Core
y.Equals(other.y);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override int GetHashCode()
{
int hash = x.GetHashCode();
@ -55,6 +57,7 @@ namespace DotRecast.Core
return !left.Equals(right);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override string ToString()
{
return $"{x}, {y}";

View File

@ -48,6 +48,7 @@ namespace DotRecast.Core
return new RcVec3f(x, y, z);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public RcVec3f(float x, float y, float z)
{
this.x = x;
@ -55,6 +56,7 @@ namespace DotRecast.Core
this.z = z;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public RcVec3f(float f)
{
x = f;
@ -63,6 +65,7 @@ namespace DotRecast.Core
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public RcVec3f(float[] f)
{
x = f[0];
@ -76,6 +79,7 @@ namespace DotRecast.Core
set => SetElement(index, value);
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public float GetElement(int index)
{
switch (index)
@ -87,6 +91,7 @@ namespace DotRecast.Core
}
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public void SetElement(int index, float value)
{
switch (index)
@ -202,6 +207,7 @@ namespace DotRecast.Core
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public override int GetHashCode()
{
int hash = x.GetHashCode();

View File

@ -21,6 +21,7 @@ freely, subject to the following restrictions:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.CompilerServices;
namespace DotRecast.Detour.Crowd
{
@ -37,6 +38,7 @@ namespace DotRecast.Detour.Crowd
_items = new Dictionary<long, List<DtCrowdAgent>>();
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static long CombineKey(int x, int y)
{
uint ux = (uint)x;
@ -44,6 +46,7 @@ namespace DotRecast.Detour.Crowd
return ((long)ux << 32) | uy;
}
[MethodImpl(MethodImplOptions.AggressiveInlining)]
public static void DecomposeKey(long key, out int x, out int y)
{
uint ux = (uint)(key >> 32);

View File

@ -37,7 +37,7 @@ public static class Program
private static void InitializeWorkingDirectory()
{
var path = Loader.ToRPath("dungeon.obj");
var path = Loader.FindParentPath("dungeon.obj");
path = Path.GetDirectoryName(path);
if (!string.IsNullOrEmpty(path))
{

View File

@ -81,7 +81,7 @@ public class UnityAStarPathfindingImporterTest
private DtNavMesh LoadNavMesh(string filename)
{
var filepath = Loader.ToRPath(filename);
var filepath = Loader.FindParentPath(filename);
using var fs = new FileStream(filepath, FileMode.Open, FileAccess.Read);
// Import the graphs