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


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

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


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

示例1: 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

示例2: update


//.........这里部分代码省略.........
						}
					}
					else if(type == Constants::DESTROY) {
					
						int id;
						pStream->readInt(id);

						mLevel->killEnemy(id);
					}
					else if(type == Constants::DESTROYPICKUP) {
					
						int id;
						pStream->readInt(id);

						mLevel->destroyPickup(id);
					}
					else if(type == Constants::CREATEPICKUP) {
					
						int type, x, y, id;
						pStream->readInt(type);
						pStream->readInt(id); // Clients sends -1
						pStream->readInt(x);
						pStream->readInt(y);

						mLevel->createPickup(type, x, y);

						if(mHost) {
							// Send create to peer
							// Send Id of created pickup
							PacketStream s;
							s.writeInt(Constants::CREATEPICKUP);
							s.writeInt(mLevel->getPickups().back()->getID());
							s.writeInt(type);
							s.writeFloat(x);
							s.writeFloat(y);
							s.writeChar('\0');

							char message[10];
							s.toCharArray(message);
							message[strlen(message)-1] = '\0';

							s3eSocketSendTo(mSock, message, strlen(message), 0, &mDest_addr);
						}
						else {
							// Set id of pickup if client if client
							mLevel->getPickups().back()->setID(id);
						}
					}
					else if(type == Constants::CREATECRATE) {
				
						int type, id;
						float x, y;
						//pStream->readInt(id);
						pStream->readInt(type);
						pStream->readFloat(x);
						pStream->readFloat(y);

						if(mHost) {
						
							mLevel->createCrate(type, x, y);
							crateSpawned = true;

							PacketStream s;
							s.writeInt(Constants::CREATECRATE);
							//s.writeInt(mLevel->getCrates().back()->getID());
							s.writeInt(type);
开发者ID:JamesBuggy,项目名称:Final-Year-Project,代码行数:67,代码来源:game.cpp


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