ref: f9d1d15dbdda82faaca58d7d4a3ccd0c74f10da2
parent: a3a2b9a7c5c262d5f1eef855a064249a2e020f88
author: LTCHIPS <ltchips994@gmail.com>
date: Tue Mar 13 15:19:05 EDT 2018
begin porting ROTT to SDL2. It runs, but scancodes seem to be wrong
--- a/rott/Makefile
+++ b/rott/Makefile
@@ -2,7 +2,7 @@
# Make sure only one of the following is set to 1 at once
# Triple 0 will build the commercial/registered version
-SHAREWARE ?= 1
+SHAREWARE ?= 0
SUPERROTT ?= 0
SITELICENSE ?= 0
@@ -18,7 +18,7 @@
CFLAGS ?= -g -O2
CFLAGS += -Wall -Wno-unused
-CFLAGS += $(shell sdl-config --cflags)
+CFLAGS += $(shell sdl2-config --cflags)
CFLAGS += $(EXTRACFLAGS)
CPPFLAGS += -DUSE_SDL=1
@@ -27,7 +27,7 @@
LDFLAGS += $(EXTRALDFLAGS)
-LDLIBS += $(shell sdl-config --libs)
+LDLIBS += $(shell sdl2-config --libs)
LDLIBS += -lSDL_mixer
LDLIBS += $(EXTRALDLIBS)
--- a/rott/audiolib/dsl.c
+++ b/rott/audiolib/dsl.c
@@ -4,8 +4,8 @@
#include "dsl.h"
#include "util.h"
-#include "SDL.h"
-#include "SDL_mixer.h"
+#include "SDL2/SDL.h"
+#include "SDL2/SDL_mixer.h"
extern volatile int MV_MixPage;
--- a/rott/dosutil.c
+++ b/rott/dosutil.c
@@ -15,7 +15,7 @@
#include "rt_def.h"
#if defined(USE_SDL)
-#include "SDL.h"
+#include "SDL2/SDL.h"
#endif
/*
@@ -236,7 +236,7 @@
printf ("Here is where:\n");
print_stack (1);
#if defined(USE_SDL)
- SDL_Quit ();
+ atexit(SDL_Quit);
#endif
exit (1);
}
--- a/rott/dukemusc.c
+++ b/rott/dukemusc.c
@@ -33,8 +33,8 @@
#define cdecl
#endif
-#include "SDL.h"
-#include "SDL_mixer.h"
+#include "SDL2/SDL.h"
+#include "SDL2/SDL_mixer.h"
#ifdef ROTT
#include "rt_def.h" // ROTT music hack
#include "rt_cfg.h" // ROTT music hack
--- a/rott/fx_man.c
+++ b/rott/fx_man.c
@@ -20,7 +20,7 @@
#define cdecl
#endif
-#include "SDL.h"
+#include "SDL2/SDL.h"
#include "SDL_mixer.h"
#include "rt_def.h" // ROTT music hack
#include "rt_cfg.h" // ROTT music hack
--- a/rott/isr.c
+++ b/rott/isr.c
@@ -749,7 +749,7 @@
}
#else
-#include "SDL.h"
+#include "SDL2/SDL.h"
static int ticoffset; /* offset for SDL_GetTicks() */
static int ticbase; /* game-supplied base */
--- a/rott/modexlib.c
+++ b/rott/modexlib.c
@@ -34,6 +34,7 @@
#include <stdlib.h>
#include <sys/stat.h>
+#include <SDL2/SDL_video.h>
#include "modexlib.h"
//MED
#include "memcheck.h"
@@ -51,6 +52,17 @@
extern int iG_Y_center;
char *iG_buf_center;
+SDL_Surface *sdl_surface = NULL;
+
+static SDL_Window * window = NULL;
+
+static SDL_Renderer * renderer = NULL;
+
+SDL_Surface *unstretch_sdl_surface = NULL;
+
+static SDL_Texture *sdl_texture = NULL; //sort of a replacement for surface...
+
+
int linewidth;
//int ylookup[MAXSCREENHEIGHT];
int ylookup[MAXSCREENHEIGHT];//just set to max res
@@ -399,8 +411,8 @@
#else
-#include "SDL.h"
+
#ifndef STUB_FUNCTION
/* rt_def.h isn't included, so I just put this here... */
@@ -419,9 +431,8 @@
=
====================
*/
-static SDL_Surface *sdl_surface = NULL;
-static SDL_Surface *unstretch_sdl_surface = NULL;
+
void GraphicsMode ( void )
{
Uint32 flags = 0;
@@ -436,14 +447,36 @@
flags = SDL_FULLSCREEN;
#endif
- SDL_WM_GrabInput(SDL_GRAB_ON);
- SDL_WM_SetCaption ("Rise of the Triad", "ROTT");
- SDL_ShowCursor (0);
+
+ SDL_SetRelativeMouseMode(SDL_TRUE);
+
+ //SDL_WM_GrabInput(SDL_GRAB_ON);
+ //SDL_WM_SetCaption ("Rise of the Triad", "ROTT");
+ //SDL_ShowCursor (0);
// sdl_surface = SDL_SetVideoMode (320, 200, 8, flags);
- if (sdl_fullscreen)
- flags = SDL_FULLSCREEN;
- sdl_surface = SDL_SetVideoMode (iGLOBAL_SCREENWIDTH, iGLOBAL_SCREENHEIGHT, 8, flags);
- if (sdl_surface == NULL)
+ //if (sdl_fullscreen)
+ //flags = SDL_FULLSCREEN;
+
+ //replaces sdl_surface
+ window = SDL_CreateWindow("Rise of the Triad",
+ SDL_WINDOWPOS_UNDEFINED, SDL_WINDOWPOS_UNDEFINED,
+ iGLOBAL_SCREENWIDTH, iGLOBAL_SCREENHEIGHT,
+ 0);
+
+ //SDL_CreateWindowAndRenderer(iGLOBAL_SCREENWIDTH, iGLOBAL_SCREENHEIGHT, 0, &window, &renderer);
+
+
+ renderer = SDL_CreateRenderer(window, -1, 0);
+
+ sdl_texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ABGR8888,
+ SDL_TEXTUREACCESS_STREAMING, iGLOBAL_SCREENWIDTH,
+ iGLOBAL_SCREENHEIGHT);
+
+
+ //sdl_surface = SDL_SetVideoMode (iGLOBAL_SCREENWIDTH, iGLOBAL_SCREENHEIGHT, 8, flags);
+ sdl_surface = SDL_CreateRGBSurface(0,iGLOBAL_SCREENWIDTH,iGLOBAL_SCREENHEIGHT,
+ 8,0,0,0,0);
+ if (window == NULL)
{
Error ("Could not set video mode\n");
}
@@ -694,7 +727,19 @@
} else {
DrawCenterAim ();
}
- SDL_UpdateRect (SDL_GetVideoSurface (), 0, 0, 0, 0);
+
+ //SDL_UpdateRect (SDL_GetVideoSurface (), 0, 0, 0, 0);
+ SDL_Texture *newTex = SDL_CreateTextureFromSurface(renderer, sdl_surface);
+ if (newTex == NULL) {
+ Error("CreateTextureFromSurface failed: %s\n", SDL_GetError());
+ exit(1);
+ }
+
+ SDL_RenderClear(renderer);
+ SDL_RenderCopy(renderer, newTex, NULL, NULL);
+ SDL_RenderPresent(renderer);
+
+ SDL_DestroyTexture(newTex);
}
@@ -727,7 +772,19 @@
} else {
DrawCenterAim ();
}
- SDL_UpdateRect (sdl_surface, 0, 0, 0, 0);
+
+ SDL_Texture *newTex = SDL_CreateTextureFromSurface(renderer, sdl_surface);
+ if (newTex == NULL) {
+ Error("CreateTextureFromSurface failed: %s\n", SDL_GetError());
+ exit(1);
+ }
+
+ SDL_RenderClear(renderer);
+ SDL_RenderCopy(renderer, newTex, NULL, NULL);
+ SDL_RenderPresent(renderer);
+
+ SDL_DestroyTexture(newTex);
+ //SDL_UpdateRect (sdl_surface, 0, 0, 0, 0);s
#endif
}
--- a/rott/modexlib.h
+++ b/rott/modexlib.h
@@ -28,6 +28,7 @@
#include "WinRott.h"
#include "rt_def.h"
+#include "SDL2/SDL.h"
/*
int iGLOBAL_SCREENWIDTH;//bna val 800
int iGLOBAL_SCREENHEIGHT;//bna val 600
@@ -120,6 +121,10 @@
extern byte *bufferofs;
extern byte *displayofs;
extern boolean graphicsmode;
+
+//extern SDL_Window* window;
+
+extern SDL_Surface * sdl_surface;
void GraphicsMode ( void );
--- a/rott/rt_in.c
+++ b/rott/rt_in.c
@@ -28,7 +28,7 @@
#endif
#if USE_SDL
-#include "SDL.h"
+#include "SDL2/SDL.h"
#endif
#include "rt_main.h"
@@ -103,7 +103,7 @@
static word *sdl_stick_button_state = NULL;
static word sdl_sticks_joybits = 0;
static int sdl_mouse_grabbed = 0;
-static unsigned int scancodes[SDLK_LAST];
+static unsigned int scancodes[SDL_NUM_SCANCODES]; //TODO: replace with a hashtable if possible
extern boolean sdl_fullscreen;
#endif
@@ -269,148 +269,8 @@
* surface's current flags are used.
* @return non-zero on success, zero on failure.
*/
-static int attempt_fullscreen_toggle(SDL_Surface **surface, Uint32 *flags)
-{
- long framesize = 0;
- void *pixels = NULL;
- SDL_Rect clip;
- Uint32 tmpflags = 0;
- int w = 0;
- int h = 0;
- int bpp = 0;
- int grabmouse = (SDL_WM_GrabInput(SDL_GRAB_QUERY) == SDL_GRAB_ON);
- int showmouse = SDL_ShowCursor(-1);
- SDL_Color *palette = NULL;
- int ncolors = 0;
+//TODO: Write new fullscreen toggle....
- /*
- sdldebug("attempting to toggle fullscreen flag...");
- */
-
- if ( (!surface) || (!(*surface)) ) /* don't try if there's no surface. */
- {
- /*
- sdldebug("Null surface (?!). Not toggling fullscreen flag.");
- */
- return(0);
- } /* if */
-
- if (SDL_WM_ToggleFullScreen(*surface))
- {
- /*
- sdldebug("SDL_WM_ToggleFullScreen() seems to work on this system.");
- */
- if (flags)
- *flags ^= SDL_FULLSCREEN;
- return(1);
- } /* if */
-
- if ( !(SDL_GetVideoInfo()->wm_available) )
- {
- /*
- sdldebug("No window manager. Not toggling fullscreen flag.");
- */
- return(0);
- } /* if */
-
- /*
- sdldebug("toggling fullscreen flag The Hard Way...");
- */
- tmpflags = (*surface)->flags;
- w = (*surface)->w;
- h = (*surface)->h;
- bpp = (*surface)->format->BitsPerPixel;
-
- if (flags == NULL) /* use the surface's flags. */
- flags = &tmpflags;
-
- SDL_GetClipRect(*surface, &clip);
-
- /* save the contents of the screen. */
- if ( (!(tmpflags & SDL_OPENGL)) && (!(tmpflags & SDL_OPENGLBLIT)) )
- {
- framesize = (w * h) * ((*surface)->format->BytesPerPixel);
- pixels = malloc(framesize);
- if (pixels == NULL)
- return(0);
- memcpy(pixels, (*surface)->pixels, framesize);
- } /* if */
-
-#if 1
- STUB_FUNCTION; /* palette is broken. FIXME !!! --ryan. */
-#else
- if ((*surface)->format->palette != NULL)
- {
- ncolors = (*surface)->format->palette->ncolors;
- palette = malloc(ncolors * sizeof (SDL_Color));
- if (palette == NULL)
- {
- free(pixels);
- return(0);
- } /* if */
- memcpy(palette, (*surface)->format->palette->colors,
- ncolors * sizeof (SDL_Color));
- } /* if */
-#endif
-
- if (grabmouse)
- SDL_WM_GrabInput(SDL_GRAB_OFF);
-
- SDL_ShowCursor(1);
-
- *surface = SDL_SetVideoMode(w, h, bpp, (*flags) ^ SDL_FULLSCREEN);
-
- if (*surface != NULL)
- *flags ^= SDL_FULLSCREEN;
-
- else /* yikes! Try to put it back as it was... */
- {
- *surface = SDL_SetVideoMode(w, h, bpp, tmpflags);
- if (*surface == NULL) /* completely screwed. */
- {
- if (pixels != NULL)
- free(pixels);
- if (palette != NULL)
- free(palette);
- return(0);
- } /* if */
- } /* if */
-
- /* Unfortunately, you lose your OpenGL image until the next frame... */
-
- if (pixels != NULL)
- {
- memcpy((*surface)->pixels, pixels, framesize);
- free(pixels);
- } /* if */
-
-#if 1
- STUB_FUNCTION; /* palette is broken. FIXME !!! --ryan. */
-#else
- if (palette != NULL)
- {
- /* !!! FIXME : No idea if that flags param is right. */
- SDL_SetPalette(*surface, SDL_LOGPAL, palette, 0, ncolors);
- free(palette);
- } /* if */
-#endif
-
- SDL_SetClipRect(*surface, &clip);
-
- if (grabmouse)
- SDL_WM_GrabInput(SDL_GRAB_ON);
-
- SDL_ShowCursor(showmouse);
-
-#if 0
- STUB_FUNCTION; /* pull this out of buildengine/sdl_driver.c ... */
- output_surface_info(*surface);
-#endif
-
- return(1);
-} /* attempt_fullscreen_toggle */
-
-
/*
* The windib driver can't alert us to the keypad enter key, which
* Ken's code depends on heavily. It sends it as the same key as the
@@ -453,7 +313,7 @@
int k;
int keyon;
int strippedkey;
- SDL_GrabMode grab_mode = SDL_GRAB_OFF;
+ //SDL_GrabMode grab_mode = SDL_GRAB_OFF;
int extended;
if ( (event->key.keysym.sym == SDLK_g) &&
@@ -460,13 +320,13 @@
(event->key.state == SDL_PRESSED) &&
(event->key.keysym.mod & KMOD_CTRL) )
{
- if (!sdl_fullscreen)
- {
- sdl_mouse_grabbed = ((sdl_mouse_grabbed) ? 0 : 1);
- if (sdl_mouse_grabbed)
- grab_mode = SDL_GRAB_ON;
- SDL_WM_GrabInput(grab_mode);
- }
+ //if (!sdl_fullscreen)
+ //{
+ //sdl_mouse_grabbed = ((sdl_mouse_grabbed) ? 0 : 1);
+ //if (sdl_mouse_grabbed)
+ //grab_mode = SDL_GRAB_ON;
+ //SDL_WM_GrabInput(grab_mode);
+ //}
return(0);
} /* if */
@@ -475,9 +335,9 @@
(event->key.state == SDL_PRESSED) &&
(event->key.keysym.mod & KMOD_ALT) )
{
- if (SDL_WM_ToggleFullScreen(SDL_GetVideoSurface()))
- sdl_fullscreen ^= 1;
- return(0);
+ //if (SDL_WM_ToggleFullScreen(SDL_GetVideoSurface()))
+ //sdl_fullscreen ^= 1;
+ //return(0);
} /* if */
/* HDG: put this above the scancode lookup otherwise it is never reached */
@@ -498,11 +358,11 @@
/* Fix elweirdo SDL capslock/numlock handling, always treat as press */
if ( (event->key.keysym.sym != SDLK_CAPSLOCK) &&
- (event->key.keysym.sym != SDLK_NUMLOCK) &&
+ (event->key.keysym.sym != SDLK_NUMLOCKCLEAR) &&
(event->key.state == SDL_RELEASED) )
k += 128; /* +128 signifies that the key is released in DOS. */
- if (event->key.keysym.sym == SDLK_SCROLLOCK)
+ if (event->key.keysym.sym == SDLK_SCROLLLOCK)
PanicPressed = true;
else
@@ -577,15 +437,8 @@
//******************************************************************************
void IN_PumpEvents(void)
{
-#if USE_SDL
sdl_handle_events();
-
-#elif PLATFORM_DOS
/* no-op. */
-
-#else
-#error please define for your platform.
-#endif
}
@@ -1084,7 +937,7 @@
scancodes[SDLK_BACKSLASH] = 0x2B;
/* Accept the German eszett as a backslash key */
- scancodes[SDLK_WORLD_63] = 0x2B;
+ //scancodes[SDLK_WORLD_63] = 0x2B;
scancodes[SDLK_z] = sc_Z;
scancodes[SDLK_x] = sc_X;
scancodes[SDLK_c] = sc_C;
@@ -1119,15 +972,15 @@
scancodes[SDLK_F10] = sc_F10;
scancodes[SDLK_F11] = sc_F11;
scancodes[SDLK_F12] = sc_F12;
- scancodes[SDLK_NUMLOCK] = 0x45;
- scancodes[SDLK_SCROLLOCK] = 0x46;
+ scancodes[SDLK_NUMLOCKCLEAR] = 0x45;
+ scancodes[SDLK_SCROLLLOCK] = 0x46;
//scancodes[SDLK_MINUS] = 0x4A;
scancodes[SDLK_MINUS] = sc_Minus;
- scancodes[SDLK_KP7] = sc_Home;
- scancodes[SDLK_KP8] = sc_UpArrow;
- scancodes[SDLK_KP9] = sc_PgUp;
+ scancodes[SDLK_KP_7] = sc_Home;
+ scancodes[SDLK_KP_8] = sc_UpArrow;
+ scancodes[SDLK_KP_9] = sc_PgUp;
scancodes[SDLK_HOME] = sc_Home;
scancodes[SDLK_UP] = sc_UpArrow;
scancodes[SDLK_PAGEUP] = sc_PgUp;
@@ -1134,9 +987,9 @@
// Make this a normal minus, for viewport changing
//scancodes[SDLK_KP_MINUS] = 0xE04A;
scancodes[SDLK_KP_MINUS] = sc_Minus;
- scancodes[SDLK_KP4] = sc_LeftArrow;
- scancodes[SDLK_KP5] = 0x4C;
- scancodes[SDLK_KP6] = sc_RightArrow;
+ scancodes[SDLK_KP_4] = sc_LeftArrow;
+ scancodes[SDLK_KP_5] = 0x4C;
+ scancodes[SDLK_KP_6] = sc_RightArrow;
scancodes[SDLK_LEFT] = sc_LeftArrow;
scancodes[SDLK_RIGHT] = sc_RightArrow;
@@ -1143,14 +996,14 @@
//scancodes[SDLK_KP_PLUS] = 0x4E;
scancodes[SDLK_KP_PLUS] = sc_Plus;
- scancodes[SDLK_KP1] = sc_End;
- scancodes[SDLK_KP2] = sc_DownArrow;
- scancodes[SDLK_KP3] = sc_PgDn;
+ scancodes[SDLK_KP_1] = sc_End;
+ scancodes[SDLK_KP_2] = sc_DownArrow;
+ scancodes[SDLK_KP_3] = sc_PgDn;
scancodes[SDLK_END] = sc_End;
scancodes[SDLK_DOWN] = sc_DownArrow;
scancodes[SDLK_PAGEDOWN] = sc_PgDn;
scancodes[SDLK_DELETE] = sc_Delete;
- scancodes[SDLK_KP0] = sc_Insert;
+ scancodes[SDLK_KP_0] = sc_Insert;
scancodes[SDLK_INSERT] = sc_Insert;
scancodes[SDLK_KP_ENTER] = sc_Return;
#endif
--- a/rott/rt_main.c
+++ b/rott/rt_main.c
@@ -40,7 +40,7 @@
#if USE_SDL
/* Need to redefine main to SDL_main on some platforms... */
-#include "SDL.h"
+#include "SDL2/SDL.h"
#endif
#include "rt_actor.h"
@@ -1145,7 +1145,8 @@
while (1)
{
- SDL_WarpMouse(iGLOBAL_SCREENWIDTH<<1, iGLOBAL_SCREENHEIGHT<<1);
+ //no longer needed in SDL2
+ //SDL_WarpMouse(iGLOBAL_SCREENWIDTH<<1, iGLOBAL_SCREENHEIGHT<<1);
if ( playstate == ex_battledone )
{
while( damagecount > 0 )
--- a/rott/rt_menu.c
+++ b/rott/rt_menu.c
@@ -38,7 +38,7 @@
#include <io.h>
#elif PLATFORM_UNIX
#include <unistd.h>
-#include "SDL.h"
+#include "SDL2/SDL.h"
#endif
#include <sys/types.h>
@@ -5729,11 +5729,11 @@
DrawExtOptionsButtons ();
break;
case 5:
- if (SDL_WM_ToggleFullScreen(SDL_GetVideoSurface()))
- {
- sdl_fullscreen ^= 1;
- DrawExtOptionsButtons ();
- }
+ //if (SDL_WM_ToggleFullScreen(SDL_GetVideoSurface()))
+ //{
+ //sdl_fullscreen ^= 1;
+ DrawExtOptionsButtons ();
+ //}
break;
case 6:
autoAimMissileWeps ^= 1;
--- a/rott/rt_util.c
+++ b/rott/rt_util.c
@@ -27,7 +27,7 @@
#include <io.h>
#include <direct.h>
#elif USE_SDL
-#include "SDL.h"
+#include "SDL2/SDL.h"
#endif
#include <stdarg.h>
@@ -39,6 +39,7 @@
#include <stdlib.h>
#include <sys/stat.h>
#include <time.h>
+#include <SDL2/SDL_render.h>
#include "watcom.h"
#include "_rt_util.h"
#include "rt_util.h"
@@ -1250,7 +1251,7 @@
palette[i] = inp (PEL_DATA)<<2;
#else
int i;
- SDL_Palette *pal = SDL_GetVideoSurface()->format->palette;
+ SDL_Palette *pal = sdl_surface->format->palette;
for (i = 0; i < 256; i++) {
palette[0] = pal->colors[i].r;
@@ -1291,7 +1292,8 @@
cmap[i].b = pal[i*3+2];
}
- SDL_SetColors (SDL_GetVideoSurface (), cmap, 0, 256);
+ SDL_SetPaletteColors(sdl_surface->format->palette, cmap, 0, 256);
+ //SDL_SetColors (SDL_GetWindowSurface(window), cmap, 0, 256);
#endif
}
@@ -1305,7 +1307,7 @@
*(palette+(unsigned char)i)=inp(0x3c9)<<2;
#else
int i;
- SDL_Palette *pal = SDL_GetVideoSurface()->format->palette;
+ SDL_Palette *pal = sdl_surface->format->palette;
for (i = 0; i < 256; i++) {
palette[0] = pal->colors[i].r;
@@ -1406,7 +1408,9 @@
cmap[i].b = blue << 2;
}
- SDL_SetColors (SDL_GetVideoSurface (), cmap, 0, 256);
+ //SDL_SetColors (SDL_GetVideoSurface (), cmap, 0, 256);
+ SDL_SetPaletteColors(sdl_surface->format->palette, cmap, 0, 256);
+
#endif
}
@@ -1506,7 +1510,9 @@
cmap[i].b = gammatable[(gammaindex<<6)+(*palette++)] << 2;
}
- SDL_SetColors (SDL_GetVideoSurface (), cmap, 0, 256);
+ //SDL_SetColors (SDL_GetWindowSurface(window), cmap, 0, 256);
+ SDL_SetPaletteColors(sdl_surface->format->palette, cmap, 0, 256);
+
#endif
}
@@ -1535,7 +1541,8 @@
*palette++ = inp (PEL_DATA);
#else
int i;
- SDL_Palette *pal = SDL_GetVideoSurface()->format->palette;
+ SDL_Palette *pal = sdl_surface->format->palette;
+ //SDL_Palette *pal = SDL_GetVideoSurface()->format->palette;
for (i = 0; i < 256; i++) {
palette[0] = pal->colors[i].r >> 2;