Exemplo n.º 1
0
/**
 *  toString() recursively prints this Tree234Node and its descendants as
 *  a string.  Each node is printed in the form such as (for a 3-key node)
 *
 *      (child1)key1(child2)key2(child3)key3(child4)
 *
 *  where each child is a recursive call to toString, and null children
 *  are printed as a space with no parentheses.  Here's an example.
 *      ((1)7(11 16)22(23)28(37 49))50((60)84(86 95 100))
 *
 *  DO NOT CHANGE THIS METHOD.
 **/
const string Tree234Node::toString() {
  string s = "";

  if (child1 != NULL) {
    s = "(" + child1->toString() + ")";
  }
  s = s + int2String(key1);
  if (child2 != NULL) {
    s = s + "(" + child2->toString() + ")";
  } else if (keys > 1) {
    s = s + " ";
  }
  if (keys > 1) {
    s = s + int2String(key2);
    if (child3 != NULL) {
      s = s + "(" + child3->toString() + ")";
    } else if (keys > 2) {
      s = s + " ";
    }
  }
  if (keys > 2) {
    s = s + int2String(key3);
    if (child4 != NULL) {
      s = s + "(" + child4->toString() + ")";
    }
  }
  return s;
}
Exemplo n.º 2
0
void BattleLayer::_testCode(){
    Size visibleSize = Director::getInstance()->getVisibleSize();
    
    //Add Tile Label
    for (int column = 0; column < astarData.size(); ++column){
        for (int row = 0; row < astarData[column].size(); ++row){
            std::string labelString = int2String(column) + "," + int2String(row);
            Label *tileLabel = Label::createWithSystemFont(labelString, "Arial", 10);
            tileLabel->setColor(Color3B(0, 0, 0));
            tileLabel->setPosition(column * _battleTileSize.width + _battleTileSize.width / 2, row * _battleTileSize.height + _battleTileSize.height / 2);
            _battleMap->addChild(tileLabel, 1);
        }
    }
    
//    this->schedule([&](float dt){
//        CCLOG("Test Water");
//        _playerWater = 2;
//    }, 20, "TestWater");
    
    //Find Path Test
//    std::vector<AStarNode *> path;
//    AStarDataNode beginNode = AStarDataNode(3, 0, true);
//    AStarDataNode targetNode = AStarDataNode(3, 29, true);
//    astar(astarData, path, beginNode, targetNode);
//    for (auto iter = path.begin(); iter != path.end(); ++iter){
////        CCLOG("(%d, %d)", (*iter)->column, (*iter)->row);
//        Sprite *pathNode = Sprite::createWithSpriteFrameName("battle_map_path.png");
//        pathNode->setAnchorPoint(Vec2(0, 0));
//        pathNode->setPosition((*iter)->column * _battleTileSize.width, (*iter)->row * _battleTileSize.height);
//        _battleMap->addChild(pathNode, 1);
//    }
    
//    this->schedule([&](float deltaTime){
//        playerKingTower->loseBlood(5);
//        playerDefendLeftTower->loseBlood(8);
//        npcKingTower->loseBlood(7);
//        npcDefendRightTower->loseBlood(10);
//    }, 1, "Test");
    
    //Tower Test
//    Tower *tower1 = Tower::createTower(TowerType::King, Side::Player);
//    tower1->setPosition(_battleMapSize.width / 2, 0);
//    _battleMap->addChild(tower1, getBattleElementZOrderOnBattleMap(tower1));
//    
//    Tower *tower2 = Tower::createTower(TowerType::Defend, Side::Player);
//    tower2->setPosition(_battleMapSize.width / 2, _battleMapSize.height / 4);
//    _battleMap->addChild(tower2, getBattleElementZOrderOnBattleMap(tower2));
//    
//    Tower *tower3 = Tower::createTower(TowerType::King, Side::NPC);
//    tower3->setPosition(_battleMapSize.width / 2, _battleMapSize.height / 2);
//    _battleMap->addChild(tower3, getBattleElementZOrderOnBattleMap(tower3));
//    
//    Tower *tower4 = Tower::createTower(TowerType::Defend, Side::NPC);
//    tower4->setPosition(_battleMapSize.width / 2, _battleMapSize.height / 4 * 3);
//    _battleMap->addChild(tower4, getBattleElementZOrderOnBattleMap(tower4));
    
}
Exemplo n.º 3
0
UALQnx::UALQnx(ros::NodeHandle *n, int uavId, std::string qnx_host, unsigned int statePort, unsigned int commandPort):
   generalCommunications(n,uavId),
   qnxCommunications(n, qnx_host, commandPort, statePort),
   actual_state(LANDED),
   landActionServer(std::string("land"),int2String(uavId)),
   takeoffActionServer(std::string("take_off"),int2String(uavId))
{
   update_timer_ = n->createTimer(ros::Duration(1/UPDATE_RATE),
               boost::bind(&UALQnx::updateLoop, this, _1));
}
Exemplo n.º 4
0
	Raid_map_table* Raid_map::getRaid_mapVo(int id)
	{
		auto it = m_data.find(int2String(id));
		if (it == m_data.end())
		{
			return nullptr;
		} else {
			return &((*it).second);
		}
	}
