Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

id_ca: Use filenames from EPISODE.CKx #64

Merged
merged 3 commits into from
Sep 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions data/keen4/EPISODE.CK4
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,24 @@
#

# Episode variables

# Graphics files
%string ca_gfxInfoFile "GFXINFOE.CK4"
%string ca_graphDict "EGADICT.CK4"
%string ca_graphHead "EGAHEAD.CK4"
%string ca_graphFile "EGAGRAPH.CK4"

# Sound Files
%string ca_audioInfoFile "AUDINFOE.CK4"
%string ca_audioHead "AUDIOHHD.CK4"
%string ca_audioDict "AUDIODCT.CK4"
%string ca_audioFile "AUDIO.CK4"

# Level Files
%string ca_mapFile "GAMEMAPS.CK4"
%string ca_mapHead "MAPHEAD.CK4"
%string ca_tileInfo "TILEINFO.CK4"

%int CK_activeLimit 4
%int CK_highScoreLevel 19
%int CK_highScoreTopMargin 0x33
Expand Down
18 changes: 18 additions & 0 deletions data/keen5/EPISODE.CK5
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,24 @@
#

# Episode variables

# Graphics files
%string ca_gfxInfoFile "GFXINFOE.CK5"
%string ca_graphDict "EGADICT.CK5"
%string ca_graphHead "EGAHEAD.CK5"
%string ca_graphFile "EGAGRAPH.CK5"

# Sound Files
%string ca_audioInfoFile "AUDINFOE.CK5"
%string ca_audioHead "AUDIOHHD.CK5"
%string ca_audioDict "AUDIODCT.CK5"
%string ca_audioFile "AUDIO.CK5"

# Level Files
%string ca_mapFile "GAMEMAPS.CK5"
%string ca_mapHead "MAPHEAD.CK5"
%string ca_tileInfo "TILEINFO.CK5"

%int CK_activeLimit 6
%int CK_highScoreLevel 15
%int CK_highScoreTopMargin 0x23
Expand Down
18 changes: 18 additions & 0 deletions data/keen6e14/EPISODE.CK6
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,24 @@
#

# Episode variables

# Graphics files
%string ca_gfxInfoFile "GFXINFOE.CK6"
%string ca_graphDict "EGADICT.CK6"
%string ca_graphHead "EGAHEAD.CK6"
%string ca_graphFile "EGAGRAPH.CK6"

# Sound Files
%string ca_audioInfoFile "AUDINFOE.CK6"
%string ca_audioHead "AUDIOHHD.CK6"
%string ca_audioDict "AUDIODCT.CK6"
%string ca_audioFile "AUDIO.CK6"

# Level Files
%string ca_mapFile "GAMEMAPS.CK6"
%string ca_mapHead "MAPHEAD.CK6"
%string ca_tileInfo "TILEINFO.CK6"

%int CK_activeLimit 4
%int CK_highScoreLevel 18
%int CK_highScoreTopMargin 0x33
Expand Down
18 changes: 18 additions & 0 deletions data/keen6e15/EPISODE.CK6
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,24 @@
#

# Episode variables

# Graphics files
%string ca_gfxInfoFile "GFXINFOE.CK6"
%string ca_graphDict "EGADICT.CK6"
%string ca_graphHead "EGAHEAD.CK6"
%string ca_graphFile "EGAGRAPH.CK6"

# Sound Files
%string ca_audioInfoFile "AUDINFOE.CK6"
%string ca_audioHead "AUDIOHHD.CK6"
%string ca_audioDict "AUDIODCT.CK6"
%string ca_audioFile "AUDIO.CK6"

# Level Files
%string ca_mapFile "GAMEMAPS.CK6"
%string ca_mapHead "MAPHEAD.CK6"
%string ca_tileInfo "TILEINFO.CK6"

%int CK_activeLimit 4
%int CK_highScoreLevel 18
%int CK_highScoreTopMargin 0x33
Expand Down
2 changes: 1 addition & 1 deletion src/ck_act.c
Original file line number Diff line number Diff line change
Expand Up @@ -660,5 +660,5 @@ void CK_VAR_LoadVars(const char *filename)
while (CK_VAR_ParseVar(&parserstate))
numVarsParsed++;

