//----------------------------------------------------------------------------- // child bool TestRPCRacesChild::RecvStart() { puts("Test 1"); if (!SendStartRace()) fail("problem sending StartRace()"); bool dontcare; if (!CallRace(&dontcare)) fail("problem calling Race()"); mHasReply = true; return true; }
void TestRaceDeferralParent::Test1() { if (!SendStartRace()) fail("sending StartRace"); if (!CallWin()) fail("calling Win"); if (mProcessedLose) fail("Lose didn't lose"); if (!CallRpc()) fail("calling Rpc"); if (!mProcessedLose) fail("didn't resolve Rpc vs. Lose 'race' correctly"); }
void Game::RecieveData() { //********************* recieve data ******************************** // create a packet stream object for recieving and sending data PacketStream PS; // now we want to recieve any data char recieved[100] = "n"; // set to "n" as a flag that it is unpopulated Net::GetInstance()->ReceiveData(recieved); // if the array has been populated if(recieved[0] != 'n') { // if we recieve any valid data and connectedToPeer is false if(!m_connectedToPeer) { /// we are now connected to a peer m_connectedToPeer = true; SendStartRace(); } PS.fromCharArray(recieved); int e; PS.readInt(e); while(e != ENDOFMESSAGE) { switch (e) { case STATEDATA: { float x = m_pOtherCar->X(); float y = m_pOtherCar->Y(); float angle = m_pOtherCar->GetAngleY(); float directionX = m_pOtherCar->DirectionX(); float directionY = m_pOtherCar->DirectionY(); float topSpeed = m_pOtherCar->TopSpeed(); float speed = m_pOtherCar->Speed(); float friction = m_pOtherCar->Friction(); PS.readFloat(x); PS.readFloat(y); PS.readFloat(angle); PS.readFloat(directionX); PS.readFloat(directionY); PS.readFloat(topSpeed); PS.readFloat(speed); PS.readFloat(friction); if(m_packetTransferState == CONSTANT) { m_pOtherCar->SetX(x); m_pOtherCar->SetY(y); m_pOtherCar->SetAngleY(angle); } else { // set this first so we can determine if the car should accelerate m_otherCarLastSpeed = m_pOtherCar->Speed(); // set positional data of other car // we want a smooth movement to the new point Vector2 newPos(x,y); // get the vector between the new pos and old pos Vector2 vector = newPos-m_pOtherCar->Position(); // if we are a good bit away then snap if(vector.Length() > 20) { m_pOtherCar->SetX(x); m_pOtherCar->SetY(y); } else if(vector.Length() > 2) { // normalise to find the direction vector.Normalise(); directionX = vector.X; directionY = vector.Y; } m_pOtherCar->SetAngleY(angle); m_pOtherCar->SetDirectionX(directionX); m_pOtherCar->SetDirectionY(directionY); m_pOtherCar->SetTopSpeed(topSpeed); m_pOtherCar->SetSpeed(speed); m_pOtherCar->SetFriction(friction); } } break; case FINISHEDRACE: { // the race is over m_raceFinished = true; // if the host recieved this message then they are not the winner if(m_host) { m_hostWon = false; } else { m_hostWon = true; } } break; case STARTRACE: { if(m_host) { m_pMyCar->SetX(m_hostCarStartPosX); m_pMyCar->SetY(m_hostCarStartPosY); m_pOtherCar->SetX(m_joinCarStartPosX); m_pOtherCar->SetY(m_joinCarStartPosY); } else { m_pMyCar->SetX(m_joinCarStartPosX); m_pMyCar->SetY(m_joinCarStartPosY); m_pOtherCar->SetX(m_hostCarStartPosX); m_pOtherCar->SetY(m_hostCarStartPosY); } m_raceStarted = true; } break; } PS.readInt(e); } m_lastPacketRecieveTime = GetTickCount(); } // if we recieved an empty packet the we have reached a timeout else if(GetTickCount() - m_lastPacketRecieveTime > CONNECTION_TIMEOUT) { // then we assume that we are no longer connected to the peer m_connectedToPeer = false; m_raceStarted = false; } //******************************************************************* }