⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 events.cpp

📁 行人模拟
💻 CPP
字号:
//// pedsim - A microscopic pedestrian simulation system. // Copyright (c) 2003 - 2004 by Christian Gloor//                              // You can redistribute and/or modify this program under the terms of// the GNU General Public License.  See copying.txt for details.// #include <stdio.h>#include <iostream> // cout ...#include <string>   // strncpy//#include "main.h"#include <stdlib.h> // malloc()//#include <unistd.h> // sleep()//#include <netdb.h>  // gethostbyname()#include <fcntl.h>  // fcntl()#include <sys/types.h>                                      //#include <sys/socket.h>//#include <arpa/inet.h>#include "events.h"#include "agent.h"#include "functions.h"using namespace std;extern AgentContainer a;#define SERV_PORT  10002#define SERV_ADDR  "127.0.0.1"// --------------------------------------------------// Name: Tevent// Purpose: Constructor. Initializes all the connections needed. // Introduced: chgloor Monday, December 29, 2003 12:26:47// --------------------------------------------------Tevent::Tevent(char *replicator) {/*  // 2do: replace this for windos // chgloor aug13 2004
  if (replicator != NULL) {    cerr << "Reliable events sent via tcp replicator on " << replicator << ", port " << SERV_PORT << endl;    struct sockaddr_in servaddr;    tcpSocket = socket(AF_INET, SOCK_STREAM, 0);    //    if (tcpSocket == 0) cerr << "socket error" << endl;    bzero(&servaddr, sizeof(servaddr));    servaddr.sin_family      = AF_INET;    //  servaddr.sin_addr.s_addr = htonl(INADDR_ANY);    servaddr.sin_port        = htons(SERV_PORT);    inet_pton(AF_INET, replicator, &servaddr.sin_addr);    if (connect(tcpSocket, (sockaddr*) &servaddr, sizeof(servaddr)) != 0) {      cerr << "could not connect to tcp multicast daemon" << endl;      cerr << "please start ~/src/alps/net/tcp-mc/tcp-mc and try again" << endl;      exit(-1);    }    int flags = fcntl(tcpSocket, F_GETFL, 0);    flags |= O_NONBLOCK;    fcntl(tcpSocket, F_SETFL, flags);  } else {     tcpSocket = 0;   }*/
  };// --------------------------------------------------// Name: tcpsend// Purpose: wrapper for _reliable_ multicast send// Introduced: chgloor Monday, June 30, 2003 14:26:43// --------------------------------------------------int Tevent::tcpsend(char *s, int len) {  if (tcpSocket == 0) {     cerr << s << endl;     return len;   } else {/* // 2do: replace this for windos // chgloor aug13 2004
	  int sent = 0;    while (sent < len) {      int ret = send(tcpSocket, s+sent, (size_t)len-sent, 0);      if (ret > 0) { // ret can be -1 if there was an error, e.g. the sender buffer was full.	sent += ret;      }          }//    cout << s << endl;    return sent;
	*/  }};// --------------------------------------------------// Name: send_position// Purpose: sends a position event// Introduced: chgloor Monday, June 30, 2003 14:27:24// --------------------------------------------------void Tevent::send_position(long time, int id, int type, double x, double y) {  char buffer[200];  char temp[30];  strcpy(buffer, "<event type=\"position\" ");  strcat(buffer,"time=\"");  sprintf(temp, "%ld",time);  strcat(buffer,temp);  strcat(buffer,"\" ");  strcat(buffer,"id=\"");  sprintf(temp, "%d",id);  strcat(buffer,temp);  strcat(buffer,"\" ");  strcat(buffer,"agenttype=\"");  sprintf(temp, "%d",type);  strcat(buffer,temp);  strcat(buffer,"\" ");  strcat(buffer,"x=\"");  sprintf(temp, "%f", x);  strcat(buffer,temp);  strcat(buffer,"\" ");  strcat(buffer,"y=\"");  sprintf(temp, "%f", y);  strcat(buffer,temp);  strcat(buffer,"\" ");  strcat(buffer, "/>");  //  cerr << buffer << endl;  tcpsend(buffer, strlen(buffer));};

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -