mail[Wesnoth-commits] r25262 - in /trunk: data/core/about.cfg src/game.cpp src/server/game.cpp src/server/simple_wml.hpp


Others Months | Index by Date | Thread Index
>>   [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Header


Content

Posted by jeremy . rosen on March 28, 2008 - 22:46:
Author: boucman
Date: Fri Mar 28 22:46:30 2008
New Revision: 25262

URL: http://svn.gna.org/viewcvs/wesnoth?rev=25262&view=rev
Log:
minor refactoring, patch 1026 by davi hilton

Modified:
    trunk/data/core/about.cfg
    trunk/src/game.cpp
    trunk/src/server/game.cpp
    trunk/src/server/simple_wml.hpp

Modified: trunk/data/core/about.cfg
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/data/core/about.cfg?rev=25262&r1=25261&r2=25262&view=diff
==============================================================================
--- trunk/data/core/about.cfg (original)
+++ trunk/data/core/about.cfg Fri Mar 28 22:46:30 2008
@@ -43,6 +43,9 @@
         comment = "coder, internationalization manager"
     [/entry]
     [entry]
+        name = "David Hilton"
+    [/entry]
+    [entry]
         name = "Dominic Bolin (Xan)"
     [/entry]
     [entry]

Modified: trunk/src/game.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/game.cpp?rev=25262&r1=25261&r2=25262&view=diff
==============================================================================
--- trunk/src/game.cpp (original)
+++ trunk/src/game.cpp Fri Mar 28 22:46:30 2008
@@ -1966,6 +1966,51 @@
        delete gui::empty_menu;
        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 @@
                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&) {

Modified: trunk/src/server/game.cpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/server/game.cpp?rev=25262&r1=25261&r2=25262&view=diff
==============================================================================
--- trunk/src/server/game.cpp (original)
+++ trunk/src/server/game.cpp Fri Mar 28 22:46:30 2008
@@ -335,7 +335,7 @@
                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 @@
 
        // 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());
 }

Modified: trunk/src/server/simple_wml.hpp
URL: 
http://svn.gna.org/viewcvs/wesnoth/trunk/src/server/simple_wml.hpp?rev=25262&r1=25261&r2=25262&view=diff
==============================================================================
--- trunk/src/server/simple_wml.hpp (original)
+++ trunk/src/server/simple_wml.hpp Fri Mar 28 22:46:30 2008
@@ -79,8 +79,8 @@
        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);




Related Messages


Powered by MHonArc, Updated Fri Mar 28 23:21:35 2008