Skip to content

Commit

Permalink
Fixed engine startup and shutdown. Updated variable/argument names re…
Browse files Browse the repository at this point in the history
… resourcetype_t > resourceclass_t
  • Loading branch information
danij-deng committed Nov 28, 2010
1 parent c9b98b7 commit 19208b3
Show file tree
Hide file tree
Showing 13 changed files with 115 additions and 96 deletions.
4 changes: 2 additions & 2 deletions doomsday/engine/api/doomsday.h
Expand Up @@ -102,12 +102,12 @@ extern "C" {
* \note Resource registration order defines the load order of resources (among those of the same type).
*
* @param game Unique identifier/name of the game.
* @param type Type of resource being added.
* @param rclass Class of resource being added.
* @param names One or more known potential names, seperated by semicolon e.g., "name1;name2".
* Names may include valid absolute, or relative file paths. These paths include
* valid symbolbolic escape tokens, predefined symbols into the virtual file system.
*/
void DD_AddGameResource(gameid_t game, resourceclass_t type, const char* names, void* params);
void DD_AddGameResource(gameid_t game, resourceclass_t rclass, const char* names, void* params);

/**
* Retrieve extended info about the specified game.
Expand Down
1 change: 1 addition & 0 deletions doomsday/engine/portable/include/dd_main.h
Expand Up @@ -53,6 +53,7 @@ extern int isDedicated;
extern GETGAMEAPI GetGameAPI;
#endif

boolean DD_EarlyInit(void);
int DD_Main(void);
void DD_CheckTimeDemo(void);
void DD_UpdateEngineState(void);
Expand Down
26 changes: 13 additions & 13 deletions doomsday/engine/portable/include/dd_pinit.h
Expand Up @@ -3,8 +3,8 @@
* License: GPL
* 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>
*\author Copyright © 2003-2010 Jaakko Keränen <jaakko.keranen@iki.fi>
*\author Copyright © 2009-2010 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 @@ -23,27 +23,27 @@
*/

/**
* dd_pinit.h: Portable Engine Initialization
* Portable Engine Initialization
*/

#ifndef __DOOMSDAY_PORTABLE_INIT_H__
#define __DOOMSDAY_PORTABLE_INIT_H__
#ifndef LIBDENG_PORTABLE_INIT_H
#define LIBDENG_PORTABLE_INIT_H

#include "dd_share.h"
#include "dd_api.h"

// Maximum allowed number of plugins.
#define MAX_PLUGS 32

void DD_ShutdownAll(void);
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_ShutdownAll(void);
int DD_CheckArg(char* tag, const char** value);
void DD_ErrorBox(boolean error, char* format, ...) PRINTF_F(2,3);
void DD_ComposeMainWindowTitle(char* title);
void DD_ConsoleInit(void);
void DD_InitAPI(void);
void DD_InitCommandLine(const char* cmdLine);

extern game_import_t gi;
extern game_export_t gx;

#endif // __DOOMSDAY_PORTABLE_INIT_H__
#endif /* LIBDENG_PORTABLE_INIT_H */
13 changes: 7 additions & 6 deletions doomsday/engine/portable/include/gameinfo.h
Expand Up @@ -35,8 +35,8 @@
* @ingroup core
*/
typedef struct {
/// Type of resource.
resourceclass_t type;
/// Class of resource.
resourceclass_t rclass;

/// List of known potential names. Seperated with a semicolon.
ddstring_t names;
Expand Down Expand Up @@ -116,10 +116,11 @@ void P_DestroyGameInfo(gameinfo_t* info);
*
* \note Resource registration order defines the order in which resources of each type are loaded.
*
* @param type Type of resource.
* @param class Class of resource being added.
* @param rni Namespace to associate the resource with.
* @param name Potential resource name.
*/
gameresource_record_t* GameInfo_AddResource(gameinfo_t* info, resourceclass_t type,
gameresource_record_t* GameInfo_AddResource(gameinfo_t* info, resourceclass_t rclass,
resourcenamespaceid_t rni, const ddstring_t* name);

/**
Expand All @@ -133,7 +134,7 @@ boolean GameInfo_AddResourceSearchPath(gameinfo_t* info, resourcenamespaceid_t r
void GameInfo_ClearResourceSearchPaths(gameinfo_t* info);

/**
* Clear resource-locator search paths for a specific resource class.
* Clear resource-locator search paths for a specific resource namespace.
*/
void GameInfo_ClearResourceSearchPaths2(gameinfo_t* info, resourcenamespaceid_t rni);

Expand All @@ -148,7 +149,7 @@ const ddstring_t* GameInfo_ResourceSearchPaths(gameinfo_t* info, resourcenamespa
/// @return Unique plugin identifier attributed to that which registered this.
pluginid_t GameInfo_PluginId(gameinfo_t* info);

/// @return Ptr to a string containing the mode-identifier.
/// @return Ptr to a string containing the identity key.
const ddstring_t* GameInfo_IdentityKey(gameinfo_t* info);

/// @return Ptr to a string containing the default title.
Expand Down
6 changes: 3 additions & 3 deletions doomsday/engine/portable/include/sys_reslocator.h
Expand Up @@ -51,7 +51,7 @@ resourcenamespaceid_t F_ToResourceNamespaceId(int val);
resourcenamespace_t* F_ToResourceNamespace(resourcenamespaceid_t);
uint F_NumResourceNamespaces(void);

resourcenamespaceid_t F_DefaultResourceNamespaceForType(resourceclass_t type);
resourcenamespaceid_t F_DefaultResourceNamespaceForClass(resourceclass_t rclass);
resourcenamespaceid_t F_ResourceNamespaceForName(const char* name);
resourcenamespaceid_t F_SafeResourceNamespaceForName(const char* name);

Expand All @@ -60,7 +60,7 @@ resourcenamespaceid_t F_ParseResourceNamespace(const char* str);
/**
* Attempt to locate an external file for the specified resource.
*
* @param type Type of resource being searched for (if known).
* @param rclass Class of resource being searched for (if known).
*
* @param foundPath If found, the fully qualified path will be written back here.
* Can be @c NULL, changing this routine to only check that file
Expand All @@ -80,7 +80,7 @@ resourcenamespaceid_t F_ParseResourceNamespace(const char* str);
*
* @return @c true, iff a file was found.
*/
boolean F_FindResource(resourceclass_t type, char* foundPath, const char* searchPath,
boolean F_FindResource(resourceclass_t rclass, char* foundPath, const char* searchPath,
const char* suffix, size_t foundPathLength);

#endif /* LIBDENG_FILESYS_EXTRES_H */
3 changes: 1 addition & 2 deletions doomsday/engine/portable/src/con_main.c
Expand Up @@ -1848,9 +1848,8 @@ void Con_Error(const char *error, ...)

void Con_AbnormalShutdown(const char* message)
{
Sys_Shutdown();
B_Shutdown();
DD_DestroyGameInfo();
Sys_Shutdown();

#ifdef WIN32
ChangeDisplaySettings(0, 0); // Restore original mode, just in case.
Expand Down
61 changes: 35 additions & 26 deletions doomsday/engine/portable/src/dd_main.c
Expand Up @@ -306,16 +306,16 @@ static void addIdentityKeyToResourceNamespaceRecord(gameresource_record_t* rec,
}
}

void DD_AddGameResource(gameid_t gameId, resourceclass_t type, const char* _names, void* params)
void DD_AddGameResource(gameid_t gameId, resourceclass_t rclass, const char* _names, void* params)
{
gameinfo_t* info = findGameInfoForId(gameId);
resourcenamespaceid_t rni;
ddstring_t names, name;

if(!info || DD_IsNullGameInfo(info))
Con_Error("DD_AddGameResource: Error, unknown game id %u.", gameId);
if(!VALID_RESOURCE_CLASS(type))
Con_Error("DD_AddGameResource: Error, unknown resource type %i.", (int)type);
if(!VALID_RESOURCE_CLASS(rclass))
Con_Error("DD_AddGameResource: Error, unknown resource class %i.", (int)rclass);
if(!_names || !_names[0] || !strcmp(_names, ";"))
Con_Error("DD_AddGameResource: Error, invalid name argument.");

Expand All @@ -326,14 +326,14 @@ void DD_AddGameResource(gameid_t gameId, resourceclass_t type, const char* _name
Str_Append(&names, ";");

if((rni = F_ParseResourceNamespace(Str_Text(&names))) == 0)
rni = F_DefaultResourceNamespaceForType(type);
rni = F_DefaultResourceNamespaceForClass(rclass);

Str_Init(&name);
{ gameresource_record_t* rec;
if((rec = GameInfo_AddResource(info, type, rni, &names)))
if((rec = GameInfo_AddResource(info, rclass, rni, &names)))
{
if(params)
switch(rec->type)
switch(rec->rclass)
{
case RC_PACKAGE:
// Add an auto-identification file name list to the info record.
Expand Down Expand Up @@ -481,9 +481,9 @@ static boolean recognizeZIP(const char* filePath, void* data)
static boolean validateGameResource(gameresource_record_t* rec, const char* name)
{
filename_t foundPath;
if(!F_FindResource(rec->type, foundPath, name, 0, FILENAME_T_MAXLEN))
if(!F_FindResource(rec->rclass, foundPath, name, 0, FILENAME_T_MAXLEN))
return false;
switch(rec->type)
switch(rec->rclass)
{
case RC_PACKAGE:
if(recognizeWAD(foundPath, (void*)rec->identityKeys)) break;
Expand Down Expand Up @@ -553,27 +553,27 @@ static boolean allGameResourcesFound(gameinfo_t* info)
return true;
}

static void loadGameResources(gameinfo_t* info, resourceclass_t type, const char* searchPath)
static void loadGameResources(gameinfo_t* info, resourceclass_t rclass, const char* searchPath)
{
assert(info && VALID_RESOURCE_CLASS(type) && searchPath);
assert(info && VALID_RESOURCE_CLASS(rclass) && searchPath);
{
resourcenamespaceid_t rni;

if((rni = F_ParseResourceNamespace(searchPath)) == 0)
rni = F_DefaultResourceNamespaceForType(type);
rni = F_DefaultResourceNamespaceForClass(rclass);

{gameresource_record_t* const* records;
if((records = GameInfo_Resources(info, rni, 0)))
do
{
switch((*records)->type)
switch((*records)->rclass)
{
case RC_PACKAGE:
if(Str_Length(&(*records)->path) != 0)
W_AddFile(Str_Text(&(*records)->path), false);
break;
default:
Con_Error("loadGameResources: Error, no resource loader found for %s.", F_ResourceTypeStr((*records)->type));
Con_Error("loadGameResources: Error, no resource loader found for %s.", F_ResourceTypeStr((*records)->rclass));
};
} while(*(++records));
}
Expand Down Expand Up @@ -602,7 +602,7 @@ static void printGameInfo(gameinfo_t* info)
Con_Printf(" Namespace: \"%s\"\n", Str_Text(&F_ToResourceNamespace((resourcenamespaceid_t)i)->_name));
do
{
Con_Printf(" %i:%s - \"%s\" > %s\n", n++, F_ResourceTypeStr((*records)->type), Str_Text(&(*records)->names), Str_Length(&(*records)->path) == 0? "--(!)missing" : M_PrettyPath(Str_Text(&(*records)->path)));
Con_Printf(" %i:%s - \"%s\" > %s\n", n++, F_ResourceTypeStr((*records)->rclass), Str_Text(&(*records)->names), Str_Length(&(*records)->path) == 0? "--(!)missing" : M_PrettyPath(Str_Text(&(*records)->path)));
} while(*(++records));
}
}}
Expand Down Expand Up @@ -994,6 +994,27 @@ void DD_AutoselectGame(void)
}
}

int DD_EarlyInit(void)
{
// Bring the console online as soon as we can.
DD_ConsoleInit();

// Bring the window manager online.
Sys_InitWindowManager();

/**
* One-time creation and initialization of the special "null-game" object (activated once created).
*/
{ filename_t dataPath, defsPath;
M_TranslatePath(dataPath, DD_BASEPATH_DATA, FILENAME_T_MAXLEN);
Dir_ValidDir(dataPath, FILENAME_T_MAXLEN);
M_TranslatePath(defsPath, DD_BASEPATH_DEFS, FILENAME_T_MAXLEN);
Dir_ValidDir(defsPath, FILENAME_T_MAXLEN);
currentGameInfoIndex = gameInfoIndex(addGameInfoRecord(0, 0, dataPath, defsPath, 0, 0, 0, 0, 0));
}
return true;
}

/**
* Engine initialization. When complete, starts the "game loop".
*/
Expand Down Expand Up @@ -1221,7 +1242,6 @@ int DD_Main(void)
}

B_Shutdown();
DD_DestroyGameInfo();
Sys_Shutdown();

return exitCode;
Expand All @@ -1236,17 +1256,6 @@ static int DD_StartupWorker(void* parm)

F_InitMapping();

/**
* One-time creation and initialization of the special "null-game" object (activated once created).
*/
{ filename_t dataPath, defsPath;
M_TranslatePath(dataPath, DD_BASEPATH_DATA, FILENAME_T_MAXLEN);
Dir_ValidDir(dataPath, FILENAME_T_MAXLEN);
M_TranslatePath(defsPath, DD_BASEPATH_DEFS, FILENAME_T_MAXLEN);
Dir_ValidDir(defsPath, FILENAME_T_MAXLEN);
currentGameInfoIndex = gameInfoIndex(addGameInfoRecord(0, 0, dataPath, defsPath, 0, 0, 0, 0, 0));
}

// Initialize the key mappings.
DD_InitInput();

Expand Down
7 changes: 1 addition & 6 deletions doomsday/engine/portable/src/dd_pinit.c
Expand Up @@ -198,7 +198,7 @@ void DD_Verbosity(void)
* Called early on during the startup process so that we can get the console
* online ready for printing ASAP.
*/
boolean DD_EarlyInit(void)
void DD_ConsoleInit(void)
{
const char* outFileName = "doomsday.out";

Expand Down Expand Up @@ -257,11 +257,6 @@ boolean DD_EarlyInit(void)
}
}
}

// Bring the window manager online.
Sys_InitWindowManager();

return true;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions doomsday/engine/portable/src/gameinfo.c
Expand Up @@ -343,10 +343,10 @@ void P_DestroyGameInfo(gameinfo_t* info)
M_Free(info);
}

gameresource_record_t* GameInfo_AddResource(gameinfo_t* info, resourceclass_t type,
gameresource_record_t* GameInfo_AddResource(gameinfo_t* info, resourceclass_t rclass,
resourcenamespaceid_t rni, const ddstring_t* names)
{
assert(info && VALID_RESOURCE_CLASS(type) && F_IsValidResourceNamespaceId(rni) && names);
assert(info && VALID_RESOURCE_CLASS(rclass) && F_IsValidResourceNamespaceId(rni) && names);
{
gameresource_recordset_t* rset = &info->_requiredResources[rni-1];
gameresource_record_t* record;
Expand All @@ -358,8 +358,8 @@ gameresource_record_t* GameInfo_AddResource(gameinfo_t* info, resourceclass_t ty

Str_Init(&record->names); Str_Copy(&record->names, names);
Str_Init(&record->path);
record->type = type;
switch(record->type)
record->rclass = rclass;
switch(record->rclass)
{
case RC_PACKAGE:
record->identityKeys = 0;
Expand Down

0 comments on commit 19208b3

Please sign in to comment.