Skip to content

Commit

Permalink
big refactoring, new navmesh tester
Browse files Browse the repository at this point in the history
  • Loading branch information
Jnnshschl committed Jan 26, 2024
1 parent 0df7265 commit d1e7a94
Show file tree
Hide file tree
Showing 22 changed files with 785 additions and 442 deletions.
16 changes: 8 additions & 8 deletions AmeisenNavigation.Server/AmeisenNavigation.Server.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -113,9 +113,9 @@
<PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpplatest</LanguageStandard>
<LanguageStandard_C>stdc17</LanguageStandard_C>
<LanguageStandard_C>Default</LanguageStandard_C>
<OpenMPSupport>true</OpenMPSupport>
<CallingConvention>FastCall</CallingConvention>
<CallingConvention>Cdecl</CallingConvention>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -132,12 +132,12 @@
<PreprocessorDefinitions>WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpplatest</LanguageStandard>
<LanguageStandard_C>stdc17</LanguageStandard_C>
<LanguageStandard_C>Default</LanguageStandard_C>
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<OmitFramePointers>true</OmitFramePointers>
<OpenMPSupport>true</OpenMPSupport>
<CallingConvention>FastCall</CallingConvention>
<CallingConvention>Cdecl</CallingConvention>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
</ClCompile>
<Link>
Expand All @@ -155,9 +155,9 @@
<PreprocessorDefinitions>_DEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpplatest</LanguageStandard>
<LanguageStandard_C>stdc17</LanguageStandard_C>
<LanguageStandard_C>Default</LanguageStandard_C>
<OpenMPSupport>true</OpenMPSupport>
<CallingConvention>FastCall</CallingConvention>
<CallingConvention>Cdecl</CallingConvention>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
Expand All @@ -174,13 +174,13 @@
<PreprocessorDefinitions>NDEBUG;_CONSOLE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
<ConformanceMode>true</ConformanceMode>
<LanguageStandard>stdcpplatest</LanguageStandard>
<LanguageStandard_C>stdc17</LanguageStandard_C>
<LanguageStandard_C>Default</LanguageStandard_C>
<EnableEnhancedInstructionSet>NotSet</EnableEnhancedInstructionSet>
<InlineFunctionExpansion>AnySuitable</InlineFunctionExpansion>
<FavorSizeOrSpeed>Speed</FavorSizeOrSpeed>
<OmitFramePointers>true</OmitFramePointers>
<OpenMPSupport>true</OpenMPSupport>
<CallingConvention>FastCall</CallingConvention>
<CallingConvention>Cdecl</CallingConvention>
<RuntimeLibrary>MultiThreadedDLL</RuntimeLibrary>
</ClCompile>
<Link>
Expand Down
6 changes: 4 additions & 2 deletions AmeisenNavigation.Server/src/Config/Config.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ struct AmeisenNavConfig
{ "fRandomPathMaxDistance", &randomPathMaxDistance },
{ "iBezierCurvePoints", &bezierCurvePoints },
{ "iCatmullRomSplinePoints", &catmullRomSplinePoints },
{ "iMaxPointPath", &maxPointPath },
{ "iMaxPolyPath", &maxPolyPath },
{ "iMaxSearchNodes", &maxSearchNodes },
{ "iMmapFormat", &mmapFormat },
Expand All @@ -33,11 +34,12 @@ struct AmeisenNavConfig
};

public:
float catmullRomSplineAlpha = 1.0f;
float catmullRomSplineAlpha = 0.5f;
float randomPathMaxDistance = 1.5f;
int bezierCurvePoints = 8;
int catmullRomSplinePoints = 4;
int maxPolyPath = 512;
int maxPointPath = 512;
int maxPolyPath = 2048;
int maxSearchNodes = 65535;
int mmapFormat = static_cast<int>(MmapFormat::UNKNOWN);
int port = 47110;
Expand Down
87 changes: 50 additions & 37 deletions AmeisenNavigation.Server/src/Main.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include "Main.hpp"

int main(int argc, const char* argv[])
int __cdecl main(int argc, const char* argv[])
{
#if defined(WIN32) || defined(WIN64)
SetConsoleTitle(L"AmeisenNavigation Server");
Expand Down Expand Up @@ -108,16 +108,18 @@ int main(int argc, const char* argv[])
delete Nav;
delete Server;

for (const auto& kv : ClientPathBuffers)
for (const auto& [id, buffers] : ClientPathBuffers)
{
if (kv.second.first)
if (buffers.first)
{
delete[] kv.second.first;
delete[] buffers.first->points;
delete[] buffers.first;
}

if (kv.second.second)
if (buffers.second)
{
delete[] kv.second.second;
delete[] buffers.second->points;
delete[] buffers.second;
}
}
}
Expand All @@ -137,18 +139,25 @@ 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]);
ClientPathBuffers[handler->GetId()] = std::make_pair
(
new Path(Config->maxPointPath),
new Path(Config->maxPointPath)
);

Nav->NewClient(handler->GetId(), static_cast<MmapFormat>(Config->mmapFormat));
}

