Skip to content

Commit

Permalink
Fixed: "External resource loader - File names with extensions" (see h…
Browse files Browse the repository at this point in the history
…ere http://sourceforge.net/tracker/index.php?func=detail&aid=2536942&group_id=74815&atid=542099).

Also in this commit:
* Merged model search path handling into the resource locator.
* A filehash is now built for each resource class.
* Revised resource locator design to shift more work to the file hash creation stage (resource class data, search path variations gamemode, override paths etc).
* Deferred R_InitModels until after the game's post init routine has been called. This allows the game chance to determine the gamemode before we make any attempt at building file hashes so the engine only has to do the later once.
* Numerous routines taking/returning character array ptrs given const specifiers where appropriate.
  • Loading branch information
danij committed May 26, 2009
1 parent 503c32c commit 1cc9218
Show file tree
Hide file tree
Showing 33 changed files with 859 additions and 678 deletions.
11 changes: 11 additions & 0 deletions doomsday/engine/api/dd_share.h
Expand Up @@ -914,9 +914,20 @@ typedef enum resourceclass_e {
RC_MUSIC, // Names == lumpnames.
RC_SFX, // Names == lumpnames.
RC_GRAPHICS, // Doomsday graphics.
RC_MODEL,
NUM_RESOURCE_CLASSES
} resourceclass_t;

typedef enum resourcetype_e {
RT_UNKNOWN = -1,
RT_FIRST = 0,
RT_GRAPHIC = RT_FIRST,
RT_MODEL,
RT_SOUND,
RT_MUSIC,
NUM_RESOURCE_TYPES
} resourcetype_t;

/**
* Processing modes for GL_LoadGraphics.
*/
Expand Down
15 changes: 8 additions & 7 deletions doomsday/engine/api/doomsday.h
Expand Up @@ -509,14 +509,15 @@ extern "C" {
binangle_t bamsAtan2(int y, int x);

// Miscellaneous: Command line.
void _DECALL ArgAbbreviate(char* longname, char* shortname);
void _DECALL ArgAbbreviate(const char* longName,
const char* shortName);
int _DECALL Argc(void);
char* _DECALL Argv(int i);
char** _DECALL ArgvPtr(int i);
char* _DECALL ArgNext(void);
int _DECALL ArgCheck(char* check);
int _DECALL ArgCheckWith(char* check, int num);
int _DECALL ArgExists(char* check);
const char* _DECALL Argv(int i);
const char** _DECALL ArgvPtr(int i);
const char* _DECALL ArgNext(void);
int _DECALL ArgCheck(const char* check);
int _DECALL ArgCheckWith(const char* check, int num);
int _DECALL ArgExists(const char* check);
int _DECALL ArgIsOption(int i);

#ifdef __cplusplus
Expand Down
5 changes: 3 additions & 2 deletions doomsday/engine/portable/include/con_config.h
Expand Up @@ -31,9 +31,10 @@

#include "con_decl.h"

boolean Con_ParseCommands(char *fileName, boolean setdefault);
boolean Con_ParseCommands(const char* fileName, boolean setdefault);
void Con_SaveDefaults(void);
boolean Con_WriteState(const char *fileName, const char *bindingsFileName);
boolean Con_WriteState(const char* fileName,
const char* bindingsFileName);

D_CMD(WriteConsole);

Expand Down
8 changes: 4 additions & 4 deletions doomsday/engine/portable/include/dd_pinit.h
Expand Up @@ -36,12 +36,12 @@
#define MAX_PLUGS 32

void DD_ShutdownAll(void);
int DD_CheckArg(char *tag, char **value);
void DD_ErrorBox(boolean error, char *format, ...) PRINTF_F(2,3);
void DD_ComposeMainWindowTitle(char *title);
int DD_CheckArg(char* tag, const char** value);
void DD_ErrorBox(boolean error, char* format, ...) PRINTF_F(2,3);
void DD_ComposeMainWindowTitle(char* title);
boolean DD_EarlyInit(void);
void DD_InitAPI(void);
void DD_InitCommandLine(const char *cmdLine);
void DD_InitCommandLine(const char* cmdLine);

extern game_import_t gi;
extern game_export_t gx;
Expand Down
21 changes: 11 additions & 10 deletions doomsday/engine/portable/include/m_args.h
Expand Up @@ -4,6 +4,7 @@
* Online License Link: http://www.gnu.org/licenses/gpl.html
*
*\author Copyright © 2003-2009 Jaakko Keränen <jaakko.keranen@iki.fi>
*\author Copyright © 2009 Daniel Swanson <danij@dengine.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -17,7 +18,7 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/

Expand All @@ -28,18 +29,18 @@
#ifndef __COMMAND_LINE_ARGS_H__
#define __COMMAND_LINE_ARGS_H__

void ArgInit(const char *cmdline);
void ArgInit(const char* cmdline);
void ArgShutdown(void);
void ArgAbbreviate(char *longname, char *shortname);
void ArgAbbreviate(const char* longname, const char* shortname);

int Argc(void);
char *Argv(int i);
char **ArgvPtr(int i);
char *ArgNext(void);
int ArgCheck(char *check);
int ArgCheckWith(char *check, int num);
int ArgExists(char *check);
const char* Argv(int i);
const char** ArgvPtr(int i);
const char* ArgNext(void);
int ArgCheck(const char* check);
int ArgCheckWith(const char* check, int num);
int ArgExists(const char* check);
int ArgIsOption(int i);
int ArgRecognize(char *first, char *second);
int ArgRecognize(const char* first, const char* second);

#endif //__COMMAND_LINE_ARGS_H__
17 changes: 11 additions & 6 deletions doomsday/engine/portable/include/m_filehash.h
Expand Up @@ -4,6 +4,7 @@
* Online License Link: http://www.gnu.org/licenses/gpl.html
*
*\author Copyright © 2003-2009 Jaakko Keränen <jaakko.keranen@iki.fi>
*\author Copyright © 2009 Daniel Swanson <danij@dengine.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
Expand All @@ -17,19 +18,23 @@
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Foundation, Inc., 51 Franklin St, Fifth Floor,
* Boston, MA 02110-1301 USA
*/

/*
* m_filehash.h: File Name Hash Table
/**
* m_filehash.h: File name/directory search hashes.
*/

#ifndef __DOOMSDAY_MISC_FILE_HASH_H__
#define __DOOMSDAY_MISC_FILE_HASH_H__

void FH_Clear(void);
void FH_Init(const char *pathList);
boolean FH_Find(const char *name, char *foundPath);
typedef void* filehash_t;

filehash_t* FileHash_Create(const char* pathList);
void FileHash_Destroy(filehash_t* fh);

boolean FileHash_Find(filehash_t* fh, const char* name,
char* foundPath);

#endif
3 changes: 2 additions & 1 deletion doomsday/engine/portable/include/m_misc.h
Expand Up @@ -52,7 +52,7 @@ void M_ExtractFileBase(const char* path, char* dest);
void M_ExtractFileBase2(const char* path, char* dest,
int max, int ignore);
void M_GetFileExt(const char* path, char* ext);
void M_ReplaceFileExt(char* path, char* newext);
void M_ReplaceFileExt(char* path, const char* newext);
boolean M_CheckPath(char* path);
int M_FileExists(const char* file);
void M_TranslatePath(const char* path, char* translated);
Expand Down Expand Up @@ -82,6 +82,7 @@ char* M_LimitedStrCat(const char* str, size_t maxWidth,
char separator, char* buf,
size_t bufLength);
char* M_StrCatQuoted(char* dest, const char* src);
char* M_StrTok(char** cursor, char* delimiters);

// Random numbers.
byte RNG_RandByte(void);
Expand Down
17 changes: 13 additions & 4 deletions doomsday/engine/portable/include/r_extres.h
Expand Up @@ -29,12 +29,21 @@
#ifndef __DOOMSDAY_REFRESH_EXT_RES_H__
#define __DOOMSDAY_REFRESH_EXT_RES_H__

void R_InitExternalResources(void);
void R_InitResourceLocator(void);
void R_ShutdownResourceLocator(void);

void R_SetDataPath(const char* path);
void R_InitDataPaths(const char* path, boolean justGamePaths);
const char* R_GetDataPath(void);
void R_PrependDataPath(const char* origPath, char* newPath);
boolean R_FindResource(resourceclass_t resClass, const char* name,
const char* optionalSuffix, char* fileName);

void R_AddClassDataPath(resourceclass_t resClass,
const char* addPath, boolean append);
void R_ClearClassDataPath(resourceclass_t resClass);
const char* R_GetClassDataPath(resourceclass_t resClass);

boolean R_FindResource(resourcetype_t resType, const char* name,
const char* optionalSuffix, char* fileName);
boolean R_FindResource2(resourcetype_t resType,
resourceclass_t resClass, const char* name,
const char* optionalSuffix, char* fileName);
#endif
3 changes: 0 additions & 3 deletions doomsday/engine/portable/include/r_model.h
Expand Up @@ -110,15 +110,12 @@ extern float rModelAspectMod;

void R_InitModels(void);
void R_ShutdownModels(void);
void R_ClearModelPath(void);
void R_AddModelPath(char* addPath, boolean append);
float R_CheckModelFor(struct mobj_s* mo, modeldef_t** mdef,
modeldef_t** nextmdef);
modeldef_t* R_CheckIDModelFor(const char* id);
int R_ModelFrameNumForName(int modelnum, char* fname);
void R_SetModelFrame(modeldef_t* modef, int frame);
void R_SetSpriteReplacement(int sprite, char* modelname);
int R_FindModelFile(const char* filename, char* outfn);
void R_PrecacheSkinsForState(int stateIndex);
boolean R_PrecacheSkinsForMobj(thinker_t* th, void* context);
void R_PrecacheModelSkins(modeldef_t* modef);
Expand Down
10 changes: 5 additions & 5 deletions doomsday/engine/portable/src/con_config.c
Expand Up @@ -49,17 +49,17 @@

// PUBLIC DATA DEFINITIONS -------------------------------------------------

static char cfgFile[256];
static char cfgFile[256];

// PRIVATE DATA DEFINITIONS ------------------------------------------------

// CODE --------------------------------------------------------------------

boolean Con_ParseCommands(char *fileName, boolean setdefault)
boolean Con_ParseCommands(const char* fileName, boolean setdefault)
{
DFILE *file;
char buff[512];
int line = 1;
DFILE* file;
char buff[512];
int line = 1;

// Is this supposed to be the default?
if(setdefault)
Expand Down
29 changes: 19 additions & 10 deletions doomsday/engine/portable/src/dd_main.c
Expand Up @@ -408,6 +408,9 @@ int DD_Main(void)
{
GL_Init();
GL_InitRefresh();

// \todo we could be loading these in busy mode.
GL_LoadSystemTextures();
GL_LoadLightmaps();
GL_LoadFlareTextures();
}
Expand Down Expand Up @@ -475,7 +478,7 @@ static int DD_StartupWorker(void *parm)
Con_SetProgress(20);

DD_AddStartupWAD("}data\\doomsday.pk3");
R_InitExternalResources();
R_SetDataPath("}data\\");

// The name of the .cfg will invariably be overwritten by the Game.
strcpy(configFileName, "doomsday.cfg");
Expand Down Expand Up @@ -535,7 +538,7 @@ static int DD_StartupWorker(void *parm)
{
for(;;)
{
char *arg = ArgNext();
const char* arg = ArgNext();

if(!arg || arg[0] == '-')
break;
Expand Down Expand Up @@ -582,6 +585,9 @@ static int DD_StartupWorker(void *parm)
// Now the game can identify the game mode.
gx.UpdateState(DD_GAME_MODE);

// We can now initialize the resource locator (game mode identified).
R_InitResourceLocator();

// Palette information will be needed for preparing textures.
R_LoadPalette();

Expand Down Expand Up @@ -609,11 +615,11 @@ static int DD_StartupWorker(void *parm)

if(ArgCheckWith("-dumplump", 1))
{
char *arg = ArgNext();
const char* arg = ArgNext();
char fname[100];
FILE *file;
FILE* file;
int lump = W_GetNumForName(arg);
byte *lumpPtr = W_CacheLumpNum(lump, PU_STATIC);
byte* lumpPtr = W_CacheLumpNum(lump, PU_STATIC);

sprintf(fname, "%s.dum", arg);
file = fopen(fname, "wb");
Expand Down Expand Up @@ -654,18 +660,21 @@ static int DD_StartupWorker(void *parm)
Con_Message("R_Init: Init the refresh daemon.\n");
R_Init();

Con_SetProgress(199);

Con_Message("Net_InitGame: Initializing game data.\n");
Net_InitGame();
Demo_Init();

if(gx.PostInit)
gx.PostInit();

// Now the defs have been read we can init the map format info
Con_SetProgress(150);

// Defs have been read; we can now init models and the map format info.
R_InitModels();
P_InitData();

Con_SetProgress(199);

// Try to load the autoexec file. This is done here to make sure
// everything is initialized: the user can do here anything that
// s/he'd be able to do in the game.
Expand All @@ -676,7 +685,7 @@ static int DD_StartupWorker(void *parm)
{
for(;;)
{
char *arg = ArgNext();
const char* arg = ArgNext();

if(!arg || arg[0] == '-')
break;
Expand All @@ -694,7 +703,7 @@ static int DD_StartupWorker(void *parm)

for(++p; p < Argc(); p++)
{
char *arg = Argv(p);
const char* arg = Argv(p);

if(arg[0] == '-')
{
Expand Down

0 comments on commit 1cc9218

Please sign in to comment.