Пример #1
0
void star_destruction(int level) {
    int i, j;
    int icell, idelete, ipart, ipart_next;
    int num_level_cells;
    int *level_cells;
    double dt_eff;

    if(sf_feedback_particle->destroy_star_particle == NULL) return;

#ifdef STAR_PARTICLE_TYPES /* this ifdef is not strictly necessary */
    start_time( WORK_TIMER );
    select_level( level, CELL_TYPE_LOCAL | CELL_TYPE_LEAF, &num_level_cells, &level_cells );
    #pragma omp parallel for default(none), private(icell,ipart,ipart_next,idelete), shared(num_level_cells,level_cells,cell_particle_list,particle_level,level,particle_id,star_particle_type,particle_species_indices,num_particle_species,particle_list_next, particle_list_prev, sf_feedback_particle), schedule(dynamic)
    for ( i = 0; i < num_level_cells; i++ ) {
        icell = level_cells[i];

        ipart = cell_particle_list[icell];
        while ( ipart != NULL_PARTICLE ) {
            ipart_next = particle_list_next[ipart];
            if ( particle_is_star(ipart) ) {
                idelete = sf_feedback_particle->destroy_star_particle(level,icell,ipart);
                cart_assert(idelete==0 || idelete==1);
                if(idelete == 1) {
                    #pragma omp critical
                    {
                        /* delete_particle should be threadsafe, but just to be sure */
                        delete_particle(icell,ipart);
                        particle_free(ipart);
                    }
                }
            }

            ipart = ipart_next;
        }
    }

    cart_free(level_cells);
    end_time( WORK_TIMER );

#endif /* STAR_PARTICLE_TYPES */
}
Пример #2
0
void process_message_from_server(unsigned char *in_data, int data_lenght)
{
	//see what kind of data we got
	switch (in_data[PROTOCOL])
		{
		case RAW_TEXT:
			{
				// do filtering and ignoring
				data_lenght=filter_or_ignore_text(&in_data[3],data_lenght-3)+3;
				if(data_lenght > 3)
					{
						//how to display it
						if(interface_mode!=interface_opening)
							put_text_in_buffer(&in_data[3],data_lenght-3,0);
						else put_text_in_buffer(&in_data[3],data_lenght-3,54);
						//lets log it
						write_to_log(&in_data[3],data_lenght-3);
					}
			}
			break;
		
		case SMALL_WINDOW_TEXT:
			{
				add_text_to_small_text_buffer(in_data+3, data_lenght-3);
				display_small_text_window();
			}
			break;

		case ADD_NEW_ACTOR:
			{
				add_actor_from_server(&in_data[3]);
			}
			break;

		case ADD_NEW_ENHANCED_ACTOR:
			{
				add_enhanced_actor_from_server(&in_data[3]);
			}
			break;

		case ADD_ACTOR_COMMAND:
			{
				add_command_to_actor(*((short *)(in_data+3)),in_data[5]);
			}
			break;

		case REMOVE_ACTOR:
			{
				destroy_actor(*((short *)(in_data+3)));
			}
			break;

		case KILL_ALL_ACTORS:
			{
				destroy_all_actors();
			}
			break;

		case NEW_MINUTE:
			{
				game_minute=*((short *)(in_data+3));
				new_minute();
			}
			break;

		case LOG_IN_OK:
			{
				interface_mode=interface_game;
				previously_logged_in=1;
			}
			break;

		case HERE_YOUR_STATS:
			{
				get_the_stats((Sint16 *)(in_data+3));
			}
			break;

		case SEND_PARTIAL_STAT:
			{
				get_partial_stat(*((Uint8 *)(in_data+3)),*((Sint32 *)(in_data+4)));
			}
			break;

		case GET_KNOWLEDGE_LIST:
			{
				get_knowledge_list(*(Uint16 *)(in_data+1)-1, in_data+3);
			}
			break;

		case GET_NEW_KNOWLEDGE:
			{
				get_new_knowledge(*(Uint16 *)(in_data+3));
			}
			break;

		case HERE_YOUR_INVENTORY:
			{
				get_your_items(in_data+3);
			}
			break;

		case GET_NEW_INVENTORY_ITEM:
			{
				get_new_inventory_item(in_data+3);
			}
			break;

		case REMOVE_ITEM_FROM_INVENTORY:
			{
				remove_item_from_inventory(*((Uint8 *)(in_data+3)));
			}
			break;

		case INVENTORY_ITEM_TEXT:
			{
				put_small_text_in_box(&in_data[3],data_lenght-3,6*51+100,items_string);
				if(!(get_show_window(items_win)||get_show_window(trade_win)))
					{
						put_text_in_buffer(&in_data[3],data_lenght-3,0);
					}
			}
			break;

		case GET_KNOWLEDGE_TEXT:
			{
				put_small_text_in_box(&in_data[3],data_lenght-3,6*51+150,knowledge_string);
			}
			break;

		case CHANGE_MAP:
			{
				current_sector=-1;
				if(map_file_name[0]!=0)
					save_map(map_file_name);
				object_under_mouse=-1;//to prevent a nasty crash, while looking for bags, when we change the map
				close_dialogue();	// close the dialogue window if open
				destroy_all_particles();

				if(!load_map(&in_data[4])){ // creating map if it does not exist
					int size=(in_data[3]&0x1f)<<4;
					new_map(size,size);
					dungeon=(in_data[3]&0x20)?1:0;
					strcpy(map_file_name,&in_data[4]);
					save_map(map_file_name);
				}
				kill_local_sounds();
#ifndef	NO_MUSIC
				playing_music=0;
#endif	//NO_MUSIC
				get_map_playlist();
				have_a_map=1;
				//also, stop the rain
				seconds_till_rain_starts=-1;
				seconds_till_rain_stops=-1;
				is_raining=0;
				rain_sound=0;//kill local sounds also kills the rain sound
				weather_light_offset=0;
				rain_light_offset=0;
			}
			break;

		case GET_TELEPORTERS_LIST:
			{
				add_teleporters_from_list(&in_data[3]);
			}
			break;

		case PLAY_MUSIC:
			{
				if(!no_sound)play_music(*((short *)(in_data+3)));
			}
			break;

		case PLAY_SOUND:
			{
				if(!no_sound)add_sound_object(*((short *)(in_data+3)),*((short *)(in_data+5)),*((short *)(in_data+7)),*((char *)(in_data+9)),*((short *)(in_data+10)));
			}
			break;

		case TELEPORT_OUT:
			{
				add_particle_sys_at_tile("./particles/teleport_in.part",*((short *)(in_data+3)),*((short *)(in_data+5)));
				if(!no_sound)add_sound_object(snd_tele_out,*((short *)(in_data+3)),*((short *)(in_data+5)),1,0);
			}
			break;

		case TELEPORT_IN:
			{
				add_particle_sys_at_tile("./particles/teleport_in.part",*((short *)(in_data+3)),*((short *)(in_data+5)));
				if(!no_sound)add_sound_object(snd_tele_in,*((short *)(in_data+3)),*((short *)(in_data+5)),1,0);
			}
			break;

		case LOG_IN_NOT_OK:
			{
				sprintf(log_in_error_str,"%s: %s",reg_error_str,invalid_pass);
			}
			break;

		case REDEFINE_YOUR_COLORS:
			{
				strcpy(log_in_error_str,redefine_your_colours);
			}
			break;

		case YOU_DONT_EXIST:
			{
				sprintf(log_in_error_str,"%s: %s",reg_error_str,char_dont_exist);
			}
			break;


		case CREATE_CHAR_NOT_OK:
			{
				sprintf(create_char_error_str,"%s: %s",reg_error_str,char_name_in_use);
				return;
			}
			break;


		case CREATE_CHAR_OK:
			{
				login_from_new_char();
			}
			break;

		case YOU_ARE:
			{
				yourself=*((short *)(in_data+3));
			}
			break;

		case START_RAIN:
			{
				seconds_till_rain_starts=*((Uint8 *)(in_data+3));
				seconds_till_rain_stops=-1;
			}
			break;

		case STOP_RAIN:
			{
				seconds_till_rain_stops=*((Uint8 *)(in_data+3));
				seconds_till_rain_starts=-1;
			}
			break;

		case THUNDER:
			{
				add_thunder(rand()%5,*((Uint8 *)(in_data+3)));
			}
			break;


		case SYNC_CLOCK:
			{
				server_time_stamp=*((int *)(in_data+3));
				client_time_stamp=SDL_GetTicks();
				client_server_delta_time=server_time_stamp-client_time_stamp;
			}
			break;

		case PONG:
			{
				Uint8 str[160];
				sprintf(str,"%s: %i MS",server_latency, SDL_GetTicks()-*((Uint32 *)(in_data+3)));
				log_to_console(c_green1,str);
			}
			break;

		case UPGRADE_NEW_VERSION:
			{
				log_to_console(c_red1,update_your_client);
				log_to_console(c_red1,(char*)web_update_address);
			}
			break;

		case UPGRADE_TOO_OLD:
			{
				log_to_console(c_red1,client_ver_not_supported);
				log_to_console(c_red1,(char*)web_update_address);
				this_version_is_invalid=1;
			}
			break;

		case GET_NEW_BAG:
			{
				put_bag_on_ground(*((Uint16 *)(in_data+3)),*((Uint16 *)(in_data+5)),*((Uint8 *)(in_data+7)));
			}
			break;

		case GET_BAGS_LIST:
			{
				add_bags_from_list(&in_data[3]);
			}
			break;

		case SPAWN_BAG_PARTICLES:
			{
			  add_particle_sys_at_tile("./particles/bag_in.part",*((Uint16 *)(in_data+3)),*((Uint16 *)(in_data+5)));
			}
			break;

		case GET_NEW_GROUND_ITEM:
			{
				get_bag_item(in_data+3);
			}
			break;

		case HERE_YOUR_GROUND_ITEMS:
			{
				get_bags_items_list(&in_data[3]);
			}
			break;

		case CLOSE_BAG:
			{
				hide_window(ground_items_win);
			}
			break;

		case REMOVE_ITEM_FROM_GROUND:
			{
				remove_item_from_ground(in_data[3]);
			}
			break;

		case DESTROY_BAG:
			{
				remove_bag(in_data[3]);
			}
			break;

		case NPC_TEXT:
			{
				put_small_text_in_box(&in_data[3],data_lenght-3,dialogue_menu_x_len-70,dialogue_string);
				display_dialogue();
				if(in_data[3]>=127 && in_data[4]>=127)
					{
						add_questlog(&in_data[4],data_lenght-4);
					}
			}
			break;

		case SEND_NPC_INFO:
			{
				my_strcp(npc_name,&in_data[3]);
				cur_portrait=in_data[23];
			}
			break;

		case NPC_OPTIONS_LIST:
			{
				build_response_entries(&in_data[3],*((Uint16 *)(in_data+1)));
			}
			break;

		case GET_TRADE_ACCEPT:
			{
				if(!in_data[3])trade_you_accepted=1;
				else
					trade_other_accepted=1;
			}
			break;

		case GET_TRADE_REJECT:
			{
				if(!in_data[3])trade_you_accepted=0;
				else
					trade_other_accepted=0;
			}
			break;

		case GET_TRADE_EXIT:
			{
				hide_window(trade_win);
			}
			break;

		case GET_YOUR_TRADEOBJECTS:
			{
				get_your_trade_objects(in_data+3);
			}
			break;

		case GET_TRADE_OBJECT:
			{
				put_item_on_trade(in_data+3);
			}
			break;

		case REMOVE_TRADE_OBJECT:
			{
				remove_item_from_trade(in_data+3);
			}
			break;

		case GET_TRADE_PARTNER_NAME:
			{
				get_trade_partner_name(&in_data[3],*((Uint16 *)(in_data+1))-1);
			}
			break;

		case GET_ACTOR_DAMAGE:
			{
				get_actor_damage(*((Uint16 *)(in_data+3)),in_data[5]);
			}
			break;

		case GET_ACTOR_HEAL:
			{
				get_actor_heal(*((Uint16 *)(in_data+3)),in_data[5]);
			}
			break;

		case ACTOR_UNWEAR_ITEM:
			{
				unwear_item_from_actor(*((Uint16 *)(in_data+3)),in_data[5]);
			}
			break;

		case ACTOR_WEAR_ITEM:
			{
				actor_wear_item(*((Uint16 *)(in_data+3)),in_data[5],in_data[6]);
			}
			break;

		case NPC_SAY_OVERTEXT:
			{
				add_displayed_text_to_actor(
					get_actor_ptr_from_id( *((Uint16 *)(in_data+3)) ), in_data+5 );
			}
			break;

		case BUDDY_EVENT:
			{
				if(in_data[3]==1)
					add_buddy(&in_data[5],in_data[4],data_lenght-5);
				else if(in_data[3]==0)
					del_buddy(&in_data[4],data_lenght-4);
			}
			break;

		// BARREN MOON NEW MESSAGES
		case THIS_IS_ACTIVE_SECTOR:
			active_sector=*((Uint16 *)(in_data+3));
			break;

		case GET_TILE_DATA:
			get_tile_data(in_data+3);
			break;

		case GET_3D_OBJECTS:
			get_3d_objects(in_data+3);
			break;

		case GET_2D_OBJECTS:
			get_2d_objects(in_data+3);
			break;

		case GET_LIGHT_OBJECTS:
			get_light_objects(in_data+3);
			break;

		case GET_PARTICLE_OBJECTS:
			get_particle_objects(in_data+3);
			break;

		case GET_3D_OBJECTS_FULL_ROTATION:
			get_3d_objects_full_rotation(in_data+3);
			break;

		case GET_CHECKSUMS:
		{
			actor *actor=pf_get_our_actor();
			get_checksums(in_data+3, sector_get(actor->x_pos,actor->y_pos));
			break;
		}

		case ADD_3D_OBJECT:
			add_3d_object(in_data+3);
			break;

		case ADD_3D_OBJECT_FULL_ROTATION:
			add_3d_object_fullrotation(in_data+3);
			break;

		case DELETE_3D_OBJECT:
			delete_3d_object(in_data+3);
			break;

		case REPLACE_3D_OBJECT:
			replace_3d_object(in_data+3);
			break;

		case ADD_2D_OBJECT:
			add_2d_object(in_data+3);
			break;

		case DELETE_2D_OBJECT:
			delete_2d_object(in_data+3);
			break;

		case REPLACE_2D_OBJECT:
			replace_2d_object(in_data+3);
			break;

		case ADD_LIGHT:
			add_lights(in_data+3);
			break;

		case DELETE_LIGHT:
			delete_light(in_data+3);
			break;

		case ADD_PARTICLE:
			add_particle(in_data+3);
			break;

		case DELETE_PARTICLE:
			delete_particle(in_data+3);
			break;

		case REPLACE_PARTICLE:
			replace_particle(in_data+3);
			break;

		default:
			{
				/* Unknown data type?? */;
			}
			break;
		}
}
Пример #3
0
void insert_nondom() /* Insertar particulas no dominadas en el archivo */
{
	unsigned int i, j, k, total, insertFlag, bottom, cont;
	double archiveCons[maxvar], popCons[maxvar];

	for(i=0; i< popsize; i++)
	{
		if(nondomCtr == 0)
		{ /* Si el archivo esta vacio */
      /* Insertar la particula en el archivo */
			for(j = 0; j < maxvar; j++)
				archiveVar[nondomCtr][j] = popVar[i][j];
			for(j = 0; j < maxfun; j++)
				archiveFit[nondomCtr][j] = popFit[i][j];
			nondomCtr += 1;
		}
		else
		{ /* Si el archivo no esta vacio */
			insertFlag = 1;
            /*Para cada particula en el archivo */
			for(k=0; k < nondomCtr; k++)
			{
            /* Primero, verificar si es factibe */
				for(j=0; j < maxvar; j++)
				{
					popCons[j] = popVar[i][j];
					archiveCons[j] = archiveVar[k][j];
				}
                    /* Si ambas partculas no son factibles */
				if((check_constraints(archiveCons) > 0) && (check_constraints(popCons) > 0))
				{
					delete_particle(k); /* Eliminar particula del archivo */
					insertFlag = 0;		/* No insertar la particula en la poblacion */
					break;
				}
				else if(check_constraints(popCons) > 0)
				{ /* Si la particula de la poblacion en infactible */
					insertFlag = 0;/* No insertar la particula en la poblacion */
					break;
				}
				else if(check_constraints(archiveCons) > 0)
				{ /* Si la particula en el archivo es infactible */
					delete_particle(k); /* Borrar la particula en el archivo  */
					if((nondomCtr != 0) || (k != nondomCtr-1))
						k--;
					continue;
				}
	/* Segundo, verificar dominancia*/
				total = 0;
				cont = 0;
                /* Si ambos son factiblesf, vereficar no diminancia*/
				for(j=0; j < maxfun; j++)
				{
					if(( (popFit[i][j] < archiveFit[k][j]) && (optimization == 0)) || (popFit[i][j] > archiveFit[k][j]) && (optimization == 1))
                        total += 1;
				}
				for(j=0; j < maxfun; j++)
				{
					if( (popFit[i][j] == archiveFit[k][j]))
                    {
                        cont ++;     /* No insertar la particula en la poblacion */
                        insertFlag = 0;
                    }
				}
				if(total == maxfun || cont == maxfun)   /* Si la particula es totalmente dominada     */
                    delete_particle(k); /* Borrar particula del archivo*/
				else if(total == 0)
				{  /* Si la particula en dominada en el archivo*/
					insertFlag = 0;     /* No insertar la particula en la poblacion */
					break;
				}

			} /* Termina la comparacion de una particula en la poblacion con el archivo */
		}
    /* Insertar la particula si es factible y no dominada */
		if(insertFlag == 1)
		{
            /* Si la memoria no esta llena, insertar particula */
      		if (nondomCtr < archive_size)
			{
				for(j = 0; j < maxvar; j++)
					archiveVar[nondomCtr][j] = popVar[i][j];
				for(j = 0; j < maxfun; j++)
					archiveFit[nondomCtr][j] = popFit[i][j];
				nondomCtr += 1;
			}
			else
			{   /* Calcular hipervolumen*/

				bottom = (unsigned int)((nondomCtr-1) * 0.90);
            /* Selecionar aleatoriamente un lugar para reemplazar */
				k = RandomInt(bottom, nondomCtr-1);
            /* Insertar nueva particula en el archivo */
				for(j = 0; j < maxvar; j++)
					archiveVar[k][j] = popVar[i][j];
				for(j = 0; j < maxfun; j++)
					archiveFit[k][j] = popFit[i][j];
			}
		}
	} /* Termina la comparacion de particulas de la poblacion en el archivo */
}
Пример #4
0
void update_particle_list( int level ) { 
	int i, k;
	int ipart;
	int iter_cell;
	int num_level_cells;
	int *level_cells;
	double pos[nDim];
	int num_parts_to_send[MAX_PROCS];
	int particle_list_to_send[MAX_PROCS];
	int *particle_array_to_send[MAX_PROCS];
	int ipart2, new_cell;
	int proc;
	int collect_level;
	int sfc;

	start_time( UPDATE_PARTS_TIMER );
	start_time( WORK_TIMER );

	/* now move particles from one cell list to another */
	for ( i = 0; i < num_procs; i++ ) {
		num_parts_to_send[i] = 0;
		particle_list_to_send[i] = NULL_PARTICLE;
	}

	select_level( level, CELL_TYPE_LOCAL, &num_level_cells, &level_cells );
	for ( k = 0; k < num_level_cells; k++ ) {
		iter_cell = level_cells[k];

		ipart = cell_particle_list[iter_cell];
		while ( ipart != NULL_PARTICLE ) {
			ipart2 = particle_list_next[ipart];

			sfc = sfc_index_position( particle_x[ipart] );
			proc = processor_owner(sfc);

			if ( proc == local_proc_id ) {
				new_cell = cell_find_position_sfc( sfc, particle_x[ipart] );
				if ( new_cell != iter_cell ) {
					cart_assert( cell_is_local(new_cell) );
					delete_particle( iter_cell, ipart );
					insert_particle( new_cell, ipart );
				}
			} else if ( proc == -1 ) {
				cart_error( "Unable to locate processor for particle %d!", particle_id[ipart]);
			} else {
				delete_particle( iter_cell, ipart );
				particle_list_next[ipart] = particle_list_to_send[proc];
				particle_list_to_send[proc] = ipart;
				num_parts_to_send[proc]++;
			}

			ipart = ipart2;
		}
	}

	cart_free( level_cells );

	end_time( WORK_TIMER );

	start_time( COMMUNICATION_TIMER );
	start_time( UPDATE_PARTS_COMMUNICATION_TIMER );

	for ( proc = 0; proc < num_procs; proc++ ) {
		if ( num_parts_to_send[proc] > 0 ) {
			particle_array_to_send[proc] = cart_alloc(int, num_parts_to_send[proc]);
			num_parts_to_send[proc] = 0;

			/* add particles that ended up in processor linked list */
			ipart = particle_list_to_send[proc];
			while ( ipart != NULL_PARTICLE ) {
				particle_array_to_send[proc][ num_parts_to_send[proc]++ ] = ipart;
				ipart = particle_list_next[ipart];
			}
		}
	}