mirror of
https://github.com/kevinbentley/Descent3.git
synced 2026-04-04 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:
@@ -907,10 +907,10 @@ int PriestClueSound = -1;
|
||||
int DummyObject = -1;
|
||||
int DummyDefaultPos = -1;
|
||||
|
||||
#define Var_ThereIsPlayerInPriestKeyPuzzle (*((int *)(&User_vars[7])))
|
||||
#define Var_PriestPlayerCurrentRoom (*((int *)(&User_vars[8])))
|
||||
#define Var_PriestPlayerCurrNode (*((int *)(&User_vars[9])))
|
||||
#define Var_PriestPuzzleCurrSoundNode (*((int *)(&User_vars[10])))
|
||||
#define Var_ThereIsPlayerInPriestKeyPuzzle User_vars[7]
|
||||
#define Var_PriestPlayerCurrentRoom User_vars[8]
|
||||
#define Var_PriestPlayerCurrNode User_vars[9]
|
||||
#define Var_PriestPuzzleCurrSoundNode User_vars[10]
|
||||
#define Var_PriestPuzzleCompleted User_vars[11]
|
||||
#define Var_PriestPuzzleGoofed User_vars[12]
|
||||
#define Var_SavedObject Saved_object_handles[1]
|
||||
@@ -1189,11 +1189,12 @@ void aPriestKeyRoomChange(void) {
|
||||
int GoodRoom;
|
||||
int num_BadRooms = 0;
|
||||
int curr_x, curr_y;
|
||||
curr_x = PriestCorrectPath[Var_PriestPlayerCurrNode].x;
|
||||
curr_y = PriestCorrectPath[Var_PriestPlayerCurrNode].y;
|
||||
auto cn = std::get<int32_t>(Var_PriestPlayerCurrNode);
|
||||
curr_x = PriestCorrectPath[cn].x;
|
||||
curr_y = PriestCorrectPath[cn].y;
|
||||
|
||||
GoodRoom = PriestKeyRoomMap[PriestCorrectPath[Var_PriestPlayerCurrNode + 1].y]
|
||||
[PriestCorrectPath[Var_PriestPlayerCurrNode + 1].x];
|
||||
GoodRoom = PriestKeyRoomMap[PriestCorrectPath[cn + 1].y]
|
||||
[PriestCorrectPath[cn + 1].x];
|
||||
|
||||
// check room to left
|
||||
if (curr_x > 0) {
|
||||
@@ -1261,11 +1262,12 @@ void aPriestKeyRoomChange(void) {
|
||||
// the player moved into a good room
|
||||
Var_PriestPlayerCurrNode += 1;
|
||||
Var_PriestPlayerCurrentRoom = Player_room;
|
||||
if (Var_PriestPlayerCurrNode == 16) {
|
||||
cn = std::get<int32_t>(Var_PriestPlayerCurrNode);
|
||||
if (cn == 16) {
|
||||
PriestPlayerSolvesPuzzle();
|
||||
} else {
|
||||
// adjust sound Position
|
||||
PriestPlaySoundAtNode(Var_PriestPlayerCurrNode + 1);
|
||||
PriestPlaySoundAtNode(cn + 1);
|
||||
}
|
||||
} break;
|
||||
}
|
||||
@@ -1687,6 +1689,8 @@ const char *Message_strings[NUM_MESSAGE_NAMES];
|
||||
// ===============
|
||||
// InitializeDLL()
|
||||
// ===============
|
||||
static constexpr std::initializer_list<int> uservars_as_int = {7, 8, 9, 10};
|
||||
|
||||
char STDCALL InitializeDLL(tOSIRISModuleInit *func_list) {
|
||||
osicommon_Initialize((tOSIRISModuleInit *)func_list);
|
||||
if (func_list->game_checksum != CHECKSUM) {
|
||||
@@ -1696,7 +1700,7 @@ char STDCALL InitializeDLL(tOSIRISModuleInit *func_list) {
|
||||
}
|
||||
|
||||
ClearGlobalActionCtrs();
|
||||
dfInit();
|
||||
dfInit(uservars_as_int);
|
||||
InitMessageList();
|
||||
|
||||
// Build the filename of the message file
|
||||
@@ -2483,7 +2487,7 @@ int16_t LevelScript_0000::CallEvent(int event, tOSIRISEventInfo *data) {
|
||||
tOSIRISEVTLEVELSTART *event_data = &data->evt_levelstart;
|
||||
|
||||
ClearGlobalActionCtrs();
|
||||
dfInit();
|
||||
dfInit(uservars_as_int);
|
||||
|
||||
// Script 006: LevelStart
|
||||
if (1) {
|
||||
|
||||
Reference in New Issue
Block a user