forgottent commit on former computer
git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/hilnius@13531 178a84e3-b1eb-0310-8ba1-8eac791a3b58
This commit is contained in:
parent
98f3b20bcb
commit
e3261775e3
Binary file not shown.
@ -21,6 +21,7 @@
|
||||
#include "items/powerup_manager.hpp"
|
||||
#include "karts/abstract_kart.hpp"
|
||||
#include "karts/controller/controller.hpp"
|
||||
#include "network/network_manager.hpp"œ
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
StandardRace::StandardRace() : LinearWorld()
|
||||
@ -123,5 +124,6 @@ void StandardRace::endRaceEarly()
|
||||
} // Finish the active players
|
||||
endSetKartPositions();
|
||||
setPhase(RESULT_DISPLAY_PHASE);
|
||||
terminateRace();
|
||||
if (!isNetworkWorld() || NetworkManager::getInstance()->isServer())
|
||||
terminateRace();
|
||||
} // endRaceEarly
|
||||
|
@ -117,6 +117,7 @@ World::World() : WorldStatus(), m_clear_color(255,100,101,140)
|
||||
m_schedule_exit_race = false;
|
||||
m_self_destruct = false;
|
||||
m_schedule_tutorial = false;
|
||||
m_is_network_world = false;
|
||||
|
||||
m_stop_music_when_dialog_open = true;
|
||||
|
||||
@ -946,7 +947,9 @@ void World::updateHighscores(int* best_highscore_rank, int* best_finish_time,
|
||||
|
||||
PlayerController *controller = (PlayerController*)(k->getController());
|
||||
|
||||
int highscore_rank = highscores->addData(k->getIdent(),
|
||||
int highscore_rank = 0;
|
||||
if (controller->getPlayer()->getProfile() != NULL) // if we have the player profile here
|
||||
highscore_rank = highscores->addData(k->getIdent(),
|
||||
controller->getPlayer()->getProfile()->getName(),
|
||||
k->getFinishTime());
|
||||
|
||||
|
@ -152,6 +152,9 @@ protected:
|
||||
*/
|
||||
bool m_self_destruct;
|
||||
|
||||
/** Set when the world is online and counts network players. */
|
||||
bool m_is_network_world;
|
||||
|
||||
virtual void onGo();
|
||||
/** Returns true if the race is over. Must be defined by all modes. */
|
||||
virtual bool isRaceOver() = 0;
|
||||
@ -197,7 +200,7 @@ public:
|
||||
* this method in child classes to provide it. */
|
||||
virtual const std::string& getIdent() const = 0;
|
||||
// ------------------------------------------------------------------------
|
||||
/** Returns the number of rescue positions on a given track and game
|
||||
/** Returns the number of rescue positions on a given track and game
|
||||
* mode. */
|
||||
virtual unsigned int getNumberOfRescuePositions() const OVERRIDE = 0;
|
||||
// ------------------------------------------------------------------------
|
||||
@ -327,6 +330,10 @@ public:
|
||||
// ------------------------------------------------------------------------
|
||||
virtual void escapePressed();
|
||||
|
||||
/** Set the network mode (true if networked) */
|
||||
void setNetworkWorld(bool is_networked) { m_is_network_world = is_networked; }
|
||||
|
||||
bool isNetworkWorld() const { return m_is_network_world; }
|
||||
}; // World
|
||||
|
||||
#endif
|
||||
|
@ -32,6 +32,7 @@ void NetworkWorld::update(float dt)
|
||||
{
|
||||
return;
|
||||
}
|
||||
World::getWorld()->setNetworkWorld(true);
|
||||
}
|
||||
World::getWorld()->updateWorld(dt);
|
||||
if (World::getWorld()->getPhase() >= WorldStatus::RESULT_DISPLAY_PHASE) // means it's the end
|
||||
@ -42,11 +43,22 @@ void NetworkWorld::update(float dt)
|
||||
}
|
||||
}
|
||||
|
||||
void NetworkWorld::start()
|
||||
{
|
||||
m_running = true;
|
||||
}
|
||||
|
||||
void NetworkWorld::stop()
|
||||
{
|
||||
m_running = false;
|
||||
World::getWorld()->setNetworkWorld(false);
|
||||
}
|
||||
|
||||
bool NetworkWorld::isRaceOver()
|
||||
{
|
||||
if (!World::getWorld())
|
||||
return false;
|
||||
return (World::getWorld()->getPhase() >= WorldStatus::RESULT_DISPLAY_PHASE);
|
||||
return (World::getWorld()->getPhase() > WorldStatus::RACE_PHASE);
|
||||
}
|
||||
|
||||
void NetworkWorld::collectedItem(Item *item, AbstractKart *kart)
|
||||
|
@ -19,8 +19,8 @@ class NetworkWorld : public Singleton<NetworkWorld>
|
||||
public:
|
||||
void update(float dt);
|
||||
|
||||
void start() { m_running = true; }
|
||||
void stop() { m_running = false; }
|
||||
void start();
|
||||
void stop();
|
||||
bool isRunning() { return m_running; }
|
||||
bool isRaceOver();
|
||||
|
||||
|
@ -112,6 +112,8 @@ bool ClientLobbyRoomProtocol::notifyEventAsynchronous(Event* event)
|
||||
startGame(event);
|
||||
else if (message_type == 0x05) // start selection phase
|
||||
startSelection(event);
|
||||
else if (message_type == 0x06) // end of race
|
||||
raceFinished(event);
|
||||
else if (message_type == 0x80) // connection refused
|
||||
connectionRefused(event);
|
||||
else if (message_type == 0x81) // connection accepted
|
||||
@ -193,9 +195,11 @@ void ClientLobbyRoomProtocol::update()
|
||||
Log::error("ClientLobbyRoomProtocol", "No game events protocol registered.");
|
||||
|
||||
Log::info("ClientLobbyRoomProtocol", "Game finished.");
|
||||
m_state = CONNECTED;
|
||||
m_state = RACE_FINISHED;
|
||||
}
|
||||
} break;
|
||||
case RACE_FINISHED:
|
||||
break;
|
||||
case DONE:
|
||||
m_state = EXITING;
|
||||
m_listener->requestTerminate(this);
|
||||
@ -523,11 +527,11 @@ void ClientLobbyRoomProtocol::startSelection(Event* event)
|
||||
* \param event : Event providing the information.
|
||||
*
|
||||
* Format of the data :
|
||||
* Byte 0 1 5 6 7 8 9
|
||||
* -------------------------------------------------------------------
|
||||
* Size | 1 | 4 | 1 | 1 | 1 | 1 | |
|
||||
* Data | 4 | kart id | race_id | position | kart id 2 | position 2 | ... |
|
||||
* -------------------------------------------------------------------
|
||||
* Byte 0 1 5 6 7 8 9
|
||||
* ---------------------------------------------------
|
||||
* Size | 1 | 4 | 1 | 1 | 1 | 1 | |
|
||||
* Data | 4 | token | 1 | Kart 1 ID | 1 | kart id 2 | ... |
|
||||
* ---------------------------------------------------
|
||||
*/
|
||||
void ClientLobbyRoomProtocol::raceFinished(Event* event)
|
||||
{
|
||||
@ -544,6 +548,7 @@ void ClientLobbyRoomProtocol::raceFinished(Event* event)
|
||||
}
|
||||
data.removeFront(5);
|
||||
WorldWithRank* ranked_world = (WorldWithRank*)(World::getWorld());
|
||||
int position = 1;
|
||||
while(data.size()>0)
|
||||
{
|
||||
if (data.size() < 2)
|
||||
@ -551,12 +556,18 @@ void ClientLobbyRoomProtocol::raceFinished(Event* event)
|
||||
Log::error("ClientLobbyRoomProtocol", "Incomplete field.");
|
||||
return;
|
||||
}
|
||||
uint8_t kart_id = data[0];
|
||||
uint8_t position = data[1];
|
||||
if (data[0] != 1)
|
||||
{
|
||||
Log::error("ClientLobbyRoomProtocol", "Badly formatted field.");
|
||||
return;
|
||||
}
|
||||
uint8_t kart_id = data[1];
|
||||
ranked_world->setKartPosition(kart_id,position);
|
||||
Log::info("ClientLobbyRoomProtocol", "Kart %d has finished #%d", kart_id, position);
|
||||
data.removeFront(2);
|
||||
position++;
|
||||
}
|
||||
m_state = RACE_FINISHED;
|
||||
ranked_world->terminateRace();
|
||||
}
|
||||
|
||||
|
@ -42,6 +42,7 @@ class ClientLobbyRoomProtocol : public LobbyRoomProtocol
|
||||
KART_SELECTION,
|
||||
SELECTING_KARTS, // in the network kart selection screen
|
||||
PLAYING,
|
||||
RACE_FINISHED,
|
||||
DONE,
|
||||
EXITING
|
||||
};
|
||||
|
@ -219,19 +219,18 @@ void ServerLobbyRoomProtocol::checkIncomingConnectionRequests()
|
||||
void ServerLobbyRoomProtocol::checkRaceFinished()
|
||||
{
|
||||
assert(NetworkWorld::getInstance()->isRunning());
|
||||
assert(World::getWorld());
|
||||
// if race is over, give the final score to everybody
|
||||
if (NetworkWorld::getInstance()->isRaceOver())
|
||||
{
|
||||
World* world = World::getWorld();
|
||||
world->terminateRace();
|
||||
// calculate karts ranks :
|
||||
int num_players = race_manager->getNumberOfKarts();
|
||||
std::vector<int> karts_results;
|
||||
for (unsigned int j = 0; j < num_players; j++)
|
||||
for (int j = 0; j < num_players; j++)
|
||||
{
|
||||
float lowest_time = race_manager->getKartRaceTime(0);
|
||||
int lowest_index = 0;
|
||||
for (unsigned int i = 0; i < num_players; i++)
|
||||
for (int i = 0; i < num_players; i++)
|
||||
{
|
||||
float time = race_manager->getKartRaceTime(i);
|
||||
if (time < lowest_time)
|
||||
@ -248,16 +247,22 @@ void ServerLobbyRoomProtocol::checkRaceFinished()
|
||||
NetworkString queue;
|
||||
for (unsigned int i = 0; i < karts_results.size(); i++)
|
||||
{
|
||||
queue.ai8(karts_results[i]).ai8(i+1); // position is i+1
|
||||
queue.ai8(1).ai8(karts_results[i]); // position is i+1
|
||||
}
|
||||
for (unsigned int i = 0; i < peers.size(); i++)
|
||||
{
|
||||
NetworkString ns;
|
||||
ns.ai8(4).ai32(peers[i]->getClientServerToken());
|
||||
ns.ai8(0x06).ai8(4).ai32(peers[i]->getClientServerToken());
|
||||
NetworkString total = ns + queue;
|
||||
m_listener->sendMessage(this, peers[i], total, true);
|
||||
}
|
||||
Log::info("ServerLobbyRoomProtocol", "End of game message sent");
|
||||
m_in_race = false;
|
||||
NetworkWorld::getInstance()->stop();
|
||||
}
|
||||
else
|
||||
{
|
||||
//Log::info("ServerLobbyRoomProtocol", "Phase is %d", World::getWorld()->getPhase());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -45,7 +45,7 @@ class STKPeer
|
||||
bool exists() const;
|
||||
uint32_t getAddress() const;
|
||||
uint16_t getPort() const;
|
||||
NetworkPlayerProfile* getPlayerProfile() { return *m_player_profile; }
|
||||
NetworkPlayerProfile* getPlayerProfile() { return (m_player_profile==NULL)?NULL:(*m_player_profile); }
|
||||
uint32_t getClientServerToken() const { return *m_client_server_token; }
|
||||
bool isClientServerTokenSet() const { return *m_token_set; }
|
||||
|
||||
|
@ -723,7 +723,9 @@ void RaceManager::kartFinishedRace(const AbstractKart *kart, float time)
|
||||
m_kart_status[id].m_overall_time += time;
|
||||
m_kart_status[id].m_last_time = time;
|
||||
m_num_finished_karts ++;
|
||||
if(kart->getController()->isPlayerController()) m_num_finished_players++;
|
||||
if(kart->getController()->isPlayerController() ||
|
||||
kart->getController()->isNetworkController())
|
||||
m_num_finished_players++;
|
||||
} // kartFinishedRace
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
Loading…
x
Reference in New Issue
Block a user