Skip to content

Commit

Permalink
updates mmaps, add random locations, tweak detour
Browse files Browse the repository at this point in the history
  • Loading branch information
Jnnshschl committed Jul 10, 2020
1 parent f017906 commit 5c9470e
Show file tree
Hide file tree
Showing 28 changed files with 239 additions and 10,220 deletions.
88 changes: 62 additions & 26 deletions AmeisenNavigation.Demo/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,42 @@

int main()
{
int mapId = 0; // Eastern Kingdoms
std::string mmapsFolder = "H:\\WoW Stuff\\3.3.5a mmaps\\";
int mapId = 489; // warsong gulch
std::string mmapsFolder = "C:\\Users\\Jannis Server\\Downloads\\mmaps\\";

Vector3 startPositionCastMovementRay(-8826.562500f, -371.839752f, 71.638428f);
Vector3 endPositionCastMovementRay(-8918.406250f, -130.297256f, 80.906364f);
Vector3 startPositionCastMovementRay(916, 1434, 346);
Vector3 endPositionCastMovementRay(1539, 1481, 352);

Vector3 startPositionMoveAlongSurface(-8826.562500f, -371.839752f, 71.638428f);
Vector3 endPositionMoveAlongSurface(-8918.406250f, -130.297256f, 80.906364f);
Vector3 startPositionMoveAlongSurface(916, 1434, 346);
Vector3 endPositionMoveAlongSurface(1539, 1481, 352);

Vector3 startPositionGetPath(-8826.562500f, -371.839752f, 71.638428f);
Vector3 endPositionGetPath(-8918.406250f, -130.297256f, 80.906364f);
Vector3 startPositionGetPath(916, 1434, 346);
Vector3 endPositionGetPath(1539, 1481, 352);

// use this to test same-poly pathfinding
Vector3 endPositionSamePoly(-8828.562500f, -371.839752f, 71.638428f);
std::cout << ">> Ameisen Navigation Demo" << std::endl;

std::cout << ">> Ameisen Navigation Demo" << std::endl << std::endl;
std::cout << ">> MMAPFolder: \"" << mmapsFolder << "\"" << std::endl;
std::cout << ">> MapId: " << mapId << std::endl;

std::cout << ">> MMAPFolder: \t\t\t\"" << mmapsFolder << "\"" << std::endl;
std::cout << ">> MapId: \t\t\t" << mapId << std::endl << std::endl;

AmeisenNavigation ameisenNavigation = AmeisenNavigation(mmapsFolder);
AmeisenNavigation ameisenNavigation = AmeisenNavigation(mmapsFolder, 256, 32);

TestLoadMmaps(mapId, ameisenNavigation);
TestCastMovementRay(mapId, ameisenNavigation, startPositionCastMovementRay, endPositionCastMovementRay);

std::cout << std::endl << ">> ---- Testing CastMovementRay:" << std::endl;
TestCastMovementRay(mapId, ameisenNavigation, startPositionCastMovementRay, Vector3(918, 1434, 346));

std::cout << std::endl << ">> ---- Testing MoveAlongSurface:" << std::endl;
TestMoveAlongSurface(mapId, ameisenNavigation, startPositionMoveAlongSurface, endPositionMoveAlongSurface);

std::cout << std::endl << ">> ---- Testing GetPath:" << std::endl;
TestGetPath(mapId, ameisenNavigation, startPositionGetPath, endPositionGetPath);

std::cout << std::endl << ">> ---- Testing GetRandomPoint:" << std::endl;
TestRandomPoint(mapId, ameisenNavigation);

std::cout << std::endl << ">> ---- Testing GetRandomPointAround:" << std::endl;
TestRandomPointAround(mapId, ameisenNavigation, startPositionGetPath);

std::cout << std::endl << ">> Press a key to exit this Application";
std::cin.get();
}
Expand All @@ -39,32 +48,33 @@ void TestCastMovementRay(const int mapId, AmeisenNavigation& ameisenNavigation,
bool result = ameisenNavigation.CastMovementRay(mapId, startPosition, endPosition);
std::chrono::high_resolution_clock::time_point t2CastMovementRay = std::chrono::high_resolution_clock::now();

std::string txt = result ? "no hit" : "hit wall";

auto durationCastMovementRay = std::chrono::duration_cast<std::chrono::milliseconds>(t2CastMovementRay - t1CastMovementRay).count();
std::cout << ">> CastMovementRay \t\t" << durationCastMovementRay << " ms" << std::endl;
std::cout << ">> Result: \t\t\t" << result << std::endl << std::endl;
std::cout << ">> CastMovementRay took " << durationCastMovementRay << " ms" << std::endl;
std::cout << ">> Result: " << txt << std::endl;
}

