[Widelands-cvs] SF.net SVN: widelands: [1986] trunk/src
Status: Beta
Brought to you by:
sirver
From: <si...@us...> - 2007-01-28 21:13:05
|
Revision: 1986 http://svn.sourceforge.net/widelands/?rev=1986&view=rev Author: sigra Date: 2007-01-28 13:12:57 -0800 (Sun, 28 Jan 2007) Log Message: ----------- Clean up my mess from yesterday (which Florian already had to fix today) and the mess that was already there before it. Get rid of the const char * argument and use std::string all the way instead (also in Fullscreen_Menu_LoadGame). Add doxygen-formatted documentation for Game:run_load_game. In Fullscreen_Menu_LoadGame: * Swap members to follow the convention that the public part is above and the private part below. * Make game a reference instead of a pointer and initialize it! The scary thing is that it is used but it seems like it has not been initialized since revision 753 (see [http://widelands.svn.sourceforge.net/viewvc/widelands/trunk/src/ui/ui_fs_menus/fullscreen_menu_loadgame.cc?revision=753&view=markup#l_43]). It seems like the initialization was removed in revision 756 for some reason (see [http://widelands.svn.sourceforge.net/viewvc/widelands/trunk/src/ui/ui_fs_menus/fullscreen_menu_loadgame.cc?r1=756&r2=755&pathrev=756]). Unless I got this wrong, this is the reason for some really strange behaviour that Widelands has shown since then. But unfortunately it was most likely not the cause of bug #1620088. Revision Links: -------------- http://svn.sourceforge.net/widelands/?rev=753&view=rev http://svn.sourceforge.net/widelands/?rev=756&view=rev Modified Paths: -------------- trunk/src/game.cc trunk/src/game.h trunk/src/ui/ui_fs_menus/fullscreen_menu_loadgame.cc trunk/src/ui/ui_fs_menus/fullscreen_menu_loadgame.h Modified: trunk/src/game.cc =================================================================== --- trunk/src/game.cc 2007-01-28 18:02:15 UTC (rev 1985) +++ trunk/src/game.cc 2007-01-28 21:12:57 UTC (rev 1986) @@ -173,21 +173,17 @@ * argument defines if this is a single player game (true) * or networked (false) */ -bool Game::run_load_game(const bool is_splayer, const char * gamename) { +bool Game::run_load_game(const bool is_splayer, std::string filename) { assert(is_splayer); // TODO: net game saving not supported - std::string gn=gamename; - - if (gn.empty()) { - Fullscreen_Menu_LoadGame ssg(this, true); - if (ssg.run()) - gn = ssg.get_gamename(); - else return false; + if (filename.empty()) { + Fullscreen_Menu_LoadGame ssg(*this); + if (ssg.run()) filename = ssg.filename(); else return false; } // We have to create an empty map, otherwise nothing will load properly set_map(new Map); - FileSystem * const fs = g_fs->MakeSubFileSystem(gn.c_str()); + FileSystem * const fs = g_fs->MakeSubFileSystem(filename.c_str()); Game_Loader gl(*fs, this); gl.load_game(); Modified: trunk/src/game.h =================================================================== --- trunk/src/game.h 2007-01-28 18:02:15 UTC (rev 1985) +++ trunk/src/game.h 2007-01-28 21:12:57 UTC (rev 1986) @@ -52,12 +52,11 @@ class PlayerCommand; class NetGame; -class Game : public Editor_Game_Base { +struct Game : public Editor_Game_Base { friend class Cmd_Queue; // this class handles the commands friend class Game_Game_Class_Data_Packet; friend class Game_Player_Info_Data_Packet; -public: Game(void); ~Game(void); @@ -65,8 +64,15 @@ bool run_splayer_map_direct(const char* mapname, bool scenario); bool run_single_player (); bool run_multi_player (NetGame*); - bool run_load_game(const bool is_splayer, const char * gamename = 0); + /** + * Loads a game from filename and runs it. If filename is empty, a dialog is + * shown that lets the user chose a file to load. Returns false if the user + * cancels the dialog. Otherwise returns the result of running the game. + */ + bool run_load_game + (const bool is_splayer, std::string filename = std::string()); + void load_map (const char*); void think(void); Modified: trunk/src/ui/ui_fs_menus/fullscreen_menu_loadgame.cc =================================================================== --- trunk/src/ui/ui_fs_menus/fullscreen_menu_loadgame.cc 2007-01-28 18:02:15 UTC (rev 1985) +++ trunk/src/ui/ui_fs_menus/fullscreen_menu_loadgame.cc 2007-01-28 21:12:57 UTC (rev 1986) @@ -1,5 +1,5 @@ /* - * Copyright (C) 2002, 2006 by the Widelands Development Team + * Copyright (C) 2002, 2006-2007 by the Widelands Development Team * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU General Public License @@ -27,16 +27,9 @@ #include "i18n.h" #include "layered_filesystem.h" -/* -============================================================================== - -Fullscreen_Menu_LoadGame - -============================================================================== -*/ - -Fullscreen_Menu_LoadGame::Fullscreen_Menu_LoadGame(Game *, bool) : +Fullscreen_Menu_LoadGame::Fullscreen_Menu_LoadGame(Game & g) : Fullscreen_Menu_Base("choosemapmenu.jpg"), +game(g), // UI::Buttons @@ -87,7 +80,7 @@ void Fullscreen_Menu_LoadGame::map_selected(uint) { if (const char * const name = list.get_selected()) { FileSystem* fs = g_fs->MakeSubFileSystem( name ); - Game_Loader gl(*fs, game); + Game_Loader gl(*fs, &game); Game_Preload_Data_Packet gpdp; gl.preload_game(&gpdp); // This has worked before, no problem @@ -136,7 +129,7 @@ try { fs = g_fs->MakeSubFileSystem( name ); - Game_Loader gl(*fs, game); + Game_Loader gl(*fs, &game); gl.preload_game(&gpdp); char* fname = strdup(FileSystem::FS_Filename(name)); Modified: trunk/src/ui/ui_fs_menus/fullscreen_menu_loadgame.h =================================================================== --- trunk/src/ui/ui_fs_menus/fullscreen_menu_loadgame.h 2007-01-28 18:02:15 UTC (rev 1985) +++ trunk/src/ui/ui_fs_menus/fullscreen_menu_loadgame.h 2007-01-28 21:12:57 UTC (rev 1986) @@ -34,12 +34,20 @@ class Map_Loader; class RenderTarget; -/** - * Select a Saved Game in Fullscreen Mode. It's a modal fullscreen menu - */ -class Fullscreen_Menu_LoadGame : public Fullscreen_Menu_Base { - Game* game; +/// Select a Saved Game in Fullscreen Mode. It's a modal fullscreen menu. +struct Fullscreen_Menu_LoadGame : public Fullscreen_Menu_Base { + Fullscreen_Menu_LoadGame(Game &); + ~Fullscreen_Menu_LoadGame(); + const std::string & filename() {return m_filename;} + + void clicked_ok (); + void map_selected (uint); + void double_clicked(uint); + void fill_list (); + +private: + Game & game; UI::IDButton<Fullscreen_Menu_LoadGame, int> back; UI::Button<Fullscreen_Menu_LoadGame> m_ok; UI::Listselect<const char * const> list; @@ -52,16 +60,6 @@ filenameset_t m_gamefiles; -public: - Fullscreen_Menu_LoadGame(Game *g, bool is_singleplayer); - ~Fullscreen_Menu_LoadGame(); - - const char *get_gamename() { return m_filename.c_str(); } - - void clicked_ok(); - void map_selected (uint); - void double_clicked(uint); - void fill_list(void); }; This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |