Commit 82ef4cc1 authored by Steven Fuller's avatar Steven Fuller

Xlib Support. Forgot to return TRUE from SetupScalers (would cause

intermittent failures when going to gamemode).
parent 79356e2e
...@@ -4,8 +4,8 @@ CC = gcc ...@@ -4,8 +4,8 @@ CC = gcc
#CFLAGS = -g -Wall -O6 -fomit-frame-pointer -ffast-math -funroll-loops -mpentiumpro -mcpu=pentiumpro -march=pentiumpro #CFLAGS = -g -Wall -O6 -fomit-frame-pointer -ffast-math -funroll-loops -mpentiumpro -mcpu=pentiumpro -march=pentiumpro
#CFLAGS = -g -Wall #CFLAGS = -g -Wall
#CFLAGS = -g -DNOVGA #CFLAGS = -g -DNOVGA
#CFLAGS = -g CFLAGS = -g
CFLAGS = -Os -g #CFLAGS = -Os -g
#CFLAGS = -g -Wall -I/home/relnev/cvs/oal/include #CFLAGS = -g -Wall -I/home/relnev/cvs/oal/include
OBJS = Data.o Doors.o EnMove.o EnThink.o Intro.o Level.o \ OBJS = Data.o Doors.o EnMove.o EnThink.o Intro.o Level.o \
...@@ -13,15 +13,17 @@ OBJS = Data.o Doors.o EnMove.o EnThink.o Intro.o Level.o \ ...@@ -13,15 +13,17 @@ OBJS = Data.o Doors.o EnMove.o EnThink.o Intro.o Level.o \
RefBsp.o RefSprite.o Refresh.o Refresh2.o Sight.o Main.o \ RefBsp.o RefSprite.o Refresh.o Refresh2.o Sight.o Main.o \
StateDef.o WolfMain.o WolfIO.o InterMis.o Burger.o stub.o res.o StateDef.o WolfMain.o WolfIO.o InterMis.o Burger.o stub.o res.o
SOBJS = $(OBJS) vi_svga.o SOBJS = $(OBJS) vi_svga.o
XOBJS = $(OBJS) XOBJS = $(OBJS) vi_xlib.o
GOBJS = $(OBJS) GOBJS = $(OBJS)
LFLAGS = -lm LFLAGS = -lm
#LFLAGS = -lm -L/home/relnev/cvs/oal/linux/src -lopenal -lpthread -ldl #LFLAGS = -lm -L/home/relnev/cvs/oal/linux/src -lopenal -lpthread -ldl
#LFLAGS = -lm /home/relnev/ElectricFence-2.1/libefence.a
#LFLAGS = -lm /home/relnev/ElectricFence-2.2.2/libefence.a -lpthread #LFLAGS = -lm /home/relnev/ElectricFence-2.2.2/libefence.a -lpthread
SLFLAGS = $(LFLAGS) -lvga SLFLAGS = $(LFLAGS) -lvga
XLFLAGS = $(LFLAGS) -L/usr/X11R6/lib -lX11 -lXext -lXxf86vm -lXxf86dga #XLFLAGS = $(LFLAGS) -L/usr/X11R6/lib -lX11 -lXext -lXxf86vm -lXxf86dga
XLFLAGS = $(LFLAGS) -L/usr/X11R6/lib -lX11
GLFLAGS = $(LFLAGS) -L/usr/X11R6/lib -lX11 -lXext -lGL GLFLAGS = $(LFLAGS) -L/usr/X11R6/lib -lX11 -lXext -lGL
NASM = nasm NASM = nasm
...@@ -29,7 +31,7 @@ NASM = nasm ...@@ -29,7 +31,7 @@ NASM = nasm
.SUFFIXES: .asm .SUFFIXES: .asm
#all: swolf3d xwolf3d gwolf3d #all: swolf3d xwolf3d gwolf3d
all: swolf3d all: swolf3d xwolf3d
$(SOBJS): Sounds.h Sprites.h States.h Wolf.h burger.h wolfdef.h $(SOBJS): Sounds.h Sprites.h States.h Wolf.h burger.h wolfdef.h
$(XOBJS): Sounds.h Sprites.h States.h Wolf.h burger.h wolfdef.h $(XOBJS): Sounds.h Sprites.h States.h Wolf.h burger.h wolfdef.h
......
The README has not been written yet.
...@@ -30,7 +30,7 @@ void RenderWallLoop(Word x1,Word x2,Word distance) ...@@ -30,7 +30,7 @@ void RenderWallLoop(Word x1,Word x2,Word distance)
while (x1 < x2) { /* Time to draw? */ while (x1 < x2) { /* Time to draw? */
scaler = rw_scale >> FRACBITS; /* Get the draw scale */ scaler = rw_scale >> FRACBITS; /* Get the draw scale */
xscale[x1] = scaler; /* Save the scale factor */ xscale[x1] = scaler; /* Save the scale factor */
angle = xtoviewangle[x1]+rw_centerangle; angle = (xtoviewangle[x1]+rw_centerangle)&4095;/* TODO: for some reason i had to add this */
texturecolumn = rw_midpoint - SUFixedMul(finetangent[angle],distance); /* Which texture to use? */ texturecolumn = rw_midpoint - SUFixedMul(finetangent[angle],distance); /* Which texture to use? */
if ((Word)texturecolumn < rw_mintex) { if ((Word)texturecolumn < rw_mintex) {
texturecolumn = rw_mintex; texturecolumn = rw_mintex;
...@@ -47,7 +47,7 @@ void RenderWallLoop(Word x1,Word x2,Word distance) ...@@ -47,7 +47,7 @@ void RenderWallLoop(Word x1,Word x2,Word distance)
while (x1 < x2) { /* Time to draw? */ while (x1 < x2) { /* Time to draw? */
scaler = rw_scale >> FRACBITS; /* Get the draw scale */ scaler = rw_scale >> FRACBITS; /* Get the draw scale */
xscale[x1] = scaler; /* Save the scale factor */ xscale[x1] = scaler; /* Save the scale factor */
angle = xtoviewangle[x1]+rw_centerangle; angle = (xtoviewangle[x1]+rw_centerangle)&4095; /* TODO: same as above */
texturecolumn = SUFixedMul(finetangent[angle],distance)+rw_midpoint; /* Which texture to use? */ texturecolumn = SUFixedMul(finetangent[angle],distance)+rw_midpoint; /* Which texture to use? */
if ((Word)texturecolumn < rw_mintex) { if ((Word)texturecolumn < rw_mintex) {
texturecolumn = rw_mintex; texturecolumn = rw_mintex;
...@@ -322,7 +322,7 @@ void P_DrawSeg (saveseg_t *seg) ...@@ -322,7 +322,7 @@ void P_DrawSeg (saveseg_t *seg)
/* calc center angle for texture mapping*/ /* calc center angle for texture mapping*/
rw_centerangle = (centerangle-normalangle)&FINEMASK; rw_centerangle = (centerangle-normalangle)&FINEMASK;
if (rw_centerangle > FINEANGLES/2) { if (rw_centerangle > (FINEANGLES/2)) {
rw_centerangle -= FINEANGLES; rw_centerangle -= FINEANGLES;
} }
rw_centerangle += FINEANGLES/4; rw_centerangle += FINEANGLES/4;
......
...@@ -15,3 +15,7 @@ to it... ...@@ -15,3 +15,7 @@ to it...
* menu type stuff in svgalib version (would use the Fx keys to save game * menu type stuff in svgalib version (would use the Fx keys to save game
etc, text menus for options?) etc, text menus for options?)
* when saving/loading games, run them through htons/etc. * when saving/loading games, run them through htons/etc.
* added an 'and' hack to lines 33 and 50 in RefBsp.c Not sure if this causes
any problems (value was overflowing finetangent...)
* forget about major svgalib support?
...@@ -285,7 +285,7 @@ void UpdateFace(void) ...@@ -285,7 +285,7 @@ void UpdateFace(void)
**********************************/ **********************************/
void PrepPlayLoop (void) void PrepPlayLoop()
{ {
StartSong(SongListPtr[gamestate.mapon+2]); /* start music */ StartSong(SongListPtr[gamestate.mapon+2]); /* start music */
if (!SetupGameLevel()) { /* Load the game map */ if (!SetupGameLevel()) { /* Load the game map */
...@@ -293,6 +293,7 @@ void PrepPlayLoop (void) ...@@ -293,6 +293,7 @@ void PrepPlayLoop (void)
ReleaseScalers(); /* Release the compiled scalers */ ReleaseScalers(); /* Release the compiled scalers */
PlaySong(0); PlaySong(0);
while (!SetupGameLevel()) { /* Try loading it again */ while (!SetupGameLevel()) { /* Try loading it again */
printf("SetGameLevel returned 0...\n");
Again: Again:
ReleaseMap(); /* Oh oh... */ ReleaseMap(); /* Oh oh... */
if (!GameViewSize) { /* Smallest screen? */ if (!GameViewSize) { /* Smallest screen? */
...@@ -303,6 +304,7 @@ Again: ...@@ -303,6 +304,7 @@ Again:
} }
} }
if (!StartupRendering(GameViewSize)) { if (!StartupRendering(GameViewSize)) {
printf("StartupRendering returned 0...\n");
ReleaseScalers(); ReleaseScalers();
goto Again; goto Again;
} }
......
...@@ -23,6 +23,186 @@ unsigned long lMSB(unsigned long x) ...@@ -23,6 +23,186 @@ unsigned long lMSB(unsigned long x)
return x1 | x2 | x3 | x4; return x1 | x2 | x3 | x4;
} }
void FixMapList(maplist_t *m)
{
int i;
m->MaxMap = sMSB(m->MaxMap);
m->MapRezNum = sMSB(m->MapRezNum);
for (i = 0; i < m->MaxMap; i++) {
m->InfoArray[i].NextLevel = sMSB(m->InfoArray[i].NextLevel);
m->InfoArray[i].SecretLevel = sMSB(m->InfoArray[i].SecretLevel);
m->InfoArray[i].ParTime = sMSB(m->InfoArray[i].ParTime);
m->InfoArray[i].ScenarioNum = sMSB(m->InfoArray[i].ScenarioNum);
m->InfoArray[i].FloorNum = sMSB(m->InfoArray[i].FloorNum);
}
}
void InitData()
{
/*
InitSoundMusicSystem(8,8,5, 11025);
SoundListPtr = (Word *) LoadAResource(MySoundList);
RegisterSounds(SoundListPtr,FALSE);
ReleaseAResource(MySoundList);
*/
GetTableMemory();
MapListPtr = (maplist_t *) LoadAResource(rMapList);
FixMapList(MapListPtr);
SongListPtr = (unsigned short *) LoadAResource(rSongList);
WallListPtr = (unsigned short *) LoadAResource(MyWallList);
}
extern int VidSize;
Word ScaleX(Word x)
{
switch(VidSize) {
case 1:
return x*8/5;
case 2:
case 3:
return x*2;
}
return x;
}
Word ScaleY(Word y)
{
switch(VidSize) {
case 1:
y = (y*8/5)+64;
if (y == 217)
y++;
return y;
case 2:
return y*2;
case 3:
return y*2+80;
}
return y;
}
void ScaledDraw(Byte *gfx, Word scale, Byte *vid, LongWord TheFrac, Word TheInt, Word Width, LongWord Delta)
{
LongWord OldDelta;
while (scale--) {
*vid = *gfx;
vid += Width;
OldDelta = Delta;
Delta += TheFrac;
gfx += TheInt;
if (OldDelta > Delta)
gfx += 1;
}
}
void IO_ScaleWallColumn(Word x, Word scale, Word tile, Word column)
{
LongWord TheFrac;
Word TheInt;
LongWord y;
Byte *ArtStart;
if (scale) {
scale*=2;
TheFrac = 0x80000000UL / scale;
ArtStart = &ArtData[tile][column<<7];
if (scale<VIEWHEIGHT) {
y = (VIEWHEIGHT-scale)/2;
TheInt = TheFrac>>24;
TheFrac <<= 8;
ScaledDraw(ArtStart,scale,&VideoPointer[(y*VideoWidth)+x],
TheFrac,TheInt,VideoWidth, 0);
return;
}
y = (scale-VIEWHEIGHT)/2;
y *= TheFrac;
TheInt = TheFrac>>24;
TheFrac <<= 8;
ScaledDraw(&ArtStart[y>>24],VIEWHEIGHT,&VideoPointer[x],
TheFrac,TheInt,VideoWidth,y<<8);
}
}
typedef struct {
SWord Topy;
SWord Boty;
SWord Shape;
} PACKED SpriteRun;
void IO_ScaleMaskedColumn(Word x,Word scale, unsigned short *CharPtr,Word column)
{
Byte * CharPtr2;
int Y1,Y2;
Byte *Screenad;
SpriteRun *RunPtr;
LongWord TheFrac;
LongWord TFrac;
LongWord TInt;
Word RunCount;
int TopY;
Word Index;
LongWord Delta;
if (!scale)
return;
CharPtr2 = (Byte *) CharPtr;
TheFrac = 0x40000000/scale;
RunPtr = (SpriteRun *)&CharPtr[sMSB(CharPtr[column+1])/2];
Screenad = &VideoPointer[x];
TFrac = TheFrac<<8;
TInt = TheFrac>>24;
TopY = (VIEWHEIGHT/2)-scale;
while (RunPtr->Topy != 0xFFFF) {
Y1 = scale*(LongWord)sMSB(RunPtr->Topy)/128+TopY;
if (Y1 < VIEWHEIGHT) {
Y2 = scale*(LongWord)sMSB(RunPtr->Boty)/128+TopY;
if (Y2 > 0) {
if (Y2 > VIEWHEIGHT)
Y2 = VIEWHEIGHT;
Index = sMSB(RunPtr->Shape)+sMSB(RunPtr->Topy)/2;
Delta = 0;
if (Y1 < 0) {
Delta = (0-(LongWord)Y1)*TheFrac;
Index += (Delta>>24);
Delta <<= 8;
Y1 = 0;
}
RunCount = Y2-Y1;
if (RunCount)
ScaledDraw(&CharPtr2[Index],RunCount,
&Screenad[Y1*VideoWidth],TFrac,TInt,VideoWidth, Delta);
}
}
RunPtr++;
}
}
Boolean SetupScalers()
{
return TRUE;
}
void ReleaseScalers()
{
}
Byte *SmallFontPtr; Byte *SmallFontPtr;
void MakeSmallFont(void) void MakeSmallFont(void)
...@@ -244,19 +424,6 @@ void EndAllSound(void) ...@@ -244,19 +424,6 @@ void EndAllSound(void)
{ {
} }
void PurgeAllSounds(unsigned long minMemory)
{
}
Word ChooseGameDiff(void)
{
/* 0 = easy, 1 = normal, 2 = hard, 3 = death incarnate */
difficulty = 1;
SetAPalette(rGamePal);
return 1;
}
void FinishLoadGame(void) void FinishLoadGame(void)
{ {
} }
...@@ -10,21 +10,7 @@ Byte *gfxbuf; ...@@ -10,21 +10,7 @@ Byte *gfxbuf;
void keyboard_handler(int key, int press); void keyboard_handler(int key, int press);
void FixMapList(maplist_t *m)
{
int i;
m->MaxMap = sMSB(m->MaxMap);
m->MapRezNum = sMSB(m->MapRezNum);
for (i = 0; i < m->MaxMap; i++) {
m->InfoArray[i].NextLevel = sMSB(m->InfoArray[i].NextLevel);
m->InfoArray[i].SecretLevel = sMSB(m->InfoArray[i].SecretLevel);
m->InfoArray[i].ParTime = sMSB(m->InfoArray[i].ParTime);
m->InfoArray[i].ScenarioNum = sMSB(m->InfoArray[i].ScenarioNum);
m->InfoArray[i].FloorNum = sMSB(m->InfoArray[i].FloorNum);
}
}
int main(int argc, char *argv[]) int main(int argc, char *argv[])
{ {
...@@ -40,20 +26,7 @@ int main(int argc, char *argv[]) ...@@ -40,20 +26,7 @@ int main(int argc, char *argv[])
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
/* InitData();
InitSoundMusicSystem(8,8,5, 11025);
SoundListPtr = (Word *) LoadAResource(MySoundList);
RegisterSounds(SoundListPtr,FALSE);
ReleaseAResource(MySoundList);
*/
GetTableMemory();
MapListPtr = (maplist_t *) LoadAResource(rMapList);
FixMapList(MapListPtr);
SongListPtr = (unsigned short *) LoadAResource(rSongList);
WallListPtr = (unsigned short *) LoadAResource(MyWallList);
NewGameWindow(0); /* 320x200 */ NewGameWindow(0); /* 320x200 */
//#ifndef NOVGA //#ifndef NOVGA
...@@ -71,6 +44,11 @@ void Quit(char *str) ...@@ -71,6 +44,11 @@ void Quit(char *str)
keyboard_close(); keyboard_close();
vga_setmode(TEXT); vga_setmode(TEXT);
FreeResources();
if (gfxbuf)
free(gfxbuf);
if (str && *str) { if (str && *str) {
fprintf(stderr, "%s\n", str); fprintf(stderr, "%s\n", str);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
...@@ -124,33 +102,6 @@ Word VidPics[] = {rFaceShapes,rFace512,rFace640,rFace640}; ...@@ -124,33 +102,6 @@ Word VidPics[] = {rFaceShapes,rFace512,rFace640,rFace640};
Word VidSize = -1; Word VidSize = -1;
int VidModes[] = { G320x200x256, G512x384x256, G640x400x256, G640x480x256 }; int VidModes[] = { G320x200x256, G512x384x256, G640x400x256, G640x480x256 };
Word ScaleX(Word x)
{
switch(VidSize) {
case 1:
return x*8/5;
case 2:
case 3:
return x*2;
}
return x;
}
Word ScaleY(Word y)
{
switch(VidSize) {
case 1:
y = (y*8/5)+64;
if (y == 217)
y++;
return y;
case 2:
return y*2;
case 3:
return y*2+80;
}
return y;
}
Word NewGameWindow(Word NewVidSize) Word NewGameWindow(Word NewVidSize)
{ {
...@@ -216,120 +167,6 @@ Word NewGameWindow(Word NewVidSize) ...@@ -216,120 +167,6 @@ Word NewGameWindow(Word NewVidSize)
return VidSize; return VidSize;
} }
void ScaledDraw(Byte *gfx, Word scale, Byte *vid, LongWord TheFrac, Word TheInt, Word Width, LongWord Delta)
{
LongWord OldDelta;
while (scale--) {
*vid = *gfx;
vid += Width;
OldDelta = Delta;
Delta += TheFrac;
gfx += TheInt;
if (OldDelta > Delta)
gfx += 1;
}
}
void IO_ScaleWallColumn(Word x, Word scale, Word tile, Word column)
{
LongWord TheFrac;
Word TheInt;
LongWord y;
Byte *ArtStart;
if (scale) {
scale*=2;
TheFrac = 0x80000000UL / scale;
ArtStart = &ArtData[tile][column<<7];
if (scale<VIEWHEIGHT) {
y = (VIEWHEIGHT-scale)/2;
TheInt = TheFrac>>24;
TheFrac <<= 8;
ScaledDraw(ArtStart,scale,&VideoPointer[(y*VideoWidth)+x],
TheFrac,TheInt,VideoWidth, 0);
return;
}
y = (scale-VIEWHEIGHT)/2;
y *= TheFrac;
TheInt = TheFrac>>24;
TheFrac <<= 8;
ScaledDraw(&ArtStart[y>>24],VIEWHEIGHT,&VideoPointer[x],
TheFrac,TheInt,VideoWidth,y<<8);
}
}
typedef struct {
SWord Topy;
SWord Boty;
SWord Shape;
} PACKED SpriteRun;
void IO_ScaleMaskedColumn(Word x,Word scale, unsigned short *CharPtr,Word column)
{
Byte * CharPtr2;
int Y1,Y2;
Byte *Screenad;
SpriteRun *RunPtr;
LongWord TheFrac;
LongWord TFrac;
LongWord TInt;
Word RunCount;
int TopY;
Word Index;
LongWord Delta;
if (!scale)
return;
CharPtr2 = (Byte *) CharPtr;
TheFrac = 0x40000000/scale;
RunPtr = (SpriteRun *)&CharPtr[sMSB(CharPtr[column+1])/2];
Screenad = &VideoPointer[x];
TFrac = TheFrac<<8;
TInt = TheFrac>>24;
TopY = (VIEWHEIGHT/2)-scale;
while (RunPtr->Topy != 0xFFFF) {
Y1 = scale*(LongWord)sMSB(RunPtr->Topy)/128+TopY;
if (Y1 < VIEWHEIGHT) {
Y2 = scale*(LongWord)sMSB(RunPtr->Boty)/128+TopY;
if (Y2 > 0) {
if (Y2 > VIEWHEIGHT)
Y2 = VIEWHEIGHT;
Index = sMSB(RunPtr->Shape)+sMSB(RunPtr->Topy)/2;
Delta = 0;
if (Y1 < 0) {
Delta = (0-(LongWord)Y1)*TheFrac;
Index += (Delta>>24);
Delta <<= 8;
Y1 = 0;
}
RunCount = Y2-Y1;
if (RunCount)
ScaledDraw(&CharPtr2[Index],RunCount,
&Screenad[Y1*VideoWidth],TFrac,TInt,VideoWidth, Delta);
}
}
RunPtr++;
}
}
Boolean SetupScalers()
{
}
void ReleaseScalers()
{
}
/* Keyboard Hack */ /* Keyboard Hack */
static int RSJ; static int RSJ;
...@@ -532,3 +369,13 @@ int DoEvents() ...@@ -532,3 +369,13 @@ int DoEvents()
} }
return 0; return 0;
} }
Word ChooseGameDiff(void)
{
/* 0 = easy, 1 = normal, 2 = hard, 3 = death incarnate */
difficulty = 3;
SetAPalette(rGamePal);
return 1;
}
\ No newline at end of file
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <X11/Xlib.h>
#include <X11/Xutil.h>
#include <X11/keysym.h>
#include "wolfdef.h"
Display *dpy;
int screen;
Window win, root;
XVisualInfo *vi;
GC gc;
XImage *img;
Colormap cmap;
Atom wmDeleteWindow;
XColor clr[256];
Byte *gfxbuf;
int main(int argc, char *argv[])
{
XSetWindowAttributes attr;
XVisualInfo vitemp;
XGCValues gcvalues;
Pixmap bitmap;
Cursor cursor;
XColor bg = { 0 };
XColor fg = { 0 };
char data[8] = { 0x01 };
char *display;
int mask, i;
if (argc != 2) {
fprintf(stderr, "usage: %s <mac wolf3d resource fork>\n", argv[0]);
exit(EXIT_FAILURE);
}
if (InitResources(argv[1])) {
fprintf(stderr, "could not load %s\n", argv[1]);
exit(EXIT_FAILURE);
}
display = getenv("DISPLAY");
dpy = XOpenDisplay(getenv(display));
if (dpy == NULL) {
fprintf(stderr, "Unable to open display %s\n", XDisplayName(display));
exit(EXIT_FAILURE);
}
screen = DefaultScreen(dpy);
root = RootWindow(dpy, screen);
vitemp.screen = screen;
vitemp.depth = 8;
vitemp.class = PseudoColor;
mask = VisualScreenMask | VisualDepthMask | VisualClassMask;
vi = XGetVisualInfo(dpy, mask, &vitemp, &i);
if ( !(vi && i) ) {
fprintf(stderr, "Unable to get a depth 8 PseudoColor visual on screen %d\n", screen);
exit(EXIT_FAILURE);
}
cmap = XCreateColormap(dpy, root, vi->visual, AllocAll);
for (i = 0; i < 256; i++) {
clr[i].pixel = i;
clr[i].flags = DoRed | DoGreen | DoBlue;
}
attr.colormap = cmap;
attr.event_mask = KeyPressMask | KeyReleaseMask | ExposureMask;
mask = CWColormap | CWEventMask;
win = XCreateWindow(dpy, root, 0, 0, 320, 200, 0, CopyFromParent,
InputOutput, vi->visual, mask, &attr);
if (win == None) {
fprintf(stderr, "Unable to create window\n");
exit(EXIT_FAILURE);
}
gcvalues.foreground = BlackPixel(dpy, screen);
gcvalues.background = WhitePixel(dpy, screen);
mask = GCForeground | GCBackground;
gc = XCreateGC(dpy, win, mask, &gcvalues);
XSetWMProperties(dpy, win, NULL, NULL, argv, argc, None, None, None);
XStoreName(dpy, win, "Wolfenstein 3D");
XSetIconName(dpy, win, "Wolfenstein 3D");
wmDeleteWindow = XInternAtom(dpy, "WM_DELETE_WINDOW", False);
XSetWMProtocols(dpy, win, &wmDeleteWindow, 1);
bitmap = XCreateBitmapFromData(dpy, win, data, 8, 8);
cursor = XCreatePixmapCursor(dpy, bitmap, bitmap, &fg, &bg, 0, 0);
XDefineCursor(dpy, win, cursor);
XMapWindow(dpy, win);
XFlush(dpy);
InitData();
GameViewSize = 2;
NewGameWindow(GameViewSize);
ClearTheScreen(BLACK);
BlastScreen();
return WolfMain(argc, argv);
}
void Quit(char *str)
{
FreeResources();
if (gfxbuf)
free(gfxbuf);
if (str && *str) {
fprintf(stderr, "%s\n", str);
exit(EXIT_FAILURE);
}
exit(EXIT_SUCCESS);
}
void SetPalette(Byte *pal)
{
int i;
for (i = 0; i < 256; i++) {
clr[i].red = pal[i*3+0] << 8;
clr[i].green = pal[i*3+1] << 8;
clr[i].blue = pal[i*3+2] << 8;
}
XStoreColors(dpy, cmap, clr, 256);
}
void BlastScreen2(Rect *BlastRect)
{
BlastScreen();
}
int VidWidth, VidHeight, ViewHeight;
#define w VidWidth
#define h VidHeight
#define v ViewHeight
void BlastScreen()
{
XPutImage(dpy, win, gc, img, 0, 0, 0, 0, w, h);
}
Word VidXs[] = {320,512,640,640}; /* Screen sizes to play with */
Word VidYs[] = {200,384,400,480};
Word VidVs[] = {160,320,320,400};
Word VidPics[] = {rFaceShapes,rFace512,rFace640,rFace640};
Word VidSize = -1;
Word NewGameWindow(Word NewVidSize)
{
XSizeHints sizehints;
LongWord *LongPtr;
Byte *DestPtr;
int i;
printf("Called: %d\n", NewVidSize);
if (NewVidSize == VidSize)
return VidSize;
printf("Setting Size: %d (from %d)\n", NewVidSize, VidSize);
if (NewVidSize < 4) {
w = VidXs[NewVidSize];
h = VidYs[NewVidSize];
v = VidVs[NewVidSize];
} else {
fprintf(stderr, "Invalid Vid size: %d\n", NewVidSize);
exit(EXIT_FAILURE);
}
if (gfxbuf) {
XDestroyImage(img);
/* free(gfxbuf); */
}
sizehints.min_width = sizehints.max_width = sizehints.base_width = w;
sizehints.min_height = sizehints.max_height = sizehints.base_height = h;
sizehints.flags = PMinSize | PMaxSize | PBaseSize;
XSetWMNormalHints(dpy, win, &sizehints);
XResizeWindow(dpy, win, w, h);
gfxbuf = (Byte *)malloc(w * h);
img = XCreateImage(dpy, vi->visual, vi->depth, ZPixmap, 0,
(char *)gfxbuf, w, h, 8, w);
if (img == NULL) {
fprintf(stderr, "XCreateImage returned NULL, Unable to create an XImage\n");
exit(EXIT_FAILURE);
}
VideoPointer = gfxbuf;
VideoWidth = w;
InitYTable();
SetAPalette(rBlackPal);
ClearTheScreen(BLACK);
BlastScreen();
LongPtr = (LongWord *) LoadAResource(VidPics[NewVidSize]);
if (GameShapes)
FreeSomeMem(GameShapes);
GameShapes = (Byte **)AllocSomeMem(lMSB(LongPtr[0]));
DLZSS((Byte *)GameShapes, (Byte *)&LongPtr[1], lMSB(LongPtr[0]));
ReleaseAResource(VidPics[NewVidSize]);
LongPtr = (LongWord *)GameShapes;
DestPtr = (Byte *)GameShapes;
for (i = 0; i < ((NewVidSize == 1) ? 57 : 47); i++)
GameShapes[i] = DestPtr + lMSB(LongPtr[i]);
VidSize = NewVidSize;
return VidSize;
}
/* Keyboard Hack */
static int RSJ;
static int keys[128];
void FlushKeys()
{
joystick1 = 0;
memset(keys, 0, sizeof(keys));
}
struct {
char code[13];
} CheatCodes[] = {
{ "XUSCNIELPPA" }, /* "XUSCNIELPPA" */
{ "IDDQD" }, /* "IDDQD" */
{ "BURGER" }, /* "BURGER" */
{ "WOWZERS" }, /* "WOWZERS" */
{ "LEDOUX" }, /* "LEDOUX" */
{ "SEGER" }, /* "SEGER" */
{ "MCCALL" }, /* "MCCALL" */
{ "APPLEIIGS" } /* "APPLEIIGS" */
};
const int CheatCount = sizeof(CheatCodes) / sizeof(CheatCodes[0]);
int CheatIndex;
#define SC_CURSORUPLEFT 1
#define SC_CURSORUP 2
#define SC_CURSORUPRIGHT 3
#define SC_CURSORRIGHT 4
#define SC_CURSORDOWNRIGHT 5
#define SC_CURSORDOWN 6
#define SC_CURSORDOWNLEFT 7
#define SC_CURSORLEFT 8
#define SC_CURSORBLOCKLEFT 9
#define SC_CURSORBLOCKRIGHT 10
#define SC_CURSORBLOCKUP 11
#define SC_CURSORBLOCKDOWN 12
#define SC_KEYPADENTER 13
#define SC_ENTER 14
#define SC_SPACE 15
#define SC_LEFTALT 16
#define SC_RIGHTALT 17
#define SC_LEFTCONTROL 18
#define SC_RIGHTCONTROL 19
#define SC_LEFTSHIFT 20
#define SC_RIGHTSHIFT 21
#define SC_B 22
void UpdateKeys(KeySym key, int press)
{
switch(key) {
case XK_KP_Home:
keys[SC_CURSORUPLEFT] = press;
break;
case XK_KP_Up:
keys[SC_CURSORUP] = press;
break;
case XK_KP_Page_Up:
keys[SC_CURSORUPRIGHT] = press;
break;
case XK_KP_Right:
keys[SC_CURSORRIGHT] = press;
break;
case XK_KP_Page_Down:
keys[SC_CURSORDOWNRIGHT] = press;
break;
case XK_KP_Down:
keys[SC_CURSORDOWN] = press;
break;
case XK_KP_End:
keys[SC_CURSORDOWNLEFT] = press;
break;
case XK_KP_Left:
keys[SC_CURSORLEFT] = press;
break;
case XK_Up:
keys[SC_CURSORBLOCKUP] = press;
break;
case XK_Down:
keys[SC_CURSORBLOCKDOWN] = press;
break;
case XK_Left:
keys[SC_CURSORBLOCKLEFT] = press;
break;
case XK_Right:
keys[SC_CURSORBLOCKRIGHT] = press;
break;
case XK_KP_Enter:
keys[SC_KEYPADENTER] = press;
break;
case XK_Return:
keys[SC_ENTER] = press;
break;
case XK_space:
keys[SC_SPACE] = press;
break;
case XK_Alt_L:
keys[SC_LEFTALT] = press;
break;
case XK_Alt_R:
keys[SC_RIGHTALT] = press;
break;
case XK_Control_L:
keys[SC_LEFTCONTROL] = press;
break;
case XK_Control_R:
keys[SC_RIGHTCONTROL] = press;
break;
case XK_Shift_L:
keys[SC_LEFTSHIFT] = press;
break;
case XK_Shift_R:
keys[SC_RIGHTSHIFT] = press;
break;
case XK_b:
keys[SC_B] = press;
break;
}
}
void keyboard_handler(KeySym keycode, int press)
{
int i;
UpdateKeys(keycode, press);
if (RSJ) {
if (press == 0) {
for (i = 0; i < CheatCount; i++) {
char *key = XKeysymToString(keycode);
if (key == NULL)
break;
if (strlen(key) != 1)
break;
if (CheatCodes[i].code[CheatIndex] == toupper(key[0])) {
CheatIndex++;
if (CheatCodes[i].code[CheatIndex] == 0) {
PlaySound(SND_BONUS);
switch (i) {
case 0:
case 4:
GiveKey(0);
GiveKey(1);
gamestate.godmode = TRUE;
break;
case 1:
gamestate.godmode^=TRUE;
break;
case 2:
gamestate.machinegun = TRUE;
gamestate.chaingun = TRUE;
gamestate.flamethrower = TRUE;
gamestate.missile = TRUE;
GiveAmmo(gamestate.maxammo);
GiveGas(99);
GiveMissile(99);
break;
case 3:
gamestate.maxammo = 999;
GiveAmmo(999);
break;
case 5:
GiveKey(0);
GiveKey(1);
break;
case 6:
playstate=EX_WARPED;
nextmap = gamestate.mapon+1;
if (MapListPtr->MaxMap<=nextmap)
nextmap = 0;
break;
case 7:
ShowPush ^= TRUE;
break;
}
CheatIndex = 0;
}
break;
}
}
if (i == CheatCount)
CheatIndex = 0;
}
joystick1 = 0;
if (press == 0) {
switch(keycode) {
case XK_1:
gamestate.pendingweapon = WP_KNIFE;
break;
case XK_2:
if (gamestate.ammo) {
gamestate.pendingweapon = WP_PISTOL;
}
break;
case XK_3:
if (gamestate.ammo && gamestate.machinegun) {
gamestate.pendingweapon = WP_MACHINEGUN;
}
break;
case XK_4:
if (gamestate.ammo && gamestate.chaingun) {
gamestate.pendingweapon = WP_CHAINGUN;
}
break;
case XK_5:
if (gamestate.gas && gamestate.flamethrower) {
gamestate.pendingweapon = WP_FLAMETHROWER;
}
break;
case XK_6:
if (gamestate.missiles && gamestate.missile) {
gamestate.pendingweapon = WP_MISSILE;
}
break;
case XK_period:
case XK_slash:
joystick1 = JOYPAD_START;
break;
case XK_Escape:
Quit(NULL); /* fast way out */
}
}
if (keys[SC_CURSORUPLEFT])
joystick1 |= (JOYPAD_UP|JOYPAD_LFT);
if (keys[SC_CURSORUP])
joystick1 |= JOYPAD_UP;
if (keys[SC_CURSORUPRIGHT])
joystick1 |= (JOYPAD_UP|JOYPAD_RGT);
if (keys[SC_CURSORRIGHT])
joystick1 |= JOYPAD_RGT;
if (keys[SC_CURSORDOWNRIGHT])
joystick1 |= (JOYPAD_DN|JOYPAD_RGT);
if (keys[SC_CURSORDOWN])
joystick1 |= JOYPAD_DN;
if (keys[SC_CURSORDOWNLEFT])
joystick1 |= (JOYPAD_DN|JOYPAD_LFT);
if (keys[SC_CURSORLEFT])
joystick1 |= JOYPAD_LFT;
if (keys[SC_CURSORBLOCKLEFT])
joystick1 |= JOYPAD_LFT;
if (keys[SC_CURSORBLOCKRIGHT])
joystick1 |= JOYPAD_RGT;
if (keys[SC_CURSORBLOCKUP])
joystick1 |= JOYPAD_UP;
if (keys[SC_CURSORBLOCKDOWN])
joystick1 |= JOYPAD_DN;
if (keys[SC_KEYPADENTER])
joystick1 |= JOYPAD_A;
if (keys[SC_ENTER])
joystick1 |= JOYPAD_A;
if (keys[SC_SPACE])
joystick1 |= JOYPAD_A;
if (keys[SC_LEFTALT])
joystick1 |= JOYPAD_TL;
if (keys[SC_RIGHTALT])
joystick1 |= JOYPAD_TR;
if (keys[SC_LEFTCONTROL])
joystick1 |= JOYPAD_B;
if (keys[SC_RIGHTCONTROL])
joystick1 |= JOYPAD_B;
if (keys[SC_LEFTSHIFT])
joystick1 |= (JOYPAD_X|JOYPAD_Y);
if (keys[SC_RIGHTSHIFT])
joystick1 |= (JOYPAD_X|JOYPAD_Y);
}
}
int HandleEvents()
{
XEvent event;
int ret = 0;
if (XPending(dpy)) {
do {
XNextEvent(dpy, &event);
switch(event.type) {
case KeyPress:
keyboard_handler(XKeycodeToKeysym(dpy, event.xkey.keycode, 0), 1);
/* ret = 1; */
break;
case KeyRelease:
keyboard_handler(XKeycodeToKeysym(dpy, event.xkey.keycode, 0), 0);
ret = 1;
break;
case Expose:
BlastScreen();
break;
case ClientMessage:
if (event.xclient.data.l[0] == wmDeleteWindow)
Quit(NULL);
break;
default:
break;
}
} while (XPending(dpy));
}
return ret;
}
void ReadSystemJoystick()
{
RSJ = 1;
HandleEvents();
}
int DoEvents()
{
RSJ = 0;
if (HandleEvents()) {
if (keys[SC_B]) { /* Special */
return 'B';
}
return 1;
}
return 0;
}
Word ChooseGameDiff()
{
/* 0 = easy, 1 = normal, 2 = hard, 3 = death incarnate */
difficulty = 1;
SetAPalette(rGamePal);
return 1;
}
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