void TCOD_list_remove(TCOD_list_t l, const void * elt) { void **curElt; for ( curElt = TCOD_list_begin(l); curElt != TCOD_list_end(l); curElt ++) { if ( *curElt == elt ) { TCOD_list_remove_iterator(l,curElt); return; } } }
static void visit_coords(map_t *m,int startX, int startY, int x, int y, int dx, int dy, TCOD_list_t active_views, bool light_walls) { // top left int tlx=x, tly=y+STEP_SIZE; // bottom right int brx=x+STEP_SIZE, bry=y; view_t *view=NULL; while (current_view != (view_t **)TCOD_list_end(active_views)) { view=*current_view; if ( ! BELOW_OR_COLINEAR(&view->steep_line,brx,bry) ) { break; } current_view++; } if ( current_view == (view_t **)TCOD_list_end(active_views) || ABOVE_OR_COLINEAR(&view->shallow_line,tlx,tly)) { // no more active view return; } if ( !is_blocked(m,view,startX,startY,x,y,dx,dy,light_walls) ) return; if ( ABOVE(&view->shallow_line,brx,bry) && BELOW(&view->steep_line,tlx,tly)) { // view blocked // slow ! TCOD_list_remove_iterator(active_views,(void **)current_view); } else if ( ABOVE(&view->shallow_line,brx,bry)) { // shallow bump add_shallow_bump(tlx,tly,view); check_view(active_views,current_view); } else if (BELOW(&view->steep_line,tlx,tly)) { // steep bump add_steep_bump(brx,bry,view); check_view(active_views,current_view); } else { // view splitted int offset=startX+x*dx/STEP_SIZE + (startY+y*dy/STEP_SIZE)*m->width; view_t *shallower_view= & views[offset]; int view_index=current_view - (view_t **)TCOD_list_begin(active_views); view_t **shallower_view_it; view_t **steeper_view_it; *shallower_view=**current_view; // slow ! shallower_view_it = (view_t **)TCOD_list_insert_before(active_views,shallower_view,view_index); steeper_view_it=shallower_view_it+1; current_view=shallower_view_it; add_steep_bump(brx,bry,shallower_view); if (!check_view(active_views,shallower_view_it)) steeper_view_it--; add_shallow_bump(tlx,tly,*steeper_view_it); check_view(active_views,steeper_view_it); if ( view_index > TCOD_list_size(active_views)) current_view=(view_t **)TCOD_list_end(active_views); } }
static bool check_view(TCOD_list_t active_views, view_t **it) { view_t *view=*it; line_t *shallow_line=&view->shallow_line; line_t *steep_line=&view->steep_line; if (LINE_COLINEAR(shallow_line,steep_line) && (COLINEAR(shallow_line,offset,limit) || COLINEAR(shallow_line,limit,offset)) ) { //printf ("deleting view %x\n",it); // slow ! TCOD_list_remove_iterator(active_views,(void **)it); return false; } return true; }
/* this is the slow part, when we change the heuristic of a cell already in the heap */ static void heap_reorder(TCOD_path_data_t *path, uint32 offset) { uintptr *array=(uintptr *)TCOD_list_begin(path->heap); uintptr *end=(uintptr *)TCOD_list_end(path->heap); uintptr *cur=array; /* find the node corresponding to offset ... SLOW !! */ while (cur != end) { if (*cur == offset ) break; cur++; } if ( cur == end ) return; /* remove it... SLOW !! */ TCOD_list_remove_iterator(path->heap,(void **)cur); /* put it back on the heap */ TCOD_list_push(path->heap,(void *)(uintptr)offset); /* bubble the value up to its real position */ heap_sift_up(path,path->heap); }