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