Skip to content

Commit

Permalink
update recastnavigation parameters, add polygon class with bridsons p…
Browse files Browse the repository at this point in the history
…oisson disk sampling
  • Loading branch information
Jnnshschl committed Jan 10, 2024
1 parent 763a464 commit 76cba14
Show file tree
Hide file tree
Showing 37 changed files with 7,033 additions and 3,245 deletions.
4 changes: 3 additions & 1 deletion AmeisenNavigation.Server/AmeisenNavigation.Server.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,9 @@
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpplatest</LanguageStandard>
<LanguageStandard_C>stdc17</LanguageStandard_C>
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<OmitFramePointers>true</OmitFramePointers>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand Down Expand Up @@ -180,7 +183,6 @@
<ItemGroup>
<ClInclude Include="resource.h" />
<ClInclude Include="src\Config\Config.hpp" />
<ClInclude Include="src\Enums\EMessageType.hpp" />
<ClInclude Include="src\Logging\AmeisenLogger.hpp" />
<ClInclude Include="src\Main.hpp" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
<ClInclude Include="src\Main.hpp">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClInclude Include="src\Enums\EMessageType.hpp">
<Filter>Headerdateien</Filter>
</ClInclude>
<ClInclude Include="src\Config\Config.hpp">
<Filter>Headerdateien</Filter>
</ClInclude>
Expand Down
6 changes: 3 additions & 3 deletions AmeisenNavigation.Server/src/Config/Config.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#pragma once

#include <map>
#include <unordered_map>
#include <string>
#include <fstream>
#include <sstream>
Expand All @@ -16,7 +16,7 @@ constexpr auto CONFIG_CHAR_DELIMITER = '=';
struct AmeisenNavConfig
{
private:
std::map<std::string, void*> Map
std::unordered_map<std::string, void*> Map
{
{ "fCatmullRomSplineAlpha", &catmullRomSplineAlpha },
{ "fRandomPathMaxDistance", &randomPathMaxDistance },
Expand All @@ -36,7 +36,7 @@ struct AmeisenNavConfig
int maxPolyPath = 512;
int maxSearchNodes = 65535;
int port = 47110;
int clientVersion = static_cast<int>(CLIENT_VERSION::V335A);
int clientVersion = static_cast<int>(ClientVersion::TC335A);
std::string ip = "127.0.0.1";
std::string mmapsPath = "C:\\shady stuff\\mmaps\\";

Expand Down
9 changes: 0 additions & 9 deletions AmeisenNavigation.Server/src/Enums/EMessageType.hpp

This file was deleted.

2 changes: 1 addition & 1 deletion AmeisenNavigation.Server/src/Logging/AmeisenLogger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ template<typename ...Args>
constexpr void Log(const std::string& tag, int color, int colorSecond, Args&& ...args)
{
#if defined WIN32 || defined WIN64
static void* ConsoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
void* ConsoleHandle = GetStdHandle(STD_OUTPUT_HANDLE);
#endif

std::cout << std::setw(14) << tag;
Expand Down
92 changes: 51 additions & 41 deletions AmeisenNavigation.Server/src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,12 +91,15 @@ int main(int argc, const char* argv[])
Server->SetOnClientDisconnected(OnClientDisconnect);

Server->AddCallback(static_cast<char>(MessageType::PATH), PathCallback);
Server->AddCallback(static_cast<char>(MessageType::RANDOM_PATH), RandomPathCallback);
Server->AddCallback(static_cast<char>(MessageType::RANDOM_POINT), RandomPointCallback);
Server->AddCallback(static_cast<char>(MessageType::RANDOM_POINT_AROUND), RandomPointAroundCallback);
Server->AddCallback(static_cast<char>(MessageType::MOVE_ALONG_SURFACE), MoveAlongSurfaceCallback);
Server->AddCallback(static_cast<char>(MessageType::CAST_RAY), CastRayCallback);

Server->AddCallback(static_cast<char>(MessageType::RANDOM_PATH), RandomPathCallback);
Server->AddCallback(static_cast<char>(MessageType::RANDOM_POINT), RandomPointCallback);

Server->AddCallback(static_cast<char>(MessageType::EXPLORE_POLY), CastRayCallback);

LogS("Starting server on: ", Config->ip, ":", std::to_string(Config->port));
Server->Run();

Expand Down Expand Up @@ -135,7 +138,7 @@ void OnClientConnect(ClientHandler* handler) noexcept
LogI("Client Connected: ", handler->GetIpAddress(), ":", handler->GetPort());

ClientPathBuffers[handler->GetId()] = std::make_pair(new float[Config->maxPolyPath * 3], new float[Config->maxPolyPath * 3]);
Nav->NewClient(handler->GetId(), static_cast<CLIENT_VERSION>(Config->clientVersion));
Nav->NewClient(handler->GetId(), static_cast<ClientVersion>(Config->clientVersion));
}

void OnClientDisconnect(ClientHandler* handler) noexcept
Expand All @@ -161,29 +164,10 @@ void RandomPathCallback(ClientHandler* handler, char type, const void* data, int
GenericPathCallback(handler, type, data, size, PathType::RANDOM);
}

void RandomPointCallback(ClientHandler* handler, char type, const void* data, int size) noexcept
{
const int mapId = *reinterpret_cast<const int*>(data);
float point[3]{};

Nav->GetRandomPoint(handler->GetId(), mapId, point);
handler->SendData(type, point, VEC3_SIZE);
}

void RandomPointAroundCallback(ClientHandler* handler, char type, const void* data, int size) noexcept
{
const RandomPointAroundData request = *reinterpret_cast<const RandomPointAroundData*>(data);
float point[3]{};

Nav->GetRandomPointAround(handler->GetId(), request.mapId, request.start, request.radius, point);
handler->SendData(type, point, VEC3_SIZE);
}

void MoveAlongSurfaceCallback(ClientHandler* handler, char type, const void* data, int size) noexcept
{
const MoveRequestData request = *reinterpret_cast<const MoveRequestData*>(data);
float point[3]{};

Nav->MoveAlongSurface(handler->GetId(), request.mapId, request.start, request.end, point);
handler->SendData(type, point, VEC3_SIZE);
}
Expand Down Expand Up @@ -225,30 +209,56 @@ void GenericPathCallback(ClientHandler* handler, char type, const void* data, in

if (pathGenerated)
{
if ((request.flags & static_cast<int>(PathRequestFlags::CATMULLROM)) && pathSize > 9)
{
int smoothedPathSize = 0;
float* smoothedPathBuffer = ClientPathBuffers[handler->GetId()].second;
Nav->SmoothPathCatmullRom(pathBuffer, pathSize, smoothedPathBuffer, &smoothedPathSize, Config->catmullRomSplinePoints, Config->catmullRomSplineAlpha);
HandlePathFlagsAndSendData(handler, request.flags, pathSize, pathBuffer, type);
}
else
{
float zero[3]{};
handler->SendData(type, zero, VEC3_SIZE);
}
}

handler->SendData(type, smoothedPathBuffer, smoothedPathSize * sizeof(float));
}
else if ((request.flags & static_cast<int>(PathRequestFlags::CHAIKIN)) && pathSize > 6)
{
int smoothedPathSize = 0;
float* smoothedPathBuffer = ClientPathBuffers[handler->GetId()].second;
Nav->SmoothPathChaikinCurve(pathBuffer, pathSize, smoothedPathBuffer, &smoothedPathSize);
void RandomPointCallback(ClientHandler* handler, char type, const void* data, int size) noexcept
{
const int mapId = *reinterpret_cast<const int*>(data);
float point[3]{};
Nav->GetRandomPoint(handler->GetId(), mapId, point);
handler->SendData(type, point, VEC3_SIZE);
}

handler->SendData(type, smoothedPathBuffer, smoothedPathSize * sizeof(float));
}
else
{
handler->SendData(type, pathBuffer, pathSize * sizeof(float));
}
void RandomPointAroundCallback(ClientHandler* handler, char type, const void* data, int size) noexcept
{
const RandomPointAroundData request = *reinterpret_cast<const RandomPointAroundData*>(data);
float point[3]{};
Nav->GetRandomPointAround(handler->GetId(), request.mapId, request.start, request.radius, point);
handler->SendData(type, point, VEC3_SIZE);
}

void ExplorePolyCallback(ClientHandler* handler, char type, const void* data, int size) noexcept
{
const ExplorePolyData request = *reinterpret_cast<const ExplorePolyData*>(data);

int pathSize = 0;
float* pathBuffer = ClientPathBuffers[handler->GetId()].first;
bool pathGenerated = Nav->GetExplorePolyPath
(
handler->GetId(),
request.mapId,
request.firstPolyPoint,
request.polyPointCount,
pathBuffer,
&pathSize,
request.start,
request.viewDistance
);

if (pathGenerated)
{
HandlePathFlagsAndSendData(handler, request.flags, pathSize, pathBuffer, type);
}
else
{
float zero[3]{};
handler->SendData(type, zero, VEC3_SIZE);
}
}
}
62 changes: 48 additions & 14 deletions AmeisenNavigation.Server/src/Main.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,18 +11,18 @@
#include <iostream>
#include <mutex>

constexpr auto AMEISENNAV_VERSION = "1.8.2.0";

constexpr auto AMEISENNAV_VERSION = "1.8.3.0";
constexpr auto VEC3_SIZE = sizeof(float) * 3;

enum class MessageType
{
PATH,
MOVE_ALONG_SURFACE,
RANDOM_POINT,
RANDOM_POINT_AROUND,
CAST_RAY,
RANDOM_PATH,
PATH, // Generate a simple straight path
MOVE_ALONG_SURFACE, // Move an entity by small deltas using pathfinding (usefull to prevent falling off edges...)
RANDOM_POINT, // Get a random point on the mesh
RANDOM_POINT_AROUND, // Get a random point on the mesh in a circle
CAST_RAY, // Cast a movement ray to test for obstacles
RANDOM_PATH, // Generate a straight path where the nodes get offsetted by a random value
EXPLORE_POLY, // Generate a route to explore the polygon (W.I.P)
};

enum class PathType
Expand All @@ -34,8 +34,8 @@ enum class PathType
enum class PathRequestFlags : int
{
NONE = 0,
CHAIKIN = 1,
CATMULLROM = 2,
SMOOTH_CHAIKIN = 1,
SMOOTH_CATMULLROM = 2,
};

struct PathRequestData
Expand Down Expand Up @@ -67,11 +67,21 @@ struct RandomPointAroundData
float radius;
};

