rnd-20131209-1-src
[rocksndiamonds.git] / src / init.c
index e239da9d81b38be5b0566c32ac860188fcc9ce23..c2344a507175af8ce42059a4d563ca8c35cada54 100644 (file)
@@ -39,7 +39,7 @@
 #define CONFIG_TOKEN_GLOBAL_BUSY               "global.busy"
 
 #define DEBUG_PRINT_INIT_TIMESTAMPS            TRUE
-#define DEBUG_PRINT_INIT_TIMESTAMPS_DEPTH      1
+#define DEBUG_PRINT_INIT_TIMESTAMPS_DEPTH      0
 
 
 static struct FontBitmapInfo font_initial[NUM_INITIAL_FONTS];
@@ -159,8 +159,8 @@ void DrawInitAnim()
 {
   struct GraphicInfo *graphic_info_last = graphic_info;
   int graphic = 0;
-  static unsigned long action_delay = 0;
-  unsigned long action_delay_value = GameFrameDelay;
+  static unsigned int action_delay = 0;
+  unsigned int action_delay_value = GameFrameDelay;
   int sync_frame = FrameCounter;
   int x, y;
 
@@ -175,9 +175,9 @@ void DrawInitAnim()
 
 #if 0
   {
-    static unsigned long last_counter = -1;
-    unsigned long current_counter = Counter();
-    unsigned long delay = current_counter - last_counter;
+    static unsigned int last_counter = -1;
+    unsigned int current_counter = Counter();
+    unsigned int delay = current_counter - last_counter;
 
     if (last_counter != -1 && delay > action_delay_value + 5)
       printf("::: DrawInitAnim: DELAY TOO LONG: %ld\n", delay);
@@ -1857,7 +1857,7 @@ static void InitGraphicInfo()
   static boolean clipmasks_initialized = FALSE;
   Pixmap src_pixmap;
   XGCValues clip_gc_values;
-  unsigned long clip_gc_valuemask;
+  unsigned int clip_gc_valuemask;
   GC copy_clipmask_gc = None;
 #endif
 
@@ -5313,6 +5313,7 @@ void Execute_Command(char *command)
 
 #if DEBUG
 #if defined(TARGET_SDL)
+#if !defined(TARGET_SDL2)
   else if (strEqual(command, "SDL_ListModes"))
   {
     SDL_Rect **modes;
@@ -5347,6 +5348,7 @@ void Execute_Command(char *command)
     exit(0);
   }
 #endif
+#endif
 #endif
 
   else
@@ -6274,6 +6276,63 @@ void KeyboardAutoRepeatOffUnlessAutoplay()
     KeyboardAutoRepeatOff();
 }
 
+void DisplayExitMessage(char *format, va_list ap)
+{
+  // check if draw buffer and fonts for exit message are already available
+  if (drawto == NULL || font_initial[NUM_INITIAL_FONTS - 1].bitmap == NULL)
+    return;
+
+  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()                                                                 */
@@ -6336,7 +6395,7 @@ void OpenAll()
   InitVideoDisplay();
   InitVideoBuffer(WIN_XSIZE, WIN_YSIZE, DEFAULT_DEPTH, setup.fullscreen);
 
-  InitEventFilter(FilterMouseMotionEvents);
+  InitEventFilter(FilterEvents);
 
   print_timestamp_time("[init video stuff]");
 
@@ -6432,15 +6491,28 @@ void CloseAllAndExit(int exit_value)
   FreeAllImages();
 
 #if defined(TARGET_SDL)
+#if defined(TARGET_SDL2)
+  // !!! TODO !!!
+  // set a flag to tell the network server thread to quit and wait for it
+  // using SDL_WaitThread()
+#else
   if (network_server)  /* terminate network server */
     SDL_KillThread(server_thread);
+#endif
 #endif
 
   CloseVideoDisplay();
   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);
 }