Exemplo n.º 5
0
	Stage_table* Stage::getStageVo(int id)
	{
		auto it = m_data.find(int2String(id));
		if (it == m_data.end())
		{
			return nullptr;
		} else {
			return &((*it).second);
		}
	}
Exemplo n.º 6
0
	Upgrade_table* Upgrade::getUpgradeVo(int level)
	{
		auto it = m_data.find(int2String(level));
		if (it == m_data.end())
		{
			return nullptr;
		} else {
			return &((*it).second);
		}
	}
Exemplo n.º 7
0
int addSigSock(int newFd, struct sockaddr_in* clientAddr, bool isProxySock)
{
  if (newFd <1)
  {
    return -1;
  }

  fcntl(newFd, F_SETFL, O_NONBLOCK);
  ProxySock* pProxySock = new ProxySock(newFd);
  pProxySock->setIsProxySock(isProxySock);
  string name;
  if (clientAddr)
  {
    if (isProxySock)
    {
      name="Proxy|";
      name = name+inet_ntoa(clientAddr->sin_addr)+":"+int2String(ntohs(clientAddr->sin_port));
      pProxySock->setName(name);
    }
    else
    {
      name="Listen|";
      name = name+inet_ntoa(clientAddr->sin_addr)+":"+int2String(ntohs(clientAddr->sin_port));
      pProxySock->setName(name);
    }
  }

  if (pthread_mutex_lock(&sockListMutex))
  {
    close(newFd);
    return -1;
  }
  gSockFdList.push_back(newFd);
  gProxySockMap.insert(map<int, ProxySock*>::value_type(newFd, pProxySock));
  pthread_mutex_unlock(&sockListMutex);
  printSysTime();
  gOsLog<<"add sockfd="<<newFd<<",name="<<name<<endl; 
  return 0;
}
Exemplo n.º 8
0
void MyGesture::drawFingerTips(MyInputImgStruct *m){
/***
 *@DOC: draw small circle at each fingertips
 * Points are taken from FingetTips vector
**/
	Point p;
	int k=0;
	for(int i=0; i < FingerTips.size(); i++)
	{	p = FingerTips[i];
		putText(m->src, int2String(i), p-Point(0,30), fontFace, 1.2f, Scalar(200,200,200), 2);
		circle( m->src, p, 5, Scalar(100,255,100), 4 );
	}
} //ENDOF Method: drawFingerTips(MyInputImgStruct *m)
Exemplo n.º 9
0
void PublishDialog::initPublishDialog(void) {
	ui.listWidget_Weeks->clear();
	const scheduleWeekVector &weeks = Controller::theSchedulerSettings.getScheduleWeeks();
	QString weekStr;

	for (scheduleWeekVector::const_iterator it = weeks.begin(); it != weeks.end(); ++it) {
		weekStr="";
		weekStr = QString(int2String(it->first).c_str()) + QString(", starting on Monday ") + QString(it->second.toString().c_str());
		QListWidgetItem * item = new QListWidgetItem(weekStr);
		item->setData(200, it->second.toJulian()); // store the date of Monday as an int (julian day) in the listwidget item for later comparison
		ui.listWidget_Weeks->addItem(item);
	}
}
Exemplo n.º 10
0
void MyGesture::printGestureInfo(Mat src){
	int fontFace = FONT_HERSHEY_PLAIN;
	Scalar fontColor(245, 200, 200);
	int xpos = src.cols / 1.5;
	int ypos = src.rows / 1.6;
	float fontSize = 0.7f;
	int lineChange = 14;
	std::string info = "Figure Info:";
	putText(src, info, Point(ypos, xpos), fontFace, fontSize, fontColor);
	xpos = xpos + lineChange;
	info = std::string("bounding box height, width ") + std::string(int2String(numOfDefects));
	putText(src, info, Point(ypos, xpos), fontFace, fontSize, fontColor);
	xpos = xpos + lineChange;
	info = std::string("is Hande: ") + std::string(bool2String(isHand));
	putText(src, info, Point(ypos, xpos), fontFace, fontSize, fontColor);
} //ENDOF Method: printGestureInfo(Mat src)
Exemplo n.º 11
0
void MyGesture::addNumberToImg(MyInputImgStruct *m){
/***
 * DOC: displays the number of fingers in the image
 */
	int fontFace = FONT_HERSHEY_PLAIN;
	int xPos = 10, yPos = 10, offset = 30;
	float fontSize = 1.5f;
	for(int i=0; i<numbers2Display.size(); i++)
	{
		rectangle(m->src,Point(xPos,yPos),Point(xPos+offset,yPos+offset),numberOfColor, 2);
		putText(m->src, int2String(numbers2Display[i]), Point(xPos+7, yPos+offset-3), fontFace, fontSize, numberOfColor);
		xPos = xPos+40;
		if(xPos>(m->src.cols - m->src.cols/3.2))
		{
			yPos+=40;
			xPos=10;
		}
	}
}//ENDOF method: addNumberToImg()
Exemplo n.º 12
0
void proxySocketThread(int argument)
{

	string sMessage;
	unsigned char* recvBuff = 0;
	int proxyFd = 0;
	int proxyRtpFd = 0;
	int proxyRtcpFd = 0;
	int proxyRtpPort = 0;
	int listenRtpFd = 0;
	int listenRtcpFd = 0;
	int listenRtpPort = 0;
	fd_set fds;	// set of file descriptors to check.
	int nread = 0;	// return from read() 
	int nready = 0;	// # fd's ready. 
	int maxfd = 0;	// fd's 0 to maxfd-1 checked.
	int proxyRtpClientInited = 0;
	int listenRtpClientInited = 0;
	int proxyRtcpClientInited = 0;
	int listenRtcpClientInited = 0;
	int result = 0;
	int sock_len = sizeof(struct sockaddr);
	int readMsgLen = 0;
	int readStep = 0;
	bool readHead = true;
	
	struct sockaddr_in clientAddr;
	struct sockaddr_in proxyRtpCliAddr;
	struct sockaddr_in listenRtpCliAddr;
	struct sockaddr_in proxyRtcpCliAddr;
	struct sockaddr_in listenRtcpCliAddr;

	proxyFd = argument;
	if (0 == proxyFd)
	{
		gOsLog<<"argument is null ,exit from the thread!"<<endl;
		pthread_exit(0); // Notice the cast
	}

	for(int i=0;i<10;i++)
	{
		proxyRtpPort = RTPPortRange.getRTPPort();
		listenRtpPort = RTPPortRange.getRTPPort();

		proxyRtpFd = UDPListen(proxyRtpPort);
		if (1 > proxyRtpFd)
		{
			proxyRtpFd = 0;
			continue;
		}
		proxyRtcpFd = UDPListen(proxyRtpPort+1);

		if (1 > proxyRtcpFd)
		{
			close(proxyRtpFd);
			proxyRtcpFd = 0;
			proxyRtpFd = 0;
			continue;
		}

		listenRtpFd = UDPListen(listenRtpPort);
		if (1 > listenRtpFd)
		{
			close(proxyRtpFd);
			close(proxyRtcpFd);
			proxyRtcpFd = 0;
			proxyRtpFd = 0;
			listenRtpFd = 0;
			continue;
		}

		listenRtcpFd = UDPListen(listenRtpPort+1);
		if (1 > listenRtcpFd)
		{
			close(proxyRtpFd);
			close(proxyRtcpFd);
			close(listenRtpFd);
			proxyRtcpFd = 0;
			proxyRtpFd = 0;
			listenRtpFd = 0;
			listenRtcpFd = 0;
			continue;
		}
		break;
	}

	if (proxyFd < 1 || proxyRtpFd < 1 || proxyRtcpFd < 1
		|| listenRtpFd < 1|| listenRtcpFd < 1 )
	{
		if (proxyRtpFd > 0)
		{
			close(proxyRtpFd);
		}
		if (proxyRtcpFd > 0)
		{
			close(proxyRtcpFd);
		}
		if (listenRtpFd > 0)
		{
			close(listenRtpFd);
		}
		if (listenRtcpFd > 0)
		{
			close(listenRtcpFd);
		}
		close(proxyFd);
		gOsLog<<"can't get 4 udp port.exit thread."<<endl;
		pthread_exit(0); // Notice the cast
	}

	maxfd = listenRtcpFd;
	if (listenRtpFd > maxfd)
	{
		maxfd = listenRtpFd;
	}
	if (proxyRtcpFd > maxfd)
	{
		maxfd = proxyRtcpFd;
	}
	if (proxyRtpFd > maxfd)
	{
		maxfd = proxyRtpFd;
	}
	if (proxyFd > maxfd)
	{
		maxfd = proxyFd;
	}
	
	gOsLog<<"listen UDP on proxyRtp="<<proxyRtpPort<<endl;

	recvBuff = new unsigned char [MAXLINE];
	maxfd ++;
	while (!bSysStop)
	{
		// Set up polling.
		FD_ZERO(&fds);
		FD_SET(proxyFd,&fds);
		FD_SET(proxyRtpFd,&fds);
		FD_SET(proxyRtcpFd,&fds);
		FD_SET(listenRtpFd,&fds);
		FD_SET(listenRtcpFd,&fds);

		struct timeval tv;
		/* Wait up to 30*60 seconds. */
		tv.tv_sec = 1800;
		tv.tv_usec = 0;

		//* Wait for some input.
		nready = select(maxfd, &fds, (fd_set *) 0, (fd_set *) 0, &tv);
		//nready = select(maxfd, &fds, (fd_set *) 0, (fd_set *) 0,NULL);
		switch (nready) 
		{  
		case -1:  
			//error
			gOsLog<<"select  error:"<<strerror(errno)<<endl;
		        break;
		case 0:  
			//timeout 
			gOsLog<<"select timeout, error:"<<strerror(errno)<<endl;
		        break;
		default:  
			break;
		}  
		
		if( FD_ISSET(proxyFd, &fds))
		{
			
			char tcpBuff;
			nread = recv(proxyFd, &tcpBuff, 1, 0);
			// If error or eof, terminate. 
			if(nread < 1)
			{
				gOsLog<<"recv proxyFd error:"<<strerror(errno)<<endl;
				break;
			}

			if (readHead)
			{
				if (0 == readStep && 3 == tcpBuff)
				{
					readStep ++;
				}
				else if (1 == readStep && 0 == tcpBuff)
				{
					readStep++;
				}
				else if (2 == readStep )
				{
					readStep ++;
					readMsgLen = tcpBuff<<8;
					//gOsLog<<"readStep=2,tcpBuff="<<tcpBuff<<",readMsgLen="<<readMsgLen<<endl;
				}
				else if (3 == readStep )
				{
					readStep =0;
					readMsgLen += tcpBuff;
					readMsgLen -=4;//len include 03,00,LH,LL
					readHead = false;
					sMessage = "";
					//gOsLog<<"readStep=3,tcpBuff="<<tcpBuff<<",readMsgLen="<<readMsgLen<<endl;
				}
				else
				{
					readStep = 0;
					readMsgLen = 0;
					readHead = true;
					//no use data read
				}
			}
			else if (readMsgLen > 0)
			{
				sMessage += tcpBuff;
				readMsgLen --;
				if (0 == readMsgLen)
				{
					readMsgLen = 0;
					readHead = true;
					//string sMessage = string((const char*)recvBuff);
					printSysTime();
					gOsLog<<"proxyFd="<<proxyFd<<",read message: "<<sMessage<<endl;
					string sCommand = getTagContent(sMessage,"<Command>","</Command>");
					if ("Close" == sCommand)
					{
						break;
					}
					else if ("Start" == sCommand)
					{
						int len = 0;
						//<Message><ProxyRTP>RTPPort</ProxyRTP><ListenRTP>RTPPort</ListenRTP></Message>
						sMessage = "<Message><ProxyRTP>";
						sMessage += int2String(proxyRtpPort);
						sMessage +="</ProxyRTP><ListenRTP>";
						sMessage += int2String(listenRtpPort);
						sMessage +="</ListenRTP></Message>";
						//3,0,length(H,L),Message
						len = sMessage.length()+4;
	
						//string msg;
						unsigned char sendbuf[1024];
						sendbuf[0]=3;
						sendbuf[1]=0;
						sendbuf[2]=((len >> 8) & 0x0ff);
						sendbuf[3]=(len & 0x0ff);
						memcpy(sendbuf+4, sMessage.data(),len-4);
						sendbuf[len] ='\0';
						len = send(proxyFd, sendbuf, len+1, 0);
						if (0 > len)
						{
						    bSysStop = true;
						    gOsLog<<"error send msg,error:"<<strerror(errno)<<endl;    
						    break;
						}
					}//end of start
					else if (!listenRtpClientInited && "SetClientAddr" == sCommand)
Exemplo n.º 13
0
void listenThread(void)
{
	int listenSockt = 0;
	int yes = 1;

	// init socket to receive message from AppServer
	if( (listenSockt = socket(AF_INET, SOCK_STREAM, 0) ) == -1 )
	{
		gOsLog<<"receive socket() error:"<<strerror(errno)<<endl;
		return;
	}
	
	if( setsockopt(listenSockt, SOL_SOCKET, SO_REUSEADDR, &yes, sizeof(int)) == -1 )
	{
	 	gOsLog<<"setsockopt error:"<<strerror(errno)<<endl;
	 	close(listenSockt);
	 	return;
	}

	//  int appserversock_fd;
	sockaddr_in myAddr,clientAddr;
	// fill in connection parameters
	myAddr.sin_family = AF_INET;
	myAddr.sin_port = htons(PROXY_TCP_PORT);
	myAddr.sin_addr.s_addr = INADDR_ANY;
	bzero( &(myAddr.sin_zero), 8);

	if( bind(listenSockt, (sockaddr*)&myAddr, sizeof(sockaddr)) == -1 )
	{
		gOsLog<<"bind() error:"<<strerror(errno)<<endl;
		close(listenSockt);
		return;
	}
	else
	{
		gOsLog<<"bind() on port"<<PROXY_TCP_PORT<<endl;
	}
	
	if( listen(listenSockt, MAXCONNECTION) == -1 )
	{
		gOsLog<<"listen()  error:"<<strerror(errno)<<endl;
		close(listenSockt);
		return;
	}

	gOsLog<<"waiting for connection request from client...\n"<<endl;
	
	int sin_size = sizeof(sockaddr_in);
	int newFd = 0;
	
	while(!bSysStop)
	{
		
		newFd = accept(listenSockt, (sockaddr*)&clientAddr, (socklen_t *)&sin_size);
		if( -1 == newFd)
		{
		    gOsLog<<"accept()  error:"<<strerror(errno)<<endl;
		    continue; // try to get in another connection request from ep
		}
		else
		{
			gOsLog<<"got socket fd="<<newFd<<" connection from client:"<<inet_ntoa(clientAddr.sin_addr)<<":"<<int2String(ntohs(clientAddr.sin_port));
			int status = 0;
			do
			{
				pthread_t tidProxy = 0;
				pthread_attr_t attr;
				pthread_attr_init(&attr);
				pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED);
				status = pthread_create(&tidProxy, &attr, (void *(*)(void*))proxySocketThread, (void*)newFd);
				if (status)
				{
					gOsLog<<"create proxySocketThread thread fail! status="<<status<<",error:"<<strerror(errno)<<endl;
				}
				pthread_attr_destroy(&attr);
			}while(0 != status && errno == EINTR);
		}
	}
	
	close(listenSockt);
	return;
}
Exemplo n.º 14
0
inline void Player::draw(Coordinate unused)	{
	glColor3f(1,1,1);
	string s;
	s.assign("Score: ");
	s.append(int2String(score));
	renderString(412, 354, s);

	int currentFps = Fps::getFps();
	if (currentFps < 1)	{
		currentFps = 1;
	}
	if (l)	{
		if (dTheta <= 1.1)	{
			dTheta += 0.02;
		}
	}
	else if (r)	{
		if (dTheta >= -1.1)	{
			dTheta -= 0.02;
		}
	}
	else {
		dTheta /= 1.1;
		if (dTheta < 0.3 && dTheta > -0.3)	{
			dTheta = 0;
		}
	}
	direction += dTheta;
	if (direction >= 360)	{
		direction -= 360;
	}
	if (direction < 0)	{
		direction += 360;
	}
	if (f)	{
		dX = acceleration*cos(D2R(direction));
		dY = acceleration*sin(D2R(direction));
		velocity.vx += dX;
		velocity.vy += dY;
	}
	else if (b)	{
		dX = -(acceleration*cos(D2R(direction)));
		dY = -(acceleration*sin(D2R(direction)));
		velocity.vx += dX;
		velocity.vy += dY;
	}
	else {
		velocity.vx *= ((1-deceleration));
		velocity.vy *= ((1-deceleration));
	}
	velocity.magnitude = sqrt(velocity.vx*velocity.vx + velocity.vy*velocity.vy);
	if(velocity.magnitude > 2)	{
		float tempDecel = (2/velocity.magnitude);
		velocity.vx *= tempDecel;
		velocity.vy *= tempDecel;
	}
	if(this->cell != -1)	{
		Collision collision = detectCollisions();
		if(collision.happened)	{
			velocity.vx = collision.vx;
			velocity.vy = collision.vy;
		}
	}

	if(sucked)	{
		Coordinate dw;
		dw.x = wpLoc.x - location.x;
		dw.y = wpLoc.y - location.y;
		if(abs(dw.x) < 10 && abs(dw.y) < 10)	{
			velocity.vx = 0;
			velocity.vy = 0;
			location.x = wpLoc.x;
			location.y = wpLoc.y;
			finishLevel();
		}
		else	{
			velocity.vx = dw.x * 0.2;
			velocity.vy = dw.y * 0.2;
		}
	}
	location.x += velocity.vx;
	location.y += velocity.vy;

	if(attacking)	{
		int atkspeed = 6;
		atkspin += atkspeed;
		if(atkspeed < 0)	{
			attacking = false;
		}
		if (atkspin >= 180)	{
			atkspeed -= 0.0001;
		}
		if (atkspin > 360)	{
			atkspin -= 360;
			atkspeed -= 0.0001;
		}
		bbox.hheight = 42;
	}
	else	{
		bbox.hheight = 25;
	}

	if(hit)	{
		if(glutGet(GLUT_ELAPSED_TIME) - safetimer > 3000)	{
			hit = false;
			safe = false;
		}
		if(!flash)	{
			flash = true;
		}
		else	{
			drawPlayer();
			flash = false;
		}
	}
	else	{
		drawPlayer();
	}
};