Commit 79356e2e authored by Steven Fuller's avatar Steven Fuller

Fixed map loading bug when you died (instead of returning the resource

itself, return a copy of the resource).

Updated res.c to do more work by making copies of resources and freeing the
copies when released.

Removed a few lines of unused code, etc

TODO: find where/why GameShapes (and/or the memory it is pointing to) is
getting trashed.
parent aa014f57
......@@ -642,24 +642,6 @@ void KillAResource(Word RezNum)
KillAResource2(RezNum, BRGR);
}
void SaveJunk(void *AckPtr,Word Length)
{
static Word Count=1;
FILE *fp;
char SaveName[40];
sprintf(SaveName,"SprRec%d",Count);
fp = fopen(SaveName,"wb");
fwrite(AckPtr,1,Length,fp);
fclose(fp);
++Count;
}
/**********************************
Kill a global resource
**********************************/
unsigned short SwapUShort(unsigned short Val)
{
return ((Val<<8) | (Val>>8));
......@@ -690,6 +672,7 @@ void DLZSS(Byte *Dest,Byte *Src,LongWord Length)
++Dest;
--Length;
} else {
/* TODO - sounds have this line the other way around */
RunCount = (Word) Src[0] | ((Word) Src[1]<<8);
Fun = 0x1000-(RunCount&0xfff);
BackPtr = Dest-Fun;
......@@ -720,9 +703,9 @@ void DLZSS(Byte *Dest,Byte *Src,LongWord Length)
**********************************/
/* TODO */
#include <sys/types.h>
#include <signal.h>
/* TODO - cheap way to find MSB problems */
#include <sys/types.h>
#include <signal.h>
void *AllocSomeMem(LongWord Size)
{
......@@ -732,33 +715,6 @@ void *AllocSomeMem(LongWord Size)
return (void *)malloc(Size);
}
/**********************************
Allocate some memory
**********************************/
static Word FreeStage(Word Stage,LongWord Size)
{
switch (Stage) {
case 1:
PurgeAllSounds(Size); /* Kill off sounds until I can get memory */
break;
case 2:
PlaySound(0); /* Shut down all sounds... */
PurgeAllSounds(Size); /* Purge them */
break;
case 3:
PlaySong(0); /* Kill music */
FreeSong(); /* Purge it */
PurgeAllSounds(Size); /* Make SURE it's gone! */
break;
case 4:
return 0;
}
return Stage+1;
}
/**********************************
Release some memory
......
......@@ -73,7 +73,6 @@ Byte *rw_texture;
LongWord rw_scale;
Byte *ArtData[64];
void *SpriteArray[S_LASTONE];
Word MacVidSize = -1;
Word SlowDown = 1; /* Force the game to 15 hz */
Word MouseEnabled = 0; /* Allow mouse control */
Word GameViewSize = 0; /* Size of the game screen */
......@@ -81,7 +80,6 @@ Word NoWeaponDraw=1; /* Flag to not draw the weapon on the screen */
maplist_t *MapListPtr; /* Pointer to map info record */
unsigned short *SongListPtr; /* Pointer to song list record */
unsigned short *WallListPtr; /* Pointer to wall list record */
Word MaxScaler = 1; /* Maximum number of VALID scalers */
Boolean ShowPush; /* Cheat for pushwalls */
Byte textures[MAPSIZE*2+5][MAPSIZE]; /* Texture indexes */
Word NaziSound[] = {SND_ESEE,SND_ESEE2,SND_ESEE3,SND_ESEE4};
......
......@@ -281,10 +281,14 @@ void SpawnStand(Word x,Word y,class_t which)
Word *TilePtr;
Word tile;
if (numactors >= MAXACTORS) {
fprintf("SpawnStand DEBUG (%d, %d)\n", numactors, MAXACTORS);
}
if (numactors==MAXACTORS) { /* Too many actors already? */
return; /* Exit */
}
EnemyHits[which] = 1;
info = &classinfo[which]; /* Get the pointer to the basic info */
state = info->standstate; /* Get the state logic value */
......@@ -324,6 +328,10 @@ void SpawnAmbush(Word x,Word y,class_t which)
{
actor_t *ActorPtr;
if (numactors >= MAXACTORS) {
fprintf("SpawnAmbush DEBUG (%d, %d)\n", numactors, MAXACTORS);
}
ActorPtr = &actors[numactors]; /* Get the pointer to the new actor entry */
SpawnStand(x,y,which); /* Fill in all the entries */
ActorPtr->flags |= FL_AMBUSH; /* Set the ambush flag */
......@@ -458,16 +466,19 @@ void SpawnThings(void)
Word *EnemyPtr;
memset(EnemyHits,0,sizeof(EnemyHits));
spawn_p = (Byte *)MapPtr+MapPtr->spawnlistofs; /* Point to the spawn table */
Count = MapPtr->numspawn; /* How many items to spawn? */
if (!Count) {
return;
}
do {
x = spawn_p[0]; /* Get the X */
y = spawn_p[1]; /* Get the y */
type = spawn_p[2]; /* Get the type */
spawn_p+=3; /* Index past the record */
if (type<19) {
continue;
} else if (type<23) { /* 19-22 */
......
......@@ -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
#CFLAGS = -g -DNOVGA
CFLAGS = -g
#CFLAGS = -Os -g
#CFLAGS = -g
CFLAGS = -Os -g
#CFLAGS = -g -Wall -I/home/relnev/cvs/oal/include
OBJS = Data.o Doors.o EnMove.o EnThink.o Intro.o Level.o \
......
* remove NOVGA when other ports are added. NOVGA is a hack for using
ElectricFence (since svgalib doesn't work too well with it)
* fix return value of DoEvents
* when you die, where do all the sprites go?
* drawing seems like its imprecise, stationary sprites move back and forth,
and walls 'swim' when you move around, or sprites pop into different sizes
when are far enough and get closer/farther away
* Word is 16bit damnit, wonder why in the MAC version its 32bits?!
* How about adding red/white shifts (from PC wolf3d)?
* it crashes somewhere, no reason why...
#0 0x804fa55 in DrawXMShape (x=128, y=96, ShapePtr=0x8c8c8c8c) at
Burger.c:198
But what is trashing GameShapes's memory?
I don't think GameShapes itself is being ran over, just the memory allocated
to it...
* Pause key
* menu type stuff in svgalib version (would use the Fx keys to save game
etc, text menus for options?)
* when saving/loading games, run them through htons/etc.
......@@ -296,7 +296,7 @@ void PrepPlayLoop (void)
Again:
ReleaseMap(); /* Oh oh... */
if (!GameViewSize) { /* Smallest screen? */
BailOut(); /* Leave... */
Quit("PrepPlayLoop failed"); /* Leave... */
}
--GameViewSize; /* Smaller screen size */
GameViewSize = NewGameWindow(GameViewSize);
......@@ -424,6 +424,7 @@ skipbrief:
ShowGetPsyched();
PrepPlayLoop(); /* Init internal variables */
EndGetPsyched();
FlushKeys();
PlayLoop(); /* Play the game */
if (playstate == EX_DIED) { /* Did you die? */
--gamestate.lives; /* Remove a life */
......
......@@ -93,4 +93,3 @@ void KillAResource(Word RezNum);
void *LoadAResource2(Word RezNum,LongWord Type);
void ReleaseAResource2(Word RezNum,LongWord Type);
void KillAResource2(Word RezNum,LongWord Type);
void SaveJunk(void *AckPtr,Word Length);
......@@ -9,6 +9,9 @@ typedef struct ResItem_t
Word item;
Byte *dat;
int size;
Byte *buf;
struct ResItem_t *next;
} ResItem;
......@@ -76,6 +79,8 @@ int InitResources(char *name)
t->dat = (Byte *)malloc(datalen);
fread(t->dat, datalen, 1, fp);
t->size = datalen;
t->buf = NULL;
*cur = t;
......@@ -97,12 +102,27 @@ void *LoadAResource2(Word RezNum, LongWord Type)
ResItem *c = lr;
while (c != NULL) {
if ( (c->type == Type) && (c->item == RezNum) )
return c->dat;
if ( (c->type == Type) && (c->item == RezNum) ) {
if (c->buf == NULL) {
c->buf = malloc(c->size);
memcpy(c->buf, c->dat, c->size);
} else {
/* DEBUG: we want a fresh copy... */
printf("DEBUG: Item %d/%d already loaded!\n", Type, RezNum);
free(c->buf);
c->buf = malloc(c->size);
memcpy(c->buf, c->dat, c->size);
}
if (c->buf == NULL)
Quit("MALLOC FAILED?");
return c->buf;
}
c = c->next;
}
fprintf(stderr, "ERROR: %ld/%d was not found!\n", Type, RezNum);
fprintf(stderr, "ERROR (LoadAResource2): %ld/%d was not found!\n", Type, RezNum);
AllocSomeMem(666666666); /* TODO: hack! */
exit(EXIT_FAILURE);
}
......@@ -112,17 +132,22 @@ void ReleaseAResource2(Word RezNum, LongWord Type)
ResItem *c = lr;
while (c != NULL) {
if ( (c->type == Type) && (c->item == RezNum) ) {
if (c->buf)
free(c->buf);
c->buf = NULL;
return;
}
c = c->next;
}
fprintf(stderr, "ERROR (ReleaseAResource2): %ld/%d was not found!\n", Type, RezNum);
AllocSomeMem(666666666); /* TODO: hack! */
exit(EXIT_FAILURE);
}
void KillAResource2(Word RezNum, LongWord Type)
{
ResItem *c = lr;
while (c != NULL) {
c = c->next;
}
ReleaseAResource2(RezNum, Type);
}
void FreeResources()
......@@ -135,6 +160,9 @@ void FreeResources()
if (c->dat)
free(c->dat);
if (c->buf)
free(c->buf);
c = c->next;
free(t);
......
......@@ -100,21 +100,25 @@ void DrawSmall(Word x,Word y,Word tile)
} while (++Height<16);
}
LongWord PsyTime;
void ShowGetPsyched(void)
{
LongWord *PackPtr;
Byte *ShapePtr;
LongWord PackLength;
Word X,Y;
PsyTime = ReadTick() + 60*2;
ClearTheScreen(BLACK);
BlastScreen();
PackPtr = LoadAResource(rGetPsychPic);
PackLength = lMSB(PackPtr[0]);
ShapePtr = AllocSomeMem(PackLength);
DLZSS(ShapePtr,(Byte *) &PackPtr[1],PackLength);
X = 10; /* TODO */
Y = 100;
X = (VidWidth-224)/2;
Y = (ViewHeight-56)/2;
DrawShape(X,Y,ShapePtr);
FreeSomeMem(ShapePtr);
ReleaseAResource(rGetPsychPic);
......@@ -130,6 +134,8 @@ void DrawPsyched(Word Index)
void EndGetPsyched(void)
{
while (PsyTime > ReadTick()) ;
SetAPalette(rBlackPal);
}
......@@ -242,12 +248,6 @@ void PurgeAllSounds(unsigned long minMemory)
{
}
void BailOut()
{
printf("BailOut()\n");
exit(1);
}
Word ChooseGameDiff(void)
{
/* 0 = easy, 1 = normal, 2 = hard, 3 = death incarnate */
......
......@@ -106,11 +106,14 @@ void BlastScreen()
int i;
#ifndef NOVGA
for (i = 0; i < 200; i++) {
memcpy(ptrd, ptrs, 320);
ptrs += w;
ptrd += 320;
}
/* memcpy(ptrd, ptrs, w * h); */
#endif
}
......@@ -120,6 +123,7 @@ Word VidVs[] = {160,320,320,400};
Word VidPics[] = {rFaceShapes,rFace512,rFace640,rFace640};
Word VidSize = -1;
int VidModes[] = { G320x200x256, G512x384x256, G640x400x256, G640x480x256 };
Word ScaleX(Word x)
{
switch(VidSize) {
......@@ -174,8 +178,15 @@ Word NewGameWindow(Word NewVidSize)
free(gfxbuf);
gfxbuf = (Byte *)malloc(w * h);
#ifndef NOVGA
/*
if (!vga_hasmode(VidModes[NewVidSize]))
Quit("SVGAlib does not support this mode");
vga_setmode(VidModes[NewVidSize]);
vga_setlinearaddressing();
*/
vga_setmode(G320x200x256);
#endif
......@@ -187,26 +198,24 @@ Word NewGameWindow(Word NewVidSize)
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(rFaceShapes);
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;
}
LongWord ScaleDiv[2048];
void ScaledDraw(Byte *gfx, Word scale, Byte *vid, LongWord TheFrac, Word TheInt, Word Width, LongWord Delta)
{
LongWord OldDelta;
......@@ -246,7 +255,7 @@ void IO_ScaleWallColumn(Word x, Word scale, Word tile, Word column)
}
y = (scale-VIEWHEIGHT)/2;
y = y*TheFrac;
y *= TheFrac;
TheInt = TheFrac>>24;
TheFrac <<= 8;
......@@ -279,8 +288,10 @@ void IO_ScaleMaskedColumn(Word x,Word scale, unsigned short *CharPtr,Word column
return;
CharPtr2 = (Byte *) CharPtr;
TheFrac = ScaleDiv[scale];
RunPtr = (SpriteRun *) &CharPtr[sMSB(CharPtr[column+1])/2];
TheFrac = 0x40000000/scale;
RunPtr = (SpriteRun *)&CharPtr[sMSB(CharPtr[column+1])/2];
Screenad = &VideoPointer[x];
TFrac = TheFrac<<8;
TInt = TheFrac>>24;
......@@ -288,14 +299,14 @@ void IO_ScaleMaskedColumn(Word x,Word scale, unsigned short *CharPtr,Word column
while (RunPtr->Topy != 0xFFFF) {
Y1 = scale*(LongWord)sMSB(RunPtr->Topy)/128+TopY;
if (Y1<(int)VIEWHEIGHT) {
if (Y1 < VIEWHEIGHT) {
Y2 = scale*(LongWord)sMSB(RunPtr->Boty)/128+TopY;
if (Y2>0) {
if (Y2>(int)VIEWHEIGHT)
if (Y2 > 0) {
if (Y2 > VIEWHEIGHT)
Y2 = VIEWHEIGHT;
Index = sMSB(RunPtr->Shape)+sMSB(RunPtr->Topy)/2;
Delta = 0;
if (Y1<0) {
if (Y1 < 0) {
Delta = (0-(LongWord)Y1)*TheFrac;
Index += (Delta>>24);
Delta <<= 8;
......@@ -311,17 +322,8 @@ void IO_ScaleMaskedColumn(Word x,Word scale, unsigned short *CharPtr,Word column
}
}
Boolean SetupScalers(void)
Boolean SetupScalers()
{
Word i;
if (!ScaleDiv[1]) {
i = 1;
do {
ScaleDiv[i] = 0x40000000/i;
} while (++i<2048);
MaxScaler = 2048;
}
return 1;
}
void ReleaseScalers()
......@@ -330,12 +332,14 @@ void ReleaseScalers()
/* Keyboard Hack */
static int RSJ;
static int keys[128];
void FlushKeys()
{
while (keyboard_update()) ;
joystick1 = 0;
memset(keys, 0, sizeof(keys));
}
......@@ -364,9 +368,9 @@ void keyboard_handler(int key, int press)
if (key == SCANCODE_ESCAPE)
Quit(0);
if (RSJ) {
keys[key] = press;
keys[key] = press;
if (RSJ) {
if (press == 0) {
for (i = 0; i < CheatCount; i++) {
if (CheatCodes[i].code[CheatIndex] == key) {
......@@ -512,24 +516,19 @@ void keyboard_handler(int key, int press)
void ReadSystemJoystick(void)
{
RSJ = 1;
//#ifndef NOVGA
keyboard_update();
//#endif
/* keyboard_update(); */
while (keyboard_update()) ;
}
/*
Handle events, and return:
last keypress (if any) in ascii
mouse button events == 1
zero means none of the above
*/
int DoEvents()
{
RSJ = 0;
//#ifndef NOVGA
keyboard_update();
//#endif
/* TODO: hack */
return 'B';
if (keyboard_update()) {
while (keyboard_update()) ;
if (keys[SCANCODE_B]) {
return 'B';
}
return 1;
}
return 0;
}
......@@ -59,7 +59,6 @@ typedef unsigned short ufixed_t; /* 8.8 unsigned fixed point number */
#define NUMBUTTONS 10 /* Number of control buttons */
#define WALLHEIGHT 128 /* Height,width of walls */
#define SPRITEHEIGHT 64 /* Height,width of a sprite */
#define MAXSCALER 960 /* Number of scalers to create */
#define PLAYERSIZE 88 /* radius of player in 8.8 fixed point */
#define PROJECTIONSCALE (SCREENWIDTH/2)*0x90l
......@@ -223,19 +222,6 @@ typedef enum { /* actor class info*/
enum {BSPTOP,BSPBOTTOM,BSPLEFT,BSPRIGHT}; /* BSP quadrants */
/**********************************
Compiled scaler
**********************************/
typedef struct {
unsigned short codeofs[WALLHEIGHT+1]; /* Entry to the code for sprites */
Byte FixA1[WALLHEIGHT+1]; /* A1 adjust for the screen */
Byte Pad[1]; /* Long word align it... */
Byte code[1]; /* Scaler code */
} t_compscale;
/**********************************
Status of the game (Save game record)
......@@ -543,12 +529,8 @@ extern Boolean rw_downside; /* True for dir_east and dir_south*/
extern Byte *ArtData[64];
extern Byte textures[MAPSIZE*2+5][MAPSIZE]; /* 0-63 is horizontal, 64-127 is vertical*/
extern void InitTools(void);
extern void BlastScreen(void);
extern void BlastScreen2(Rect *BlastRect);
extern void DoMacEvents(void);
extern void BailOut(void);
extern void GoodBye(void);
extern void ReadSystemJoystick(void);
extern Word NewGameWindow(Word NewVidSize);
extern void ShowGetPsyched(void);
......@@ -818,7 +800,6 @@ extern Word nummissiles; /* Number of active missiles */
extern missile_t missiles[MAXMISSILES]; /* Data for the missile items */
extern Word numactors; /* Number of active actors */
extern actor_t actors[MAXACTORS]; /* Data for the actors */
extern t_compscale *AllScalers[MAXSCALER]; /* Pointers to all the compiled scalers */
extern Byte **GameShapes; /* Pointer to the game shape array */
extern Word difficulty; /* 0 = easy, 1= normal, 2=hard*/
extern gametype_t gamestate; /* Status of the game (Save game) */
......@@ -863,7 +844,6 @@ extern Boolean areavis[MAXAREAS]; /* Area visible */
extern Word bspcoord[4]; /* Rect for the BSP search */
extern Word TicCount; /* Ticks since last screen draw */
extern Word LastTicCount; /* Tick value at start of render */
extern Word MacVidSize; /* Current 0 = 320, 1 = 512, 2 = 640 */
extern Word SlowDown; /* If true, then limit game to 30hz */
extern Word MouseEnabled; /* Allow mouse control */
extern Word GameViewSize; /* Size of the game screen */
......@@ -872,7 +852,6 @@ extern Word NoWeaponDraw; /* Flag to not draw the weapon on the screen */
extern maplist_t *MapListPtr; /* Pointer to map info record */
extern unsigned short *SongListPtr; /* Pointer to song list record */
extern unsigned short *WallListPtr; /* Pointer to wall list record */
extern Word MaxScaler; /* Maximum number of VALID scalers */
extern Word NaziSound[]; /* Sounds for nazis starting */
extern Boolean ShowPush; /* Cheat for showing pushwalls on automap */
......
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