Merge branch 'master' into releases releases 3.3.1.2
authorHolger Schemel <info@artsoft.org>
Sat, 30 Aug 2014 09:00:08 +0000 (11:00 +0200)
committerHolger Schemel <info@artsoft.org>
Sat, 30 Aug 2014 09:00:08 +0000 (11:00 +0200)
17 files changed:
ChangeLog
Makefile
src/Makefile
src/config.c
src/conftime.h
src/init.c
src/init.h
src/libgame/macosx.h
src/libgame/misc.c
src/libgame/setup.c
src/libgame/setup.h
src/libgame/system.c
src/libgame/system.h
src/libgame/text.c
src/libgame/text.h
src/main.c
src/main.h

index 7c0df045a9aab7d623ae4bed7943153989c02937..2469c878cf229ac1e4e1ef9df49af90d5bbb3ed7 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,22 @@
+2013-11-24
+       * version 3.3.1.2 released
+
+2013-11-20
+       * improved error handling: display error message on screen (not only in
+         the error file or on the console), and display path of the error file
+
+2013-11-13
+       * fixed problem with R'n'D restarting with same level set that may have
+         caused a problem (and therefore failing again and again); after an
+         error, the last level set is now deactivated in file "levelsetup.conf"
+         to restart with default level set (which should work without error)
+
+2013-11-07
+       * fixed determining main game data directory on Mac OS X "Mavericks"
+
+2013-11-04
+       * version number set to 3.3.1.2
+
 2013-11-04
        * version 3.3.1.1 released
 
index b2d8476cd80dbc66d9193cbdc80a685c80bfce99..8a51c93a811025640d07da5f7ae7622a3483046f 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -143,7 +143,7 @@ backup:
 backup-net-copy:
        ./Scripts/make_backup.sh src scp
 
-backup-net: backup backup-net-copy
+backup-all: backup backup-net-copy
 
 backup_lev:
        ./Scripts/make_backup.sh lev
index 853c415baba744c7f14e357977e28b1d5f9c452e..a67cd14c4be5ef0159e110b809cc2ccfb162c1a9 100644 (file)
@@ -327,13 +327,13 @@ clean: clean-obj clean-ico clean-bin
 # run and test targets
 # -----------------------------------------------------------------------------
 
-run: all
+run:
        cd .. && ./$(PROGBASE) --verbose
 
-gdb: all
+gdb:
        cd .. && gdb -batch -x GDB_COMMANDS ./$(PROGBASE)
 
-valgrind: all
+valgrind:
        cd .. && valgrind -v --leak-check=yes ./$(PROGBASE) 2> valgrind.out
 
 
index c812adfdbfd148588e2f4af3727e4b99d9e3cb6c..bb1c6ee4a7d1154a0e2fce8295394088e934332c 100644 (file)
@@ -71,15 +71,27 @@ char *getProgramInitString()
 {
   static char *program_init_string = NULL;
 
+#if 1
+  // do not display compile target anymore, as it is almost always "SDL" now
   if (program_init_string == NULL)
   {
     program_init_string = checked_malloc(strlen(PROGRAM_TITLE_STRING) + 1 +
-                                        strlen(getProgramVersionString()) +1 +
+                                        strlen(getProgramVersionString()) + 1);
+
+    sprintf(program_init_string, "%s %s",
+           PROGRAM_TITLE_STRING, getProgramVersionString());
+  }
+#else
+  if (program_init_string == NULL)
+  {
+    program_init_string = checked_malloc(strlen(PROGRAM_TITLE_STRING) + 1 +
+                                        strlen(getProgramVersionString()) + 1 +
                                         strlen(TARGET_STRING) + 1);
 
     sprintf(program_init_string, "%s %s %s",
            PROGRAM_TITLE_STRING, getProgramVersionString(), TARGET_STRING);
   }
+#endif
 
   return program_init_string;
 }