struct ExplorePolyData
{
int mapId;
int flags;
float start[3];
float viewDistance;
int polyPointCount;
float firstPolyPoint[3];
};

inline AnTcpServer* Server = nullptr;
inline AmeisenNavigation* Nav = nullptr;
inline AmeisenNavConfig* Config = nullptr;

inline std::unordered_map<int, std::pair<float*, float*>> ClientPathBuffers;
inline std::unordered_map<size_t, std::pair<float*, float*>> ClientPathBuffers;

int __stdcall SigIntHandler(unsigned long signal);

Expand All @@ -80,9 +90,33 @@ void OnClientDisconnect(ClientHandler* handler) noexcept;

void PathCallback(ClientHandler* handler, char type, const void* data, int size) noexcept;
void RandomPathCallback(ClientHandler* handler, char type, const void* data, int size) noexcept;
void RandomPointCallback(ClientHandler* handler, char type, const void* data, int size) noexcept;
void RandomPointAroundCallback(ClientHandler* handler, char type, const void* data, int size) noexcept;
void MoveAlongSurfaceCallback(ClientHandler* handler, char type, const void* data, int size) noexcept;
void CastRayCallback(ClientHandler* handler, char type, const void* data, int size) noexcept;

void GenericPathCallback(ClientHandler* handler, char type, const void* data, int size, PathType pathType) noexcept;

void RandomPointCallback(ClientHandler* handler, char type, const void* data, int size) noexcept;
void RandomPointAroundCallback(ClientHandler* handler, char type, const void* data, int size) noexcept;

void ExplorePolyCallback(ClientHandler* handler, char type, const void* data, int size) noexcept;

inline void HandlePathFlagsAndSendData(ClientHandler* handler, int flags, int pathSize, float* pathBuffer, char type) noexcept
{
if ((flags & static_cast<int>(PathRequestFlags::SMOOTH_CATMULLROM)) && pathSize > 9)
{
int smoothedPathSize = 0;
float* smoothedPathBuffer = ClientPathBuffers[handler->GetId()].second;
Nav->SmoothPathCatmullRom(pathBuffer, pathSize, smoothedPathBuffer, &smoothedPathSize, Config->catmullRomSplinePoints, Config->catmullRomSplineAlpha);
handler->SendData(type, smoothedPathBuffer, smoothedPathSize * sizeof(float));
}
else if ((flags & static_cast<int>(PathRequestFlags::SMOOTH_CHAIKIN)) && pathSize > 6)
{
int smoothedPathSize = 0;
float* smoothedPathBuffer = ClientPathBuffers[handler->GetId()].second;
Nav->SmoothPathChaikinCurve(pathBuffer, pathSize, smoothedPathBuffer, &smoothedPathSize);
handler->SendData(type, smoothedPathBuffer, smoothedPathSize * sizeof(float));
}
else
{
handler->SendData(type, pathBuffer, pathSize * sizeof(float));
}
}
10 changes: 5 additions & 5 deletions AmeisenNavigation.Tester/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,23 +41,23 @@ public IEnumerable<Vector3> GetPath(MessageType msgType, int mapId, Vector3 star
{
try
{
return Client.IsConnected ? Client.Send((byte)msgType, (mapId, flags, start, end)).AsArray<Vector3>() : Array.Empty<Vector3>();
return Client.IsConnected ? Client.Send((byte)msgType, (mapId, flags, start, end)).AsArray<Vector3>() : [];
}
catch
{
return Array.Empty<Vector3>();
return [];
}
}

public Vector3 GetPoint(int mapId)
{
try
{
return Client.IsConnected ? Client.Send((byte)MessageType.RANDOM_POINT, mapId).As<Vector3>() : new Vector3();
return Client.IsConnected ? Client.Send((byte)MessageType.RANDOM_POINT, mapId).As<Vector3>() : new();
}
catch
{
return new Vector3();
return new();
}
}

Expand Down Expand Up @@ -187,7 +187,7 @@ private void Window_Loaded(object sender, RoutedEventArgs e)
TextBoxEndZ.Text = end.Z.ToString();
}

private bool TryLoadFloat(TextBox textBox, out float f)
private static bool TryLoadFloat(TextBox textBox, out float f)
{
bool result = float.TryParse(textBox.Text, out f);
// mark textbox red
Expand Down
Loading

0 comments on commit 76cba14

Please sign in to comment.