Commit 32ab9957 authored by Steven Fuller's avatar Steven Fuller

Implemented vi_xlib! Fixed a wl_menu bug with custom controls.

parent c7e721f4
...@@ -60,13 +60,14 @@ at the same time... especially when you pick up items ...@@ -60,13 +60,14 @@ at the same time... especially when you pick up items
metaname like sc_Left etc or something metaname like sc_Left etc or something
* fizzlefade is hackish, stipple buf would work ok in opengl, maybe only * fizzlefade is hackish, stipple buf would work ok in opengl, maybe only
update once per frame or such.. hm update once per frame or such.. hm
and where is that greenpixel coming from (when using end game with largest and where is that stray pixel coming from (when using end game with largest
window size) window size)
* change id_sd to sd_oss, sd_win, sd_dos, sd_oal, etc * change id_sd to sd_oss, sd_win, sd_dos, sd_oal, etc
idea is that different <outputs> can share some drivers, unlike video idea is that different <outputs> can share some drivers, unlike video
* check filehandling (ex, file missing, bad file type, and such) * check filehandling (ex, file missing, bad file type, and such)
PlayDemoFromFile specifically PlayDemoFromFile specifically
* make sure all infinite loops are found (looping around Keyboard) * make sure all infinite loops are found (looping around Keyboard)
* move FadeIn/FadeOut to id_vh? since it calls vl functions only
Specific: Specific:
* memory/sound intro screen goes * memory/sound intro screen goes
......
...@@ -14,24 +14,28 @@ ...@@ -14,24 +14,28 @@
/* #define SPEARDEMO */ /* #define SPEARDEMO */
/* #define GOODTIMES */ /* #define GOODTIMES */
#define UPLOAD #define UPLOAD
#define GAMENAME "Wolfenstein 3D Shareware"
#elif WMODE == 1 #elif WMODE == 1
/* #define SPEAR */ /* #define SPEAR */
/* #define SPEARDEMO */ /* #define SPEARDEMO */
#define GOODTIMES #define GOODTIMES
/* #define UPLOAD */ /* #define UPLOAD */
#define GAMENAME "Wolfenstein 3D"
#elif WMODE == 2 #elif WMODE == 2
#define SPEAR #define SPEAR
#define SPEARDEMO #define SPEARDEMO
#define GOODTIMES #define GOODTIMES
/* #define UPLOAD */ /* #define UPLOAD */
#define GAMENAME "Spear of Destiny Demo"
#elif WMODE == 3 #elif WMODE == 3
#define SPEAR #define SPEAR
/* #define SPEARDEMO */ /* #define SPEARDEMO */
#define GOODTIMES #define GOODTIMES
/* #define UPLOAD */ /* #define UPLOAD */
#define GAMENAME "Spear of Destiny"
#else #else
#error "please edit version.h and fix WMODE" #error "please edit version.h and fix WMODE"
......
...@@ -250,18 +250,6 @@ void VL_FadeIn(int start, int end, byte *palette, int steps) ...@@ -250,18 +250,6 @@ void VL_FadeIn(int start, int end, byte *palette, int steps)
screenfaded = false; screenfaded = false;
} }
/*
==================
=
= VL_ColorBorder
=
==================
*/
void VL_ColorBorder (int color)
{
}
/* /*
============================================================================= =============================================================================
......
...@@ -33,7 +33,12 @@ void VL_Startup (void) ...@@ -33,7 +33,12 @@ void VL_Startup (void)
gfxbuf = malloc(320 * 200 * 1); gfxbuf = malloc(320 * 200 * 1);
vga_init(); /* TODO: maybe move into main or such? */ vga_init(); /* TODO: maybe move into main or such? */
vga_setmode(G320x200x256);
if (vga_hasmode(G320x200x256) == 0)
Quit("vga_hasmode failed!");
if (vga_setmode(G320x200x256) != 0)
Quit("vga_setmode failed!");
} }
/* /*
...@@ -264,18 +269,6 @@ void VL_FadeIn(int start, int end, byte *palette, int steps) ...@@ -264,18 +269,6 @@ void VL_FadeIn(int start, int end, byte *palette, int steps)
screenfaded = false; screenfaded = false;
} }
/*
==================
=
= VL_ColorBorder
=
==================
*/
void VL_ColorBorder (int color)
{
}
/* /*
============================================================================= =============================================================================
...@@ -824,7 +817,6 @@ void IN_ReadControl(int player,ControlInfo *info) ...@@ -824,7 +817,6 @@ void IN_ReadControl(int player,ControlInfo *info)
mx = my = motion_None; mx = my = motion_None;
buttons = 0; buttons = 0;
//keyboard_update();
IN_CheckAck(); IN_CheckAck();
switch (type = Controls[player]) switch (type = Controls[player])
......
...@@ -4,6 +4,13 @@ ...@@ -4,6 +4,13 @@
#include <X11/Xlib.h> #include <X11/Xlib.h>
#include <X11/keysym.h> #include <X11/keysym.h>
#include <X11/Xutil.h>
#include <X11/Xos.h>
#include <X11/cursorfont.h>
#include <X11/keysym.h>
#include <X11/keysymdef.h>
#include <X11/Xatom.h>
#include <X11/extensions/XShm.h>
boolean screenfaded; boolean screenfaded;
...@@ -11,12 +18,111 @@ byte palette1[256][3], palette2[256][3]; ...@@ -11,12 +18,111 @@ byte palette1[256][3], palette2[256][3];
byte *gfxbuf = NULL; byte *gfxbuf = NULL;
Display *dpy;
int screen;
Window root, win;
XVisualInfo *vi;
GC gc;
XImage *img;
Colormap cmap;
Atom wmDeleteWindow;
XColor clr[256];
int main(int argc, char *argv[])
{
/* TODO: move these to proper functions */
XSetWindowAttributes attr;
XVisualInfo vitemp;
XSizeHints sizehints;
XGCValues gcvalues;
char *disp;
int attrmask, numVisuals, i;
disp = getenv("DISPLAY");
dpy = XOpenDisplay(disp);
if (dpy == NULL) {
/* TODO: quit function with vsnprintf */
printf("Unable to open display %s!\n", XDisplayName(disp));
exit(EXIT_FAILURE);
}
screen = DefaultScreen(dpy);
root = RootWindow(dpy, screen);
vitemp.screen = screen;
vitemp.depth = 8;
vitemp.class = PseudoColor;
vi = XGetVisualInfo(dpy, VisualScreenMask | VisualDepthMask |
VisualClassMask, &vitemp, &numVisuals);
if ((vi == NULL) || (numVisuals == 0)) {
Quit("No visuals found!");
}
if (vi->class != PseudoColor) {
Quit("Currently no support for non-TrueColor visuals");
}
cmap = XCreateColormap(dpy, root, vi->visual, AllocAll);
for (i = 0; i < 256; i++) {
clr[i].pixel = i;
clr[i].flags = DoRed|DoGreen|DoBlue;
}
//XQueryColors(dpy, DefaultColormap(dpy, screen), clr, 256);
//XStoreColors(dpy, cmap, clr, 256);
attr.colormap = cmap;
attr.event_mask = KeyPressMask | KeyReleaseMask | ExposureMask;
attrmask = CWColormap | CWEventMask;
win = XCreateWindow(dpy, root, 0, 0, 320, 200, 0, CopyFromParent,
InputOutput, vi->visual, attrmask, &attr);
if (win == None) {
Quit("Unable to create window!");
}
gcvalues.foreground = BlackPixel(dpy, screen);
gcvalues.background = WhitePixel(dpy, screen);
gc = XCreateGC(dpy, win, GCForeground | GCBackground, &gcvalues);
sizehints.min_width = 320;
sizehints.min_height = 200;
sizehints.max_width = 320;
sizehints.max_height = 200;
sizehints.base_width = 320;
sizehints.base_height = 200;
sizehints.flags = PMinSize | PMaxSize | PBaseSize;
XSetWMProperties(dpy, win, NULL, NULL, argv, argc, &sizehints, None, None);
/* TODO: have some global identifier for each game type */
XStoreName(dpy, win, GAMENAME);
XSetIconName(dpy, win, GAMENAME);
wmDeleteWindow = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
XSetWMProtocols(dpy, win, &wmDeleteWindow, 1);
XFlush(dpy);
return WolfMain(argc, argv);
}
void VL_WaitVBL(int vbls) void VL_WaitVBL(int vbls)
{ {
/* hack - but it works for me */
long last = get_TimeCount() + 1;
while (last > get_TimeCount()) ;
} }
void VW_UpdateScreen() void VW_UpdateScreen()
{ {
XPutImage(dpy, win, gc, img, 0, 0, 0, 0, 320, 200);
} }
/* /*
...@@ -27,10 +133,15 @@ void VW_UpdateScreen() ...@@ -27,10 +133,15 @@ void VW_UpdateScreen()
======================= =======================
*/ */
void VL_Startup (void) void VL_Startup()
{ {
if (gfxbuf == NULL) if (gfxbuf == NULL)
gfxbuf = malloc(320 * 200 * 1); gfxbuf = malloc(320 * 200 * 1);
img = XCreateImage(dpy, vi->visual, 8, ZPixmap, 0, gfxbuf, 320, 200,
8, 320);
XMapWindow(dpy, win);
} }
/* /*
...@@ -88,6 +199,14 @@ void VL_ClearVideo(byte color) ...@@ -88,6 +199,14 @@ void VL_ClearVideo(byte color)
void VL_FillPalette(int red, int green, int blue) void VL_FillPalette(int red, int green, int blue)
{ {
int i; int i;
for (i = 0; i < 256; i++) {
clr[i].red = red << 10;
clr[i].green = green << 10;
clr[i].blue = blue << 10;
}
XStoreColors(dpy, cmap, clr, 256);
} }
//=========================================================================== //===========================================================================
...@@ -102,6 +221,11 @@ void VL_FillPalette(int red, int green, int blue) ...@@ -102,6 +221,11 @@ void VL_FillPalette(int red, int green, int blue)
void VL_SetColor(int color, int red, int green, int blue) void VL_SetColor(int color, int red, int green, int blue)
{ {
clr[color].red = red << 10;
clr[color].green = green << 10;
clr[color].blue = blue << 10;
XStoreColors(dpy, cmap, clr, 256);
} }
//=========================================================================== //===========================================================================
...@@ -116,6 +240,9 @@ void VL_SetColor(int color, int red, int green, int blue) ...@@ -116,6 +240,9 @@ void VL_SetColor(int color, int red, int green, int blue)
void VL_GetColor(int color, int *red, int *green, int *blue) void VL_GetColor(int color, int *red, int *green, int *blue)
{ {
*red = clr[color].red >> 10;
*green = clr[color].green >> 10;
*blue = clr[color].blue >> 10;
} }
//=========================================================================== //===========================================================================
...@@ -130,6 +257,14 @@ void VL_GetColor(int color, int *red, int *green, int *blue) ...@@ -130,6 +257,14 @@ void VL_GetColor(int color, int *red, int *green, int *blue)
void VL_SetPalette(byte *palette) void VL_SetPalette(byte *palette)
{ {
int i;
for (i = 0; i < 256; i++) {
clr[i].red = palette[i*3+0] << 10;
clr[i].green = palette[i*3+1] << 10;
clr[i].blue = palette[i*3+2] << 10;
}
XStoreColors(dpy, cmap, clr, 256);
} }
...@@ -148,9 +283,9 @@ void VL_GetPalette(byte *palette) ...@@ -148,9 +283,9 @@ void VL_GetPalette(byte *palette)
int i, r, g, b; int i, r, g, b;
for (i = 0; i < 256; i++) { for (i = 0; i < 256; i++) {
palette[i*3+0] = r; palette[i*3+0] = clr[i].red >> 10;
palette[i*3+1] = g; palette[i*3+1] = clr[i].green >> 10;
palette[i*3+2] = b; palette[i*3+2] = clr[i].blue >> 10;
} }
} }
...@@ -250,18 +385,6 @@ void VL_FadeIn(int start, int end, byte *palette, int steps) ...@@ -250,18 +385,6 @@ void VL_FadeIn(int start, int end, byte *palette, int steps)
screenfaded = false; screenfaded = false;
} }
/*
==================
=
= VL_ColorBorder
=
==================
*/
void VL_ColorBorder (int color)
{
}
/* /*
============================================================================= =============================================================================
...@@ -384,6 +507,8 @@ void VL_DeModeXize(byte *buf, int width, int height) ...@@ -384,6 +507,8 @@ void VL_DeModeXize(byte *buf, int width, int height)
void VL_DirectPlot(int x1, int y1, int x2, int y2) void VL_DirectPlot(int x1, int y1, int x2, int y2)
{ {
XSetForeground(dpy, gc, *(gfxbuf + x1 + y1 * 320));
XDrawPoint(dpy, win, gc, x2, y2);
} }
/* /*
...@@ -470,13 +595,54 @@ static char *ParmStrings[] = {"nojoys","nomouse",nil}; ...@@ -470,13 +595,54 @@ static char *ParmStrings[] = {"nojoys","nomouse",nil};
// Internal routines // Internal routines
int XKeysymToScancode(unsigned int keysym)
{
switch (keysym) {
case XK_Left:
case XK_KP_Left:
return sc_LeftArrow;
case XK_Right:
case XK_KP_Right:
return sc_RightArrow;
case XK_Up:
case XK_KP_Up:
return sc_UpArrow;
case XK_Down:
case XK_KP_Down:
return sc_DownArrow;
case XK_Control_L:
return sc_Control;
case XK_Alt_L:
return sc_Alt;
case XK_Shift_L:
return sc_LShift;
case XK_Shift_R:
return sc_RShift;
case XK_Escape:
return sc_Escape;
case XK_space:
case XK_KP_Space:
return sc_Space;
case XK_KP_Enter:
case XK_Return:
return sc_Enter;
case XK_y:
return sc_Y;
case XK_n:
return sc_N;
default:
printf("unknown: %s\n", XKeysymToString(keysym));
return sc_None;
}
}
void keyboard_handler(int code, int press) void keyboard_handler(int code, int press)
{ {
static boolean special; static boolean special;
byte k, c, temp; byte k, c, temp;
int i; int i;
/* k = inportb(0x60); // Get the scan code */
k = code; k = code;
if (k == 0xe0) // Special key prefix if (k == 0xe0) // Special key prefix
...@@ -743,7 +909,7 @@ void IN_ReadControl(int player,ControlInfo *info) ...@@ -743,7 +909,7 @@ void IN_ReadControl(int player,ControlInfo *info)
mx = my = motion_None; mx = my = motion_None;
buttons = 0; buttons = 0;
//keyboard_update(); IN_CheckAck();
switch (type = Controls[player]) switch (type = Controls[player])
{ {
...@@ -808,7 +974,6 @@ void IN_ReadControl(int player,ControlInfo *info) ...@@ -808,7 +974,6 @@ void IN_ReadControl(int player,ControlInfo *info)
info->button2 = buttons & (1 << 2); info->button2 = buttons & (1 << 2);
info->button3 = buttons & (1 << 3); info->button3 = buttons & (1 << 3);
info->dir = DirTable[((my + 1) * 3) + (mx + 1)]; info->dir = DirTable[((my + 1) * 3) + (mx + 1)];
} }
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
...@@ -839,20 +1004,35 @@ void IN_StartAck(void) ...@@ -839,20 +1004,35 @@ void IN_StartAck(void)
btnstate[i] = true; btnstate[i] = true;
} }
int flipz; boolean IN_CheckAck()
boolean IN_CheckAck (void)
{ {
unsigned i,buttons; XEvent event;
if (flipz == 1) { unsigned i, buttons;
flipz = 0;
return false; if (XPending(dpy)) {
do {
XNextEvent(dpy, &event);
switch(event.type) {
case KeyPress:
keyboard_handler(XKeysymToScancode(XKeycodeToKeysym(dpy, event.xkey.keycode, 0)), 1);
break;
case KeyRelease:
keyboard_handler(XKeysymToScancode(XKeycodeToKeysym(dpy, event.xkey.keycode, 0)), 0);
break;
case Expose:
VW_UpdateScreen();
break;
case ClientMessage:
if (event.xclient.data.l[0] == wmDeleteWindow)
Quit(NULL);
break;
default:
break;
}
} while (XPending(dpy));
} }
flipz++;
//while (keyboard_update()) ; /* get all events */
if (LastScan) if (LastScan)
return true; return true;
...@@ -872,12 +1052,11 @@ boolean IN_CheckAck (void) ...@@ -872,12 +1052,11 @@ boolean IN_CheckAck (void)
return false; return false;
} }
void IN_Ack (void) void IN_Ack()
{ {
IN_StartAck (); IN_StartAck();
// return; /* TODO: fix when keyboard implemented */ while(!IN_CheckAck()) ;
while (!IN_CheckAck ()) ;
} }
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
...@@ -894,7 +1073,7 @@ boolean IN_UserInput(longword delay) ...@@ -894,7 +1073,7 @@ boolean IN_UserInput(longword delay)
lasttime = get_TimeCount(); lasttime = get_TimeCount();
IN_StartAck (); IN_StartAck();
do { do {
if (IN_CheckAck()) if (IN_CheckAck())
return true; return true;
...@@ -930,8 +1109,3 @@ byte IN_JoyButtons (void) ...@@ -930,8 +1109,3 @@ byte IN_JoyButtons (void)
{ {
return 0; return 0;
} }
int main(int argc, char *argv[])
{
return WolfMain(argc, argv);
}
...@@ -137,7 +137,6 @@ void PicturePause (void) ...@@ -137,7 +137,6 @@ void PicturePause (void)
byte *dest, *src; byte *dest, *src;
memptr buffer; memptr buffer;
VW_ColorBorder (15);
FinishPaletteShifts (); FinishPaletteShifts ();
LastScan = 0; LastScan = 0;
...@@ -145,11 +144,9 @@ void PicturePause (void) ...@@ -145,11 +144,9 @@ void PicturePause (void)
; ;
if (LastScan != sc_Enter) if (LastScan != sc_Enter)
{ {
VW_ColorBorder (0);
return; return;
} }
VW_ColorBorder (1);
// //
// vga stuff... // vga stuff...
// //
...@@ -353,27 +350,11 @@ static char buf[10]; ...@@ -353,27 +350,11 @@ static char buf[10];
================ ================
*/ */
int DebugKeys (void) int DebugKeys()
{ {
boolean esc; boolean esc;
int level,i; int level,i;
if (Keyboard[sc_B]) // B = border color
{
CenterWindow(24,3);
PrintY+=6;
US_Print(" Border color (0-15):");
VW_UpdateScreen();
esc = !US_LineInput (px,py,str,NULL,true,2,0);
if (!esc)
{
level = atoi (str);
if (level>=0 && level<=15)
VW_ColorBorder (level);
}
return 1;
}
if (Keyboard[sc_C]) // C = count objects if (Keyboard[sc_C]) // C = count objects
{ {
CountObjects(); CountObjects();
......
...@@ -1170,7 +1170,7 @@ void Quit(char *error) ...@@ -1170,7 +1170,7 @@ void Quit(char *error)
} }
if (error && *error) { if (error && *error) {
printf("Quit: %s\n", error); fprintf(stderr, "Quit: %s\n", error);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
......
...@@ -1936,12 +1936,12 @@ void EnterCtrlData(int index,CustomCtrls *cust,void (*DrawRtn)(int),void (*Print ...@@ -1936,12 +1936,12 @@ void EnterCtrlData(int index,CustomCtrls *cust,void (*DrawRtn)(int),void (*Print
do do
{ {
int button,result=0; int button,result=0;
IN_CheckAck(); /* force update */
if (type==KEYBOARDBTNS||type==KEYBOARDMOVE) if (type==KEYBOARDBTNS||type==KEYBOARDMOVE)
IN_ClearKeysDown(); IN_ClearKeysDown();
IN_CheckAck(); /* force update */
// //
// FLASH CURSOR // FLASH CURSOR
// //
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment