@@ -55,23 +55,23 @@ int main(int argc, const char* argv[])
5555 return 1 ;
5656 }
5757
58- if (Config->maxPointPath <= 0 )
58+ if (Config->maxPolyPath <= 0 )
5959 {
60- LogE (" iMaxPointPath has to be a value > 0" );
60+ LogE (" iMaxPolyPath has to be a value > 0" );
6161 std::cin.get ();
6262 return 1 ;
6363 }
6464
65- if (Config->maxPolyPath <= 0 )
65+ if (Config->port <= 0 || Config-> port > 65535 )
6666 {
67- LogE (" iMaxPolyPath has to be a value > 0 " );
67+ LogE (" iPort has to be a value bewtween 1 and 65535 " );
6868 std::cin.get ();
6969 return 1 ;
7070 }
7171
72- if (Config->port <= 0 || Config->port > 65535 )
72+ if (Config->maxSearchNodes <= 0 || Config->maxSearchNodes > 65535 )
7373 {
74- LogE (" iMaxPolyPath has to be a value bewtween 1 and 65535" );
74+ LogE (" iMaxSearchNodes has to be a value bewtween 1 and 65535" );
7575 std::cin.get ();
7676 return 1 ;
7777 }
@@ -84,13 +84,14 @@ int main(int argc, const char* argv[])
8484 return 1 ;
8585 }
8686
87- Nav = new AmeisenNavigation (Config->mmapsPath , Config->maxPolyPath , Config->maxPointPath );
87+ Nav = new AmeisenNavigation (Config->mmapsPath , Config->maxPolyPath , Config->maxSearchNodes );
8888 Server = new AnTcpServer (Config->ip , Config->port );
8989
9090 Server->SetOnClientConnected (OnClientConnect);
9191 Server->SetOnClientDisconnected (OnClientDisconnect);
9292
9393 Server->AddCallback (static_cast <char >(MessageType::PATH), PathCallback);
94+ Server->AddCallback (static_cast <char >(MessageType::RANDOM_PATH), RandomPathCallback);
9495 Server->AddCallback (static_cast <char >(MessageType::RANDOM_POINT), RandomPointCallback);
9596 Server->AddCallback (static_cast <char >(MessageType::RANDOM_POINT_AROUND), RandomPointAroundCallback);
9697 Server->AddCallback (static_cast <char >(MessageType::MOVE_ALONG_SURFACE), MoveAlongSurfaceCallback);
@@ -106,14 +107,14 @@ int main(int argc, const char* argv[])
106107
107108 for (const auto & kv : ClientPathBuffers)
108109 {
109- if (kv.second .second )
110+ if (kv.second .first )
110111 {
111112 delete[] kv.second .first ;
112113 }
113114
114115 if (kv.second .second )
115116 {
116- delete[] kv.second .first ;
117+ delete[] kv.second .second ;
117118 }
118119 }
119120}
@@ -129,15 +130,15 @@ int __stdcall SigIntHandler(unsigned long signal)
129130 return 1 ;
130131}
131132
132- void OnClientConnect (ClientHandler* handler)
133+ void OnClientConnect (ClientHandler* handler) noexcept
133134{
134135 LogI (" Client Connected: " , handler->GetIpAddress (), " :" , handler->GetPort ());
135136
136- ClientPathBuffers[handler->GetId ()] = std::make_pair (new float [Config->maxPointPath * 3 ], new float [Config->maxPointPath * 3 ]);
137+ ClientPathBuffers[handler->GetId ()] = std::make_pair (new float [Config->maxPolyPath * 3 ], new float [Config->maxPolyPath * 3 ]);
137138 Nav->NewClient (handler->GetId ());
138139}
139140
140- void OnClientDisconnect (ClientHandler* handler)
141+ void OnClientDisconnect (ClientHandler* handler) noexcept
141142{
142143 Nav->FreeClient (handler->GetId ());
143144
@@ -150,44 +151,17 @@ void OnClientDisconnect(ClientHandler* handler)
150151 LogI (" Client Disconnected: " , handler->GetIpAddress (), " :" , handler->GetPort ());
151152}
152153
153- void PathCallback (ClientHandler* handler, char type, const void * data, int size)
154+ void PathCallback (ClientHandler* handler, char type, const void * data, int size) noexcept
154155{
155- const PathRequestData request = *reinterpret_cast <const PathRequestData*>(data);
156-
157- int pathSize = 0 ;
158- float * pathBuffer = ClientPathBuffers[handler->GetId ()].first ;
159-
160- if (Nav->GetPath (handler->GetId (), request.mapId , request.start , request.end , pathBuffer, &pathSize))
161- {
162- if ((request.flags & static_cast <int >(PathRequestFlags::CATMULLROM)) && pathSize > 9 )
163- {
164- int smoothedPathSize = 0 ;
165- float * smoothedPathBuffer = ClientPathBuffers[handler->GetId ()].second ;
166- Nav->SmoothPathCatmullRom (pathBuffer, pathSize, smoothedPathBuffer, &smoothedPathSize, Config->catmullRomSplinePoints , Config->catmullRomSplineAlpha );
167-
168- handler->SendData (type, smoothedPathBuffer, smoothedPathSize * sizeof (float ));
169- }
170- else if ((request.flags & static_cast <int >(PathRequestFlags::CHAIKIN)) && pathSize > 6 )
171- {
172- int smoothedPathSize = 0 ;
173- float * smoothedPathBuffer = ClientPathBuffers[handler->GetId ()].second ;
174- Nav->SmoothPathChaikinCurve (pathBuffer, pathSize, smoothedPathBuffer, &smoothedPathSize);
156+ GenericPathCallback (handler, type, data, size, PathType::STRAIGHT);
157+ }
175158
176- handler->SendData (type, smoothedPathBuffer, smoothedPathSize * sizeof (float ));
177- }
178- else
179- {
180- handler->SendData (type, pathBuffer, pathSize * sizeof (float ));
181- }
182- }
183- else
184- {
185- float zero[3 ]{};
186- handler->SendData (type, zero, VEC3_SIZE);
187- }
159+ void RandomPathCallback (ClientHandler* handler, char type, const void * data, int size) noexcept
160+ {
161+ GenericPathCallback (handler, type, data, size, PathType::RANDOM);
188162}
189163
190- void RandomPointCallback (ClientHandler* handler, char type, const void * data, int size)
164+ void RandomPointCallback (ClientHandler* handler, char type, const void * data, int size) noexcept
191165{
192166 const int mapId = *reinterpret_cast <const int *>(data);
193167 float point[3 ]{};
@@ -196,7 +170,7 @@ void RandomPointCallback(ClientHandler* handler, char type, const void* data, in
196170 handler->SendData (type, point, VEC3_SIZE);
197171}
198172
199- void RandomPointAroundCallback (ClientHandler* handler, char type, const void * data, int size)
173+ void RandomPointAroundCallback (ClientHandler* handler, char type, const void * data, int size) noexcept
200174{
201175 const RandomPointAroundData request = *reinterpret_cast <const RandomPointAroundData*>(data);
202176 float point[3 ]{};
@@ -205,7 +179,7 @@ void RandomPointAroundCallback(ClientHandler* handler, char type, const void* da
205179 handler->SendData (type, point, VEC3_SIZE);
206180}
207181
208- void MoveAlongSurfaceCallback (ClientHandler* handler, char type, const void * data, int size)
182+ void MoveAlongSurfaceCallback (ClientHandler* handler, char type, const void * data, int size) noexcept
209183{
210184 const MoveRequestData request = *reinterpret_cast <const MoveRequestData*>(data);
211185 float point[3 ]{};
@@ -214,7 +188,7 @@ void MoveAlongSurfaceCallback(ClientHandler* handler, char type, const void* dat
214188 handler->SendData (type, point, VEC3_SIZE);
215189}
216190
217- void CastRayCallback (ClientHandler* handler, char type, const void * data, int size)
191+ void CastRayCallback (ClientHandler* handler, char type, const void * data, int size) noexcept
218192{
219193 const CastRayData request = *reinterpret_cast <const CastRayData*>(data);
220194 dtRaycastHit hit;
@@ -228,4 +202,53 @@ void CastRayCallback(ClientHandler* handler, char type, const void* data, int si
228202 float zero[3 ]{};
229203 handler->SendData (type, zero, VEC3_SIZE);
230204 }
205+ }
206+
207+ void GenericPathCallback (ClientHandler* handler, char type, const void * data, int size, PathType pathType) noexcept
208+ {
209+ const PathRequestData request = *reinterpret_cast <const PathRequestData*>(data);
210+
211+ int pathSize = 0 ;
212+ float * pathBuffer = ClientPathBuffers[handler->GetId ()].first ;
213+
214+ bool pathGenerated = false ;
215+
216+ switch (pathType)
217+ {
218+ case PathType::STRAIGHT:
219+ pathGenerated = Nav->GetPath (handler->GetId (), request.mapId , request.start , request.end , pathBuffer, &pathSize);
220+ break ;
221+ case PathType::RANDOM:
222+ pathGenerated = Nav->GetRandomPath (handler->GetId (), request.mapId , request.start , request.end , pathBuffer, &pathSize, Config->randomPathMaxDistance );
223+ break ;
224+ }
225+
226+ if (pathGenerated)
227+ {
228+ if ((request.flags & static_cast <int >(PathRequestFlags::CATMULLROM)) && pathSize > 9 )
229+ {
230+ int smoothedPathSize = 0 ;
231+ float * smoothedPathBuffer = ClientPathBuffers[handler->GetId ()].second ;
232+ Nav->SmoothPathCatmullRom (pathBuffer, pathSize, smoothedPathBuffer, &smoothedPathSize, Config->catmullRomSplinePoints , Config->catmullRomSplineAlpha );
233+
234+ handler->SendData (type, smoothedPathBuffer, smoothedPathSize * sizeof (float ));
235+ }
236+ else if ((request.flags & static_cast <int >(PathRequestFlags::CHAIKIN)) && pathSize > 6 )
237+ {
238+ int smoothedPathSize = 0 ;
239+ float * smoothedPathBuffer = ClientPathBuffers[handler->GetId ()].second ;
240+ Nav->SmoothPathChaikinCurve (pathBuffer, pathSize, smoothedPathBuffer, &smoothedPathSize);
241+
242+ handler->SendData (type, smoothedPathBuffer, smoothedPathSize * sizeof (float ));
243+ }
244+ else
245+ {
246+ handler->SendData (type, pathBuffer, pathSize * sizeof (float ));
247+ }
248+ }
249+ else
250+ {
251+ float zero[3 ]{};
252+ handler->SendData (type, zero, VEC3_SIZE);
253+ }
231254}
0 commit comments