index f0fbdec7b7202491d24a6a0c2a7f33d4e87e3665..fd1449b6c20b8a12a10f8244736110d080c73dbd 100644 (file)
@@ -1 +1 @@
-#define COMPILE_DATE_STRING "2013-11-04 00:44"
+#define COMPILE_DATE_STRING "2013-11-24 14:05"
index f176e13e37537924810553446e64f5d0609bf9ac..a7ad871bdd019d4735d66077a01e15b24fbebabd 100644 (file)
@@ -6274,6 +6274,59 @@ void KeyboardAutoRepeatOffUnlessAutoplay()
     KeyboardAutoRepeatOff();
 }
 
+void DisplayExitMessage(char *format, va_list ap)
+{
+  int font_1 = FC_RED;
+  int font_2 = FC_YELLOW;
+  int font_3 = FC_BLUE;
+  int font_width = getFontWidth(font_2);
+  int font_height = getFontHeight(font_2);
+  int sx = SX;
+  int sy = SY;
+  int sxsize = WIN_XSIZE - 2 * sx;
+  int sysize = WIN_YSIZE - 2 * sy;
+  int line_length = sxsize / font_width;
+  int max_lines = sysize / font_height;
+  int num_lines_printed;
+
+  gfx.sx = sx;
+  gfx.sy = sy;
+  gfx.sxsize = sxsize;
+  gfx.sysize = sysize;
+
+  sy = 20;
+
+  ClearRectangle(drawto, 0, 0, WIN_XSIZE, WIN_YSIZE);
+
+  DrawTextSCentered(sy, font_1, "Fatal error:");
+  sy += 3 * font_height;;
+
+  num_lines_printed =
+    DrawTextBufferVA(sx, sy, format, ap, font_2,
+                    line_length, line_length, max_lines,
+                    0, BLIT_ON_BACKGROUND, TRUE, TRUE, FALSE);
+  sy += (num_lines_printed + 3) * font_height;
+
+  DrawTextSCentered(sy, font_1, "For details, see the following error file:");
+  sy += 3 * font_height;
+
+  num_lines_printed =
+    DrawTextBuffer(sx, sy, program.error_filename, font_2,
+                  line_length, line_length, max_lines,
+                  0, BLIT_ON_BACKGROUND, TRUE, TRUE, FALSE);
+
+  DrawTextSCentered(SYSIZE - 20, font_3, "Press any key or button to exit");
+
+  redraw_mask = REDRAW_ALL;
+
+  BackToFront();
+
+  /* deactivate toons on error message screen */
+  setup.toons = FALSE;
+
+  WaitForEventToContinue();
+}
+
 
 /* ========================================================================= */
 /* OpenAll()                                                                 */
@@ -6440,7 +6493,14 @@ void CloseAllAndExit(int exit_value)
   ClosePlatformDependentStuff();
 
   if (exit_value != 0)
-    NotifyUserAboutErrorFile();
+  {
+    /* fall back to default level set (current set may have caused an error) */
+    SaveLevelSetup_LastSeries_Deactivate();
+
+    /* tell user where to find error log file which may contain more details */
+    // (error notification now directly displayed on screen inside R'n'D
+    // NotifyUserAboutErrorFile();     /* currently only works for Windows */
+  }
 
   exit(exit_value);
 }
index 42bc9f740525d79035a0abfdd5c8bbb1d6297b1a..d52aef4d9dce3fc139040d1b485bc6b51f4541fa 100644 (file)
@@ -46,6 +46,8 @@ void KeyboardAutoRepeatOffUnlessAutoplay();
 void InitGfxBuffers();
 void InitGadgets();
 
+void DisplayExitMessage(char *, va_list);
+
 void OpenAll(void);
 void CloseAllAndExit(int);
 
index c4818e76a4d3448c15e785b2a76ca5f56988f454..ddd9d4b14d8d14dda0bf8a00672f765e15cd198c 100644 (file)
 #define MACOSX_H
 
 
+/* define some Mac OS X specific paths */
+
+#define MAC_APP_BINARY_SUBDIR  "Contents/MacOS"
+
+
 /* some symbols are already defined on Mac OS X */
 #define Delay Delay_internal
 #define DrawLine DrawLine_internal
index 60dbcf068c20e9d84a29a6d4de15356d1ce15892..c196fe81d67703ca76620463d06a9ead7eff20df 100644 (file)
@@ -564,6 +564,36 @@ char *getBasePath(char *filename)
   return basepath;
 }
 
+static char *getProgramMainDataPath()
+{
+  char *main_data_path = getStringCopy(program.command_basepath);
+
+#if defined(PLATFORM_MACOSX)
+  static char *main_data_binary_subdir = NULL;
+
+  if (main_data_binary_subdir == NULL)
+  {
+    main_data_binary_subdir = checked_malloc(strlen(program.program_title) + 1 +
+                                            strlen("app") + 1 +
+                                            strlen(MAC_APP_BINARY_SUBDIR) + 1);
+
+    sprintf(main_data_binary_subdir, "%s.app/%s",
+           program.program_title, MAC_APP_BINARY_SUBDIR);
+  }
+
+  // cut relative path to Mac OS X application binary directory from path
+  if (strSuffix(main_data_path, main_data_binary_subdir))
+    main_data_path[strlen(main_data_path) -
+                  strlen(main_data_binary_subdir)] = '\0';
+
+  // cut trailing path separator from path (but not if path is root directory)
+  if (strSuffix(main_data_path, "/") && !strEqual(main_data_path, "/"))
+    main_data_path[strlen(main_data_path) - 1] = '\0';
+#endif
+
+  return main_data_path;
+}
+
 
 /* ------------------------------------------------------------------------- */
 /* various string functions                                                  */
@@ -721,6 +751,18 @@ void GetOptions(char *argv[], void (*print_usage_function)(void))
   char *rw_base_path = RW_BASE_PATH;
   char **options_left = &argv[1];
 
+#if 1
+  /* if the program is configured to start from current directory (default),
+     determine program package directory from program binary (some versions
+     of KDE/Konqueror and Mac OS X (especially "Mavericks") apparently do not
+     set the current working directory to the program package directory) */
+
+  if (strEqual(ro_base_path, "."))
+    ro_base_path = getProgramMainDataPath();
+  if (strEqual(rw_base_path, "."))
+    rw_base_path = getProgramMainDataPath();
+#else
+
 #if !defined(PLATFORM_MACOSX)
   /* if the program is configured to start from current directory (default),
      determine program package directory (KDE/Konqueror does not do this by
@@ -732,6 +774,8 @@ void GetOptions(char *argv[], void (*print_usage_function)(void))
     ro_base_path = program.command_basepath;
   if (strEqual(rw_base_path, "."))
     rw_base_path = program.command_basepath;
+#endif
+
 #endif
 
   /* initialize global program options */
@@ -963,9 +1007,11 @@ void Error(int mode, char *format, ...)
   static boolean last_line_was_separator = FALSE;
   char *process_name = "";
 
+#if 1
   /* display warnings only when running in verbose mode */
   if (mode & ERR_WARN && !options.verbose)
     return;
+#endif
 
   if (mode == ERR_INFO_LINE)
   {
@@ -999,6 +1045,13 @@ void Error(int mode, char *format, ...)
     va_start(ap, format);
     vfprintf_newline(program.error_file, format, ap);
     va_end(ap);
+
+    if ((mode & ERR_EXIT) && !(mode & ERR_FROM_SERVER))
+    {
+      va_start(ap, format);
+      program.exit_message_function(format, ap);
+      va_end(ap);
+    }
   }
   
   if (mode & ERR_HELP)
