bool KartUpdateProtocol::notifyEventAsynchronous(Event* event) { if (event->type != EVENT_TYPE_MESSAGE) return true; NetworkString ns = event->data(); if (ns.size() < 36) { Log::info("KartUpdateProtocol", "Message too short."); return true; } ns.removeFront(4); while(ns.size() >= 16) { uint32_t kart_id = ns.getUInt32(0); float a,b,c; a = ns.getFloat(4); b = ns.getFloat(8); c = ns.getFloat(12); float d,e,f,g; d = ns.getFloat(16); e = ns.getFloat(20); f = ns.getFloat(24); g = ns.getFloat(28); pthread_mutex_trylock(&m_positions_updates_mutex); m_next_positions.push_back(Vec3(a,b,c)); m_next_quaternions.push_back(btQuaternion(d,e,f,g)); m_karts_ids.push_back(kart_id); pthread_mutex_unlock(&m_positions_updates_mutex); ns.removeFront(32); } return true; }
/** This function is called on a client when it receives a kartFinishedRace * event from the server. It updates the game with this information. * \param ns The message from the server. */ void GameEventsProtocol::kartFinishedRace(const NetworkString &ns) { if (ns.size() < 5) { Log::warn("GameEventsProtocol", "kartFinisheRace: Too short message."); return; } uint8_t kart_id = ns.getUInt8(); float time = ns.getFloat(); if (race_manager->modeHasLaps()) { World::getWorld()->getKart(kart_id) ->setPosition(m_last_finished_position++); } World::getWorld()->getKart(kart_id)->finishedRace(time, /*from_server*/true); } // kartFinishedRace