summaryrefslogtreecommitdiff
path: root/os/macosx
diff options
context:
space:
mode:
authorbjarni <bjarni@openttd.org>2006-03-02 21:43:09 +0000
committerbjarni <bjarni@openttd.org>2006-03-02 21:43:09 +0000
commit1931b8ea96c1d8f9bc8034d08b2b59435b381c28 (patch)
tree39fa6d2e9a522c2c973d049b1935d9e6dc137f8e /os/macosx
parent8878ab2e9a042ed64ee2a117f7088cb0454a2731 (diff)
downloadopenttd-1931b8ea96c1d8f9bc8034d08b2b59435b381c28.tar.xz
(svn r3740) -Feature: [OSX] added OS version, CPU type and newGRF settings to assert window and a message to tell people to add that to a bug report
It also adds a new error window, which can be used just like assert, but it is also active when asserts are turned off This is useful for places where it's really important to check even if assert is turned off. It's not used in the code yet
Diffstat (limited to 'os/macosx')
-rw-r--r--os/macosx/macos.h9
-rw-r--r--os/macosx/macos.m105
2 files changed, 112 insertions, 2 deletions
diff --git a/os/macosx/macos.h b/os/macosx/macos.h
index ac1780112..bec5149be 100644
--- a/os/macosx/macos.h
+++ b/os/macosx/macos.h
@@ -3,8 +3,17 @@
#ifndef MACOS_H
#define MACOS_H
+/*
+ * Functions to show the popup window
+ * use ShowMacDialog when you want to control title, message and text on the button
+ * ShowMacAssertDialog is used by assert
+ * ShowMacErrorDialog should be used when an unrecoverable error shows up. It only contains the title, which will should tell what went wrong
+ * the function then adds text that tells the user to update and then report the bug if it's present in the newest version
+ * It also quits in a nice way since we call it when we know something happened that will crash OpenTTD (like a needed pointer turns out to be NULL or similar)
+ */
void ShowMacDialog ( const char *title, const char *message, const char *buttonLabel );
void ShowMacAssertDialog ( const char *function, const char *file, const int line, const char *expression );
+void ShowMacErrorDialog(const char *error);
// Since MacOS X users will never see an assert unless they started the game from a terminal
// we're using a custom assert(e) macro.
diff --git a/os/macosx/macos.m b/os/macosx/macos.m
index c09e58de1..5ac2c4922 100644
--- a/os/macosx/macos.m
+++ b/os/macosx/macos.m
@@ -2,6 +2,20 @@
#include <AppKit/AppKit.h>
+#include <mach/mach.h>
+#include <mach/mach_host.h>
+#include <mach/host_info.h>
+#include <mach/machine.h>
+#include <stdio.h>
+#include "../../stdafx.h"
+#include "../../openttd.h"
+#include "../../newgrf.h"
+#include "../../gfx.h"
+
+#ifndef CPU_SUBTYPE_POWERPC_970
+#define CPU_SUBTYPE_POWERPC_970 ((cpu_subtype_t) 100)
+#endif
+
/*
* This file contains objective C
* Apple uses objective C instead of plain C to interact with OS specific/native functions
@@ -10,6 +24,82 @@
* To insure that the crosscompiler still works, let him try any changes before they are committed
*/
+static char *GetOSString(void)
+{
+ static char buffer[175];
+ char CPU[20];
+ char OS[20];
+ char newgrf[125];
+ long sysVersion;
+ extern const char _openttd_revision[];
+
+
+ // get the hardware info
+ host_basic_info_data_t hostInfo;
+ mach_msg_type_number_t infoCount;
+
+ infoCount = HOST_BASIC_INFO_COUNT;
+ host_info(mach_host_self(), HOST_BASIC_INFO,
+ (host_info_t)&hostInfo, &infoCount);
+
+ // replace the hardware info with strings, that tells a bit more than just an int
+#ifdef __POWERPC__
+ switch (hostInfo.cpu_subtype) {
+ case CPU_SUBTYPE_POWERPC_750:
+ sprintf(CPU,"G3");
+ break;
+ case CPU_SUBTYPE_POWERPC_7400:
+ case CPU_SUBTYPE_POWERPC_7450:
+ sprintf(CPU,"G4");
+ break;
+ case CPU_SUBTYPE_POWERPC_970:
+ sprintf(CPU,"G5");
+ break;
+ default:
+ sprintf(CPU,"Unknown PPC");
+ }
+#else
+ // it looks odd to have a switch for two cases, but it leaves room for easy expansion. Odds are that Apple will some day use newer CPUs than i686
+ switch (hostInfo.cpu_subtype) {
+ case CPU_SUBTYPE_PENTPRO:
+ sprintf(CPU,"i686");
+ break;
+ default:
+ sprintf(CPU,"Unknown Intel");
+ }
+#endif
+
+ // get the version of OSX
+ if( Gestalt( gestaltSystemVersion, &sysVersion ) != noErr ) {
+ sprintf(OS,"Undetected");
+ } else {
+
+ int majorHiNib, majorLoNib, minorNib, bugNib;
+
+ majorHiNib = (sysVersion & 0x0000F000) >> 12;
+ majorLoNib = (sysVersion & 0x00000F00) >> 8;
+ minorNib = (sysVersion & 0x000000F0) >> 4;
+ bugNib = sysVersion & 0x0000000F;
+
+ sprintf(OS, "%d%d.%d.%d", majorHiNib, majorLoNib, minorNib, bugNib);
+ }
+
+ // make a list of used newgrf files
+ if (_first_grffile != NULL) {
+ GRFFile *file;
+ newgrf[0] = 0;
+
+
+ for (file = _first_grffile; file != NULL; file = file->next) {
+ sprintf(newgrf, "%s %s", newgrf, file->filename);
+ }
+ } else {
+ sprintf(newgrf, "none");
+ }
+ sprintf(buffer, "Please add this info: (tip: copy-paste works)\nCPU: %s, OSX: %s, OpenTTD version: %s\nNewGRF files:%s", CPU, OS, _openttd_revision, newgrf);
+ return buffer;
+}
+
#ifdef WITH_SDL
@@ -40,11 +130,22 @@ void ShowMacDialog ( const char *title, const char *message, const char *buttonL
void ShowMacAssertDialog ( const char *function, const char *file, const int line, const char *expression )
{
const char *buffer =
- [[NSString stringWithFormat:@"An assertion has failed and OpenTTD must quit.\n%s in %s (line %d)\n\"%s\"\n\nYou should report this error the OpenTTD developers if you think you found a bug.",
- function, file, line, expression] cString];
+ [[NSString stringWithFormat:@"An assertion has failed and OpenTTD must quit.\n%s in %s (line %d)\n\"%s\"\n\nYou should report this error the OpenTTD developers if you think you found a bug.\n\n%s",
+ function, file, line, expression, GetOSString()] cString];
NSLog(@"%s", buffer);
+ ToggleFullScreen(0);
ShowMacDialog( "Assertion Failed", buffer, "Quit" );
// abort so that a debugger has a chance to notice
abort();
}
+
+
+void ShowMacErrorDialog(const char *error)
+{
+ const char *buffer =
+ [[NSString stringWithFormat:@"Please update to the newest version of OpenTTD\nIf the problem presists, please report this to\nhttp://bugs.openttd.org\n\n%s", GetOSString()] cString];
+ ToggleFullScreen(0);
+ ShowMacDialog(error, buffer, "Quit" );
+ abort();
+}