- made the game interfaces classes instead of function pointer lists because that is far better at error catching.

- fixed: Blood's monster flag is a 'have_monsters', not 'nomonsters' flag. As a result none were spawned.
This commit is contained in:
Christoph Oelckers 2019-11-03 12:32:58 +01:00
parent d7e7c516a0
commit 3c7151810f
12 changed files with 91 additions and 72 deletions

View file

@ -1229,10 +1229,10 @@ static int32_t check_filename_casing(void)
}
#endif
int app_main()
int GameInterface::app_main()
{
memcpy(&gGameOptions, &gSingleGameOptions, sizeof(GAMEOPTIONS));
gGameOptions.nMonsterSettings = userConfig.nomonsters;
gGameOptions.nMonsterSettings = !userConfig.nomonsters;
bQuickStart = userConfig.nologo;
ParseOptions();
@ -2139,19 +2139,10 @@ void sndPlaySpecialMusicOrNothing(int nMusic)
}
}
extern void faketimerhandler();
extern int app_main();
bool validate_hud(int layout);
void set_hud_layout(int layout);
void set_hud_scale(int scale);
int32_t GetTime();
GameInterface Interface = {
faketimerhandler,
app_main,
validate_hud,
set_hud_layout,
set_hud_scale,
};
::GameInterface* CreateInterface()
{
return new GameInterface;
}
END_BLD_NS

View file

@ -83,4 +83,13 @@ bool fileExistsRFF(int id, const char* ext);
int sndTryPlaySpecialMusic(int nMusic);
void sndPlaySpecialMusicOrNothing(int nMusic);
struct GameInterface : ::GameInterface
{
void faketimerhandler() override;
int app_main() override;
bool validate_hud(int) override;
void set_hud_layout(int size) override;
void set_hud_scale(int size) override;
};
END_BLD_NS

View file

@ -84,12 +84,12 @@ int32_t mouseyaxismode = -1;
// This is mainly here to account for the different implementation between Blood and the other games
// and to allow unified handling and the same value range in the CVAR code.
// Unlike EDuke's version, NBlood's was actually fine, it just had a too small value range to be chosen as the unified version.
bool validate_hud(int layout)
bool GameInterface::validate_hud(int layout)
{
return layout > 3 && layout != 8; // 8 is the status bar overlay which NBlood did not implement.
}
void set_hud_layout(int layout)
void GameInterface::set_hud_layout(int layout)
{
static const uint8_t screen_size_vals[] = { 7, 7, 7, 7, 6, 5, 4, 3, 3, 2, 1, 0 };
@ -99,7 +99,7 @@ void set_hud_layout(int layout)
}
}
void set_hud_scale(int scale)
void GameInterface::set_hud_scale(int scale)
{
// Not implemented, only needed as a placeholder. Maybe implement it after all? The hud is a bit large at its default size.
}

View file

@ -1392,6 +1392,11 @@ void faketimerhandler(void)
// enet_host_service(gNetMode == NETWORK_SERVER ? gNetENetServer : gNetENetClient, NULL, 0);
}
void GameInterface::faketimerhandler()
{
::Blood::faketimerhandler();
}
void netPlayerQuit(int nPlayer)
{
char buffer[128];

View file

@ -228,13 +228,15 @@ int32_t baselayer_init();
struct GameInterface
{
void (*faketimerhandler)();
int (*app_main)();
bool (*validate_hud)(int);
void (*set_hud_layout)(int size);
void (*set_hud_scale)(int size);
virtual ~GameInterface() {}
virtual void faketimerhandler() {} // This is a remnant of older versions, but Blood backend has not updated yet.
virtual int app_main() = 0;
virtual bool validate_hud(int) = 0;
virtual void set_hud_layout(int size) = 0;
virtual void set_hud_scale(int size) = 0;
};
extern GameInterface* gi;
#endif // baselayer_h_

View file

@ -301,46 +301,46 @@ void UserConfig::ProcessOptions()
namespace Duke
{
extern GameInterface Interface;
::GameInterface* CreateInterface();
}
namespace Redneck
{
extern GameInterface Interface;
::GameInterface* CreateInterface();
}
namespace Blood
{
extern GameInterface Interface;
::GameInterface* CreateInterface();
}
namespace ShadowWarrior
{
extern GameInterface Interface;
::GameInterface* CreateInterface();
}
void CheckFrontend(int flags)
{
if (flags & GAMEFLAG_BLOOD)
{
gi = &Blood::Interface;
gi = Blood::CreateInterface();
globalShadeDiv = 62;
}
else if (flags & GAMEFLAG_RR)
{
gi = &Redneck::Interface;
gi = Redneck::CreateInterface();
globalShadeDiv = 30;
}
else if (flags & GAMEFLAG_FURY)
{
gi = &Duke::Interface;
gi = Duke::CreateInterface();
globalShadeDiv = 26; // This is different from all other games which need a value two less than the amount of shades.
}
else if (flags & GAMEFLAG_SW)
{
gi = &ShadowWarrior::Interface;
gi = ShadowWarrior::CreateInterface();
globalShadeDiv = 30;
}
else
{
gi = &Duke::Interface;
gi = Duke::CreateInterface();
globalShadeDiv = 30;
}
}

View file

@ -144,6 +144,15 @@ static inline int32_t G_DefaultActorHealth(int spriteNum)
return G_HaveActor(spriteNum) ? g_tile[spriteNum].execPtr[0] : 0;
}
struct GameInterface : ::GameInterface
{
int app_main() override;
bool validate_hud(int) override;
void set_hud_layout(int size) override;
void set_hud_scale(int size) override;
};
END_DUKE_NS
#endif

View file