CK_Cross_LogMessage(CK_LOG_MSG_NORMAL, "Parsed %d vars from \"%s\" over %d lines (%d actions created).\n", numVarsParsed, FS_AdjustExtension(filename), parserstate.linecount, ck_actionsUsed);
CK_Cross_LogMessage(CK_LOG_MSG_NORMAL, "Parsed %d vars from \"%s\" over %d lines (%d actions created).\n", numVarsParsed, filename, parserstate.linecount, ck_actionsUsed);
}
2 changes: 2 additions & 0 deletions src/ck_act.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ typedef int16_t chunk_id_t;
#define CK_INTELEMENT(name, i) (CK_INTARRAY(name)[i])
#define CK_STRINGARRAY(name) STRARRAY_ ## name
#define CK_STRINGELEMENT(name, i) (CK_STRINGARRAY(name)[i])
#define CK_FILENAME(name, def) STRINGS_ ## name
#else
#define CK_INT(name, default) CK_VAR_GetInt(#name, default)
#define CK_CHUNKNUM(name) CK_VAR_GetInt(#name, 0)
Expand All @@ -80,6 +81,7 @@ typedef const char *chunk_id_t;
#define CK_INTELEMENT(name, i) CK_VAR_GetIntArrayElement(#name, i)
#define CK_STRINGARRAY(name) CK_VAR_GetStringArray(#name)
#define CK_STRINGELEMENT(name, i) CK_VAR_GetStringArrayElement(#name, i)
#define CK_FILENAME(name, def) CK_VAR_GetString(#name, FS_AdjustExtension(def))
#endif


Expand Down
4 changes: 2 additions & 2 deletions src/ck_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ void CK_InitGame()


CK_VAR_Startup();
CK_VAR_LoadVars("EPISODE.EXT");
CK_VAR_LoadVars(FS_AdjustExtension("EPISODE.EXT"));

// Load the core datafiles
CA_Startup();
Expand Down Expand Up @@ -615,7 +615,7 @@ int main(int argc, char *argv[])

if (!ck_currentEpisode->isPresent())
{
Quit("Couldn't find game data files!");
// Quit("Couldn't find game data files!");
}

#ifdef CK_ENABLE_PLAYLOOP_DUMPER
Expand Down
11 changes: 11 additions & 0 deletions src/ck_quit.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include "id_heads.h"
#include "ck_act.h"
#include "ck_cross.h"
Expand Down Expand Up @@ -58,3 +59,13 @@ void Quit(const char *msg)
exit(-1);
}
}

void QuitF(const char *msg, ...)
{
char msg_buf[512];
va_list args;
va_start(args, msg);
vsnprintf(msg_buf, sizeof(msg_buf), msg, args);
va_end(args);
Quit(msg_buf);
}
75 changes: 51 additions & 24 deletions src/id_ca.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ void (*ca_finishCacheBox)(void);

