rnd-20000718-1-src
authorHolger Schemel <info@artsoft.org>
Tue, 18 Jul 2000 21:52:22 +0000 (23:52 +0200)
committerHolger Schemel <info@artsoft.org>
Sat, 30 Aug 2014 08:34:39 +0000 (10:34 +0200)
INSTALL [deleted file]
Makefile [deleted file]
src/Makefile
src/init.c
src/main.c
src/main.h
src/sdl.c [new file with mode: 0644]
src/sdl.h [new file with mode: 0644]
src/tools.c

diff --git a/INSTALL b/INSTALL
deleted file mode 100644 (file)
index 697475a..0000000
--- a/INSTALL
+++ /dev/null
@@ -1,85 +0,0 @@
-
-Installation instructions for Rocks'n'Diamonds 1.2.0
-====================================================
-
-Compilation
------------
-
-If your system supports Linux/i386/ELF/libc5 executables (Linux package)
-or if you run DOS/Windows (DOS package), you can directly use the included
-precompiled binary.
-
-If you use a different system, just recompile the game:
-
-If you use Linux with gcc or DOS/Windows with djgpp, just try 'make'
-which should work without problems.
-
-If you use SUN/Solaris with gcc and GNU make, try 'make solaris'.
-
-If the above doesn't work, edit the Makefile in the top level directory.
-If it doesn't work either, edit the Makefile in the 'src' subdirectory.
-
-If you had to modify any Makefile to compile it, please drop me a note
-about it to 'aeglos@valinor.owl.de'. Thanks!
-
-
-Customization
--------------
-
-The following configuration options in the top level Makefile help
-you to customize the game to your system and your environment:
-
-CC             Choose your favorite ANSI C compiler.
-               Default is 'gcc'.
-
-PLATFORM       Choose your platform, if auto detection fails.
-               Auto detection should work for Linux and DOS
-               (just type 'make'), on SUN/Solaris systems 'make solaris'
-               should work. Other systems may need additional editing
-               of 'src/Makefile' to set some additional compiler options.
-
-X11_PATH       Specify the path to your X11 installation. Include files
-               and libraries are searched for at $(X11_PATH)/include and
-               $(X11_PATH)/lib, if you set this variables. If you don't
-               set this variable, your compiler must be able to find X11
-               by itself, which works fine for Linux, for example.
-
-GAME_DIR       Specify the directory where the program looks for all the
-               graphics, sounds, levels and high scores. If you leave this
-               commented out, the current directory ('.') is used, which
-               lets you use the game without installing it somewhere in
-               your system (although you have to 'cd' to the game directory
-               each time you want to play it).
-
-JOYSTICK       Uncomment this line if your system does not support game
-               port hardware like joysticks (and has therefore no joystick
-               include file). Currently the game should work with joysticks
-               on Linux and FreeBSD.
-
-SOUNDS         Uncomment this line if your system does not support audio
-               hardware. Currently the game should work with sound support
-               on Linux, FreeBSD, SUN/Solaris, HP-UX and most Unix system
-               that support '/dev/dsp' or '/dev/audio' devices.
-
-SCORE_ENTRIES  Choose if you want to allow many entries in the high score
-               table for one player or exactly one entry. Systems with a
-               lot of users maybe want to limit high score entries to only
-               one entry for each player (and therefore set 'SCORE_ENTRIES'
-               to 'ONE_PER_NAME') where systems used by only one person
-               maybe want to use the default of 'MANY_PER_NAME' which is
-               automatically choosen if you leave everything commented out.
-
-Modifications of the Makefile in the directory 'src' are normally not needed.
-If the game fails to compile out of the box, you may have to modify some
-of the system variables there to get it to compile.
-
-SYSTEM         May need to be set to some system dependend values.
-
-INCL, LIBS     Maybe some more directories for include files and libraries
-               have to be added to this variables depending on your system.
-
-
-If you have any comments, additions or modifications to the Makefile(s),
-please send me mail: 'aeglos@valinor.owl.de'. Thanks!
-
-05-DEC-1998, Holger Schemel
diff --git a/Makefile b/Makefile
deleted file mode 100644 (file)
index d8c400d..0000000
--- a/Makefile
+++ /dev/null
@@ -1,62 +0,0 @@
-#=============================================================================#
-# Makefile for Rocks'n'Diamonds 1.4.0                                         #
-# (c) 1995-1999 Holger Schemel, aeglos@valinor.owl.de                         #
-#=============================================================================#
-
-#-----------------------------------------------------------------------------#
-# configuration section                                                       #
-#-----------------------------------------------------------------------------#
-
-# specify your favorite ANSI C compiler
-CC = gcc
-
-# explicitely choose your platform, if defaults doesn't work right
-# needed for SUN/Solaris; Linux and DOS work fine with auto detection
-# PLATFORM = solaris
-# PLATFORM = unix
-# PLATFORM = dos
-
-# specify path to X11 on your system
-# if undefined, use system defaults (works with Linux/gcc/libc5)
-X11_PATH = /usr/X11
-
-# specify directory for read-only game data (like graphics, sounds, levels)
-# default is '.', so you can play without installing game data somewhere
-# RO_GAME_DIR = /usr/games
-
-# specify directory for writable game data (like highscore files)
-# default is '.', so you can play without installing game data somewhere
-# RW_GAME_DIR = /var/games
-
-# uncomment this if your system has no joystick include file
-# JOYSTICK = -DNO_JOYSTICK
-
-# uncomment this if your system has no sound
-# SOUNDS = -DNO_SOUNDS
-
-# choose if you want to allow many global score file entries for one player
-# default is 'MANY_PER_NAME'
-# when installing the game in a multi user environment, choose this
-# SCORE_ENTRIES = ONE_PER_NAME
-# when installing the game in a single user environment, choose this
-# SCORE_ENTRIES = MANY_PER_NAME
-
-#-----------------------------------------------------------------------------#
-# you should not need to change anything below                                #
-#-----------------------------------------------------------------------------#
-
-.EXPORT_ALL_VARIABLES:
-
-MAKE = make
-
-SRC_DIR = src
-MAKE_CMD = @$(MAKE) -C $(SRC_DIR)
-
-all:
-       $(MAKE_CMD)
-
-solaris:
-       $(MAKE_CMD) PLATFORM=solaris
-
-clean:
-       $(MAKE_CMD) clean
index 2be4220..044e136 100644 (file)
@@ -34,8 +34,11 @@ ifeq ($(PLATFORM),solaris)
 EXTRA_LIBS = -lnsl -lsocket -R$(XLIB_PATH)
 endif
 
+SDL_CFLAGS := -DUSE_SDL_LIBRARY $(shell sdl-config --cflags)
+SDL_LDFLAGS := -lIMG $(shell sdl-config --libs)
+
 INCL = $(X11_INCL)
-LIBS = $(X11_LIBS) -lX11 -lm $(EXTRA_LIBS)
+LIBS = $(X11_LIBS) -lX11 -lm $(EXTRA_LIBS) $(SDL_LDFLAGS)
 
 endif
 
@@ -58,14 +61,14 @@ CONFIG_GAME_DIR = $(CONFIG_RO_GAME_DIR) $(CONFIG_RW_GAME_DIR)
 CONFIG = $(CONFIG_GAME_DIR) $(CONFIG_SCORE_ENTRIES) $(SOUNDS) $(JOYSTICK)
 
 # OPTIONS = -DDEBUG -g -Wall -ansi -pedantic   # only for debugging purposes
-# OPTIONS = -DDEBUG -g -Wall                   # only for debugging purposes
+OPTIONS = -DDEBUG -g -Wall                     # only for debugging purposes
 # OPTIONS = -O3 -Wall -ansi -pedantic
 # OPTIONS = -O3 -Wall
-OPTIONS = -O3
+OPTIONS = -O3
 
 # SYSTEM = -DSYSV -Ae          # may be needed for HP-UX
 
-CFLAGS = $(OPTIONS) $(SYSTEM) $(INCL) $(CONFIG)
+CFLAGS = $(OPTIONS) $(SDL_CFLAGS) $(SYSTEM) $(INCL) $(CONFIG)
 
 SRCS = main.c          \
        init.c          \
@@ -86,7 +89,8 @@ SRCS =        main.c          \
        image.c         \
        network.c       \
        netserv.c       \
-       msdos.c
+       msdos.c         \
+       sdl.c
 
 OBJS = main.o          \
        init.o          \
@@ -107,7 +111,8 @@ OBJS =      main.o          \
        image.o         \
        network.o       \
        netserv.o       \
-       msdos.o
+       msdos.o         \
+       sdl.o
 
 all:   $(PROGNAME)
 
index 78a587f..f77bd79 100644 (file)
@@ -79,13 +79,16 @@ void OpenAll(int argc, char *argv[])
   InitDisplay();
   InitWindow(argc, argv);
 
