当前位置: 首页>>代码示例>>C++>>正文


C++ PacketStream::writeInt方法代码示例

本文整理汇总了C++中PacketStream::writeInt方法的典型用法代码示例。如果您正苦于以下问题:C++ PacketStream::writeInt方法的具体用法?C++ PacketStream::writeInt怎么用?C++ PacketStream::writeInt使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在PacketStream的用法示例。


在下文中一共展示了PacketStream::writeInt方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: SendFinishRace

void Game::SendFinishRace()
{
	PacketStream PS;

	ENUM_Event e = FINISHEDRACE;
	PS.writeInt(e);

	e = ENDOFMESSAGE;
	PS.writeInt(e);

	// get the data from the stream
	char data[100];
	PS.toCharArray(data);

	// send the data
	Net::GetInstance()->SendData(data,"127.0.0.1",m_sendToPort);

	// increment num packets sent
	m_numPacketsSent++;

	m_raceFinished = true;
	if(m_host)
	{
		m_hostWon = true;
	}
	else
	{
		m_hostWon = false;
	}
}
开发者ID:jeromebyrne,项目名称:college_PeerToPeerRace,代码行数:30,代码来源:Game.cpp

示例2: SendStartRace

void Game::SendStartRace()
{
	PacketStream PS;

	ENUM_Event e = STARTRACE;
	PS.writeInt(e);

	e = ENDOFMESSAGE;
	PS.writeInt(e);

	// get the data from the stream
	char data[100];
	PS.toCharArray(data);

	// send the data
	Net::GetInstance()->SendData(data,"127.0.0.1",m_sendToPort);

	// increment num packets sent
	m_numPacketsSent++;

}
开发者ID:jeromebyrne,项目名称:college_PeerToPeerRace,代码行数:21,代码来源:Game.cpp

示例3: SendMyCarData

void Game::SendMyCarData()
{
			PacketStream PS;
			//===================== send data ==================================
			ENUM_Event e = STATEDATA;
			PS.writeInt(e);

			// write the xy values to the stream
			PS.writeFloat(m_pMyCar->X());
			PS.writeFloat(m_pMyCar->Y());

			// write the angle of rotation to the stream
			PS.writeFloat(m_pMyCar->GetAngleY());

			// write the direction and topspeed variables to the stream
			PS.writeFloat(m_pMyCar->DirectionX());
			PS.writeFloat(m_pMyCar->DirectionY());
			PS.writeFloat(m_pMyCar->TopSpeed());
			PS.writeFloat(m_pMyCar->Speed());
			PS.writeFloat(m_pMyCar->Friction());

			e = ENDOFMESSAGE;
			PS.writeInt(e);

			// get the data from the stream
			char data[100];
			PS.toCharArray(data);

			// send the data
			Net::GetInstance()->SendData(data,"127.0.0.1",m_sendToPort);

			// update the time of the packet sent - for interpolate
			m_lastPacketSentTime = GetTickCount();

			// increment the number of packets sent
			m_numPacketsSent++;

			//===================================================================
}
开发者ID:jeromebyrne,项目名称:college_PeerToPeerRace,代码行数:39,代码来源:Game.cpp

示例4: update

/**
* Game update function
* @param pStream the packet stream to write state data to (if playing multiplayer)
*/
void Game::update(PacketStream* pStream) {

	//cout << "update" << endl;

	// timer
	g_timeNow = s3eTimerGetMs();
	g_deltaTime = float( (g_timeNow - g_prevTime) * 0.001 );
	// Time since last packet was sent
	timeSinceLastSend += g_timeNow - g_prevTime;
	g_prevTime = g_timeNow;

	if(mStage == Constants::INGAME) {

		for(int i = 0; i < bufferSize; i++) {
	
			mMessageReceived[i] = 0;
			mMessageSent[i] = 0;
		}

		if(mPlayer->getHealth() <= 0) {
			mPlayer->loadCheckpoint = true;
			mPlayer->mPos = CIwSVec2(mCheckpoint.x, mCheckpoint.y);

			// Create respawn effect
			CIwSVec2 screenCentre = CIwSVec2((int16)Iw2DGetSurfaceWidth() >> 1, (int16)Iw2DGetSurfaceHeight() >> 1);
			CIwSVec2 pos = screenCentre + (CIwSVec2(int16(mCheckpoint.x*8), -int16(mCheckpoint.y*8)));

			createEffect(CIwSVec2(pos.x, pos.y), 10, "Images/respawn.png", 1.0f);
		}

		if(mSpawnPickup == true) {
		
			mLevel->createPickup(mPickupSpawnType, mPickupSpawnPoint.x, mPickupSpawnPoint.y);
			mSpawnPickup = false;
		}

		if(!mPaused) {
			mTimeTaken += g_deltaTime;
		}

		// Sync clients if multiplayer
		if(mMultiplayer) {

			// Packet rate modification
			if(timeSinceLastSend >= 1000/30) {

				pStream->writeInt(Constants::UPDATE);

				// Dead reckoning
				if( abs(mDRPlayer->getBody()->GetPosition().Length() - mPlayer->getBody()->GetPosition().Length()) >= 1 ) {

					pStream->writeInt(Constants::DRUPDATE);
					mPlayer->serialize(pStream);
					mRDXVel = mPlayer->getBody()->GetLinearVelocity().x;

					mDRPlayer->getBody()->SetTransform(mPlayer->getBody()->GetPosition(), 0.0f);
					mDRPlayer->getBody()->SetLinearVelocity(b2Vec2(mRDXVel, mPlayer->getBody()->GetLinearVelocity().y));
				}
				else {
					pStream->writeInt(Constants::UPDATE);
				}

				if(mHost) {
					// Serialize level
					mLevel->serialize(pStream);
				}

				pStream->writeChar('\0');
				pStream->toCharArray(mMessageSent);
				mMessageSent[strlen(mMessageSent)-1] = '\0';

				//cout << "SENDING: " << mMessageSent << endl;
				// Send data
				s3eSocketSendTo(mSock, mMessageSent, strlen(mMessageSent), 0, &mDest_addr);

				timeSinceLastSend = 0;
			}

			// Recieve data
			mBytesRecieved = s3eSocketRecvFrom(mSock, mMessageReceived, sizeof(mMessageReceived), 0, &mDest_addr);
		

			if(mBytesRecieved != -1) {
				cout << "RECIEVING: " << mMessageReceived << endl;
				pStream->fromCharArray(mMessageReceived);

				int type;
				pStream->readInt(type);

				while (type) {
					cout << "checking message types" << endl;
					if(type == Constants::UPDATE) {

						int updateType;
						pStream->readInt(updateType);

//.........这里部分代码省略.........
开发者ID:JamesBuggy,项目名称:Final-Year-Project,代码行数:101,代码来源:game.cpp


注:本文中的PacketStream::writeInt方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。