/ports/psp/trunk/Source_Files/CSeries/csalerts_sdl.cpp

# · C++ · 178 lines · 100 code · 31 blank · 47 comment · 27 complexity · 56d86c70aa5e50b32fad780d5c916828 MD5 · raw file

  1. /*
  2. Copyright (C) 1991-2001 and beyond by Bungie Studios, Inc.
  3. and the "Aleph One" developers.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. This license is contained in the file "COPYING",
  13. which is included with this source code; it is available online at
  14. http://www.gnu.org/licenses/gpl.html
  15. */
  16. /*
  17. * csalerts_sdl.cpp - Game alerts and debugging support, SDL implementation
  18. *
  19. * Written in 2000 by Christian Bauer
  20. April 22, 2003 (Woody Zenfell):
  21. Now dumping alert text etc. with Logging as well
  22. */
  23. #include "cseries.h"
  24. #include <stdio.h>
  25. #include "Logging.h"
  26. #include "sdl_dialogs.h"
  27. #include "sdl_widgets.h"
  28. /*
  29. * Display alert message
  30. */
  31. const int MAX_ALERT_WIDTH = 320;
  32. extern void update_game_window(void);
  33. void alert_user(const char *message, short severity)
  34. {
  35. if (SDL_GetVideoSurface() == NULL) {
  36. fprintf(stderr, "%s: %s\n", severity == infoError ? "INFO" : "FATAL", message);
  37. } else {
  38. dialog d;
  39. vertical_placer *placer = new vertical_placer;
  40. placer->dual_add(new w_title(severity == infoError ? "WARNING" : "ERROR"), d);
  41. placer->add(new w_spacer, true);
  42. // Wrap lines
  43. uint16 style;
  44. font_info *font = get_theme_font(MESSAGE_WIDGET, style);
  45. char *t = strdup(message);
  46. char *p = t;
  47. while (strlen(t)) {
  48. unsigned i = 0, last = 0;
  49. int width = 0;
  50. while (i < strlen(t) && width < MAX_ALERT_WIDTH) {
  51. width = text_width(t, i, font, style);
  52. if (t[i] == ' ')
  53. last = i;
  54. i++;
  55. }
  56. if (i != strlen(t))
  57. t[last] = 0;
  58. placer->dual_add(new w_static_text(t), d);
  59. if (i != strlen(t))
  60. t += last + 1;
  61. else
  62. t += i;
  63. }
  64. free(p);
  65. placer->add(new w_spacer, true);
  66. w_button *button = new w_button(severity == infoError ? "OK" : "QUIT", dialog_ok, &d);
  67. placer->dual_add (button, d);
  68. d.set_widget_placer(placer);
  69. d.activate_widget(button);
  70. d.run();
  71. if (severity == infoError && top_dialog == NULL)
  72. update_game_window();
  73. }
  74. if (severity != infoError) exit(1);
  75. }
  76. void alert_user(short severity, short resid, short item, OSErr error)
  77. {
  78. char str[256];
  79. getcstr(str, resid, item);
  80. char msg[300];
  81. sprintf(msg, "%s (error %d)", str, error);
  82. if (severity == infoError) {
  83. logError2("alert (ID=%hd): %s", error, str);
  84. } else if (severity == fatalError) {
  85. logFatal2("fatal alert (ID=%hd): %s", error, str);
  86. }
  87. alert_user(msg, severity);
  88. }
  89. extern "C" void debugger(const char *message);
  90. /*
  91. * Jump into debugger (and return)
  92. */
  93. void pause_debug(void)
  94. {
  95. logNote("pause_debug called");
  96. fprintf(stderr, "pause\n");
  97. }
  98. /*
  99. * Display message
  100. */
  101. void vpause(const char *message)
  102. {
  103. logWarning1("vpause: %s", message);
  104. fprintf(stderr, "vpause %s\n", message);
  105. }
  106. /*
  107. * Jump into debugger (and don't return)
  108. */
  109. void halt(void)
  110. {
  111. logFatal("halt called");
  112. fprintf(stderr, "halt\n");
  113. abort();
  114. }
  115. /*
  116. * Display message and halt
  117. */
  118. extern void stop_recording();
  119. void vhalt(const char *message)
  120. {
  121. stop_recording();
  122. logFatal1("vhalt: %s", message);
  123. fprintf(stderr, "vhalt %s\n", message);
  124. #if defined(__APPLE__) && defined(__MACH__)
  125. * (char *) 0x0 = 0;
  126. #else
  127. abort();
  128. #endif
  129. }
  130. /*
  131. * Assertion failed
  132. */
  133. static char assert_text[256];
  134. void _alephone_assert(const char *file, long line, const char *what)
  135. {
  136. vhalt(csprintf(assert_text, "%s:%ld: %s", file, line, what));
  137. }
  138. void _alephone_warn(const char *file, long line, const char *what)
  139. {
  140. vpause(csprintf(assert_text, "%s:%ld: %s", file, line, what));
  141. }