From: <de...@us...> - 2006-03-03 18:51:14
|
Revision: 1789 Author: dennis Date: 2006-03-03 10:50:36 -0800 (Fri, 03 Mar 2006) ViewCVS: http://svn.sourceforge.net/freeorion?rev=1789&view=rev Log Message: ----------- Added DejaVu fonts. These are a modified version of Bitstream Vera supporting, among others, cyrillic characters. Added Paths: ----------- trunk/FreeOrion/DejaVuSans-Bold.ttf trunk/FreeOrion/DejaVuSans-BoldOblique.ttf trunk/FreeOrion/DejaVuSans-Oblique.ttf trunk/FreeOrion/DejaVuSans.ttf trunk/FreeOrion/License.DejaVu Added: trunk/FreeOrion/DejaVuSans-Bold.ttf =================================================================== (Binary files differ) Property changes on: trunk/FreeOrion/DejaVuSans-Bold.ttf ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/FreeOrion/DejaVuSans-BoldOblique.ttf =================================================================== (Binary files differ) Property changes on: trunk/FreeOrion/DejaVuSans-BoldOblique.ttf ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/FreeOrion/DejaVuSans-Oblique.ttf =================================================================== (Binary files differ) Property changes on: trunk/FreeOrion/DejaVuSans-Oblique.ttf ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/FreeOrion/DejaVuSans.ttf =================================================================== (Binary files differ) Property changes on: trunk/FreeOrion/DejaVuSans.ttf ___________________________________________________________________ Name: svn:mime-type + application/octet-stream Added: trunk/FreeOrion/License.DejaVu =================================================================== --- trunk/FreeOrion/License.DejaVu (rev 0) +++ trunk/FreeOrion/License.DejaVu 2006-03-03 18:50:36 UTC (rev 1789) @@ -0,0 +1,4 @@ +The DejaVu fonts are based on Bitstream Vera. See License.Vera for +license terms of Vera. + +The DejaVu changes are in the public domain. |
From: <tz...@us...> - 2006-03-03 21:00:30
|
Revision: 1790 Author: tzlaine Date: 2006-03-03 13:00:24 -0800 (Fri, 03 Mar 2006) ViewCVS: http://svn.sourceforge.net/freeorion?rev=1790&view=rev Log Message: ----------- Changed the way Version.cpp gets its version and revision strings to be more flexible and consistent with the rest of the organization of the build system. Modified Paths: -------------- trunk/FreeOrion/SConscript trunk/FreeOrion/SConstruct trunk/FreeOrion/build_config.py trunk/FreeOrion/build_support.py Added Paths: ----------- trunk/FreeOrion/util/Version.cpp.in Removed Paths: ------------- trunk/FreeOrion/util/Version.cpp Modified: trunk/FreeOrion/SConscript =================================================================== --- trunk/FreeOrion/SConscript 2006-03-03 18:50:36 UTC (rev 1789) +++ trunk/FreeOrion/SConscript 2006-03-03 21:00:24 UTC (rev 1790) @@ -39,6 +39,7 @@ 'util/SitRepEntry.cpp', 'util/Serialize.cpp', 'util/VarText.cpp', + 'util/Version.cpp', 'util/binreloc.c', 'util/Directories.cpp', 'util/XMLDoc.cpp' @@ -108,27 +109,7 @@ ] target = 'human' -def get_revision(env): - "Try to determine the current revision from SVN." - try: - from os import popen - inf = popen("svn info") - for i in inf: - if i[:10] == "Revision: ": - return r'\" [Rev ' + i[10:-1] + r']\"' - except: - return None - objects = env.Object(common_sources) -# This evil line should prevent SCons from issuing a warning -# [b,a][c==d] is equivalent to C's c==d?a:b -# So what is does is defining FREEORION_REVISION if get_revision -# returned one -objects += env.Object('util/Version.cpp', CPPDEFINES = [ - [('FREEORION_REVISION', get_revision(env))], - []][get_revision(common_sources) == None] -) - objects += [env.Object(target = source.split(".")[0] + '-' + target, source = source, CPPDEFINES = env['CPPDEFINES'] + [env['target_define']]) Modified: trunk/FreeOrion/SConstruct =================================================================== --- trunk/FreeOrion/SConstruct 2006-03-03 18:50:36 UTC (rev 1789) +++ trunk/FreeOrion/SConstruct 2006-03-03 21:00:24 UTC (rev 1790) @@ -470,6 +470,17 @@ else: env.Append(CCFLAGS = ['-Wall', '-O2']) +# generate Version.cpp +version_cpp_in = open('util/Version.cpp.in', 'r') +version_cpp = open('util/Version.cpp', 'w') +values = { + "freeorion_version" : freeorion_version, + "freeorion_repository_revision" : GetRepositoryRevision() + } +version_cpp.write(version_cpp_in.read() % values) +version_cpp.close() +version_cpp_in.close() + Export('env') # define server objects Modified: trunk/FreeOrion/build_config.py =================================================================== --- trunk/FreeOrion/build_config.py 2006-03-03 18:50:36 UTC (rev 1789) +++ trunk/FreeOrion/build_config.py 2006-03-03 21:00:24 UTC (rev 1790) @@ -1,5 +1,7 @@ # -*- Python -*- +freeorion_version = "v0.3.1-RC4" + gigi_version = '0.6.0' ft_pkgconfig_version = '9.0.0' Modified: trunk/FreeOrion/build_support.py =================================================================== --- trunk/FreeOrion/build_support.py 2006-03-03 18:50:36 UTC (rev 1789) +++ trunk/FreeOrion/build_support.py 2006-03-03 21:00:24 UTC (rev 1790) @@ -356,3 +356,14 @@ install_nodes = [] TraverseHeaderTree(dir, header_root, headers, current_path, op, install_nodes) return install_nodes + +def GetRepositoryRevision(): + "Try to determine the current revision from SVN." + try: + from os import popen + inf = popen("svn info") + for i in inf: + if i[:10] == "Revision: ": + return ' [Rev ' + i[10:-1] + ']' + except: + return None Deleted: trunk/FreeOrion/util/Version.cpp =================================================================== --- trunk/FreeOrion/util/Version.cpp 2006-03-03 18:50:36 UTC (rev 1789) +++ trunk/FreeOrion/util/Version.cpp 2006-03-03 21:00:24 UTC (rev 1790) @@ -1,14 +0,0 @@ -#include "Version.h" - -namespace { - const std::string version_string = "v0.3.1-RC4" // no semicolon here -#ifdef FREEORION_REVISION - FREEORION_REVISION -#endif - ; -} - -const std::string& FreeOrionVersionString() -{ - return version_string; -} Copied: trunk/FreeOrion/util/Version.cpp.in (from rev 1789, trunk/FreeOrion/util/Version.cpp) =================================================================== --- trunk/FreeOrion/util/Version.cpp.in (rev 0) +++ trunk/FreeOrion/util/Version.cpp.in 2006-03-03 21:00:24 UTC (rev 1790) @@ -0,0 +1,7 @@ +#include "Version.h" + +const std::string& FreeOrionVersionString() +{ + static const std::string retval = "%(freeorion_version)s%(freeorion_repository_revision)s"; + return retval; +} |
From: <tz...@us...> - 2006-03-04 06:32:41
|
Revision: 1794 Author: tzlaine Date: 2006-03-03 22:32:36 -0800 (Fri, 03 Mar 2006) ViewCVS: http://svn.sourceforge.net/freeorion?rev=1794&view=rev Log Message: ----------- Replaced the use of Vera Bitstream fonts with DejaVu fonts, which are the same, but have more characters (e.g. Cyrillic). Modified Paths: -------------- trunk/FreeOrion/UI/ClientUI.cpp Removed Paths: ------------- trunk/FreeOrion/Vera.ttf trunk/FreeOrion/VeraBI.ttf trunk/FreeOrion/VeraBd.ttf trunk/FreeOrion/VeraIt.ttf Modified: trunk/FreeOrion/UI/ClientUI.cpp =================================================================== --- trunk/FreeOrion/UI/ClientUI.cpp 2006-03-04 06:28:24 UTC (rev 1793) +++ trunk/FreeOrion/UI/ClientUI.cpp 2006-03-04 06:32:36 UTC (rev 1794) @@ -42,21 +42,21 @@ namespace { const fs::path GLOBAL_DIR = GetGlobalDir(); } -std::string ClientUI::FONT = (GLOBAL_DIR / "Vera.ttf").native_file_string(); -std::string ClientUI::FONT_BOLD = (GLOBAL_DIR / "VeraBd.ttf").native_file_string(); -std::string ClientUI::FONT_ITALIC = (GLOBAL_DIR / "VeraIt.ttf").native_file_string(); -std::string ClientUI::FONT_BOLD_ITALIC = (GLOBAL_DIR / "VeraBI.ttf").native_file_string(); -std::string ClientUI::TITLE_FONT = (GLOBAL_DIR / "Vera.ttf").native_file_string(); +std::string ClientUI::FONT = (GLOBAL_DIR / "DejaVuSans.ttf").native_file_string(); +std::string ClientUI::FONT_BOLD = (GLOBAL_DIR / "DejaVuSans-Bold.ttf").native_file_string(); +std::string ClientUI::FONT_ITALIC = (GLOBAL_DIR / "DejaVuSans-Oblique.ttf").native_file_string(); +std::string ClientUI::FONT_BOLD_ITALIC = (GLOBAL_DIR / "DejaVuSans-BoldOblique.ttf").native_file_string(); +std::string ClientUI::TITLE_FONT = (GLOBAL_DIR / "DejaVuSans.ttf").native_file_string(); std::string ClientUI::DIR = (GLOBAL_DIR / "default/").native_directory_string(); std::string ClientUI::ART_DIR = (GLOBAL_DIR / "default/data/art/").native_directory_string(); std::string ClientUI::SOUND_DIR = (GLOBAL_DIR / "default/data/sound/").native_directory_string(); #else -std::string ClientUI::FONT = "Vera.ttf"; -std::string ClientUI::FONT_BOLD = "VeraBd.ttf"; -std::string ClientUI::FONT_ITALIC = "VeraIt.ttf"; -std::string ClientUI::FONT_BOLD_ITALIC = "VeraBI.ttf"; -std::string ClientUI::TITLE_FONT = "Vera.ttf"; +std::string ClientUI::FONT = "DejaVuSans.ttf"; +std::string ClientUI::FONT_BOLD = "DejaVuSans-Bold.ttf"; +std::string ClientUI::FONT_ITALIC = "DejaVuSans-Oblique.ttf"; +std::string ClientUI::FONT_BOLD_ITALIC = "DejaVuSans-BoldOblique.ttf"; +std::string ClientUI::TITLE_FONT = "DejaVuSans.ttf"; std::string ClientUI::DIR = "default/"; std::string ClientUI::ART_DIR = "default/data/art/"; Deleted: trunk/FreeOrion/Vera.ttf =================================================================== (Binary files differ) Deleted: trunk/FreeOrion/VeraBI.ttf =================================================================== (Binary files differ) Deleted: trunk/FreeOrion/VeraBd.ttf =================================================================== (Binary files differ) Deleted: trunk/FreeOrion/VeraIt.ttf =================================================================== (Binary files differ) |
From: <tz...@us...> - 2006-05-21 07:22:49
|
Revision: 1827 Author: tzlaine Date: 2006-05-21 00:22:41 -0700 (Sun, 21 May 2006) ViewCVS: http://svn.sourceforge.net/freeorion?rev=1827&view=rev Log Message: ----------- Brought the project up to date a bit, by changing the code to work with the latest version of GraphViz and the much stricter gcc 4.1. Also changes all calls to env.Append() in the SCons files to env.AppendUnique(). Modified Paths: -------------- trunk/FreeOrion/SConstruct trunk/FreeOrion/UI/TechTreeWnd.cpp trunk/FreeOrion/build_config.py trunk/FreeOrion/build_support.py trunk/FreeOrion/universe/ValueRefParser.cpp Modified: trunk/FreeOrion/SConstruct =================================================================== --- trunk/FreeOrion/SConstruct 2006-03-23 05:20:46 UTC (rev 1826) +++ trunk/FreeOrion/SConstruct 2006-05-21 07:22:41 UTC (rev 1827) @@ -203,7 +203,7 @@ else: if OptionValue('boost_signals_namespace', env): signals_namespace = OptionValue('boost_signals_namespace', env) - env.Append(CPPDEFINES = [ + env.AppendUnique(CPPDEFINES = [ ('BOOST_SIGNALS_NAMESPACE', signals_namespace), ('signals', signals_namespace) ]) @@ -219,14 +219,14 @@ if str(Platform()) == 'posix': if env['multithreaded']: if conf.CheckCHeader('pthread.h') and conf.CheckLib('pthread', 'pthread_create', autoadd = 0): - env.Append(CCFLAGS = ' -pthread') - env.Append(LINKFLAGS = ' -pthread') + env.AppendUnique(CCFLAGS = ' -pthread') + env.AppendUnique(LINKFLAGS = ' -pthread') else: Exit(1) # GL and GLU if str(Platform()) == 'win32': - env.Append(LIBS = [ + env.AppendUnique(LIBS = [ 'opengl32.lib', 'glu32.lib' ]) @@ -266,7 +266,7 @@ if not conf.CheckLib('freetype', 'FT_Init_FreeType'): Exit(1) else: - env.Append(LIBS = [ft_win32_lib_name]) + env.AppendUnique(LIBS = [ft_win32_lib_name]) # DevIL (aka IL) AppendPackagePaths('devil', env) @@ -325,30 +325,26 @@ if not conf.CheckLib('fmod-' + fmod_version, 'FSOUND_GetVersion', header = '#include <fmod.h>'): Exit(1) else: - env.Append(LIBS = [fmod_win32_lib_name]) + env.AppendUnique(LIBS = [fmod_win32_lib_name]) # GraphViz AppendPackagePaths('graphviz', env) if pkg_config: - if conf.CheckPkg('graphviz', graphviz_pkgconfig_version): - env.ParseConfig('pkg-config --cflags --libs graphviz') - elif conf.CheckPkg('libdotneato', graphviz_pkgconfig_version): - env.ParseConfig('pkg-config --cflags --libs libdotneato') - if not conf.CheckCHeader('graphviz/render.h') and not conf.CheckCHeader('render.h'): - Exit(1) - env.Append(LIBS = [ - 'cdt', - 'common', - 'dotgen', - 'dotneato', - 'graph', - 'gvrender', - 'pathplan' - ]) - if str(Platform()) != 'win32': - old_libs = env['LIBS'] - if not conf.CheckLib('dotgen', 'begin_component', header = '#include <graphviz/render.h>\n#include <graphviz/dotprocs.h>'): + if conf.CheckPkg('libgraph', graphviz_pkgconfig_version) and conf.CheckPkg('libgvc', graphviz_pkgconfig_version): + env.ParseConfig('pkg-config --cflags --libs libgraph') + env.ParseConfig('pkg-config --cflags --libs libgvc') + found_it_with_pkg_config = True + if not found_it_with_pkg_config: + if not conf.CheckCHeader('gvc.h'): Exit(1) + if str(Platform()) != 'win32': + if not conf.CheckLib('gvc', 'gvContext', header = '#include <gvc.h>'): + Exit(1) + env.AppendUnique(LIBS = [ + 'cdt', + 'graph', + 'gvc' + ]) # Log4cpp AppendPackagePaths('log4cpp', env) @@ -390,15 +386,15 @@ # define targets # ################################################## if env['release']: - env.Append(CPPDEFINES = [ + env.AppendUnique(CPPDEFINES = [ 'FREEORION_RELEASE' ]) if str(Platform()) == 'win32': - env.Append(CPPDEFINES = [ + env.AppendUnique(CPPDEFINES = [ 'FREEORION_WIN32' ]) else: - env.Append(CPPDEFINES = [ + env.AppendUnique(CPPDEFINES = [ 'FREEORION_LINUX', 'ENABLE_BINRELOC' ]) @@ -431,19 +427,19 @@ '/Zi', '/wd4099', '/wd4251', '/wd4800', '/wd4267', '/wd4275', '/wd4244', '/wd4101', '/wd4258', '/wd4351', '/wd4996' ] - env.Append(CCFLAGS = flags) - env.Append(CPPDEFINES = [ + env.AppendUnique(CCFLAGS = flags) + env.AppendUnique(CPPDEFINES = [ (env['debug'] and '_DEBUG' or 'NDEBUG'), 'WIN32', '_WINDOWS' ]) if env['dynamic']: - env.Append(CPPDEFINES = [ + env.AppendUnique(CPPDEFINES = [ '_USRDLL', '_WINDLL' ]) - env.Append(LINKFLAGS = ['/SUBSYSTEM:CONSOLE', '/DEBUG']) - env.Append(LIBS = [ + env.AppendUnique(LINKFLAGS = ['/SUBSYSTEM:CONSOLE', '/DEBUG']) + env.AppendUnique(LIBS = [ 'comdlg32', 'gd', 'gdi32', @@ -466,9 +462,9 @@ ]) else: if env['debug']: - env.Append(CCFLAGS = ['-Wall', '-g', '-O0']) + env.AppendUnique(CCFLAGS = ['-Wall', '-g', '-O0']) else: - env.Append(CCFLAGS = ['-Wall', '-O2']) + env.AppendUnique(CCFLAGS = ['-Wall', '-O2']) # generate Version.cpp version_cpp_in = open('util/Version.cpp.in', 'r') Modified: trunk/FreeOrion/UI/TechTreeWnd.cpp =================================================================== --- trunk/FreeOrion/UI/TechTreeWnd.cpp 2006-03-23 05:20:46 UTC (rev 1826) +++ trunk/FreeOrion/UI/TechTreeWnd.cpp 2006-05-21 07:22:41 UTC (rev 1827) @@ -19,15 +19,7 @@ #include <valarray> -extern "C" { -#ifdef FREEORION_WIN32 -#include <render.h> -#include <dotprocs.h> -#else -#include <graphviz/render.h> -#include <graphviz/dotprocs.h> -#endif -} +#include <gvc.h> #include <boost/format.hpp> @@ -93,6 +85,21 @@ return HumanClientApp::GetApp()->GetTextureOrDefault(ClientUI::ART_DIR + icon_filename); } + pointf Bezier(pointf* patch, double t) + { + pointf temp[6][6]; + for (int j = 0; j <= 3; j++) { + temp[0][j] = patch[j]; + } + for (int i = 1; i <= 3; i++) { + for (int j = 0; j <= 3 - i; j++) { + temp[i][j].x = (1.0 - t) * temp[i - 1][j].x + t * temp[i - 1][j + 1].x; + temp[i][j].y = (1.0 - t) * temp[i - 1][j].y + t * temp[i - 1][j + 1].y; + } + } + return temp[3][0]; + } + std::vector<std::pair<double, double> > Spline(const std::vector<std::pair<int, int> >& control_points) { std::vector<std::pair<double, double> > retval; @@ -108,7 +115,7 @@ retval.push_back(std::make_pair(patch[0].x, patch[0].y)); const int SUBDIVISIONS = 20; for (int step = 1; step <= SUBDIVISIONS; ++step) { - pointf pt = Bezier(patch, 3, static_cast<double>(step) / SUBDIVISIONS, 0, 0); + pointf pt = Bezier(patch, static_cast<double>(step) / SUBDIVISIONS); retval.push_back(std::make_pair(pt.x, pt.y)); } } @@ -1385,7 +1392,7 @@ Clear(); m_selected_tech = selected_tech; - aginit(); + GVC_t* gvc = gvContext(); // default graph properties agraphattr(0, "rankdir", "LR"); @@ -1427,7 +1434,7 @@ } } - dot_layout(graph); + gvLayout(gvc, graph, "dot"); // create new tech panels and new dependency arcs const int TECH_PANEL_MARGIN = 10; @@ -1489,7 +1496,9 @@ m_vscroll->SizeScroll(0, layout_size.y - 1, std::max(50, std::min(layout_size.y / 10, client_sz.y)), client_sz.y); m_hscroll->SizeScroll(0, layout_size.x - 1, std::max(50, std::min(layout_size.x / 10, client_sz.x)), client_sz.x); - dot_cleanup(graph); + gvFreeLayout(gvc, graph); + gvFreeContext(gvc); + agclose(graph); if (keep_position) { Modified: trunk/FreeOrion/build_config.py =================================================================== --- trunk/FreeOrion/build_config.py 2006-03-23 05:20:46 UTC (rev 1826) +++ trunk/FreeOrion/build_config.py 2006-05-21 07:22:41 UTC (rev 1827) @@ -21,7 +21,7 @@ log4cpp_version = '0.3.4b' -fmod_version = '3.74' +fmod_version = '3.75' fmod_win32_lib_name = 'fmodvc' -graphviz_pkgconfig_version = '0.15.0' +graphviz_pkgconfig_version = '2.8' Modified: trunk/FreeOrion/build_support.py =================================================================== --- trunk/FreeOrion/build_support.py 2006-03-23 05:20:46 UTC (rev 1826) +++ trunk/FreeOrion/build_support.py 2006-05-21 07:22:41 UTC (rev 1827) @@ -148,9 +148,9 @@ if not lib and root: lib = os.path.normpath(os.path.join(root, 'lib')) if inc: - env.Append(CPPPATH = [inc]) + env.AppendUnique(CPPPATH = [inc]) if lib: - env.Append(LIBPATH = [lib]) + env.AppendUnique(LIBPATH = [lib]) def CheckPkgConfig(context, version): context.Message('Checking for pkg-config... ') Modified: trunk/FreeOrion/universe/ValueRefParser.cpp =================================================================== --- trunk/FreeOrion/universe/ValueRefParser.cpp 2006-03-23 05:20:46 UTC (rev 1826) +++ trunk/FreeOrion/universe/ValueRefParser.cpp 2006-05-21 07:22:41 UTC (rev 1827) @@ -53,151 +53,151 @@ ValueRefParserDefinition<UniverseObjectType> universeobjecttype_value_ref_def(universeobjecttype_expr_p); ValueRefParserDefinition<StarType> startype_value_ref_def(startype_expr_p); ValueRefParserDefinition<FocusType> focustype_value_ref_def(focustype_expr_p); -} -template <class T> -ValueRefParserDefinition<T>::ValueRefParserDefinition(Rule& expr) -{ - SpecializedInit(); + template <class T> + ValueRefParserDefinition<T>::ValueRefParserDefinition(Rule& expr) + { + SpecializedInit(); - variable_container = - str_p("planet") - | "system"; + variable_container = + str_p("planet") + | "system"; - variable = - str_p("source") >> '.' >> (!(variable_container >> ".") >> variable_final) - [variable.this_ = new_<RefVar>(val(true), construct_<std::string>(arg1, arg2))] - | str_p("target") >> '.' >> (!(variable_container >> ".") >> variable_final) - [variable.this_ = new_<RefVar>(val(false), construct_<std::string>(arg1, arg2))]; + variable = + str_p("source") >> '.' >> (!(variable_container >> ".") >> variable_final) + [variable.this_ = new_<RefVar>(val(true), construct_<std::string>(arg1, arg2))] + | str_p("target") >> '.' >> (!(variable_container >> ".") >> variable_final) + [variable.this_ = new_<RefVar>(val(false), construct_<std::string>(arg1, arg2))]; - primary_expr = - constant[primary_expr.this_ = arg1] - | variable[primary_expr.this_ = arg1] - | '(' >> expr[primary_expr.this_ = arg1] >> ')'; + primary_expr = + constant[primary_expr.this_ = arg1] + | variable[primary_expr.this_ = arg1] + | '(' >> expr[primary_expr.this_ = arg1] >> ')'; - negative_expr = - primary_expr[negative_expr.this_ = arg1] - | (ch_p('-') >> primary_expr[negative_expr.operand1 = arg1])[negative_expr.this_ = new_<RefOp>(val(ValueRef::NEGATE), negative_expr.operand1)]; + negative_expr = + primary_expr[negative_expr.this_ = arg1] + | (ch_p('-') >> primary_expr[negative_expr.operand1 = arg1])[negative_expr.this_ = new_<RefOp>(val(ValueRef::NEGATE), negative_expr.operand1)]; - times_expr = - (negative_expr[times_expr.operand1 = arg1] >> ch_p('*') >> times_expr[times_expr.operand2 = arg1])[times_expr.this_ = new_<RefOp>(val(ValueRef::TIMES), times_expr.operand1, times_expr.operand2)] - | negative_expr[times_expr.this_ = arg1]; + times_expr = + (negative_expr[times_expr.operand1 = arg1] >> ch_p('*') >> times_expr[times_expr.operand2 = arg1])[times_expr.this_ = new_<RefOp>(val(ValueRef::TIMES), times_expr.operand1, times_expr.operand2)] + | negative_expr[times_expr.this_ = arg1]; - divides_expr = - (times_expr[divides_expr.operand1 = arg1] >> ch_p('/') >> divides_expr[divides_expr.operand2 = arg1])[divides_expr.this_ = new_<RefOp>(val(ValueRef::DIVIDES), divides_expr.operand1, divides_expr.operand2)] - | times_expr[divides_expr.this_ = arg1]; + divides_expr = + (times_expr[divides_expr.operand1 = arg1] >> ch_p('/') >> divides_expr[divides_expr.operand2 = arg1])[divides_expr.this_ = new_<RefOp>(val(ValueRef::DIVIDES), divides_expr.operand1, divides_expr.operand2)] + | times_expr[divides_expr.this_ = arg1]; - plus_expr = - (divides_expr[plus_expr.operand1 = arg1] >> ch_p('+') >> plus_expr[plus_expr.operand2 = arg1])[plus_expr.this_ = new_<RefOp>(val(ValueRef::PLUS), plus_expr.operand1, plus_expr.operand2)] - | divides_expr[plus_expr.this_ = arg1]; + plus_expr = + (divides_expr[plus_expr.operand1 = arg1] >> ch_p('+') >> plus_expr[plus_expr.operand2 = arg1])[plus_expr.this_ = new_<RefOp>(val(ValueRef::PLUS), plus_expr.operand1, plus_expr.operand2)] + | divides_expr[plus_expr.this_ = arg1]; - minus_expr = - (plus_expr[minus_expr.operand1 = arg1] >> ch_p('-') >> minus_expr[minus_expr.operand2 = arg1])[minus_expr.this_ = new_<RefOp>(val(ValueRef::MINUS), minus_expr.operand1, minus_expr.operand2)] - | plus_expr[minus_expr.this_ = arg1]; + minus_expr = + (plus_expr[minus_expr.operand1 = arg1] >> ch_p('-') >> minus_expr[minus_expr.operand2 = arg1])[minus_expr.this_ = new_<RefOp>(val(ValueRef::MINUS), minus_expr.operand1, minus_expr.operand2)] + | plus_expr[minus_expr.this_ = arg1]; - expr = minus_expr[expr.this_ = arg1]; -} + expr = minus_expr[expr.this_ = arg1]; + } -template <> -void ValueRefParserDefinition<int>::SpecializedInit() -{ - constant = - real_p[constant.this_ = new_<RefConst>(static_cast_<int>(arg1))] - | int_p[constant.this_ = new_<RefConst>(arg1)]; + template <> + void ValueRefParserDefinition<int>::SpecializedInit() + { + constant = + real_p[constant.this_ = new_<RefConst>(static_cast_<int>(arg1))] + | int_p[constant.this_ = new_<RefConst>(arg1)]; - variable_final = str_p("owner") | "id"; -} + variable_final = str_p("owner") | "id"; + } -template <> -void ValueRefParserDefinition<double>::SpecializedInit() -{ - constant = - real_p[constant.this_ = new_<RefConst>(arg1)] - | int_p[constant.this_ = new_<RefConst>(static_cast_<double>(arg1))]; + template <> + void ValueRefParserDefinition<double>::SpecializedInit() + { + constant = + real_p[constant.this_ = new_<RefConst>(arg1)] + | int_p[constant.this_ = new_<RefConst>(static_cast_<double>(arg1))]; - variable_final = - str_p("currentfarming") - | "maxfarming" - | "currentindustry" - | "maxindustry" - | "currentresearch" - | "maxresearch" - | "currenttrade" - | "maxtrade" - | "currentmining" - | "maxmining" - | "currentconstruction" - | "maxconstruction" - | "currenthealth" - | "maxhealth" - | "currentpopulation" - | "maxpopulation" - | "tradestockpile" - | "mineralstockpile" - | "foodstockpile" - | "tradeproduction" - | "foodproduction" - | "mineralproduction" - | "industryproduction" - | "researchproduction"; -} + variable_final = + str_p("currentfarming") + | "maxfarming" + | "currentindustry" + | "maxindustry" + | "currentresearch" + | "maxresearch" + | "currenttrade" + | "maxtrade" + | "currentmining" + | "maxmining" + | "currentconstruction" + | "maxconstruction" + | "currenthealth" + | "maxhealth" + | "currentpopulation" + | "maxpopulation" + | "tradestockpile" + | "mineralstockpile" + | "foodstockpile" + | "tradeproduction" + | "foodproduction" + | "mineralproduction" + | "industryproduction" + | "researchproduction"; + } -template <> -void ValueRefParserDefinition<PlanetSize>::SpecializedInit() -{ - constant = - planet_size_p[constant.this_ = new_<RefConst>(arg1)] - | int_p[constant.this_ = new_<RefConst>(static_cast_<PlanetSize>(arg1))]; + template <> + void ValueRefParserDefinition<PlanetSize>::SpecializedInit() + { + constant = + planet_size_p[constant.this_ = new_<RefConst>(arg1)] + | int_p[constant.this_ = new_<RefConst>(static_cast_<PlanetSize>(arg1))]; - variable_final = str_p("planetsize"); -} + variable_final = str_p("planetsize"); + } -template <> -void ValueRefParserDefinition<PlanetType>::SpecializedInit() -{ - constant = - planet_type_p[constant.this_ = new_<RefConst>(arg1)] - | int_p[constant.this_ = new_<RefConst>(static_cast_<PlanetType>(arg1))]; + template <> + void ValueRefParserDefinition<PlanetType>::SpecializedInit() + { + constant = + planet_type_p[constant.this_ = new_<RefConst>(arg1)] + | int_p[constant.this_ = new_<RefConst>(static_cast_<PlanetType>(arg1))]; - variable_final = str_p("planettype"); -} + variable_final = str_p("planettype"); + } -template <> -void ValueRefParserDefinition<PlanetEnvironment>::SpecializedInit() -{ - constant = - planet_environment_type_p[constant.this_ = new_<RefConst>(arg1)] - | int_p[constant.this_ = new_<RefConst>(static_cast_<PlanetEnvironment>(arg1))]; + template <> + void ValueRefParserDefinition<PlanetEnvironment>::SpecializedInit() + { + constant = + planet_environment_type_p[constant.this_ = new_<RefConst>(arg1)] + | int_p[constant.this_ = new_<RefConst>(static_cast_<PlanetEnvironment>(arg1))]; - variable_final = str_p("planetenvironment"); -} + variable_final = str_p("planetenvironment"); + } -template <> -void ValueRefParserDefinition<UniverseObjectType>::SpecializedInit() -{ - constant = - universe_object_type_p[constant.this_ = new_<RefConst>(arg1)] - | int_p[constant.this_ = new_<RefConst>(static_cast_<UniverseObjectType>(arg1))]; + template <> + void ValueRefParserDefinition<UniverseObjectType>::SpecializedInit() + { + constant = + universe_object_type_p[constant.this_ = new_<RefConst>(arg1)] + | int_p[constant.this_ = new_<RefConst>(static_cast_<UniverseObjectType>(arg1))]; - variable_final = str_p("objecttype"); -} + variable_final = str_p("objecttype"); + } -template <> -void ValueRefParserDefinition<StarType>::SpecializedInit() -{ - constant = - star_type_p[constant.this_ = new_<RefConst>(arg1)] - | int_p[constant.this_ = new_<RefConst>(static_cast_<StarType>(arg1))]; + template <> + void ValueRefParserDefinition<StarType>::SpecializedInit() + { + constant = + star_type_p[constant.this_ = new_<RefConst>(arg1)] + | int_p[constant.this_ = new_<RefConst>(static_cast_<StarType>(arg1))]; - variable_final = str_p("startype"); -} + variable_final = str_p("startype"); + } -template <> -void ValueRefParserDefinition<FocusType>::SpecializedInit() -{ - constant = - focus_type_p[constant.this_ = new_<RefConst>(arg1)] - | int_p[constant.this_ = new_<RefConst>(static_cast_<FocusType>(arg1))]; + template <> + void ValueRefParserDefinition<FocusType>::SpecializedInit() + { + constant = + focus_type_p[constant.this_ = new_<RefConst>(arg1)] + | int_p[constant.this_ = new_<RefConst>(static_cast_<FocusType>(arg1))]; - variable_final = str_p("primaryfocus") | "secondaryfocus"; + variable_final = str_p("primaryfocus") | "secondaryfocus"; + } } |
From: <tz...@us...> - 2006-08-23 02:20:57
|
Revision: 1869 Author: tzlaine Date: 2006-08-22 19:20:52 -0700 (Tue, 22 Aug 2006) ViewCVS: http://svn.sourceforge.net/freeorion?rev=1869&view=rev Log Message: ----------- Made a few small changes to aid in building FO on Macs. Modified Paths: -------------- trunk/FreeOrion/SConstruct trunk/FreeOrion/build_support.py trunk/FreeOrion/client/human/HumanClientApp.cpp Modified: trunk/FreeOrion/SConstruct =================================================================== --- trunk/FreeOrion/SConstruct 2006-07-31 18:21:50 UTC (rev 1868) +++ trunk/FreeOrion/SConstruct 2006-08-23 02:20:52 UTC (rev 1869) @@ -286,7 +286,7 @@ stdout.write('Checking for DevIL OpenGL support... ') devil_gl_check_app = """ #include <IL/ilut.h> -#if !ILUT_USE_OPENGL +#ifndef ILUT_USE_OPENGL #error "DevIL not built with OpenGL support" #endif int main() { Modified: trunk/FreeOrion/build_support.py =================================================================== --- trunk/FreeOrion/build_support.py 2006-07-31 18:21:50 UTC (rev 1868) +++ trunk/FreeOrion/build_support.py 2006-08-23 02:20:52 UTC (rev 1869) @@ -276,7 +276,7 @@ context.env.ParseConfig('sdl-config ' + sdl_config_prefix_flag + ' --cflags ' + (build_dynamic and '--libs' or '--static-libs')) found_it_with_sdl_config = True if not found_it_with_sdl_config: - if not conf.CheckCHeader('SDL/SDL.h') and not conf.CheckCHeader('SDL.h'): + if not conf.CheckCHeader(os.path.join('SDL', 'SDL.h')) and not conf.CheckCHeader('SDL.h'): context.Message('SDL configuration... ') context.Result(False) return False @@ -285,7 +285,7 @@ context.Result(False) return False version_regex = re.compile(r'SDL_MAJOR_VERSION\s*(\d+).*SDL_MINOR_VERSION\s*(\d+).*SDL_PATCHLEVEL\s*(\d+)', re.DOTALL) - if not conf.CheckVersionHeader('SDL', 'SDL_version.h', version_regex, sdl_version, True): + if not conf.CheckVersionHeader('SDL', os.path.join('SDL', 'SDL_version.h'), version_regex, sdl_version, True): context.Message('SDL configuration... ') context.Result(False) return False @@ -294,7 +294,7 @@ link_test_app = """ #include <SDL/SDL.h> #include <SDL/SDL_opengl.h> -int main() +int main(int argc, char** argv) { SDL_Init(SDL_INIT_VIDEO); SDL_GL_SetAttribute(SDL_GL_RED_SIZE, 5); @@ -319,9 +319,9 @@ def CheckLibLTDL(context): retval = True - context.Message('Generating libltdl/config.h using libltdl/configure... ') + context.Message('Generating GG/libltdl/config.h using GG/libltdl/configure... ') initial_dir = os.getcwd() - os.chdir('libltdl') + os.chdir(os.path.join('GG', 'libltdl')) configure_run = os.system('./configure > /dev/null') code = os.WEXITSTATUS(configure_run) if code: Modified: trunk/FreeOrion/client/human/HumanClientApp.cpp =================================================================== --- trunk/FreeOrion/client/human/HumanClientApp.cpp 2006-07-31 18:21:50 UTC (rev 1868) +++ trunk/FreeOrion/client/human/HumanClientApp.cpp 2006-08-23 02:20:52 UTC (rev 1869) @@ -446,13 +446,8 @@ EventType gg_event = MOUSEMOVE; GG::Key key = GGKeyFromSDLKey(event.key.keysym); Uint32 key_mods = SDL_GetModState(); -#ifdef __APPLE__ - GG::Pt mouse_pos(event.motion.x, m_app_height - event.motion.y); - GG::Pt mouse_rel(event.motion.xrel, -event.motion.yrel); -#else GG::Pt mouse_pos(event.motion.x, event.motion.y); GG::Pt mouse_rel(event.motion.xrel, event.motion.yrel); -#endif switch (event.type) { case SDL_KEYDOWN: |
From: <tz...@us...> - 2006-10-18 02:40:05
|
Revision: 1910 http://svn.sourceforge.net/freeorion/revision/?rev=1910&view=rev Author: tzlaine Date: 2006-10-17 19:40:02 -0700 (Tue, 17 Oct 2006) Log Message: ----------- - Widened the OptionWnd. - Made the OptionWnd resizable. - Widened the default tooltip text box. - Made autosave.single-player default to true. Modified Paths: -------------- trunk/FreeOrion/UI/OptionsWnd.cpp trunk/FreeOrion/client/human/HumanClientApp.cpp Modified: trunk/FreeOrion/UI/OptionsWnd.cpp =================================================================== --- trunk/FreeOrion/UI/OptionsWnd.cpp 2006-10-17 05:03:26 UTC (rev 1909) +++ trunk/FreeOrion/UI/OptionsWnd.cpp 2006-10-18 02:40:02 UTC (rev 1910) @@ -25,7 +25,7 @@ namespace fs = boost::filesystem; namespace { - const int PAGE_WIDTH = 300; + const int PAGE_WIDTH = 400; const int PAGE_HEIGHT = 450; const int INDENTATION = 20; const int ROW_WIDTH = PAGE_WIDTH - 4 - 14 - 5; @@ -221,13 +221,15 @@ CUIWnd(UserString("OPTIONS_TITLE"), (GG::GUI::GetGUI()->AppWidth() - (PAGE_WIDTH + 20)) / 2, (GG::GUI::GetGUI()->AppHeight() - (PAGE_HEIGHT + 70)) / 2, - PAGE_WIDTH + 20, PAGE_HEIGHT + 70, GG::CLICKABLE | GG::DRAGABLE | GG::MODAL), + PAGE_WIDTH + 20, PAGE_HEIGHT + 70, GG::CLICKABLE | GG::DRAGABLE | GG::MODAL | GG::RESIZABLE), m_current_option_list(0), m_indentation_level(0), m_tabs(0), m_done_button(0), m_num_wnds(0) { + SetMaxSize(GG::Pt(PAGE_WIDTH + 20, MaxSize().y)); + SetMinSize(GG::Pt(PAGE_WIDTH + 20, PAGE_HEIGHT + 70)); m_done_button = new CUIButton(15, PAGE_HEIGHT + 17, 75, UserString("DONE")); m_tabs = new GG::TabWnd(5, 2, PAGE_WIDTH, PAGE_HEIGHT + 20, GG::GUI::GetGUI()->GetFont(ClientUI::Font(), ClientUI::Pts()), ClientUI::WndColor(), ClientUI::TextColor(), GG::TAB_BAR_DETACHED); Init(); Modified: trunk/FreeOrion/client/human/HumanClientApp.cpp =================================================================== --- trunk/FreeOrion/client/human/HumanClientApp.cpp 2006-10-17 05:03:26 UTC (rev 1909) +++ trunk/FreeOrion/client/human/HumanClientApp.cpp 2006-10-18 02:40:02 UTC (rev 1910) @@ -83,7 +83,7 @@ // command-line options void AddOptions(OptionsDB& db) { - db.Add("autosave.single-player", "If true, autosaves will occur during single-player games.", false, Validator<bool>()); + db.Add("autosave.single-player", "If true, autosaves will occur during single-player games.", true, Validator<bool>()); db.Add("autosave.multiplayer", "If true, autosaves will occur during multiplayer games.", false, Validator<bool>()); db.Add("autosave.turns", "Sets the number of turns that should elapse between autosaves.", 5, RangedValidator<int>(1, 50)); db.Add("autosave.saves", "Sets the number of autosaved games that should be kept.", 10, RangedValidator<int>(1, 50)); @@ -425,7 +425,7 @@ PlayMusic(ClientUI::SoundDir() / GetOptionsDB().Get<std::string>("bg-music"), -1); boost::shared_ptr<GG::BrowseInfoWnd> default_browse_info_wnd( - new GG::TextBoxBrowseInfoWnd(300, GG::GUI::GetGUI()->GetFont(ClientUI::Font(), ClientUI::Pts()), + new GG::TextBoxBrowseInfoWnd(400, GG::GUI::GetGUI()->GetFont(ClientUI::Font(), ClientUI::Pts()), GG::Clr(0, 0, 0, 200), ClientUI::WndOuterBorderColor(), ClientUI::TextColor(), GG::TF_LEFT | GG::TF_WORDBREAK, 1)); GG::Wnd::SetDefaultBrowseInfoWnd(default_browse_info_wnd); |
From: <tz...@us...> - 2006-10-18 04:32:10
|
Revision: 1911 http://svn.sourceforge.net/freeorion/revision/?rev=1911&view=rev Author: tzlaine Date: 2006-10-17 21:31:57 -0700 (Tue, 17 Oct 2006) Log Message: ----------- Moved the OptionsDB options descriptions into the string tables to allow them to be translated. Modified Paths: -------------- trunk/FreeOrion/UI/ClientUI.cpp trunk/FreeOrion/UI/GalaxySetupWnd.cpp trunk/FreeOrion/UI/InGameMenu.cpp trunk/FreeOrion/UI/IntroScreen.cpp trunk/FreeOrion/UI/MapWnd.cpp trunk/FreeOrion/UI/TechTreeWnd.cpp trunk/FreeOrion/client/human/HumanClientApp.cpp trunk/FreeOrion/client/human/chmain.cpp trunk/FreeOrion/default/eng_stringtable.txt trunk/FreeOrion/default/ger_stringtable.txt trunk/FreeOrion/util/MultiplayerCommon.cpp trunk/FreeOrion/util/OptionsDB.cpp Modified: trunk/FreeOrion/UI/ClientUI.cpp =================================================================== --- trunk/FreeOrion/UI/ClientUI.cpp 2006-10-18 02:40:02 UTC (rev 1910) +++ trunk/FreeOrion/UI/ClientUI.cpp 2006-10-18 04:31:57 UTC (rev 1911) @@ -120,77 +120,77 @@ // command-line options void AddOptions(OptionsDB& db) { - db.Add("app-width", "Sets horizontal app resolution.", 1024, RangedValidator<int>(800, 2048)); - db.Add("app-height", "Sets vertical app resolution.", 768, RangedValidator<int>(600, 1536)); - db.Add('c', "color-depth", "Sets screen color depth, in bits per pixel.", 32, RangedStepValidator<int>(8, 16, 32)); + db.Add("app-width", "OPTIONS_DB_APP_WIDTH", 1024, RangedValidator<int>(800, 2048)); + db.Add("app-height", "OPTIONS_DB_APP_HEIGHT", 768, RangedValidator<int>(600, 1536)); + db.Add('c', "color-depth", "OPTIONS_DB_COLOR_DEPTH", 32, RangedStepValidator<int>(8, 16, 32)); // sound - db.Add("UI.sound.enabled", "Toggles UI sound effects on or off.", true, Validator<bool>()); - db.Add("UI.sound.volume", "The volume (0 to 255) at which UI sound effects should be played.", 255, RangedValidator<int>(0, 255)); - db.Add<std::string>("UI.sound.button-rollover", "The sound file played when the mouse moves over a button.", "button_rollover.wav"); - db.Add<std::string>("UI.sound.button-click", "The sound file played when a button is clicked.", "button_click.wav"); - db.Add<std::string>("UI.sound.turn-button-click", "The sound file played when the turn button is clicked.", "turn_button_click.wav"); - db.Add<std::string>("UI.sound.list-select", "The sound file played when a listbox or drop-down list item is selected.", "list_select.wav"); - db.Add<std::string>("UI.sound.item-drop", "The sound file played when an item is dropped into a listbox.", "item_drop.wav"); - db.Add<std::string>("UI.sound.list-pulldown", "The sound file played when the list is opened in a drop-down list.", "list_pulldown.wav"); - db.Add<std::string>("UI.sound.text-typing", "The sound file played when the user types text.", "text_typing.wav"); - db.Add<std::string>("UI.sound.window-maximize", "The sound file played when a window is maximized.", "window_maximize.wav"); - db.Add<std::string>("UI.sound.window-minimize", "The sound file played when a window is minimized.", "window_minimize.wav"); - db.Add<std::string>("UI.sound.window-close", "The sound file played when a window is closed.", "window_close.wav"); - db.Add<std::string>("UI.sound.alert", "The sound file played when an error or illegal action occurs.", "alert.wav"); - db.Add<std::string>("UI.sound.planet-button-click", "The sound file played when a planet button is clicked.", "button_click.wav"); - db.Add<std::string>("UI.sound.fleet-button-rollover", "The sound file played when mouse moves over a fleet button.", "fleet_button_rollover.wav"); - db.Add<std::string>("UI.sound.fleet-button-click", "The sound file played when a fleet button is clicked.", "fleet_button_click.wav"); - db.Add<std::string>("UI.sound.sidepanel-open", "The sound file played when the system side-panel is opened.", "sidepanel_open.wav"); - db.Add<std::string>("UI.sound.farming-focus", "The sound file played when a farming focus button is clicked.", "farm_select.wav"); - db.Add<std::string>("UI.sound.industry-focus", "The sound file played when an industry focus button is clicked.", "industry_select.wav"); - db.Add<std::string>("UI.sound.research-focus", "The sound file played when a research focus button is clicked.", "research_select.wav"); - db.Add<std::string>("UI.sound.mining-focus", "The sound file played when a mining focus button is clicked.", "mining_select.wav"); + db.Add("UI.sound.enabled", "OPTIONS_DB_UI_SOUND_ENABLED", true, Validator<bool>()); + db.Add("UI.sound.volume", "OPTIONS_DB_UI_SOUND_VOLUME", 255, RangedValidator<int>(0, 255)); + db.Add<std::string>("UI.sound.button-rollover", "OPTIONS_DB_UI_SOUND_BUTTON_ROLLOVER", "button_rollover.wav"); + db.Add<std::string>("UI.sound.button-click", "OPTIONS_DB_UI_SOUND_BUTTON_CLICK", "button_click.wav"); + db.Add<std::string>("UI.sound.turn-button-click", "OPTIONS_DB_UI_SOUND_TURN_BUTTON_CLICK", "turn_button_click.wav"); + db.Add<std::string>("UI.sound.list-select", "OPTIONS_DB_UI_SOUND_LIST_SELECT", "list_select.wav"); + db.Add<std::string>("UI.sound.item-drop", "OPTIONS_DB_UI_SOUND_ITEM_DROP", "item_drop.wav"); + db.Add<std::string>("UI.sound.list-pulldown", "OPTIONS_DB_UI_SOUND_LIST_PULLDOWN", "list_pulldown.wav"); + db.Add<std::string>("UI.sound.text-typing", "OPTIONS_DB_UI_SOUND_TEXT_TYPING", "text_typing.wav"); + db.Add<std::string>("UI.sound.window-maximize", "OPTIONS_DB_UI_SOUND_WINDOW_MAXIMIZE", "window_maximize.wav"); + db.Add<std::string>("UI.sound.window-minimize", "OPTIONS_DB_UI_SOUND_WINDOW_MINIMIZE", "window_minimize.wav"); + db.Add<std::string>("UI.sound.window-close", "OPTIONS_DB_UI_SOUND_WINDOW_CLOSE", "window_close.wav"); + db.Add<std::string>("UI.sound.alert", "OPTIONS_DB_UI_SOUND_ALERT", "alert.wav"); + db.Add<std::string>("UI.sound.planet-button-click", "OPTIONS_DB_UI_SOUND_PLANET_BUTTON_CLICK", "button_click.wav"); + db.Add<std::string>("UI.sound.fleet-button-rollover", "OPTIONS_DB_UI_SOUND_FLEET_BUTTON_ROLLOVER", "fleet_button_rollover.wav"); + db.Add<std::string>("UI.sound.fleet-button-click", "OPTIONS_DB_UI_SOUND_FLEET_BUTTON_CLICK", "fleet_button_click.wav"); + db.Add<std::string>("UI.sound.sidepanel-open", "OPTIONS_DB_UI_SOUND_SIDEPANEL_OPEN", "sidepanel_open.wav"); + db.Add<std::string>("UI.sound.farming-focus", "OPTIONS_DB_UI_SOUND_FARMING_FOCUS", "farm_select.wav"); + db.Add<std::string>("UI.sound.industry-focus", "OPTIONS_DB_UI_SOUND_INDUSTRY_FOCUS", "industry_select.wav"); + db.Add<std::string>("UI.sound.research-focus", "OPTIONS_DB_UI_SOUND_RESEARCH_FOCUS", "research_select.wav"); + db.Add<std::string>("UI.sound.mining-focus", "OPTIONS_DB_UI_SOUND_MINING_FOCUS", "mining_select.wav"); // TODO: uncomment when trade is added to side panel //db.Add<std::string>("UI.sound.trade-focus", "The sound file played when a trade focus button is clicked.", "trade_select.wav"); - db.Add<std::string>("UI.sound.balanced-focus", "The sound file played when a balanced focus button is clicked.", "balanced_select.wav"); + db.Add<std::string>("UI.sound.balanced-focus", "OPTIONS_DB_UI_SOUND_BALANCED_FOCUS", "balanced_select.wav"); // fonts - db.Add<std::string>("UI.font", "Sets UI font resource file.", "DejaVuSans.ttf"); - db.Add<std::string>("UI.font-bold", "Sets UI bold font resource file.", "DejaVuSans-Bold.ttf"); - db.Add<std::string>("UI.font-italic", "Sets UI bold font resource file.", "DejaVuSans-Oblique.ttf"); - db.Add<std::string>("UI.font-bold-italic", "Sets UI bold font resource file.", "DejaVuSans-BoldOblique.ttf"); - db.Add("UI.font-size", "Sets UI font size.", 12, RangedValidator<int>(4, 40)); - db.Add<std::string>("UI.title-font", "Sets UI title font resource file.", "DejaVuSans.ttf"); - db.Add("UI.title-font-size", "Sets UI title font size.", 12, RangedValidator<int>(4, 40)); + db.Add<std::string>("UI.font", "OPTIONS_DB_UI_FONT", "DejaVuSans.ttf"); + db.Add<std::string>("UI.font-bold", "OPTIONS_DB_UI_FONT_BOLD", "DejaVuSans-Bold.ttf"); + db.Add<std::string>("UI.font-italic", "OPTIONS_DB_UI_FONT_ITALIC", "DejaVuSans-Oblique.ttf"); + db.Add<std::string>("UI.font-bold-italic", "OPTIONS_DB_UI_FONT_BOLD_ITALIC", "DejaVuSans-BoldOblique.ttf"); + db.Add("UI.font-size", "OPTIONS_DB_UI_FONT_SIZE", 12, RangedValidator<int>(4, 40)); + db.Add<std::string>("UI.title-font", "OPTIONS_DB_UI_TITLE_FONT", "DejaVuSans.ttf"); + db.Add("UI.title-font-size", "OPTIONS_DB_UI_TITLE_FONT_SIZE", 12, RangedValidator<int>(4, 40)); // colors - db.Add("UI.wnd-color", "Sets UI window color.", StreamableColor(GG::Clr(0, 0, 0, 210)), Validator<StreamableColor>()); - db.Add("UI.text-color", "Sets UI text color.", StreamableColor(GG::Clr(255, 255, 255, 255)), Validator<StreamableColor>()); - db.Add("UI.ctrl-color", "Sets UI control color.", StreamableColor(GG::Clr(30, 30, 30, 255)), Validator<StreamableColor>()); - db.Add("UI.ctrl-border-color", "Sets UI control border color.", StreamableColor(GG::Clr(124, 124, 124, 255)), Validator<StreamableColor>()); - db.Add("UI.button-color", "Sets UI button color.", StreamableColor(GG::Clr(0, 0, 0, 255)), Validator<StreamableColor>()); - db.Add("UI.state-button-color", "Sets UI state button color.", StreamableColor(GG::Clr(0, 127, 0, 255)), Validator<StreamableColor>()); - db.Add("UI.scroll-tab-color", "Sets UI scroll tab color.", StreamableColor(GG::Clr(60, 60, 60, 255)), Validator<StreamableColor>()); - db.Add("UI.dropdownlist-interior-color", "Sets UI drop-down-list interior color.", StreamableColor(GG::Clr(0, 0, 0, 255)), Validator<StreamableColor>()); - db.Add("UI.dropdownlist-arrow-color", "Sets UI drop-down-list arrow color.", StreamableColor(GG::Clr(130, 130, 0, 255)), Validator<StreamableColor>()); - db.Add("UI.edit-hilite", "Sets color of hilighting in UI edit controls.", StreamableColor(GG::Clr(43, 81, 102, 255)), Validator<StreamableColor>()); - db.Add("UI.edit-interior", "Sets UI edit controls' interior color.", StreamableColor(GG::Clr(0, 0, 0, 255)), Validator<StreamableColor>()); - db.Add("UI.multiedit-interior", "Sets UI multi-line edit controls' interior color.", StreamableColor(GG::Clr(0, 0, 0, 255)), Validator<StreamableColor>()); - db.Add("UI.stat-increase-color", "Sets the color of increased stats in the UI.", StreamableColor(GG::Clr(127, 255, 127, 255)), Validator<StreamableColor>()); - db.Add("UI.stat-decrease-color", "Sets the color of decreased stats in the UI.", StreamableColor(GG::Clr(255, 127, 127, 255)), Validator<StreamableColor>()); - db.Add("UI.sidepanel-color", "Sets the color of the side-panel.", StreamableColor(GG::Clr(0, 0, 0, 220)), Validator<StreamableColor>()); - db.Add("UI.wnd-outer-border-color", "Sets UI outer border color.", StreamableColor(GG::Clr(64, 64, 64, 255)), Validator<StreamableColor>()); - db.Add("UI.wnd-border-color", "Sets UI border color.", StreamableColor(GG::Clr(0, 0, 0, 255)), Validator<StreamableColor>()); - db.Add("UI.wnd-inner-border-color", "Sets UI inner border color.", StreamableColor(GG::Clr(255, 255, 255, 255)), Validator<StreamableColor>()); - db.Add("UI.known-tech", "Sets color of known techs in the tech tree.", StreamableColor(GG::Clr(72, 72, 72, 255)), Validator<StreamableColor>()); - db.Add("UI.known-tech-border", "Sets text and border color of known techs in the tech tree.", StreamableColor(GG::Clr(164, 164, 164, 255)), Validator<StreamableColor>()); - db.Add("UI.researchable-tech", "Sets color of researchable techs in the tech tree.", StreamableColor(GG::Clr(48, 48, 48, 255)), Validator<StreamableColor>()); - db.Add("UI.researchable-tech-border", "Sets text and border color of researchable techs in the tech tree.", StreamableColor(GG::Clr(164, 164, 164, 255)), Validator<StreamableColor>()); - db.Add("UI.unresearchable-tech", "Sets color of unresearchable techs in the tech tree.", StreamableColor(GG::Clr(30, 30, 30, 255)), Validator<StreamableColor>()); - db.Add("UI.unresearchable-tech-border", "Sets text and border color of unresearchable techs in the tech tree.", StreamableColor(GG::Clr(86, 86, 86, 255)), Validator<StreamableColor>()); - db.Add("UI.tech-progress-background", "Sets background color of progress bars in the tech tree.", StreamableColor(GG::Clr(72, 72, 72, 255)), Validator<StreamableColor>()); - db.Add("UI.tech-progress", "Sets color of progress bars in the tech tree.", StreamableColor(GG::Clr(40, 40, 40, 255)), Validator<StreamableColor>()); + db.Add("UI.wnd-color", "OPTIONS_DB_UI_WND_COLOR", StreamableColor(GG::Clr(0, 0, 0, 210)), Validator<StreamableColor>()); + db.Add("UI.text-color", "OPTIONS_DB_UI_TEXT_COLOR", StreamableColor(GG::Clr(255, 255, 255, 255)), Validator<StreamableColor>()); + db.Add("UI.ctrl-color", "OPTIONS_DB_UI_CTRL_COLOR", StreamableColor(GG::Clr(30, 30, 30, 255)), Validator<StreamableColor>()); + db.Add("UI.ctrl-border-color", "OPTIONS_DB_UI_CTRL_BORDER_COLOR", StreamableColor(GG::Clr(124, 124, 124, 255)), Validator<StreamableColor>()); + db.Add("UI.button-color", "OPTIONS_DB_UI_BUTTON_COLOR", StreamableColor(GG::Clr(0, 0, 0, 255)), Validator<StreamableColor>()); + db.Add("UI.state-button-color", "OPTIONS_DB_UI_STATE_BUTTON_COLOR", StreamableColor(GG::Clr(0, 127, 0, 255)), Validator<StreamableColor>()); + db.Add("UI.scroll-tab-color", "OPTIONS_DB_UI_SCROLL_TAB_COLOR", StreamableColor(GG::Clr(60, 60, 60, 255)), Validator<StreamableColor>()); + db.Add("UI.dropdownlist-interior-color", "OPTIONS_DB_UI_DROPDOWNLIST_INTERIOR_COLOR", StreamableColor(GG::Clr(0, 0, 0, 255)), Validator<StreamableColor>()); + db.Add("UI.dropdownlist-arrow-color", "OPTIONS_DB_UI_DROPDOWNLIST_ARROW_COLOR", StreamableColor(GG::Clr(130, 130, 0, 255)), Validator<StreamableColor>()); + db.Add("UI.edit-hilite", "OPTIONS_DB_UI_EDIT_HILITE", StreamableColor(GG::Clr(43, 81, 102, 255)), Validator<StreamableColor>()); + db.Add("UI.edit-interior", "OPTIONS_DB_UI_EDIT_INTERIOR", StreamableColor(GG::Clr(0, 0, 0, 255)), Validator<StreamableColor>()); + db.Add("UI.multiedit-interior", "OPTIONS_DB_UI_MULTIEDIT_INTERIOR", StreamableColor(GG::Clr(0, 0, 0, 255)), Validator<StreamableColor>()); + db.Add("UI.stat-increase-color", "OPTIONS_DB_UI_STAT_INCREASE_COLOR", StreamableColor(GG::Clr(127, 255, 127, 255)), Validator<StreamableColor>()); + db.Add("UI.stat-decrease-color", "OPTIONS_DB_UI_STAT_DECREASE_COLOR", StreamableColor(GG::Clr(255, 127, 127, 255)), Validator<StreamableColor>()); + db.Add("UI.sidepanel-color", "OPTIONS_DB_UI_SIDEPANEL_COLOR", StreamableColor(GG::Clr(0, 0, 0, 220)), Validator<StreamableColor>()); + db.Add("UI.wnd-outer-border-color", "OPTIONS_DB_UI_WND_OUTER_BORDER_COLOR", StreamableColor(GG::Clr(64, 64, 64, 255)), Validator<StreamableColor>()); + db.Add("UI.wnd-border-color", "OPTIONS_DB_UI_WND_BORDER_COLOR", StreamableColor(GG::Clr(0, 0, 0, 255)), Validator<StreamableColor>()); + db.Add("UI.wnd-inner-border-color", "OPTIONS_DB_UI_WND_INNER_BORDER_COLOR", StreamableColor(GG::Clr(255, 255, 255, 255)), Validator<StreamableColor>()); + db.Add("UI.known-tech", "OPTIONS_DB_UI_KNOWN_TECH", StreamableColor(GG::Clr(72, 72, 72, 255)), Validator<StreamableColor>()); + db.Add("UI.known-tech-border", "OPTIONS_DB_UI_KNOWN_TECH_BORDER", StreamableColor(GG::Clr(164, 164, 164, 255)), Validator<StreamableColor>()); + db.Add("UI.researchable-tech", "OPTIONS_DB_UI_RESEARCHABLE_TECH", StreamableColor(GG::Clr(48, 48, 48, 255)), Validator<StreamableColor>()); + db.Add("UI.researchable-tech-border", "OPTIONS_DB_UI_RESEARCHABLE_TECH_BORDER", StreamableColor(GG::Clr(164, 164, 164, 255)), Validator<StreamableColor>()); + db.Add("UI.unresearchable-tech", "OPTIONS_DB_UI_UNRESEARCHABLE_TECH", StreamableColor(GG::Clr(30, 30, 30, 255)), Validator<StreamableColor>()); + db.Add("UI.unresearchable-tech-border", "OPTIONS_DB_UI_UNRESEARCHABLE_TECH_BORDER", StreamableColor(GG::Clr(86, 86, 86, 255)), Validator<StreamableColor>()); + db.Add("UI.tech-progress-background", "OPTIONS_DB_UI_TECH_PROGRESS_BACKGROUND", StreamableColor(GG::Clr(72, 72, 72, 255)), Validator<StreamableColor>()); + db.Add("UI.tech-progress", "OPTIONS_DB_UI_TECH_PROGRESS", StreamableColor(GG::Clr(40, 40, 40, 255)), Validator<StreamableColor>()); // misc - db.Add("UI.scroll-width", "Sets UI scroll width.", 14, RangedValidator<int>(8, 30)); - db.Add("UI.system-icon-size", "Sets size of system icons.", 14, RangedValidator<int>(8, 50)); - db.Add("UI.fleet-button-size", "Sets size of fleet buttons.", 0.5, RangedValidator<double>(0.2, 2)); + db.Add("UI.scroll-width", "OPTIONS_DB_UI_SCROLL_WIDTH", 14, RangedValidator<int>(8, 30)); + db.Add("UI.system-icon-size", "OPTIONS_DB_UI_SYSTEM_ICON_SIZE", 14, RangedValidator<int>(8, 50)); + db.Add("UI.fleet-button-size", "OPTIONS_DB_UI_FLEET_BUTTON_SIZE", 0.5, RangedValidator<double>(0.2, 2)); // tech category colors const GG::Clr LEARNING_CATEGORY(93, 155, 246, 255); @@ -198,21 +198,17 @@ const GG::Clr PRODUCTION_CATEGORY(240, 106, 106, 255); const GG::Clr CONSTRUCTION_CATEGORY(241, 233, 87, 255); const GG::Clr ECONOMICS_CATEGORY(255, 112, 247, 255); - db.Add("UI.tech-category-1", "Sets color of the first category of techs defined in techs.xml.", StreamableColor(LEARNING_CATEGORY), Validator<StreamableColor>()); - db.Add("UI.tech-category-2", "Sets color of the second category of techs defined in techs.xml.", StreamableColor(GROWTH_CATEGORY), Validator<StreamableColor>()); - db.Add("UI.tech-category-3", "Sets color of the third category of techs defined in techs.xml.", StreamableColor(PRODUCTION_CATEGORY), Validator<StreamableColor>()); - db.Add("UI.tech-category-4", "Sets color of the fourth category of techs defined in techs.xml.", StreamableColor(CONSTRUCTION_CATEGORY), Validator<StreamableColor>()); - db.Add("UI.tech-category-5", "Sets color of the fifth category of techs defined in techs.xml.", StreamableColor(ECONOMICS_CATEGORY), Validator<StreamableColor>()); + db.Add("UI.tech-category-1", "OPTIONS_DB_UI_TECH_CATEGORY_1", StreamableColor(LEARNING_CATEGORY), Validator<StreamableColor>()); + db.Add("UI.tech-category-2", "OPTIONS_DB_UI_TECH_CATEGORY_2", StreamableColor(GROWTH_CATEGORY), Validator<StreamableColor>()); + db.Add("UI.tech-category-3", "OPTIONS_DB_UI_TECH_CATEGORY_3", StreamableColor(PRODUCTION_CATEGORY), Validator<StreamableColor>()); + db.Add("UI.tech-category-4", "OPTIONS_DB_UI_TECH_CATEGORY_4", StreamableColor(CONSTRUCTION_CATEGORY), Validator<StreamableColor>()); + db.Add("UI.tech-category-5", "OPTIONS_DB_UI_TECH_CATEGORY_5", StreamableColor(ECONOMICS_CATEGORY), Validator<StreamableColor>()); // UI behavior - db.Add("UI.tooltip-delay", "Sets UI tooltip popup delay, in ms.", 1000, RangedValidator<int>(0, 3000)); - db.Add("UI.multiple-fleet-windows", "If true, clicks on multiple fleet buttons will open multiple fleet " - "windows at the same time. Otherwise, opening a fleet window will close any currently-open fleet window.", - false); - db.Add("UI.fleet-autoselect", "Auto-select the top fleet when a fleet window " - "is opened. Consider using this flag if you use UI.multiple-fleet-windows.", true); - db.Add("UI.window-quickclose", "Close open windows such as fleet windows and the system-view side panel when you " - "right-click on the main map.", true); + db.Add("UI.tooltip-delay", "OPTIONS_DB_UI_TOOLTIP_DELAY", 1000, RangedValidator<int>(0, 3000)); + db.Add("UI.multiple-fleet-windows", "OPTIONS_DB_UI_MULTIPLE_FLEET_WINDOWS", false); + db.Add("UI.fleet-autoselect", "OPTIONS_DB_UI_FLEET_AUTOSELECT", true); + db.Add("UI.window-quickclose", "OPTIONS_DB_UI_WINDOW_QUICKCLOSE", true); } bool temp_bool = RegisterOptions(&AddOptions); Modified: trunk/FreeOrion/UI/GalaxySetupWnd.cpp =================================================================== --- trunk/FreeOrion/UI/GalaxySetupWnd.cpp 2006-10-18 02:40:02 UTC (rev 1910) +++ trunk/FreeOrion/UI/GalaxySetupWnd.cpp 2006-10-18 04:31:57 UTC (rev 1911) @@ -1,4 +1,3 @@ -//GalaxySetupWnd.cpp #include "GalaxySetupWnd.h" #include "CUIControls.h" @@ -27,12 +26,12 @@ // persistant between-executions galaxy setup settings, mainly so I don't have to redo these settings to what I want every time I run FO to test something void AddOptions(OptionsDB& db) { - db.Add("GameSetup.stars", "The number of stars in the galaxy to be generated.", 100, RangedValidator<int>(10, 500)); - db.Add("GameSetup.galaxy-shape", "The shape of the galaxy to be generated.", SPIRAL_3, RangedValidator<Shape>(SPIRAL_2, RING)); - db.Add("GameSetup.galaxy-age", "The shape of the galaxy to be generated.", AGE_MATURE, RangedValidator<Age>(AGE_YOUNG, AGE_ANCIENT)); - db.Add("GameSetup.planet-density", "The number of planets per system in the galaxy to be generated.", PD_AVERAGE, RangedValidator<PlanetDensity>(PD_LOW, PD_HIGH)); - db.Add("GameSetup.starlane-frequency", "The number of starlanes in the galaxy to be generated.", LANES_SEVERAL, RangedValidator<StarlaneFrequency>(ALLOW_NO_STARLANES ? LANES_NONE : LANES_FEW, LANES_VERY_MANY)); - db.Add("GameSetup.specials-frequency", "The frequency of specials appearing in the galaxy to be generated.", SPECIALS_UNCOMMON, RangedValidator<SpecialsFrequency>(SPECIALS_NONE, SPECIALS_COMMON)); + db.Add("GameSetup.stars", "OPTIONS_DB_GAMESETUP_STARS", 100, RangedValidator<int>(10, 500)); + db.Add("GameSetup.galaxy-shape", "OPTIONS_DB_GAMESETUP_GALAXY_SHAPE", SPIRAL_3, RangedValidator<Shape>(SPIRAL_2, RING)); + db.Add("GameSetup.galaxy-age", "OPTIONS_DB_GAMESETUP_GALAXY_AGE", AGE_MATURE, RangedValidator<Age>(AGE_YOUNG, AGE_ANCIENT)); + db.Add("GameSetup.planet-density", "OPTIONS_DB_GAMESETUP_PLANET_DENSITY", PD_AVERAGE, RangedValidator<PlanetDensity>(PD_LOW, PD_HIGH)); + db.Add("GameSetup.starlane-frequency", "OPTIONS_DB_GAMESETUP_STARLANE_FREQUENCY", LANES_SEVERAL, RangedValidator<StarlaneFrequency>(ALLOW_NO_STARLANES ? LANES_NONE : LANES_FEW, LANES_VERY_MANY)); + db.Add("GameSetup.specials-frequency", "OPTIONS_DB_GAMESETUP_SPECIALS_FREQUENCY", SPECIALS_UNCOMMON, RangedValidator<SpecialsFrequency>(SPECIALS_NONE, SPECIALS_COMMON)); } bool temp_bool = RegisterOptions(&AddOptions); } Modified: trunk/FreeOrion/UI/InGameMenu.cpp =================================================================== --- trunk/FreeOrion/UI/InGameMenu.cpp 2006-10-18 02:40:02 UTC (rev 1910) +++ trunk/FreeOrion/UI/InGameMenu.cpp 2006-10-18 04:31:57 UTC (rev 1911) @@ -19,11 +19,7 @@ namespace { void Options(OptionsDB& db) { - db.Add<std::string>('S', - "save-dir", - "The directory in which saved games are saved and from which they are loaded. Directory " - "names are taken to be relative to the location of the executable.", - (GetLocalDir() / "save").native_directory_string()); + db.Add<std::string>('S', "save-dir", "OPTIONS_DB_SAVE_DIR", (GetLocalDir() / "save").native_directory_string()); } bool foo_bool = RegisterOptions(&Options); Modified: trunk/FreeOrion/UI/IntroScreen.cpp =================================================================== --- trunk/FreeOrion/UI/IntroScreen.cpp 2006-10-18 02:40:02 UTC (rev 1910) +++ trunk/FreeOrion/UI/IntroScreen.cpp 2006-10-18 04:31:57 UTC (rev 1911) @@ -34,11 +34,9 @@ void Options(OptionsDB& db) { - db.AddFlag("force-external-server", - "Force the client not to start a server, even when hosting a game on localhost, playing single player, etc."); - - db.Add("UI.main-menu.x", "Position of the center of the intro screen main menu, as a portion of the application's total width.", 0.75, RangedValidator<double>(0.0, 1.0)); - db.Add("UI.main-menu.y", "Position of the center of the intro screen main menu, as a portion of the application's total height.", 0.35, RangedValidator<double>(0.0, 1.0)); + db.AddFlag("force-external-server", "OPTIONS_DB_FORCE_EXTERNAL_SERVER"); + db.Add("UI.main-menu.x", "OPTIONS_DB_UI_MAIN_MENU_X", 0.75, RangedValidator<double>(0.0, 1.0)); + db.Add("UI.main-menu.y", "OPTIONS_DB_UI_MAIN_MENU_Y", 0.35, RangedValidator<double>(0.0, 1.0)); } bool foo_bool = RegisterOptions(&Options); Modified: trunk/FreeOrion/UI/MapWnd.cpp =================================================================== --- trunk/FreeOrion/UI/MapWnd.cpp 2006-10-18 02:40:02 UTC (rev 1910) +++ trunk/FreeOrion/UI/MapWnd.cpp 2006-10-18 04:31:57 UTC (rev 1911) @@ -65,9 +65,8 @@ int g_history_position = 0; // the current edit contents are in history position 0 void AddOptions(OptionsDB& db) { - db.Add("UI.chat-hide-interval", "Time interval, in seconds, after which the multiplayer chat window will disappear if " - "nothing is added to it. A value of 0 indicates that the window should never disappear.", 10, RangedValidator<int>(0, 3600)); - db.Add("UI.chat-edit-history", "The number of outgoing messages to keep in the chat edit box history.", 50, RangedValidator<int>(0, 1000)); + db.Add("UI.chat-hide-interval", "OPTIONS_DB_UI_CHAT_HIDE_INTERVAL", 10, RangedValidator<int>(0, 3600)); + db.Add("UI.chat-edit-history", "OPTIONS_DB_UI_CHAT_EDIT_HISTORY", 50, RangedValidator<int>(0, 1000)); } bool temp_bool = RegisterOptions(&AddOptions); Modified: trunk/FreeOrion/UI/TechTreeWnd.cpp =================================================================== --- trunk/FreeOrion/UI/TechTreeWnd.cpp 2006-10-18 02:40:02 UTC (rev 1910) +++ trunk/FreeOrion/UI/TechTreeWnd.cpp 2006-10-18 04:31:57 UTC (rev 1911) @@ -33,8 +33,8 @@ // command-line options void AddOptions(OptionsDB& db) { - db.Add("UI.tech-layout-horz-spacing", "The horizontal spacing to be placed between techs in the tech screen, in multiples of the width of a single theory tech.", 0.75, RangedValidator<double>(0.1, 10.0)); - db.Add("UI.tech-layout-vert-spacing", "The vertical spacing to be placed between techs in the tech screen, in multiples of the height of a single theory tech.", 1.0, RangedValidator<double>(0.1, 10.0)); + db.Add("UI.tech-layout-horz-spacing", "OPTIONS_DB_UI_TECH_LAYOUT_HORZ_SPACING", 0.75, RangedValidator<double>(0.1, 10.0)); + db.Add("UI.tech-layout-vert-spacing", "OPTIONS_DB_UI_TECH_LAYOUT_VERT_SPACING", 1.0, RangedValidator<double>(0.1, 10.0)); } bool temp_bool = RegisterOptions(&AddOptions); Modified: trunk/FreeOrion/client/human/HumanClientApp.cpp =================================================================== --- trunk/FreeOrion/client/human/HumanClientApp.cpp 2006-10-18 02:40:02 UTC (rev 1910) +++ trunk/FreeOrion/client/human/HumanClientApp.cpp 2006-10-18 04:31:57 UTC (rev 1911) @@ -83,16 +83,14 @@ // command-line options void AddOptions(OptionsDB& db) { - db.Add("autosave.single-player", "If true, autosaves will occur during single-player games.", true, Validator<bool>()); - db.Add("autosave.multiplayer", "If true, autosaves will occur during multiplayer games.", false, Validator<bool>()); - db.Add("autosave.turns", "Sets the number of turns that should elapse between autosaves.", 5, RangedValidator<int>(1, 50)); - db.Add("autosave.saves", "Sets the number of autosaved games that should be kept.", 10, RangedValidator<int>(1, 50)); + db.Add("autosave.single-player", "OPTIONS_DB_AUTOSAVE_SINGLE_PLAYER", true, Validator<bool>()); + 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", "Enables creation of a thread dedicated to handling incoming SDL " - "messages. This may make FreeOrion more or less responsive, depending on your system.", - false, Validator<bool>()); + db.Add("enable-sdl-event-thread", "OPTIONS_DB_ENABLE_SDL_EVENT_THREAD", false, Validator<bool>()); #endif - db.Add("music-volume", "The volume (0 to 255) at which music should be played.", 255, RangedValidator<int>(1, 255)); + db.Add("music-volume", "OPTIONS_DB_MUSIC_VOLUME", 255, RangedValidator<int>(1, 255)); } bool temp_bool = RegisterOptions(&AddOptions); Modified: trunk/FreeOrion/client/human/chmain.cpp =================================================================== --- trunk/FreeOrion/client/human/chmain.cpp 2006-10-18 02:40:02 UTC (rev 1910) +++ trunk/FreeOrion/client/human/chmain.cpp 2006-10-18 04:31:57 UTC (rev 1911) @@ -19,11 +19,11 @@ // read and process command-line arguments, if any try { - GetOptionsDB().AddFlag('h', "help", "Print this help message."); - GetOptionsDB().AddFlag('g', "generate-config-xml", "Uses all the settings from any existing config.xml file and those given on the command line to generate a config.xml file. This will overwrite the current config.xml file, if it exists."); - GetOptionsDB().AddFlag('m', "music-off", "Disables music in the game"); - GetOptionsDB().Add<std::string>("bg-music", "Sets the background track to play", "artificial_intelligence_v3.ogg"); - GetOptionsDB().AddFlag('f', "fullscreen", "Start the game in fullscreen"); + GetOptionsDB().AddFlag('h', "help", "OPTIONS_DB_HELP"); + GetOptionsDB().AddFlag('g', "generate-config-xml", "OPTIONS_DB_GENERATE_CONFIG_XML"); + GetOptionsDB().AddFlag('m', "music-off", "OPTIONS_DB_MUSIC_OFF"); + GetOptionsDB().Add<std::string>("bg-music", "OPTIONS_DB_BG_MUSIC", "artificial_intelligence_v3.ogg"); + GetOptionsDB().AddFlag('f', "fullscreen", "OPTIONS_DB_FULLSCREEN"); XMLDoc doc; boost::filesystem::ifstream ifs(GetConfigPath()); doc.ReadDoc(ifs); Modified: trunk/FreeOrion/default/eng_stringtable.txt =================================================================== --- trunk/FreeOrion/default/eng_stringtable.txt 2006-10-18 02:40:02 UTC (rev 1910) +++ trunk/FreeOrion/default/eng_stringtable.txt 2006-10-18 04:31:57 UTC (rev 1911) @@ -97,6 +97,311 @@ An orbital defense platform that aids in the defense of the planet at which it is located.\n\nAttack: 1\nDefense: 3 +###################################### +# Command Line and OptionsDB Options # +###################################### + +COMMAND_LINE_USAGE +Usage: + +COMMAND_LINE_DEFAULT +Default: + +OPTIONS_DB_HELP +Print this help message. + +OPTIONS_DB_GENERATE_CONFIG_XML +Uses all the settings from any existing config.xml file and those given on the command line to generate a config.xml file. This will overwrite the current config.xml file, if it exists. + +OPTIONS_DB_MUSIC_OFF +Disables music in the game. + +OPTIONS_DB_BG_MUSIC +Sets the background track to play. + +OPTIONS_DB_FULLSCREEN +Start the game in fullscreen. + +OPTIONS_DB_UI_CHAT_HIDE_INTERVAL +Time interval, in seconds, after which the multiplayer chat window will disappear if nothing is added to it. A value of 0 indicates that the window should never disappear. + +OPTIONS_DB_UI_CHAT_EDIT_HISTORY +The number of outgoing messages to keep in the chat edit box history. + +OPTIONS_DB_FORCE_EXTERNAL_SERVER +Force the client not to start a server, even when hosting a game on localhost, playing single player, etc. + +OPTIONS_DB_UI_MAIN_MENU_X +Position of the center of the intro screen main menu, as a portion of the application's total width. + +OPTIONS_DB_UI_MAIN_MENU_Y +Position of the center of the intro screen main menu, as a portion of the application's total height. + +OPTIONS_DB_APP_WIDTH +Sets horizontal app resolution. + +OPTIONS_DB_APP_HEIGHT +Sets vertical app resolution. + +OPTIONS_DB_COLOR_DEPTH +Sets screen color depth, in bits per pixel. + +OPTIONS_DB_UI_SOUND_ENABLED +Toggles UI sound effects on or off. + +OPTIONS_DB_UI_SOUND_VOLUME +The volume (0 to 255) at which UI sound effects should be played. + +OPTIONS_DB_UI_SOUND_BUTTON_ROLLOVER +The sound file played when the mouse moves over a button. + +OPTIONS_DB_UI_SOUND_BUTTON_CLICK +The sound file played when a button is clicked. + +OPTIONS_DB_UI_SOUND_TURN_BUTTON_CLICK +The sound file played when the turn button is clicked. + +OPTIONS_DB_UI_SOUND_LIST_SELECT +The sound file played when a listbox or drop-down list item is selected. + +OPTIONS_DB_UI_SOUND_ITEM_DROP +The sound file played when an item is dropped into a listbox. + +OPTIONS_DB_UI_SOUND_LIST_PULLDOWN +The sound file played when the list is opened in a drop-down list. + +OPTIONS_DB_UI_SOUND_TEXT_TYPING +The sound file played when the user types text. + +OPTIONS_DB_UI_SOUND_WINDOW_MAXIMIZE +The sound file played when a window is maximized. + +OPTIONS_DB_UI_SOUND_WINDOW_MINIMIZE +The sound file played when a window is minimized. + +OPTIONS_DB_UI_SOUND_WINDOW_CLOSE +The sound file played when a window is closed. + +OPTIONS_DB_UI_SOUND_ALERT +The sound file played when an error or illegal action occurs. + +OPTIONS_DB_UI_SOUND_PLANET_BUTTON_CLICK +The sound file played when a planet button is clicked. + +OPTIONS_DB_UI_SOUND_FLEET_BUTTON_ROLLOVER +The sound file played when mouse moves over a fleet button. + +OPTIONS_DB_UI_SOUND_FLEET_BUTTON_CLICK +The sound file played when a fleet button is clicked. + +OPTIONS_DB_UI_SOUND_SIDEPANEL_OPEN +The sound file played when the system side-panel is opened. + +OPTIONS_DB_UI_SOUND_FARMING_FOCUS +The sound file played when a farming focus button is clicked. + +OPTIONS_DB_UI_SOUND_INDUSTRY_FOCUS +The sound file played when an industry focus button is clicked. + +OPTIONS_DB_UI_SOUND_RESEARCH_FOCUS +The sound file played when a research focus button is clicked. + +OPTIONS_DB_UI_SOUND_MINING_FOCUS +The sound file played when a mining focus button is clicked. + +OPTIONS_DB_UI_SOUND_BALANCED_FOCUS +The sound file played when a balanced focus button is clicked. + +OPTIONS_DB_UI_FONT +Sets UI font resource file. + +OPTIONS_DB_UI_FONT_BOLD +Sets UI bold font resource file. + +OPTIONS_DB_UI_FONT_ITALIC +Sets UI bold font resource file. + +OPTIONS_DB_UI_FONT_BOLD_ITALIC +Sets UI bold font resource file. + +OPTIONS_DB_UI_FONT_SIZE +Sets UI font size. + +OPTIONS_DB_UI_TITLE_FONT +Sets UI title font resource file. + +OPTIONS_DB_UI_TITLE_FONT_SIZE +Sets UI title font size. + +OPTIONS_DB_UI_WND_COLOR +Sets UI window color. + +OPTIONS_DB_UI_TEXT_COLOR +Sets UI text color. + +OPTIONS_DB_UI_CTRL_COLOR +Sets UI control color. + +OPTIONS_DB_UI_CTRL_BORDER_COLOR +Sets UI control border color. + +OPTIONS_DB_UI_BUTTON_COLOR +Sets UI button color. + +OPTIONS_DB_UI_STATE_BUTTON_COLOR +Sets UI state button color. + +OPTIONS_DB_UI_SCROLL_TAB_COLOR +Sets UI scroll tab color. + +OPTIONS_DB_UI_DROPDOWNLIST_INTERIOR_COLOR +Sets UI drop-down-list interior color. + +OPTIONS_DB_UI_DROPDOWNLIST_ARROW_COLOR +Sets UI drop-down-list arrow color. + +OPTIONS_DB_UI_EDIT_HILITE +Sets color of hilighting in UI edit controls. + +OPTIONS_DB_UI_EDIT_INTERIOR +Sets UI edit controls' interior color. + +OPTIONS_DB_UI_MULTIEDIT_INTERIOR +Sets UI multi-line edit controls' interior color. + +OPTIONS_DB_UI_STAT_INCREASE_COLOR +Sets the color of increased stats in the UI. + +OPTIONS_DB_UI_STAT_DECREASE_COLOR +Sets the color of decreased stats in the UI. + +OPTIONS_DB_UI_SIDEPANEL_COLOR +Sets the color of the side-panel. + +OPTIONS_DB_UI_WND_OUTER_BORDER_COLOR +Sets UI outer border color. + +OPTIONS_DB_UI_WND_BORDER_COLOR +Sets UI border color. + +OPTIONS_DB_UI_WND_INNER_BORDER_COLOR +Sets UI inner border color. + +OPTIONS_DB_UI_KNOWN_TECH +Sets color of known techs in the tech tree. + +OPTIONS_DB_UI_KNOWN_TECH_BORDER +Sets text and border color of known techs in the tech tree. + +OPTIONS_DB_UI_RESEARCHABLE_TECH +Sets color of researchable techs in the tech tree. + +OPTIONS_DB_UI_RESEARCHABLE_TECH_BORDER +Sets text and border color of researchable techs in the tech tree. + +OPTIONS_DB_UI_UNRESEARCHABLE_TECH +Sets color of unresearchable techs in the tech tree. + +OPTIONS_DB_UI_UNRESEARCHABLE_TECH_BORDER +Sets text and border color of unresearchable techs in the tech tree. + +OPTIONS_DB_UI_TECH_PROGRESS_BACKGROUND +Sets background color of progress bars in the tech tree. + +OPTIONS_DB_UI_TECH_PROGRESS +Sets color of progress bars in the tech tree. + +OPTIONS_DB_UI_SCROLL_WIDTH +Sets UI scroll width. + +OPTIONS_DB_UI_SYSTEM_ICON_SIZE +Sets size of system icons. + +OPTIONS_DB_UI_FLEET_BUTTON_SIZE +Sets size of fleet buttons. + +OPTIONS_DB_UI_TECH_CATEGORY_1 +Sets color of the first category of techs defined in techs.xml. + +OPTIONS_DB_UI_TECH_CATEGORY_2 +Sets color of the second category of techs defined in techs.xml. + +OPTIONS_DB_UI_TECH_CATEGORY_3 +Sets color of the third category of techs defined in techs.xml. + +OPTIONS_DB_UI_TECH_CATEGORY_4 +Sets color of the fourth category of techs defined in techs.xml. + +OPTIONS_DB_UI_TECH_CATEGORY_5 +Sets color of the fifth category of techs defined in techs.xml. + +OPTIONS_DB_UI_TOOLTIP_DELAY +Sets UI tooltip popup delay, in ms. + +OPTIONS_DB_UI_MULTIPLE_FLEET_WINDOWS +If true, clicks on multiple fleet buttons will open multiple fleet windows at the same time. Otherwise, opening a fleet window will close any currently-open fleet window. + +OPTIONS_DB_UI_FLEET_AUTOSELECT +Auto-select the top fleet when a fleet window is opened. Consider using this flag if you use UI.multiple-fleet-windows. + +OPTIONS_DB_UI_WINDOW_QUICKCLOSE +Close open windows such as fleet windows and the system-view side panel when you right-click on the main map. + +OPTIONS_DB_GAMESETUP_STARS +The number of stars in the galaxy to be generated. + +OPTIONS_DB_GAMESETUP_GALAXY_SHAPE +The shape of the galaxy to be generated. + +OPTIONS_DB_GAMESETUP_GALAXY_AGE +The shape of the galaxy to be generated. + +OPTIONS_DB_GAMESETUP_PLANET_DENSITY +The number of planets per system in the galaxy to be generated. + +OPTIONS_DB_GAMESETUP_STARLANE_FREQUENCY +The number of starlanes in the galaxy to be generated. + +OPTIONS_DB_GAMESETUP_SPECIALS_FREQUENCY +The frequency of specials appearing in the galaxy to be generated. + +OPTIONS_DB_UI_TECH_LAYOUT_HORZ_SPACING +The horizontal spacing to be placed between techs in the tech screen, in multiples of the width of a single theory tech. + +OPTIONS_DB_UI_TECH_LAYOUT_VERT_SPACING +The vertical spacing to be placed between techs in the tech screen, in multiples of the height of a single theory tech. + +OPTIONS_DB_SAVE_DIR +The directory in which saved games are saved and from which they are loaded. Directory names are taken to be relative to the location of the executable. + +OPTIONS_DB_SETTINGS_DIR +Sets the root directory for the settings and data files. + +OPTIONS_DB_LOG_LEVEL +Sets the level at or above which log messages will be output (levels in order of decreasing verbosity: DEBUG, INFO, NOTICE, WARN, ERROR, CRIT, ALERT, FATAL, EMERG) + +OPTIONS_DB_STRINGTABLE_FILENAME +Sets the language-specific string table filename. + +OPTIONS_DB_AUTOSAVE_SINGLE_PLAYER +If true, autosaves will occur during single-player games. + +OPTIONS_DB_AUTOSAVE_MULTIPLAYER +If true, autosaves will occur during multiplayer games. + +OPTIONS_DB_AUTOSAVE_TURNS +Sets the number of turns that should elapse between autosaves. + +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. + + ################# # File Dialog # ################# Modified: trunk/FreeOrion/default/ger_stringtable.txt =================================================================== --- trunk/FreeOrion/default/ger_stringtable.txt 2006-10-18 02:40:02 UTC (rev 1910) +++ trunk/FreeOrion/default/ger_stringtable.txt 2006-10-18 04:31:57 UTC (rev 1911) @@ -97,6 +97,311 @@ Eine orbitale Verteidigungsbasis, die bei der Verteidigung des Planeten hilft, in dessen Orbit sie sich befindet.\n\nAngriff: 1\nVerteidigung: 3 +###################################### +# Command Line and OptionsDB Options # +###################################### + +COMMAND_LINE_USAGE +Usage: + +COMMAND_LINE_DEFAULT +Default: + +OPTIONS_DB_HELP +Print this help message. + +OPTIONS_DB_GENERATE_CONFIG_XML +Uses all the settings from any existing config.xml file and those given on the command line to generate a config.xml file. This will overwrite the current config.xml file, if it exists. + +OPTIONS_DB_MUSIC_OFF +Disables music in the game. + +OPTIONS_DB_BG_MUSIC +Sets the background track to play. + +OPTIONS_DB_FULLSCREEN +Start the game in fullscreen. + +OPTIONS_DB_UI_CHAT_HIDE_INTERVAL +Time interval, in seconds, after which the multiplayer chat window will disappear if nothing is added to it. A value of 0 indicates that the window should never disappear. + +OPTIONS_DB_UI_CHAT_EDIT_HISTORY +The number of outgoing messages to keep in the chat edit box history. + +OPTIONS_DB_FORCE_EXTERNAL_SERVER +Force the client not to start a server, even when hosting a game on localhost, playing single player, etc. + +OPTIONS_DB_UI_MAIN_MENU_X +Position of the center of the intro screen main menu, as a portion of the application's total width. + +OPTIONS_DB_UI_MAIN_MENU_Y +Position of the center of the intro screen main menu, as a portion of the application's total height. + +OPTIONS_DB_APP_WIDTH +Sets horizontal app resolution. + +OPTIONS_DB_APP_HEIGHT +Sets vertical app resolution. + +OPTIONS_DB_COLOR_DEPTH +Sets screen color depth, in bits per pixel. + +OPTIONS_DB_UI_SOUND_ENABLED +Toggles UI sound effects on or off. + +OPTIONS_DB_UI_SOUND_VOLUME +The volume (0 to 255) at which UI sound effects should be played. + +OPTIONS_DB_UI_SOUND_BUTTON_ROLLOVER +The sound file played when the mouse moves over a button. + +OPTIONS_DB_UI_SOUND_BUTTON_CLICK +The sound file played when a button is clicked. + +OPTIONS_DB_UI_SOUND_TURN_BUTTON_CLICK +The sound file played when the turn button is clicked. + +OPTIONS_DB_UI_SOUND_LIST_SELECT +The sound file played when a listbox or drop-down list item is selected. + +OPTIONS_DB_UI_SOUND_ITEM_DROP +The sound file played when an item is dropped into a listbox. + +OPTIONS_DB_UI_SOUND_LIST_PULLDOWN +The sound file played when the list is opened in a drop-down list. + +OPTIONS_DB_UI_SOUND_TEXT_TYPING +The sound file played when the user types text. + +OPTIONS_DB_UI_SOUND_WINDOW_MAXIMIZE +The sound file played when a window is maximized. + +OPTIONS_DB_UI_SOUND_WINDOW_MINIMIZE +The sound file played when a window is minimized. + +OPTIONS_DB_UI_SOUND_WINDOW_CLOSE +The sound file played when a window is closed. + +OPTIONS_DB_UI_SOUND_ALERT +The sound file played when an error or illegal action occurs. + +OPTIONS_DB_UI_SOUND_PLANET_BUTTON_CLICK +The sound file played when a planet button is clicked. + +OPTIONS_DB_UI_SOUND_FLEET_BUTTON_ROLLOVER +The sound file played when mouse moves over a fleet button. + +OPTIONS_DB_UI_SOUND_FLEET_BUTTON_CLICK +The sound file played when a fleet button is clicked. + +OPTIONS_DB_UI_SOUND_SIDEPANEL_OPEN +The sound file played when the system side-panel is opened. + +OPTIONS_DB_UI_SOUND_FARMING_FOCUS +The sound file played when a farming focus button is clicked. + +OPTIONS_DB_UI_SOUND_INDUSTRY_FOCUS +The sound file played when an industry focus button is clicked. + +OPTIONS_DB_UI_SOUND_RESEARCH_FOCUS +The sound file played when a research focus button is clicked. + +OPTIONS_DB_UI_SOUND_MINING_FOCUS +The sound file played when a mining focus button is clicked. + +OPTIONS_DB_UI_SOUND_BALANCED_FOCUS +The sound file played when a balanced focus button is clicked. + +OPTIONS_DB_UI_FONT +Sets UI font resource file. + +OPTIONS_DB_UI_FONT_BOLD +Sets UI bold font resource file. + +OPTIONS_DB_UI_FONT_ITALIC +Sets UI bold font resource file. + +OPTIONS_DB_UI_FONT_BOLD_ITALIC +Sets UI bold font resource file. + +OPTIONS_DB_UI_FONT_SIZE +Sets UI font size. + +OPTIONS_DB_UI_TITLE_FONT +Sets UI title font resource file. + +OPTIONS_DB_UI_TITLE_FONT_SIZE +Sets UI title font size. + +OPTIONS_DB_UI_WND_COLOR +Sets UI window color. + +OPTIONS_DB_UI_TEXT_COLOR +Sets UI text color. + +OPTIONS_DB_UI_CTRL_COLOR +Sets UI control color. + +OPTIONS_DB_UI_CTRL_BORDER_COLOR +Sets UI control border color. + +OPTIONS_DB_UI_BUTTON_COLOR +Sets UI button color. + +OPTIONS_DB_UI_STATE_BUTTON_COLOR +Sets UI state button color. + +OPTIONS_DB_UI_SCROLL_TAB_COLOR +Sets UI scroll tab color. + +OPTIONS_DB_UI_DROPDOWNLIST_INTERIOR_COLOR +Sets UI drop-down-list interior color. + +OPTIONS_DB_UI_DROPDOWNLIST_ARROW_COLOR +Sets UI drop-down-list arrow color. + +OPTIONS_DB_UI_EDIT_HILITE +Sets color of hilighting in UI edit controls. + +OPTIONS_DB_UI_EDIT_INTERIOR +Sets UI edit controls' interior color. + +OPTIONS_DB_UI_MULTIEDIT_INTERIOR +Sets UI multi-line edit controls' interior color. + +OPTIONS_DB_UI_STAT_INCREASE_COLOR +Sets the color of increased stats in the UI. + +OPTIONS_DB_UI_STAT_DECREASE_COLOR +Sets the color of decreased stats in the UI. + +OPTIONS_DB_UI_SIDEPANEL_COLOR +Sets the color of the side-panel. + +OPTIONS_DB_UI_WND_OUTER_BORDER_COLOR +Sets UI outer border color. + +OPTIONS_DB_UI_WND_BORDER_COLOR +Sets UI border color. + +OPTIONS_DB_UI_WND_INNER_BORDER_COLOR +Sets UI inner border color. + +OPTIONS_DB_UI_KNOWN_TECH +Sets color of known techs in the tech tree. + +OPTIONS_DB_UI_KNOWN_TECH_BORDER +Sets text and border color of known techs in the tech tree. + +OPTIONS_DB_UI_RESEARCHABLE_TECH +Sets color of researchable techs in the tech tree. + +OPTIONS_DB_UI_RESEARCHABLE_TECH_BORDER +Sets text and border color of researchable techs in the tech tree. + +OPTIONS_DB_UI_UNRESEARCHABLE_TECH +Sets color of unresearchable techs in the tech tree. + +OPTIONS_DB_UI_UNRESEARCHABLE_TECH_BORDER +Sets text and border color of unresearchable techs in the tech tree. + +OPTIONS_DB_UI_TECH_PROGRESS_BACKGROUND +Sets background color of progress bars in the tech tree. + +OPTIONS_DB_UI_TECH_PROGRESS +Sets color of progress bars in the tech tree. + +OPTIONS_DB_UI_SCROLL_WIDTH +Sets UI scroll width. + +OPTIONS_DB_UI_SYSTEM_ICON_SIZE +Sets size of system icons. + +OPTIONS_DB_UI_FLEET_BUTTON_SIZE +Sets size of fleet buttons. + +OPTIONS_DB_UI_TECH_CATEGORY_1 +Sets color of the first category of techs defined in techs.xml. + +OPTIONS_DB_UI_TECH_CATEGORY_2 +Sets color of the second category of techs defined in techs.xml. + +OPTIONS_DB_UI_TECH_CATEGORY_3 +Sets color of the third category of techs defined in techs.xml. + +OPTIONS_DB_UI_TECH_CATEGORY_4 +Sets color of the fourth category of techs defined in techs.xml. + +OPTIONS_DB_UI_TECH_CATEGORY_5 +Sets color of the fifth category of techs defined in techs.xml. + +OPTIONS_DB_UI_TOOLTIP_DELAY +Sets UI tooltip popup delay, in ms. + +OPTIONS_DB_UI_MULTIPLE_FLEET_WINDOWS +If true, clicks on multiple fleet buttons will open multiple fleet windows at the same time. Otherwise, opening a fleet window will close any currently-open fleet window. + +OPTIONS_DB_UI_FLEET_AUTOSELECT +Auto-select the top fleet when a fleet window is opened. Consider using this flag if you use UI.multiple-fleet-windows. + +OPTIONS_DB_UI_WINDOW_QUICKCLOSE +Close open windows such as fleet windows and the system-view side panel when you right-click on the main map. + +OPTIONS_DB_GAMESETUP_STARS +The number of stars in the galaxy to be generated. + +OPTIONS_DB_GAMESETUP_GALAXY_SHAPE +The shape of the galaxy to be generated. + +OPTIONS_DB_GAMESETUP_GALAXY_AGE +The shape of the galaxy to be generated. + +OPTIONS_DB_GAMESETUP_PLANET_DENSITY +The number of planets per system in the galaxy to be generated. + +OPTIONS_DB_GAMESETUP_STARLANE_FREQUENCY +The number of starlanes in the galaxy to be generated. + +OPTIONS_DB_GAMESETUP_SPECIALS_FREQUENCY +The frequency of specials appearing in the galaxy to be generated. + +OPTIONS_DB_UI_TECH_LAYOUT_HORZ_SPACING +The horizontal spacing to be placed between techs in the tech screen, in multiples of the width of a single theory tech. + +OPTIONS_DB_UI_TECH_LAYOUT_VERT_SPACING +The vertical spacing to be placed between techs in the tech screen, in multiples of the height of a single theory tech. + +OPTIONS_DB_SAVE_DIR +The directory in which saved games are saved and from which they are loaded. Directory names are taken to be relative to the location of the executable. + +OPTIONS_DB_SETTINGS_DIR +Sets the root directory for the settings and data files. + +OPTIONS_DB_LOG_LEVEL +Sets the level at or above which log messages will be output (levels in order of decreasing verbosity: DEBUG, INFO, NOTICE, WARN, ERROR, CRIT, ALERT, FATAL, EMERG) + +OPTIONS_DB_STRINGTABLE_FILENAME +Sets the language-specific string table filename. + +OPTIONS_DB_AUTOSAVE_SINGLE_PLAYER +If true, autosaves will occur during single-player games. + +OPTIONS_DB_AUTOSAVE_MULTIPLAYER +If true, autosaves will occur during multiplayer games. + +OPTIONS_DB_AUTOSAVE_TURNS +Sets the number of turns that should elapse between autosaves. + +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. + + ################# # File Dialog # ################# Modified: trunk/FreeOrion/util/MultiplayerCommon.cpp =================================================================== --- trunk/FreeOrion/util/MultiplayerCommon.cpp 2006-10-18 02:40:02 UTC (rev 1910) +++ trunk/FreeOrion/util/MultiplayerCommon.cpp 2006-10-18 04:31:57 UTC (rev 1911) @@ -14,11 +14,9 @@ // command-line options void AddOptions(OptionsDB& db) { - db.Add<std::string>("settings-dir", "Sets the root directory for the settings and data files.", (GetGlobalDir() / "default").native_directory_string()); - db.Add<std::string>("log-level", "Sets the level at or above which log messages will be output " - "(levels in order of decreasing verbosity: DEBUG, INFO, NOTICE, WARN, ERROR, CRIT, " - "ALERT, FATAL, EMERG)", "WARN"); - db.Add<std::string>("stringtable-filename", "Sets the language-specific string table filename.", "eng_stringtable.txt"); + db.Add<std::string>("settings-dir", "OPTIONS_DB_SETTINGS_DIR", (GetGlobalDir() / "default").native_directory_string()); + db.Add<std::string>("log-level", "OPTIONS_DB_LOG_LEVEL", "WARN"); + db.Add<std::string>("stringtable-filename", "OPTIONS_DB_STRINGTABLE_FILENAME", "eng_stringtable.txt"); } bool temp_bool = RegisterOptions(&AddOptions); Modified: trunk/FreeOrion/util/OptionsDB.cpp =================================================================== --- trunk/FreeOrion/util/OptionsDB.cpp 2006-10-18 02:40:02 UTC (rev 1910) +++ trunk/FreeOrion/util/OptionsDB.cpp 2006-10-18 04:31:57 UTC (rev 1911) @@ -151,7 +151,7 @@ void OptionsDB::GetUsage(std::ostream& os, const std::string& command_line/* = ""*/) const { - os << "Usage: " << command_line << "\n"; + os << UserString("COMMAND_LINE_USAGE") << command_line << "\n"; int longest_param_name = 0; for (std::map<std::string, Option>::const_iterator it = m_options.begin(); it != m_options.end(); ++it) { @@ -159,7 +159,7 @@ longest_param_name = it->first.size(); } - int description_column = 5;//(longest_param_name + 7); // 7 comes from 4 for e.g. "-P, ", 2 for "--", and 1 space afterwards + int description_column = 5; int description_width = 80 - description_column; if (description_width <= 0) @@ -171,14 +171,14 @@ else os << "--" << it->second.name << "\n"; - os << std::string(description_column - 1, ' ');// - (it->second.name.size() + 7), ' '); + os << std::string(description_column - 1, ' '); std::vector<std::string> tokenized_strings; using boost::spirit::anychar_p; using boost::spirit::rule; using boost::spirit::space_p; rule<> tokenizer = +(*space_p >> (+(anychar_p - space_p))[PushBack(tokenized_strings)]); - parse(it->second.description.c_str(), tokenizer); + parse(UserString(it->second.description).c_str(), tokenizer); int curr_column = description_column; for (unsigned int i = 0; i < tokenized_strings.size(); ++i) { if (80 < curr_column + tokenized_strings[i].size() + (i ? 1 : 0)) { @@ -191,16 +191,16 @@ } if (it->second.validator) { std::stringstream stream; - stream << "Default: " << it->second.default_value; + stream << UserString("COMMAND_LINE_DEFAULT") << it->second.default_value; if (80 < curr_column + stream.str().size() + 3) { os << "\n" << std::string(description_column, ' ') << stream.str() << "\n"; } else { os << " | " << stream.str() << "\n"; } } else { - std::cout << "\n"; + os << "\n"; } - std::cout << "\n"; + os << "\n"; } } |
From: <tz...@us...> - 2006-10-20 10:16:40
|
Revision: 1916 http://svn.sourceforge.net/freeorion/revision/?rev=1916&view=rev Author: tzlaine Date: 2006-10-20 03:16:30 -0700 (Fri, 20 Oct 2006) Log Message: ----------- Added quotes around settings-dir paths that are passed as command-line args between FO apps (human client to server, server to AI clients), to make sure they arrive intact, even when they include spaces. Modified Paths: -------------- trunk/FreeOrion/client/human/HumanClientApp.cpp trunk/FreeOrion/server/ServerApp.cpp Modified: trunk/FreeOrion/client/human/HumanClientApp.cpp =================================================================== --- trunk/FreeOrion/client/human/HumanClientApp.cpp 2006-10-20 03:30:52 UTC (rev 1915) +++ trunk/FreeOrion/client/human/HumanClientApp.cpp 2006-10-20 10:16:30 UTC (rev 1916) @@ -174,7 +174,7 @@ #endif std::vector<std::string> args(1, SERVER_CLIENT_EXE); args.push_back("--settings-dir"); - args.push_back(GetOptionsDB().Get<std::string>("settings-dir")); + args.push_back("\"" + GetOptionsDB().Get<std::string>("settings-dir") + "\""); args.push_back("--log-level"); args.push_back(GetOptionsDB().Get<std::string>("log-level")); m_server_process = Process(SERVER_CLIENT_EXE, args); Modified: trunk/FreeOrion/server/ServerApp.cpp =================================================================== --- trunk/FreeOrion/server/ServerApp.cpp 2006-10-20 03:30:52 UTC (rev 1915) +++ trunk/FreeOrion/server/ServerApp.cpp 2006-10-20 10:16:30 UTC (rev 1916) @@ -276,7 +276,7 @@ args.push_back(AI_CLIENT_EXE); args.push_back(player_name); args.push_back("--settings-dir"); - args.push_back(GetOptionsDB().Get<std::string>("settings-dir")); + args.push_back("\"" + GetOptionsDB().Get<std::string>("settings-dir") + "\""); args.push_back("--log-level"); args.push_back(GetOptionsDB().Get<std::string>("log-level")); Logger().debugStream() << "starting " << AI_CLIENT_EXE; |
From: <tz...@us...> - 2006-10-20 21:20:35
|
Revision: 1917 http://svn.sourceforge.net/freeorion/revision/?rev=1917&view=rev Author: tzlaine Date: 2006-10-20 14:20:30 -0700 (Fri, 20 Oct 2006) Log Message: ----------- Fixed a typo in GetAsteroidTextures() in SidePanel.cpp that was causing asteroids not to show up. Also removed unsafe sprintf call. This lead me to look for others, the only one of which was in an MD5 sum-producing function that is cruft. It and all the MD5 are now removed. Modified Paths: -------------- trunk/FreeOrion/SConscript trunk/FreeOrion/UI/SidePanel.cpp trunk/FreeOrion/util/MultiplayerCommon.cpp trunk/FreeOrion/util/MultiplayerCommon.h Removed Paths: ------------- trunk/FreeOrion/util/md5.c trunk/FreeOrion/util/md5.h Modified: trunk/FreeOrion/SConscript =================================================================== --- trunk/FreeOrion/SConscript 2006-10-20 10:16:30 UTC (rev 1916) +++ trunk/FreeOrion/SConscript 2006-10-20 21:20:30 UTC (rev 1917) @@ -36,7 +36,6 @@ 'universe/ValueRefParser.cpp', 'util/DataTable.cpp', 'util/GZStream.cpp', - 'util/md5.c', 'util/MultiplayerCommon.cpp', 'util/OptionsDB.cpp', 'util/Order.cpp', Modified: trunk/FreeOrion/UI/SidePanel.cpp =================================================================== --- trunk/FreeOrion/UI/SidePanel.cpp 2006-10-20 10:16:30 UTC (rev 1916) +++ trunk/FreeOrion/UI/SidePanel.cpp 2006-10-20 21:20:30 UTC (rev 1917) @@ -91,7 +91,7 @@ Atmosphere(const XMLElement& elem) { if (elem.Tag() != "Atmosphere") - throw std::invalid_argument("Attempted to construct a Atmosphere from an XMLElement that had a tag other than \"Atmosphere\""); + throw std::invalid_argument("Attempted to construct an Atmosphere from an XMLElement that had a tag other than \"Atmosphere\""); filename = elem.Child("filename").Text(); alpha = lexical_cast<int>(elem.Child("alpha").Text()); alpha = std::max(0, std::min(alpha, 255)); @@ -634,9 +634,7 @@ const int SET = (planet_id % NUM_ASTEROID_SETS) + 1; for (int i = 0; i < NUM_IMAGES_PER_SET; ++i) { - char buf[1024]; - sprintf(buf, "asteroids%d_%03d.png", SET, i); - textures.push_back(ClientUI::GetTexture(ClientUI::ArtDir() / "planets" / " asteroids" / buf)); + textures.push_back(ClientUI::GetTexture(ClientUI::ArtDir() / "planets" / "asteroids" / boost::io::str(boost::format("asteroids%d_%03d.png") % SET % i))); } } Modified: trunk/FreeOrion/util/MultiplayerCommon.cpp =================================================================== --- trunk/FreeOrion/util/MultiplayerCommon.cpp 2006-10-20 10:16:30 UTC (rev 1916) +++ trunk/FreeOrion/util/MultiplayerCommon.cpp 2006-10-20 21:20:30 UTC (rev 1917) @@ -1,6 +1,5 @@ #include "MultiplayerCommon.h" -#include "md5.h" #include "OptionsDB.h" #include "../UI/StringTable.h" #include "../util/Directories.h" @@ -96,39 +95,6 @@ return priority_map[name]; } -std::string MD5StringSum(const std::string& str) -{ - std::string retval; - if (!str.empty()) { - md5_state_t md5_state; - md5_byte_t digest[16]; - md5_init(&md5_state); - md5_append(&md5_state, - reinterpret_cast<const md5_byte_t*>(str.c_str()), - str.size()); - md5_finish(&md5_state, digest); - if (0) { - retval = reinterpret_cast<const char*>(digest); - } else { - retval.resize(32, ' '); - for (int i = 0; i < 16; ++i) { - sprintf(&retval[i * 2], "%02x", digest[i]); - } - } - } - return retval; -} - -std::string MD5FileSum(const std::string& filename) -{ - std::string file_contents; - std::ifstream ifs(filename.c_str()); - while (ifs) { - file_contents += ifs.get(); - } - return MD5StringSum(file_contents); -} - const std::string& UserString(const std::string& str) { static std::string retval("ERROR"); Modified: trunk/FreeOrion/util/MultiplayerCommon.h =================================================================== --- trunk/FreeOrion/util/MultiplayerCommon.h 2006-10-20 10:16:30 UTC (rev 1916) +++ trunk/FreeOrion/util/MultiplayerCommon.h 2006-10-20 21:20:30 UTC (rev 1917) @@ -20,12 +20,6 @@ /** Returns the integer priority level that should be passed to log4cpp for a given priority name string. */ int PriorityValue(const std::string& name); -/** Returns an MD5 "sum" of the given string as a 32-digithexidecimal string. */ -std::string MD5StringSum(const std::string& str); - -/** Returns an MD5 "sum" of the given text file as a 32-digit hexidecimal string. */ -std::string MD5FileSum(const std::string& filename); - /** Returns a language-specific string for the key-string \a str */ const std::string& UserString(const std::string& str); Deleted: trunk/FreeOrion/util/md5.c =================================================================== --- trunk/FreeOrion/util/md5.c 2006-10-20 10:16:30 UTC (rev 1916) +++ trunk/FreeOrion/util/md5.c 2006-10-20 21:20:30 UTC (rev 1917) @@ -1,381 +0,0 @@ -/* - Copyright (C) 1999, 2000, 2002 Aladdin Enterprises. All rights reserved. - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - L. Peter Deutsch - gh...@al... - - */ -/* $Id$ */ -/* - Independent implementation of MD5 (RFC 1321). - - This code implements the MD5 Algorithm defined in RFC 1321, whose - text is available at - http://www.ietf.org/rfc/rfc1321.txt - The code is derived from the text of the RFC, including the test suite - (section A.5) but excluding the rest of Appendix A. It does not include - any code or documentation that is identified in the RFC as being - copyrighted. - - The original and principal author of md5.c is L. Peter Deutsch - <gh...@al...>. Other authors are noted in the change history - that follows (in reverse chronological order): - - 2002-04-13 lpd Clarified derivation from RFC 1321; now handles byte order - either statically or dynamically; added missing #include <string.h> - in library. - 2002-03-11 lpd Corrected argument list for main(), and added int return - type, in test program and T value program. - 2002-02-21 lpd Added missing #include <stdio.h> in test program. - 2000-07-03 lpd Patched to eliminate warnings about "constant is - unsigned in ANSI C, signed in traditional"; made test program - self-checking. - 1999-11-04 lpd Edited comments slightly for automatic TOC extraction. - 1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5). - 1999-05-03 lpd Original version. - */ - -#include "md5.h" -#include <string.h> - -#undef BYTE_ORDER /* 1 = big-endian, -1 = little-endian, 0 = unknown */ -#ifdef ARCH_IS_BIG_ENDIAN -# define BYTE_ORDER (ARCH_IS_BIG_ENDIAN ? 1 : -1) -#else -# define BYTE_ORDER 0 -#endif - -#define T_MASK ((md5_word_t)~0) -#define T1 /* 0xd76aa478 */ (T_MASK ^ 0x28955b87) -#define T2 /* 0xe8c7b756 */ (T_MASK ^ 0x173848a9) -#define T3 0x242070db -#define T4 /* 0xc1bdceee */ (T_MASK ^ 0x3e423111) -#define T5 /* 0xf57c0faf */ (T_MASK ^ 0x0a83f050) -#define T6 0x4787c62a -#define T7 /* 0xa8304613 */ (T_MASK ^ 0x57cfb9ec) -#define T8 /* 0xfd469501 */ (T_MASK ^ 0x02b96afe) -#define T9 0x698098d8 -#define T10 /* 0x8b44f7af */ (T_MASK ^ 0x74bb0850) -#define T11 /* 0xffff5bb1 */ (T_MASK ^ 0x0000a44e) -#define T12 /* 0x895cd7be */ (T_MASK ^ 0x76a32841) -#define T13 0x6b901122 -#define T14 /* 0xfd987193 */ (T_MASK ^ 0x02678e6c) -#define T15 /* 0xa679438e */ (T_MASK ^ 0x5986bc71) -#define T16 0x49b40821 -#define T17 /* 0xf61e2562 */ (T_MASK ^ 0x09e1da9d) -#define T18 /* 0xc040b340 */ (T_MASK ^ 0x3fbf4cbf) -#define T19 0x265e5a51 -#define T20 /* 0xe9b6c7aa */ (T_MASK ^ 0x16493855) -#define T21 /* 0xd62f105d */ (T_MASK ^ 0x29d0efa2) -#define T22 0x02441453 -#define T23 /* 0xd8a1e681 */ (T_MASK ^ 0x275e197e) -#define T24 /* 0xe7d3fbc8 */ (T_MASK ^ 0x182c0437) -#define T25 0x21e1cde6 -#define T26 /* 0xc33707d6 */ (T_MASK ^ 0x3cc8f829) -#define T27 /* 0xf4d50d87 */ (T_MASK ^ 0x0b2af278) -#define T28 0x455a14ed -#define T29 /* 0xa9e3e905 */ (T_MASK ^ 0x561c16fa) -#define T30 /* 0xfcefa3f8 */ (T_MASK ^ 0x03105c07) -#define T31 0x676f02d9 -#define T32 /* 0x8d2a4c8a */ (T_MASK ^ 0x72d5b375) -#define T33 /* 0xfffa3942 */ (T_MASK ^ 0x0005c6bd) -#define T34 /* 0x8771f681 */ (T_MASK ^ 0x788e097e) -#define T35 0x6d9d6122 -#define T36 /* 0xfde5380c */ (T_MASK ^ 0x021ac7f3) -#define T37 /* 0xa4beea44 */ (T_MASK ^ 0x5b4115bb) -#define T38 0x4bdecfa9 -#define T39 /* 0xf6bb4b60 */ (T_MASK ^ 0x0944b49f) -#define T40 /* 0xbebfbc70 */ (T_MASK ^ 0x4140438f) -#define T41 0x289b7ec6 -#define T42 /* 0xeaa127fa */ (T_MASK ^ 0x155ed805) -#define T43 /* 0xd4ef3085 */ (T_MASK ^ 0x2b10cf7a) -#define T44 0x04881d05 -#define T45 /* 0xd9d4d039 */ (T_MASK ^ 0x262b2fc6) -#define T46 /* 0xe6db99e5 */ (T_MASK ^ 0x1924661a) -#define T47 0x1fa27cf8 -#define T48 /* 0xc4ac5665 */ (T_MASK ^ 0x3b53a99a) -#define T49 /* 0xf4292244 */ (T_MASK ^ 0x0bd6ddbb) -#define T50 0x432aff97 -#define T51 /* 0xab9423a7 */ (T_MASK ^ 0x546bdc58) -#define T52 /* 0xfc93a039 */ (T_MASK ^ 0x036c5fc6) -#define T53 0x655b59c3 -#define T54 /* 0x8f0ccc92 */ (T_MASK ^ 0x70f3336d) -#define T55 /* 0xffeff47d */ (T_MASK ^ 0x00100b82) -#define T56 /* 0x85845dd1 */ (T_MASK ^ 0x7a7ba22e) -#define T57 0x6fa87e4f -#define T58 /* 0xfe2ce6e0 */ (T_MASK ^ 0x01d3191f) -#define T59 /* 0xa3014314 */ (T_MASK ^ 0x5cfebceb) -#define T60 0x4e0811a1 -#define T61 /* 0xf7537e82 */ (T_MASK ^ 0x08ac817d) -#define T62 /* 0xbd3af235 */ (T_MASK ^ 0x42c50dca) -#define T63 0x2ad7d2bb -#define T64 /* 0xeb86d391 */ (T_MASK ^ 0x14792c6e) - - -static void -md5_process(md5_state_t *pms, const md5_byte_t *data /*[64]*/) -{ - md5_word_t - a = pms->abcd[0], b = pms->abcd[1], - c = pms->abcd[2], d = pms->abcd[3]; - md5_word_t t; -#if BYTE_ORDER > 0 - /* Define storage only for big-endian CPUs. */ - md5_word_t X[16]; -#else - /* Define storage for little-endian or both types of CPUs. */ - md5_word_t xbuf[16]; - const md5_word_t *X; -#endif - - { -#if BYTE_ORDER == 0 - /* - * Determine dynamically whether this is a big-endian or - * little-endian machine, since we can use a more efficient - * algorithm on the latter. - */ - static const int w = 1; - - if (*((const md5_byte_t *)&w)) /* dynamic little-endian */ -#endif -#if BYTE_ORDER <= 0 /* little-endian */ - { - /* - * On little-endian machines, we can process properly aligned - * data without copying it. - */ - if (!((data - (const md5_byte_t *)0) & 3)) { - /* data are properly aligned */ - X = (const md5_word_t *)data; - } else { - /* not aligned */ - memcpy(xbuf, data, 64); - X = xbuf; - } - } -#endif -#if BYTE_ORDER == 0 - else /* dynamic big-endian */ -#endif -#if BYTE_ORDER >= 0 /* big-endian */ - { - /* - * On big-endian machines, we must arrange the bytes in the - * right order. - */ - const md5_byte_t *xp = data; - int i; - -# if BYTE_ORDER == 0 - X = xbuf; /* (dynamic only) */ -# else -# define xbuf X /* (static only) */ -# endif - for (i = 0; i < 16; ++i, xp += 4) - xbuf[i] = xp[0] + (xp[1] << 8) + (xp[2] << 16) + (xp[3] << 24); - } -#endif - } - -#define ROTATE_LEFT(x, n) (((x) << (n)) | ((x) >> (32 - (n)))) - - /* Round 1. */ - /* Let [abcd k s i] denote the operation - a = b + ((a + F(b,c,d) + X[k] + T[i]) <<< s). */ -#define F(x, y, z) (((x) & (y)) | (~(x) & (z))) -#define SET(a, b, c, d, k, s, Ti)\ - t = a + F(b,c,d) + X[k] + Ti;\ - a = ROTATE_LEFT(t, s) + b - /* Do the following 16 operations. */ - SET(a, b, c, d, 0, 7, T1); - SET(d, a, b, c, 1, 12, T2); - SET(c, d, a, b, 2, 17, T3); - SET(b, c, d, a, 3, 22, T4); - SET(a, b, c, d, 4, 7, T5); - SET(d, a, b, c, 5, 12, T6); - SET(c, d, a, b, 6, 17, T7); - SET(b, c, d, a, 7, 22, T8); - SET(a, b, c, d, 8, 7, T9); - SET(d, a, b, c, 9, 12, T10); - SET(c, d, a, b, 10, 17, T11); - SET(b, c, d, a, 11, 22, T12); - SET(a, b, c, d, 12, 7, T13); - SET(d, a, b, c, 13, 12, T14); - SET(c, d, a, b, 14, 17, T15); - SET(b, c, d, a, 15, 22, T16); -#undef SET - - /* Round 2. */ - /* Let [abcd k s i] denote the operation - a = b + ((a + G(b,c,d) + X[k] + T[i]) <<< s). */ -#define G(x, y, z) (((x) & (z)) | ((y) & ~(z))) -#define SET(a, b, c, d, k, s, Ti)\ - t = a + G(b,c,d) + X[k] + Ti;\ - a = ROTATE_LEFT(t, s) + b - /* Do the following 16 operations. */ - SET(a, b, c, d, 1, 5, T17); - SET(d, a, b, c, 6, 9, T18); - SET(c, d, a, b, 11, 14, T19); - SET(b, c, d, a, 0, 20, T20); - SET(a, b, c, d, 5, 5, T21); - SET(d, a, b, c, 10, 9, T22); - SET(c, d, a, b, 15, 14, T23); - SET(b, c, d, a, 4, 20, T24); - SET(a, b, c, d, 9, 5, T25); - SET(d, a, b, c, 14, 9, T26); - SET(c, d, a, b, 3, 14, T27); - SET(b, c, d, a, 8, 20, T28); - SET(a, b, c, d, 13, 5, T29); - SET(d, a, b, c, 2, 9, T30); - SET(c, d, a, b, 7, 14, T31); - SET(b, c, d, a, 12, 20, T32); -#undef SET - - /* Round 3. */ - /* Let [abcd k s t] denote the operation - a = b + ((a + H(b,c,d) + X[k] + T[i]) <<< s). */ -#define H(x, y, z) ((x) ^ (y) ^ (z)) -#define SET(a, b, c, d, k, s, Ti)\ - t = a + H(b,c,d) + X[k] + Ti;\ - a = ROTATE_LEFT(t, s) + b - /* Do the following 16 operations. */ - SET(a, b, c, d, 5, 4, T33); - SET(d, a, b, c, 8, 11, T34); - SET(c, d, a, b, 11, 16, T35); - SET(b, c, d, a, 14, 23, T36); - SET(a, b, c, d, 1, 4, T37); - SET(d, a, b, c, 4, 11, T38); - SET(c, d, a, b, 7, 16, T39); - SET(b, c, d, a, 10, 23, T40); - SET(a, b, c, d, 13, 4, T41); - SET(d, a, b, c, 0, 11, T42); - SET(c, d, a, b, 3, 16, T43); - SET(b, c, d, a, 6, 23, T44); - SET(a, b, c, d, 9, 4, T45); - SET(d, a, b, c, 12, 11, T46); - SET(c, d, a, b, 15, 16, T47); - SET(b, c, d, a, 2, 23, T48); -#undef SET - - /* Round 4. */ - /* Let [abcd k s t] denote the operation - a = b + ((a + I(b,c,d) + X[k] + T[i]) <<< s). */ -#define I(x, y, z) ((y) ^ ((x) | ~(z))) -#define SET(a, b, c, d, k, s, Ti)\ - t = a + I(b,c,d) + X[k] + Ti;\ - a = ROTATE_LEFT(t, s) + b - /* Do the following 16 operations. */ - SET(a, b, c, d, 0, 6, T49); - SET(d, a, b, c, 7, 10, T50); - SET(c, d, a, b, 14, 15, T51); - SET(b, c, d, a, 5, 21, T52); - SET(a, b, c, d, 12, 6, T53); - SET(d, a, b, c, 3, 10, T54); - SET(c, d, a, b, 10, 15, T55); - SET(b, c, d, a, 1, 21, T56); - SET(a, b, c, d, 8, 6, T57); - SET(d, a, b, c, 15, 10, T58); - SET(c, d, a, b, 6, 15, T59); - SET(b, c, d, a, 13, 21, T60); - SET(a, b, c, d, 4, 6, T61); - SET(d, a, b, c, 11, 10, T62); - SET(c, d, a, b, 2, 15, T63); - SET(b, c, d, a, 9, 21, T64); -#undef SET - - /* Then perform the following additions. (That is increment each - of the four registers by the value it had before this block - was started.) */ - pms->abcd[0] += a; - pms->abcd[1] += b; - pms->abcd[2] += c; - pms->abcd[3] += d; -} - -void -md5_init(md5_state_t *pms) -{ - pms->count[0] = pms->count[1] = 0; - pms->abcd[0] = 0x67452301; - pms->abcd[1] = /*0xefcdab89*/ T_MASK ^ 0x10325476; - pms->abcd[2] = /*0x98badcfe*/ T_MASK ^ 0x67452301; - pms->abcd[3] = 0x10325476; -} - -void -md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes) -{ - const md5_byte_t *p = data; - int left = nbytes; - int offset = (pms->count[0] >> 3) & 63; - md5_word_t nbits = (md5_word_t)(nbytes << 3); - - if (nbytes <= 0) - return; - - /* Update the message length. */ - pms->count[1] += nbytes >> 29; - pms->count[0] += nbits; - if (pms->count[0] < nbits) - pms->count[1]++; - - /* Process an initial partial block. */ - if (offset) { - int copy = (offset + nbytes > 64 ? 64 - offset : nbytes); - - memcpy(pms->buf + offset, p, copy); - if (offset + copy < 64) - return; - p += copy; - left -= copy; - md5_process(pms, pms->buf); - } - - /* Process full blocks. */ - for (; left >= 64; p += 64, left -= 64) - md5_process(pms, p); - - /* Process a final partial block. */ - if (left) - memcpy(pms->buf, p, left); -} - -void -md5_finish(md5_state_t *pms, md5_byte_t digest[16]) -{ - static const md5_byte_t pad[64] = { - 0x80, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 - }; - md5_byte_t data[8]; - int i; - - /* Save the length before padding. */ - for (i = 0; i < 8; ++i) - data[i] = (md5_byte_t)(pms->count[i >> 2] >> ((i & 3) << 3)); - /* Pad to 56 bytes mod 64. */ - md5_append(pms, pad, ((55 - (pms->count[0] >> 3)) & 63) + 1); - /* Append the length. */ - md5_append(pms, data, 8); - for (i = 0; i < 16; ++i) - digest[i] = (md5_byte_t)(pms->abcd[i >> 2] >> ((i & 3) << 3)); -} Deleted: trunk/FreeOrion/util/md5.h =================================================================== --- trunk/FreeOrion/util/md5.h 2006-10-20 10:16:30 UTC (rev 1916) +++ trunk/FreeOrion/util/md5.h 2006-10-20 21:20:30 UTC (rev 1917) @@ -1,91 +0,0 @@ -/* - Copyright (C) 1999, 2002 Aladdin Enterprises. All rights reserved. - - This software is provided 'as-is', without any express or implied - warranty. In no event will the authors be held liable for any damages - arising from the use of this software. - - Permission is granted to anyone to use this software for any purpose, - including commercial applications, and to alter it and redistribute it - freely, subject to the following restrictions: - - 1. The origin of this software must not be misrepresented; you must not - claim that you wrote the original software. If you use this software - in a product, an acknowledgment in the product documentation would be - appreciated but is not required. - 2. Altered source versions must be plainly marked as such, and must not be - misrepresented as being the original software. - 3. This notice may not be removed or altered from any source distribution. - - L. Peter Deutsch - gh...@al... - - */ -/* $Id$ */ -/* - Independent implementation of MD5 (RFC 1321). - - This code implements the MD5 Algorithm defined in RFC 1321, whose - text is available at - http://www.ietf.org/rfc/rfc1321.txt - The code is derived from the text of the RFC, including the test suite - (section A.5) but excluding the rest of Appendix A. It does not include - any code or documentation that is identified in the RFC as being - copyrighted. - - The original and principal author of md5.h is L. Peter Deutsch - <gh...@al...>. Other authors are noted in the change history - that follows (in reverse chronological order): - - 2002-04-13 lpd Removed support for non-ANSI compilers; removed - references to Ghostscript; clarified derivation from RFC 1321; - now handles byte order either statically or dynamically. - 1999-11-04 lpd Edited comments slightly for automatic TOC extraction. - 1999-10-18 lpd Fixed typo in header comment (ansi2knr rather than md5); - added conditionalization for C++ compilation from Martin - Purschke <pur...@bn...>. - 1999-05-03 lpd Original version. - */ - -#ifndef md5_INCLUDED -# define md5_INCLUDED - -/* - * This package supports both compile-time and run-time determination of CPU - * byte order. If ARCH_IS_BIG_ENDIAN is defined as 0, the code will be - * compiled to run only on little-endian CPUs; if ARCH_IS_BIG_ENDIAN is - * defined as non-zero, the code will be compiled to run only on big-endian - * CPUs; if ARCH_IS_BIG_ENDIAN is not defined, the code will be compiled to - * run on either big- or little-endian CPUs, but will run slightly less - * efficiently on either one than if ARCH_IS_BIG_ENDIAN is defined. - */ - -typedef unsigned char md5_byte_t; /* 8-bit byte */ -typedef unsigned int md5_word_t; /* 32-bit word */ - -/* Define the state of the MD5 Algorithm. */ -typedef struct md5_state_s { - md5_word_t count[2]; /* message length in bits, lsw first */ - md5_word_t abcd[4]; /* digest buffer */ - md5_byte_t buf[64]; /* accumulate block */ -} md5_state_t; - -#ifdef __cplusplus -extern "C" -{ -#endif - -/* Initialize the algorithm. */ -void md5_init(md5_state_t *pms); - -/* Append a string to the message. */ -void md5_append(md5_state_t *pms, const md5_byte_t *data, int nbytes); - -/* Finish the message and return the digest. */ -void md5_finish(md5_state_t *pms, md5_byte_t digest[16]); - -#ifdef __cplusplus -} /* end extern "C" */ -#endif - -#endif /* md5_INCLUDED */ |
From: <tz...@us...> - 2006-10-21 18:22:07
|
Revision: 1919 http://svn.sourceforge.net/freeorion/revision/?rev=1919&view=rev Author: tzlaine Date: 2006-10-21 11:21:58 -0700 (Sat, 21 Oct 2006) Log Message: ----------- - Added code to OptionsDB to strip enclosing quotes off of command-line options, which caused havoc with the Linux build (not having the quotes on the command line at all caused havoc on the Win32 build). - Moved planet naming to the end of the universe creation sequence, in order to avoid name collisions due to the replacement of planets when home systems are generated. This is due to the fact that some "planets", asteroids, have no roman numerals, so when they are replaced by a home world, one of other planets *with* roman numerals will end up with the same name as the homeworld. - Added stringtable strings for many strings created in the universe creation sequence. The strings that are most temporary have been left hardcoded, since they will be removed fairly soon anyway. - Added a new "storable" flag to OptionsDB::Option, that when set to false prevents an option from being stored in the XML config file. Options such as --force-external-server (and perhaps others in the future) should not be persistent. Modified Paths: -------------- trunk/FreeOrion/UI/IntroScreen.cpp trunk/FreeOrion/default/eng_stringtable.txt trunk/FreeOrion/default/ger_stringtable.txt trunk/FreeOrion/universe/Universe.cpp trunk/FreeOrion/universe/Universe.h trunk/FreeOrion/util/OptionsDB.cpp trunk/FreeOrion/util/OptionsDB.h trunk/FreeOrion/util/Process.cpp Modified: trunk/FreeOrion/UI/IntroScreen.cpp =================================================================== --- trunk/FreeOrion/UI/IntroScreen.cpp 2006-10-21 02:56:15 UTC (rev 1918) +++ trunk/FreeOrion/UI/IntroScreen.cpp 2006-10-21 18:21:58 UTC (rev 1919) @@ -34,7 +34,7 @@ void Options(OptionsDB& db) { - db.AddFlag("force-external-server", "OPTIONS_DB_FORCE_EXTERNAL_SERVER"); + db.AddFlag("force-external-server", "OPTIONS_DB_FORCE_EXTERNAL_SERVER", false); db.Add("UI.main-menu.x", "OPTIONS_DB_UI_MAIN_MENU_X", 0.75, RangedValidator<double>(0.0, 1.0)); db.Add("UI.main-menu.y", "OPTIONS_DB_UI_MAIN_MENU_Y", 0.35, RangedValidator<double>(0.0, 1.0)); } Modified: trunk/FreeOrion/default/eng_stringtable.txt =================================================================== --- trunk/FreeOrion/default/eng_stringtable.txt 2006-10-21 02:56:15 UTC (rev 1918) +++ trunk/FreeOrion/default/eng_stringtable.txt 2006-10-21 18:21:58 UTC (rev 1919) @@ -72,6 +72,9 @@ PLAYER_VICTORIOUS You are victorious. +EMPIRE +Empire + EMPIRE_DEFEATED The %1% empire is no more. @@ -1016,6 +1019,9 @@ PLANET_PANEL Planet Panel +PL_ASTEROID_BELT +Asteroid belt + PL_UNINHABITED Uninhabited @@ -1077,6 +1083,9 @@ FW_EMPIRE_FLEETS %1% Fleets +FW_HOME_FLEET +Home Fleet + # the name that is used for fleets the player does not control FW_FOREIGN_FLEET Foreign fleet Modified: trunk/FreeOrion/default/ger_stringtable.txt =================================================================== --- trunk/FreeOrion/default/ger_stringtable.txt 2006-10-21 02:56:15 UTC (rev 1918) +++ trunk/FreeOrion/default/ger_stringtable.txt 2006-10-21 18:21:58 UTC (rev 1919) @@ -72,6 +72,9 @@ PLAYER_VICTORIOUS Sie haben gewonnen. +EMPIRE +Empire + EMPIRE_DEFEATED Imperium %1% wurde ausgel\xF6scht. @@ -1016,6 +1019,9 @@ PLANET_PANEL Planetenfenster +PL_ASTEROID_BELT +Asteroid belt + PL_UNINHABITED Unbewohnt @@ -1077,6 +1083,9 @@ FW_EMPIRE_FLEETS %1% Flotten +FW_HOME_FLEET +Home Fleet + # the name that is used for fleets the player does not control FW_FOREIGN_FLEET Fremde Flotte Modified: trunk/FreeOrion/universe/Universe.cpp =================================================================== --- trunk/FreeOrion/universe/Universe.cpp 2006-10-21 02:56:15 UTC (rev 1918) +++ trunk/FreeOrion/universe/Universe.cpp 2006-10-21 18:21:58 UTC (rev 1919) @@ -1183,6 +1183,7 @@ GenerateStarlanes(starlane_freq, adjacency_grid); InitializeSystemGraph(); GenerateHomeworlds(players + ai_players, homeworlds); + NamePlanets(); GenerateEmpires(players + ai_players, homeworlds, player_setup_data); ApplyEffects(); @@ -1475,7 +1476,6 @@ for (std::vector<System*>::iterator it = sys_vec.begin(); it != sys_vec.end(); ++it) { System* system = *it; - int num_planets_in_system = 0; // the number of slots in this system that were determined to contain planets for (int orbit = 0; orbit < system->Orbits(); orbit++) { // make a series of "rolls" (1-100) for each planet size, and take the highest modified roll int idx = 0; @@ -1492,8 +1492,6 @@ if (planet_size == SZ_NOWORLD) continue; - else if (planet_size != SZ_ASTEROIDS) - ++num_planets_in_system; if (planet_size == SZ_ASTEROIDS) { idx = PT_ASTEROIDS; @@ -1527,10 +1525,6 @@ Insert(planet); // add planet to universe map system->Insert(planet, orbit); // add planet to system map - if (planet_type == PT_ASTEROIDS) - planet->Rename("Asteroid Belt"); - else - planet->Rename(system->Name() + " " + RomanNumber(num_planets_in_system)); } } } @@ -2301,6 +2295,26 @@ } } +void Universe::NamePlanets() +{ + std::vector<System*> sys_vec = FindObjects<System>(); + for (std::vector<System*>::iterator it = sys_vec.begin(); it != sys_vec.end(); ++it) { + System* system = *it; + int num_planets_in_system = 0; + for (int i = 0; i < system->Orbits(); i++) { + std::vector<Planet*> planets = system->FindObjectsInOrbit<Planet>(i); + if (!planets.empty()) { + assert(planets.size() == 1); + Planet* planet = planets[0]; + if (planet->Type() == PT_ASTEROIDS) + planet->Rename(UserString("PL_ASTEROID_BELT")); + else + planet->Rename(system->Name() + " " + RomanNumber(++num_planets_in_system)); + } + } + } +} + void Universe::GenerateEmpires(int players, std::vector<int>& homeworlds, const std::vector<PlayerSetupData>& player_setup_data) { #ifdef FREEORION_BUILD_SERVER @@ -2311,7 +2325,7 @@ unsigned int i = 0; std::vector<GG::Clr> colors = EmpireColors(); for (std::map<int, PlayerInfo>::const_iterator it = player_info.begin(); it != player_info.end(); ++it, ++i) { - std::string empire_name = "Empire" + boost::lexical_cast<std::string>(i); + std::string empire_name = UserString("EMPIRE") + boost::lexical_cast<std::string>(i); GG::Clr color; if (i < player_setup_data.size()) { // first try to use user-assigned colors @@ -2454,7 +2468,7 @@ empire->AddShipDesign(design); // create the empire's starting fleet - Fleet* home_fleet = new Fleet("Home Fleet", home_system->X(), home_system->Y(), empire_id); + Fleet* home_fleet = new Fleet(UserString("FW_HOME_FLEET"), home_system->X(), home_system->Y(), empire_id); Insert(home_fleet); home_system->Insert(home_fleet); Modified: trunk/FreeOrion/universe/Universe.h =================================================================== --- trunk/FreeOrion/universe/Universe.h 2006-10-21 02:56:15 UTC (rev 1918) +++ trunk/FreeOrion/universe/Universe.h 2006-10-21 18:21:58 UTC (rev 1919) @@ -277,16 +277,14 @@ void GenerateIrregularGalaxy(int stars, Age age, AdjacencyGrid& adjacency_grid); ///< creates an irregular galaxy and stores the empire homeworlds in the homeworlds vector void PopulateSystems(PlanetDensity density, SpecialsFrequency specials_freq); ///< Will generate planets for all systems that have empty object maps (ie those that aren't homeworld systems) - void GenerateStarlanes(StarlaneFrequency freq, const AdjacencyGrid& adjacency_grid); ///< creates starlanes and adds them systems already generated bool ConnectedWithin(int system1, int system2, int maxLaneJumps, std::vector<std::set<int> >& laneSetArray); // used by GenerateStarlanes. Determines if two systems are connected by maxLaneJumps or less edges on graph void CullAngularlyTooCloseLanes(double maxLaneUVectDotProd, std::vector<std::set<int> >& laneSetArray, std::vector<System*> &systems); // Removes lanes from passed graph that are angularly too close to eachother void CullTooLongLanes(double maxLaneLength, std::vector<std::set<int> >& laneSetArray, std::vector<System*> &systems); // Removes lanes from passed graph that are too long void GrowSpanningTrees(std::vector<int> roots, std::vector<std::set<int> >& potentialLaneSetArray, std::vector<std::set<int> >& laneSetArray); // grows trees to connect stars... takes an array of sets of potential starlanes for each star, and puts the starlanes of the tree into another set - void InitializeSystemGraph(); ///< resizes the system graph to the appropriate size and populates m_system_distances void GenerateHomeworlds(int players, std::vector<int>& homeworlds); ///< Picks systems to host homeworlds, generates planets for them, stores the ID's of the homeworld planets into the homeworld vector - + void NamePlanets(); ///< Names the planets in each system, based on the system's name /// Will create empire objects, assign them homeworlds, setup the homeworld population, industry, and starting fleets /// NOTE: does nothing if executed client-side. This is a hack to deal with the /// dependency on ServerEmpireManager -- jdb Modified: trunk/FreeOrion/util/OptionsDB.cpp =================================================================== --- trunk/FreeOrion/util/OptionsDB.cpp 2006-10-21 02:56:15 UTC (rev 1918) +++ trunk/FreeOrion/util/OptionsDB.cpp 2006-10-21 18:21:58 UTC (rev 1919) @@ -8,6 +8,8 @@ #include <string> #include <boost/spirit.hpp> +#include <boost/algorithm/string/erase.hpp> +#include <boost/algorithm/string/predicate.hpp> namespace { std::vector<OptionsDBFn>& OptionsRegistry() @@ -33,6 +35,16 @@ void operator()(const char* first, const char* last) const {m_string_vec.push_back(std::string(first, last));} std::vector<std::string>& m_string_vec; }; + + void StripQuotation(std::string& str) + { + using namespace boost::algorithm; + if (starts_with(str, "\"") && ends_with(str, "\"")) + { + erase_first(str, "\""); + erase_last(str, "\""); + } + } } ///////////////////////////////////////////// @@ -63,17 +75,17 @@ std::map<char, std::string> OptionsDB::Option::short_names; OptionsDB::Option::Option() -{ -} +{} OptionsDB::Option::Option(char short_name_, const std::string& name_, const boost::any& value_, const std::string& default_value_, const std::string& description_, - const ValidatorBase* validator_/* = 0*/) : + const ValidatorBase* validator_, bool storable_) : name(name_), short_name(short_name_), value(value_), default_value(default_value_), description(description_), validator(validator_), + storable(storable_), option_changed_sig_ptr(new boost::signal<void ()>()) { if (short_name_) @@ -212,6 +224,8 @@ elem_stack.push_back(&doc.root_node); for (std::map<std::string, Option>::const_iterator it = m_options.begin(); it != m_options.end(); ++it) { + if (!it->second.storable) + continue; std::string::size_type last_dot = it->first.find_last_of('.'); std::string section_name = last_dot == std::string::npos ? "" : it->first.substr(0, last_dot); std::string name = it->first.substr(last_dot == std::string::npos ? 0 : last_dot + 1); @@ -292,7 +306,9 @@ if (option.validator) { // non-flag try { - option.FromString(argv[++i]); + std::string value_str(argv[++i]); + StripQuotation(value_str); + option.FromString(value_str); } catch (const std::exception& e) { throw std::runtime_error("OptionsDB::SetFromCommandLine() : the following exception was caught when attemptimg to set option \"" + option.name + "\": " + e.what()); } Modified: trunk/FreeOrion/util/OptionsDB.h =================================================================== --- trunk/FreeOrion/util/OptionsDB.h 2006-10-21 02:56:15 UTC (rev 1918) +++ trunk/FreeOrion/util/OptionsDB.h 2006-10-21 18:21:58 UTC (rev 1919) @@ -110,41 +110,41 @@ /** adds an Option, optionally with a custom validator */ template <class T> - void Add(const std::string& name, const std::string& description, T default_value, const ValidatorBase& validator = Validator<T>()) + void Add(const std::string& name, const std::string& description, T default_value, const ValidatorBase& validator = Validator<T>(), bool storable = true) { if (m_options.find(name) != m_options.end()) throw std::runtime_error("OptionsDB::Add<>() : Option " + name + " was specified twice."); - m_options[name] = Option(static_cast<char>(0), name, default_value, boost::lexical_cast<std::string>(default_value), description, validator.Clone()); + m_options[name] = Option(static_cast<char>(0), name, default_value, boost::lexical_cast<std::string>(default_value), description, validator.Clone(), storable); OptionAddedSignal(name); } /** adds an Option with an alternative one-character shortened name, optionally with a custom validator */ template <class T> - void Add(char short_name, const std::string& name, const std::string& description, T default_value, const ValidatorBase& validator = Validator<T>()) + void Add(char short_name, const std::string& name, const std::string& description, T default_value, const ValidatorBase& validator = Validator<T>(), bool storable = true) { if (m_options.find(name) != m_options.end()) throw std::runtime_error("OptionsDB::Add<>() : Option " + name + " was specified twice."); - m_options[name] = Option(short_name, name, default_value, boost::lexical_cast<std::string>(default_value), description, validator.Clone()); + m_options[name] = Option(short_name, name, default_value, boost::lexical_cast<std::string>(default_value), description, validator.Clone(), storable); OptionAddedSignal(name); } /** adds a flag Option, which is treated as a boolean value with a default of false. Using the flag on the command line at all indicates that its value it set to true. */ - void AddFlag(const std::string& name, const std::string& description) + void AddFlag(const std::string& name, const std::string& description, bool storable = true) { if (m_options.find(name) != m_options.end()) throw std::runtime_error("OptionsDB::AddFlag<>() : Option " + name + " was specified twice."); - m_options[name] = Option(static_cast<char>(0), name, false, boost::lexical_cast<std::string>(false), description); + m_options[name] = Option(static_cast<char>(0), name, false, boost::lexical_cast<std::string>(false), description, 0, storable); OptionAddedSignal(name); } /** adds an Option with an alternative one-character shortened name, which is treated as a boolean value with a default of false. Using the flag on the command line at all indicates that its value it set to true. */ - void AddFlag(char short_name, const std::string& name, const std::string& description) + void AddFlag(char short_name, const std::string& name, const std::string& description, bool storable = true) { if (m_options.find(name) != m_options.end()) throw std::runtime_error("OptionsDB::AddFlag<>() : Option " + name + " was specified twice."); - m_options[name] = Option(short_name, name, false, boost::lexical_cast<std::string>(false), description); + m_options[name] = Option(short_name, name, false, boost::lexical_cast<std::string>(false), description, 0, storable); OptionAddedSignal(name); } @@ -164,14 +164,14 @@ } void SetFromCommandLine(int argc, char* argv[]); ///< fills some or all of the options of the DB from values passed in from the command line - void SetFromXML(const XMLDoc& doc); ///< fills some or all of the options of the DB from values stored in XMLDoc \a doc + void SetFromXML(const XMLDoc& doc); ///< fills some or all of the options of the DB from values stored in XMLDoc \a doc private: struct Option { Option(); Option(char short_name_, const std::string& name_, const boost::any& value_, const std::string& default_value_, - const std::string& description_, const ValidatorBase *validator_ = 0); + const std::string& description_, const ValidatorBase *validator_, bool storable_); void FromString(const std::string& str); std::string ToString() const; @@ -183,6 +183,7 @@ std::string description; ///< a desription of the option boost::shared_ptr<const ValidatorBase> validator; ///< a validator for the option. Flags have no validators; lexical_cast boolean conversions oare done for them. + bool storable; ///< whether this option can be stored in an XMl config file for use across multiple runs mutable boost::shared_ptr<boost::signal<void ()> > option_changed_sig_ptr; Modified: trunk/FreeOrion/util/Process.cpp =================================================================== --- trunk/FreeOrion/util/Process.cpp 2006-10-21 02:56:15 UTC (rev 1918) +++ trunk/FreeOrion/util/Process.cpp 2006-10-21 18:21:58 UTC (rev 1919) @@ -95,6 +95,7 @@ #include <signal.h> #include <cstdio> + Process::ProcessImpl::ProcessImpl(const std::string& cmd, const std::vector<std::string>& argv) : m_free(false) { |
From: <tz...@us...> - 2006-10-24 03:50:52
|
Revision: 1929 http://svn.sourceforge.net/freeorion/revision/?rev=1929&view=rev Author: tzlaine Date: 2006-10-23 20:50:43 -0700 (Mon, 23 Oct 2006) Log Message: ----------- Generalized the recent commit that allowed random selection of nebula graphics based on the ones available in the nebula graphics directory. Now selection of random graphics or modulo-N graphics is available, chosen from whatever set is available in the applicable directory. Modified Paths: -------------- trunk/FreeOrion/UI/ClientUI.cpp trunk/FreeOrion/UI/ClientUI.h trunk/FreeOrion/UI/MapWnd.cpp trunk/FreeOrion/UI/SidePanel.cpp trunk/FreeOrion/UI/SystemIcon.cpp Added Paths: ----------- trunk/FreeOrion/default/data/art/stars/blackhole1.png trunk/FreeOrion/default/data/art/stars/blackhole2.png Removed Paths: ------------- trunk/FreeOrion/default/data/art/stars/black1.png trunk/FreeOrion/default/data/art/stars/black2.png Modified: trunk/FreeOrion/UI/ClientUI.cpp =================================================================== --- trunk/FreeOrion/UI/ClientUI.cpp 2006-10-24 03:20:25 UTC (rev 1928) +++ trunk/FreeOrion/UI/ClientUI.cpp 2006-10-24 03:50:43 UTC (rev 1929) @@ -27,8 +27,10 @@ #include <log4cpp/PatternLayout.hh> #include <log4cpp/FileAppender.hh> +#include <boost/algorithm/string/predicate.hpp> +#include <boost/filesystem/exception.hpp> +#include <boost/filesystem/fstream.hpp> #include <boost/filesystem/operations.hpp> -#include <boost/filesystem/fstream.hpp> #include <boost/spirit.hpp> #include <string> @@ -96,7 +98,20 @@ GG::Clr ClientUI::TechWndProgressBarBackground() { return GetOptionsDB().Get<StreamableColor>("UI.tech-progress-background").ToClr(); } GG::Clr ClientUI::TechWndProgressBar() { return GetOptionsDB().Get<StreamableColor>("UI.tech-progress").ToClr(); } +std::map<StarType, std::string>& ClientUI::StarTypeFilePrefixes() +{ + static std::map<StarType, std::string> prefixes; + prefixes[STAR_BLUE] = "blue"; + prefixes[STAR_WHITE] = "white"; + prefixes[STAR_YELLOW] = "yellow"; + prefixes[STAR_ORANGE] = "orange"; + prefixes[STAR_RED] = "red"; + prefixes[STAR_NEUTRON] = "neutron"; + prefixes[STAR_BLACK] = "blackhole"; + return prefixes; +} + // private static members log4cpp::Category& ClientUI::s_logger(log4cpp::Category::getRoot()); ClientUI* ClientUI::s_the_UI = 0; @@ -379,6 +394,19 @@ #endif } +boost::shared_ptr<GG::Texture> ClientUI::GetRandomTexture(const boost::filesystem::path& dir, const std::string& prefix) +{ + TexturesAndDist prefixed_textures_and_dist = PrefixedTexturesAndDist(dir, prefix); + return prefixed_textures_and_dist.first[(*prefixed_textures_and_dist.second)()]; +} + +boost::shared_ptr<GG::Texture> ClientUI::GetModuloTexture(const boost::filesystem::path& dir, const std::string& prefix, int n) +{ + assert(0 <= n); + TexturesAndDist prefixed_textures_and_dist = PrefixedTexturesAndDist(dir, prefix); + return prefixed_textures_and_dist.first[n % prefixed_textures_and_dist.first.size()]; +} + ///////////////////////////////////////////////////// //Screen Functions/////////////////////////////////// @@ -556,49 +584,6 @@ } } -boost::shared_ptr<GG::Texture> -ClientUI::GetNumberedTexture(const std::string& dir_name, const std::map<int, std::string>& types_to_names, - int type, int hash_key) -{ - using boost::lexical_cast; - using std::string; - - static std::map<int, std::pair<string, int> > image_names; - - if (image_names.empty()) { - for (std::map<int, std::string>::const_iterator it = types_to_names.begin(); it != types_to_names.end(); ++it) { - image_names[it->first].first = it->second; - } - - fs::path star_dir(ClientUI::ArtDir() / dir_name); - fs::directory_iterator end_it; - for (fs::directory_iterator it(star_dir); it != end_it; ++it) { - if (!fs::is_directory(*it)) { - if (it->leaf().find("blue") == 0) { - ++image_names[STAR_BLUE].second; - } else if (it->leaf().find("white") == 0) { - ++image_names[STAR_WHITE].second; - } else if (it->leaf().find("yellow") == 0) { - ++image_names[STAR_YELLOW].second; - } else if (it->leaf().find("orange") == 0) { - ++image_names[STAR_ORANGE].second; - } else if (it->leaf().find("red") == 0) { - ++image_names[STAR_RED].second; - } else if (it->leaf().find("neutron") == 0) { - ++image_names[STAR_NEUTRON].second; - } else if (it->leaf().find("black") == 0) { - ++image_names[STAR_BLACK].second; - } - } - } - } - - int star_variant = image_names[type].second ? (hash_key % image_names[type].second) : 0; - fs::path path = ClientUI::ArtDir() / "stars" / - (image_names[type].first + lexical_cast<string>(star_variant + 1) + ".png"); - return GetTexture(path); -} - //////////////////////////////////////////////////// void ClientUI::HideAllWindows() { @@ -612,6 +597,32 @@ #endif } +ClientUI::TexturesAndDist ClientUI::PrefixedTexturesAndDist(const boost::filesystem::path& dir, const std::string& prefix) +{ + namespace fs = boost::filesystem; + assert(fs::is_directory(dir)); + const std::string KEY = dir.native_directory_string() + "/" + prefix; + PrefixedTextures::iterator prefixed_textures_it = m_prefixed_textures.find(KEY); + if (prefixed_textures_it == m_prefixed_textures.end()) { + prefixed_textures_it = m_prefixed_textures.insert(std::make_pair(KEY, TexturesAndDist())).first; + std::vector<boost::shared_ptr<GG::Texture> >& textures = prefixed_textures_it->second.first; + boost::shared_ptr<SmallIntDistType>& rand_int = prefixed_textures_it->second.second; + fs::directory_iterator end_it; + for (fs::directory_iterator it(dir); it != end_it; ++it) { + try { + if (fs::exists(*it) && !fs::is_directory(*it) && boost::algorithm::starts_with(it->leaf(), prefix)) + textures.push_back(ClientUI::GetTexture(*it)); + } catch (const fs::filesystem_error& e) { + // ignore files for which permission is denied, and rethrow other exceptions + if (e.error() != fs::security_error) + throw; + } + } + rand_int.reset(new SmallIntDistType(SmallIntDist(0, textures.size() - 1))); + } + return prefixed_textures_it->second; +} + TempUISoundDisabler::TempUISoundDisabler() : m_was_enabled(GetOptionsDB().Get<bool>("UI.sound.enabled")) { Modified: trunk/FreeOrion/UI/ClientUI.h =================================================================== --- trunk/FreeOrion/UI/ClientUI.h 2006-10-24 03:20:25 UTC (rev 1928) +++ trunk/FreeOrion/UI/ClientUI.h 2006-10-24 03:50:43 UTC (rev 1929) @@ -2,9 +2,9 @@ #ifndef _ClientUI_h_ #define _ClientUI_h_ -#ifndef _SitRepEntry_h_ +#include "../universe/Enums.h" #include "../util/SitRepEntry.h" -#endif +#include "../util/Random.h" #ifndef _GG_Wnd_h_ #include <GG/Wnd.h> @@ -115,6 +115,13 @@ bool ZoomToEncyclopediaEntry(const std::string& str); //!< Opens the encyclodedia screen and presents the entry for the given item void ZoomToSystem(System* system); //!< Zooms to a particular system on the galaxy map void ZoomToFleet(Fleet* fleet); //!< Zooms to a particular fleet on the galaxy map and opens the fleet window + + /** Loads a texture at random from the set of files starting with \a prefix in directory \a dir. */ + boost::shared_ptr<GG::Texture> GetRandomTexture(const boost::filesystem::path& dir, const std::string& prefix); + + /** Loads texture \a n % N from the set of files starting with \a prefix in directory \a dir, where N is the number + of files found in \a dir with prefix \a prefix. */ + boost::shared_ptr<GG::Texture> GetModuloTexture(const boost::filesystem::path& dir, const std::string& prefix, int n); //!@} static ClientUI* GetClientUI() {return s_the_UI;} //!< returns a pointer to the singleton ClientUI class @@ -125,24 +132,12 @@ static void LogMessage(const std::string& msg); //!<sends a message to the logger - static void GenerateSitRepText( SitRepEntry *p_sit_rep ); ///< generates a SitRep string from it's XML data. + static void GenerateSitRepText(SitRepEntry *p_sit_rep); ///< generates a SitRep string from it's XML data. /** Loads the requested texture from file \a name; mipmap textures are generated if \a mipmap is true load default missing.png if name isn't found. */ static boost::shared_ptr<GG::Texture> GetTexture(const boost::filesystem::path& path, bool mipmap = false); - /** Loads and returns one of a set of numbered textures. This is supposed to be used to retrieve textures that are numbered, e.g. the star textures - blue1.png, blue2,png, ..., yellow1.png, yellow2.png, etc. It is assumed that all such files are numbered starting with 1, not 0. \a dir_name - is the name of the directory in which the images are found, relative to ClientUI::ArtDir(). - \a types_to_names is a map of object types to their base filenames, e.g. (System::BLUE --> "blue"), (PT_SWAMP --> "swamp"), etc. \a type is - the type of object for which you want a texture, which is used to look up the name in \a types_to_names. \a hash_key is used to pick the numer - from [1, N] of the texture to be used. This number is usually the ID() of the UniverseObject that the texture represents on-screen. This is - used so that the texture used to represent the object is arbitrary, but is always the same, even after a save-reload cycle. \see SystemIcon.cpp - ... for an example of how to use this function. */ - static boost::shared_ptr<GG::Texture> GetNumberedTexture(const std::string& dir_name, const std::map<int, std::string>& types_to_names, - int type, int hash_key); - - //! \name Static Config Data //!@{ static boost::filesystem::path ArtDir(); //!< directory holding artwork static boost::filesystem::path SoundDir(); //!< directory holding sound and music @@ -200,6 +195,8 @@ static GG::Clr UnresearchableTechTextAndBorderColor(); static GG::Clr TechWndProgressBarBackground(); static GG::Clr TechWndProgressBar(); + + static std::map<StarType, std::string>& StarTypeFilePrefixes(); //!@} private: @@ -207,6 +204,10 @@ void SwitchState(State state); //!< switch current state to \a state, free's last state window and create the one for the new state + typedef std::pair<std::vector<boost::shared_ptr<GG::Texture> >, boost::shared_ptr<SmallIntDistType> > TexturesAndDist; + typedef std::map<std::string, TexturesAndDist> PrefixedTextures; + TexturesAndDist PrefixedTexturesAndDist(const boost::filesystem::path& dir, const std::string& prefix); + State m_state; //!< represents the screen currently being displayed IntroScreen* m_intro_screen; //!< the intro (and main menu) screen first showed when the game starts up @@ -216,6 +217,8 @@ int m_previously_shown_system; //!< the ID of the system that was shown in the sidepanel before the last call to HideAllWindows() + PrefixedTextures m_prefixed_textures; + static log4cpp::Category& s_logger; //!< log4cpp logging category static ClientUI* s_the_UI; //!< pointer to the one and only ClientUI object }; Modified: trunk/FreeOrion/UI/MapWnd.cpp =================================================================== --- trunk/FreeOrion/UI/MapWnd.cpp 2006-10-24 03:20:25 UTC (rev 1928) +++ trunk/FreeOrion/UI/MapWnd.cpp 2006-10-24 03:50:43 UTC (rev 1929) @@ -27,10 +27,6 @@ #include <GG/DrawUtil.h> #include <GG/MultiEdit.h> -#include <boost/algorithm/string/predicate.hpp> -#include <boost/filesystem/operations.hpp> -#include <boost/filesystem/exception.hpp> - #include <vector> #include <deque> @@ -80,29 +76,6 @@ return true; } #endif - - boost::shared_ptr<GG::Texture> RandomNebula() - { - static std::vector<boost::shared_ptr<GG::Texture> > nebulae; - static boost::shared_ptr<SmallIntDistType> rand_int; - if (nebulae.empty()) { - namespace fs = boost::filesystem; - fs::directory_iterator end_it; - for (fs::directory_iterator it(ClientUI::ArtDir()); it != end_it; ++it) { - try { - if (fs::exists(*it) && !fs::is_directory(*it) && boost::algorithm::starts_with(it->leaf(), "nebula")) - nebulae.push_back(ClientUI::GetTexture(*it)); - } catch (const fs::filesystem_error& e) { - // ignore files for which permission is denied, and rethrow other exceptions - if (e.error() != fs::security_error) - throw; - } - } - rand_int.reset(new SmallIntDistType(SmallIntDist(0, nebulae.size() - 1))); - } - assert(2 <= nebulae.size()); - return nebulae[(*rand_int)()]; - } } @@ -604,7 +577,7 @@ m_nebula_centers.resize(num_nebulae); SmallIntDistType universe_placement = SmallIntDist(0, static_cast<int>(Universe::UniverseWidth())); for (int i = 0; i < num_nebulae; ++i) { - m_nebulae[i] = RandomNebula(); + m_nebulae[i] = ClientUI::GetClientUI()->GetRandomTexture(ClientUI::ArtDir(), "nebula"); m_nebula_centers[i] = GG::Pt(universe_placement(), universe_placement()); } } Modified: trunk/FreeOrion/UI/SidePanel.cpp =================================================================== --- trunk/FreeOrion/UI/SidePanel.cpp 2006-10-24 03:20:25 UTC (rev 1928) +++ trunk/FreeOrion/UI/SidePanel.cpp 2006-10-24 03:50:43 UTC (rev 1929) @@ -1477,41 +1477,23 @@ int drop_height = std::min(TEXT_ROW_HEIGHT * system_names_in_droplist, MAX_DROPLIST_DROP_HEIGHT) + TOTAL_LISTBOX_MARGIN; m_system_name->SetDropHeight(drop_height); - for (int i = 0; i < m_system_name->NumRows(); i++) + for (int i = 0; i < m_system_name->NumRows(); i++) { if(select_row == &m_system_name->GetRow(i)) { m_system_name->Select(i); break; } - - std::vector<boost::shared_ptr<GG::Texture> > textures; - boost::shared_ptr<GG::Texture> graphic; - - boost::filesystem::path star_image = ClientUI::ArtDir() / "stars_sidepanel"; - std::string star_filename; - switch (s_system->Star()) - { - case STAR_BLUE : star_filename = "blue0" ; break; - case STAR_WHITE : star_filename = "white0" ; break; - case STAR_YELLOW : star_filename = "yellow0" ; break; - case STAR_ORANGE : star_filename = "orange0" ; break; - case STAR_RED : star_filename = "red0" ; break; - case STAR_NEUTRON : star_filename = "neutron0" ; break; - case STAR_BLACK : star_filename = "blackhole0"; break; - default : star_filename = "white0" ; break; } - star_filename += lexical_cast<std::string>(s_system->ID() % 2) + ".png"; - star_image /= star_filename; - std::cout << star_image.native_file_string() << std::endl; - graphic = ClientUI::GetTexture(star_image); - + boost::shared_ptr<GG::Texture> graphic = ClientUI::GetClientUI()->GetModuloTexture(ClientUI::ArtDir() / "stars_sidepanel", ClientUI::StarTypeFilePrefixes()[s_system->Star()], s_system->ID()); + std::vector<boost::shared_ptr<GG::Texture> > textures; textures.push_back(graphic); int star_dim = (Width()*4)/5; m_star_graphic = new GG::DynamicGraphic(Width()-(star_dim*2)/3,-(star_dim*1)/3,star_dim,star_dim,true,textures[0]->DefaultWidth(),textures[0]->DefaultHeight(),0,textures, GG::GR_FITGRAPHIC | GG::GR_PROPSCALE); - AttachChild(m_star_graphic);MoveChildDown(m_star_graphic); + AttachChild(m_star_graphic); + MoveChildDown(m_star_graphic); // TODO: add fleet icons std::pair<System::const_orbit_iterator, System::const_orbit_iterator> range = s_system->non_orbit_range(); @@ -1523,8 +1505,7 @@ std::vector<const Planet*> plt_vec = s_system->FindObjects<Planet>(); m_planet_panel_container->SetPlanets(plt_vec, s_system->Star()); - for(unsigned int i = 0; i < plt_vec.size(); i++) - { + for(unsigned int i = 0; i < plt_vec.size(); i++) { GG::Connect(plt_vec[i]->StateChangedSignal, &SidePanel::PlanetsChanged, this); GG::Connect(plt_vec[i]->ResourceCenterChangedSignal, &SidePanel::PlanetsChanged, this); } Modified: trunk/FreeOrion/UI/SystemIcon.cpp =================================================================== --- trunk/FreeOrion/UI/SystemIcon.cpp 2006-10-24 03:20:25 UTC (rev 1928) +++ trunk/FreeOrion/UI/SystemIcon.cpp 2006-10-24 03:50:43 UTC (rev 1929) @@ -19,21 +19,6 @@ #include <boost/lexical_cast.hpp> -namespace { - const std::map<int, std::string>& StarTypesNames() - { - static std::map<int, std::string> star_type_names; - star_type_names[STAR_BLUE] = "blue"; - star_type_names[STAR_WHITE] = "white"; - star_type_names[STAR_YELLOW] = "yellow"; - star_type_names[STAR_ORANGE] = "orange"; - star_type_names[STAR_RED] = "red"; - star_type_names[STAR_NEUTRON] = "neutron"; - star_type_names[STAR_BLACK] = "black"; - return star_type_names; - } -} - //////////////////////////////////////////////// // OwnerColoredSystemName //////////////////////////////////////////////// @@ -84,9 +69,9 @@ m_system(*GetUniverse().Object<const System>(id)), m_static_graphic(0), m_selection_indicator(0), + m_selected(false), m_name(0), - m_default_star_color(GG::CLR_WHITE), - m_selected(false) + m_default_star_color(GG::CLR_WHITE) { Connect(m_system.StateChangedSignal, &SystemIcon::Refresh, this); @@ -100,7 +85,7 @@ static_cast<int>(ul.y + ClientUI::SystemIconSize() * zoom + 0.5))); // static graphic - boost::shared_ptr<GG::Texture> graphic = ClientUI::GetNumberedTexture("stars", StarTypesNames(), m_system.Star(), m_system.ID()); + boost::shared_ptr<GG::Texture> graphic = ClientUI::GetClientUI()->GetModuloTexture(ClientUI::ArtDir() / "stars", ClientUI::StarTypeFilePrefixes()[m_system.Star()], m_system.ID()); m_static_graphic = new GG::StaticGraphic(0, 0, Width(), Height(), graphic, GG::GR_FITGRAPHIC); AdjustBrightness(m_default_star_color, 0.80); m_static_graphic->SetColor(m_default_star_color); @@ -108,7 +93,7 @@ // selection indicator graphic boost::shared_ptr<GG::Texture> selection_texture = ClientUI::GetTexture(ClientUI::ArtDir() / "misc" / "system_selection.png"); - double size = ClientUI::SystemSelectionIndicatorSize()*Width(); + int size = static_cast<int>(ClientUI::SystemSelectionIndicatorSize() * Width()); m_selection_indicator = new GG::StaticGraphic(0, 0, size, size, selection_texture, GG::GR_FITGRAPHIC); AttachChild(m_selection_indicator); m_selection_indicator->Hide(); @@ -147,8 +132,8 @@ m_static_graphic->SizeMove(GG::Pt(0, 0), lr - ul); if (m_selection_indicator && m_selected) { - double size = ClientUI::SystemSelectionIndicatorSize()*Width(); - GG::Pt ind_ul = GG::Pt((Width() - size)*0.5, (Height() - size)*0.5); + int size = static_cast<int>(ClientUI::SystemSelectionIndicatorSize() * Width()); + GG::Pt ind_ul = GG::Pt((Width() - size) / 2, (Height() - size) / 2); GG::Pt ind_lr = ind_ul + GG::Pt(size, size); m_selection_indicator->SizeMove(ind_ul, ind_lr); m_selection_indicator->Show(); @@ -205,8 +190,8 @@ m_selected = selected; if (m_selected) { - double size = ClientUI::SystemSelectionIndicatorSize()*Width(); - GG::Pt ind_ul = GG::Pt((Width() - size)*0.5, (Height() - size)*0.5); + int size = static_cast<int>(ClientUI::SystemSelectionIndicatorSize() * Width()); + GG::Pt ind_ul = GG::Pt((Width() - size) / 2, (Height() - size) / 2); GG::Pt ind_lr = ind_ul + GG::Pt(size, size); m_selection_indicator->SizeMove(ind_ul, ind_lr); m_selection_indicator->Show(); Deleted: trunk/FreeOrion/default/data/art/stars/black1.png =================================================================== (Binary files differ) Deleted: trunk/FreeOrion/default/data/art/stars/black2.png =================================================================== (Binary files differ) Copied: trunk/FreeOrion/default/data/art/stars/blackhole1.png (from rev 1925, trunk/FreeOrion/default/data/art/stars/black1.png) =================================================================== (Binary files differ) Copied: trunk/FreeOrion/default/data/art/stars/blackhole2.png (from rev 1925, trunk/FreeOrion/default/data/art/stars/black2.png) =================================================================== (Binary files differ) |
From: <tz...@us...> - 2006-10-26 01:18:52
|
Revision: 1931 http://svn.sourceforge.net/freeorion/revision/?rev=1931&view=rev Author: tzlaine Date: 2006-10-25 18:18:46 -0700 (Wed, 25 Oct 2006) Log Message: ----------- Several small bugfixes: - Fixed a small leak in SidePanel. - Added a check against null on the ShipRow passed to FleetDetailPanel::ShipRightClicked(). - Fixed a potential null pointer dereference in FollowReference() in ValueRef.cpp. - Added several assert()s in several files in order to ensure some assumptions are being met. Modified Paths: -------------- trunk/FreeOrion/Empire/Empire.cpp trunk/FreeOrion/UI/FleetWnd.cpp trunk/FreeOrion/UI/MapWnd.cpp trunk/FreeOrion/UI/SidePanel.cpp trunk/FreeOrion/server/ServerApp.cpp trunk/FreeOrion/universe/ResourceCenter.cpp trunk/FreeOrion/universe/Universe.cpp trunk/FreeOrion/universe/ValueRef.cpp Modified: trunk/FreeOrion/Empire/Empire.cpp =================================================================== --- trunk/FreeOrion/Empire/Empire.cpp 2006-10-25 05:12:05 UTC (rev 1930) +++ trunk/FreeOrion/Empire/Empire.cpp 2006-10-26 01:18:46 UTC (rev 1931) @@ -1396,28 +1396,21 @@ { m_food_resource_pool.Update(); // recalculate total food production - //Logger().debugStream() << "Empire::UpdateFoodDistribution for empire " << m_id; - double available_food = GetFoodResPool().Available(); m_food_total_distributed = 0.0; - //Logger().debugStream() << "Empire::UpdateFoodDistribution: total available_food = " << available_food; - std::vector<PopCenter*> pop_centers = GetPopulationPool().PopCenters(); //GetUniverse().FindObjects(OwnedVisitor<PopCenter>(m_id)); std::vector<PopCenter*>::iterator pop_it; std::vector<ResourceCenter*> resource_centers = GetFoodResPool().ResourceCenters(); //GetUniverse().FindObjects(OwnedVisitor<ResourceCenter>(m_id)); std::vector<ResourceCenter*>::iterator res_it; - //Logger().debugStream() << "Empire::UpdateFoodDistribution: pop_centers.size() = " << pop_centers.size(); - // compile map of food production of ResourceCenters, indexed by center's id std::map<int, double> fp_map; - std::map<int, double>::iterator fp_map_it; for (res_it = resource_centers.begin(); res_it != resource_centers.end(); ++res_it) { ResourceCenter *center = *res_it; UniverseObject *obj = dynamic_cast<UniverseObject*>(center); // can't use universe_object_cast<UniverseObject*> because ResourceCenter is not derived from UniverseObject - if (!obj) continue; // apparently wasn't a valid object... might want to throw an error in this situation instead... + assert(obj); fp_map[obj->ID()] = center->FarmingPoints(); } @@ -1427,29 +1420,18 @@ PopCenter *center = *pop_it; double need = center->PopPoints(); // basic need is current population - prevents starvation - //Logger().debugStream() << "Empire::UpdateFoodDistribution: PopCenter needs: " << need; - UniverseObject *obj = dynamic_cast<UniverseObject*>(center); // can't use universe_object_cast<UniverseObject*> because ResourceCenter is not derived from UniverseObject - if (!obj) - { - // apparently wasn't a valid object... might want to throw an error in this situation instead... - center->SetAvailableFood(0.0); - continue; - } + assert(obj); // determine if, and if so how much, food this center produces locally double food_prod = 0.0; - fp_map_it = fp_map.find(obj->ID()); + std::map<int, double>::iterator fp_map_it = fp_map.find(obj->ID()); if (fp_map_it != fp_map.end()) food_prod = fp_map_it->second; - //Logger().debugStream() << "Empire::UpdateFoodDistribution: PopCenter produces: " << food_prod; - // allocate food to this PopCenter, deduct from pool, add to total food distribution tally double allocation = std::min(available_food, std::min(need, food_prod)); - //Logger().debugStream() << "Empire::UpdateFoodDistribution: PopCenter allocated: " << allocation; - center->SetAvailableFood(allocation); m_food_total_distributed += allocation; available_food -= allocation; @@ -1477,13 +1459,14 @@ { PopCenter *center = *pop_it; double basic_need = center->PopPoints(); - double full_need = 2*basic_need; + double full_need = 2 * basic_need; double has = center->AvailableFood(); UniverseObject *obj = dynamic_cast<UniverseObject*>(center); + assert(obj); double food_prod = 0.0; - fp_map_it = fp_map.find(obj->ID()); + std::map<int, double>::iterator fp_map_it = fp_map.find(obj->ID()); if (fp_map_it != fp_map.end()) food_prod = fp_map_it->second; @@ -1509,6 +1492,7 @@ available_food -= addition; m_food_total_distributed += addition; } + // after changing food distribution, population growth predictions may need to be redone // by calling UpdatePopulationGrowth() Modified: trunk/FreeOrion/UI/FleetWnd.cpp =================================================================== --- trunk/FreeOrion/UI/FleetWnd.cpp 2006-10-25 05:12:05 UTC (rev 1930) +++ trunk/FreeOrion/UI/FleetWnd.cpp 2006-10-26 01:18:46 UTC (rev 1931) @@ -828,7 +828,7 @@ { ShipRow* ship_row = dynamic_cast<ShipRow*>(row); - if (ship_row->m_ship->Owners().size() != 1 || HumanClientApp::GetApp()->EmpireID() != *ship_row->m_ship->Owners().begin()) + if (!ship_row || ship_row->m_ship->Owners().size() != 1 || HumanClientApp::GetApp()->EmpireID() != *ship_row->m_ship->Owners().begin()) return; Ship* ship = GetUniverse().Object<Ship>(ship_row->ShipID()); Modified: trunk/FreeOrion/UI/MapWnd.cpp =================================================================== --- trunk/FreeOrion/UI/MapWnd.cpp 2006-10-25 05:12:05 UTC (rev 1930) +++ trunk/FreeOrion/UI/MapWnd.cpp 2006-10-26 01:18:46 UTC (rev 1931) @@ -655,17 +655,16 @@ MoveChildUp(m_sitrep_panel); // are there any sitreps to show? - Empire *empire = HumanClientApp::GetApp()->Empires().Lookup( HumanClientApp::GetApp()->EmpireID() ); + Empire* empire = HumanClientApp::GetApp()->Empires().Lookup(HumanClientApp::GetApp()->EmpireID()); + assert(empire); m_sitrep_panel->Update(); // HACK! The first time this SitRepPanel gets an update, the report row(s) are misaligned. I have no idea why, and // I am sick of dealing with it, so I'm forcing a resize in order to force it to behave. m_sitrep_panel->Resize(m_sitrep_panel->Size()); - if (empire) { - if (empire->NumSitRepEntries()) - m_sitrep_panel->Show(); - else - m_sitrep_panel->Hide(); - } + if (empire->NumSitRepEntries()) + m_sitrep_panel->Show(); + else + m_sitrep_panel->Hide(); m_research_wnd->Hide(); m_production_wnd->Hide(); Modified: trunk/FreeOrion/UI/SidePanel.cpp =================================================================== --- trunk/FreeOrion/UI/SidePanel.cpp 2006-10-25 05:12:05 UTC (rev 1930) +++ trunk/FreeOrion/UI/SidePanel.cpp 2006-10-26 01:18:46 UTC (rev 1931) @@ -1457,10 +1457,12 @@ GG::ListBox::Row *row = new SystemRow(sys_vec[i]->ID()); if (sys_vec[i]->Name().length()==0) { - if (sys_vec[i] == s_system) + if (sys_vec[i] == s_system) { row->push_back(UserString("SP_UNKNOWN_SYSTEM"), ClientUI::Font(), SystemNameFontSize(), ClientUI::TextColor()); - else + } else { + delete row; continue; + } } else { row->push_back(new OwnerColoredSystemName(sys_vec[i], HumanClientApp::GetApp()->GetFont(ClientUI::Font(), SystemNameFontSize()), UserString("SP_SYSTEM_NAME"))); } Modified: trunk/FreeOrion/server/ServerApp.cpp =================================================================== --- trunk/FreeOrion/server/ServerApp.cpp 2006-10-25 05:12:05 UTC (rev 1930) +++ trunk/FreeOrion/server/ServerApp.cpp 2006-10-26 01:18:46 UTC (rev 1931) @@ -1402,6 +1402,8 @@ // since this must be an AI player, it does not have the correct player name set in its Empire yet, so we need to do so now Empires().Lookup(empire_id)->SetPlayerName(it->second.name); break; + } else { + assert(!"No empire id was found for one of the players in ServerApp::LoadGameInit()."); } } } Modified: trunk/FreeOrion/universe/ResourceCenter.cpp =================================================================== --- trunk/FreeOrion/universe/ResourceCenter.cpp 2006-10-25 05:12:05 UTC (rev 1930) +++ trunk/FreeOrion/universe/ResourceCenter.cpp 2006-10-26 01:18:46 UTC (rev 1931) @@ -223,6 +223,7 @@ else if (focus == FOCUS_BALANCED) new_max_mods = ProductionDataTables()["FocusMods"][2][0]; Meter* meter = GetMeter(i); + assert(meter); meter->SetMax(meter->Max() + new_max_mods - old_max_mods); } m_primary = focus; @@ -243,6 +244,7 @@ else if (focus == FOCUS_BALANCED) new_max_mods = ProductionDataTables()["FocusMods"][3][0]; Meter* meter = GetMeter(i); + assert(meter); meter->SetMax(meter->Max() + new_max_mods - old_max_mods); } m_secondary = focus; Modified: trunk/FreeOrion/universe/Universe.cpp =================================================================== --- trunk/FreeOrion/universe/Universe.cpp 2006-10-25 05:12:05 UTC (rev 1930) +++ trunk/FreeOrion/universe/Universe.cpp 2006-10-26 01:18:46 UTC (rev 1931) @@ -758,7 +758,6 @@ for (n = 0; n < theSize - 3; n++) { pointNumList.clear(); - // check each triangle in list, to see if the new point lies in its circumcircle. if so, delete // the triangle and add its vertices to a list itCur = triList->begin(); @@ -825,6 +824,7 @@ // go through list of points, making new triangles out of them itCur2 = pointNumList.begin(); itEnd2 = pointNumList.end(); + assert(itCur2 != itEnd2); // add triangle for last and first points and n triList->push_front(Delauney::DTTriangle(n, (pointNumList.front()).num, (pointNumList.back()).num, points)); @@ -1844,6 +1844,7 @@ // extract data on starlane vector... laneVectsMapIter = laneVectsMap.find(dest1); + assert(laneVectsMapIter != laneVectsMap.end()); tempVectAndMag = laneVectsMapIter->second; tempVect = tempVectAndMag.first; vectX1 = tempVect.first; @@ -1865,6 +1866,7 @@ // extract data on starlane vector... laneVectsMapIter = laneVectsMap.find(dest2); + assert(laneVectsMapIter != laneVectsMap.end()); tempVectAndMag = laneVectsMapIter->second; tempVect = tempVectAndMag.first; vectX2 = tempVect.first; Modified: trunk/FreeOrion/universe/ValueRef.cpp =================================================================== --- trunk/FreeOrion/universe/ValueRef.cpp 2006-10-25 05:12:05 UTC (rev 1930) +++ trunk/FreeOrion/universe/ValueRef.cpp 2006-10-26 01:18:46 UTC (rev 1931) @@ -38,7 +38,8 @@ obj = 0; } } else if (*first == "System") { - obj = obj->GetSystem(); + if (obj) + obj = obj->GetSystem(); } ++first; } |
From: <tz...@us...> - 2006-10-29 03:25:07
|
Revision: 1936 http://svn.sourceforge.net/freeorion/revision/?rev=1936&view=rev Author: tzlaine Date: 2006-10-28 20:24:58 -0700 (Sat, 28 Oct 2006) Log Message: ----------- Firmed up the Boost.Serialization code. A lot more things are serializable now, and the Universe and Empires are fully serializable. Modified Paths: -------------- trunk/FreeOrion/Empire/Empire.h trunk/FreeOrion/Empire/ResourcePool.h trunk/FreeOrion/server/ServerApp.cpp trunk/FreeOrion/universe/Building.h trunk/FreeOrion/universe/Condition.h trunk/FreeOrion/universe/Effect.h trunk/FreeOrion/universe/Fleet.h trunk/FreeOrion/universe/Planet.h trunk/FreeOrion/universe/PopCenter.cpp trunk/FreeOrion/universe/PopCenter.h trunk/FreeOrion/universe/ResourceCenter.cpp trunk/FreeOrion/universe/ResourceCenter.h trunk/FreeOrion/universe/Special.h trunk/FreeOrion/universe/UniverseObject.h trunk/FreeOrion/universe/ValueRef.h trunk/FreeOrion/util/Serialize.cpp Modified: trunk/FreeOrion/Empire/Empire.h =================================================================== --- trunk/FreeOrion/Empire/Empire.h 2006-10-27 22:06:40 UTC (rev 1935) +++ trunk/FreeOrion/Empire/Empire.h 2006-10-29 03:24:58 UTC (rev 1936) @@ -35,9 +35,9 @@ typedef std::deque<Element> QueueType; - /** The ResearchQueue iterator type. Dereference yields a Element. */ + /** The ResearchQueue iterator type. Dereference yields an Element. */ typedef QueueType::iterator iterator; - /** The const ResearchQueue iterator type. Dereference yields a Element. */ + /** The const ResearchQueue iterator type. Dereference yields an Element. */ typedef QueueType::const_iterator const_iterator; /** \name Structors */ //@{ @@ -678,9 +678,11 @@ & BOOST_SERIALIZATION_NVP(m_mineral_resource_pool) & BOOST_SERIALIZATION_NVP(m_food_resource_pool) & BOOST_SERIALIZATION_NVP(m_research_resource_pool) + & BOOST_SERIALIZATION_NVP(m_industry_resource_pool) + & BOOST_SERIALIZATION_NVP(m_trade_resource_pool) & BOOST_SERIALIZATION_NVP(m_population_pool) - & BOOST_SERIALIZATION_NVP(m_industry_resource_pool) - & BOOST_SERIALIZATION_NVP(m_trade_resource_pool); + & BOOST_SERIALIZATION_NVP(m_food_total_distributed) + & BOOST_SERIALIZATION_NVP(m_maintenance_total_cost); } } Modified: trunk/FreeOrion/Empire/ResourcePool.h =================================================================== --- trunk/FreeOrion/Empire/ResourcePool.h 2006-10-27 22:06:40 UTC (rev 1935) +++ trunk/FreeOrion/Empire/ResourcePool.h 2006-10-29 03:24:58 UTC (rev 1936) @@ -122,7 +122,7 @@ void PopulationPool::serialize(Archive& ar, const unsigned int version) { ar & BOOST_SERIALIZATION_NVP(m_pop_centers) - & BOOST_SERIALIZATION_NVP(m_population) - & BOOST_SERIALIZATION_NVP(m_growth); + & BOOST_SERIALIZATION_NVP(m_population) + & BOOST_SERIALIZATION_NVP(m_growth); } #endif // _ResourcePool_h_ Modified: trunk/FreeOrion/server/ServerApp.cpp =================================================================== --- trunk/FreeOrion/server/ServerApp.cpp 2006-10-27 22:06:40 UTC (rev 1935) +++ trunk/FreeOrion/server/ServerApp.cpp 2006-10-29 03:24:58 UTC (rev 1936) @@ -62,12 +62,9 @@ #endif #define TEST_BOOST_SERIALIZATION 0 -#define TEST_BINARY_ARCHIVES 1 +#define TEST_BINARY_ARCHIVES 0 #if TEST_BOOST_SERIALIZATION #include "../util/Serialize.h" -#include <boost/iostreams/device/back_inserter.hpp> -#include <boost/iostreams/filtering_stream.hpp> -#include <boost/range/iterator_range.hpp> #endif @@ -108,7 +105,7 @@ } } - // build list of empire colors + // get list of empire colors empire_colors = EmpireColors(); } } @@ -556,16 +553,88 @@ doc.ReadDoc(ifs); ifs.close(); +#if TEST_BOOST_SERIALIZATION + std::map<Empire*, XMLElement> empire_docs; +#endif + m_expected_players = 0; for (int i = 0; i < doc.root_node.NumChildren(); ++i) { if (doc.root_node.Child(i).Tag() == "Player") { - m_empires.InsertEmpire(new Empire(doc.root_node.Child(i).Child("Empire"))); + Empire* empire = new Empire(doc.root_node.Child(i).Child("Empire")); + m_empires.InsertEmpire(empire); ++m_expected_players; +#if TEST_BOOST_SERIALIZATION + empire_docs[empire] = doc.root_node.Child(i).Child("Empire"); +#endif } } m_universe.SetUniverse(doc.root_node.Child("Universe")); LoadGameVars(doc); +#if TEST_BOOST_SERIALIZATION + using boost::lexical_cast; + for (std::map<Empire*, XMLElement>::iterator it = empire_docs.begin(); it != empire_docs.end(); ++it) { + Empire test_empire("", "", 0, GG::Clr(), 0); + std::ostringstream os; + { + boost::archive::binary_oarchive oa(os); + Serialize(&oa, *it->first); + } + std::ofstream ofs(("test_boost_empire_" + lexical_cast<std::string>(it->first->EmpireID())).c_str()); + ofs << os.str(); + { + std::ifstream ifs(("test_boost_empire_" + lexical_cast<std::string>(it->first->EmpireID())).c_str()); + boost::archive::binary_iarchive ia(ifs); + Deserialize(&ia, test_empire); + } + { + XMLDoc empire_doc; + empire_doc.root_node.AppendChild(it->first->XMLEncode(ALL_EMPIRES)); + for (int i = 0; i <= 4; ++i) + empire_doc.root_node.AppendChild(it->first->XMLEncode(i)); + std::ofstream ofs(("empire_" + lexical_cast<std::string>(it->first->EmpireID()) + "_doc.xml").c_str()); + empire_doc.WriteDoc(ofs); + } + { + XMLDoc copy_empire_doc; + copy_empire_doc.root_node.AppendChild(it->first->XMLEncode(ALL_EMPIRES)); + for (int i = 0; i <= 4; ++i) + copy_empire_doc.root_node.AppendChild(it->first->XMLEncode(i)); + std::ofstream ofs(("empire_" + lexical_cast<std::string>(it->first->EmpireID()) + "_doc_copy.xml").c_str()); + copy_empire_doc.WriteDoc(ofs); + } + std::cout << "loaded empire " << it->first->EmpireID() << " successfully" << std::endl; + } + + Universe test_universe; + std::ostringstream os; + { + boost::archive::binary_oarchive oa(os); + Serialize(&oa, m_universe); + } + std::ofstream ofs("test_boost_universe", std::ios_base::binary); + ofs << os.str(); + { + std::ifstream ifs("test_boost_universe", std::ios_base::binary); + boost::archive::binary_iarchive ia(ifs); + Deserialize(&ia, test_universe); + } + { + XMLDoc universe_doc; + universe_doc.root_node.AppendChild(m_universe.XMLEncode(ALL_EMPIRES)); + std::ofstream ofs("universe_doc.xml"); + universe_doc.WriteDoc(ofs); + } + { + XMLDoc copy_universe_doc; + copy_universe_doc.root_node.AppendChild(test_universe.XMLEncode(ALL_EMPIRES)); + std::ofstream ofs("universe_doc_copy.xml"); + copy_universe_doc.WriteDoc(ofs); + } + + std::cout << "loaded universe successfully" << std::endl; +#endif + CreateAIClients(std::vector<PlayerSetupData>(m_expected_players - 1)); g_load_doc = doc; m_state = SERVER_GAME_SETUP; @@ -1283,7 +1352,7 @@ AddEmpireTurn( it->first ); } -#if TEST_BOOST_SERIALIZATION +#if 0//TEST_BOOST_SERIALIZATION { Universe::s_encoding_empire = Universe::ALL_EMPIRES; std::string encoded_string; @@ -1318,7 +1387,7 @@ doc.root_node.AppendChild(m_empires.CreateClientEmpireUpdate(it->first)); doc.root_node.AppendChild(XMLElement("empire_id", boost::lexical_cast<std::string>(it->first))); -#if TEST_BOOST_SERIALIZATION +#if 0//TEST_BOOST_SERIALIZATION { Universe::s_encoding_empire = it->first; std::string encoded_string; @@ -1917,7 +1986,7 @@ { pEmpire = GetPlayerEmpire( player_it->first ); XMLDoc doc = CreateTurnUpdate( pEmpire->EmpireID() ); -#if TEST_BOOST_SERIALIZATION +#if 0//TEST_BOOST_SERIALIZATION { Universe::s_encoding_empire = pEmpire->EmpireID(); std::string encoded_string; Modified: trunk/FreeOrion/universe/Building.h =================================================================== --- trunk/FreeOrion/universe/Building.h 2006-10-27 22:06:40 UTC (rev 1935) +++ trunk/FreeOrion/universe/Building.h 2006-10-29 03:24:58 UTC (rev 1936) @@ -139,7 +139,8 @@ & BOOST_SERIALIZATION_NVP(m_build_cost) & BOOST_SERIALIZATION_NVP(m_build_time) & BOOST_SERIALIZATION_NVP(m_maintenance_cost) - // TODO: & BOOST_SERIALIZATION_NVP(m_effects) + & BOOST_SERIALIZATION_NVP(m_location) + & BOOST_SERIALIZATION_NVP(m_effects) & BOOST_SERIALIZATION_NVP(m_graphic); } Modified: trunk/FreeOrion/universe/Condition.h =================================================================== --- trunk/FreeOrion/universe/Condition.h 2006-10-27 22:06:40 UTC (rev 1935) +++ trunk/FreeOrion/universe/Condition.h 2006-10-29 03:24:58 UTC (rev 1936) @@ -60,6 +60,10 @@ private: virtual bool Match(const UniverseObject* source, const UniverseObject* target) const; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; /** Matches all objects if the number of objects that match Condition \a condition is is >= \a low and < \a high. @@ -76,6 +80,10 @@ const ValueRef::ValueRefBase<int>* m_low; const ValueRef::ValueRefBase<int>* m_high; const ConditionBase* m_condition; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; /** Matches all objects if the current game turn is >= \a low and < \a high. */ @@ -90,6 +98,10 @@ private: const ValueRef::ValueRefBase<int>* m_low; const ValueRef::ValueRefBase<int>* m_high; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; /** Matches a randomly selected \a number of objects that match Condition \a condition, or as many objects @@ -105,6 +117,10 @@ private: const ValueRef::ValueRefBase<int>* m_number; const ConditionBase* m_condition; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; /** Matches all objects. */ @@ -114,6 +130,10 @@ virtual void Eval(const UniverseObject* source, Condition::ObjectSet& targets, Condition::ObjectSet& non_targets, SearchDomain search_domain = NON_TARGETS) const; virtual std::string Description(bool negated = false) const; virtual std::string Dump() const; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; /** Matches all objects that are owned (if \a exclusive == false) or only owned (if \a exclusive == true) by an empire that has @@ -130,6 +150,10 @@ const ValueRef::ValueRefBase<int>* m_empire_id; EmpireAffiliationType m_affiliation; bool m_exclusive; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; /** Matches the source object only. */ @@ -141,6 +165,10 @@ private: virtual bool Match(const UniverseObject* source, const UniverseObject* target) const; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; /** Matches all objects that are of UniverseObjectType \a type. */ @@ -153,6 +181,10 @@ private: virtual bool Match(const UniverseObject* source, const UniverseObject* target) const; const ValueRef::ValueRefBase<UniverseObjectType>* m_type; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; /** Matches all Building objects of the sort specified by \a name. */ @@ -165,6 +197,10 @@ private: virtual bool Match(const UniverseObject* source, const UniverseObject* target) const; std::string m_name; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; /** Matches all objects that have an attached Special of the sort specified by \a name. Passing "All" for @@ -178,6 +214,10 @@ private: virtual bool Match(const UniverseObject* source, const UniverseObject* target) const; std::string m_name; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; /** Matches all objects that contain an object that matches Condition \a condition. Container objects are Systems, @@ -191,6 +231,10 @@ private: const ConditionBase* m_condition; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; /** Matches all objects that are contained by an object that matches Condition \a condition. Container objects @@ -204,6 +248,10 @@ private: const ConditionBase* m_condition; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; /** Matches all Planet objects that have one of the PlanetTypes in \a types. Note that all @@ -218,6 +266,10 @@ private: virtual bool Match(const UniverseObject* source, const UniverseObject* target) const; std::vector<const ValueRef::ValueRefBase< ::PlanetType>*> m_types; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; /** Matches all Planet objects that have one of the PlanetSizes in \a sizes. Note that all @@ -232,6 +284,10 @@ private: virtual bool Match(const UniverseObject* source, const UniverseObject* target) const; std::vector<const ValueRef::ValueRefBase< ::PlanetSize>*> m_sizes; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; /** Matches all Planet objects that have one of the PlanetEnvironments in \a environments. Note that all @@ -246,6 +302,10 @@ private: virtual bool Match(const UniverseObject* source, const UniverseObject* target) const; std::vector<const ValueRef::ValueRefBase< ::PlanetEnvironment>*> m_environments; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; /** Matches all ProdCenter objects that have one of the FocusTypes in \a foci. */ @@ -260,6 +320,10 @@ virtual bool Match(const UniverseObject* source, const UniverseObject* target) const; std::vector<const ValueRef::ValueRefBase< ::FocusType>*> m_foci; bool m_primary; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; /** Matches all System objects that have one of the StarTypes in \a types. Note that all objects @@ -274,6 +338,10 @@ private: virtual bool Match(const UniverseObject* source, const UniverseObject* target) const; std::vector<const ValueRef::ValueRefBase< ::StarType>*> m_types; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; /** Matches a given object with a linearly distributed probability of \a chance. */ @@ -287,6 +355,10 @@ private: virtual bool Match(const UniverseObject* source, const UniverseObject* target) const; const ValueRef::ValueRefBase<double>* m_chance; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; /** Matches all objects that have a meter of type \a meter, and whose current value (if \a max_meter == false) or @@ -304,6 +376,10 @@ const ValueRef::ValueRefBase<double>* m_low; const ValueRef::ValueRefBase<double>* m_high; bool m_max_meter; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; /** Matches all objects with exactly one owner, whose owner's stockpile of \a stockpile is between \a low @@ -320,6 +396,10 @@ ResourceType m_stockpile; const ValueRef::ValueRefBase<double>* m_low; const ValueRef::ValueRefBase<double>* m_high; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; /** Matches all objects that have a single owner who has tech \a tech_name. */ @@ -332,6 +412,10 @@ private: virtual bool Match(const UniverseObject* source, const UniverseObject* target) const; std::string m_name; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; /** Matches all objects that are visible to at least one Empire in \a empire_ids. */ @@ -345,6 +429,10 @@ private: virtual bool Match(const UniverseObject* source, const UniverseObject* target) const; std::vector<const ValueRef::ValueRefBase<int>*> m_empire_ids; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; /** Matches all objects that are within \a distance units of at least one object that meets \a condition. @@ -362,6 +450,10 @@ virtual bool Match(const UniverseObject* source, const UniverseObject* target) const; const ValueRef::ValueRefBase<double>* m_distance; const ConditionBase* m_condition; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; /** Matches all objects that are within \a jumps starlane jumps of at least one object that meets \a condition. @@ -379,6 +471,10 @@ virtual bool Match(const UniverseObject* source, const UniverseObject* target) const; const ValueRef::ValueRefBase<int>* m_jumps; const ConditionBase* m_condition; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; struct Condition::EffectTarget : Condition::ConditionBase @@ -389,6 +485,10 @@ private: virtual bool Match(const UniverseObject* source, const UniverseObject* target) const; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; /** Matches all objects that match every Condition in \a operands. */ @@ -402,6 +502,10 @@ private: std::vector<const ConditionBase*> m_operands; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; /** Matches all objects that match at least one Condition in \a operands. */ @@ -415,6 +519,10 @@ private: std::vector<const ConditionBase*> m_operands; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; /** Matches all objects that do not match the Condition \a operand. */ @@ -428,6 +536,214 @@ private: const ConditionBase* m_operand; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; +// template implementations +template <class Archive> +void Condition::ConditionBase::serialize(Archive& ar, const unsigned int version) +{} + +template <class Archive> +void Condition::Number::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(ConditionBase) + & BOOST_SERIALIZATION_NVP(m_low) + & BOOST_SERIALIZATION_NVP(m_high) + & BOOST_SERIALIZATION_NVP(m_condition); +} + +template <class Archive> +void Condition::Turn::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(ConditionBase) + & BOOST_SERIALIZATION_NVP(m_low) + & BOOST_SERIALIZATION_NVP(m_high); +} + +template <class Archive> +void Condition::NumberOf::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(ConditionBase) + & BOOST_SERIALIZATION_NVP(m_number) + & BOOST_SERIALIZATION_NVP(m_condition); +} + +template <class Archive> +void Condition::All::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(ConditionBase); +} + +template <class Archive> +void Condition::EmpireAffiliation::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(ConditionBase) + & BOOST_SERIALIZATION_NVP(m_empire_id) + & BOOST_SERIALIZATION_NVP(m_affiliation) + & BOOST_SERIALIZATION_NVP(m_exclusive); +} + +template <class Archive> +void Condition::Self::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(ConditionBase); +} + +template <class Archive> +void Condition::Type::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(ConditionBase) + & BOOST_SERIALIZATION_NVP(m_type); +} + +template <class Archive> +void Condition::Building::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(ConditionBase) + & BOOST_SERIALIZATION_NVP(m_name); +} + +template <class Archive> +void Condition::HasSpecial::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(ConditionBase) + & BOOST_SERIALIZATION_NVP(m_name); +} + +template <class Archive> +void Condition::Contains::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(ConditionBase) + & BOOST_SERIALIZATION_NVP(m_condition); +} + +template <class Archive> +void Condition::ContainedBy::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(ConditionBase) + & BOOST_SERIALIZATION_NVP(m_condition); +} + +template <class Archive> +void Condition::PlanetType::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(ConditionBase) + & BOOST_SERIALIZATION_NVP(m_types); +} + +template <class Archive> +void Condition::PlanetSize::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(ConditionBase) + & BOOST_SERIALIZATION_NVP(m_sizes); +} + +template <class Archive> +void Condition::PlanetEnvironment::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(ConditionBase) + & BOOST_SERIALIZATION_NVP(m_environments); +} + +template <class Archive> +void Condition::FocusType::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(ConditionBase) + & BOOST_SERIALIZATION_NVP(m_foci) + & BOOST_SERIALIZATION_NVP(m_primary); +} + +template <class Archive> +void Condition::StarType::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(ConditionBase) + & BOOST_SERIALIZATION_NVP(m_types); +} + +template <class Archive> +void Condition::Chance::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(ConditionBase) + & BOOST_SERIALIZATION_NVP(m_chance); +} + +template <class Archive> +void Condition::MeterValue::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(ConditionBase) + & BOOST_SERIALIZATION_NVP(m_meter) + & BOOST_SERIALIZATION_NVP(m_low) + & BOOST_SERIALIZATION_NVP(m_high) + & BOOST_SERIALIZATION_NVP(m_max_meter); +} + +template <class Archive> +void Condition::EmpireStockpileValue::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(ConditionBase) + & BOOST_SERIALIZATION_NVP(m_low) + & BOOST_SERIALIZATION_NVP(m_high); +} + +template <class Archive> +void Condition::OwnerHasTech::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(ConditionBase) + & BOOST_SERIALIZATION_NVP(m_name); +} + +template <class Archive> +void Condition::VisibleToEmpire::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(ConditionBase) + & BOOST_SERIALIZATION_NVP(m_empire_ids); +} + +template <class Archive> +void Condition::WithinDistance::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(ConditionBase) + & BOOST_SERIALIZATION_NVP(m_distance) + & BOOST_SERIALIZATION_NVP(m_condition); +} + +template <class Archive> +void Condition::WithinStarlaneJumps::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(ConditionBase) + & BOOST_SERIALIZATION_NVP(m_jumps) + & BOOST_SERIALIZATION_NVP(m_condition); +} + +template <class Archive> +void Condition::EffectTarget::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(ConditionBase); +} + +template <class Archive> +void Condition::And::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(ConditionBase) + & BOOST_SERIALIZATION_NVP(m_operands); +} + +template <class Archive> +void Condition::Or::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(ConditionBase) + & BOOST_SERIALIZATION_NVP(m_operands); +} + +template <class Archive> +void Condition::Not::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(ConditionBase) + & BOOST_SERIALIZATION_NVP(m_operand); +} + #endif // _Condition_h_ Modified: trunk/FreeOrion/universe/Effect.h =================================================================== --- trunk/FreeOrion/universe/Effect.h 2006-10-27 22:06:40 UTC (rev 1935) +++ trunk/FreeOrion/universe/Effect.h 2006-10-29 03:24:58 UTC (rev 1936) @@ -8,6 +8,8 @@ #include "Enums.h" #include <boost/shared_ptr.hpp> +#include <boost/serialization/access.hpp> +#include <boost/serialization/nvp.hpp> class UniverseObject; @@ -75,6 +77,11 @@ std::string m_stacking_group; std::string m_explicit_description; std::vector<EffectBase*> m_effects; + +private: + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; /** Returns a single string which describes a vector of EffectsGroups. */ @@ -91,6 +98,11 @@ virtual void Execute(const UniverseObject* source, UniverseObject* target) const = 0; virtual std::string Description() const = 0; virtual std::string Dump() const = 0; + +private: + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; /** Sets the meter of the given kind to \a value. The max value of the meter is set if \a max == true; otherwise the @@ -110,6 +122,10 @@ MeterType m_meter; const ValueRef::ValueRefBase<double>* m_value; bool m_max; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; /** Sets the empire stockpile of the target's owning empire to \a value. If the target does not have exactly one owner, @@ -127,6 +143,10 @@ private: ResourceType m_stockpile; const ValueRef::ValueRefBase<double>* m_value; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; /** Sets the planet type of the target to \a type. This has no effect on non-Planet targets. Note that changing the @@ -145,6 +165,10 @@ private: const ValueRef::ValueRefBase<PlanetType>* m_type; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; /** Sets the planet size of the target to \a size. This has no effect on non-Planet targets. Note that changing the @@ -162,6 +186,10 @@ private: const ValueRef::ValueRefBase<PlanetSize>* m_size; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; /** Adds empire \a empire_id as an owner of the target. This has no effect if \a empire_id was already an owner of the target object. */ @@ -177,6 +205,10 @@ private: const ValueRef::ValueRefBase<int>* m_empire_id; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; /** Removes empire \a empire_id as an owner of the target. This has no effect if \a empire_id was not already an owner of the target object. */ @@ -192,6 +224,10 @@ private: const ValueRef::ValueRefBase<int>* m_empire_id; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; // TODO: create multiple Create*s for different kinds of objects @@ -215,6 +251,11 @@ virtual void Execute(const UniverseObject* source, UniverseObject* target) const; virtual std::string Description() const; virtual std::string Dump() const; + +private: + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; /** Adds the Special with the name \a name to the target object. */ @@ -229,6 +270,10 @@ private: std::string m_name; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; /** Removes the Special with the name \a name to the target object. This has no effect if no such Special was already attached to the target object. */ @@ -243,6 +288,10 @@ private: std::string m_name; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; /** Sets the star type of the target to \a type. This has no effect on non-System targets. */ @@ -258,6 +307,10 @@ private: const ValueRef::ValueRefBase<StarType>* m_type; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; /** Sets the availability of tech \a tech_name to empire \a empire_id. If \a include_tech is true, the tech is fully available, just as if it were @@ -278,6 +331,10 @@ const ValueRef::ValueRefBase<int>* m_empire_id; bool m_available; bool m_include_tech; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; class Effect::SetEffectTarget : public Effect::EffectBase @@ -292,6 +349,114 @@ private: const ValueRef::ValueRefBase<int>* m_effect_target_id; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; +// template implementations +template <class Archive> +void Effect::EffectsGroup::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_NVP(m_scope) + & BOOST_SERIALIZATION_NVP(m_activation) + & BOOST_SERIALIZATION_NVP(m_stacking_group) + & BOOST_SERIALIZATION_NVP(m_explicit_description) + & BOOST_SERIALIZATION_NVP(m_effects); +} + +template <class Archive> +void Effect::EffectBase::serialize(Archive& ar, const unsigned int version) +{} + +template <class Archive> +void Effect::SetMeter::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(EffectBase) + & BOOST_SERIALIZATION_NVP(m_meter) + & BOOST_SERIALIZATION_NVP(m_value) + & BOOST_SERIALIZATION_NVP(m_max); +} + +template <class Archive> +void Effect::SetEmpireStockpile::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(EffectBase) + & BOOST_SERIALIZATION_NVP(m_stockpile) + & BOOST_SERIALIZATION_NVP(m_value); +} + +template <class Archive> +void Effect::SetPlanetType::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(EffectBase) + & BOOST_SERIALIZATION_NVP(m_type); +} + +template <class Archive> +void Effect::SetPlanetSize::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(EffectBase) + & BOOST_SERIALIZATION_NVP(m_size); +} + +template <class Archive> +void Effect::AddOwner::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(EffectBase) + & BOOST_SERIALIZATION_NVP(m_empire_id); +} + +template <class Archive> +void Effect::RemoveOwner::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(EffectBase) + & BOOST_SERIALIZATION_NVP(m_empire_id); +} + +template <class Archive> +void Effect::Destroy::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(EffectBase); +} + +template <class Archive> +void Effect::AddSpecial::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(EffectBase) + & BOOST_SERIALIZATION_NVP(m_name); +} + +template <class Archive> +void Effect::RemoveSpecial::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(EffectBase) + & BOOST_SERIALIZATION_NVP(m_name); +} + +template <class Archive> +void Effect::SetStarType::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(EffectBase) + & BOOST_SERIALIZATION_NVP(m_type); +} + +template <class Archive> +void Effect::SetTechAvailability::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(EffectBase) + & BOOST_SERIALIZATION_NVP(m_tech_name) + & BOOST_SERIALIZATION_NVP(m_empire_id) + & BOOST_SERIALIZATION_NVP(m_available) + & BOOST_SERIALIZATION_NVP(m_include_tech); +} + +template <class Archive> +void Effect::SetEffectTarget::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(EffectBase) + & BOOST_SERIALIZATION_NVP(m_effect_target_id); +} + #endif // _Effect_h_ Modified: trunk/FreeOrion/universe/Fleet.h =================================================================== --- trunk/FreeOrion/universe/Fleet.h 2006-10-27 22:06:40 UTC (rev 1935) +++ trunk/FreeOrion/universe/Fleet.h 2006-10-29 03:24:58 UTC (rev 1936) @@ -113,20 +113,23 @@ template <class Archive> void Fleet::serialize(Archive& ar, const unsigned int version) { - bool visible; + bool vis; int moving_to; if (Archive::is_saving::value) - visible = Universe::ALL_OBJECTS_VISIBLE || Universe::s_encoding_empire == ALL_EMPIRES || OwnedBy(Universe::s_encoding_empire); + vis = GetVisibility(Universe::s_encoding_empire); ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(UniverseObject) - & BOOST_SERIALIZATION_NVP(visible); + & BOOST_SERIALIZATION_NVP(vis); if (Archive::is_saving::value) - moving_to = visible ? m_moving_to : m_next_system; + moving_to = vis ? m_moving_to : m_next_system; ar & BOOST_SERIALIZATION_NVP(m_ships) & BOOST_SERIALIZATION_NVP(moving_to) & BOOST_SERIALIZATION_NVP(m_prev_system) & BOOST_SERIALIZATION_NVP(m_next_system); if (Archive::is_loading::value) m_moving_to = moving_to; + if (Universe::ALL_OBJECTS_VISIBLE || + vis == FULL_VISIBILITY) + ar & BOOST_SERIALIZATION_NVP(m_speed); } #endif // _Fleet_h_ Modified: trunk/FreeOrion/universe/Planet.h =================================================================== --- trunk/FreeOrion/universe/Planet.h 2006-10-27 22:06:40 UTC (rev 1935) +++ trunk/FreeOrion/universe/Planet.h 2006-10-29 03:24:58 UTC (rev 1936) @@ -48,9 +48,9 @@ virtual const Meter* GetMeter(MeterType type) const; ///////////////////////////////////////////////////////////////////////////// - // V0.2 ONLY!!!! + // V0.3 ONLY!!!! int DefBases() const {return m_def_bases;} - // V0.2 ONLY!!!! + // V0.3 ONLY!!!! ///////////////////////////////////////////////////////////////////////////// virtual UniverseObject::Visibility GetVisibility(int empire_id) const; ///< returns the visibility status of this universe object relative to the input empire. @@ -67,9 +67,9 @@ virtual void PopGrowthProductionResearchPhase( ); ///////////////////////////////////////////////////////////////////////////// - // V0.2 ONLY!!!! + // V0.3 ONLY!!!! void AdjustDefBases(int bases) {m_def_bases += bases; if (m_def_bases < 0) m_def_bases = 0; StateChangedSignal();} - // V0.2 ONLY!!!! + // V0.3 ONLY!!!! ///////////////////////////////////////////////////////////////////////////// void SetType(PlanetType type); ///< sets the type of this Planet to \a type Modified: trunk/FreeOrion/universe/PopCenter.cpp =================================================================== --- trunk/FreeOrion/universe/PopCenter.cpp 2006-10-27 22:06:40 UTC (rev 1935) +++ trunk/FreeOrion/universe/PopCenter.cpp 2006-10-29 03:24:58 UTC (rev 1936) @@ -42,6 +42,12 @@ } +PopCenter::PopCenter() : + m_growth(0), + m_race(0), + m_available_food(0) +{} + PopCenter::PopCenter(double max_pop_mod, double max_health_mod) { Reset(max_pop_mod, max_health_mod); Modified: trunk/FreeOrion/universe/PopCenter.h =================================================================== --- trunk/FreeOrion/universe/PopCenter.h 2006-10-27 22:06:40 UTC (rev 1935) +++ trunk/FreeOrion/universe/PopCenter.h 2006-10-29 03:24:58 UTC (rev 1936) @@ -77,6 +77,8 @@ mutable GetObjectSignalType GetObjectSignal; ///< the UniverseObject-retreiving signal object for this PopCenter private: + PopCenter(); ///< default ctor + Meter m_pop; Meter m_health; double m_growth; Modified: trunk/FreeOrion/universe/ResourceCenter.cpp =================================================================== --- trunk/FreeOrion/universe/ResourceCenter.cpp 2006-10-27 22:06:40 UTC (rev 1935) +++ trunk/FreeOrion/universe/ResourceCenter.cpp 2006-10-29 03:24:58 UTC (rev 1936) @@ -80,8 +80,14 @@ } +ResourceCenter::ResourceCenter() : + m_primary(FOCUS_UNKNOWN), + m_secondary(FOCUS_UNKNOWN), + m_pop(0) +{} + ResourceCenter::ResourceCenter(const Meter& pop) : - m_pop(pop) + m_pop(&pop) { Reset(); } @@ -89,7 +95,7 @@ ResourceCenter::ResourceCenter(const XMLElement& elem, const Meter& pop) : m_primary(FOCUS_UNKNOWN), m_secondary(FOCUS_UNKNOWN), - m_pop(pop) + m_pop(&pop) { if (elem.Tag() != "ResourceCenter") throw std::invalid_argument("Attempted to construct a ResourceCenter from an XMLElement that had a tag other than \"ResourceCenter\""); @@ -134,33 +140,33 @@ double ResourceCenter::FarmingPoints() const { - return m_pop.Current() / 10.0 * m_farming.Current(); + return m_pop->Current() / 10.0 * m_farming.Current(); } double ResourceCenter::IndustryPoints() const { - return m_pop.Current() / 10.0 * m_industry.Current(); + return m_pop->Current() / 10.0 * m_industry.Current(); } double ResourceCenter::MiningPoints() const { - return m_pop.Current() / 10.0 * m_mining.Current(); + return m_pop->Current() / 10.0 * m_mining.Current(); } double ResourceCenter::ResearchPoints() const { - return m_pop.Current() / 10.0 * m_research.Current(); + return m_pop->Current() / 10.0 * m_research.Current(); } double ResourceCenter::TradePoints() const { - return m_pop.Current() / 10.0 * m_trade.Current(); + return m_pop->Current() / 10.0 * m_trade.Current(); } double ResourceCenter::ProjectedCurrent(MeterType type) const { Meter construction = m_construction, farming = m_farming, industry = m_industry, mining = m_mining, research = m_research, trade = m_trade; - Growth(construction, farming, industry, mining, research, trade, m_pop); + Growth(construction, farming, industry, mining, research, trade, *m_pop); switch (type) { case METER_FARMING: return farming.Current(); case METER_INDUSTRY: return industry.Current(); @@ -301,7 +307,7 @@ void ResourceCenter::PopGrowthProductionResearchPhase() { - Growth(m_construction, m_farming, m_industry, m_mining, m_research, m_trade, m_pop); + Growth(m_construction, m_farming, m_industry, m_mining, m_research, m_trade, *m_pop); } Modified: trunk/FreeOrion/universe/ResourceCenter.h =================================================================== --- trunk/FreeOrion/universe/ResourceCenter.h 2006-10-27 22:06:40 UTC (rev 1935) +++ trunk/FreeOrion/universe/ResourceCenter.h 2006-10-29 03:24:58 UTC (rev 1936) @@ -74,6 +74,8 @@ mutable GetObjectSignalType GetObjectSignal; ///< the UniverseObject-retreiving signal object for this ResourceCenter private: + ResourceCenter(); ///< default ctor + FocusType m_primary; FocusType m_secondary; @@ -84,7 +86,7 @@ Meter m_trade; Meter m_construction; - const Meter& m_pop; ///< current / max pop present in this center (may be the one from m_object, e.g. if m_object is a Planet) + const Meter* m_pop; ///< current / max pop present in this center (may be the one from m_object, e.g. if m_object is a Planet) friend class boost::serialization::access; template <class Archive> @@ -112,7 +114,7 @@ & BOOST_SERIALIZATION_NVP(m_research) & BOOST_SERIALIZATION_NVP(m_trade) & BOOST_SERIALIZATION_NVP(m_construction) - & boost::serialization::make_nvp("m_pop", const_cast<Meter&>(m_pop)); + & boost::serialization::make_nvp("m_pop", const_cast<Meter*&>(m_pop)); } } Modified: trunk/FreeOrion/universe/Special.h =================================================================== --- trunk/FreeOrion/universe/Special.h 2006-10-27 22:06:40 UTC (rev 1935) +++ trunk/FreeOrion/universe/Special.h 2006-10-29 03:24:58 UTC (rev 1936) @@ -33,6 +33,10 @@ std::string m_description; std::vector<boost::shared_ptr<const Effect::EffectsGroup> > m_effects; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; /** Returns the Special object used to represent specials of type \a name. If no such Special exists, 0 is returned instead. */ @@ -43,4 +47,13 @@ to non-planet UniverseObjects, just like all Specials, and are not restricted to use during universe creation. */ const std::set<std::string>& PlanetSpecialNames(); +// template implementations +template <class Archive> +void Special::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_NVP(m_name) + & BOOST_SERIALIZATION_NVP(m_description) + & BOOST_SERIALIZATION_NVP(m_effects); +} + #endif // _Special_h_ Modified: trunk/FreeOrion/universe/UniverseObject.h =================================================================== --- trunk/FreeOrion/universe/UniverseObject.h 2006-10-27 22:06:40 UTC (rev 1935) +++ trunk/FreeOrion/universe/UniverseObject.h 2006-10-29 03:24:58 UTC (rev 1936) @@ -193,13 +193,14 @@ vis == PARTIAL_VISIBILITY || vis == FULL_VISIBILITY) { std::string name; if (Archive::is_saving::value) { - // We don't disclose the real object name for some types of objects, cinve it would look funny if e.g. the user - // saw an incoming enemy cleet called "Decoy". + // We don't disclose the real object name for some types of objects, since it would look funny if e.g. the + // user saw an incoming enemy cleet called "Decoy". name = PublicName(Universe::s_encoding_empire); } ar & BOOST_SERIALIZATION_NVP(name) & BOOST_SERIALIZATION_NVP(m_owners) - & BOOST_SERIALIZATION_NVP(m_specials); + & BOOST_SERIALIZATION_NVP(m_specials) + & BOOST_SERIALIZATION_NVP(m_created_on_turn); if (Archive::is_loading::value) m_name = name; } Modified: trunk/FreeOrion/universe/ValueRef.h =================================================================== --- trunk/FreeOrion/universe/ValueRef.h 2006-10-27 22:06:40 UTC (rev 1935) +++ trunk/FreeOrion/universe/ValueRef.h 2006-10-29 03:24:58 UTC (rev 1936) @@ -46,6 +46,11 @@ virtual T Eval(const UniverseObject* source, const UniverseObject* target) const = 0; ///< evaluates the expression tree and return the results virtual std::string Description() const = 0; virtual std::string Dump() const = 0; ///< returns a text description of this type of special + +private: + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; /** the constant value leaf ValueRef class. */ @@ -62,6 +67,10 @@ private: T m_value; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; /** the variable value ValueRef class. The value returned by this node is taken from either the \a source or \a target parameters to Eval. */ @@ -85,6 +94,10 @@ private: bool m_source_ref; std::vector<std::string> m_property_name; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; /** the variable static_cast class. The value returned by this node is taken from the ctor \a value_ref parameter's FromType value, @@ -100,6 +113,10 @@ private: const ValueRefBase<FromType>* m_value_ref; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; /** an arithmetic operation node ValueRef class. One of addition, subtraction, mutiplication, division, or unary negation is @@ -123,6 +140,10 @@ OpType m_op_type; const ValueRefBase<T>* m_operand1; const ValueRefBase<T>* m_operand2; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; /** A function that returns the correct amount of spacing for the current indentation level during a dump. Note that @@ -131,6 +152,13 @@ // Template Implementations +/////////////////////////////////////////////////////////// +// ValueRefBase // +/////////////////////////////////////////////////////////// +template <class T> +template <class Archive> +void ValueRef::ValueRefBase<T>::serialize(Archive& ar, const unsigned int version) +{} /////////////////////////////////////////////////////////// // Constant // @@ -190,6 +218,14 @@ std::string Constant<int>::Dump() const; } +template <class T> +template <class Archive> +void ValueRef::Constant<T>::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(ValueRefBase) + & BOOST_SERIALIZATION_NVP(m_value); +} + /////////////////////////////////////////////////////////// // Variable // /////////////////////////////////////////////////////////// @@ -267,6 +303,15 @@ int Variable<int>::Eval(const UniverseObject* source, const UniverseObject* target) const; } +template <class T> +template <class Archive> +void ValueRef::Variable<T>::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(ValueRefBase) + & BOOST_SERIALIZATION_NVP(m_source_ref) + & BOOST_SERIALIZATION_NVP(m_property_name); +} + /////////////////////////////////////////////////////////// // StaticCast // /////////////////////////////////////////////////////////// @@ -294,6 +339,14 @@ return m_value_ref->Dump(); } +template <class FromType, class ToType> +template <class Archive> +void ValueRef::StaticCast<FromType, ToType>::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(ValueRefBase) + & BOOST_SERIALIZATION_NVP(m_value_ref); +} + /////////////////////////////////////////////////////////// // Operation // /////////////////////////////////////////////////////////// @@ -443,8 +496,17 @@ return retval; } -// template implementations template <class T> +template <class Archive> +void ValueRef::Operation<T>::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(ValueRefBase) + & BOOST_SERIALIZATION_NVP(m_op_type) + & BOOST_SERIALIZATION_NVP(m_operand1) + & BOOST_SERIALIZATION_NVP(m_operand2); +} + +template <class T> bool ValueRef::ConstantExpr(const ValueRefBase<T>* expr) { assert(expr); Modified: trunk/FreeOrion/util/Serialize.cpp =================================================================== --- trunk/FreeOrion/util/Serialize.cpp 2006-10-27 22:06:40 UTC (rev 1935) +++ trunk/FreeOrion/util/Serialize.cpp 2006-10-29 03:24:58 UTC (rev 1936) @@ -9,8 +9,6 @@ #include "../universe/ShipDesign.h" #include "../universe/System.h" -//#include "../universe/Predicates.h" - #include "SDL_byteorder.h" #if defined(_MSC_VER) |
From: <tz...@us...> - 2006-10-29 19:46:11
|
Revision: 1937 http://svn.sourceforge.net/freeorion/revision/?rev=1937&view=rev Author: tzlaine Date: 2006-10-29 11:45:57 -0800 (Sun, 29 Oct 2006) Log Message: ----------- Completed Boost.Serialization conversion, at least for turn updates distributed from the server. Also removed crufty serialization test code. Modified Paths: -------------- trunk/FreeOrion/SConscript trunk/FreeOrion/client/AI/AIClientApp.cpp trunk/FreeOrion/client/human/HumanClientApp.cpp trunk/FreeOrion/network/Message.cpp trunk/FreeOrion/network/Message.h trunk/FreeOrion/server/ServerApp.cpp Modified: trunk/FreeOrion/SConscript =================================================================== --- trunk/FreeOrion/SConscript 2006-10-29 03:24:58 UTC (rev 1936) +++ trunk/FreeOrion/SConscript 2006-10-29 19:45:57 UTC (rev 1937) @@ -42,6 +42,7 @@ 'util/OrderSet.cpp', 'util/Process.cpp', 'util/Random.cpp', + 'util/Serialize.cpp', 'util/SitRepEntry.cpp', 'util/VarText.cpp', 'util/Version.cpp', Modified: trunk/FreeOrion/client/AI/AIClientApp.cpp =================================================================== --- trunk/FreeOrion/client/AI/AIClientApp.cpp 2006-10-29 03:24:58 UTC (rev 1936) +++ trunk/FreeOrion/client/AI/AIClientApp.cpp 2006-10-29 19:45:57 UTC (rev 1937) @@ -3,6 +3,7 @@ #include "../../util/MultiplayerCommon.h" #include "../../util/OptionsDB.h" #include "../../util/Directories.h" +#include "../../util/Serialize.h" #include "../../network/Message.h" #include <GG/net/fastevents.h> @@ -17,7 +18,6 @@ #include <boost/filesystem/fstream.hpp> - // static member(s) AIClientApp* AIClientApp::s_app = 0; @@ -215,6 +215,7 @@ std::stringstream stream(msg.GetText()); XMLDoc doc; doc.ReadDoc(stream); + m_empire_id = boost::lexical_cast<int>(doc.root_node.Child("empire_id").Text()); m_current_turn = boost::lexical_cast<int>(doc.root_node.Attribute("turn_number")); // as it stands now, just start turn StartTurn(); @@ -241,12 +242,12 @@ case Message::TURN_UPDATE: { if (msg.Sender() == -1) { - // as it stands now, just start turn - Logger().debugStream() << "AIClientApp::HandleMessageImpl : Received TURN_UPDATE message; ..."; - std::stringstream stream(msg.GetText()); - XMLDoc doc; - doc.ReadDoc(stream); - m_current_turn = boost::lexical_cast<int>(doc.root_node.Attribute("turn_number")); + std::istringstream is(msg.GetText()); + boost::archive::binary_iarchive ia(is); + Universe::s_encoding_empire = m_empire_id; + ia >> BOOST_SERIALIZATION_NVP(m_current_turn); + Deserialize(&ia, GetUniverse()); + Deserialize(&ia, Empires()); StartTurn(); } break; Modified: trunk/FreeOrion/client/human/HumanClientApp.cpp =================================================================== --- trunk/FreeOrion/client/human/HumanClientApp.cpp 2006-10-29 03:24:58 UTC (rev 1936) +++ trunk/FreeOrion/client/human/HumanClientApp.cpp 2006-10-29 19:45:57 UTC (rev 1937) @@ -12,6 +12,7 @@ #include "../../util/OptionsDB.h" #include "../../universe/Planet.h" #include "../../util/Process.h" +#include "../../util/Serialize.h" #include "../../util/SitRepEntry.h" #include "../../util/Directories.h" #include "../../util/XMLDoc.h" @@ -32,17 +33,6 @@ #include <sstream> -#define TEST_BOOST_SERIALIZATION 0 -#define TEST_BINARY_ARCHIVES 1 -#if TEST_BOOST_SERIALIZATION -#include "../../util/Serialize.h" -#include <boost/iostreams/device/back_inserter.hpp> -#include <boost/iostreams/filtering_stream.hpp> -#include <boost/range/iterator_range.hpp> -#include <boost/iostreams/device/file.hpp> -#endif - - #ifdef ENABLE_CRASH_BACKTRACE # include <signal.h> # include <execinfo.h> @@ -614,46 +604,6 @@ m_universe.SetUniverse(doc.root_node.Child("Universe")); -#if TEST_BOOST_SERIALIZATION - namespace io = boost::iostreams; - std::string boost_xml_filename = (GetLocalDir() / ("NewGameUniverse-empire" + boost::lexical_cast<std::string>(m_empire_id) + "-boost.xml")).native_file_string(); - std::string boost_binary_filename = (GetLocalDir() / ("NewGameUniverse-empire" + boost::lexical_cast<std::string>(m_empire_id) + "-boost.bin")).native_file_string(); - io::filtering_istream is; -#if TEST_BINARY_ARCHIVES - is.push(io::file_source(boost_binary_filename, std::ios_base::in | std::ios_base::binary)); - boost::archive::binary_iarchive ia(is); -#else - is.push(io::file_source(boost_xml_filename)); - boost::archive::xml_iarchive ia(is); -#endif - bool boost_xml_single_player_game; - Universe boost_xml_universe; - EmpireManager boost_xml_empire_manager; - Universe::s_encoding_empire = m_empire_id; - ia >> boost::serialization::make_nvp("single_player_game", boost_xml_single_player_game); - Deserialize(&ia, boost_xml_universe); - Deserialize(&ia, boost_xml_empire_manager); - - assert(boost_xml_single_player_game == m_single_player_game); - - { - XMLDoc doc; - doc.root_node.AppendChild(m_universe.XMLEncode()); - doc.root_node.AppendChild(m_empires.XMLEncode(m_empire_id)); - doc.root_node.AppendChild(m_empires.XMLEncode()); - std::ofstream ofs("Univese_XMLDoc.xml"); - doc.WriteDoc(ofs); - } - { - XMLDoc doc; - doc.root_node.AppendChild(boost_xml_universe.XMLEncode()); - doc.root_node.AppendChild(boost_xml_empire_manager.XMLEncode(m_empire_id)); - doc.root_node.AppendChild(boost_xml_empire_manager.XMLEncode()); - std::ofstream ofs("Univese_Boost_Serialization.xml"); - doc.WriteDoc(ofs); - } -#endif - Logger().debugStream() << "HumanClientApp::HandleMessageImpl : Universe setup complete."; for (Empire::SitRepItr it = Empires().Lookup(m_empire_id)->SitRepBegin(); it != Empires().Lookup(m_empire_id)->SitRepEnd(); ++it) { @@ -694,58 +644,13 @@ } case Message::TURN_UPDATE: { - std::stringstream stream(msg.GetText()); - XMLDoc doc; - doc.ReadDoc(stream); - - m_current_turn = boost::lexical_cast<int>(doc.root_node.Attribute("turn_number")); - - // free current sitreps - Empires().Lookup(m_empire_id)->ClearSitRep(); - - // Update data universe and empire using state from server - UpdateTurnData(doc); - -#if TEST_BOOST_SERIALIZATION - namespace io = boost::iostreams; - std::string boost_xml_filename = (GetLocalDir() / ("TurnUpdate-empire" + boost::lexical_cast<std::string>(m_empire_id) + "-boost.xml")).native_file_string(); - std::string boost_binary_filename = (GetLocalDir() / ("TurnUpdate-empire" + boost::lexical_cast<std::string>(m_empire_id) + "-boost.bin")).native_file_string(); - io::filtering_istream is; -#if TEST_BINARY_ARCHIVES - is.push(io::file_source(boost_binary_filename, std::ios_base::in | std::ios_base::binary)); + std::istringstream is(msg.GetText()); boost::archive::binary_iarchive ia(is); -#else - is.push(io::file_source(boost_xml_filename)); - boost::archive::xml_iarchive ia(is); -#endif - int boost_xml_turn_number; - Universe boost_xml_universe; - EmpireManager boost_xml_empire_manager; Universe::s_encoding_empire = m_empire_id; - ia >> boost::serialization::make_nvp("turn_number", boost_xml_turn_number); - Deserialize(&ia, boost_xml_universe); - Deserialize(&ia, boost_xml_empire_manager); + ia >> BOOST_SERIALIZATION_NVP(m_current_turn); + Deserialize(&ia, GetUniverse()); + Deserialize(&ia, Empires()); - assert(boost_xml_turn_number == m_current_turn); - - { - XMLDoc doc; - doc.root_node.AppendChild(m_universe.XMLEncode()); - doc.root_node.AppendChild(m_empires.XMLEncode(m_empire_id)); - doc.root_node.AppendChild(m_empires.XMLEncode()); - std::ofstream ofs("TurnUpdate_XMLDoc.xml"); - doc.WriteDoc(ofs); - } - { - XMLDoc doc; - doc.root_node.AppendChild(boost_xml_universe.XMLEncode()); - doc.root_node.AppendChild(boost_xml_empire_manager.XMLEncode(m_empire_id)); - doc.root_node.AppendChild(boost_xml_empire_manager.XMLEncode()); - std::ofstream ofs("TurnUpdate_Boost_Serialization.xml"); - doc.WriteDoc(ofs); - } -#endif - // Now decode sitreps // Empire sitreps need UI in order to generate text, since it needs string resources // generate textr for all sitreps @@ -753,7 +658,6 @@ SitRepEntry *pEntry = *sitrep_it; m_ui->GenerateSitRepText(pEntry); } - //Logger().debugStream() << "HumanClientApp::HandleMessageImpl : Sitrep creation complete"; Autosave(false); Modified: trunk/FreeOrion/network/Message.cpp =================================================================== --- trunk/FreeOrion/network/Message.cpp 2006-10-29 03:24:58 UTC (rev 1936) +++ trunk/FreeOrion/network/Message.cpp 2006-10-29 19:45:57 UTC (rev 1937) @@ -12,7 +12,7 @@ //////////////////////////////////////////////// // Free Functions //////////////////////////////////////////////// -void ZipString(std::string str, std::string& zipped_str) +void ZipString(const std::string& str, std::string& zipped_str) { zipped_str.resize(static_cast<int>(str.size() * 1.01 + 13)); // space required by zlib uLongf zipped_size = zipped_str.size(); @@ -24,7 +24,7 @@ zipped_str.resize(zipped_size); } -void UnzipString(std::string str, std::string& unzipped_str, int size) +void UnzipString(const std::string& str, std::string& unzipped_str, int size) { unzipped_str.resize(size); uLongf unzipped_size = unzipped_str.size(); @@ -247,9 +247,9 @@ return Message(Message::TURN_PROGRESS, -1, player_id, Message::CORE, doc); } -Message TurnUpdateMessage(int player_id, const XMLDoc& start_data) +Message TurnUpdateMessage(int player_id, const std::string& data) { - return Message(Message::TURN_UPDATE, -1, player_id, Message::CORE, start_data); + return Message(Message::TURN_UPDATE, -1, player_id, Message::CORE, data); } Message RequestNewObjectIDMessage(int sender) Modified: trunk/FreeOrion/network/Message.h =================================================================== --- trunk/FreeOrion/network/Message.h 2006-10-29 03:24:58 UTC (rev 1936) +++ trunk/FreeOrion/network/Message.h 2006-10-29 19:45:57 UTC (rev 1937) @@ -11,12 +11,12 @@ #include <string> /** compresses \a str using zlib, and puts the result into \a zipped_str */ -void ZipString(std::string str, std::string& zipped_str); +void ZipString(const std::string& str, std::string& zipped_str); /** decompresses \a str using zlib, and puts the result into \a unzipped_str. The uncompressed size of the string must be known beforehand, and passed in \a size. Results are undefined when \a str does not conatain a valid zipped byte sequence.*/ -void UnzipString(std::string str, std::string& unzipped_str, int size); +void UnzipString(const std::string& str, std::string& unzipped_str, int size); @@ -169,8 +169,8 @@ /** creates an TURN_PROGRESS message. */ Message TurnProgressMessage(int player_id, Message::TurnProgressPhase phase_id, int empire_id); -/** creates a TURN_UPDATE message. Contains a diff of universe and empire data */ -Message TurnUpdateMessage(int player_id, const XMLDoc& start_data); +/** creates a TURN_UPDATE message. */ +Message TurnUpdateMessage(int player_id, const std::string& data); /** creates an REQUEST_NEW_OBJECT_ID message. This message is a synchronous message, when sent it will wait for a reply form the server */ Message RequestNewObjectIDMessage(int sender); Modified: trunk/FreeOrion/server/ServerApp.cpp =================================================================== --- trunk/FreeOrion/server/ServerApp.cpp 2006-10-29 03:24:58 UTC (rev 1936) +++ trunk/FreeOrion/server/ServerApp.cpp 2006-10-29 19:45:57 UTC (rev 1937) @@ -17,6 +17,7 @@ #include "../util/OptionsDB.h" #include "../util/OrderSet.h" #include "../util/XMLDoc.h" +#include "../util/Serialize.h" #include "../util/SitRepEntry.h" #include <GG/Font.h> @@ -61,13 +62,7 @@ # define GZIP_SAVE_FILES_COMPRESSION_LEVEL 0 #endif -#define TEST_BOOST_SERIALIZATION 0 -#define TEST_BINARY_ARCHIVES 0 -#if TEST_BOOST_SERIALIZATION -#include "../util/Serialize.h" -#endif - namespace { const std::string SAVE_FILE_EXTENSION = ".mps"; const std::string SAVE_DIR_NAME = "save/"; @@ -553,88 +548,16 @@ doc.ReadDoc(ifs); ifs.close(); -#if TEST_BOOST_SERIALIZATION - std::map<Empire*, XMLElement> empire_docs; -#endif - m_expected_players = 0; for (int i = 0; i < doc.root_node.NumChildren(); ++i) { if (doc.root_node.Child(i).Tag() == "Player") { - Empire* empire = new Empire(doc.root_node.Child(i).Child("Empire")); - m_empires.InsertEmpire(empire); + m_empires.InsertEmpire(new Empire(doc.root_node.Child(i).Child("Empire"))); ++m_expected_players; -#if TEST_BOOST_SERIALIZATION - empire_docs[empire] = doc.root_node.Child(i).Child("Empire"); -#endif } } m_universe.SetUniverse(doc.root_node.Child("Universe")); LoadGameVars(doc); -#if TEST_BOOST_SERIALIZATION - using boost::lexical_cast; - for (std::map<Empire*, XMLElement>::iterator it = empire_docs.begin(); it != empire_docs.end(); ++it) { - Empire test_empire("", "", 0, GG::Clr(), 0); - std::ostringstream os; - { - boost::archive::binary_oarchive oa(os); - Serialize(&oa, *it->first); - } - std::ofstream ofs(("test_boost_empire_" + lexical_cast<std::string>(it->first->EmpireID())).c_str()); - ofs << os.str(); - { - std::ifstream ifs(("test_boost_empire_" + lexical_cast<std::string>(it->first->EmpireID())).c_str()); - boost::archive::binary_iarchive ia(ifs); - Deserialize(&ia, test_empire); - } - { - XMLDoc empire_doc; - empire_doc.root_node.AppendChild(it->first->XMLEncode(ALL_EMPIRES)); - for (int i = 0; i <= 4; ++i) - empire_doc.root_node.AppendChild(it->first->XMLEncode(i)); - std::ofstream ofs(("empire_" + lexical_cast<std::string>(it->first->EmpireID()) + "_doc.xml").c_str()); - empire_doc.WriteDoc(ofs); - } - { - XMLDoc copy_empire_doc; - copy_empire_doc.root_node.AppendChild(it->first->XMLEncode(ALL_EMPIRES)); - for (int i = 0; i <= 4; ++i) - copy_empire_doc.root_node.AppendChild(it->first->XMLEncode(i)); - std::ofstream ofs(("empire_" + lexical_cast<std::string>(it->first->EmpireID()) + "_doc_copy.xml").c_str()); - copy_empire_doc.WriteDoc(ofs); - } - std::cout << "loaded empire " << it->first->EmpireID() << " successfully" << std::endl; - } - - Universe test_universe; - std::ostringstream os; - { - boost::archive::binary_oarchive oa(os); - Serialize(&oa, m_universe); - } - std::ofstream ofs("test_boost_universe", std::ios_base::binary); - ofs << os.str(); - { - std::ifstream ifs("test_boost_universe", std::ios_base::binary); - boost::archive::binary_iarchive ia(ifs); - Deserialize(&ia, test_universe); - } - { - XMLDoc universe_doc; - universe_doc.root_node.AppendChild(m_universe.XMLEncode(ALL_EMPIRES)); - std::ofstream ofs("universe_doc.xml"); - universe_doc.WriteDoc(ofs); - } - { - XMLDoc copy_universe_doc; - copy_universe_doc.root_node.AppendChild(test_universe.XMLEncode(ALL_EMPIRES)); - std::ofstream ofs("universe_doc_copy.xml"); - copy_universe_doc.WriteDoc(ofs); - } - - std::cout << "loaded universe successfully" << std::endl; -#endif - CreateAIClients(std::vector<PlayerSetupData>(m_expected_players - 1)); g_load_doc = doc; m_state = SERVER_GAME_SETUP; @@ -1352,32 +1275,6 @@ AddEmpireTurn( it->first ); } -#if 0//TEST_BOOST_SERIALIZATION - { - Universe::s_encoding_empire = Universe::ALL_EMPIRES; - std::string encoded_string; - { - namespace io = boost::iostreams; - io::filtering_ostream os; - os.push(io::back_inserter(encoded_string)); -#if TEST_BINARY_ARCHIVES - boost::archive::binary_oarchive oa(os); -#else - boost::archive::xml_oarchive oa(os); -#endif - oa << boost::serialization::make_nvp("single_player_game", m_single_player_game); - Serialize(&oa, m_universe); - Serialize(&oa, m_empires); - } -#if TEST_BINARY_ARCHIVES - boost::filesystem::ofstream ofs(GetLocalDir() / ("NewGameUniverse-boost.bin"), std::ios_base::out | std::ios_base::binary); -#else - boost::filesystem::ofstream ofs(GetLocalDir() / ("NewGameUniverse-boost.xml")); -#endif - ofs << encoded_string; - } -#endif - // the universe creation caused the creation of empires. But now we need to assign the empires to players. for (std::map<int, PlayerInfo>::const_iterator it = m_network_core.Players().begin(); it != m_network_core.Players().end(); ++it) { XMLDoc doc; @@ -1387,32 +1284,6 @@ doc.root_node.AppendChild(m_empires.CreateClientEmpireUpdate(it->first)); doc.root_node.AppendChild(XMLElement("empire_id", boost::lexical_cast<std::string>(it->first))); -#if 0//TEST_BOOST_SERIALIZATION - { - Universe::s_encoding_empire = it->first; - std::string encoded_string; - { - namespace io = boost::iostreams; - io::filtering_ostream os; - os.push(io::back_inserter(encoded_string)); -#if TEST_BINARY_ARCHIVES - boost::archive::binary_oarchive oa(os); -#else - boost::archive::xml_oarchive oa(os); -#endif - oa << boost::serialization::make_nvp("single_player_game", m_single_player_game); - Serialize(&oa, m_universe); - Serialize(&oa, m_empires); - } -#if TEST_BINARY_ARCHIVES - boost::filesystem::ofstream ofs(GetLocalDir() / ("NewGameUniverse-empire" + boost::lexical_cast<std::string>(it->first) + "-boost.bin"), std::ios_base::out | std::ios_base::binary); -#else - boost::filesystem::ofstream ofs(GetLocalDir() / ("NewGameUniverse-empire" + boost::lexical_cast<std::string>(it->first) + "-boost.xml")); -#endif - ofs << encoded_string; - } -#endif - // turn number is an attribute of the document doc.root_node.SetAttribute("turn_number", boost::lexical_cast<std::string>(m_current_turn)); @@ -1984,44 +1855,16 @@ // send new-turn updates to all players for (std::map<int, PlayerInfo>::const_iterator player_it = m_network_core.Players().begin(); player_it != m_network_core.Players().end(); ++player_it) { - pEmpire = GetPlayerEmpire( player_it->first ); - XMLDoc doc = CreateTurnUpdate( pEmpire->EmpireID() ); -#if 0//TEST_BOOST_SERIALIZATION + pEmpire = GetPlayerEmpire(player_it->first); + std::ostringstream os; { + boost::archive::binary_oarchive oa(os); Universe::s_encoding_empire = pEmpire->EmpireID(); - std::string encoded_string; - { - namespace io = boost::iostreams; - io::filtering_ostream os; - os.push(io::back_inserter(encoded_string)); -#if TEST_BINARY_ARCHIVES - boost::archive::binary_oarchive oa(os); -#else - boost::archive::xml_oarchive oa(os); -#endif - oa << boost::serialization::make_nvp("turn_number", m_current_turn); - Serialize(&oa, m_universe); - Serialize(&oa, m_empires); - } -#if TEST_BINARY_ARCHIVES - boost::filesystem::ofstream ofs(GetLocalDir() / ("TurnUpdate-empire" + boost::lexical_cast<std::string>(pEmpire->EmpireID()) + "-boost.bin"), std::ios_base::out | std::ios_base::binary); -#else - boost::filesystem::ofstream ofs(GetLocalDir() / ("TurnUpdate-empire" + boost::lexical_cast<std::string>(pEmpire->EmpireID()) + "-boost.xml")); -#endif - ofs << encoded_string; - ofs.close(); + oa << BOOST_SERIALIZATION_NVP(m_current_turn); + Serialize(&oa, m_universe); + Serialize(&oa, m_empires); } -#endif - if (GetOptionsDB().Get<bool>("debug.log-turn-update-universe")) { - std::string filename = "TurnUpdate" + boost::lexical_cast<std::string>(m_current_turn) + - "-empire" + boost::lexical_cast<std::string>(pEmpire->EmpireID()) + - "-doc.xml"; - boost::filesystem::ofstream ofs(GetLocalDir() / filename); - doc.WriteDoc(ofs); - ofs.close(); - } - - m_network_core.SendMessage( TurnUpdateMessage( player_it->first, doc ) ); + m_network_core.SendMessage(TurnUpdateMessage(player_it->first, os.str())); } // notify all players of the eliminated players |
From: <tz...@us...> - 2006-10-30 04:54:51
|
Revision: 1940 http://svn.sourceforge.net/freeorion/revision/?rev=1940&view=rev Author: tzlaine Date: 2006-10-29 20:54:43 -0800 (Sun, 29 Oct 2006) Log Message: ----------- Implemented use of Boost.Serialization, isntead of XMLDoc, for transmission of turn-orders. Modified Paths: -------------- trunk/FreeOrion/client/ClientApp.cpp trunk/FreeOrion/client/human/HumanClientApp.cpp trunk/FreeOrion/network/Message.cpp trunk/FreeOrion/network/Message.h trunk/FreeOrion/server/ServerApp.cpp trunk/FreeOrion/util/Order.h trunk/FreeOrion/util/OrderSet.h trunk/FreeOrion/util/Serialize.cpp trunk/FreeOrion/util/Serialize.h Modified: trunk/FreeOrion/client/ClientApp.cpp =================================================================== --- trunk/FreeOrion/client/ClientApp.cpp 2006-10-29 21:37:15 UTC (rev 1939) +++ trunk/FreeOrion/client/ClientApp.cpp 2006-10-30 04:54:43 UTC (rev 1940) @@ -1,6 +1,7 @@ #include "ClientApp.h" #include "../util/MultiplayerCommon.h" +#include "../util/Serialize.h" #include "../universe/UniverseObject.h" #include <stdexcept> @@ -46,23 +47,27 @@ Message ClientApp::TurnOrdersMessage(bool save_game_data/* = false*/) const { - XMLDoc orders_doc; - if (save_game_data) - orders_doc.root_node.AppendChild("save_game_data"); - orders_doc.root_node.AppendChild(XMLElement("Orders")); - for (OrderSet::const_iterator order_it = m_orders.begin(); order_it != m_orders.end(); ++order_it) { - orders_doc.root_node.LastChild().AppendChild(order_it->second->XMLEncode()); + if (save_game_data) { + XMLDoc orders_doc; + orders_doc.root_node.AppendChild(XMLElement("Orders")); + for (OrderSet::const_iterator order_it = m_orders.begin(); order_it != m_orders.end(); ++order_it) { + orders_doc.root_node.LastChild().AppendChild(order_it->second->XMLEncode()); + } + return ClientSaveDataMessage(m_player_id, orders_doc); + } else { + std::ostringstream os; + { + boost::archive::xml_oarchive oa(os); + Serialize(&oa, m_orders); + } + return ::TurnOrdersMessage(m_player_id, os.str()); } - return ::TurnOrdersMessage(m_player_id, -1, orders_doc); } void ClientApp::StartTurn() { - // send message m_network_core.SendMessage(TurnOrdersMessage()); - - // clear order set - m_orders.Reset( ); + m_orders.Reset(); } Universe& ClientApp::GetUniverse() Modified: trunk/FreeOrion/client/human/HumanClientApp.cpp =================================================================== --- trunk/FreeOrion/client/human/HumanClientApp.cpp 2006-10-29 21:37:15 UTC (rev 1939) +++ trunk/FreeOrion/client/human/HumanClientApp.cpp 2006-10-30 04:54:43 UTC (rev 1940) @@ -132,16 +132,23 @@ Message HumanClientApp::TurnOrdersMessage(bool save_game_data/* = false*/) const { - XMLDoc orders_doc; if (save_game_data) { - orders_doc.root_node.AppendChild("save_game_data"); - orders_doc.root_node.AppendChild(ClientUI::GetClientUI()->SaveGameData()); // include relevant UI state + XMLDoc orders_doc; + if (save_game_data) + orders_doc.root_node.AppendChild(ClientUI::GetClientUI()->SaveGameData()); // include relevant UI state + orders_doc.root_node.AppendChild(XMLElement("Orders")); + for (OrderSet::const_iterator order_it = m_orders.begin(); order_it != m_orders.end(); ++order_it) { + orders_doc.root_node.LastChild().AppendChild(order_it->second->XMLEncode()); + } + return ClientSaveDataMessage(m_player_id, orders_doc); + } else { + std::ostringstream os; + { + boost::archive::xml_oarchive oa(os); + Serialize(&oa, m_orders); + } + return ::TurnOrdersMessage(m_player_id, os.str()); } - orders_doc.root_node.AppendChild(XMLElement("Orders")); - for (OrderSet::const_iterator order_it = m_orders.begin(); order_it != m_orders.end(); ++order_it) { - orders_doc.root_node.LastChild().AppendChild(order_it->second->XMLEncode()); - } - return ::TurnOrdersMessage(m_player_id, -1, orders_doc); } std::map<int, int> HumanClientApp::PendingColonizationOrders() const Modified: trunk/FreeOrion/network/Message.cpp =================================================================== --- trunk/FreeOrion/network/Message.cpp 2006-10-29 21:37:15 UTC (rev 1939) +++ trunk/FreeOrion/network/Message.cpp 2006-10-30 04:54:43 UTC (rev 1940) @@ -226,9 +226,9 @@ return Message(Message::END_GAME, -1, receiver, Message::CORE, "VICTORY"); } -Message TurnOrdersMessage(int sender, int receiver, const XMLDoc& orders_data) +Message TurnOrdersMessage(int sender, const std::string& data) { - return Message(Message::TURN_ORDERS, sender, receiver, Message::CORE, orders_data); + return Message(Message::TURN_ORDERS, sender, -1, Message::CORE, data); } Message TurnProgressMessage(int player_id, Message::TurnProgressPhase phase_id, int empire_id) @@ -252,6 +252,11 @@ return Message(Message::TURN_UPDATE, -1, player_id, Message::CORE, data); } +Message ClientSaveDataMessage(int sender, const XMLDoc& data) +{ + return Message(Message::CLIENT_SAVE_DATA, sender, -1, Message::CORE, data); +} + Message RequestNewObjectIDMessage(int sender) { return Message(Message::REQUEST_NEW_OBJECT_ID, sender, -1, Message::CORE, "", Message::DISPATCH_NEW_OBJECT_ID); Modified: trunk/FreeOrion/network/Message.h =================================================================== --- trunk/FreeOrion/network/Message.h 2006-10-29 21:37:15 UTC (rev 1939) +++ trunk/FreeOrion/network/Message.h 2006-10-30 04:54:43 UTC (rev 1940) @@ -42,8 +42,9 @@ LOAD_GAME, ///< sent to server (by the "host" client only) when a game is to be loaded, or from the server to the clients when the game is being loaded GAME_START, ///< sent to each client before the first turn of a new or newly loaded game, instead of a TURN_UPDATE TURN_UPDATE, ///< sent to a client when the server updates the client Universes and Empires, and sends the SitReps each turn; indicates to the receiver that a new turn has begun - TURN_ORDERS, ///< sent to the server by a client that has orders to be processed at the end of a turn or when a game is saved + TURN_ORDERS, ///< sent to the server by a client that has orders to be processed at the end of a turn TURN_PROGRESS, ///< sent to clients to display a turn progress message. To make messages short, IDs are used + CLIENT_SAVE_DATA, ///< sent to the server in response to a server request for the data needed to create a save file COMBAT_START, ///< sent to clients when a combat is about to start COMBAT_ROUND_UPDATE, ///< sent to clients when a combat round has been resolved COMBAT_END, ///< sent to clients when a combat is concluded @@ -164,7 +165,7 @@ Message VictoryMessage(int receiver); /** creates an TURN_ORDERS message. */ -Message TurnOrdersMessage(int sender, int receiver, const XMLDoc& orders_data); +Message TurnOrdersMessage(int sender, const std::string& data); /** creates an TURN_PROGRESS message. */ Message TurnProgressMessage(int player_id, Message::TurnProgressPhase phase_id, int empire_id); @@ -172,6 +173,9 @@ /** creates a TURN_UPDATE message. */ Message TurnUpdateMessage(int player_id, const std::string& data); +/** creates an CLIENT_SAVE_DATA message. */ +Message ClientSaveDataMessage(int sender, const XMLDoc& data); + /** creates an REQUEST_NEW_OBJECT_ID message. This message is a synchronous message, when sent it will wait for a reply form the server */ Message RequestNewObjectIDMessage(int sender); Modified: trunk/FreeOrion/server/ServerApp.cpp =================================================================== --- trunk/FreeOrion/server/ServerApp.cpp 2006-10-29 21:37:15 UTC (rev 1939) +++ trunk/FreeOrion/server/ServerApp.cpp 2006-10-30 04:54:43 UTC (rev 1940) @@ -569,72 +569,55 @@ } case Message::TURN_ORDERS: { - /* decode order set */ - std::stringstream stream(msg.GetText()); - XMLDoc doc; - doc.ReadDoc(stream); + std::istringstream is(msg.GetText()); + boost::archive::xml_iarchive ia(is); + OrderSet* order_set = new OrderSet; + Deserialize(&ia, *order_set); - if (doc.root_node.ContainsChild("save_game_data")) { // the Orders were in answer to a save game data request - doc.root_node.RemoveChild("save_game_data"); - m_player_save_game_data[msg.Sender()].AppendChild(doc.root_node.Child("Orders")); - if (doc.root_node.ContainsChild("UI")) - m_player_save_game_data[msg.Sender()].AppendChild(doc.root_node.Child("UI")); - m_players_responded.insert(msg.Sender()); - } else { // the Orders were sent from a Player who has finished her turn - if (GetOptionsDB().Get<bool>("debug.log-turn-orders")) { - std::string dbg_file("TurnOrdersReceived_empire"); - dbg_file += boost::lexical_cast<std::string>(GetPlayerEmpire(msg.Sender())->EmpireID()); - dbg_file += ".xml"; - boost::filesystem::ofstream output(GetLocalDir() / dbg_file); - doc.WriteDoc(output); - output.close(); + // check order validity -- all orders must originate from this empire in order to be considered valid + Empire* empire = GetPlayerEmpire(msg.Sender()); + assert(empire); + for (OrderSet::const_iterator it = order_set->begin(); it != order_set->end(); ++it) { + Order* order = it->second; + assert(order); + if (empire->EmpireID() != order->EmpireID()) { + throw std::runtime_error( + "ServerApp::HandleMessage : Player \"" + empire->PlayerName() + "\"" + " attempted to issue an order for player " + "\"" + Empires().Lookup(order->EmpireID())->PlayerName() + "\"! Terminating..."); } + } - m_network_core.SendMessage(TurnProgressMessage(msg.Sender(), Message::WAITING_FOR_PLAYERS, -1)); + m_network_core.SendMessage(TurnProgressMessage(msg.Sender(), Message::WAITING_FOR_PLAYERS, -1)); - OrderSet *p_order_set; - p_order_set = new OrderSet( ); - XMLObjectFactory<Order> order_factory; - Order::InitOrderFactory(order_factory); - const XMLElement& root = doc.root_node.Child("Orders"); + m_log_category.debugStream() << "ServerApp::HandleMessage : Received orders from player " << msg.Sender(); - // all orders must originate from this empire in order to be considered valid - Empire* empire = GetPlayerEmpire(msg.Sender()); - assert(empire); + /* if all orders are received already, do nothing as we are processing a turn */ + if (AllOrdersReceived()) + break; - for (int i = 0; i < root.NumChildren(); ++i) { - Order* p_order = order_factory.GenerateObject(root.Child(i)); - if (p_order) { - if (empire->EmpireID() != p_order->EmpireID()) { - throw std::runtime_error( - "ServerApp::HandleMessage : Player \"" + empire->PlayerName() + "\"" - " attempted to issue an order for player " - "\"" + Empires().Lookup(p_order->EmpireID())->PlayerName() + "\"! Terminating..."); - } - p_order_set->AddOrder(p_order); - } else { - m_log_category.errorStream() << "ServerApp::HandleMessage : An Order has been received that has no factory - ignoring."; - } - } + /* add orders to turn sequence */ + SetEmpireTurnOrders(GetPlayerEmpire(msg.Sender())->EmpireID(), order_set); - m_log_category.debugStream() << "ServerApp::HandleMessage : Received orders from player " << msg.Sender(); - - /* if all orders are received already, do nothing as we are processing a turn */ - if ( AllOrdersReceived( ) ) - break; - - /* add orders to turn sequence */ - SetEmpireTurnOrders( GetPlayerEmpire( msg.Sender() )->EmpireID(), p_order_set ); - - /* look to see if all empires are done */ - if ( AllOrdersReceived( ) ) { - m_log_category.debugStream() << "ServerApp::HandleMessage : All orders received; processing turn..."; - ProcessTurns( ); - } + /* look to see if all empires are done */ + if (AllOrdersReceived()) { + m_log_category.debugStream() << "ServerApp::HandleMessage : All orders received; processing turn..."; + ProcessTurns(); } break; } + case Message::CLIENT_SAVE_DATA: { + std::stringstream stream(msg.GetText()); + XMLDoc doc; + doc.ReadDoc(stream); + m_player_save_game_data[msg.Sender()].AppendChild(doc.root_node.Child("Orders")); + if (doc.root_node.ContainsChild("UI")) + m_player_save_game_data[msg.Sender()].AppendChild(doc.root_node.Child("UI")); + m_players_responded.insert(msg.Sender()); + break; + } + case Message::HUMAN_PLAYER_MSG: { std::string text = msg.GetText(); Modified: trunk/FreeOrion/util/Order.h =================================================================== --- trunk/FreeOrion/util/Order.h 2006-10-29 21:37:15 UTC (rev 1939) +++ trunk/FreeOrion/util/Order.h 2006-10-30 04:54:43 UTC (rev 1940) @@ -6,12 +6,17 @@ #include "../universe/Enums.h" #endif -#include <vector> - #ifndef _XMLObjectFactory_h_ #include "XMLObjectFactory.h" #endif +#include <boost/serialization/access.hpp> +#include <boost/serialization/is_abstract.hpp> +#include <boost/serialization/nvp.hpp> + +#include <vector> + + class XMLElement; ///////////////////////////////////////////////////// @@ -69,8 +74,13 @@ int m_empire; mutable bool m_executed; // indicates that Execute() has occured, and so an undo is legal + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; +BOOST_IS_ABSTRACT(Order); ///////////////////////////////////////////////////// // RenameOrder @@ -105,6 +115,10 @@ int m_object; std::string m_name; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; @@ -150,6 +164,10 @@ int m_new_id; std::pair<double, double> m_position; std::vector<int> m_ship_ids; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; @@ -194,6 +212,10 @@ int m_dest_system; std::vector<int> m_route; double m_route_length; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; @@ -237,6 +259,10 @@ int m_fleet_from; int m_fleet_to; std::vector<int> m_add_ships; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; @@ -289,6 +315,10 @@ // these are for undoing this order only mutable int m_colony_fleet_id; // the fleet from which the colony ship was taken mutable std::string m_colony_fleet_name; // the name of fleet from which the colony ship was taken + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; @@ -333,6 +363,10 @@ virtual void ExecuteImpl() const; int m_fleet; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; @@ -369,6 +403,10 @@ int m_planet; FocusType m_focus; bool m_primary; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; @@ -398,6 +436,10 @@ std::string m_tech_name; int m_position; bool m_remove; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; @@ -436,7 +478,105 @@ static const int INVALID_INDEX = -500; static const int INVALID_QUANTITY = -1000; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; +// Template Implementations +template <class Archive> +void Order::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_NVP(m_empire) + & BOOST_SERIALIZATION_NVP(m_executed); +} + +template <class Archive> +void RenameOrder::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Order) + & BOOST_SERIALIZATION_NVP(m_object) + & BOOST_SERIALIZATION_NVP(m_name); +} + +template <class Archive> +void NewFleetOrder::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Order) + & BOOST_SERIALIZATION_NVP(m_fleet_name) + & BOOST_SERIALIZATION_NVP(m_system_id) + & BOOST_SERIALIZATION_NVP(m_new_id) + & BOOST_SERIALIZATION_NVP(m_position) + & BOOST_SERIALIZATION_NVP(m_ship_ids); +} + +template <class Archive> +void FleetMoveOrder::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Order) + & BOOST_SERIALIZATION_NVP(m_fleet) + & BOOST_SERIALIZATION_NVP(m_start_system) + & BOOST_SERIALIZATION_NVP(m_dest_system) + & BOOST_SERIALIZATION_NVP(m_route) + & BOOST_SERIALIZATION_NVP(m_route_length); +} + +template <class Archive> +void FleetTransferOrder::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Order) + & BOOST_SERIALIZATION_NVP(m_fleet_from) + & BOOST_SERIALIZATION_NVP(m_fleet_to) + & BOOST_SERIALIZATION_NVP(m_add_ships); +} + +template <class Archive> +void FleetColonizeOrder::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Order) + & BOOST_SERIALIZATION_NVP(m_ship) + & BOOST_SERIALIZATION_NVP(m_planet) + & BOOST_SERIALIZATION_NVP(m_colony_fleet_id) + & BOOST_SERIALIZATION_NVP(m_colony_fleet_name); +} + +template <class Archive> +void DeleteFleetOrder::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Order) + & BOOST_SERIALIZATION_NVP(m_fleet); +} + +template <class Archive> +void ChangeFocusOrder::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Order) + & BOOST_SERIALIZATION_NVP(m_planet) + & BOOST_SERIALIZATION_NVP(m_focus) + & BOOST_SERIALIZATION_NVP(m_primary); +} + +template <class Archive> +void ResearchQueueOrder::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Order) + & BOOST_SERIALIZATION_NVP(m_tech_name) + & BOOST_SERIALIZATION_NVP(m_position) + & BOOST_SERIALIZATION_NVP(m_remove); +} + +template <class Archive> +void ProductionQueueOrder::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(Order) + & BOOST_SERIALIZATION_NVP(m_build_type) + & BOOST_SERIALIZATION_NVP(m_item) + & BOOST_SERIALIZATION_NVP(m_number) + & BOOST_SERIALIZATION_NVP(m_location) + & BOOST_SERIALIZATION_NVP(m_index) + & BOOST_SERIALIZATION_NVP(m_new_quantity) + & BOOST_SERIALIZATION_NVP(m_new_index); +} + #endif // _Order_h_ - Modified: trunk/FreeOrion/util/OrderSet.h =================================================================== --- trunk/FreeOrion/util/OrderSet.h 2006-10-29 21:37:15 UTC (rev 1939) +++ trunk/FreeOrion/util/OrderSet.h 2006-10-30 04:54:43 UTC (rev 1940) @@ -61,8 +61,19 @@ private: OrderMap m_orders; + + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); }; +// Template Implementations +template <class Archive> +void OrderSet::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_NVP(m_orders); +} + #endif // _OrderSet_h_ Modified: trunk/FreeOrion/util/Serialize.cpp =================================================================== --- trunk/FreeOrion/util/Serialize.cpp 2006-10-29 21:37:15 UTC (rev 1939) +++ trunk/FreeOrion/util/Serialize.cpp 2006-10-30 04:54:43 UTC (rev 1940) @@ -8,6 +8,7 @@ #include "../universe/Planet.h" #include "../universe/ShipDesign.h" #include "../universe/System.h" +#include "../util/OrderSet.h" #include "SDL_byteorder.h" @@ -40,6 +41,17 @@ BOOST_CLASS_EXPORT(Fleet) BOOST_CLASS_EXPORT(Ship) +// exports for boost serialization of polymorphic Order hierarchy +BOOST_CLASS_EXPORT(RenameOrder) +BOOST_CLASS_EXPORT(NewFleetOrder) +BOOST_CLASS_EXPORT(FleetMoveOrder) +BOOST_CLASS_EXPORT(FleetTransferOrder) +BOOST_CLASS_EXPORT(FleetColonizeOrder) +BOOST_CLASS_EXPORT(DeleteFleetOrder) +BOOST_CLASS_EXPORT(ChangeFocusOrder) +BOOST_CLASS_EXPORT(ResearchQueueOrder) +BOOST_CLASS_EXPORT(ProductionQueueOrder) + // some endianness and size checks to ensure portability of binary save files; of one or more of these fails, it means // that FreeOrion is not supported on your platform/compiler pair, and must be modified to provide data of the // appropriate size(s). @@ -78,6 +90,14 @@ *boost::get<boost::archive::binary_oarchive*>(oa) << BOOST_SERIALIZATION_NVP(universe); } +void Serialize(OArchivePtr oa, const OrderSet& order_set) +{ + if (oa.which()) + *boost::get<boost::archive::xml_oarchive*>(oa) << BOOST_SERIALIZATION_NVP(order_set); + else + *boost::get<boost::archive::binary_oarchive*>(oa) << BOOST_SERIALIZATION_NVP(order_set); +} + void Deserialize(IArchivePtr ia, Empire& empire) { if (ia.which()) @@ -101,3 +121,11 @@ else *boost::get<boost::archive::binary_iarchive*>(ia) >> BOOST_SERIALIZATION_NVP(universe); } + +void Deserialize(IArchivePtr ia, OrderSet& order_set) +{ + if (ia.which()) + *boost::get<boost::archive::xml_iarchive*>(ia) >> BOOST_SERIALIZATION_NVP(order_set); + else + *boost::get<boost::archive::binary_iarchive*>(ia) >> BOOST_SERIALIZATION_NVP(order_set); +} Modified: trunk/FreeOrion/util/Serialize.h =================================================================== --- trunk/FreeOrion/util/Serialize.h 2006-10-29 21:37:15 UTC (rev 1939) +++ trunk/FreeOrion/util/Serialize.h 2006-10-30 04:54:43 UTC (rev 1940) @@ -11,6 +11,7 @@ class Empire; class EmpireManager; class Universe; +class OrderSet; /** The type used to refer to an input archive, whether binary or XML. */ typedef boost::variant<boost::archive::binary_iarchive*, @@ -29,6 +30,9 @@ /** Serializes \a universe to output archive \a oa. */ void Serialize(OArchivePtr oa, const Universe& universe); +/** Serializes \a order_set to output archive \a oa. */ +void Serialize(OArchivePtr oa, const OrderSet& order_set); + /** Deserializes the single empire \a empire from input archive \a ia. */ void Deserialize(IArchivePtr ia, Empire& empire); @@ -38,4 +42,7 @@ /** Deserializes \a universe from input archive \a ia. */ void Deserialize(IArchivePtr ia, Universe& universe); +/** Deserializes \a order_set from input archive \a ia. */ +void Deserialize(IArchivePtr ia, OrderSet& order_set); + #endif // _Serialize_h_ |
From: <tz...@us...> - 2006-11-01 00:41:48
|
Revision: 1943 http://svn.sourceforge.net/freeorion/revision/?rev=1943&view=rev Author: tzlaine Date: 2006-10-31 16:41:39 -0800 (Tue, 31 Oct 2006) Log Message: ----------- Changed the game-saving and -loading code to use Boost.Serialization instead of XMLDoc. Modified Paths: -------------- trunk/FreeOrion/UI/ClientUI.cpp trunk/FreeOrion/UI/ClientUI.h trunk/FreeOrion/UI/MapWnd.cpp trunk/FreeOrion/UI/MapWnd.h trunk/FreeOrion/client/AI/AIClientApp.cpp trunk/FreeOrion/client/ClientApp.cpp trunk/FreeOrion/client/human/HumanClientApp.cpp trunk/FreeOrion/network/Message.cpp trunk/FreeOrion/network/Message.h trunk/FreeOrion/server/ServerApp.cpp trunk/FreeOrion/server/ServerApp.h trunk/FreeOrion/util/OrderSet.cpp trunk/FreeOrion/util/OrderSet.h Modified: trunk/FreeOrion/UI/ClientUI.cpp =================================================================== --- trunk/FreeOrion/UI/ClientUI.cpp 2006-10-31 22:13:43 UTC (rev 1942) +++ trunk/FreeOrion/UI/ClientUI.cpp 2006-11-01 00:41:39 UTC (rev 1943) @@ -296,13 +296,9 @@ return true; } -XMLElement ClientUI::SaveGameData() const +void ClientUI::GetSaveGameUIData(SaveGameUIData& data) const { - XMLElement retval("UI"); -#ifndef FREEORION_BUILD_UTIL - retval.AppendChild(m_map_wnd->SaveGameData()); -#endif - return retval; + m_map_wnd->GetSaveGameUIData(data); } @@ -431,10 +427,10 @@ #endif } -void ClientUI::RestoreFromSaveData(const XMLElement& elem) +void ClientUI::RestoreFromSaveData(const SaveGameUIData& ui_data) { #ifndef FREEORION_BUILD_UTIL - m_map_wnd->RestoreFromSaveData(elem.Child("MapWnd")); + m_map_wnd->RestoreFromSaveData(ui_data); #endif } Modified: trunk/FreeOrion/UI/ClientUI.h =================================================================== --- trunk/FreeOrion/UI/ClientUI.h 2006-10-31 22:13:43 UTC (rev 1942) +++ trunk/FreeOrion/UI/ClientUI.h 2006-11-01 00:41:39 UTC (rev 1943) @@ -26,6 +26,7 @@ class MapWnd; class PythonConsoleWnd; class SitRepEntry; +struct SaveGameUIData; class System; class Tech; class TurnProgressWnd; @@ -74,9 +75,9 @@ const GG::SubTexture& SitRepIcon(SitRepEntry::EntryType type) const; //!< returns the icon for this sitrep entry type; returns the default icon if \a type has no associated icon - XMLElement SaveGameData() const; //!< returns the relevant data that should be restored after a save-and-load cycle + void GetSaveGameUIData(SaveGameUIData& data) const; //!< populates the relevant UI state that should be restored after a save-and-load cycle //!@} - + //! \name Mutators //!@{ // GameCore Interface functions // calling these changes internal state to display the proper screen @@ -86,10 +87,10 @@ //!@{ void InitTurn( int turn_number ); //!< resets all active controls to use the latest data when it has been changed at the beginning of a new turn - void RestoreFromSaveData(const XMLElement& elem); ///< restores the UI state that was saved in an earlier call to SaveGameData(). + void RestoreFromSaveData(const SaveGameUIData& elem); ///< restores the UI state that was saved in an earlier call to GetSaveGameUIData(). void ScreenIntro(); //!< Intro Screen - void ScreenProcessTurn(); //!< Turn Star Progress Splash Screen + void ScreenProcessTurn(); //!< Turn Star Progress Splash Screen void ScreenMap(); //!< Universe Map Screen Modified: trunk/FreeOrion/UI/MapWnd.cpp =================================================================== --- trunk/FreeOrion/UI/MapWnd.cpp 2006-10-31 22:13:43 UTC (rev 1942) +++ trunk/FreeOrion/UI/MapWnd.cpp 2006-11-01 00:41:39 UTC (rev 1943) @@ -15,6 +15,7 @@ #include "../util/Random.h" #include "ProductionWnd.h" #include "ResearchWnd.h" +#include "SaveGameUIData.h" #include "SidePanel.h" #include "SitRepPanel.h" #include "../universe/System.h" @@ -350,20 +351,15 @@ return UpperLeft() + GG::Pt(GG::GUI::GetGUI()->AppWidth(), GG::GUI::GetGUI()->AppHeight()); } -XMLElement MapWnd::SaveGameData() const +void MapWnd::GetSaveGameUIData(SaveGameUIData& data) const { - XMLElement retval("MapWnd"); - retval.AppendChild(XMLElement("upper_left_x", boost::lexical_cast<std::string>(UpperLeft().x))); - retval.AppendChild(XMLElement("upper_left_y", boost::lexical_cast<std::string>(UpperLeft().y))); - retval.AppendChild(XMLElement("m_zoom_factor", boost::lexical_cast<std::string>(m_zoom_factor))); - retval.AppendChild(XMLElement("m_nebulae")); - for (unsigned int i = 0; i < m_nebulae.size(); ++i) { - retval.LastChild().AppendChild(XMLElement("nebula" + boost::lexical_cast<std::string>(i))); - retval.LastChild().LastChild().AppendChild(XMLElement("filename", m_nebulae[i]->Filename())); - retval.LastChild().LastChild().AppendChild(XMLElement("position_x", boost::lexical_cast<std::string>(m_nebula_centers[i].x))); - retval.LastChild().LastChild().AppendChild(XMLElement("position_y", boost::lexical_cast<std::string>(m_nebula_centers[i].y))); + data.map_upper_left = UpperLeft(); + data.map_zoom_factor = m_zoom_factor; + data.map_nebulae.resize(m_nebulae.size()); + for (unsigned int i = 0; i < data.map_nebulae.size(); ++i) { + data.map_nebulae[i].filename = m_nebulae[i]->Filename(); + data.map_nebulae[i].center = m_nebula_centers[i]; } - return retval; } bool MapWnd::InProductionViewMode() const @@ -706,9 +702,9 @@ m_toolbar->Show(); } -void MapWnd::RestoreFromSaveData(const XMLElement& elem) +void MapWnd::RestoreFromSaveData(const SaveGameUIData& data) { - m_zoom_factor = boost::lexical_cast<double>(elem.Child("m_zoom_factor").Text()); + m_zoom_factor = data.map_zoom_factor; for (std::map<int, SystemIcon*>::iterator it = m_system_icons.begin(); it != m_system_icons.end(); ++it) { const System& system = it->second->GetSystem(); @@ -731,10 +727,7 @@ } GG::Pt ul = UpperLeft(); - GG::Pt map_move = - GG::Pt(boost::lexical_cast<int>(elem.Child("upper_left_x").Text()), - boost::lexical_cast<int>(elem.Child("upper_left_y").Text())) - - ul; + GG::Pt map_move = data.map_upper_left - ul; OffsetMove(map_move); MoveBackgrounds(map_move); m_side_panel->OffsetMove(-map_move); @@ -756,12 +749,9 @@ m_nebulae.clear(); m_nebula_centers.clear(); - const XMLElement& nebulae = elem.Child("m_nebulae"); - for (int i = 0; i < nebulae.NumChildren(); ++i) { - const XMLElement& curr_nebula = nebulae.Child(i); - m_nebulae.push_back(GG::GUI::GetGUI()->GetTexture(curr_nebula.Child("filename").Text())); - m_nebula_centers.push_back(GG::Pt(boost::lexical_cast<int>(curr_nebula.Child("position_x").Text()), - boost::lexical_cast<int>(curr_nebula.Child("position_y").Text()))); + for (unsigned int i = 0; i < data.map_nebulae.size(); ++i) { + m_nebulae.push_back(GG::GUI::GetGUI()->GetTexture(data.map_nebulae[i].filename)); + m_nebula_centers.push_back(data.map_nebulae[i].center); } } Modified: trunk/FreeOrion/UI/MapWnd.h =================================================================== --- trunk/FreeOrion/UI/MapWnd.h 2006-10-31 22:13:43 UTC (rev 1942) +++ trunk/FreeOrion/UI/MapWnd.h 2006-11-01 00:41:39 UTC (rev 1943) @@ -16,6 +16,7 @@ class MapWndPopup; class ProductionWnd; class ResearchWnd; +struct SaveGameUIData; class SidePanel; class SitRepPanel; class System; @@ -56,8 +57,8 @@ double ZoomFactor() const {return m_zoom_factor;} SidePanel* GetSidePanel() const {return m_side_panel;} - XMLElement SaveGameData() const; //!< returns the relevant data that should be restored after a save-and-load cycle - bool InProductionViewMode() const; //!< returns tru iff this MapWnd is visible and usable for interaction, but the allowed interactions are restricted to those appropriate to the production screen + void GetSaveGameUIData(SaveGameUIData& data) const; //!< populates the relevant UI state that should be restored after a save-and-load cycle + bool InProductionViewMode() const; //!< returns true iff this MapWnd is visible and usable for interaction, but the allowed interactions are restricted to those appropriate to the production screen //!@} //! \name Mutators //!@{ @@ -71,7 +72,7 @@ virtual void MouseWheel(const GG::Pt& pt, int move, Uint32 keys); void InitTurn( int turn_number ); //!< called at the start of each turn - void RestoreFromSaveData(const XMLElement& elem); //!< restores the UI state that was saved in an earlier call to SaveGameData(). + void RestoreFromSaveData(const SaveGameUIData& data); //!< restores the UI state that was saved in an earlier call to GetSaveGameUIData(). void ShowSystemNames(); //!< enables the system name text void HideSystemNames(); //!< disables the system name text void HandlePlayerChatMessage(const std::string& msg); //!< displays incoming player chat text Modified: trunk/FreeOrion/client/AI/AIClientApp.cpp =================================================================== --- trunk/FreeOrion/client/AI/AIClientApp.cpp 2006-10-31 22:13:43 UTC (rev 1942) +++ trunk/FreeOrion/client/AI/AIClientApp.cpp 2006-11-01 00:41:39 UTC (rev 1943) @@ -232,14 +232,11 @@ } case Message::LOAD_GAME: { - std::stringstream stream(msg.GetText()); - XMLDoc doc; - doc.ReadDoc(stream); - XMLObjectFactory<Order> factory; - Order::InitOrderFactory(factory); - for (int i = 0; i < doc.root_node.Child("Orders").NumChildren(); ++i) { - Orders().IssueOrder(factory.GenerateObject(doc.root_node.Child("Orders").Child(i))); - } + std::istringstream is(msg.GetText()); + boost::archive::binary_iarchive ia(is); + Deserialize(&ia, Orders()); + Orders().ApplyOrders(); + // KLUDGE: We're just ignoring the rest of the message, since it only contains human-player UI settings break; } Modified: trunk/FreeOrion/client/ClientApp.cpp =================================================================== --- trunk/FreeOrion/client/ClientApp.cpp 2006-10-31 22:13:43 UTC (rev 1942) +++ trunk/FreeOrion/client/ClientApp.cpp 2006-11-01 00:41:39 UTC (rev 1943) @@ -48,16 +48,18 @@ Message ClientApp::TurnOrdersMessage(bool save_game_data/* = false*/) const { if (save_game_data) { - XMLDoc orders_doc; - orders_doc.root_node.AppendChild(XMLElement("Orders")); - for (OrderSet::const_iterator order_it = m_orders.begin(); order_it != m_orders.end(); ++order_it) { - orders_doc.root_node.LastChild().AppendChild(order_it->second->XMLEncode()); + std::ostringstream os; + { + boost::archive::binary_oarchive oa(os); + Serialize(&oa, m_orders); + bool ui_data_available = false; + oa << BOOST_SERIALIZATION_NVP(ui_data_available); } - return ClientSaveDataMessage(m_player_id, orders_doc); + return ClientSaveDataMessage(m_player_id, os.str()); } else { std::ostringstream os; { - boost::archive::xml_oarchive oa(os); + boost::archive::binary_oarchive oa(os); Serialize(&oa, m_orders); } return ::TurnOrdersMessage(m_player_id, os.str()); Modified: trunk/FreeOrion/client/human/HumanClientApp.cpp =================================================================== --- trunk/FreeOrion/client/human/HumanClientApp.cpp 2006-10-31 22:13:43 UTC (rev 1942) +++ trunk/FreeOrion/client/human/HumanClientApp.cpp 2006-11-01 00:41:39 UTC (rev 1943) @@ -5,6 +5,7 @@ #include "../../UI/CUIControls.h" #include "../../UI/CUIStyle.h" +#include "../../UI/SaveGameUIData.h" #include "../../UI/MapWnd.h" #include "../../network/Message.h" #include "../../UI/MultiplayerLobbyWnd.h" @@ -30,6 +31,7 @@ #include <boost/filesystem/operations.hpp> #include <boost/filesystem/fstream.hpp> #include <boost/format.hpp> +#include <boost/serialization/vector.hpp> #include <sstream> @@ -133,18 +135,21 @@ Message HumanClientApp::TurnOrdersMessage(bool save_game_data/* = false*/) const { if (save_game_data) { - XMLDoc orders_doc; - if (save_game_data) - orders_doc.root_node.AppendChild(ClientUI::GetClientUI()->SaveGameData()); // include relevant UI state - orders_doc.root_node.AppendChild(XMLElement("Orders")); - for (OrderSet::const_iterator order_it = m_orders.begin(); order_it != m_orders.end(); ++order_it) { - orders_doc.root_node.LastChild().AppendChild(order_it->second->XMLEncode()); + std::ostringstream os; + { + boost::archive::binary_oarchive oa(os); + Serialize(&oa, m_orders); + bool ui_data_available = true; + oa << BOOST_SERIALIZATION_NVP(ui_data_available); + SaveGameUIData ui_data; + ClientUI::GetClientUI()->GetSaveGameUIData(ui_data); + oa << BOOST_SERIALIZATION_NVP(ui_data); } - return ClientSaveDataMessage(m_player_id, orders_doc); + return ClientSaveDataMessage(m_player_id, os.str()); } else { std::ostringstream os; { - boost::archive::xml_oarchive oa(os); + boost::archive::binary_oarchive oa(os); Serialize(&oa, m_orders); } return ::TurnOrdersMessage(m_player_id, os.str()); @@ -614,21 +619,17 @@ } case Message::LOAD_GAME: { - std::stringstream stream(msg.GetText()); - XMLDoc doc; - doc.ReadDoc(stream); - - // re-issue orders given earlier in the saved turn - XMLObjectFactory<Order> factory; - Order::InitOrderFactory(factory); - for (int i = 0; i < doc.root_node.Child("Orders").NumChildren(); ++i) { - Orders().IssueOrder(factory.GenerateObject(doc.root_node.Child("Orders").Child(i))); + std::istringstream is(msg.GetText()); + boost::archive::binary_iarchive ia(is); + bool ui_data_available; + SaveGameUIData ui_data; + Deserialize(&ia, Orders()); + Orders().ApplyOrders(); + ia >> BOOST_SERIALIZATION_NVP(ui_data_available); + if (ui_data_available) { + ia >> BOOST_SERIALIZATION_NVP(ui_data); + ClientUI::GetClientUI()->RestoreFromSaveData(ui_data); } - - // restore UI state - if (doc.root_node.ContainsChild("UI")) { - ClientUI::GetClientUI()->RestoreFromSaveData(doc.root_node.Child("UI")); - } break; } Modified: trunk/FreeOrion/network/Message.cpp =================================================================== --- trunk/FreeOrion/network/Message.cpp 2006-10-31 22:13:43 UTC (rev 1942) +++ trunk/FreeOrion/network/Message.cpp 2006-11-01 00:41:39 UTC (rev 1943) @@ -252,7 +252,7 @@ return Message(Message::TURN_UPDATE, -1, player_id, Message::CORE, data); } -Message ClientSaveDataMessage(int sender, const XMLDoc& data) +Message ClientSaveDataMessage(int sender, const std::string& data) { return Message(Message::CLIENT_SAVE_DATA, sender, -1, Message::CORE, data); } @@ -282,7 +282,7 @@ return Message(Message::SAVE_GAME, -1, receiver, done ? Message::CLIENT_SYNCHRONOUS_RESPONSE : Message::CORE, ""); } -Message ServerLoadGameMessage(int receiver, const XMLDoc& data) +Message ServerLoadGameMessage(int receiver, const std::string& data) { return Message(Message::LOAD_GAME, -1, receiver, Message::CORE, data); } Modified: trunk/FreeOrion/network/Message.h =================================================================== --- trunk/FreeOrion/network/Message.h 2006-10-31 22:13:43 UTC (rev 1942) +++ trunk/FreeOrion/network/Message.h 2006-11-01 00:41:39 UTC (rev 1943) @@ -174,7 +174,7 @@ Message TurnUpdateMessage(int player_id, const std::string& data); /** creates an CLIENT_SAVE_DATA message. */ -Message ClientSaveDataMessage(int sender, const XMLDoc& data); +Message ClientSaveDataMessage(int sender, const std::string& data); /** creates an REQUEST_NEW_OBJECT_ID message. This message is a synchronous message, when sent it will wait for a reply form the server */ Message RequestNewObjectIDMessage(int sender); @@ -192,7 +192,7 @@ Message ServerSaveGameMessage(int receiver, bool done = false); /** creates a LOAD_GAME data message. This message should only be sent by the server to provide saved game data to a client.*/ -Message ServerLoadGameMessage(int receiver, const XMLDoc& data); +Message ServerLoadGameMessage(int receiver, const std::string& data); /** creates a HUMAN_PLAYER_MSG, which is sent to the server, and then from the server to all human players, including the originating player. This is used for MP chat.*/ Modified: trunk/FreeOrion/server/ServerApp.cpp =================================================================== --- trunk/FreeOrion/server/ServerApp.cpp 2006-10-31 22:13:43 UTC (rev 1942) +++ trunk/FreeOrion/server/ServerApp.cpp 2006-11-01 00:41:39 UTC (rev 1943) @@ -19,14 +19,21 @@ #include "../util/XMLDoc.h" #include "../util/Serialize.h" #include "../util/SitRepEntry.h" +#include "../UI/SaveGameUIData.h" #include <GG/Font.h> #include <GG/net/fastevents.h> -#include <boost/lexical_cast.hpp> #include <boost/filesystem/exception.hpp> #include <boost/filesystem/fstream.hpp> #include <boost/filesystem/operations.hpp> +#include <boost/lexical_cast.hpp> +#include <boost/serialization/deque.hpp> +#include <boost/serialization/list.hpp> +#include <boost/serialization/map.hpp> +#include <boost/serialization/set.hpp> +#include <boost/serialization/vector.hpp> +#include "../universe/ShipDesign.h" #include <log4cpp/Appender.hh> #include <log4cpp/Category.hh> @@ -153,7 +160,6 @@ const std::string AI_CLIENT_EXE = (BIN_DIR / "freeorionca").native_file_string(); #endif const std::string LAST_TURN_UPDATE_SAVE_ELEM_PREFIX = "empire_"; - XMLDoc g_load_doc; // command-line options void AddOptions(OptionsDB& db) @@ -183,6 +189,22 @@ //////////////////////////////////////////////// +// ServerApp::PlayerSaveGameData +//////////////////////////////////////////////// +ServerApp::PlayerSaveGameData::PlayerSaveGameData() : + m_empire(0) +{} + +ServerApp::PlayerSaveGameData::PlayerSaveGameData(const std::string& name, Empire* empire, const boost::shared_ptr<OrderSet>& orders, const boost::shared_ptr<SaveGameUIData>& ui_data) : + m_name(name), + m_empire(empire), + m_orders(orders), + m_ui_data(ui_data) +{} + + + +//////////////////////////////////////////////// // ServerApp //////////////////////////////////////////////// // static member(s) @@ -310,13 +332,13 @@ } m_state = SERVER_GAME_SETUP; CreateAIClients(g_lobby_data.AIs); - g_load_doc.root_node = XMLElement(); + m_player_save_game_data.clear(); m_log_category.debugStream() << "ServerApp::HandleMessage : Server now in mode " << SERVER_GAME_SETUP << " (SERVER_GAME_SETUP)."; if (m_expected_players == static_cast<int>(m_network_core.Players().size())) { - if (g_load_doc.root_node.NumChildren()) + if (m_player_save_game_data.empty()) + NewGameInit(); + else LoadGameInit(); - else - NewGameInit(); m_state = SERVER_WAITING; m_log_category.debugStream() << "ServerApp::HandleMessage : Server now in mode " << SERVER_WAITING << " (SERVER_WAITING)."; } @@ -327,38 +349,33 @@ m_single_player_game = false; std::string load_filename = (GetLocalDir() / SAVE_DIR_NAME / g_lobby_data.save_games[g_lobby_data.save_file]).native_file_string(); - XMLDoc doc; - GZStream::igzstream ifs(load_filename.c_str()); - doc.ReadDoc(ifs); +#if GZIP_SAVE_FILES_COMPRESSION_LEVEL + GZStream::igzstream ifs(load_filename.c_str(), std::ios_base::binary); +#else + std::ifstream ifs(load_filename.c_str(), std::ios_base::binary); +#endif + { + boost::archive::binary_iarchive ia(ifs); + ia >> BOOST_SERIALIZATION_NVP(m_current_turn); + ia >> BOOST_SERIALIZATION_NVP(m_player_save_game_data); + Universe::s_encoding_empire = ALL_EMPIRES; + ia >> BOOST_SERIALIZATION_NVP(m_universe); + } ifs.close(); + m_expected_players = m_player_save_game_data.size(); - // set the player names of all empires to match the selected player name/empire name pairs in the lobby - // (AI players' names will replace the applicable old names when the AIs connect later.) - for (int i = 0; i < doc.root_node.NumChildren(); ++i) { - if (doc.root_node.Child(i).Tag() == "Player") { - int player_empire_id = boost::lexical_cast<int>(doc.root_node.Child(i).Child("Empire").Child("m_id").Text()); - for (unsigned int j = 0; j < g_lobby_data.players.size(); ++j) { - if (g_lobby_data.players[j].save_game_empire_id == player_empire_id) { - std::map<int, PlayerInfo>::const_iterator player_it = m_network_core.Players().begin(); - std::advance(player_it, j); - doc.root_node.Child(i).Child("name").SetText(player_it->second.name); - doc.root_node.Child(i).Child("Empire").Child("m_player_name").SetText(player_it->second.name); - break; - } + for (unsigned int i = 0; i < m_player_save_game_data.size(); ++i) { + for (unsigned int j = 0; j < g_lobby_data.players.size(); ++j) { + assert(m_player_save_game_data[i].m_empire); + if (g_lobby_data.players[j].save_game_empire_id == m_player_save_game_data[i].m_empire->EmpireID()) { + std::map<int, PlayerInfo>::const_iterator player_it = m_network_core.Players().begin(); + std::advance(player_it, j); + m_player_save_game_data[i].m_name = player_it->second.name; + m_player_save_game_data[i].m_empire->SetPlayerName(player_it->second.name); } } } - m_expected_players = 0; - for (int i = 0; i < doc.root_node.NumChildren(); ++i) { - if (doc.root_node.Child(i).Tag() == "Player") { - m_empires.InsertEmpire(new Empire(doc.root_node.Child(i).Child("Empire"))); - ++m_expected_players; - } - } - m_universe.SetUniverse(doc.root_node.Child("Universe")); - LoadGameVars(doc); - for (std::map<int, PlayerInfo>::const_iterator it = m_network_core.Players().begin(); it != m_network_core.Players().end(); ++it) { if (it != sender_it) m_network_core.SendMessage(Message(Message::GAME_START, -1, it->first, Message::CLIENT_LOBBY_MODULE, "")); @@ -366,7 +383,6 @@ int AI_clients = m_expected_players - m_network_core.Players().size(); CreateAIClients(std::vector<PlayerSetupData>(AI_clients)); - g_load_doc = doc; m_state = SERVER_GAME_SETUP; if (!AI_clients) @@ -503,30 +519,19 @@ break; } if (m_players_responded == needed_reponses) { - SaveGameVars(doc); - for (std::map<int, XMLElement>::iterator it = m_player_save_game_data.begin(); it != m_player_save_game_data.end(); ++it) { - XMLElement player_element("Player"); - player_element.AppendChild(XMLElement("name", m_network_core.Players().find(it->first)->second.name)); - Empire* player_empire = GetPlayerEmpire(it->first); - player_element.AppendChild(m_empires.Lookup(player_empire->EmpireID())->XMLEncode()); - for (XMLElement::const_child_iterator elem_it = it->second.child_begin(); elem_it != it->second.child_end(); ++elem_it) { - player_element.AppendChild(*elem_it); - } - doc.root_node.AppendChild(player_element); - } - doc.root_node.AppendChild(m_universe.XMLEncode(ALL_EMPIRES)); - #if GZIP_SAVE_FILES_COMPRESSION_LEVEL - GZStream::ogzstream ofs(save_filename.c_str()); - /* For now, we use the standard compression settings, - but later we could let the compression settings be - customizable in the save-dialog */ - // The default is: ofs.set_gzparams(6, Z_DEFAULT_STRATEGY); + GZStream::ogzstream ofs(save_filename.c_str(), std::ios_base::binary); ofs.set_gzparams(GZIP_SAVE_FILES_COMPRESSION_LEVEL, Z_DEFAULT_STRATEGY); #else - boost::filesystem::ofstream ofs(save_filename); + std::ofstream ofs(save_filename.c_str(), std::ios_base::binary); #endif - doc.WriteDoc(ofs, GZIP_SAVE_FILES_COMPRESSION_LEVEL ? false : true); + { + boost::archive::binary_oarchive oa(ofs); + oa << BOOST_SERIALIZATION_NVP(m_current_turn); + Universe::s_encoding_empire = ALL_EMPIRES; + oa << BOOST_SERIALIZATION_NVP(m_player_save_game_data); + oa << BOOST_SERIALIZATION_NVP(m_universe); + } ofs.close(); m_network_core.SendMessage(ServerSaveGameMessage(msg.Sender(), true)); } @@ -541,25 +546,23 @@ if (sender_it != m_network_core.Players().end() && sender_it->second.host) { m_empires.RemoveAllEmpires(); m_single_player_game = true; - std::string load_filename = msg.GetText(); - XMLDoc doc; - GZStream::igzstream ifs(load_filename.c_str()); - doc.ReadDoc(ifs); +#if GZIP_SAVE_FILES_COMPRESSION_LEVEL + GZStream::igzstream ifs(load_filename.c_str(), std::ios_base::binary); +#else + std::ifstream ifs(load_filename.c_str(), std::ios_base::binary); +#endif + { + boost::archive::binary_iarchive ia(ifs); + ia >> BOOST_SERIALIZATION_NVP(m_current_turn); + Universe::s_encoding_empire = ALL_EMPIRES; + ia >> BOOST_SERIALIZATION_NVP(m_player_save_game_data); + ia >> BOOST_SERIALIZATION_NVP(m_universe); + } ifs.close(); + m_expected_players = m_player_save_game_data.size(); - m_expected_players = 0; - for (int i = 0; i < doc.root_node.NumChildren(); ++i) { - if (doc.root_node.Child(i).Tag() == "Player") { - m_empires.InsertEmpire(new Empire(doc.root_node.Child(i).Child("Empire"))); - ++m_expected_players; - } - } - m_universe.SetUniverse(doc.root_node.Child("Universe")); - LoadGameVars(doc); - CreateAIClients(std::vector<PlayerSetupData>(m_expected_players - 1)); - g_load_doc = doc; m_state = SERVER_GAME_SETUP; } else { m_log_category.errorStream() << "Player #" << msg.Sender() << " attempted to initiate a game save, but is not the host, or is " @@ -570,7 +573,7 @@ case Message::TURN_ORDERS: { std::istringstream is(msg.GetText()); - boost::archive::xml_iarchive ia(is); + boost::archive::binary_iarchive ia(is); OrderSet* order_set = new OrderSet; Deserialize(&ia, *order_set); @@ -608,12 +611,20 @@ } case Message::CLIENT_SAVE_DATA: { - std::stringstream stream(msg.GetText()); - XMLDoc doc; - doc.ReadDoc(stream); - m_player_save_game_data[msg.Sender()].AppendChild(doc.root_node.Child("Orders")); - if (doc.root_node.ContainsChild("UI")) - m_player_save_game_data[msg.Sender()].AppendChild(doc.root_node.Child("UI")); + std::istringstream is(msg.GetText()); + boost::archive::binary_iarchive ia(is); + boost::shared_ptr<OrderSet> order_set(new OrderSet); + bool ui_data_available; + boost::shared_ptr<SaveGameUIData> ui_data; + Deserialize(&ia, *order_set); + ia >> BOOST_SERIALIZATION_NVP(ui_data_available); + if (ui_data_available) { + ui_data.reset(new SaveGameUIData); + ia >> boost::serialization::make_nvp("ui_data", *ui_data); + } + std::map<int, PlayerInfo>::const_iterator player_it = m_network_core.Players().find(msg.Sender()); + assert(player_it != m_network_core.Players().end()); + m_player_save_game_data.push_back(PlayerSaveGameData(player_it->second.name, GetPlayerEmpire(msg.Sender()), order_set, ui_data)); m_players_responded.insert(msg.Sender()); break; } @@ -649,7 +660,7 @@ return; } Empire* sender_empire = GetPlayerEmpire(msg.Sender()); - std::string final_text = RgbaTag(Empires().Lookup(sender_empire->EmpireID())->Color()) + m_network_core.Players().find(msg.Sender())->second.name + + std::string final_text = RgbaTag(Empires().Lookup(sender_empire->EmpireID())->Color()) + m_network_core.Players().find(msg.Sender())->second.name + (target_player_names.empty() ? ": " : " (whisper):") + text + "</rgba>\n"; for (std::map<int, PlayerInfo>::const_iterator it = m_network_core.Players().begin(); it != m_network_core.Players().end(); ++it) { if (target_player_names.empty() || target_player_names.find(it->second.name) != target_player_names.end()) @@ -963,7 +974,7 @@ m_planet_density = boost::lexical_cast<PlanetDensity>(doc.root_node.Child("universe_params").Child("planet_density").Text()); m_specials_freq = boost::lexical_cast<SpecialsFrequency>(doc.root_node.Child("universe_params").Child("specials_freq").Text()); CreateAIClients(doc.root_node); - g_load_doc.root_node = XMLElement(); + m_player_save_game_data.clear(); g_lobby_data.players.clear(); g_lobby_data.players.push_back(PlayerSetupData()); g_lobby_data.players.back().empire_name = doc.root_node.Child("empire_name").Text(); @@ -1036,10 +1047,10 @@ } if (static_cast<int>(m_network_core.Players().size()) == m_expected_players) { // if we've gotten all the players joined up - if (g_load_doc.root_node.NumChildren()) + if (m_player_save_game_data.empty()) + NewGameInit(); + else LoadGameInit(); - else - NewGameInit(); m_state = SERVER_WAITING; m_log_category.debugStream() << "ServerApp::HandleNonPlayerMessage : Server now in mode " << SERVER_WAITING << " (SERVER_WAITING)."; } @@ -1278,18 +1289,14 @@ void ServerApp::LoadGameInit() { + assert(!m_player_save_game_data.empty()); + m_turn_sequence.clear(); - std::map<int, XMLDoc> player_docs; // indexed by empire id - for (int i = 0; i < g_load_doc.root_node.NumChildren(); ++i) { - if (g_load_doc.root_node.Child(i).Tag() == "Player") { - XMLDoc player_doc; - player_doc.root_node.SetTag("XMLDoc"); - player_doc.root_node.AppendChild(g_load_doc.root_node.Child(i).Child("Orders")); - if (g_load_doc.root_node.Child(i).ContainsChild("UI")) - player_doc.root_node.AppendChild(g_load_doc.root_node.Child(i).Child("UI")); - player_docs[boost::lexical_cast<int>(g_load_doc.root_node.Child(i).Child("Empire").Child("m_id").Text())] = player_doc; - } + std::map<int, PlayerSaveGameData> player_data_by_empire; + for (unsigned int i = 0; i < m_player_save_game_data.size(); ++i) { + assert(m_player_save_game_data[i].m_empire); + player_data_by_empire[m_player_save_game_data[i].m_empire->EmpireID()] = m_player_save_game_data[i]; } std::map<int, int> player_to_empire_ids; @@ -1302,19 +1309,19 @@ already_chosen_empire_ids.insert(g_lobby_data.players[i].save_game_empire_id); } - std::map<int, XMLDoc>::iterator player_doc_it = player_docs.begin(); - for (std::map<int, PlayerInfo>::const_iterator it = m_network_core.Players().begin(); it != m_network_core.Players().end(); ++it, ++player_doc_it) { + for (std::map<int, PlayerInfo>::const_iterator it = m_network_core.Players().begin(); it != m_network_core.Players().end(); ++it) { const int INVALID_EMPIRE_ID = -5000; int empire_id = INVALID_EMPIRE_ID; if (player_to_empire_ids[it->first] != -1) { empire_id = player_to_empire_ids[it->first]; } else { - for (std::map<int, XMLDoc>::iterator doc_it = player_docs.begin(); doc_it != player_docs.end(); ++doc_it) { - if (already_chosen_empire_ids.find(doc_it->first) == already_chosen_empire_ids.end()) { - empire_id = doc_it->first; + for (std::map<int, PlayerSaveGameData>::iterator player_data_it = player_data_by_empire.begin(); player_data_it != player_data_by_empire.end(); ++player_data_it) { + if (already_chosen_empire_ids.find(player_data_it->first) == already_chosen_empire_ids.end()) { + empire_id = player_data_it->first; already_chosen_empire_ids.insert(empire_id); // since this must be an AI player, it does not have the correct player name set in its Empire yet, so we need to do so now - Empires().Lookup(empire_id)->SetPlayerName(it->second.name); + player_data_it->second.m_empire->SetPlayerName(it->second.name); + Empires().InsertEmpire(player_data_it->second.m_empire); break; } } @@ -1333,7 +1340,16 @@ m_network_core.SendMessage(GameStartMessage(it->first, os.str())); // send saved pending orders to player - m_network_core.SendMessage(ServerLoadGameMessage(it->first, player_docs[empire_id])); + std::ostringstream os2; + { + boost::archive::binary_oarchive oa(os2); + Serialize(&oa, *player_data_by_empire[empire_id].m_orders); + bool ui_data_available = player_data_by_empire[empire_id].m_ui_data; + oa << BOOST_SERIALIZATION_NVP(ui_data_available); + if (ui_data_available) + oa << boost::serialization::make_nvp("ui_data", *player_data_by_empire[empire_id].m_ui_data); + } + m_network_core.SendMessage(ServerLoadGameMessage(it->first, os2.str())); m_turn_sequence[empire_id] = 0; } @@ -1463,18 +1479,6 @@ return retval; } -void ServerApp::SaveGameVars(XMLDoc& doc) const -{ - doc.root_node.AppendChild(XMLElement("turn_number", boost::lexical_cast<std::string>(m_current_turn))); - -} - -void ServerApp::LoadGameVars(const XMLDoc& doc) -{ - m_current_turn = boost::lexical_cast<int>(doc.root_node.Child("turn_number").Text()); -} - - Empire* ServerApp::GetPlayerEmpire(int player_id) const { Empire* retval = 0; Modified: trunk/FreeOrion/server/ServerApp.h =================================================================== --- trunk/FreeOrion/server/ServerApp.h 2006-10-31 22:13:43 UTC (rev 1942) +++ trunk/FreeOrion/server/ServerApp.h 2006-11-01 00:41:39 UTC (rev 1943) @@ -33,6 +33,7 @@ class Message; class OrderSet; struct PlayerSetupData; +struct SaveGameUIData; class XMLDoc; class XMLElement; @@ -136,9 +137,6 @@ XMLDoc LobbyStartDoc() const; ///< returns an MP lobby-mode update XMLDoc containing just the initial server-side data that the clients don't have XMLDoc SaveGameUpdateDoc() const; ///< returns an MP lobby-mode update XMLDoc containing just empire data for the currently-selected save game - void SaveGameVars(XMLDoc& doc) const; ///< adds all game-state variables to \a doc - void LoadGameVars(const XMLDoc& doc); ///< assigns all game-state variables from \a doc - Empire* GetPlayerEmpire(int player_id) const; ///< returns the object for the empire that that the player with ID \a player_id is playing int GetEmpirePlayerID(int empire_id) const; ///< returns the player ID for the player playing the empire with ID \a empire_id @@ -172,9 +170,24 @@ bool m_single_player_game; ///< true when the game being played is single-player std::set<int> m_players_responded; ///< tracks which players have responded to a server request (eg for save-data) - std::map<int, XMLElement> - m_player_save_game_data; ///< stores the save game data coming in from the players during a save game operation + struct PlayerSaveGameData + { + PlayerSaveGameData(); + PlayerSaveGameData(const std::string& name, Empire* empire, const boost::shared_ptr<OrderSet>& orders, const boost::shared_ptr<SaveGameUIData>& ui_data); + + std::string m_name; + Empire* m_empire; + boost::shared_ptr<OrderSet> m_orders; + boost::shared_ptr<SaveGameUIData> m_ui_data; + + private: + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); + }; + std::vector<PlayerSaveGameData> m_player_save_game_data; ///< stores the save game data coming in from the players during a save game operation + // turn sequence map is used for turn processing. Each empire is added at the start of a game or reload and then the map maintains OrderSets for that turn std::map<int, OrderSet*> m_turn_sequence; @@ -183,5 +196,15 @@ static ServerApp* s_app; }; +// template implementations +template <class Archive> +void ServerApp::PlayerSaveGameData::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_NVP(m_name) + & BOOST_SERIALIZATION_NVP(m_empire) + & BOOST_SERIALIZATION_NVP(m_orders) + & BOOST_SERIALIZATION_NVP(m_ui_data); +} + #endif // _ServerApp_h_ Modified: trunk/FreeOrion/util/OrderSet.cpp =================================================================== --- trunk/FreeOrion/util/OrderSet.cpp 2006-10-31 22:13:43 UTC (rev 1942) +++ trunk/FreeOrion/util/OrderSet.cpp 2006-11-01 00:41:39 UTC (rev 1943) @@ -34,11 +34,11 @@ } -int OrderSet::AddOrder(Order* order) +void OrderSet::ApplyOrders() { - int retval = ((m_orders.rbegin() != m_orders.rend()) ? m_orders.rbegin()->first + 1 : 0); - m_orders[retval] = order; - return retval; + for (OrderMap::iterator it = m_orders.begin(); it != m_orders.end(); ++it) { + it->second->Execute(); + } } Modified: trunk/FreeOrion/util/OrderSet.h =================================================================== --- trunk/FreeOrion/util/OrderSet.h 2006-10-31 22:13:43 UTC (rev 1942) +++ trunk/FreeOrion/util/OrderSet.h 2006-11-01 00:41:39 UTC (rev 1943) @@ -46,15 +46,15 @@ //@} /** \name Mutators */ //@{ - /** executes a given Order, then stores it order in the OrderSet. Returns an index that can be used to reference the order. - \warning The OrderSet assumes that the Order is allocated on the heap, and takes ownership of it. Do not delete any - Order* passed to OrderSet.*/ + /** executes a given Order, then stores it in the OrderSet. Returns an index that can be used to reference the + order. \warning The OrderSet assumes that the Order is allocated on the heap, and takes ownership of it. Do + not delete any Order* passed to OrderSet.*/ int IssueOrder(Order* order); - /** adds order order to set without executing it. Order* passed to OrderSet.*/ - int AddOrder(Order* order); + /** Applies all Orders in the OrderSet. As of this writing, this is needed only after deserializing an OrderSet + client-side during game loading. */ + void ApplyOrders(); - bool RecindOrder(int order); ///< removes the order from the OrderSet; returns true on success, false if there was no such order or the order is non-recindable void Reset(); ///< clears all orders; should be called at the beginning of a new turn //@} |
From: <tz...@us...> - 2006-11-04 18:54:24
|
Revision: 1947 http://svn.sourceforge.net/freeorion/revision/?rev=1947&view=rev Author: tzlaine Date: 2006-11-04 10:54:17 -0800 (Sat, 04 Nov 2006) Log Message: ----------- Moved SaveGameUIData into MultiplayerCommon.h, where it should have been put to begin with. Modified Paths: -------------- trunk/FreeOrion/UI/MapWnd.cpp trunk/FreeOrion/UI/SystemIcon.cpp trunk/FreeOrion/client/human/HumanClientApp.cpp trunk/FreeOrion/server/ServerApp.cpp trunk/FreeOrion/util/MultiplayerCommon.h Removed Paths: ------------- trunk/FreeOrion/UI/SaveGameUIData.h Modified: trunk/FreeOrion/UI/MapWnd.cpp =================================================================== --- trunk/FreeOrion/UI/MapWnd.cpp 2006-11-04 18:10:34 UTC (rev 1946) +++ trunk/FreeOrion/UI/MapWnd.cpp 2006-11-04 18:54:17 UTC (rev 1947) @@ -15,7 +15,6 @@ #include "../util/Random.h" #include "ProductionWnd.h" #include "ResearchWnd.h" -#include "SaveGameUIData.h" #include "SidePanel.h" #include "SitRepPanel.h" #include "../universe/System.h" Deleted: trunk/FreeOrion/UI/SaveGameUIData.h =================================================================== --- trunk/FreeOrion/UI/SaveGameUIData.h 2006-11-04 18:10:34 UTC (rev 1946) +++ trunk/FreeOrion/UI/SaveGameUIData.h 2006-11-04 18:54:17 UTC (rev 1947) @@ -1,54 +0,0 @@ -// -*- C++ -*- -#ifndef _SaveGameUIData_h_ -#define _SaveGameUIData_h_ - -#include <GG/PtRect.h> - -#include <boost/serialization/access.hpp> -#include <boost/serialization/nvp.hpp> - -#include <string> -#include <vector> - - -/** Contains the UI data that must be saved in save game files in order to restore games to the users' last views. */ -struct SaveGameUIData -{ - struct NebulaData - { - std::string filename; - GG::Pt center; - - private: - friend class boost::serialization::access; - template <class Archive> - void serialize(Archive& ar, const unsigned int version); - }; - - GG::Pt map_upper_left; - double map_zoom_factor; - std::vector<NebulaData> map_nebulae; - -private: - friend class boost::serialization::access; - template <class Archive> - void serialize(Archive& ar, const unsigned int version); -}; - -// template implementations -template <class Archive> -void SaveGameUIData::NebulaData::serialize(Archive& ar, const unsigned int version) -{ - ar & BOOST_SERIALIZATION_NVP(filename) - & BOOST_SERIALIZATION_NVP(center); -} - -template <class Archive> -void SaveGameUIData::serialize(Archive& ar, const unsigned int version) -{ - ar & BOOST_SERIALIZATION_NVP(map_upper_left) - & BOOST_SERIALIZATION_NVP(map_zoom_factor) - & BOOST_SERIALIZATION_NVP(map_nebulae); -} - -#endif Modified: trunk/FreeOrion/UI/SystemIcon.cpp =================================================================== --- trunk/FreeOrion/UI/SystemIcon.cpp 2006-11-04 18:10:34 UTC (rev 1946) +++ trunk/FreeOrion/UI/SystemIcon.cpp 2006-11-04 18:54:17 UTC (rev 1947) @@ -70,8 +70,8 @@ m_disc_graphic(0), m_halo_graphic(0), m_selection_indicator(0), + m_mouseover_indicator(0), m_selected(false), - m_mouseover_indicator(0), m_name(0) { Connect(m_system.StateChangedSignal, &SystemIcon::Refresh, this); Modified: trunk/FreeOrion/client/human/HumanClientApp.cpp =================================================================== --- trunk/FreeOrion/client/human/HumanClientApp.cpp 2006-11-04 18:10:34 UTC (rev 1946) +++ trunk/FreeOrion/client/human/HumanClientApp.cpp 2006-11-04 18:54:17 UTC (rev 1947) @@ -5,7 +5,6 @@ #include "../../UI/CUIControls.h" #include "../../UI/CUIStyle.h" -#include "../../UI/SaveGameUIData.h" #include "../../UI/MapWnd.h" #include "../../network/Message.h" #include "../../UI/MultiplayerLobbyWnd.h" Modified: trunk/FreeOrion/server/ServerApp.cpp =================================================================== --- trunk/FreeOrion/server/ServerApp.cpp 2006-11-04 18:10:34 UTC (rev 1946) +++ trunk/FreeOrion/server/ServerApp.cpp 2006-11-04 18:54:17 UTC (rev 1947) @@ -18,7 +18,6 @@ #include "../util/XMLDoc.h" #include "../util/Serialize.h" #include "../util/SitRepEntry.h" -#include "../UI/SaveGameUIData.h" #include <GG/Font.h> #include <GG/net/fastevents.h> Modified: trunk/FreeOrion/util/MultiplayerCommon.h =================================================================== --- trunk/FreeOrion/util/MultiplayerCommon.h 2006-11-04 18:10:34 UTC (rev 1946) +++ trunk/FreeOrion/util/MultiplayerCommon.h 2006-11-04 18:54:17 UTC (rev 1947) @@ -30,6 +30,30 @@ /** Returns the language of the StringTable currently in use */ const std::string& Language(); +/** Contains the UI data that must be saved in save game files in order to restore games to the users' last views. */ +struct SaveGameUIData +{ + struct NebulaData + { + std::string filename; + GG::Pt center; + + private: + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); + }; + + GG::Pt map_upper_left; + double map_zoom_factor; + std::vector<NebulaData> map_nebulae; + +private: + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); +}; + /** The data for one empire necessary for game-setup during multiplayer loading. */ struct SaveGameEmpireData { @@ -105,6 +129,21 @@ // template implementations template <class Archive> +void SaveGameUIData::NebulaData::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_NVP(filename) + & BOOST_SERIALIZATION_NVP(center); +} + +template <class Archive> +void SaveGameUIData::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_NVP(map_upper_left) + & BOOST_SERIALIZATION_NVP(map_zoom_factor) + & BOOST_SERIALIZATION_NVP(map_nebulae); +} + +template <class Archive> void SaveGameEmpireData::serialize(Archive& ar, const unsigned int version) { ar & BOOST_SERIALIZATION_NVP(m_id) |
From: <geo...@us...> - 2006-11-16 01:38:30
|
Revision: 1948 http://svn.sourceforge.net/freeorion/revision/?rev=1948&view=rev Author: geoffthemedio Date: 2006-11-15 17:38:30 -0800 (Wed, 15 Nov 2006) Log Message: ----------- -Added eleazar and MareviQ to credits.xml -Fixed comments in Predicates.h -Removed SaveGameUIData.h from MSVC project files Modified Paths: -------------- trunk/FreeOrion/default/credits.xml trunk/FreeOrion/msvc2005/FreeOrion/freeorion/freeorion.vcproj trunk/FreeOrion/msvc2005/FreeOrion/freeorionca/freeorionca.vcproj trunk/FreeOrion/universe/Predicates.h Modified: trunk/FreeOrion/default/credits.xml =================================================================== --- trunk/FreeOrion/default/credits.xml 2006-11-04 18:54:17 UTC (rev 1947) +++ trunk/FreeOrion/default/credits.xml 2006-11-16 01:38:30 UTC (rev 1948) @@ -17,6 +17,7 @@ <PERSON name="Tony Casale" nick="Tsev" task="Programming"/> <PERSON name="Michael J. Agostini" nick="" task="Programming"/> <PERSON name="Geoff Topping" nick="Geoff the Medio" task="Programming, Game Design"/> + <PERSON name="Karol Szumski" nick="MareviQ" task="Programming"/> </GROUP> <GROUP name ="GAMEDESIGN"> <PERSON name="Krum Stanoev" nick="" task="Game Design"/> @@ -43,6 +44,7 @@ <PERSON name="Tomi Hartikka" nick="Mystiqq" task="Graphics"/> <PERSON name="Brendan Mauro" nick="BreadMan" task="Graphics"/> <PERSON name="Karel Kalvoda" nick="Solid Liquid" task="Graphics"/> + <PERSON name="J. W. Bjerk" nick="eleazar" task="Graphics"/> </GROUP> <GROUP name ="AUDIO"> <PERSON name="Shannon Roberts" nick="Guiguibaah" task="Audio"/> Modified: trunk/FreeOrion/msvc2005/FreeOrion/freeorion/freeorion.vcproj =================================================================== --- trunk/FreeOrion/msvc2005/FreeOrion/freeorion/freeorion.vcproj 2006-11-04 18:54:17 UTC (rev 1947) +++ trunk/FreeOrion/msvc2005/FreeOrion/freeorion/freeorion.vcproj 2006-11-16 01:38:30 UTC (rev 1948) @@ -714,10 +714,6 @@ > </File> <File - RelativePath="..\..\..\UI\SaveGameUIData.h" - > - </File> - <File RelativePath="..\..\..\Ui\ServerConnectWnd.cpp" > </File> Modified: trunk/FreeOrion/msvc2005/FreeOrion/freeorionca/freeorionca.vcproj =================================================================== --- trunk/FreeOrion/msvc2005/FreeOrion/freeorionca/freeorionca.vcproj 2006-11-04 18:54:17 UTC (rev 1947) +++ trunk/FreeOrion/msvc2005/FreeOrion/freeorionca/freeorionca.vcproj 2006-11-16 01:38:30 UTC (rev 1948) @@ -702,10 +702,6 @@ Name="UI" > <File - RelativePath="..\..\..\UI\SaveGameUIData.h" - > - </File> - <File RelativePath="..\..\..\Ui\StringTable.cpp" > </File> Modified: trunk/FreeOrion/universe/Predicates.h =================================================================== --- trunk/FreeOrion/universe/Predicates.h 2006-11-04 18:54:17 UTC (rev 1947) +++ trunk/FreeOrion/universe/Predicates.h 2006-11-16 01:38:30 UTC (rev 1948) @@ -53,8 +53,8 @@ virtual ~UniverseObjectSubclassVisitor() {} }; -/** returns obj iff \a obj is a Fleet belonging to the given empire, and that is under orders to move, but is not yet moving. - If the given empire is -1, all stationary fleets will be returned. Note that it is preferable to use this functor on System +/** returns obj iff \a obj is a Fleet belonging to the given empire object that is parked at a System, not under orders to move. + If the given empire is -1, all orderd moving fleets will be returned. Note that it is preferable to use this functor on System searches, rather than Universe ones. */ struct StationaryFleetVisitor : UniverseObjectVisitor { @@ -64,8 +64,8 @@ const int empire_id; }; -/** returns obj iff \a obj is a Fleet belonging to the given empire object that is parked at a System, not under orders to move. - If the given empire is -1, all orderd moving fleets will be returned. Note that it is preferable to use this functor on System +/** returns obj iff \a obj is a Fleet belonging to the given empire, and that is under orders to move, but is not yet moving. + If the given empire is -1, all stationary fleets will be returned. Note that it is preferable to use this functor on System searches, rather than Universe ones. */ struct OrderedMovingFleetVisitor : UniverseObjectVisitor { |
From: <geo...@us...> - 2006-11-16 06:47:57
|
Revision: 1949 http://svn.sourceforge.net/freeorion/revision/?rev=1949&view=rev Author: geoffthemedio Date: 2006-11-15 22:47:54 -0800 (Wed, 15 Nov 2006) Log Message: ----------- -Added a few includes and define hacks to get the MSVC build working, mostly by tzlaine, in MultiplayerCommon and MultiplayerLobby .cpp and .h files. -HumanClientAppSoundOpenAL.cpp change, from forum by MareviQ, that fixes a crash in HumanClientAppSoundOpenAL::StopMusic() when OpenAL sound is used Modified Paths: -------------- trunk/FreeOrion/UI/MultiplayerLobbyWnd.cpp trunk/FreeOrion/UI/MultiplayerLobbyWnd.h trunk/FreeOrion/client/human/HumanClientAppSoundOpenAL.cpp trunk/FreeOrion/server/ServerApp.h trunk/FreeOrion/util/MultiplayerCommon.cpp Modified: trunk/FreeOrion/UI/MultiplayerLobbyWnd.cpp =================================================================== --- trunk/FreeOrion/UI/MultiplayerLobbyWnd.cpp 2006-11-16 01:38:30 UTC (rev 1948) +++ trunk/FreeOrion/UI/MultiplayerLobbyWnd.cpp 2006-11-16 06:47:54 UTC (rev 1949) @@ -6,6 +6,18 @@ #include "../util/MultiplayerCommon.h" #include "../util/Serialize.h" +#if defined(_MSC_VER) + // HACK! this keeps VC 7.x from barfing when it sees "typedef __int64 int64_t;" + // in boost/cstdint.h when compiling under windows +# if defined(int64_t) +# undef int64_t +# endif +#elif defined(WIN32) + // HACK! this keeps gcc 3.x from barfing when it sees "typedef long long uint64_t;" + // in boost/cstdint.h when compiling under windows +# define BOOST_MSVC -1 +#endif + #include <boost/serialization/vector.hpp> #include <GG/Button.h> Modified: trunk/FreeOrion/UI/MultiplayerLobbyWnd.h =================================================================== --- trunk/FreeOrion/UI/MultiplayerLobbyWnd.h 2006-11-16 01:38:30 UTC (rev 1948) +++ trunk/FreeOrion/UI/MultiplayerLobbyWnd.h 2006-11-16 06:47:54 UTC (rev 1949) @@ -10,6 +10,8 @@ #include "GalaxySetupWnd.h" #endif +#include "../util/MultiplayerCommon.h" + #include <vector> class CUIButton; Modified: trunk/FreeOrion/client/human/HumanClientAppSoundOpenAL.cpp =================================================================== --- trunk/FreeOrion/client/human/HumanClientAppSoundOpenAL.cpp 2006-11-16 01:38:30 UTC (rev 1948) +++ trunk/FreeOrion/client/human/HumanClientAppSoundOpenAL.cpp 2006-11-16 06:47:54 UTC (rev 1949) @@ -201,8 +201,7 @@ m_music_name.clear(); // do this to avoid music being re-started by other functions ov_clear(&m_ogg_file); // and unload the file for good measure. the file itself is closed now, don't re-close it again } - alGetSourcei(m_sources[0],AL_BUFFERS_PROCESSED,&num_buffers_processed); // we need to unqueue any unplayed buffers - alSourceUnqueueBuffers (m_sources[0], num_buffers_processed, &buffer_name_yay); // otherwise they'll cause problems if we open another file + alSourcei(m_sources[0], AL_BUFFER, 0); } } Modified: trunk/FreeOrion/server/ServerApp.h =================================================================== --- trunk/FreeOrion/server/ServerApp.h 2006-11-16 01:38:30 UTC (rev 1948) +++ trunk/FreeOrion/server/ServerApp.h 2006-11-16 06:47:54 UTC (rev 1949) @@ -2,25 +2,12 @@ #ifndef _ServerApp_h_ #define _ServerApp_h_ -#ifndef _AppInterface_h_ #include "../util/AppInterface.h" -#endif - -#ifndef _Process_h_ #include "../util/Process.h" -#endif - -#ifndef _ServerEmpire_h_ #include "../Empire/ServerEmpireManager.h" -#endif - -#ifndef _ServerNetworkCore_h_ #include "../network/ServerNetworkCore.h" -#endif - -#ifndef _Universe_h_ #include "../universe/Universe.h" -#endif +#include "../util/MultiplayerCommon.h" #include <set> #include <vector> @@ -183,7 +170,7 @@ std::vector<PlayerSaveGameData> m_player_save_game_data; ///< stores the save game data coming in from the players during a save game operation - MultiplayerLobbyData m_lobby_data; + MultiplayerLobbyData m_lobby_data; // turn sequence map is used for turn processing. Each empire is added at the start of a game or reload and then the map maintains OrderSets for that turn std::map<int, OrderSet*> m_turn_sequence; Modified: trunk/FreeOrion/util/MultiplayerCommon.cpp =================================================================== --- trunk/FreeOrion/util/MultiplayerCommon.cpp 2006-11-16 01:38:30 UTC (rev 1948) +++ trunk/FreeOrion/util/MultiplayerCommon.cpp 2006-11-16 06:47:54 UTC (rev 1949) @@ -6,6 +6,18 @@ #include <log4cpp/Priority.hh> +#if defined(_MSC_VER) + // HACK! this keeps VC 7.x from barfing when it sees "typedef __int64 int64_t;" + // in boost/cstdint.h when compiling under windows +# if defined(int64_t) +# undef int64_t +# endif +#elif defined(WIN32) + // HACK! this keeps gcc 3.x from barfing when it sees "typedef long long uint64_t;" + // in boost/cstdint.h when compiling under windows +# define BOOST_MSVC -1 +#endif + #include <boost/filesystem/exception.hpp> #include <boost/filesystem/operations.hpp> |
From: <tz...@us...> - 2006-11-18 23:37:18
|
Revision: 1950 http://svn.sourceforge.net/freeorion/revision/?rev=1950&view=rev Author: tzlaine Date: 2006-11-18 15:37:17 -0800 (Sat, 18 Nov 2006) Log Message: ----------- More removal of XMLDoc from messages passed between the server and clients. Modified Paths: -------------- trunk/FreeOrion/UI/OptionsWnd.cpp trunk/FreeOrion/client/AI/AIClientApp.cpp trunk/FreeOrion/client/human/HumanClientApp.cpp trunk/FreeOrion/network/ClientNetworkCore.cpp trunk/FreeOrion/network/Message.cpp trunk/FreeOrion/network/Message.h trunk/FreeOrion/network/NetworkCore.h trunk/FreeOrion/network/ServerNetworkCore.cpp trunk/FreeOrion/server/ServerApp.cpp trunk/FreeOrion/server/ServerApp.h Modified: trunk/FreeOrion/UI/OptionsWnd.cpp =================================================================== --- trunk/FreeOrion/UI/OptionsWnd.cpp 2006-11-16 06:47:54 UTC (rev 1949) +++ trunk/FreeOrion/UI/OptionsWnd.cpp 2006-11-18 23:37:17 UTC (rev 1950) @@ -598,6 +598,12 @@ CUIStateButton* fullscreen_button = BoolOption("fullscreen", UserString("OPTIONS_FULLSCREEN")); #ifdef FREEORION_WIN32 GG::Connect(drop_list->SelChangedSignal, ResolutionDropListIndexSetOptionFunctor(drop_list, width_spin, height_spin, color_depth_spin, fullscreen_button)); +#else + // HACK! These lines are only here to quiet "unused variable" warnings. + width_spin = 0; + height_spin = 0; + color_depth_spin = 0; + fullscreen_button = 0; #endif } Modified: trunk/FreeOrion/client/AI/AIClientApp.cpp =================================================================== --- trunk/FreeOrion/client/AI/AIClientApp.cpp 2006-11-16 06:47:54 UTC (rev 1949) +++ trunk/FreeOrion/client/AI/AIClientApp.cpp 2006-11-18 23:37:17 UTC (rev 1950) @@ -182,17 +182,7 @@ { switch (msg.Type()) { case Message::SERVER_STATUS: { - std::stringstream stream(msg.GetText()); - XMLDoc doc; - doc.ReadDoc(stream); - if (doc.root_node.ContainsChild("new_name")) { - m_player_name = doc.root_node.Child("new_name").Text(); - Logger().debugStream() << "AIClientApp::HandleMessageImpl : Received SERVER_STATUS -- server has renamed this player \"" << - m_player_name << "\""; - } else if (doc.root_node.ContainsChild("server_state")) { - Logger().debugStream() << "AIClientApp::HandleMessageImpl : Received SERVER_STATUS (status code " << - doc.root_node.Child("server_state").Attribute("value") << ")"; - } + Logger().debugStream() << "AIClientApp::HandleMessageImpl : Received SERVER_STATUS (status code " << msg.GetText() << ")"; break; } @@ -208,6 +198,13 @@ break; } + case Message::RENAME_PLAYER: { + m_player_name = msg.GetText(); + Logger().debugStream() << "AIClientApp::HandleMessageImpl : Received RENAME_PLAYER -- server has renamed this player \"" << + m_player_name << "\""; + break; + } + case Message::GAME_START: { if (msg.Sender() == -1) { Logger().debugStream() << "AIClientApp::HandleMessageImpl : Received GAME_START message; " Modified: trunk/FreeOrion/client/human/HumanClientApp.cpp =================================================================== --- trunk/FreeOrion/client/human/HumanClientApp.cpp 2006-11-16 06:47:54 UTC (rev 1949) +++ trunk/FreeOrion/client/human/HumanClientApp.cpp 2006-11-18 23:37:17 UTC (rev 1950) @@ -538,28 +538,10 @@ m_handling_message = true; switch (msg.Type()) { case Message::SERVER_STATUS: { - std::stringstream stream(msg.GetText()); - XMLDoc doc; - doc.ReadDoc(stream); - if (doc.root_node.ContainsChild("new_name")) { - m_player_name = doc.root_node.Child("new_name").Text(); - Logger().debugStream() << "HumanClientApp::HandleMessageImpl : Received SERVER_STATUS -- Server has renamed this player \"" << - m_player_name << "\""; - } else if (doc.root_node.ContainsChild("server_state")) { - ServerState server_state = ServerState(boost::lexical_cast<int>(doc.root_node.Child("server_state").Attribute("value"))); - Logger().debugStream() << "HumanClientApp::HandleMessageImpl : Received SERVER_STATUS (status code " << - doc.root_node.Child("server_state").Attribute("value") << ")"; - if (server_state == SERVER_DYING) - KillServer(); - } else if (doc.root_node.ContainsChild("settings_files")) { - std::string settings_files = doc.root_node.Child("settings_files").Text(); - std::string source_files = doc.root_node.Child("source_files").Text(); - Logger().debugStream() << "HumanClientApp::HandleMessageImpl : Received SERVER_STATUS -- Connection rejected by server, " - "because different versions of the following settings and/or source files are in use by the client and the server: " << - settings_files << " " << source_files; - ClientUI::MessageBox(UserString("ERR_VERSION_MISMATCH") + settings_files + " " + source_files, true); - EndGame(); - } + ServerState server_state = boost::lexical_cast<ServerState>(msg.GetText()); + Logger().debugStream() << "HumanClientApp::HandleMessageImpl : Received SERVER_STATUS (status code " << msg.GetText() << ")"; + if (server_state == SERVER_DYING) + KillServer(); break; } @@ -583,6 +565,13 @@ break; } + case Message::RENAME_PLAYER: { + m_player_name = msg.GetText(); + Logger().debugStream() << "HumanClientApp::HandleMessageImpl : Received RENAME_PLAYER -- Server has renamed this player \"" << + m_player_name << "\""; + break; + } + case Message::GAME_START: { if (msg.Sender() == -1) { Logger().debugStream() << "HumanClientApp::HandleMessageImpl : Received GAME_START message; " @@ -673,7 +662,7 @@ empire_id = boost::lexical_cast<int>(doc.root_node.Child("empire_id").Attribute("value")); // given IDs, build message - if (phase_id == Message::FLEET_MOVEMENT) + if (phase_id ==Message:: FLEET_MOVEMENT) phase_str = UserString("TURN_PROGRESS_PHASE_FLEET_MOVEMENT"); else if (phase_id == Message::COMBAT) phase_str = UserString("TURN_PROGRESS_PHASE_COMBAT"); @@ -703,7 +692,7 @@ } case Message::PLAYER_ELIMINATED: { - Logger().debugStream() << "HumanClientApp::HandleMessageImpl : Message::PLAYER_ELIMINATED : m_empire_id=" << m_empire_id << " Empires().Lookup(m_empire_id)=" << Empires().Lookup(m_empire_id); + Logger().debugStream() << "HumanClientApp::HandleMessageImpl : PLAYER_ELIMINATED : m_empire_id=" << m_empire_id << " Empires().Lookup(m_empire_id)=" << Empires().Lookup(m_empire_id); Empire* empire = Empires().Lookup(m_empire_id); if (!empire) break; if (empire->Name() == msg.GetText()) { Modified: trunk/FreeOrion/network/ClientNetworkCore.cpp =================================================================== --- trunk/FreeOrion/network/ClientNetworkCore.cpp 2006-11-16 06:47:54 UTC (rev 1949) +++ trunk/FreeOrion/network/ClientNetworkCore.cpp 2006-11-18 23:37:17 UTC (rev 1950) @@ -245,14 +245,6 @@ #endif break; - case Message::CLIENT_UNIVERSE_MODULE: - //ClientApp::ClientUniverse().HandleMessage(msg); - break; - - case Message::CLIENT_EMPIRE_MODULE: - //ClientApp::ClientEmpire().HandleMessage(msg); - break; - case Message::CLIENT_COMBAT_MODULE: if (ClientApp::GetApp()->CurrentCombat()) { //ClientApp::CombatModule().HandleMessage(msg); Modified: trunk/FreeOrion/network/Message.cpp =================================================================== --- trunk/FreeOrion/network/Message.cpp 2006-11-16 06:47:54 UTC (rev 1949) +++ trunk/FreeOrion/network/Message.cpp 2006-11-18 23:37:17 UTC (rev 1950) @@ -89,8 +89,6 @@ GG_ENUM_MAP_BEGIN(Message::ModuleType) GG_ENUM_MAP_INSERT(Message::CORE) GG_ENUM_MAP_INSERT(Message::CLIENT_LOBBY_MODULE) - GG_ENUM_MAP_INSERT(Message::CLIENT_UNIVERSE_MODULE) - GG_ENUM_MAP_INSERT(Message::CLIENT_EMPIRE_MODULE) GG_ENUM_MAP_INSERT(Message::CLIENT_COMBAT_MODULE) GG_ENUM_MAP_INSERT(Message::CLIENT_SYNCHRONOUS_RESPONSE) GG_ENUM_MAP_END @@ -319,9 +317,7 @@ Message RenameMessage(int player_id, const std::string& new_name) { - XMLDoc doc; - doc.root_node.AppendChild(XMLElement("new_name", new_name)); - return Message(Message::SERVER_STATUS, -1, player_id, Message::CORE, doc); + return Message(Message::RENAME_PLAYER, -1, player_id, Message::CORE, new_name); } Message EndGameMessage(int sender, int receiver) Modified: trunk/FreeOrion/network/Message.h =================================================================== --- trunk/FreeOrion/network/Message.h 2006-11-16 06:47:54 UTC (rev 1949) +++ trunk/FreeOrion/network/Message.h 2006-11-18 23:37:17 UTC (rev 1950) @@ -37,6 +37,7 @@ SERVER_STATUS, ///< sent to the client when requested, and when the server first recieves a connection from a client HOST_GAME, ///< sent when a client wishes to establish a game at the server JOIN_GAME, ///< sent when a client wishes to join a game being established at the server + RENAME_PLAYER, ///< sent when the server must assign a new name to a player, because another player already has her desired name LOBBY_UPDATE, ///< used to synchronize multiplayer lobby dialogs among different players, when a user changes a setting, or the server updates the state LOBBY_CHAT, ///< used to send chat messages in the multiplayer lobby LOBBY_HOST_ABORT, ///< sent to server (by the "host" client only) when a multiplayer game is to be cancelled while it is still being set up in the multiplayer lobby @@ -58,13 +59,11 @@ DISPATCH_NEW_OBJECT_ID, ///< sent by server to client with the new object ID. END_GAME, ///< sent to the server by the host client when the current game is to end }; - + /** Represents the module which is the destination for the message */ enum ModuleType { CORE, ///< this module is the ServerCore or ClientCore, as appropriate; all server-bound messages go here CLIENT_LOBBY_MODULE, ///< the human-only multiplayer lobby dialog - CLIENT_UNIVERSE_MODULE, ///< the ClientUniverse module - CLIENT_EMPIRE_MODULE, ///< the ClientEmpire module CLIENT_COMBAT_MODULE, ///< the client Combat module CLIENT_SYNCHRONOUS_RESPONSE ///< client-only - the response to a synchronous message }; @@ -154,11 +153,6 @@ /** creates a JOIN_GAME message. Sends an xml document of the player's details.*/ Message JoinGameSetup(const XMLDoc& player_setup); -/** creates a SERVER_STATUS message that indicates that the JOIN_GAME message just received from the client will - not be honored because the client and server are using different versions of code or essential configuration - files. This message should only be sent by the server.*/ -Message VersionConflictMessage(int player_id, const XMLDoc& conflict_details); - /** creates a GAME_START message. Contains the initial game state visible to player \a player_id.*/ Message GameStartMessage(int player_id, const std::string& data); @@ -170,8 +164,8 @@ should only be sent by the server.*/ Message JoinAckMessage(int player_id); -/** creates a SERVER_STATUS message that renames a player that has just joined a game with a name already in use. - The \a player_id is the ID of the receiving player. This message should only be sent by the server.*/ +/** creates a RENAME_PLAYER message that renames a player that has just joined a game with a name already in use. The + \a player_id is the ID of the receiving player. This message should only be sent by the server.*/ Message RenameMessage(int player_id, const std::string& new_name); /** creates an END_GAME message used to terminate an active game. Only END_GAME messages sent from the host client Modified: trunk/FreeOrion/network/NetworkCore.h =================================================================== --- trunk/FreeOrion/network/NetworkCore.h 2006-11-16 06:47:54 UTC (rev 1949) +++ trunk/FreeOrion/network/NetworkCore.h 2006-11-18 23:37:17 UTC (rev 1950) @@ -12,6 +12,8 @@ #include <GG/net/net2.h> #endif +#include <GG/Enum.h> + // deal with dirty, dirty MS macros #if defined(_MSC_VER) # if defined(SendMessage) @@ -84,5 +86,19 @@ net/net2 involves hostname resolution.*/ std::string ToString(const IPaddress& addr); +namespace GG { + GG_ENUM_MAP_BEGIN(ServerState) + GG_ENUM_MAP_INSERT(SERVER_IDLE) + GG_ENUM_MAP_INSERT(SERVER_MP_LOBBY) + GG_ENUM_MAP_INSERT(SERVER_GAME_SETUP) + GG_ENUM_MAP_INSERT(SERVER_WAITING) + GG_ENUM_MAP_INSERT(SERVER_PROCESSING) + GG_ENUM_MAP_INSERT(SERVER_DISCONNECT) + GG_ENUM_MAP_INSERT(SERVER_DYING) + GG_ENUM_MAP_END +} +GG_ENUM_STREAM_IN(ServerState) +GG_ENUM_STREAM_OUT(ServerState) + #endif // _NetworkCore_h_ Modified: trunk/FreeOrion/network/ServerNetworkCore.cpp =================================================================== --- trunk/FreeOrion/network/ServerNetworkCore.cpp 2006-11-16 06:47:54 UTC (rev 1949) +++ trunk/FreeOrion/network/ServerNetworkCore.cpp 2006-11-18 23:37:17 UTC (rev 1950) @@ -194,7 +194,7 @@ m_new_connections.push_back(PlayerInfo(socket, *addr)); ServerApp::GetApp()->Logger().debugStream() << "ServerNetworkCore::HandleNetEvent : Now connected to client at " << (socket_hostname ? socket_hostname : "[unknown host]") << ", on socket " << socket << "."; - SendMessage(Message(Message::SERVER_STATUS, -1, -1, Message::CORE, ServerApp::GetApp()->ServerStatusDoc()), + SendMessage(Message(Message::RENAME_PLAYER, -1, -1, Message::CORE, boost::lexical_cast<std::string>(ServerApp::GetApp()->State())), socket, "ServerNetworkCore"); } else { // oops. unknown port ServerApp::GetApp()->Logger().error("ServerNetworkCore::HandleNetEvent : Somehow we accepted a TCP connection " Modified: trunk/FreeOrion/server/ServerApp.cpp =================================================================== --- trunk/FreeOrion/server/ServerApp.cpp 2006-11-16 06:47:54 UTC (rev 1949) +++ trunk/FreeOrion/server/ServerApp.cpp 2006-11-18 23:37:17 UTC (rev 1950) @@ -154,15 +154,6 @@ log4cpp::Category::shutdown(); } -XMLDoc ServerApp::ServerStatusDoc() const -{ - XMLDoc retval; - XMLElement elem("server_state"); - elem.SetAttribute("value", boost::lexical_cast<std::string>(m_state)); - retval.root_node.AppendChild(elem); - return retval; -} - void ServerApp::operator()() { Run(); @@ -382,7 +373,6 @@ case Message::SAVE_GAME: { if (m_network_core.Players().find(msg.Sender()) != m_network_core.Players().end()) { std::string save_filename = msg.GetText(); - XMLDoc doc; // send out all save game data requests std::set<int> needed_reponses; @@ -572,7 +562,7 @@ } m_state = SERVER_DYING; m_log_category.debugStream() << "ServerApp::HandleMessage : Server now in mode " << SERVER_DYING << " (SERVER_DYING)."; - m_network_core.SendMessage(Message(Message::SERVER_STATUS, -1, msg.Sender(), Message::CORE, ServerStatusDoc())); + m_network_core.SendMessage(Message(Message::SERVER_STATUS, -1, msg.Sender(), Message::CORE, boost::lexical_cast<std::string>(m_state))); m_network_core.DumpAllConnections(); Exit(0); } Modified: trunk/FreeOrion/server/ServerApp.h =================================================================== --- trunk/FreeOrion/server/ServerApp.h 2006-11-16 06:47:54 UTC (rev 1949) +++ trunk/FreeOrion/server/ServerApp.h 2006-11-18 23:37:17 UTC (rev 1950) @@ -67,7 +67,6 @@ /** \name Accessors */ //@{ ServerState State() const {return m_state;} ///< returns the current state of the server (one of the ServerState enum values) - XMLDoc ServerStatusDoc() const; ///< returns an XMLDoc that represents the status of the server, suitable for transmission to a client int CurrentTurn() const {return m_current_turn;} ///< returns current turn of the server //@} |
From: <tz...@us...> - 2006-11-22 03:10:41
|
Revision: 1952 http://svn.sourceforge.net/freeorion/revision/?rev=1952&view=rev Author: tzlaine Date: 2006-11-21 19:10:41 -0800 (Tue, 21 Nov 2006) Log Message: ----------- Converted JOIN_GAME messages from XML to plain text. Modified Paths: -------------- trunk/FreeOrion/network/Message.cpp trunk/FreeOrion/network/Message.h trunk/FreeOrion/server/ServerApp.cpp Modified: trunk/FreeOrion/network/Message.cpp =================================================================== --- trunk/FreeOrion/network/Message.cpp 2006-11-22 02:57:40 UTC (rev 1951) +++ trunk/FreeOrion/network/Message.cpp 2006-11-22 03:10:41 UTC (rev 1952) @@ -122,7 +122,7 @@ << msg.Sender(); if (msg.Sender() == -1) - os << "(server) --> "; + os << "(server/unknown) --> "; else if (msg.Sender() == 0) os << "(host) --> "; else @@ -131,7 +131,7 @@ os << msg.Receiver(); if (msg.Receiver() == -1) - os << "(server)."; + os << "(server/unknown)."; else if (msg.Receiver() == 0) os << "(host)."; else @@ -269,9 +269,8 @@ //////////////////////////////////////////////// // Message-Creation Free Functions //////////////////////////////////////////////// -Message HostGameMessage(int player_id, const XMLDoc& game_parameters) +Message HostGameMessage(int player_id, const XMLDoc& doc) { - XMLDoc doc(game_parameters); return Message(Message::HOST_GAME, player_id, -1, Message::CORE, doc); } @@ -284,22 +283,14 @@ Message JoinGameMessage(const std::string& player_name) { - XMLDoc doc; - doc.root_node.AppendChild(XMLElement("player_name", player_name)); - return Message(Message::JOIN_GAME, -1, -1, Message::CORE, doc); + return Message(Message::JOIN_GAME, -1, -1, Message::CORE, player_name); } -Message JoinGameSetup(const XMLDoc& player_setup) +Message JoinGameSetup(const XMLDoc& doc) { - XMLDoc doc(player_setup); return Message(Message::JOIN_GAME, -1, -1, Message::CORE, doc); } -Message VersionConflictMessage(int player_id, const XMLDoc& conflict_details) -{ - return Message(Message::SERVER_STATUS, -1, player_id, Message::CORE, conflict_details); -} - Message GameStartMessage(int player_id, const std::string& data) { return Message(Message::GAME_START, -1, player_id, Message::CORE, data); Modified: trunk/FreeOrion/network/Message.h =================================================================== --- trunk/FreeOrion/network/Message.h 2006-11-22 02:57:40 UTC (rev 1951) +++ trunk/FreeOrion/network/Message.h 2006-11-22 03:10:41 UTC (rev 1952) @@ -142,7 +142,7 @@ /** creates a HOST_GAME message*/ -Message HostGameMessage(int player_id, const XMLDoc& game_parameters); +Message HostGameMessage(int player_id, const XMLDoc& doc); /** creates a minimal HOST_GAME message used to enter and finalize the multiplayer "lobby" setup*/ Message HostGameMessage(int player_id, const std::string& host_player_name); @@ -151,7 +151,7 @@ Message JoinGameMessage(const std::string& player_name); /** creates a JOIN_GAME message. Sends an xml document of the player's details.*/ -Message JoinGameSetup(const XMLDoc& player_setup); +Message JoinGameSetup(const XMLDoc& doc); /** creates a GAME_START message. Contains the initial game state visible to player \a player_id.*/ Message GameStartMessage(int player_id, const std::string& data); Modified: trunk/FreeOrion/server/ServerApp.cpp =================================================================== --- trunk/FreeOrion/server/ServerApp.cpp 2006-11-22 02:57:40 UTC (rev 1951) +++ trunk/FreeOrion/server/ServerApp.cpp 2006-11-22 03:10:41 UTC (rev 1952) @@ -641,10 +641,7 @@ } case Message::JOIN_GAME: { - std::stringstream stream(msg.GetText()); - XMLDoc doc; - doc.ReadDoc(stream); - std::string player_name = doc.root_node.Child("player_name").Text(); + std::string player_name = msg.GetText(); PlayerInfo player_info(connection.socket, connection.address, player_name, false); int player_id = std::max(NetworkCore::HOST_PLAYER_ID + 1, static_cast<int>(m_network_core.Players().size())); |
From: <tz...@us...> - 2006-11-22 05:25:25
|
Revision: 1954 http://svn.sourceforge.net/freeorion/revision/?rev=1954&view=rev Author: tzlaine Date: 2006-11-21 21:25:25 -0800 (Tue, 21 Nov 2006) Log Message: ----------- Completed the last of the XML to Boost.Serialization conversion, except for the combat messages. Those will be eliminated when combat is implemented. Modified Paths: -------------- trunk/FreeOrion/UI/ClientUI.h trunk/FreeOrion/UI/GalaxySetupWnd.cpp trunk/FreeOrion/UI/GalaxySetupWnd.h trunk/FreeOrion/UI/IntroScreen.cpp trunk/FreeOrion/UI/MultiplayerLobbyWnd.cpp trunk/FreeOrion/client/human/HumanClientApp.cpp trunk/FreeOrion/network/Message.cpp trunk/FreeOrion/network/Message.h trunk/FreeOrion/server/ServerApp.cpp trunk/FreeOrion/server/ServerApp.h trunk/FreeOrion/util/MultiplayerCommon.cpp trunk/FreeOrion/util/MultiplayerCommon.h Modified: trunk/FreeOrion/UI/ClientUI.h =================================================================== --- trunk/FreeOrion/UI/ClientUI.h 2006-11-22 03:56:47 UTC (rev 1953) +++ trunk/FreeOrion/UI/ClientUI.h 2006-11-22 05:25:25 UTC (rev 1954) @@ -42,7 +42,7 @@ //! \brief ClientUI Main Module //!This is the main class of the ClientUI module. //!it contains objects of many other classes and controls the -//!display of all information oTURN_PROGRESS_WND_COLORnscreen. +//!display of all information onscreen. class ClientUI { public: Modified: trunk/FreeOrion/UI/GalaxySetupWnd.cpp =================================================================== --- trunk/FreeOrion/UI/GalaxySetupWnd.cpp 2006-11-22 03:56:47 UTC (rev 1953) +++ trunk/FreeOrion/UI/GalaxySetupWnd.cpp 2006-11-22 05:25:25 UTC (rev 1954) @@ -154,24 +154,24 @@ } } -void GalaxySetupPanel::SetFromLobbyData(const MultiplayerLobbyData& lobby_data) +void GalaxySetupPanel::SetFromSetupData(const GalaxySetupData& setup_data) { - m_stars_spin->SetValue(lobby_data.m_size); - m_galaxy_shapes_list->Select(lobby_data.m_shape); - m_galaxy_ages_list->Select(lobby_data.m_age); - m_starlane_freq_list->Select(lobby_data.m_starlane_freq - (ALLOW_NO_STARLANES ? 0 : 1)); - m_planet_density_list->Select(lobby_data.m_planet_density); - m_specials_freq_list->Select(lobby_data.m_specials_freq); + m_stars_spin->SetValue(setup_data.m_size); + m_galaxy_shapes_list->Select(setup_data.m_shape); + m_galaxy_ages_list->Select(setup_data.m_age); + m_starlane_freq_list->Select(setup_data.m_starlane_freq - (ALLOW_NO_STARLANES ? 0 : 1)); + m_planet_density_list->Select(setup_data.m_planet_density); + m_specials_freq_list->Select(setup_data.m_specials_freq); } -void GalaxySetupPanel::GetLobbyData(MultiplayerLobbyData& lobby_data) +void GalaxySetupPanel::GetSetupData(GalaxySetupData& setup_data) const { - lobby_data.m_size = Systems(); - lobby_data.m_shape = GetShape(); - lobby_data.m_age = GetAge(); - lobby_data.m_starlane_freq = GetStarlaneFrequency(); - lobby_data.m_planet_density = GetPlanetDensity(); - lobby_data.m_specials_freq = GetSpecialsFrequency(); + setup_data.m_size = Systems(); + setup_data.m_shape = GetShape(); + setup_data.m_age = GetAge(); + setup_data.m_starlane_freq = GetStarlaneFrequency(); + setup_data.m_planet_density = GetPlanetDensity(); + setup_data.m_specials_freq = GetSpecialsFrequency(); } void GalaxySetupPanel::Init() Modified: trunk/FreeOrion/UI/GalaxySetupWnd.h =================================================================== --- trunk/FreeOrion/UI/GalaxySetupWnd.h 2006-11-22 03:56:47 UTC (rev 1953) +++ trunk/FreeOrion/UI/GalaxySetupWnd.h 2006-11-22 05:25:25 UTC (rev 1954) @@ -67,8 +67,8 @@ virtual void Render() {} virtual void Disable(bool b = true); - void SetFromLobbyData(const MultiplayerLobbyData& lobby_data); ///< sets the controls from a MultiplayerLobbyData - void GetLobbyData(MultiplayerLobbyData& lobby_data); ///< fills values in \a lobby_data from the panel's current state + void SetFromSetupData(const GalaxySetupData& setup_data); ///< sets the controls from a GalaxySetupData + void GetSetupData(GalaxySetupData& setup_data) const; ///< fills values in \a setup_data from the panel's current state //!@} private: Modified: trunk/FreeOrion/UI/IntroScreen.cpp =================================================================== --- trunk/FreeOrion/UI/IntroScreen.cpp 2006-11-22 03:56:47 UTC (rev 1953) +++ trunk/FreeOrion/UI/IntroScreen.cpp 2006-11-22 05:25:25 UTC (rev 1954) @@ -14,6 +14,7 @@ #include "OptionsWnd.h" #include "../util/OptionsDB.h" #include "Splash.h" +#include "../util/Serialize.h" #include "ServerConnectWnd.h" #include "../util/Version.h" @@ -201,21 +202,6 @@ GalaxySetupWnd galaxy_wnd; galaxy_wnd.Run(); if (galaxy_wnd.EndedWithOk()) { - // TODO: Select number and difficulty of AIs - string player_name = "Happy_Player"; - int num_AIs = 4; - - XMLDoc game_parameters; - game_parameters.root_node.AppendChild(XMLElement("host_player_name", player_name)); - game_parameters.root_node.AppendChild(XMLElement("num_players", lexical_cast<string>(num_AIs + 1))); - game_parameters.root_node.AppendChild(galaxy_wnd.Panel().XMLEncode()); - game_parameters.root_node.AppendChild(XMLElement("empire_name", galaxy_wnd.EmpireName())); - game_parameters.root_node.AppendChild(XMLElement("empire_color", ClrToXML(galaxy_wnd.EmpireColor()))); - - for (int i = 0; i < num_AIs; ++i) { - game_parameters.root_node.AppendChild(XMLElement("AI_client")); - } - int start_time = GG::GUI::GetGUI()->Ticks(); while (!HumanClientApp::GetApp()->NetworkCore().ConnectToLocalhostServer()) { if (SERVER_CONNECT_TIMEOUT < GG::GUI::GetGUI()->Ticks() - start_time) { @@ -229,7 +215,20 @@ if (!failed) { ClientUI::GetClientUI()->ScreenNewGame(); - HumanClientApp::GetApp()->NetworkCore().SendMessage(HostSPGameMessage(HumanClientApp::GetApp()->PlayerID(), game_parameters)); + + // TODO: Select number and difficulty of AIs + SinglePlayerSetupData setup_data; + galaxy_wnd.Panel().GetSetupData(setup_data); + setup_data.m_host_player_name = "Happy_Player"; + setup_data.m_empire_name = galaxy_wnd.EmpireName(); + setup_data.m_empire_color = galaxy_wnd.EmpireColor(); + setup_data.m_AIs = 4; + std::ostringstream os; + { + boost::archive::xml_oarchive oa(os); + oa << BOOST_SERIALIZATION_NVP(setup_data); + } + HumanClientApp::GetApp()->NetworkCore().SendMessage(HostSPGameMessage(HumanClientApp::GetApp()->PlayerID(), os.str())); } } else { failed = true; Modified: trunk/FreeOrion/UI/MultiplayerLobbyWnd.cpp =================================================================== --- trunk/FreeOrion/UI/MultiplayerLobbyWnd.cpp 2006-11-22 03:56:47 UTC (rev 1953) +++ trunk/FreeOrion/UI/MultiplayerLobbyWnd.cpp 2006-11-22 05:25:25 UTC (rev 1954) @@ -264,7 +264,7 @@ m_lobby_data = mp_lobby_data; m_new_load_game_buttons->SetCheck(!mp_lobby_data.m_new_game); - m_galaxy_setup_panel->SetFromLobbyData(mp_lobby_data); + m_galaxy_setup_panel->SetFromSetupData(mp_lobby_data); m_saved_games_list->Clear(); for (unsigned int i = 0; i < mp_lobby_data.m_save_games.size(); ++i) { @@ -380,7 +380,7 @@ void MultiplayerLobbyWnd::GalaxySetupPanelChanged() { - m_galaxy_setup_panel->GetLobbyData(m_lobby_data); + m_galaxy_setup_panel->GetSetupData(m_lobby_data); SendUpdate(); } Modified: trunk/FreeOrion/client/human/HumanClientApp.cpp =================================================================== --- trunk/FreeOrion/client/human/HumanClientApp.cpp 2006-11-22 03:56:47 UTC (rev 1953) +++ trunk/FreeOrion/client/human/HumanClientApp.cpp 2006-11-22 05:25:25 UTC (rev 1954) @@ -649,19 +649,18 @@ } case Message::TURN_PROGRESS: { - XMLDoc doc; - int phase_id; + std::istringstream is(msg.GetText()); + Message::TurnProgressPhase phase_id; int empire_id; - std::string phase_str; - std::stringstream stream(msg.GetText()); + { + boost::archive::xml_iarchive ia(is); + ia >> BOOST_SERIALIZATION_NVP(phase_id) + >> BOOST_SERIALIZATION_NVP(empire_id); + } - doc.ReadDoc(stream); - - phase_id = boost::lexical_cast<int>(doc.root_node.Child("phase_id").Attribute("value")); - empire_id = boost::lexical_cast<int>(doc.root_node.Child("empire_id").Attribute("value")); - // given IDs, build message - if (phase_id ==Message:: FLEET_MOVEMENT) + std::string phase_str; + if (phase_id == Message::FLEET_MOVEMENT) phase_str = UserString("TURN_PROGRESS_PHASE_FLEET_MOVEMENT"); else if (phase_id == Message::COMBAT) phase_str = UserString("TURN_PROGRESS_PHASE_COMBAT"); @@ -674,13 +673,13 @@ else if (phase_id == Message::DOWNLOADING) phase_str = UserString("TURN_PROGRESS_PHASE_DOWNLOADING"); - m_ui->UpdateTurnProgress( phase_str, empire_id); + m_ui->UpdateTurnProgress(phase_str, empire_id); break; } case Message::COMBAT_START: case Message::COMBAT_ROUND_UPDATE: - case Message::COMBAT_END:{ + case Message::COMBAT_END: { m_ui->UpdateCombatTurnProgress(msg.GetText()); break; } Modified: trunk/FreeOrion/network/Message.cpp =================================================================== --- trunk/FreeOrion/network/Message.cpp 2006-11-22 03:56:47 UTC (rev 1953) +++ trunk/FreeOrion/network/Message.cpp 2006-11-22 05:25:25 UTC (rev 1954) @@ -2,6 +2,7 @@ #include "../util/MultiplayerCommon.h" #include "../util/OptionsDB.h" +#include "../util/Serialize.h" #include <boost/lexical_cast.hpp> #include <boost/algorithm/string/erase.hpp> @@ -271,9 +272,9 @@ //////////////////////////////////////////////// // Message-Creation Free Functions //////////////////////////////////////////////// -Message HostSPGameMessage(int player_id, const XMLDoc& doc) +Message HostSPGameMessage(int player_id, const std::string& data) { - return Message(Message::HOST_SP_GAME, player_id, -1, Message::CORE, doc); + return Message(Message::HOST_SP_GAME, player_id, -1, Message::CORE, data); } Message HostMPGameMessage(int player_id, const std::string& host_player_name) @@ -286,11 +287,6 @@ return Message(Message::JOIN_GAME, -1, -1, Message::CORE, player_name); } -Message JoinGameSetup(const XMLDoc& doc) -{ - return Message(Message::JOIN_GAME, -1, -1, Message::CORE, doc); -} - Message GameStartMessage(int player_id, const std::string& data) { return Message(Message::GAME_START, -1, player_id, Message::CORE, data); @@ -333,18 +329,13 @@ Message TurnProgressMessage(int player_id, Message::TurnProgressPhase phase_id, int empire_id) { - /// Turn progress message sends down message ID instead of text for faster transfer - /// The data is a number indicating the phase being started and the empire ID - XMLDoc doc; - - XMLElement phase_id_elt("phase_id"); - phase_id_elt.SetAttribute("value", boost::lexical_cast<std::string>(phase_id)); - doc.root_node.AppendChild( phase_id_elt ); - - XMLElement empire_id_elt("empire_id"); - empire_id_elt.SetAttribute("value", boost::lexical_cast<std::string>(empire_id)); - doc.root_node.AppendChild( empire_id_elt ); - return Message(Message::TURN_PROGRESS, -1, player_id, Message::CORE, doc); + std::ostringstream os; + { + boost::archive::xml_oarchive oa(os); + oa << BOOST_SERIALIZATION_NVP(phase_id) + << BOOST_SERIALIZATION_NVP(empire_id); + } + return Message(Message::TURN_PROGRESS, -1, player_id, Message::CORE, os.str()); } Message TurnUpdateMessage(int player_id, const std::string& data) Modified: trunk/FreeOrion/network/Message.h =================================================================== --- trunk/FreeOrion/network/Message.h 2006-11-22 03:56:47 UTC (rev 1953) +++ trunk/FreeOrion/network/Message.h 2006-11-22 05:25:25 UTC (rev 1954) @@ -144,7 +144,7 @@ /** creates a HOST_SP_GAME message*/ -Message HostSPGameMessage(int player_id, const XMLDoc& doc); +Message HostSPGameMessage(int player_id, const std::string& data); /** creates a minimal HOST_MP_GAME message used to initiate multiplayer "lobby" setup*/ Message HostMPGameMessage(int player_id, const std::string& host_player_name); @@ -152,9 +152,6 @@ /** creates a JOIN_GAME message. The sender's player name is sent in the message.*/ Message JoinGameMessage(const std::string& player_name); -/** creates a JOIN_GAME message. Sends an xml document of the player's details.*/ -Message JoinGameSetup(const XMLDoc& doc); - /** creates a GAME_START message. Contains the initial game state visible to player \a player_id.*/ Message GameStartMessage(int player_id, const std::string& data); Modified: trunk/FreeOrion/server/ServerApp.cpp =================================================================== --- trunk/FreeOrion/server/ServerApp.cpp 2006-11-22 03:56:47 UTC (rev 1953) +++ trunk/FreeOrion/server/ServerApp.cpp 2006-11-22 05:25:25 UTC (rev 1954) @@ -199,17 +199,6 @@ } } -void ServerApp::CreateAIClients(const XMLElement& elem) -{ - std::vector<PlayerSetupData> AIs; - for (int i = 0; i < elem.NumChildren(); ++i) { - if (elem.Child(i).Tag() == "AI_client") { - AIs.push_back(PlayerSetupData()); - } - } - CreateAIClients(AIs); -} - void ServerApp::HandleMessage(const Message& msg) { switch (msg.Type()) { @@ -570,30 +559,33 @@ switch (msg.Type()) { case Message::HOST_SP_GAME: { if (m_network_core.Players().empty() && m_expected_ai_players.empty()) { - std::stringstream stream(msg.GetText()); - XMLDoc doc; - doc.ReadDoc(stream); - std::string host_player_name = doc.root_node.Child("host_player_name").Text(); - PlayerInfo host_player_info(connection.socket, connection.address, host_player_name, true); + std::istringstream is(msg.GetText()); + SinglePlayerSetupData setup_data; + { + boost::archive::xml_iarchive ia(is); + ia >> BOOST_SERIALIZATION_NVP(setup_data); + } + + PlayerInfo host_player_info(connection.socket, connection.address, setup_data.m_host_player_name, true); int player_id = NetworkCore::HOST_PLAYER_ID; // immediately start a new game with the given parameters m_single_player_game = true; - m_expected_players = boost::lexical_cast<int>(doc.root_node.Child("num_players").Text()); - m_galaxy_size = boost::lexical_cast<int>(doc.root_node.Child("universe_params").Child("size").Text()); - m_galaxy_shape = boost::lexical_cast<Shape>(doc.root_node.Child("universe_params").Child("shape").Text()); - m_galaxy_age = boost::lexical_cast<Age>(doc.root_node.Child("universe_params").Child("age").Text()); - m_starlane_freq = boost::lexical_cast<StarlaneFrequency>(doc.root_node.Child("universe_params").Child("starlane_freq").Text()); - m_planet_density = boost::lexical_cast<PlanetDensity>(doc.root_node.Child("universe_params").Child("planet_density").Text()); - m_specials_freq = boost::lexical_cast<SpecialsFrequency>(doc.root_node.Child("universe_params").Child("specials_freq").Text()); - CreateAIClients(doc.root_node); + m_expected_players = setup_data.m_AIs + 1; + m_galaxy_size = setup_data.m_size; + m_galaxy_shape = setup_data.m_shape; + m_galaxy_age = setup_data.m_age; + m_starlane_freq = setup_data.m_starlane_freq; + m_planet_density = setup_data.m_planet_density; + m_specials_freq = setup_data.m_specials_freq; + CreateAIClients(std::vector<PlayerSetupData>(setup_data.m_AIs)); m_player_save_game_data.clear(); m_lobby_data.m_players.clear(); m_lobby_data.m_players.push_back(PlayerSetupData()); m_lobby_data.m_players.back().m_player_id = 0; - m_lobby_data.m_players.back().m_player_name = "Happy_Player"; - m_lobby_data.m_players.back().m_empire_name = doc.root_node.Child("empire_name").Text(); - m_lobby_data.m_players.back().m_empire_color = XMLToClr(doc.root_node.Child("empire_color").Child("GG::Clr")); + m_lobby_data.m_players.back().m_player_name = setup_data.m_host_player_name; + m_lobby_data.m_players.back().m_empire_name = setup_data.m_empire_name; + m_lobby_data.m_players.back().m_empire_color = setup_data.m_empire_color; m_state = SERVER_GAME_SETUP; if (m_network_core.EstablishPlayer(connection.socket, player_id, host_player_info)) { m_network_core.SendMessage(HostSPAckMessage(player_id)); Modified: trunk/FreeOrion/server/ServerApp.h =================================================================== --- trunk/FreeOrion/server/ServerApp.h 2006-11-22 03:56:47 UTC (rev 1953) +++ trunk/FreeOrion/server/ServerApp.h 2006-11-22 05:25:25 UTC (rev 1954) @@ -21,8 +21,6 @@ class OrderSet; struct PlayerSetupData; struct SaveGameUIData; -class XMLDoc; -class XMLElement; /** contains the info needed to manage one player, including connection info */ struct PlayerInfo @@ -78,10 +76,6 @@ /** creates an AI client child process for each element of \a AIs*/ void CreateAIClients(const std::vector<PlayerSetupData>& AIs); - /** creates a single AI client child process for each AI_client subelement of \a elem. This function is provided as a convenience - interface to void CreateAIClients(const LobbyModeData& AIs).*/ - void CreateAIClients(const XMLElement& elem); - /** handles an incoming message from the server with the appropriate action or response */ void HandleMessage(const Message& msg); @@ -92,20 +86,20 @@ void PlayerDisconnected(int id); /** Adds an existing empire to turn processing. The position the empire is in the vector is it's position in the turn processing.*/ - void AddEmpireTurn( int empire_id ); + void AddEmpireTurn(int empire_id); /** Removes an empire from turn processing. This is most likely called when an empire is eliminated from the game */ - void RemoveEmpireTurn( int empire_id ); + void RemoveEmpireTurn(int empire_id); /** Adds turn orders for the given empire for the current turn. pOrderSet will be freed when all processing is done for the turn */ - void SetEmpireTurnOrders( int empire_id , OrderSet *pOrderSet ); + void SetEmpireTurnOrders(int empire_id, OrderSet* pOrderSet); /** Determines if all empired have submitted their orders for this turn It will loop the turn squence vector and check for a set pOrderSet. A pOrderSet * of NULL indicates that the empire has not yet submitted their orders for the given turn */ - bool AllOrdersReceived( ); + bool AllOrdersReceived(); /** Processes all empires in the manager in the order that they are added. Will delete all pOrderSets assigned.*/ - void ProcessTurns( ); + void ProcessTurns(); //@} static ServerApp* GetApp(); ///< returns a ClientApp pointer to the singleton instance of the app Modified: trunk/FreeOrion/util/MultiplayerCommon.cpp =================================================================== --- trunk/FreeOrion/util/MultiplayerCommon.cpp 2006-11-22 03:56:47 UTC (rev 1953) +++ trunk/FreeOrion/util/MultiplayerCommon.cpp 2006-11-22 05:25:25 UTC (rev 1954) @@ -127,6 +127,27 @@ ///////////////////////////////////////////////////// +// GalaxySetupData +///////////////////////////////////////////////////// +GalaxySetupData::GalaxySetupData(): + m_size(100), + m_shape(SPIRAL_2), + m_age(AGE_MATURE), + m_starlane_freq(LANES_SEVERAL), + m_planet_density(PD_AVERAGE), + m_specials_freq(SPECIALS_UNCOMMON) +{} + + +///////////////////////////////////////////////////// +// SinglePlayerSetupData +///////////////////////////////////////////////////// +SinglePlayerSetupData::SinglePlayerSetupData(): + m_AIs(0) +{} + + +///////////////////////////////////////////////////// // SaveGameEmpireData ///////////////////////////////////////////////////// SaveGameEmpireData::SaveGameEmpireData(): @@ -153,24 +174,12 @@ MultiplayerLobbyData::MultiplayerLobbyData() : m_new_game(true), - m_size(100), - m_shape(SPIRAL_2), - m_age(AGE_MATURE), - m_starlane_freq(LANES_SEVERAL), - m_planet_density(PD_AVERAGE), - m_specials_freq(SPECIALS_UNCOMMON), m_save_file_index(-1), m_empire_colors(EmpireColors()) {} MultiplayerLobbyData::MultiplayerLobbyData(bool build_save_game_list) : m_new_game(true), - m_size(100), - m_shape(SPIRAL_2), - m_age(AGE_MATURE), - m_starlane_freq(LANES_SEVERAL), - m_planet_density(PD_AVERAGE), - m_specials_freq(SPECIALS_UNCOMMON), m_save_file_index(-1), m_empire_colors(EmpireColors()) { Modified: trunk/FreeOrion/util/MultiplayerCommon.h =================================================================== --- trunk/FreeOrion/util/MultiplayerCommon.h 2006-11-22 03:56:47 UTC (rev 1953) +++ trunk/FreeOrion/util/MultiplayerCommon.h 2006-11-22 05:25:25 UTC (rev 1954) @@ -30,6 +30,44 @@ /** Returns the language of the StringTable currently in use */ const std::string& Language(); +/** The data that represent the galaxy setup for a new game. */ +struct GalaxySetupData +{ + /** \name Structors */ //@{ + GalaxySetupData(); ///< default ctor. + //@} + + int m_size; + Shape m_shape; + Age m_age; + StarlaneFrequency m_starlane_freq; + PlanetDensity m_planet_density; + SpecialsFrequency m_specials_freq; + +private: + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); +}; + +/** The data needed to establish a new single player game. */ +struct SinglePlayerSetupData : public GalaxySetupData +{ + /** \name Structors */ //@{ + SinglePlayerSetupData(); ///< default ctor. + //@} + + std::string m_host_player_name; + std::string m_empire_name; + GG::Clr m_empire_color; + int m_AIs; + +private: + friend class boost::serialization::access; + template <class Archive> + void serialize(Archive& ar, const unsigned int version); +}; + /** Contains the UI data that must be saved in save game files in order to restore games to the users' last views. */ struct SaveGameUIData { @@ -92,7 +130,7 @@ }; /** The data structure that represents the state of the multiplayer lobby. */ -struct MultiplayerLobbyData +struct MultiplayerLobbyData : public GalaxySetupData { /** \name Structors */ //@{ MultiplayerLobbyData(); ///< Default ctor. @@ -104,12 +142,6 @@ //@} bool m_new_game; - int m_size; - Shape m_shape; - Age m_age; - StarlaneFrequency m_starlane_freq; - PlanetDensity m_planet_density; - SpecialsFrequency m_specials_freq; int m_save_file_index; std::vector<PlayerSetupData> m_players; std::vector<PlayerSetupData> m_AIs; @@ -129,6 +161,27 @@ // template implementations template <class Archive> +void GalaxySetupData::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_NVP(m_size) + & BOOST_SERIALIZATION_NVP(m_shape) + & BOOST_SERIALIZATION_NVP(m_age) + & BOOST_SERIALIZATION_NVP(m_starlane_freq) + & BOOST_SERIALIZATION_NVP(m_planet_density) + & BOOST_SERIALIZATION_NVP(m_specials_freq); +} + +template <class Archive> +void SinglePlayerSetupData::serialize(Archive& ar, const unsigned int version) +{ + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(GalaxySetupData) + & BOOST_SERIALIZATION_NVP(m_host_player_name) + & BOOST_SERIALIZATION_NVP(m_empire_name) + & BOOST_SERIALIZATION_NVP(m_empire_color) + & BOOST_SERIALIZATION_NVP(m_AIs); +} + +template <class Archive> void SaveGameUIData::NebulaData::serialize(Archive& ar, const unsigned int version) { ar & BOOST_SERIALIZATION_NVP(filename) @@ -165,13 +218,8 @@ template <class Archive> void MultiplayerLobbyData::serialize(Archive& ar, const unsigned int version) { - ar & BOOST_SERIALIZATION_NVP(m_new_game) - & BOOST_SERIALIZATION_NVP(m_size) - & BOOST_SERIALIZATION_NVP(m_shape) - & BOOST_SERIALIZATION_NVP(m_age) - & BOOST_SERIALIZATION_NVP(m_starlane_freq) - & BOOST_SERIALIZATION_NVP(m_planet_density) - & BOOST_SERIALIZATION_NVP(m_specials_freq) + ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(GalaxySetupData) + & BOOST_SERIALIZATION_NVP(m_new_game) & BOOST_SERIALIZATION_NVP(m_save_file_index) & BOOST_SERIALIZATION_NVP(m_players) // NOTE: We are not serializing the AIs on purpose; they are supposed to be server-side entities only. |
From: <tz...@us...> - 2006-11-28 02:30:46
|
Revision: 1956 http://svn.sourceforge.net/freeorion/revision/?rev=1956&view=rev Author: tzlaine Date: 2006-11-27 18:30:42 -0800 (Mon, 27 Nov 2006) Log Message: ----------- Made several changes to the code to get it to compile and link using MSVC. This included #undef-ing some windows.h macros and moving #includes around a bit. Modified Paths: -------------- trunk/FreeOrion/UI/GalaxySetupWnd.h trunk/FreeOrion/network/ClientNetworkCore.cpp trunk/FreeOrion/network/Message.cpp trunk/FreeOrion/network/Message.h trunk/FreeOrion/server/SaveLoad.cpp trunk/FreeOrion/server/SaveLoad.h trunk/FreeOrion/server/ServerApp.cpp Modified: trunk/FreeOrion/UI/GalaxySetupWnd.h =================================================================== --- trunk/FreeOrion/UI/GalaxySetupWnd.h 2006-11-24 01:39:57 UTC (rev 1955) +++ trunk/FreeOrion/UI/GalaxySetupWnd.h 2006-11-28 02:30:42 UTC (rev 1956) @@ -23,7 +23,7 @@ class CUIButton; class CUIStateButton; class EmpireColorSelector; -class MultiplayerLobbyData; +class GalaxySetupData; /** Encapsulates the galaxy setup options so that they may be reused in the GalaxySetupWnd and the MultiplayerLobbyWnd. */ class GalaxySetupPanel : public GG::Control Modified: trunk/FreeOrion/network/ClientNetworkCore.cpp =================================================================== --- trunk/FreeOrion/network/ClientNetworkCore.cpp 2006-11-24 01:39:57 UTC (rev 1955) +++ trunk/FreeOrion/network/ClientNetworkCore.cpp 2006-11-28 02:30:42 UTC (rev 1956) @@ -14,6 +14,14 @@ #include <sstream> +// Win32 macros strike again +#ifdef SendMessage +#undef SendMessage +#endif +#ifdef DispatchMessage +#undef DispatchMessage +#endif + namespace { const unsigned int SYCHRONOUS_TIMEOUT = 30000; // 30 seconds } Modified: trunk/FreeOrion/network/Message.cpp =================================================================== --- trunk/FreeOrion/network/Message.cpp 2006-11-24 01:39:57 UTC (rev 1955) +++ trunk/FreeOrion/network/Message.cpp 2006-11-28 02:30:42 UTC (rev 1956) @@ -430,7 +430,7 @@ return Message(Message::SAVE_GAME, -1, receiver, done ? Message::CLIENT_SYNCHRONOUS_RESPONSE : Message::CORE, ""); } -Message ServerLoadGameMessage(int receiver, const OrderSet& orders, const boost::shared_ptr<SaveGameUIData>& ui_data) +Message ServerLoadGameMessage(int receiver, const OrderSet& orders, const SaveGameUIData* ui_data) { std::ostringstream os; { Modified: trunk/FreeOrion/network/Message.h =================================================================== --- trunk/FreeOrion/network/Message.h 2006-11-24 01:39:57 UTC (rev 1955) +++ trunk/FreeOrion/network/Message.h 2006-11-28 02:30:42 UTC (rev 1956) @@ -219,7 +219,7 @@ Message ServerSaveGameMessage(int receiver, bool done = false); /** creates a LOAD_GAME data message. This message should only be sent by the server to provide saved game data to a client.*/ -Message ServerLoadGameMessage(int receiver, const OrderSet& orders, const boost::shared_ptr<SaveGameUIData>& ui_data); +Message ServerLoadGameMessage(int receiver, const OrderSet& orders, const SaveGameUIData* ui_data); /** creates a HUMAN_PLAYER_MSG, which is sent to the server, and then from the server to all human players, including the originating player. This is used for MP chat.*/ Modified: trunk/FreeOrion/server/SaveLoad.cpp =================================================================== --- trunk/FreeOrion/server/SaveLoad.cpp 2006-11-24 01:39:57 UTC (rev 1955) +++ trunk/FreeOrion/server/SaveLoad.cpp 2006-11-28 02:30:42 UTC (rev 1956) @@ -1,6 +1,5 @@ #include "SaveLoad.h" -#include "ServerApp.h" #include "../Empire/Empire.h" #include "../Empire/EmpireManager.h" #include "../universe/Building.h" Modified: trunk/FreeOrion/server/SaveLoad.h =================================================================== --- trunk/FreeOrion/server/SaveLoad.h 2006-11-24 01:39:57 UTC (rev 1955) +++ trunk/FreeOrion/server/SaveLoad.h 2006-11-28 02:30:42 UTC (rev 1956) @@ -2,11 +2,10 @@ #ifndef _SaveLoad_h_ #define _SaveLoad_h_ +#include "ServerApp.h" #include "../util/Serialize.h" -class PlayerSaveGameData; - /** Saves the provided data to savefile \a filename. */ void SaveGame(const std::string& filename, int current_turn, const std::vector<PlayerSaveGameData>& player_save_game_data, const Universe& universe); Modified: trunk/FreeOrion/server/ServerApp.cpp =================================================================== --- trunk/FreeOrion/server/ServerApp.cpp 2006-11-24 01:39:57 UTC (rev 1955) +++ trunk/FreeOrion/server/ServerApp.cpp 2006-11-28 02:30:42 UTC (rev 1956) @@ -898,7 +898,7 @@ m_network_core.SendMessage(GameStartMessage(it->first, m_single_player_game, empire_id, m_current_turn, m_empires, m_universe)); // send saved pending orders to player - m_network_core.SendMessage(ServerLoadGameMessage(it->first, *player_data_by_empire[empire_id].m_orders, player_data_by_empire[empire_id].m_ui_data)); + m_network_core.SendMessage(ServerLoadGameMessage(it->first, *player_data_by_empire[empire_id].m_orders, player_data_by_empire[empire_id].m_ui_data.get())); m_turn_sequence[empire_id] = 0; } |
From: <tz...@us...> - 2006-12-01 05:24:05
|
Revision: 1959 http://svn.sourceforge.net/freeorion/revision/?rev=1959&view=rev Author: tzlaine Date: 2006-11-30 21:24:04 -0800 (Thu, 30 Nov 2006) Log Message: ----------- Greatly improved the logic that defines the visible elements of Fleets. Now, fleets' entire routes can be serialized (though only the visible nodes of the routes are actually serialized). Also did a small amount of grooming. Modified Paths: -------------- trunk/FreeOrion/UI/FleetWnd.cpp trunk/FreeOrion/UI/MapWnd.cpp trunk/FreeOrion/default/eng_stringtable.txt trunk/FreeOrion/universe/Fleet.cpp trunk/FreeOrion/universe/Fleet.h trunk/FreeOrion/universe/Universe.cpp trunk/FreeOrion/universe/Universe.h Modified: trunk/FreeOrion/UI/FleetWnd.cpp =================================================================== --- trunk/FreeOrion/UI/FleetWnd.cpp 2006-11-30 04:30:45 UTC (rev 1958) +++ trunk/FreeOrion/UI/FleetWnd.cpp 2006-12-01 05:24:04 UTC (rev 1959) @@ -866,8 +866,10 @@ retval = boost::io::str(boost::format(UserString("FW_FLEET_MOVING_TO")) % (dest->Name().empty() ? UserString("UNKNOWN_SYSTEM") : dest->Name()) % eta.first); if (eta.first != eta.second) retval += "(" + boost::lexical_cast<std::string>(eta.second) + ")"; - } else { - retval = boost::io::str(boost::format(UserString("FW_FLEET_MOVING_TO")) % (dest->Name().empty() ? UserString("UNKNOWN_SYSTEM") : dest->Name()) % UserString("FW_FLEET_ETA_NEVER")); + } else if (eta.first == Fleet::ETA_UNKNOWN) { + retval = boost::io::str(boost::format(UserString("FW_FLEET_MOVING_TO")) % + (dest->Name().empty() ? UserString("UNKNOWN_SYSTEM") : dest->Name()) % + UserString(eta.first == Fleet::ETA_UNKNOWN ? "FW_FLEET_ETA_UNKNOWN" : "FW_FLEET_ETA_NEVER")); } } else if (current) { retval = boost::io::str(boost::format(UserString("FW_FLEET_AT")) % current->Name()); Modified: trunk/FreeOrion/UI/MapWnd.cpp =================================================================== --- trunk/FreeOrion/UI/MapWnd.cpp 2006-11-30 04:30:45 UTC (rev 1958) +++ trunk/FreeOrion/UI/MapWnd.cpp 2006-12-01 05:24:04 UTC (rev 1959) @@ -1154,6 +1154,9 @@ GG::Pt ul = ClientUpperLeft(); for (std::map<Fleet*, MovementLineData>::iterator it = m_fleet_lines.begin(); it != m_fleet_lines.end(); ++it) { + if (it->first->UnknownRoute()) + continue; + // this is obviously less efficient than using GL_LINE_STRIP, but GL_LINE_STRIP sometimes produces nasty artifacts // when the begining of a line segment starts offscreen glBegin(GL_LINES); Modified: trunk/FreeOrion/default/eng_stringtable.txt =================================================================== --- trunk/FreeOrion/default/eng_stringtable.txt 2006-11-30 04:30:45 UTC (rev 1958) +++ trunk/FreeOrion/default/eng_stringtable.txt 2006-12-01 05:24:04 UTC (rev 1959) @@ -1069,6 +1069,9 @@ FW_FLEET_ETA_NEVER Never +FW_FLEET_ETA_UNKNOWN +Unknown + FW_SHIP_CLASS Ship Class Modified: trunk/FreeOrion/universe/Fleet.cpp =================================================================== --- trunk/FreeOrion/universe/Fleet.cpp 2006-11-30 04:30:45 UTC (rev 1958) +++ trunk/FreeOrion/universe/Fleet.cpp 2006-12-01 05:24:04 UTC (rev 1959) @@ -1,6 +1,5 @@ #include "Fleet.h" -#include "System.h" #include "Ship.h" #include "Predicates.h" #include "../util/AppInterface.h" @@ -16,8 +15,15 @@ namespace { const double MAX_SHIP_SPEED = 500.0; // max allowed speed of ship movement + + inline bool SystemNotReachable(System* system) + { return !GetUniverse().SystemReachable(system->ID(), Universe::s_encoding_empire); } } +// static(s) +const int Fleet::ETA_NEVER = -1; +const int Fleet::ETA_UNKNOWN = -2; + Fleet::Fleet() : UniverseObject(), m_moving_to(INVALID_OBJECT_ID), @@ -25,8 +31,7 @@ m_prev_system(INVALID_OBJECT_ID), m_next_system(INVALID_OBJECT_ID), m_travel_distance(0.0) -{ -} +{} Fleet::Fleet(const std::string& name, double x, double y, int owner) : UniverseObject(name, x, y), @@ -35,10 +40,14 @@ m_prev_system(INVALID_OBJECT_ID), m_next_system(INVALID_OBJECT_ID), m_travel_distance(0.0) -{ - AddOwner(owner); -} +{ AddOwner(owner); } +Fleet::const_iterator Fleet::begin() const +{ return m_ships.begin(); } + +Fleet::const_iterator Fleet::end() const +{ return m_ships.end(); } + UniverseObject::Visibility Fleet::GetVisibility(int empire_id) const { if (Universe::ALL_OBJECTS_VISIBLE || empire_id == ALL_EMPIRES || OwnedBy(empire_id)) { @@ -80,34 +89,48 @@ std::pair<int, int> Fleet::ETA() const { std::pair<int, int> retval; - CalculateRoute(); - if (m_speed > 0.0) { - retval.first = static_cast<int>(std::ceil(m_travel_distance / m_speed)); - - if (!m_travel_route.empty()) { - std::list<System*>::iterator next_system_it = m_travel_route.begin(); - if (SystemID() == m_travel_route.front()->ID()) - ++next_system_it; - System* next = *next_system_it; - if (next == m_travel_route.back()) { - retval.second = retval.first; - } else { - double x = next->X() - X(); - double y = next->Y() - Y(); - retval.second = static_cast<int>(std::ceil(std::sqrt(x * x + y * y) / m_speed)); + if (UnknownRoute()) { + retval.first = ETA_UNKNOWN; + } else { + CalculateRoute(); + if (m_speed > 0.0) { + retval.first = static_cast<int>(std::ceil(m_travel_distance / m_speed)); + + if (!m_travel_route.empty()) { + std::list<System*>::iterator next_system_it = m_travel_route.begin(); + if (SystemID() == m_travel_route.front()->ID()) + ++next_system_it; + System* next = *next_system_it; + if (next == m_travel_route.back()) { + retval.second = retval.first; + } else { + double x = next->X() - X(); + double y = next->Y() - Y(); + retval.second = static_cast<int>(std::ceil(std::sqrt(x * x + y * y) / m_speed)); + } } + } else { + retval.first = ETA_NEVER; } - } else { - retval.first = -1; // sentinel indiates ETA of never } return retval; } +int Fleet::FinalDestinationID() const +{ return m_moving_to; } + System* Fleet::FinalDestination() const -{ - return GetUniverse().Object<System>(m_moving_to); -} +{ return GetUniverse().Object<System>(m_moving_to); } +int Fleet::PreviousSystemID() const +{ return m_prev_system; } + +int Fleet::NextSystemID() const +{ return m_next_system; } + +double Fleet::Speed() const +{ return m_speed; } + bool Fleet::CanChangeDirectionEnRoute() const { // TODO: enable this code when technologies or other factors to allow a fleet to turn around in mid-flight, without completing its current leg @@ -123,16 +146,26 @@ return false; } +int Fleet::NumShips() const +{ return m_ships.size(); } + +bool Fleet::ContainsShip(int id) const +{ return m_ships.find(id) != m_ships.end(); } + +bool Fleet::UnknownRoute() const +{ return m_travel_route.size() == 1 && m_travel_route.front() == 0; } + UniverseObject* Fleet::Accept(const UniverseObjectVisitor& visitor) const -{ - return visitor.Visit(const_cast<Fleet* const>(this)); -} +{ return visitor.Visit(const_cast<Fleet* const>(this)); } void Fleet::SetRoute(const std::list<System*>& route, double distance) { if (route.empty()) throw std::invalid_argument("Fleet::SetRoute() : Attempted to set an empty route."); + if (UnknownRoute()) + throw std::invalid_argument("Fleet::SetRoute() : Attempted to set an unkown route."); + if (m_prev_system != SystemID() && m_prev_system == route.front()->ID() && !CanChangeDirectionEnRoute()) throw std::invalid_argument("Fleet::SetRoute() : Illegally attempted to change a fleet's direction while it was in transit."); @@ -324,6 +357,12 @@ } } +Fleet::iterator Fleet::begin() +{ return m_ships.begin(); } + +Fleet::iterator Fleet::end() +{ return m_ships.end(); } + void Fleet::PopGrowthProductionResearchPhase() { // ensure that any newly opened or closed routes are taken into account @@ -383,3 +422,21 @@ m_speed = 0.0; } } + +void Fleet::GetVisibleRoute(std::list<System*>& travel_route, int moving_to) +{ + std::list<System*>::iterator visible_end_it; + if (moving_to != m_moving_to) { + System* final_destination = GetUniverse().Object<System>(moving_to); + assert(std::find(m_travel_route.begin(), m_travel_route.end(), final_destination) != m_travel_route.end()); + visible_end_it = ++std::find(m_travel_route.begin(), m_travel_route.end(), final_destination); + } else { + visible_end_it = m_travel_route.end(); + } + std::list<System*>::iterator end_it = std::find_if(m_travel_route.begin(), visible_end_it, boost::bind(&SystemNotReachable, _1)); + std::copy(m_travel_route.begin(), end_it, std::back_inserter(travel_route)); + // If no Systems in a nonempty route are known reachable, put a null pointer in the route as a sentinel indicating + // that the route is unknown, but needs not be recomputed. + if (travel_route.empty() && !m_travel_route.empty()) + travel_route.push_back(0); +} Modified: trunk/FreeOrion/universe/Fleet.h =================================================================== --- trunk/FreeOrion/universe/Fleet.h 2006-11-30 04:30:45 UTC (rev 1958) +++ trunk/FreeOrion/universe/Fleet.h 2006-12-01 05:24:04 UTC (rev 1959) @@ -2,8 +2,8 @@ #ifndef _Fleet_h_ #define _Fleet_h_ -#ifndef _UniverseObject_h_ -#include "UniverseObject.h" +#ifndef _System_h_ +#include "System.h" #endif #include <list> @@ -26,8 +26,8 @@ //@} /** \name Accessors */ //@{ - const_iterator begin() const {return m_ships.begin();} ///< returns the begin const_iterator for the ships in the fleet - const_iterator end() const {return m_ships.end();} ///< returns the end const_iterator for the ships in the fleet + const_iterator begin() const; ///< returns the begin const_iterator for the ships in the fleet + const_iterator end() const; ///< returns the end const_iterator for the ships in the fleet virtual UniverseObject::Visibility GetVisibility(int empire_id) const; virtual const std::string& PublicName(int empire_id) const; @@ -40,19 +40,19 @@ std::pair<int, int> ETA() const; /// Returns ID of system that this fleet is moving to. - int FinalDestinationID() const {return m_moving_to;} + int FinalDestinationID() const; /// Returns system that this fleet is moving to (may be null). System* FinalDestination() const; /// Returns ID of system that this fleet is moving away from as it moves to its destination. - int PreviousSystemID() const {return m_prev_system;} + int PreviousSystemID() const; /// Returns ID of system that this fleet is moving to next as it moves to its destination. - int NextSystemID() const {return m_next_system;} + int NextSystemID() const; /// Returns speed of fleet. (Should be equal to speed of slowest ship in fleet, unless in future the calculation of fleet speed changes.) - double Speed() const {return m_speed;} + double Speed() const; /// Returns true iff this fleet can change its direction while in interstellar space. bool CanChangeDirectionEnRoute() const; @@ -61,11 +61,16 @@ bool HasArmedShips() const; /// Returns number of ships in fleet. - int NumShips() const {return m_ships.size();} + int NumShips() const; /// Returns true iff this Fleet contains a ship with ID \a id. - bool ContainsShip(int id) const {return m_ships.find(id) != m_ships.end();} + bool ContainsShip(int id) const; + /// Returns true iff this fleet is moving, but the route is unknown. This is usually the case when a foreign + /// player A's fleet is represented on another player B's client, and player B has never seen one or more of the + /// systems in the fleet's route. + bool UnknownRoute() const; + virtual UniverseObject* Accept(const UniverseObjectVisitor& visitor) const; //@} @@ -78,16 +83,20 @@ std::vector<int> RemoveShips(const std::vector<int>& ships); ///< removes the ships with the IDs stored in \a ships from the fleet, and returns any IDs not found in the fleet std::vector<int> DeleteShips(const std::vector<int>& ships); ///< removes and deletes the ships with the IDs stored in \a ships from the fleet, and returns any IDs not found in the fleet - iterator begin() {return m_ships.begin();} ///< returns the begin iterator for the ships in the fleet - iterator end() {return m_ships.end();} ///< returns the end iterator for the ships in the fleet + iterator begin(); ///< returns the begin iterator for the ships in the fleet + iterator end(); ///< returns the end iterator for the ships in the fleet virtual void MovementPhase(); virtual void PopGrowthProductionResearchPhase(); //@} + static const int ETA_NEVER; + static const int ETA_UNKNOWN; + private: void CalculateRoute() const; // sets m_travel_route and m_travel_distance to their proper values based on the other member data void RecalculateFleetSpeed(); // recalculates the speed of the fleet by finding the lowest speed of the ships in the fleet. + void GetVisibleRoute(std::list<System*>& travel_route, int moving_to); ShipIDSet m_ships; int m_moving_to; @@ -98,7 +107,7 @@ int m_prev_system; // the next system in the route, if any int m_next_system; // the previous system in the route, if any - mutable std::list<System*> m_travel_route; + mutable std::list<System*> m_travel_route; // Note that this may contain a single null ptr, indicating that the route is unknown, but needs not be recomputed. mutable double m_travel_distance; friend class boost::serialization::access; @@ -106,24 +115,49 @@ void serialize(Archive& ar, const unsigned int version); }; +BOOST_CLASS_VERSION(Fleet, 1) + + // template implementations template <class Archive> void Fleet::serialize(Archive& ar, const unsigned int version) { bool vis; int moving_to; + std::list<System*> travel_route; + double travel_distance; if (Archive::is_saving::value) vis = GetVisibility(Universe::s_encoding_empire); ar & BOOST_SERIALIZATION_BASE_OBJECT_NVP(UniverseObject) & BOOST_SERIALIZATION_NVP(vis); - if (Archive::is_saving::value) - moving_to = vis ? m_moving_to : m_next_system; + if (Archive::is_saving::value) { + moving_to = (Universe::ALL_OBJECTS_VISIBLE || vis == FULL_VISIBILITY) ? m_moving_to : m_next_system; + if (1 <= version) { + GetVisibleRoute(travel_route, moving_to); + travel_distance = m_travel_distance; + if (!travel_route.empty() && travel_route.front() != 0 && travel_route.size() != m_travel_route.size()) { + if (moving_to == m_moving_to) + moving_to = travel_route.back()->ID(); + travel_distance -= GetUniverse().ShortestPath(travel_route.back()->ID(), m_travel_route.back()->ID()).second; + } + } + } ar & BOOST_SERIALIZATION_NVP(m_ships) & BOOST_SERIALIZATION_NVP(moving_to) & BOOST_SERIALIZATION_NVP(m_prev_system) & BOOST_SERIALIZATION_NVP(m_next_system); - if (Archive::is_loading::value) + if (1 <= version) { + ar & BOOST_SERIALIZATION_NVP(m_speed) + & BOOST_SERIALIZATION_NVP(travel_route) + & BOOST_SERIALIZATION_NVP(travel_distance); + } + if (Archive::is_loading::value) { m_moving_to = moving_to; + if (1 <= version) { + std::swap(m_travel_route, travel_route); + m_travel_distance = travel_distance; + } + } if (Universe::ALL_OBJECTS_VISIBLE || vis == FULL_VISIBILITY) ar & BOOST_SERIALIZATION_NVP(m_speed); Modified: trunk/FreeOrion/universe/Universe.cpp =================================================================== --- trunk/FreeOrion/universe/Universe.cpp 2006-11-30 04:30:45 UTC (rev 1958) +++ trunk/FreeOrion/universe/Universe.cpp 2006-12-01 05:24:04 UTC (rev 1959) @@ -127,7 +127,7 @@ if(positions.size()==0) return 0.0; - unsigned int j; + unsigned int j; double lowest_dist= (positions[0].first - position.first ) * (positions[0].first - position.first ) + (positions[0].second - position.second) * (positions[0].second - position.second),distance=0.0; @@ -467,7 +467,7 @@ // templated implementations of Universe graph search methods template <class Graph> - std::pair<std::list<System*>, double> ShortestPathImpl(const Graph& graph, int system1, int system2, int empire_id, double linear_distance) + std::pair<std::list<System*>, double> ShortestPathImpl(const Graph& graph, int system1, int system2, double linear_distance) { typedef typename boost::property_map<Graph, Universe::vertex_system_pointer_t>::const_type ConstSystemPointerPropertyMap; typedef typename boost::property_map<Graph, boost::vertex_index_t>::const_type ConstIndexPropertyMap; @@ -512,12 +512,12 @@ retval.second = linear_distance; } #endif - + return retval; } template <class Graph> - std::pair<std::list<System*>, int> LeastJumpsPathImpl(const Graph& graph, int system1, int system2, int empire_id) + std::pair<std::list<System*>, int> LeastJumpsPathImpl(const Graph& graph, int system1, int system2) { typedef typename boost::property_map<Graph, Universe::vertex_system_pointer_t>::const_type ConstSystemPointerPropertyMap; @@ -553,7 +553,11 @@ } template <class Graph> - std::map<double, System*> ImmediateNeighborsImpl(const Graph& graph, int system, int empire_id) + bool SystemReachableImpl(const Graph& graph, int system) + { return boost::in_degree(system, graph); } + + template <class Graph> + std::map<double, System*> ImmediateNeighborsImpl(const Graph& graph, int system) { typedef typename Graph::out_edge_iterator OutEdgeIterator; typedef typename boost::property_map<Graph, Universe::vertex_system_pointer_t>::const_type ConstSystemPointerPropertyMap; @@ -938,6 +942,18 @@ return retval; } +Universe::iterator Universe::begin() +{ return m_objects.begin(); } + +Universe::iterator Universe::end() +{ return m_objects.end(); } + +Universe::const_iterator Universe::begin() const +{ return m_objects.begin(); } + +Universe::const_iterator Universe::end() const +{ return m_objects.end(); } + const UniverseObject* Universe::DestroyedObject(int id) const { const_iterator it = m_destroyed_objects.find(id); @@ -953,11 +969,11 @@ { double linear_distance = LinearDistance(system1, system2); if (empire_id == ALL_EMPIRES) { - return ShortestPathImpl(m_system_graph, system1, system2, empire_id, linear_distance); + return ShortestPathImpl(m_system_graph, system1, system2, linear_distance); } else { EmpireViewSystemGraphMap::const_iterator graph_it = m_empire_system_graph_views.find(empire_id); if (graph_it != m_empire_system_graph_views.end()) - return ShortestPathImpl(*graph_it->second, system1, system2, empire_id, linear_distance); + return ShortestPathImpl(*graph_it->second, system1, system2, linear_distance); } return std::pair<std::list<System*>, double>(); } @@ -965,24 +981,37 @@ std::pair<std::list<System*>, int> Universe::LeastJumpsPath(int system1, int system2, int empire_id/* = ALL_EMPIRES*/) const { if (empire_id == ALL_EMPIRES) { - return LeastJumpsPathImpl(m_system_graph, system1, system2, empire_id); + return LeastJumpsPathImpl(m_system_graph, system1, system2); } else { EmpireViewSystemGraphMap::const_iterator graph_it = m_empire_system_graph_views.find(empire_id); if (graph_it != m_empire_system_graph_views.end()) - return LeastJumpsPathImpl(*graph_it->second, system1, system2, empire_id); + return LeastJumpsPathImpl(*graph_it->second, system1, system2); } return std::pair<std::list<System*>, int>(); } +bool Universe::SystemReachable(int system, int empire_id) const +{ + m_system_distances.at(system); // for an exception-throwing bounds check + if (empire_id == ALL_EMPIRES) { + return SystemReachableImpl(m_system_graph, system); + } else { + EmpireViewSystemGraphMap::const_iterator graph_it = m_empire_system_graph_views.find(empire_id); + if (graph_it != m_empire_system_graph_views.end()) + return SystemReachableImpl(*graph_it->second, system); + } + return false; +} + std::map<double, System*> Universe::ImmediateNeighbors(int system, int empire_id/* = ALL_EMPIRES*/) const { m_system_distances.at(system); // for an exception-throwing bounds check if (empire_id == ALL_EMPIRES) { - return ImmediateNeighborsImpl(m_system_graph, system, empire_id); + return ImmediateNeighborsImpl(m_system_graph, system); } else { EmpireViewSystemGraphMap::const_iterator graph_it = m_empire_system_graph_views.find(empire_id); if (graph_it != m_empire_system_graph_views.end()) - return ImmediateNeighborsImpl(*graph_it->second, system, empire_id); + return ImmediateNeighborsImpl(*graph_it->second, system); } return std::map<double, System*>(); } @@ -2360,11 +2389,15 @@ #endif } +double Universe::UniverseWidth() +{ return s_universe_width; } + int Universe::GenerateObjectID() -{ - return ++m_last_allocated_id; -} +{ return ++m_last_allocated_id; } +const bool& Universe::InhibitUniverseObjectSignals() +{ return s_inhibit_universe_object_signals; } + void Universe::DestroyImpl(int id) { UniverseObject* obj = Object(id); Modified: trunk/FreeOrion/universe/Universe.h =================================================================== --- trunk/FreeOrion/universe/Universe.h 2006-11-30 04:30:45 UTC (rev 1958) +++ trunk/FreeOrion/universe/Universe.h 2006-12-01 05:24:04 UTC (rev 1959) @@ -122,11 +122,11 @@ /** returns the IDs of all the objects of type T. */ template <class T> ObjectIDVec FindObjectIDs() const; - iterator begin() { return m_objects.begin();} - iterator end() { return m_objects.end();} + iterator begin(); + iterator end(); - const_iterator begin() const {return m_objects.begin();} ///< returns the begin const_iterator for the objects in the universe - const_iterator end() const {return m_objects.end();} ///< returns the end const_iterator for the objects in the universe + const_iterator begin() const; ///< returns the begin const_iterator for the objects in the universe + const_iterator end() const; ///< returns the end const_iterator for the objects in the universe const UniverseObject* DestroyedObject(int id) const; ///< returns a pointer to the destroyed universe object with ID number \a id, or 0 if none exists @@ -151,6 +151,11 @@ ID is out of range. */ std::pair<std::list<System*>, int> LeastJumpsPath(int system1, int system2, int empire_id = ALL_EMPIRES) const; + /** returns true iff \a system is reachable (i.e. it has at least one known starlane to it). The starlanes + considered depend on their visiblity for empire \a empire_id, or without regard to visibility if \a empire_id == + ALL_EMPIRES. \throw std::out_of_range This function will throw if the system ID is out of range. */ + bool SystemReachable(int system, int empire_id = ALL_EMPIRES) const; + /** returns the systems that are one starlane hop away from system \a system. The returned systems are indexed by distance from \a system. The neighborhood is calculated using the visiblity for empire \a empire_id, or without regard to visibility if \a empire_id == ALL_EMPIRES. \throw std::out_of_range This function will throw if the @@ -197,13 +202,13 @@ /** returns the size of the galaxy map. Does not measure absolute distances; the ratio between map coordinates and actual distance varies depending on universe size */ - static double UniverseWidth() {return s_universe_width;} + static double UniverseWidth(); - int GenerateObjectID( ); ///< generates an object ID for a future object. Usually used by the server to service new ID requests + int GenerateObjectID(); ///< generates an object ID for a future object. Usually used by the server to service new ID requests typedef std::vector<std::vector<std::set<System*> > > AdjacencyGrid; - static const bool& InhibitUniverseObjectSignals() {return s_inhibit_universe_object_signals;} + static const bool& InhibitUniverseObjectSignals(); /** HACK! This must be set to the encoding empire's id when serializing a Universe, so that only the relevant parts of the Universe are serialized. The use of this global variable is done just so I don't have to rewrite any |
From: <geo...@us...> - 2006-12-03 03:28:53
|
Revision: 1968 http://svn.sourceforge.net/freeorion/revision/?rev=1968&view=rev Author: geoffthemedio Date: 2006-12-02 19:28:08 -0800 (Sat, 02 Dec 2006) Log Message: ----------- -Some basic AI code: AI fleets explore the galaxy. -Removed some done TODO comments from TechTreeWnd.cpp Modified Paths: -------------- trunk/FreeOrion/UI/TechTreeWnd.cpp trunk/FreeOrion/client/AI/AIClientApp.cpp trunk/FreeOrion/client/AI/AIClientApp.h Modified: trunk/FreeOrion/UI/TechTreeWnd.cpp =================================================================== --- trunk/FreeOrion/UI/TechTreeWnd.cpp 2006-12-03 00:28:45 UTC (rev 1967) +++ trunk/FreeOrion/UI/TechTreeWnd.cpp 2006-12-03 03:28:08 UTC (rev 1968) @@ -26,8 +26,6 @@ // TODO: after v0.3: // - make the category buttons toggle the visibility of each category -// - render an insertion line between queue items when drag-dropping -// - implement zooming (probably just need a zoomed-out version that shows only the tech icons) namespace { // command-line options Modified: trunk/FreeOrion/client/AI/AIClientApp.cpp =================================================================== --- trunk/FreeOrion/client/AI/AIClientApp.cpp 2006-12-03 00:28:45 UTC (rev 1967) +++ trunk/FreeOrion/client/AI/AIClientApp.cpp 2006-12-03 03:28:08 UTC (rev 1968) @@ -15,9 +15,17 @@ #include <log4cpp/PatternLayout.hh> #include <log4cpp/FileAppender.hh> +#include "../../universe/Universe.h" +#include "../../universe/System.h" +#include "../../universe/Fleet.h" +#include "../../universe/Ship.h" +#include "../../universe/ShipDesign.h" +#include "../../util/OrderSet.h" +#include "../../util/Order.h" +#include "../../empire/Empire.h" + #include <boost/filesystem/fstream.hpp> - // static member(s) AIClientApp* AIClientApp::s_app = 0; @@ -51,7 +59,7 @@ m_log_category.setAdditivity(false); // make appender the only appender used... m_log_category.setAppender(appender); m_log_category.setAdditivity(true); // ...but allow the addition of others later - m_log_category.setPriority(PriorityValue(GetOptionsDB().Get<std::string>("log-level"))); + m_log_category.setPriority(log4cpp::Priority::DEBUG); m_log_category.debug(m_player_name + " logger initialized."); } @@ -211,7 +219,22 @@ "starting AI turn..."; bool single_player_game; // note that this is ignored ExtractMessageData(msg, single_player_game, m_empire_id, m_current_turn, Empires(), GetUniverse()); + + Logger().debugStream() << "Got Turn Update message, extracted message data"; + + // ... copied from HumanClientApp.cpp. Not sure if / why it's necessary. + // if this is the last turn, the TCP message handling inherent in Autosave()'s synchronous message may have + // processed an end-of-game message, in which case we need *not* to execute these last two lines below + if (!NetworkCore().Connected()) break; + Logger().debugStream() << "Still connected, starting to generate AI orders"; + + AIGenerateOrders(); + + Logger().debugStream() << "Generated AI Orders, starting turn update"; + StartTurn(); + + Logger().debugStream() << "Done dealing with turn update message"; } break; } @@ -231,7 +254,22 @@ case Message::TURN_UPDATE: { if (msg.Sender() == -1) { ExtractMessageData(msg, m_empire_id, m_current_turn, Empires(), GetUniverse()); + + Logger().debugStream() << "Got Turn Update message, extracted message data"; + + // ... copied from HumanClientApp.cpp. Not sure if / why it's necessary. + // if this is the last turn, the TCP message handling inherent in Autosave()'s synchronous message may have + // processed an end-of-game message, in which case we need *not* to execute these last two lines below + if (!NetworkCore().Connected()) break; + Logger().debugStream() << "Still connected, starting to generate AI orders"; + + AIGenerateOrders(); + + Logger().debugStream() << "Generated AI Orders, starting turn update"; + StartTurn(); + + Logger().debugStream() << "Done dealing with turn update message"; } break; } @@ -261,3 +299,152 @@ ClientApp::StartTurn(); } +void AIClientApp::AIGenerateOrders() +{ + Universe& universe = ClientApp::GetUniverse(); + int empire_id = ClientApp::EmpireID(); + + Fleet* fleet; + + // 1) Split stationary multi-ship fleets into multiple single-ship fleets + Universe::ObjectVec stat_fleets = universe.FindObjects(StationaryFleetVisitor(empire_id)); + Universe::ObjectVec::iterator fleet_it; + + for (fleet_it = stat_fleets.begin(); fleet_it != stat_fleets.end(); ++fleet_it) { + if(!(fleet = dynamic_cast<Fleet*>(*fleet_it))) continue; + + // split fleet into single-ship fleets if it presently has more than one ship + if (fleet->NumShips() > 1) { + SplitFleet(fleet); + } + } + + // 2) Give stationary fleets orders + stat_fleets = universe.FindObjects(StationaryFleetVisitor(empire_id)); // redo to get any newly created fleets from above + + for (fleet_it = stat_fleets.begin(); fleet_it != stat_fleets.end(); ++fleet_it) { + if(!(fleet = dynamic_cast<Fleet*>(*fleet_it))) continue; + + if (fleet->NumShips() < 1) continue; // shouldn't be possible... but to be safe... + + // get ship, design + Ship* ship = universe.Object<Ship>(*(fleet->begin())); if (!ship) continue; + const ShipDesign *design = ship->Design(); + + // give orders according to type of ship in fleet + if (design->name == "Scout") { + Explore(fleet); + + } else if (design->name == "Colony Ship") { + ColonizeSomewhere(fleet); + + } + } +} + +void AIClientApp::Explore(Fleet* fleet) { + if (!fleet) return; + + Logger().debugStream() << "telling fleet to explore"; + + Universe& universe = ClientApp::GetUniverse(); + int empire_id = ClientApp::EmpireID(); + + // ensure this player owns this fleet + const std::set<int>& owners = fleet->Owners(); + if (owners.size() != 1 || *(owners.begin()) != empire_id) return; // don't own fleet + + const Empire* empire = ClientApp::Empires().Lookup(empire_id); + if (!empire) throw std::runtime_error("Couldn't get pointer to empire when telling fleet to Explore"); + + + int start_id = fleet->SystemID(); // system where fleet is presently + + Logger().debugStream() << "telling fleet to explore2"; + + // attempt to find an unexplored system that can be explored (fleet can get to) + int explorable_system = UniverseObject::INVALID_OBJECT_ID; + std::vector<System*> systems = universe.FindObjects<System>(); + for (std::vector<System*>::const_iterator system_it = systems.begin(); system_it != systems.end(); ++system_it) { + System* system = *system_it; + int dest_id = system->ID(); // system to go to + if (empire->HasExploredSystem(dest_id)) continue; // already explored system + if (m_fleet_exploration_targets_map.find(dest_id) != m_fleet_exploration_targets_map.end()) continue; // another fleet has been dispatched + + Logger().debugStream() << "telling fleet to explore3"; + + // get path to destination. don't care that it's short, but just that it exists + std::list<System*> route = universe.ShortestPath(start_id, dest_id, empire_id).first; + + if (route.empty()) continue; // can't get to system (with present starlanes knowledge) + + Logger().debugStream() << "telling fleet to explore4"; + + // order ship to go ot system + GetApp()->Orders().IssueOrder(new FleetMoveOrder(empire_id, fleet->ID(), start_id, dest_id)); + + Logger().debugStream() << "telling fleet to explore5"; + + // mark system as targeted for exploration, so another ship isn't sent to it redundantly + m_fleet_exploration_targets_map.insert(std::pair<int, int>(dest_id, fleet->ID())); + + return; // don't need to keep looping at this point + } +} + +void AIClientApp::ColonizeSomewhere(Fleet* fleet) { + +} + +void AIClientApp::SplitFleet(Fleet* fleet) +{ + if (!fleet) return; // no fleet to process... + if (fleet->NumShips() < 2) return; // can't split fleet with one (or no?) ships + + Universe& universe = ClientApp::GetUniverse(); + int empire_id = ClientApp::EmpireID(); + + // ensure this player owns this fleet + const std::set<int>& owners = fleet->Owners(); + + if (owners.size() != 1 || *(owners.begin()) != empire_id) return; // don't own fleet + + // starting with second ship, pick ships to transfer to new fleets + std::set<int> ship_ids_to_remove; + for (Fleet::iterator ship_it = ++(fleet->begin()); ship_it != fleet->end(); ++ship_it) { + + Ship *ship = universe.Object<Ship>(*ship_it); + const std::set<int>& ship_owners = ship->Owners(); + + if (ship_owners.size() != 1 || *(ship_owners.begin()) != empire_id) continue; // don't own ship + + ship_ids_to_remove.insert(*ship_it); + } + + if (ship_ids_to_remove.empty()) return; // nothing more to do + + // info from source fleet that may be copied to new fleets + System* system = fleet->GetSystem(); + double fleet_x = fleet->X(); + double fleet_y = fleet->Y(); + + // order transfers of ships from old fleet to new fleets + for (std::set<int>::iterator ship_it = ship_ids_to_remove.begin(); ship_it != ship_ids_to_remove.end(); ++ship_it) { + std::vector<int> ship_ids; + ship_ids.push_back(*ship_it); + + int new_fleet_id = ClientApp::GetNewObjectID(); + if (new_fleet_id == UniverseObject::INVALID_OBJECT_ID) + throw std::runtime_error("Couldn't get new object ID when transferring ship to new fleet"); + + std::string fleet_name = UserString("FW_NEW_FLEET_NAME") + boost::lexical_cast<std::string>(new_fleet_id); + + Fleet* new_fleet = 0; + if (system) { + GetApp()->Orders().IssueOrder(new NewFleetOrder(empire_id, fleet_name, new_fleet_id, system->ID(), ship_ids)); + + } else { + GetApp()->Orders().IssueOrder(new NewFleetOrder(empire_id, fleet_name, new_fleet_id, fleet_x, fleet_y, ship_ids)); + } + } +} \ No newline at end of file Modified: trunk/FreeOrion/client/AI/AIClientApp.h =================================================================== --- trunk/FreeOrion/client/AI/AIClientApp.h 2006-12-03 00:28:45 UTC (rev 1967) +++ trunk/FreeOrion/client/AI/AIClientApp.h 2006-12-03 03:28:08 UTC (rev 1968) @@ -12,13 +12,13 @@ class AIClientApp : public ClientApp { public: - virtual void StartTurn(); + virtual void StartTurn(); ///< encodes order sets and sends turn orders message /** \name Structors */ //@{ AIClientApp(int argc, char* argv[]); ~AIClientApp(); //@} - + /** \name Mutators */ //@{ void operator()(); ///< external interface to Run() void Exit(int code); ///< does basic clean-up, then calls exit(); callable from anywhere in user code via GetApp() @@ -28,16 +28,25 @@ static AIClientApp* GetApp(); ///< returns a AIClientApp pointer to the singleton instance of the app private: - void Run(); ///< initializes app state, then executes main event handler/render loop (PollAndRender()) + void Run(); ///< initializes app state, then executes main event handler/render loop (PollAndRender()) - void SDLInit(); ///< initializes SDL and SDL-related libs - void Initialize(); ///< app initialization - - void Poll(); ///< handles all waiting SDL messages + void SDLInit(); ///< initializes SDL and SDL-related libs + void Initialize(); ///< app initialization + void AIGenerateOrders(); ///< processes gamestate and generates orders - void FinalCleanup(); ///< app final cleanup - void SDLQuit(); ///< cleans up FE and SDL + // utility order-generating functions + void SplitFleet(Fleet* fleet); ///< transfers ships after first ship in fleet into new single-ship fleets + void Explore(Fleet* fleet); ///< orders fleet to explore. tries to find an unexplored system and goes there + void ColonizeSomewhere(Fleet* fleet); ///< orders fleet to find and colonize a planet / system + // planning data / universe analysis intermediate results + std::map<int, int> m_fleet_exploration_targets_map; ///< map of (system_id, fleet_id) for systems that have had a fleet dispatched to explore them + + void Poll(); ///< handles all waiting SDL messages + + void FinalCleanup(); ///< app final cleanup + void SDLQuit(); ///< cleans up FE and SDL + virtual void HandleMessageImpl(const Message& msg); virtual void HandleServerDisconnectImpl(); |