Beispiel #1
0
int main(object me,string arg)
{
	string *files;
	mixed *file;
	int i,j,w=0,col,total=0;
	int size;
	set_eval_limit(1); 
	seteuid(getuid());
	if(!arg || arg=="") return notify_fail("╕ё╩╜▓╗╢╘гб\n");

	error = 0;

	if (arg == "-o")
		arg = "/daemon/";
	else
		arg = "/daemon/class/"+arg+"/";
    
	file = get_dir(arg, -1);
   	reset_eval_cost();
	if( !sizeof(file) )
	{if (file_size(arg) == -2) return notify_fail("╬─╡╡╝╨╩╟┐╒╡─бг\n");
		else
		return notify_fail("├╗╙╨╒т╕Ў╬─╡╡╝╨бг\n");
	}

	write(HIW"╒¤╘┌╦є╤▓"+arg+"╬─╡╡╝╨гогого\n"NOR);

	i = sizeof(file);
	w = 0;
	while(i--) {
		if (file[i][1]==-2) 
		{
			files = get_dir(arg+file[i][0]+"/");
		   	reset_eval_cost();
			// р┼гм╒т╕Ў╙ж╕├╩╟╢╘╙ж╡─skill╬─╡╡гм╥╗╞Ё▒р╥ы░╔
			update_function(me,"/daemon/skill/"+file[i][0]);
			// is a directory , ╜Ў╫╖╦▌╥╗▓убг
			for(j=0; j<sizeof(files); j++) 
			{
				size=sizeof(files[j]);
				if(files[j][(size-2)..size]==".c")
				{
					update_function(me,arg+file[i][0]+"/"+files[j]);
					total++;
				}
			}   	 	
			file[i][0] += "/";
		}
	}
Beispiel #2
0
int main(object me,string arg)
// arg should be /d/baiyun/ ....
{
    	string *files;
    	int i,total=0;
    	int size;
    	set_eval_limit(1); 
    	seteuid(getuid());
    	if(!arg || arg=="") return notify_fail("╕ё╩╜▓╗╢╘гб\n");
    
    	error = 0;
    	
    	write(HIW"╒¤╘┌╦є╤▓"+arg+"╬─╡╡╝╨гогого\n"NOR);
    	
    	files= get_dir(arg);
    	reset_eval_cost();
    	for(i=0; i<sizeof(files); i++) 
    	{
    	    size=sizeof(files[i]);
        	if(files[i][(size-2)..size]==".c"){
        		if (files[i]=="updatep.c") continue;
        		total++;
				update_function(me, arg+files[i]);
			}	
//  	           	me->ccommand(sprintf("update %s%s",arg,files[i]));
        }   
        
        write(HIW"гогого"+arg+"╬─╡╡╝╨▒р╥ы═ъ│╔бг
бббббб╣▓╦є╤▓╡╜"+total+"╕Ў╡╡░╕гм╞ф╓╨"+error+"╕Ў▒р╥ы╩з░▄бг\n"NOR);	 	
    	return 1;
}
Beispiel #3
0
bool update(const std::wstring& inf, const std::wstring& hardware_id, bool& reboot_required)
{
	TCHAR inf_path[MAX_PATH];

	if (GetFullPathName(inf.c_str(), MAX_PATH, inf_path, NULL) >= MAX_PATH)
	{
		return false;
	}

	if (GetFileAttributes(inf_path) == (DWORD)(-1))
	{
		return false;
	}

	bool result = false;

	DWORD flags = INSTALLFLAG_FORCE;

	HMODULE new_device_module = LoadLibrary(TEXT("newdev.dll"));

	if (new_device_module)
	{
		std::wcerr << "Loaded newdev.dll." << std::endl;

		UpdateDriverForPlugAndPlayDevicesFunc update_function = 
			reinterpret_cast<UpdateDriverForPlugAndPlayDevicesFunc>(
					GetProcAddress(new_device_module, "UpdateDriverForPlugAndPlayDevicesW")
					);

		if (update_function)
		{
			std::wcerr << "Update function loaded." << std::endl;

			BOOL reboot = FALSE;

			if (update_function(NULL, hardware_id.c_str(), inf_path, flags, &reboot))
			{
				std::wcerr << "Update function suceeded. Device is up to date." << std::endl;

				reboot_required = (reboot == TRUE);

				result = true;
			} else
			{
				std::wcerr << "Unable to update the device." << std::endl;
			}
		} else
		{
			std::wcerr << "Unable to load the update function." << std::endl;
		}

		FreeLibrary(new_device_module);
	}

	return result;
}
Beispiel #4
0
static int do_load_map(const char *file_name, update_func *update_function)
{
	int i;
	int cur_tile, j;
	AABBOX bbox;
	map_header cur_map_header;
	char* file_mem;
#ifdef CLUSTER_INSIDES
	char* occupied = 0;
	int have_clusters;
#endif
	object3d_io* objs_3d;
	obj_2d_io* objs_2d;
	light_io* lights;
	particles_io* particles;
#ifndef FASTER_MAP_LOAD
	float progress;
#endif
	el_file_ptr file;

	file = el_open(file_name);

	if (!file)
	{
		return 0;
	}

#ifdef EXTRA_DEBUG
	ERR();
#endif
	file_mem = el_get_pointer(file);

	my_strcp(map_file_name, file_name);

	LOG_DEBUG("Loading map '%s'.", file_name);

	main_bbox_tree_items = create_bbox_items(1024);

	memcpy(&cur_map_header, file_mem, sizeof(cur_map_header));
	cur_map_header.tile_map_x_len = SDL_SwapLE32(cur_map_header.tile_map_x_len);
	cur_map_header.tile_map_y_len = SDL_SwapLE32(cur_map_header.tile_map_y_len);
	cur_map_header.tile_map_offset = SDL_SwapLE32(cur_map_header.tile_map_offset);
	cur_map_header.height_map_offset = SDL_SwapLE32(cur_map_header.height_map_offset);
	cur_map_header.obj_3d_struct_len = SDL_SwapLE32(cur_map_header.obj_3d_struct_len);
	cur_map_header.obj_3d_no = SDL_SwapLE32(cur_map_header.obj_3d_no);
	cur_map_header.obj_3d_offset = SDL_SwapLE32(cur_map_header.obj_3d_offset);
	cur_map_header.obj_2d_struct_len = SDL_SwapLE32(cur_map_header.obj_2d_struct_len);
	cur_map_header.obj_2d_no = SDL_SwapLE32(cur_map_header.obj_2d_no);
	cur_map_header.obj_2d_offset = SDL_SwapLE32(cur_map_header.obj_2d_offset);
	cur_map_header.lights_struct_len = SDL_SwapLE32(cur_map_header.lights_struct_len);
	cur_map_header.lights_no = SDL_SwapLE32(cur_map_header.lights_no);
	cur_map_header.lights_offset = SDL_SwapLE32(cur_map_header.lights_offset);

	cur_map_header.ambient_r = SwapLEFloat(cur_map_header.ambient_r);
	cur_map_header.ambient_g = SwapLEFloat(cur_map_header.ambient_g);
	cur_map_header.ambient_b = SwapLEFloat(cur_map_header.ambient_b);

	cur_map_header.particles_struct_len = SDL_SwapLE32(cur_map_header.particles_struct_len);
	cur_map_header.particles_no = SDL_SwapLE32(cur_map_header.particles_no);
	cur_map_header.particles_offset = SDL_SwapLE32(cur_map_header.particles_offset);

#ifdef CLUSTER_INSIDES
	cur_map_header.clusters_offset = SDL_SwapLE32(cur_map_header.clusters_offset);
#endif

	LOG_DEBUG("Checking map '%s' file signature.", file_name);

	//verify if we have a valid file
	if(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')
	{
		LOG_ERROR(invalid_map, map_file_name);
		exit_now = 1; // We might as well quit...
		el_close(file);

		return 0;
	}

	LOG_DEBUG("Checking map '%s' sizes.", file_name);

	// Check the sizes of structures. If they don't match, we have a
	// major problem, since these structures are supposed to be
	// written flat out to disk.
	if (cur_map_header.obj_3d_struct_len != sizeof (object3d_io)
	    || cur_map_header.obj_2d_struct_len != sizeof (obj_2d_io)
	    || cur_map_header.lights_struct_len != sizeof (light_io)
	    || (cur_map_header.particles_struct_len != sizeof (particles_io) && cur_map_header.particles_no > 0)
	   )
	{
		LOG_ERROR ("Invalid object size on map %s", map_file_name);
		exit_now = 1; // We might as well quit...
		el_close(file);

		return 0;
	}

	update_function(load_map_str, 0);

	//get the map size
	tile_map_size_x = cur_map_header.tile_map_x_len;
	tile_map_size_y = cur_map_header.tile_map_y_len;

	LOG_DEBUG("Map '%s' size <%d, %d>.", file_name, tile_map_size_x,
		tile_map_size_y);

	// allocate the tile map (it was destroyed), and fill it
	tile_map = calloc (tile_map_size_x*tile_map_size_y, 1);
	memcpy(tile_map, file_mem + cur_map_header.tile_map_offset, tile_map_size_x*tile_map_size_y);
	begin_managing_memchunk(tile_map);

	// allocate the height map, and fill it
	height_map = calloc (tile_map_size_x*tile_map_size_y*6*6, 1);
	memcpy(height_map, file_mem + cur_map_header.height_map_offset, tile_map_size_x*tile_map_size_y*6*6);
	begin_managing_memchunk(height_map);

#ifdef CLUSTER_INSIDES
	// check if we need to compute the clusters, or if they're stored
	// in the map
	have_clusters = (cur_map_header.clusters_offset > 0)
	                && ((cur_map_header.clusters_offset +
			tile_map_size_x * tile_map_size_y * 6 * 6 *
			sizeof(short)) <= el_get_size(file));

	LOG_DEBUG("Map '%s' has clusters: %d.", file_name, have_clusters);

	if (have_clusters)
	{
		// clusters are stored in the map, set them
		set_clusters (file_mem + cur_map_header.clusters_offset);
	}
	else
	{
		// We need to compute the clusters, allocate memory for
		// the occupation array, and initialize it with the
		// tile and height maps
		occupied = calloc (tile_map_size_x*tile_map_size_y*6*6, 1);
		update_occupied_with_tile_map (occupied, tile_map);
		update_occupied_with_height_map (occupied, height_map);
	}
#endif

	LOG_DEBUG("Map '%s' is dungeon %d and ambient <%f, %f, %f>.",
		file_name, cur_map_header.dungeon, cur_map_header.ambient_r,
		cur_map_header.ambient_g, cur_map_header.ambient_b);
	//get the type of map, and the ambient light
	dungeon = cur_map_header.dungeon;
	ambient_r = cur_map_header.ambient_r;
	ambient_g = cur_map_header.ambient_g;
	ambient_b = cur_map_header.ambient_b;

/* 	water_tiles_extension = (tile_map_size_x > tile_map_size_y ? */
/* 							 tile_map_size_x : tile_map_size_y * 1.5); */
/* 	if (water_tiles_extension < 500.0) */
/* 		water_tiles_extension = 500.0 - water_tiles_extension; */
/* 	else */
/* 		water_tiles_extension = 0.0; */

	LOG_DEBUG("Loading tiles");
	//load the tiles in this map, if not already loaded
	load_map_tiles();

	LOG_DEBUG("Initializing buffers");
	init_buffers();
#ifndef CLUSTER_INSIDES
	for(i = 0; i < tile_map_size_y; i++)
	{
		bbox.bbmin[Y] = i*3.0f;
		bbox.bbmax[Y] = (i+1)*3.0f;
		if (i == 0)
			bbox.bbmin[Y] -= water_tiles_extension;
		else if (i == tile_map_size_y-1)
			bbox.bbmax[Y] += water_tiles_extension;
		for(j = 0; j < tile_map_size_x; j++)
		{
			cur_tile = tile_map[i*tile_map_size_x+j];
			if (cur_tile != 255)
			{
				bbox.bbmin[X] = j*3.0f;
				bbox.bbmax[X] = (j+1)*3.0f;
				if (j == 0)
					bbox.bbmin[X] -= water_tiles_extension;
				else if (j == tile_map_size_x-1)
					bbox.bbmax[X] += water_tiles_extension;
				if (IS_WATER_TILE(cur_tile))
				{
					bbox.bbmin[Z] = -0.25f;
					bbox.bbmax[Z] = -0.25f;
					if (IS_REFLECTING(cur_tile)) add_water_to_list(main_bbox_tree_items, get_terrain_id(j, i), bbox, cur_tile, 1);
					else add_water_to_list(main_bbox_tree_items, get_terrain_id(j, i), bbox, cur_tile, 0);
				}
				else 
				{
					bbox.bbmin[Z] = 0.0f;
					bbox.bbmax[Z] = 0.0f;
					add_terrain_to_list(main_bbox_tree_items, get_terrain_id(j, i), bbox, cur_tile);
				}
			}
		}
	}
#endif // CLUSTER_INSIDES

#ifdef FASTER_MAP_LOAD
	update_function(load_3d_object_str, 20.0f);
#else  // FASTER_MAP_LOAD
	progress = (cur_map_header.obj_3d_no + 249) / 250;
	if (progress > 0.0f)
	{
		update_function(load_3d_object_str, 0.0f);
		progress = 20.0f / progress;
	}
	else
	{
		update_function(load_3d_object_str, 20.0f);
		progress = 0.0f;
	}
#endif // FASTER_MAP_LOAD

	LOG_DEBUG("Loading %d 3d objects.", cur_map_header.obj_3d_no);

	//read the 3d objects
#ifndef FASTER_MAP_LOAD
	clear_objects_list_placeholders();
#endif
	objs_3d = (object3d_io*) (file_mem + cur_map_header.obj_3d_offset);

	ENTER_DEBUG_MARK("load 3d objects");
	for (i = 0; i < cur_map_header.obj_3d_no; i++)
	{
		object3d_io cur_3d_obj_io = objs_3d[i];

		cur_3d_obj_io.x_pos = SwapLEFloat (cur_3d_obj_io.x_pos);
		cur_3d_obj_io.y_pos = SwapLEFloat (cur_3d_obj_io.y_pos);
		cur_3d_obj_io.z_pos = SwapLEFloat (cur_3d_obj_io.z_pos);
		cur_3d_obj_io.x_rot = SwapLEFloat (cur_3d_obj_io.x_rot);
		cur_3d_obj_io.y_rot = SwapLEFloat (cur_3d_obj_io.y_rot);
		cur_3d_obj_io.z_rot = SwapLEFloat (cur_3d_obj_io.z_rot);
		cur_3d_obj_io.r = SwapLEFloat (cur_3d_obj_io.r);
		cur_3d_obj_io.g = SwapLEFloat (cur_3d_obj_io.g);
		cur_3d_obj_io.b = SwapLEFloat (cur_3d_obj_io.b);

		LOG_DEBUG("Adding 3d object (%d) '%s' at <%d, %f, %f> with "
			"rotation <%f, %f, %f>, left lit %d, blended %d and "
			"color <%f, %f, %f>.", i, cur_3d_obj_io.file_name,
			cur_3d_obj_io.x_pos, cur_3d_obj_io.y_pos,
			cur_3d_obj_io.z_pos, cur_3d_obj_io.x_rot,
			cur_3d_obj_io.y_rot, cur_3d_obj_io.z_rot,
			cur_3d_obj_io.self_lit, cur_3d_obj_io.blended,
			cur_3d_obj_io.r, cur_3d_obj_io.g, cur_3d_obj_io.b);

		if (cur_3d_obj_io.blended != 20)
		{
#ifdef CLUSTER_INSIDES
			int id;

			if (cur_3d_obj_io.blended != 1)
				cur_3d_obj_io.blended = 0;
			id = add_e3d (cur_3d_obj_io.file_name, cur_3d_obj_io.x_pos, cur_3d_obj_io.y_pos,
				cur_3d_obj_io.z_pos, cur_3d_obj_io.x_rot, cur_3d_obj_io.y_rot,
				cur_3d_obj_io.z_rot, cur_3d_obj_io.self_lit, cur_3d_obj_io.blended,
				cur_3d_obj_io.r, cur_3d_obj_io.g, cur_3d_obj_io.b, 0);

			if (!have_clusters)
				update_occupied_with_3d (occupied, id);
#else
			if (cur_3d_obj_io.blended != 1) cur_3d_obj_io.blended = 0;
			add_e3d (cur_3d_obj_io.file_name, cur_3d_obj_io.x_pos, cur_3d_obj_io.y_pos,
				cur_3d_obj_io.z_pos, cur_3d_obj_io.x_rot, cur_3d_obj_io.y_rot,
				cur_3d_obj_io.z_rot, cur_3d_obj_io.self_lit, cur_3d_obj_io.blended,
				cur_3d_obj_io.r, cur_3d_obj_io.g, cur_3d_obj_io.b, 0);
#endif
		}
		else
		{
			inc_objects_list_placeholders();
		}

#ifndef FASTER_MAP_LOAD
		if (i % 250 == 0)
		{
			update_function(load_3d_object_str, progress);
		}
#endif
	}
	LEAVE_DEBUG_MARK("load 3d objects");

#ifdef FASTER_MAP_LOAD
	update_function(load_2d_object_str, 20.0f);
#else  // FASTER_MAP_LOAD
	progress = (cur_map_header.obj_2d_no + 249) / 250;
	if (progress > 0)
	{
		update_function(load_2d_object_str, 0.0f);
		progress = 20.0f / progress;
	}
	else
	{
		update_function(load_2d_object_str, 20.0f);
		progress = 0.0f;
	}
#endif // FASTER_MAP_LOAD

	LOG_DEBUG("Loading %d 2d objects.", cur_map_header.obj_2d_no);

	//read the 2d objects
	objs_2d = (obj_2d_io*) (file_mem + cur_map_header.obj_2d_offset);

	ENTER_DEBUG_MARK("load 2d objects");
	for (i = 0; i < cur_map_header.obj_2d_no; i++)
	{
		obj_2d_io cur_2d_obj_io = objs_2d[i];
#ifdef CLUSTER_INSIDES
		int id;
#endif

		cur_2d_obj_io.x_pos = SwapLEFloat(cur_2d_obj_io.x_pos);
		cur_2d_obj_io.y_pos = SwapLEFloat(cur_2d_obj_io.y_pos);
		cur_2d_obj_io.z_pos = SwapLEFloat(cur_2d_obj_io.z_pos);
		cur_2d_obj_io.x_rot = SwapLEFloat(cur_2d_obj_io.x_rot);
		cur_2d_obj_io.y_rot = SwapLEFloat(cur_2d_obj_io.y_rot);
		cur_2d_obj_io.z_rot = SwapLEFloat(cur_2d_obj_io.z_rot);

		LOG_DEBUG("Adding 2d object (%d) '%s' at <%d, %f, %f> with "
			"rotation <%f, %f, %f>.", i, 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);

#ifndef SHOW_FLICKERING
		// Add in low-order bits to prevent flicker.
		cur_2d_obj_io.z_pos += offset_2d;
		offset_2d += offset_2d_increment;
		if (offset_2d >= offset_2d_max)
			offset_2d = offset_2d_increment;
#endif

#ifdef FASTER_MAP_LOAD
#ifdef CLUSTER_INSIDES
		id = add_2d_obj(i, 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);
		if (!have_clusters)
			update_occupied_with_2d (occupied, id);
#else  // CLUSTER_INSIDES
		add_2d_obj(i, 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);
#endif // CLUSTER_INSIDES
#else  // FASTER_MAP_LOAD
#ifdef CLUSTER_INSIDES
		id = 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);
		if (!have_clusters)
			update_occupied_with_2d (occupied, id);
#else  // CLUSTER_INSIDES
		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);
#endif // CLUSTER_INSIDES

		if (i % 250 == 0)
		{
			update_function(load_2d_object_str, progress);
		}
#endif // FASTER_MAP_LOAD
	}
	LEAVE_DEBUG_MARK("load 2d objects");

#ifdef CLUSTER_INSIDES
	// If we need to compute the clusters, do it here, so that the
	// newly added lights and particle systems get the right cluster
	// number automagically. We don't update the occupation map with
	// lights or particle systems since I don't expect them to bridge
	// any clusters, and if they do happen to hang in the void,
	// they'll be shown anyway.
	if (!have_clusters)
	{
		compute_clusters (occupied);
		free (occupied);

		// Ok, we have the clusters, now assign new IDs to each
		// object that we added.
		for (i = 0; i < MAX_OBJ_3D; i++)
		{
			if (objects_list[i])
			{
				int x = (int) (objects_list[i]->x_pos / 0.5f);
				int y = (int) (objects_list[i]->y_pos / 0.5f);
				objects_list[i]->cluster = get_cluster (x, y);
			}
		}

		for (i = 0; i < MAX_OBJ_2D; i++)
		{
			if (obj_2d_list[i])
			{
				int x = (int) (obj_2d_list[i]->x_pos / 0.5f);
				int y = (int) (obj_2d_list[i]->y_pos / 0.5f);
				obj_2d_list[i]->cluster = get_cluster (x, y);
			}
		}
	}

	// we finally add the tiles to the abt
	for(i = 0; i < tile_map_size_y; i++)
	{
		bbox.bbmin[Y] = i*3.0f;
		bbox.bbmax[Y] = (i+1)*3.0f;
		if (i == 0)
			bbox.bbmin[Y] -= water_tiles_extension;
		else if (i == tile_map_size_y-1)
			bbox.bbmax[Y] += water_tiles_extension;
		for(j = 0; j < tile_map_size_x; j++)
		{
			current_cluster = get_cluster(j*6, i*6);
			cur_tile = tile_map[i*tile_map_size_x+j];
			if (cur_tile != 255)
			{
				bbox.bbmin[X] = j*3.0f;
				bbox.bbmax[X] = (j+1)*3.0f;
				if (j == 0)
					bbox.bbmin[X] -= water_tiles_extension;
				else if (j == tile_map_size_x-1)
					bbox.bbmax[X] += water_tiles_extension;
				if (IS_WATER_TILE(cur_tile))
				{
					bbox.bbmin[Z] = -0.25f;
					bbox.bbmax[Z] = -0.25f;
					if (IS_REFLECTING(cur_tile)) add_water_to_list(main_bbox_tree_items, get_terrain_id(j, i), bbox, cur_tile, 1);
					else add_water_to_list(main_bbox_tree_items, get_terrain_id(j, i), bbox, cur_tile, 0);
				}
				else
				{
					bbox.bbmin[Z] = 0.0f;
					bbox.bbmax[Z] = 0.0f;
					add_terrain_to_list(main_bbox_tree_items, get_terrain_id(j, i), bbox, cur_tile);
				}
			}
		}
	}
#endif

#ifdef FASTER_MAP_LOAD
	update_function(load_lights_str, 20.0f);
#else  // FASTER_MAP_LOAD
	progress = (cur_map_header.lights_no + 99) / 100;
	if (progress > 0)
	{
		update_function(load_lights_str, 0.0f);
		progress = 20.0f / progress;
	}
	else
	{
		update_function(load_lights_str, 20.0f);
		progress = 0.0f;
	}
#endif // FASTER_MAP_LOAD

	LOG_DEBUG("Loading %d lights.", cur_map_header.lights_no);

	//read the lights
	lights = (light_io *) (file_mem + cur_map_header.lights_offset);

	ENTER_DEBUG_MARK("load lights");
	for (i = 0; i < cur_map_header.lights_no; i++)
	{
		light_io cur_light_io = lights[i];

		cur_light_io.pos_x = SwapLEFloat (cur_light_io.pos_x);
		cur_light_io.pos_y = SwapLEFloat (cur_light_io.pos_y);
		cur_light_io.pos_z = SwapLEFloat (cur_light_io.pos_z);
		cur_light_io.r = SwapLEFloat (cur_light_io.r);
		cur_light_io.g = SwapLEFloat (cur_light_io.g);
		cur_light_io.b = SwapLEFloat (cur_light_io.b);

		LOG_DEBUG("Adding light(%d) at <%d, %f, %f> with color "
			"<%f, %f, %f>.", i, 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);

		if (cur_light_io.pos_x < 0.0f || cur_light_io.pos_x > 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;
		}

		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);

#ifndef FASTER_MAP_LOAD
		if (i % 100 == 0)
		{
			update_function(load_lights_str, progress);
		}
#endif
	}
	LEAVE_DEBUG_MARK("load lights");

#ifdef FASTER_MAP_LOAD
	update_function(load_particles_str, 20.0f);
#else  // FASTER_MAP_LOAD
	progress = (cur_map_header.particles_no + 99) / 100;
	if (progress > 0.0f)
	{
		update_function(load_particles_str, 0.0f);
		progress = 20.0f / progress;
	}
	else
	{
		update_function(load_particles_str, 20.0f);
		progress = 0.0f;
	}
#endif // FASTER_MAP_LOAD

	LOG_DEBUG("Loading %d particles.", cur_map_header.particles_no);

	//read particle systems
	particles = (particles_io *) (file_mem + cur_map_header.particles_offset);

	ENTER_DEBUG_MARK("load particles");
	for (i = 0; i < cur_map_header.particles_no; i++)
	{
		particles_io cur_particles_io = particles[i];

		cur_particles_io.x_pos = SwapLEFloat (cur_particles_io.x_pos);
		cur_particles_io.y_pos = SwapLEFloat (cur_particles_io.y_pos);
		cur_particles_io.z_pos = SwapLEFloat (cur_particles_io.z_pos);

		LOG_DEBUG("Adding particle(%d) '%s' at <%d, %f, %f>.", i,
			cur_particles_io.file_name, cur_particles_io.x_pos,
			cur_particles_io.y_pos, cur_particles_io.z_pos);

		if (!strncmp(cur_particles_io.file_name, "ec://", 5))
		{
			ec_create_effect_from_map_code(cur_particles_io.file_name + 5, cur_particles_io.x_pos, cur_particles_io.y_pos, cur_particles_io.z_pos, (poor_man ? 6 : 10));
		}
		else
		{
#ifdef NEW_SOUND
			add_map_particle_sys (cur_particles_io.file_name, cur_particles_io.x_pos, cur_particles_io.y_pos, cur_particles_io.z_pos, 0);
#else
			add_particle_sys (cur_particles_io.file_name, cur_particles_io.x_pos, cur_particles_io.y_pos, cur_particles_io.z_pos, 0);
#endif // NEW_SOUND
		}

#ifndef FASTER_MAP_LOAD
		if (i % 100 == 0)
		{
			update_function(load_particles_str, progress);
		}
#endif
	}
	LEAVE_DEBUG_MARK("load particles");

	// Everything copied, get rid of the file data
	el_close(file);

	update_function(bld_sectors_str, 0.0f);

	LOG_DEBUG("Building bbox tree for map '%s'.", file_name);

	init_bbox_tree(main_bbox_tree, main_bbox_tree_items);
	free_bbox_items(main_bbox_tree_items);
	main_bbox_tree_items = 0;
	update_function(init_done_str, 20.0f);
#ifdef EXTRA_DEBUG
	ERR();//We finished loading the new map apparently...
#endif
	return 1;
}
Beispiel #5
0
static void do_trace_hist(struct tracecmd_input *handle)
{
	struct pevent *pevent = tracecmd_get_pevent(handle);
	struct event_format *event;
	struct pevent_record *record;
	int cpus;
	int cpu;
	int ret;

	ret = tracecmd_init_data(handle);
	if (ret < 0)
		die("failed to init data");

	if (ret > 0)
		die("trace-cmd hist does not work with latency traces\n");

	cpus = tracecmd_cpus(handle);

	/* Need to get any event */
	for (cpu = 0; cpu < cpus; cpu++) {
		record = tracecmd_peek_data(handle, cpu);
		if (record)
			break;
	}
	if (!record)
		die("No records found in file");

	ret = pevent_data_type(pevent, record);
	event = pevent_data_event_from_type(pevent, ret);

	long_size = tracecmd_long_size(handle);

	common_type_field = pevent_find_common_field(event, "common_type");
	if (!common_type_field)
		die("Can't find a 'type' field?");

	common_pid_field = pevent_find_common_field(event, "common_pid");
	if (!common_pid_field)
		die("Can't find a 'pid' field?");

	update_sched_wakeup(pevent);
	update_sched_wakeup_new(pevent);
	update_sched_switch(pevent);
	update_function(pevent);
	update_function_graph_entry(pevent);
	update_function_graph_exit(pevent);
	update_kernel_stack(pevent);

	for (cpu = 0; cpu < cpus; cpu++) {
		for (;;) {
			struct pevent_record *record;

			record = tracecmd_read_data(handle, cpu);
			if (!record)
				break;

			/* If we missed events, just flush out the current stack */
			if (record->missed_events)
				flush_stack();

			process_record(pevent, record);
			free_record(record);
		}
	}

	if (current_pid >= 0)
		save_call_chain(current_pid, ips, ips_idx, 0);
	if (pending_pid >= 0)
		save_call_chain(pending_pid, pending_ips, pending_ips_idx, 1);

	save_stored_stacks();

	sort_chains();
	print_chains(pevent);
}
Beispiel #6
0
int main (int argc, char *argv [])
{
    int
        i,
        j,
        k,
	n,
        p1 = 0,
        p2 = 0,
	run,
	runnoise,
	nn_noise,
	nn_maxcl,
	n_total,
	counter;
    float
	sum,
	ssum,
	sd,
        d;
    char
        *infile = NULL;
    FILE
        *fp = NULL;
    time_t
        tp;

#ifdef __WIN32__
    struct timeb
	tb;
#endif
 
    no_mem_buffer = (char *) malloc (1024);

    get_programname (argv [0]);

    update_function = NULL;

    arg_c = argc;
    arg_v = argv;
    process_args ();

    if (! update_function)
        syntax ();
    if (n_runs > 1 && ((! cophenetic) || ! n_noise))
	errit ("-r only useful in combination with -b or -c, and -N");
    if (n_maxcl && ! cophenetic)
	errit ("-m only useful in combination with -b or -c");
    if (n_noise > 1 && ! cophenetic)
	errit ("Multiple noise levels only in combination with -b or -c");
    if (binary && ! n_maxcl)
	errit ("No -b without -m");

    switch (arg_c) {
	case 1:
	    if (isatty (fileno (stdin)))
		syntax ();
	    fp = stdin;
	    infile = "<stdin>";
	    break;
	case 2:
	    infile = arg_v [1];
	    fp = fopen (infile, "r");
	    if (! fp)
		errit ("Opening file \"%s\": %s", infile, strerror (errno));
	    break;
	default:
	    syntax ();
    }

    GetLine (fp, 1, infile);
    if (sscanf (buffer, "%i", &size) != 1)
	errit (
	    "file \"%s\", line %i\nTable size expected",
	    infile,
	    input_line
	);
    labels = (char **) s_malloc (size * sizeof (char *));
    for (i = 0; i < size; i++) {
        GetLine (fp, 1, infile);
        labels [i] = s_strdup (buffer);
    }

    diff_in = (float **) s_malloc (size * sizeof (float *));
    for (i = 1; i < size; i++)
	diff_in [i] = (float *) s_malloc (i * sizeof (float));
    for (i = 1; i < size; i++) {
        for (j = 0; j < i; j++) {
            GetLine (fp, 1, infile);
            if (sscanf (buffer, "%f", &d) != 1)
                errit ("file \"%s\", line %i\nValue expected", infile, input_line);
            diff_in [i][j] = d;
	}
    }

    if (fp != stdin)
	fclose (fp);

    for (i = 0; i < n_maxcl; i++)
	if (maxcl [i] > size)
	    errit ("Value for -m too large");

    if (cophenetic) {
	diff_cp = (float **) s_malloc (size * sizeof (float *));
	for (i = 1; i < size; i++) {
	    diff_cp [i] = (float *) s_malloc (i * sizeof (float));
	    for (j = 0; j < i; j++)
		diff_cp [i][j] = 0;
	}
    }

    diff = (float **) s_malloc ((2 * size - 1) * sizeof (float *));
    for (i = 0; i < 2 * size - 1; i++)
	diff [i] = (float *) s_malloc ((2 * size - 1) * sizeof (float));

    sd = 0;
    if (n_noise) {

#ifdef __WIN32__
	ftime (&tb);
	srand (tb.millitm ^ (tb.time << 8));
#else
	srand (time (NULL) ^ (getpid () << 8));
#endif

	if (seed)
	    srand (seed);

	n = 0;
	sum = ssum = 0.0;
	for (i = 0; i < size; i++)
	    for (j = 0; j < i; j++) {
		sum += diff_in [i][j];
		ssum += diff_in [i][j] * diff_in [i][j];
		n++;
	    }
	sd = sqrt ((ssum - sum * sum / (float) n) / (float) (n - 1));

    }

    cl = (CLUSTER *) s_malloc ((2 * size - 1) * sizeof (CLUSTER));

    nn_noise = n_noise ? n_noise : 1;
    nn_maxcl = n_maxcl ? n_maxcl : 1;

    n_total = n_runs * nn_noise * nn_maxcl;
    counter = n_runs * nn_noise;

    if (counter > 10)
	verbose = 1;

    for (run = 0; run < n_runs; run++) {

	for (runnoise = 0; runnoise < nn_noise; runnoise++) {

	    checkCancel();

	    for (i = 0; i < size; i++) {
		diff [i][i] = 0;
		for (j = 0; j < i; j++)
		    diff [i][j] = diff [j][i] = diff_in [i][j];
	    }

	    if (n_noise)
		for (i = 0; i < size; i++)
		    for (j = 0; j < i; j++)
			diff [i][j] = diff [j][i] = diff [i][j] + noise [runnoise] * sd * (((float) rand ()) / (float) RAND_MAX);

	    for (i = 0; i < size; i++) {
		cl [i].used = 0;
		cl [i].n_items = 1;
		cl [i].cl1 = cl [i].cl2 = -1;
		cl [i].f = 0.0;
		cl [i].cluster = i;
	    }

	    for (i = size; i < 2 * size - 1; i++) {
		cl [i].used = 0;
		d = FLT_MAX;
		for (j = 0; j < i; j++)
		    if (! cl [j].used)
			for (k = 0; k < j; k++)
			    if ((! cl [k].used) && (diff [j][k] < d)) {
				p1 = j;
				p2 = k;
				d = diff [j][k];
			    }
		cl [i].n_items = cl [p1].n_items + cl [p2].n_items;
		cl [p1].used = cl [p2].used = 1;
		cl [i].cl1 = p1;
		cl [i].cl2 = p2;
		cl [i].f = d;
		cl [i].cluster = i;

		if (cophenetic) {
		    if (n_maxcl) {
			k = 0;
			for (j = 0; j < n_maxcl; j++)
			    if (i > 2 * size - 1 - maxcl [j])
				k++;
			if (k)
			    update_cp (binary ? (k / (float) n_total) : (k * d / (float) n_total), p1, p2);
		    } else 
			update_cp (binary ? (1.0 / (float) n_total) : (d / (float) n_total), p1, p2);
		}

		update_function (i);

	    }

	    if (verbose) {
		fprintf (stderr, "  %i \r", counter--);
		fflush (stderr);
	    }
	}
    }

    if (verbose)
	fprintf (stderr, "    \r");

    if (outfile) {
	fp_out = fopen (outfile, "w");
	if (! fp_out)
	    errit ("Creating file \"%s\": %s", outfile, strerror (errno));
    } else
	fp_out = stdout;

    time (&tp);
    fprintf (
	fp_out,
	"# Created by %s, (c) Peter Kleiweg 1998 - 2007\n"
	"# More info: http://www.let.rug.nl/~kleiweg/L04/\n"
	"# More info: http://www.let.rug.nl/~kleiweg/clustering/\n"
	"# Input file: %s\n"
	"# Clustering algorithm: %s\n",
	programname,
	infile,
	name_update
    );
    if (cophenetic && ! binary) 
	fprintf (fp_out, "# Cophenetic differences\n");
    if (cophenetic && binary) 
	fprintf (fp_out, "# Binary differences\n");
    if (n_noise) {
	fputs ("# Noise:", fp_out);
	for (i = 0; i < n_noise; i++) {
	    if (i && (i % 8 == 0))
		fprintf (fp_out, "\n#    ");
	    fprintf (fp_out, " %g", noise [i]);
	}
	fputs ("\n", fp_out);
    }
    if (n_maxcl) {
	fputs ("# Clusters:", fp_out);
	for (i = 0; i < n_maxcl; i++) {
	    if (i && (i % 16 == 0))
		fprintf (fp_out, "\n#    ");
	    fprintf (fp_out, " %i", maxcl [i]);
	}
	fputs ("\n", fp_out);
    }
    if (n_runs > 1)
	fprintf (fp_out, "# Runs: %i\n", n_runs);
    fprintf (
	fp_out,
	"# Date: %s\n",
	asctime (localtime (&tp))
    );

    if (cophenetic) {
	fprintf (fp_out, "%i\n", size);
	for (i = 0; i < size; i++)
	    fprintf (fp_out, "%s\n", labels [i]);
	for (i = 1; i < size; i++)
	    for (j = 0; j < i; j++)
		fprintf (fp_out, "%g\n", diff_cp [i][j]);
    } else {

	if (sorted)
	    sortclus (2 * size - 2);
	for (i = size; i < 2 * size - 1; i++) {
	    fprintf (fp_out, "%i %g\n", i, cl [i].f);
	    if (cl [i].cl1 < size)
		fprintf (fp_out, "L %s\n", labels [cl [i].cl1]);
	    else
		fprintf (fp_out, "C %i\n", cl [i].cl1);
	    if (cl [i].cl2 < size)
		fprintf (fp_out, "L %s\n", labels [cl [i].cl2]);
	    else
		fprintf (fp_out, "C %i\n", cl [i].cl2);
	}

    }

    if (outfile)
	fclose (fp_out);

    return 0;
}