void OnClientDisconnect(ClientHandler* handler) noexcept
{
Nav->FreeClient(handler->GetId());

delete[] ClientPathBuffers[handler->GetId()].first;
delete[] ClientPathBuffers[handler->GetId()].first->points;
delete ClientPathBuffers[handler->GetId()].first;
ClientPathBuffers[handler->GetId()].first = nullptr;

delete[] ClientPathBuffers[handler->GetId()].second;
delete[] ClientPathBuffers[handler->GetId()].second->points;
delete ClientPathBuffers[handler->GetId()].second;
ClientPathBuffers[handler->GetId()].second = nullptr;

LogI("Client Disconnected: ", handler->GetIpAddress(), ":", handler->GetPort());
Expand All @@ -167,9 +176,9 @@ void RandomPathCallback(ClientHandler* handler, char type, const void* data, int
void MoveAlongSurfaceCallback(ClientHandler* handler, char type, const void* data, int size) noexcept
{
const MoveRequestData request = *reinterpret_cast<const MoveRequestData*>(data);
float point[3]{};
Vector3 point;
Nav->MoveAlongSurface(handler->GetId(), request.mapId, request.start, request.end, point);
handler->SendData(type, point, VEC3_SIZE);
handler->SendData(type, point, sizeof(Vector3));
}

void CastRayCallback(ClientHandler* handler, char type, const void* data, int size) noexcept
Expand All @@ -179,88 +188,92 @@ void CastRayCallback(ClientHandler* handler, char type, const void* data, int si

if (Nav->CastMovementRay(handler->GetId(), request.mapId, request.start, request.end, &hit))
{
handler->SendData(type, request.end, VEC3_SIZE);
handler->SendData(type, request.end, sizeof(Vector3));
}
else
{
float zero[3]{ 0.0f };
handler->SendData(type, zero, VEC3_SIZE);
Vector3 zero;
handler->SendData(type, zero, sizeof(Vector3));
}
}

void GenericPathCallback(ClientHandler* handler, char type, const void* data, int size, PathType pathType) noexcept
{
const PathRequestData request = *reinterpret_cast<const PathRequestData*>(data);

int pathSize = 0;
float* pathBuffer = ClientPathBuffers[handler->GetId()].first;

bool pathGenerated = false;

Path& path = *ClientPathBuffers[handler->GetId()].first;
Path& pathMisc = *ClientPathBuffers[handler->GetId()].second;

switch (pathType)
{
case PathType::STRAIGHT:
pathGenerated = Nav->GetPath(handler->GetId(), request.mapId, request.start, request.end, pathBuffer, &pathSize);
pathGenerated = Nav->GetPath(handler->GetId(), request.mapId, request.start, request.end, path);
break;
case PathType::RANDOM:
pathGenerated = Nav->GetRandomPath(handler->GetId(), request.mapId, request.start, request.end, pathBuffer, &pathSize, Config->randomPathMaxDistance);
pathGenerated = Nav->GetRandomPath(handler->GetId(), request.mapId, request.start, request.end, path, Config->randomPathMaxDistance);
break;
}

if (pathGenerated)
{
HandlePathFlagsAndSendData(handler, request.flags, pathSize, pathBuffer, type);
HandlePathFlagsAndSendData(handler, request.mapId, request.flags, path, pathMisc, type, pathType);
}
else
{
float zero[3]{ 0.0f };
handler->SendData(type, zero, VEC3_SIZE);
Vector3 zero;
handler->SendData(type, zero, sizeof(Vector3));
}

path.pointCount = 0;
pathMisc.pointCount = 0;
}

void RandomPointCallback(ClientHandler* handler, char type, const void* data, int size) noexcept
{
const int mapId = *reinterpret_cast<const int*>(data);
float point[3]{};
Vector3 point;
Nav->GetRandomPoint(handler->GetId(), mapId, point);
handler->SendData(type, point, VEC3_SIZE);
handler->SendData(type, point, sizeof(Vector3));
}

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

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;
float* tmpBuffer = ClientPathBuffers[handler->GetId()].second;
Path& path = *ClientPathBuffers[handler->GetId()].first;
Path& pathMisc = *ClientPathBuffers[handler->GetId()].second;

bool pathGenerated = Nav->GetPolyExplorationPath
(
handler->GetId(),
request.mapId,
request.firstPolyPoint,
&request.firstPolyPoint,
request.polyPointCount,
pathBuffer,
&pathSize,
tmpBuffer,
path,
pathMisc,
request.start,
request.viewDistance
);

if (pathGenerated)
{
HandlePathFlagsAndSendData(handler, request.flags, pathSize, pathBuffer, type);
HandlePathFlagsAndSendData(handler, request.mapId, request.flags, path, pathMisc, type, PathType::STRAIGHT);
}
else
{
float zero[3]{ 0.0f };
handler->SendData(type, zero, VEC3_SIZE);
Vector3 zero;
handler->SendData(type, zero, sizeof(Vector3));
}

path.pointCount = 0;
pathMisc.pointCount = 0;
}
Loading

0 comments on commit d1e7a94

Please sign in to comment.