StructRecord structrecord_init(StructRecord sr, char *typeName, char *name, StructRecord parent) { sr->type=strdup(typeName); sr->name = name ? strdup(name) : NULL; if(parent) { structrecord_add_child(parent, sr); } sr->flags=TCOD_list_new(); sr->props=TCOD_list_new(); sr->children=TCOD_list_new(); return sr; }
static TCOD_path_data_t *TCOD_path_new_intern(int w, int h) { TCOD_path_data_t *path=(TCOD_path_data_t *)calloc(sizeof(TCOD_path_data_t),1); path->w=w; path->h=h; path->grid=(float *)calloc(sizeof(float),w*h); path->heur=(float *)calloc(sizeof(float),w*h); path->prev=(dir_t *)calloc(sizeof(dir_t),w*h); if (! path->grid || ! path->heur || ! path->prev ) { TCOD_fatal("Fatal error : path finding module cannot allocate djikstra grids (size %dx%d)\n",w,h); exit(1); } path->path=TCOD_list_new(); path->heap=TCOD_list_new(); return path; }
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); }
/* retrieve the list of all available syllable set names */ TCOD_list_t TCOD_namegen_get_sets (void) { TCOD_list_t l = TCOD_list_new(); namegen_t ** it; for (it = (namegen_t**)TCOD_list_begin(namegen_generators_list); it < (namegen_t**)TCOD_list_end(namegen_generators_list); it++) TCOD_list_push(l,(const void*)((*it)->name)); return l; }
Sensor sensor_init(Sensor s, char *id, Volume volume, void *context) { s->id = strdup(id); s->volume = volume; volume_swept_bounds(s->volume, &(s->borig), &(s->bsz)); s->vistiles = calloc(s->bsz.x*s->bsz.y*s->bsz.z, sizeof(perception)); s->visObjects = TCOD_list_new(); s->oldVisObjects = TCOD_list_new(); s->stimuli = TCOD_list_new(); s->context = context; return s; }
TCOD_list_t TCOD_list_duplicate(TCOD_list_t l) { int i=0; void **t; TCOD_list_int_t *ret=(TCOD_list_int_t *)TCOD_list_new(); while ( ret->allocSize < LIST(l)->allocSize ) TCOD_list_allocate_int((TCOD_list_t)ret); ret->fillSize=LIST(l)->fillSize; for (t=TCOD_list_begin(l); t != TCOD_list_end(l); t++) { ret->array[i++]=*t; } return (TCOD_list_t)ret; }
/* create a new generator */ namegen_t * namegen_generator_new (void) { namegen_t * data = malloc(sizeof(namegen_t)); data->name = NULL; /* assign the rng */ data->random = TCOD_random_get_instance(); /* create the lists */ data->vocals = TCOD_list_new(); data->consonants = TCOD_list_new(); data->syllables_pre = TCOD_list_new(); data->syllables_start = TCOD_list_new(); data->syllables_middle = TCOD_list_new(); data->syllables_end = TCOD_list_new(); data->syllables_post = TCOD_list_new(); data->illegal_strings = TCOD_list_new(); data->rules = TCOD_list_new(); return (TCOD_namegen_t)data; }
bool namegen_parser_end_struct(TCOD_parser_struct_t str, const char *name) { /* if there's no syllable set by this name, add it to the list */ if (namegen_generator_check(name) == false) { parser_data->name = TCOD_strdup(name); parser_output = namegen_generator_new(); namegen_populate(parser_output,parser_data); parser_output->random = namegen_random; if (namegen_generators_list == NULL) namegen_generators_list = TCOD_list_new(); TCOD_list_push(namegen_generators_list, (const void*)parser_output); } /* free the allocated memory to prevent a memory leak */ namegen_syllables_delete(parser_data); return true; }
bool TCOD_bsp_traverse_inverted_level_order(TCOD_bsp_t *node, TCOD_bsp_callback_t listener, void *userData) { TCOD_list_t stack1=TCOD_list_new(); TCOD_list_t stack2=TCOD_list_new(); TCOD_list_push(stack1,node); while ( ! TCOD_list_is_empty(stack1) ) { TCOD_bsp_t *node=(TCOD_bsp_t *)TCOD_list_get(stack1,0); TCOD_list_push(stack2,node); TCOD_list_remove(stack1,node); if ( TCOD_bsp_left(node) ) TCOD_list_push(stack1,TCOD_bsp_left(node)); if ( TCOD_bsp_right(node) ) TCOD_list_push(stack1,TCOD_bsp_right(node)); } while ( ! TCOD_list_is_empty(stack2) ) { TCOD_bsp_t *node=(TCOD_bsp_t *)TCOD_list_pop(stack2); if (!listener(node,userData)) { TCOD_list_delete(stack1); TCOD_list_delete(stack2); return false; } } TCOD_list_delete(stack1); TCOD_list_delete(stack2); return true; }
/* run the parser */ void namegen_parser_run (const char * filename) { char ** it; /* prepare the parser --- this will be executed only once */ namegen_parser_prepare(); if (parsed_files == NULL) parsed_files = TCOD_list_new(); if (TCOD_list_size(parsed_files) > 0) { for (it = (char **)TCOD_list_begin(parsed_files); it != (char **)TCOD_list_end(parsed_files); it++) if (strcmp(*it,filename) == 0) return; } /* if the file hasn't been parsed yet, add its name to the list so that it's never parsed twice */ TCOD_list_push(parsed_files,(const void *)TCOD_strdup(filename)); /* run the parser */ TCOD_parser_run(namegen_parser,filename,&namegen_listener); }
/* check whether a given generator already exists */ bool namegen_generator_check (const char * name) { /* if the list is not created yet, create it */ if (namegen_generators_list == NULL) { namegen_generators_list = TCOD_list_new(); return false; } /* otherwise, scan it for the name */ else { namegen_t ** it; for (it = (namegen_t**)TCOD_list_begin(namegen_generators_list); it < (namegen_t**)TCOD_list_end(namegen_generators_list); it++) { if (strcmp((*it)->name,name) == 0) return true; } return false; } }
TCOD_dijkstra_t TCOD_dijkstra_new_using_function(int map_width, int map_height, TCOD_path_func_t func, void *user_data, float diagonalCost) { dijkstra_t * data; TCOD_IFNOT(func != NULL && map_width > 0 && map_height > 0) return NULL; data = malloc(sizeof(dijkstra_t)); data->map = NULL; data->func = func; data->user_data=user_data; data->distances = malloc(map_width*map_height*sizeof(int)*4); data->nodes = malloc(map_width*map_height*sizeof(int)*4); data->diagonal_cost = (int)((diagonalCost * 100.0f)+0.1f); /* because (int)(1.41f*100.0f) == 140!!! */ data->width = map_width; data->height = map_height; data->nodes_max = map_width*map_height; data->path = TCOD_list_new(); return (TCOD_dijkstra_t)data; }
/* create a Dijkstra object */ TCOD_dijkstra_t TCOD_dijkstra_new (TCOD_map_t map, float diagonalCost) { dijkstra_t * data ; TCOD_IFNOT(map != NULL) return NULL; data = malloc(sizeof(dijkstra_t)); data->map = map; data->func = NULL; data->user_data=NULL; data->distances = malloc(TCOD_map_get_nb_cells(data->map)*sizeof(int)); data->nodes = malloc(TCOD_map_get_nb_cells(data->map)*sizeof(int)); data->diagonal_cost = (int)((diagonalCost * 100.0f)+0.1f); /* because (int)(1.41f*100.0f) == 140!!! */ data->width = TCOD_map_get_width(data->map); data->height = TCOD_map_get_height(data->map); data->nodes_max = TCOD_map_get_nb_cells(data->map); data->path = TCOD_list_new(); return (TCOD_dijkstra_t)data; }
struct gui *mkgui(int w, int h) { struct gui *gui = malloc(sizeof *gui); if (gui) { gui->con = TCOD_console_new(w, h); gui->inventory_con = TCOD_console_new(INVENTORY_WIDTH, INVENTORY_HEIGHT); gui->render_bar = render_bar; gui->render_log = render_log; gui->render_mouse_look = render_mouse_look; gui->render = gui_render; gui->message = message; gui->log = TCOD_list_new(); } return gui; }
TCOD_list_t TCOD_sys_get_directory_content(const char *path, const char *pattern) { TCOD_list_t list=TCOD_list_new(); #ifdef TCOD_WINDOWS WIN32_FIND_DATA FileData; HANDLE hList; char dname[ 512 ]; sprintf(dname, "%s\\*",path); hList = FindFirstFile(dname, &FileData); if (hList == INVALID_HANDLE_VALUE) { return list; } do { if ( ! (strcmp(FileData.cFileName,".") == 0 || strcmp(FileData.cFileName,"..") == 0 ) ) { if ( filename_match(FileData.cFileName,pattern) ) TCOD_list_push(list,TCOD_strdup(FileData.cFileName)); } } while ( FindNextFile(hList, &FileData) ); FindClose(hList); #else DIR *dir = opendir(path); struct dirent *dirent = NULL; if ( ! dir ) return list; while ( ( dirent = readdir(dir) ) ) { if ( ! (strcmp(dirent->d_name,".") == 0 || strcmp(dirent->d_name,"..") == 0 ) ) { if ( filename_match(dirent->d_name,pattern) ) TCOD_list_push(list,strdup(dirent->d_name)); } } closedir(dir); #endif return list; }
TCOD_list_t TCOD_list_allocate(int nb_elements) { TCOD_list_t l=TCOD_list_new(); LIST(l)->array = (void **)calloc(sizeof(void *),nb_elements); LIST(l)->allocSize = nb_elements; return l; }
Loader loader_init(Loader l, char *basePath) { l->path = strdup(basePath); //first, install the basic trigger schema. this happens before any config files are loaded. l->triggerSchema = flagschema_init(flagschema_new()); #define ADD_TRIGGER(_trigName) flagschema_insert(l->triggerSchema, "on_" #_trigName , 1) ADD_TRIGGER(enter); ADD_TRIGGER(exit); ADD_TRIGGER(inside); ADD_TRIGGER(bump); ADD_TRIGGER(atop); ADD_TRIGGER(walk_up); ADD_TRIGGER(walk_down); ADD_TRIGGER(fall_onto); ADD_TRIGGER(fall_through); ADD_TRIGGER(chomp); ADD_TRIGGER(unchomp); ADD_TRIGGER(attach); ADD_TRIGGER(release); ADD_TRIGGER(eat); ADD_TRIGGER(digesting); ADD_TRIGGER(digested); ADD_TRIGGER(carry); ADD_TRIGGER(carry_left); ADD_TRIGGER(carry_right); ADD_TRIGGER(carry_back); ADD_TRIGGER(carry_forward); ADD_TRIGGER(carry_up); ADD_TRIGGER(carry_down); ADD_TRIGGER(latch); ADD_TRIGGER(tug_left); ADD_TRIGGER(tug_right); ADD_TRIGGER(tug_back); ADD_TRIGGER(tug_forward); #undef ADD_TRIGGER l->configParser = configlistener_init_parser(TCOD_parser_new(), l); l->configListener = configlistener_init(configlistener_new(), l); l->moveFlags = TCOD_list_new(); loader_add_move_flag(l, "normal"); loader_load_config(l, "init"); l->statusParser = statuslistener_init_parser(TCOD_parser_new(), l); l->statusListener = statuslistener_init(statuslistener_new(), l); TCOD_list_t statusFiles = configlistener_status_files(l->configListener); TS_LIST_FOREACH(statusFiles, loader_load_status(l, each)); l->objectParser = objectlistener_init_parser(TCOD_parser_new(), l); l->objectListener = objectlistener_init(objectlistener_new(), l); l->mapParser = maplistener_init_parser(TCOD_parser_new(), l); l->mapListener = maplistener_init(maplistener_new(), l); l->saveParser = savelistener_init_parser(TCOD_parser_new(), l); l->saveListener = savelistener_init(savelistener_new(), l); return l; }
TCOD_list_t sensor_consume_stimuli(Sensor s) { TCOD_list_t ret = s->stimuli; s->stimuli = TCOD_list_new(); return ret; }