minor refactoring, patch 1026 by davi hilton
This commit is contained in:
parent
99e00bbeee
commit
99b3f4b80d
4 changed files with 53 additions and 9 deletions
|
@ -42,6 +42,9 @@
|
|||
name = "Cédric Duval"
|
||||
comment = "coder, internationalization manager"
|
||||
[/entry]
|
||||
[entry]
|
||||
name = "David Hilton"
|
||||
[/entry]
|
||||
[entry]
|
||||
name = "Dominic Bolin (Xan)"
|
||||
[/entry]
|
||||
|
|
51
src/game.cpp
51
src/game.cpp
|
@ -1967,6 +1967,51 @@ game_controller::~game_controller()
|
|||
sound::close_sound();
|
||||
}
|
||||
|
||||
// this is needed to allow identical functionality with clean refactoring
|
||||
// play_game only returns on an error, all returns within play_game can
|
||||
// be replaced with this
|
||||
void safe_exit(int res) {
|
||||
|
||||
LOG_GENERAL << "exiting with code " << res << "\n";
|
||||
#ifdef OS2 /* required to correctly shutdown SDL on OS/2 */
|
||||
SDL_Quit();
|
||||
#endif
|
||||
exit(res);
|
||||
}
|
||||
|
||||
// maybe this should go in a util file somewhere?
|
||||
void gzip_codec(const std::string & input_file, const std::string & output_file, bool encode)
|
||||
{
|
||||
try {
|
||||
std::ofstream ofile(output_file.c_str(), std::ios_base::out
|
||||
| std::ios_base::binary | std::ios_base::binary);
|
||||
std::ifstream ifile(input_file.c_str(),
|
||||
std::ios_base::in | std::ios_base::binary);
|
||||
boost::iostreams::filtering_streambuf<boost::iostreams::input> in;
|
||||
if(encode)
|
||||
in.push(boost::iostreams::gzip_compressor());
|
||||
else
|
||||
in.push(boost::iostreams::gzip_decompressor());
|
||||
in.push(ifile);
|
||||
boost::iostreams::copy(in, ofile);
|
||||
ifile.close();
|
||||
safe_exit(remove(input_file.c_str()));
|
||||
} catch(io_exception& e) {
|
||||
std::cerr << "IO error: " << e.what() << "\n";
|
||||
}
|
||||
}
|
||||
|
||||
void gzip_encode(const std::string & input_file, const std::string & output_file)
|
||||
{
|
||||
gzip_codec(input_file, output_file, true);
|
||||
}
|
||||
|
||||
void gzip_decode(const std::string & input_file, const std::string & output_file)
|
||||
{
|
||||
gzip_codec(input_file, output_file, false);
|
||||
}
|
||||
|
||||
|
||||
//! Process commandline-arguments
|
||||
static int play_game(int argc, char** argv)
|
||||
{
|
||||
|
@ -2357,11 +2402,7 @@ int main(int argc, char** argv)
|
|||
std::cerr << "Started on " << ctime(&t) << "\n";
|
||||
|
||||
const int res = play_game(argc,argv);
|
||||
LOG_GENERAL << "exiting with code " << res << "\n";
|
||||
#ifdef OS2 /* required to correctly shutdown SDL on OS/2 */
|
||||
SDL_Quit();
|
||||
#endif
|
||||
return res;
|
||||
safe_exit(res);
|
||||
} catch(CVideo::error&) {
|
||||
std::cerr << "Could not initialize video. Exiting.\n";
|
||||
} catch(font::manager::error&) {
|
||||
|
|
|
@ -335,7 +335,7 @@ void game::transfer_side_control(const network::connection sock, const simple_wm
|
|||
return;
|
||||
}
|
||||
// Check the side number.
|
||||
const int side_num = cfg["side"].to_int();
|
||||
const unsigned int side_num = cfg["side"].to_int();
|
||||
if(side_num < 1 || side_num > gamemap::MAX_PLAYERS) {
|
||||
std::ostringstream msg;
|
||||
msg << "The side number has to be between 1 and "
|
||||
|
@ -441,7 +441,7 @@ void game::send_change_controller(const size_t side_num,
|
|||
|
||||
// Update the level so observers who join get the new name.
|
||||
const simple_wml::node::child_list& side_list = level_.root().children("side");
|
||||
const int index = side_num - 1;
|
||||
const unsigned int index = side_num - 1;
|
||||
assert(index < side_list.size());
|
||||
side_list[index]->set_attr_dup("current_player", newplayer->second.name().c_str());
|
||||
}
|
||||
|
|
|
@ -79,8 +79,8 @@ public:
|
|||
char* duplicate() const;
|
||||
|
||||
private:
|
||||
const char* str_;
|
||||
int size_;
|
||||
const char* str_;
|
||||
unsigned int size_;
|
||||
};
|
||||
|
||||
std::ostream& operator<<(std::ostream& o, const string_span& s);
|
||||
|
|
Loading…
Add table
Reference in a new issue