#include #include #ifdef MAP_EDITOR2 #include "../map_editor2/global.h" #else #include "global.h" #endif #include "loading_win.h" #ifdef ZLIB #include #endif #if defined SFX && defined EYE_CANDY #include "eye_candy_wrapper.h" #endif int map_type=1; Uint32 map_flags=0; #ifndef SHOW_FLICKERING const float offset_2d_increment = (1.0f / 32768.0f); // (1.0f / 8388608.0f) is the minimum for 32-bit floating point. float offset_2d = (1.0f / 32768.0f); const float offset_2d_max = 0.01f; #endif void destroy_map() { int i; #ifdef EXTRA_DEBUG ERR(); #endif #ifdef NEW_FRUSTUM clear_bbox_tree(main_bbox_tree); #endif //kill the tile and height map if(tile_map) { free(tile_map); tile_map=0; } memset(tile_list,0,sizeof(tile_list)); if(height_map) { free(height_map); height_map=0; } #ifndef MAP_EDITOR2 ///kill the pathfinding tile map if(pf_tile_map) { free(pf_tile_map); pf_tile_map=0; if (pf_follow_path) { pf_destroy_path(); } } #endif //kill the 3d objects links for(i=0;iclouds_uv){ if(have_vertex_buffers){ const GLuint l=objects_list[i]->cloud_vbo; ELglDeleteBuffersARB(1, &l); objects_list[i]->cloud_vbo=0; } free(objects_list[i]->clouds_uv); } #endif #ifdef EYE_CANDY ec_remove_obstruction_by_object3d(objects_list[i]); #endif free(objects_list[i]); objects_list[i]=NULL;//kill any refference to it } } // reset the top pointer highest_obj_3d= 0; //kill the 2d objects links for(i=0;i= offset_2d_max) offset_2d = offset_2d_increment; #endif #ifdef NEW_FRUSTUM add_2d_obj(cur_2d_obj_io.file_name,cur_2d_obj_io.x_pos,cur_2d_obj_io.y_pos, cur_2d_obj_io.z_pos,cur_2d_obj_io.x_rot,cur_2d_obj_io.y_rot,cur_2d_obj_io.z_rot, 0); #else add_2d_obj(cur_2d_obj_io.file_name,cur_2d_obj_io.x_pos,cur_2d_obj_io.y_pos, cur_2d_obj_io.z_pos,cur_2d_obj_io.x_rot,cur_2d_obj_io.y_rot,cur_2d_obj_io.z_rot); #endif if(i%100 == 0) { update_loading_win(NULL, 0); } } update_loading_win(load_lights_str, 20); //read the lights for(i=0;i tile_map_size_x*60 || cur_light_io.pos_y < 0.0f || cur_light_io.pos_y > tile_map_size_y*60 || cur_light_io.pos_z < -1000.0f || cur_light_io.pos_z > 1000.0f || cur_light_io.r < -1.0f || cur_light_io.r > 1000.0f || cur_light_io.g < -1.0f || cur_light_io.g > 1000.0f || cur_light_io.b < -1.0f || cur_light_io.b > 1000.0f){ LOG_ERROR("Bad light (number %d) when loading '%s'; co-ords [%f %f %f] colour [%f %f %f]", i, file_name, cur_light_io.pos_x, cur_light_io.pos_y, cur_light_io.pos_z, cur_light_io.r, cur_light_io.g, cur_light_io.b); cur_light_io.pos_x = cur_light_io.pos_y = 1.0f; cur_light_io.pos_z = 2.0f; cur_light_io.r = cur_light_io.g = cur_light_io.b = 1.0f; continue; } #ifdef NEW_FRUSTUM #ifdef MAP_EDITOR2 add_light(cur_light_io.pos_x,cur_light_io.pos_y,cur_light_io.pos_z,cur_light_io.r,cur_light_io.g,cur_light_io.b,1.0f,1, 0); #else add_light(cur_light_io.pos_x,cur_light_io.pos_y,cur_light_io.pos_z,cur_light_io.r,cur_light_io.g,cur_light_io.b,1.0f, 0); #endif #else #ifdef MAP_EDITOR2 add_light(cur_light_io.pos_x,cur_light_io.pos_y,cur_light_io.pos_z,cur_light_io.r,cur_light_io.g,cur_light_io.b,1.0f,1); #else add_light(cur_light_io.pos_x,cur_light_io.pos_y,cur_light_io.pos_z,cur_light_io.r,cur_light_io.g,cur_light_io.b,1.0f); #endif #endif if(i%100 == 0) { update_loading_win(NULL, 0); } } update_loading_win(load_particles_str, 20); //read particle systems for(i=0;i 1) { sscanf (text, "%d %d", &marks[max_mark].x, &marks[max_mark].y); text[strlen(text)-1] = '\0'; //remove the newline safe_strncpy(marks[max_mark].text, strstr(strstr(text, " ")+1, " ") + 1, sizeof(marks[max_mark].text)); max_mark++; if ( max_mark > 200 ) break; } } fclose(fp); } #endif #ifdef MAP_EDITOR2 void new_map(int m_x_size,int m_y_size,int tile_type) { int i; #ifdef NEW_FRUSTUM unsigned int j; AABBOX bbox; #endif #ifdef EXTRA_DEBUG ERR(); #endif //destroy the previous map, if any destroy_map(); //allocate memory for the tile map (it was destroyed) tile_map=(char *)calloc(m_x_size*m_y_size, 1); //now, fill the map for(i=0;i=0) for(i=0;idef && particles_list[i]->def->ttl<0)particles_no++; //ok, now build the header... //clear the header memset(mem_map_header, 0, sizeof(mem_map_header)); //build the file signature cur_map_header.file_sig[0]='e'; cur_map_header.file_sig[1]='l'; cur_map_header.file_sig[2]='m'; cur_map_header.file_sig[3]='f'; cur_map_header.tile_map_x_len=tile_map_size_x; cur_map_header.tile_map_y_len=tile_map_size_y; cur_map_header.tile_map_offset=sizeof(map_header); cur_map_header.height_map_offset=cur_map_header.tile_map_offset+tile_map_size_x*tile_map_size_y; cur_map_header.obj_3d_struct_len=obj_3d_io_size; cur_map_header.obj_3d_no=obj_3d_no; cur_map_header.obj_3d_offset=cur_map_header.height_map_offset+tile_map_size_x*tile_map_size_y*6*6; cur_map_header.obj_2d_struct_len=obj_2d_io_size; cur_map_header.obj_2d_no=obj_2d_no; cur_map_header.obj_2d_offset=cur_map_header.obj_3d_offset+obj_3d_no*obj_3d_io_size; cur_map_header.lights_struct_len=lights_io_size; cur_map_header.lights_no=lights_no; cur_map_header.lights_offset=cur_map_header.obj_2d_offset+obj_2d_no*obj_2d_io_size; cur_map_header.dungeon=dungeon; cur_map_header.ambient_r=ambient_r; cur_map_header.ambient_g=ambient_g; cur_map_header.ambient_b=ambient_b; cur_map_header.particles_struct_len=particles_io_size; cur_map_header.particles_no=particles_no; cur_map_header.particles_offset=cur_map_header.lights_offset+lights_no*lights_io_size; //ok, now let's open/create the file, and start writting the header... #ifdef ZLIBW f=my_gzopen(file_name, "wb9"); // with high level compression #else //ZLIBW f=my_fopen(file_name, "wb"); #endif //ZLIBW if (f == NULL) { // unable to open output file // Let's quit now before our user spends a whole lot of time // creating a map that can't be saved. SDL_Quit (); exit (1); } //write the header #ifdef ZLIBW gzwrite(f, mem_map_header, sizeof(map_header)); #else //ZLIBW fwrite(mem_map_header, sizeof(map_header), 1, f); #endif //ZLIBW //write the tiles map #ifdef ZLIBW gzwrite(f, tile_map, tile_map_size_x*tile_map_size_y); #else //ZLIBW fwrite(tile_map, tile_map_size_x*tile_map_size_y, 1, f); #endif //ZLIBW //write the heights map #ifdef ZLIBW gzwrite(f, height_map, tile_map_size_x*tile_map_size_y*6*6); #else //ZLIBW fwrite(height_map, tile_map_size_x*tile_map_size_y*6*6, 1, f); #endif //ZLIBW //write the 3d objects j=0; for(i=0;iobj_3d_no)break; if(objects_list[i]) { char * cur_3do_pointer=(char *)&cur_3d_obj_io; Uint32 k=0; //clear the object for(k=0;kfile_name); cur_3d_obj_io.x_pos=objects_list[i]->x_pos; cur_3d_obj_io.y_pos=objects_list[i]->y_pos; cur_3d_obj_io.z_pos=objects_list[i]->z_pos; cur_3d_obj_io.x_rot=objects_list[i]->x_rot; cur_3d_obj_io.y_rot=objects_list[i]->y_rot; cur_3d_obj_io.z_rot=objects_list[i]->z_rot; cur_3d_obj_io.self_lit=objects_list[i]->self_lit; cur_3d_obj_io.blended=objects_list[i]->blended; cur_3d_obj_io.r=objects_list[i]->r; cur_3d_obj_io.g=objects_list[i]->g; cur_3d_obj_io.b=objects_list[i]->b; #ifdef ZLIBW gzwrite(f, cur_3do_pointer, sizeof(object3d_io)); #else //ZLIBW fwrite(cur_3do_pointer, sizeof(object3d_io), 1, f); #endif //ZLIBW j++; } } //write the 2d objects j=0; for(i=0;iobj_2d_no)break; if(obj_2d_list[i]) { char * cur_2do_pointer=(char *)&cur_2d_obj_io; Uint32 k=0; //clear the object for(k=0;kfile_name); cur_2d_obj_io.x_pos=obj_2d_list[i]->x_pos; cur_2d_obj_io.y_pos=obj_2d_list[i]->y_pos; cur_2d_obj_io.z_pos=obj_2d_list[i]->z_pos; cur_2d_obj_io.x_rot=obj_2d_list[i]->x_rot; cur_2d_obj_io.y_rot=obj_2d_list[i]->y_rot; cur_2d_obj_io.z_rot=obj_2d_list[i]->z_rot; #ifdef ZLIBW gzwrite(f, cur_2do_pointer, sizeof(obj_2d_io)); #else //ZLIBW fwrite(cur_2do_pointer, sizeof(obj_2d_io), 1, f); #endif //ZLIBW j++; } } //write the lights j=0; for(i=0;ilights_no)break; if(lights_list[i]) { char * cur_light_pointer=(char *)&cur_light_io; Uint32 k=0; //clear the object for(k=0;kpos_x; cur_light_io.pos_y=lights_list[i]->pos_y; cur_light_io.pos_z=lights_list[i]->pos_z; cur_light_io.r=lights_list[i]->r; cur_light_io.g=lights_list[i]->g; cur_light_io.b=lights_list[i]->b; #ifdef ZLIBW gzwrite(f, cur_light_pointer, sizeof(light_io)); #else //ZLIBW fwrite(cur_light_pointer, sizeof(light_io), 1, f); #endif //ZLIBW j++; } } // Write the particle systems j=0; for(i=0;iparticles_no)break; if(particles_list[i] && particles_list[i]->def && particles_list[i]->def->ttl<0) { char *cur_particles_pointer=(char *)&cur_particles_io; Uint32 k=0; for(k=0;kdef->file_name); cur_particles_io.x_pos=particles_list[i]->x_pos; cur_particles_io.y_pos=particles_list[i]->y_pos; cur_particles_io.z_pos=particles_list[i]->z_pos; #ifdef ZLIBW gzwrite(f, cur_particles_pointer,sizeof(particles_io)); #else //ZLIBW fwrite(cur_particles_pointer,sizeof(particles_io),1,f); #endif //ZLIBW j++; } } #ifdef ZLIBW gzclose(f); #else //ZLIBW fclose(f); #endif //ZLIBW return 1; } #endif #ifndef MAP_EDITOR2 int get_3d_objects_from_server (int nr_objs, const Uint8 *data, int len) { int iobj; int obj_x, obj_y; int offset, nb_left; float x = 0.0f, y = 0.0f, z = 0.0f, rx = 0.0f, ry = 0.0f, rz = 0.0f; char obj_name[128]; int name_len, max_name_len; int id = -1; int all_ok = 1; offset = 0; nb_left = len; for (iobj = 0; iobj < nr_objs; iobj++) { int obj_err = 0; if (nb_left < 14) { // Warn about this error! log_error ("Incomplete 3D objects list!"); all_ok = 0; break; } obj_x = SDL_SwapLE16 (*((Uint16 *)(&data[offset]))); offset += 2; obj_y = SDL_SwapLE16 (*((Uint16 *)(&data[offset]))); offset += 2; if (obj_x > tile_map_size_x * 6 || obj_y > tile_map_size_y * 6) { // Warn about this error! log_error("A 3D object was located OUTSIDE the map!"); offset += 8; obj_err = 1; } else { rx = SwapLEFloat (*((float *)(&data[offset]))); offset += 2; ry = SwapLEFloat (*((float *)(&data[offset]))); offset += 2; rz = SwapLEFloat (*((float *)(&data[offset]))); offset += 2; id = SDL_SwapLE16 (*((Uint16 *)(&data[offset]))); offset += 2; x = 0.5f * obj_x + 0.25f; y = 0.5f * obj_y + 0.25f; z = -2.2f + height_map[obj_y*tile_map_size_x*6+obj_x] * 0.2f; } nb_left -= 12; max_name_len = nb_left > sizeof (obj_name) ? sizeof (obj_name) : nb_left; name_len = safe_snprintf (obj_name, max_name_len, "%s", &data[offset]); if (name_len < 0 || name_len >= sizeof (obj_name)) { // Warn about this error! log_error("3D object has invalid or too long file name!"); all_ok = 0; break; } offset += name_len + 1; nb_left -= name_len + 1; if (!obj_err) #ifdef NEW_FRUSTUM add_e3d_at_id (id, obj_name, x, y, z, rx, ry, rz, 0, 0, 1.0f, 1.0f, 1.0f, 1); #else add_e3d_at_id (id, obj_name, x, y, z, rx, ry, rz, 0, 0, 1.0f, 1.0f, 1.0f); #endif else all_ok = 0; } return all_ok; } void remove_3d_object_from_server (int id) { #ifndef NEW_FRUSTUM int sector, i, j = MAX_3D_OBJECTS-1, k = -1; #endif if (id < 0 || id > MAX_OBJ_3D) { LOG_ERROR ("Trying to remove object with invalid id %d", id); return; } if (objects_list[id] == NULL) { LOG_ERROR ("Trying to remove non-existant object"); return; } #ifndef NEW_FRUSTUM sector = SECTOR_GET (objects_list[id]->x_pos, objects_list[id]->y_pos); for (i = 0; i < MAX_3D_OBJECTS; i++) { if (k != -1 && sectors[sector].e3d_local[i] == -1) { j = i-1; break; } else if (k==-1 && sectors[sector].e3d_local[i] == id) { k = i; } } sectors[sector].e3d_local[k] = sectors[sector].e3d_local[j]; sectors[sector].e3d_local[j] = -1; #endif destroy_3d_object (id); } #endif