map_iterator_t map_insert(map_t* pt_map, const pair_t* cpt_pair) { pair_t t_elempair; map_iterator_t t_result; #ifdef CSTL_MAP_AVL_TREE avl_tree_result_pair_t t_avlresult; #else rb_tree_result_pair_t t_rbresult; #endif assert(pt_map != NULL && cpt_pair != NULL); assert(_same_map_pair_type(&pt_map->_t_pair, cpt_pair)); /* initialize the new pair */ t_elempair = _create_pair( pt_map->_t_pair._t_firsttypesize, pt_map->_t_pair._sz_firsttypename, pt_map->_t_pair._t_secondtypesize, pt_map->_t_pair._sz_secondtypename); pair_init(&t_elempair); memcpy(t_elempair.first, cpt_pair->first, t_elempair._t_firsttypesize); memcpy(t_elempair.second, cpt_pair->second, t_elempair._t_secondtypesize); /* insert pair into tree */ #ifdef CSTL_MAP_AVL_TREE t_avlresult = _avl_tree_insert_unique(_GET_MAP_AVL_TREE(pt_map), &t_elempair); if(t_avlresult._t_second._t_bool) { t_result = t_avlresult._t_first; } else { t_result = map_end(pt_map); pair_destroy(&t_elempair); } #else t_rbresult = _rb_tree_insert_unique(_GET_MAP_RB_TREE(pt_map), &t_elempair); if(t_rbresult._t_second._t_bool) { t_result = t_rbresult._t_first; } else { t_result = map_end(pt_map); pair_destroy(&t_elempair); } #endif _GET_CONTAINER(&t_result) = pt_map; _GET_MAP_CONTAINER_TYPE(&t_result) = _MAP_CONTAINER; _GET_MAP_ITERATOR_TYPE(&t_result) = _BIDIRECTIONAL_ITERATOR; return t_result; }
void app_end(void) { if (server.map_open) map_end(); if (server.game_open) game_end(); // shut down app console_add_system("Closing App"); // shutdown view if (!app.dedicated_host) view_shutdown(); // physics ray tracing ray_trace_shutdown(); // shutdown server server_shutdown(); // OS network shutdown net_shutdown(); }
void map_init_copy(map_t* pt_mapdest, const map_t* cpt_mapsrc) { assert(pt_mapdest != NULL && cpt_mapsrc != NULL); assert( pt_mapdest->_t_pair._t_firsttypesize == cpt_mapsrc->_t_pair._t_firsttypesize && pt_mapdest->_t_pair._t_secondtypesize == cpt_mapsrc->_t_pair._t_secondtypesize); assert( strncmp( pt_mapdest->_t_pair._sz_firsttypename, cpt_mapsrc->_t_pair._sz_firsttypename, _ELEM_TYPE_NAME_SIZE) == 0 && strncmp( pt_mapdest->_t_pair._sz_secondtypename, cpt_mapsrc->_t_pair._sz_secondtypename, _ELEM_TYPE_NAME_SIZE) == 0); /* initialize dest map with src map attribute */ map_init(pt_mapdest); /* insert all element from src to dest */ if(!map_empty(cpt_mapsrc)) { map_insert_range(pt_mapdest, map_begin(cpt_mapsrc), map_end(cpt_mapsrc)); } }
void map_assign(map_t* pt_mapdest, const map_t* cpt_mapsrc) { assert(pt_mapdest != NULL && cpt_mapsrc != NULL); assert(_same_map_pair_type(&pt_mapdest->_t_pair, &cpt_mapsrc->_t_pair)); /* destroy dest map */ map_destroy(pt_mapdest); /* initialize dest map with src map attribute */ map_init(pt_mapdest); /* insert all element from src to dest */ if(!map_empty(cpt_mapsrc)) { map_insert_range(pt_mapdest, map_begin(cpt_mapsrc), map_end(cpt_mapsrc)); } }
/** * Assign map container. */ void map_assign(map_t* pmap_dest, const map_t* cpmap_src) { assert(pmap_dest != NULL); assert(cpmap_src != NULL); assert(_pair_is_inited(&pmap_dest->_pair_temp)); assert(_pair_is_inited(&cpmap_src->_pair_temp)); assert(_map_same_pair_type_ex(&pmap_dest->_pair_temp, &cpmap_src->_pair_temp)); /* clear */ map_clear(pmap_dest); /* insert all element from src to dest */ if(!map_empty(cpmap_src)) { map_insert_range(pmap_dest, map_begin(cpmap_src), map_end(cpmap_src)); } }
/** * Initialize map container with map. */ void map_init_copy(map_t* pmap_dest, const map_t* cpmap_src) { assert(pmap_dest != NULL); assert(cpmap_src != NULL); assert(_pair_is_created(&pmap_dest->_pair_temp)); assert(_pair_is_inited(&cpmap_src->_pair_temp)); /* initialize dest map with src map attribute */ map_init(pmap_dest); pmap_dest->_bfun_keycompare = cpmap_src->_bfun_keycompare; pmap_dest->_bfun_valuecompare = cpmap_src->_bfun_valuecompare; pmap_dest->_pair_temp._bfun_mapkeycompare = cpmap_src->_pair_temp._bfun_mapkeycompare; pmap_dest->_pair_temp._bfun_mapvaluecompare = cpmap_src->_pair_temp._bfun_mapvaluecompare; assert(_map_same_pair_type_ex(&pmap_dest->_pair_temp, &cpmap_src->_pair_temp)); /* insert all element from src to dest */ if(!map_empty(cpmap_src)) { map_insert_range(pmap_dest, map_begin(cpmap_src), map_end(cpmap_src)); } }
void boucle_principal(t_bal *bal, t_brick *brick, t_env *e) { t_seg s; while (1) { if (map_end(e)) change_map(e); if (glfwWindowShouldClose(e->window)) break ; glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT); draw_bricks(e, brick); draw_seg(&s, e); if (e->space == 0) bal->x1 = e->x_bar + 0.125; draw_circle(bal, e); draw_barre(e->x_bar, -0.90); if (e->space == 1 && e->pauz == 1) move_bal(bal, e); glfwSwapBuffers(e->window); glfwPollEvents(); } }
/** * Access an element with specific index. */ void* _map_at_varg(map_t* pmap_map, va_list val_elemlist) { map_iterator_t it_iter; va_list val_elemlist_copy; assert(pmap_map != NULL); assert(_pair_is_inited(&pmap_map->_pair_temp)); va_copy(val_elemlist_copy, val_elemlist); _type_get_varg_value(&pmap_map->_pair_temp._t_typeinfofirst, val_elemlist, pmap_map->_pair_temp._pv_first); #ifdef CSTL_MAP_AVL_TREE it_iter = _avl_tree_insert_unique(&pmap_map->_t_tree, &pmap_map->_pair_temp); #else it_iter = _rb_tree_insert_unique(&pmap_map->_t_tree, &pmap_map->_pair_temp); #endif _ITERATOR_CONTAINER(it_iter) = pmap_map; _MAP_ITERATOR_CONTAINER_TYPE(it_iter) = _MAP_CONTAINER; _MAP_ITERATOR_ITERATOR_TYPE(it_iter) = _BIDIRECTIONAL_ITERATOR; if(iterator_equal(it_iter, map_end(pmap_map))) { it_iter = _map_find_varg(pmap_map, val_elemlist_copy); } va_end(val_elemlist_copy); /* char* */ if(strncmp(_GET_MAP_SECOND_TYPE_BASENAME(pmap_map), _C_STRING_TYPE, _TYPE_NAME_SIZE) == 0) { return (char*)string_c_str((string_t*)((pair_t*)iterator_get_pointer(it_iter))->_pv_second); } else { return ((pair_t*)iterator_get_pointer(it_iter))->_pv_second; } }
bool app_run_dedicated_host(char *err_str) { char str[256]; // launch directly into hosting // setup hosting flags and IPs host_game_setup(); net_host_game_setup(); net_setup.mode=net_mode_host; net_setup.client.latency=0; net_setup.client.host_addr.ip=0; net_setup.client.host_addr.port=0; net_create_project_hash(); // setup map map.info.name[0]=0x0; strcpy(map.info.host_name,setup.network.map_list.maps[net_setup.host.current_map_idx].name); // start game if (!game_start(FALSE,skill_medium,0,0,err_str)) { net_host_game_end(); return(FALSE); } // add any multiplayer bots if (!game_multiplayer_bots_create(err_str)) { game_end(); net_host_game_end(); return(FALSE); } // start the map if (!map_start(FALSE,TRUE,err_str)) { game_end(); net_host_game_end(); return(FALSE); } // start hosting if (!net_host_game_start(err_str)) { map_end(); game_end(); net_host_game_end(); return(FALSE); } // dedicated hosting, no local // player to add, only add // multiplayer bots to host net_host_join_multiplayer_bots(); // game is running sprintf(str,"Running on %s...",net_setup.host.ip_resolve); console_add(str); server.next_state=gs_running; return(TRUE); }
bool game_file_load(char *file_name,char *err_str) { char *c,path[1024],fname[256]; file_save_header head; // load and expand strcpy(fname,file_name); c=strrchr(fname,'.'); if (c!=NULL) *c=0x0; // remove any extensions file_paths_documents(&setup.file_path_setup,path,"Saved Games",fname,"sav"); if (!game_file_expand_load(path,err_str)) return(FALSE); game_file_pos=0; progress_initialize("Loading"); // if game isn't running, then start if (!server.game_open) { if (!game_start(skill_medium,NULL,err_str)) { free(game_file_data); return(FALSE); } } // get header game_file_get_chunk(&head); // check version if (strcmp(head.version,dim3_version)!=0) { sprintf(err_str,"This saved game file is from a different version of dim3"); free(game_file_data); return(FALSE); } // reload map progress_draw(10); if ((!server.map_open) || (strcmp(head.map_name,map.info.name)!=0)) { // need to load a map? if (server.map_open) map_end(); strcpy(map.info.name,head.map_name); map.info.player_start_name[0]=0x0; map.info.player_start_type[0]=0x0; map.info.in_load=TRUE; if (!map_start(TRUE,err_str)) { free(game_file_data); return(FALSE); } } // timing game_time_set(head.tick); // view and server objects progress_draw(20); game_file_get_chunk(&view.time); game_file_get_chunk(&view.fps); game_file_get_chunk(&camera); game_file_get_chunk(&server.time); game_file_get_chunk(&server.player_obj_uid); game_file_get_chunk(&server.skill); game_file_get_chunk(&server.uid); game_file_get_chunk(&server.count); progress_draw(30); free(server.objs); free(server.weapons); free(server.proj_setups); server.objs=(obj_type*)game_file_replace_chunk(); server.weapons=(weapon_type*)game_file_replace_chunk(); server.proj_setups=(proj_setup_type*)game_file_replace_chunk(); if ((server.objs==NULL) || (server.weapons==NULL) || (server.proj_setups==NULL)) { free(game_file_data); return(FALSE); } progress_draw(40); game_file_get_chunk(server.projs); game_file_get_chunk(server.effects); game_file_get_chunk(server.decals); progress_draw(50); game_file_get_chunk(hud.bitmaps); game_file_get_chunk(hud.texts); game_file_get_chunk(hud.bars); game_file_get_chunk(&hud.radar); // map changes progress_draw(60); game_file_get_chunk(&map.ambient); game_file_get_chunk(&map.rain); game_file_get_chunk(&map.background); game_file_get_chunk(&map.sky); game_file_get_chunk(&map.fog); progress_draw(70); map_group_dispose_unit_list(&map); // need to destroy and rebuild unit lists game_file_get_chunk(map.groups); map_group_create_unit_list(&map); game_file_get_chunk(map.movements); group_moves_synch_with_load(); // script objects progress_draw(80); game_file_get_chunk(&js.script_current_uid); game_file_get_chunk(&js.count); game_file_get_chunk(&js.time); game_file_get_chunk(js.timers); game_file_get_chunk(js.globals); // reset model UIDs progress_draw(90); models_reset_uid(); // send scripts load event // to restore globals progress_draw(95); script_state_load(); // free game data progress_draw(100); free(game_file_data); // finished progress_shutdown(); // fix some necessary functions map.rain.reset=TRUE; fade_screen_cancel(); // return to old game time game_time_reset(); return(TRUE); }
void file_click(void) { int id,k; char err_str[256],file_name[256]; id=-1; // keyboard if (input_get_keyboard_escape()) id=file_button_cancel_id; if (input_get_keyboard_return()) id=file_is_save?file_button_save_id:file_button_load_id; // clicking if (id==-1) { id=gui_click(); if (id!=-1) hud_click(); } if (id==-1) return; // handle click switch (id) { case file_button_save_id: if (!game_file_save(FALSE,FALSE,err_str)) console_add_error(err_str); server.next_state=gs_running; break; case file_button_load_id: k=element_get_value(file_info_table_id); if (k==-1) break; element_get_table_column_data(file_info_table_id,k,1,file_name,256); server.next_state=gs_running; if (game_file_load(file_name,FALSE,err_str)) { game_time_pause_end(); break; } if (server.map_open) map_end(); if (server.game_open) game_end(); error_setup(err_str,"Game Load Canceled"); server.next_state=gs_error; break; case file_button_delete_id: file_save_delete(); break; case file_button_cancel_id: server.next_state=file_last_state; break; case file_info_table_id: file_save_selected(); break; } }