bool CA_LoadFile(const char *filename, mm_ptr_t *ptr, int *memsize)
{
FS_File f = FS_OpenOmniFile(FS_AdjustExtension(filename));
FS_File f = FS_OpenOmniFile(filename);

if (!FS_IsFileValid(f))
return false;
Expand Down Expand Up @@ -578,7 +578,9 @@ void CAL_SetupGrFile()
CK_Cross_LogMessage(CK_LOG_MSG_NORMAL, "CAL_SetupGrFile: Loading graphics headers...\n");

//Load the ?GADICT
CA_LoadFile("EGADICT.EXT", (void **)(&ca_gr_huffdict), 0);
const char *dictName = CK_FILENAME(ca_graphDict, "EGADICT.EXT");
if (!CA_LoadFile(dictName, (void **)(&ca_gr_huffdict), 0))
QuitF("Couldn't load EGA graphics huffman dictionary %s\n", dictName);

#ifdef CK_CROSS_IS_BIGENDIAN
for (int i = 0; i < 256; ++i)
Expand All @@ -592,24 +594,29 @@ void CAL_SetupGrFile()
//CAL_OptimizeNodes(ca_gr_huffdict);

//Load the ?GAHEAD
CA_LoadFile("EGAHEAD.EXT", &ca_graphStarts, &ca_graphHeadSize);
const char *headName = CK_FILENAME(ca_graphHead, "EGAHEAD.EXT");
CA_LoadFile(headName, &ca_graphStarts, &ca_graphHeadSize);

// Read chunk type info from GFEINFO?
FS_File gfxinfoe = FS_OpenOmniFile(FS_AdjustExtension("GFXINFOE.EXT"));
// Read chunk type info from GFXINFOE?
const char *gfxinfoe_fname = CK_FILENAME(ca_gfxInfoFile, "GFXINFOE.EXT");
FS_File gfxinfoe = FS_OpenOmniFile(gfxinfoe_fname);
if (!FS_IsFileValid(gfxinfoe))
Quit("Couldn't load GFXINFOE!");
QuitF("Couldn't load %s!", gfxinfoe_fname);
size_t gfxinfoeLen = FS_Read(&ca_gfxInfoE, sizeof(ca_gfxinfo), 1, gfxinfoe);
FS_CloseFile(gfxinfoe);
if (gfxinfoeLen != 1)
Quit("Couldn't read GFXINFOE!");
QuitF("Couldn't read GFXINFOE from %s!", gfxinfoe_fname);
#ifdef CK_CROSS_IS_BIGENDIAN
uint16_t *uptr = (uint16_t *)&ca_gfxInfoE;
for (size_t loopVar = 0; loopVar < sizeof(ca_gfxInfoE) / 2; loopVar++, uptr++)
*uptr = CK_Cross_Swap16(*uptr);
#endif

//Load the graphics --- we will keep the file open for the duration of the game.
ca_graphHandle = FS_OpenKeenFile(FS_AdjustExtension("EGAGRAPH.EXT"));
const char *graphName = CK_FILENAME(ca_graphFile, "EGAGRAPH.EXT");
ca_graphHandle = FS_OpenKeenFile(graphName);
if (!FS_IsFileValid(ca_graphHandle))
QuitF("Couldn't open %s!", graphName);

// Find the size of the file. Some mods do not have the last entry in the ?GAHEAD,
// so we compute it like so.
Expand Down Expand Up @@ -951,24 +958,32 @@ void CAL_SetupMapFile(void)
CK_Cross_LogMessage(CK_LOG_MSG_NORMAL, "CAL_SetupMapFile: Loading map headers...\n");

int mapHeadFileSize = 0;
CA_LoadFile("MAPHEAD.EXT", (void **)(&ca_MapHead), &mapHeadFileSize);
const char *mapHeadFileName = CK_FILENAME(ca_mapHead, "MAPHEAD.EXT");
if (!CA_LoadFile(mapHeadFileName, (void **)(&ca_MapHead), &mapHeadFileSize))
QuitF("Couldn't load map headers from %s\n", mapHeadFileName);
#ifdef CK_CROSS_IS_BIGENDIAN
ca_MapHead->rleTag = CK_Cross_SwapLE16(ca_MapHead->rleTag);
for (int i = 0; i < CA_NUMMAPS; ++i)
{
ca_MapHead->headerOffsets[i] = CK_Cross_SwapLE32(ca_MapHead->headerOffsets[i]);
}
#endif
ca_GameMaps = FS_OpenKeenFile(FS_AdjustExtension("GAMEMAPS.EXT"));
const char *gameMapsFileName = CK_FILENAME(ca_mapFile, "GAMEMAPS.EXT");
ca_GameMaps = FS_OpenKeenFile(gameMapsFileName);
if (!FS_IsFileValid(ca_GameMaps))
QuitF("Couldn't open %s!", gameMapsFileName);
// Try reading TILEINFO.EXT first, otherwise use data from MAPHEAD.EXT
ti_tileInfo = NULL;
if (!CA_LoadFile("TILEINFO.EXT", (void **)(&ti_tileInfo), 0))
const char *tileInfoName = CK_FILENAME(ca_tileInfo, "TILEINFO.EXT");
if (tileInfoName)
CA_LoadFile(tileInfoName, (void **)(&ti_tileInfo), 0);
if (!ti_tileInfo)
{
if (ti_tileInfo) // CA_LoadFile may leave a memory leak
MM_FreePtr((void **)&ti_tileInfo);
// CA_LoadFile may leave a memory leak
MM_FreePtr((void **)&ti_tileInfo);

if (mapHeadFileSize <= sizeof(*ca_MapHead))
Quit("Can't open TILEINFO file, and MAPHEAD file lacks tileinfo data!");
QuitF("Can't open TILEINFO file (%s), and MAPHEAD file lacks tileinfo data!", tileInfoName);

ti_tileInfo = (uint8_t *)(ca_MapHead + 1);
}
Expand All @@ -984,11 +999,14 @@ void CAL_SetupAudioFile(void)
CK_Cross_LogMessage(CK_LOG_MSG_NORMAL, "CAL_SetupAudioFile: Loading audio headers...\n");

// Read audio chunk type info from AUDINFOE
FS_File audinfoe = FS_OpenOmniFile(FS_AdjustExtension("AUDINFOE.EXT"));
const char *audinfoe_fname = CK_FILENAME(ca_audioInfoFile, "AUDINFOE.EXT");
FS_File audinfoe = FS_OpenOmniFile(audinfoe_fname);
if (!FS_IsFileValid(audinfoe))
QuitF("Couldn't open audio info file: %s!", audinfoe_fname);
size_t audinfoeLen = FS_Read(&ca_audInfoE, sizeof(ca_audinfo), 1, audinfoe);
FS_CloseFile(audinfoe);
if (audinfoeLen != 1)
Quit("Couldn't read AUDINFOE!");
QuitF("Couldn't read AUDINFOE data from %s!", audinfoe_fname);
#ifdef CK_CROSS_IS_BIGENDIAN
uint16_t *uptr = (uint16_t *)&ca_audInfoE;
for (size_t loopVar = 0; loopVar < sizeof(ca_audInfoE) / 2; loopVar++, uptr++)
Expand All @@ -997,7 +1015,9 @@ void CAL_SetupAudioFile(void)

#ifndef CA_AUDIOUNCOMPRESSED
//Load the AUDIODCT
CA_LoadFile("AUDIODCT.EXT", (void **)(&ca_audiohuffman), 0);
const char *dict_fname = CK_FILENAME(ca_audioDict, "AUDIODCT.EXT");
if (!CA_LoadFile(dict_fname, (void **)(&ca_audiohuffman), 0))
QuitF("Couldn't load audio dictionary %s\n", dict_fname);

#ifdef CK_CROSS_IS_BIGENDIAN
for (int i = 0; i < 256; ++i)
Expand All @@ -1011,23 +1031,28 @@ void CAL_SetupAudioFile(void)
//CAL_OptimizeNodes(ca_audiohuffman);

//Load the AUDIOHHD
CA_LoadFile("AUDIOHHD.EXT", (void **)(&ca_audiostarts), 0);
const char *head_fname = CK_FILENAME(ca_audioHead, "AUDIOHHD.EXT");
if (!CA_LoadFile(head_fname, (void **)(&ca_audiostarts), 0))
QuitF("Couldn't load (compressed) audio header %s\n", head_fname);

//Load the sound data --- we will keep the file open for the duration of the game.
ca_audiohandle = FS_OpenKeenFile(FS_AdjustExtension("AUDIO.EXT"));
const char *audio_fname = CK_FILENAME(ca_audioFile, "AUDIO.EXT");
ca_audiohandle = FS_OpenKeenFile(audio_fname);
if (!ca_audiohandle)
{
Quit("Can't open AUDIO.CKx!");
QuitF("Can't open %s!", audio_fname);
}
#else
//Load the AUDIOHHD
CA_LoadFile("AUDIOHED.EXT", (void **)(&ca_audiostarts), 0);
//Load the AUDIOHED
const char *head_fname = CK_FILENAME(ca_audioHead, "AUDIOHED.EXT");
CA_LoadFile(head_fname, (void **)(&ca_audiostarts), 0);

//Load the sound data --- we will keep the file open for the duration of the game.
ca_audiohandle = FS_OpenKeenFile(FS_AdjustExtension("AUDIOT.EXT"));
const char *audio_fname = CK_FILENAME(ca_audioFile, "AUDIOT.EXT");
ca_audiohandle = FS_OpenKeenFile(audio_fname);
if (!ca_audiohandle)
{
Quit("Can't open AUDIOT.CKx!");
QuitF("Can't open %s!", audio_fname);
}
#endif
}
Expand Down Expand Up @@ -1077,6 +1102,8 @@ void CA_CacheMap(int mapIndex)
//Make sure we don't purge it accidentally.
MM_SetPurge((void **)(&CA_MapHeaders[mapIndex]), 0);
}

CK_Cross_LogMessage(CK_LOG_MSG_NORMAL, "CA_CacheMap: Loading map %d (\"%s\")\n", mapIndex, CA_MapHeaders[mapIndex]->name);

int planeSize = CA_MapHeaders[mapIndex]->width * CA_MapHeaders[mapIndex]->height * 2;

Expand Down
1 change: 0 additions & 1 deletion src/id_ca.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ void CA_LoadAllSounds(void);
// -- File IO --

size_t CA_GetFileSize(char *filename);
char *CAL_AdjustExtension(const char *filename);
bool CA_FarWrite(int handle, uint8_t *source, int length);
bool CA_ReadFile(const char *filename, void *offset);
bool CA_SafeReadFile(const char *filename, void *offset, int bufLength);
Expand Down
1 change: 1 addition & 0 deletions src/id_us.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ typedef struct

// In ck_quit.c, as it may be customized by individual games.
void Quit(const char *msg) _NORETURN;
void QuitF(const char *msg, ...) _NORETURN CK_PRINTF_FORMAT(1, 2);

// id_us_1.c:
// Parameter Checking
Expand Down