Doom alpha 2

git-svn-id: svn://kolibrios.org@333 a494cfbc-eb01-0410-851d-a64ba20cac60
This commit is contained in:
Sergey Semyonov (Serge) 2007-02-08 22:53:29 +00:00
parent a89bf95159
commit c682e2d8c0
22 changed files with 4263 additions and 4763 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -28,8 +28,8 @@ rcsid[] = "$Id: f_finale.c,v 1.5 1997/02/03 21:26:34 b1 Exp $";
#include <ctype.h>
// Functions.
#include "m_swap.h"
#include "i_system.h"
#include "m_swap.h"
#include "z_zone.h"
#include "v_video.h"
#include "w_wad.h"

File diff suppressed because it is too large Load Diff

View File

@ -25,11 +25,10 @@ rcsid[] = "$Id: hu_lib.c,v 1.3 1997/01/26 07:44:58 b1 Exp $";
#include <ctype.h>
#include "m_swap.h"
#include "doomdef.h"
#include "v_video.h"
#include "m_swap.h"
#include "hu_lib.h"
#include "r_local.h"

View File

@ -17,31 +17,39 @@
// $Log:$
//
// DESCRIPTION:
// Main program, simply calls D_DoomMain high level loop.
// Main program, simply calls D_DoomMain high level loop.
//
//-----------------------------------------------------------------------------
static const char
rcsid[] = "$Id: i_main.c,v 1.4 1997/02/03 22:45:10 b1 Exp $";
//#include "SDL.h"
#include "doomdef.h"
#include "m_argv.h"
#include "d_main.h"
#include "kolibri.h"
int
main( int argc, char** argv)
int main(int argc, char **argv)
{
static char * tmp[]=
{"/hd/1/menuetos/doom/mdoom",
NULL};
// static char * tmp[]=
// {"/hd/1/menuetos/doom/mdoom",
// NULL};
myargc = 1;
myargv = tmp;
myargv = argv;
// chdir("/hd/1/menuetos/doom");
// InitHeap(32*1024*1024);
_asm
{
push ebx
push ecx
mov eax, 66
mov ebx, 1
mov ecx, 1
int 0x40
pop ecx
pop ebx
};
D_DoomMain ();

View File

@ -1,3 +1,4 @@
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
@ -9,6 +10,18 @@
#include "doomstat.h"
#include "i_net.h"
#ifdef DLHEAP
void* _cdecl dlmalloc(size_t);
void _cdecl dlfree(void*);
void _cdecl mf_init();
#define malloc dlmalloc
#define free dlfree
#define realloc dlrealloc
#endif
#ifndef B_HOST_IS_LENDIAN
#define B_HOST_IS_LENDIAN 1
#endif
@ -35,7 +48,7 @@
#endif
#endif
void NetSend (void);
void NetSend (void);
int NetListen (void);
@ -44,18 +57,19 @@ int NetListen (void);
//
#ifndef IPPORT_USERRESERVED
#define IPPORT_USERRESERVED 5000
#define IPPORT_USERRESERVED 5000
#endif
int DOOMPORT = (IPPORT_USERRESERVED+0x1d);
int sendsocket[MAXNETNODES];
int insocket;
int DOOMPORT = (IPPORT_USERRESERVED+0x1d);
int sendsocket[MAXNETNODES];
int insocket;
void (*netget) (void);
void (*netsend) (void);
void (*netget) (void);
void (*netsend) (void);
static int first_user_port=IPPORT_USERRESERVED+0x1D+0x10;
/**********
int GetAvailPort(void)
{
int i,d0;
@ -70,11 +84,11 @@ int GetAvailPort(void)
I_Error("Unable to get new port\n");
return -1;
}
**********/
int CreateInputUDPsocket(void)
{
int d0;
int d0=0;
//__asm__ __volatile__(
// "int $0x40"
// :"=a"(d0)
@ -109,6 +123,11 @@ void PacketSend (void)
{
int c;
doomdata_t sw;
//printf("ERROR Packet Send\n\r");
// byte swap
sw.checksum = htonl(netbuffer->checksum);
sw.player = netbuffer->player;
@ -158,11 +177,12 @@ int GetLocalAddress (void)
//
// I_InitNetwork
//
void I_InitNetwork (void)
{
boolean trueval = true;
int i;
int p;
boolean trueval = true;
int i;
int p;
doomcom = malloc (sizeof (*doomcom) );
memset (doomcom, 0, sizeof(*doomcom) );
@ -171,25 +191,25 @@ void I_InitNetwork (void)
i = M_CheckParm ("-dup");
if (i && i< myargc-1)
{
doomcom->ticdup = myargv[i+1][0]-'0';
if (doomcom->ticdup < 1)
doomcom->ticdup = 1;
if (doomcom->ticdup > 9)
doomcom->ticdup = 9;
doomcom->ticdup = myargv[i+1][0]-'0';
if (doomcom->ticdup < 1)
doomcom->ticdup = 1;
if (doomcom->ticdup > 9)
doomcom->ticdup = 9;
}
else
doomcom-> ticdup = 1;
doomcom-> ticdup = 1;
if (M_CheckParm ("-extratic"))
doomcom-> extratics = 1;
doomcom-> extratics = 1;
else
doomcom-> extratics = 0;
doomcom-> extratics = 0;
p = M_CheckParm ("-port");
if (p && p<myargc-1)
{
DOOMPORT = atoi (myargv[p+1]);
// __libclog_printf ("using alternate port %i\n",DOOMPORT);
DOOMPORT = atoi (myargv[p+1]);
// __libclog_printf ("using alternate port %i\n",DOOMPORT);
}
// parse network game options,
@ -198,13 +218,13 @@ void I_InitNetwork (void)
if (!i)
{
// single player game
netgame = false;
doomcom->id = DOOMCOM_ID;
doomcom->numplayers = doomcom->numnodes = 1;
doomcom->deathmatch = false;
doomcom->consoleplayer = 0;
return;
// single player game
netgame = false;
doomcom->id = DOOMCOM_ID;
doomcom->numplayers = doomcom->numnodes = 1;
doomcom->deathmatch = false;
doomcom->consoleplayer = 0;
return;
}
netsend = PacketSend;
@ -214,7 +234,7 @@ void I_InitNetwork (void)
// parse player number and host list
doomcom->consoleplayer = myargv[i+1][0]-'1';
doomcom->numnodes = 1; // this node for sure
doomcom->numnodes = 1; // this node for sure
doomcom->id = DOOMCOM_ID;
doomcom->numplayers = doomcom->numnodes;
sendsocket[0]=0;
@ -226,17 +246,21 @@ void I_InitNetwork (void)
// __libclog_printf("DOOM: Input UDP socket is %d\n",insocket);
}
void I_NetCmd (void)
{
//printf("ERROR NetCmd");
if (doomcom->command == CMD_SEND)
{
netsend ();
// netsend ();
}
else if (doomcom->command == CMD_GET)
{
netget ();
// netget ();
}
else
I_Error ("Bad net cmd: %i\n",doomcom->command);
I_Error ("Bad net cmd: %i\n",doomcom->command);
}

View File

@ -17,7 +17,7 @@
// $Log:$
//
// DESCRIPTION:
// System interface for sound.
// System interface for sound.
//
//-----------------------------------------------------------------------------
@ -55,37 +55,37 @@ rcsid[] = "$Id: i_unix.c,v 1.5 1997/02/03 22:45:10 b1 Exp $";
// Needed for calling the actual sound output.
#define SAMPLECOUNT 512
#define NUM_CHANNELS 16
#define SAMPLECOUNT 512
#define NUM_CHANNELS 16
// It is 2 for 16bit, and 2 for two channels.
#define BUFMUL 4
#define MIXBUFFERSIZE (SAMPLECOUNT*BUFMUL)
#define MIXBUFFERSIZE (SAMPLECOUNT*BUFMUL)
#define SAMPLERATE 11025 // Hz
#define SAMPLESIZE 2 // 16bit
#define SAMPLERATE 11025 // Hz
#define SAMPLESIZE 2 // 16bit
// The actual lengths of all sound effects.
int lengths[NUMSFX];
int lengths[NUMSFX];
// The actual output device.
int audio_fd;
int audio_fd;
// The global mixing buffer.
// Basically, samples from all active internal channels
// are modifed and added, and stored in the buffer
// that is submitted to the audio device.
signed short mixbuffer[MIXBUFFERSIZE];
signed short mixbuffer[MIXBUFFERSIZE];
// The channel step amount...
unsigned int channelstep[NUM_CHANNELS];
unsigned int channelstep[NUM_CHANNELS];
// ... and a 0.16 bit remainder of last step.
unsigned int channelstepremainder[NUM_CHANNELS];
unsigned int channelstepremainder[NUM_CHANNELS];
// The channel data pointers, start and end.
unsigned char* channels[NUM_CHANNELS];
unsigned char* channelsend[NUM_CHANNELS];
unsigned char* channels[NUM_CHANNELS];
unsigned char* channelsend[NUM_CHANNELS];
// Time/gametic that the channel started playing,
@ -93,27 +93,27 @@ unsigned char* channelsend[NUM_CHANNELS];
// has lowest priority.
// In case number of active sounds exceeds
// available channels.
int channelstart[NUM_CHANNELS];
int channelstart[NUM_CHANNELS];
// The sound in channel handles,
// determined on registration,
// might be used to unregister/stop/modify,
// currently unused.
int channelhandles[NUM_CHANNELS];
int channelhandles[NUM_CHANNELS];
// SFX id of the playing sound effect.
// Used to catch duplicates (like chainsaw).
int channelids[NUM_CHANNELS];
int channelids[NUM_CHANNELS];
// Pitch to stepping lookup, unused.
int steptable[256];
int steptable[256];
// Volume lookups.
int vol_lookup[128*256];
int vol_lookup[128*256];
// Hardware left and right channel volume lookup.
int* channelleftvol_lookup[NUM_CHANNELS];
int* channelrightvol_lookup[NUM_CHANNELS];
int* channelleftvol_lookup[NUM_CHANNELS];
int* channelrightvol_lookup[NUM_CHANNELS];
//
@ -155,7 +155,7 @@ void* getsfx (char* sfxname, int* len)
// Debug.
// fprintf( stderr, "." );
//fprintf( stderr, " -loading %s (lump %d, %d bytes)\n",
// sfxname, sfxlump, size );
// sfxname, sfxlump, size );
//fflush( stderr );
sfx = (unsigned char*)W_CacheLumpNum( sfxlump, PU_STATIC );
@ -193,54 +193,54 @@ void* getsfx (char* sfxname, int* len)
// Returns a handle.
//
static unsigned short handlenums = 0;
static unsigned short handlenums = 0;
int addsfx(int sfxid, int volume, int step, int seperation)
{
int i;
int rc = -1;
int i;
int rc = -1;
int oldest = gametic;
int oldestnum = 0;
int slot;
int oldest = gametic;
int oldestnum = 0;
int slot;
int rightvol;
int leftvol;
int rightvol;
int leftvol;
// Chainsaw troubles.
// Play these sound effects only one at a time.
if ( sfxid == sfx_sawup
|| sfxid == sfx_sawidl
|| sfxid == sfx_sawful
|| sfxid == sfx_sawhit
|| sfxid == sfx_stnmov
|| sfxid == sfx_pistol )
|| sfxid == sfx_sawidl
|| sfxid == sfx_sawful
|| sfxid == sfx_sawhit
|| sfxid == sfx_stnmov
|| sfxid == sfx_pistol )
{
// Loop all channels, check.
for (i=0 ; i<NUM_CHANNELS ; i++)
{
// Active, and using the same SFX?
if ( (channels[i])
&& (channelids[i] == sfxid) )
{
// Reset.
channels[i] = 0;
// We are sure that iff,
// there will only be one.
break;
}
}
// Loop all channels, check.
for (i=0 ; i<NUM_CHANNELS ; i++)
{
// Active, and using the same SFX?
if ( (channels[i])
&& (channelids[i] == sfxid) )
{
// Reset.
channels[i] = 0;
// We are sure that iff,
// there will only be one.
break;
}
}
}
// Loop all channels to find oldest SFX.
for (i=0; (i<NUM_CHANNELS) && (channels[i]); i++)
{
if (channelstart[i] < oldest)
{
oldestnum = i;
oldest = channelstart[i];
}
if (channelstart[i] < oldest)
{
oldestnum = i;
oldest = channelstart[i];
}
}
// Tales from the cryptic.
@ -248,9 +248,9 @@ int addsfx(int sfxid, int volume, int step, int seperation)
// If not, we simply overwrite the first one, 0.
// Probably only happens at startup.
if (i == NUM_CHANNELS)
slot = oldestnum;
slot = oldestnum;
else
slot = i;
slot = i;
// Okay, in the less recent channel,
// we will handle the new SFX.
@ -261,7 +261,7 @@ int addsfx(int sfxid, int volume, int step, int seperation)
// Reset current handle number, limited to 0..100.
if (!handlenums)
handlenums = 100;
handlenums = 100;
// Assign current handle number.
// Preserved so sounds could be stopped (unused).
@ -282,17 +282,17 @@ int addsfx(int sfxid, int volume, int step, int seperation)
// x^2 seperation,
// adjust volume properly.
leftvol =
volume - ((volume*seperation*seperation) >> 16); ///(256*256);
volume - ((volume*seperation*seperation) >> 16); ///(256*256);
seperation = seperation - 257;
rightvol =
volume - ((volume*seperation*seperation) >> 16);
volume - ((volume*seperation*seperation) >> 16);
// Sanity check, clamp volume.
if (rightvol < 0 || rightvol > 127)
I_Error("rightvol out of bounds");
I_Error("rightvol out of bounds");
if (leftvol < 0 || leftvol > 127)
I_Error("leftvol out of bounds");
I_Error("leftvol out of bounds");
// Get the proper lookup table piece
// for this volume level???
@ -321,10 +321,10 @@ void I_SetChannels()
// Init internal lookups (raw data, mixing buffer, channels).
// This function sets up internal lookups used during
// the mixing process.
int i;
int j;
int i;
int j;
int* steptablemid = steptable + 128;
int* steptablemid = steptable + 128;
// Okay, reset internal mixing channels to zero.
for (i=0; i<NUM_CHANNELS; i++)
@ -332,8 +332,8 @@ void I_SetChannels()
channels[i] = 0;
}
for (i=-128 ; i<128 ; i++)
steptablemid[i] = (int)(pow(2.0, (i/64.0))*65536.0);
// for (i=-128 ; i<128 ; i++)
// steptablemid[i] = (int)(pow(2.0, (i/64.0))*65536.0);
// Generates volume lookup tables
// which also turn the unsigned samples
@ -428,19 +428,19 @@ void I_UpdateSound( void )
// Mix current sound data.
// Data, from raw sound, for right and left.
register unsigned int sample;
register int dl;
register int dr;
register unsigned int sample;
register int dl;
register int dr;
// Pointers in global mixbuffer, left, right, end.
signed short* leftout;
signed short* rightout;
signed short* leftend;
signed short* leftout;
signed short* rightout;
signed short* leftend;
// Step in mixbuffer, left and right, thus two.
int step;
int step;
// Mixing channel index.
int chan;
int chan;
// Left and right channel
// are in global mixbuffer, alternating.
@ -457,65 +457,65 @@ void I_UpdateSound( void )
// that is 512 values for two channels.
while (leftout != leftend)
{
// Reset left/right value.
dl = 0;
dr = 0;
// Reset left/right value.
dl = 0;
dr = 0;
// Love thy L2 chache - made this a loop.
// Now more channels could be set at compile time
// as well. Thus loop those channels.
for ( chan = 0; chan < NUM_CHANNELS; chan++ )
{
// Check channel, if active.
if (channels[ chan ])
{
// Get the raw data from the channel.
sample = *channels[ chan ];
// Add left and right part
// for this channel (sound)
// to the current data.
// Adjust volume accordingly.
dl += channelleftvol_lookup[ chan ][sample];
dr += channelrightvol_lookup[ chan ][sample];
// Love thy L2 chache - made this a loop.
// Now more channels could be set at compile time
// as well. Thus loop those channels.
for ( chan = 0; chan < NUM_CHANNELS; chan++ )
{
// Check channel, if active.
if (channels[ chan ])
{
// Get the raw data from the channel.
sample = *channels[ chan ];
// Add left and right part
// for this channel (sound)
// to the current data.
// Adjust volume accordingly.
dl += channelleftvol_lookup[ chan ][sample];
dr += channelrightvol_lookup[ chan ][sample];
channelstepremainder[ chan ] += channelstep[ chan ];
channelstepremainder[ chan ] += channelstep[ chan ];
channels[ chan ] += channelstepremainder[ chan ] >> 16;
channels[ chan ] += channelstepremainder[ chan ] >> 16;
channelstepremainder[ chan ] &= 65536-1;
channelstepremainder[ chan ] &= 65536-1;
// Check whether we are done.
if (channels[ chan ] >= channelsend[ chan ])
channels[ chan ] = 0;
}
}
// Check whether we are done.
if (channels[ chan ] >= channelsend[ chan ])
channels[ chan ] = 0;
}
}
// Clamp to range. Left hardware channel.
// Has been char instead of short.
// if (dl > 127) *leftout = 127;
// else if (dl < -128) *leftout = -128;
// else *leftout = dl;
// Clamp to range. Left hardware channel.
// Has been char instead of short.
// if (dl > 127) *leftout = 127;
// else if (dl < -128) *leftout = -128;
// else *leftout = dl;
if (dl > 0x7fff)
*leftout = 0x7fff;
else if (dl < -0x8000)
*leftout = -0x8000;
else
*leftout = dl;
if (dl > 0x7fff)
*leftout = 0x7fff;
else if (dl < -0x8000)
*leftout = -0x8000;
else
*leftout = dl;
// Same for right hardware channel.
if (dr > 0x7fff)
*rightout = 0x7fff;
else if (dr < -0x8000)
*rightout = -0x8000;
else
*rightout = dr;
// Same for right hardware channel.
if (dr > 0x7fff)
*rightout = 0x7fff;
else if (dr < -0x8000)
*rightout = -0x8000;
else
*rightout = dr;
// Increment current pointers in mixbuffer.
leftout += step;
rightout += step;
// Increment current pointers in mixbuffer.
leftout += step;
rightout += step;
}
I_SubmitSound(mixbuffer);
// I_SubmitSound(mixbuffer);
}
@ -603,11 +603,11 @@ void I_InitSound()
// Still no music done.
// Remains. Dummies.
//
void I_InitMusic(void) { }
void I_ShutdownMusic(void) { }
void I_InitMusic(void) { }
void I_ShutdownMusic(void) { }
static int looping=0;
static int musicdies=-1;
static int looping=0;
static int musicdies=-1;
void I_PlaySong(int handle, int looping)
{

View File

@ -26,8 +26,6 @@ rcsid[] = "$Id: m_bbox.c,v 1.1 1997/02/03 22:45:10 b1 Exp $";
#include <stdlib.h>
#include <stdarg.h>
#include <ctype.h>
//#include "SDL.h"
//#include "SDL_timer.h"
#include "doomdef.h"
#include "m_misc.h"
@ -39,36 +37,23 @@ rcsid[] = "$Id: m_bbox.c,v 1.1 1997/02/03 22:45:10 b1 Exp $";
#include "i_system.h"
#include "kolibri.h"
int mb_used = 6;
int I_strncasecmp(char *str1, char *str2, int len)
{
char c1, c2;
while ( *str1 && *str2 && len-- ) {
c1 = *str1++;
c2 = *str2++;
if ( toupper(c1) != toupper(c2) )
return(1);
}
return(0);
}
int mb_used = 8;
void
I_Tactile
( int on,
int off,
int total )
( int on,
int off,
int total )
{
// UNUSED.
on = off = total = 0;
}
ticcmd_t emptycmd;
ticcmd_t* I_BaseTiccmd(void)
ticcmd_t emptycmd;
ticcmd_t* I_BaseTiccmd(void)
{
return &emptycmd;
}
@ -79,7 +64,7 @@ int I_GetHeapSize (void)
return mb_used*1024*1024;
}
byte* I_ZoneBase (int* size)
byte* I_ZoneBase (int* size)
{
*size = mb_used*1024*1024;
return (byte *) UserAlloc(*size);
@ -91,21 +76,17 @@ byte* I_ZoneBase (int* size)
// returns time in 1/35 second tics
//
__declspec(dllimport) unsigned int __stdcall GetTickCount(void);
int I_GetTime (void)
{
unsigned int tm;
// _asm
// {
// mov eax, 26
// mov ebx, 9
// int 0x40
// mov [tm], eax
// };
tm=GetTickCount()/10;
_asm
{ push ebx
mov eax, 26
mov ebx, 9
int 0x40
mov dword ptr [tm], eax
pop ebx
};
return (tm*TICRATE)/100;
}
@ -118,7 +99,7 @@ int I_GetTime (void)
void I_Init (void)
{
I_InitGraphics();
I_InitSound();
// I_InitSound();
}
//
@ -148,15 +129,16 @@ void I_EndRead(void)
{
}
byte* I_AllocLow(int length)
/***********
byte* I_AllocLow(int length)
{
byte* mem;
byte* mem;
mem = (byte *)malloc (length);
memset (mem,0,length);
return mem;
}
************/
//
// I_Error
@ -165,18 +147,18 @@ extern boolean demorecording;
void I_Error (char *error, ...)
{
va_list argptr;
va_list argptr;
// Message first.
va_start (argptr,error);
printf ("Error: ");
printf (argptr);
printf ("\n");
printf ("Error: ");
printf (error,argptr);
printf ("\n\r");
va_end (argptr);
// Shutdown. Here might be other errors.
if (demorecording)
G_CheckDemoStatus();
G_CheckDemoStatus();
D_QuitNetGame ();
I_ShutdownGraphics();

File diff suppressed because it is too large Load Diff

View File

@ -26,10 +26,8 @@ rcsid[] = "$Id: m_argv.c,v 1.1 1997/02/03 22:45:10 b1 Exp $";
#include <string.h>
#include "i_system.h"
int myargc;
char** myargv;
int myargc;
char** myargv;
@ -42,13 +40,13 @@ char** myargv;
// or 0 if not present
int M_CheckParm (char *check)
{
int i;
int i;
for (i = 1;i<myargc;i++)
{
if ( !I_strncasecmp(check, myargv[i], strlen(check)) )
return i;
}
if ( !strnicmp(check, myargv[i], strlen(check)) )
return i;
}
return 0;
}

View File

@ -18,9 +18,9 @@
// $Log:$
//
// DESCRIPTION:
// Main loop menu stuff.
// Default Config File.
// PCX Screenshots.
// Main loop menu stuff.
// Default Config File.
// PCX Screenshots.
//
//-----------------------------------------------------------------------------
@ -29,8 +29,9 @@ rcsid[] = "$Id: m_misc.c,v 1.6 1997/02/03 22:45:10 b1 Exp $";
#include <stdlib.h>
#include <ctype.h>
//#include "//kolibc.h"
extern int access(char *file, int mode);
//extern int access(char *file, int mode);
#include "doomdef.h"
@ -60,36 +61,36 @@ extern int access(char *file, int mode);
// Returns the final X coordinate
// HU_Init must have been called to init the font
//
extern patch_t* hu_font[HU_FONTSIZE];
extern patch_t* hu_font[HU_FONTSIZE];
int
M_DrawText
( int x,
int y,
boolean direct,
char* string )
( int x,
int y,
boolean direct,
char* string )
{
int c;
int w;
int c;
int w;
while (*string)
{
c = toupper(*string) - HU_FONTSTART;
string++;
if (c < 0 || c> HU_FONTSIZE)
{
x += 4;
continue;
}
c = toupper(*string) - HU_FONTSTART;
string++;
if (c < 0 || c> HU_FONTSIZE)
{
x += 4;
continue;
}
w = SHORT (hu_font[c]->width);
if (x+w > SCREENWIDTH)
break;
if (direct)
V_DrawPatchDirect(x, y, 0, hu_font[c]);
else
V_DrawPatch(x, y, 0, hu_font[c]);
x+=w;
w = SHORT (hu_font[c]->width);
if (x+w > SCREENWIDTH)
break;
if (direct)
V_DrawPatchDirect(x, y, 0, hu_font[c]);
else
V_DrawPatch(x, y, 0, hu_font[c]);
x+=w;
}
return x;
@ -107,23 +108,23 @@ M_DrawText
boolean
M_WriteFile
( char const* name,
void* source,
int length )
( char const* name,
void* source,
int length )
{
FILE *handle;
int count;
int count;
handle = fopen ( name, "wb");
if (handle == NULL)
return false;
return false;
count = fwrite (source, 1, length, handle);
// count = fwrite (source, 1, length, handle);
fclose (handle);
if (count < length)
return false;
return false;
return true;
}
@ -134,16 +135,19 @@ M_WriteFile
//
int
M_ReadFile
( char const* name,
byte** buffer )
( char const* name,
byte** buffer )
{
FILE *handle;
int count, length;
byte *buf;
byte *buf;
handle=0;
buf=0;
handle = fopen (name, "rb");
if (handle == NULL)
I_Error ("Couldn't read file %s", name);
I_Error ("Couldn't read file %s", name);
fseek(handle, 0, SEEK_END);
length = ftell(handle);
rewind(handle);
@ -152,7 +156,7 @@ M_ReadFile
fclose (handle);
if (count < length)
I_Error ("Couldn't read file %s", name);
I_Error ("Couldn't read file %s", name);
*buffer = buf;
return length;
@ -162,61 +166,61 @@ M_ReadFile
//
// DEFAULTS
//
int usemouse;
int usejoystick;
int usemouse;
int usejoystick;
extern int key_right;
extern int key_left;
extern int key_up;
extern int key_down;
extern int key_right;
extern int key_left;
extern int key_up;
extern int key_down;
extern int key_strafeleft;
extern int key_straferight;
extern int key_strafeleft;
extern int key_straferight;
extern int key_fire;
extern int key_use;
extern int key_strafe;
extern int key_speed;
extern int key_fire;
extern int key_use;
extern int key_strafe;
extern int key_speed;
extern int mousebfire;
extern int mousebstrafe;
extern int mousebforward;
extern int mousebfire;
extern int mousebstrafe;
extern int mousebforward;
extern int joybfire;
extern int joybstrafe;
extern int joybuse;
extern int joybspeed;
extern int joybfire;
extern int joybstrafe;
extern int joybuse;
extern int joybspeed;
extern int viewwidth;
extern int viewheight;
extern int viewwidth;
extern int viewheight;
extern int mouseSensitivity;
extern int showMessages;
extern int mouseSensitivity;
extern int showMessages;
extern int detailLevel;
extern int detailLevel;
extern int screenblocks;
extern int screenblocks;
extern int showMessages;
extern int showMessages;
// machine-independent sound params
extern int numChannels;
extern int numChannels;
extern char* chat_macros[];
extern char* chat_macros[];
typedef struct
{
char* name;
int* location;
int defaultvalue;
int scantranslate; // PC scan code hack
int untranslated; // lousy hack
char* name;
int* location;
int defaultvalue;
int scantranslate; // PC scan code hack
int untranslated; // lousy hack
} default_t;
default_t defaults[] =
default_t defaults[] =
{
{"mouse_sensitivity",&mouseSensitivity, 5},
{"sfx_volume",&snd_SfxVolume, 8},
@ -228,6 +232,12 @@ default_t defaults[] =
{"key_left",&key_left, KEY_LEFTARROW},
{"key_up",&key_up, KEY_UPARROW},
{"key_down",&key_down, KEY_DOWNARROW},
// {"key_right",&key_right, KEY_D},
// {"key_left",&key_left, KEY_A},
// {"key_up",&key_up, KEY_W},
// {"key_down",&key_down, KEY_S},
{"key_strafeleft",&key_strafeleft, ','},
{"key_straferight",&key_straferight, '.'},
@ -271,8 +281,8 @@ default_t defaults[] =
};
int numdefaults;
char* defaultfile;
int numdefaults;
char* defaultfile;
//
@ -280,25 +290,25 @@ char* defaultfile;
//
void M_SaveDefaults (void)
{
int i;
int v;
FILE* f;
int i;
int v;
FILE* f;
f = fopen (defaultfile, "w");
if (!f)
return; // can't write the file, but don't complain
return; // can't write the file, but don't complain
for (i=0 ; i<numdefaults ; i++)
{
if (defaults[i].defaultvalue > -0xfff
&& defaults[i].defaultvalue < 0xfff)
{
v = *defaults[i].location;
printf ("%s\t\t%i\n",defaults[i].name,v);
} else {
printf ("%s\t\t\"%s\"\n",defaults[i].name,
* (char **) (defaults[i].location));
}
if (defaults[i].defaultvalue > -0xfff
&& defaults[i].defaultvalue < 0xfff)
{
v = *defaults[i].location;
printf ("%s\t\t%i\n",defaults[i].name,v);
} else {
printf ("%s\t\t\"%s\"\n",defaults[i].name,
* (char **) (defaults[i].location));
}
}
fclose (f);
@ -308,73 +318,88 @@ void M_SaveDefaults (void)
//
// M_LoadDefaults
//
extern byte scantokey[128];
extern byte scantokey[128];
size_t FileSize(FILE *handle);
void M_LoadDefaults (void)
{
int i;
int len;
FILE* f;
char def[80];
char strparm[100];
char* newstring;
int parm;
boolean isstring;
int i;
int len;
FILE* f;
char def[80];
char strparm[100];
char* newstring;
int parm;
boolean isstring;
char *buf;
char *p;
size_t val;
// set everything to base values
numdefaults = sizeof(defaults)/sizeof(defaults[0]);
for (i=0 ; i<numdefaults ; i++)
*defaults[i].location = defaults[i].defaultvalue;
*defaults[i].location = defaults[i].defaultvalue;
// check for a custom default file
i = M_CheckParm ("-config");
if (i && i<myargc-1)
{
defaultfile = myargv[i+1];
// __libclog_printf (" default file: %s\n",defaultfile);
defaultfile = myargv[i+1];
// __libclog_printf (" default file: %s\n",defaultfile);
}
else
defaultfile = basedefault;
/**********
defaultfile = basedefault;
// read the file in, overriding any set defaults
f = fopen (defaultfile, "r");
f = fopen (defaultfile, "rb");
if (f)
{
while (!feof(f))
{
isstring = false;
if (fscanf (f, "%79s %[^\n]\n", def, strparm) == 2)
{
if (strparm[0] == '"')
{
// get a string default
isstring = true;
len = strlen(strparm);
newstring = (char *) malloc(len);
strparm[len-1] = 0;
strcpy(newstring, strparm+1);
}
else if (strparm[0] == '0' && strparm[1] == 'x')
sscanf(strparm+2, "%x", &parm);
else
sscanf(strparm, "%i", &parm);
for (i=0 ; i<numdefaults ; i++)
if (!strcmp(def, defaults[i].name))
{
if (!isstring)
*defaults[i].location = parm;
else
*defaults[i].location =
(int) newstring;
break;
}
}
}
len=FileSize(f)+1;
buf = malloc(len);
memset(buf,0,len);
val = fread(buf,1,len,f);
fclose (f);
p = buf;
while(*p)
{
isstring = false;
if (sscanf (p, "%79s %[^\n]\n", def, strparm) == 2)
{
if (strparm[0] == '"')
{
// get a string default
isstring = true;
len = strlen(strparm);
newstring = (char *) malloc(len);
strparm[len-1] = 0;
strcpy(newstring, strparm+1);
}
else
if (strparm[0] == '0' && strparm[1] == 'x')
sscanf(strparm+2, "%x", &parm);
else
sscanf(strparm, "%i", &parm);
for (i=0 ; i<numdefaults ; i++)
if (!strcmp(def, defaults[i].name))
{
if (!isstring)
*defaults[i].location = parm;
else
*defaults[i].location = (int) newstring;
break;
}
};
p=strchr(p, '\n')+1;
};
free(buf);
};
};
fclose (f);
}
**********/
}
//
@ -384,28 +409,28 @@ void M_LoadDefaults (void)
typedef struct
{
char manufacturer;
char version;
char encoding;
char bits_per_pixel;
char manufacturer;
char version;
char encoding;
char bits_per_pixel;
unsigned short xmin;
unsigned short ymin;
unsigned short xmax;
unsigned short ymax;
unsigned short xmin;
unsigned short ymin;
unsigned short xmax;
unsigned short ymax;
unsigned short hres;
unsigned short vres;
unsigned short hres;
unsigned short vres;
unsigned char palette[48];
unsigned char palette[48];
char reserved;
char color_planes;
unsigned short bytes_per_line;
unsigned short palette_type;
char reserved;
char color_planes;
unsigned short bytes_per_line;
unsigned short palette_type;
char filler[58];
unsigned char data; // unbounded
char filler[58];
unsigned char data; // unbounded
} pcx_t;
@ -414,23 +439,23 @@ typedef struct
//
void
WritePCXfile
( char* filename,
byte* data,
int width,
int height,
byte* palette )
( char* filename,
byte* data,
int width,
int height,
byte* palette )
{
int i;
int length;
pcx_t* pcx;
byte* pack;
int i;
int length;
pcx_t* pcx;
byte* pack;
pcx = Z_Malloc (width*height*2+1000, PU_STATIC, NULL);
pcx->manufacturer = 0x0a; // PCX id
pcx->version = 5; // 256 color
pcx->encoding = 1; // uncompressed
pcx->bits_per_pixel = 8; // 256 color
pcx->manufacturer = 0x0a; // PCX id
pcx->version = 5; // 256 color
pcx->encoding = 1; // uncompressed
pcx->bits_per_pixel = 8; // 256 color
pcx->xmin = 0;
pcx->ymin = 0;
pcx->xmax = SHORT(width-1);
@ -438,9 +463,9 @@ WritePCXfile
pcx->hres = SHORT(width);
pcx->vres = SHORT(height);
memset (pcx->palette,0,sizeof(pcx->palette));
pcx->color_planes = 1; // chunky image
pcx->color_planes = 1; // chunky image
pcx->bytes_per_line = SHORT(width);
pcx->palette_type = SHORT(2); // not a grey scale
pcx->palette_type = SHORT(2); // not a grey scale
memset (pcx->filler,0,sizeof(pcx->filler));
@ -449,19 +474,19 @@ WritePCXfile
for (i=0 ; i<width*height ; i++)
{
if ( (*data & 0xc0) != 0xc0)
*pack++ = *data++;
else
{
*pack++ = 0xc1;
*pack++ = *data++;
}
if ( (*data & 0xc0) != 0xc0)
*pack++ = *data++;
else
{
*pack++ = 0xc1;
*pack++ = *data++;
}
}
// write the palette
*pack++ = 0x0c; // palette ID byte
*pack++ = 0x0c; // palette ID byte
for (i=0 ; i<768 ; i++)
*pack++ = *palette++;
*pack++ = *palette++;
// write output file
length = pack - (byte *)pcx;
@ -476,9 +501,9 @@ WritePCXfile
//
void M_ScreenShot (void)
{
int i;
byte* linear;
char lbmname[12];
int i;
byte* linear;
char lbmname[12];
// munge planar buffer to linear
linear = screens[2];
@ -489,18 +514,18 @@ void M_ScreenShot (void)
for (i=0 ; i<=99 ; i++)
{
lbmname[4] = i/10 + '0';
lbmname[5] = i%10 + '0';
if (access(lbmname,0) == -1)
break; // file doesn't exist
lbmname[4] = i/10 + '0';
lbmname[5] = i%10 + '0';
if (access(lbmname,0) == -1)
break; // file doesn't exist
}
if (i==100)
I_Error ("M_ScreenShot: Couldn't create a PCX");
I_Error ("M_ScreenShot: Couldn't create a PCX");
// save the pcx file
WritePCXfile (lbmname, linear,
SCREENWIDTH, SCREENHEIGHT,
W_CacheLumpName ("PLAYPAL",PU_CACHE));
SCREENWIDTH, SCREENHEIGHT,
W_CacheLumpName ("PLAYPAL",PU_CACHE));
players[consoleplayer].message = "screen shot";
}

View File

@ -31,6 +31,9 @@ rcsid[] = "$Id: m_bbox.c,v 1.1 1997/02/03 22:45:10 b1 Exp $";
#include "m_swap.h"
// Not needed with big endian.
#ifndef __BIG_ENDIAN__
// Swap 16bit, that is, MSB and LSB byte.
unsigned short SwapSHORT(unsigned short x)
{
@ -49,3 +52,6 @@ unsigned long SwapLONG( unsigned long x)
}
#endif

View File

@ -18,8 +18,8 @@
//
// Revision 1.3 1997/01/29 20:10
// DESCRIPTION:
// Preparation of data for rendering,
// generation of lookups, caching, retrieval by name.
// Preparation of data for rendering,
// generation of lookups, caching, retrieval by name.
//
//-----------------------------------------------------------------------------
@ -27,19 +27,11 @@
static const char
rcsid[] = "$Id: r_data.c,v 1.4 1997/02/03 16:47:55 b1 Exp $";
#ifdef __BEOS__
#ifdef __GNUC__
extern void *alloca(int);
#else
#include <alloca.h>
#endif
#endif /* __BEOS__ */
#include "m_swap.h"
#include "i_system.h"
#include "z_zone.h"
#include "m_swap.h"
#include "w_wad.h"
#include "doomdef.h"
@ -49,8 +41,11 @@ extern void *alloca(int);
#include "doomstat.h"
#include "r_sky.h"
#include <malloc.h>
#include "r_data.h"
#include <malloc.h>
//
// Graphics.
// DOOM graphics for walls and sprites
@ -71,11 +66,11 @@ extern void *alloca(int);
//
typedef struct
{
short originx;
short originy;
short patch;
short stepdir;
short colormap;
short originx;
short originy;
short patch;
short stepdir;
short colormap;
} mappatch_t;
@ -86,13 +81,13 @@ typedef struct
//
typedef struct
{
char name[8];
int masked;
short width;
short height;
void **columndirectory; // OBSOLETE
short patchcount;
mappatch_t patches[1];
char name[8];
int masked;
short width;
short height;
void **columndirectory; // OBSOLETE
short patchcount;
mappatch_t patches[1];
} maptexture_t;
@ -104,9 +99,9 @@ typedef struct
// Block origin (allways UL),
// which has allready accounted
// for the internal origin of the patch.
int originx;
int originy;
int patch;
int originx;
int originy;
int patch;
} texpatch_t;
@ -116,53 +111,53 @@ typedef struct
typedef struct
{
// Keep name for switch changing, etc.
char name[8];
short int width;
short int height;
char name[8];
short int width;
short int height;
// All the patches[patchcount]
// are drawn back to front into the cached texture.
short patchcount;
texpatch_t patches[1];
short int patchcount;
texpatch_t patches[1];
} texture_t;
int firstflat;
int lastflat;
int numflats;
int firstflat;
int lastflat;
int numflats;
int firstpatch;
int lastpatch;
int numpatches;
int firstpatch;
int lastpatch;
int numpatches;
int firstspritelump;
int lastspritelump;
int numspritelumps;
int firstspritelump;
int lastspritelump;
int numspritelumps;
int numtextures;
texture_t** textures;
int numtextures;
texture_t** textures;
int* texturewidthmask;
int* texturewidthmask;
// needed for texture pegging
fixed_t* textureheight;
int* texturecompositesize;
short** texturecolumnlump;
unsigned short** texturecolumnofs;
byte** texturecomposite;
fixed_t* textureheight;
int* texturecompositesize;
short** texturecolumnlump;
unsigned short** texturecolumnofs;
byte** texturecomposite;
// for global animation
int* flattranslation;
int* texturetranslation;
int* flattranslation;
int* texturetranslation;
// needed for pre rendering
fixed_t* spritewidth;
fixed_t* spriteoffset;
fixed_t* spritetopoffset;
fixed_t* spritewidth;
fixed_t* spriteoffset;
fixed_t* spritetopoffset;
lighttable_t *colormaps;
lighttable_t *colormaps;
//
@ -186,37 +181,37 @@ lighttable_t *colormaps;
//
void
R_DrawColumnInCache
( column_t* patch,
byte* cache,
int originy,
int cacheheight )
( column_t* patch,
byte* cache,
int originy,
int cacheheight )
{
int count;
int position;
byte* source;
byte* dest;
int count;
int position;
byte* source;
byte* dest;
dest = (byte *)cache + 3;
while (patch->topdelta != 0xff)
{
source = (byte *)patch + 3;
count = patch->length;
position = originy + patch->topdelta;
source = (byte *)patch + 3;
count = patch->length;
position = originy + patch->topdelta;
if (position < 0)
{
count += position;
position = 0;
}
if (position < 0)
{
count += position;
position = 0;
}
if (position + count > cacheheight)
count = cacheheight - position;
if (position + count > cacheheight)
count = cacheheight - position;
if (count > 0)
memcpy (cache + position, source, count);
if (count > 0)
memcpy (cache + position, source, count);
patch = (column_t *)( (byte *)patch + patch->length + 4);
patch = (column_t *)( (byte *)patch + patch->length + 4);
}
}
@ -230,23 +225,23 @@ R_DrawColumnInCache
//
void R_GenerateComposite (int texnum)
{
byte* block;
texture_t* texture;
texpatch_t* patch;
patch_t* realpatch;
int x;
int x1;
int x2;
int i;
column_t* patchcol;
short* collump;
unsigned short* colofs;
byte* block;
texture_t* texture;
texpatch_t* patch;
patch_t* realpatch;
int x;
int x1;
int x2;
int i;
column_t* patchcol;
short* collump;
unsigned short* colofs;
texture = textures[texnum];
block = Z_Malloc (texturecompositesize[texnum],
PU_STATIC,
&texturecomposite[texnum]);
PU_STATIC,
&texturecomposite[texnum]);
collump = texturecolumnlump[texnum];
colofs = texturecolumnofs[texnum];
@ -255,34 +250,34 @@ void R_GenerateComposite (int texnum)
patch = texture->patches;
for (i=0 , patch = texture->patches;
i<texture->patchcount;
i++, patch++)
i<texture->patchcount;
i++, patch++)
{
realpatch = W_CacheLumpNum (patch->patch, PU_CACHE);
x1 = patch->originx;
x2 = x1 + SHORT(realpatch->width);
realpatch = W_CacheLumpNum (patch->patch, PU_CACHE);
x1 = patch->originx;
x2 = x1 + SHORT(realpatch->width);
if (x1<0)
x = 0;
else
x = x1;
if (x1<0)
x = 0;
else
x = x1;
if (x2 > texture->width)
x2 = texture->width;
if (x2 > texture->width)
x2 = texture->width;
for ( ; x<x2 ; x++)
{
// Column does not have multiple patches?
if (collump[x] >= 0)
continue;
for ( ; x<x2 ; x++)
{
// Column does not have multiple patches?
if (collump[x] >= 0)
continue;
patchcol = (column_t *)((byte *)realpatch
+ LONG(realpatch->columnofs[x-x1]));
R_DrawColumnInCache (patchcol,
block + colofs[x],
patch->originy,
texture->height);
}
patchcol = (column_t *)((byte *)realpatch
+ LONG(realpatch->columnofs[x-x1]));
R_DrawColumnInCache (patchcol,
block + colofs[x],
patch->originy,
texture->height);
}
}
@ -291,21 +286,23 @@ void R_GenerateComposite (int texnum)
Z_ChangeTag (block, PU_CACHE);
}
//
// R_GenerateLookup
//
void R_GenerateLookup (int texnum)
{
texture_t* texture;
byte* patchcount; // patchcount[texture->width]
texpatch_t* patch;
patch_t* realpatch;
int x;
int x1;
int x2;
int i;
short* collump;
unsigned short* colofs;
texture_t* texture;
byte* patchcount; // patchcount[texture->width]
texpatch_t* patch;
patch_t* realpatch;
int x;
int x1;
int x2;
int i;
short* collump;
unsigned short* colofs;
texture = textures[texnum];
@ -325,52 +322,52 @@ void R_GenerateLookup (int texnum)
patch = texture->patches;
for (i=0 , patch = texture->patches;
i<texture->patchcount;
i++, patch++)
i<texture->patchcount;
i++, patch++)
{
realpatch = W_CacheLumpNum (patch->patch, PU_CACHE);
x1 = patch->originx;
x2 = x1 + SHORT(realpatch->width);
realpatch = W_CacheLumpNum (patch->patch, PU_CACHE);
x1 = patch->originx;
x2 = x1 + SHORT(realpatch->width);
if (x1 < 0)
x = 0;
else
x = x1;
if (x1 < 0)
x = 0;
else
x = x1;
if (x2 > texture->width)
x2 = texture->width;
for ( ; x<x2 ; x++)
{
patchcount[x]++;
collump[x] = patch->patch;
colofs[x] = LONG(realpatch->columnofs[x-x1])+3;
}
if (x2 > texture->width)
x2 = texture->width;
for ( ; x<x2 ; x++)
{
patchcount[x]++;
collump[x] = patch->patch;
colofs[x] = LONG(realpatch->columnofs[x-x1])+3;
}
}
for (x=0 ; x<texture->width ; x++)
{
if (!patchcount[x])
{
printf("R_GenerateLookup: column without a patch (%s)\n",
texture->name);
return;
}
// I_Error ("R_GenerateLookup: column without a patch");
if (!patchcount[x])
{
printf ("R_GenerateLookup: column without a patch (%s)\n",
texture->name);
return;
}
// I_Error ("R_GenerateLookup: column without a patch");
if (patchcount[x] > 1)
{
// Use the cached block.
collump[x] = -1;
colofs[x] = texturecompositesize[texnum];
if (patchcount[x] > 1)
{
// Use the cached block.
collump[x] = -1;
colofs[x] = texturecompositesize[texnum];
if (texturecompositesize[texnum] > 0x10000-texture->height)
{
I_Error ("R_GenerateLookup: texture %i is >64k",
texnum);
}
if (texturecompositesize[texnum] > 0x10000-texture->height)
{
I_Error ("R_GenerateLookup: texture %i is >64k",
texnum);
}
texturecompositesize[texnum] += texture->height;
}
texturecompositesize[texnum] += texture->height;
}
}
}
@ -382,21 +379,21 @@ void R_GenerateLookup (int texnum)
//
byte*
R_GetColumn
( int tex,
int col )
( int tex,
int col )
{
int lump;
int ofs;
int lump;
int ofs;
col &= texturewidthmask[tex];
lump = texturecolumnlump[tex][col];
ofs = texturecolumnofs[tex][col];
if (lump > 0)
return (byte *)W_CacheLumpNum(lump,PU_CACHE)+ofs;
return (byte *)W_CacheLumpNum(lump,PU_CACHE)+ofs;
if (!texturecomposite[tex])
R_GenerateComposite (tex);
R_GenerateComposite (tex);
return texturecomposite[tex] + ofs;
}
@ -411,37 +408,37 @@ R_GetColumn
//
void R_InitTextures (void)
{
maptexture_t* mtexture;
texture_t* texture;
mappatch_t* mpatch;
texpatch_t* patch;
maptexture_t* mtexture;
texture_t* texture;
mappatch_t* mpatch;
texpatch_t* patch;
int i;
int j;
int i;
int j;
int* maptex;
int* maptex2;
int* maptex1;
int* maptex;
int* maptex2;
int* maptex1;
char name[9];
char* names;
char* name_p;
char name[9];
char* names;
char* name_p;
int* patchlookup;
int* patchlookup;
int totalwidth;
int nummappatches;
int offset;
int maxoff;
int maxoff2;
int numtextures1;
int numtextures2;
int totalwidth;
int nummappatches;
int offset;
int maxoff;
int maxoff2;
int numtextures1;
int numtextures2;
int* directory;
int* directory;
int temp1;
int temp2;
int temp3;
int temp1;
int temp2;
int temp3;
// Load the patch names from pnames.lmp.
@ -453,8 +450,8 @@ void R_InitTextures (void)
for (i=0 ; i<nummappatches ; i++)
{
strncpy (name,name_p+i*8, 8);
patchlookup[i] = W_CheckNumForName (name);
strncpy (name,name_p+i*8, 8);
patchlookup[i] = W_CheckNumForName (name);
}
Z_Free (names);
@ -468,15 +465,15 @@ void R_InitTextures (void)
if (W_CheckNumForName ("TEXTURE2") != -1)
{
maptex2 = W_CacheLumpName ("TEXTURE2", PU_STATIC);
numtextures2 = LONG(*maptex2);
maxoff2 = W_LumpLength (W_GetNumForName ("TEXTURE2"));
maptex2 = W_CacheLumpName ("TEXTURE2", PU_STATIC);
numtextures2 = LONG(*maptex2);
maxoff2 = W_LumpLength (W_GetNumForName ("TEXTURE2"));
}
else
{
maptex2 = NULL;
numtextures2 = 0;
maxoff2 = 0;
maptex2 = NULL;
numtextures2 = 0;
maxoff2 = 0;
}
numtextures = numtextures1 + numtextures2;
@ -490,98 +487,88 @@ void R_InitTextures (void)
totalwidth = 0;
// Really complex printing shit...
// Really complex printing shit...
temp1 = W_GetNumForName ("S_START"); // P_???????
temp2 = W_GetNumForName ("S_END") - 1;
temp3 = ((temp2-temp1+63)/64) + ((numtextures+63)/64);
printf("[");
for (i = 0; i < temp3; i++)
printf(" ");
printf(" ");
printf(" ]");
for (i = 0; i < temp3; i++)
printf("\x8");
printf("\x8");
printf("\x8\x8\x8\x8\x8\x8\x8\x8\x8\x8");
for (i=0 ; i<numtextures ; i++, directory++)
{
if (!(i&63))
printf (".");
if (!(i&63))
printf (".");
if (i == numtextures1)
{
// Start looking in second texture file.
maptex = maptex2;
maxoff = maxoff2;
directory = maptex+1;
}
if (i == numtextures1)
{
// Start looking in second texture file.
maptex = maptex2;
maxoff = maxoff2;
directory = maptex+1;
}
offset = LONG(*directory);
offset = LONG(*directory);
if (offset > maxoff)
I_Error ("R_InitTextures: bad texture directory");
if (offset > maxoff)
I_Error ("R_InitTextures: bad texture directory");
mtexture = (maptexture_t *) ( (byte *)maptex + offset);
mtexture = (maptexture_t *) ( (byte *)maptex + offset);
texture = textures[i] =
Z_Malloc (sizeof(texture_t)
+ sizeof(texpatch_t)*(SHORT(mtexture->patchcount)-1),
PU_STATIC, 0);
texture = textures[i] =
Z_Malloc (sizeof(texture_t)
+ sizeof(texpatch_t)*(SHORT(mtexture->patchcount)-1),
PU_STATIC, 0);
texture->width = SHORT(mtexture->width);
texture->height = SHORT(mtexture->height);
texture->patchcount = SHORT(mtexture->patchcount);
texture->width = SHORT(mtexture->width);
texture->height = SHORT(mtexture->height);
texture->patchcount = SHORT(mtexture->patchcount);
// memcpy() generates a BUS error on Solaris with optimization on */
#if 1
memcpy (texture->name, mtexture->name, sizeof(texture->name));
#else
{ char *src; char *dst;
src = (char *)mtexture->name;
dst = (char *)texture->name;
for (j=0; j<sizeof(texture->name); ++j )
*dst++ = *src++;
}
#endif
mpatch = &mtexture->patches[0];
patch = &texture->patches[0];
memcpy (texture->name, mtexture->name, sizeof(texture->name));
mpatch = &mtexture->patches[0];
patch = &texture->patches[0];
for (j=0 ; j<texture->patchcount ; j++, mpatch++, patch++)
{
patch->originx = SHORT(mpatch->originx);
patch->originy = SHORT(mpatch->originy);
patch->patch = patchlookup[SHORT(mpatch->patch)];
if (patch->patch == -1)
{
I_Error ("R_InitTextures: Missing patch in texture %s",
texture->name);
}
}
texturecolumnlump[i] = Z_Malloc (texture->width*2, PU_STATIC,0);
texturecolumnofs[i] = Z_Malloc (texture->width*2, PU_STATIC,0);
for (j=0 ; j<texture->patchcount ; j++, mpatch++, patch++)
{
patch->originx = SHORT(mpatch->originx);
patch->originy = SHORT(mpatch->originy);
patch->patch = patchlookup[SHORT(mpatch->patch)];
if (patch->patch == -1)
{
I_Error ("R_InitTextures: Missing patch in texture %s",
texture->name);
}
}
texturecolumnlump[i] = Z_Malloc (texture->width*2, PU_STATIC,0);
texturecolumnofs[i] = Z_Malloc (texture->width*2, PU_STATIC,0);
j = 1;
while (j*2 <= texture->width)
j<<=1;
j = 1;
while (j*2 <= texture->width)
j<<=1;
texturewidthmask[i] = j-1;
textureheight[i] = texture->height<<FRACBITS;
texturewidthmask[i] = j-1;
textureheight[i] = texture->height<<FRACBITS;
totalwidth += texture->width;
totalwidth += texture->width;
}
Z_Free (maptex1);
if (maptex2)
Z_Free (maptex2);
Z_Free (maptex2);
// Precalculate whatever possible.
for (i=0 ; i<numtextures ; i++)
R_GenerateLookup (i);
R_GenerateLookup (i);
// Create translation table for global animation.
texturetranslation = Z_Malloc ((numtextures+1)*4, PU_STATIC, 0);
for (i=0 ; i<numtextures ; i++)
texturetranslation[i] = i;
texturetranslation[i] = i;
}
@ -591,7 +578,7 @@ void R_InitTextures (void)
//
void R_InitFlats (void)
{
int i;
int i;
firstflat = W_GetNumForName ("F_START") + 1;
lastflat = W_GetNumForName ("F_END") - 1;
@ -601,7 +588,7 @@ void R_InitFlats (void)
flattranslation = Z_Malloc ((numflats+1)*4, PU_STATIC, 0);
for (i=0 ; i<numflats ; i++)
flattranslation[i] = i;
flattranslation[i] = i;
}
@ -613,8 +600,8 @@ void R_InitFlats (void)
//
void R_InitSpriteLumps (void)
{
int i;
patch_t *patch;
int i;
patch_t *patch;
firstspritelump = W_GetNumForName ("S_START") + 1;
lastspritelump = W_GetNumForName ("S_END") - 1;
@ -626,13 +613,13 @@ void R_InitSpriteLumps (void)
for (i=0 ; i< numspritelumps ; i++)
{
if (!(i&63))
printf (".");
if (!(i&63))
printf (".");
patch = W_CacheLumpNum (firstspritelump+i, PU_CACHE);
spritewidth[i] = SHORT(patch->width)<<FRACBITS;
spriteoffset[i] = SHORT(patch->leftoffset)<<FRACBITS;
spritetopoffset[i] = SHORT(patch->topoffset)<<FRACBITS;
patch = W_CacheLumpNum (firstspritelump+i, PU_CACHE);
spritewidth[i] = SHORT(patch->width)<<FRACBITS;
spriteoffset[i] = SHORT(patch->leftoffset)<<FRACBITS;
spritetopoffset[i] = SHORT(patch->topoffset)<<FRACBITS;
}
}
@ -643,7 +630,7 @@ void R_InitSpriteLumps (void)
//
void R_InitColormaps (void)
{
int lump, length;
int lump, length;
// Load in the light tables,
// 256 byte align tables.
@ -665,13 +652,13 @@ void R_InitColormaps (void)
void R_InitData (void)
{
R_InitTextures ();
printf ("\nInitTextures");
printf ("InitTextures\n\r");
R_InitFlats ();
printf ("\nInitFlats");
printf ("InitFlats\n\r");
R_InitSpriteLumps ();
printf ("\nInitSprites");
printf ("InitSprites\n\r");
R_InitColormaps ();
printf ("\nInitColormaps");
printf ("InitColormaps\n\r");
}
@ -682,16 +669,16 @@ void R_InitData (void)
//
int R_FlatNumForName (char* name)
{
int i;
char namet[9];
int i;
char namet[9];
i = W_CheckNumForName (name);
if (i == -1)
{
namet[8] = 0;
memcpy (namet, name,8);
I_Error ("R_FlatNumForName: %s not found",namet);
namet[8] = 0;
memcpy (namet, name,8);
I_Error ("R_FlatNumForName: %s not found",namet);
}
return i - firstflat;
}
@ -704,38 +691,36 @@ int R_FlatNumForName (char* name)
// Check whether texture is available.
// Filter out NoTexture indicator.
//
int R_CheckTextureNumForName (char *name)
int R_CheckTextureNumForName (char *name)
{
int i;
int i;
// "NoTexture" marker.
if (name[0] == '-')
return 0;
return 0;
for (i=0 ; i<numtextures ; i++)
if (!I_strncasecmp (textures[i]->name, name, 8) )
return i;
if (!strnicmp (textures[i]->name, name, 8) )
return i;
return -1;
}
//
// R_TextureNumForName
// Calls R_CheckTextureNumForName,
// aborts with error message.
//
int R_TextureNumForName (char* name)
int R_TextureNumForName (char* name)
{
int i;
int i;
i = R_CheckTextureNumForName (name);
if (i==-1)
{
I_Error ("R_TextureNumForName: %s not found",
name);
I_Error ("R_TextureNumForName: %s not found",
name);
}
return i;
}
@ -747,27 +732,27 @@ int R_TextureNumForName (char* name)
// R_PrecacheLevel
// Preloads all relevant graphics for the level.
//
int flatmemory;
int texturememory;
int spritememory;
int flatmemory;
int texturememory;
int spritememory;
void R_PrecacheLevel (void)
{
char* flatpresent;
char* texturepresent;
char* spritepresent;
char* flatpresent;
char* texturepresent;
char* spritepresent;
int i;
int j;
int k;
int lump;
int i;
int j;
int k;
int lump;
texture_t* texture;
thinker_t* th;
spriteframe_t* sf;
texture_t* texture;
thinker_t* th;
spriteframe_t* sf;
if (demoplayback)
return;
return;
// Precache flats.
flatpresent = alloca(numflats);
@ -775,20 +760,20 @@ void R_PrecacheLevel (void)
for (i=0 ; i<numsectors ; i++)
{
flatpresent[sectors[i].floorpic] = 1;
flatpresent[sectors[i].ceilingpic] = 1;
flatpresent[sectors[i].floorpic] = 1;
flatpresent[sectors[i].ceilingpic] = 1;
}
flatmemory = 0;
for (i=0 ; i<numflats ; i++)
{
if (flatpresent[i])
{
lump = firstflat + i;
flatmemory += lumpinfo[lump].size;
W_CacheLumpNum(lump, PU_CACHE);
}
if (flatpresent[i])
{
lump = firstflat + i;
flatmemory += lumpinfo[lump].size;
W_CacheLumpNum(lump, PU_CACHE);
}
}
// Precache textures.
@ -797,9 +782,9 @@ void R_PrecacheLevel (void)
for (i=0 ; i<numsides ; i++)
{
texturepresent[sides[i].toptexture] = 1;
texturepresent[sides[i].midtexture] = 1;
texturepresent[sides[i].bottomtexture] = 1;
texturepresent[sides[i].toptexture] = 1;
texturepresent[sides[i].midtexture] = 1;
texturepresent[sides[i].bottomtexture] = 1;
}
// Sky texture is always present.
@ -813,17 +798,17 @@ void R_PrecacheLevel (void)
texturememory = 0;
for (i=0 ; i<numtextures ; i++)
{
if (!texturepresent[i])
continue;
if (!texturepresent[i])
continue;
texture = textures[i];
texture = textures[i];
for (j=0 ; j<texture->patchcount ; j++)
{
lump = texture->patches[j].patch;
texturememory += lumpinfo[lump].size;
W_CacheLumpNum(lump , PU_CACHE);
}
for (j=0 ; j<texture->patchcount ; j++)
{
lump = texture->patches[j].patch;
texturememory += lumpinfo[lump].size;
W_CacheLumpNum(lump , PU_CACHE);
}
}
// Precache sprites.
@ -832,26 +817,26 @@ void R_PrecacheLevel (void)
for (th = thinkercap.next ; th != &thinkercap ; th=th->next)
{
if (th->function.acp1 == (actionf_p1)P_MobjThinker)
spritepresent[((mobj_t *)th)->sprite] = 1;
if (th->function.acp1 == (actionf_p1)P_MobjThinker)
spritepresent[((mobj_t *)th)->sprite] = 1;
}
spritememory = 0;
for (i=0 ; i<numsprites ; i++)
{
if (!spritepresent[i])
continue;
if (!spritepresent[i])
continue;
for (j=0 ; j<sprites[i].numframes ; j++)
{
sf = &sprites[i].spriteframes[j];
for (k=0 ; k<8 ; k++)
{
lump = firstspritelump + sf->lump[k];
spritememory += lumpinfo[lump].size;
W_CacheLumpNum(lump , PU_CACHE);
}
}
for (j=0 ; j<sprites[i].numframes ; j++)
{
sf = &sprites[i].spriteframes[j];
for (k=0 ; k<8 ; k++)
{
lump = firstspritelump + sf->lump[k];
spritememory += lumpinfo[lump].size;
W_CacheLumpNum(lump , PU_CACHE);
}
}
}
}

View File

@ -17,14 +17,14 @@
// $Log:$
//
// DESCRIPTION:
// Rendering main loop and setup functions,
// utility functions (BSP, geometry, trigonometry).
// See tables.c, too.
// Rendering main loop and setup functions,
// utility functions (BSP, geometry, trigonometry).
// See tables.c, too.
//
//-----------------------------------------------------------------------------
static const char rcsid[] = "$Id: r_main.c,v 1.5 1997/02/03 22:45:12 b1 Exp $";
//static const char rcsid[] = "$Id: r_main.c,v 1.5 1997/02/03 22:45:12 b1 Exp $";
@ -45,80 +45,80 @@ static const char rcsid[] = "$Id: r_main.c,v 1.5 1997/02/03 22:45:12 b1 Exp $";
// Fineangles in the SCREENWIDTH wide window.
#define FIELDOFVIEW 2048
#define FIELDOFVIEW 2048
int viewangleoffset;
int viewangleoffset;
// increment every time a check is made
int validcount = 1;
int validcount = 1;
lighttable_t* fixedcolormap;
extern lighttable_t** walllights;
lighttable_t* fixedcolormap;
extern lighttable_t** walllights;
int centerx;
int centery;
int centerx;
int centery;
fixed_t centerxfrac;
fixed_t centeryfrac;
fixed_t projection;
fixed_t centerxfrac;
fixed_t centeryfrac;
fixed_t projection;
// just for profiling purposes
int framecount;
int framecount;
int sscount;
int linecount;
int loopcount;
int sscount;
int linecount;
int loopcount;
fixed_t viewx;
fixed_t viewy;
fixed_t viewz;
fixed_t viewx;
fixed_t viewy;
fixed_t viewz;
angle_t viewangle;
angle_t viewangle;
fixed_t viewcos;
fixed_t viewsin;
fixed_t viewcos;
fixed_t viewsin;
player_t* viewplayer;
player_t* viewplayer;
// 0 = high, 1 = low
int detailshift;
int detailshift;
//
// precalculated math tables
//
angle_t clipangle;
angle_t clipangle;
// The viewangletox[viewangle + FINEANGLES/4] lookup
// maps the visible view angles to screen X coordinates,
// flattening the arc to a flat projection plane.
// There will be many angles mapped to the same X.
int viewangletox[FINEANGLES/2];
int viewangletox[FINEANGLES/2];
// The xtoviewangleangle[] table maps a screen pixel
// to the lowest viewangle that maps back to x ranges
// from clipangle to -clipangle.
angle_t xtoviewangle[SCREENWIDTH+1];
angle_t xtoviewangle[SCREENWIDTH+1];
// UNUSED.
// The finetangentgent[angle+FINEANGLES/4] table
// holds the fixed_t tangent values for view angles,
// ranging from MININT to 0 to MAXINT.
// fixed_t finetangent[FINEANGLES/2];
// fixed_t finetangent[FINEANGLES/2];
// fixed_t finesine[5*FINEANGLES/4];
fixed_t* finecosine = &finesine[FINEANGLES/4];
// fixed_t finesine[5*FINEANGLES/4];
fixed_t* finecosine = &finesine[FINEANGLES/4];
lighttable_t* scalelight[LIGHTLEVELS][MAXLIGHTSCALE];
lighttable_t* scalelightfixed[MAXLIGHTSCALE];
lighttable_t* zlight[LIGHTLEVELS][MAXLIGHTZ];
lighttable_t* scalelight[LIGHTLEVELS][MAXLIGHTSCALE];
lighttable_t* scalelightfixed[MAXLIGHTSCALE];
lighttable_t* zlight[LIGHTLEVELS][MAXLIGHTZ];
// bumped light from gun blasts
int extralight;
int extralight;
@ -137,18 +137,18 @@ void (*spanfunc) (void);
//
void
R_AddPointToBox
( int x,
int y,
fixed_t* box )
( int x,
int y,
fixed_t* box )
{
if (x< box[BOXLEFT])
box[BOXLEFT] = x;
box[BOXLEFT] = x;
if (x> box[BOXRIGHT])
box[BOXRIGHT] = x;
box[BOXRIGHT] = x;
if (y< box[BOXBOTTOM])
box[BOXBOTTOM] = y;
box[BOXBOTTOM] = y;
if (y> box[BOXTOP])
box[BOXTOP] = y;
box[BOXTOP] = y;
}
@ -160,28 +160,28 @@ R_AddPointToBox
//
int
R_PointOnSide
( fixed_t x,
fixed_t y,
node_t* node )
( fixed_t x,
fixed_t y,
node_t* node )
{
fixed_t dx;
fixed_t dy;
fixed_t left;
fixed_t right;
fixed_t dx;
fixed_t dy;
fixed_t left;
fixed_t right;
if (!node->dx)
{
if (x <= node->x)
return node->dy > 0;
if (x <= node->x)
return node->dy > 0;
return node->dy < 0;
return node->dy < 0;
}
if (!node->dy)
{
if (y <= node->y)
return node->dx < 0;
if (y <= node->y)
return node->dx < 0;
return node->dx > 0;
return node->dx > 0;
}
dx = (x - node->x);
@ -190,12 +190,12 @@ R_PointOnSide
// Try to quickly decide by looking at sign bits.
if ( (node->dy ^ node->dx ^ dx ^ dy)&0x80000000 )
{
if ( (node->dy ^ dx) & 0x80000000 )
{
// (left is negative)
return 1;
}
return 0;
if ( (node->dy ^ dx) & 0x80000000 )
{
// (left is negative)
return 1;
}
return 0;
}
left = FixedMul ( node->dy>>FRACBITS , dx );
@ -203,8 +203,8 @@ R_PointOnSide
if (right < left)
{
// front side
return 0;
// front side
return 0;
}
// back side
return 1;
@ -213,18 +213,18 @@ R_PointOnSide
int
R_PointOnSegSide
( fixed_t x,
fixed_t y,
seg_t* line )
( fixed_t x,
fixed_t y,
seg_t* line )
{
fixed_t lx;
fixed_t ly;
fixed_t ldx;
fixed_t ldy;
fixed_t dx;
fixed_t dy;
fixed_t left;
fixed_t right;
fixed_t lx;
fixed_t ly;
fixed_t ldx;
fixed_t ldy;
fixed_t dx;
fixed_t dy;
fixed_t left;
fixed_t right;
lx = line->v1->x;
ly = line->v1->y;
@ -234,17 +234,17 @@ R_PointOnSegSide
if (!ldx)
{
if (x <= lx)
return ldy > 0;
if (x <= lx)
return ldy > 0;
return ldy < 0;
return ldy < 0;
}
if (!ldy)
{
if (y <= ly)
return ldx < 0;
if (y <= ly)
return ldx < 0;
return ldx > 0;
return ldx > 0;
}
dx = (x - lx);
@ -253,12 +253,12 @@ R_PointOnSegSide
// Try to quickly decide by looking at sign bits.
if ( (ldy ^ ldx ^ dx ^ dy)&0x80000000 )
{
if ( (ldy ^ dx) & 0x80000000 )
{
// (left is negative)
return 1;
}
return 0;
if ( (ldy ^ dx) & 0x80000000 )
{
// (left is negative)
return 1;
}
return 0;
}
left = FixedMul ( ldy>>FRACBITS , dx );
@ -266,8 +266,8 @@ R_PointOnSegSide
if (right < left)
{
// front side
return 0;
// front side
return 0;
}
// back side
return 1;
@ -290,85 +290,85 @@ R_PointOnSegSide
angle_t
R_PointToAngle
( fixed_t x,
fixed_t y )
( fixed_t x,
fixed_t y )
{
x -= viewx;
y -= viewy;
if ( (!x) && (!y) )
return 0;
return 0;
if (x>= 0)
{
// x >=0
if (y>= 0)
{
// y>= 0
// x >=0
if (y>= 0)
{
// y>= 0
if (x>y)
{
// octant 0
return tantoangle[ SlopeDiv(y,x)];
}
else
{
// octant 1
return ANG90-1-tantoangle[ SlopeDiv(x,y)];
}
}
else
{
// y<0
y = -y;
if (x>y)
{
// octant 0
return tantoangle[ SlopeDiv(y,x)];
}
else
{
// octant 1
return ANG90-1-tantoangle[ SlopeDiv(x,y)];
}
}
else
{
// y<0
y = -y;
if (x>y)
{
// octant 8
return -tantoangle[SlopeDiv(y,x)];
}
else
{
// octant 7
return ANG270+tantoangle[ SlopeDiv(x,y)];
}
}
if (x>y)
{
// octant 8
return -tantoangle[SlopeDiv(y,x)];
}
else
{
// octant 7
return ANG270+tantoangle[ SlopeDiv(x,y)];
}
}
}
else
{
// x<0
x = -x;
// x<0
x = -x;
if (y>= 0)
{
// y>= 0
if (x>y)
{
// octant 3
return ANG180-1-tantoangle[ SlopeDiv(y,x)];
}
else
{
// octant 2
return ANG90+ tantoangle[ SlopeDiv(x,y)];
}
}
else
{
// y<0
y = -y;
if (y>= 0)
{
// y>= 0
if (x>y)
{
// octant 3
return ANG180-1-tantoangle[ SlopeDiv(y,x)];
}
else
{
// octant 2
return ANG90+ tantoangle[ SlopeDiv(x,y)];
}
}
else
{
// y<0
y = -y;
if (x>y)
{
// octant 4
return ANG180+tantoangle[ SlopeDiv(y,x)];
}
else
{
// octant 5
return ANG270-1-tantoangle[ SlopeDiv(x,y)];
}
}
if (x>y)
{
// octant 4
return ANG180+tantoangle[ SlopeDiv(y,x)];
}
else
{
// octant 5
return ANG270-1-tantoangle[ SlopeDiv(x,y)];
}
}
}
return 0;
}
@ -376,10 +376,10 @@ R_PointToAngle
angle_t
R_PointToAngle2
( fixed_t x1,
fixed_t y1,
fixed_t x2,
fixed_t y2 )
( fixed_t x1,
fixed_t y1,
fixed_t x2,
fixed_t y2 )
{
viewx = x1;
viewy = y1;
@ -390,23 +390,23 @@ R_PointToAngle2
fixed_t
R_PointToDist
( fixed_t x,
fixed_t y )
( fixed_t x,
fixed_t y )
{
int angle;
fixed_t dx;
fixed_t dy;
fixed_t temp;
fixed_t dist;
int angle;
fixed_t dx;
fixed_t dy;
fixed_t temp;
fixed_t dist;
dx = abs(x - viewx);
dy = abs(y - viewy);
if (dy>dx)
{
temp = dx;
dx = dy;
dy = temp;
temp = dx;
dx = dy;
dy = temp;
}
angle = (tantoangle[ FixedDiv(dy,dx)>>DBITS ]+ANG90) >> ANGLETOFINESHIFT;
@ -427,17 +427,17 @@ void R_InitPointToAngle (void)
{
// UNUSED - now getting from tables.c
#if 0
int i;
long t;
float f;
int i;
long t;
float f;
//
// slope (tangent) to angle lookup
//
for (i=0 ; i<=SLOPERANGE ; i++)
{
f = atan( (float)i/SLOPERANGE )/(3.141592657*2);
t = 0xffffffff*f;
tantoangle[i] = t;
f = atan( (float)i/SLOPERANGE )/(3.141592657*2);
t = 0xffffffff*f;
tantoangle[i] = t;
}
#endif
}
@ -452,21 +452,21 @@ void R_InitPointToAngle (void)
//
fixed_t R_ScaleFromGlobalAngle (angle_t visangle)
{
fixed_t scale;
int anglea;
int angleb;
int sinea;
int sineb;
fixed_t num;
int den;
fixed_t scale;
int anglea;
int angleb;
int sinea;
int sineb;
fixed_t num;
int den;
// UNUSED
#if 0
{
fixed_t dist;
fixed_t z;
fixed_t sinv;
fixed_t cosv;
fixed_t dist;
fixed_t z;
fixed_t sinv;
fixed_t cosv;
sinv = finesine[(visangle-rw_normalangle)>>ANGLETOFINESHIFT];
dist = FixedDiv (rw_distance, sinv);
@ -488,15 +488,15 @@ fixed_t R_ScaleFromGlobalAngle (angle_t visangle)
if (den > num>>16)
{
scale = FixedDiv (num, den);
scale = FixedDiv (num, den);
if (scale > 64*FRACUNIT)
scale = 64*FRACUNIT;
else if (scale < 256)
scale = 256;
if (scale > 64*FRACUNIT)
scale = 64*FRACUNIT;
else if (scale < 256)
scale = 256;
}
else
scale = 64*FRACUNIT;
scale = 64*FRACUNIT;
return scale;
}
@ -510,27 +510,27 @@ void R_InitTables (void)
{
// UNUSED: now getting from tables.c
#if 0
int i;
float a;
float fv;
int t;
int i;
float a;
float fv;
int t;
// viewangle tangent table
for (i=0 ; i<FINEANGLES/2 ; i++)
{
a = (i-FINEANGLES/4+0.5)*PI*2/FINEANGLES;
fv = FRACUNIT*tan (a);
t = fv;
finetangent[i] = t;
a = (i-FINEANGLES/4+0.5)*PI*2/FINEANGLES;
fv = FRACUNIT*tan (a);
t = fv;
finetangent[i] = t;
}
// finesine table
for (i=0 ; i<5*FINEANGLES/4 ; i++)
{
// OPTIMIZE: mirror...
a = (i+0.5)*PI*2/FINEANGLES;
t = FRACUNIT*sin (a);
finesine[i] = t;
// OPTIMIZE: mirror...
a = (i+0.5)*PI*2/FINEANGLES;
t = FRACUNIT*sin (a);
finesine[i] = t;
}
#endif
@ -543,10 +543,10 @@ void R_InitTables (void)
//
void R_InitTextureMapping (void)
{
int i;
int x;
int t;
fixed_t focallength;
int i;
int x;
int t;
fixed_t focallength;
// Use tangent table to generate viewangletox:
// viewangletox will give the next greatest x
@ -555,25 +555,25 @@ void R_InitTextureMapping (void)
// Calc focallength
// so FIELDOFVIEW angles covers SCREENWIDTH.
focallength = FixedDiv (centerxfrac,
finetangent[FINEANGLES/4+FIELDOFVIEW/2] );
finetangent[FINEANGLES/4+FIELDOFVIEW/2] );
for (i=0 ; i<FINEANGLES/2 ; i++)
{
if (finetangent[i] > FRACUNIT*2)
t = -1;
else if (finetangent[i] < -FRACUNIT*2)
t = viewwidth+1;
else
{
t = FixedMul (finetangent[i], focallength);
t = (centerxfrac - t+FRACUNIT-1)>>FRACBITS;
if (finetangent[i] > FRACUNIT*2)
t = -1;
else if (finetangent[i] < -FRACUNIT*2)
t = viewwidth+1;
else
{
t = FixedMul (finetangent[i], focallength);
t = (centerxfrac - t+FRACUNIT-1)>>FRACBITS;
if (t < -1)
t = -1;
else if (t>viewwidth+1)
t = viewwidth+1;
}
viewangletox[i] = t;
if (t < -1)
t = -1;
else if (t>viewwidth+1)
t = viewwidth+1;
}
viewangletox[i] = t;
}
// Scan viewangletox[] to generate xtoviewangle[]:
@ -581,22 +581,22 @@ void R_InitTextureMapping (void)
// that maps to x.
for (x=0;x<=viewwidth;x++)
{
i = 0;
while (viewangletox[i]>x)
i++;
xtoviewangle[x] = (i<<ANGLETOFINESHIFT)-ANG90;
i = 0;
while (viewangletox[i]>x)
i++;
xtoviewangle[x] = (i<<ANGLETOFINESHIFT)-ANG90;
}
// Take out the fencepost cases from viewangletox.
for (i=0 ; i<FINEANGLES/2 ; i++)
{
t = FixedMul (finetangent[i], focallength);
t = centerx - t;
t = FixedMul (finetangent[i], focallength);
t = centerx - t;
if (viewangletox[i] == -1)
viewangletox[i] = 0;
else if (viewangletox[i] == viewwidth+1)
viewangletox[i] = viewwidth;
if (viewangletox[i] == -1)
viewangletox[i] = 0;
else if (viewangletox[i] == viewwidth+1)
viewangletox[i] = viewwidth;
}
clipangle = xtoviewangle[0];
@ -609,35 +609,35 @@ void R_InitTextureMapping (void)
// Only inits the zlight table,
// because the scalelight table changes with view size.
//
#define DISTMAP 2
#define DISTMAP 2
void R_InitLightTables (void)
{
int i;
int j;
int level;
int startmap;
int scale;
int i;
int j;
int level;
int startmap;
int scale;
// Calculate the light levels to use
// for each level / distance combination.
for (i=0 ; i< LIGHTLEVELS ; i++)
{
startmap = ((LIGHTLEVELS-1-i)*2)*NUMCOLORMAPS/LIGHTLEVELS;
for (j=0 ; j<MAXLIGHTZ ; j++)
{
scale = FixedDiv ((SCREENWIDTH/2*FRACUNIT), (j+1)<<LIGHTZSHIFT);
scale >>= LIGHTSCALESHIFT;
level = startmap - scale/DISTMAP;
startmap = ((LIGHTLEVELS-1-i)*2)*NUMCOLORMAPS/LIGHTLEVELS;
for (j=0 ; j<MAXLIGHTZ ; j++)
{
scale = FixedDiv ((SCREENWIDTH/2*FRACUNIT), (j+1)<<LIGHTZSHIFT);
scale >>= LIGHTSCALESHIFT;
level = startmap - scale/DISTMAP;
if (level < 0)
level = 0;
if (level < 0)
level = 0;
if (level >= NUMCOLORMAPS)
level = NUMCOLORMAPS-1;
if (level >= NUMCOLORMAPS)
level = NUMCOLORMAPS-1;
zlight[i][j] = colormaps + level*256;
}
zlight[i][j] = colormaps + level*256;
}
}
}
@ -649,15 +649,15 @@ void R_InitLightTables (void)
// because it might be in the middle of a refresh.
// The change will take effect next refresh.
//
boolean setsizeneeded;
int setblocks;
int setdetail;
boolean setsizeneeded;
int setblocks;
int setdetail;
void
R_SetViewSize
( int blocks,
int detail )
( int blocks,
int detail )
{
setsizeneeded = true;
setblocks = blocks;
@ -670,24 +670,24 @@ R_SetViewSize
//
void R_ExecuteSetViewSize (void)
{
fixed_t cosadj;
fixed_t dy;
int i;
int j;
int level;
int startmap;
fixed_t cosadj;
fixed_t dy;
int i;
int j;
int level;
int startmap;
setsizeneeded = false;
if (setblocks == 11)
{
scaledviewwidth = SCREENWIDTH;
viewheight = SCREENHEIGHT;
scaledviewwidth = SCREENWIDTH;
viewheight = SCREENHEIGHT;
}
else
{
scaledviewwidth = setblocks*32;
viewheight = (setblocks*168/10)&~7;
scaledviewwidth = setblocks*32;
viewheight = (setblocks*168/10)&~7;
}
detailshift = setdetail;
@ -701,17 +701,17 @@ void R_ExecuteSetViewSize (void)
if (!detailshift)
{
colfunc = basecolfunc = R_DrawColumn;
fuzzcolfunc = R_DrawFuzzColumn;
transcolfunc = R_DrawTranslatedColumn;
spanfunc = R_DrawSpan;
colfunc = basecolfunc = R_DrawColumn;
fuzzcolfunc = R_DrawFuzzColumn;
transcolfunc = R_DrawTranslatedColumn;
spanfunc = R_DrawSpan;
}
else
{
colfunc = basecolfunc = R_DrawColumnLow;
fuzzcolfunc = R_DrawFuzzColumn;
transcolfunc = R_DrawTranslatedColumn;
spanfunc = R_DrawSpanLow;
colfunc = basecolfunc = R_DrawColumnLow;
fuzzcolfunc = R_DrawFuzzColumn;
transcolfunc = R_DrawTranslatedColumn;
spanfunc = R_DrawSpanLow;
}
R_InitBuffer (scaledviewwidth, viewheight);
@ -724,39 +724,39 @@ void R_ExecuteSetViewSize (void)
// thing clipping
for (i=0 ; i<viewwidth ; i++)
screenheightarray[i] = viewheight;
screenheightarray[i] = viewheight;
// planes
for (i=0 ; i<viewheight ; i++)
{
dy = ((i-viewheight/2)<<FRACBITS)+FRACUNIT/2;
dy = abs(dy);
yslope[i] = FixedDiv ( (viewwidth<<detailshift)/2*FRACUNIT, dy);
dy = ((i-viewheight/2)<<FRACBITS)+FRACUNIT/2;
dy = abs(dy);
yslope[i] = FixedDiv ( (viewwidth<<detailshift)/2*FRACUNIT, dy);
}
for (i=0 ; i<viewwidth ; i++)
{
cosadj = abs(finecosine[xtoviewangle[i]>>ANGLETOFINESHIFT]);
distscale[i] = FixedDiv (FRACUNIT,cosadj);
cosadj = abs(finecosine[xtoviewangle[i]>>ANGLETOFINESHIFT]);
distscale[i] = FixedDiv (FRACUNIT,cosadj);
}
// Calculate the light levels to use
// for each level / scale combination.
for (i=0 ; i< LIGHTLEVELS ; i++)
{
startmap = ((LIGHTLEVELS-1-i)*2)*NUMCOLORMAPS/LIGHTLEVELS;
for (j=0 ; j<MAXLIGHTSCALE ; j++)
{
level = startmap - j*SCREENWIDTH/(viewwidth<<detailshift)/DISTMAP;
startmap = ((LIGHTLEVELS-1-i)*2)*NUMCOLORMAPS/LIGHTLEVELS;
for (j=0 ; j<MAXLIGHTSCALE ; j++)
{
level = startmap - j*SCREENWIDTH/(viewwidth<<detailshift)/DISTMAP;
if (level < 0)
level = 0;
if (level < 0)
level = 0;
if (level >= NUMCOLORMAPS)
level = NUMCOLORMAPS-1;
if (level >= NUMCOLORMAPS)
level = NUMCOLORMAPS-1;
scalelight[i][j] = colormaps + level*256;
}
scalelight[i][j] = colormaps + level*256;
}
}
}
@ -765,30 +765,30 @@ void R_ExecuteSetViewSize (void)
//
// R_Init
//
extern int detailLevel;
extern int screenblocks;
extern int detailLevel;
extern int screenblocks;
void R_Init (void)
{
R_InitData ();
printf ("\nR_InitData");
printf ("R_InitData\n\r");
R_InitPointToAngle ();
printf ("\nR_InitPointToAngle");
printf ("R_InitPointToAngle\n\r");
R_InitTables ();
// viewwidth / viewheight / detailLevel are set by the defaults
printf ("\nR_InitTables");
printf ("R_InitTables\n\r");
R_SetViewSize (screenblocks, detailLevel);
R_InitPlanes ();
printf ("\nR_InitPlanes");
printf ("R_InitPlanes\n\r");
R_InitLightTables ();
printf ("\nR_InitLightTables");
printf ("R_InitLightTables\n\r");
R_InitSkyMap ();
printf ("\nR_InitSkyMap");
printf ("R_InitSkyMap\n\r");
R_InitTranslationTables ();
printf ("\nR_InitTranslationsTables");
printf ("R_InitTranslationsTables\n\r");
framecount = 0;
}
@ -799,24 +799,24 @@ void R_Init (void)
//
subsector_t*
R_PointInSubsector
( fixed_t x,
fixed_t y )
( fixed_t x,
fixed_t y )
{
node_t* node;
int side;
int nodenum;
node_t* node;
int side;
int nodenum;
// single subsector is a special case
if (!numnodes)
return subsectors;
return subsectors;
nodenum = numnodes-1;
while (! (nodenum & NF_SUBSECTOR) )
{
node = &nodes[nodenum];
side = R_PointOnSide (x, y, node);
nodenum = node->children[side];
node = &nodes[nodenum];
side = R_PointOnSide (x, y, node);
nodenum = node->children[side];
}
return &subsectors[nodenum & ~NF_SUBSECTOR];
@ -829,7 +829,7 @@ R_PointInSubsector
//
void R_SetupFrame (player_t* player)
{
int i;
int i;
viewplayer = player;
viewx = player->mo->x;
@ -846,17 +846,17 @@ void R_SetupFrame (player_t* player)
if (player->fixedcolormap)
{
fixedcolormap =
colormaps
+ player->fixedcolormap*256*sizeof(lighttable_t);
fixedcolormap =
colormaps
+ player->fixedcolormap*256*sizeof(lighttable_t);
walllights = scalelightfixed;
walllights = scalelightfixed;
for (i=0 ; i<MAXLIGHTSCALE ; i++)
scalelightfixed[i] = fixedcolormap;
for (i=0 ; i<MAXLIGHTSCALE ; i++)
scalelightfixed[i] = fixedcolormap;
}
else
fixedcolormap = 0;
fixedcolormap = 0;
framecount++;
validcount++;

View File

@ -51,37 +51,37 @@ void WriteDebug(char *);
const char snd_prefixen[]
= { 'P', 'P', 'A', 'S', 'S', 'S', 'M', 'M', 'M', 'S', 'S', 'S' };
#define S_MAX_VOLUME 127
#define S_MAX_VOLUME 127
// when to clip out sounds
// Does not fit the large outdoor areas.
#define S_CLIPPING_DIST (1200*0x10000)
#define S_CLIPPING_DIST (1200*0x10000)
// Distance tp origin when sounds should be maxed out.
// This should relate to movement clipping resolution
// (see BLOCKMAP handling).
// Originally: (200*0x10000).
#define S_CLOSE_DIST (160*0x10000)
#define S_CLOSE_DIST (160*0x10000)
#define S_ATTENUATOR ((S_CLIPPING_DIST-S_CLOSE_DIST)>>FRACBITS)
#define S_ATTENUATOR ((S_CLIPPING_DIST-S_CLOSE_DIST)>>FRACBITS)
// Adjustable by menu.
#define NORM_VOLUME snd_MaxVolume
#define NORM_VOLUME snd_MaxVolume
#define NORM_PITCH 128
#define NORM_PRIORITY 64
#define NORM_SEP 128
#define NORM_PITCH 128
#define NORM_PRIORITY 64
#define NORM_SEP 128
#define S_PITCH_PERTURB 1
#define S_STEREO_SWING (96*0x10000)
#define S_PITCH_PERTURB 1
#define S_STEREO_SWING (96*0x10000)
// percent attenuation from front to back
#define S_IFRACVOL 30
#define S_IFRACVOL 30
#define NA 0
//#define S_NUMCHANNELS 2
#define NUM_CHANNELS 16
#define NA 0
//#define S_NUMCHANNELS 2
#define NUM_CHANNELS 16
// Current music/sfx card - index useless
// w/o a reference LUT in a sound module.
@ -95,42 +95,42 @@ extern int snd_DesiredSfxDevice;
typedef struct
{
// sound information (if null, channel avail.)
sfxinfo_t* sfxinfo;
sfxinfo_t* sfxinfo;
// origin of sound
void* origin;
void* origin;
// handle of the sound being played
int handle;
int handle;
} channel_t;
// the set of channels available
static channel_t* channels;
static channel_t* channels;
// These are not used, but should be (menu).
// Maximum volume of a sound effect.
// Internal default is max out of 0-15.
int snd_SfxVolume = 80;
int snd_SfxVolume = 80;
// Maximum volume of music. Useless so far.
int snd_MusicVolume = 80;
int snd_MusicVolume = 80;
// whether songs are mus_paused
static boolean mus_paused;
static boolean mus_paused;
// music currently being played
static musicinfo_t* mus_playing=0;
static musicinfo_t* mus_playing=0;
// following is set
// by the defaults code in M_misc:
// number of channels available
int numChannels;
int numChannels;
static int nextcleanup;
static int nextcleanup;
@ -139,18 +139,18 @@ static int nextcleanup;
//
int
S_getChannel
( void* origin,
sfxinfo_t* sfxinfo,
( void* origin,
sfxinfo_t* sfxinfo,
int sfxid );
int
S_AdjustSoundParams
( mobj_t* listener,
mobj_t* source,
int* vol,
int* sep,
int* pitch );
( mobj_t* listener,
mobj_t* source,
int* vol,
int* sep,
int* pitch );
void S_StopChannel(int cnum);
@ -162,14 +162,14 @@ void S_StopChannel(int cnum);
// allocates channel buffer, sets S_sfx lookup.
//
void S_Init
( int sfxVolume,
int musicVolume )
( int sfxVolume,
int musicVolume )
{
int i;
int i;
printf("S_Init: default sfx volume %d\n", sfxVolume);
I_CreateSound();
//I_CreateSound();
numChannels = NUM_CHANNELS;
// Whatever these did with DMX, these are rather dummies now.
@ -217,27 +217,27 @@ void S_Start(void)
mus_paused = 0;
if (gamemode == commercial)
mnum = mus_runnin + gamemap - 1;
mnum = mus_runnin + gamemap - 1;
else
{
int spmus[]=
{
// Song - Who? - Where?
mus_e3m4, // American e4m1
mus_e3m2, // Romero e4m2
mus_e3m3, // Shawn e4m3
mus_e1m5, // American e4m4
mus_e2m7, // Tim e4m5
mus_e2m4, // Romero e4m6
mus_e2m6, // J.Anderson e4m7 CHIRON.WAD
mus_e2m5, // Shawn e4m8
mus_e1m9 // Tim e4m9
};
int spmus[]=
{
// Song - Who? - Where?
mus_e3m4, // American e4m1
mus_e3m2, // Romero e4m2
mus_e3m3, // Shawn e4m3
mus_e1m5, // American e4m4
mus_e2m7, // Tim e4m5
mus_e2m4, // Romero e4m6
mus_e2m6, // J.Anderson e4m7 CHIRON.WAD
mus_e2m5, // Shawn e4m8
mus_e1m9 // Tim e4m9
};
if (gameepisode < 4)
mnum = mus_e1m1 + (gameepisode-1)*9 + gamemap-1;
else
mnum = spmus[gamemap-1];
if (gameepisode < 4)
mnum = mus_e1m1 + (gameepisode-1)*9 + gamemap-1;
else
mnum = spmus[gamemap-1];
}
// HACK FOR COMMERCIAL
@ -259,7 +259,7 @@ void S_StartSoundAtVolume( void *origin_p, int sfx_id, int volume )
int cnum;
// int chnum; <-- 10.9.98 compiler warning
mobj_t* origin = (mobj_t *)origin_p;
mobj_t* origin = (mobj_t *)origin_p;
//WriteDebug("S_StartSoundAtVolume...\n");
@ -372,8 +372,7 @@ void S_StartSoundAtVolume( void *origin_p, int sfx_id, int volume )
// Assigns the handle to one of the channels in the
// mix/output buffer.
//WriteDebug("I_StartSound...\n");
channels[cnum].handle = I_StartSound(sfx_id,/*sfx->data,*/volume,sep,pitch,priority,origin);
//cnum = I_StartSound(sfx_id,/*sfx->data,*/volume,sep,pitch,priority,origin);
channels[cnum].handle = I_StartSound(sfx_id,volume,sep,pitch,priority);
channels[cnum].handle = cnum;
channels[cnum].sfxinfo = sfx;
channels[cnum].origin = origin;
@ -396,51 +395,51 @@ void S_StartSound( void *origin, int sfx_id )
int n;
static mobj_t* last_saw_origins[10] = {1,1,1,1,1,1,1,1,1,1};
static int first_saw=0;
static int next_saw=0;
static int first_saw=0;
static int next_saw=0;
if (sfx_id == sfx_sawidl
|| sfx_id == sfx_sawful
|| sfx_id == sfx_sawhit)
|| sfx_id == sfx_sawful
|| sfx_id == sfx_sawhit)
{
for (i=first_saw;i!=next_saw;i=(i+1)%10)
if (last_saw_origins[i] != origin)
fprintf(stderr, "old origin 0x%lx != "
"origin 0x%lx for sfx %d\n",
last_saw_origins[i],
origin,
sfx_id);
for (i=first_saw;i!=next_saw;i=(i+1)%10)
if (last_saw_origins[i] != origin)
fprintf(stderr, "old origin 0x%lx != "
"origin 0x%lx for sfx %d\n",
last_saw_origins[i],
origin,
sfx_id);
last_saw_origins[next_saw] = origin;
next_saw = (next_saw + 1) % 10;
if (next_saw == first_saw)
first_saw = (first_saw + 1) % 10;
last_saw_origins[next_saw] = origin;
next_saw = (next_saw + 1) % 10;
if (next_saw == first_saw)
first_saw = (first_saw + 1) % 10;
for (n=i=0; i<numChannels ; i++)
{
if (channels[i].sfxinfo == &S_sfx[sfx_sawidl]
|| channels[i].sfxinfo == &S_sfx[sfx_sawful]
|| channels[i].sfxinfo == &S_sfx[sfx_sawhit]) n++;
}
for (n=i=0; i<numChannels ; i++)
{
if (channels[i].sfxinfo == &S_sfx[sfx_sawidl]
|| channels[i].sfxinfo == &S_sfx[sfx_sawful]
|| channels[i].sfxinfo == &S_sfx[sfx_sawhit]) n++;
}
if (n>1)
{
for (i=0; i<numChannels ; i++)
{
if (channels[i].sfxinfo == &S_sfx[sfx_sawidl]
|| channels[i].sfxinfo == &S_sfx[sfx_sawful]
|| channels[i].sfxinfo == &S_sfx[sfx_sawhit])
{
fprintf(stderr,
"chn: sfxinfo=0x%lx, origin=0x%lx, "
"handle=%d\n",
channels[i].sfxinfo,
channels[i].origin,
channels[i].handle);
}
}
fprintf(stderr, "\n");
}
if (n>1)
{
for (i=0; i<numChannels ; i++)
{
if (channels[i].sfxinfo == &S_sfx[sfx_sawidl]
|| channels[i].sfxinfo == &S_sfx[sfx_sawful]
|| channels[i].sfxinfo == &S_sfx[sfx_sawhit])
{
fprintf(stderr,
"chn: sfxinfo=0x%lx, origin=0x%lx, "
"handle=%d\n",
channels[i].sfxinfo,
channels[i].origin,
channels[i].handle);
}
}
fprintf(stderr, "\n");
}
}
}
#endif
@ -457,11 +456,11 @@ void S_StopSound(void *origin)
for (cnum=0 ; cnum<numChannels ; cnum++)
{
if (channels[cnum].sfxinfo && channels[cnum].origin == origin)
{
S_StopChannel(cnum);
break;
}
if (channels[cnum].sfxinfo && channels[cnum].origin == origin)
{
S_StopChannel(cnum);
break;
}
}
}
@ -480,8 +479,8 @@ void S_PauseSound(void)
{
if (mus_playing && !mus_paused)
{
I_PauseSong(mus_playing->handle);
mus_paused = true;
I_PauseSong(mus_playing->handle);
mus_paused = true;
}
}
@ -489,8 +488,8 @@ void S_ResumeSound(void)
{
if (mus_playing && mus_paused)
{
I_ResumeSong(mus_playing->handle);
mus_paused = false;
I_ResumeSong(mus_playing->handle);
mus_paused = false;
}
}
@ -500,15 +499,15 @@ void S_ResumeSound(void)
//
void S_UpdateSounds(void* listener_p)
{
int audible;
int cnum;
int volume;
int sep;
int pitch;
sfxinfo_t* sfx;
channel_t* c;
int audible;
int cnum;
int volume;
int sep;
int pitch;
sfxinfo_t* sfx;
channel_t* c;
mobj_t* listener = (mobj_t*)listener_p;
mobj_t* listener = (mobj_t*)listener_p;
@ -517,78 +516,78 @@ void S_UpdateSounds(void* listener_p)
// DOS 8bit remains.
/*if (gametic > nextcleanup)
{
for (i=1 ; i<NUMSFX ; i++)
{
if (S_sfx[i].usefulness < 1
&& S_sfx[i].usefulness > -1)
{
if (--S_sfx[i].usefulness == -1)
{
Z_ChangeTag(S_sfx[i].data, PU_CACHE);
S_sfx[i].data = 0;
}
}
}
nextcleanup = gametic + 15;
for (i=1 ; i<NUMSFX ; i++)
{
if (S_sfx[i].usefulness < 1
&& S_sfx[i].usefulness > -1)
{
if (--S_sfx[i].usefulness == -1)
{
Z_ChangeTag(S_sfx[i].data, PU_CACHE);
S_sfx[i].data = 0;
}
}
}
nextcleanup = gametic + 15;
}*/
for (cnum=0 ; cnum<numChannels ; cnum++)
{
c = &channels[cnum];
sfx = c->sfxinfo;
c = &channels[cnum];
sfx = c->sfxinfo;
if (c->sfxinfo)
{
if (I_SoundIsPlaying(c->handle))
{
// initialize parameters
volume = snd_SfxVolume;
pitch = NORM_PITCH;
sep = NORM_SEP;
if (c->sfxinfo)
{
if (I_SoundIsPlaying(c->handle))
{
// initialize parameters
volume = snd_SfxVolume;
pitch = NORM_PITCH;
sep = NORM_SEP;
if (sfx->link)
{
pitch = sfx->pitch;
volume += sfx->volume;
if (volume < 1)
{
S_StopChannel(cnum);
continue;
}
else if (volume > snd_SfxVolume)
{
volume = snd_SfxVolume;
}
}
if (sfx->link)
{
pitch = sfx->pitch;
volume += sfx->volume;
if (volume < 1)
{
S_StopChannel(cnum);
continue;
}
else if (volume > snd_SfxVolume)
{
volume = snd_SfxVolume;
}
}
// check non-local sounds for distance clipping
// or modify their params
if (c->origin && listener_p != c->origin)
{
audible = S_AdjustSoundParams(listener,
c->origin,
&volume,
&sep,
&pitch);
// check non-local sounds for distance clipping
// or modify their params
if (c->origin && listener_p != c->origin)
{
audible = S_AdjustSoundParams(listener,
c->origin,
&volume,
&sep,
&pitch);
if (!audible)
{
S_StopChannel(cnum);
}
else
I_UpdateSoundParams(c->handle, volume, sep, pitch);
}
}
else
{
// if channel is allocated but sound has stopped,
// free it
S_StopChannel(cnum);
}
}
if (!audible)
{
S_StopChannel(cnum);
}
else
I_UpdateSoundParams(c->handle, volume, sep, pitch);
}
}
else
{
// if channel is allocated but sound has stopped,
// free it
S_StopChannel(cnum);
}
}
}
// kill music if it is a single-play && finished
// if ( mus_playing
// if ( mus_playing
// && !I_QrySongPlaying(mus_playing->handle)
// && !mus_paused )
// S_StopMusic();
@ -599,8 +598,8 @@ void S_SetMusicVolume(int volume)
{
if (volume < 0 || volume > 127)
{
I_Error("Attempt to set music volume at %d",
volume);
I_Error("Attempt to set music volume at %d",
volume);
}
I_SetMusicVolume(127);
@ -614,7 +613,7 @@ void S_SetSfxVolume(int volume)
{
if (volume < 0 || volume > 127)
I_Error("Attempt to set sfx volume at %d", volume);
I_Error("Attempt to set sfx volume at %d", volume);
snd_SfxVolume = volume;
@ -634,7 +633,7 @@ void S_ChangeMusic(int musicnum, int looping)
{
// I_PlaySong(music->handle, looping);
// mus_playing = music;
// mus_playing = music;
}
@ -642,48 +641,48 @@ void S_StopMusic(void)
{
if (mus_playing)
{
if (mus_paused) I_ResumeSong(mus_playing->handle);
I_StopSong(mus_playing->handle);
I_UnRegisterSong(mus_playing->handle);
Z_ChangeTag(mus_playing->data, PU_CACHE);
mus_playing->data = 0;
mus_playing = 0;
if (mus_paused) I_ResumeSong(mus_playing->handle);
I_StopSong(mus_playing->handle);
I_UnRegisterSong(mus_playing->handle);
Z_ChangeTag(mus_playing->data, PU_CACHE);
mus_playing->data = 0;
mus_playing = 0;
}
}
void S_StopChannel(int cnum)
{
int i;
channel_t* c = &channels[cnum];
int i;
channel_t* c = &channels[cnum];
if (c->sfxinfo)
{
// stop the sound playing
if (I_SoundIsPlaying(c->handle))
{
// stop the sound playing
if (I_SoundIsPlaying(c->handle))
{
#ifdef SAWDEBUG
if (c->sfxinfo == &S_sfx[sfx_sawful])
fprintf(stderr, "stopped\n");
if (c->sfxinfo == &S_sfx[sfx_sawful])
fprintf(stderr, "stopped\n");
#endif
I_StopSound(c->handle);
}
I_StopSound(c->handle);
}
// check to see
// if other channels are playing the sound
for (i=0 ; i<numChannels ; i++)
{
if (cnum != i
&& c->sfxinfo == channels[i].sfxinfo)
{
break;
}
}
// check to see
// if other channels are playing the sound
for (i=0 ; i<numChannels ; i++)
{
if (cnum != i
&& c->sfxinfo == channels[i].sfxinfo)
{
break;
}
}
// degrade usefulness of sound data
c->sfxinfo->usefulness--;
// degrade usefulness of sound data
c->sfxinfo->usefulness--;
c->sfxinfo = 0;
c->sfxinfo = 0;
}
}
@ -698,10 +697,10 @@ int
S_AdjustSoundParams (mobj_t* listener, mobj_t* source,
int* vol, int* sep, int* pitch)
{
fixed_t approx_dist;
fixed_t adx;
fixed_t ady;
angle_t angle;
fixed_t approx_dist;
fixed_t adx;
fixed_t ady;
angle_t angle;
// calculate the distance to sound origin
// and clip it if necessary
@ -712,21 +711,21 @@ S_AdjustSoundParams (mobj_t* listener, mobj_t* source,
approx_dist = adx + ady - ((adx < ady ? adx : ady)>>1);
if (gamemap != 8
&& approx_dist > S_CLIPPING_DIST)
&& approx_dist > S_CLIPPING_DIST)
{
return 0;
return 0;
}
// angle of source to listener
angle = R_PointToAngle2(listener->x,
listener->y,
source->x,
source->y);
listener->y,
source->x,
source->y);
if (angle > listener->angle)
angle = angle - listener->angle;
angle = angle - listener->angle;
else
angle = angle + (0xffffffff - listener->angle);
angle = angle + (0xffffffff - listener->angle);
angle >>= ANGLETOFINESHIFT;
@ -736,23 +735,23 @@ S_AdjustSoundParams (mobj_t* listener, mobj_t* source,
// volume calculation
if (approx_dist < S_CLOSE_DIST)
{
*vol = snd_SfxVolume;
*vol = snd_SfxVolume;
}
else if (gamemap == 8)
{
if (approx_dist > S_CLIPPING_DIST)
approx_dist = S_CLIPPING_DIST;
if (approx_dist > S_CLIPPING_DIST)
approx_dist = S_CLIPPING_DIST;
*vol = 15+ ((snd_SfxVolume-15)
*((S_CLIPPING_DIST - approx_dist)>>FRACBITS))
/ S_ATTENUATOR;
*vol = 15+ ((snd_SfxVolume-15)
*((S_CLIPPING_DIST - approx_dist)>>FRACBITS))
/ S_ATTENUATOR;
}
else
{
// distance effect
*vol = (snd_SfxVolume
* ((S_CLIPPING_DIST - approx_dist)>>FRACBITS))
/ S_ATTENUATOR;
// distance effect
*vol = (snd_SfxVolume
* ((S_CLIPPING_DIST - approx_dist)>>FRACBITS))
/ S_ATTENUATOR;
}
return (*vol > 0);
@ -765,9 +764,9 @@ S_AdjustSoundParams (mobj_t* listener, mobj_t* source,
int S_getChannel( void *origin, sfxinfo_t *sfxinfo, int sfxid )
{
// channel number to use
int cnum;
int cnum;
channel_t* c;
channel_t* c;
// Find an open channel
//for (cnum = 0; cnum < numChannels; cnum++)

View File

@ -32,6 +32,8 @@ rcsid[] = "$Id: st_lib.c,v 1.4 1997/02/03 16:47:56 b1 Exp $";
#include "z_zone.h"
#include "v_video.h"
#include "m_swap.h"
#include "i_system.h"
#include "w_wad.h"
@ -94,8 +96,8 @@ STlib_drawNum
int numdigits = n->width;
int num = *n->num;
int w = (n->p[0]->width);
int h = (n->p[0]->height);
int w = SHORT(n->p[0]->width);
int h = SHORT(n->p[0]->height);
int x = n->x;
int neg;
@ -222,10 +224,10 @@ STlib_updateMultIcon
{
if (mi->oldinum != -1)
{
x = mi->x - (mi->p[mi->oldinum]->leftoffset);
y = mi->y - (mi->p[mi->oldinum]->topoffset);
w = (mi->p[mi->oldinum]->width);
h = (mi->p[mi->oldinum]->height);
x = mi->x - SHORT(mi->p[mi->oldinum]->leftoffset);
y = mi->y - SHORT(mi->p[mi->oldinum]->topoffset);
w = SHORT(mi->p[mi->oldinum]->width);
h = SHORT(mi->p[mi->oldinum]->height);
if (y - ST_Y < 0)
I_Error("updateMultIcon: y - ST_Y < 0");
@ -271,10 +273,10 @@ STlib_updateBinIcon
if (*bi->on
&& (bi->oldval != *bi->val || refresh))
{
x = bi->x - (bi->p->leftoffset);
y = bi->y - (bi->p->topoffset);
w = (bi->p->width);
h = (bi->p->height);
x = bi->x - SHORT(bi->p->leftoffset);
y = bi->y - SHORT(bi->p->topoffset);
w = SHORT(bi->p->width);
h = SHORT(bi->p->height);
if (y - ST_Y < 0)
I_Error("updateBinIcon: y - ST_Y < 0");

View File

@ -1074,13 +1074,13 @@ void ST_drawWidgets(boolean refresh)
STlib_updateBinIcon(&w_armsbg, refresh);
for (i=0;i<5;i++)
STlib_updateMultIcon(&w_arms[i], refresh);
for (i=0;i<6;i++)
STlib_updateMultIcon(&w_arms[i], refresh);
STlib_updateMultIcon(&w_faces, refresh);
for (i=0;i<3;i++)
STlib_updateMultIcon(&w_keyboxes[i], refresh);
STlib_updateMultIcon(&w_keyboxes[i], refresh);
STlib_updateNum(&w_frags, refresh);
@ -1273,7 +1273,7 @@ void ST_initData(void)
for (i=0;i<3;i++)
keyboxes[i] = -1;
// STlib_init();
STlib_init();
}

View File

@ -17,9 +17,9 @@
// $Log:$
//
// DESCRIPTION:
// Gamma correction LUT stuff.
// Functions to draw patches (by post) directly to screen.
// Functions to blit a block to the screen.
// Gamma correction LUT stuff.
// Functions to draw patches (by post) directly to screen.
// Functions to blit a block to the screen.
//
//-----------------------------------------------------------------------------
@ -41,9 +41,9 @@ rcsid[] = "$Id: v_video.c,v 1.5 1997/02/03 22:45:13 b1 Exp $";
#include "kolibri.h"
// Each screen is [SCREENWIDTH*SCREENHEIGHT];
byte* screens[5];
byte* screens[5];
int dirtybox[4];
int dirtybox[4];
@ -134,17 +134,17 @@ byte gammatable[5][256] =
int usegamma;
int usegamma;
//
// V_MarkRect
//
void
V_MarkRect
( int x,
int y,
int width,
int height )
( int x,
int y,
int width,
int height )
{
M_AddToBox (dirtybox, x, y);
M_AddToBox (dirtybox, x+width-1, y+height-1);
@ -156,30 +156,30 @@ V_MarkRect
//
void
V_CopyRect
( int srcx,
int srcy,
int srcscrn,
int width,
int height,
int destx,
int desty,
int destscrn )
( int srcx,
int srcy,
int srcscrn,
int width,
int height,
int destx,
int desty,
int destscrn )
{
byte* src;
byte* dest;
byte* src;
byte* dest;
#ifdef RANGECHECK
if (srcx<0
||srcx+width >SCREENWIDTH
|| srcy<0
|| srcy+height>SCREENHEIGHT
||destx<0||destx+width >SCREENWIDTH
|| desty<0
|| desty+height>SCREENHEIGHT
|| (unsigned)srcscrn>4
|| (unsigned)destscrn>4)
||srcx+width >SCREENWIDTH
|| srcy<0
|| srcy+height>SCREENHEIGHT
||destx<0||destx+width >SCREENWIDTH
|| desty<0
|| desty+height>SCREENHEIGHT
|| (unsigned)srcscrn>4
|| (unsigned)destscrn>4)
{
I_Error ("Bad V_CopyRect");
I_Error ("Bad V_CopyRect");
}
#endif
V_MarkRect (destx, desty, width, height);
@ -189,9 +189,9 @@ V_CopyRect
for ( ; height>0 ; height--)
{
memcpy (dest, src, width);
src += SCREENWIDTH;
dest += SCREENWIDTH;
memcpy (dest, src, width);
src += SCREENWIDTH;
dest += SCREENWIDTH;
}
}
@ -202,38 +202,38 @@ V_CopyRect
//
void
V_DrawPatch
( int x,
int y,
int scrn,
patch_t* patch )
( int x,
int y,
int scrn,
patch_t* patch )
{
int count;
int col;
column_t* column;
byte* desttop;
byte* dest;
byte* source;
int w;
int count;
int col;
column_t* column;
byte* desttop;
byte* dest;
byte* source;
int w;
y -= SHORT(patch->topoffset);
x -= SHORT(patch->leftoffset);
#ifdef RANGECHECK
if (x<0
||x+SHORT(patch->width) >SCREENWIDTH
|| y<0
|| y+SHORT(patch->height)>SCREENHEIGHT
|| (unsigned)scrn>4)
||x+SHORT(patch->width) >SCREENWIDTH
|| y<0
|| y+SHORT(patch->height)>SCREENHEIGHT
|| (unsigned)scrn>4)
{
printf("Patch at %d,%d exceeds LFB\n", x,y );
//printf("Patch at %d,%d exceeds LFB\n", x,y );
// No I_Error abort - what is up with TNT.WAD?
printf("V_DrawPatch: bad patch (ignored)\n");
//printf("V_DrawPatch: bad patch (ignored)\n");
return;
}
#endif
if (!scrn)
V_MarkRect (x, y, SHORT(patch->width), SHORT(patch->height));
V_MarkRect (x, y, SHORT(patch->width), SHORT(patch->height));
col = 0;
desttop = screens[scrn]+y*SCREENWIDTH+x;
@ -242,23 +242,23 @@ V_DrawPatch
for ( ; col<w ; x++, col++, desttop++)
{
column = (column_t *)((byte *)patch + LONG(patch->columnofs[col]));
column = (column_t *)((byte *)patch + LONG(patch->columnofs[col]));
// step through the posts in a column
while (column->topdelta != 0xff )
{
source = (byte *)column + 3;
dest = desttop + column->topdelta*SCREENWIDTH;
count = column->length;
// step through the posts in a column
while (column->topdelta != 0xff )
{
source = (byte *)column + 3;
dest = desttop + column->topdelta*SCREENWIDTH;
count = column->length;
while (count--)
{
*dest = *source++;
dest += SCREENWIDTH;
}
column = (column_t *)( (byte *)column + column->length
+ 4 );
}
while (count--)
{
*dest = *source++;
dest += SCREENWIDTH;
}
column = (column_t *)( (byte *)column + column->length
+ 4 );
}
}
}
@ -269,36 +269,36 @@ V_DrawPatch
//
void
V_DrawPatchFlipped
( int x,
int y,
int scrn,
patch_t* patch )
( int x,
int y,
int scrn,
patch_t* patch )
{
int count;
int col;
column_t* column;
byte* desttop;
byte* dest;
byte* source;
int w;
int count;
int col;
column_t* column;
byte* desttop;
byte* dest;
byte* source;
int w;
y -= SHORT(patch->topoffset);
x -= SHORT(patch->leftoffset);
#ifdef RANGECHECK
if (x<0
||x+SHORT(patch->width) >SCREENWIDTH
|| y<0
|| y+SHORT(patch->height)>SCREENHEIGHT
|| (unsigned)scrn>4)
||x+SHORT(patch->width) >SCREENWIDTH
|| y<0
|| y+SHORT(patch->height)>SCREENHEIGHT
|| (unsigned)scrn>4)
{
printf("Patch origin %d,%d exceeds LFB\n", x,y );
//printf("Patch origin %d,%d exceeds LFB\n", x,y );
I_Error ("Bad V_DrawPatch in V_DrawPatchFlipped");
}
#endif
if (!scrn)
V_MarkRect (x, y, SHORT(patch->width), SHORT(patch->height));
V_MarkRect (x, y, SHORT(patch->width), SHORT(patch->height));
col = 0;
desttop = screens[scrn]+y*SCREENWIDTH+x;
@ -307,23 +307,23 @@ V_DrawPatchFlipped
for ( ; col<w ; x++, col++, desttop++)
{
column = (column_t *)((byte *)patch + LONG(patch->columnofs[w-1-col]));
column = (column_t *)((byte *)patch + LONG(patch->columnofs[w-1-col]));
// step through the posts in a column
while (column->topdelta != 0xff )
{
source = (byte *)column + 3;
dest = desttop + column->topdelta*SCREENWIDTH;
count = column->length;
// step through the posts in a column
while (column->topdelta != 0xff )
{
source = (byte *)column + 3;
dest = desttop + column->topdelta*SCREENWIDTH;
count = column->length;
while (count--)
{
*dest = *source++;
dest += SCREENWIDTH;
}
column = (column_t *)( (byte *)column + column->length
+ 4 );
}
while (count--)
{
*dest = *source++;
dest += SCREENWIDTH;
}
column = (column_t *)( (byte *)column + column->length
+ 4 );
}
}
}
@ -335,63 +335,63 @@ V_DrawPatchFlipped
//
void
V_DrawPatchDirect
( int x,
int y,
int scrn,
patch_t* patch )
( int x,
int y,
int scrn,
patch_t* patch )
{
V_DrawPatch (x,y,scrn, patch);
/*
int count;
int col;
column_t* column;
byte* desttop;
byte* dest;
byte* source;
int w;
int count;
int col;
column_t* column;
byte* desttop;
byte* dest;
byte* source;
int w;
y -= SHORT(patch->topoffset);
x -= SHORT(patch->leftoffset);
#ifdef RANGECHECK
if (x<0
||x+SHORT(patch->width) >SCREENWIDTH
|| y<0
|| y+SHORT(patch->height)>SCREENHEIGHT
|| (unsigned)scrn>4)
||x+SHORT(patch->width) >SCREENWIDTH
|| y<0
|| y+SHORT(patch->height)>SCREENHEIGHT
|| (unsigned)scrn>4)
{
I_Error ("Bad V_DrawPatchDirect");
I_Error ("Bad V_DrawPatchDirect");
}
#endif
// V_MarkRect (x, y, SHORT(patch->width), SHORT(patch->height));
// V_MarkRect (x, y, SHORT(patch->width), SHORT(patch->height));
desttop = destscreen + y*SCREENWIDTH/4 + (x>>2);
w = SHORT(patch->width);
for ( col = 0 ; col<w ; col++)
{
outp (SC_INDEX+1,1<<(x&3));
column = (column_t *)((byte *)patch + LONG(patch->columnofs[col]));
outp (SC_INDEX+1,1<<(x&3));
column = (column_t *)((byte *)patch + LONG(patch->columnofs[col]));
// step through the posts in a column
// step through the posts in a column
while (column->topdelta != 0xff )
{
source = (byte *)column + 3;
dest = desttop + column->topdelta*SCREENWIDTH/4;
count = column->length;
while (column->topdelta != 0xff )
{
source = (byte *)column + 3;
dest = desttop + column->topdelta*SCREENWIDTH/4;
count = column->length;
while (count--)
{
*dest = *source++;
dest += SCREENWIDTH/4;
}
column = (column_t *)( (byte *)column + column->length
+ 4 );
}
if ( ((++x)&3) == 0 )
desttop++; // go to next byte, not next plane
while (count--)
{
*dest = *source++;
dest += SCREENWIDTH/4;
}
column = (column_t *)( (byte *)column + column->length
+ 4 );
}
if ( ((++x)&3) == 0 )
desttop++; // go to next byte, not next plane
}*/
}
@ -403,23 +403,23 @@ V_DrawPatchDirect
//
void
V_DrawBlock
( int x,
int y,
int scrn,
int width,
int height,
byte* src )
( int x,
int y,
int scrn,
int width,
int height,
byte* src )
{
byte* dest;
byte* dest;
#ifdef RANGECHECK
if (x<0
||x+width >SCREENWIDTH
|| y<0
|| y+height>SCREENHEIGHT
|| (unsigned)scrn>4 )
||x+width >SCREENWIDTH
|| y<0
|| y+height>SCREENHEIGHT
|| (unsigned)scrn>4 )
{
I_Error ("Bad V_DrawBlock");
I_Error ("Bad V_DrawBlock");
}
#endif
@ -429,9 +429,9 @@ V_DrawBlock
while (height--)
{
memcpy (dest, src, width);
src += width;
dest += SCREENWIDTH;
memcpy (dest, src, width);
src += width;
dest += SCREENWIDTH;
}
}
@ -443,23 +443,23 @@ V_DrawBlock
//
void
V_GetBlock
( int x,
int y,
int scrn,
int width,
int height,
byte* dest )
( int x,
int y,
int scrn,
int width,
int height,
byte* dest )
{
byte* src;
byte* src;
#ifdef RANGECHECK
if (x<0
||x+width >SCREENWIDTH
|| y<0
|| y+height>SCREENHEIGHT
|| (unsigned)scrn>4 )
||x+width >SCREENWIDTH
|| y<0
|| y+height>SCREENHEIGHT
|| (unsigned)scrn>4 )
{
I_Error ("Bad V_DrawBlock");
I_Error ("Bad V_DrawBlock");
}
#endif
@ -467,9 +467,9 @@ V_GetBlock
while (height--)
{
memcpy (dest, src, width);
src += SCREENWIDTH;
dest += width;
memcpy (dest, src, width);
src += SCREENWIDTH;
dest += width;
}
}
@ -481,13 +481,13 @@ V_GetBlock
//
void V_Init (void)
{
int i;
byte* base;
size_t size;
int i;
byte* base;
size_t size;
// stick these in low dos memory on PCs
size = SCREENWIDTH*SCREENHEIGHT*4;
base = (byte*)UserAlloc(size);
for (i=0 ; i<4 ; i++)
screens[i] = base + i*SCREENWIDTH*SCREENHEIGHT;
screens[i] = base + i*SCREENWIDTH*SCREENHEIGHT;
}

View File

@ -24,8 +24,6 @@
static const char
rcsid[] = "$Id: i_unix.c,v 1.5 1997/02/03 22:45:10 b1 Exp $";
#include <windows.h>
#include <dsound.h>
#include "sounds.h"
char MsgText[256];
@ -67,13 +65,13 @@ void I_CreateSound(void)
hret = DirectSoundCreate8(NULL, &lpDS, NULL);
if (hret != DS_OK)
{
printf("failed DirectSoundCreate");
//printf("failed DirectSoundCreate");
return;
}
hret = lpDS->lpVtbl->SetCooperativeLevel(lpDS, win, DSSCL_PRIORITY);
if (hret != DS_OK)
printf("failled DirectSound.SetCooperativeLevel");
//printf("failled DirectSound.SetCooperativeLevel");
memset( &wfx,0, sizeof(WAVEFORMATEX) );
wfx.wFormatTag = WAVE_FORMAT_PCM;
@ -119,7 +117,7 @@ void I_SubmitSound(signed short *mixbuffer)
hret=lpMix[mixbuff]->lpVtbl->Lock(lpMix[mixbuff],0,MIXBUFFERSIZE,&pPtr1,
&dwSize1,&pPtr2,&dwSize2,0);
if (hret!=DS_OK)
{ printf("Error locking on play start");
{ //printf("Error locking on play start");
return ;
}
memcpy(pPtr1, (void*)mixbuffer, MIXBUFFERSIZE);

View File

@ -17,7 +17,7 @@
// $Log:$
//
// DESCRIPTION:
// Handles WAD file header, directory, lump I/O.
// Handles WAD file header, directory, lump I/O.
//
//-----------------------------------------------------------------------------
@ -40,45 +40,53 @@ rcsid[] = "$Id: w_wad.c,v 1.5 1997/02/03 16:47:57 b1 Exp $";
#include <malloc.h>
extern char *main_file;
#ifdef DLHEAP
void* _cdecl dlmalloc(size_t);
void _cdecl dlfree(void*);
void _cdecl mf_init();
#define malloc dlmalloc
#define free dlfree
#define realloc dlrealloc
#endif
size_t FileSize(FILE *handle);
int _stdcall read_file (char *name, void *buff,
size_t offset, size_t count, size_t *reads);
//
// GLOBALS
//
// Location of each lump on disk.
lumpinfo_t* lumpinfo;
int numlumps;
void** lumpcache;
int filelength (FILE *handle)
{
unsigned long pos, size;
pos = ftell(handle);
fseek(handle, 0, SEEK_END);
size = ftell(handle);
fseek(handle, pos, SEEK_SET);
return (int)size;
}
lumpinfo_t* lumpinfo;
int numlumps;
void** lumpcache;
void
ExtractFileBase
( char* path,
char* dest )
( char* path,
char* dest )
{
char* src;
int length;
char* src;
int length;
src = path + strlen(path) - 1;
// back up until a \ or the start
while (src != path
&& *(src-1) != '\\'
&& *(src-1) != '/')
&& *(src-1) != '\\'
&& *(src-1) != '/')
{
src--;
src--;
}
// copy up to eight characters
@ -87,10 +95,10 @@ ExtractFileBase
while (*src && *src != '.')
{
if (++length == 9)
I_Error ("Filename base of %s >8 chars",path);
if (++length == 9)
I_Error ("Filename base of %s >8 chars",path);
*dest++ = toupper((int)*src++);
*dest++ = toupper((int)*src++);
}
}
@ -115,91 +123,81 @@ ExtractFileBase
// specially to allow map reloads.
// But: the reload feature is a fragile hack...
#ifdef __BEOS__
#ifdef __GNUC__
extern void *alloca(int);
#else
#include <alloca.h>
#endif
#endif /* __BEOS__ */
int reloadlump;
char* reloadname;
int reloadlump;
char* reloadname;
void W_AddFile (char *filename)
{
wadinfo_t header;
lumpinfo_t* lump_p;
unsigned i;
FILE *handle;
int length;
int startlump;
filelump_t* fileinfo;
filelump_t singleinfo;
int storehandle;
wadinfo_t header;
lumpinfo_t* lump_p;
unsigned i;
FILE *handle;
int length;
int startlump;
filelump_t* fileinfo;
filelump_t singleinfo;
int storehandle;
int err;
size_t bytes;
// open the file and add to directory
// handle reload indicator.
if (filename[0] == '~')
{
filename++;
reloadname = filename;
reloadlump = numlumps;
filename++;
reloadname = filename;
reloadlump = numlumps;
}
if ( (handle = fopen (filename,"rb")) == NULL)
{
printf (" couldn't open %s\n",filename);
return;
printf (" couldn't open %s\n",filename);
return;
}
printf (" adding %s\n",filename);
printf (" adding %s\n\r",filename);
startlump = numlumps;
if (I_strncasecmp (filename+strlen(filename)-3 , "wad", 3 ) )
if (strnicmp (filename+strlen(filename)-3 , "wad", 3 ) )
{
// single lump file
fileinfo = &singleinfo;
singleinfo.filepos = 0;
singleinfo.size = LONG(filelength(handle));
ExtractFileBase (filename, singleinfo.name);
numlumps++;
// single lump file
fileinfo = &singleinfo;
singleinfo.filepos = 0;
singleinfo.size = FileSize(handle);
ExtractFileBase (filename, singleinfo.name);
numlumps++;
}
else
{
//WAD file
printf("f1 at %x,%u\n",&header,handle);
fread (&header, 1, sizeof(header), handle);
printf("f2\n");
if (strncmp(header.identification,"IWAD",4))
{
printf("No IWAD id\n");
// Homebrew levels?
if (strncmp(header.identification,"PWAD",4))
{
I_Error ("Wad file %s doesn't have IWAD "
"or PWAD id\n", filename);
}
// printf("WAD magic OK\n");
// ???modifiedgame = true;
}
printf("after checking hdr\n");
header.numlumps = LONG(header.numlumps);
printf("%u lumps in WAD\n",header.numlumps);
header.infotableofs = LONG(header.infotableofs);
printf("infor table at %x\n",header.infotableofs);
length = header.numlumps*sizeof(filelump_t);
printf("length %u\n",length);
fileinfo = alloca(length);
//WAD file
fread (&header, 1, sizeof(header), handle);
printf("seeking to info table\n");
fseek (handle, header.infotableofs, SEEK_SET);
printf("f3\n");
fread (fileinfo, 1, length, handle);
printf("f4\n");
numlumps += header.numlumps;
if (strncmp(header.identification,"IWAD",4))
{
printf("No IWAD id\n");
// Homebrew levels?
if (strncmp(header.identification,"PWAD",4))
{
I_Error ("Wad file %s doesn't have IWAD "
"or PWAD id\n", filename);
}
printf("WAD magic OK\n");
// ???modifiedgame = true;
}
header.numlumps = LONG(header.numlumps);
header.infotableofs = LONG(header.infotableofs);
length = header.numlumps*sizeof(filelump_t);
fileinfo = alloca(length);
fseek (handle, header.infotableofs, SEEK_SET);
fread (fileinfo, 1, length, handle);
numlumps += header.numlumps;
}
@ -207,7 +205,7 @@ void W_AddFile (char *filename)
lumpinfo = realloc (lumpinfo, numlumps*sizeof(lumpinfo_t));
if (!lumpinfo)
I_Error ("Couldn't realloc lumpinfo");
I_Error ("Couldn't realloc lumpinfo");
lump_p = &lumpinfo[startlump];
@ -215,14 +213,14 @@ void W_AddFile (char *filename)
for (i=startlump ; i<numlumps ; i++,lump_p++, fileinfo++)
{
lump_p->handle = storehandle;
lump_p->position = LONG(fileinfo->filepos);
lump_p->size = LONG(fileinfo->size);
strncpy (lump_p->name, fileinfo->name, 8);
lump_p->handle = storehandle;
lump_p->position = LONG(fileinfo->filepos);
lump_p->size = LONG(fileinfo->size);
strncpy (lump_p->name, fileinfo->name, 8);
}
if (reloadname)
fclose (handle);
fclose (handle);
}
@ -235,51 +233,46 @@ void W_AddFile (char *filename)
//
void W_Reload (void)
{
wadinfo_t header;
int lumpcount;
lumpinfo_t* lump_p;
unsigned i;
FILE *handle;
int length;
filelump_t* fileinfo;
wadinfo_t header;
int lumpcount;
lumpinfo_t* lump_p;
unsigned i;
FILE *handle;
int length;
filelump_t* fileinfo;
if (!reloadname)
return;
return;
if ( (handle = fopen (reloadname,"rb")) == NULL)
I_Error ("W_Reload: couldn't open %s",reloadname);
I_Error ("W_Reload: couldn't open %s",reloadname);
printf("f5\n");
fread (&header, 1, sizeof(header), handle);
printf("f6\n");
lumpcount = LONG(header.numlumps);
header.infotableofs = LONG(header.infotableofs);
length = lumpcount*sizeof(filelump_t);
fileinfo = malloc (length);
fseek (handle, header.infotableofs, SEEK_SET);
printf("f7\n");
fread (fileinfo, 1, length, handle);
printf("f8\n");
// Fill in lumpinfo
lump_p = &lumpinfo[reloadlump];
for (i=reloadlump ;
i<reloadlump+lumpcount ;
i++,lump_p++, fileinfo++)
i<reloadlump+lumpcount ;
i++,lump_p++, fileinfo++)
{
if (lumpcache[i])
Z_Free (lumpcache[i]);
if (lumpcache[i])
Z_Free (lumpcache[i]);
lump_p->position = LONG(fileinfo->filepos);
lump_p->size = LONG(fileinfo->size);
lump_p->position = LONG(fileinfo->filepos);
lump_p->size = LONG(fileinfo->size);
}
fclose (handle);
}
//
// W_InitMultipleFiles
// Pass a null terminated list of files to use.
@ -295,26 +288,26 @@ void W_Reload (void)
//
void W_InitMultipleFiles (char** filenames)
{
int size;
int size;
// open all the files, load headers, and count lumps
numlumps = 0;
// will be realloced as lumps are added
lumpinfo = malloc(1);
lumpinfo = malloc(16384);
for ( ; *filenames ; filenames++)
W_AddFile (*filenames);
W_AddFile (*filenames);
if (!numlumps)
I_Error ("W_InitFiles: no files found");
I_Error ("W_InitFiles: no files found");
// set up caching
size = numlumps * sizeof(*lumpcache);
lumpcache = malloc (size);
if (!lumpcache)
I_Error ("Couldn't allocate lumpcache");
I_Error ("Couldn't allocate lumpcache");
memset (lumpcache,0, size);
}
@ -328,7 +321,7 @@ void W_InitMultipleFiles (char** filenames)
//
void W_InitFile (char* filename)
{
char* names[2];
char* names[2];
names[0] = filename;
names[1] = NULL;
@ -355,14 +348,14 @@ int W_NumLumps (void)
int W_CheckNumForName (char* name)
{
union {
char s[9];
int x[2];
char s[9];
int x[2];
} name8;
int v1;
int v2;
lumpinfo_t* lump_p;
int v1;
int v2;
lumpinfo_t* lump_p;
// make the name into two integers for easy compares
strncpy (name8.s,name,8);
@ -382,11 +375,11 @@ int W_CheckNumForName (char* name)
while (lump_p-- != lumpinfo)
{
if ( *(int *)lump_p->name == v1
&& *(int *)&lump_p->name[4] == v2)
{
return lump_p - lumpinfo;
}
if ( *(int *)lump_p->name == v1
&& *(int *)&lump_p->name[4] == v2)
{
return lump_p - lumpinfo;
}
}
// TFB. Not found.
@ -402,7 +395,7 @@ int W_CheckNumForName (char* name)
//
int W_GetNumForName (char* name)
{
int i;
int i;
i = W_CheckNumForName (name);
@ -420,7 +413,7 @@ int W_GetNumForName (char* name)
int W_LumpLength (int lump)
{
if (lump >= numlumps)
I_Error ("W_LumpLength: %i >= numlumps",lump);
I_Error ("W_LumpLength: %i >= numlumps",lump);
return lumpinfo[lump].size;
}
@ -434,15 +427,16 @@ int W_LumpLength (int lump)
//
void
W_ReadLump
( int lump,
void* dest )
( int lump,
void* dest )
{
int c;
lumpinfo_t* l;
FILE *handle;
int c;
lumpinfo_t* l;
FILE *handle;
size_t bytes;
if (lump >= numlumps)
I_Error ("W_ReadLump: %i >= numlumps",lump);
I_Error ("W_ReadLump: %i >= numlumps",lump);
l = lumpinfo+lump;
@ -450,21 +444,21 @@ W_ReadLump
if (l->handle == -1)
{
// reloadable file, so use open / read / close
if ( (handle = fopen (reloadname,"rb")) == NULL)
I_Error ("W_ReadLump: couldn't open %s",reloadname);
// reloadable file, so use open / read / close
if ( (handle = fopen (reloadname,"rb")) == NULL)
I_Error ("W_ReadLump: couldn't open %s",reloadname);
}
else
handle = (FILE *)l->handle;
handle = (FILE *)l->handle;
fseek (handle, l->position, SEEK_SET);
c = fread (dest, 1, l->size, handle);
if (c < l->size)
I_Error ("W_ReadLump: only read %i of %i on lump %i",
c,l->size,lump);
I_Error ("W_ReadLump: only read %i of %i on lump %i",
c,l->size,lump);
if (l->handle == -1)
fclose (handle);
fclose (handle);
// ??? I_EndRead ();
}
@ -477,26 +471,26 @@ W_ReadLump
//
void*
W_CacheLumpNum
( int lump,
int tag )
( int lump,
int tag )
{
byte* ptr;
byte* ptr;
if ((unsigned)lump >= numlumps)
I_Error ("W_CacheLumpNum: %i >= numlumps",lump);
if ((unsigned)lump >= (unsigned)numlumps)
I_Error ("W_CacheLumpNum: %i >= numlumps",lump);
if (!lumpcache[lump])
{
// read the lump in
// read the lump in
//printf ("cache miss on lump %i\n",lump);
ptr = Z_Malloc (W_LumpLength (lump), tag, &lumpcache[lump]);
W_ReadLump (lump, lumpcache[lump]);
//printf ("cache miss on lump %i\n",lump);
ptr = Z_Malloc (W_LumpLength (lump), tag, &lumpcache[lump]);
W_ReadLump (lump, lumpcache[lump]);
}
else
{
//printf ("cache hit on lump %i\n",lump);
Z_ChangeTag (lumpcache[lump],tag);
//printf ("cache hit on lump %i\n",lump);
Z_ChangeTag (lumpcache[lump],tag);
}
return lumpcache[lump];
@ -509,8 +503,8 @@ W_CacheLumpNum
//
void*
W_CacheLumpName
( char* name,
int tag )
( char* name,
int tag )
{
return W_CacheLumpNum (W_GetNumForName(name), tag);
}
@ -520,37 +514,37 @@ W_CacheLumpName
//
// W_Profile
//
int info[2500][10];
int profilecount;
int info[2500][10];
int profilecount;
void W_Profile (void)
{
int i;
memblock_t* block;
void* ptr;
char ch;
FILE* f;
int j;
char name[9];
int i;
memblock_t* block;
void* ptr;
char ch;
FILE* f;
int j;
char name[9];
for (i=0 ; i<numlumps ; i++)
{
ptr = lumpcache[i];
if (!ptr)
{
ch = ' ';
continue;
}
else
{
block = (memblock_t *) ( (byte *)ptr - sizeof(memblock_t));
if (block->tag < PU_PURGELEVEL)
ch = 'S';
else
ch = 'P';
}
info[i][profilecount] = ch;
ptr = lumpcache[i];
if (!ptr)
{
ch = ' ';
continue;
}
else
{
block = (memblock_t *) ( (byte *)ptr - sizeof(memblock_t));
if (block->tag < PU_PURGELEVEL)
ch = 'S';
else
ch = 'P';
}
info[i][profilecount] = ch;
}
profilecount++;
@ -559,23 +553,30 @@ void W_Profile (void)
for (i=0 ; i<numlumps ; i++)
{
memcpy (name,lumpinfo[i].name,8);
memcpy (name,lumpinfo[i].name,8);
for (j=0 ; j<8 ; j++)
if (!name[j])
break;
for (j=0 ; j<8 ; j++)
if (!name[j])
break;
for ( ; j<8 ; j++)
name[j] = ' ';
for ( ; j<8 ; j++)
name[j] = ' ';
printf ("%s ",name);
//printf ("%s ",name);
for (j=0 ; j<profilecount ; j++)
fprintf (f," %c",info[i][j]);
for (j=0 ; j<profilecount ; j++)
fprintf (f," %c",info[i][j]);
printf ("\n");
//printf ("\n");
}
fclose (f);
}
#endif

View File

@ -26,7 +26,7 @@
//
//
// DESCRIPTION:
// Zone Memory Allocation. Neat.
// Zone Memory Allocation. Neat.
//
//-----------------------------------------------------------------------------
@ -49,24 +49,24 @@ z_zone_rcsid[] = "$Id: z_zone.c,v 1.2 1997/12/29 19:51:30 pekangas Exp $";
// because it will get overwritten automatically if needed.
//
#define ZONEID 0x1d4a11
#define ZONEID 0x1d4a11
typedef struct
{
// total bytes malloced, including header
int size;
int size;
// start / end cap for linked list
memblock_t blocklist;
memblock_t blocklist;
memblock_t* rover;
memblock_t* rover;
} memzone_t;
memzone_t* mainzone;
memzone_t* mainzone;
@ -75,12 +75,12 @@ memzone_t* mainzone;
//
void Z_ClearZone (memzone_t* zone)
{
memblock_t* block;
memblock_t* block;
// set the entire zone to one free block
zone->blocklist.next =
zone->blocklist.prev =
block = (memblock_t *)( (byte *)zone + sizeof(memzone_t) );
zone->blocklist.prev =
block = (memblock_t *)( (byte *)zone + sizeof(memzone_t) );
zone->blocklist.user = (void *)zone;
zone->blocklist.tag = PU_STATIC;
@ -101,16 +101,16 @@ void Z_ClearZone (memzone_t* zone)
//
void Z_Init (void)
{
memblock_t* block;
int size;
memblock_t* block;
int size;
mainzone = (memzone_t *)I_ZoneBase (&size);
mainzone->size = size;
// set the entire zone to one free block
mainzone->blocklist.next =
mainzone->blocklist.prev =
block = (memblock_t *)( (byte *)mainzone + sizeof(memzone_t) );
mainzone->blocklist.prev =
block = (memblock_t *)( (byte *)mainzone + sizeof(memzone_t) );
mainzone->blocklist.user = (void *)mainzone;
mainzone->blocklist.tag = PU_STATIC;
@ -130,21 +130,21 @@ void Z_Init (void)
//
void Z_Free (void* ptr)
{
memblock_t* block;
memblock_t* other;
memblock_t* block;
memblock_t* other;
block = (memblock_t *) ( (byte *)ptr - sizeof(memblock_t));
if (block->id != ZONEID)
I_Error ("Z_Free: freed a pointer without ZONEID");
I_Error ("Z_Free: freed a pointer without ZONEID");
if (block->user > (void **)0x100)
{
// smaller values are not pointers
// Note: OS-dependend?
// smaller values are not pointers
// Note: OS-dependend?
// clear the user's mark
*block->user = 0;
// clear the user's mark
*block->user = 0;
}
// mark as free
@ -156,27 +156,27 @@ void Z_Free (void* ptr)
if (!other->user)
{
// merge with previous free block
other->size += block->size;
other->next = block->next;
other->next->prev = other;
// merge with previous free block
other->size += block->size;
other->next = block->next;
other->next->prev = other;
if (block == mainzone->rover)
mainzone->rover = other;
if (block == mainzone->rover)
mainzone->rover = other;
block = other;
block = other;
}
other = block->next;
if (!other->user)
{
// merge the next free block onto the end
block->size += other->size;
block->next = other->next;
block->next->prev = block;
// merge the next free block onto the end
block->size += other->size;
block->next = other->next;
block->next->prev = block;
if (other == mainzone->rover)
mainzone->rover = block;
if (other == mainzone->rover)
mainzone->rover = block;
}
}
@ -186,20 +186,20 @@ void Z_Free (void* ptr)
// Z_Malloc
// You can pass a NULL user if the tag is < PU_PURGELEVEL.
//
#define MINFRAGMENT 64
#define MINFRAGMENT 64
void*
Z_Malloc
( int size,
int tag,
void* user )
( int size,
int tag,
void* user )
{
int extra;
memblock_t* start;
int extra;
memblock_t* start;
memblock_t* rover;
memblock_t* newblock;
memblock_t* base;
memblock_t* base;
size = (size + 3) & ~3;
@ -216,40 +216,40 @@ Z_Malloc
base = mainzone->rover;
if (!base->prev->user)
base = base->prev;
base = base->prev;
rover = base;
start = base->prev;
do
{
if (rover == start)
{
// scanned all the way around the list
I_Error ("Z_Malloc: failed on allocation of %i bytes", size);
}
if (rover == start)
{
// scanned all the way around the list
I_Error ("Z_Malloc: failed on allocation of %i bytes", size);
}
if (rover->user)
{
if (rover->tag < PU_PURGELEVEL)
{
// hit a block that can't be purged,
// so move base past it
base = rover = rover->next;
}
else
{
// free the rover block (adding the size to base)
if (rover->user)
{
if (rover->tag < PU_PURGELEVEL)
{
// hit a block that can't be purged,
// so move base past it
base = rover = rover->next;
}
else
{
// free the rover block (adding the size to base)
// the rover can be the base block
base = base->prev;
Z_Free ((byte *)rover+sizeof(memblock_t));
base = base->next;
rover = base->next;
}
}
else
rover = rover->next;
// the rover can be the base block
base = base->prev;
Z_Free ((byte *)rover+sizeof(memblock_t));
base = base->next;
rover = base->next;
}
}
else
rover = rover->next;
} while (base->user || base->size < size);
@ -258,34 +258,34 @@ Z_Malloc
if (extra > MINFRAGMENT)
{
// there will be a free fragment after the allocated block
newblock = (memblock_t *) ((byte *)base + size );
newblock->size = extra;
// there will be a free fragment after the allocated block
newblock = (memblock_t *) ((byte *)base + size );
newblock->size = extra;
// NULL indicates free block.
newblock->user = NULL;
newblock->tag = 0;
newblock->prev = base;
newblock->next = base->next;
newblock->next->prev = newblock;
// NULL indicates free block.
newblock->user = NULL;
newblock->tag = 0;
newblock->prev = base;
newblock->next = base->next;
newblock->next->prev = newblock;
base->next = newblock;
base->size = size;
base->next = newblock;
base->size = size;
}
if (user)
{
// mark as an in use block
base->user = user;
*(void **)user = (void *) ((byte *)base + sizeof(memblock_t));
// mark as an in use block
base->user = user;
*(void **)user = (void *) ((byte *)base + sizeof(memblock_t));
}
else
{
if (tag >= PU_PURGELEVEL)
I_Error ("Z_Malloc: an owner is required for purgable blocks");
if (tag >= PU_PURGELEVEL)
I_Error ("Z_Malloc: an owner is required for purgable blocks");
// mark as in use, but unowned
base->user = (void *)2;
// mark as in use, but unowned
base->user = (void *)2;
}
base->tag = tag;
@ -304,25 +304,25 @@ Z_Malloc
//
void
Z_FreeTags
( int lowtag,
int hightag )
( int lowtag,
int hightag )
{
memblock_t* block;
memblock_t* next;
memblock_t* block;
memblock_t* next;
for (block = mainzone->blocklist.next ;
block != &mainzone->blocklist ;
block = next)
block != &mainzone->blocklist ;
block = next)
{
// get link before freeing
next = block->next;
// get link before freeing
next = block->next;
// free block?
if (!block->user)
continue;
// free block?
if (!block->user)
continue;
if (block->tag >= lowtag && block->tag <= hightag)
Z_Free ( (byte *)block+sizeof(memblock_t));
if (block->tag >= lowtag && block->tag <= hightag)
Z_Free ( (byte *)block+sizeof(memblock_t));
}
}
@ -334,37 +334,37 @@ Z_FreeTags
//
void
Z_DumpHeap
( int lowtag,
int hightag )
( int lowtag,
int hightag )
{
memblock_t* block;
memblock_t* block;
printf ("zone size: %i location: %p\n",
mainzone->size,mainzone);
//printf ("zone size: %i location: %p\n",
// mainzone->size,mainzone);
printf ("tag range: %i to %i\n",
lowtag, hightag);
//printf ("tag range: %i to %i\n",
// lowtag, hightag);
for (block = mainzone->blocklist.next ; ; block = block->next)
{
if (block->tag >= lowtag && block->tag <= hightag)
printf ("block:%p size:%7i user:%p tag:%3i\n",
block, block->size, block->user, block->tag);
if (block->tag >= lowtag && block->tag <= hightag)
printf ("block:%p size:%7i user:%p tag:%3i\n",
block, block->size, block->user, block->tag);
if (block->next == &mainzone->blocklist)
{
// all blocks have been hit
break;
}
if (block->next == &mainzone->blocklist)
{
// all blocks have been hit
break;
}
if ( (byte *)block + block->size != (byte *)block->next)
printf ("ERROR: block size does not touch the next block\n");
if ( (byte *)block + block->size != (byte *)block->next)
printf ("ERROR: block size does not touch the next block\n");
if ( block->next->prev != block)
printf ("ERROR: next block doesn't have proper back link\n");
if ( block->next->prev != block)
printf ("ERROR: next block doesn't have proper back link\n");
if (!block->user && !block->next->user)
printf ("ERROR: two consecutive free blocks\n");
if (!block->user && !block->next->user)
printf ("ERROR: two consecutive free blocks\n");
}
}
@ -374,29 +374,29 @@ Z_DumpHeap
//
void Z_FileDumpHeap (FILE* f)
{
memblock_t* block;
memblock_t* block;
fprintf (f,"zone size: %i location: %p\n",mainzone->size,mainzone);
//printf ("zone size: %i location: %p\n",mainzone->size,mainzone);
for (block = mainzone->blocklist.next ; ; block = block->next)
{
fprintf (f,"block:%p size:%7i user:%p tag:%3i\n",
block, block->size, block->user, block->tag);
printf ("block:%p size:%7i user:%p tag:%3i\n",
block, block->size, block->user, block->tag);
if (block->next == &mainzone->blocklist)
{
// all blocks have been hit
break;
}
if (block->next == &mainzone->blocklist)
{
// all blocks have been hit
break;
}
if ( (byte *)block + block->size != (byte *)block->next)
fprintf (f,"ERROR: block size does not touch the next block\n");
if ( (byte *)block + block->size != (byte *)block->next)
printf ("ERROR: block size does not touch the next block\n");
if ( block->next->prev != block)
fprintf (f,"ERROR: next block doesn't have proper back link\n");
if ( block->next->prev != block)
printf ("ERROR: next block doesn't have proper back link\n");
if (!block->user && !block->next->user)
fprintf (f,"ERROR: two consecutive free blocks\n");
if (!block->user && !block->next->user)
printf ("ERROR: two consecutive free blocks\n");
}
}
@ -407,24 +407,24 @@ void Z_FileDumpHeap (FILE* f)
//
void Z_CheckHeap (void)
{
memblock_t* block;
memblock_t* block;
for (block = mainzone->blocklist.next ; ; block = block->next)
{
if (block->next == &mainzone->blocklist)
{
// all blocks have been hit
break;
}
if (block->next == &mainzone->blocklist)
{
// all blocks have been hit
break;
}
if ( (byte *)block + block->size != (byte *)block->next)
I_Error ("Z_CheckHeap: block size does not touch the next block\n");
if ( (byte *)block + block->size != (byte *)block->next)
I_Error ("Z_CheckHeap: block size does not touch the next block\n");
if ( block->next->prev != block)
I_Error ("Z_CheckHeap: next block doesn't have proper back link\n");
if ( block->next->prev != block)
I_Error ("Z_CheckHeap: next block doesn't have proper back link\n");
if (!block->user && !block->next->user)
I_Error ("Z_CheckHeap: two consecutive free blocks\n");
if (!block->user && !block->next->user)
I_Error ("Z_CheckHeap: two consecutive free blocks\n");
}
}
@ -436,18 +436,18 @@ void Z_CheckHeap (void)
//
void
Z_ChangeTag2
( void* ptr,
int tag )
( void* ptr,
int tag )
{
memblock_t* block;
memblock_t* block;
block = (memblock_t *) ( (byte *)ptr - sizeof(memblock_t));
if (block->id != ZONEID)
I_Error ("Z_ChangeTag: freed a pointer without ZONEID");
I_Error ("Z_ChangeTag: freed a pointer without ZONEID");
if (tag >= PU_PURGELEVEL && (unsigned)block->user < 0x100)
I_Error ("Z_ChangeTag: an owner is required for purgable blocks");
I_Error ("Z_ChangeTag: an owner is required for purgable blocks");
block->tag = tag;
}
@ -459,17 +459,17 @@ Z_ChangeTag2
//
int Z_FreeMemory (void)
{
memblock_t* block;
int free;
memblock_t* block;
int free;
free = 0;
for (block = mainzone->blocklist.next ;
block != &mainzone->blocklist;
block = block->next)
block != &mainzone->blocklist;
block = block->next)
{
if (!block->user || block->tag >= PU_PURGELEVEL)
free += block->size;
if (!block->user || block->tag >= PU_PURGELEVEL)
free += block->size;
}
return free;
}