本文整理汇总了C++中PacketStream::writeChar方法的典型用法代码示例。如果您正苦于以下问题:C++ PacketStream::writeChar方法的具体用法?C++ PacketStream::writeChar怎么用?C++ PacketStream::writeChar使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类PacketStream
的用法示例。
在下文中一共展示了PacketStream::writeChar方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: 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);
//.........这里部分代码省略.........