@ -4454,7 +4454,7 @@ void G_PrintCurrentMusic(void)
// Trying to sanitize the mess of options and the mess of variables the mess was stored in. (Did I say this was a total mess before...? >) )
// Hopefully this is more comprehensible, at least it neatly stores everything useful in a single linear value...
bool validate_hud(int layout)
bool GameInterface::validate_hud(int layout)
{
if (layout <= 6) // Status bar with border
{
@ -4483,7 +4483,7 @@ bool validate_hud(int layout)
return false;
}
void set_hud_layout(int layout)
void GameInterface::set_hud_layout(int layout)
{
static const uint8_t screen_size_vals[] = { 60, 54, 48, 40, 32, 24, 16, 8, 8, 4, 4, 0 };
if (validate_hud(layout))
@ -4495,7 +4495,7 @@ void set_hud_layout(int layout)
}
}
void set_hud_scale(int scale)
void GameInterface::set_hud_scale(int scale)
{
G_UpdateScreenArea();
}
@ -6125,7 +6125,7 @@ void G_MaybeAllocPlayer(int32_t pnum)
EDUKE32_STATIC_ASSERT(sizeof(actor_t)%4 == 0);
EDUKE32_STATIC_ASSERT(sizeof(DukePlayer_t)%4 == 0);
int app_main()
int GameInterface::app_main()
{
g_skillCnt = 4;
ud.multimode = 1;
@ -6908,14 +6908,9 @@ void A_SpawnRandomGlass(int spriteNum, int wallNum, int glassCnt)
}
#endif
extern void faketimerhandler();
GameInterface Interface = {
faketimerhandler,
app_main,
validate_hud,
set_hud_layout,
set_hud_scale,
};
::GameInterface* CreateInterface()
{
return new GameInterface;
}
END_DUKE_NS

View file

@ -148,6 +148,15 @@ static inline int32_t G_DefaultActorHealth(int spriteNum)
return G_HaveActor(spriteNum) ? g_tile[spriteNum].execPtr[0] : 0;
}
struct GameInterface : ::GameInterface
{
int app_main() override;
bool validate_hud(int) override;
void set_hud_layout(int size) override;
void set_hud_scale(int size) override;
};
END_RR_NS
#endif

View file

@ -5975,7 +5975,7 @@ void G_PrintCurrentMusic(void)
// Trying to sanitize the mess of options and the mess of variables the mess was stored in. (Did I say this was a total mess before...? >) )
// Hopefully this is more comprehensible, at least it neatly stores everything useful in a single linear value...
bool validate_hud(int layout)
bool GameInterface::validate_hud(int layout)
{
if (layout <= (RR? 5: 6)) // Status bar with border
{
@ -6004,7 +6004,7 @@ bool validate_hud(int layout)
return false;
}
void set_hud_layout(int layout)
void GameInterface::set_hud_layout(int layout)
{
static const uint8_t screen_size_vals[] = { 60, 54, 48, 40, 32, 24, 16, 8, 8, 4, 4, 0 };
static const uint8_t screen_size_vals_rr[] = { 56, 48, 40, 32, 24, 16, 12, 8, 8, 4, 4, 0 };
@ -6017,7 +6017,7 @@ void set_hud_layout(int layout)
}
}
void set_hud_scale(int scale)
void GameInterface::set_hud_scale(int scale)
{
G_UpdateScreenArea();
}
@ -7532,7 +7532,7 @@ void G_MaybeAllocPlayer(int32_t pnum)
EDUKE32_STATIC_ASSERT(sizeof(actor_t)%4 == 0);
EDUKE32_STATIC_ASSERT(sizeof(DukePlayer_t)%4 == 0);
int app_main()
int GameInterface::app_main()
{
playing_rr = 1;
g_skillCnt = 4;
@ -8388,16 +8388,9 @@ void A_SpawnRandomGlass(int spriteNum, int wallNum, int glassCnt)
}
}
::GameInterface* CreateInterface()
{
return new GameInterface;
}
extern void faketimerhandler();
extern int app_main();
GameInterface Interface = {
faketimerhandler,
app_main,
validate_hud,
set_hud_layout,
set_hud_scale,
};
END_RR_NS

View file

@ -3288,7 +3288,7 @@ void CommandLineHelp(char const * const * argv)
#endif
}
int32_t app_main()
int32_t GameInterface::app_main()
{
int i;
int stat, nexti;
@ -5029,18 +5029,15 @@ saveable_module saveable_build =
NUM_SAVEABLE_ITEMS(saveable_build_data)
};
extern void faketimerhandler();
extern int app_main();
/*extern*/ bool validate_hud(int requested_size) { return requested_size; }
/*extern*/ void set_hud(int requested_size) { /* the relevant setting is gs.BorderNum */}
/*extern*/ bool GameInterface::validate_hud(int requested_size) { return requested_size; }
/*extern*/ void GameInterface::set_hud_layout(int requested_size) { /* the relevant setting is gs.BorderNum */}
/*extern*/ void GameInterface::set_hud_scale(int requested_size) { /* the relevant setting is gs.BorderNum */ }
::GameInterface* CreateInterface()
{
return new GameInterface;
}
GameInterface Interface = {
faketimerhandler,
app_main,
validate_hud,
set_hud,
set_hud,
};
// vim:ts=4:sw=4:expandtab:
END_SW_NS

View file

@ -2374,6 +2374,15 @@ int COVERinsertsprite(short sectnum, short statnum); //returns (short)spritenu
void AudioUpdate(void); // stupid
struct GameInterface : ::GameInterface
{
int app_main() override;
bool validate_hud(int) override;
void set_hud_layout(int size) override;
void set_hud_scale(int size) override;
};
END_SW_NS
#endif