From 2e99b0c26d334eb287486b8933b52b5048c6cc0c Mon Sep 17 00:00:00 2001 From: Holger Schemel Date: Thu, 15 May 2014 01:36:00 +0200 Subject: [PATCH] rnd-20140515-2-src * removed native X11 support (X11 now only supported via SDL/SDL2) --- ChangeLog | 1 + Makefile | 13 - src/Makefile | 21 -- src/conftime.h | 2 +- src/events.c | 8 - src/game_em/init.c | 5 - src/init.c | 58 --- src/libgame/Makefile | 4 - src/libgame/image.c | 794 ----------------------------------------- src/libgame/image.h | 59 --- src/libgame/joystick.c | 85 ----- src/libgame/joystick.h | 5 - src/libgame/libgame.h | 1 - src/libgame/misc.c | 41 +-- src/libgame/pcx.c | 314 ---------------- src/libgame/pcx.h | 37 -- src/libgame/platform.h | 4 - src/libgame/setup.c | 4 +- src/libgame/sound.c | 56 +-- src/libgame/sound.h | 6 - src/libgame/system.c | 171 +-------- src/libgame/system.h | 27 +- src/libgame/text.c | 102 ------ src/libgame/x11.c | 518 --------------------------- src/libgame/x11.h | 350 ------------------ src/main.c | 14 +- src/main.h | 8 - src/screens.c | 56 --- 28 files changed, 12 insertions(+), 2752 deletions(-) delete mode 100644 src/libgame/pcx.c delete mode 100644 src/libgame/pcx.h delete mode 100644 src/libgame/x11.c delete mode 100644 src/libgame/x11.h diff --git a/ChangeLog b/ChangeLog index 2b738cc5..2f434da7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,5 +1,6 @@ 2014-05-15 * removed MS-DOS support + * removed native X11 support (X11 now only supported via SDL/SDL2) 2014-05-14 * cleanup of functions RedrawPlayfield() and BlitScreenToBitmap() diff --git a/Makefile b/Makefile index d80dcb57..aae58256 100644 --- a/Makefile +++ b/Makefile @@ -16,9 +16,6 @@ CC = gcc # (this must be set to "gmake" for some systems) MAKE = make -# path to X11 on your system -X11_PATH = /usr/X11R6 - # directory for read-only game data (like graphics, sounds, levels) # default is '.' to be able to run program without installation # RO_GAME_DIR = /usr/games @@ -57,7 +54,6 @@ CROSS_PATH_WIN32 = /usr/local/cross-tools/i386-mingw32msvc SRC_DIR = src MAKE_CMD = $(MAKE) -C $(SRC_DIR) -# DEFAULT_TARGET = x11 DEFAULT_TARGET = sdl2 @@ -68,21 +64,12 @@ DEFAULT_TARGET = sdl2 all: @$(MAKE_CMD) TARGET=$(DEFAULT_TARGET) -x11: - @$(MAKE_CMD) TARGET=x11 - sdl: @$(MAKE_CMD) TARGET=sdl sdl2: @$(MAKE_CMD) TARGET=sdl2 -solaris: - @$(MAKE_CMD) PLATFORM=solaris TARGET=x11 - -solaris-sdl: - @$(MAKE_CMD) PLATFORM=solaris TARGET=sdl - mac: @$(MAKE_CMD) PLATFORM=macosx diff --git a/src/Makefile b/src/Makefile index 39eaad9f..2a02d816 100644 --- a/src/Makefile +++ b/src/Makefile @@ -14,13 +14,6 @@ ifndef PLATFORM # unknown platform -- default to Unix PLATFORM = unix endif -ifdef X11_PATH # path to X11 from top level Makefile -XINC_PATH = $(X11_PATH)/include -XLIB_PATH = $(X11_PATH)/lib -X11_INCL = -I$(XINC_PATH) -X11_LIBS = -L$(XLIB_PATH) -lX11 -endif - AR = ar RANLIB = ranlib ETAGS = etags @@ -55,15 +48,6 @@ PLATFORM = unix TARGET = sdl endif -ifeq ($(PLATFORM),os2) # native compiling to OS/2 -RANLIB = echo -PROGNAME = ../$(PROGBASE).exe -EXTRA_CFLAGS = -Zbin-files -D__ST_MT_ERRNO__ -Zmtd -fomit-frame-pointer -EXTRA_LDFLAGS = -lsocket -PLATFORM = unix -TARGET = x11 -endif - ifeq ($(PLATFORM),unix) # native compiling to Unix (generic) PROFILING_FLAGS = -pg endif @@ -80,11 +64,6 @@ endif # configuring target # ----------------------------------------------------------------------------- -ifeq ($(TARGET),x11) # compiling for X11 target -SYS_CFLAGS = -DTARGET_X11 $(X11_INCL) -SYS_LDFLAGS = $(X11_LIBS) -endif - ifeq ($(TARGET),sdl) # compiling for SDL target SYS_CFLAGS = -DTARGET_SDL $(shell sdl-config --cflags) SDL_LIBS = -lSDL_image -lSDL_mixer -lSDL_net -lsmpeg diff --git a/src/conftime.h b/src/conftime.h index 762c55f1..d996e25e 100644 --- a/src/conftime.h +++ b/src/conftime.h @@ -1 +1 @@ -#define COMPILE_DATE_STRING "2014-05-15 00:13" +#define COMPILE_DATE_STRING "2014-05-15 01:35" diff --git a/src/events.c b/src/events.c index 62d146fa..8ca30fce 100644 --- a/src/events.c +++ b/src/events.c @@ -363,14 +363,6 @@ void SleepWhileUnmapped() void HandleExposeEvent(ExposeEvent *event) { -#if !defined(TARGET_SDL) -#if 1 - RedrawPlayfield(); -#else - RedrawPlayfield(FALSE, event->x, event->y, event->width, event->height); -#endif - FlushDisplay(); -#endif } void HandleButtonEvent(ButtonEvent *event) diff --git a/src/game_em/init.c b/src/game_em/init.c index 2033b2db..3aa8361d 100644 --- a/src/game_em/init.c +++ b/src/game_em/init.c @@ -5,13 +5,8 @@ #include "main_em.h" - #include -#if !defined(TARGET_SDL) -#include -#endif - Bitmap *objBitmap; Bitmap *sprBitmap; diff --git a/src/init.c b/src/init.c index d6df6a85..fec8cc2d 100644 --- a/src/init.c +++ b/src/init.c @@ -1753,14 +1753,6 @@ static void InitGraphicInfo() int num_images = getImageListSize(); int i; -#if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND) - static boolean clipmasks_initialized = FALSE; - Pixmap src_pixmap; - XGCValues clip_gc_values; - unsigned int clip_gc_valuemask; - GC copy_clipmask_gc = None; -#endif - /* use image size as default values for width and height for these images */ static int full_size_graphics[] = { @@ -1835,22 +1827,6 @@ static void InitGraphicInfo() graphic_info[full_size_graphics[i]].use_image_size = TRUE; #endif -#if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND) - if (clipmasks_initialized) - { - for (i = 0; i < num_images; i++) - { - if (graphic_info[i].clip_mask) - XFreePixmap(display, graphic_info[i].clip_mask); - if (graphic_info[i].clip_gc) - XFreeGC(display, graphic_info[i].clip_gc); - - graphic_info[i].clip_mask = None; - graphic_info[i].clip_gc = None; - } - } -#endif - /* first set all graphic paramaters ... */ for (i = 0; i < num_images; i++) set_graphic_parameters(i); @@ -1943,41 +1919,7 @@ static void InitGraphicInfo() graphic_info[i] = graphic_info[fallback_graphic]; } - -#if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND) - /* currently we only need a tile clip mask from the first frame */ - getFixedGraphicSource(i, first_frame, &src_bitmap, &src_x, &src_y); - - if (copy_clipmask_gc == None) - { - clip_gc_values.graphics_exposures = False; - clip_gc_valuemask = GCGraphicsExposures; - copy_clipmask_gc = XCreateGC(display, src_bitmap->clip_mask, - clip_gc_valuemask, &clip_gc_values); - } - - graphic_info[i].clip_mask = - XCreatePixmap(display, window->drawable, TILEX, TILEY, 1); - - src_pixmap = src_bitmap->clip_mask; - XCopyArea(display, src_pixmap, graphic_info[i].clip_mask, - copy_clipmask_gc, src_x, src_y, TILEX, TILEY, 0, 0); - - clip_gc_values.graphics_exposures = False; - clip_gc_values.clip_mask = graphic_info[i].clip_mask; - clip_gc_valuemask = GCGraphicsExposures | GCClipMask; - - graphic_info[i].clip_gc = - XCreateGC(display, window->drawable, clip_gc_valuemask, &clip_gc_values); -#endif } - -#if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND) - if (copy_clipmask_gc) - XFreeGC(display, copy_clipmask_gc); - - clipmasks_initialized = TRUE; -#endif } static void InitGraphicCompatibilityInfo() diff --git a/src/libgame/Makefile b/src/libgame/Makefile index 62353527..f1460540 100644 --- a/src/libgame/Makefile +++ b/src/libgame/Makefile @@ -15,13 +15,11 @@ SRCS = system.c \ joystick.c \ snapshot.c \ toons.c \ - pcx.c \ image.c \ random.c \ hash.c \ setup.c \ misc.c \ - x11.c \ sdl.c OBJS = system.o \ @@ -31,13 +29,11 @@ OBJS = system.o \ snapshot.o \ joystick.o \ toons.o \ - pcx.o \ image.o \ random.o \ hash.o \ setup.o \ misc.o \ - x11.o \ sdl.o LIBGAME = libgame.a diff --git a/src/libgame/image.c b/src/libgame/image.c index 505238dc..36fd184a 100644 --- a/src/libgame/image.c +++ b/src/libgame/image.c @@ -12,804 +12,10 @@ ***********************************************************/ #include "image.h" -#include "pcx.h" #include "misc.h" #include "setup.h" -/* ========================================================================= */ -/* PLATFORM SPECIFIC IMAGE FUNCTIONS */ -/* ========================================================================= */ - -#if defined(TARGET_X11) - -Image *newImage(unsigned int width, unsigned int height, unsigned int depth) -{ - Image *image; - unsigned int bytes_per_pixel = (depth + 7) / 8; - int i; - - image = checked_calloc(sizeof(Image)); - image->data = checked_calloc(width * height * bytes_per_pixel); - image->width = width; - image->height = height; - image->depth = depth; - image->bytes_per_pixel = bytes_per_pixel; - image->bytes_per_row = width * bytes_per_pixel; - - image->rgb.used = 0; - for (i = 0; i < MAX_COLORS; i++) - image->rgb.color_used[i] = FALSE; - - image->type = (depth < 8 ? IMAGETYPE_BITMAP : - depth > 8 ? IMAGETYPE_TRUECOLOR : IMAGETYPE_RGB); - - return image; -} - -void freeImage(Image *image) -{ - free(image->data); - free(image); -} - -/* extra colors to try allocating in private color maps to minimize flashing */ -#define NOFLASH_COLORS 256 - -/* architecture independent value <-> memory conversions; - note: the internal format is big endian */ - -#define memory_to_value(ptr, len) ( \ -(len) == 1 ? (unsigned int)( *( (byte *)(ptr)) ) : \ -(len) == 2 ? (unsigned int)(((unsigned int)(*( (byte *)(ptr)) ))<< 8) \ - + ( *(((byte *)(ptr))+1) ) : \ -(len) == 3 ? (unsigned int)(((unsigned int)(*( (byte *)(ptr)) ))<<16) \ - + (((unsigned int)(*(((byte *)(ptr))+1)))<< 8) \ - + ( *(((byte *)(ptr))+2) ) : \ - (unsigned int)(((unsigned int)(*( (byte *)(ptr)) ))<<24) \ - + (((unsigned int)(*(((byte *)(ptr))+1)))<<16) \ - + (((unsigned int)(*(((byte *)(ptr))+2)))<< 8) \ - + ( *(((byte *)(ptr))+3) ) ) - - -#define value_to_memory(value, ptr, len) ( \ -(len) == 1 ? (*( (byte *)(ptr) ) = ( value ) ) : \ -(len) == 2 ? (*( (byte *)(ptr) ) = (((unsigned int)(value))>> 8), \ - *(((byte *)(ptr))+1) = ( value ) ) : \ -(len) == 3 ? (*( (byte *)(ptr) ) = (((unsigned int)(value))>>16), \ - *(((byte *)(ptr))+1) = (((unsigned int)(value))>> 8), \ - *(((byte *)(ptr))+2) = ( value ) ) : \ - (*( (byte *)(ptr) ) = (((unsigned int)(value))>>24), \ - *(((byte *)(ptr))+1) = (((unsigned int)(value))>>16), \ - *(((byte *)(ptr))+2) = (((unsigned int)(value))>> 8), \ - *(((byte *)(ptr))+3) = ( value ) )) - -static Pixmap Image_to_Mask(Image *image, Display *display, Window window) -{ - byte *src_ptr, *dst_ptr, *dst_ptr2; - unsigned int bytes_per_row; - unsigned int x, y, i; - byte bitmask; - byte *mask_data; - Pixmap mask_pixmap; - - bytes_per_row = (image->width + 7) / 8; - mask_data = checked_calloc(bytes_per_row * image->height); - - src_ptr = image->data; - dst_ptr = mask_data; - - /* create bitmap data which can be used by 'XCreateBitmapFromData()' - * directly to create a pixmap of depth 1 for use as a clip mask for - * the corresponding image pixmap - */ - - for (y = 0; y < image->height; y++) - { - bitmask = 0x01; /* start with leftmost bit in the byte */ - dst_ptr2 = dst_ptr; /* start with leftmost byte in the row */ - - for (x = 0; x < image->width; x++) - { - for (i = 0; i < image->bytes_per_pixel; i++) - if (*src_ptr++) /* source pixel solid? (pixel index != 0) */ - *dst_ptr2 |= bitmask; /* then write a bit into the image mask */ - - if ((bitmask <<= 1) == 0) /* bit at rightmost byte position reached? */ - { - bitmask = 0x01; /* start again with leftmost bit position */ - dst_ptr2++; /* continue with next byte in image mask */ - } - } - - dst_ptr += bytes_per_row; /* continue with leftmost byte of next row */ - } - - if ((mask_pixmap = XCreateBitmapFromData(display, window, (char *)mask_data, - image->width, image->height)) - == None) - Error(ERR_EXIT, "Image_to_Mask(): XCreateBitmapFromData() failed"); - - free(mask_data); - - return mask_pixmap; -} - -Pixmap Pixmap_to_Mask(Pixmap src_pixmap, int src_width, int src_height) -{ - XImage *src_ximage; - byte *src_ptr, *dst_ptr, *dst_ptr2; - int bits_per_pixel; - int bytes_per_pixel; - unsigned int bytes_per_row; - unsigned int x, y, i; - byte bitmask; - byte *mask_data; - Pixmap mask_pixmap; - - /* copy source pixmap to temporary image */ - if ((src_ximage = XGetImage(display, src_pixmap, 0, 0, src_width, src_height, - AllPlanes, ZPixmap)) == NULL) - Error(ERR_EXIT, "Pixmap_to_Mask(): XGetImage() failed"); - - bits_per_pixel = src_ximage->bits_per_pixel; - bytes_per_pixel = (bits_per_pixel + 7) / 8; - - bytes_per_row = (src_width + 7) / 8; - mask_data = checked_calloc(bytes_per_row * src_height); - - src_ptr = (byte *)src_ximage->data; - dst_ptr = mask_data; - - /* create bitmap data which can be used by 'XCreateBitmapFromData()' - * directly to create a pixmap of depth 1 for use as a clip mask for - * the corresponding image pixmap - */ - - for (y = 0; y < src_height; y++) - { - bitmask = 0x01; /* start with leftmost bit in the byte */ - dst_ptr2 = dst_ptr; /* start with leftmost byte in the row */ - - for (x = 0; x < src_width; x++) - { - for (i = 0; i < bytes_per_pixel; i++) - if (*src_ptr++) /* source pixel solid? (pixel index != 0) */ - *dst_ptr2 |= bitmask; /* then write a bit into the image mask */ - - if ((bitmask <<= 1) == 0) /* bit at rightmost byte position reached? */ - { - bitmask = 0x01; /* start again with leftmost bit position */ - dst_ptr2++; /* continue with next byte in image mask */ - } - } - - dst_ptr += bytes_per_row; /* continue with leftmost byte of next row */ - } - - if ((mask_pixmap = XCreateBitmapFromData(display, window->drawable, - (char *)mask_data, - src_width, src_height)) == None) - Error(ERR_EXIT, "Pixmap_to_Mask(): XCreateBitmapFromData() failed"); - - free(mask_data); - - return mask_pixmap; -} - -static int bitsPerPixelAtDepth(Display *display, int screen, int depth) -{ - XPixmapFormatValues *pixmap_format; - int i, num_pixmap_formats, bits_per_pixel = -1; - - /* get Pixmap formats supported by the X server */ - pixmap_format = XListPixmapFormats(display, &num_pixmap_formats); - - /* find format that matches the given depth */ - for (i = 0; i < num_pixmap_formats; i++) - if (pixmap_format[i].depth == depth) - bits_per_pixel = pixmap_format[i].bits_per_pixel; - - XFree(pixmap_format); - - if (bits_per_pixel == -1) - Error(ERR_EXIT, "cannot find pixmap format for depth %d", depth); - - return bits_per_pixel; -} - -XImageInfo *Image_to_Pixmap(Display *display, int screen, Visual *visual, - Window window, GC gc, int depth, Image *image) -{ - static XColor xcolor_private[NOFLASH_COLORS]; - static int colorcell_used[NOFLASH_COLORS]; - static Colormap global_cmap = 0; - static Pixel *global_cmap_index; - static int num_cmap_entries, free_cmap_entries; - static boolean private_cmap = FALSE; - Pixel *redvalue, *greenvalue, *bluevalue; - unsigned int display_bytes_per_pixel, display_bits_per_pixel; - unsigned int a, c = 0, x, y; - XColor xcolor; - XImage *ximage; - XImageInfo *ximageinfo; - byte *src_ptr, *dst_ptr; - char *error = "Image_to_Pixmap(): %s"; - - if (image->type == IMAGETYPE_TRUECOLOR && depth == 8) - { - SetError(error, "cannot handle true-color images on 8-bit display"); - return NULL; - } - - if (!global_cmap) - { - if (visual == DefaultVisual(display, screen)) - global_cmap = DefaultColormap(display, screen); - else - { - global_cmap = XCreateColormap(display, RootWindow(display, screen), - visual, AllocNone); - private_cmap = TRUE; - } - } - - xcolor.flags = DoRed | DoGreen | DoBlue; - redvalue = greenvalue = bluevalue = NULL; - ximageinfo = checked_malloc(sizeof(XImageInfo)); - ximageinfo->display = display; - ximageinfo->depth = depth; - - switch (visual->class) - { - case TrueColor: - case DirectColor: - { - Pixel pixval; - unsigned int redcolors, greencolors, bluecolors; - unsigned int redstep, greenstep, bluestep; - unsigned int redbottom, greenbottom, bluebottom; - unsigned int redtop, greentop, bluetop; - - redvalue = (Pixel *)checked_malloc(sizeof(Pixel) * 256); - greenvalue = (Pixel *)checked_malloc(sizeof(Pixel) * 256); - bluevalue = (Pixel *)checked_malloc(sizeof(Pixel) * 256); - - ximageinfo->cmap = global_cmap; - - retry_direct: /* tag we hit if a DirectColor allocation fails on - * default colormap */ - - /* calculate number of distinct colors in each band */ - - redcolors = greencolors = bluecolors = 1; - for (pixval = 1; pixval; pixval <<= 1) - { - if (pixval & visual->red_mask) - redcolors <<= 1; - if (pixval & visual->green_mask) - greencolors <<= 1; - if (pixval & visual->blue_mask) - bluecolors <<= 1; - } - - /* consistency check */ - if (redcolors > visual->map_entries || - greencolors > visual->map_entries || - bluecolors > visual->map_entries) - Error(ERR_WARN, "inconsistency in color information"); - - redstep = 256 / redcolors; - greenstep = 256 / greencolors; - bluestep = 256 / bluecolors; - redbottom = greenbottom = bluebottom = 0; - redtop = greentop = bluetop = 0; - - for (a = 0; a < visual->map_entries; a++) - { - if (redbottom < 256) - redtop = redbottom + redstep; - if (greenbottom < 256) - greentop = greenbottom + greenstep; - if (bluebottom < 256) - bluetop = bluebottom + bluestep; - - xcolor.red = (redtop - 1) << 8; - xcolor.green = (greentop - 1) << 8; - xcolor.blue = (bluetop - 1) << 8; - if (!XAllocColor(display, ximageinfo->cmap, &xcolor)) - { - /* if an allocation fails for a DirectColor default visual then - we should create a private colormap and try again. */ - - if ((visual->class == DirectColor) && - (visual == DefaultVisual(display, screen))) - { - global_cmap = XCopyColormapAndFree(display, global_cmap); - ximageinfo->cmap = global_cmap; - private_cmap = TRUE; - - goto retry_direct; - } - - /* something completely unexpected happened */ - - fprintf(stderr, "Image_to_Pixmap: XAllocColor failed on a TrueColor/Directcolor visual\n"); - - free(redvalue); - free(greenvalue); - free(bluevalue); - free(ximageinfo); - - return NULL; - } - - /* fill in pixel values for each band at this intensity */ - - while ((redbottom < 256) && (redbottom < redtop)) - redvalue[redbottom++] = xcolor.pixel & visual->red_mask; - while ((greenbottom < 256) && (greenbottom < greentop)) - greenvalue[greenbottom++] = xcolor.pixel & visual->green_mask; - while ((bluebottom < 256) && (bluebottom < bluetop)) - bluevalue[bluebottom++] = xcolor.pixel & visual->blue_mask; - } - - break; - } - - case PseudoColor: - - ximageinfo->cmap = global_cmap; - - for (a = 0; a < MAX_COLORS; a++) - { - XColor xcolor2; - unsigned short mask; - int color_found; - int i; - - if (!image->rgb.color_used[a]) - continue; - - xcolor.red = *(image->rgb.red + a); - xcolor.green = *(image->rgb.green + a); - xcolor.blue = *(image->rgb.blue + a); - - /* look if this color already exists in our colormap */ - if (!XAllocColor(display, ximageinfo->cmap, &xcolor)) - { - if (!private_cmap) - { - if (options.verbose) - Error(ERR_INFO, "switching to private colormap"); - - /* we just filled up the default colormap -- get a private one - which contains all already allocated colors */ - - global_cmap = XCopyColormapAndFree(display, global_cmap); - ximageinfo->cmap = global_cmap; - private_cmap = TRUE; - - /* allocate the rest of the color cells read/write */ - global_cmap_index = - (Pixel *)checked_malloc(sizeof(Pixel) * NOFLASH_COLORS); - for (i = 0; i < NOFLASH_COLORS; i++) - if (!XAllocColorCells(display, global_cmap, FALSE, NULL, 0, - global_cmap_index + i, 1)) - break; - num_cmap_entries = free_cmap_entries = i; - - /* - printf("We've got %d free colormap entries.\n", free_cmap_entries); - */ - - /* to minimize colormap flashing, copy default colors and try - to keep them as near as possible to the old values */ - - for (i = 0; i < num_cmap_entries; i++) - { - xcolor2.pixel = *(global_cmap_index + i); - XQueryColor(display, DefaultColormap(display, screen), &xcolor2); - XStoreColor(display, global_cmap, &xcolor2); - xcolor_private[xcolor2.pixel] = xcolor2; - colorcell_used[xcolor2.pixel] = FALSE; - } - - /* now we have the default colormap private: all colors we - successfully allocated so far are read-only, which is okay, - because we don't want to change them anymore -- if we need - an existing color again, we get it by XAllocColor; all other - colors are read/write and we can set them by XStoreColor, - but we will try to overwrite those color cells with our new - color which are as close as possible to our new color */ - } - - /* look for an existing default color close the one we want */ - - mask = 0xf000; - color_found = FALSE; - - while (!color_found) - { - for (i = num_cmap_entries - 1; i >= 0; i--) - { - xcolor2.pixel = *(global_cmap_index + i); - xcolor2 = xcolor_private[xcolor2.pixel]; - - if (colorcell_used[xcolor2.pixel]) - continue; - - if ((xcolor.red & mask) == (xcolor2.red & mask) && - (xcolor.green & mask) == (xcolor2.green & mask) && - (xcolor.blue & mask) == (xcolor2.blue & mask)) - { - /* - printf("replacing color cell %ld with a close color\n", - xcolor2.pixel); - */ - color_found = TRUE; - break; - } - } - - if (mask == 0x0000) - break; - - mask = (mask << 1) & 0xffff; - } - - if (!color_found) /* no more free color cells */ - { - SetError(error, "cannot allocate enough color cells"); - return NULL; - } - - xcolor.pixel = xcolor2.pixel; - xcolor_private[xcolor.pixel] = xcolor; - colorcell_used[xcolor.pixel] = TRUE; - XStoreColor(display, ximageinfo->cmap, &xcolor); - free_cmap_entries--; - } - - *(ximageinfo->index + a) = xcolor.pixel; - } - - /* - printf("still %d free colormap entries\n", free_cmap_entries); - */ - - ximageinfo->no = a; /* number of pixels allocated for this image */ - break; - - default: - Error(ERR_INFO,"DirectColor, TrueColor or PseudoColor display needed"); - SetError(error, "display class not supported"); - - return NULL; - } - -#if DEBUG_TIMING - debug_print_timestamp(2, " ALLOCATING IMAGE COLORS: "); -#endif - - /* create XImage from internal image structure and convert it to Pixmap */ - - display_bits_per_pixel = bitsPerPixelAtDepth(display, screen, depth); - display_bytes_per_pixel = (display_bits_per_pixel + 7) / 8; - - ximage = XCreateImage(display, visual, depth, ZPixmap, - 0, NULL, image->width, image->height, - 8, image->width * display_bytes_per_pixel); - ximage->data = - checked_malloc(image->width * image->height * display_bytes_per_pixel); - ximage->byte_order = MSBFirst; - - src_ptr = image->data; - dst_ptr = (byte *)ximage->data; - - switch (visual->class) - { - case DirectColor: - case TrueColor: - { - Pixel pixval; - - switch (image->type) - { - case IMAGETYPE_RGB: - { - for (y = 0; y < image->height; y++) /* general case */ - { - for (x = 0; x < image->width; x++) - { - pixval = *src_ptr++; - pixval = - redvalue[image->rgb.red[pixval] >> 8] | - greenvalue[image->rgb.green[pixval] >> 8] | - bluevalue[image->rgb.blue[pixval] >> 8]; - value_to_memory(pixval, dst_ptr, display_bytes_per_pixel); - dst_ptr += display_bytes_per_pixel; - } - } - - break; - } - - case IMAGETYPE_TRUECOLOR: - { - for (y = 0; y < image->height; y++) /* general case */ - { - for (x = 0; x < image->width; x++) - { - pixval = memory_to_value(src_ptr, image->bytes_per_pixel); - pixval = - redvalue[TRUECOLOR_RED(pixval)] | - greenvalue[TRUECOLOR_GREEN(pixval)] | - bluevalue[TRUECOLOR_BLUE(pixval)]; - value_to_memory(pixval, dst_ptr, display_bytes_per_pixel); - src_ptr += image->bytes_per_pixel; - dst_ptr += display_bytes_per_pixel; - } - } - - break; - } - - default: - Error(ERR_INFO, "RGB or TrueColor image needed"); - SetError(error, "image type not supported"); - - return NULL; - } - - break; - } - - case PseudoColor: - { - if (display_bytes_per_pixel == 1) /* special case */ - { - for (y = 0; y < image->height; y++) - for (x = 0; x < image->width; x++) - *dst_ptr++ = ximageinfo->index[c + *src_ptr++]; - } - else /* general case */ - { - for (y = 0; y < image->height; y++) - { - for (x = 0; x < image->width; x++) - { - value_to_memory(ximageinfo->index[c + *src_ptr++], - dst_ptr, display_bytes_per_pixel); - dst_ptr += display_bytes_per_pixel; - } - } - } - - break; - } - - default: - Error(ERR_INFO,"DirectColor, TrueColor or PseudoColor display needed"); - SetError(error, "display class not supported"); - - return NULL; - } - - if (redvalue) - { - free((byte *)redvalue); - free((byte *)greenvalue); - free((byte *)bluevalue); - } - -#if DEBUG_TIMING - debug_print_timestamp(2, " CONVERTING IMAGE TO XIMAGE:"); -#endif - - ximageinfo->pixmap = XCreatePixmap(display, window, - ximage->width, ximage->height, - ximageinfo->depth); - - XPutImage(ximageinfo->display, ximageinfo->pixmap, gc, - ximage, 0, 0, 0, 0, ximage->width, ximage->height); - - X11DestroyImage(ximage); - - return ximageinfo; -} - -/* - ----------------------------------------------------------------------------- - ZoomPixmap - - Important note: The scaling code currently only supports scaling of the image - up or down by a power of 2 -- other scaling factors currently not supported! - Also not supported is scaling of pixmap masks (with depth 1); to scale them, - better use Pixmap_to_Mask() for now. - ----------------------------------------------------------------------------- -*/ - -void ZoomPixmap(Display *display, GC gc, Pixmap src_pixmap, Pixmap dst_pixmap, - int src_width, int src_height, - int dst_width, int dst_height) -{ - XImage *src_ximage, *dst_ximage; - byte *src_ptr, *dst_ptr; - int bits_per_pixel; - int bytes_per_pixel; - int x, y, xx, yy, i; - int row_skip, col_skip; - int zoom_factor; - boolean scale_down = (src_width > dst_width); - - if (scale_down) - { -#if 1 - zoom_factor = MIN(src_width / dst_width, src_height / dst_height); -#else - zoom_factor = src_width / dst_width; -#endif - - /* adjust source image size to integer multiple of destination size */ - src_width = dst_width * zoom_factor; - src_height = dst_height * zoom_factor; - } - else - { -#if 1 - zoom_factor = MIN(dst_width / src_width, dst_height / src_height); -#else - zoom_factor = dst_width / src_width; -#endif - - /* no adjustment needed when scaling up (some pixels may be left blank) */ - } - - /* copy source pixmap to temporary image */ - if ((src_ximage = XGetImage(display, src_pixmap, 0, 0, src_width, src_height, - AllPlanes, ZPixmap)) == NULL) - Error(ERR_EXIT, "ZoomPixmap(): XGetImage() failed"); - - bits_per_pixel = src_ximage->bits_per_pixel; - bytes_per_pixel = (bits_per_pixel + 7) / 8; - - if ((dst_ximage = XCreateImage(display, visual, src_ximage->depth, ZPixmap, - 0, NULL, dst_width, dst_height, - 8, dst_width * bytes_per_pixel)) == NULL) - Error(ERR_EXIT, "ZoomPixmap(): XCreateImage() failed"); - - dst_ximage->data = - checked_malloc(dst_width * dst_height * bytes_per_pixel); - dst_ximage->byte_order = src_ximage->byte_order; - - src_ptr = (byte *)src_ximage->data; - dst_ptr = (byte *)dst_ximage->data; - - if (scale_down) - { - col_skip = (zoom_factor - 1) * bytes_per_pixel; - row_skip = col_skip * src_width; - - /* scale image down by scaling factor 'zoom_factor' */ - for (y = 0; y < src_height; y += zoom_factor, src_ptr += row_skip) - for (x = 0; x < src_width; x += zoom_factor, src_ptr += col_skip) - for (i = 0; i < bytes_per_pixel; i++) - *dst_ptr++ = *src_ptr++; - } - else - { - row_skip = src_width * bytes_per_pixel; - - /* scale image up by scaling factor 'zoom_factor' */ - for (y = 0; y < src_height; y++) - { - for (yy = 0; yy < zoom_factor; yy++) - { - if (yy > 0) - src_ptr -= row_skip; - - for (x = 0; x < src_width; x++) - { - for (xx = 0; xx < zoom_factor; xx++) - for (i = 0; i < bytes_per_pixel; i++) - *dst_ptr++ = *(src_ptr + i); - - src_ptr += bytes_per_pixel; - } - } - } - } - - /* copy scaled image to destination pixmap */ - XPutImage(display, dst_pixmap, gc, dst_ximage, 0, 0, 0, 0, - dst_width, dst_height); - - /* free temporary images */ - X11DestroyImage(src_ximage); - X11DestroyImage(dst_ximage); -} - -void freeXImage(Image *image, XImageInfo *ximageinfo) -{ - if (ximageinfo->index != NULL && ximageinfo->no > 0) - XFreeColors(ximageinfo->display, ximageinfo->cmap, ximageinfo->index, - ximageinfo->no, 0); - /* this ^^^^^^^^^^^^^^ is wrong, because the used color cells - * are somewhere between 0 and MAX_COLORS; there are indeed 'ximageinfo->no' - * used color cells, but they are not at array position 0 - 'ximageinfo->no' - */ - - free(ximageinfo); -} - -int Read_PCX_to_Pixmap(Display *display, Window window, GC gc, char *filename, - Pixmap *pixmap, Pixmap *pixmap_mask) -{ - Image *image; - XImageInfo *ximageinfo; - int screen; - Visual *visual; - int depth; - -#if DEBUG_TIMING - debug_print_timestamp(2, NULL); /* initialize timestamp function */ -#endif - - /* read the graphic file in PCX format to image structure */ - if ((image = Read_PCX_to_Image(filename)) == NULL) - return errno_pcx; - -#if DEBUG_TIMING - printf("%s:\n", filename); - debug_print_timestamp(2, " READING PCX FILE TO IMAGE: "); -#endif - - screen = DefaultScreen(display); - visual = DefaultVisual(display, screen); - depth = DefaultDepth(display, screen); - - /* convert image structure to X11 Pixmap */ - if (!(ximageinfo = Image_to_Pixmap(display, screen, visual, - window, gc, depth, image))) - { - freeImage(image); - - return PCX_OtherError; - } - - /* if a private colormap has been created, install it */ - if (ximageinfo->cmap != DefaultColormap(display, screen)) - XSetWindowColormap(display, window, ximageinfo->cmap); - -#if DEBUG_TIMING - debug_print_timestamp(2, " CONVERTING IMAGE TO PIXMAP:"); -#endif - - /* create clip mask for the image */ - ximageinfo->pixmap_mask = Image_to_Mask(image, display, window); - -#if DEBUG_TIMING - debug_print_timestamp(2, " CONVERTING IMAGE TO MASK: "); -#endif - - *pixmap = ximageinfo->pixmap; - *pixmap_mask = ximageinfo->pixmap_mask; - - /* free generic image and ximageinfo after native Pixmap has been created */ - free(ximageinfo); - freeImage(image); - - return PCX_Success; -} - -#endif /* TARGET_X11 */ - - -/* ========================================================================= */ -/* PLATFORM INDEPENDENT IMAGE FUNCTIONS */ -/* ========================================================================= */ - struct ImageInfo { char *source_filename; diff --git a/src/libgame/image.h b/src/libgame/image.h index c3c1e0d1..0d8dd27a 100644 --- a/src/libgame/image.h +++ b/src/libgame/image.h @@ -17,65 +17,6 @@ #include "system.h" -#if defined(TARGET_X11) - -#define MAX_COLORS 256 /* maximal number of colors for each image */ - -typedef unsigned short Intensity; /* RGB intensity for X11 */ - -typedef struct -{ - Display *display; /* destination display */ - int depth; /* depth of destination drawable */ - Pixel index[MAX_COLORS]; /* array of pixel values */ - int no; /* number of pixels in the array */ - Colormap cmap; /* colormap used for image */ - Pixmap pixmap; /* final pixmap */ - Pixmap pixmap_mask; /* final pixmap of mask */ -} XImageInfo; - -struct RGBMap -{ - unsigned int used; /* number of colors used in RGB map */ - Intensity red[MAX_COLORS]; /* color values in X style */ - Intensity green[MAX_COLORS]; - Intensity blue[MAX_COLORS]; - boolean color_used[MAX_COLORS]; /* flag if color cell is used */ -}; - -typedef struct -{ - unsigned int type; /* type of image (True-Color etc.) */ - struct RGBMap rgb; /* RGB map of image if IRGB type */ - unsigned int width; /* width of image in pixels */ - unsigned int height; /* height of image in pixels */ - unsigned int depth; /* depth of image in bits if IRGB type */ - unsigned int bytes_per_pixel;/* (depth + 7) / 8 */ - unsigned int bytes_per_row; /* width * bytes_per_pixel */ - byte *data; /* image data */ -} Image; - -#define IMAGETYPE_BITMAP 0 /* monochrome bitmap */ -#define IMAGETYPE_RGB 1 /* RGB image with colormap */ -#define IMAGETYPE_TRUECOLOR 2 /* true-color image */ - -#define TRUECOLOR_RED(pixel) (((unsigned int)((pixel) & 0xff0000)) >> 16) -#define TRUECOLOR_GREEN(pixel) (((unsigned int)((pixel) & 0xff00)) >> 8) -#define TRUECOLOR_BLUE(pixel) ( (unsigned int)((pixel) & 0xff)) -#define RGB_TO_TRUECOLOR(r,g,b) ((((unsigned int)((r) & 0xff00)) << 8) | ((g) & 0xff00) | (((unsigned short)(b)) >> 8)) - -Image *newImage(unsigned int, unsigned int, unsigned int); -void freeImage(Image *); -void freeXImage(Image *, XImageInfo *); - -Pixmap Pixmap_to_Mask(Pixmap, int, int); - -void ZoomPixmap(Display *, GC, Pixmap, Pixmap, int, int, int, int); - -int Read_PCX_to_Pixmap(Display *, Window, GC, char *, Pixmap *, Pixmap *); - -#endif /* TARGET_X11 */ - int getImageListSize(); struct FileInfo *getImageListEntryFromImageID(int); Bitmap *getBitmapFromImageID(int); diff --git a/src/libgame/joystick.c b/src/libgame/joystick.c index d5a78a29..0966b949 100644 --- a/src/libgame/joystick.c +++ b/src/libgame/joystick.c @@ -19,91 +19,6 @@ #include "misc.h" -/* ========================================================================= */ -/* platform dependent joystick functions */ -/* ========================================================================= */ - -#if defined(PLATFORM_UNIX) && !defined(TARGET_SDL) -void UnixInitJoysticks() -{ - static boolean unix_joystick_subsystem_initialized = FALSE; - boolean print_warning = !unix_joystick_subsystem_initialized; - int i; - - for (i = 0; i < MAX_PLAYERS; i++) - { - char *device_name = setup.input[i].joy.device_name; - - /* this allows subsequent calls to 'InitJoysticks' for re-initialization */ - if (joystick.fd[i] != -1) - { - close(joystick.fd[i]); - joystick.fd[i] = -1; - } - - if (!setup.input[i].use_joystick) - continue; - - if (access(device_name, R_OK) != 0) - { - if (print_warning) - Error(ERR_WARN, "cannot access joystick device '%s'", device_name); - - continue; - } - - if ((joystick.fd[i] = open(device_name, O_RDONLY)) < 0) - { - if (print_warning) - Error(ERR_WARN, "cannot open joystick device '%s'", device_name); - - continue; - } - - joystick.status = JOYSTICK_ACTIVATED; - } - - unix_joystick_subsystem_initialized = TRUE; -} - -boolean UnixReadJoystick(int fd, int *x, int *y, boolean *b1, boolean *b2) -{ -#if defined(PLATFORM_FREEBSD) - struct joystick joy_ctrl; -#else - struct joystick_control - { - int buttons; - int x; - int y; - } joy_ctrl; -#endif - - if (read(fd, &joy_ctrl, sizeof(joy_ctrl)) != sizeof(joy_ctrl)) - return FALSE; - - if (x != NULL) - *x = joy_ctrl.x; - if (y != NULL) - *y = joy_ctrl.y; - -#if defined(PLATFORM_FREEBSD) - if (b1 != NULL) - *b1 = joy_ctrl.b1; - if (b2 != NULL) - *b2 = joy_ctrl.b2; -#else - if (b1 != NULL) - *b1 = joy_ctrl.buttons & 1; - if (b2 != NULL) - *b2 = joy_ctrl.buttons & 2; -#endif - - return TRUE; -} -#endif /* PLATFORM_UNIX && !TARGET_SDL */ - - /* ========================================================================= */ /* platform independent joystick functions */ /* ========================================================================= */ diff --git a/src/libgame/joystick.h b/src/libgame/joystick.h index d778c88c..fe4356e8 100644 --- a/src/libgame/joystick.h +++ b/src/libgame/joystick.h @@ -72,11 +72,6 @@ #define JOY_BUTTON_NEW_PRESSED 2 #define JOY_BUTTON_NEW_RELEASED 3 -#if defined(PLATFORM_UNIX) -void UnixInitJoysticks(void); -boolean UnixReadJoystick(int, int *, int *, boolean *, boolean *); -#endif - char *getJoyNameFromJoySymbol(int); int getJoySymbolFromJoyName(char *); int getJoystickNrFromDeviceName(char *); diff --git a/src/libgame/libgame.h b/src/libgame/libgame.h index d1f05c82..3ce4812e 100644 --- a/src/libgame/libgame.h +++ b/src/libgame/libgame.h @@ -27,7 +27,6 @@ #include "joystick.h" #include "toons.h" #include "image.h" -#include "pcx.h" #include "setup.h" #include "misc.h" diff --git a/src/libgame/misc.c b/src/libgame/misc.c index 7c2f4353..5fdbe85b 100644 --- a/src/libgame/misc.c +++ b/src/libgame/misc.c @@ -233,20 +233,7 @@ static unsigned int getCurrentMS() { return SDL_GetTicks(); } - -#else /* !TARGET_SDL */ - -#if defined(PLATFORM_UNIX) -static unsigned int getCurrentMS() -{ - struct timeval current_time; - - gettimeofday(¤t_time, NULL); - - return current_time.tv_sec * 1000 + current_time.tv_usec / 1000; -} -#endif /* PLATFORM_UNIX */ -#endif /* !TARGET_SDL */ +#endif static unsigned int mainCounter(int mode) { @@ -283,29 +270,7 @@ static unsigned int mainCounter(int mode) return counter_ms; /* return milliseconds since last init */ } - -#else /* !TARGET_SDL */ - -#if defined(PLATFORM_UNIX) -static unsigned int mainCounter(int mode) -{ - static struct timeval base_time = { 0, 0 }; - struct timeval current_time; - unsigned int counter_ms; - - gettimeofday(¤t_time, NULL); - - /* reset base time in case of counter initializing or wrap-around */ - if (mode == INIT_COUNTER || current_time.tv_sec < base_time.tv_sec) - base_time = current_time; - - counter_ms = (current_time.tv_sec - base_time.tv_sec) * 1000 - + (current_time.tv_usec - base_time.tv_usec) / 1000; - - return counter_ms; /* return milliseconds since last init */ -} -#endif /* PLATFORM_UNIX */ -#endif /* !TARGET_SDL */ +#endif #endif @@ -340,8 +305,6 @@ static void sleep_milliseconds(unsigned int milliseconds_delay) { #if defined(TARGET_SDL) SDL_Delay(milliseconds_delay); -#elif defined(TARGET_ALLEGRO) - rest(milliseconds_delay); #else struct timeval delay; diff --git a/src/libgame/pcx.c b/src/libgame/pcx.c deleted file mode 100644 index 908def5c..00000000 --- a/src/libgame/pcx.c +++ /dev/null @@ -1,314 +0,0 @@ -/*********************************************************** -* Artsoft Retro-Game Library * -*----------------------------------------------------------* -* (c) 1994-2006 Artsoft Entertainment * -* Holger Schemel * -* Detmolder Strasse 189 * -* 33604 Bielefeld * -* Germany * -* e-mail: info@artsoft.org * -*----------------------------------------------------------* -* pcx.c * -***********************************************************/ - -#include "pcx.h" -#include "misc.h" - - -#if !defined(TARGET_SDL) - -#define PCX_DEBUG 0 - -#define PCX_MAGIC 0x0a /* first byte in a PCX image file */ -#define PCX_SUPPORTED_VERSION 5 /* last acceptable version number */ -#define PCX_ENCODING 1 /* PCX encoding method */ -#define PCX_256COLORS_MAGIC 0x0c /* first byte of a PCX 256 color map */ -#define PCX_MAXCOLORS 256 /* maximum number of colors */ - -#define PCX_HEADER_SIZE 128 -#define PCX_COLORMAP_SIZE (3 * PCX_MAXCOLORS) - -struct PCX_Header -{ - unsigned char signature; /* PCX file identifier */ - unsigned char version; /* version compatibility level */ - unsigned char encoding; /* encoding method */ - unsigned char bits_per_pixel; /* bits per pixel (not depth!) */ - unsigned short xmin; /* X position of left edge */ - unsigned short ymin; /* Y position of top edge */ - unsigned short xmax; /* X position of right edge */ - unsigned short ymax; /* Y position of bottom edge */ - unsigned short hres; /* X screen resolution of source image */ - unsigned short vres; /* Y screen resolution of source image */ - unsigned char palette[16][3]; /* PCX color map */ - unsigned char reserved; /* should be 0, 1 if std res fax */ - unsigned char color_planes; /* "color planes" in image */ - unsigned short bytes_per_line;/* byte delta between scanlines */ - unsigned short palette_type; /* 0 = undef, 1 = color, 2 = grayscale */ - unsigned char filler[58]; /* fill to struct size of 128 */ -}; - -/* global PCX error value */ -int errno_pcx = PCX_Success; - -static boolean PCX_ReadBitmap(FILE *file, struct PCX_Header *pcx, Image *image) -{ - int width = image->width; - int height = image->height; - int pcx_depth = pcx->bits_per_pixel * pcx->color_planes; - int bytes_per_row = pcx->color_planes * pcx->bytes_per_line; - byte *row_buffer = checked_malloc(bytes_per_row); - byte *bitmap_ptr = image->data; - int y; - - for (y = 0; y < height; y++) - { - /* decode a scan line into a temporary buffer first */ - byte *dst_ptr = (pcx_depth == 8 ? bitmap_ptr : row_buffer); - byte value = 0, count = 0; - int value_int; - int i; - - for (i = 0; i < bytes_per_row; i++) - { - if (count == 0) - { - if ((value_int = fgetc(file)) == EOF) - { - free(row_buffer); - return FALSE; - } - - value = (byte)value_int; - - if ((value & 0xc0) == 0xc0) /* this is a repeat count byte */ - { - count = value & 0x3f; /* extract repeat count from byte */ - - if ((value_int = fgetc(file)) == EOF) - { - free(row_buffer); - return FALSE; - } - - value = (byte)value_int; - } - else - count = 1; - } - - dst_ptr[i] = value; - count--; - - if (pcx_depth == 8) - image->rgb.color_used[value] = TRUE; - } - - if (pcx_depth <= 4) /* expand planes to 1 byte/pixel */ - { - byte *src_ptr = row_buffer; - int plane; - - for (plane = 0; plane < pcx->color_planes; plane++) - { - int i, j, x = 0; - - for (i = 0; i < pcx->bytes_per_line; i++) - { - byte value = *src_ptr++; - - for (j = 7; j >= 0; j--) - { - byte bit = (value >> j) & 1; - - if (i * 8 + j >= width) /* skip padding bits */ - continue; - - bitmap_ptr[x++] |= bit << plane; - } - } - } - } - else if (pcx_depth == 24) /* de-interlace planes */ - { - byte *src_ptr = row_buffer; - int plane; - - for (plane = 0; plane < pcx->color_planes; plane++) - { - int x; - - dst_ptr = bitmap_ptr + plane; - for (x = 0; x < width; x++) - { - *dst_ptr = *src_ptr++; - dst_ptr += pcx->color_planes; - } - } - } - - bitmap_ptr += image->bytes_per_row; - } - - free(row_buffer); - - return TRUE; -} - -static boolean PCX_ReadColormap(FILE *file,struct PCX_Header *pcx,Image *image) -{ - int pcx_depth = pcx->bits_per_pixel * pcx->color_planes; - int num_colors = (1 << pcx_depth); - int i; - - if (image->depth != 8) - return TRUE; - - if (pcx_depth == 8) - { - byte value; - int value_int; - - /* look for a 256-colour palette */ - do - { - if ((value_int = fgetc(file)) == EOF) - return FALSE; - value = (byte)value_int; - } - while (value != PCX_256COLORS_MAGIC); - - /* read 256 colors from PCX colormap */ - for (i = 0; i < PCX_MAXCOLORS; i++) - { - image->rgb.red[i] = (byte)fgetc(file) << 8; - image->rgb.green[i] = (byte)fgetc(file) << 8; - image->rgb.blue[i] = (byte)fgetc(file) << 8; - } - } - else - { - for (i = 0; i < num_colors; i++) - { - image->rgb.red[i] = pcx->palette[i][0] << 8; - image->rgb.green[i] = pcx->palette[i][1] << 8; - image->rgb.blue[i] = pcx->palette[i][2] << 8; - } - } - - return TRUE; -} - -Image *Read_PCX_to_Image(char *filename) -{ - FILE *file; - byte header_buffer[PCX_HEADER_SIZE]; - struct PCX_Header pcx; - Image *image; - int width, height, depth, pcx_depth; - int i; - - errno_pcx = PCX_Success; - - if (!(file = fopen(filename, MODE_READ))) - { - errno_pcx = PCX_OpenFailed; - return NULL; - } - - if (fread(header_buffer, 1, PCX_HEADER_SIZE, file) != PCX_HEADER_SIZE) - { - fclose(file); - - errno_pcx = PCX_ReadFailed; - return NULL; - } - - pcx.signature = header_buffer[0]; - pcx.version = header_buffer[1]; - pcx.encoding = header_buffer[2]; - pcx.bits_per_pixel = header_buffer[3]; - pcx.xmin = (header_buffer[5] << 8) | header_buffer[4]; - pcx.ymin = (header_buffer[7] << 8) | header_buffer[6]; - pcx.xmax = (header_buffer[9] << 8) | header_buffer[8]; - pcx.ymax = (header_buffer[11] << 8) | header_buffer[10]; - pcx.color_planes = header_buffer[65]; - pcx.bytes_per_line = (header_buffer[67] << 8) | header_buffer[66]; - pcx.palette_type = (header_buffer[69] << 8) | header_buffer[68]; - - for (i = 0; i < 48; i++) - pcx.palette[i / 3][i % 3] = header_buffer[16 + i]; - - width = pcx.xmax - pcx.xmin + 1; - height = pcx.ymax - pcx.ymin + 1; - pcx_depth = pcx.bits_per_pixel * pcx.color_planes; - depth = ((pcx_depth + 7) / 8) * 8; - - if (pcx.signature != PCX_MAGIC || - pcx.version != PCX_SUPPORTED_VERSION || - pcx.encoding != PCX_ENCODING || - width < 0 || height < 0) - { - fclose(file); - - errno_pcx = PCX_FileInvalid; - return NULL; - } - -#if PCX_DEBUG - if (options.verbose) - { - printf("\n"); - printf("%s is a %dx%d PC Paintbrush image\n", filename, width, height); - printf("depth: %d\n", depth); - printf("bits_per_pixel: %d\n", pcx.bits_per_pixel); - printf("color_planes: %d\n", pcx.color_planes); - printf("bytes_per_line: %d\n", pcx.bytes_per_line); - printf("palette type: %s\n", - (pcx.palette_type == 1 ? "color" : - pcx.palette_type == 2 ? "grayscale" : "undefined")); - } -#endif - - /* allocate new image structure */ - image = newImage(width, height, depth); - - /* read compressed bitmap data */ - if (!PCX_ReadBitmap(file, &pcx, image)) - { - fclose(file); - freeImage(image); - - errno_pcx = PCX_FileInvalid; - return NULL; - } - - /* read colormap data */ - if (!PCX_ReadColormap(file, &pcx, image)) - { - fclose(file); - freeImage(image); - - errno_pcx = PCX_ColorFailed; - return NULL; - } - - fclose(file); - - if (pcx_depth == 8) - { - /* determine number of used colormap entries for 8-bit PCX images */ - for (i = 0; i < PCX_MAXCOLORS; i++) - if (image->rgb.color_used[i]) - image->rgb.used++; - } - -#if PCX_DEBUG - if (options.verbose) - printf("Read_PCX_to_Image: %d colors in colormap\n", image->rgb.used); -#endif - - return image; -} - -#endif /* !TARGET_SDL */ diff --git a/src/libgame/pcx.h b/src/libgame/pcx.h deleted file mode 100644 index 566c28d3..00000000 --- a/src/libgame/pcx.h +++ /dev/null @@ -1,37 +0,0 @@ -/*********************************************************** -* Artsoft Retro-Game Library * -*----------------------------------------------------------* -* (c) 1994-2006 Artsoft Entertainment * -* Holger Schemel * -* Detmolder Strasse 189 * -* 33604 Bielefeld * -* Germany * -* e-mail: info@artsoft.org * -*----------------------------------------------------------* -* pcx.h * -***********************************************************/ - -#ifndef PCX_H -#define PCX_H - -#include "system.h" -#include "image.h" - - -#if !defined(TARGET_SDL) - -#define PCX_Success 0 -#define PCX_OpenFailed -1 -#define PCX_ReadFailed -2 -#define PCX_FileInvalid -3 -#define PCX_NoMemory -4 -#define PCX_ColorFailed -5 -#define PCX_OtherError -6 - -/* global PCX error value */ -extern int errno_pcx; - -Image *Read_PCX_to_Image(char *); - -#endif /* !TARGET_SDL */ -#endif /* PCX_H */ diff --git a/src/libgame/platform.h b/src/libgame/platform.h index 292ff45c..a908fc7c 100644 --- a/src/libgame/platform.h +++ b/src/libgame/platform.h @@ -160,10 +160,6 @@ /* define additional target keywords */ /* ========================================================================= */ -#if defined(PLATFORM_UNIX) && defined(TARGET_X11) -#define TARGET_X11_NATIVE -#endif - #if defined(TARGET_SDL2) #ifndef TARGET_SDL #define TARGET_SDL diff --git a/src/libgame/setup.c b/src/libgame/setup.c index a0711637..cb1da5bd 100644 --- a/src/libgame/setup.c +++ b/src/libgame/setup.c @@ -598,9 +598,7 @@ char *getLevelSetTitleMessageFilename(int nr, boolean initial) static char *getCorrectedArtworkBasename(char *basename) { - char *basename_corrected = basename; - - return basename_corrected; + return basename; } char *getCustomImageFilename(char *basename) diff --git a/src/libgame/sound.c b/src/libgame/sound.c index adfb8147..c5ec068f 100644 --- a/src/libgame/sound.c +++ b/src/libgame/sound.c @@ -138,10 +138,6 @@ struct SoundControl void *data_ptr; /* pointer to first sample (8 or 16 bit) */ int data_len; /* number of samples, NOT number of bytes */ int num_channels; /* mono: 1 channel, stereo: 2 channels */ - -#if defined(TARGET_ALLEGRO) - int voice; -#endif }; typedef struct SoundControl SoundControl; @@ -650,32 +646,15 @@ static boolean Mixer_ChannelExpired(int channel) return TRUE; #if defined(TARGET_SDL) - if (!Mix_Playing(channel)) return TRUE; - -#elif defined(TARGET_ALLEGRO) - - mixer[channel].playing_pos = voice_get_position(mixer[channel].voice); - mixer[channel].volume = voice_get_volume(mixer[channel].voice); - - /* sound sample has completed playing or was completely faded out */ - if (mixer[channel].playing_pos == -1 || mixer[channel].volume == 0) - return TRUE; - -#endif /* TARGET_ALLEGRO */ +#endif return FALSE; } static boolean Mixer_AllocateChannel(int channel) { -#if defined(TARGET_ALLEGRO) - mixer[channel].voice = allocate_voice((SAMPLE *)mixer[channel].data_ptr); - if (mixer[channel].voice < 0) - return FALSE; -#endif - return TRUE; } @@ -686,9 +665,6 @@ static void Mixer_SetChannelProperties(int channel) Mix_SetPanning(channel, SOUND_VOLUME_LEFT(mixer[channel].stereo_position), SOUND_VOLUME_RIGHT(mixer[channel].stereo_position)); -#elif defined(TARGET_ALLEGRO) - voice_set_volume(mixer[channel].voice, mixer[channel].volume); - voice_set_pan(mixer[channel].voice, mixer[channel].stereo_position); #endif } @@ -697,11 +673,6 @@ static void Mixer_StartChannel(int channel) #if defined(TARGET_SDL) Mix_PlayChannel(channel, mixer[channel].data_ptr, IS_LOOP(mixer[channel]) ? -1 : 0); -#elif defined(TARGET_ALLEGRO) - if (IS_LOOP(mixer[channel])) - voice_set_playmode(mixer[channel].voice, PLAYMODE_LOOP); - - voice_start(mixer[channel].voice); #endif } @@ -748,9 +719,6 @@ static void Mixer_StopChannel(int channel) #if defined(TARGET_SDL) Mix_HaltChannel(channel); -#elif defined(TARGET_ALLEGRO) - voice_set_volume(mixer[channel].voice, 0); - deallocate_voice(mixer[channel].voice); #endif mixer[channel].active = FALSE; @@ -775,9 +743,6 @@ static void Mixer_FadeChannel(int channel) #if defined(TARGET_SDL) Mix_FadeOutChannel(channel, SOUND_FADING_INTERVAL); -#elif defined(TARGET_ALLEGRO) - if (voice_check(mixer[channel].voice)) - voice_ramp_volume(mixer[channel].voice, SOUND_FADING_INTERVAL, 0); #endif } @@ -801,10 +766,6 @@ static void Mixer_UnFadeChannel(int channel) #if defined(TARGET_SDL) Mix_ExpireChannel(channel, -1); Mix_Volume(channel, mixer[channel].volume); -#elif defined(TARGET_ALLEGRO) - voice_stop_volumeramp(mixer[channel].voice); - voice_ramp_volume(mixer[channel].voice, SOUND_FADING_INTERVAL, - mixer[channel].volume); #endif } @@ -1563,17 +1524,6 @@ static void *Load_WAV(char *filename) snd_info->data_len = ((Mix_Chunk *)snd_info->data_ptr)->alen; -#elif defined(TARGET_ALLEGRO) - - if ((snd_info->data_ptr = load_sample(filename)) == NULL) - { - Error(ERR_WARN, "cannot read sound file '%s'", filename); - free(snd_info); - return NULL; - } - - snd_info->data_len = ((SAMPLE *)snd_info->data_ptr)->len; - #else /* AUDIO_UNIX_NATIVE */ clear_mem(&header, sizeof(struct SoundHeader_WAV)); /* to make gcc happy */ @@ -2371,8 +2321,6 @@ void FreeSound(void *ptr) { #if defined(TARGET_SDL) Mix_FreeChunk(sound->data_ptr); -#elif defined(TARGET_ALLEGRO) - destroy_sample(sound->data_ptr); #else /* AUDIO_UNIX_NATIVE */ free(sound->data_ptr); #endif @@ -2397,8 +2345,6 @@ void FreeMusic(void *ptr) Mix_FreeMusic(music->data_ptr); else Mix_FreeChunk(music->data_ptr); -#elif defined(TARGET_ALLEGRO) - destroy_sample(music->data_ptr); #else /* AUDIO_UNIX_NATIVE */ free(music->data_ptr); #endif diff --git a/src/libgame/sound.h b/src/libgame/sound.h index fc111e9b..e6a8a20a 100644 --- a/src/libgame/sound.h +++ b/src/libgame/sound.h @@ -17,10 +17,6 @@ #include "system.h" -#if defined(PLATFORM_UNIX) && !defined(TARGET_SDL) -#define AUDIO_UNIX_NATIVE -#endif - #if defined(PLATFORM_LINUX) || defined(PLATFORM_FREEBSD) || defined(VOXWARE) #define AUDIO_LINUX_IOCTL #endif @@ -109,8 +105,6 @@ #define SOUND_MIN_VOLUME 0 #if defined(TARGET_SDL) #define SOUND_MAX_VOLUME SDL_MIX_MAXVOLUME -#elif defined(TARGET_ALLEGRO) -#define SOUND_MAX_VOLUME 255 #else #define SOUND_MAX_VOLUME 128 #endif diff --git a/src/libgame/system.c b/src/libgame/system.c index 1e43e0b7..3f466bcc 100644 --- a/src/libgame/system.c +++ b/src/libgame/system.c @@ -71,14 +71,8 @@ int FrameCounter = 0; void InitProgramInfo(char *argv0, char *userdata_subdir, char *userdata_subdir_unix, - char *program_title, -#if 0 - char *window_title, -#endif - char *icon_title, - char *x11_icon_filename, char *x11_iconmask_filename, - char *sdl_icon_filename, - char *cookie_prefix, char *filename_prefix, + char *program_title, char *icon_title, + char *sdl_icon_filename, char *cookie_prefix, int program_version) { program.command_basepath = getBasePath(argv0); @@ -89,19 +83,12 @@ void InitProgramInfo(char *argv0, program.userdata_path = getUserGameDataDir(); program.program_title = program_title; -#if 1 program.window_title = "(undefined)"; -#else - program.window_title = window_title; -#endif program.icon_title = icon_title; - program.x11_icon_filename = x11_icon_filename; - program.x11_iconmask_filename = x11_iconmask_filename; program.sdl_icon_filename = sdl_icon_filename; program.cookie_prefix = cookie_prefix; - program.filename_prefix = filename_prefix; program.version_major = VERSION_MAJOR(program_version); program.version_minor = VERSION_MINOR(program_version); @@ -408,24 +395,15 @@ inline static int GetRealDepth(int depth) inline static void sysFillRectangle(Bitmap *bitmap, int x, int y, int width, int height, Pixel color) { -#if defined(TARGET_SDL) SDLFillRectangle(bitmap, x, y, width, height, color); -#else - X11FillRectangle(bitmap, x, y, width, height, color); -#endif } inline static void sysCopyArea(Bitmap *src_bitmap, Bitmap *dst_bitmap, int src_x, int src_y, int width, int height, int dst_x, int dst_y, int mask_mode) { -#if defined(TARGET_SDL) SDLCopyArea(src_bitmap, dst_bitmap, src_x, src_y, width, height, dst_x, dst_y, mask_mode); -#else - X11CopyArea(src_bitmap, dst_bitmap, src_x, src_y, width, height, - dst_x, dst_y, mask_mode); -#endif } void LimitScreenUpdates(boolean enable) @@ -437,11 +415,7 @@ void LimitScreenUpdates(boolean enable) void InitVideoDisplay(void) { -#if defined(TARGET_SDL) SDLInitVideoDisplay(); -#else - X11InitVideoDisplay(); -#endif } void CloseVideoDisplay(void) @@ -476,11 +450,7 @@ void InitVideoBuffer(int width, int height, int depth, boolean fullscreen) video.window_scaling_available = WINDOW_SCALING_STATUS; -#if defined(TARGET_SDL) SDLInitVideoBuffer(&backbuffer, &window, fullscreen); -#else - X11InitVideoBuffer(&backbuffer, &window); -#endif drawto = backbuffer; } @@ -490,11 +460,7 @@ inline static void FreeBitmapPointers(Bitmap *bitmap) if (bitmap == NULL) return; -#if defined(TARGET_SDL) SDLFreeBitmapPointers(bitmap); -#else - X11FreeBitmapPointers(bitmap); -#endif checked_free(bitmap->source_filename); bitmap->source_filename = NULL; @@ -523,11 +489,7 @@ void FreeBitmap(Bitmap *bitmap) Bitmap *CreateBitmapStruct(void) { -#if defined(TARGET_SDL) return checked_calloc(sizeof(struct SDLSurfaceInfo)); -#else - return checked_calloc(sizeof(struct X11DrawableInfo)); -#endif } Bitmap *CreateBitmap(int width, int height, int depth) @@ -537,11 +499,7 @@ Bitmap *CreateBitmap(int width, int height, int depth) int real_height = MAX(1, height); /* prevent zero bitmap height */ int real_depth = GetRealDepth(depth); -#if defined(TARGET_SDL) SDLCreateBitmapContent(new_bitmap, real_width, real_height, real_depth); -#else - X11CreateBitmapContent(new_bitmap, real_width, real_height, real_depth); -#endif new_bitmap->width = real_width; new_bitmap->height = real_height; @@ -566,9 +524,6 @@ void ReCreateBitmap(Bitmap **bitmap, int width, int height, int depth) void CloseWindow(DrawWindow *window) { -#if defined(TARGET_X11) - X11CloseWindow(window); -#endif } inline static boolean CheckDrawingArea(int x, int y, int width, int height, @@ -854,13 +809,8 @@ void FadeRectangle(Bitmap *bitmap_cross, int x, int y, int width, int height, return; #endif -#if defined(TARGET_SDL) SDLFadeRectangle(bitmap_cross, x, y, width, height, fade_mode, fade_delay, post_delay, draw_border_function); -#else - X11FadeRectangle(bitmap_cross, x, y, width, height, - fade_mode, fade_delay, post_delay, draw_border_function); -#endif } void FillRectangle(Bitmap *bitmap, int x, int y, int width, int height, @@ -904,24 +854,10 @@ void ClearRectangleOnBackground(Bitmap *bitmap, int x, int y, void SetClipMask(Bitmap *bitmap, GC clip_gc, Pixmap clip_pixmap) { -#if defined(TARGET_X11) - if (clip_gc) - { - bitmap->clip_gc = clip_gc; - XSetClipMask(display, bitmap->clip_gc, clip_pixmap); - } -#endif } void SetClipOrigin(Bitmap *bitmap, GC clip_gc, int clip_x, int clip_y) { -#if defined(TARGET_X11) - if (clip_gc) - { - bitmap->clip_gc = clip_gc; - XSetClipOrigin(display, bitmap->clip_gc, clip_x, clip_y); - } -#endif } void BlitBitmapMasked(Bitmap *src_bitmap, Bitmap *dst_bitmap, @@ -959,24 +895,15 @@ void BlitBitmapOnBackground(Bitmap *src_bitmap, Bitmap *dst_bitmap, void DrawSimpleBlackLine(Bitmap *bitmap, int from_x, int from_y, int to_x, int to_y) { -#if defined(TARGET_SDL) SDLDrawSimpleLine(bitmap, from_x, from_y, to_x, to_y, BLACK_PIXEL); -#else - X11DrawSimpleLine(bitmap, from_x, from_y, to_x, to_y, BLACK_PIXEL); -#endif } void DrawSimpleWhiteLine(Bitmap *bitmap, int from_x, int from_y, int to_x, int to_y) { -#if defined(TARGET_SDL) SDLDrawSimpleLine(bitmap, from_x, from_y, to_x, to_y, WHITE_PIXEL); -#else - X11DrawSimpleLine(bitmap, from_x, from_y, to_x, to_y, WHITE_PIXEL); -#endif } -#if !defined(TARGET_X11_NATIVE) void DrawLine(Bitmap *bitmap, int from_x, int from_y, int to_x, int to_y, Pixel pixel, int line_width) { @@ -995,21 +922,14 @@ void DrawLine(Bitmap *bitmap, int from_x, int from_y, (x == line_width - 1 && y == line_width - 1)) continue; -#if defined(TARGET_SDL) SDLDrawLine(bitmap, from_x + dx, from_y + dy, to_x + dx, to_y + dy, pixel); -#elif defined(TARGET_ALLEGRO) - AllegroDrawLine(bitmap->drawable, from_x + dx, from_y + dy, - to_x + dx, to_y + dy, pixel); -#endif } } } -#endif void DrawLines(Bitmap *bitmap, struct XY *points, int num_points, Pixel pixel) { -#if !defined(TARGET_X11_NATIVE) int line_width = 4; int i; @@ -1020,11 +940,6 @@ void DrawLines(Bitmap *bitmap, struct XY *points, int num_points, Pixel pixel) /* SDLDrawLines(bitmap->surface, points, num_points, pixel); */ -#else - XSetForeground(display, bitmap->line_gc[1], pixel); - XDrawLines(display, bitmap->drawable, bitmap->line_gc[1], - (XPoint *)points, num_points, CoordModeOrigin); -#endif } Pixel GetPixel(Bitmap *bitmap, int x, int y) @@ -1033,25 +948,13 @@ Pixel GetPixel(Bitmap *bitmap, int x, int y) y < 0 || y >= bitmap->height) return BLACK_PIXEL; -#if defined(TARGET_SDL) return SDLGetPixel(bitmap, x, y); -#elif defined(TARGET_ALLEGRO) - return AllegroGetPixel(bitmap->drawable, x, y); -#else - return X11GetPixel(bitmap, x, y); -#endif } Pixel GetPixelFromRGB(Bitmap *bitmap, unsigned int color_r, unsigned int color_g, unsigned int color_b) { -#if defined(TARGET_SDL) return SDL_MapRGB(bitmap->surface->format, color_r, color_g, color_b); -#elif defined(TARGET_ALLEGRO) - return AllegroAllocColorCell(color_r << 8, color_g << 8, color_b << 8); -#else - return X11GetPixelFromRGB(color_r, color_g, color_b); -#endif } Pixel GetPixelFromRGBcompact(Bitmap *bitmap, unsigned int color) @@ -1066,17 +969,11 @@ Pixel GetPixelFromRGBcompact(Bitmap *bitmap, unsigned int color) /* execute all pending screen drawing operations */ void FlushDisplay(void) { -#if !defined(TARGET_SDL) - XFlush(display); -#endif } /* execute and wait for all pending screen drawing operations */ void SyncDisplay(void) { -#if !defined(TARGET_SDL) - XSync(display, FALSE); -#endif } void KeyboardAutoRepeatOn(void) @@ -1129,23 +1026,7 @@ boolean PointerInWindow(DrawWindow *window) boolean SetVideoMode(boolean fullscreen) { -#if defined(TARGET_SDL) return SDLSetVideoMode(&backbuffer, fullscreen); -#else - boolean success = TRUE; - - if (fullscreen && video.fullscreen_available) - { - Error(ERR_WARN, "fullscreen not available in X11 version"); - - /* display error message only once */ - video.fullscreen_available = FALSE; - - success = FALSE; - } - - return success; -#endif } boolean ChangeVideoModeIfNeeded(boolean fullscreen) @@ -1163,11 +1044,7 @@ Bitmap *LoadImage(char *filename) { Bitmap *new_bitmap; -#if defined(TARGET_SDL) new_bitmap = SDLLoadImage(filename); -#else - new_bitmap = X11LoadImage(filename); -#endif if (new_bitmap) new_bitmap->source_filename = getStringCopy(filename); @@ -1232,11 +1109,7 @@ Bitmap *ZoomBitmap(Bitmap *src_bitmap, int zoom_width, int zoom_height) { Bitmap *dst_bitmap = CreateBitmap(zoom_width, zoom_height, DEFAULT_DEPTH); -#if defined(TARGET_SDL) SDLZoomBitmap(src_bitmap, dst_bitmap); -#else - X11ZoomBitmap(src_bitmap, dst_bitmap); -#endif return dst_bitmap; } @@ -1342,15 +1215,6 @@ static void CreateScaledBitmaps(Bitmap *old_bitmap, int zoom_factor, /* if image was scaled up, create new clipmask for normal size image */ if (zoom_factor != 1) { -#if defined(TARGET_X11) - if (old_bitmap->clip_mask) - XFreePixmap(display, old_bitmap->clip_mask); - - old_bitmap->clip_mask = - Pixmap_to_Mask(tmp_bitmap_1->drawable, width_1, height_1); - - XSetClipMask(display, old_bitmap->stored_clip_gc, old_bitmap->clip_mask); -#else SDL_Surface *tmp_surface_1 = tmp_bitmap_1->surface; if (old_bitmap->surface_masked) @@ -1361,7 +1225,6 @@ static void CreateScaledBitmaps(Bitmap *old_bitmap, int zoom_factor, if ((old_bitmap->surface_masked = SDL_DisplayFormat(tmp_surface_1)) ==NULL) Error(ERR_EXIT, "SDL_DisplayFormat() failed"); SDL_SetColorKey(tmp_surface_1, UNSET_TRANSPARENT_PIXEL, 0); -#endif } #endif @@ -1433,15 +1296,6 @@ static void CreateScaledBitmaps(Bitmap *old_bitmap, int zoom_factor, #if 1 /* this replaces all blit masks created when loading -- maybe optimize this */ { -#if defined(TARGET_X11) - if (old_bitmap->clip_mask) - XFreePixmap(display, old_bitmap->clip_mask); - - old_bitmap->clip_mask = - Pixmap_to_Mask(old_bitmap->drawable, new_width, new_height); - - XSetClipMask(display, old_bitmap->stored_clip_gc, old_bitmap->clip_mask); -#else SDL_Surface *old_surface = old_bitmap->surface; if (old_bitmap->surface_masked) @@ -1452,7 +1306,6 @@ static void CreateScaledBitmaps(Bitmap *old_bitmap, int zoom_factor, if ((old_bitmap->surface_masked = SDL_DisplayFormat(old_surface)) ==NULL) Error(ERR_EXIT, "SDL_DisplayFormat() failed"); SDL_SetColorKey(old_surface, UNSET_TRANSPARENT_PIXEL, 0); -#endif } #endif @@ -1550,11 +1403,7 @@ static const char **cursor_image_playfield = cursor_image_dot; static const char **cursor_image_playfield = cursor_image_none; #endif -#if defined(TARGET_SDL) static const int cursor_bit_order = BIT_ORDER_MSB; -#elif defined(TARGET_X11_NATIVE) -static const int cursor_bit_order = BIT_ORDER_LSB; -#endif static struct MouseCursorInfo *get_cursor_from_image(const char **image) { @@ -1619,11 +1468,7 @@ void SetMouseCursor(int mode) mode == CURSOR_NONE ? cursor_none : mode == CURSOR_PLAYFIELD ? cursor_playfield : NULL); -#if defined(TARGET_SDL) SDLSetMouseCursor(cursor_new); -#elif defined(TARGET_X11_NATIVE) - X11SetMouseCursor(cursor_new); -#endif } @@ -1652,8 +1497,6 @@ void OpenAudio(void) #if defined(TARGET_SDL) SDLOpenAudio(); -#elif defined(PLATFORM_UNIX) - UnixOpenAudio(); #endif } @@ -1661,8 +1504,6 @@ void CloseAudio(void) { #if defined(TARGET_SDL) SDLCloseAudio(); -#elif defined(PLATFORM_UNIX) - UnixCloseAudio(); #endif audio.sound_enabled = FALSE; @@ -1836,10 +1677,6 @@ boolean CheckCloseWindowEvent(ClientMessageEvent *event) #if defined(TARGET_SDL) return TRUE; /* the only possible message here is SDL_QUIT */ -#elif defined(PLATFORM_UNIX) - if ((event->window == window->drawable) && - (event->data.l[0] == XInternAtom(display, "WM_DELETE_WINDOW", FALSE))) - return TRUE; #endif return FALSE; @@ -1865,8 +1702,6 @@ void InitJoysticks() #if defined(TARGET_SDL) SDLInitJoysticks(); -#elif defined(PLATFORM_UNIX) - UnixInitJoysticks(); #endif #if 0 @@ -1879,7 +1714,5 @@ boolean ReadJoystick(int nr, int *x, int *y, boolean *b1, boolean *b2) { #if defined(TARGET_SDL) return SDLReadJoystick(nr, x, y, b1, b2); -#elif defined(PLATFORM_UNIX) - return UnixReadJoystick(nr, x, y, b1, b2); #endif } diff --git a/src/libgame/system.h b/src/libgame/system.h index 6580d083..af8772b1 100644 --- a/src/libgame/system.h +++ b/src/libgame/system.h @@ -26,11 +26,7 @@ #include "android.h" #endif -#if defined(TARGET_SDL) #include "sdl.h" -#elif defined(TARGET_X11) -#include "x11.h" -#endif /* the additional 'b' is needed for Win32 to open files in binary mode */ @@ -313,17 +309,10 @@ REDRAW_MICROLEVEL) #define REDRAW_FPS (1 << 11) -#if defined(TARGET_X11) -/* on old-style, classic and potentially slow graphics systems, redraw single - tiles instead of the whole playfield unless a certain threshold is reached; - when using the X11 target, this method should still be fast on all systems */ -#define REDRAWTILES_THRESHOLD (SCR_FIELDX * SCR_FIELDY / 2) -#else -/* on modern graphics systems and when using the SDL target, this tile redraw +/* on modern graphics systems and when using the SDL target, the old tile redraw optimization can slow things down a lot due to many small blits compared to one single playfield-sized blit (especially observed on Mac OS X with SDL) */ #define REDRAWTILES_THRESHOLD 0 -#endif #define IN_GFX_FIELD_PLAY(x, y) (x >= gfx.sx && x < gfx.sx + gfx.sxsize && \ y >= gfx.sy && y < gfx.sy + gfx.sysize) @@ -680,12 +669,9 @@ struct ProgramInfo char *window_title; char *icon_title; - char *x11_icon_filename; - char *x11_iconmask_filename; char *sdl_icon_filename; char *cookie_prefix; - char *filename_prefix; /* prefix to cut off from DOS filenames */ char *error_filename; /* filename where to write error messages to */ FILE *error_file; /* (used instead of 'stderr' on some systems) */ @@ -777,10 +763,6 @@ struct FontBitmapInfo int num_chars; int num_chars_per_line; - -#if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND) - Pixmap *clip_mask; /* single-char-only clip mask array for X11 */ -#endif }; struct GfxInfo @@ -1280,13 +1262,8 @@ extern int FrameCounter; /* function definitions */ -#if 1 -void InitProgramInfo(char *, char *, char *, char *, char *, char *, char *, - char *, char *, char *, int); -#else void InitProgramInfo(char *, char *, char *, char *, char *, char *, char *, - char *, char *, char *, char *, char *, int); -#endif + int); void SetWindowTitle(); diff --git a/src/libgame/text.c b/src/libgame/text.c index b771c1a3..63a1389e 100644 --- a/src/libgame/text.c +++ b/src/libgame/text.c @@ -22,90 +22,6 @@ /* font functions */ /* ========================================================================= */ -#if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND) -static GC font_clip_gc = None; - -static void InitFontClipmasks() -{ - XGCValues clip_gc_values; - unsigned int clip_gc_valuemask; - GC copy_clipmask_gc; - int i, j; - - /* This stuff is needed because X11 (XSetClipOrigin(), to be precise) is - often very slow when preparing a masked XCopyArea() for big Pixmaps. - To prevent this, create small (tile-sized) mask Pixmaps which will then - be set much faster with XSetClipOrigin() and speed things up a lot. */ - - clip_gc_values.graphics_exposures = False; - clip_gc_valuemask = GCGraphicsExposures; - font_clip_gc = XCreateGC(display, window->drawable, - clip_gc_valuemask, &clip_gc_values); - - /* create graphic context structures needed for clipping */ - clip_gc_values.graphics_exposures = False; - clip_gc_valuemask = GCGraphicsExposures; - copy_clipmask_gc = XCreateGC(display, - gfx.font_bitmap_info[0].bitmap->clip_mask, - clip_gc_valuemask, &clip_gc_values); - - /* create only those clipping Pixmaps we really need */ - for (i = 0; i < gfx.num_fonts; i++) - { - if (gfx.font_bitmap_info[i].bitmap == NULL) - continue; - - gfx.font_bitmap_info[i].clip_mask = - checked_calloc(gfx.font_bitmap_info[i].num_chars * sizeof(Pixmap)); - - for (j = 0; j < gfx.font_bitmap_info[i].num_chars; j++) - { - Bitmap *src_bitmap = gfx.font_bitmap_info[i].bitmap; - Pixmap src_pixmap = src_bitmap->clip_mask; - int xpos = j % gfx.font_bitmap_info[i].num_chars_per_line; - int ypos = j / gfx.font_bitmap_info[i].num_chars_per_line; - int width = gfx.font_bitmap_info[i].width; - int height = gfx.font_bitmap_info[i].height; - int src_x = gfx.font_bitmap_info[i].src_x + xpos * width; - int src_y = gfx.font_bitmap_info[i].src_y + ypos * height; - - gfx.font_bitmap_info[i].clip_mask[j] = - XCreatePixmap(display, window->drawable, width, height, 1); - - XCopyArea(display, src_pixmap, gfx.font_bitmap_info[i].clip_mask[j], - copy_clipmask_gc, src_x, src_y, width, height, 0, 0); - } - } - - XFreeGC(display, copy_clipmask_gc); -} - -static void FreeFontClipmasks() -{ - int i, j; - - if (gfx.num_fonts == 0 || gfx.font_bitmap_info[0].bitmap == NULL) - return; - - for (i = 0; i < gfx.num_fonts; i++) - { - if (gfx.font_bitmap_info[i].clip_mask) - { - for (j = 0; j < gfx.font_bitmap_info[i].num_chars; j++) - XFreePixmap(display, gfx.font_bitmap_info[i].clip_mask[j]); - free(gfx.font_bitmap_info[i].clip_mask); - } - - gfx.font_bitmap_info[i].clip_mask = NULL; - gfx.font_bitmap_info[i].num_chars = 0; - } - - if (font_clip_gc) - XFreeGC(display, font_clip_gc); - font_clip_gc = None; -} -#endif /* TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND */ - void InitFontInfo(struct FontBitmapInfo *font_bitmap_info, int num_fonts, int (*select_font_function)(int), int (*get_font_from_token_function)(char *)) @@ -114,10 +30,6 @@ void InitFontInfo(struct FontBitmapInfo *font_bitmap_info, int num_fonts, gfx.font_bitmap_info = font_bitmap_info; gfx.select_font_function = select_font_function; gfx.get_font_from_token_function = get_font_from_token_function; - -#if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND) - InitFontClipmasks(); -#endif } void FreeFontInfo(struct FontBitmapInfo *font_bitmap_info) @@ -125,10 +37,6 @@ void FreeFontInfo(struct FontBitmapInfo *font_bitmap_info) if (font_bitmap_info == NULL) return; -#if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND) - FreeFontClipmasks(); -#endif - free(font_bitmap_info); } @@ -475,18 +383,8 @@ void DrawTextExt(DrawBuffer *dst_bitmap, int dst_x, int dst_y, char *text, font_width, font_height); } -#if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND) - /* use special font tile clipmasks */ - { - int font_pos = getFontCharPosition(font_nr, c); - - SetClipMask(src_bitmap, font_clip_gc, font->clip_mask[font_pos]); - SetClipOrigin(src_bitmap, font_clip_gc, dst_x, dst_y); - } -#else SetClipOrigin(src_bitmap, src_bitmap->stored_clip_gc, dst_x - src_x, dst_y - src_y); -#endif BlitBitmapMasked(src_bitmap, dst_bitmap, src_x, src_y, font_width, font_height, dst_x, dst_y); diff --git a/src/libgame/x11.c b/src/libgame/x11.c deleted file mode 100644 index bdc21aee..00000000 --- a/src/libgame/x11.c +++ /dev/null @@ -1,518 +0,0 @@ -/*********************************************************** -* Artsoft Retro-Game Library * -*----------------------------------------------------------* -* (c) 1994-2006 Artsoft Entertainment * -* Holger Schemel * -* Detmolder Strasse 189 * -* 33604 Bielefeld * -* Germany * -* e-mail: info@artsoft.org * -*----------------------------------------------------------* -* x11.c * -***********************************************************/ - -#include "system.h" -#include "pcx.h" -#include "misc.h" -#include "setup.h" - - -#if defined(TARGET_X11) - -static void X11InitDisplay(); -static DrawWindow *X11InitWindow(); - -static int X11DebugErrorHandler(Display *display, XErrorEvent *event) -{ - int x = 0; - - return 1 / x; /* !!! crash program to give backtrace in gdb !!! */ -} - -void X11InitVideoDisplay(void) -{ - /* initialize X11 video */ - X11InitDisplay(); - - /* set default X11 depth */ - video.default_depth = XDefaultDepth(display, screen); -} - -void X11InitVideoBuffer(DrawBuffer **backbuffer, DrawWindow **window) -{ - if (*window != NULL) - X11CloseWindow(*window); - - *window = X11InitWindow(); - - XMapWindow(display, (*window)->drawable); - - FlushDisplay(); - - /* create additional (off-screen) buffer for double-buffering */ -#if 1 - ReCreateBitmap(backbuffer, video.width, video.height, video.depth); -#else - *backbuffer = CreateBitmap(video.width, video.height, video.depth); -#endif -} - -static void X11InitDisplay() -{ - XVisualInfo vinfo_template, *vinfo; - int num_visuals; - unsigned int depth; - - /* connect to X server */ - if (!(display = XOpenDisplay(options.display_name))) - Error(ERR_EXIT, "cannot connect to X server %s", - XDisplayName(options.display_name)); - - if (options.debug_x11_sync) - { - Error(ERR_WARN, "running in X11 synchronous mode (debug only)"); - - XSynchronize(display, True); - XSetErrorHandler(X11DebugErrorHandler); - } - - screen = DefaultScreen(display); - visual = DefaultVisual(display, screen); - depth = DefaultDepth(display, screen); - cmap = DefaultColormap(display, screen); - - /* look for good enough visual */ - vinfo_template.screen = screen; - vinfo_template.class = (depth == 8 ? PseudoColor : TrueColor); - vinfo_template.depth = depth; - if ((vinfo = XGetVisualInfo(display, VisualScreenMask | VisualClassMask | - VisualDepthMask, &vinfo_template, &num_visuals))) - { - visual = vinfo->visual; - XFree((void *)vinfo); - } - - /* got appropriate visual? */ - if (depth < 8) - Error(ERR_EXIT, "X11 display not supported (less than 8 bits per pixel)"); - else if ((depth ==8 && visual->class != PseudoColor) || - (depth > 8 && visual->class != TrueColor && - visual->class != DirectColor)) - Error(ERR_EXIT, "X11 display not supported (inappropriate visual)"); -} - -static DrawWindow *X11InitWindow() -{ - DrawWindow *new_window = CreateBitmapStruct(); - unsigned int border_width = 4; - XGCValues gc_values; - unsigned int gc_valuemask; - XTextProperty windowName, iconName; - Pixmap icon_pixmap, iconmask_pixmap; - unsigned int icon_width, icon_height; - int icon_hot_x, icon_hot_y; - XSizeHints size_hints; - XWMHints wm_hints; - XClassHint class_hints; - char *window_name = program.window_title; - char *icon_name = program.window_title; - int window_event_mask; - Atom proto_atom = None, delete_atom = None; - int screen_width, screen_height; - int win_xpos, win_ypos; - unsigned int pen_fg = WhitePixel(display, screen); - unsigned int pen_bg = BlackPixel(display, screen); - const int width = video.width, height = video.height; - int i; - - screen_width = XDisplayWidth(display, screen); - screen_height = XDisplayHeight(display, screen); - - win_xpos = (screen_width - width) / 2; - win_ypos = (screen_height - height) / 2; - - new_window->width = width; - new_window->height = height; - - new_window->drawable = XCreateSimpleWindow(display, - RootWindow(display, screen), - win_xpos, win_ypos, - width, height, border_width, - pen_fg, pen_bg); - - proto_atom = XInternAtom(display, "WM_PROTOCOLS", FALSE); - delete_atom = XInternAtom(display, "WM_DELETE_WINDOW", FALSE); - if ((proto_atom != None) && (delete_atom != None)) - XChangeProperty(display, new_window->drawable, proto_atom, XA_ATOM, 32, - PropModePrepend, (unsigned char *) &delete_atom, 1); - - if (XReadBitmapFile(display, new_window->drawable, - getCustomImageFilename(program.x11_icon_filename), - &icon_width, &icon_height, &icon_pixmap, - &icon_hot_x, &icon_hot_y) != BitmapSuccess) - Error(ERR_EXIT, "cannot read icon bitmap file '%s'", - program.x11_icon_filename); - - if (XReadBitmapFile(display, new_window->drawable, - getCustomImageFilename(program.x11_iconmask_filename), - &icon_width, &icon_height, &iconmask_pixmap, - &icon_hot_x, &icon_hot_y) != BitmapSuccess) - Error(ERR_EXIT, "cannot read icon bitmap file '%s'", - program.x11_iconmask_filename); - - size_hints.width = size_hints.min_width = size_hints.max_width = width; - size_hints.height = size_hints.min_height = size_hints.max_height = height; - size_hints.flags = PSize | PMinSize | PMaxSize; - - if (win_xpos || win_ypos) - { - size_hints.x = win_xpos; - size_hints.y = win_ypos; - size_hints.flags |= PPosition; - } - - if (!XStringListToTextProperty(&window_name, 1, &windowName)) - Error(ERR_EXIT, "structure allocation for windowName failed"); - - if (!XStringListToTextProperty(&icon_name, 1, &iconName)) - Error(ERR_EXIT, "structure allocation for iconName failed"); - - wm_hints.initial_state = NormalState; - wm_hints.input = True; - wm_hints.icon_pixmap = icon_pixmap; - wm_hints.icon_mask = iconmask_pixmap; - wm_hints.flags = StateHint | IconPixmapHint | IconMaskHint | InputHint; - - class_hints.res_name = program.command_basename; - class_hints.res_class = program.program_title; - - XSetWMProperties(display, new_window->drawable, &windowName, &iconName, - NULL, 0, &size_hints, &wm_hints, - &class_hints); - - XFree(windowName.value); - XFree(iconName.value); - - /* Select event types wanted */ - window_event_mask = - ExposureMask | StructureNotifyMask | FocusChangeMask | - ButtonPressMask | ButtonReleaseMask | - PointerMotionMask | PointerMotionHintMask | - KeyPressMask | KeyReleaseMask; - - XSelectInput(display, new_window->drawable, window_event_mask); - - /* create GC for drawing with window depth and background color (black) */ - gc_values.graphics_exposures = False; - gc_values.foreground = pen_bg; - gc_values.background = pen_bg; - gc_valuemask = GCGraphicsExposures | GCForeground | GCBackground; - new_window->gc = - XCreateGC(display, new_window->drawable, gc_valuemask, &gc_values); - - /* create GCs for line drawing (black and white) */ - for (i = 0; i < 2; i++) - { - gc_values.graphics_exposures = False; - gc_values.foreground = (i ? pen_fg : pen_bg); - gc_values.background = pen_bg; - gc_values.line_width = 4; - gc_values.line_style = LineSolid; - gc_values.cap_style = CapRound; - gc_values.join_style = JoinRound; - - gc_valuemask = GCGraphicsExposures | GCForeground | GCBackground | - GCLineWidth | GCLineStyle | GCCapStyle | GCJoinStyle; - new_window->line_gc[i] = - XCreateGC(display, new_window->drawable, gc_valuemask, &gc_values); - } - - return new_window; -} - -void X11CloseWindow(DrawWindow *window) -{ - if (window->drawable) - { - XUnmapWindow(display, window->drawable); - XDestroyWindow(display, window->drawable); - } - - if (window->gc) - XFreeGC(display, window->gc); - - free(window); -} - -void X11ZoomBitmap(Bitmap *src_bitmap, Bitmap *dst_bitmap) -{ -#if defined(TARGET_ALLEGRO) - AllegroZoomBitmap(src_bitmap->drawable, dst_bitmap->drawable, - src_bitmap->width, src_bitmap->height, - dst_bitmap->width, dst_bitmap->height); -#else - ZoomPixmap(display, src_bitmap->gc, - src_bitmap->drawable, dst_bitmap->drawable, - src_bitmap->width, src_bitmap->height, - dst_bitmap->width, dst_bitmap->height); -#endif -} - -static void SetImageDimensions(Bitmap *bitmap) -{ -#if defined(TARGET_ALLEGRO) - BITMAP *allegro_bitmap = (BITMAP *)(bitmap->drawable); - - bitmap->width = allegro_bitmap->w; - bitmap->height = allegro_bitmap->h; -#else - Window root; - int x, y; - unsigned int border_width, depth; - - XGetGeometry(display, bitmap->drawable, &root, &x, &y, - &bitmap->width, &bitmap->height, &border_width, &depth); -#endif -} - -Bitmap *X11LoadImage(char *filename) -{ - Bitmap *new_bitmap = CreateBitmapStruct(); - char *error = "Read_PCX_to_Pixmap(): %s '%s'"; - int pcx_err; - XGCValues clip_gc_values; - unsigned int clip_gc_valuemask; - - pcx_err = Read_PCX_to_Pixmap(display, window->drawable, window->gc, filename, - &new_bitmap->drawable, &new_bitmap->clip_mask); - switch(pcx_err) - { - case PCX_Success: - break; - case PCX_OpenFailed: - SetError(error, "cannot open PCX file", filename); - return NULL; - case PCX_ReadFailed: - SetError(error, "cannot read PCX file", filename); - return NULL; - case PCX_FileInvalid: - SetError(error, "invalid PCX file", filename); - return NULL; - case PCX_NoMemory: - SetError(error, "not enough memory for PCX file", filename); - return NULL; - case PCX_ColorFailed: - SetError(error, "cannot get colors for PCX file", filename); - return NULL; - case PCX_OtherError: - /* this should already have called SetError() */ - return NULL; - default: - SetError(error, "unknown error reading PCX file", filename); - return NULL; - } - - if (!new_bitmap->drawable) - { - SetError("X11LoadImage(): cannot get graphics for '%s'", filename); - return NULL; - } - - if (!new_bitmap->clip_mask) - { - SetError("X11LoadImage(): cannot get clipmask for '%s'", filename); - return NULL; - } - - clip_gc_values.graphics_exposures = False; - clip_gc_values.clip_mask = new_bitmap->clip_mask; - clip_gc_valuemask = GCGraphicsExposures | GCClipMask; - new_bitmap->stored_clip_gc = XCreateGC(display, window->drawable, - clip_gc_valuemask, &clip_gc_values); - - /* set GraphicContext inheritated from Window */ - new_bitmap->gc = window->gc; - - /* set image width and height */ - SetImageDimensions(new_bitmap); - - return new_bitmap; -} - -void X11CreateBitmapContent(Bitmap *new_bitmap, - int width, int height, int depth) -{ - Pixmap pixmap; - - if ((pixmap = XCreatePixmap(display, window->drawable, width, height, depth)) - == None) - Error(ERR_EXIT, "cannot create pixmap"); - - new_bitmap->drawable = pixmap; - - if (window == NULL) - Error(ERR_EXIT, "Window GC needed for Bitmap -- create Window first"); - - new_bitmap->gc = window->gc; - - new_bitmap->line_gc[0] = window->line_gc[0]; - new_bitmap->line_gc[1] = window->line_gc[1]; -} - -void X11FreeBitmapPointers(Bitmap *bitmap) -{ - /* The X11 version seems to have a memory leak here -- although - "XFreePixmap()" is called, the corresponding memory seems not - to be freed (according to "ps"). The SDL version apparently - does not have this problem. */ - - if (bitmap->drawable) - XFreePixmap(display, bitmap->drawable); - if (bitmap->clip_mask) - XFreePixmap(display, bitmap->clip_mask); - if (bitmap->stored_clip_gc) - XFreeGC(display, bitmap->stored_clip_gc); - /* the other GCs are only pointers to GCs used elsewhere */ - bitmap->drawable = None; - bitmap->clip_mask = None; - bitmap->stored_clip_gc = None; -} - -void X11CopyArea(Bitmap *src_bitmap, Bitmap *dst_bitmap, - int src_x, int src_y, int width, int height, - int dst_x, int dst_y, int mask_mode) -{ - XCopyArea(display, src_bitmap->drawable, dst_bitmap->drawable, - (mask_mode == BLIT_MASKED ? src_bitmap->clip_gc : dst_bitmap->gc), - src_x, src_y, width, height, dst_x, dst_y); -} - -void X11FillRectangle(Bitmap *bitmap, int x, int y, - int width, int height, Pixel color) -{ - XSetForeground(display, bitmap->gc, color); - XFillRectangle(display, bitmap->drawable, bitmap->gc, x, y, width, height); -} - -void X11FadeRectangle(Bitmap *bitmap_cross, int x, int y, int width, int height, - int fade_mode, int fade_delay, int post_delay, - void (*draw_border_function)(void)) -{ - /* fading currently not supported -- simply copy backbuffer to screen */ - - if (fade_mode == FADE_MODE_FADE_OUT) - X11FillRectangle(backbuffer, x, y, width, height, BLACK_PIXEL); - - if (draw_border_function != NULL) - draw_border_function(); - - X11CopyArea(backbuffer, window, x, y, width, height, x, y, BLIT_OPAQUE); - - /* as we currently cannot use the fade delay, also do not use post delay */ -} - -void X11DrawSimpleLine(Bitmap *bitmap, int from_x, int from_y, - int to_x, int to_y, Pixel color) -{ - XSetForeground(display, bitmap->gc, color); - XDrawLine(display, bitmap->drawable, bitmap->gc, from_x, from_y, to_x, to_y); -} - -Pixel X11GetPixel(Bitmap *bitmap, int x, int y) -{ - XImage *pixel_image; - Pixel pixel_value; - - pixel_image = XGetImage(display, bitmap->drawable, x, y, 1, 1, - AllPlanes, ZPixmap); - pixel_value = XGetPixel(pixel_image, 0, 0); - - X11DestroyImage(pixel_image); - - return pixel_value; -} - -#if defined(TARGET_X11_NATIVE) -Pixel X11GetPixelFromRGB(unsigned int color_r, unsigned int color_g, - unsigned int color_b) -{ - XColor xcolor; - Pixel pixel; - - xcolor.flags = DoRed | DoGreen | DoBlue; - xcolor.red = (color_r << 8); - xcolor.green = (color_g << 8); - xcolor.blue = (color_b << 8); - - XAllocColor(display, cmap, &xcolor); - pixel = xcolor.pixel; - - return pixel; -} -#endif /* TARGET_X11_NATIVE */ - -void X11DestroyImage(XImage *ximage) -{ -#if defined(TARGET_X11_NATIVE) - /* this seems to be needed for OS/2, but does not hurt on other platforms */ - if (ximage->data != NULL) - { - free(ximage->data); - ximage->data = NULL; - } -#endif /* TARGET_X11_NATIVE */ - - XDestroyImage(ximage); -} - - -/* ------------------------------------------------------------------------- */ -/* mouse pointer functions */ -/* ------------------------------------------------------------------------- */ - -#if defined(TARGET_X11_NATIVE) - -static Cursor create_cursor(struct MouseCursorInfo *cursor_info) -{ - Pixmap pixmap_data, pixmap_mask; - XColor color_fg, color_bg; - Cursor cursor; - - /* shape and mask are single plane pixmaps */ - pixmap_data = - XCreatePixmapFromBitmapData(display, window->drawable, cursor_info->data, - cursor_info->width, cursor_info->height, - 1, 0, 1); - pixmap_mask = - XCreatePixmapFromBitmapData(display, window->drawable, cursor_info->mask, - cursor_info->width, cursor_info->height, - 1, 0, 1); - - XParseColor(display, cmap, "black", &color_fg); - XParseColor(display, cmap, "white", &color_bg); - - cursor = XCreatePixmapCursor(display, pixmap_data, pixmap_mask, - &color_fg, &color_bg, - cursor_info->hot_x, cursor_info->hot_y); - - return cursor; -} - -void X11SetMouseCursor(struct MouseCursorInfo *cursor_info) -{ - static struct MouseCursorInfo *last_cursor_info = NULL; - static Cursor cursor_default = None; - static Cursor cursor_current = None; - - if (cursor_info != NULL && cursor_info != last_cursor_info) - { - cursor_current = create_cursor(cursor_info); - last_cursor_info = cursor_info; - } - - XDefineCursor(display, window->drawable, - cursor_info ? cursor_current : cursor_default); -} -#endif /* TARGET_X11_NATIVE */ - -#endif /* TARGET_X11 */ diff --git a/src/libgame/x11.h b/src/libgame/x11.h deleted file mode 100644 index 6e46e78d..00000000 --- a/src/libgame/x11.h +++ /dev/null @@ -1,350 +0,0 @@ -/*********************************************************** -* Artsoft Retro-Game Library * -*----------------------------------------------------------* -* (c) 1994-2006 Artsoft Entertainment * -* Holger Schemel * -* Detmolder Strasse 189 * -* 33604 Bielefeld * -* Germany * -* e-mail: info@artsoft.org * -*----------------------------------------------------------* -* x11.h * -***********************************************************/ - -#ifndef X11_H -#define X11_H - -#define XK_MISCELLANY -#define XK_LATIN1 - -#include -#include -#include -#include -#include -#include - - -/* system dependent definitions */ - -#define TARGET_STRING "X11" - -/* This triggers some stuff that is needed because X11 (XSetClipOrigin(), - to be precise) is often very slow when preparing a masked XCopyArea() - for big Pixmaps. - To prevent this, small (tile-sized) mask Pixmaps are created which will - then be set much faster with XSetClipOrigin() and speed things up a lot. */ -#define TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND - -#define WINDOW_SCALING_STATUS WINDOW_SCALING_NOT_AVAILABLE -#define FULLSCREEN_STATUS FULLSCREEN_NOT_AVAILABLE - -#define CURSOR_MAX_WIDTH 32 -#define CURSOR_MAX_HEIGHT 32 - - -/* X11 type definitions */ - -typedef struct X11DrawableInfo Bitmap; -typedef struct X11DrawableInfo DrawWindow; -typedef struct X11DrawableInfo DrawBuffer; -/* "Pixel" is already defined */ -/* "Cursor" is already defined */ - -typedef KeySym Key; -typedef unsigned int KeyMod; - -typedef XEvent Event; -typedef XButtonEvent ButtonEvent; -typedef XMotionEvent MotionEvent; -typedef XKeyEvent KeyEvent; -typedef XExposeEvent ExposeEvent; -typedef XFocusChangeEvent FocusChangeEvent; -typedef XClientMessageEvent ClientMessageEvent; - - -/* structure definitions */ - -struct X11DrawableInfo -{ - char *source_filename; - - unsigned int width, height; - Drawable drawable; - Drawable clip_mask; - GC gc; /* GC for normal drawing (inheritated from 'window') */ - GC line_gc[2]; /* GC for foreground and background line drawing */ - GC stored_clip_gc; /* GC for masked drawing (used for whole Pixmap) */ - GC clip_gc; /* can be 'stored_clip_gc' or one-tile-only clip GC */ -}; - -struct MouseCursorInfo -{ - int width, height; - int hot_x, hot_y; - - char data[CURSOR_MAX_WIDTH * CURSOR_MAX_HEIGHT / 8]; - char mask[CURSOR_MAX_WIDTH * CURSOR_MAX_HEIGHT / 8]; -}; - - -/* X11 symbol definitions */ - -#define BLACK_PIXEL BlackPixel(display, screen) -#define WHITE_PIXEL WhitePixel(display, screen) - -#define EVENT_BUTTONPRESS ButtonPress -#define EVENT_BUTTONRELEASE ButtonRelease -#define EVENT_MOTIONNOTIFY MotionNotify -#define EVENT_KEYPRESS KeyPress -#define EVENT_KEYRELEASE KeyRelease -#define EVENT_EXPOSE Expose -#define EVENT_FOCUSIN FocusIn -#define EVENT_FOCUSOUT FocusOut -#define EVENT_CLIENTMESSAGE ClientMessage -#define EVENT_MAPNOTIFY MapNotify -#define EVENT_UNMAPNOTIFY UnmapNotify - -#define KSYM_UNDEFINED XK_VoidSymbol - -#define KSYM_Return XK_Return -#define KSYM_Escape XK_Escape - -#define KSYM_Left XK_Left -#define KSYM_Right XK_Right -#define KSYM_Up XK_Up -#define KSYM_Down XK_Down - -#ifdef XK_KP_Left -#define KSYM_KP_Left XK_KP_Left -#define KSYM_KP_Right XK_KP_Right -#define KSYM_KP_Up XK_KP_Up -#define KSYM_KP_Down XK_KP_Down -#endif - -#ifdef XK_KP_Enter -#define KSYM_KP_Enter XK_KP_Enter -#define KSYM_KP_Add XK_KP_Add -#define KSYM_KP_Subtract XK_KP_Subtract -#define KSYM_KP_Multiply XK_KP_Multiply -#define KSYM_KP_Divide XK_KP_Divide -#define KSYM_KP_Separator XK_KP_Separator -#endif - -#define KSYM_Shift_L XK_Shift_L -#define KSYM_Shift_R XK_Shift_R -#define KSYM_Control_L XK_Control_L -#define KSYM_Control_R XK_Control_R -#define KSYM_Meta_L XK_Meta_L -#define KSYM_Meta_R XK_Meta_R -#define KSYM_Alt_L XK_Alt_L -#define KSYM_Alt_R XK_Alt_R -#define KSYM_Super_L XK_Super_L -#define KSYM_Super_R XK_Super_R -#define KSYM_Mode_switch XK_Mode_switch -#define KSYM_Multi_key XK_Multi_key - -#define KSYM_BackSpace XK_BackSpace -#define KSYM_Delete XK_Delete -#define KSYM_Insert XK_Insert -#define KSYM_Tab XK_Tab -#define KSYM_Home XK_Home -#define KSYM_End XK_End -#define KSYM_Page_Up XK_Page_Up -#define KSYM_Page_Down XK_Page_Down -#define KSYM_Menu XK_Menu - -#define KSYM_space XK_space -#define KSYM_exclam XK_exclam -#define KSYM_quotedbl XK_quotedbl -#define KSYM_numbersign XK_numbersign -#define KSYM_dollar XK_dollar -#define KSYM_percent XK_percent -#define KSYM_ampersand XK_ampersand -#define KSYM_apostrophe XK_apostrophe -#define KSYM_parenleft XK_parenleft -#define KSYM_parenright XK_parenright -#define KSYM_asterisk XK_asterisk -#define KSYM_plus XK_plus -#define KSYM_comma XK_comma -#define KSYM_minus XK_minus -#define KSYM_period XK_period -#define KSYM_slash XK_slash - -#define KSYM_colon XK_colon -#define KSYM_semicolon XK_semicolon -#define KSYM_less XK_less -#define KSYM_equal XK_equal -#define KSYM_greater XK_greater -#define KSYM_question XK_question -#define KSYM_at XK_at - -#define KSYM_bracketleft XK_bracketleft -#define KSYM_backslash XK_backslash -#define KSYM_bracketright XK_bracketright -#define KSYM_asciicircum XK_asciicircum -#define KSYM_underscore XK_underscore -#define KSYM_grave XK_grave - -#define KSYM_quoteleft XK_quoteleft -#define KSYM_braceleft XK_braceleft -#define KSYM_bar XK_bar -#define KSYM_braceright XK_braceright -#define KSYM_asciitilde XK_asciitilde - -#define KSYM_degree XK_degree -#define KSYM_Adiaeresis XK_Adiaeresis -#define KSYM_Odiaeresis XK_Odiaeresis -#define KSYM_Udiaeresis XK_Udiaeresis -#define KSYM_adiaeresis XK_adiaeresis -#define KSYM_odiaeresis XK_odiaeresis -#define KSYM_udiaeresis XK_udiaeresis -#define KSYM_ssharp XK_ssharp - -#define KSYM_A XK_A -#define KSYM_B XK_B -#define KSYM_C XK_C -#define KSYM_D XK_D -#define KSYM_E XK_E -#define KSYM_F XK_F -#define KSYM_G XK_G -#define KSYM_H XK_H -#define KSYM_I XK_I -#define KSYM_J XK_J -#define KSYM_K XK_K -#define KSYM_L XK_L -#define KSYM_M XK_M -#define KSYM_N XK_N -#define KSYM_O XK_O -#define KSYM_P XK_P -#define KSYM_Q XK_Q -#define KSYM_R XK_R -#define KSYM_S XK_S -#define KSYM_T XK_T -#define KSYM_U XK_U -#define KSYM_V XK_V -#define KSYM_W XK_W -#define KSYM_X XK_X -#define KSYM_Y XK_Y -#define KSYM_Z XK_Z - -#define KSYM_a XK_a -#define KSYM_b XK_b -#define KSYM_c XK_c -#define KSYM_d XK_d -#define KSYM_e XK_e -#define KSYM_f XK_f -#define KSYM_g XK_g -#define KSYM_h XK_h -#define KSYM_i XK_i -#define KSYM_j XK_j -#define KSYM_k XK_k -#define KSYM_l XK_l -#define KSYM_m XK_m -#define KSYM_n XK_n -#define KSYM_o XK_o -#define KSYM_p XK_p -#define KSYM_q XK_q -#define KSYM_r XK_r -#define KSYM_s XK_s -#define KSYM_t XK_t -#define KSYM_u XK_u -#define KSYM_v XK_v -#define KSYM_w XK_w -#define KSYM_x XK_x -#define KSYM_y XK_y -#define KSYM_z XK_z - -#define KSYM_0 XK_0 -#define KSYM_1 XK_1 -#define KSYM_2 XK_2 -#define KSYM_3 XK_3 -#define KSYM_4 XK_4 -#define KSYM_5 XK_5 -#define KSYM_6 XK_6 -#define KSYM_7 XK_7 -#define KSYM_8 XK_8 -#define KSYM_9 XK_9 - -#define KSYM_KP_0 XK_KP_0 -#define KSYM_KP_1 XK_KP_1 -#define KSYM_KP_2 XK_KP_2 -#define KSYM_KP_3 XK_KP_3 -#define KSYM_KP_4 XK_KP_4 -#define KSYM_KP_5 XK_KP_5 -#define KSYM_KP_6 XK_KP_6 -#define KSYM_KP_7 XK_KP_7 -#define KSYM_KP_8 XK_KP_8 -#define KSYM_KP_9 XK_KP_9 - -#define KSYM_F1 XK_F1 -#define KSYM_F2 XK_F2 -#define KSYM_F3 XK_F3 -#define KSYM_F4 XK_F4 -#define KSYM_F5 XK_F5 -#define KSYM_F6 XK_F6 -#define KSYM_F7 XK_F7 -#define KSYM_F8 XK_F8 -#define KSYM_F9 XK_F9 -#define KSYM_F10 XK_F10 -#define KSYM_F11 XK_F11 -#define KSYM_F12 XK_F12 -#define KSYM_F13 XK_F13 -#define KSYM_F14 XK_F14 -#define KSYM_F15 XK_F15 -#define KSYM_F16 XK_F16 -#define KSYM_F17 XK_F17 -#define KSYM_F18 XK_F18 -#define KSYM_F19 XK_F19 -#define KSYM_F20 XK_F20 -#define KSYM_F21 XK_F21 -#define KSYM_F22 XK_F22 -#define KSYM_F23 XK_F23 -#define KSYM_F24 XK_F24 - -#define KSYM_FKEY_FIRST KSYM_F1 -#define KSYM_FKEY_LAST KSYM_F24 -#define KSYM_NUM_FKEYS (KSYM_FKEY_LAST - KSYM_FKEY_FIRST + 1) - -#define KMOD_None None -#define KMOD_Shift_L 0x0001 -#define KMOD_Shift_R 0x0002 -#define KMOD_Control_L 0x0040 -#define KMOD_Control_R 0x0080 -#define KMOD_Meta_L 0x0400 -#define KMOD_Meta_R 0x0800 -#define KMOD_Alt_L 0x0100 -#define KMOD_Alt_R 0x0200 - -#define KMOD_Shift (KMOD_Shift_L | KMOD_Shift_R) -#define KMOD_Control (KMOD_Control_L | KMOD_Control_R) -#define KMOD_Meta (KMOD_Meta_L | KMOD_Meta_R) -#define KMOD_Alt (KMOD_Alt_L | KMOD_Alt_R) - - -/* X11 function definitions */ - -void X11InitVideoDisplay(void); -void X11InitVideoBuffer(DrawBuffer **, DrawWindow **); - -void X11CloseWindow(DrawWindow *); - -void X11ZoomBitmap(Bitmap *, Bitmap *); -Bitmap *X11LoadImage(char *); - -void X11CreateBitmapContent(Bitmap *, int, int, int); -void X11FreeBitmapPointers(Bitmap *); -void X11CopyArea(Bitmap *, Bitmap *, int, int, int, int, int, int, int); -void X11FillRectangle(Bitmap *, int, int, int, int, Pixel); -void X11FadeRectangle(Bitmap *, int, int, int, int, int, int, int, - void (*draw_border_function)(void)); -void X11DrawSimpleLine(Bitmap *, int, int, int, int, Pixel); -Pixel X11GetPixel(Bitmap *, int, int); -Pixel X11GetPixelFromRGB(unsigned int, unsigned int, unsigned int); -void X11DestroyImage(XImage *); - -#if defined(TARGET_X11_NATIVE) -void X11SetMouseCursor(struct MouseCursorInfo *); -#endif - -#endif /* X11_H */ diff --git a/src/main.c b/src/main.c index f2bcf143..ae56447b 100644 --- a/src/main.c +++ b/src/main.c @@ -5602,19 +5602,9 @@ static void print_usage() int main(int argc, char *argv[]) { -#if 1 InitProgramInfo(argv[0], USERDATA_DIRECTORY, USERDATA_DIRECTORY_UNIX, - PROGRAM_TITLE_STRING, ICON_TITLE_STRING, - X11_ICON_FILENAME, X11_ICONMASK_FILENAME, SDL_ICON_FILENAME, - COOKIE_PREFIX, FILENAME_PREFIX, GAME_VERSION_ACTUAL); -#else - char *window_title_string = getWindowTitleString(); - - InitProgramInfo(argv[0], USERDATA_DIRECTORY, USERDATA_DIRECTORY_UNIX, - PROGRAM_TITLE_STRING, window_title_string, ICON_TITLE_STRING, - X11_ICON_FILENAME, X11_ICONMASK_FILENAME, SDL_ICON_FILENAME, - COOKIE_PREFIX, FILENAME_PREFIX, GAME_VERSION_ACTUAL); -#endif + PROGRAM_TITLE_STRING, ICON_TITLE_STRING, SDL_ICON_FILENAME, + COOKIE_PREFIX, GAME_VERSION_ACTUAL); InitWindowTitleFunction(getWindowTitleString); InitExitMessageFunction(DisplayExitMessage); diff --git a/src/main.h b/src/main.h index c9a7164b..0bd31a50 100644 --- a/src/main.h +++ b/src/main.h @@ -2094,7 +2094,6 @@ #define ICON_TITLE_STRING PROGRAM_TITLE_STRING #define COOKIE_PREFIX "ROCKSNDIAMONDS" -#define FILENAME_PREFIX "Rocks" #define USERDATA_DIRECTORY_WIN32 PROGRAM_TITLE_STRING #define USERDATA_DIRECTORY_MACOSX PROGRAM_TITLE_STRING @@ -2111,8 +2110,6 @@ #define USERDATA_DIRECTORY USERDATA_DIRECTORY_OTHER #endif -#define X11_ICON_FILENAME "rocks_icon.xbm" -#define X11_ICONMASK_FILENAME "rocks_iconmask.xbm" #define SDL_ICON_FILENAME "RocksIcon32x32.png" /* file version numbers for resource files (levels, tapes, score, setup, etc.) @@ -2827,11 +2824,6 @@ struct GraphicInfo int pressed_yoffset; boolean use_image_size; /* use image size as default width and height */ - -#if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND) - Pixmap clip_mask; /* single-graphic-only clip mask for X11 */ - GC clip_gc; /* single-graphic-only clip gc for X11 */ -#endif }; struct SoundInfo diff --git a/src/screens.c b/src/screens.c index 95b6706f..2d8b85b6 100644 --- a/src/screens.c +++ b/src/screens.c @@ -428,11 +428,6 @@ static struct menu.list_size[game_status] : \ MAX_MENU_ENTRIES_ON_SCREEN) -#if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND) -#define NUM_SCROLLBAR_BITMAPS 2 -static Bitmap *scrollbar_bitmap[NUM_SCROLLBAR_BITMAPS]; -#endif - /* title display and control definitions */ @@ -7345,11 +7340,7 @@ static struct static struct { -#if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND) - Bitmap **gfx_unpressed, **gfx_pressed; -#else int gfx_unpressed, gfx_pressed; -#endif int x, y; int width, height; int type; @@ -7358,11 +7349,7 @@ static struct } scrollbar_info[NUM_SCREEN_SCROLLBARS] = { { -#if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND) - &scrollbar_bitmap[0], &scrollbar_bitmap[1], -#else IMG_MENU_SCROLLBAR, IMG_MENU_SCROLLBAR_ACTIVE, -#endif #if 1 -1, -1, /* these values are not constant, but can change at runtime */ -1, -1, /* these values are not constant, but can change at runtime */ @@ -7505,9 +7492,7 @@ static void CreateScreenScrollbars() for (i = 0; i < NUM_SCREEN_SCROLLBARS; i++) { Bitmap *gd_bitmap_unpressed, *gd_bitmap_pressed; -#if !defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND) int gfx_unpressed, gfx_pressed; -#endif int x, y, width, height; int gd_x1, gd_x2, gd_y1, gd_y2; struct GadgetInfo *gi; @@ -7530,14 +7515,6 @@ static void CreateScreenScrollbars() items_visible = num_page_entries; item_position = 0; -#if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND) - gd_bitmap_unpressed = *scrollbar_info[i].gfx_unpressed; - gd_bitmap_pressed = *scrollbar_info[i].gfx_pressed; - gd_x1 = 0; - gd_y1 = 0; - gd_x2 = 0; - gd_y2 = 0; -#else gfx_unpressed = scrollbar_info[i].gfx_unpressed; gfx_pressed = scrollbar_info[i].gfx_pressed; gd_bitmap_unpressed = graphic_info[gfx_unpressed].bitmap; @@ -7546,7 +7523,6 @@ static void CreateScreenScrollbars() gd_y1 = graphic_info[gfx_unpressed].src_y; gd_x2 = graphic_info[gfx_pressed].src_x; gd_y2 = graphic_info[gfx_pressed].src_y; -#endif gi = CreateGadget(GDI_CUSTOM_ID, id, GDI_CUSTOM_TYPE_ID, i, @@ -7590,27 +7566,6 @@ void CreateScreenGadgets() { int last_game_status = game_status; /* save current game status */ -#if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND) - int i; - - for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++) - { - scrollbar_bitmap[i] = CreateBitmap(TILEX, TILEY, DEFAULT_DEPTH); - - /* copy pointers to clip mask and GC */ - scrollbar_bitmap[i]->clip_mask = - graphic_info[IMG_MENU_SCROLLBAR + i].clip_mask; - scrollbar_bitmap[i]->stored_clip_gc = - graphic_info[IMG_MENU_SCROLLBAR + i].clip_gc; - - BlitBitmap(graphic_info[IMG_MENU_SCROLLBAR + i].bitmap, - scrollbar_bitmap[i], - graphic_info[IMG_MENU_SCROLLBAR + i].src_x, - graphic_info[IMG_MENU_SCROLLBAR + i].src_y, - TILEX, TILEY, 0, 0); - } -#endif - CreateScreenMenubuttons(); #if 0 @@ -7628,17 +7583,6 @@ void FreeScreenGadgets() { int i; -#if defined(TARGET_X11_NATIVE_PERFORMANCE_WORKAROUND) - for (i = 0; i < NUM_SCROLLBAR_BITMAPS; i++) - { - /* prevent freeing clip mask and GC twice */ - scrollbar_bitmap[i]->clip_mask = None; - scrollbar_bitmap[i]->stored_clip_gc = None; - - FreeBitmap(scrollbar_bitmap[i]); - } -#endif - for (i = 0; i < NUM_SCREEN_GADGETS; i++) FreeGadget(screen_gadget[i]); } -- 2.34.1