summaryrefslogtreecommitdiff
path: root/os
diff options
context:
space:
mode:
authorbjarni <bjarni@openttd.org>2005-12-10 11:16:45 +0000
committerbjarni <bjarni@openttd.org>2005-12-10 11:16:45 +0000
commit6a6e1450106f9944f74021edcd9aec54b3cc11ab (patch)
treeb00faf47a1ca2028f095a2c406983e4e94fd533e /os
parentf1877b3fe9b03f34fdfa5aa7ef3cfd205e08ab29 (diff)
downloadopenttd-6a6e1450106f9944f74021edcd9aec54b3cc11ab.tar.xz
(svn r3281) -Feature: [OSX] added native cocoa sound and video drivers (egladil)
you can still use SDL drivers if you like and you have to run "make upgradeconf" to start using the cocoa drivers (or manually write WITH_COCOA:=1) since SDL breaks the cocoa drivers, you can't compile with both SDL and cocoa support Using cocoa drivers makes it easier to make universal binaries and it solves: -FS#18 [OSX] SDL is weird in universal binaries -FS#2 [OSX] lazy pointer crash on exit -FS#10 [OSX] linking error when linking statically to SDL 1.2.8 (needless to explain this, but it means it should be able to compile statically with the default settings now) -[ 1215073 ] Switching to large size out of fullscreen crashes Using SDL drivers will still have those issues though
Diffstat (limited to 'os')
-rw-r--r--os/macosx/Makefile1
-rw-r--r--os/macosx/macos.m4
-rw-r--r--os/macosx/splash.c145
-rw-r--r--os/macosx/splash.h9
-rw-r--r--os/macosx/splash.pngbin0 -> 20053 bytes
5 files changed, 157 insertions, 2 deletions
diff --git a/os/macosx/Makefile b/os/macosx/Makefile
index 577bf420a..3ea875843 100644
--- a/os/macosx/Makefile
+++ b/os/macosx/Makefile
@@ -45,6 +45,7 @@ $(BUILD_OSX_BUNDLE): $(TTD) $(FAT_BINARY)
$(Q)cp os/macosx/openttd.icns "$(OSXAPP)"/Contents/Resources/openttd.icns
$(Q)os/macosx/plistgen.sh "$(OSXAPP)" "$(REV)"
$(Q)cp data/* "$(OSXAPP)"/Contents/Data/
+ $(Q)cp os/macosx/splash.png "$(OSXAPP)"/Contents/Data/
$(Q)cp lang/*.lng "$(OSXAPP)"/Contents/Lang/
$(Q)cp $(TTD) "$(OSXAPP)"/Contents/MacOS/$(TTD)
$(COPY_x86_SDL_LIB)
diff --git a/os/macosx/macos.m b/os/macosx/macos.m
index 936aaa7a0..6c5fa8791 100644
--- a/os/macosx/macos.m
+++ b/os/macosx/macos.m
@@ -15,12 +15,12 @@ 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 =
+ 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] cStringUsingEncoding:NSASCIIStringEncoding];
NSLog(@"%s", buffer);
ShowMacDialog( "Assertion Failed", buffer, "Quit" );
-
+
// abort so that a debugger has a chance to notice
abort();
}
diff --git a/os/macosx/splash.c b/os/macosx/splash.c
new file mode 100644
index 000000000..99791cc21
--- /dev/null
+++ b/os/macosx/splash.c
@@ -0,0 +1,145 @@
+
+#include "../../stdafx.h"
+#include "../../openttd.h"
+#include "../../variables.h"
+#include "../../macros.h"
+#include "../../debug.h"
+#include "../../functions.h"
+#include "../../gfx.h"
+#include "../../fileio.h"
+
+#include "splash.h"
+
+#ifdef WITH_PNG
+
+#include <png.h>
+
+static void PNGAPI png_my_error(png_structp png_ptr, png_const_charp message)
+{
+ DEBUG(misc, 0) ("ERROR(libpng): %s - %s", message, (char *)png_get_error_ptr(png_ptr));
+ longjmp(png_ptr->jmpbuf, 1);
+}
+
+static void PNGAPI png_my_warning(png_structp png_ptr, png_const_charp message)
+{
+ DEBUG(misc, 0) ("WARNING(libpng): %s - %s", message, (char *)png_get_error_ptr(png_ptr));
+}
+
+void DisplaySplashImage(void)
+{
+ png_byte header[8];
+ FILE *f;
+ png_structp png_ptr;
+ png_infop info_ptr, end_info;
+ uint width, height, bit_depth, color_type;
+ png_colorp palette;
+ int num_palette;
+ png_bytep *row_pointers;
+ uint8 *src, *dst;
+ uint y;
+ uint xoff, yoff;
+ int i;
+
+ f = FioFOpenFile(SPLASH_IMAGE_FILE);
+ if (f == NULL) return;
+
+ fread(header, 1, 8, f);
+ if (png_sig_cmp(header, 0, 8) != 0) {
+ fclose(f);
+ return;
+ }
+
+ png_ptr = png_create_read_struct (PNG_LIBPNG_VER_STRING, (png_voidp) NULL, png_my_error, png_my_warning);
+
+ if (png_ptr == NULL) {
+ fclose(f);
+ return;
+ }
+
+ info_ptr = png_create_info_struct(png_ptr);
+ if (info_ptr == NULL) {
+ png_destroy_read_struct(&png_ptr, (png_infopp)NULL, (png_infopp)NULL);
+ fclose(f);
+ return;
+ }
+
+ end_info = png_create_info_struct(png_ptr);
+ if (end_info == NULL) {
+ png_destroy_read_struct(&png_ptr, &info_ptr, (png_infopp)NULL);
+ fclose(f);
+ return;
+ }
+
+ if (setjmp(png_jmpbuf(png_ptr))) {
+ png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
+ fclose(f);
+ return;
+ }
+
+ png_init_io(png_ptr, f);
+ png_set_sig_bytes(png_ptr, 8);
+
+ png_read_png(png_ptr, info_ptr, PNG_TRANSFORM_IDENTITY, NULL);
+
+ width = png_get_image_width(png_ptr, info_ptr);
+ height = png_get_image_height(png_ptr, info_ptr);
+ bit_depth = png_get_bit_depth(png_ptr, info_ptr);
+ color_type = png_get_color_type(png_ptr, info_ptr);
+
+ if(color_type != PNG_COLOR_TYPE_PALETTE || bit_depth != 8) {
+ png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
+ fclose(f);
+ return;
+ }
+
+ if(!png_get_valid(png_ptr, info_ptr, PNG_INFO_PLTE)) {
+ png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
+ fclose(f);
+ return;
+ }
+
+ png_get_PLTE(png_ptr, info_ptr, &palette, &num_palette);
+
+ row_pointers = png_get_rows(png_ptr, info_ptr);
+
+ memset(_screen.dst_ptr, 0xff, _screen.pitch * _screen.height);
+
+ if(width > (uint) _screen.width)
+ width = _screen.width;
+ if(height > (uint) _screen.height)
+ height = _screen.height;
+
+ xoff = (_screen.width - width) / 2;
+ yoff = (_screen.height - height) / 2;
+ for(y = 0; y < height; y++) {
+ src = row_pointers[y];
+ dst = ((uint8 *) _screen.dst_ptr) + (yoff + y) * _screen.pitch + xoff;
+
+ memcpy(dst, src, width);
+ }
+
+ for (i = 0; i < num_palette; i++) {
+ _cur_palette[i].r = palette[i].red;
+ _cur_palette[i].g = palette[i].green;
+ _cur_palette[i].b = palette[i].blue;
+ }
+
+ _cur_palette[0xff].r = 0;
+ _cur_palette[0xff].g = 0;
+ _cur_palette[0xff].b = 0;
+
+ _pal_first_dirty = 0;
+ _pal_last_dirty = 0xff;
+
+ png_destroy_read_struct(&png_ptr, &info_ptr, &end_info);
+ fclose(f);
+ return;
+}
+
+
+
+#else // WITH_PNG
+
+void DisplaySplashImage(void) {}
+
+#endif // WITH_PNG
diff --git a/os/macosx/splash.h b/os/macosx/splash.h
new file mode 100644
index 000000000..7454ccaa0
--- /dev/null
+++ b/os/macosx/splash.h
@@ -0,0 +1,9 @@
+
+#ifndef SPLASH_H
+#define SPLASH_H
+
+#define SPLASH_IMAGE_FILE "splash.png"
+
+void DisplaySplashImage(void);
+
+#endif
diff --git a/os/macosx/splash.png b/os/macosx/splash.png
new file mode 100644
index 000000000..e67d10da8
--- /dev/null
+++ b/os/macosx/splash.png
Binary files differ