本文整理汇总了C++中Universe::Clear方法的典型用法代码示例。如果您正苦于以下问题:C++ Universe::Clear方法的具体用法?C++ Universe::Clear怎么用?C++ Universe::Clear使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Universe
的用法示例。
在下文中一共展示了Universe::Clear方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: LoadGame
void LoadGame(const std::string& filename, ServerSaveGameData& server_save_game_data,
std::vector<PlayerSaveGameData>& player_save_game_data,
Universe& universe, EmpireManager& empire_manager,
SpeciesManager& species_manager, CombatLogManager& combat_log_manager)
{
//Sleep(5000);
// player notifications
if (ServerApp* server = ServerApp::GetApp())
server->Networking().SendMessage(TurnProgressMessage(Message::LOADING_GAME));
GetUniverse().EncodingEmpire() = ALL_EMPIRES;
std::map<int, SaveGameEmpireData> ignored_save_game_empire_data;
empire_manager.Clear();
universe.Clear();
try {
#ifdef FREEORION_WIN32
// convert UTF-8 file name to UTF-16
fs::path::string_type file_name_native;
utf8::utf8to16(filename.begin(), filename.end(), std::back_inserter(file_name_native));
fs::path path = fs::path(file_name_native);
#else
fs::path path = fs::path(filename);
#endif
fs::ifstream ifs(path, std::ios_base::binary);
if (!ifs)
throw std::runtime_error(UNABLE_TO_OPEN_FILE);
FREEORION_IARCHIVE_TYPE ia(ifs);
Logger().debugStream() << "LoadGame : Reading Server Save Game Data";
ia >> BOOST_SERIALIZATION_NVP(server_save_game_data);
Logger().debugStream() << "LoadGame : Reading Player Save Game Data";
ia >> BOOST_SERIALIZATION_NVP(player_save_game_data);
Logger().debugStream() << "LoadGame : Reading Empire Save Game Data (Ignored)";
ia >> BOOST_SERIALIZATION_NVP(ignored_save_game_empire_data);
Logger().debugStream() << "LoadGame : Reading Empires Data";
ia >> BOOST_SERIALIZATION_NVP(empire_manager);
Logger().debugStream() << "LoadGame : Reading Species Data";
ia >> BOOST_SERIALIZATION_NVP(species_manager);
Logger().debugStream() << "LoadGame : Reading Combat Logs";
ia >> BOOST_SERIALIZATION_NVP(combat_log_manager);
Logger().debugStream() << "LoadGame : Reading Universe Data";
Deserialize(ia, universe);
} catch (const std::exception& e) {
Logger().errorStream() << UserString("UNABLE_TO_READ_SAVE_FILE") << " LoadGame exception: " << ": " << e.what();
throw e;
}
Logger().debugStream() << "LoadGame : Done loading save file";
}
示例2: LoadGame
void LoadGame(const std::string& filename, ServerSaveGameData& server_save_game_data,
std::vector<PlayerSaveGameData>& player_save_game_data, Universe& universe,
EmpireManager& empire_manager, SpeciesManager& species_manager,
CombatLogManager& combat_log_manager, GalaxySetupData& galaxy_setup_data)
{
//boost::this_thread::sleep(boost::posix_time::seconds(1));
ScopedTimer timer("LoadGame: " + filename, true);
// player notifications
if (ServerApp* server = ServerApp::GetApp())
server->Networking().SendMessage(TurnProgressMessage(Message::LOADING_GAME));
GetUniverse().EncodingEmpire() = ALL_EMPIRES;
std::map<int, SaveGameEmpireData> ignored_save_game_empire_data;
SaveGamePreviewData ignored_save_preview_data;
std::vector<PlayerSaveHeaderData> ignored_player_save_header_data;
empire_manager.Clear();
universe.Clear();
try {
// set up input archive / stream for loading
const fs::path path = FilenameToPath(filename);
fs::ifstream ifs(path, std::ios_base::binary);
if (!ifs)
throw std::runtime_error(UNABLE_TO_OPEN_FILE);
try {
// first attempt binary deserialziation
freeorion_bin_iarchive ia(ifs);
DebugLogger() << "Reading binary iarchive";
ia >> BOOST_SERIALIZATION_NVP(ignored_save_preview_data);
ia >> BOOST_SERIALIZATION_NVP(galaxy_setup_data);
ia >> BOOST_SERIALIZATION_NVP(server_save_game_data);
ia >> BOOST_SERIALIZATION_NVP(ignored_player_save_header_data);
ia >> BOOST_SERIALIZATION_NVP(ignored_save_game_empire_data);
ia >> BOOST_SERIALIZATION_NVP(player_save_game_data);
ia >> BOOST_SERIALIZATION_NVP(empire_manager);
ia >> BOOST_SERIALIZATION_NVP(species_manager);
ia >> BOOST_SERIALIZATION_NVP(combat_log_manager);
Deserialize(ia, universe);
DebugLogger() << "Done deserializing";
} catch (...) {
// if binary deserialization failed, try more-portable XML deserialization
// reset to start of stream (attempted binary serialization will have consumed some input...)
boost::iostreams::seek(ifs, 0, std::ios_base::beg);
// allocate buffers for serialized gamestate
DebugLogger() << "Allocating buffers for XML deserialization...";
std::string serial_str, compressed_str;
try {
serial_str.reserve( std::pow(2.0, 29.0));
compressed_str.reserve(std::pow(2.0, 26.0));
} catch (...) {
DebugLogger() << "Unable to preallocate full deserialization buffers. Attempting deserialization with dynamic buffer allocation.";
}
// create archive with (preallocated) buffer...
freeorion_xml_iarchive xia(ifs);
// read from save file: uncompressed header serialized data, with compressed main archive string at end...
// deserialize uncompressed save header info
xia >> BOOST_SERIALIZATION_NVP(ignored_save_preview_data);
xia >> BOOST_SERIALIZATION_NVP(galaxy_setup_data);
xia >> BOOST_SERIALIZATION_NVP(server_save_game_data);
xia >> BOOST_SERIALIZATION_NVP(ignored_player_save_header_data);
xia >> BOOST_SERIALIZATION_NVP(ignored_save_game_empire_data);
// extract compressed gamestate info
xia >> BOOST_SERIALIZATION_NVP(compressed_str);
// wrap compressed string in iostream::stream to extract compressed data
typedef boost::iostreams::basic_array_source<char> SourceDevice;
SourceDevice compressed_source(compressed_str.data(), compressed_str.size());
boost::iostreams::stream<SourceDevice> c_source(compressed_source);
// wrap uncompressed buffer string in iostream::stream to receive decompressed string
typedef boost::iostreams::back_insert_device<std::string> InsertDevice;
InsertDevice serial_inserter(serial_str);
boost::iostreams::stream<InsertDevice> s_sink(serial_inserter);
// set up filter to decompress data
boost::iostreams::filtering_istreambuf i;
i.push(boost::iostreams::zlib_decompressor());
i.push(c_source);
boost::iostreams::copy(i, s_sink);
s_sink.flush();
// wrap uncompressed buffer string in iostream::stream to extract decompressed string
SourceDevice serial_source(serial_str.data(), serial_str.size());
boost::iostreams::stream<SourceDevice> s_source(serial_source);
// create archive with (preallocated) buffer...
freeorion_xml_iarchive xia2(s_source);
// deserialize main gamestate info
xia2 >> BOOST_SERIALIZATION_NVP(player_save_game_data);
xia2 >> BOOST_SERIALIZATION_NVP(empire_manager);
xia2 >> BOOST_SERIALIZATION_NVP(species_manager);
//.........这里部分代码省略.........
示例3: LoadGame
void LoadGame(const std::string& filename, ServerSaveGameData& server_save_game_data,
std::vector<PlayerSaveGameData>& player_save_game_data,
Universe& universe, EmpireManager& empire_manager,
SpeciesManager& species_manager, CombatLogManager& combat_log_manager,
GalaxySetupData& galaxy_setup_data, bool alternate_serialization)
{
//boost::this_thread::sleep(boost::posix_time::seconds(5));
bool use_binary = GetOptionsDB().Get<bool>("binary-serialization") ^ alternate_serialization;
// player notifications
if (ServerApp* server = ServerApp::GetApp())
server->Networking().SendMessage(TurnProgressMessage(Message::LOADING_GAME));
GetUniverse().EncodingEmpire() = ALL_EMPIRES;
std::map<int, SaveGameEmpireData> ignored_save_game_empire_data;
SaveGamePreviewData ignored_save_preview_data;
empire_manager.Clear();
universe.Clear();
try {
const fs::path path = FilenameToPath(filename);
fs::ifstream ifs(path, std::ios_base::binary);
if (!ifs)
throw std::runtime_error(UNABLE_TO_OPEN_FILE);
if (use_binary) {
freeorion_bin_iarchive ia(ifs);
DebugLogger() << "LoadGame : Passing Preview Data";
ia >> BOOST_SERIALIZATION_NVP(ignored_save_preview_data);
DebugLogger() << "LoadGame : Reading Galaxy Setup Data";
ia >> BOOST_SERIALIZATION_NVP(galaxy_setup_data);
DebugLogger() << "LoadGame : Reading Server Save Game Data";
ia >> BOOST_SERIALIZATION_NVP(server_save_game_data);
DebugLogger() << "LoadGame : Reading Player Save Game Data";
ia >> BOOST_SERIALIZATION_NVP(player_save_game_data);
DebugLogger() << "LoadGame : Reading Empire Save Game Data (Ignored)";
ia >> BOOST_SERIALIZATION_NVP(ignored_save_game_empire_data);
DebugLogger() << "LoadGame : Reading Empires Data";
ia >> BOOST_SERIALIZATION_NVP(empire_manager);
DebugLogger() << "LoadGame : Reading Species Data";
ia >> BOOST_SERIALIZATION_NVP(species_manager);
DebugLogger() << "LoadGame : Reading Combat Logs";
ia >> BOOST_SERIALIZATION_NVP(combat_log_manager);
DebugLogger() << "LoadGame : Reading Universe Data";
Deserialize(ia, universe);
} else {
freeorion_xml_iarchive ia(ifs);
DebugLogger() << "LoadGame : Passing Preview Data";
ia >> BOOST_SERIALIZATION_NVP(ignored_save_preview_data);
DebugLogger() << "LoadGame : Reading Galaxy Setup Data";
ia >> BOOST_SERIALIZATION_NVP(galaxy_setup_data);
DebugLogger() << "LoadGame : Reading Server Save Game Data";
ia >> BOOST_SERIALIZATION_NVP(server_save_game_data);
DebugLogger() << "LoadGame : Reading Player Save Game Data";
ia >> BOOST_SERIALIZATION_NVP(player_save_game_data);
DebugLogger() << "LoadGame : Reading Empire Save Game Data (Ignored)";
ia >> BOOST_SERIALIZATION_NVP(ignored_save_game_empire_data);
DebugLogger() << "LoadGame : Reading Empires Data";
ia >> BOOST_SERIALIZATION_NVP(empire_manager);
DebugLogger() << "LoadGame : Reading Species Data";
ia >> BOOST_SERIALIZATION_NVP(species_manager);
DebugLogger() << "LoadGame : Reading Combat Logs";
ia >> BOOST_SERIALIZATION_NVP(combat_log_manager);
DebugLogger() << "LoadGame : Reading Universe Data";
Deserialize(ia, universe);
}
} catch (const std::exception& e) {