void HudPanel::updateBuffList()
{
	auto buffUnits = _buffList->getItems();
	auto buffs = Detect::shareDetect()->getUser()->getBuffs();

	auto delBuffUnits = Vector<BuffUnit*>();
	for(auto pair:buffUnits)
	{
		auto buffUnit = dynamic_cast<BuffUnit*>(pair);
		if(buffUnit != nullptr)
		{
			auto exist = false;
			for(auto buff:buffs)
			{
				if(buffUnit->getBuff() == buff)
				{
					exist = true;
					break;
				}
			}
			if(exist == false)
			{
				delBuffUnits.pushBack(buffUnit);
			}
		}
	}

	for(auto pair:delBuffUnits)
	{
		_buffList->removeItem(_buffList->getIndex(pair));
	}
	delBuffUnits.clear();



	for(auto buff:buffs)
	{
		auto exist = false;
		for(auto pair:buffUnits)
		{
			auto buffUnit = dynamic_cast<BuffUnit*>(pair);
			if(buffUnit != nullptr && buffUnit->getBuff() == buff)
			{
				exist = true;
				break;
			}
		}
		if(exist == false)
		{
			auto buffUnit = BuffUnit::create();
			buffUnit->setBuff(buff);
			_buffList->pushBackCustomItem(buffUnit);
		}
	}
}
void HudPanel::selectedBuffEvent(Ref *pSender, ListView::EventType type)
{
	switch (type)
	{
	case cocos2d::ui::ListView::EventType::ON_SELECTED_ITEM_START:
		{
			ListView* listView = static_cast<ListView*>(pSender);
			CC_UNUSED_PARAM(listView);
			CCLOG("select child start index = %ld", listView->getCurSelectedIndex());
			//auto tag = listView->getItem(listView->getCurSelectedIndex())->getTag();
			//auto endStatUnit = _endStatsUnit.at(listView->getCurSelectedIndex());
			break;
		}
	case cocos2d::ui::ListView::EventType::ON_SELECTED_ITEM_END:
		{
			ListView* listView = static_cast<ListView*>(pSender);
			CC_UNUSED_PARAM(listView);
			CCLOG("select child end index = %ld", listView->getCurSelectedIndex());
			auto buffUnit = static_cast<BuffUnit*>(listView->getItem(listView->getCurSelectedIndex()));
			
			auto buffPan = BuffPanel::create("buff");
			buffPan->initWithBuff(buffUnit->getBuff());
			PopPanel::getInstance()->addPanel(buffPan, 2);
			break;
		}
	default:
		break;
	}
}
void
NParam::dump( ostream& out, bool dumpValue, bool singleLine, 
              uint32 maxLen ) const
 {
   if ( !singleLine ) {
      out << "   ParamID " << getParamID() << " len " 
          << getLength() << endl;
      if ( dumpValue ) {
         Utility::hexDump( out, const_cast<byte*>( getBuff() ), 
                           getLength(), "      " );
      }
   } else {
      out << getParamID();
      bool allPrintable = true;
      bool anyPrintable = false;
      for ( uint32 i = 0 ; i < MIN( getLength(), maxLen ) ; ++i ) {
         if ( !isprint( getVector()[ i ] ) || getVector()[ i ] == ':' ||
              getVector()[ i ] == ';' ) {
            if ( i + 1 == getLength() && getVector()[ i ] == '\0' &&
                 getLength() > 1 )
            {
               // Ok is stringlike
            } else {
               allPrintable = false;
            }
         } else {
            anyPrintable = true; 
         }
      }
      if ( !allPrintable ) {
         out << ":0x" << hex << setfill( '0' );
         for ( uint32 i = 0 ; i < MIN( getLength(), maxLen ) ; ++i ) {
            out << setw( 2 ) << uint32( getVector()[ i ] );
         }
         out << dec;
         out << ";";
      }
      if ( anyPrintable ) {
         if ( allPrintable ) {
            out << ":";
         }
         for ( uint32 i = 0 ; i < MIN( getLength(), maxLen ) ; ++i ) {
            if ( isprint( getVector()[ i ] ) && getVector()[ i ] != ':' &&
                 getVector()[ i ] != ';' ) {
               out << getVector()[ i ];
            } else {
               out << ".";
            }
         }
      } else if ( getLength() == 0 ) {
         // Empty
         out << ":";
      }
      if ( getLength() > maxLen ) {
         out << "(" << getLength() << ")"; 
      }
   }
}
Exemple #4
0
INT32 _mongoSession::run()
{
   INT32 rc                     = SDB_OK ;
   BOOLEAN bigEndian            = FALSE ;
   UINT32 msgSize               = 0 ;
   UINT32  headerLen            = sizeof( mongoMsgHeader ) - sizeof( INT32 ) ;
   INT32 bodyLen                = 0 ;
   engine::pmdEDUMgr *pmdEDUMgr = NULL ;
   CHAR *pBuff                  = NULL ;
   const CHAR *pBody            = NULL ;
   const CHAR *pInMsg           = NULL ;
   engine::monDBCB *mondbcb     = engine::pmdGetKRCB()->getMonDBCB() ;

   if ( !_pEDUCB )
   {
      rc = SDB_SYS ;
      goto error ;
   }

   pmdEDUMgr = _pEDUCB->getEDUMgr() ;
   bigEndian = checkBigEndian() ;
   while ( !_pEDUCB->isDisconnected() && !_socket.isClosed() )
   {
      _pEDUCB->resetInterrupt() ;
      _pEDUCB->resetInfo( engine::EDU_INFO_ERROR ) ;
      _pEDUCB->resetLsn() ;

      rc = recvData( (CHAR*)&msgSize, sizeof(UINT32) ) ;
      if ( rc )
      {
         if ( SDB_APP_FORCED != rc )
         {
            PD_LOG( PDERROR, "Session[%s] failed to recv msg size, "
                    "rc: %d", sessionName(), rc ) ;
         }
         break ;
      }

      if ( bigEndian )
      {
      }

      if ( msgSize < headerLen || msgSize > SDB_MAX_MSG_LENGTH )
      {
         PD_LOG( PDERROR, "Session[%s] recv msg size[%d] is less than "
                 "mongoMsgHeader size[%d] or more than max msg size[%d]",
                 sessionName(), msgSize, sizeof( mongoMsgHeader ),
                 SDB_MAX_MSG_LENGTH ) ;
         rc = SDB_INVALIDARG ;
         break ;
      }
      else
      {
         pBuff = getBuff( msgSize + 1 ) ;
         if ( !pBuff )
         {
            rc = SDB_OOM ;
            break ;
         }
         *(UINT32*)pBuff = msgSize ;
         rc = recvData( pBuff + sizeof(UINT32), msgSize - sizeof(UINT32) ) ;
         if ( rc )
         {
            if ( SDB_APP_FORCED != rc )
            {
               PD_LOG( PDERROR, "Session[%s] failed to recv rest msg, rc: %d",
                       sessionName(), rc ) ;
            }
            break ;
         }
         pBuff[ msgSize ] = 0 ;
         {
            _resetBuffers() ;
            _converter.loadFrom( pBuff, msgSize ) ;
            rc = _converter.convert( _inBuffer ) ;
            if ( SDB_OK != rc && SDB_OPTION_NOT_SUPPORT != rc)
            {
               goto error ;
            }

            _pEDUCB->incEventCount() ;
            mondbcb->addReceiveNum() ;
            if ( SDB_OK != ( rc = pmdEDUMgr->activateEDU( _pEDUCB ) ) )
            {
               PD_LOG( PDERROR, "Session[%s] activate edu failed, rc: %d",
                       sessionName(), rc ) ;
               goto error ;
            }

            if ( _preProcessMsg( _converter.getParser(),
                                 _resource, _contextBuff ) )
            {
               goto reply ;
            }

            pInMsg = _inBuffer.data() ;
            while ( NULL != pInMsg )
            {
               rc = _processMsg( pInMsg ) ;
               if ( SDB_OK == rc )
               {
                  _authed = TRUE ;
               }

               rc = _converter.reConvert( _inBuffer, &_replyHeader ) ;
               if ( SDB_OK != rc )
               {
                  goto reply ;
               }
               else
               {
                  if ( !_inBuffer.empty() )
                  {
                     _contextBuff.release() ;
                     pInMsg = _inBuffer.data() ;
                  }
                  else
                  {
                     pInMsg = NULL ;
                  }
               }
            }
         reply:
            _handleResponse( _converter.getOpType(), _contextBuff ) ;
            pBody = _contextBuff.data() ;
            bodyLen = _contextBuff.size() ;
            INT32 rcTmp = _reply( &_replyHeader, pBody, bodyLen ) ;
            if ( rcTmp )
            {
               PD_LOG( PDERROR, "Session[%s] failed to send response,"
                       "rc: %d", sessionName(), rcTmp ) ;
               goto error ;
            }
            pBody = NULL ;
            bodyLen = 0 ;
            _contextBuff.release() ;

            if ( SDB_OK != ( rc = pmdEDUMgr->waitEDU( _pEDUCB ) ) )
            {
               PD_LOG( PDERROR, "Session[%s] wait edu failed, rc: %d",
                       sessionName(), rc ) ;
               goto error ;
            }
         }
      }
   } // end while
done:
   disconnect() ;
   return rc ;
error:
   goto done ;
}
Exemple #5
0
int ActuatorARTKSM::actuatorReadFile(){
	FILE          *fp;
	char		  buf[256],buf1[256],fileDAT[256];

	//--------------------------------------------------------------------------
	// Open the ActuatorARTKSM Configuration file
	//--------------------------------------------------------------------------
	printf("\n --------------------------------------------------------------------------");
	if( (fp=fopen(this->configFilename,"r")) == NULL) {
		printf("\n Error on opening %s !! ",this->configFilename);
		return  -1;
	}
	printf("\n Opening file %s ,  ARTKSM Actuator", this->configFilename);
	printf("\n --------------------------------------------------------------------------");

	//--------------------------------------------------------------------------
	// READ THE Actuator Name
	//--------------------------------------------------------------------------
	getBuff(buf, 256, fp);
	if (sscanf(buf, "%s", &this->name) != 1) { printf("\n Check %s file format", this->configFilename); fclose(fp); return -1;	}
	printf("\n Actuator name: %s", this->name);

	//--------------------------------------------------------------------------
	// READ THE MARKER CONFIGURATION
	//--------------------------------------------------------------------------
	// Marker that defines the actuator
	getBuff(buf, 256, fp);
	if (sscanf(buf, "%s", &buf1) != 1) { printf("\n Check %s file format", this->configFilename); fclose(fp); return -1;	}
	if ((this->patternNumber = arLoadPatt(buf1)) < 0) { fclose(fp);  return(0);	}
	printf("\n Using marker: %s, id: %d", buf1, this->patternNumber); 
	// Marker Width
	getBuff(buf, 256, fp);
	if (sscanf(buf, "%lf", &this->markerWidth) != 1) { printf("\n Check %s file format", this->configFilename);fclose(fp); return -1;  }
	// Marker Center
	getBuff(buf, 256, fp);
	if (sscanf(buf, "%lf %lf", &this->markerCenter[0], &this->markerCenter[1]) != 2) {
			printf("\n Check %s file format", this->configFilename); fclose(fp); return(0);  }
	printf(" W: %3.2f, Center(%3.2f,%3.2f)", this->markerWidth , this->markerCenter[0], this->markerCenter[1]);
	// Marker cover (USE_DEFAULT to get default marker cover / NO_COVER to don't use a marker cover)
	getBuff(buf, 256, fp);
	if (sscanf(buf, "%s %s", &buf1, &fileDAT) != 2) { printf("\n Check %s file format", this->configFilename); fclose(fp); return -1; }
	
	if( strcmp(buf1, "NO_COVER") == 0){
		this->cover = 0;
		printf("\n Actuator Marker without cover.");
	}
	else{

		if ( strcmp(buf1, "USE_DEFAULT") == 0) { 
			this->cover = (*myArpe).myGenericItens.markCover;
			printf("\n Using Default Cover ");
		}
		else{
			if (strcmp(buf1, "VRML") == 0) {
				//VRML Object
				iVrml *c = new iVrml();
				(*c).modelType = 1;
				(*c).vrmlID = arVrmlLoadFile(fileDAT); 
				if ((*c).vrmlID < 0) {
					printf("\n Error on Marker Base Cover %s file or on VRML file (%d)",fileDAT,(*c).vrmlID);
					this->cover = 0;
				} else { 
					printf("\n Cover object VRML id: %d ", (*c).vrmlID); 
					this->cover = c;}
				
			} else {
				printf("\n type not yet coded!!! Patience! ");
			}
		}
	}
	//--------------------------------------------------------------------------
	// READ THE Symbolic
	//--------------------------------------------------------------------------
	getBuff(buf, 256, fp);
	if (sscanf(buf, "%s %s", &buf1, &fileDAT) != 2) { printf("\n Check %s file format", this->configFilename); fclose(fp); return -1; }
	if (strcmp(buf1, "VRML") == 0) {
		//VRML Object
		iVrml *s = new iVrml();
		(*s).modelType = 1;
		(*s).vrmlID = arVrmlLoadFile(fileDAT); 
		if ((*s).vrmlID < 0) {
			printf("\n Error on Symbolic object %s file or on VRML file (%d)",fileDAT,(*s).vrmlID);
			this->symbol = 0;
		} else { 
			printf("\n Symbolic object VRML id: %d ", (*s).vrmlID); 
			this->symbol = s;}
	} else {
		printf("\n type not yet coded!!! Patience! ");
	}

	//--------------------------------------------------------------------------
	// READ Point were the action occors on the ARTSM Actuator
	//--------------------------------------------------------------------------
	// Point model
	getBuff(buf, 256, fp);
	if (sscanf(buf, "%s %s", &buf1, &fileDAT) != 2) { printf("\n Check %s file format", this->configFilename); fclose(fp); return -1; }

	if ( strcmp(buf1, "DEFAULT_IPOINT") == 0) { 
		this->interactionPoint = (*myArpe).myGenericItens.holding;
		printf("\n Using Default Interaction Point Representation.");
	}
	else{

		if (strcmp(buf1, "VRML") == 0) {
			//VRML Object
			iVrml *ip = new iVrml();
			(*ip).modelType = 1;
			(*ip).vrmlID = arVrmlLoadFile(fileDAT); 
			printf("\n Point model object VRML id: %d ", (*ip).vrmlID);
			if ((*ip).vrmlID < 0) {
				printf("\n Error on Point model object %s file or on VRML file (%d)",fileDAT,(*ip).vrmlID);
				this->interactionPoint = 0;
			} else { 
				printf("\n Point model object VRML id: %d ", (*ip).vrmlID); 
				this->interactionPoint = ip;}
			if ((*ip).vrmlID < 0) { fclose(fp); return(0); }
			
		} else {
			printf("\n type not yet coded!!! Patience! ");
		}
	}
	// Translation (x,y,z) (mm)
	getBuff(buf, 256, fp);
	if( sscanf(buf, "%lf %lf %lf",	&this->ipTra[0], &this->ipTra[1], &this->ipTra[2]) != 3 ) {
			printf("\n Check %s file format", this->configFilename);fclose(fp); return -1;  }
	// Action radius of the point
	getBuff(buf, 256, fp);
	if (sscanf(buf, "%lf", &this->distCollision) != 1) { printf("\n Check %s file format", this->configFilename); fclose(fp); return -1; }
	printf("\n Point position from center (%3.2f,%3.2f,%3.2f), radius: %3.2f", 
		this->ipTra[0], this->ipTra[1], this->ipTra[2], this->distCollision);

	fclose(fp);
	
	return 0;
}
Exemple #6
0
int Ball::ballReadFile(){
	
	FILE          *fp;
	char           buf[256],buf1[256],buf2[256],fileDAT[256];
	int			   numObjects;

	//--------------------------------------------------------------------------
	// Open the Ball Configuration file
	//--------------------------------------------------------------------------
	printf("\n --------------------------------------------------------------------------");
	printf("\n Setting up action point balls file %s", this->filename);
	printf("\n --------------------------------------------------------------------------");

	if( strcmp(this->filename,"") == 0) {
		printf("\n Any balls will be assigned to this action point"); 
		return 0;
	}

	if( (fp=fopen(this->filename,"r")) == NULL) { printf("\n Error on opening %s action point balls file!! ",this->filename);	return 0;}

	//--------------------------------------------------------------------------
	// Read the amount of models
	//--------------------------------------------------------------------------
	getBuff(buf,256,fp);
    if (sscanf(buf, "%d", &numObjects) != 1) {
		 printf("\n Check %s file format", this->filename);fclose(fp); return(0);
	}
	printf("\n About to load %d balls.", numObjects);

	//Looping para ler todos os modelos do iPoint
    for (int i = 0; i < numObjects; i++) {
		//--------------------------------------------------------------------------
		// Read the objects
		//--------------------------------------------------------------------------
        getBuff(buf, 256, fp);
		if (sscanf(buf, "%s", &buf1) != 1) { printf("\n Check %s file format", this->filename); fclose(fp); return(0); }
		
		if ( strcmp(buf1,"MODEL3D") == 0 ){
			if (sscanf(buf, "%s %s %s", &buf1, &buf2, &fileDAT) != 3) { printf("\n Check %s file format", this->filename); fclose(fp); return(0); }
			if(  strcmp(buf2,"VRML") == 0 ){
				iVrml* obj = new iVrml();

				strcpy((*obj).filename,fileDAT);

				(*obj).id = i +1;
				(*obj).type = 1; // MODEL3D
				(*obj).modelType = 1;  //VRML
				(*obj).vrmlID = arVrmlLoadFile(fileDAT);
				if ((*obj).vrmlID < 0) {
					printf("\n Error on %s file or on VRML file (%d)",fileDAT,(*obj).vrmlID);
				} else {
					printf("\n Ball %s VRML id: %d ", (*obj).filename, (*obj).vrmlID);

					switch(i){
					case 0:{ // Holding
							this->holding = obj;
							break;}
					case 1:{ // Canwork
							this->canWork = obj;
							break;}
					case 2:{ // Cannotwork
							this->cannotWork = obj;
							break;}
					default: {
							printf("\n The file %d will be ignore", fileDAT);
							break;}
					};


				}

			} else {
				printf("\n This type of object (%s-%s) is not coded on Matrix yet.",buf1,buf2);
			}
		} else { 
			printf("\n This type of object (%s) is not coded on Matrix yet.",buf1);
		}
	
	}

	printf("\n %d Balls correctly read!",numObjects);
	fclose(fp);

	return 1;
}
Exemple #7
0
INT32 _mongoSession::run()
{
   INT32 rc                     = SDB_OK ;
   BOOLEAN bigEndian            = FALSE ;
   UINT32 msgSize               = 0 ;
   UINT32  headerLen            = sizeof( mongoMsgHeader ) - sizeof( INT32 ) ;
   CHAR *pBuff                  = NULL ;
   const CHAR *pBody            = NULL ;
   INT32 bodyLen                = 0 ;
   engine::pmdEDUMgr *pmdEDUMgr = NULL ;
   std::vector< msgBuffer * >::iterator itr ;

   if ( !_pEDUCB )
   {
      rc = SDB_SYS ;
      goto error ;
   }

   pmdEDUMgr = _pEDUCB->getEDUMgr() ;
   bigEndian = checkBigEndian() ;
   while ( !_pEDUCB->isDisconnected() && !_socket.isClosed() )
   {
      _pEDUCB->resetInterrupt() ;
      _pEDUCB->resetInfo( engine::EDU_INFO_ERROR ) ;
      _pEDUCB->resetLsn() ;

      rc = recvData( (CHAR*)&msgSize, sizeof(UINT32) ) ;
      if ( rc )
      {
         if ( SDB_APP_FORCED != rc )
         {
            PD_LOG( PDERROR, "Session[%s] failed to recv msg size, "
                    "rc: %d", sessionName(), rc ) ;
         }
         break ;
      }

      if ( bigEndian )
      {
      }

      if ( msgSize < headerLen || msgSize > SDB_MAX_MSG_LENGTH )
      {
         PD_LOG( PDERROR, "Session[%s] recv msg size[%d] is less than "
                 "mongoMsgHeader size[%d] or more than max msg size[%d]",
                 sessionName(), msgSize, sizeof( mongoMsgHeader ),
                 SDB_MAX_MSG_LENGTH ) ;
         rc = SDB_INVALIDARG ;
         break ;
      }
      else
      {
         pBuff = getBuff( msgSize + 1 ) ;
         if ( !pBuff )
         {
            rc = SDB_OOM ;
            break ;
         }
         *(UINT32*)pBuff = msgSize ;
         rc = recvData( pBuff + sizeof(UINT32), msgSize - sizeof(UINT32) ) ;
         if ( rc )
         {
            if ( SDB_APP_FORCED != rc )
            {
               PD_LOG( PDERROR, "Session failed to recv rest msg, rc: %d",
                       sessionName(), rc ) ;
            }
            break ;
         }
         pBuff[ msgSize ] = 0 ;

         {
            resetBuffers() ;
            _converter->loadFrom( pBuff, msgSize ) ;
            rc = _converter->convert( _inBufferVec ) ;
            if ( SDB_OK != rc )
            {
               if ( SDB_OPTION_NOT_SUPPORT == rc )
               {
               }
               else
               {
                  goto error ;
               }
            }

            if ( _preProcessMsg( _converter->getParser(),
                                 _resource, _contextBuff ) )
            {
               goto reply ;
            }
            itr = _inBufferVec.begin() ;
            for ( ; itr != _inBufferVec.end() ; ++itr )
            {
               _pEDUCB->incEventCount() ;
               _needReply = FALSE ;
               if ( SDB_OK != ( rc = pmdEDUMgr->activateEDU( _pEDUCB ) ) )
               {
                  PD_LOG( PDERROR, "Session[%s] activate edu failed, rc: %d",
                          sessionName(), rc ) ;
                  goto error ;
               }
               rc = _processMsg( (*itr)->data() ) ;
               if ( rc )
               {
                  if ( SDB_DMS_CS_EXIST == rc &&
                       OP_CMD_CREATE == _converter->getOpType())
                  {
                     _contextBuff.release() ;
                  }
                  else
                  {
                     goto reply ;
                  }
               }
               if ( SDB_OK != ( rc = pmdEDUMgr->waitEDU( _pEDUCB ) ) )
               {
                  PD_LOG( PDERROR, "Session[%s] wait edu failed, rc: %d",
                          sessionName(), rc ) ;
                  goto error ;
               }
            }
         reply:
            pBody = _contextBuff.data() ;
            bodyLen = _contextBuff.size() ;
            INT32 rcTmp = _reply( &_replyHeader, pBody, bodyLen ) ;
            if ( rcTmp )
            {
               PD_LOG( PDERROR, "Session[%s] failed to send response, rc: %d",
                       sessionName(), rcTmp ) ;
               goto error ;
            }
            pBody = NULL ;
            bodyLen = 0 ;
         }
      }
   } // end while
done:
   disconnect() ;
   return rc ;
error:
   goto done ;
}