char *TextDisplayer::preprocessString(const char *str) { if (str != _talkBuffer) { assert(strlen(str) < sizeof(_talkBuffer) - 1); strcpy(_talkBuffer, str); } char *p = _talkBuffer; while (*p) { if (*p == '\r') { return _talkBuffer; } ++p; } p = _talkBuffer; Screen::FontId curFont = _screen->setFont(Screen::FID_8_FNT); _screen->_charWidth = -2; int textWidth = _screen->getTextWidth(p); _screen->_charWidth = 0; if (textWidth > 176) { if (textWidth > 352) { int count = getCharLength(p, textWidth / 3); int offs = dropCRIntoString(p, count); p += count + offs; _screen->_charWidth = -2; textWidth = _screen->getTextWidth(p); _screen->_charWidth = 0; count = getCharLength(p, textWidth / 2); dropCRIntoString(p, count); } else { int count = getCharLength(p, textWidth / 2); dropCRIntoString(p, count); } } _screen->setFont(curFont); return _talkBuffer; }
/** Constructor, takes the name of the kart name and the host id. * \param kart_name Name of the kart. * \param host_id Id of the host who selected this character. */ CharacterConfirmMessage(const std::string &kart_name, int host_id) : Message(Message::MT_CHARACTER_CONFIRM) { allocate(getStringLength(kart_name) + getCharLength()); addString(kart_name); addChar(host_id); } // CharacterConfirmMessage
/** Contains information about a selected kart. When send from the client * to the server, it contains the number of local players (which * technically needs only to be sent once); when send from from the server * to the clients this field instead contains the host id of the host * selected the character. This allows the client to detect if a selected * kart was not confirmed by the server (i.e. another client or the server * has selected the kart first * \param player_id The local player id. * \param host_id If this value is specified (>-1), then this value is * used in the message instead of the number of local * players. */ CharacterSelectedMessage(int player_id, int host_id=-1) : Message(Message::MT_CHARACTER_INFO) { m_kart_info = race_manager->getLocalKartInfo(player_id); m_num_local_players = race_manager->getNumLocalPlayers(); allocate(getCharLength() // m_kart_info.getLocalPlayerId()) +getStringLength(m_kart_info.getKartName()) +m_kart_info.getPlayerName().size() + 1 // FIXME: encoding issues +getCharLength()); // m_num_local_players) addChar(m_kart_info.getLocalPlayerId()); addString(m_kart_info.getKartName()); addString(core::stringc(m_kart_info.getPlayerName().c_str()).c_str()); // FIXME: encoding issues // Piggy backing this information saves sending it as a separate // message. It is actually only required in the first message if(host_id>-1) addChar(host_id); else addChar(race_manager->getNumLocalPlayers()); } // CharacterSelectedMessage
/** Creates a message containing the finishing time and rank of each kart. * This message is serialised so that it can be sent. */ RaceResultMessage::RaceResultMessage() : Message(MT_RACE_RESULT) { World *world = World::getWorld(); const unsigned int num_karts = world->getNumKarts(); allocate(num_karts * (getFloatLength()+getCharLength())); for(unsigned int i=0; i<num_karts; i++) { const AbstractKart *kart = world->getKart(i); addFloat(kart->getFinishTime()); addChar(kart->getPosition()); } // for i in karts } // RaceResultMessage
KartUpdateMessage::KartUpdateMessage() : Message(Message::MT_KART_INFO) { World *world = World::getWorld(); unsigned int num_karts = world->getNumKarts(); // Send the number of karts and for each kart the compressed // control structure (3 ints) and xyz,hpr (4 floats: quaternion: allocate(getCharLength()+ num_karts*(KartControl::getLength() + getVec3Length() +getQuaternionLength()) ); addChar(num_karts); for(unsigned int i=0; i<num_karts; i++) { const Kart* kart = world->getKart(i); const KartControl& kc=kart->getControls(); kc.serialise(this); addVec3(kart->getXYZ()); addQuaternion(kart->getRotation()); } // for i } // KartUpdateMessage
/** Constructor, creates an empty message */ RaceResultAckMessage(char menu_choice) : Message(Message::MT_RACE_RESULT_ACK) { allocate(getCharLength()); addChar(menu_choice); } // RaceResultAckMessage