void TestGetPath(const int mapId, AmeisenNavigation& ameisenNavigation, const Vector3& startPosition, const Vector3& endPosition)
{
int pathSize = 0;
Vector3 path[MAX_PATH_LENGHT];
Vector3 path[256];

std::chrono::high_resolution_clock::time_point t1GetPath = std::chrono::high_resolution_clock::now();
bool result = ameisenNavigation.GetPath(mapId, startPosition, endPosition, path, &pathSize);
std::chrono::high_resolution_clock::time_point t2GetPath = std::chrono::high_resolution_clock::now();

auto durationGetPath = std::chrono::duration_cast<std::chrono::milliseconds>(t2GetPath - t1GetPath).count();
std::cout << ">> GetPath \t\t\t" << durationGetPath << " ms" << std::endl << std::endl;
std::cout << ">> GetPath took " << durationGetPath << " ms" << std::endl;

if (result)
{
std::cout << ">> Path size: \t\t\t" << pathSize << " Nodes" << std::endl;
std::cout << ">> Path Address: \t\t0x" << std::hex << path << "" << std::dec << std::endl << std::endl;
std::cout << ">> Path size: " << pathSize << " Nodes" << std::endl;

// print the nodes
for (int i = 0; i < pathSize; ++i)
{
std::cout << std::fixed << std::setprecision(2) << ">> Node [" << i << "]: \t\t\t" << path[i] << std::endl;
std::cout << std::fixed << std::setprecision(2) << ">> Node [" << i << "]: " << path[i] << std::endl;
}
}
else
Expand All @@ -80,7 +90,7 @@ void TestLoadMmaps(int mapId, AmeisenNavigation& ameisenNavigation)
std::chrono::high_resolution_clock::time_point t2LoadMmapsForContinent = std::chrono::high_resolution_clock::now();

auto durationtLoadMmapsForContinent = std::chrono::duration_cast<std::chrono::milliseconds>(t2LoadMmapsForContinent - t1LoadMmapsForContinent).count();
std::cout << ">> LoadMmapsForContinent \t" << durationtLoadMmapsForContinent << " ms" << std::endl << std::endl;
std::cout << ">> LoadMmapsForContinent took " << durationtLoadMmapsForContinent << " ms" << std::endl;
}

void TestMoveAlongSurface(const int mapId, AmeisenNavigation& ameisenNavigation, const Vector3& startPosition, const Vector3& endPosition)
Expand All @@ -92,6 +102,32 @@ void TestMoveAlongSurface(const int mapId, AmeisenNavigation& ameisenNavigation,
std::chrono::high_resolution_clock::time_point t2MoveAlongSurface = std::chrono::high_resolution_clock::now();

auto durationMoveAlongSurface = std::chrono::duration_cast<std::chrono::milliseconds>(t2MoveAlongSurface - t1MoveAlongSurface).count();
std::cout << ">> MoveAlongSurface \t\t" << durationMoveAlongSurface << " ms" << std::endl;
std::cout << std::fixed << std::setprecision(2) << ">> Target Position: \t\t" << moveAlongSurfacePoint << std::endl << std::endl;
std::cout << ">> MoveAlongSurface took " << durationMoveAlongSurface << " ms" << std::endl;
std::cout << std::fixed << std::setprecision(2) << ">> Target Position: " << moveAlongSurfacePoint << std::endl;
}

