From d394bcc39ffe18c14613c95ba264c5e37a78d43d Mon Sep 17 00:00:00 2001 From: Lwmte Date: Fri, 20 Aug 2021 15:26:12 +0300 Subject: [PATCH] Completely get rid of TriggerIndex --- TR5Main/Game/Lara/lara.cpp | 4 -- TR5Main/Game/collide.cpp | 25 -------- TR5Main/Game/collide.h | 1 - TR5Main/Game/control.cpp | 126 ++++++++++++++++++++++++++----------- TR5Main/Game/control.h | 2 +- TR5Main/Game/objects.cpp | 39 ++---------- TR5Main/Game/savegame.cpp | 9 +-- TR5Main/Game/switch.cpp | 22 +++---- 8 files changed, 111 insertions(+), 117 deletions(-) diff --git a/TR5Main/Game/Lara/lara.cpp b/TR5Main/Game/Lara/lara.cpp index 28795b7bc..60c7ba953 100644 --- a/TR5Main/Game/Lara/lara.cpp +++ b/TR5Main/Game/Lara/lara.cpp @@ -919,10 +919,6 @@ void LaraAboveWater(ITEM_INFO* item, COLL_INFO* coll) //hmmmm // Check for collision with items LaraBaddieCollision(item, coll); - // FIXME: refresh floor globals because sometimes they are messed by calling GetFloorHeight - // all over the place. Needed for monkeyswing. Remove when block flags decoupled from floordata. -- Lwmte 19.08.21 - RefreshFloorGlobals(item); - // Handle Lara collision if (Lara.Vehicle == NO_ITEM) lara_collision_routines[item->currentAnimState](item, coll); diff --git a/TR5Main/Game/collide.cpp b/TR5Main/Game/collide.cpp index db5d71969..beb178807 100644 --- a/TR5Main/Game/collide.cpp +++ b/TR5Main/Game/collide.cpp @@ -1080,8 +1080,6 @@ void DoFloorThings(FLOOR_INFO* floor, int x, int y, int z) int height = floor->floor * 256; if (height != NO_HEIGHT) { - TriggerIndex = NULL; - if (floor->index != 0) { short* data = &g_Level.FloorData[floor->index]; @@ -1131,11 +1129,7 @@ void DoFloorThings(FLOOR_INFO* floor, int x, int y, int z) break; case TRIGGER_TYPE: - if (!TriggerIndex) - TriggerIndex = data - 1; - data++; - do { trigger = *(data++); @@ -1152,18 +1146,6 @@ void DoFloorThings(FLOOR_INFO* floor, int x, int y, int z) } while (!(trigger & END_BIT)); break; - case LAVA_TYPE: - TriggerIndex = data - 1; - break; - - case CLIMB_TYPE: - case MONKEY_TYPE: - case TRIGTRIGGER_TYPE: - case MINER_TYPE: - if (!TriggerIndex) - TriggerIndex = data - 1; - break; - case SPLIT1: case SPLIT2: case NOCOLF1T: @@ -1258,13 +1240,6 @@ void DoFloorThings(FLOOR_INFO* floor, int x, int y, int z) } } -void RefreshFloorGlobals(ITEM_INFO* item) -{ - auto room = item->roomNumber; - auto floor = GetFloor(item->pos.xPos, item->pos.yPos, item->pos.zPos, &room); - DoFloorThings(floor, item->pos.xPos, item->pos.yPos, item->pos.zPos); -} - void GetCollisionInfo(COLL_INFO* coll, int xPos, int yPos, int zPos, int roomNumber, int objectHeight) { int resetRoom; diff --git a/TR5Main/Game/collide.h b/TR5Main/Game/collide.h index 8bdda1c75..07be9061b 100644 --- a/TR5Main/Game/collide.h +++ b/TR5Main/Game/collide.h @@ -126,7 +126,6 @@ int Move3DPosTo3DPos(PHD_3DPOS* src, PHD_3DPOS* dest, int velocity, short angAdd int MoveLaraPosition(PHD_VECTOR* pos, ITEM_INFO* item, ITEM_INFO* l); int TestBoundsCollide(ITEM_INFO* item, ITEM_INFO* l, int radius); void CreatureCollision(short itemNum, ITEM_INFO* l, COLL_INFO* coll); -void RefreshFloorGlobals(ITEM_INFO* item); void GetCollisionInfo(COLL_INFO* coll, int xPos, int yPos, int zPos, int roomNumber, int objectHeight); void GetObjectCollisionInfo(COLL_INFO* coll, int xPos, int yPos, int zPos, int roomNumber, int objectHeight); void LaraBaddieCollision(ITEM_INFO* item, COLL_INFO* coll); diff --git a/TR5Main/Game/control.cpp b/TR5Main/Game/control.cpp index 2d4fc20b6..e677b75a6 100644 --- a/TR5Main/Game/control.cpp +++ b/TR5Main/Game/control.cpp @@ -104,7 +104,6 @@ short NextFxActive; short NextFxFree; short NextItemActive; short NextItemFree; -short *TriggerIndex; int DisableLaraControl = 0; int WeatherType; @@ -130,7 +129,6 @@ int InitialiseGame; int RequiredStartPos; int WeaponDelay; int WeaponEnemyTimer; -HEIGHT_TYPES HeightType; int HeavyTriggered; short SkyPos1; short SkyPos2; @@ -162,6 +160,7 @@ short FlashFadeG; short FlashFadeB; short FlashFader; +HEIGHT_TYPES HeightType; int SplitFloor; int SplitCeiling; int TiltXOffset; @@ -1756,9 +1755,86 @@ int CheckNoColCeilingTriangle(FLOOR_INFO *floor, int x, int z) return 0; } +short* GetTriggerIndex(FLOOR_INFO* floor, int x, int y, int z) +{ + ROOM_INFO* r; + while (floor->pitRoom != NO_ROOM) + { + if (CheckNoColFloorTriangle(floor, x, z) == 1) + break; + r = &g_Level.Rooms[floor->pitRoom]; + floor = &XZ_GET_SECTOR(r, x - r->x, z - r->z); + } + + if ((floor->floor * 256) == NO_HEIGHT || floor->index == 0) + return NULL; + + short* triggerIndex = NULL; + + short* data = &g_Level.FloorData[floor->index]; + short type; + int trigger; + do + { + type = *(data++); + + switch (type & DATA_TYPE) + { + case DOOR_TYPE: + case TILT_TYPE: + case ROOF_TYPE: + case SPLIT1: + case SPLIT2: + case SPLIT3: + case SPLIT4: + case NOCOLF1T: + case NOCOLF1B: + case NOCOLF2T: + case NOCOLF2B: + case NOCOLC1T: + case NOCOLC1B: + case NOCOLC2T: + case NOCOLC2B: + data++; + break; + + case LAVA_TYPE: + case CLIMB_TYPE: + case MONKEY_TYPE: + case TRIGTRIGGER_TYPE: + case MINER_TYPE: + break; + + case TRIGGER_TYPE: + triggerIndex = data - 1; + data++; + + do + { + trigger = *(data++); + + if (TRIG_BITS(trigger) != TO_OBJECT) + { + if (TRIG_BITS(trigger) == TO_CAMERA || + TRIG_BITS(trigger) == TO_FLYBY) + { + trigger = *(data++); + } + } + + } while (!(trigger & END_BIT)); + break; + + default: + break; + } + } while (!(type & END_BIT)); + + return triggerIndex; +} + int GetFloorHeight(FLOOR_INFO *floor, int x, int y, int z) { - TiltYOffset = 0; TiltXOffset = 0; OnObject = 0; @@ -1777,15 +1853,8 @@ int GetFloorHeight(FLOOR_INFO *floor, int x, int y, int z) int height = floor->floor * 256; if (height != NO_HEIGHT) { - // return height; - - - TriggerIndex = NULL; - if (floor->index != 0) { - // return height; - short* data = &g_Level.FloorData[floor->index]; short type, hadj; @@ -1799,6 +1868,14 @@ int GetFloorHeight(FLOOR_INFO *floor, int x, int y, int z) switch (type & DATA_TYPE) { + + case LAVA_TYPE: + case CLIMB_TYPE: + case MONKEY_TYPE: + case TRIGTRIGGER_TYPE: + case MINER_TYPE: + break; + case DOOR_TYPE: case ROOF_TYPE: case SPLIT3: @@ -1833,11 +1910,7 @@ int GetFloorHeight(FLOOR_INFO *floor, int x, int y, int z) break; case TRIGGER_TYPE: - if (!TriggerIndex) - TriggerIndex = data - 1; - data++; - do { trigger = *(data++); @@ -1850,32 +1923,10 @@ int GetFloorHeight(FLOOR_INFO *floor, int x, int y, int z) trigger = *(data++); } } - else - { - /*item = &g_Level.Items[trigger & VALUE_BITS]; - obj = &Objects[item->objectNumber]; - - if (obj->floor && !(item->flags & 0x8000)) - { - (obj->floor)(item, x, y, z, &height); - }*/ - } } while (!(trigger & END_BIT)); break; - case LAVA_TYPE: - TriggerIndex = data - 1; - break; - - case CLIMB_TYPE: - case MONKEY_TYPE: - case TRIGTRIGGER_TYPE: - case MINER_TYPE: - if (!TriggerIndex) - TriggerIndex = data - 1; - break; - case SPLIT1: case SPLIT2: case NOCOLF1T: @@ -3522,13 +3573,12 @@ void TestTriggersAtXYZ(int x, int y, int z, short roomNumber, int heavy, int fla { auto roomNum = roomNumber; auto floor = GetFloor(x, y, z, &roomNum); - GetFloorHeight(floor, x, y, z); // Don't process legacy triggers if trigger triggerer wasn't used if (floor->Flags.MarkTriggerer && !floor->Flags.MarkTriggererActive) return; - TestTriggers(TriggerIndex, heavy, flags); + TestTriggers(GetTriggerIndex(floor, x, y, z), heavy, flags); } void ProcessSectorFlags(int x, int y, int z, short roomNumber) diff --git a/TR5Main/Game/control.h b/TR5Main/Game/control.h index a035c6536..8ed363ae9 100644 --- a/TR5Main/Game/control.h +++ b/TR5Main/Game/control.h @@ -76,7 +76,6 @@ extern short NextFxActive; extern short NextFxFree; extern short NextItemActive; extern short NextItemFree; -extern short* TriggerIndex; extern int DisableLaraControl; extern int WeatherType; extern int LaraDrawType; @@ -154,6 +153,7 @@ void AlterFloorHeight(ITEM_INFO* item, int height); int CheckNoColCeilingTriangle(FLOOR_INFO* floor, int x, int z); int CheckNoColFloorTriangle(FLOOR_INFO* floor, int x, int z); int GetFloorHeight(FLOOR_INFO* floor, int x, int y, int z); +short* GetTriggerIndex(FLOOR_INFO* floor, int x, int y, int z); FLOOR_INFO* GetFloor(int x, int y, int z, short* roomNumber); //void UpdateDebris(); int LOS(GAME_VECTOR* start, GAME_VECTOR* end); diff --git a/TR5Main/Game/objects.cpp b/TR5Main/Game/objects.cpp index 7b508ec0d..a00556681 100644 --- a/TR5Main/Game/objects.cpp +++ b/TR5Main/Game/objects.cpp @@ -130,40 +130,13 @@ void ControlTriggerTriggerer(short itemNumber) { ITEM_INFO* item = &g_Level.Items[itemNumber]; FLOOR_INFO* floor = GetFloor(item->pos.xPos, item->pos.yPos, item->pos.zPos, &item->roomNumber); - int height = GetFloorHeight(floor, item->pos.xPos, item->pos.yPos, item->pos.zPos); - - if (TriggerIndex) + + if (floor->Flags.MarkTriggerer) { - short* trigger = TriggerIndex; - - if ((*trigger & 0x1F) == 5) - { - if ((*trigger & 0x8000) != 0) - return; - trigger++; - } - - if ((*trigger & 0x1F) == 6) - { - if ((*trigger & 0x8000) != 0) - return; - trigger++; - } - - if ((*trigger & 0x1F) == 19) - { - if ((*trigger & 0x8000) != 0) - return; - trigger++; - } - - if ((*trigger & 0x1F) == 20) - { - if (TriggerActive(item)) - *trigger |= 0x20u; - else - *trigger &= 0xDFu; - } + if (TriggerActive(item)) + floor->Flags.MarkTriggererActive = true; + else + floor->Flags.MarkTriggererActive = false; } } diff --git a/TR5Main/Game/savegame.cpp b/TR5Main/Game/savegame.cpp index eb02d960a..fbfb39a02 100644 --- a/TR5Main/Game/savegame.cpp +++ b/TR5Main/Game/savegame.cpp @@ -811,10 +811,11 @@ bool SaveGame::readGameStatusChunks(ChunkId* chunkId, int maxSize, int arg) g_Level.Rooms[roomIndex].mesh[staticIndex].y, g_Level.Rooms[roomIndex].mesh[staticIndex].z, &roomIndex); - int height = GetFloorHeight(floor, g_Level.Rooms[roomIndex].mesh[staticIndex].x, - g_Level.Rooms[roomIndex].mesh[staticIndex].y, - g_Level.Rooms[roomIndex].mesh[staticIndex].z); - TestTriggers(TriggerIndex, 1, 0); + + TestTriggersAtXYZ(g_Level.Rooms[roomIndex].mesh[staticIndex].x, + g_Level.Rooms[roomIndex].mesh[staticIndex].y, + g_Level.Rooms[roomIndex].mesh[staticIndex].z, roomIndex, true, NULL); + floor->stopper = false; } diff --git a/TR5Main/Game/switch.cpp b/TR5Main/Game/switch.cpp index 48cf58491..f73a82d0d 100644 --- a/TR5Main/Game/switch.cpp +++ b/TR5Main/Game/switch.cpp @@ -1182,12 +1182,12 @@ void SwitchControl(short itemNumber) int GetKeyTrigger(ITEM_INFO* item) { FLOOR_INFO* floor = GetFloor(item->pos.xPos, item->pos.yPos, item->pos.zPos, &item->roomNumber); - GetFloorHeight(floor, item->pos.xPos, item->pos.yPos, item->pos.zPos); + auto triggerIndex = GetTriggerIndex(floor, item->pos.xPos, item->pos.yPos, item->pos.zPos); - if (TriggerIndex) + if (triggerIndex) { - short* trigger = TriggerIndex; - for (short i = *TriggerIndex; (i & 0x1F) != 4; trigger++) + short* trigger = triggerIndex; + for (short i = *triggerIndex; (i & 0x1F) != 4; trigger++) { if (i < 0) break; @@ -1210,12 +1210,12 @@ int GetKeyTrigger(ITEM_INFO* item) int GetSwitchTrigger(ITEM_INFO* item, short* itemNos, int AttatchedToSwitch) { FLOOR_INFO* floor = GetFloor(item->pos.xPos, item->pos.yPos, item->pos.zPos, &item->roomNumber); - GetFloorHeight(floor, item->pos.xPos, item->pos.yPos, item->pos.zPos); + auto triggerIndex = GetTriggerIndex(floor, item->pos.xPos, item->pos.yPos, item->pos.zPos); - if (TriggerIndex) + if (triggerIndex) { short* trigger; - for (trigger = TriggerIndex; (*trigger & DATA_TYPE) != TRIGGER_TYPE; trigger++) + for (trigger = triggerIndex; (*trigger & DATA_TYPE) != TRIGGER_TYPE; trigger++) { if (*trigger & END_BIT) break; @@ -1338,16 +1338,16 @@ void CogSwitchCollision(short itemNum, ITEM_INFO* l, COLL_INFO* coll) ITEM_INFO* item = &g_Level.Items[itemNum]; FLOOR_INFO* floor = GetFloor(item->pos.xPos, item->pos.yPos, item->pos.zPos, &item->roomNumber); - GetFloorHeight(floor, item->pos.xPos, item->pos.yPos, item->pos.zPos); + auto triggerIndex = GetTriggerIndex(floor, item->pos.xPos, item->pos.yPos, item->pos.zPos); - if (!TriggerIndex) + if (!triggerIndex) { ObjectCollision(itemNum, l, coll); return; } - short* trigger = TriggerIndex; - for (int i = *TriggerIndex; (i & 0x1F) != 4; trigger++) + short* trigger = triggerIndex; + for (int i = *triggerIndex; (i & 0x1F) != 4; trigger++) { if (i < 0) break;