void TCOD_path_delete(TCOD_path_t p) { TCOD_path_data_t *path=(TCOD_path_data_t *)p; TCOD_IFNOT(p != NULL) return; if ( path->grid ) free(path->grid); if ( path->heur ) free(path->heur); if ( path->prev ) free(path->prev); if ( path->path ) TCOD_list_delete(path->path); if ( path->heap ) TCOD_list_delete(path->heap); free(path); }
void sensor_free(Sensor s) { free(s->id); volume_free(s->volume); if(s->vistiles) { free(s->vistiles); } TCOD_list_delete(s->visObjects); TCOD_list_delete(s->oldVisObjects); TS_LIST_CLEAR_AND_DELETE(s->stimuli, stimulus); free(s); }
static void check_quadrant(map_t *m,int startX,int startY,int dx, int dy, int extentX,int extentY, bool light_walls) { TCOD_list_t active_views=TCOD_list_new(); line_t shallow_line= {offset,limit,extentX*STEP_SIZE,0}; line_t steep_line= {limit,offset,0,extentY*STEP_SIZE}; int maxI=extentX+extentY,i=1; view_t *view= &views[startX+startY*m->width]; view->shallow_line=shallow_line; view->steep_line=steep_line; view->shallow_bump=NULL; view->steep_bump=NULL; TCOD_list_push(active_views,view); current_view=(view_t **)TCOD_list_begin(active_views); while ( i != maxI+1 && ! TCOD_list_is_empty(active_views) ) { int startJ=MAX(i-extentX,0); int maxJ=MIN(i,extentY); int j=startJ; while ( j != maxJ+1 && ! TCOD_list_is_empty(active_views) && current_view != (view_t **)TCOD_list_end(active_views) ) { int x=(i - j)*STEP_SIZE; int y=j*STEP_SIZE; visit_coords(m,startX,startY,x,y,dx,dy,active_views, light_walls); j++; } i++; current_view=(view_t **)TCOD_list_begin(active_views); } TCOD_list_delete(active_views); }
bool TCOD_bsp_traverse_level_order(TCOD_bsp_t *node, TCOD_bsp_callback_t listener, void *userData) { TCOD_list_t stack=TCOD_list_new(); TCOD_list_push(stack,node); while ( ! TCOD_list_is_empty(stack) ) { TCOD_bsp_t *node=(TCOD_bsp_t *)TCOD_list_get(stack,0); TCOD_list_remove(stack,node); if ( TCOD_bsp_left(node) ) TCOD_list_push(stack,TCOD_bsp_left(node)); if ( TCOD_bsp_right(node) ) TCOD_list_push(stack,TCOD_bsp_right(node)); if (!listener(node,userData)) { TCOD_list_delete(stack); return false; } } TCOD_list_delete(stack); return true; }
/* delete a Dijkstra object */ void TCOD_dijkstra_delete (TCOD_dijkstra_t dijkstra) { dijkstra_t * data = (dijkstra_t*)dijkstra; TCOD_IFNOT(data != NULL) return; if ( data->distances ) free(data->distances); if ( data->nodes ) free(data->nodes); if ( data->path ) TCOD_list_delete(data->path); free(data); }
void free_log(TCOD_list_t log) { struct message **iter; for (iter = (struct message **) TCOD_list_begin(log); iter != (struct message **) TCOD_list_end(log); iter++) { struct message *message = *iter; free_message(message); } TCOD_list_delete(log); }
void drawstimuli(Map m, Sensor s) { TCOD_list_t stims = sensor_consume_stimuli(s); unsigned char *tiles; mapVec pos, size, oldPt, delta; unsigned char visflags; if(TCOD_list_size(stims) > 0) { TCOD_console_print_left(NULL, 0, 10, TCOD_BKGND_NONE, " "); } for(int i = 0; i < TCOD_list_size(stims); i++) { //this is a very naive approach that completely ignores the possibility of overdraw and 'forgets' object positions Stimulus st = TCOD_list_get(stims, i); stimtype type = stimulus_type(st); TCOD_console_print_left(NULL, i*2, 10, TCOD_BKGND_NONE, "s%i", type); switch(type) { case StimTileLitChange: case StimTileVisChange: //redraw all tiles tiles = stimulus_tile_sight_change_get_new_tiles(st); pos = stimulus_tile_sight_change_get_position(st); size = stimulus_tile_sight_change_get_size(st); drawtiles(m, tiles, s, pos, size); break; case StimObjLitChange: case StimObjVisChange: //redraw object draw_object(st); break; case StimObjMoved: visflags = stimulus_obj_sight_change_get_new_flags(st); pos = stimulus_obj_sight_change_get_position(st); delta = stimulus_obj_moved_get_dir(st); oldPt = mapvec_subtract(pos, delta); TCOD_console_print_left(NULL, oldPt.x*2, oldPt.y, TCOD_BKGND_NONE, "x"); draw_object(st); TCOD_console_print_left(NULL, 0, 15, TCOD_BKGND_NONE, "got move"); break; case StimGeneric: default: TCOD_console_print_left(NULL, i*9, 16, TCOD_BKGND_NONE, "generic %d", i); break; } stimulus_free(st); } TCOD_list_delete(stims); }
int TCOD_namegen_get_nb_sets_wrapper() { TCOD_list_t l=TCOD_namegen_get_sets(); int nb = TCOD_list_size(l); TCOD_list_delete(l); return nb; }
void TCOD_map_compute_fov_diamond_raycasting(TCOD_map_t map, int player_x, int player_y, int max_radius, bool light_walls) { map_t *m = (map_t *)map; TCOD_list_t perim=TCOD_list_allocate(m->nbcells); cell_t *c; ray_data_t **r; int nbcells; int r2=max_radius*max_radius; perimidx=0; raymap=(ray_data_t **)calloc(sizeof(ray_data_t*),m->nbcells); raymap2=(ray_data_t *)calloc(sizeof(ray_data_t),m->nbcells); origx=player_x; origy=player_y; expandPerimeterFrom(m,perim,new_ray(m,0,0)); while ( perimidx < TCOD_list_size(perim) ) { ray_data_t *ray=(ray_data_t *)TCOD_list_get(perim,perimidx); int distance = 0; if ( r2 > 0 ) distance = ((ray->xloc * ray->xloc) + (ray->yloc * ray->yloc)); perimidx++; if ( distance <= r2) { merge_input(m, ray); if ( !ray->ignore ) expandPerimeterFrom(m,perim,ray); } else ray->ignore=true; } // set fov data c=m->cells; r=raymap; nbcells=m->nbcells; while ( nbcells!= 0 ) { if ( *r == NULL || (*r)->ignore || ((*r)->xerr > 0 && (*r)->xerr <= (*r)->xob ) || ((*r)->yerr > 0 && (*r)->yerr <= (*r)->yob ) ) { c->fov=0; } else { c->fov=1; } c++; r++; nbcells--; } m->cells[origx+origy*m->width].fov=1; // light walls if ( light_walls ) { int xmin=0, ymin=0, xmax=m->width, ymax=m->height; if ( max_radius > 0 ) { xmin=MAX(0,player_x-max_radius); ymin=MAX(0,player_y-max_radius); xmax=MIN(m->width,player_x+max_radius+1); ymax=MIN(m->height,player_y+max_radius+1); } TCOD_map_postproc(m,xmin,ymin,player_x,player_y,-1,-1); TCOD_map_postproc(m,player_x,ymin,xmax-1,player_y,1,-1); TCOD_map_postproc(m,xmin,player_y,player_x,ymax-1,-1,1); TCOD_map_postproc(m,player_x,player_y,xmax-1,ymax-1,1,1); } free(raymap); free(raymap2); TCOD_list_delete(perim); }