From acefce6b410416c53ea7bc8a709e5e559a1623ac Mon Sep 17 00:00:00 2001 From: Nick Gasson Date: Fri, 13 Jun 2008 22:09:17 +0100 Subject: [PATCH] Resolution switching --- po/POTFILES.in | 78 ++++++++++++++++----------------- po/en_GB.po | 112 +++++++++++++++++++++++++---------------------- po/lander.pot | 88 +++++++++++++++++++------------------ src/Main.cpp | 61 ++++++++++++++++++-------- src/Makefile.am | 2 +- src/OpenGL.cpp | 41 ++++++++++------- src/OpenGL.hpp | 5 ++- src/Options.cpp | 15 ++++++- src/Platform.hpp | 1 + 9 files changed, 230 insertions(+), 173 deletions(-) diff --git a/po/POTFILES.in b/po/POTFILES.in index f360437..46042d6 100644 --- a/po/POTFILES.in +++ b/po/POTFILES.in @@ -1,50 +1,50 @@ +src/Ship.cpp +src/Input.hpp +src/Game.hpp +src/Input.cpp src/Mechanics.hpp +src/OpenGL.hpp +src/OpenGL.cpp +src/Key.cpp +src/Options.hpp +src/ElectricGate.hpp src/Texture.cpp -src/Ship.cpp -src/Texture.hpp -src/Ship.hpp -src/Emitter.cpp -src/ObjectGrid.cpp src/Emitter.hpp -src/ObjectGrid.hpp -src/Image.cpp -src/AnimatedImage.cpp -src/Image.hpp +src/LandingPad.cpp +src/Main.cpp +src/Geometry.hpp src/Mine.cpp +src/ScreenManager.hpp +src/Surface.cpp +src/ObjectGrid.cpp +src/Viewport.cpp +src/Asteroid.hpp +src/Viewport.hpp +src/Font.cpp src/LoadOnce.hpp src/Platform.hpp -src/AnimatedImage.hpp +src/Key.hpp +src/ConfigFile.hpp +src/LandingPad.hpp src/ElectricGate.cpp -src/Mine.hpp -src/HighScores.cpp -src/Input.cpp -src/ElectricGate.hpp -src/Geometry.hpp -src/LandingPad.cpp +src/Emitter.cpp +src/ScreenManager.cpp +src/Texture.hpp src/HighScores.hpp -src/Input.hpp -src/Menu.cpp -src/LandingPad.hpp -src/Game.cpp -src/Menu.hpp -src/Lander.hpp +src/Mine.hpp +src/AnimatedImage.hpp src/Asteroid.cpp -src/ScreenManager.cpp -src/Bitmap.cpp -src/Asteroid.hpp -src/File.cpp -src/ScreenManager.hpp -src/Viewport.cpp -src/Bitmap.hpp -src/FreeType.cpp -src/Main.cpp -src/File.hpp -src/OpenGL.cpp -src/Viewport.hpp -src/Key.cpp -src/FreeType.hpp -src/Surface.cpp -src/OpenGL.hpp +src/Image.cpp src/Mechanics.cpp -src/Key.hpp +src/Font.hpp src/Surface.hpp +src/AnimatedImage.cpp +src/ObjectGrid.hpp +src/Menu.hpp +src/Game.cpp +src/HighScores.cpp +src/Options.cpp +src/Menu.cpp +src/Ship.hpp +src/Image.hpp +src/ConfigFile.cpp diff --git a/po/en_GB.po b/po/en_GB.po index 853a127..96c4f67 100644 --- a/po/en_GB.po +++ b/po/en_GB.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: lander 0.9\n" "Report-Msgid-Bugs-To: nick@cakesniffer.co.uk\n" -"POT-Creation-Date: 2008-06-04 12:05+0100\n" +"POT-Creation-Date: 2008-06-13 22:08+0100\n" "PO-Revision-Date: 2008-04-19 01:09+0100\n" "Last-Translator: Nick Gasson \n" "Language-Team: English (British)\n" @@ -16,86 +16,94 @@ msgstr "" "Content-Transfer-Encoding: 8bit\n" "Plural-Forms: nplurals=2; plural=(n != 1);\n" -#: src/HighScores.cpp:180 -msgid "Press SPACE or FIRE to return" +#: src/Main.cpp:114 +#, c-format +msgid "Runtime Error: %s\n" +msgstr "Runtime Error: %s\n" + +#: src/Game.cpp:616 +msgid "Press SPACE to continue" +msgstr "Press SPACE to continue" + +#: src/Game.cpp:674 +msgid "Land now" +msgstr "Land now" + +#: src/Game.cpp:680 +#, c-format +msgid "Score: %d" +msgstr "Score: %d" + +#: src/Game.cpp:695 +#, c-format +msgid "Level %d" +msgstr "Level %d" + +#: src/Game.cpp:714 +msgid "Paused" +msgstr "Paused" + +#: src/HighScores.cpp:177 +#, fuzzy +msgid "Press SPACE or FIRE to return" msgstr "Press SPACE or FIRE to return" -#: src/HighScores.cpp:198 -msgid "Well done - You got a high score" +#: src/HighScores.cpp:192 +#, fuzzy +msgid "Well done - You got a high score" msgstr "Well done - You got a high score" -#: src/HighScores.cpp:208 -msgid "Press ENTER or FIRE to continue" +#: src/HighScores.cpp:197 +#, fuzzy +msgid "Press ENTER or FIRE to continue" msgstr "Press ENTER or FIRE to continue" -#: src/HighScores.cpp:217 +#: src/HighScores.cpp:202 #, c-format msgid "Name? %s" msgstr "Name? %s" -#: src/Menu.cpp:235 +#: src/Options.cpp:213 +msgid "Use UP and DOWN to select options" +msgstr "" + +#: src/Options.cpp:218 +msgid "Use LEFT and RIGHT to change values" +msgstr "" + +#: src/Options.cpp:223 +#, fuzzy +msgid "Press FIRE or RETURN to exit" +msgstr "Press SPACE or FIRE to return" + +#: src/Menu.cpp:244 msgid "Use the arrow keys to rotate the ship" msgstr "" -#: src/Menu.cpp:236 +#: src/Menu.cpp:245 msgid "Press the up arrow to fire the thruster" msgstr "" -#: src/Menu.cpp:237 +#: src/Menu.cpp:246 msgid "Smaller landing pads give you more points" msgstr "" -#: src/Menu.cpp:238 +#: src/Menu.cpp:247 msgid "Press P to pause the game" msgstr "" -#: src/Menu.cpp:239 +#: src/Menu.cpp:248 msgid "Press escape to self destruct" msgstr "" -#: src/Menu.cpp:241 -msgid "You can only land safely when the" -msgstr "" - -#: src/Menu.cpp:242 -msgid "speed bar is green" +#: src/Menu.cpp:249 +msgid "You can only land safely when then speed bar is green" msgstr "" -#: src/Menu.cpp:243 -msgid "Collect the spinning rings to" +#: src/Menu.cpp:250 +msgid "Collect the spinning rings to unlock the landing pads" msgstr "" -#: src/Menu.cpp:244 -msgid "unlock the landing pads" -msgstr "" - -#: src/Game.cpp:614 -msgid "Press SPACE to continue" -msgstr "Press SPACE to continue" - -#: src/Game.cpp:674 -msgid "Land now" -msgstr "Land now" - -#: src/Game.cpp:682 -#, c-format -msgid "Score: %d" -msgstr "Score: %d" - -#: src/Game.cpp:700 -#, c-format -msgid "Level %d" -msgstr "Level %d" - -#: src/Game.cpp:721 -msgid "Paused" -msgstr "Paused" - -#: src/Main.cpp:100 -#, c-format -msgid "Runtime Error: %s\n" -msgstr "Runtime Error: %s\n" - #~ msgid "LUNAR LANDER" #~ msgstr "LUNAR LANDER" diff --git a/po/lander.pot b/po/lander.pot index 6b4441b..607a48e 100644 --- a/po/lander.pot +++ b/po/lander.pot @@ -6,9 +6,9 @@ #, fuzzy msgid "" msgstr "" -"Project-Id-Version: PACKAGE VERSION\n" +"Project-Id-Version: lander 0.3\n" "Report-Msgid-Bugs-To: nick@cakesniffer.co.uk\n" -"POT-Creation-Date: 2008-06-04 12:05+0100\n" +"POT-Creation-Date: 2008-06-13 22:08+0100\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -16,82 +16,86 @@ msgstr "" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" -#: src/HighScores.cpp:180 -msgid "Press SPACE or FIRE to return" +#: src/Main.cpp:114 +#, c-format +msgid "Runtime Error: %s\n" msgstr "" -#: src/HighScores.cpp:198 -msgid "Well done - You got a high score" +#: src/Game.cpp:616 +msgid "Press SPACE to continue" msgstr "" -#: src/HighScores.cpp:208 -msgid "Press ENTER or FIRE to continue" +#: src/Game.cpp:674 +msgid "Land now" msgstr "" -#: src/HighScores.cpp:217 +#: src/Game.cpp:680 #, c-format -msgid "Name? %s" +msgid "Score: %d" msgstr "" -#: src/Menu.cpp:235 -msgid "Use the arrow keys to rotate the ship" +#: src/Game.cpp:695 +#, c-format +msgid "Level %d" msgstr "" -#: src/Menu.cpp:236 -msgid "Press the up arrow to fire the thruster" +#: src/Game.cpp:714 +msgid "Paused" msgstr "" -#: src/Menu.cpp:237 -msgid "Smaller landing pads give you more points" +#: src/HighScores.cpp:177 +msgid "Press SPACE or FIRE to return" msgstr "" -#: src/Menu.cpp:238 -msgid "Press P to pause the game" +#: src/HighScores.cpp:192 +msgid "Well done - You got a high score" msgstr "" -#: src/Menu.cpp:239 -msgid "Press escape to self destruct" +#: src/HighScores.cpp:197 +msgid "Press ENTER or FIRE to continue" +msgstr "" + +#: src/HighScores.cpp:202 +#, c-format +msgid "Name? %s" msgstr "" -#: src/Menu.cpp:241 -msgid "You can only land safely when the" +#: src/Options.cpp:213 +msgid "Use UP and DOWN to select options" msgstr "" -#: src/Menu.cpp:242 -msgid "speed bar is green" +#: src/Options.cpp:218 +msgid "Use LEFT and RIGHT to change values" msgstr "" -#: src/Menu.cpp:243 -msgid "Collect the spinning rings to" +#: src/Options.cpp:223 +msgid "Press FIRE or RETURN to exit" msgstr "" #: src/Menu.cpp:244 -msgid "unlock the landing pads" +msgid "Use the arrow keys to rotate the ship" msgstr "" -#: src/Game.cpp:614 -msgid "Press SPACE to continue" +#: src/Menu.cpp:245 +msgid "Press the up arrow to fire the thruster" msgstr "" -#: src/Game.cpp:674 -msgid "Land now" +#: src/Menu.cpp:246 +msgid "Smaller landing pads give you more points" msgstr "" -#: src/Game.cpp:682 -#, c-format -msgid "Score: %d" +#: src/Menu.cpp:247 +msgid "Press P to pause the game" msgstr "" -#: src/Game.cpp:700 -#, c-format -msgid "Level %d" +#: src/Menu.cpp:248 +msgid "Press escape to self destruct" msgstr "" -#: src/Game.cpp:721 -msgid "Paused" +#: src/Menu.cpp:249 +msgid "You can only land safely when then speed bar is green" msgstr "" -#: src/Main.cpp:100 -#, c-format -msgid "Runtime Error: %s\n" +#: src/Menu.cpp:250 +msgid "Collect the spinning rings to unlock the landing pads" msgstr "" diff --git a/src/Main.cpp b/src/Main.cpp index 268d654..e3b9171 100644 --- a/src/Main.cpp +++ b/src/Main.cpp @@ -23,6 +23,43 @@ #include +static MainMenu *menu = NULL; +static Game *game = NULL; +static HighScores *scores = NULL; +static Options *options = NULL; + +static void DestroyScreens() +{ + ScreenManager::GetInstance().RemoveAllScreens(); + if (menu) + delete menu; + if (game) + delete game; + if (scores) + delete scores; + if (options) + delete options; +} + +/* + * Recreate all the screens. After a resolution switch for + * example. + */ +void RecreateScreens() +{ + DestroyScreens(); + + menu = new MainMenu(); + game = new Game(); + scores = new HighScores(); + options = new Options(); + + ScreenManager &sm = ScreenManager::GetInstance(); + sm.AddScreen("MAIN MENU", menu); + sm.AddScreen("GAME", game); + sm.AddScreen("HIGH SCORES", scores); + sm.AddScreen("OPTIONS", options); +} /* * Entry point. @@ -62,27 +99,13 @@ int main(int argc, char **argv) OpenGL &opengl = OpenGL::GetInstance(); opengl.Init(width, height, depth, fullscreen); - // Create screens - MainMenu *mm = new MainMenu(); - Game *g = new Game(); - HighScores *hs = new HighScores(); - Options *opt = new Options(); - - ScreenManager &sm = ScreenManager::GetInstance(); - sm.AddScreen("MAIN MENU", mm); - sm.AddScreen("GAME", g); - sm.AddScreen("HIGH SCORES", hs); - sm.AddScreen("OPTIONS", opt); - + RecreateScreens(); + // Run the game - sm.SelectScreen("MAIN MENU"); + ScreenManager::GetInstance().SelectScreen("MAIN MENU"); opengl.Run(); - - sm.RemoveAllScreens(); - delete mm; - delete g; - delete hs; - delete opt; + + DestroyScreens(); } catch (std::runtime_error e) { #ifdef WIN32 diff --git a/src/Makefile.am b/src/Makefile.am index 44aee26..2f0679c 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -2,7 +2,7 @@ bin_PROGRAMS = lander AM_CXXFLAGS=$(LANDER_CFLAGS) $(SDL_CFLAGS) -Wall AM_LDFLAGS=$(LANDER_LIBS) $(SDL_LIBS) -lGLU $(LTLIBINTL) -lander_SOURCES = Main.cpp Lander.hpp Game.cpp \ +lander_SOURCES = Main.cpp Game.hpp Game.cpp \ Font.cpp Font.hpp HighScores.cpp HighScores.hpp Input.cpp \ Input.hpp Platform.hpp LoadOnce.hpp \ OpenGL.cpp OpenGL.hpp Menu.cpp Menu.hpp Emitter.cpp \ diff --git a/src/OpenGL.cpp b/src/OpenGL.cpp index 6454575..a600c89 100644 --- a/src/OpenGL.cpp +++ b/src/OpenGL.cpp @@ -22,7 +22,7 @@ #include "ScreenManager.hpp" OpenGL::OpenGL() - : screen_width(0), screen_height(0), screen_depth(0), + : screen_width(0), screen_height(0), fullscreen(false), running(false), active(true), dodisplay(true), fps_lastcheck(0), fps_framesdrawn(0), fps_rate(0) @@ -46,31 +46,17 @@ OpenGL &OpenGL::GetInstance() * necessary initialisation. */ void OpenGL::Init(int width, int height, int depth, bool fullscreen) -{ - // Store parameters - screen_height = height; - screen_width = width; - screen_depth = depth; - this->fullscreen = fullscreen; - +{ // Start SDL if (SDL_Init(SDL_INIT_VIDEO) < 0) RuntimeError("Unable to initialise SDL: " + SDLErrorString()); atexit(SDL_Quit); - int flags = SDL_OPENGL; - if (fullscreen) - flags |= SDL_FULLSCREEN; + SetVideoMode(fullscreen, width, height); - SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); - if (SDL_SetVideoMode(screen_width, screen_height, 0, flags) == NULL) - RuntimeError("Unable to create OpenGL screen: " + SDLErrorString());; - SDL_WM_SetCaption(WINDOW_TITLE, NULL); SDL_ShowCursor(SDL_DISABLE); - - ResizeGLScene(screen_width, screen_height); // Start OpenGL if (!InitGL()) @@ -82,6 +68,27 @@ void OpenGL::RuntimeError(string mess) throw runtime_error(mess); } +bool OpenGL::SetVideoMode(bool fullscreen, int width, int height) +{ + bool resized = !(width == screen_width && height == screen_height); + + screen_height = height; + screen_width = width; + this->fullscreen = fullscreen; + + sdl_flags = SDL_OPENGL; + if (fullscreen) + sdl_flags |= SDL_FULLSCREEN; + + SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1); + if (SDL_SetVideoMode(screen_width, screen_height, 0, sdl_flags) == NULL) + RuntimeError("Unable to create OpenGL screen: " + SDLErrorString());; + + ResizeGLScene(screen_width, screen_height); + + return resized; +} + /* * Return the last SDL error as a C++ string. */ diff --git a/src/OpenGL.hpp b/src/OpenGL.hpp index 976b808..b6e8fda 100644 --- a/src/OpenGL.hpp +++ b/src/OpenGL.hpp @@ -108,6 +108,8 @@ public: int GetWidth() const { return screen_width; } int GetHeight() const { return screen_height; } + + bool SetVideoMode(bool fullscreen, int width, int height); bool IsTextureSizeSupported(int width, int height, int ncols=4, GLenum format=GL_RGBA); @@ -127,9 +129,10 @@ private: void RuntimeError(string mess); // Window related variables - int screen_width, screen_height, screen_depth; + int screen_width, screen_height; bool fullscreen; bool running, active, dodisplay; + int sdl_flags; // Frame rate variables int fps_lastcheck, fps_framesdrawn, fps_rate; diff --git a/src/Options.cpp b/src/Options.cpp index 398997d..6893147 100644 --- a/src/Options.cpp +++ b/src/Options.cpp @@ -108,18 +108,29 @@ void Options::ProcessMain() void Options::Apply() { + int hres = 0, vres = 0; + bool fullscreen = false; + for (ItemListIt it = items.begin(); it != items.end(); ++it) { if ((*it).name == "Fullscreen") { - cfile.put("fullscreen", (*it).active == 0); + fullscreen = (*it).active == 0; + + cfile.put("fullscreen", fullscreen); } if ((*it).name == "Resolution") { - int hres, vres; ParseResolutionString((*it).values[(*it).active], &hres, &vres); cfile.put("hres", hres); cfile.put("vres", vres); } } + + assert(hres > 0 && vres > 0); + + if (OpenGL::GetInstance().SetVideoMode(fullscreen, hres, vres)) { + // This *must* be the very last thing that is done! + RecreateScreens(); + } } void Options::ProcessFadeOut() diff --git a/src/Platform.hpp b/src/Platform.hpp index e88af4f..3ec7d58 100644 --- a/src/Platform.hpp +++ b/src/Platform.hpp @@ -150,6 +150,7 @@ using namespace std; #endif /* #ifdef LANDER_BIG_ENDIAN */ +void RecreateScreens(); const char *LocateResource(const char *file); bool FileExists(const char *file); string GetConfigDir(); -- 2.39.2