Skip to content

Commit

Permalink
Refactoring plugin management (part 2)
Browse files Browse the repository at this point in the history
Updated jDoom64, jHeretic and jHexen to use DP_Load and DP_Unload.
It is now possible to change games at runtime on Unix platforms without
symbol conflicts.
  • Loading branch information
skyjake committed Dec 30, 2011
1 parent e9329d0 commit da282c2
Show file tree
Hide file tree
Showing 7 changed files with 68 additions and 4 deletions.
2 changes: 1 addition & 1 deletion doomsday/engine/portable/src/dd_main.c
Expand Up @@ -1174,7 +1174,7 @@ boolean DD_ChangeGame2(Game* game, boolean allowReload)

if(!DD_IsNullGame(theGame))
{
// Tell the plugin it is being unloaded.
// Tell the plugin it is being loaded.
void* loader = DD_FindEntryPoint(Game_PluginId(theGame), "DP_Load");
#ifdef _DEBUG
Con_Message("DD_ChangeGame2: Calling DP_Load (%p)\n", loader);
Expand Down
2 changes: 2 additions & 0 deletions doomsday/plugins/jdoom64/api/jdoom64.def
Expand Up @@ -3,3 +3,5 @@ LIBRARY JDOOM64
EXPORTS
DP_Initialize @1
GetGameAPI @2
DP_Load @3
DP_Unload @4
20 changes: 19 additions & 1 deletion doomsday/plugins/jdoom64/src/d_api.c
Expand Up @@ -84,6 +84,25 @@ int G_RegisterGames(int hookType, int param, void* data)
#undef DATAPATH
}

/**
* Called right after the game plugin is selected into use.
*/
void DP_Load(void)
{
// We might've been freed from memory, so refresh the game ids.
gameIds[doom64] = DD_GameIdForKey("doom64");

Plug_AddHook(HOOK_VIEWPORT_RESHAPE, R_UpdateViewport);
}

/**
* Called when the game plugin is freed from memory.
*/
void DP_Unload(void)
{
Plug_RemoveHook(HOOK_VIEWPORT_RESHAPE, R_UpdateViewport);
}

void G_PreInit(gameid_t gameId)
{
/// \todo Refactor me away.
Expand Down Expand Up @@ -178,5 +197,4 @@ game_export_t* GetGameAPI(game_import_t* imports)
void DP_Initialize()
{
Plug_AddHook(HOOK_STARTUP, G_RegisterGames);
Plug_AddHook(HOOK_VIEWPORT_RESHAPE, R_UpdateViewport);
}
2 changes: 2 additions & 0 deletions doomsday/plugins/jheretic/api/jheretic.def
Expand Up @@ -3,3 +3,5 @@ LIBRARY JHERETIC
EXPORTS
DP_Initialize @1
GetGameAPI @2
DP_Load @3
DP_Unload @4
22 changes: 21 additions & 1 deletion doomsday/plugins/jheretic/src/h_api.c
Expand Up @@ -107,6 +107,27 @@ int G_RegisterGames(int hookType, int param, void* data)
#undef DATAPATH
}

/**
* Called right after the game plugin is selected into use.
*/
void DP_Load(void)
{
// We might've been freed from memory, so refresh the game ids.
gameIds[heretic_shareware] = DD_GameIdForKey("heretic-share");
gameIds[heretic] = DD_GameIdForKey("heretic");
gameIds[heretic_extended] = DD_GameIdForKey("heretic-ext");

Plug_AddHook(HOOK_VIEWPORT_RESHAPE, R_UpdateViewport);
}

/**
* Called when the game plugin is freed from memory.
*/
void DP_Unload(void)
{
Plug_RemoveHook(HOOK_VIEWPORT_RESHAPE, R_UpdateViewport);
}

void G_PreInit(gameid_t gameId)
{
/// \todo Refactor me away.
Expand Down Expand Up @@ -202,5 +223,4 @@ game_export_t* GetGameAPI(game_import_t* imports)
void DP_Initialize(void)
{
Plug_AddHook(HOOK_STARTUP, G_RegisterGames);
Plug_AddHook(HOOK_VIEWPORT_RESHAPE, R_UpdateViewport);
}
2 changes: 2 additions & 0 deletions doomsday/plugins/jhexen/api/jhexen.def
Expand Up @@ -3,3 +3,5 @@ LIBRARY JHEXEN
EXPORTS
DP_Initialize @1
GetGameAPI @2
DP_Load @3
DP_Unload @4
22 changes: 21 additions & 1 deletion doomsday/plugins/jhexen/src/x_api.c
Expand Up @@ -106,6 +106,27 @@ int G_RegisterGames(int hookType, int param, void* data)
#undef DATAPATH
}

/**
* Called right after the game plugin is selected into use.
*/
void DP_Load(void)
{
// We might've been freed from memory, so refresh the game ids.
gameIds[hexen_deathkings] = DD_GameIdForKey("hexen-dk");
gameIds[hexen] = DD_GameIdForKey("hexen");
gameIds[hexen_demo] = DD_GameIdForKey("hexen-demo");

Plug_AddHook(HOOK_VIEWPORT_RESHAPE, R_UpdateViewport);
}

/**
* Called when the game plugin is freed from memory.
*/
void DP_Unload(void)
{
Plug_RemoveHook(HOOK_VIEWPORT_RESHAPE, R_UpdateViewport);
}

void G_PreInit(gameid_t gameId)
{
/// \todo Refactor me away.
Expand Down Expand Up @@ -201,5 +222,4 @@ game_export_t* GetGameAPI(game_import_t* imports)
void DP_Initialize(void)
{
Plug_AddHook(HOOK_STARTUP, G_RegisterGames);
Plug_AddHook(HOOK_VIEWPORT_RESHAPE, R_UpdateViewport);
}

0 comments on commit da282c2

Please sign in to comment.