Commit 6fe38b42 authored by Steven Fuller's avatar Steven Fuller

Few more minor code reformats.

Removed OpenAL/OpenGL code for now.  Want to concentrate more on improving
the current code before adding extra features.
parent 0ce3e007
......@@ -13,7 +13,8 @@
* Fully compile with no warnings/errors using -Wall -ansi -pedantic and with
other compilers (would need to turn off warnings about unused parameters)
* Port to: Linux/SVGAlib, Linux/X (Windowed and DGA), Linux/OpenGL,
DOS/Allegro, Win32/GDI?, Win32/DX, Win32/D3D, Win32/OpenGL, BeOS?, MacOS?
DOS/Allegro, Win32/GDI?, Win32/DX, Win32/D3D, Win32/OpenGL, BeOS?, MacOS?,
QNX?
* Ease in using demos. Playing demos from files, recording to files, batch
playing, and so on.
* Make Wolf3D the game it was originally planned to be... More strategy...
......@@ -21,12 +22,10 @@
regardless of future plans [IDEAS]) and no TODO/FIXME/XXXs in the source
code
* Have some sort of way of playing both digital and adlib sounds on all
platforms (if possible)
platforms [fmopl.c] (if possible)
* Test with other available mods (that were compatible with the original
game)
* Unified input handling
* Configuration files and save games which work regardless of operating
system/processor/binary build
* Suite of utilities to edit the game data.
* Building on previous idea, have some way to break out of requiring the
game to be recompiled for each game dataset
......@@ -5,34 +5,28 @@ CC = gcc
CFLAGS = -g -Wall
#CFLAGS = -Os -Wall
#CFLAGS = -Os -Wall -fomit-frame-pointer -ffast-math -mpentiumpro -mcpu=pentiumpro -march=pentiumpro
#CFLAGS = -g -Wall -I/home/relnev/cvs/oal/include
OBJS = objs.o misc.o id_ca.o id_vh.o id_us.o \
wl_act1.o wl_act2.o wl_agent.o wl_game.o \
wl_inter.o wl_menu.o wl_play.o wl_state.o wl_text.o wl_main.o \
wl_debug.o gfxsave.o sd_null.o # sd_oal.o # sd_null.o
wl_debug.o gfxsave.o sd_null.o
ROBJS = wl_draw.o wl_scale.o
SOBJS = $(OBJS) $(ROBJS) vi_svga.o
XOBJS = $(OBJS) $(ROBJS) vi_xlib.o
#GOBJS = $(OBJS) vi_ogl.o vi_glx.o
LFLAGS = -lm
#LFLAGS = -lm /home/relnev/cvs/oal/linux/src/libopenal.a -lpthread -ldl
SLFLAGS = $(LFLAGS) -lvga
XLFLAGS = $(LFLAGS) -L/usr/X11R6/lib -lX11 -lXext -lXxf86vm -lXxf86dga
#GLFLAGS = $(LFLAGS) -L/usr/X11R6/lib -lX11 -lXext -lGL
NASM = nasm
.SUFFIXES: .asm
#all: swolf3d xwolf3d gwolf3d
all: swolf3d xwolf3d
$(SOBJS): version.h id_heads.h wl_def.h
$(XOBJS): version.h id_heads.h wl_def.h
$(GOBJS): version.h id_heads.h wl_def.h
.asm.o:
$(NASM) -f elf -o $@ $<
......@@ -43,11 +37,8 @@ swolf3d: $(SOBJS)
xwolf3d: $(XOBJS)
gcc -o xwolf3d $(XOBJS) $(XLFLAGS)
gwolf3d: $(GOBJS)
gcc -o gwolf3d $(GOBJS) $(GLFLAGS)
clean:
rm -rf swolf3d xwolf3d gwolf3d *.o
rm -rf swolf3d xwolf3d *.o
distclean: clean
rm -rf *~ DEADJOE
......
/* id_sd.c */
#include "id_heads.h"
#include <AL/al.h>
#include <AL/alc.h>
#error "This code is out of date/broken"
// Global variables
boolean SoundSourcePresent,
AdLibPresent,
SoundBlasterPresent,
SoundPositioned;
SDMode SoundMode;
SMMode MusicMode;
SDSMode DigiMode;
int DigiMap[LASTSOUND];
// Internal variables
static boolean SD_Started;
boolean nextsoundpos;
int LeftPosition,RightPosition;
word NumDigi;
word *DigiList;
boolean DigiPlaying;
boolean sqActive;
/* ------------------------------------------------------------------------ */
ALuint *sources;
ALuint *buffers;
void *cc;
void SD_Poll(void)
{
}
void SD_SetDigiDevice(SDSMode mode)
{
}
///////////////////////////////////////////////////////////////////////////
//
// SD_SetSoundMode() - Sets which sound hardware to use for sound effects
//
///////////////////////////////////////////////////////////////////////////
boolean SD_SetSoundMode(SDMode mode)
{
return false;
}
///////////////////////////////////////////////////////////////////////////
//
// SD_SetMusicMode() - sets the device to use for background music
//
///////////////////////////////////////////////////////////////////////////
boolean SD_SetMusicMode(SMMode mode)
{
return false;
}
///////////////////////////////////////////////////////////////////////////
//
// SD_Startup() - starts up the Sound Mgr
//
///////////////////////////////////////////////////////////////////////////
void SD_Startup(void)
{
int i;
if (SD_Started)
return;
for (i = 0; i < LASTSOUND; i++)
DigiMap[i] = -1;
cc = alcCreateContext(NULL);
if (cc == NULL)
printf("alcCreateContext failed..\n");
else {
word *SoundList = PM_GetPage(ChunksInFile - 1);
PageListStruct *page = &PMPages[ChunksInFile - 1];
int p = page->length;
int x = 0, w, y, z;
for (i = 0; i < p / 2; i += 2) {
w = *(SoundList + i);
y = *(SoundList + i+1);
page = &PMPages[w + PMSoundStart];
if (page->length == 0) {
x++; // count it?
continue;
}
for (z = 0; z < y; w++, z++) {
page = &PMPages[w + PMSoundStart];
z += page->length;
}
x++;
}
buffers = (ALuint *)malloc(sizeof(ALuint) * x);
//if (alGenBuffers(x, buffers) != x)
// printf("OpenAL buffer allocation problem\n");
alGenBuffers(x, buffers);
x = 0;
for (i = 0; i < p / 2; i += 2) {
byte *dat;
w = *(SoundList + i);
y = *(SoundList + i+1);
page = &PMPages[w + PMSoundStart];
if (page->length == 0) {
x++; // count it?
continue;
}
if (y == 0){
printf("wtf?\n");
continue;
}
dat = (byte *)malloc(y);
for (z = 0; z < y; w++) {
page = &PMPages[w + PMSoundStart];
memcpy(dat+z, PM_GetPage(w + PMSoundStart), page->length);
z += page->length;
}
alBufferData(buffers[x], AL_FORMAT_MONO8, dat, y, 6896);
if(alGetError() != AL_NO_ERROR) {
printf("AL error\n");
}
free(dat);
x++;
}
sources = (ALuint *)malloc(sizeof(ALuint) * 4);
alGenSources(4, sources);
}
SD_Started = true;
}
///////////////////////////////////////////////////////////////////////////
//
// SD_Shutdown() - shuts down the Sound Mgr
// Removes sound ISR and turns off whatever sound hardware was active
//
///////////////////////////////////////////////////////////////////////////
void SD_Shutdown(void)
{
if (!SD_Started)
return;
if (cc) {
alcDestroyContext(cc);
cc = NULL;
}
SD_MusicOff();
SD_StopSound();
SD_Started = false;
}
///////////////////////////////////////////////////////////////////////////
//
// SD_PlaySound() - plays the specified sound on the appropriate hardware
//
///////////////////////////////////////////////////////////////////////////
ALfloat gval[6], pval[6];
void SD_PlaySound(soundnames sound)
{
int i;
//printf("Playing sound %d, digimap %d\n", sound, DigiMap[sound]);
//fflush(stdout);
if (DigiMap[sound] != -1) {
/* TODO: openal bug? (need to stop before play) */
/* what is there to replayce SourceIsPlaying (was removed from AL)? */
for (i = 0; i < 4; i++) {
/* if (alSourceIsPlaying(sources[i]) == AL_FALSE) */ {
//alSourceStop(*sources);
alSourcefv(sources[i], AL_POSITION, gval);
alSource3f(sources[i], AL_DIRECTION, -pval[0], 0.0f, -pval[2]);
alSourcei(sources[i], AL_BUFFER, buffers[DigiMap[sound]]);
alSourcePlay(sources[i]);
break;
}
}
}
}
/* TODO: velocity ?! */
void UpdateSoundLoc(fixed x, fixed y, int angle)
{
pval[0] = gval[0] = x >> 15;
pval[1] = 0.0f;
pval[2] = gval[2] = y >> 15;
alListenerfv(AL_POSITION, pval);
pval[3] = 0.0f;
pval[4] = 1.0f;
pval[5] = 0.0f;
pval[0] *= sin(angle * PI / 180.0f);
pval[2] *= cos(angle * PI / 180.0f);
alListenerfv(AL_ORIENTATION, pval);
}
void PlaySoundLocGlobal(word sound, fixed x, fixed y)
{
ALfloat val[3];
int i;
//printf("Playing sound %d, digimap %d\n", sound, DigiMap[sound]);
//fflush(stdout);
if (DigiMap[sound] != -1) {
/* TODO: openal bug? (need to stop before play) */
for (i = 0; i < 4; i++) {
/* if (alSourceIsPlaying(sources[i]) == AL_FALSE) */ {
//alSourceStop(*sources);
val[0] = x >> 15;
val[1] = 0.0f;
val[2] = y >> 15;
alSourcefv(sources[i], AL_POSITION, val);
alSourcei(sources[i], AL_BUFFER, buffers[DigiMap[sound]]);
alSourcePlay(sources[i]);
break;
}
}
}
}
///////////////////////////////////////////////////////////////////////////
//
// SD_SoundPlaying() - returns the sound number that's playing, or 0 if
// no sound is playing
//
///////////////////////////////////////////////////////////////////////////
/* TODO: SD_IsSoundPlaying or something? */
word SD_SoundPlaying(void)
{
int i;
/* Watch out for any looped sounds */
for (i = 0; i < 4; i++) {
/* if (alSourceIsPlaying(sources[i]) == AL_TRUE) */ {
ALint ret;
alGetSourcei(sources[i], AL_SOURCE_LOOPING, &ret);
if (ret == AL_FALSE)
return true;
}
}
return false;
}
///////////////////////////////////////////////////////////////////////////
//
// SD_StopSound() - if a sound is playing, stops it
//
///////////////////////////////////////////////////////////////////////////
void SD_StopSound()
{
//int i;
/* TODO: this crashes for some reason... */
//for (i = 0; i < 4; i++)
// if (alSourceIsPlaying(sources[i]) == AL_TRUE)
// alSourceStop(sources[i]);
}
///////////////////////////////////////////////////////////////////////////
//
// SD_WaitSoundDone() - waits until the current sound is done playing
//
///////////////////////////////////////////////////////////////////////////
void SD_WaitSoundDone(void)
{
while (SD_SoundPlaying());
}
///////////////////////////////////////////////////////////////////////////
//
// SD_MusicOn() - turns on the sequencer
//
///////////////////////////////////////////////////////////////////////////
void SD_MusicOn(void)
{
sqActive = true;
}
///////////////////////////////////////////////////////////////////////////
//
// SD_MusicOff() - turns off the sequencer and any playing notes
//
///////////////////////////////////////////////////////////////////////////
void SD_MusicOff(void)
{
sqActive = false;
}
///////////////////////////////////////////////////////////////////////////
//
// SD_StartMusic() - starts playing the music pointed to
//
///////////////////////////////////////////////////////////////////////////
void SD_StartMusic(MusicGroup *music)
{
SD_MusicOff();
}
///////////////////////////////////////////////////////////////////////////
//
// SD_FadeOutMusic() - starts fading out the music. Call SD_MusicPlaying()
// to see if the fadeout is complete
//
///////////////////////////////////////////////////////////////////////////
void SD_FadeOutMusic(void)
{
}
///////////////////////////////////////////////////////////////////////////
//
// SD_MusicPlaying() - returns true if music is currently playing, false if
// not
//
///////////////////////////////////////////////////////////////////////////
boolean SD_MusicPlaying(void)
{
return false;
}
/* id_vl.c */
#include "wl_def.h"
#include <X11/Xlib.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 <GL/gl.h>
#include <GL/glx.h>
#error "This code is out of date/broken"
byte *gfxbuf = NULL;
Display *dpy;
int screen;
Window root, win;
XVisualInfo *vi;
Colormap cmap;
Atom wmDeleteWindow;
GLXContext ctx;
int attrib[] = {
GLX_RGBA,
GLX_RED_SIZE, 5,
GLX_GREEN_SIZE, 5,
GLX_BLUE_SIZE, 5,
GLX_DEPTH_SIZE, 16,
GLX_DOUBLEBUFFER,
None
};
/*
==========================
=
= Quit
=
==========================
*/
void Quit(char *error)
{
/* TODO: blah blah blah */
memptr screen = NULL;
if (!error || !*error) {
CA_CacheGrChunk(ORDERSCREEN);
screen = grsegs[ORDERSCREEN];
WriteConfig();
} else if (error) {
CA_CacheGrChunk(ERRORSCREEN);
screen = grsegs[ERRORSCREEN];
}
ShutdownId();
if (screen) {
printf("TODO: spiffy ansi screen goes here..\n");
}
if (error && *error) {
fprintf(stderr, "Quit: %s\n", error);
exit(EXIT_FAILURE);
}
exit(EXIT_SUCCESS);
}
int main(int argc, char *argv[])
{
/* TODO: move this to the proper functions */
XSetWindowAttributes attr;
XSizeHints sizehints;
Pixmap bitmap;
Cursor cursor;
XColor bg = { 0 };
XColor fg = { 0 };
char data[8] = { 0x01 };
char *disp, *ext;
int attrmask;
int major, minor;
disp = getenv("DISPLAY");
dpy = XOpenDisplay(disp);
if (dpy == NULL) {
/* TODO: quit function with vsnprintf */
fprintf(stderr, "Unable to open display %s!\n", XDisplayName(disp));
exit(EXIT_FAILURE);
}
screen = DefaultScreen(dpy);
root = RootWindow(dpy, screen);
if (glXQueryExtension(dpy, NULL, NULL) == False) {
fprintf(stderr, "X server %s does not support GLX\n", XDisplayName(disp));
exit(EXIT_FAILURE);
}
if (glXQueryVersion(dpy, &major, &minor) == False) {
fprintf(stderr, "glXQueryVersion returned False?\n");
exit(EXIT_FAILURE);
} else {
printf("GLX Version %d.%d\n", major, minor);
printf("GLX Client:\n");
printf("GLX_VENDOR: %s\n", glXGetClientString(dpy, GLX_VENDOR));
printf("GLX_VERSION: %s\n", glXGetClientString(dpy, GLX_VERSION));
printf("GLX_EXTENSIONS: %s\n", glXGetClientString(dpy, GLX_EXTENSIONS));
printf("GLX Server:\n");
printf("GLX_VENDOR: %s\n", glXQueryServerString(dpy, DefaultScreen(dpy), GLX_VENDOR));
printf("GLX_VERSION: %s\n", glXQueryServerString(dpy, DefaultScreen(dpy), GLX_VERSION));
printf("GLX_EXTENSIONS: %s\n", glXQueryServerString(dpy, DefaultScreen(dpy), GLX_EXTENSIONS));
printf("Both:\n");
printf("GLX_EXTENSIONS: %s\n", glXQueryExtensionsString(dpy, DefaultScreen(dpy)));
}
vi = glXChooseVisual(dpy, screen, attrib);
if (vi == NULL) {
Quit("No suitable GL visual found!");
}
ctx = glXCreateContext(dpy, vi, NULL, True);
if (ctx == NULL) {
Quit("glx context create failed");
}
cmap = XCreateColormap(dpy, root, vi->visual, AllocNone);
attr.colormap = cmap;
attr.background_pixel = BlackPixel(dpy, screen);
attr.event_mask = KeyPressMask | KeyReleaseMask | ExposureMask |
StructureNotifyMask;
attrmask = CWColormap | CWEventMask | CWBackPixel;
win = XCreateWindow(dpy, root, 0, 0, 320, 200, 0, vi->depth,
InputOutput, vi->visual, attrmask, &attr);
if (win == None) {
Quit("Unable to create window!");
}
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;
*/
sizehints.flags = PMinSize;
XSetWMProperties(dpy, win, NULL, NULL, argv, argc, &sizehints, None, None);
XStoreName(dpy, win, GAMENAME);
XSetIconName(dpy, win, GAMENAME);
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);
glXMakeCurrent(dpy, win, ctx);
// XMapWindow(dpy, win);
XFlush(dpy);
printf("GL Library:\n");
printf("GL_VENDOR: %s\n", glGetString(GL_VENDOR));
printf("GL_RENDERER: %s\n", glGetString(GL_RENDERER));
printf("GL_VERSION: %s\n", glGetString(GL_VERSION));
printf("GL_EXTENSIONS: %s\n", glGetString(GL_EXTENSIONS));
return WolfMain(argc, argv);
}
void VL_WaitVBL(int vbls)
{
/* hack - but it works for me */
long last = get_TimeCount() + 1;
while (last > get_TimeCount()) ;
}
void VW_UpdateScreen()
{
glXSwapBuffers(dpy, win);
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
/*
=======================
=
= VL_Startup
=
=======================
*/
void Init3D();
void VL_Startup()
{
if (gfxbuf == NULL)
gfxbuf = malloc(320 * 200 * 1);
XMapWindow(dpy, win);
glColor4f(0.0f, 0.0f, 0.0f, 0.0f);
glClearColor(0.0f, 0.0f, 0.0f, 0.0f);
glEnable(GL_TEXTURE_2D);
glEnable(GL_DEPTH_TEST);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glFrustum(-0.286751, 0.286751, -0.288675, 0.288675, 0.500000, 182.000000);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glMatrixMode(GL_TEXTURE);
glLoadIdentity();
glDisable(GL_CULL_FACE);
glDisable(GL_DEPTH_TEST);
Init3D();
}
/*
=======================
=
= VL_Shutdown
=
=======================
*/
void VL_Shutdown (void)
{
if (gfxbuf != NULL) {
free(gfxbuf);
gfxbuf = NULL;
}
}
//===========================================================================
/*
=================
=
= VL_ClearVideo
=
= Fill the entire video buffer with a given color
=
=================
*/
void VL_ClearVideo(byte color)
{
memset(gfxbuf, color, 64000);
}
/*
=============================================================================
PALETTE OPS
To avoid snow, do a WaitVBL BEFORE calling these
=============================================================================
*/
/*
=================
=
= VL_FillPalette
=
=================
*/
void VL_FillPalette(int red, int green, int blue)
{
}
//===========================================================================
/*
=================
=
= VL_SetPalette
=
=================
*/
void VL_SetPalette(const byte *palette)
{
}
//===========================================================================
/*
=================
=
= VL_GetPalette
=
=================
*/
void VL_GetPalette(byte *palette)
{
}
/*
=============================================================================
PIXEL OPS
=============================================================================
*/
/*
=================
=
= VL_Plot
=
=================
*/
void VL_Plot(int x, int y, int color)
{
*(gfxbuf + 320 * y + x) = color;
}
/*
=================
=
= VL_Hlin
=
=================
*/
void VL_Hlin(unsigned x, unsigned y, unsigned width, unsigned color)
{
memset(gfxbuf + 320 * y + x, color, width);
}
/*
=================
=
= VL_Vlin
=
=================
*/
void VL_Vlin (int x, int y, int height, int color)
{
byte *ptr = gfxbuf + 320 * y + x;
while (height--) {
*ptr = color;
ptr += 320;
}
}
/*
=================
=
= VL_Bar
=
=================
*/
void VL_Bar(int x, int y, int width, int height, int color)
{
byte *ptr = gfxbuf + 320 * y + x;
while (height--) {
memset(ptr, color, width);
ptr += 320;
}
}
/*
============================================================================
MEMORY OPS
============================================================================
*/
/*
=================
=
= VL_MemToScreen
=
= Draws a block of data to the screen.
=
=================
*/
void VL_MemToScreen(const byte *source, int width, int height, int x, int y)
{
byte *ptr = gfxbuf + 320 * y + x;
while(height--) {
memcpy(ptr, source, width);
source += width;
ptr += 320;
}
}
void VL_DeModeXize(byte *buf, int width, int height)
{
byte *mem, *ptr, *destline;
int plane, x, y;
if (width & 3) {
printf("Not divisible by 4?\n");
return;
}
mem = malloc(width * height);
ptr = buf;
for (plane = 0; plane < 4; plane++) {
destline = mem;
for (y = 0; y < height; y++) {
for (x = 0; x < width / 4; x++)
*(destline + x*4 + plane) = *ptr++;
destline += width;
}
}
memcpy(buf, mem, width * height);
free(mem);
}
void VL_DirectPlot(int x1, int y1, int x2, int y2)
{
}
/*
=============================================================================
GLOBAL VARIABLES
=============================================================================
*/
//
// configuration variables
//
boolean MousePresent;
boolean JoysPresent[MaxJoys];
// Global variables
boolean Keyboard[NumCodes];
boolean Paused;
char LastASCII;
ScanCode LastScan;
KeyboardDef KbdDefs = {sc_Control, sc_Alt, sc_Home, sc_UpArrow, sc_PgUp, sc_LeftArrow, sc_RightArrow, sc_End, sc_DownArrow, sc_PgDn};
ControlType Controls[MaxPlayers];
/*
=============================================================================
LOCAL VARIABLES
=============================================================================
*/
static byte ASCIINames[] = // Unshifted ASCII for scan codes
{
// 0 1 2 3 4 5 6 7 8 9 A B C D E F
0 ,27 ,'1','2','3','4','5','6','7','8','9','0','-','=',8 ,9 , // 0
'q','w','e','r','t','y','u','i','o','p','[',']',13 ,0 ,'a','s', // 1
'd','f','g','h','j','k','l',';',39 ,'`',0 ,92 ,'z','x','c','v', // 2
'b','n','m',',','.','/',0 ,'*',0 ,' ',0 ,0 ,0 ,0 ,0 ,0 , // 3
0 ,0 ,0 ,0 ,0 ,0 ,0 ,'7','8','9','-','4','5','6','+','1', // 4
'2','3','0',127,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 5
0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 6
0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 // 7
},
ShiftNames[] = // Shifted ASCII for scan codes
{
// 0 1 2 3 4 5 6 7 8 9 A B C D E F
0 ,27 ,'!','@','#','$','%','^','&','*','(',')','_','+',8 ,9 , // 0
'Q','W','E','R','T','Y','U','I','O','P','{','}',13 ,0 ,'A','S', // 1
'D','F','G','H','J','K','L',':',34 ,'~',0 ,'|','Z','X','C','V', // 2
'B','N','M','<','>','?',0 ,'*',0 ,' ',0 ,0 ,0 ,0 ,0 ,0 , // 3
0 ,0 ,0 ,0 ,0 ,0 ,0 ,'7','8','9','-','4','5','6','+','1', // 4
'2','3','0',127,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 5
0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 , // 6
0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 ,0 // 7
};
static boolean IN_Started;
static boolean CapsLock;
static ScanCode CurCode,LastCode;
static Direction DirTable[] = // Quick lookup for total direction
{
dir_NorthWest, dir_North, dir_NorthEast,
dir_West, dir_None, dir_East,
dir_SouthWest, dir_South, dir_SouthEast
};
// 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_1:
return sc_1;
case XK_2:
return sc_2;
case XK_3:
return sc_3;
case XK_4:
return sc_4;
case XK_y:
return sc_Y;
case XK_n:
return sc_N;
case XK_Pause:
return 0xE1;
default:
printf("unknown: %s\n", XKeysymToString(keysym));
return sc_None;
}
}
void keyboard_handler(int code, int press)
{
byte k, c = 0;
k = code;
if (k == 0xe1) // Handle Pause key
Paused = true;
else
{
if (press == 0)
{
Keyboard[k] = false;
}
else // Make code
{
LastCode = CurCode;
CurCode = LastScan = k;
Keyboard[k] = true;
if (k == sc_CapsLock)
{
CapsLock ^= true;
}
if (Keyboard[sc_LShift] || Keyboard[sc_RShift]) // If shifted
{
c = ShiftNames[k];
if ((c >= 'A') && (c <= 'Z') && CapsLock)
c += 'a' - 'A';
}
else
{
c = ASCIINames[k];
if ((c >= 'a') && (c <= 'z') && CapsLock)
c -= 'a' - 'A';
}
if (c)
LastASCII = c;
}
}
}
///////////////////////////////////////////////////////////////////////////
//
// INL_GetMouseDelta() - Gets the amount that the mouse has moved from the
// mouse driver
//
///////////////////////////////////////////////////////////////////////////
static void INL_GetMouseDelta(int *x,int *y)
{
*x = 0;
*y = 0;
}
///////////////////////////////////////////////////////////////////////////
//
// INL_GetMouseButtons() - Gets the status of the mouse buttons from the
// mouse driver
//
///////////////////////////////////////////////////////////////////////////
static word INL_GetMouseButtons(void)
{
return 0;
}
///////////////////////////////////////////////////////////////////////////
//
// IN_GetJoyAbs() - Reads the absolute position of the specified joystick
//
///////////////////////////////////////////////////////////////////////////
void IN_GetJoyAbs(word joy,word *xp,word *yp)
{
*xp = 0;
*yp = 0;
}
///////////////////////////////////////////////////////////////////////////
//
// INL_GetJoyDelta() - Returns the relative movement of the specified
// joystick (from +/-127)
//
///////////////////////////////////////////////////////////////////////////
void INL_GetJoyDelta(word joy,int *dx,int *dy)
{
*dx = 0;
*dy = 0;
}
///////////////////////////////////////////////////////////////////////////
//
// INL_GetJoyButtons() - Returns the button status of the specified
// joystick
//
///////////////////////////////////////////////////////////////////////////
static word INL_GetJoyButtons(word joy)
{
return 0;
}
///////////////////////////////////////////////////////////////////////////
//
// INL_StartKbd() - Sets up my keyboard stuff for use
//
///////////////////////////////////////////////////////////////////////////
static void INL_StartKbd(void)
{
IN_ClearKeysDown();
}
///////////////////////////////////////////////////////////////////////////
//
// INL_ShutKbd() - Restores keyboard control to the BIOS
//
///////////////////////////////////////////////////////////////////////////
static void INL_ShutKbd(void)
{
}
///////////////////////////////////////////////////////////////////////////
//
// INL_StartMouse() - Detects and sets up the mouse
//
///////////////////////////////////////////////////////////////////////////
static boolean INL_StartMouse(void)
{
return false;
}
///////////////////////////////////////////////////////////////////////////
//
// INL_ShutMouse() - Cleans up after the mouse
//
///////////////////////////////////////////////////////////////////////////
static void INL_ShutMouse(void)
{
}
///////////////////////////////////////////////////////////////////////////
//
// IN_SetupJoy() - Sets up thresholding values and calls INL_SetJoyScale()
// to set up scaling values
//
///////////////////////////////////////////////////////////////////////////
void IN_SetupJoy(word joy,word minx,word maxx,word miny,word maxy)
{
}
///////////////////////////////////////////////////////////////////////////
//
// INL_StartJoy() - Detects & auto-configures the specified joystick
// The auto-config assumes the joystick is centered
//
///////////////////////////////////////////////////////////////////////////
static boolean INL_StartJoy(word joy)
{
return false;
}
///////////////////////////////////////////////////////////////////////////
//
// INL_ShutJoy() - Cleans up the joystick stuff
//
///////////////////////////////////////////////////////////////////////////
static void INL_ShutJoy(word joy)
{
JoysPresent[joy] = false;
}
///////////////////////////////////////////////////////////////////////////
//
// IN_Startup() - Starts up the Input Mgr
//
///////////////////////////////////////////////////////////////////////////
void IN_Startup(void)
{
boolean checkjoys,checkmouse;
word i;
if (IN_Started)
return;
checkjoys = true;
checkmouse = true;
if (MS_CheckParm("nojoy"))
checkjoys = false;
if (MS_CheckParm("nomouse"))
checkmouse = false;
INL_StartKbd();
MousePresent = checkmouse ? INL_StartMouse() : false;
for (i = 0;i < MaxJoys;i++)
JoysPresent[i] = checkjoys ? INL_StartJoy(i) : false;
IN_Started = true;
}
///////////////////////////////////////////////////////////////////////////
//
// IN_Shutdown() - Shuts down the Input Mgr
//
///////////////////////////////////////////////////////////////////////////
void IN_Shutdown(void)
{
word i;
if (!IN_Started)
return;
INL_ShutMouse();
for (i = 0;i < MaxJoys;i++)
INL_ShutJoy(i);
INL_ShutKbd();
IN_Started = false;
}
///////////////////////////////////////////////////////////////////////////
//
// IN_ClearKeysDown() - Clears the keyboard array
//
///////////////////////////////////////////////////////////////////////////
void IN_ClearKeysDown(void)
{
LastScan = sc_None;
LastASCII = key_None;
memset(Keyboard, 0, sizeof(Keyboard));
}
///////////////////////////////////////////////////////////////////////////
//
// IN_ReadControl() - Reads the device associated with the specified
// player and fills in the control info struct
//
///////////////////////////////////////////////////////////////////////////
void IN_ReadControl(int player,ControlInfo *info)
{
boolean realdelta = false;
word buttons;
int dx,dy;
Motion mx,my;
ControlType type;
KeyboardDef *def;
dx = dy = 0;
mx = my = motion_None;
buttons = 0;
IN_CheckAck();
switch (type = Controls[player])
{
case ctrl_Keyboard:
def = &KbdDefs;
if (Keyboard[def->upleft])
mx = motion_Left,my = motion_Up;
else if (Keyboard[def->upright])
mx = motion_Right,my = motion_Up;
else if (Keyboard[def->downleft])
mx = motion_Left,my = motion_Down;
else if (Keyboard[def->downright])
mx = motion_Right,my = motion_Down;
if (Keyboard[def->up])
my = motion_Up;
else if (Keyboard[def->down])
my = motion_Down;
if (Keyboard[def->left])
mx = motion_Left;
else if (Keyboard[def->right])
mx = motion_Right;
if (Keyboard[def->button0])
buttons += 1 << 0;
if (Keyboard[def->button1])
buttons += 1 << 1;
realdelta = false;
break;
case ctrl_Joystick1:
case ctrl_Joystick2:
INL_GetJoyDelta(type - ctrl_Joystick,&dx,&dy);
buttons = INL_GetJoyButtons(type - ctrl_Joystick);
realdelta = true;
break;
case ctrl_Mouse:
INL_GetMouseDelta(&dx,&dy);
buttons = INL_GetMouseButtons();
realdelta = true;
break;
}
if (realdelta)
{
mx = (dx < 0)? motion_Left : ((dx > 0)? motion_Right : motion_None);
my = (dy < 0)? motion_Up : ((dy > 0)? motion_Down : motion_None);
}
else
{
dx = mx * 127;
dy = my * 127;
}
info->x = dx;
info->xaxis = mx;
info->y = dy;
info->yaxis = my;
info->button0 = buttons & (1 << 0);
info->button1 = buttons & (1 << 1);
info->button2 = buttons & (1 << 2);
info->button3 = buttons & (1 << 3);
info->dir = DirTable[((my + 1) * 3) + (mx + 1)];
}
///////////////////////////////////////////////////////////////////////////
//
// IN_Ack() - waits for a button or key press. If a button is down, upon
// calling, it must be released for it to be recognized
//
///////////////////////////////////////////////////////////////////////////
boolean btnstate[8];
void IN_StartAck(void)
{
unsigned i,buttons;
//
// get initial state of everything
//
IN_ClearKeysDown();
memset (btnstate,0,sizeof(btnstate));
buttons = IN_JoyButtons () << 4;
if (MousePresent)
buttons |= IN_MouseButtons ();
for (i=0;i<8;i++,buttons>>=1)
if (buttons&1)
btnstate[i] = true;
}
boolean IN_CheckAck()
{
XEvent event;
unsigned i, buttons;
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 ConfigureNotify:
glViewport(0, 0, event.xconfigure.width, event.xconfigure.height);
break;
case ClientMessage:
if (event.xclient.data.l[0] == wmDeleteWindow)
Quit(NULL);
break;
default:
break;
}
} while (XPending(dpy));
}
if (LastScan)
return true;
buttons = IN_JoyButtons () << 4;
if (MousePresent)
buttons |= IN_MouseButtons ();
for (i=0;i<8;i++,buttons>>=1)
if ( buttons&1 )
{
if (!btnstate[i])
return true;
}
else
btnstate[i]=false;
return false;
}
void IN_Ack()
{
IN_StartAck();
while(!IN_CheckAck()) ;
}
///////////////////////////////////////////////////////////////////////////
//
// IN_UserInput() - Waits for the specified delay time (in ticks) or the
// user pressing a key or a mouse button. If the clear flag is set, it
// then either clears the key or waits for the user to let the mouse
// button up.
//
///////////////////////////////////////////////////////////////////////////
boolean IN_UserInput(longword delay)
{
longword lasttime;
lasttime = get_TimeCount();
IN_StartAck();
do {
if (IN_CheckAck())
return true;
} while ( (get_TimeCount() - lasttime) < delay );
return false;
}
//===========================================================================
/*
===================
=
= IN_MouseButtons
=
===================
*/
byte IN_MouseButtons (void)
{
return 0;
}
/*
===================
=
= IN_JoyButtons
=
===================
*/
byte IN_JoyButtons (void)
{
return 0;
}
/* wl_draw.c */
#include "wl_def.h"
#include <GL/gl.h>
#error "This code is out of date/broken"
// the door is the last picture before the sprites
#define DOORWALL (PMSpriteStart-8)
#define ACTORSIZE 0x4000
unsigned wallheight[MAXVIEWWIDTH];
#define mindist MINDIST
//int pixelangle[MAXVIEWWIDTH]; /* TODO: i put these in wl_main */
//long finetangent[FINEANGLES/4];
//
// refresh variables
//
fixed viewx,viewy; // the focal point
int viewangle;
//
// ray tracing variables
//
int focaltx,focalty;
int midangle,angle;
unsigned xpartial,ypartial;
unsigned xpartialup,xpartialdown,ypartialup,ypartialdown;
unsigned tilehit;
unsigned pixx;
int xtile,ytile;
int xtilestep,ytilestep;
long xintercept,yintercept;
long xstep,ystep;
void AsmRefresh (void);
void xBuildCompScale(int height, byte *source, int x);
//==========================================================================
/*
========================
=
= TransformActor
=
= Takes paramaters:
= gx,gy : globalx/globaly of point
=
= globals:
= viewx,viewy : point of view
= viewcos,viewsin : sin/cos of viewangle
= scale : conversion from global value to screen value
=
= sets:
= screenx,transx,transy,screenheight: projected edge location and size
=
========================
*/
//
// transform actor
//
void TransformActor (objtype *ob)
{
fixed gx,gy,gxt,gyt,nx,ny;
//
// translate point to view centered coordinates
//
gx = ob->x-viewx;
gy = ob->y-viewy;
//
// calculate newx
//
gxt = FixedByFrac(gx,viewcos);
gyt = FixedByFrac(gy,viewsin);
nx = gxt-gyt-ACTORSIZE; // fudge the shape forward a bit, because
// the midpoint could put parts of the shape
// into an adjacent wall
//
// calculate newy
//
gxt = FixedByFrac(gx,viewsin);
gyt = FixedByFrac(gy,viewcos);
ny = gyt+gxt;
//
// calculate perspective ratio
//
ob->transx = nx;
ob->transy = ny;
if (nx < mindist) /* too close, don't overflow the divide */
{
ob->viewheight = 0;
return;
}
ob->viewx = centerx + ny*scale/nx;
ob->viewheight = heightnumerator/(nx>>8);
}
//==========================================================================
/*
========================
=
= TransformTile
=
= Takes paramaters:
= tx,ty : tile the object is centered in
=
= globals:
= viewx,viewy : point of view
= viewcos,viewsin : sin/cos of viewangle
= scale : conversion from global value to screen value
=
= sets:
= screenx,transx,transy,screenheight: projected edge location and size
=
= Returns true if the tile is withing getting distance
=
========================
*/
boolean TransformTile (int tx, int ty, int *dispx, int *dispheight)
{
fixed gx,gy,gxt,gyt,nx,ny;
//
// translate point to view centered coordinates
//
gx = ((long)tx<<TILESHIFT)+0x8000-viewx;
gy = ((long)ty<<TILESHIFT)+0x8000-viewy;
//
// calculate newx
//
gxt = FixedByFrac(gx,viewcos);
gyt = FixedByFrac(gy,viewsin);
nx = gxt-gyt-0x2000; // 0x2000 is size of object
//
// calculate newy
//
gxt = FixedByFrac(gx,viewsin);
gyt = FixedByFrac(gy,viewcos);
ny = gyt+gxt;
//
// calculate perspective ratio
//
if (nx<mindist) /* too close, don't overflow the divide */
{
*dispheight = 0;
return false;
}
*dispx = centerx + ny*scale/nx;
*dispheight = heightnumerator/(nx>>8);
//
// see if it should be grabbed
//
if ( (nx<TILEGLOBAL) && (ny>-TILEGLOBAL/2) && (ny<TILEGLOBAL/2) )
return true;
else
return false;
}
//==========================================================================
/*
====================
=
= CalcHeight
=
= Calculates the height of xintercept,yintercept from viewx,viewy
=
====================
*/
int CalcHeight (void)
{
fixed gxt,gyt,nx,gx,gy;
gx = xintercept-viewx;
gxt = FixedByFrac(gx,viewcos);
gy = yintercept-viewy;
gyt = FixedByFrac(gy,viewsin);
nx = gxt-gyt;
//
// calculate perspective ratio (heightnumerator/(nx>>8))
//
if (nx<mindist)
nx=mindist; /* don't let divide overflow */
return heightnumerator/(nx>>8);
}
//==========================================================================
/*
===================
=
= ScalePost
=
===================
*/
unsigned postx;
#if 0
void ScalePost(byte *wall, int texture)
{
int height;
byte *source;
height = (wallheight [postx] & 0xfff8) >> 1;
source = wall+texture;
xBuildCompScale (height/2, source, postx);
}
#endif
/*
====================
=
= HitHorizDoor
=
====================
*/
void HitHorizDoor()
{
unsigned texture, doorpage = 0, doornum;
byte *wall;
doornum = tilehit&0x7f;
texture = ( (xintercept-doorposition[doornum]) >> 4) &0xfc0;
wallheight[pixx] = CalcHeight();
postx = pixx;
switch (doorobjlist[doornum].lock)
{
case dr_normal:
doorpage = DOORWALL;
break;
case dr_lock1:
case dr_lock2:
case dr_lock3:
case dr_lock4:
doorpage = DOORWALL+6;
break;
case dr_elevator:
doorpage = DOORWALL+4;
break;
}
// wall = PM_GetPage (doorpage);
// ScalePost (wall, texture);
}
//==========================================================================
/*
====================
=
= HitVertDoor
=
====================
*/
void HitVertDoor()
{
unsigned texture, doorpage = 0, doornum;
byte *wall;
doornum = tilehit&0x7f;
texture = ( (yintercept-doorposition[doornum]) >> 4) &0xfc0;
wallheight[pixx] = CalcHeight();
postx = pixx;
switch (doorobjlist[doornum].lock)
{
case dr_normal:
doorpage = DOORWALL;
break;
case dr_lock1:
case dr_lock2:
case dr_lock3:
case dr_lock4:
doorpage = DOORWALL+6;
break;
case dr_elevator:
doorpage = DOORWALL+4;
break;
}
// wall = PM_GetPage (doorpage);
// ScalePost (wall, texture);
}
//==========================================================================
unsigned Ceiling[]=
{
#ifndef SPEAR
0x1d1d,0x1d1d,0x1d1d,0x1d1d,0x1d1d,0x1d1d,0x1d1d,0x1d1d,0x1d1d,0xbfbf,
0x4e4e,0x4e4e,0x4e4e,0x1d1d,0x8d8d,0x4e4e,0x1d1d,0x2d2d,0x1d1d,0x8d8d,
0x1d1d,0x1d1d,0x1d1d,0x1d1d,0x1d1d,0x2d2d,0xdddd,0x1d1d,0x1d1d,0x9898,
0x1d1d,0x9d9d,0x2d2d,0xdddd,0xdddd,0x9d9d,0x2d2d,0x4d4d,0x1d1d,0xdddd,
0x7d7d,0x1d1d,0x2d2d,0x2d2d,0xdddd,0xd7d7,0x1d1d,0x1d1d,0x1d1d,0x2d2d,
0x1d1d,0x1d1d,0x1d1d,0x1d1d,0xdddd,0xdddd,0x7d7d,0xdddd,0xdddd,0xdddd
#else
0x6f6f,0x4f4f,0x1d1d,0xdede,0xdfdf,0x2e2e,0x7f7f,0x9e9e,0xaeae,0x7f7f,
0x1d1d,0xdede,0xdfdf,0xdede,0xdfdf,0xdede,0xe1e1,0xdcdc,0x2e2e,0x1d1d,0xdcdc
#endif
};
/*
=====================
=
= ClearScreen
=
=====================
*/
void ClearScreen()
{
unsigned ceiling = Ceiling[gamestate.episode*10+mapon] & 0xFF;
unsigned floor = 0x19;
VL_Bar(xoffset, yoffset, viewwidth, viewheight / 2, ceiling);
VL_Bar(xoffset, yoffset + viewheight / 2, viewwidth, viewheight / 2, floor);
}
//==========================================================================
/*
=====================
=
= CalcRotate
=
=====================
*/
int CalcRotate(objtype *ob)
{
int angle,viewangle;
/* this isn't exactly correct, as it should vary by a trig value, */
/* but it is close enough with only eight rotations */
viewangle = player->angle + (centerx - ob->viewx)/8;
if (ob->obclass == rocketobj || ob->obclass == hrocketobj)
angle = (viewangle-180)- ob->angle;
else
angle = (viewangle-180)- dirangle[ob->dir];
angle+=ANGLES/16;
while (angle>=ANGLES)
angle-=ANGLES;
while (angle<0)
angle+=ANGLES;
if (ob->state->rotate == 2) // 2 rotation pain frame
return 4*(angle/(ANGLES/2)); // seperated by 3 (art layout...)
return angle/(ANGLES/8);
}
/*
=====================
=
= DrawScaleds
=
= Draws all objects that are visable
=
=====================
*/
#define MAXVISABLE 50
typedef struct
{
int viewx, viewheight, shapenum;
fixed x, y;
} visobj_t;
visobj_t vislist[MAXVISABLE],*visptr,*visstep,*farthest;
void DrawScaleds()
{
int i,least,numvisable,height;
byte *tilespot,*visspot;
unsigned spotloc;
statobj_t *statptr;
objtype *obj;
visptr = &vislist[0];
//
// place static objects
//
for (statptr = &statobjlist[0] ; statptr !=laststatobj ; statptr++)
{
if ((visptr->shapenum = statptr->shapenum) == -1)
continue; // object has been deleted
if (!*statptr->visspot)
continue; // not visable
if (TransformTile (statptr->tilex,statptr->tiley
,&visptr->viewx,&visptr->viewheight) && statptr->flags & FL_BONUS)
{
GetBonus (statptr);
continue;
}
if (!visptr->viewheight)
continue; // to close to the object
visptr->x = statptr->tilex << 16;
visptr->y = statptr->tiley << 16;
if (visptr < &vislist[MAXVISABLE-1]) /* don't let it overflow */
visptr++;
}
//
// place active objects
//
for (obj = player->next;obj;obj=obj->next)
{
if (!(visptr->shapenum = obj->state->shapenum))
continue; // no shape
spotloc = (obj->tilex<<6)+obj->tiley; // optimize: keep in struct?
visspot = &spotvis[0][0]+spotloc;
tilespot = &tilemap[0][0]+spotloc;
//
// could be in any of the nine surrounding tiles
//
if (*visspot
|| ( *(visspot-1) && !*(tilespot-1) )
|| ( *(visspot+1) && !*(tilespot+1) )
|| ( *(visspot-65) && !*(tilespot-65) )
|| ( *(visspot-64) && !*(tilespot-64) )
|| ( *(visspot-63) && !*(tilespot-63) )
|| ( *(visspot+65) && !*(tilespot+65) )
|| ( *(visspot+64) && !*(tilespot+64) )
|| ( *(visspot+63) && !*(tilespot+63) ) )
{
obj->active = true;
TransformActor (obj);
if (!obj->viewheight)
continue; // too close or far away
visptr->viewx = obj->viewx;
visptr->viewheight = obj->viewheight;
if (visptr->shapenum == -1)
visptr->shapenum = obj->temp1; // special shape
if (obj->state->rotate)
visptr->shapenum += CalcRotate (obj);
visptr->x = obj->x;
visptr->y = obj->y;
if (visptr < &vislist[MAXVISABLE-1]) /* don't let it overflow */
visptr++;
obj->flags |= FL_VISABLE;
}
else
obj->flags &= ~FL_VISABLE;
}
//
// draw from back to front
//
#if 0
numvisable = visptr-&vislist[0];
if (!numvisable)
return; // no visible objects
for (i = 0; i<numvisable; i++)
{
least = 32000;
for (visstep=&vislist[0] ; visstep<visptr ; visstep++)
{
height = visstep->viewheight;
if (height < least)
{
least = height;
farthest = visstep;
}
}
//
// draw farthest
//
//ScaleShape(farthest->viewx,farthest->shapenum,farthest->viewheight);
farthest->viewheight = 32000;
}
#endif
}
//==========================================================================
extern GLuint *sprtex;
extern GLuint *waltex;
void DrawVisibleSprites()
{
for (visstep = &vislist[0]; visstep < visptr; visstep++) {
glBindTexture(GL_TEXTURE_2D, sprtex[visstep->shapenum]);
glBegin(GL_QUADS);
glTexCoord2f(0.0, 0.0); glVertex3f(visstep->x / 65536.0f + 1.0f, -1.0f, visstep->y / 65536.0f);
glTexCoord2f(0.0, 1.0); glVertex3f(visstep->x / 65536.0f + 1.0f, 1.0f, visstep->y / 65536.0f);
glTexCoord2f(1.0, 1.0); glVertex3f(visstep->x / 65536.0f - 1.0f, 1.0f, visstep->y / 65536.0f);
glTexCoord2f(1.0, 0.0); glVertex3f(visstep->x / 65536.0f - 1.0f, -1.0f, visstep->y / 65536.0f);
glEnd();
}
}
#define LEFTWALL 0x01
#define RIGHTWALL 0x02
#define TOPWALL 0x04
#define BOTTOMWALL 0x08
void DrawCubex(byte dat, GLfloat x, GLfloat y)
{
float x1 = x + 1;
float x2 = x - 1;
float z1 = -y + 1;
float z2 = -y - 1;
glBegin(GL_QUADS);
if (dat & BOTTOMWALL) {
/* glColor3f(1.0f, 0.0f, 0.0f); */
glTexCoord2d(1.0,0.0); glVertex3f(x1, -1.0f, z2);
glTexCoord2d(1.0,1.0); glVertex3f(x2, -1.0f, z2);
glTexCoord2d(0.0,1.0); glVertex3f(x2, 1.0f, z2);
glTexCoord2d(0.0,0.0); glVertex3f(x1, 1.0f, z2);
}
if (dat & TOPWALL) {
/* glColor3f(0.0f, 1.0f, 0.0f); */
glTexCoord2d(1.0,0.0); glVertex3f(x2, -1.0f, z1);
glTexCoord2d(1.0,1.0); glVertex3f(x1, -1.0f, z1);
glTexCoord2d(0.0,1.0); glVertex3f(x1, 1.0f, z1);
glTexCoord2d(0.0,0.0); glVertex3f(x2, 1.0f, z1);
}
if (dat & LEFTWALL) {
/* glColor3f(0.0f, 0.0f, 1.0f); */
glTexCoord2d(1.0,0.0); glVertex3f(x2, -1.0f, z2);
glTexCoord2d(1.0,1.0); glVertex3f(x2, -1.0f, z1);
glTexCoord2d(0.0,1.0); glVertex3f(x2, 1.0f, z1);
glTexCoord2d(0.0,0.0); glVertex3f(x2, 1.0f, z2);
}
if (dat & RIGHTWALL) {
/* glColor3f(1.0f, 1.0f, 0.0f); */
glTexCoord2d(1.0,0.0); glVertex3f(x1, -1.0f, z1);
glTexCoord2d(1.0,1.0); glVertex3f(x1, -1.0f, z2);
glTexCoord2d(0.0,1.0); glVertex3f(x1, 1.0f, z2);
glTexCoord2d(0.0,0.0); glVertex3f(x1, 1.0f, z1);
}
glEnd();
}
void DrawWalls()
{
int x, y;
int tilehit;
for (y = 0; y < 64; y++) {
for (x = 0; x < 64; x++) {
tilehit = tilemap[x][y];
if (tilehit < 64) {
glBindTexture(GL_TEXTURE_2D, waltex[0]);
DrawCubex(0xFF, (GLfloat)x + .5, (GLfloat)y + .5);
}
}
}
}
/*
==============
=
= DrawPlayerWeapon
=
= Draw the player's hands
=
==============
*/
int weaponscale[NUMWEAPONS] = {SPR_KNIFEREADY,SPR_PISTOLREADY
,SPR_MACHINEGUNREADY,SPR_CHAINREADY};
void DrawPlayerWeapon (void)
{
int shapenum;
#if 0
#ifndef SPEAR
if (gamestate.victoryflag)
{
if (player->state == &s_deathcam && (get_TimeCount() & 32) )
// SimpleScaleShape(viewwidth/2,SPR_DEATHCAM,viewheight+1);
return;
}
#endif
if (gamestate.weapon != -1)
{
shapenum = weaponscale[gamestate.weapon]+gamestate.weaponframe;
//SimpleScaleShape(viewwidth/2,shapenum,viewheight+1);
}
// if (demorecord || demoplayback)
// SimpleScaleShape(viewwidth/2,SPR_DEMO,viewheight+1);
#endif
if (gamestate.weapon != -1) {
shapenum = weaponscale[gamestate.weapon]+gamestate.weaponframe;
glBindTexture(GL_TEXTURE_2D, sprtex[shapenum]);
glBegin(GL_QUADS);
glTexCoord2d(0.0,1.0); glVertex2d(-1.0,-1.0);
glTexCoord2d(1.0,1.0); glVertex2d(+1.0,-1.0);
glTexCoord2d(1.0,0.0); glVertex2d(+1.0,+1.0);
glTexCoord2d(0.0,0.0); glVertex2d(-1.0,+1.0);
glEnd();
}
}
//==========================================================================
/*
====================
=
= WallRefresh
=
====================
*/
void WallRefresh (void)
{
/*
set up variables for this view
*/
viewangle = player->angle;
midangle = viewangle*(FINEANGLES/ANGLES);
viewsin = sintable[viewangle];
viewcos = costable[viewangle];
viewx = player->x - FixedByFrac(focallength,viewcos);
viewy = player->y + FixedByFrac(focallength,viewsin);
focaltx = viewx>>TILESHIFT;
focalty = viewy>>TILESHIFT;
xpartialdown = viewx&(TILEGLOBAL-1);
xpartialup = TILEGLOBAL-xpartialdown;
ypartialdown = viewy&(TILEGLOBAL-1);
ypartialup = TILEGLOBAL-ypartialdown;
AsmRefresh();
}
//==========================================================================
/*
========================
=
= ThreeDRefresh
=
========================
*/
void ThreeDRefresh()
{
//
// clear out the traced array
//
memset(spotvis, 0, sizeof(spotvis));
//
// follow the walls from there to the right, drawwing as we go
//
DrawPlayBorder();
ClearScreen();
WallRefresh ();
//
// draw all the scaled images
//
DrawScaleds(); // draw scaled stuff
glViewport(xoffset, 200 - (yoffset+viewheight), viewwidth, viewheight);
glMatrixMode(GL_MODELVIEW);
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
//DrawPlayerWeapon(); /* draw player's hands */
glFrustum(-0.286751, 0.286751, -0.288675, 0.288675, 0.500000, 182.000000);
glMatrixMode(GL_MODELVIEW);
glRotatef(player->angle, 0.0f, 1.0f, 0.0f);
//printf("%f, %f\n", (GLfloat)player->x / 65536.0f, (GLfloat)player->y / 65536.0f);
glTranslatef((GLfloat)player->x / 65536.0f, 0, (GLfloat)player->y / 65536.0f);
/* Render World */
DrawWalls();
godmode = 1; /* (: */
glRotatef(360 - player->angle, 0.0f, 1.0f, 0.0f);
/* Render Sprites */
DrawVisibleSprites();
glDisable(GL_DEPTH_TEST);
glMatrixMode(GL_MODELVIEW); /* temp debug */
glLoadIdentity();
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
DrawPlayerWeapon(); /* draw player's hands */
glEnable(GL_DEPTH_TEST);
//
// show screen and time last cycle
//
if (fizzlein)
{
FizzleFade(xoffset, yoffset, viewwidth,viewheight,20,false);
fizzlein = false;
lasttimecount = 0; /* don't make a big tic count */
set_TimeCount(0);
}
VW_UpdateScreen ();
VW_WaitVBL(1);
frameon++;
}
//===========================================================================
/* xpartial = 16 bit fraction
ystep = 32 bit fixed 32,16
*/
#define xpartialbyystep() FixedByFrac(xpartial, ystep)
#define ypartialbyxstep() FixedByFrac(ypartial, xstep)
int samex (int intercept, int tile)
{
if (xtilestep > 0) {
if ((intercept>>16) >= tile)
return 0;
else
return 1;
} else {
if ((intercept>>16) <= tile)
return 0;
else
return 1;
}
}
int samey (int intercept, int tile)
{
if (ytilestep > 0) {
if ((intercept>>16) >= tile)
return 0;
else
return 1;
} else {
if ((intercept>>16) <= tile)
return 0;
else
return 1;
}
}
#define DEG90 900
#define DEG180 1800
#define DEG270 2700
#define DEG360 3600
void HitHorizWall (void);
void HitVertWall (void);
void HitHorizPWall (void);
void HitVertPWall (void);
void AsmRefresh (void)
{
fixed doorxhit, dooryhit;
int angle; /* ray angle through pixx */
for (pixx = 0; pixx < viewwidth; pixx++) {
angle = midangle + pixelangle[pixx];
if (angle < 0) {
/* -90 - -1 degree arc */
angle += FINEANGLES;
goto entry360;
} else if (angle < DEG90) {
/* 0-89 degree arc */
entry90:
xtilestep = 1;
ytilestep = -1;
xstep = finetangent[DEG90-1-angle];
ystep = -finetangent[angle];
xpartial = xpartialup;
ypartial = ypartialdown;
} else if (angle < DEG180) {
/* 90-179 degree arc */
xtilestep = -1;
ytilestep = -1;
xstep = -finetangent[angle-DEG90];
ystep = -finetangent[DEG180-1-angle];
xpartial = xpartialdown;
ypartial = ypartialdown;
} else if (angle < DEG270) {
/* 180-269 degree arc */
xtilestep = -1;
ytilestep = 1;
xstep = -finetangent[DEG270-1-angle];
ystep = finetangent[angle-DEG180];
xpartial = xpartialdown;
ypartial = ypartialup;
} else if (angle < DEG360) {
/* 270-359 degree arc */
entry360:
xtilestep = 1;
ytilestep = 1;
xstep = finetangent[angle-DEG270];
ystep = finetangent[DEG360-1-angle];
xpartial = xpartialup;
ypartial = ypartialup;
} else {
angle -= FINEANGLES;
goto entry90;
}
yintercept = viewy + xpartialbyystep ();
xtile = focaltx + xtilestep;
xintercept = viewx + ypartialbyxstep ();
ytile = focalty + ytilestep;
/* CORE LOOP */
#define TILE(n) (n>>16)
/* check intersections with vertical walls */
vertcheck:
if (!samey (yintercept, ytile))
goto horizentry;
vertentry:
tilehit = tilemap [xtile][TILE(yintercept)];
if (tilehit != 0) {
if (tilehit & 0x80) {
if (tilehit & 0x40) {
/* vertpushwall */
long ytemp = yintercept + (pwallpos * ystep) / 64;
ytemp &= ~0x4000000; /* TODO: why? */
//fprintf(stderr, "VertPushWall@%d: 0x%X vs 0x%X\n", angle, yintercept, ytemp);
if (TILE(ytemp) != TILE(yintercept))
goto passvert;
yintercept = ytemp;
xintercept = xtile << 16;
HitVertPWall();
}
else {
dooryhit = yintercept + ystep / 2;
if (TILE (dooryhit) != TILE (yintercept))
goto passvert;
/* check door position */
if ((dooryhit&0xFFFF) < doorposition[tilehit&0x7f])
goto passvert;
yintercept = dooryhit;
xintercept = (xtile << 16) + 32768;
HitVertDoor ();
}
}
else {
xintercept = xtile << 16;
HitVertWall ();
}
goto nextpix;
}
passvert:
spotvis [xtile][TILE(yintercept)] = 1;
xtile += xtilestep;
yintercept += ystep;
goto vertcheck;
horizcheck:
/* check intersections with horizontal walls */
if (!samex (xintercept, xtile))
goto vertentry;
horizentry:
tilehit = tilemap [TILE(xintercept)][ytile];
if (tilehit != 0) {
if (tilehit & 0x80) {
/* horizdoor */
if (tilehit & 0x40) {
long xtemp = xintercept + (pwallpos * xstep) / 64;
xtemp &= ~0x4000000;
/* horizpushwall */
if (TILE(xtemp) != TILE(xintercept))
goto passhoriz;
xintercept = xtemp;
yintercept = ytile << 16;
HitHorizPWall();
}
else {
doorxhit = xintercept + xstep / 2;
if (TILE (doorxhit) != TILE (xintercept))
goto passhoriz;
/* check door position */
if ((doorxhit&0xFFFF) < doorposition[tilehit&0x7f])
goto passhoriz;
xintercept = doorxhit;
yintercept = (ytile << 16) + 32768;
HitHorizDoor ();
}
}
else {
yintercept = ytile << 16;
HitHorizWall ();
}
goto nextpix;
}
passhoriz:
spotvis [TILE(xintercept)][ytile] = 1;
ytile += ytilestep;
xintercept += xstep;
goto horizcheck;
nextpix:
}
}
void HitVertWall (void)
{
int wallpic;
unsigned texture;
byte *wall;
texture = (yintercept>>4)&0xfc0;
if (xtilestep == -1)
{
texture = 0xfc0-texture;
xintercept += TILEGLOBAL;
}
wallheight[pixx] = CalcHeight();
postx = pixx;
if (tilehit & 0x40)
{ // check for adjacent doors
ytile = yintercept>>TILESHIFT;
if ( tilemap[xtile-xtilestep][ytile]&0x80 )
wallpic = DOORWALL+3;
else
wallpic = vertwall[tilehit & ~0x40];
}
else
wallpic = vertwall[tilehit];
//wall = PM_GetPage (wallpic);
//ScalePost (wall, texture);
}
void HitHorizWall (void)
{
int wallpic;
unsigned texture;
byte *wall;
texture = (xintercept>>4)&0xfc0;
if (ytilestep == -1)
yintercept += TILEGLOBAL;
else
texture = 0xfc0-texture;
wallheight[pixx] = CalcHeight();
postx = pixx;
if (tilehit & 0x40)
{ // check for adjacent doors
xtile = xintercept>>TILESHIFT;
if ( tilemap[xtile][ytile-ytilestep]&0x80 )
wallpic = DOORWALL+2;
else
wallpic = horizwall[tilehit & ~0x40];
}
else
wallpic = horizwall[tilehit];
//wall = PM_GetPage (wallpic);
//ScalePost (wall, texture);
}
/*
====================
=
= HitHorizPWall
=
= A pushable wall in action has been hit
=
====================
*/
void HitHorizPWall (void)
{
int wallpic;
unsigned texture,offset;
byte *wall;
texture = (xintercept>>4)&0xfc0;
offset = pwallpos<<10;
if (ytilestep == -1)
yintercept += TILEGLOBAL-offset;
else
{
texture = 0xfc0-texture;
yintercept += offset;
}
wallheight[pixx] = CalcHeight();
postx = pixx;
wallpic = horizwall[tilehit&63];
//wall = PM_GetPage (wallpic);
//ScalePost (wall, texture);
}
/*
====================
=
= HitVertPWall
=
= A pushable wall in action has been hit
=
====================
*/
void HitVertPWall (void)
{
int wallpic;
unsigned texture,offset;
byte *wall;
texture = (yintercept>>4)&0xfc0;
offset = pwallpos<<10;
if (xtilestep == -1)
{
xintercept += TILEGLOBAL-offset;
texture = 0xfc0-texture;
}
else
xintercept += offset;
wallheight[pixx] = CalcHeight();
postx = pixx;
wallpic = vertwall[tilehit&63];
//wall = PM_GetPage (wallpic);
//ScalePost (wall, texture);
}
void SetupScaling(int test)
{
}
byte *SprToLin(byte *source)
{
byte *buf = malloc(64 * 64);
t_compshape *ptr = (t_compshape *)source;
memset(buf, '\0', 64 * 64);
{
int srcx = 32;
int slinex = 31;
int stopx = ptr->leftpix;
word *cmdptr = &ptr->dataofs[31-stopx];
while ( --srcx >=stopx ) {
short *linecmds = (short *)((unsigned char *)ptr + *cmdptr--);
slinex--;
while (linecmds[0]) {
int y;
int y0 = linecmds[2] / 2;
int y1 = linecmds[0] / 2 - 1;
unsigned char *pixels = (unsigned char *)ptr + y0 + linecmds[1];
for (y = y0; y <= y1; y++) {
unsigned char color = *pixels++;
*(buf + slinex + (y*64)) = color;
}
linecmds += 3;
}
}
slinex = 31;
stopx = ptr->rightpix;
if (ptr->leftpix < 31) {
srcx = 31;
cmdptr = &ptr->dataofs[32 - ptr->leftpix];
} else {
srcx = ptr->leftpix - 1;
cmdptr = &ptr->dataofs[0];
}
while (++srcx <= stopx) {
short *linecmds = (short *)((unsigned char *)ptr + *cmdptr++);
while (linecmds[0]) {
int y;
int y0 = linecmds[2] / 2;
int y1 = linecmds[0] / 2 - 1;
unsigned char *pixels = (unsigned char *)ptr + y0 + linecmds[1];
for (y = y0; y <= y1; y++) {
unsigned char color = *pixels++;
*(buf + slinex + (y*64)) = color;
}
linecmds += 3;
}
slinex++;
}
}
return buf;
}
byte *Pal_256_RGB(byte *source)
{
byte *dest = (byte *)malloc(64 * 64 * 3);
int i;
for (i = 0; i < 4096; i++) {
dest[i*3+0] = gamepal[source[i]*3+0] << 2;
dest[i*3+1] = gamepal[source[i]*3+1] << 2;
dest[i*3+2] = gamepal[source[i]*3+2] << 2;
}
return dest;
}
byte *Pal_256_RGBA(byte *source)
{
byte *dest = (byte *)malloc(64 * 64 * 4);
int i;
for (i = 0; i < 4096; i++) {
dest[i*4+0] = gamepal[source[i]*3+0] << 2;
dest[i*4+1] = gamepal[source[i]*3+1] << 2;
dest[i*4+2] = gamepal[source[i]*3+2] << 2;
if (source[i] == 0)
dest[i*4+3] = 0;
else
dest[i*4+3] = 255;
}
return dest;
}
GLuint *sprtex, sprcount;
GLuint *waltex, walcount;
void Init3D()
{
int i;
printf("start init\n");
walcount = PMSpriteStart;
waltex = (int *)malloc(sizeof(GLuint) * walcount);
sprcount = PMSoundStart - PMSpriteStart;
sprtex = (int *)malloc(sizeof(GLuint) * sprcount);
printf("creating %d walls, %d sprites\n", walcount, sprcount);
glGenTextures(walcount, waltex);
glGenTextures(sprcount, sprtex);
for (i = 0; i < walcount; i++) {
glBindTexture(GL_TEXTURE_2D, waltex[i]);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGB, 64, 64, 0, GL_RGB, GL_UNSIGNED_BYTE, Pal_256_RGB(PM_GetPage(i)));
}
for (i = 0; i < sprcount; i++) {
glBindTexture(GL_TEXTURE_2D, sprtex[i]);
glTexEnvf(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, GL_REPLACE);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP);
glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP);
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA, 64, 64, 0, GL_RGBA, GL_UNSIGNED_BYTE, Pal_256_RGBA(SprToLin(PM_GetSpritePage(i))));
}
printf("end init\n");
}
......@@ -47,7 +47,7 @@ void ClearMemory()
==========================
*/
void ScanInfoPlane (void)
void ScanInfoPlane()
{
unsigned x,y;
int tile;
......@@ -451,7 +451,7 @@ void ScanInfoPlane (void)
==================
*/
void SetupGameLevel (void)
void SetupGameLevel()
{
int x,y;
word *map,tile;
......@@ -579,7 +579,7 @@ void SetupGameLevel (void)
// have the caching manager load and purge stuff to make sure all marks
// are in memory
//
CA_LoadAllSounds ();
CA_LoadAllSounds();
}
......@@ -597,7 +597,7 @@ void SetupGameLevel (void)
===================
*/
void DrawPlayBorderSides (void)
void DrawPlayBorderSides()
{
int xl,yl;
......@@ -620,9 +620,9 @@ void DrawPlayBorderSides (void)
===================
*/
void DrawAllPlayBorderSides (void)
void DrawAllPlayBorderSides()
{
DrawPlayBorderSides ();
DrawPlayBorderSides();
}
/*
......@@ -632,9 +632,9 @@ void DrawAllPlayBorderSides (void)
=
===================
*/
void DrawAllPlayBorder (void)
void DrawAllPlayBorder()
{
DrawPlayBorder ();
DrawPlayBorder();
}
/*
......@@ -645,9 +645,9 @@ void DrawAllPlayBorder (void)
===================
*/
void DrawPlayBorder (void)
void DrawPlayBorder()
{
int xl,yl;
int xl, yl;
VW_Bar (0,0,320,200-STATUSLINES,127);
......@@ -662,8 +662,6 @@ void DrawPlayBorder (void)
VW_Plot (xl-1,yl+viewheight,124);
}
/*
===================
=
......@@ -674,7 +672,7 @@ void DrawPlayBorder (void)
void DrawPlayScreen()
{
VW_FadeOut ();
VW_FadeOut();
CA_CacheGrChunk(STATUSBARPIC);
......@@ -705,10 +703,10 @@ void DrawPlayScreen()
#define MAXDEMOSIZE 8192
void StartDemoRecord (int levelnumber)
void StartDemoRecord(int levelnumber)
{
MM_GetPtr (&demobuffer,MAXDEMOSIZE);
MM_SetLock (&demobuffer,true);
MM_GetPtr(&demobuffer,MAXDEMOSIZE);
MM_SetLock(&demobuffer,true);
demoptr = (char *)demobuffer;
lastdemoptr = demoptr+MAXDEMOSIZE;
......@@ -717,7 +715,6 @@ void StartDemoRecord (int levelnumber)
demorecord = true;
}
/*
==================
=
......@@ -728,9 +725,9 @@ void StartDemoRecord (int levelnumber)
char demoname[13] = "demo?.dem";
void FinishDemoRecord (void)
void FinishDemoRecord()
{
long length,level;
long length, level;
demorecord = false;
......@@ -770,7 +767,7 @@ void FinishDemoRecord (void)
==================
*/
void RecordDemo(void)
void RecordDemo()
{
int level,esc;
......@@ -902,29 +899,29 @@ int PlayDemoFromFile(char *demoname)
demoptr++;
lastdemoptr = demoptr-4+length;
VW_FadeOut ();
VW_FadeOut();
SETFONTCOLOR(0,15);
DrawPlayScreen ();
DrawPlayScreen();
VW_UpdateScreen(); /* force redraw */
VW_FadeIn ();
VW_FadeIn();
startgame = false;
demoplayback = true;
SetupGameLevel ();
StartMusic ();
SetupGameLevel();
StartMusic();
fizzlein = true;
PlayLoop ();
PlayLoop();
MM_FreePtr(&demobuffer);
demoplayback = false;
StopMusic ();
ClearMemory ();
StopMusic();
ClearMemory();
return 1;
}
......@@ -960,18 +957,15 @@ void Died()
}
fangle = atan2(dy,dx); // returns -pi to pi
if (fangle<0)
if (fangle < 0)
fangle = PI*2+fangle;
iangle = fangle/(PI*2)*ANGLES;
if (player->angle > iangle)
{
if (player->angle > iangle) {
counter = player->angle - iangle;
clockwise = ANGLES-player->angle + iangle;
}
else
{
} else {
clockwise = iangle - player->angle;
counter = player->angle + ANGLES-iangle;
}
......@@ -985,8 +979,7 @@ void Died()
//
if (curangle>iangle)
curangle -= ANGLES;
do
{
do {
change = tics*DEATHROTATE;
if (curangle + change > iangle)
change = iangle-curangle;
......@@ -996,8 +989,8 @@ void Died()
if (player->angle >= ANGLES)
player->angle -= ANGLES;
ThreeDRefresh ();
CalcTics ();
ThreeDRefresh();
CalcTics();
} while (curangle != iangle);
}
else
......
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