Esempio n. 1
0
void agent::new_speed(agent* birds, int size, int pos, objet* obj, int nb_obj, double* vpred, int nb_pred)
{
	double* v1=speed1(birds, size, pos);
	double* v2=speed2(birds, size, pos);
	double* v3=speed3(birds, size, pos, obj, nb_obj);
	double* v4=speed4(vpred, nb_pred);
	speed[0]=speed[0]+TIME*(GAMMA1*v1[0]+GAMMA2*v2[0]+GAMMA3*v3[0]+GAMMA4*v4[0]);
	speed[1]=speed[1]+TIME*(GAMMA1*v1[1]+GAMMA2*v2[1]+GAMMA3*v3[1]+GAMMA4*v4[1]);

	//norm max = VMAX

	double norm=sqrt(speed[0]*speed[0]+speed[1]*speed[1]);

	if(norm>VMAX)
	{
		double max=(norm/VMAX);
		speed[0]=speed[0]/max;
		speed[1]=speed[1]/max;
	}
	
}
Esempio n. 2
0
void CUI::displayHUD(void)
{
	width = (GLfloat)glutGet(GLUT_WINDOW_WIDTH);
	height = (GLfloat)glutGet(GLUT_WINDOW_HEIGHT);
	glEnable(GL_TEXTURE_2D);
	if (data->drawHUD && data->gameState == PLAYING)
	{
		if (data->camera->speed >= 8.0f)
			glBindTexture(GL_TEXTURE_2D, speed8());
		else if (data->camera->speed >= 6.0f)
			glBindTexture(GL_TEXTURE_2D, speed6());
		else if (data->camera->speed >= 4.0f)
			glBindTexture(GL_TEXTURE_2D, speed4());
		else if (data->camera->speed >= 2.0f)
			glBindTexture(GL_TEXTURE_2D, speed2());
		else
			glBindTexture(GL_TEXTURE_2D, speed0());

		glBegin(GL_QUADS);
		glTexCoord2f(0, 0);
		glVertex2f(10, height-10);
		glTexCoord2f(1, 0);
		glVertex2f(40, height-10);
		glTexCoord2f(1, 1);
		glVertex2f(40, height-110);
		glTexCoord2f(0, 1);
		glVertex2f(10, height-110);
		glEnd();
	}
	if (data->gameState == LOOSE)
	{
		glBindTexture(GL_TEXTURE_2D, loose());
		glBegin(GL_QUADS);
		glColor3f(1.0f, 1.0f, 1.0f);
		glTexCoord2f(1, 1);
		glVertex2f(0, 0);
		glTexCoord2f(1, 0);
		glVertex2f(0, height);
		glTexCoord2f(0, 0);
		glVertex2f(width, height);
		glTexCoord2f(0, 1);
		glVertex2f(width, 0);
		glEnd();

	}
	if (data->gameState == WIN)
	{
		glBindTexture(GL_TEXTURE_2D, win());
		glBegin(GL_QUADS);
		glColor3f(1.0f, 1.0f, 1.0f);
		glTexCoord2f(1, 1);
		glVertex2f(0, 0);
		glTexCoord2f(1, 0);
		glVertex2f(0, height);
		glTexCoord2f(0, 0);
		glVertex2f(width, height);
		glTexCoord2f(0, 1);
		glVertex2f(width, 0);
		glEnd();

	}
	glDisable(GL_TEXTURE_2D);
}
Esempio n. 3
0
int main(int argc, char* argv[])
{

	 char *dev; /* name of the device to use */ 
  char *net; /* dot notation of the network address */
  char *mask;/* dot notation of the network mask    */
  int ret;   /* return code */
 //const u_char *packet;
  pcap_t* descr;      /*you can man it*/
  char errbuf[PCAP_ERRBUF_SIZE];
  bpf_u_int32 netp; /* ip          */
  bpf_u_int32 maskp;/* subnet mask */
  struct in_addr addr;

  /* ask pcap to find a valid device for use to sniff on */
  dev = pcap_lookupdev(errbuf);

  /* error checking */
  if(dev == NULL)
  {
   printf("%s\n",errbuf);
   exit(1);
  }

  /* print out device name */
  printf("DEV: %s\n",dev);

  /* ask pcap for the network address and mask of the device */
/*  ret = pcap_lookupnet(dev,&netp,&maskp,errbuf);

  if(ret == -1)
  {
   printf("%s\n",errbuf);
   exit(1);
  }
*/
  /* get the network address in a human readable form */
//  addr.s_addr = netp;
 // net = inet_ntoa(addr);

 /* if(net == NULL)// thanks Scott :-P 
  {
    perror("inet_ntoa");
    exit(1);
  }

  printf("NET: %s\n",net);

  // do the same as above for the device's mask 
  addr.s_addr = maskp;
  mask = inet_ntoa(addr);
  
  if(mask == NULL)
  {
    perror("inet_ntoa");
    exit(1);
  }*/
  signal(SIGINT, sigproc);
  signal(SIGTERM, sigproc);
  signal(SIGINT, sigproc);
  printf("MASK: %s\n",mask);
 size_mac=sizeof(struct ether_header);
 size_ip=sizeof(struct ip);
	//char *filename="/dev/shm/get.pcap";
	//char *filename="./get.pcap";
//char *filename="/run/shm/http.pcap";
initBCBuff();
/* pthread_t my_thread;

  if(pthread_create(&my_thread, NULL, threadclass, NULL)!=0)
  	{
  		msg("Ecreate thread error\n");
  		exit(0);
  	}
*/
     /// msg("kkkkkkkkkkkkk\n");
int i;
#if 1
	#define MAX_FILE 4
	char filenameA[MAX_FILE+1][200]={{"/run/shm/http.pcap"},{"/run/shm/ftp.pcap"},{"/run/shm/pop3.pcap"},{"/run/shm/smtp.pcap"},{""}};
	//char filenameA[MAX_FILE+1][200]={{"/run/shm/http.pcap"},{""}};
	//char *filename="./exam-for/ftp.pcap";
	char *filename;
	printf("EIinit hb\n");
	hb=init_HB(HB_MAX);
	init_free_link(FREE_NODE);
	init_BC();//the cache for the pro classificationd
	printf("EIinit bc\n");
	init_patterns();
msg("hhhhhh\n");
DELAY_INI();

 	 NS_TIME_START(time); 
	int num=0;
	int kk=0;

	
	
again:
	filename= filenameA[num];
//	msg("kk=%d\n",kk);
	num=(num+1)%MAX_FILE;

	
	if(kk==100000)
		goto endk;
		++kk;
	descr =pcap_open_offline(filename, errbuf);     
	
    if(descr == NULL)
    { printf("pcap_open_live(): %s\n",errbuf); exit(1); }

/////////////////////////////
	DELAY(DELAY_NS);	
	
	pcap_loop(descr,-1,my_callback,NULL);
	//printf("llllllllllllll\n");
	pcap_close(descr);
goto again;
endk:
	exitflag=1;
	//sem_post(&bin_sem);
	 NS_TIME_END(time);
	msg("\n===================%d\n\n",kk);
	for(i=0;i<PRO_MAX+2;++i)
	{
	
	printf("%s:%lld\n",pro_map[i],pronum[i]);
  	 }
	 printf("losepacket=%lld\n",losepacket);
	
		//speed(NS_GET_TIMEP(time),count+sum,firstlen);
		speed1(NS_GET_TIMEP(time),packet_num,packet_len);
	speed2(NS_GET_TIMEP(time),packet_num,packet_len,100000,DELAY_NS);
	
	
#else
	int fd=open(filename,O_RDONLY);
	if(fd<=0)
		perror("open error\n");

	//unsigned char buf
	struct pcap_pkthdr head;
	u_char buf[3000];
	int headlen=sizeof(struct pcap_file_header);
	int phead=sizeof(struct pcap_pkthdr);
	//while(read(fd,&head,sizeof()))
	 NS_TIME_START(time); 
	printf("EIinit hb\n");
	hb=init_HB(HB_MAX);
	init_free_link(FREE_NODE);
	init_BC();//the cache for the pro classificationd
	printf("EIinit bc\n");
	init_patterns();
	//msg("EISpppppppppp");

	while(1)
	{
		lseek(fd,headlen,SEEK_SET);
		//read(fd,buf,headlen);
		while(read(fd,&head,phead))
		{
		//printf("lllll\n");
			read(fd,buf,head.caplen);
			my_callback(NULL,&head,buf);
			//printf("%d\n",head.caplen);
		}
		
	}
#endif
	


//pthread_join(my_thread, NULL);
	
/////////////////////////////////////////////////////
      
        return 0;
}