From 71fb252654076a2e8727855f3cd6d2bc3c002fba Mon Sep 17 00:00:00 2001 From: hilnius Date: Thu, 29 Aug 2013 17:57:56 +0000 Subject: [PATCH] removed some useless files + improvements in end-race GUI interaction git-svn-id: svn+ssh://svn.code.sf.net/p/supertuxkart/code/main/branches/hilnius@13592 178a84e3-b1eb-0310-8ba1-8eac791a3b58 --- src/modes/world.cpp | 1 + src/network/client_network_manager.cpp | 1 + src/network/client_network_manager.hpp | 4 ++ src/network/event.hpp | 5 ++ src/network/http_functions.cpp | 67 ------------------- src/network/http_functions.hpp | 35 ---------- src/network/network_world.cpp | 1 - .../protocols/controller_events_protocol.cpp | 1 + .../protocols/kart_update_protocol.cpp | 2 + src/network/protocols/start_game_protocol.cpp | 16 +++-- src/states_screens/race_result_gui.cpp | 21 +++++- 11 files changed, 41 insertions(+), 113 deletions(-) delete mode 100644 src/network/http_functions.cpp delete mode 100644 src/network/http_functions.hpp diff --git a/src/modes/world.cpp b/src/modes/world.cpp index 7ecd8cf02..26e4a33b7 100644 --- a/src/modes/world.cpp +++ b/src/modes/world.cpp @@ -215,6 +215,7 @@ void World::reset() m_faster_music_active = false; m_eliminated_karts = 0; m_eliminated_players = 0; + m_is_network_world = false; for ( KartList::iterator i = m_karts.begin(); i != m_karts.end() ; ++i ) { diff --git a/src/network/client_network_manager.cpp b/src/network/client_network_manager.cpp index 5fe0b6a93..2d978eb4e 100644 --- a/src/network/client_network_manager.cpp +++ b/src/network/client_network_manager.cpp @@ -86,6 +86,7 @@ ClientNetworkManager::ClientNetworkManager() ClientNetworkManager::~ClientNetworkManager() { + pthread_cancel(*m_thread_keyboard); } void ClientNetworkManager::run() diff --git a/src/network/client_network_manager.hpp b/src/network/client_network_manager.hpp index ba4101f8c..068d3728d 100644 --- a/src/network/client_network_manager.hpp +++ b/src/network/client_network_manager.hpp @@ -16,6 +16,10 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/*! \file client_network_manager.hpp + * \brief Defines a Client Network manager, that will connect to a server. + */ + #ifndef CLIENT_NETWORK_MANAGER_HPP #define CLIENT_NETWORK_MANAGER_HPP diff --git a/src/network/event.hpp b/src/network/event.hpp index 50477f5bb..291989871 100644 --- a/src/network/event.hpp +++ b/src/network/event.hpp @@ -16,6 +16,11 @@ // along with this program; if not, write to the Free Software // Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/*! \file event.hpp + * \brief Contains an interface to store network events, like connections, + * disconnections and messages. + */ + #ifndef EVENT_HPP #define EVENT_HPP diff --git a/src/network/http_functions.cpp b/src/network/http_functions.cpp deleted file mode 100644 index 8ff861a05..000000000 --- a/src/network/http_functions.cpp +++ /dev/null @@ -1,67 +0,0 @@ -// -// SuperTuxKart - a fun racing game with go-kart -// Copyright (C) 2013 SuperTuxKart-Team -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 3 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -#include "network/http_functions.hpp" - -#include "utils/log.hpp" - -#include -#include -#include -#include -#include - -namespace HTTP -{ -CURL *curl; -CURLcode res; - -static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp) -{ - ((std::string*)userp)->append((char*)contents, size * nmemb); - return size * nmemb; -} - -void init() -{ - curl_global_init(CURL_GLOBAL_DEFAULT); - curl = curl_easy_init(); - if(!curl) - Log::error("HTTP", "Error while loading cURL library.\n"); -} - -std::string getPage(std::string url) -{ - std::string readBuffer; - curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); - curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback); - curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer); - res = curl_easy_perform(curl); - if(res != CURLE_OK) - Log::error("HTTP", "curl_easy_perform() failed: %s\n", curl_easy_strerror(res)); - - return readBuffer; -} - -void shutdown() -{ - curl_easy_cleanup(curl); - curl_global_cleanup(); -} - -} diff --git a/src/network/http_functions.hpp b/src/network/http_functions.hpp deleted file mode 100644 index 970b9c1dd..000000000 --- a/src/network/http_functions.hpp +++ /dev/null @@ -1,35 +0,0 @@ -// -// SuperTuxKart - a fun racing game with go-kart -// Copyright (C) 2013 SuperTuxKart-Team -// -// This program is free software; you can redistribute it and/or -// modify it under the terms of the GNU General Public License -// as published by the Free Software Foundation; either version 3 -// of the License, or (at your option) any later version. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program; if not, write to the Free Software -// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - -#ifndef HTTP_FUNCTIONS_HPP -#define HTTP_FUNCTIONS_HPP - -#include - -namespace HTTP -{ - -void init(); -void shutdown(); - -std::string getPage(std::string url); - - -} - -#endif // HTTP_FUNCTIONS_HPP diff --git a/src/network/network_world.cpp b/src/network/network_world.cpp index ad8f4dfba..6337911f4 100644 --- a/src/network/network_world.cpp +++ b/src/network/network_world.cpp @@ -51,7 +51,6 @@ void NetworkWorld::start() void NetworkWorld::stop() { m_running = false; - World::getWorld()->setNetworkWorld(false); } bool NetworkWorld::isRaceOver() diff --git a/src/network/protocols/controller_events_protocol.cpp b/src/network/protocols/controller_events_protocol.cpp index 60021eb11..8a6067a68 100644 --- a/src/network/protocols/controller_events_protocol.cpp +++ b/src/network/protocols/controller_events_protocol.cpp @@ -164,6 +164,7 @@ void ControllerEventsProtocol::controllerAction(Controller* controller, ns.ai8(serialized_1).ai8(serialized_2).ai8(serialized_3); ns.ai8((uint8_t)(action)).ai32(value); + Log::info("ControllerEventsProtocol", "Action %d value %d", action, value); m_listener->sendMessage(this, ns, false); // send message to server } diff --git a/src/network/protocols/kart_update_protocol.cpp b/src/network/protocols/kart_update_protocol.cpp index 1287818fd..0dbf40dae 100644 --- a/src/network/protocols/kart_update_protocol.cpp +++ b/src/network/protocols/kart_update_protocol.cpp @@ -68,6 +68,8 @@ void KartUpdateProtocol::setup() void KartUpdateProtocol::update() { + if (!World::getWorld()) + return; static double time = 0; double current_time = Time::getRealTime(); if (current_time > time + 0.1) // 10 updates per second diff --git a/src/network/protocols/start_game_protocol.cpp b/src/network/protocols/start_game_protocol.cpp index cd20bdff1..a29e15d89 100644 --- a/src/network/protocols/start_game_protocol.cpp +++ b/src/network/protocols/start_game_protocol.cpp @@ -1,20 +1,21 @@ #include "network/protocols/start_game_protocol.hpp" +#include "input/device_manager.hpp" +#include "input/input_manager.hpp" +#include "challenges/unlock_manager.hpp" +#include "modes/world.hpp" #include "network/network_manager.hpp" #include "network/protocol_manager.hpp" #include "network/game_setup.hpp" #include "network/network_world.hpp" #include "network/protocols/synchronization_protocol.hpp" +#include "online/current_user.hpp" #include "race/race_manager.hpp" -#include "utils/log.hpp" -#include "utils/time.hpp" - -#include "input/device_manager.hpp" -#include "input/input_manager.hpp" -#include "challenges/unlock_manager.hpp" #include "states_screens/state_manager.hpp" #include "states_screens/kart_selection.hpp" -#include "online/current_user.hpp" +#include "states_screens/network_kart_selection.hpp" +#include "utils/log.hpp" +#include "utils/time.hpp" StartGameProtocol::StartGameProtocol(GameSetup* game_setup) : Protocol(NULL, PROTOCOL_START_GAME) @@ -166,6 +167,7 @@ void StartGameProtocol::update() // now the synchronization protocol exists. Log::info("StartGameProtocol", "Starting the race loading."); race_manager->startSingleRace("jungle", 1, false); + World::getWorld()->setNetworkWorld(true); m_state = LOADING; } } diff --git a/src/states_screens/race_result_gui.cpp b/src/states_screens/race_result_gui.cpp index d64c4c3e0..eb81b1f0f 100644 --- a/src/states_screens/race_result_gui.cpp +++ b/src/states_screens/race_result_gui.cpp @@ -36,11 +36,14 @@ #include "modes/demo_world.hpp" #include "modes/overworld.hpp" #include "modes/world_with_rank.hpp" -#include "network/network_world.hpp" #include "race/highscores.hpp" #include "states_screens/feature_unlocked.hpp" #include "states_screens/main_menu_screen.hpp" +#include "states_screens/networking_lobby.hpp" +#include "states_screens/network_kart_selection.hpp" +#include "states_screens/online_screen.hpp" #include "states_screens/race_setup_screen.hpp" +#include "states_screens/server_selection.hpp" #include "tracks/track.hpp" #include "tracks/track_manager.hpp" #include "utils/string_utils.hpp" @@ -98,8 +101,9 @@ void RaceResultGUI::enableAllButtons() } // If we're in a network world, change the buttons text - if (NetworkWorld::getInstance()->isRunning()) + if (World::getWorld()->isNetworkWorld()) { + Log::info("This work was networked", "This is a network world."); top->setVisible(false); middle->setText( _("Continue.") ); middle->setVisible(true); @@ -113,6 +117,7 @@ void RaceResultGUI::enableAllButtons() } return; } + Log::info("This work was NOT networked", "This is NOT a network world."); // If something was unlocked // ------------------------- @@ -234,11 +239,19 @@ void RaceResultGUI::eventCallback(GUIEngine::Widget* widget, } // If we're playing online : - if (NetworkWorld::getInstance()->isRunning()) + if (World::getWorld()->isNetworkWorld()) { StateManager::get()->popMenu(); if (name == "middle") // Continue button (return to server lobby) { + race_manager->exitRace(); + race_manager->setAIKartOverride(""); + Screen* newStack[] = {MainMenuScreen::getInstance(), + OnlineScreen::getInstance(), + ServerSelection::getInstance(), + NetworkingLobby::getInstance(), + NULL}; + StateManager::get()->resetAndSetStack( newStack ); } if (name == "bottom") // Quit server (return to main menu) { @@ -280,6 +293,7 @@ void RaceResultGUI::eventCallback(GUIEngine::Widget* widget, { race_manager->exitRace(); race_manager->setAIKartOverride(""); + NetworkKartSelectionScreen::getInstance()->tearDown(); // be sure to delete the kart selection screen Screen* newStack[] = {MainMenuScreen::getInstance(), RaceSetupScreen::getInstance(), NULL}; @@ -293,6 +307,7 @@ void RaceResultGUI::eventCallback(GUIEngine::Widget* widget, { race_manager->exitRace(); race_manager->setAIKartOverride(""); + NetworkKartSelectionScreen::getInstance()->tearDown(); // be sure to delete the kart selection screen StateManager::get()->resetAndGoToScreen(MainMenuScreen::getInstance()); if (race_manager->raceWasStartedFromOverworld())