コード例 #1
0
ファイル: piece.cpp プロジェクト: mjvd/personal
mm::Piece::Piece(std::string const& s)
    : mRotation(0)
    , mMaxRotations(0)
    , mPosX(InvalidPosition.first)
    , mPosY(InvalidPosition.second)
    , isSpecial(false)
    , originalStr(s)
{
    mStr[0] = CharToInt(s[3]);
    mStr[1] = CharToInt(s[0]);
    mStr[2] = CharToInt(s[1]);
    mStr[3] = CharToInt(s[2]);

    mL[0] = 100*BL() + 10*TL() + TR();
    mL[1] = 100*TL() + 10*TR() + BR();
    mL[2] = 100*TR() + 10*BR() + BL();
    mL[3] = 100*BR() + 10*BL() + TL();

    if      (mStr[0] == mStr[1] && mStr[1] == mStr[2] && mStr[0] == mStr[3]) { mMaxRotations = 1; }
    else if (mStr[0] == mStr[2] && mStr[1] == mStr[3])                       { mMaxRotations = 2; }
    else                                                                     { mMaxRotations = 4; }

    if (s == "GGGG" || s == "BBBB" || s == "YYYY" || s == "YRBG")
    {
        isSpecial = true;
    }
}
コード例 #2
0
ファイル: xfun.cpp プロジェクト: Crawping/XEIM
char StrToBin(char *str){
	char tempWord[2];
	char chn;

	tempWord[0] = CharToInt(str[0]);                         //make the B to 11 -- 00001011
	tempWord[1] = CharToInt(str[1]);                         //make the 0 to 0  -- 00000000

	chn = (tempWord[0] << 4) | tempWord[1];                //to change the BO to 10110000

	return chn;
}
コード例 #3
0
size_t LedControl::write(uint8_t c) {
  if (CharToInt(c) > 94 || CharToInt(c) < 0)
    return 0;

  this->displayChar((this->cursor_x), (this->cursor_y), c);
  if (this->Font_mode)
    this->cursor_x += 1 + pgm_read_byte(alphabetBitmap[CharToInt(c)] + FONE_SIZE_X);
  else
    this->cursor_y += 1 + FONE_SIZE_Y;
  return 1;
}
コード例 #4
0
size_t Matrix::write(uint8_t c) {
   if(CharToInt(c) > 94 || CharToInt(c) < 0)
	return 0;

  for (int a = 0; a < getMatrixNum(); a++)
    led[a].write(c);

  return 1;
/* void Matrix::print(char* _c) {
  for (int a = 0; a < this->_matrixNum; a++)
    led[a].print(_c);
} */
}
コード例 #5
0
ファイル: MyString.cpp プロジェクト: kwdhd/datastrut-c
long StrToLong(char* str){
    long num = 0;
    int len = StrLen(str);
    if( len == 0)
        return 0;
    int neg = 0;
    if(*str == '-'){
        neg = 1;
        str++;
    }
    if(*str == '+')
        str++;
    for(;*str!='\0';str++)
    {
         num = num*10 + CharToInt(*str);
    }
    
    printf("test:%ld,%s\n",num,BitToStr(num));
    if(neg == 1)
    {
        num = ~num+ 1;
        return num;
    }
    else
    {
        return num;
    }
}
コード例 #6
0
ファイル: MoonScene.cpp プロジェクト: wenqvip/MoonGame
void MoonScene::ReadCollisionBox(const char* appname, const char* scnpath, MoonObject* pObj)
{
	char ch[256];
	char c[4];
	int nCollisionBox;
	string cb;
	D3DXVECTOR3 cbmin,cbmax,cbpos;
	GetPrivateProfileString(appname,"collisionbox","0",ch,256,scnpath);
	nCollisionBox = CharToInt(ch);
	for(int i=0; i<nCollisionBox; i++)
	{
		sprintf_s(c,"%03d",i);
		cb = "cb";
		cb+=c; cb+="min";
		GetPrivateProfileString(appname,cb.c_str(),NULL,ch,256,scnpath);
		cbmin = CharToVector3(ch);
		cb = "cb";
		cb+=c; cb+="max";
		GetPrivateProfileString(appname,cb.c_str(),NULL,ch,256,scnpath);
		cbmax = CharToVector3(ch);
		cb = "cb";
		cb+=c; cb+="pos";
		GetPrivateProfileString(appname,cb.c_str(),"(0,0,0)",ch,256,scnpath);
		cbpos = CharToVector3(ch);
		_CollisionTS->Add(pObj->GetID(),pObj,cbmin,cbmax,cbpos);
	}
	LogInfo("MoonScene::ReadCollisionBox() Create all the collisionboxes of a object.");
}
コード例 #7
0
void LedControl::displayChar(int8_t row, int8_t col, char _charIndex) {
  if (row < 0 - 8 || row > 7 + 8 || col < 0 - 8 || col > 7 + 8 || CharToInt(_charIndex) > 94 || CharToInt(_charIndex) < 0)
    return;

  uint8_t n = CharToInt(_charIndex);
  uint8_t m = (this->Font_mode ? FONE_SIZE_X - pgm_read_byte(alphabetBitmap[n] + FONE_SIZE_X) : 0);

  byte val;
  for (int8_t i = m; i < FONE_SIZE_X + 1; i++) {
    for (int8_t _col = col; col < 0 ? _col < 8 + col : _col < 8; _col++) {
      if (i - m + row < 0 || i - m + row > 7)
        break;
      if (i != FONE_SIZE_X)
        val = pgm_read_byte(alphabetBitmap[n] + i) >> (_col - col);
      else
        val = 0x00 >> (_col - col);
      val = val & 0x01;
      this->setLed(i - m + row, _col, val);
    }
  }
コード例 #8
0
ファイル: stringutils.cpp プロジェクト: node-/get-token
int AtoI(char ConvertThis[])
{
    int returnVal = 0;
    int ConvertThisLen = StrLen(ConvertThis);
    for(int i = 0; i <= ConvertThisLen && ConvertThis[i] != '\0'; i++)
    {
        // multiply the digit by 10^(whichever place it's in... 1s, 10s, 100s etc)
        // -2 to compensate for the index's value and the null character
        returnVal += CharToInt(ConvertThis[i])*pow(10.0,ConvertThisLen-i-2);
    }
    return returnVal;
}
コード例 #9
0
void LedControl::writeString(int16_t _time, char * _displayString) {
  int16_t _leng = 0;
  int16_t _wight = 0;
  while (_displayString[_leng] != NULL) _wight += 1 + pgm_read_byte(alphabetBitmap[CharToInt(_displayString[_leng++])] + FONE_SIZE_X);
//  Serial.println(_wight);

  for (int16_t a = 8; a > -_wight; a--) {
    int16_t c = 0;
    setCursor(a, 0);
    print(_displayString);
    delay(_time);
  }
}
コード例 #10
0
ファイル: stringutils.cpp プロジェクト: node-/get-token
int ToInt(char MyString[], int pos)
{
    int i = pos;
    char digits[] = "1234567890"; // all digits in a char array, iterate through it similarly to FindAny()
    int MyStringLen = StrLen(MyString);
    for (; i < MyStringLen && MyString[i] != '\0'; i++) {
        for (int j = 0; j <= 10; j++) {
            if (MyString[i] == digits[j]) {
                return CharToInt(digits[j]); // i think this might be pretty hackish, but it works lol
            }
        }
    }
    return -1;
}
コード例 #11
0
bool
StringTo(
  int &	    dest,
  const char * 	    src,
  unsigned short    baseToUse,
  size_t    	    len
  )
{
  int  value = 0;

  const char * 	    end = src + ( len != NPOS ? len : strlen( src ) );
  unsigned short    base = baseToUse;
  bool	    	    neg = false;

  const char * conv = _StringToNumPrep( src, end, base, neg );

  if( ! conv || conv >= end )
    {
      dest = 0;
      return( true );
    }

  const char * first = conv;

  for( ; conv < end; conv++ )
    {
      if( CharIsBaseDigit( *conv, base ) )
	{
	  value *= base;
	  value += CharToInt( *conv );
	}
      else
	{
	  if( conv == first || isdigit( *conv ) )
	    return( false );

	  dest = (neg) ? value * -1 : value;
	  return( true );
	}
    }
  dest = (neg) ? value * -1 : value;
  return( true );
}
コード例 #12
0
ファイル: cli.c プロジェクト: tcolgan/examples
int StringToInt( char* str )
{
   int val = 0 ;
   int mult = 10 ;

   if( ( str[0] == '0' ) && ( str[1] == 'x' ) )
   {
      str += 2 ;
      mult = 16 ;
   }

   while( *str )
   {
      val *= mult ;
      val += CharToInt( *str ) ;
      str++ ;
   }

   return val ;
}
コード例 #13
0
ファイル: 1.c プロジェクト: WalkerMills/personal
int main() {
    char lower = 'e';
    char upper = 'E';

    printf("toupper(%c) = %c\n", lower, toupper(lower));
    printf("tolower(%c) = %c\n\n", upper, tolower(upper));

    char *number = "123";

    printf("CharToInt(\"%s\") = %d\n\n", number, CharToInt(number));

    unsigned char month = 7;
    unsigned char day = 9;
    uint16_t year = 2014;
    uint16_t date = ToDate(month, day, year);

    printf("Date in: %d/%d/%d\n", month, day, year);
    printf("Packed value: 0x%X\n", date);
    printf("Date out: %d/%d/%d\n\n", ExtractMonth(date), ExtractDay(date), 
           ExtractYear(date));

    int nbits = CntBits(date);

    printf("Bits set in 0x%X: %d\n\n", date, nbits);

    int bit = 4;
    int n = 2;

    printf("TestBit(0x%X, %d) = %s\n\n", bit, n, 
           TestBit(bit, n) ? "true" : "false");

    int16_t rotate = -3;

    printf("ROR(0x%X) = %d\n", rotate, ROR(rotate));
    printf("ROL(0x%X) = %d\n\n", rotate, ROL(rotate));

    return 0;
}
コード例 #14
0
void CheckBluetoothValues(void) {
    if (!firstRun) {

        // Reset the UART RX buffer to clear it
        UART1_ResetBuffer();


        DataMatch = true;
        // Check RTC value
        UART1_WriteString((unsigned char *) "SHR,0018");

        __delay_ms(5);

        // check if a recevied command is in the buffer
        if (uart1_rxLength > 11) {
            // check if the date in the Bluetooth module matches the LastDate variable.  If not then the date has been updated by a client
            for (x = 0; x < 10; x++) {
                if (DateTimeResponse[x + 9] != uart1_rxBuffer[x]) {
                    DataMatch = false;
                }
            }

            if (DataMatch == false) {
                if ((uart1_rxBuffer[0] == '1' || uart1_rxBuffer[0] == '2') && ((uart1_rxBuffer[1] >= '0') && (uart1_rxBuffer[1] <= '9'))){
                    Time.tm_year = CharToInt(uart1_rxBuffer[0], uart1_rxBuffer[1]);
                    Time.tm_mon = CharToInt(uart1_rxBuffer[2], uart1_rxBuffer[3]);
                    Time.tm_mday = CharToInt(uart1_rxBuffer[4], uart1_rxBuffer[5]);
                    Time.tm_hour = CharToInt(uart1_rxBuffer[6], uart1_rxBuffer[7]);
                    Time.tm_min = CharToInt(uart1_rxBuffer[8], uart1_rxBuffer[9]);
                    Time.tm_sec = CharToInt(uart1_rxBuffer[10], uart1_rxBuffer[11]);
                    Time.tm_wday = 1; // weekday
                    RTCC_TimeSet(&Time);

                    blinkRed();
                }
            }

        }

    }

    // Check Alert Status
}
コード例 #15
0
bool
StringTo(
  double &  	    dest,
  const char * 	    src,
  unsigned short    baseToUse,
  size_t    	    len,
  bool		    stopAtNonDigit
  )
{

  double  value = 0;
  
  const char *      end = src + ((len != NPOS) ? len : strlen( src ) );
  unsigned short    base = baseToUse;
  bool	    	    neg = false;
  
  const char * conv = _StringToNumPrep( src, end, base, neg );

  int	fract = 0;

  if( ! conv || conv >= end )
    {
      dest = 0;
      return( true );
    }

  for( ; conv < end; conv++ )
    {
      if( ! fract && *conv == '.' )
	{
	  fract = 1;
	  continue;
	}
      
      if( CharIsBaseDigit( *conv, base ) )
	{
	  value *= base;
	  value += CharToInt( *conv );
	  if( fract ) fract++;
	}
      else
	{
	  if( ! stopAtNonDigit )
	    {
	      return( false );
	    }
	  else
	    {
	      
	      if( fract )
		{
		  fract--;
		  value *= pow( (double)base, -1 * fract );
		}
	      dest =  (neg) ? value * -1 : value;
	      return( true );
	    }
	}
    }
        
  if( fract )
    {
      fract--;
      value *= pow( (double)base, -1 * fract );
    }
  
  dest =  (neg) ? value * -1 : value;
  return( true );
}
コード例 #16
0
void SENSORCOMMUNICATION_Tasks ( void )
{
    int roverSimCounter = 0;
	while(1)
	{
		//check if queue exists
		if(sensorcommunicationData.sensortheQueue != 0)	
		{
               
			//receive a message and store into rxMessage ... block 5 ticks if empty queue
			if(xQueuePeek(sensorcommunicationData.sensortheQueue, (void*)&(sensorcommunicationData.rxMessage), portMAX_DELAY ))
			{
				xQueueReceive(sensorcommunicationData.sensortheQueue, (void*)&(sensorcommunicationData.rxMessage), portMAX_DELAY);
				//received messageQ message will tell use the state which will be used
				sensorcommunicationData.state = sensorcommunicationData.rxMessage.type;
				//communicationData.state = 1;
				
				//run the state according to the message's state
				switch ( sensorcommunicationData.state )
				{
					/* Application's initial state. */
					case SENSORCOMMUNICATION_STATE_INIT:	//0
						break;

					case SENSORCOMMUNICATION_STATE_RECEIVE:	//1
						//debugU("COM rx: ");
						//debugUInt(communicationData.rxMessage.msg);
						if(sensorcommunicationData.rxMessage.msg == STARTBYTE)	//received start transmit bit
						{
							if(sensorcommunicationData.sensorrxByteCount > 0)	//we had part of a previous message...
							{
								debugU("NACK");
								//NACK;
							}
							sensorcommunicationData.sensorrxBuffer[0] = sensorcommunicationData.rxMessage.msg;
							sensorcommunicationData.sensorrxByteCount = 1;	
						}
						else if( sensorcommunicationData.sensorrxByteCount > 0)	//continuing message
						{
							sensorcommunicationData.sensorrxBuffer[sensorcommunicationData.sensorrxByteCount] = sensorcommunicationData.rxMessage.msg;
                            debugUInt(CharToInt(sensorcommunicationData.rxMessage.msg));
							sensorcommunicationData.sensorrxByteCount++;
							if(sensorcommunicationData.sensorrxByteCount == 10)
							{
								//check start byte
								if(sensorcommunicationData.sensorrxBuffer[0] == STARTBYTE)
								{
									//###CHECK seq number
									int i = 0;
									while(sensorcommunicationData.sensorrxBuffer[1] != sensorcommunicationData.sensorRxMsgSeq)
									{
										sensorcommunicationData.sensorRxMsgSeq++;
                                        sensorcommunicationData.msgErr++;
										debugU("Lost a seq number\r # dropped: ");
                                        debugUInt(sensorcommunicationData.msgErr);
										i++;
										if(i == 10)
										{
											crash("E: COM too many lost rx seqnum\n");
										}
									}
									int x = 0;
									x += CharToInt(sensorcommunicationData.sensorrxBuffer[2]) * 1000;
									x += CharToInt(sensorcommunicationData.sensorrxBuffer[3]) * 100;
									x += CharToInt(sensorcommunicationData.sensorrxBuffer[4]) * 10;
									x += CharToInt(sensorcommunicationData.sensorrxBuffer[5]);
									int y = 0;
									y += CharToInt(sensorcommunicationData.sensorrxBuffer[6]) * 1000;
									y += CharToInt(sensorcommunicationData.sensorrxBuffer[7]) * 100;
									y += CharToInt(sensorcommunicationData.sensorrxBuffer[8]) * 10;
									y += CharToInt(sensorcommunicationData.sensorrxBuffer[9]);

                                    if (x != 0 && y != 0)
                                    {
                                        roverLocation[0] = x;
                                        roverLocation[1] = y;
                                    }
                                    
                                    communication_sendIntMsg(0, 1000);
                                    
//                                    else if (roverSimCounter < 11)
//                                        communication_sendIntMsg(1, 1);
//                                    else if (roverSimCounter == 2)
//                                        communication_sendIntMsg(1, 10);
//                                    else if (roverSimCounter == 3)
//                                        communication_sendIntMsg(3, 1);
//                                    else if (roverSimCounter == 4)
//                                        communication_sendIntMsg(1, 6);
//                                    else if (roverSimCounter == 5)
//                                        communication_sendIntMsg(3, 1);
//                                    else if (roverSimCounter == 6)
//                                        communication_sendIntMsg(1, 10);
//                                    else if (roverSimCounter == 7)
//                                        communication_sendIntMsg(3, 1);
//                                    else if (roverSimCounter == 8)
//                                        communication_sendIntMsg(1, 4);
//                                        
//                                    else // Tel the rover to not do anything...
//                                        communication_sendIntMsg(0, 0);
                                    roverSimCounter++;
                                    
                                    debugUInt(roverSimCounter);
                                    debugU("sensor msg period: ");
                                    debugUInt(sensor_debugGetTime());
                                    
									debugU("Sensor1: ");
									//char msg[12];
									//sprintf(msg, "%d", x);
									//debugU(msg);
                                    debugUInt(roverLocation[0]);
									debugU("Sensor2: ");
									//sprintf(msg, "%d", y);
									//debugU(msg);
                                    debugUInt(roverLocation[1]);
                                    
                                    debugU("\n");
                                    
                                    //communication_sendIntMsg(x,y);
                                    
									sensorcommunicationData.sensorrxByteCount = 0;
									sensorcommunicationData.sensorRxMsgSeq++;
									if(sensorcommunicationData.sensorRxMsgSeq == 0x7F)
                                        sensorcommunicationData.sensorRxMsgSeq = 0x00;
									//ACK
									//debugU("\nsensor comm ACK\n");
//#ifdef TEST
//                                    testData.count++; // Increment message count
//                                    int j =0;
//                                    for (j; j<10; j++)
//                                    {
//                                        testData.sensorrxBuffer[j] = sensorcommunicationData.sensorrxBuffer[j];
//                                    }
//                                    // Receive buffer contents recorded.
//                                    
//                                    communication_sendIntMsg(x, y);
//#else
//                                    if(sensorcommunicationData.sensorRxMsgSeq % 4 == 0)
//                                        communication_sendIntMsg(3, 100);
//                                    else if(sensorcommunicationData.sensorRxMsgSeq % 4 == 2)
//                                        communication_sendIntMsg(2, 100);
//#endif
                                    sensorcommunicationData.state = 0;
								}//end if check start byte
							}//end if bytecount == 10
						}//end if bytecount > 0
						else	//failed to receive start bit and catch all... nack and reset message
						{
							//NACK
							debugU("\nsensor NACK");
							sensorcommunicationData.sensorrxByteCount = 0;	//no start byte and bytecount != 0, so unknown char drop it
						}
						break;

					/* The default state should never be executed. */
					default:
					{
						/* TODO: Handle error in application's state machine. */
						break;
					}
				}//end of case
			}//end of receive message
		}//end of check message queue != 0
		else	//attempt to create the queue again if it doesn't exist
		{
			//something terrible happens normally so have it exit rather than recreate
			crash("E: No Comm Q");
			//run exit interrupt to OS... or forever loop message
			return;
			//communicationData.sensortheQueue = xQueueCreate(10, sizeof(APP_STATES));
		}
	}//end of while(1)
}
コード例 #17
0
ファイル: stlvariables.cpp プロジェクト: dmpas/cbp2make
int CCharVariable::GetInteger(void) const
{
 return CharToInt(m_Value);
}
コード例 #18
0
ファイル: MoonScene.cpp プロジェクト: wenqvip/MoonGame
bool MoonScene::Initialize(D3DCAPS9* d3dCaps, const char* scenename)
{
	_device = NULL;
	_d3dCaps = d3dCaps;
	//检查场景配置文件是否存在
	string scnpath(SCENE_DIR(scenename));
	scnpath += ".scn";
	if(!PathFileExists(scnpath.c_str()))
	{
		LogError("MoonScene::Initialize() Cannot find scene configure file!");
		::MessageBox(0,"Cannot find scene configure file, please check bin/start.cfg.",0,0);
		return false;
	}

	char ch[256];
	string temp;
	char c[5];
	//读取场景配置信息
	GetPrivateProfileString("configure","bRenderCollisionBox","false",ch,256,scnpath.c_str());
	temp = ch;
	if(temp == "true")
		_CollisionTS = new MoonCollision(true);
	else
		_CollisionTS = new MoonCollision();

	//初始化摄像机
	_ThirdCamera = new MoonCamera(MoonCamera::RPG);
	_ThirdCamera->setPosition(&D3DXVECTOR3(0.0f, 0.0f, 0.0f));
	_ThirdCamera->setLook(&D3DXVECTOR3(0.0f, 0.0f, 1.0f));
	LogInfo("MoonScene::Initialize() Initialize CameraOnPlayer OK!");
	_FirstCamera = new MoonCamera(MoonCamera::LANDOBJECT);
	_FirstCamera->setPosition(&D3DXVECTOR3(0.0f, 150.0f, 0.0f));
	_FirstCamera->setLook(&D3DXVECTOR3(0.0f, 0.0f, 1.0f));
	LogInfo("MoonScene::Initialize() Initialize FreeCamera OK!");
	_Camera = _ThirdCamera;

	//读取地形和天空的配置名称
	GetPrivateProfileString("environment","terrain",NULL,ch,256,scnpath.c_str());
	_terrainname = ch;
	GetPrivateProfileString("environment","skybox",NULL,ch,256,scnpath.c_str());
	_skyboxname = ch;

	//读取环境光照参数
	D3DXVECTOR3 v;
	GetPrivateProfileString("environmentlight","range",NULL,ch,256,scnpath.c_str());
	_environmentLight.Range=CharToFloat(ch);
	GetPrivateProfileString("environmentlight","diffuse",NULL,ch,256,scnpath.c_str());
	v = CharToVector3(ch);
	_environmentLight.Diffuse.r=v.x;
	_environmentLight.Diffuse.b=v.y;
	_environmentLight.Diffuse.g=v.z;
	GetPrivateProfileString("environmentlight","ambient",NULL,ch,256,scnpath.c_str());
	v = CharToVector3(ch);
	_environmentLight.Ambient.r=v.x;
	_environmentLight.Ambient.b=v.y;
	_environmentLight.Ambient.g=v.z;
	GetPrivateProfileString("environmentlight","specular",NULL,ch,256,scnpath.c_str());
	v = CharToVector3(ch);
	_environmentLight.Specular.r=v.x;
	_environmentLight.Specular.b=v.y;
	_environmentLight.Specular.g=v.z;
	GetPrivateProfileString("environmentlight","direction",NULL,ch,256,scnpath.c_str());
	v = CharToVector3(ch);
	D3DXVec3Normalize((D3DXVECTOR3*)&(_environmentLight.Direction),&v);
	_environmentLight.Type = D3DLIGHT_DIRECTIONAL;

	GetPrivateProfileString("ambient","ambient",NULL,ch,256,scnpath.c_str());
	_ambient = CharToVector3(ch);

	//读取雾化参数
	GetPrivateProfileString("fog","fog",NULL,ch,256,scnpath.c_str());
	temp = ch;
	if(temp == "true")
	{
		_dwFog = TRUE;
		GetPrivateProfileString("fog","fogcolor",NULL,ch,256,scnpath.c_str());
		v = CharToVector3(ch);
		_dwFogColor = D3DCOLOR_XRGB((int)v.x,(int)v.y,(int)v.z);
		GetPrivateProfileString("fog","fogtablemode",NULL,ch,256,scnpath.c_str());
		temp = ch;
		float f;
		if(temp == "linear")
		{
			_dwFogTableMode = D3DFOG_LINEAR;
			GetPrivateProfileString("fog","fogstart",NULL,ch,256,scnpath.c_str());
			f = CharToFloat(ch);
			_dwFogStart = *(DWORD*)&f;
			GetPrivateProfileString("fog","fogend",NULL,ch,256,scnpath.c_str());
			f = CharToFloat(ch);
			_dwFogEnd = *(DWORD*)&f;
		}
		else
		{
			if(temp == "exp")
				_dwFogTableMode = D3DFOG_EXP;
			else if(temp == "exp2")
				_dwFogTableMode = D3DFOG_EXP2;
			GetPrivateProfileString("fog","fogdensity",NULL,ch,256,scnpath.c_str());
			f = CharToFloat(ch);
			_dwFogDensity = *(DWORD*)&f;
		}
	}
	else
	{
		_dwFog = FALSE;
	}

	//读取角色相关参数
	string strPlayerName;
	D3DXVECTOR3 PlayerPos;
	D3DXVECTOR3 PlayerDir;
	D3DXVECTOR3 PlayerScl;
	GetPrivateProfileString("player","player",NULL,ch,256,scnpath.c_str());
	strPlayerName = ch;
	GetPrivateProfileString("player","position",NULL,ch,256,scnpath.c_str());
	PlayerPos = CharToVector3(ch);
	GetPrivateProfileString("player","direction",NULL,ch,256,scnpath.c_str());
	PlayerDir = CharToVector3(ch);
	GetPrivateProfileString("player","scale",NULL,ch,256,scnpath.c_str());
	PlayerScl = CharToVector3(ch);
	_thePlayer = new MoonCharacter(_d3dCaps,strPlayerName.c_str(), _ID++ ,PlayerPos,PlayerDir, PlayerScl);
	LogInfo("MoonScene::Initialize() Create MoonCharacter OK!");
	ReadCollisionBox("player",scnpath.c_str(),_thePlayer);

	//读取地面物体参数
	_blockcount = 0;
	_pBlock = NULL;
	GetPrivateProfileString("block","blockcount","0",ch,256,scnpath.c_str());
	_blockcount = CharToInt(ch);
	if(_blockcount>0)
		_pBlock = new MoonBlock[_blockcount];
	string str="block";
	string blockname;
	D3DXVECTOR3 blockpos,blockscl,blockrot;
	for(int i = 0; i < _blockcount; i++)
	{
		sprintf_s(c,"%04d",i);
		str+=c;
		GetPrivateProfileString(str.c_str(),"name",NULL,ch,256,scnpath.c_str());
		blockname = ch;
		GetPrivateProfileString(str.c_str(),"pos",NULL,ch,256,scnpath.c_str());
		blockpos = CharToVector3(ch);
		GetPrivateProfileString(str.c_str(),"scl",NULL,ch,256,scnpath.c_str());
		blockscl = CharToVector3(ch);
		GetPrivateProfileString(str.c_str(),"rot",NULL,ch,256,scnpath.c_str());
		blockrot = CharToVector3(ch);
		(_pBlock[i]).Initialize(_d3dCaps,blockname.c_str(), _ID++ ,blockpos,blockrot,blockscl);
		LogInfo("MoonScene::Initialize() Create new MoonBlock, name: %s.",blockname.c_str());
		ReadCollisionBox(str.c_str(),scnpath.c_str(),&_pBlock[i]);
		str="block";
	}

	//是否下雨
	GetPrivateProfileString("rain","brainy","false",ch,256,scnpath.c_str());
	temp = ch;
	if(temp=="true")
		_pRain = new MoonRain();
	else
		_pRain = NULL;

	D3DXVECTOR3 vec1,vec2;
	//是否下雪
	GetPrivateProfileString("snow","bsnow","false",ch,256,scnpath.c_str());
	temp = ch;
	if(temp=="true")
	{
		GetPrivateProfileString("snow","boundingmin","(0,0,0)",ch,256,scnpath.c_str());
		vec1 = CharToVector3(ch);
		GetPrivateProfileString("snow","boundingmax","(1,1,1)",ch,256,scnpath.c_str());
		vec2 = CharToVector3(ch);
		GetPrivateProfileString("snow","size","0.5",ch,256,scnpath.c_str());
		float fsize = CharToFloat(ch);
		GetPrivateProfileString("snow","texture","snow.tga",ch,256,scnpath.c_str());
		_SnowTex = ch;
		GetPrivateProfileString("snow","numparticles","100",ch,256,scnpath.c_str());
		int num = CharToInt(ch);
		_SnowSystem = new MoonSnow(&BoundingBox(&vec1, &vec2), fsize, num);
	}
	else
		_SnowSystem = NULL;

	//是否绘制焰火
	GetPrivateProfileString("firework","bfirework","false",ch,256,scnpath.c_str());
	temp = ch;
	if(temp=="true")
	{
		GetPrivateProfileString("firework","position","(0,0,0)",ch,256,scnpath.c_str());
		vec1 = CharToVector3(ch);
		GetPrivateProfileString("firework","texture","fire.tga",ch,256,scnpath.c_str());
		_FireTex = ch;
		GetPrivateProfileString("firework","numparticles","100",ch,256,scnpath.c_str());
		int num = CharToInt(ch);
		_Firework = new MoonFirework(&vec1,num);
	}
	else
		_Firework = NULL;

	// 读取水体配置信息
	GetPrivateProfileString("water","water","false",ch,256,scnpath.c_str());
	temp = ch;
	if(temp == "true")
		_pWater = new MoonWater();
	else
		_pWater = NULL;
	if(_pWater)
	{
		GetPrivateProfileString("water","height","0",ch,256,scnpath.c_str());
		_WaterArg.push_back(CharToFloat(ch));
		GetPrivateProfileString("water","flx","0",ch,256,scnpath.c_str());
		_WaterArg.push_back(CharToFloat(ch));
		GetPrivateProfileString("water","flz","0",ch,256,scnpath.c_str());
		_WaterArg.push_back(CharToFloat(ch));
		GetPrivateProfileString("water","brx","0",ch,256,scnpath.c_str());
		_WaterArg.push_back(CharToFloat(ch));
		GetPrivateProfileString("water","brz","0",ch,256,scnpath.c_str());
		_WaterArg.push_back(CharToFloat(ch));
		GetPrivateProfileString("water","waveheight","0",ch,256,scnpath.c_str());
		_WaterArg.push_back(CharToFloat(ch));
		GetPrivateProfileString("water","flowspeedu","0",ch,256,scnpath.c_str());
		_WaterArg.push_back(CharToFloat(ch));
		GetPrivateProfileString("water","flowspeedv","0",ch,256,scnpath.c_str());
		_WaterArg.push_back(CharToFloat(ch));
	}

	_SoundManager = new MoonSoundManager();
	if(_SoundManager->Initialize())
		LogInfo("MoonScene::Initialize() SoundManager initialized OK!");

	return true;
}
コード例 #19
0
ファイル: TestApplication.c プロジェクト: hexanome/IF-VxWorks
int useTestApp()
{
    int sensor1;
    int sensor2;

    char buffer1[10];
    char buffer2[10];

    int nb1;
    int nb2;

    // Open sensor1.
    sensor1 = open("/sensor1", 0, 0);
    if (sensor1 < 0)
    {
        printf("\nCouldn't open sensor 1.\n");
        return ERROR;
    }

    printf("\nOpened sensor1.\n");

    // Open sensor2.
    sensor2 = open("/sensor2", 0, 0);
    if (sensor2 < 0)
    {
        printf("Couldn't open sensor 2.\n");
        return ERROR;
    }

    printf("Opened sensor2.\n\n");

    // Read the value from sensor1.
    nb1 = read(sensor1, buffer1, 10);
    if (nb1 >= 0)
    {
        printf("Resultat 1 :\n");

        // Id
        printf("Id: ");
        printf("%d\n", CharToInt(buffer1));

        // Time
        printf("Time: ");
        printf("%d\n", CharToLong(buffer1 + ID_SIZE));

        // Value
        printf("Value: ");
        printf("%d\n\n", CharToValue(buffer1 + ID_SIZE + TIME_SIZE));
    }
    else
    {
        printf("Nothing to read on sensor 1.\n\n");
    }

    // Read the value from sensor2.
    nb2 = read(sensor2, buffer2, 10);
    if (nb2 >= 0)
    {
        printf("Resultat 2 :\n");

        // Id
        printf("Id: ");
        printf("%d\n", CharToInt(buffer2));

        // Time
        printf("Time: ");
        printf("%d\n", CharToLong(buffer2 + ID_SIZE));

        // Value
        printf("Value: ");
        printf("%d\n\n", CharToValue(buffer2 + ID_SIZE + TIME_SIZE));
    }
    else
    {
        printf("Nothing to read on sensor 2.\n\n");
    }

    // Close sensor1.
    printf("Closing sensor1: %d\n", close(sensor1));

    // Close sensor2.
    printf("Closing sensor2: %d\n\n", close(sensor2));

    return OK;
}
コード例 #20
0
ファイル: EncryptFun.c プロジェクト: RingsC/UnionPay.special
int Encrypt_str_Encrypt (const char* szMacStr,char* szOutput)
{
	char szLogBuff [MAXCONTLEN] ;
	bzero (szLogBuff,sizeof(szLogBuff)) ;
	
	int fd = Encrypt_Socket_Open() ;
	if (fd==-1|| fd<0){
		bzero (szLogBuff,sizeof(szLogBuff)) ;
		sprintf (szLogBuff,"[%s-line:%d] Open the socket failed...",__FILE__,__LINE__) ;
		WriteLogFile (szLogBuff,__SYS_TYPE_LOGFILE_RAW__) ;
		Encrypt_Socket_Close(fd);
		return -1 ;
	}
	char szTmp [30] ;
	bzero (szTmp,sizeof(szTmp));	
	read_config_file ("./sysconfig.cfg","TIMEOUT_VAL",szTmp); 
	if (!strlen(szTmp))	
		sprintf (szTmp,"%d" ,3)  ;
	struct timeval tv;
	bzero (&tv ,sizeof(struct timeval)) ;
	tv.tv_sec = atoi (szTmp);	
	tv.tv_usec = atoi (szTmp);
	
	fd_set rset ,wset  ;
	FD_ZERO (&rset) ;
	FD_ZERO (&wset) ;
	
	//To set the readable and writable set .
	FD_SET (fd,&rset) ;
	FD_SET (fd,&wset) ;
	
	int iRet  = select (1024,NULL,&wset,NULL,&tv);
	if (iRet){
		//Here ,we will assemble the mac string,then send it.
		int ilen = strlen (szMacStr) ;	
		char sllen  [5] ;
		bzero (sllen,sizeof(sllen)) ;
		sprintf (sllen,"%d",ilen) ; //same as fj
		
		int ymod  = ilen % 256 ;
		ilen = ilen/ 256  ;
		char szSentMsg [MAXCONTLEN] ;
		bzero (szSentMsg,sizeof(szSentMsg)) ;
		char szReadMsg [MAXCONTLEN] ;	//To hold the response message .
		bzero (szReadMsg,sizeof(szReadMsg));
		
		sprintf (szSentMsg,"%x%x%s",ilen,ymod,szMacStr) ;		
		iRet  = write (fd,szSentMsg,strlen(szSentMsg)) ;
		if (iRet== strlen(szSentMsg)) {
			bzero (szLogBuff,sizeof(szLogBuff));
			sprintf (szLogBuff,"Send the request msg to Encrypt Successfully...") ;
			WriteLogFile (szLogBuff,__SYS_TYPE_LOGFILE_RAW__);
			WriteLogFileInHex_Ex (&szSentMsg,__SYS_TYPE_LOGFILE_RAW__) ;	
		} else{	//Can not send data totally.
			bzero (szLogBuff,sizeof(szLogBuff)) ;
			sprintf (szLogBuff,"[%s-line:%d] Send the request msg to Encrypt Failed,pls chck your system...",__FILE__,__LINE__) ;
			WriteLogFile (szLogBuff,__SYS_TYPE_LOGFILE_RAW__) ;
			WriteLogFileInHex_Ex (szSentMsg,__SYS_TYPE_LOGFILE_RAW__) ;
			Encrypt_Socket_Close(fd) ;
			strncpy (szOutput,"-1",2);
			return  -1 ;	
		}
		//Here , we will read the response msg from encryption mechine.
		iRet  = select (1024,&rset,NULL,NULL,&tv) ;
		if (iRet){
			if (FD_ISSET (fd,&rset)){
				iRet = read (fd,szReadMsg,2) ; //First 2 character are length of following
				if (iRet!=2){ //Can not read properlly.
				 	bzero (szLogBuff,sizeof(szLogBuff)) ;
					sprintf (szLogBuff,"[%s-line:%d] can not read length,pls chck your sys...",__FILE__,__LINE__) ;
					WriteLogFile (szLogBuff,__SYS_TYPE_LOGFILE_RAW__) ;
					WriteLogFileInHex_Ex (szLogBuff,__SYS_TYPE_LOGFILE_RAW__) ;
					strncpy (szOutput,"-1",sizeof("-1")) ; //The Value of executation.
					Encrypt_Socket_Close(fd) ;
					return -1; 
				}
				ilen = CharToInt(szReadMsg[0])*256+CharToInt(szReadMsg[1]) ;
				bzero (szReadMsg,sizeof(szReadMsg)) ;
				iRet = read (fd,szReadMsg,ilen);	
				if (iRet!= ilen) {
					bzero (szLogBuff,sizeof(szLogBuff)) ;
					sprintf (szLogBuff,"[%s-line:%d] Read The following data error,pls check your system...",__FILE__,__LINE__) ;
					
					WriteLogFile (szLogBuff,__SYS_TYPE_LOGFILE_RAW__) ;
					WriteLogFileInHex_Ex(szReadMsg,__SYS_TYPE_LOGFILE_RAW__) ;
					Encrypt_Socket_Close(fd) ;
					strncpy (szOutput,"-1",sizeof("-1")) ;
					return -1; 	
				}
				char sResCode  [3] ;
				bzero (sResCode,sizeof(sResCode)) ;//________________________
				strncpy (sResCode,szReadMsg+2,2) ;//|_0_|_1_|_2_|_3_|_4_|_5_|
				if (strcmp ("00",sResCode)==0){
					bzero (szLogBuff,sizeof(szLogBuff)) ;
					if (strlen(szReadMsg)==4) {
						sprintf (szLogBuff,"Send the reponse to server...") ;
						strncpy (szOutput,"0",1) ;
						WriteLogFile (szLogBuff,__SYS_TYPE_LOGFILE_RAW__) ;
					}else {
						sprintf (szLogBuff,"send the Response message to server...") ;
						strncpy (szOutput,szReadMsg+4,strlen(szReadMsg)-4) ;
						WriteLogFile (szLogBuff,__SYS_TYPE_LOGFILE_RAW__) ;
						WriteLogFile (szReadMsg+4,__SYS_TYPE_LOGFILE_RAW__) ;
					}
				}else{
					strncpy (szOutput,"-1",sizeof("-1"));
					Encrypt_Socket_Close(fd) ;
					return  -1 ;
				}	
			}
		}else if (iRet==-1){
			bzero (szLogBuff,sizeof(szLogBuff)) ;
			sprintf (szLogBuff,"[%s-line:%d] select() Exceptions occur,pls check your system...",__FILE__,__LINE__) ;
			WriteLogFile (szLogBuff,__SYS_TYPE_LOGFILE_RAW__);
			Encrypt_Socket_Close(fd);
			strncpy (szOutput,"-1",sizeof("-1"));
			return  -1; 
		}else{
			bzero (szLogBuff,sizeof(szLogBuff)) ;
			sprintf (szLogBuff,"[%s-line:%d] Timeout Exceptions occur,pls check your system...",__FILE__,__LINE__) ;
			WriteLogFile (szLogBuff,__SYS_TYPE_LOGFILE_RAW__);
			Encrypt_Socket_Close(fd);
			strncpy (szOutput,"-1",sizeof("-1")) ;
			return -1 ;
		}
	} else if (iRet==-1){
		bzero (szLogBuff,sizeof(szLogBuff)) ;
		sprintf (szLogBuff,"[%s-line:%d] Select() exceptions occur...",__FILE__,__LINE__);	
		WriteLogFile (szLogBuff,__SYS_TYPE_LOGFILE_RAW__);
		Encrypt_Socket_Close(fd)  ;
		strncpy (szOutput,"-1",sizeof("-1")) ;
		return -1 ;	
	} else {
		bzero (szLogBuff,sizeof(szLogBuff)) ;
		sprintf (szLogBuff,"[%s-line:%d] Select() timeout occur...",__FILE__,__LINE__);	
		WriteLogFile (szLogBuff,__SYS_TYPE_LOGFILE_RAW__);
		Encrypt_Socket_Close(fd)  ;
		strncpy (szOutput,"-1",sizeof("-1")) ;
		return -1 ;	
	}	
	
	return 0 ;
}
コード例 #21
0
ファイル: main.cpp プロジェクト: clscu/study_exercise
char *BigAdd2(char *str1,char *str2)
{
    int len1 = strlen(str1);
    int len2 = strlen(str2);
    int a,b;
    int c =0;
    int num =0;

    int max = len1;
    if(len2>max)
    {
        max = len2;
    }
    int temp = max;
    char *result = (char*)malloc(max+2);
    while(len1 >0 || len2 >0)
    {
        if(len1 >0)
        {
            if(len1 -4 >0)
            {
                a = CharToInt(str1,len1-4,len1-1);
                len1-=4;
            }
            else
            {
                a= CharToInt(str1,0,len1-1);
                len1-=4;
            }
        }
        else
        {
            a=0;
        }

        if(len2>0)
        {
            if(len2-4>0)
            {
                b = CharToInt(str2,len2-4,len2-1);
                len2-=4;
            }
            else
            {
                b= CharToInt(str2,0,len2-1);
                len2-=4;
            }
        }
        else
        {
            b=0;
        }
        num = a+b+c;
        if(num >=10000)
        {
            c=1;
        }
        else
        {
            c=0;
        }
        IntToChar(result,temp-3,temp,num);
        temp -=4;
    }

    *result = c+'0';
    //	temp --;

    *(result+max+1) = '\0';
    return result;
}
コード例 #22
0
ファイル: stlvariables.cpp プロジェクト: dmpas/cbp2make
void CIntegerVariable::SetChar(const char Value)
{
 m_Value = CharToInt(Value);
}