index 246e3891f486e44cdfb1abf58c60be87d7e3e593..ac5b78d0ce7c7d2044268c1a132c376d6a053ebf 100644 (file)
@@ -3951,7 +3951,7 @@ void LoadLevelSetup_LastSeries()
   free(filename);
 }
 
-void SaveLevelSetup_LastSeries()
+static void SaveLevelSetup_LastSeries_Ext(boolean deactivate_last_level_series)
 {
   /* ----------------------------------------------------------------------- */
   /* ~/.<program>/levelsetup.conf                                            */
@@ -3972,6 +3972,10 @@ void SaveLevelSetup_LastSeries()
 
   fprintf(file, "%s\n\n", getFormattedSetupEntry(TOKEN_STR_FILE_IDENTIFIER,
                                                 getCookie("LEVELSETUP")));
+
+  if (deactivate_last_level_series)
+    fprintf(file, "# %s\n# ", "the following level set may have caused a problem and was deactivated");
+
   fprintf(file, "%s\n", getFormattedSetupEntry(TOKEN_STR_LAST_LEVEL_SERIES,
                                               level_subdir));
 
@@ -3982,6 +3986,16 @@ void SaveLevelSetup_LastSeries()
   free(filename);
 }
 
+void SaveLevelSetup_LastSeries()
+{
+  SaveLevelSetup_LastSeries_Ext(FALSE);
+}
+
+void SaveLevelSetup_LastSeries_Deactivate()
+{
+  SaveLevelSetup_LastSeries_Ext(TRUE);
+}
+
 static void checkSeriesInfo()
 {
   static char *level_directory = NULL;
index c667c348b38304164c924697ce86bcb8ba60dab8..61316bbd587940d6864d217c9b44586f5659f797 100644 (file)
@@ -317,6 +317,7 @@ void LoadLevelArtworkInfo(void);
 
 void LoadLevelSetup_LastSeries(void);
 void SaveLevelSetup_LastSeries(void);
+void SaveLevelSetup_LastSeries_Deactivate();
 void LoadLevelSetup_SeriesInfo(void);
 void SaveLevelSetup_SeriesInfo(void);
 
index 51e8df8905b2a0f1e70e6a43e92bb0a12c5c9174..6d99c7c8cd11f346fb9bbe63f92cb735b114c958 100644 (file)
@@ -105,6 +105,11 @@ void InitProgramInfo(char *argv0,
   program.error_file = stderr;
 }
 
+void InitExitMessageFunction(void (*exit_message_function)(char *, va_list))
+{
+  program.exit_message_function = exit_message_function;
+}
+
 void InitExitFunction(void (*exit_function)(int))
 {
   program.exit_function = exit_function;
@@ -129,9 +134,13 @@ void InitPlatformDependentStuff(void)
   updateUserGameDataDir();
 #endif
 
+#if 1
+  openErrorFile();
+#else
 #if !defined(PLATFORM_UNIX) || defined(PLATFORM_MACOSX)
   openErrorFile();
 #endif
+#endif
 
 #if defined(TARGET_SDL)
   if (SDL_Init(SDL_INIT_EVENTTHREAD | SDL_INIT_NOPARACHUTE) < 0)
index 98225eae1d4c4bff71a029823facd8bdae9a98e4..5c1976917b04dd8c44d6790ec709fbddd1884645 100644 (file)
@@ -651,9 +651,11 @@ typedef int (*EventFilter)(const Event *);
 
 struct ProgramInfo
 {
-  char *command_basepath;      /* directory that contains the program */
+  char *command_basepath;      /* path to the program binary */
   char *command_basename;      /* base filename of the program binary */
 
+  char *maindata_path;         /* main game data (installation) directory */
+
   char *userdata_subdir;       /* personal user game data directory */
   char *userdata_subdir_unix;  /* personal user game data directory (Unix) */
   char *userdata_path;         /* resulting full path to game data directory */
@@ -677,6 +679,7 @@ struct ProgramInfo
   int version_minor;
   int version_patch;
 
+  void (*exit_message_function)(char *, va_list);
   void (*exit_function)(int);
 };
 
@@ -1228,6 +1231,7 @@ extern int                        FrameCounter;
 void InitProgramInfo(char *, char *, char *, char *, char *, char *, char *,
                     char *, char *, char *, char *, char *, int);
 
+void InitExitMessageFunction(void (*exit_message_function)(char *, va_list));
 void InitExitFunction(void (*exit_function)(int));
 void InitPlatformDependentStuff(void);
 void ClosePlatformDependentStuff(void);
index 9d4d119300833f774017527494c7ef8b6343639c..dd926f62350be231f77e5640aea4d88d2b6b4dd5 100644 (file)
@@ -947,6 +947,24 @@ int DrawTextBuffer(int x, int y, char *text_buffer, int font_nr,
   return current_line;
 }
 
+int DrawTextBufferVA(int x, int y, char *format, va_list ap, int font_nr,
+                    int line_length, int cut_length, int max_lines,
+                    int line_spacing, int mask_mode, boolean autowrap,
+                    boolean centered, boolean parse_comments)
+{
+  char text_buffer[MAX_OUTPUT_LINESIZE];
+  int text_length = vsnprintf(text_buffer, MAX_OUTPUT_LINESIZE, format, ap);
+
+  if (text_length >= MAX_OUTPUT_LINESIZE)
+    Error(ERR_WARN, "string too long in DrawTextBufferVA() -- truncated");
+
+  int num_lines_printed = DrawTextBuffer(x, y, text_buffer, font_nr,
+                                        line_length, cut_length, max_lines,
+                                        line_spacing, mask_mode, autowrap,
+                                        centered, parse_comments);
+  return num_lines_printed;
+}
+
 int DrawTextFile(int x, int y, char *filename, int font_nr,
                 int line_length, int cut_length, int max_lines,
                 int line_spacing, int mask_mode, boolean autowrap,
index 1d54a716d22d64b47eae590f88b9ed39a35cafea..17d350a0210cef008e061780d64233dfe4d26e5f 100644 (file)
@@ -91,6 +91,8 @@ void DrawTextExt(DrawBuffer *, int, int, char *, int, int);
 char *GetTextBufferFromFile(char *, int);
 int DrawTextBuffer(int, int, char *, int, int, int, int, int, int,
                   boolean, boolean, boolean);
+int DrawTextBufferVA(int, int, char *, va_list, int, int, int, int, int, int,
+                    boolean, boolean, boolean);
 int DrawTextFile(int, int, char *, int, int, int, int, int, int,
                 boolean, boolean, boolean);
 
index 94c5c3ace7cdc47034b96f86ae1989d38d4545d1..aaa3a5ba9b93412d8aeb104e3e48929611747fe8 100644 (file)
@@ -5594,6 +5594,7 @@ int main(int argc, char *argv[])
                  MSDOS_POINTER_FILENAME,
                  COOKIE_PREFIX, FILENAME_PREFIX, GAME_VERSION_ACTUAL);
 
+  InitExitMessageFunction(DisplayExitMessage);
   InitExitFunction(CloseAllAndExit);
   InitPlatformDependentStuff();
 
index 738e39b9b51b60d43e12666bb36b5c9dfdedab43..a35337cf185d04b1d05ee347b26a99938e36c461 100644 (file)
 #define PROGRAM_VERSION_MAJOR          3
 #define PROGRAM_VERSION_MINOR          3
 #define PROGRAM_VERSION_PATCH          1
-#define PROGRAM_VERSION_BUILD          1
+#define PROGRAM_VERSION_BUILD          2
 
 #define PROGRAM_TITLE_STRING           "Rocks'n'Diamonds"
 #define PROGRAM_AUTHOR_STRING          "Holger Schemel"