Commit c71617f4 authored by Steven Fuller's avatar Steven Fuller

id_ca.c: Cleaned up

parent 33b6fa93
------------- Please Disregard the Following Outdated Text: ----------------
* One binary, any game type. * One binary, any game type.
* A key to change viewsize while playing (note: max == 20, min == 5 or so...) * A key to change viewsize while playing (note: max == 20, min == 5 or so...)
* Game able to cope at any virtual resolution in software mode. OpenGL * Game able to work with any resolution in software mode
handles this transparently (after setting correct glViewport)
* Audio support using OpenAL * Audio support using OpenAL
* Add support for the Mac version, if possible * Add support for the Mac version, if possible
* Network support! * Network support!
...@@ -25,3 +20,4 @@ ...@@ -25,3 +20,4 @@
* Configuration files and save games which work regardless of operating * Configuration files and save games which work regardless of operating
system/processor/binary build system/processor/binary build
* Suite of utilities to edit the game data. * Suite of utilities to edit the game data.
* Resolve any endian issues
...@@ -13,10 +13,7 @@ Sound Menu: ...@@ -13,10 +13,7 @@ Sound Menu:
* Sampling Rate: * Sampling Rate:
- 44100 - 44100
- 22050 - 22050
------------------------------------------------------------------------------
------------- Please Disregard the Following Outdated Text: ----------------
* *
SD_StartMusic((MusicGroup *)audiosegs[STARTMUSIC + chunk]); SD_StartMusic((MusicGroup *)audiosegs[STARTMUSIC + chunk]);
=> =>
...@@ -39,7 +36,7 @@ prevent confusion. OR ver.c would depend on the source, but it does not have ...@@ -39,7 +36,7 @@ prevent confusion. OR ver.c would depend on the source, but it does not have
a version number, just __TIME__. this version id would be used for a version number, just __TIME__. this version id would be used for
savegames until they are fixed to not use pointers savegames until they are fixed to not use pointers
* use static and const where appropriate * use static and const where appropriate
* convert uses of open() to fopen(), etc * convert uses of open() to fopen(), etc maybe
* menu code is a mess, always does things differently than the rest of the * menu code is a mess, always does things differently than the rest of the
code, it really needs to be cleaned up code, it really needs to be cleaned up
* id_ca.c cache code: fix/readd/rewrite the "garbage collection" system? * id_ca.c cache code: fix/readd/rewrite the "garbage collection" system?
...@@ -92,14 +89,9 @@ directly ...@@ -92,14 +89,9 @@ directly
* rename visable to visible * rename visable to visible
* create 'sound channels' with priority.. ie a door can only make one sound * create 'sound channels' with priority.. ie a door can only make one sound
at a time at a time
* cat file.c | perl -e 'while($in = <STDIN>)
{$in =~ s/\/\/(.*)$/\/\* \1\ *\//gm;print $in;}'
or
cat foo.txt |sed -e "s/\/\/\(.*\)$/\/\*\1\*\//g"
* systems with no sound should still have working WaitSoundDone.. it's * systems with no sound should still have working WaitSoundDone.. it's
possible to calculate the sound lengths in terms of 70Hz (adlib sound len / 2, possible to calculate the sound lengths in terms of 70Hz (adlib sound len / 2,
pcm sound len / 100). pcm sound len / 100).
Things to try: Things to try:
* Convert to a 320x200xWhatever screen first then draw all at once
* Create a native palette format instead of doing conversions each frame * Create a native palette format instead of doing conversions each frame
...@@ -38,8 +38,8 @@ char extension[5]; ...@@ -38,8 +38,8 @@ char extension[5];
#define afilename "audiot." #define afilename "audiot."
#define pfilename "vswap." #define pfilename "vswap."
static long *grstarts; /* array of offsets in vgagraph, -1 for sparse */ static long *grstarts; /* array of offsets in vgagraph */
static long *audiostarts; /* array of offsets in audio / audiot */ static long *audiostarts; /* array of offsets in audiot */
static huffnode grhuffman[255]; static huffnode grhuffman[255];
...@@ -47,27 +47,6 @@ static int grhandle; /* handle to VGAGRAPH */ ...@@ -47,27 +47,6 @@ static int grhandle; /* handle to VGAGRAPH */
static int maphandle; /* handle to GAMEMAPS */ static int maphandle; /* handle to GAMEMAPS */
static int audiohandle; /* handle to AUDIOT */ static int audiohandle; /* handle to AUDIOT */
SDMode oldsoundmode;
#define FILEPOSSIZE 3
static long GRFILEPOS(int c)
{
long value;
int offset;
offset = c*3;
/* TODO: unaligned access */
value = *(long *)(((byte *)grstarts)+offset);
value &= 0x00ffffffl;
if (value == 0xffffffl)
value = -1;
return value;
}
/* /*
============================================================================= =============================================================================
...@@ -223,7 +202,7 @@ void CAL_HuffExpand(byte *source, byte *dest, long length, huffnode *htable) ...@@ -223,7 +202,7 @@ void CAL_HuffExpand(byte *source, byte *dest, long length, huffnode *htable)
{ {
huffnode *headptr; huffnode *headptr;
huffnode *nodeon; huffnode *nodeon;
byte mask = 0x0001; byte mask = 0x01;
word path; word path;
byte *endoff = dest + length; byte *endoff = dest + length;
...@@ -235,8 +214,8 @@ void CAL_HuffExpand(byte *source, byte *dest, long length, huffnode *htable) ...@@ -235,8 +214,8 @@ void CAL_HuffExpand(byte *source, byte *dest, long length, huffnode *htable)
else else
path = nodeon->bit0; path = nodeon->bit0;
mask <<= 1; mask <<= 1;
if (mask == 0x0000) { if (mask == 0x00) {
mask = 0x0001; mask = 0x01;
source++; source++;
} }
if (path < 256) { if (path < 256) {
...@@ -354,27 +333,6 @@ void CA_RLEWexpand(word *source, word *dest, long length, word rlewtag) ...@@ -354,27 +333,6 @@ void CA_RLEWexpand(word *source, word *dest, long length, word rlewtag)
============================================================================= =============================================================================
*/ */
/*
============================
=
= CAL_GetGrChunkLength
=
= Gets the length of an explicit length chunk (not tiles)
= The file pointer is positioned so the compressed data can be read in next.
=
============================
*/
static long CAL_GetGrChunkLength(int chunk)
{
long chunkexplen;
lseek(grhandle, GRFILEPOS(chunk), SEEK_SET);
read(grhandle, &chunkexplen, sizeof(chunkexplen));
return GRFILEPOS(chunk+1)-GRFILEPOS(chunk)-4;
}
/* /*
====================== ======================
= =
...@@ -388,8 +346,10 @@ static void CAL_SetupGrFile() ...@@ -388,8 +346,10 @@ static void CAL_SetupGrFile()
char fname[13]; char fname[13];
int handle; int handle;
memptr compseg; memptr compseg;
long chunkcomplen; long chunkcomplen;
byte *grtemp;
int i;
// //
// load vgadict.ext (huffman dictionary for graphics files) // load vgadict.ext (huffman dictionary for graphics files)
// //
...@@ -405,7 +365,8 @@ static void CAL_SetupGrFile() ...@@ -405,7 +365,8 @@ static void CAL_SetupGrFile()
// //
// load the data offsets from vgahead.ext // load the data offsets from vgahead.ext
// //
MM_GetPtr((memptr)&grstarts, (NUMCHUNKS+1)*FILEPOSSIZE); MM_GetPtr((memptr)&grstarts, (NUMCHUNKS+1)*4);
MM_GetPtr((memptr)&grtemp, (NUMCHUNKS+1)*3);
strcpy(fname, gheadname); strcpy(fname, gheadname);
strcat(fname, extension); strcat(fname, extension);
...@@ -413,7 +374,12 @@ static void CAL_SetupGrFile() ...@@ -413,7 +374,12 @@ static void CAL_SetupGrFile()
if ((handle = open(fname, O_RDONLY | O_BINARY)) == -1) if ((handle = open(fname, O_RDONLY | O_BINARY)) == -1)
CA_CannotOpen(fname); CA_CannotOpen(fname);
CA_FarRead(handle, (memptr)grstarts, (NUMCHUNKS+1)*FILEPOSSIZE); CA_FarRead(handle, (memptr)grtemp, (NUMCHUNKS+1)*3);
for (i = 0; i < NUMCHUNKS+1; i++)
grstarts[i] = (grtemp[i*3+0]<<0)|(grtemp[i*3+1]<<8)|(grtemp[i*3+2]<<16);
MM_FreePtr((memptr)&grtemp);
close(handle); close(handle);
...@@ -429,13 +395,15 @@ static void CAL_SetupGrFile() ...@@ -429,13 +395,15 @@ static void CAL_SetupGrFile()
// //
// load the pic and sprite headers into the arrays in the data segment // load the pic headers into pictable
// //
MM_GetPtr((memptr)&pictable,NUMPICS*sizeof(pictabletype)); MM_GetPtr((memptr)&pictable,NUMPICS*sizeof(pictabletype));
chunkcomplen = CAL_GetGrChunkLength(STRUCTPIC); chunkcomplen = grstarts[STRUCTPIC+1] - grstarts[STRUCTPIC];
MM_GetPtr(&compseg,chunkcomplen); lseek(grhandle, grstarts[STRUCTPIC], SEEK_SET);
MM_GetPtr(&compseg, chunkcomplen);
CA_FarRead(grhandle,compseg,chunkcomplen); CA_FarRead(grhandle,compseg,chunkcomplen);
CAL_HuffExpand(compseg, (byte *)pictable,NUMPICS*sizeof(pictabletype),grhuffman); CAL_HuffExpand(compseg+4, (byte *)pictable, NUMPICS*sizeof(pictabletype), grhuffman);
MM_FreePtr(&compseg); MM_FreePtr(&compseg);
} }
...@@ -485,16 +453,18 @@ static void CAL_SetupMapFile() ...@@ -485,16 +453,18 @@ static void CAL_SetupMapFile()
// //
// load all map header // load all map header
// //
for (i=0;i<NUMMAPS;i++) for (i = 0; i < NUMMAPS; i++)
{ {
pos = tinf->headeroffsets[i]; pos = tinf->headeroffsets[i];
if (pos < 0) /* $FFFFFFFF start is a sparse map */ if (pos == 0) {
mapheaderseg[i] = NULL;
continue; continue;
}
MM_GetPtr((memptr)&mapheaderseg[i],sizeof(maptype)); MM_GetPtr((memptr)&mapheaderseg[i], sizeof(maptype));
MM_SetLock((memptr)&mapheaderseg[i],true); MM_SetLock((memptr)&mapheaderseg[i],true);
lseek(maphandle,pos,SEEK_SET); lseek(maphandle, pos, SEEK_SET);
CA_FarRead (maphandle,(memptr)mapheaderseg[i],sizeof(maptype)); CA_FarRead(maphandle, (memptr)mapheaderseg[i], sizeof(maptype));
} }
// //
...@@ -567,9 +537,6 @@ void CA_Startup() ...@@ -567,9 +537,6 @@ void CA_Startup()
mapon = -1; mapon = -1;
} }
//==========================================================================
/* /*
====================== ======================
= =
...@@ -633,8 +600,6 @@ void CA_UnCacheAudioChunk(int chunk) ...@@ -633,8 +600,6 @@ void CA_UnCacheAudioChunk(int chunk)
audiosegs[chunk] = 0; audiosegs[chunk] = 0;
} }
//===========================================================================
/* /*
====================== ======================
= =
...@@ -649,43 +614,8 @@ void CA_LoadAllSounds() ...@@ -649,43 +614,8 @@ void CA_LoadAllSounds()
{ {
unsigned start, i; unsigned start, i;
#if 0
switch (oldsoundmode)
{
case sdm_PC:
start = STARTPCSOUNDS;
break;
case sdm_AdLib:
start = STARTADLIBSOUNDS;
break;
default:
goto cachein;
}
for (i=0;i<NUMSOUNDS;i++,start++)
if (audiosegs[start])
MM_SetPurge ((memptr)&audiosegs[start],3);
// make purgable
cachein:
switch (SoundMode)
{
case sdm_PC:
start = STARTPCSOUNDS;
break;
case sdm_AdLib:
start = STARTADLIBSOUNDS;
break;
default:
return;
}
#endif
for (start = STARTADLIBSOUNDS, i = 0; i < NUMSOUNDS; i++, start++) for (start = STARTADLIBSOUNDS, i = 0; i < NUMSOUNDS; i++, start++)
CA_CacheAudioChunk(start); CA_CacheAudioChunk(start);
oldsoundmode = SoundMode;
} }
//=========================================================================== //===========================================================================
...@@ -711,7 +641,7 @@ static void CAL_ExpandGrChunk(int chunk, byte *source) ...@@ -711,7 +641,7 @@ static void CAL_ExpandGrChunk(int chunk, byte *source)
if (chunk >= STARTTILE8 && chunk < STARTEXTERNS) if (chunk >= STARTTILE8 && chunk < STARTEXTERNS)
{ {
// //
// expanded sizes of tile8/16/32 are implicit // expanded sizes of tile8 are implicit
// //
expanded = (8*8)*NUMTILE8; expanded = (8*8)*NUMTILE8;
width = 8; width = 8;
...@@ -744,7 +674,6 @@ static void CAL_ExpandGrChunk(int chunk, byte *source) ...@@ -744,7 +674,6 @@ static void CAL_ExpandGrChunk(int chunk, byte *source)
} }
} }
/* /*
====================== ======================
= =
...@@ -759,7 +688,6 @@ void CA_CacheGrChunk(int chunk) ...@@ -759,7 +688,6 @@ void CA_CacheGrChunk(int chunk)
{ {
long pos, compressed; long pos, compressed;
byte *source; byte *source;
int next;
/* this is due to Quit() wanting to cache the error screen before this has been set up! */ /* this is due to Quit() wanting to cache the error screen before this has been set up! */
if ( (grhandle == 0) || (grhandle == -1) ) if ( (grhandle == 0) || (grhandle == -1) )
...@@ -772,15 +700,9 @@ void CA_CacheGrChunk(int chunk) ...@@ -772,15 +700,9 @@ void CA_CacheGrChunk(int chunk)
// //
// load the chunk into a buffer // load the chunk into a buffer
// //
pos = GRFILEPOS(chunk); pos = grstarts[chunk];
if (pos < 0) /* $FFFFFFFF start is a sparse tile */
return;
next = chunk +1; compressed = grstarts[chunk+1]-pos;
while (GRFILEPOS(next) == -1) // skip past any sparse tiles
next++;
compressed = GRFILEPOS(next)-pos;
lseek(grhandle,pos,SEEK_SET); lseek(grhandle,pos,SEEK_SET);
...@@ -799,13 +721,11 @@ void CA_UnCacheGrChunk(int chunk) ...@@ -799,13 +721,11 @@ void CA_UnCacheGrChunk(int chunk)
return; return;
} }
MM_FreePtr((void *)&grsegs[chunk]); MM_FreePtr((memptr)&grsegs[chunk]);
grsegs[chunk] = 0; grsegs[chunk] = 0;
} }
//==========================================================================
/* /*
====================== ======================
= =
...@@ -818,44 +738,12 @@ void CA_UnCacheGrChunk(int chunk) ...@@ -818,44 +738,12 @@ void CA_UnCacheGrChunk(int chunk)
void CA_CacheScreen(int chunk) void CA_CacheScreen(int chunk)
{ {
long pos,compressed,expanded; CA_CacheGrChunk(chunk);
memptr bigbufferseg; VL_MemToScreen(grsegs[chunk], 320, 200, 0, 0);
byte *source, *dest; CA_UnCacheGrChunk(chunk);
int next;
//
// load the chunk into a buffer
//
pos = GRFILEPOS(chunk);
next = chunk +1;
while (GRFILEPOS(next) == -1) // skip past any sparse tiles
next++;
compressed = GRFILEPOS(next)-pos;
lseek(grhandle,pos,SEEK_SET);
MM_GetPtr(&bigbufferseg,compressed);
MM_SetLock (&bigbufferseg,true);
CA_FarRead(grhandle,bigbufferseg,compressed);
source = bigbufferseg;
expanded = *(long *)source;
source += 4; // skip over length
//
// allocate final space, decompress it, and free bigbuffer
//
MM_GetPtr((void *)&dest, expanded);
CAL_HuffExpand(source, dest, expanded, grhuffman);
VL_DeModeXize(dest, 320, 200);
VL_MemToScreen(dest, 320, 200, 0, 0);
MM_FreePtr(&bigbufferseg);
MM_FreePtr((void *)&dest);
} }
//========================================================================== /* ======================================================================== */
/* /*
====================== ======================
...@@ -962,7 +850,7 @@ static int PageFile = -1; ...@@ -962,7 +850,7 @@ static int PageFile = -1;
word ChunksInFile; word ChunksInFile;
word PMSpriteStart, PMSoundStart; word PMSpriteStart, PMSoundStart;
PageListStruct *PMPages, *PMSegPages; PageListStruct *PMPages;
// //
// PML_ReadFromFile() - Reads some data in from the page file // PML_ReadFromFile() - Reads some data in from the page file
......
...@@ -231,6 +231,7 @@ void Blah() ...@@ -231,6 +231,7 @@ void Blah()
MM_GetPtr(&list,PMPageSize); MM_GetPtr(&list,PMPageSize);
p = PM_GetPage(ChunksInFile - 1); p = PM_GetPage(ChunksInFile - 1);
memcpy((void *)list,(void *)p,PMPageSize); memcpy((void *)list,(void *)p,PMPageSize);
pg = PMSoundStart; pg = PMSoundStart;
for (i = 0;i < PMPageSize / (sizeof(word) * 2);i++,p += 2) for (i = 0;i < PMPageSize / (sizeof(word) * 2);i++,p += 2)
{ {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment