From 2ffdd9d5ca80ad16c4e2223ffa5c0d1e0cd00c78 Mon Sep 17 00:00:00 2001 From: pouillot Date: Sun, 28 Feb 2010 15:12:52 +0000 Subject: [PATCH] Fixed infinite loop in splash when image not found + code cleanup git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@2277 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: dd5aceafd3d35723a4d03eb8c8b4c1cb15e520cd Former-commit-id: f779b01298d4b779151d3943f75b14cdc53113c0 --- cmake/macros.cmake | 3 ++- src/libs/client/client.h | 7 +------ src/libs/client/entry.cpp | 17 ++++++++--------- src/libs/client/splash.cpp | 17 +++++++++-------- src/libs/client/splash.h | 6 +----- src/libs/tgf/params.cpp | 4 ++-- src/libs/tgfclient/gui.h | 1 + src/libs/tgfclient/tgfclient.cpp | 7 +------ src/linux/main.cpp | 11 +++++++---- src/windows/main.cpp | 13 ++++++++----- 10 files changed, 40 insertions(+), 46 deletions(-) diff --git a/cmake/macros.cmake b/cmake/macros.cmake index 77c289c40..45b3171dd 100644 --- a/cmake/macros.cmake +++ b/cmake/macros.cmake @@ -5,9 +5,10 @@ ENDIF(NOT DEFINED IN_SOURCETREE) IF(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) IF(WIN32) SET(CMAKE_INSTALL_PREFIX "C:/Program files/speed-dreams-dev" CACHE PATH "Prefix prepended to install directories" FORCE) - ELSE() + ELSE() SET(CMAKE_INSTALL_PREFIX "/usr/local/dev" CACHE PATH "Prefix prepended to install directories" FORCE) ENDIF() + MESSAGE(STATUS "Default install prefix : $CMAKE_INSTALL_PREFIX") ENDIF(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) IF(NOT SOURCE_DIR AND IN_SOURCETREE) diff --git a/src/libs/client/client.h b/src/libs/client/client.h index 3c700597b..aff712b95 100644 --- a/src/libs/client/client.h +++ b/src/libs/client/client.h @@ -21,12 +21,7 @@ #ifndef _CLIENT_H_ #define _CLIENT_H_ -#if _WIN32 -#include -#endif - - -extern void GameEntry(void); +extern bool GameEntry(void); #endif /* _CLIENT_H_ */ diff --git a/src/libs/client/entry.cpp b/src/libs/client/entry.cpp index 65b640b53..bc32379a1 100644 --- a/src/libs/client/entry.cpp +++ b/src/libs/client/entry.cpp @@ -18,8 +18,7 @@ ***************************************************************************/ -#include "client.h" -#include "mainmenu.h" +#include "tgfclient.h" #include "splash.h" /* @@ -27,23 +26,23 @@ * GameEntry * * Description - * entry point of the game + * Entry point of the game. * * Parameters - * none + * None * * Return - * none + * true on success, false in anything bad happened. * * Remarks * */ -void +bool GameEntry(void) { - // Initialize gaming framework. + // Initialize gaming framework. GfInitClient(); - // Open the splash screen, load menus in "backgroud" and finally open the main menu. - SplashScreen(); + // Open the splash screen, load menus in "backgroud" and finally open the main menu. + return SplashScreen(); } diff --git a/src/libs/client/splash.cpp b/src/libs/client/splash.cpp index e205c1ce6..7bdb9556d 100644 --- a/src/libs/client/splash.cpp +++ b/src/libs/client/splash.cpp @@ -240,28 +240,29 @@ static void splashMouse(int /* b */, int s, int /* x */, int /* y */) /* * Function - * + * SplashScreen * * Description - * + * Display the splash screen and load the main menus in the background. + * On mouse click or 7 second time-out, open the main menu. * * Parameters - * + * None * * Return - * + * true on success, false in anything bad happened. * * Remarks * */ -int SplashScreen(void) +bool SplashScreen(void) { void *handle; float screen_gamma; //const char *filename = "data/img/splash.png"; const char *filename = "data/img/splash.jpg"; - if (s_texture != 0) + if (s_texture) { glDeleteTextures(1, &s_texture); } @@ -276,7 +277,7 @@ int SplashScreen(void) { GfParmReleaseHandle(handle); GfTrace("Couldn't load splash screen image %s\n", filename); - return -1; + return false; } glGenTextures(1, &s_texture); @@ -294,6 +295,6 @@ int SplashScreen(void) sdlMouseFunc(splashMouse); sdlIdleFunc(splashIdle); - return 0; + return true; } diff --git a/src/libs/client/splash.h b/src/libs/client/splash.h index dc3d92d50..b12787123 100644 --- a/src/libs/client/splash.h +++ b/src/libs/client/splash.h @@ -21,11 +21,7 @@ #ifndef _SPLASH_H_ #define _SPLASH_H_ -#if _WIN32 -#include -#endif - -extern int SplashScreen(void); +extern bool SplashScreen(void); #endif /* _SPLASH_H_ */ diff --git a/src/libs/tgf/params.cpp b/src/libs/tgf/params.cpp index 5cb7f6167..18b818084 100644 --- a/src/libs/tgf/params.cpp +++ b/src/libs/tgf/params.cpp @@ -1627,10 +1627,10 @@ GfParmWriteFile (const char *file, void *parmHandle, const char *name) fputs (line, fout); } - GfOut ("GfParmWriteFile: %s file written\n", file); - fclose (fout); + GfOut ("Wrote %s (%p)\n", file, parmHandle); + return 0; } diff --git a/src/libs/tgfclient/gui.h b/src/libs/tgfclient/gui.h index a091c3ac9..325a8a3b2 100644 --- a/src/libs/tgfclient/gui.h +++ b/src/libs/tgfclient/gui.h @@ -19,6 +19,7 @@ #ifndef _GUI_H__ #define _GUI_H__ +#include "tgfclient.h" #include "guifont.h" #define GFUI_COLORNB 26 diff --git a/src/libs/tgfclient/tgfclient.cpp b/src/libs/tgfclient/tgfclient.cpp index 4112fcab9..4ed7927d9 100644 --- a/src/libs/tgfclient/tgfclient.cpp +++ b/src/libs/tgfclient/tgfclient.cpp @@ -16,13 +16,8 @@ * * ***************************************************************************/ -#ifdef WIN32 -#include -#endif -#include "tgfclient.h" -#include - #include "gui.h" +#include "tgfclient.h" extern void gfScreenInit(void); extern void gfMenuInit(void); diff --git a/src/linux/main.cpp b/src/linux/main.cpp index ebe90a3b8..ba6e2ae06 100644 --- a/src/linux/main.cpp +++ b/src/linux/main.cpp @@ -133,10 +133,13 @@ main(int argc, char *argv[]) GfScrInit(argc, argv); /* init screen */ - GameEntry(); /* launch the game */ + if (GameEntry()) /* launch the game */ + { + sdlMainLoop(); /* Main event loop */ + exit(0); + } - sdlMainLoop(); /* SDL event loop */ - - return 0; /* just for the compiler, never reached */ + GfError("\nExiting from Speed Dreams for some fatal reason (see above).\n"); + exit(1); /* If we got here, something bad happened ... */ } diff --git a/src/windows/main.cpp b/src/windows/main.cpp index 3e86d8a37..33e7bf19f 100644 --- a/src/windows/main.cpp +++ b/src/windows/main.cpp @@ -180,10 +180,13 @@ main(int argc, char *argv[]) GfScrInit(argc, argv); /* init screen */ - GameEntry(); /* launch the game */ - - sdlMainLoop(); /* event loop of sdl */ - - return 0; /* just for the compiler, never reached */ + if (GameEntry()) /* launch the game */ + { + sdlMainLoop(); /* Main event loop */ + exit(0); + } + + GfError("\nExiting from Speed Dreams for some fatal reason (see above).\n"); + exit(1); /* If we got here, something bad happened ... */ }