void TestRandomPoint(const int mapId, AmeisenNavigation& ameisenNavigation)
{
Vector3 getRandomPointPoint;

std::chrono::high_resolution_clock::time_point t1GetRandomPoint = std::chrono::high_resolution_clock::now();
ameisenNavigation.GetRandomPoint(mapId, &getRandomPointPoint);
std::chrono::high_resolution_clock::time_point t2GetRandomPoint = std::chrono::high_resolution_clock::now();

auto durationGetRandomPoint = std::chrono::duration_cast<std::chrono::milliseconds>(t2GetRandomPoint - t1GetRandomPoint).count();
std::cout << ">> GetRandomPoint took " << durationGetRandomPoint << " ms" << std::endl;
std::cout << std::fixed << std::setprecision(2) << ">> Target Position: " << getRandomPointPoint << std::endl;
}

void TestRandomPointAround(const int mapId, AmeisenNavigation& ameisenNavigation, const Vector3& startPosition)
{
Vector3 getRandomPointAroundPoint;

std::chrono::high_resolution_clock::time_point t1GetRandomPointAround = std::chrono::high_resolution_clock::now();
ameisenNavigation.GetRandomPointAround(mapId, startPosition, 32.f, &getRandomPointAroundPoint);
std::chrono::high_resolution_clock::time_point t2GetRandomPointAround = std::chrono::high_resolution_clock::now();

auto durationGetRandomPointAround = std::chrono::duration_cast<std::chrono::milliseconds>(t2GetRandomPointAround - t1GetRandomPointAround).count();
std::cout << ">> GetRandomPointAround took " << durationGetRandomPointAround << " ms" << std::endl;
std::cout << std::fixed << std::setprecision(2) << ">> Target Position: " << getRandomPointAroundPoint << std::endl;
}
2 changes: 2 additions & 0 deletions AmeisenNavigation.Demo/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ void TestLoadMmaps(const int mapId, AmeisenNavigation& ameisenNavigation);
void TestGetPath(const int mapId, AmeisenNavigation& ameisenNavigation, const Vector3& startPosition, const Vector3& endPosition);
void TestCastMovementRay(const int mapId, AmeisenNavigation& ameisenNavigation, const Vector3& startPosition, const Vector3& endPosition);
void TestMoveAlongSurface(const int mapId, AmeisenNavigation& ameisenNavigation, const Vector3& startPosition, const Vector3& endPosition);
void TestRandomPoint(const int mapId, AmeisenNavigation& ameisenNavigation);
void TestRandomPointAround(const int mapId, AmeisenNavigation& ameisenNavigation, const Vector3& startPosition);

#endif // !_H_MAIN
2 changes: 1 addition & 1 deletion AmeisenNavigation.Server/AmeisenNavigation.Server.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
</PropertyGroup>
<ItemGroup>
<Reference Include="Newtonsoft.Json, Version=12.0.0.0, Culture=neutral, PublicKeyToken=30ad4fe6b2a6aeed, processorArchitecture=MSIL">
<HintPath>..\packages\Newtonsoft.Json.12.0.1\lib\net45\Newtonsoft.Json.dll</HintPath>
<HintPath>..\packages\Newtonsoft.Json.12.0.3\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
Expand Down
6 changes: 3 additions & 3 deletions AmeisenNavigation.Server/App.config
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2"/>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
</startup>
</configuration>
</configuration>
47 changes: 29 additions & 18 deletions AmeisenNavigation.Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public static void EnterServerLoop()
}
}

public static List<Vector3> GetPath(Vector3 start, Vector3 end, int mapId, MovementType movementType, PathRequestFlags flags, string clientIp)
public static List<Vector3> GetPath(Vector3 start, Vector3 end, float maxRadius, int mapId, MovementType movementType, PathRequestFlags flags, string clientIp)
{
int pathSize;
List<Vector3> path = new List<Vector3>();
Expand Down Expand Up @@ -102,13 +102,11 @@ public static List<Vector3> GetPath(Vector3 start, Vector3 end, int mapId, Movem
{
path = ChaikinCurve.Perform(path);
}

break;

case MovementType.MoveAlongSurface:
float* surfacePath = AmeisenNav.MoveAlongSurface(mapId, pointerStart, pointerEnd);
path.Add(new Vector3(surfacePath[0], surfacePath[1], surfacePath[2]));

break;

case MovementType.CastMovementRay:
Expand All @@ -122,15 +120,24 @@ public static List<Vector3> GetPath(Vector3 start, Vector3 end, int mapId, Movem
// return none if target is not in line of sight
path.Clear();
}
break;

case MovementType.GetRandomPoint:
float* randomPoint = AmeisenNav.GetRandomPoint(mapId);
path.Add(new Vector3(randomPoint[0], randomPoint[1], randomPoint[2]));
break;

case MovementType.GetRandomPointAround:
float* randomPointAround = AmeisenNav.GetRandomPointAround(mapId, pointerStart, maxRadius);
path.Add(new Vector3(randomPointAround[0], randomPointAround[1], randomPointAround[2]));
break;
}
}
}
}

