Changeset - r16156:aa205d601010
[Not reviewed]
master
0 2 0
alberth - 14 years ago 2010-10-02 09:46:40
alberth@openttd.org
(svn r20862) -Codechange: Make AyStar_Free() a method.
2 files changed with 5 insertions and 7 deletions:
0 comments (0 inline, 0 general)
src/pathfinder/npf/aystar.cpp
Show inline comments
 
@@ -189,31 +189,31 @@ static int AyStarMain_Loop(AyStar *aysta
 
	if (aystar->max_search_nodes != 0 && Hash_Size(&aystar->ClosedListHash) >= aystar->max_search_nodes) {
 
		/* We've expanded enough nodes */
 
		return AYSTAR_LIMIT_REACHED;
 
	} else {
 
		/* Return that we are still busy */
 
		return AYSTAR_STILL_BUSY;
 
	}
 
}
 

	
 
/*
 
 * This function frees the memory it allocated
 
 */
 
static void AyStarMain_Free(AyStar *aystar)
 
void AyStar::Free()
 
{
 
	aystar->OpenListQueue.Free(false);
 
	this->OpenListQueue.Free(false);
 
	/* 2nd argument above is false, below is true, to free the values only
 
	 * once */
 
	delete_Hash(&aystar->OpenListHash, true);
 
	delete_Hash(&aystar->ClosedListHash, true);
 
	delete_Hash(&this->OpenListHash, true);
 
	delete_Hash(&this->ClosedListHash, true);
 
#ifdef AYSTAR_DEBUG
 
	printf("[AyStar] Memory free'd\n");
 
#endif
 
}
 

	
 
/*
 
 * This function make the memory go back to zero
 
 *  This function should be called when you are using the same instance again.
 
 */
 
void AyStarMain_Clear(AyStar *aystar)
 
{
 
	/* Clean the Queue, but not the elements within. That will be done by
 
@@ -287,16 +287,15 @@ void init_AyStar(AyStar *aystar, Hash_Ha
 
	init_Hash(&aystar->OpenListHash, hash, num_buckets);
 
	init_Hash(&aystar->ClosedListHash, hash, num_buckets);
 

	
 
	/* Set up our sorting queue
 
	 *  BinaryHeap allocates a block of 1024 nodes
 
	 *  When that one gets full it reserves another one, till this number
 
	 *  That is why it can stay this high */
 
	aystar->OpenListQueue.Init(102400);
 

	
 
	aystar->addstart  = AyStarMain_AddStartNode;
 
	aystar->main      = AyStarMain_Main;
 
	aystar->loop      = AyStarMain_Loop;
 
	aystar->free      = AyStarMain_Free;
 
	aystar->clear     = AyStarMain_Clear;
 
	aystar->checktile = AyStarMain_CheckTile;
 
}
src/pathfinder/npf/aystar.h
Show inline comments
 
@@ -99,25 +99,24 @@ typedef void AyStar_GetNeighbours(AyStar
 

	
 
/*
 
 * If the End Node is found, this function is called.
 
 *  It can do, for example, calculate the route and put that in an array
 
 */
 
typedef void AyStar_FoundEndNode(AyStar *aystar, OpenListNode *current);
 

	
 
/* For internal use, see aystar.cpp */
 
typedef void AyStar_AddStartNode(AyStar *aystar, AyStarNode *start_node, uint g);
 
typedef int AyStar_Main(AyStar *aystar);
 
typedef int AyStar_Loop(AyStar *aystar);
 
typedef int AyStar_CheckTile(AyStar *aystar, AyStarNode *current, OpenListNode *parent);
 
typedef void AyStar_Free(AyStar *aystar);
 
typedef void AyStar_Clear(AyStar *aystar);
 

	
 
struct AyStar {
 
/* 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) */
 

	
 
	/* These should point to the application specific routines that do the
 
	 * actual work */
 
	AyStar_CalculateG *CalculateG;
 
	AyStar_CalculateH *CalculateH;
 
	AyStar_GetNeighbours *GetNeighbours;
 
	AyStar_EndNodeCheck *EndNodeCheck;
 
@@ -143,25 +142,25 @@ struct AyStar {
 
	uint max_search_nodes;
 

	
 
	/* These should be filled with the neighbours of a tile by
 
	 * GetNeighbours */
 
	AyStarNode neighbours[12];
 
	byte num_neighbours;
 

	
 
	/* These will contain the methods for manipulating the AyStar. Only
 
	 * main() should be called externally */
 
	AyStar_AddStartNode *addstart;
 
	AyStar_Main *main;
 
	AyStar_Loop *loop;
 
	AyStar_Free *free;
 
	void Free();
 
	AyStar_Clear *clear;
 
	AyStar_CheckTile *checktile;
 

	
 
	/* These will contain the open and closed lists */
 

	
 
	/* The actual closed list */
 
	Hash ClosedListHash;
 
	/* The open queue */
 
	BinaryHeap OpenListQueue;
 
	/* An extra hash to speed up the process of looking up an element in
 
	 * the open list */
 
	Hash OpenListHash;
0 comments (0 inline, 0 general)