本文整理汇总了C++中NetworkString::af方法的典型用法代码示例。如果您正苦于以下问题:C++ NetworkString::af方法的具体用法?C++ NetworkString::af怎么用?C++ NetworkString::af使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NetworkString
的用法示例。
在下文中一共展示了NetworkString::af方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: update
void KartUpdateProtocol::update()
{
if (!World::getWorld())
return;
static double time = 0;
double current_time = StkTime::getRealTime();
if (current_time > time + 0.1) // 10 updates per second
{
time = current_time;
if (m_listener->isServer())
{
NetworkString ns;
ns.af( World::getWorld()->getTime());
for (unsigned int i = 0; i < m_karts.size(); i++)
{
AbstractKart* kart = m_karts[i];
Vec3 v = kart->getXYZ();
btQuaternion quat = kart->getRotation();
ns.ai32( kart->getWorldKartId());
ns.af(v[0]).af(v[1]).af(v[2]); // add position
ns.af(quat.x()).af(quat.y()).af(quat.z()).af(quat.w()); // add rotation
Log::verbose("KartUpdateProtocol", "Sending %d's positions %f %f %f", kart->getWorldKartId(), v[0], v[1], v[2]);
}
m_listener->sendMessage(this, ns, false);
}
else
{
AbstractKart* kart = m_karts[m_self_kart_index];
Vec3 v = kart->getXYZ();
btQuaternion quat = kart->getRotation();
NetworkString ns;
ns.af( World::getWorld()->getTime());
ns.ai32( kart->getWorldKartId());
ns.af(v[0]).af(v[1]).af(v[2]); // add position
ns.af(quat.x()).af(quat.y()).af(quat.z()).af(quat.w()); // add rotation
Log::verbose("KartUpdateProtocol", "Sending %d's positions %f %f %f", kart->getWorldKartId(), v[0], v[1], v[2]);
m_listener->sendMessage(this, ns, false);
}
}
switch(pthread_mutex_trylock(&m_positions_updates_mutex))
{
case 0: /* if we got the lock */
while (!m_next_positions.empty())
{
uint32_t id = m_karts_ids.back();
if (id != m_self_kart_index || m_listener->isServer()) // server takes all updates
{
Vec3 pos = m_next_positions.back();
btTransform transform = m_karts[id]->getBody()->getInterpolationWorldTransform();
transform.setOrigin(pos);
transform.setRotation(m_next_quaternions.back());
m_karts[id]->getBody()->setCenterOfMassTransform(transform);
//m_karts[id]->getBody()->setLinearVelocity(Vec3(0,0,0));
Log::verbose("KartUpdateProtocol", "Update kart %i pos to %f %f %f", id, pos[0], pos[1], pos[2]);
}
m_next_positions.pop_back();
m_next_quaternions.pop_back();
m_karts_ids.pop_back();
}
pthread_mutex_unlock(&m_positions_updates_mutex);
break;
default:
break;
}
}