sw.Stop();
LogQueue.Enqueue(new LogEntry($"[{clientIp}] ", ConsoleColor.Green, $"{movementType} with {path.Count} Nodes took {sw.ElapsedMilliseconds}ms ({sw.ElapsedTicks} ticks)", LogLevel.INFO));
LogQueue.Enqueue(new LogEntry($"[{clientIp}] ", ConsoleColor.Green, $"{movementType} with {path.Count}/{Settings.MaxPointPathCount} Nodes took {sw.ElapsedMilliseconds}ms ({sw.ElapsedTicks} ticks)", LogLevel.INFO));
return path;
}

Expand All @@ -154,7 +161,7 @@ public static void HandleClient(TcpClient client)
{
PathRequest pathRequest = JsonConvert.DeserializeObject<PathRequest>(rawData);

List<Vector3> path = GetPath(pathRequest.A, pathRequest.B, pathRequest.MapId, pathRequest.MovementType, pathRequest.Flags, client.Client.RemoteEndPoint.ToString());
List<Vector3> path = GetPath(pathRequest.A, pathRequest.B, pathRequest.MaxRadius, pathRequest.MapId, pathRequest.MovementType, pathRequest.Flags, client.Client.RemoteEndPoint.ToString());

writer.WriteLine($"{JsonConvert.SerializeObject(path)}&gt;");
writer.Flush();
Expand All @@ -179,26 +186,27 @@ public static void LoggingThreadRoutine()
{
while (!stopServer || LogQueue.Count > 0)
{
if (LogQueue.TryDequeue(out LogEntry logEntry))
StringBuilder sb = new StringBuilder();

while (LogQueue.TryDequeue(out LogEntry logEntry))
{
if (logEntry.LogLevel >= Settings.LogLevel)
{
string logString = ColoredPrint(logEntry.ColoredPart, logEntry.Color, logEntry.UncoloredPart, logEntry.LogLevel);
if (Settings.LogToFile)
{
try
{
File.AppendAllText(Settings.LogFilePath, logString);
}
catch
{
// ignored, if we cant write to file we cant log it lmao
}
sb.AppendLine(logString);
}
}
}

Thread.Sleep(1);
try
{
File.WriteAllText(Settings.LogFilePath, sb.ToString());
}
catch { }

Thread.Sleep(500);
}
}

Expand Down Expand Up @@ -227,7 +235,8 @@ public static void Main()
}
else
{
AmeisenNav = new AmeisenNav(Settings.MmapsFolder.Replace('/', '\\'));
Settings.MmapsFolder = Settings.MmapsFolder.Replace('/', '\\');
AmeisenNav = new AmeisenNav(Settings.MmapsFolder, Settings.MaxPolyPathCount, Settings.MaxPointPathCount);

if (Settings.PreloadMaps.Length > 0)
{
Expand All @@ -237,7 +246,7 @@ public static void Main()
TcpListener = new TcpListener(IPAddress.Parse(Settings.IpAddress), Settings.Port);
TcpListener.Start();

LogQueue.Enqueue(new LogEntry($"{Settings.IpAddress}:{Settings.Port} press Ctrl + C to exit...", ConsoleColor.Green, string.Empty, LogLevel.MASTER));
LogQueue.Enqueue(new LogEntry($"Listening on {Settings.IpAddress}:{Settings.Port} press Ctrl + C to exit...", ConsoleColor.Green, string.Empty, LogLevel.MASTER));

EnterServerLoop();

Expand Down Expand Up @@ -297,7 +306,9 @@ private static Settings LoadConfigFile()
CheckForLogFileExistence();
}

LogQueue.Enqueue(new LogEntry($"Loaded config file", ConsoleColor.Green));
LogQueue.Enqueue(new LogEntry($"MaxPolyPathCount = {settings.MaxPolyPathCount}", ConsoleColor.White));
LogQueue.Enqueue(new LogEntry($"MaxPointPathCount = {settings.MaxPointPathCount}", ConsoleColor.White));
LogQueue.Enqueue(new LogEntry("Loaded config file", ConsoleColor.Green));
}
else
{
Expand Down
6 changes: 3 additions & 3 deletions AmeisenNavigation.Server/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("AmeisenNavigationServer")]
[assembly: AssemblyCopyright("Copyright © Jannis Höschele 2018")]
[assembly: AssemblyCopyright("")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: ComVisible(false)]
[assembly: Guid("94dd9098-c900-4e3b-8d06-01157198914e")]
[assembly: AssemblyVersion("1.3.4.0")]
[assembly: AssemblyFileVersion("1.3.4.0")]
[assembly: AssemblyVersion("1.4.0.0")]
[assembly: AssemblyFileVersion("1.4.0.0")]
4 changes: 3 additions & 1 deletion AmeisenNavigation.Server/objects/Enums/MovementType.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ public enum MovementType
{
MoveToPosition,
CastMovementRay,
MoveAlongSurface
MoveAlongSurface,
GetRandomPoint,
GetRandomPointAround,
}
}
7 changes: 5 additions & 2 deletions AmeisenNavigation.Server/objects/PathRequest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@ namespace AmeisenNavigation.Server.Objects
{
public struct PathRequest
{
public PathRequest(Vector3 a, Vector3 b, int mapId, PathRequestFlags flags = PathRequestFlags.None, MovementType movementType = MovementType.MoveToPosition)
public PathRequest(Vector3 a, Vector3 b, float maxRadius, int mapId, PathRequestFlags flags = PathRequestFlags.None, MovementType movementType = MovementType.MoveToPosition)
{
A = a;
B = b;
MaxRadius = maxRadius;
MapId = mapId;
Flags = flags;
MovementType = movementType;
Expand All @@ -21,6 +22,8 @@ public PathRequest(Vector3 a, Vector3 b, int mapId, PathRequestFlags flags = Pat

public int MapId { get; set; }

public float MaxRadius { get; set; }

public MovementType MovementType { get; set; }

public static bool operator !=(PathRequest left, PathRequest right)
Expand All @@ -45,7 +48,7 @@ public override int GetHashCode()
{
unchecked
{
return (int)(17 + (A.GetHashCode() * 23) + (B.GetHashCode() * 23) + (MapId * 23) + ((int)Flags * 23) + ((int)MovementType * 23));
return (int)(17 + (A.GetHashCode() * 23) + (B.GetHashCode() * 23) + (MaxRadius * 23) + (MapId * 23) + ((int)Flags * 23) + ((int)MovementType * 23));
}
}
}
Expand Down
9 changes: 6 additions & 3 deletions AmeisenNavigation.Server/objects/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,12 @@ public class Settings
[JsonProperty("logToFile")]
public bool LogToFile { get; set; } = false;

[JsonProperty("maxPointPathCount")]
public int MaxPointPathCount { get; set; } = 256;

[JsonProperty("maxPolyPathCount")]
public int MaxPolyPathCount { get; set; } = 512;

[JsonProperty("mmapsFolder")]
public string MmapsFolder { get; set; } = "C:\\mmaps\\";

Expand All @@ -27,7 +33,4 @@ public class Settings

[JsonProperty("removeOldLog")]
public bool RemoveOldLog { get; set; } = true;

[JsonProperty("vmapsFolder")]
public string VmapsFolder { get; set; } = "C:\\vmaps\\";
}
2 changes: 1 addition & 1 deletion AmeisenNavigation.Server/packages.config
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Newtonsoft.Json" version="12.0.1" targetFramework="net461" />
<package id="Newtonsoft.Json" version="12.0.3" targetFramework="net472" />
</packages>
Loading

0 comments on commit 5c9470e

Please sign in to comment.