mirror of
https://github.com/kevinbentley/Descent3.git
synced 2026-04-07 11:00:04 -04:00
scripts: resolve strict aliasing violations in level DLLs
$GIT/scripts/LEVEL15.cpp: In function ‘void aMatCenPuzzleInit()’: $GIT/scripts/LEVEL15.cpp:833:38: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] 833 | #define MagicMatCenSwitchSequence (*((int *)(&User_vars[17]))) $GIT/scripts/LEVEL15.cpp:834:25: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] 834 | #define MatCenStateA (*((int *)(&User_vars[0]))) ... $GIT/scripts/Level6.cpp: In function ‘void aPriestKeyEnter(int)’: $GIT/scripts/Level6.cpp:910:47: warning: dereferencing type-punned pointer will break strict-aliasing rules [-Wstrict-aliasing] 910 | #define Var_ThereIsPlayerInPriestKeyPuzzle (*((int *)(&User_vars[7]))) Turn ``User_var`` into an array of std::variant, the latter of which can hold either float or int. Savegames do not carry the necessary type information which variant (float/int) is in use; instead, this is statically decided by the level DLL logic on a per-index basis. This approach is retained for now. A lot of ``Var_something = 0`` is used despite Var_something being logically used as float, so we need to override op= to keep the variant type as-is.
This commit is contained in:
@@ -828,12 +828,12 @@ const char *GetMessage(const char *name);
|
||||
#define MatCenSwitchAOn 13
|
||||
#define MatCenSwitchAOff 14
|
||||
|
||||
#define MagicMatCenSwitchSequence (*((int *)(&User_vars[17])))
|
||||
#define MatCenStateA (*((int *)(&User_vars[0])))
|
||||
#define MatCenStateB (*((int *)(&User_vars[1])))
|
||||
#define MatCenStateC (*((int *)(&User_vars[2])))
|
||||
#define MatCenStateD (*((int *)(&User_vars[3])))
|
||||
#define MatCenStateE (*((int *)(&User_vars[4])))
|
||||
#define MagicMatCenSwitchSequence User_vars[17]
|
||||
#define MatCenStateA User_vars[0]
|
||||
#define MatCenStateB User_vars[1]
|
||||
#define MatCenStateC User_vars[2]
|
||||
#define MatCenStateD User_vars[3]
|
||||
#define MatCenStateE User_vars[4]
|
||||
|
||||
struct tMyHandle {
|
||||
const char *name;
|
||||
@@ -1053,7 +1053,11 @@ void aMatCenPuzzleInit(void) {
|
||||
PlayOffAnimation(MatCenSwitchG);
|
||||
|
||||
MagicMatCenSwitchSequence = 0;
|
||||
MatCenStateA = MatCenStateB = MatCenStateC = MatCenStateD = MatCenStateE = 1;
|
||||
MatCenStateA = 1;
|
||||
MatCenStateB = 1;
|
||||
MatCenStateC = 1;
|
||||
MatCenStateD = 1;
|
||||
MatCenStateE = 1;
|
||||
|
||||
aObjPlayAnim(GetMyObject(MatCenResetSwitch), 0, 4, 4.000000f, 0);
|
||||
}
|
||||
@@ -1119,7 +1123,11 @@ void aMatCenPuzzleReset(void) {
|
||||
SetMatCenToLevel1(MatCen5);
|
||||
|
||||
MagicMatCenSwitchSequence = 0;
|
||||
MatCenStateA = MatCenStateB = MatCenStateC = MatCenStateD = MatCenStateE = 1;
|
||||
MatCenStateA = 1;
|
||||
MatCenStateB = 1;
|
||||
MatCenStateC = 1;
|
||||
MatCenStateD = 1;
|
||||
MatCenStateE = 1;
|
||||
|
||||
aObjPlayAnim(GetMyObject(MatCenResetSwitch), 0, 4, 4.000000f, 0);
|
||||
}
|
||||
@@ -1746,6 +1754,8 @@ const char *Message_strings[NUM_MESSAGE_NAMES];
|
||||
// ===============
|
||||
// InitializeDLL()
|
||||
// ===============
|
||||
static constexpr std::initializer_list<int> uservars_as_int = {17, 0, 1, 2, 3, 4};
|
||||
|
||||
char STDCALL InitializeDLL(tOSIRISModuleInit *func_list) {
|
||||
osicommon_Initialize((tOSIRISModuleInit *)func_list);
|
||||
if (func_list->game_checksum != CHECKSUM) {
|
||||
@@ -1755,7 +1765,7 @@ char STDCALL InitializeDLL(tOSIRISModuleInit *func_list) {
|
||||
}
|
||||
|
||||
ClearGlobalActionCtrs();
|
||||
dfInit();
|
||||
dfInit(uservars_as_int);
|
||||
InitMessageList();
|
||||
|
||||
// Build the filename of the message file
|
||||
@@ -2467,7 +2477,7 @@ int16_t LevelScript_0000::CallEvent(int event, tOSIRISEventInfo *data) {
|
||||
tOSIRISEVTLEVELSTART *event_data = &data->evt_levelstart;
|
||||
|
||||
ClearGlobalActionCtrs();
|
||||
dfInit();
|
||||
dfInit(uservars_as_int);
|
||||
|
||||
// Script 034: Level Start Initialization
|
||||
if (1) {
|
||||
|
||||
Reference in New Issue
Block a user