1
0
Fork 0

(svn r20868) -Codechange: Make AyStarMain_Main() a method.

release/1.1
alberth 2010-10-02 10:00:05 +00:00
parent 49ba3539b5
commit 7bb7d6c35a
3 changed files with 9 additions and 16 deletions

View File

@ -231,15 +231,15 @@ void AyStar::Clear()
* AYSTAR_NO_PATH : indicates that there was no path found. * AYSTAR_NO_PATH : indicates that there was no path found.
* AYSTAR_STILL_BUSY : indicates we have done some checked, that we did not found the path yet, and that we still have items left to try. * AYSTAR_STILL_BUSY : indicates we have done some checked, that we did not found the path yet, and that we still have items left to try.
* When the algorithm is done (when the return value is not AYSTAR_STILL_BUSY) * When the algorithm is done (when the return value is not AYSTAR_STILL_BUSY)
* aystar->clear() is called. Note that when you stop the algorithm halfway, * this->Clear() is called. Note that when you stop the algorithm halfway,
* you should still call clear() yourself! * you should still call Clear() yourself!
*/ */
int AyStarMain_Main(AyStar *aystar) int AyStar::Main()
{ {
int r, i = 0; int r, i = 0;
/* Loop through the OpenList /* Loop through the OpenList
* Quit if result is no AYSTAR_STILL_BUSY or is more than loops_per_tick */ * Quit if result is no AYSTAR_STILL_BUSY or is more than loops_per_tick */
while ((r = aystar->Loop()) == AYSTAR_STILL_BUSY && (aystar->loops_per_tick == 0 || ++i < aystar->loops_per_tick)) { } while ((r = this->Loop()) == AYSTAR_STILL_BUSY && (this->loops_per_tick == 0 || ++i < this->loops_per_tick)) { }
#ifdef AYSTAR_DEBUG #ifdef AYSTAR_DEBUG
switch (r) { switch (r) {
case AYSTAR_FOUND_END_NODE: printf("[AyStar] Found path!\n"); break; case AYSTAR_FOUND_END_NODE: printf("[AyStar] Found path!\n"); break;
@ -250,7 +250,7 @@ int AyStarMain_Main(AyStar *aystar)
#endif #endif
if (r != AYSTAR_STILL_BUSY) { if (r != AYSTAR_STILL_BUSY) {
/* We're done, clean up */ /* We're done, clean up */
aystar->Clear(); this->Clear();
} }
switch (r) { switch (r) {
@ -288,6 +288,4 @@ void init_AyStar(AyStar *aystar, Hash_HashProc hash, uint num_buckets)
* When that one gets full it reserves another one, till this number * When that one gets full it reserves another one, till this number
* That is why it can stay this high */ * That is why it can stay this high */
aystar->OpenListQueue.Init(102400); aystar->OpenListQueue.Init(102400);
aystar->main = AyStarMain_Main;
} }

View File

@ -103,9 +103,6 @@ typedef void AyStar_GetNeighbours(AyStar *aystar, OpenListNode *current);
*/ */
typedef void AyStar_FoundEndNode(AyStar *aystar, OpenListNode *current); typedef void AyStar_FoundEndNode(AyStar *aystar, OpenListNode *current);
/* For internal use, see aystar.cpp */
typedef int AyStar_Main(AyStar *aystar);
struct AyStar { struct AyStar {
/* These fields should be filled before initting the AyStar, but not changed /* These fields should be filled before initting the AyStar, but not changed
* afterwards (except for user_data and user_path)! (free and init again to change them) */ * afterwards (except for user_data and user_path)! (free and init again to change them) */
@ -128,7 +125,7 @@ struct AyStar {
void *user_target; void *user_target;
uint user_data[10]; uint user_data[10];
/* How many loops are there called before AyStarMain_Main gives /* How many loops are there called before Main() gives
* control back to the caller. 0 = until done */ * control back to the caller. 0 = until done */
byte loops_per_tick; byte loops_per_tick;
/* If the g-value goes over this number, it stops searching /* If the g-value goes over this number, it stops searching
@ -143,9 +140,9 @@ struct AyStar {
byte num_neighbours; byte num_neighbours;
/* These will contain the methods for manipulating the AyStar. Only /* These will contain the methods for manipulating the AyStar. Only
* main() should be called externally */ * Main() should be called externally */
void AddStartNode(AyStarNode *start_node, uint g); void AddStartNode(AyStarNode *start_node, uint g);
AyStar_Main *main; int Main();
int Loop(); int Loop();
void Free(); void Free();
void Clear(); void Clear();
@ -163,8 +160,6 @@ struct AyStar {
}; };
int AyStarMain_Main(AyStar *aystar);
/* Initialize an AyStar. You should fill all appropriate fields before /* Initialize an AyStar. You should fill all appropriate fields before
* callling init_AyStar (see the declaration of AyStar for which fields are * callling init_AyStar (see the declaration of AyStar for which fields are
* internal */ * internal */

View File

@ -1007,7 +1007,7 @@ static NPFFoundTargetData NPFRouteInternal(AyStarNode *start1, bool ignore_start
_npf_aystar.user_data[NPF_RAILTYPES] = railtypes; _npf_aystar.user_data[NPF_RAILTYPES] = railtypes;
/* GO! */ /* GO! */
r = AyStarMain_Main(&_npf_aystar); r = _npf_aystar.Main();
assert(r != AYSTAR_STILL_BUSY); assert(r != AYSTAR_STILL_BUSY);
if (result.best_bird_dist != 0) { if (result.best_bird_dist != 0) {