From: <tz...@us...> - 2007-07-28 00:55:50
|
Revision: 2199 http://freeorion.svn.sourceforge.net/freeorion/revision/?rev=2199&view=rev Author: tzlaine Date: 2007-07-27 17:55:52 -0700 (Fri, 27 Jul 2007) Log Message: ----------- Removed some now-useless SDL-related code. This includes replacing calls to SDL_Delay() with Sleep() on Win32 and boost::thread::sleep() on other platforms. Modified Paths: -------------- trunk/FreeOrion/SConstruct trunk/FreeOrion/client/AI/AIClientApp.cpp trunk/FreeOrion/client/AI/AIClientApp.h trunk/FreeOrion/client/human/HumanClientApp.cpp trunk/FreeOrion/client/human/HumanClientFSM.cpp trunk/FreeOrion/combat/CombatSystem.cpp trunk/FreeOrion/default/eng_stringtable.txt trunk/FreeOrion/default/ger_stringtable.txt trunk/FreeOrion/network/ClientNetworking.cpp trunk/FreeOrion/network/ServerNetworking.cpp trunk/FreeOrion/server/ServerApp.cpp trunk/FreeOrion/server/ServerFSM.cpp trunk/FreeOrion/util/MultiplayerCommon.cpp trunk/FreeOrion/util/MultiplayerCommon.h Modified: trunk/FreeOrion/SConstruct =================================================================== --- trunk/FreeOrion/SConstruct 2007-07-27 22:23:06 UTC (rev 2198) +++ trunk/FreeOrion/SConstruct 2007-07-28 00:55:52 UTC (rev 2199) @@ -42,10 +42,6 @@ options.Add('with_sdl', 'Root directory of SDL installation') options.Add('with_sdl_include', 'Specify exact include dir for SDL headers') options.Add('with_sdl_libdir', 'Specify exact library dir for SDL library') -options.Add(BoolOption('with_builtin_sdlnet', 'Use built-in version of SDL_net', 1)) -options.Add('with_sdlnet', 'Root directory of SDL_net installation (ignored if $with_builtin_sdlnet is true)') -options.Add('with_sdlnet_include', 'Specify exact include dir for SDL_net headers (ignored if $with_builtin_sdlnet is true)') -options.Add('with_sdlnet_libdir', 'Specify exact library dir for SDL_net library (ignored if $with_builtin_sdlnet is true)') options.Add('with_ft', 'Root directory of FreeType2 installation') options.Add('with_ft_include', 'Specify exact include dir for FreeType2 headers') options.Add('with_ft_libdir', 'Specify exact library dir for FreeType2 library') @@ -227,7 +223,6 @@ freeorion_boost_libs = [ ('boost_serialization', 'boost/archive/binary_iarchive.hpp', 'boost::archive::binary_iarchive::is_saving();'), - ('boost_thread', 'boost/thread/thread.hpp', 'boost::thread::thread();'), ('boost_iostreams', 'boost/iostreams/filtering_stream.hpp', ''), ('boost_python', 'boost/python.hpp', 'boost::python::throw_error_already_set();') ] @@ -245,7 +240,8 @@ boost_libs = freeorion_boost_libs + [ ('boost_signals', 'boost/signals.hpp', 'boost::signals::connection();'), - ('boost_filesystem', 'boost/filesystem/operations.hpp', 'boost::filesystem::initial_path();') + ('boost_filesystem', 'boost/filesystem/operations.hpp', 'boost::filesystem::initial_path();'), + ('boost_thread', 'boost/thread/thread.hpp', 'boost::thread::yield();'), ] if not conf.CheckBoost(boost_version_string, boost_libs, conf, not ms_linker): Exit(1) @@ -281,13 +277,6 @@ if not conf.CheckSDL(options, conf, sdl_config, not ms_linker): Exit(1) - # SDL_net (optional) - if not env['with_builtin_sdlnet']: - AppendPackagePaths('sdlnet', env) - if not conf.CheckCHeader('SDL/SDL_net.h') and not conf.CheckCHeader('SDL_net.h') or \ - not conf.CheckLib('SDL_net', 'SDLNet_Init'): - Exit(1) - # FreeType2 AppendPackagePaths('ft', env) found_it_with_pkg_config = False Modified: trunk/FreeOrion/client/AI/AIClientApp.cpp =================================================================== --- trunk/FreeOrion/client/AI/AIClientApp.cpp 2007-07-27 22:23:06 UTC (rev 2198) +++ trunk/FreeOrion/client/AI/AIClientApp.cpp 2007-07-28 00:55:52 UTC (rev 2199) @@ -21,8 +21,6 @@ #include "../../util/Order.h" #include "../../Empire/Empire.h" -#include <SDL/SDL_timer.h> - #include <boost/lexical_cast.hpp> #include <boost/filesystem/fstream.hpp> @@ -111,7 +109,7 @@ Networking().GetMessage(msg); HandleMessage(msg); } else { - SDL_Delay(250); + Sleep(250); } } } Modified: trunk/FreeOrion/client/AI/AIClientApp.h =================================================================== --- trunk/FreeOrion/client/AI/AIClientApp.h 2007-07-27 22:23:06 UTC (rev 2198) +++ trunk/FreeOrion/client/AI/AIClientApp.h 2007-07-28 00:55:52 UTC (rev 2199) @@ -20,6 +20,7 @@ /** \name Mutators */ //@{ void operator()(); ///< external interface to Run() + void Wait(int ms); ///< put the main thread to sleep for \a ms milliseconds void Exit(int code); ///< does basic clean-up, then calls exit(); callable from anywhere in user code via GetApp() //@} Modified: trunk/FreeOrion/client/human/HumanClientApp.cpp =================================================================== --- trunk/FreeOrion/client/human/HumanClientApp.cpp 2007-07-27 22:23:06 UTC (rev 2198) +++ trunk/FreeOrion/client/human/HumanClientApp.cpp 2007-07-28 00:55:52 UTC (rev 2199) @@ -83,9 +83,6 @@ db.Add("autosave.multiplayer", "OPTIONS_DB_AUTOSAVE_MULTIPLAYER", false, Validator<bool>()); db.Add("autosave.turns", "OPTIONS_DB_AUTOSAVE_TURNS", 5, RangedValidator<int>(1, 50)); db.Add("autosave.saves", "OPTIONS_DB_AUTOSAVE_SAVES", 10, RangedValidator<int>(1, 50)); -#if defined(FREEORION_LINUX) - db.Add("enable-sdl-event-thread", "OPTIONS_DB_ENABLE_SDL_EVENT_THREAD", false, Validator<bool>()); -#endif db.Add("music-volume", "OPTIONS_DB_MUSIC_VOLUME", 255, RangedValidator<int>(1, 255)); } bool temp_bool = RegisterOptions(&AddOptions); @@ -379,17 +376,7 @@ // Set Fullscreen if specified at command line or in config-file DoFullScreen = GetOptionsDB().Get<bool>("fullscreen") ? SDL_FULLSCREEN : 0; - // SDL on MacOsX crashes if the Eventhandling-thread isn't the - // application's main thread. It seems that only the applications - // main-thread is able to receive events... -#if defined(FREEORION_WIN32) || defined(FREEORION_MACOSX) if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE) < 0) { -#else - Uint32 init_flags = SDL_INIT_VIDEO | SDL_INIT_NOPARACHUTE; - if (GetOptionsDB().Get<bool>("enable-sdl-event-thread")) - init_flags |= SDL_INIT_EVENTTHREAD; - if (SDL_Init(init_flags) < 0) { -#endif Logger().errorStream() << "SDL initialization failed: " << SDL_GetError(); Exit(1); } Modified: trunk/FreeOrion/client/human/HumanClientFSM.cpp =================================================================== --- trunk/FreeOrion/client/human/HumanClientFSM.cpp 2007-07-27 22:23:06 UTC (rev 2198) +++ trunk/FreeOrion/client/human/HumanClientFSM.cpp 2007-07-28 00:55:52 UTC (rev 2199) @@ -240,7 +240,7 @@ { if (TRACE_EXECUTION) Logger().debugStream() << "(HumanClientFSM) HostMPLobby.CancelMPGameClicked"; Client().Networking().SendMessage(LobbyHostAbortMessage(Client().PlayerID())); - SDL_Delay(1000); // HACK! Add a delay here so the message can propagate + Sleep(1000); // HACK! Add a delay here so the message can propagate Client().Networking().DisconnectFromServer(); Client().KillServer(); return transit<IntroMenu>(); @@ -278,7 +278,7 @@ { if (TRACE_EXECUTION) Logger().debugStream() << "(HumanClientFSM) NonHostMPLobby.CancelMPGameClicked"; Client().Networking().SendMessage(LobbyExitMessage(Client().PlayerID())); - SDL_Delay(1000); // HACK! Add a delay here so the message can propagate + Sleep(1000); // HACK! Add a delay here so the message can propagate HumanClientApp::GetApp()->Networking().DisconnectFromServer(); return transit<IntroMenu>(); } Modified: trunk/FreeOrion/combat/CombatSystem.cpp =================================================================== --- trunk/FreeOrion/combat/CombatSystem.cpp 2007-07-27 22:23:06 UTC (rev 2198) +++ trunk/FreeOrion/combat/CombatSystem.cpp 2007-07-28 00:55:52 UTC (rev 2199) @@ -360,7 +360,6 @@ msg = XMLDoc(); msg.root_node.AppendChild(GenerateCombatUpdateMessage(-1,system_id,empire_combat_forces).XMLEncode()); SendMessageToAllPlayers(Message::COMBAT_ROUND_UPDATE, msg); - //SDL_Delay(1000); maybe we add an delay to illustrate players a ongoing combat } #ifdef DEBUG_COMBAT Modified: trunk/FreeOrion/default/eng_stringtable.txt =================================================================== --- trunk/FreeOrion/default/eng_stringtable.txt 2007-07-27 22:23:06 UTC (rev 2198) +++ trunk/FreeOrion/default/eng_stringtable.txt 2007-07-28 00:55:52 UTC (rev 2199) @@ -416,9 +416,6 @@ OPTIONS_DB_AUTOSAVE_SAVES Sets the number of autosaved games that should be kept. -OPTIONS_DB_ENABLE_SDL_EVENT_THREAD -Enables creation of a thread dedicated to handling incoming SDL messages. This may make FreeOrion more or less responsive, depending on your system. - OPTIONS_DB_MUSIC_VOLUME The volume (0 to 255) at which music should be played. Modified: trunk/FreeOrion/default/ger_stringtable.txt =================================================================== --- trunk/FreeOrion/default/ger_stringtable.txt 2007-07-27 22:23:06 UTC (rev 2198) +++ trunk/FreeOrion/default/ger_stringtable.txt 2007-07-28 00:55:52 UTC (rev 2199) @@ -398,9 +398,6 @@ OPTIONS_DB_AUTOSAVE_SAVES Sets the number of autosaved games that should be kept. -OPTIONS_DB_ENABLE_SDL_EVENT_THREAD -Enables creation of a thread dedicated to handling incoming SDL messages. This may make FreeOrion more or less responsive, depending on your system. - OPTIONS_DB_MUSIC_VOLUME The volume (0 to 255) at which music should be played. Modified: trunk/FreeOrion/network/ClientNetworking.cpp =================================================================== --- trunk/FreeOrion/network/ClientNetworking.cpp 2007-07-27 22:23:06 UTC (rev 2198) +++ trunk/FreeOrion/network/ClientNetworking.cpp 2007-07-28 00:55:52 UTC (rev 2199) @@ -3,8 +3,6 @@ #include "Networking.h" #include "../util/AppInterface.h" -#include <SDL/SDL_timer.h> - #include <boost/algorithm/string/predicate.hpp> #include <boost/algorithm/string/erase.hpp> #include <boost/bind.hpp> @@ -177,7 +175,7 @@ void ClientNetworking::DisconnectFromServer() { m_io_service.post(boost::bind(&ClientNetworking::DisconnectFromServerImpl, this)); - SDL_Delay(1000); // HACK! wait a bit for the disconnect to occur + Sleep(1000); // HACK! wait a bit for the disconnect to occur } void ClientNetworking::SendMessage(const Message& message) Modified: trunk/FreeOrion/network/ServerNetworking.cpp =================================================================== --- trunk/FreeOrion/network/ServerNetworking.cpp 2007-07-27 22:23:06 UTC (rev 2198) +++ trunk/FreeOrion/network/ServerNetworking.cpp 2007-07-28 00:55:52 UTC (rev 2199) @@ -3,8 +3,6 @@ #include "Networking.h" #include "../util/AppInterface.h" -#include <SDL/SDL_timer.h> - #include <boost/bind.hpp> #include <boost/iterator/filter_iterator.hpp> @@ -146,7 +144,7 @@ // problem. For now, this is sufficient, since rapid connects and disconnects are not a priority. if (m_new_connection) { // wait half a second if the first data read is an error; we probably just need more setup time - SDL_Delay(500); + Sleep(500); } else { if (error == boost::asio::error::eof || error == boost::asio::error::connection_reset) Modified: trunk/FreeOrion/server/ServerApp.cpp =================================================================== --- trunk/FreeOrion/server/ServerApp.cpp 2007-07-27 22:23:06 UTC (rev 2198) +++ trunk/FreeOrion/server/ServerApp.cpp 2007-07-28 00:55:52 UTC (rev 2199) @@ -30,10 +30,6 @@ #include <log4cpp/PatternLayout.hh> #include <log4cpp/FileAppender.hh> -#include <SDL/SDL_timer.h> -// for dummy video driver setenv-hack -#include <SDL/SDL_getenv.h> - #include <ctime> @@ -609,7 +605,7 @@ // if a combat happened, give the human user a chance to look at the results if (combat_happend) - SDL_Delay(1500); + Sleep(1500); // process production and growth phase for (ServerNetworking::const_established_iterator player_it = m_networking.established_begin(); player_it != m_networking.established_end(); ++player_it) { @@ -717,7 +713,7 @@ } } - SDL_Delay(1000); + Sleep(1000); // dump connections to eliminated players, and remove server-side empire data for (std::map<int, int>::iterator it = eliminations.begin(); it != eliminations.end(); ++it) { @@ -735,7 +731,7 @@ while (m_networking.NumPlayers() == 1) { m_networking.SendMessage(EndGameMessage((*m_networking.established_begin())->ID(), Message::LAST_OPPONENT_DEFEATED)); } - SDL_Delay(2000); + Sleep(2000); Exit(0); } else if (m_ai_IDs.size() == m_networking.NumPlayers()) { // if there are none but AI players left, we're done m_log_category.debugStream() << "ServerApp::ProcessTurns : No human players left -- server terminating."; Modified: trunk/FreeOrion/server/ServerFSM.cpp =================================================================== --- trunk/FreeOrion/server/ServerFSM.cpp 2007-07-27 22:23:06 UTC (rev 2198) +++ trunk/FreeOrion/server/ServerFSM.cpp 2007-07-28 00:55:52 UTC (rev 2199) @@ -8,8 +8,6 @@ #include "../util/Directories.h" #include "../util/OrderSet.h" -#include <SDL/SDL_timer.h> - #include <GG/Font.h> @@ -92,7 +90,7 @@ } } Logger().debugStream() << "ServerFSM::HandleNonLobbyDisconnection : Host player disconnected; server terminating."; - SDL_Delay(2000); // HACK! Pause for a bit to let the player disconnected and end game messages propogate. + Sleep(2000); // HACK! Pause for a bit to let the player disconnected and end game messages propogate. m_server.Exit(1); } else if (m_server.m_losers.find(id) == m_server.m_losers.end()) { // player abnormally disconnected during a regular game Logger().debugStream() << "ServerFSM::HandleNonLobbyDisconnection : Lost connection to player #" << boost::lexical_cast<std::string>(id) @@ -109,7 +107,7 @@ // independently of everything else, if there are no humans left, it's time to terminate if (m_server.m_networking.empty() || m_server.m_ai_clients.size() == m_server.m_networking.NumPlayers()) { Logger().debugStream() << "ServerFSM::HandleNonLobbyDisconnection : All human players disconnected; server terminating."; - SDL_Delay(2000); // HACK! Pause for a bit to let the player disconnected and end game messages propogate. + Sleep(2000); // HACK! Pause for a bit to let the player disconnected and end game messages propogate. m_server.Exit(1); } } @@ -308,7 +306,7 @@ } } - SDL_Delay(1000); // HACK! Add a delay here so the messages can propagate; setting socket linger does not appear to work + Sleep(1000); // HACK! Add a delay here so the messages can propagate; setting socket linger does not appear to work for (ServerNetworking::const_established_iterator it = server.m_networking.established_begin(); it != server.m_networking.established_end(); ) { PlayerConnectionPtr player_connection = *it++; Modified: trunk/FreeOrion/util/MultiplayerCommon.cpp =================================================================== --- trunk/FreeOrion/util/MultiplayerCommon.cpp 2007-07-27 22:23:06 UTC (rev 2198) +++ trunk/FreeOrion/util/MultiplayerCommon.cpp 2007-07-28 00:55:52 UTC (rev 2199) @@ -20,6 +20,8 @@ #include <boost/filesystem/operations.hpp> #include <boost/filesystem/cerrno.hpp> +#include <boost/thread/thread.hpp> +#include <boost/thread/xtime.hpp> #include <fstream> #include <iostream> @@ -157,7 +159,22 @@ return RETVAL; } +#ifndef FREEORION_WIN32 +void Sleep(int ms) +{ + boost::xtime t; + boost::xtime_get(&t, boost::TIME_UTC); + int ns_sum = t.nsec + ms * 1000000; + const int NANOSECONDS_PER_SECOND = 1000000000; + int delta_secs = ns_sum / NANOSECONDS_PER_SECOND; + int nanosecs = ns_sum % NANOSECONDS_PER_SECOND; + t.sec += delta_secs; + t.nsec = nanosecs; + boost::thread::sleep(t); +} +#endif + ///////////////////////////////////////////////////// // GalaxySetupData ///////////////////////////////////////////////////// Modified: trunk/FreeOrion/util/MultiplayerCommon.h =================================================================== --- trunk/FreeOrion/util/MultiplayerCommon.h 2007-07-27 22:23:06 UTC (rev 2198) +++ trunk/FreeOrion/util/MultiplayerCommon.h 2007-07-28 00:55:52 UTC (rev 2199) @@ -39,6 +39,11 @@ /** Returns the canonical name of the only human player in a single player game. */ const std::string& SinglePlayerName(); +#ifndef FREEORION_WIN32 +/** Puts the calling thread to sleep for \a ms milliseconds. */ +void Sleep(int ms); +#endif + /** The data that represent the galaxy setup for a new game. */ struct GalaxySetupData { |