+#ifndef USE_SDL_LIBRARY
   XMapWindow(display, window);
   XFlush(display);
+#endif
 
   InitGfx();
   InitElementProperties();     /* initializes IS_CHAR() for el2gfx() */
 
   InitLevelAndPlayerInfo();
+  return;
   InitGadgets();               /* needs to know number of level series */
 
   DrawMainMenu();
@@ -298,6 +301,16 @@ void InitJoysticks()
 
 void InitDisplay()
 {
+#ifdef USE_SDL_LIBRARY
+  /* initialize SDL */
+  if (SDL_Init(SDL_INIT_VIDEO) < 0)
+    Error(ERR_EXIT, "SDL_Init() failed: %s\n", SDL_GetError());
+
+  /* automatically cleanup SDL stuff after exit() */
+  atexit(SDL_Quit);
+
+#else /* !USE_SDL_LIBRARY */
+
 #ifndef MSDOS
   XVisualInfo vinfo_template, *vinfo;
   int num_visuals;
@@ -339,11 +352,27 @@ void InitDisplay()
     printf("Sorry, cannot get appropriate visual.\n");
     exit(-1);
   }
-#endif
+#endif /* !MSDOS */
+#endif /* !USE_SDL_LIBRARY */
 }
 
 void InitWindow(int argc, char *argv[])
 {
+#ifdef USE_SDL_LIBRARY
+  /* open SDL video output device (window or fullscreen mode) */
+  if ((sdl_window = SDL_SetVideoMode(WIN_XSIZE, WIN_YSIZE, WIN_SDL_DEPTH,
+                                    SDL_HWSURFACE))
+      == NULL)
+    Error(ERR_EXIT, "SDL_SetVideoMode() failed: %s\n", SDL_GetError());
+
+  /* set window and icon title */
+  SDL_WM_SetCaption(WINDOW_TITLE_STRING, WINDOW_TITLE_STRING);
+
+  /* select event types: initially no mouse motion events */
+  SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
+
+#else /* !USE_SDL_LIBRARY */
+
   unsigned int border_width = 4;
   XGCValues gc_values;
   unsigned long gc_valuemask;
@@ -458,14 +487,20 @@ void InitWindow(int argc, char *argv[])
   gc_values.background = pen_bg;
   gc_valuemask = GCGraphicsExposures | GCForeground | GCBackground;
   gc = XCreateGC(display, window, gc_valuemask, &gc_values);
+#endif /* !USE_SDL_LIBRARY */
 }
 
 void InitGfx()
 {
   int i,j;
+
+#ifdef USE_SDL_LIBRARY
+  SDL_Surface *sdl_image_tmp;
+#else
   GC copy_clipmask_gc;
   XGCValues clip_gc_values;
   unsigned long clip_gc_valuemask;
+#endif
 
 #ifdef MSDOS
   static struct PictureFileInfo pic[NUM_PICTURES] =
@@ -579,8 +614,6 @@ void InitGfx()
 #endif
 #endif
 
-
-
   LoadGfx(PIX_SMALLFONT,&pic[PIX_SMALLFONT]);
   DrawInitText(WINDOW_TITLE_STRING,20,FC_YELLOW);
   DrawInitText(COPYRIGHT_STRING,50,FC_RED);
@@ -598,6 +631,85 @@ void InitGfx()
   debug_print_timestamp(0, "SUMMARY LOADING ALL GRAPHICS:");
 #endif
 
+#ifdef USE_SDL_LIBRARY
+  /* create some native image surfaces for double-buffer purposes */
+
+  /* create double-buffer surface for background image */
+  if ((sdl_image_tmp = SDL_CreateRGBSurface(SDL_SWSURFACE,
+                                           WIN_XSIZE, WIN_YSIZE,
+                                           WIN_SDL_DEPTH, 0, 0, 0, 0))
+      == NULL)
+    Error(ERR_EXIT, "SDL_CreateRGBSurface() failed: %s\n", SDL_GetError());
+
+  if ((sdl_pix[PIX_DB_BACK] = SDL_DisplayFormat(sdl_image_tmp)) == NULL)
+    Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s\n", SDL_GetError());
+
+  SDL_FreeSurface(sdl_image_tmp);
+
+  /* create double-buffer surface for door image */
+  if ((sdl_image_tmp = SDL_CreateRGBSurface(SDL_SWSURFACE,
+                                           3 * DXSIZE, DYSIZE + VYSIZE,
+                                           WIN_SDL_DEPTH, 0, 0, 0, 0))
+      == NULL)
+    Error(ERR_EXIT, "SDL_CreateRGBSurface() failed: %s\n", SDL_GetError());
+
+  if ((sdl_pix[PIX_DB_DOOR] = SDL_DisplayFormat(sdl_image_tmp)) == NULL)
+    Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s\n", SDL_GetError());
+
+  SDL_FreeSurface(sdl_image_tmp);
+
+  /* create double-buffer surface for field image */
+  if ((sdl_image_tmp = SDL_CreateRGBSurface(SDL_SWSURFACE,
+                                           FXSIZE, FYSIZE,
+                                           WIN_SDL_DEPTH, 0, 0, 0, 0))
+      == NULL)
+    Error(ERR_EXIT, "SDL_CreateRGBSurface() failed: %s\n", SDL_GetError());
+
+  if ((sdl_pix[PIX_DB_FIELD] = SDL_DisplayFormat(sdl_image_tmp)) == NULL)
+    Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s\n", SDL_GetError());
+
+  SDL_FreeSurface(sdl_image_tmp);
+
+  /* initialize surface array to 'NULL' */
+  for(i=0; i<NUM_TILES; i++)
+    sdl_tile_masked[i] = NULL;
+
+  /* create only those masked surfaces we really need */
+  for(i=0; tile_needs_clipping[i].start>=0; i++)
+  {
+    for(j=0; j<tile_needs_clipping[i].count; j++)
+    {
+      int tile = tile_needs_clipping[i].start + j;
+#if 0
+      int graphic = tile;
+      int src_x, src_y;
+      int pixmap_nr;
+      Pixmap src_pixmap;
+
+      getGraphicSource(graphic, &pixmap_nr, &src_x, &src_y);
+      src_pixmap = clipmask[pixmap_nr];
+
+      tile_clipmask[tile] = XCreatePixmap(display, window, TILEX,TILEY, 1);
+
+      XCopyArea(display,src_pixmap,tile_clipmask[tile],copy_clipmask_gc,
+               src_x,src_y, TILEX,TILEY, 0,0);
+#endif
+    }
+  }
+
+  sdl_drawto = sdl_backbuffer = sdl_pix[PIX_DB_BACK];
+  sdl_fieldbuffer = sdl_pix[PIX_DB_FIELD];
+  SetDrawtoField(DRAW_BACKBUFFER);
+
+  SDLCopyArea(sdl_pix[PIX_BACK], sdl_backbuffer,
+             0,0, WIN_XSIZE,WIN_YSIZE, 0,0);
+  SDLFillRectangle(sdl_pix[PIX_DB_BACK],
+                  REAL_SX,REAL_SY, FULL_SXSIZE,FULL_SYSIZE, 0x000000);
+  SDLFillRectangle(sdl_pix[PIX_DB_DOOR],
+                  0,0, 3*DXSIZE,DYSIZE+VYSIZE, 0x000000);
+
+#else /* !USE_SDL_LIBRARY */
+
   pix[PIX_DB_BACK] = XCreatePixmap(display, window,
                                   WIN_XSIZE,WIN_YSIZE,
                                   XDefaultDepth(display,screen));
@@ -661,12 +773,13 @@ void InitGfx()
   fieldbuffer = pix[PIX_DB_FIELD];
   SetDrawtoField(DRAW_BACKBUFFER);
 
-  XCopyArea(display,pix[PIX_BACK],backbuffer,gc,
+  XCopyArea(display, pix[PIX_BACK], backbuffer, gc,
            0,0, WIN_XSIZE,WIN_YSIZE, 0,0);
-  XFillRectangle(display,pix[PIX_DB_BACK],gc,
+  XFillRectangle(display, pix[PIX_DB_BACK], gc,
                 REAL_SX,REAL_SY, FULL_SXSIZE,FULL_SYSIZE);
-  XFillRectangle(display,pix[PIX_DB_DOOR],gc,
+  XFillRectangle(display, pix[PIX_DB_DOOR], gc,
                 0,0, 3*DXSIZE,DYSIZE+VYSIZE);
+#endif /* !USE_SDL_LIBRARY */
 
   for(i=0; i<MAX_BUF_XSIZE; i++)
     for(j=0; j<MAX_BUF_YSIZE; j++)
@@ -688,9 +801,15 @@ void LoadGfx(int pos, struct PictureFileInfo *pic)
   char *picture_ext = ".xpm";
   char *picturemask_ext = "Mask.xbm";
 #else
+
+#ifdef USE_SDL_LIBRARY
+  SDL_Surface *sdl_image_tmp;
+#else /* !USE_SDL_LIBRARY */
   int pcx_err;
+#endif /* !USE_SDL_LIBRARY */
   char *picture_ext = ".pcx";
-#endif
+
+#endif /* !USE_XPM_LIBRARY */
 
   /* Grafik laden */
   if (pic->picture_filename)
@@ -708,6 +827,26 @@ void LoadGfx(int pos, struct PictureFileInfo *pic)
     debug_print_timestamp(1, NULL);    /* initialize timestamp function */
 #endif
 
+#ifdef USE_SDL_LIBRARY
+    /* load image to temporary surface */
+    if ((sdl_image_tmp = IMG_Load(filename)) == NULL)
+      Error(ERR_EXIT, "IMG_Load() failed: %s\n", SDL_GetError());
+
+    /* create native non-transparent surface for current image */
+    if ((sdl_pix[pos] = SDL_DisplayFormat(sdl_image_tmp)) == NULL)
+      Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s\n", SDL_GetError());
+
+    /* create native transparent surface for current image */
+    SDL_SetColorKey(sdl_image_tmp, SDL_SRCCOLORKEY,
+                   SDL_MapRGB(sdl_image_tmp->format, 0x00, 0x00, 0x00));
+    if ((sdl_pix_masked[pos] = SDL_DisplayFormat(sdl_image_tmp)) == NULL)
+      Error(ERR_EXIT, "SDL_DisplayFormat() failed: %s\n", SDL_GetError());
+
+    /* free temporary surface */
+    SDL_FreeSurface(sdl_image_tmp);
+
+#else /* !USE_SDL_LIBRARY */
+
 #ifdef USE_XPM_LIBRARY
 
     xpm_att[pos].valuemask = XpmCloseness;
@@ -764,8 +903,10 @@ void LoadGfx(int pos, struct PictureFileInfo *pic)
 
     if (!pix[pos])
       Error(ERR_EXIT, "cannot get graphics for '%s'", pic->picture_filename);
+#endif /* !USE_SDL_LIBRARY */
   }
 
+#ifndef USE_SDL_LIBRARY
   /* zugehörige Maske laden (wenn vorhanden) */
   if (pic->picture_with_mask)
   {
@@ -807,6 +948,7 @@ void LoadGfx(int pos, struct PictureFileInfo *pic)
     if (!clipmask[pos])
       Error(ERR_EXIT, "cannot get clipmask for '%s'", pic->picture_filename);
   }
+#endif /* !USE_SDL_LIBRARY */
 }
 
 void InitGadgets()
index 94287fa..2c0b95c 100644 (file)
@@ -38,6 +38,14 @@ XpmAttributes        xpm_att[NUM_PICTURES];
 Drawable        drawto, drawto_field, backbuffer, fieldbuffer;
 Colormap       cmap;
 
+#ifdef USE_SDL_LIBRARY
+SDL_Surface    *sdl_window;
+SDL_Surface    *sdl_drawto, *sdl_drawto_field;
+SDL_Surface    *sdl_backbuffer, *sdl_fieldbuffer;
+SDL_Surface    *sdl_pix[NUM_PIXMAPS];
+SDL_Surface    *sdl_pix_masked[NUM_PIXMAPS], *sdl_tile_masked[NUM_TILES];
+#endif
+
 int            sound_pipe[2];
 int            sound_device;
 char          *sound_device_name = SOUND_DEVICE;
@@ -563,6 +571,183 @@ char *element_info[] =
   */
 };
 
+
+
+/* +-----------------------------------------------------------------------+ */
+/* | SDL TEST STUFF                                                        | */
+/* +-----------------------------------------------------------------------+ */
+
+#ifdef USE_SDL_LIBRARY
+
+SDL_Surface *sdl_screen, *sdl_image_tmp, *sdl_image, *sdl_image_masked;
+SDL_Surface *sdl_image2_tmp, *sdl_image2, *sdl_image2_masked;
+
+void TEST_SDL_BLIT_RECT(int x, int y)
+{
+  SDL_Rect rect_src, rect_dst;
+
+  SDLCopyArea(sdl_pix_masked[PIX_HEROES], sdl_window,
+             8 * TILEX, 8 * TILEY, TILEX, TILEY, x, y);
+  return;
+
+  rect_src.x = 8 * TILEX;
+  rect_src.y = 8 * TILEY;
+  rect_src.w = TILEX;
+  rect_src.h = TILEY;
+
+  rect_dst.x = x;
+  rect_dst.y = y;
+  rect_dst.w = TILEX;
+  rect_dst.h = TILEY;
+
+  SDL_BlitSurface(sdl_image2_masked, &rect_src, sdl_screen, &rect_dst);
+  SDL_UpdateRect(sdl_screen, x, y, TILEX, TILEY);
+}
+
+void TEST_SDL_INIT_DISPLAY()
+{
+  SDL_Rect rect_src, rect_dst;
+
+  if (SDL_Init(SDL_INIT_VIDEO) < 0)
+  {
+    fprintf(stderr, "SDL_Init() failed: %s\n", SDL_GetError());
+    exit(1);
+  }
+
+  /* automatically cleanup SDL stuff after exit() */
+  atexit(SDL_Quit);
+
+  if ((sdl_screen = SDL_SetVideoMode(WIN_XSIZE, WIN_YSIZE, 16, SDL_HWSURFACE))
+      == NULL)
+  {
+    fprintf(stderr, "SDL_SetVideoMode() failed: %s\n", SDL_GetError());
+    exit(1);
+  }
+
+  SDL_WM_SetCaption(WINDOW_TITLE_STRING, WINDOW_TITLE_STRING);
+
+  if ((sdl_image_tmp = IMG_Load("graphics/RocksScreen.pcx")) == NULL)
+  {
+    fprintf(stderr, "IMG_Load() failed: %s\n", SDL_GetError());
+    exit(1);
+  }
+
+  sdl_image = SDL_DisplayFormat(sdl_image_tmp);
+
+  SDL_SetColorKey(sdl_image_tmp, SDL_SRCCOLORKEY,
+                 SDL_MapRGB(sdl_image_tmp->format, 0x00, 0x00, 0x00));
+  sdl_image_masked = SDL_DisplayFormat(sdl_image_tmp);
+
+  SDL_FreeSurface(sdl_image_tmp);
+
+  if ((sdl_image2_tmp = IMG_Load("graphics/RocksHeroes.pcx")) == NULL)
+  {
+    fprintf(stderr, "IMG_Load() failed: %s\n", SDL_GetError());
+    exit(1);
+  }
+
+  sdl_image2 = SDL_DisplayFormat(sdl_image2_tmp);
+  SDL_FreeSurface(sdl_image2_tmp);
+
+  sdl_image2_masked = SDL_DisplayFormat(sdl_image2);
+  SDL_SetColorKey(sdl_image2_masked, SDL_SRCCOLORKEY,
+                 SDL_MapRGB(sdl_image2_masked->format, 0x00, 0x00, 0x00));
+
+  rect_src.x = 0;
+  rect_src.y = 0;
+  rect_src.w = sdl_image->w;
+  rect_src.h = sdl_image->h;
+
+  rect_dst.x = 0;
+  rect_dst.y = 0;
+  rect_dst.w = sdl_image->w;
+  rect_dst.h = sdl_image->h;
+                                           
+  SDL_BlitSurface(sdl_image, &rect_src, sdl_screen, &rect_dst);
+
+  /*
+  SDL_UpdateRect(sdl_screen, 0, 0, WIN_XSIZE, WIN_YSIZE);
+  */
+  /*
+  SDL_UpdateRect(sdl_screen, 0, 0, 0, 0);
+  */
+  SDL_Flip(sdl_screen);
+
+  /*
+  SDL_Delay(5000);
+  */
+}
+
+void TEST_SDL_EVENT_LOOP()
+{
+  SDL_Event event;
+  int quit_loop = 0;
+
+  SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
+
+  while (!quit_loop && SDL_WaitEvent(&event) >=0)
+  {
+    /* hier werden die Ereignisse behandelt */
+    switch(event.type)
+    {
+      case SDL_QUIT:
+      {
+       quit_loop = 1;
+       break;
+      }
+
+      case SDL_MOUSEBUTTONDOWN:
+      {
+       int x = event.button.x;
+       int y = event.button.y;
+
+       SDL_EventState(SDL_MOUSEMOTION, SDL_ENABLE);
+
+       TEST_SDL_BLIT_RECT(x, y);
+
+       printf("SDL_MOUSEBUTTONDOWN(%d, %d)\n", x, y);
+       break;
+      }
+
+      case SDL_MOUSEBUTTONUP:
+      {
+       int x = event.button.x;
+       int y = event.button.y;
+
+       SDL_EventState(SDL_MOUSEMOTION, SDL_IGNORE);
+
+       printf("SDL_MOUSEBUTTONUP(%d, %d)\n", x, y);
+       break;
+      }
+
+      case SDL_MOUSEMOTION:
+      {
+       int x = event.motion.x;
+       int y = event.motion.y;
+
+       TEST_SDL_BLIT_RECT(x, y);
+
+       printf("SDL_MOUSEMOTION(%d, %d)\n", x, y);
+       break;
+      }
+
+      default:
+       break;
+    }
+  }
+
+  SDL_FreeSurface(sdl_image);
+  SDL_Quit();
+}
+
+#endif /* USE_SDL_LIBRARY */
+
+/* +-----------------------------------------------------------------------+ */
+/* | SDL TEST STUFF                                                        | */
+/* +-----------------------------------------------------------------------+ */
+
+
+
 int main(int argc, char *argv[])
 {
   program_name = (strrchr(argv[0],'/') ? strrchr(argv[0],'/') + 1 : argv[0]);
@@ -573,6 +758,13 @@ int main(int argc, char *argv[])
 
   GetOptions(argv);
   OpenAll(argc,argv);
+
+#ifdef USE_SDL_LIBRARY
+  TEST_SDL_BLIT_RECT((WIN_XSIZE - TILEX)/2, (WIN_YSIZE - TILEY)/2);
+  TEST_SDL_EVENT_LOOP();
+  exit(0);
+#endif
+
   EventLoop();
   CloseAllAndExit(0);
   exit(0);     /* to keep compilers happy */
index add49d7..4c1d57d 100644 (file)
 #include "msdos.h"
 #endif  /* MSDOS */
 
+#ifdef USE_SDL_LIBRARY
+#include "sdl.h"
+#endif
+
 #ifdef DEBUG
 #define DEBUG_TIMING   0
 #endif
@@ -54,6 +58,7 @@ typedef unsigned char byte;
 
 #define WIN_XSIZE      672
 #define WIN_YSIZE      560
+#define WIN_SDL_DEPTH  16      /* !!! change this !!! */
 #ifndef MSDOS
 #define WIN_XPOS       0
 #define WIN_YPOS       0
@@ -473,6 +478,14 @@ extern XpmAttributes       xpm_att[];
 extern Drawable        drawto, drawto_field, backbuffer, fieldbuffer;
 extern Colormap                cmap;
 
+#ifdef USE_SDL_LIBRARY
+extern SDL_Surface    *sdl_window;
+extern SDL_Surface    *sdl_drawto, *sdl_drawto_field;
+extern SDL_Surface    *sdl_backbuffer, *sdl_fieldbuffer;
+extern SDL_Surface    *sdl_pix[];
+extern SDL_Surface    *sdl_pix_masked[], *sdl_tile_masked[];
+#endif
+
 extern int             sound_pipe[2];
 extern int             sound_device;
 extern char           *sound_device_name;
@@ -1662,7 +1675,7 @@ extern char               *element_info[];
 #define TAPES_DIRECTORY                "tapes"
 #define SCORES_DIRECTORY       "scores"
 
-#define PROGRAM_VERSION_STRING "1.4.0"
+#define PROGRAM_VERSION_STRING "1.4.0 SDL"
 #define PROGRAM_TITLE_STRING   "Rocks'n'Diamonds"
 #define PROGRAM_AUTHOR_STRING  "Holger Schemel"
 #define WINDOW_TITLE_STRING    PROGRAM_TITLE_STRING " " PROGRAM_VERSION_STRING
diff --git a/src/sdl.c b/src/sdl.c
new file mode 100644 (file)
index 0000000..d810012
--- /dev/null
+++ b/src/sdl.c
@@ -0,0 +1,57 @@
+/***********************************************************
+*  Rocks'n'Diamonds -- McDuffin Strikes Back!              *
+*----------------------------------------------------------*
+*  ©1995 Artsoft Development                               *
+*        Holger Schemel                                    *
+*        33659 Bielefeld-Senne                             *
+*        Telefon: (0521) 493245                            *
+*        eMail: aeglos@valinor.owl.de                      *
+*               aeglos@uni-paderborn.de                    *
+*               q99492@pbhrzx.uni-paderborn.de             *
+*----------------------------------------------------------*
+*  sdl.c                                                   *
+***********************************************************/
+
+#ifdef USE_SDL_LIBRARY
+
+#include "main.h"
+
+inline void SDLCopyArea(SDL_Surface *src_surface, SDL_Surface *dst_surface,
+                       int src_x, int src_y,
+                       int width, int height,
+                       int dst_x, int dst_y)
+{
+  SDL_Rect src_rect, dst_rect;
+
+  src_rect.x = src_x;
+  src_rect.y = src_y;
+  src_rect.w = width;
+  src_rect.h = height;
+
+  dst_rect.x = dst_x;
+  dst_rect.y = dst_y;
+  dst_rect.w = width;
+  dst_rect.h = height;
+
+  SDL_BlitSurface(src_surface, &src_rect, dst_surface, &dst_rect);
+  SDL_UpdateRect(dst_surface, dst_x, dst_y, width, height);
+}
+
+inline void SDLFillRectangle(SDL_Surface *surface, int x, int y,
+                            int width, int height, unsigned int color)
+{
+  SDL_Rect rect;
+  unsigned int color_r = (color >> 2) && 0xff;
+  unsigned int color_g = (color >> 1) && 0xff;
+  unsigned int color_b = (color >> 0) && 0xff;
+
+  rect.x = x;
+  rect.y = y;
+  rect.w = width;
+  rect.h = height;
+
+  SDL_FillRect(surface, &rect,
+               SDL_MapRGB(surface->format, color_r, color_g, color_b));
+}
+
+#endif /* USE_SDL_LIBRARY */
diff --git a/src/sdl.h b/src/sdl.h
new file mode 100644 (file)
index 0000000..9bfcff3
--- /dev/null
+++ b/src/sdl.h
@@ -0,0 +1,21 @@
+/***********************************************************
+*  Rocks'n'Diamonds -- McDuffin Strikes Back!              *
+*----------------------------------------------------------*
+*  ©1995 Artsoft Development                               *
+*        Holger Schemel                                    *
+*        33659 Bielefeld-Senne                             *
+*        Telefon: (0521) 493245                            *
+*        eMail: aeglos@valinor.owl.de                      *
+*               aeglos@uni-paderborn.de                    *
+*               q99492@pbhrzx.uni-paderborn.de             *
+*----------------------------------------------------------*
+*  sdl.h                                                   *
+***********************************************************/
+
+#include <SDL/SDL.h>
+#include <IMG.h>
+
+inline void SDLCopyArea(SDL_Surface *, SDL_Surface *,
+                       int, int, int, int, int, int);
+inline void SDLFillRectangle(SDL_Surface *, int, int,
+                            int, int, unsigned int);
index 775bc0d..0c9cd17 100644 (file)
@@ -338,6 +338,15 @@ int getFontHeight(int font_size, int font_type)
 
 void DrawInitText(char *text, int ypos, int color)
 {
+#ifdef USE_SDL_LIBRARY
+  if (sdl_window && sdl_pix[PIX_SMALLFONT])
+  {
+    SDLFillRectangle(sdl_window, 0, ypos, WIN_XSIZE, FONT2_YSIZE, 0x000000);
+    DrawTextExt(window, gc, (WIN_XSIZE - strlen(text) * FONT2_XSIZE)/2,
+               ypos,text,FS_SMALL,color);
+    SDL_Flip(sdl_window);
+  }
+#else
   if (display && window && pix[PIX_SMALLFONT])
   {
     XFillRectangle(display, window, gc, 0, ypos, WIN_XSIZE, FONT2_YSIZE);
@@ -345,6 +354,7 @@ void DrawInitText(char *text, int ypos, int color)
                ypos,text,FS_SMALL,color);
     XFlush(display);
   }
+#endif
 }
 
 void DrawTextFCentered(int y, int font_type, char *format, ...)
@@ -447,8 +457,15 @@ void DrawTextExt(Drawable d, GC gc, int x, int y,
                  0, 0, font_width, font_height, dest_x, dest_y);
       }
       else
+      {
+#ifdef USE_SDL_LIBRARY
+       SDLCopyArea(sdl_pix[font_pixmap], sdl_window,
+                   src_x, src_y, font_width, font_height, dest_x, dest_y);
+#else
        XCopyArea(display, pix[font_pixmap], d, gc,
                  src_x, src_y, font_width, font_height, dest_x, dest_y);
+#endif
+      }
     }
 
     x += font_width;