Could this be caused by calling 'draw_text' for each tile? I use it for debugging purpose... Without it f.e. fnc ms goes down to 0.3 from ~8 grin
Sure those constant 7/8 ms is the drawing function, but I meant when you click to solve, it grows to more than 10 caused by the flood I guess, but I can be wrong.
You don't really need a list implementation. Two pointers and a linking member into the struct is enough.
Here goes a fast and untested implementation of the flood. I was too lazy to build the canvas xP
Code:
typedef struct CELL {
int depth; // <0 = wall, 0 = unvisited, >0 = visited
struct CELL *parent;
struct CELL *next;
} CELL;
CELL cells[4096];
BOOL flood(CELL *_cStart, CELL *_cEnd) {
int cellOffsets[4] = {1, 64, -1, -64};
CELL *_cListFirst = _cEnd; // candidate list
CELL *_cListLast = _cEnd; // at the beginning it only contains the ending point
_cEnd->depth = 1; // starting depth
_cEnd->next = NULL; // clean the linker
_cEnd->parent = NULL; // clean the parent
while(_cListFirst != NULL) {
CELL *_c = _cListFirst; // take the first member of the candidates list
_cListFirst = _c->next; // remove it from the list
int _newDepth = _c->depth + 1;
int *_off = cellOffsets;
int *_offLast = _off + 4;
for(; _off<_offLast; _off+=1) { // 4 directions loop
CELL *_cT = _c + *_off; // get the neighbor
if(_cT->depth != 0) // it is a wall or already visited
continue;
_cT->depth = _newDepth; // set the depth
_cT->parent = _c; // set the parent
_cT->next = NULL; // clean the linker
if (_cT == _cStart) // end when the starting point is reached
return TRUE;
// include into the candidates list
if(!_cListFirst) { // if there are no candidates in the list
_cListFirst = _cT;
_cListLast = _cT;
} else { // otherway, set as the last member in the list
_cListLast->next = _cT;
_cListLast = _cT;
}
}
}
return FALSE;
}
As you can see, it is pretty short and, let me praise, the path is solved by the chain built by the parent member.
Last edited by txesmi; 12/06/1823:47. Reason: little change