Wow, relax, everyone! No need to fight over this :)
The functions are in the DLL, and I take function pointers to switch between the editor, gameplay, etc.
They're really just like the main "update and render" function in HH, but switchable depending on context. The problem is, when the DLL reloads, those pointers of course become invalid, and the game crashes.
Now, regarding ways to fix this, I think the second of Nimbal's solutions was pretty decent, without involving huge amounts of arcane magic.
My implementation looks like this:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 | SCENE_UPDATE_FUNC(gameplayUpdateAndRender);
SCENE_UPDATE_FUNC(editorUpdateAndRender);
SCENE_UPDATE_FUNC(mainMenuUpdateAndRender);
SCENE_UPDATE_FUNC(settingsUpdateAndRender);
enum funcPointerNames{
FUNC_GAMEPLAY_UPDATE,
FUNC_EDITOR_UPDATE,
FUNC_MAINMENU_UPDATE,
FUNC_SETTINGS_UPDATE
};
typedef SCENE_UPDATE_FUNC((*gameSceneFunc));
global_var gameSceneFunc g_funcPointers[] = {
gameplayUpdateAndRender,
editorUpdateAndRender,
mainMenuUpdateAndRender,
settingsUpdateAndRender
};
|
Then in the data section I store an enum for the current scene, and then call it like this:
| g_funcPointers[GameState->CurrentSceneFunc](MemPool, Platform, Renderer, Input, TimeInfo);
|
The dll, on load, makes sure the global function pointers array is initialized every time, so those pointers will never become invalid as long as I don't take them out of that array :)
This method has no switch statement, no class hierarchy, and is not very verbose. And if I ever need to use several types of functions, I can simply store them in an array of void(*)() pointers and cast them to the proper type before invocation.
Nice one, Nimbal :) Thanks!