diff --git a/TR5Main/Game/Lara/lara_flare.cpp b/TR5Main/Game/Lara/lara_flare.cpp index 0902052bc..3286e1f6d 100644 --- a/TR5Main/Game/Lara/lara_flare.cpp +++ b/TR5Main/Game/Lara/lara_flare.cpp @@ -63,7 +63,8 @@ void FlareControl(short itemNumber) DoProperDetection(itemNumber, oldX, oldY, oldZ, xv, item->fallspeed, zv); - short age = (short)(item->data) & 0x7FFF; + short& age = item->data; + age &= 0x7FFF; if (age >= FLARE_AGE) { if (!item->fallspeed && !item->speed) @@ -84,8 +85,6 @@ void FlareControl(short itemNumber) age |= 0x8000; } - - item->data = (void*)age; } void ready_flare() @@ -362,10 +361,11 @@ void CreateFlare(GAME_OBJECT_ID objectNum, int thrown) if (objectNum == ID_FLARE_ITEM) { + short& age = item->data; if (DoFlareLight((PHD_VECTOR*)&item->pos, Lara.flareAge)) - item->data = (void*)(Lara.flareAge | 0x8000); + age = (Lara.flareAge | 0x8000); else - item->data = (void*)(Lara.flareAge & 0x7FFF); + age = (Lara.flareAge & 0x7FFF); } else { diff --git a/TR5Main/Game/box.cpp b/TR5Main/Game/box.cpp index 1d6887a90..6d9faeaf4 100644 --- a/TR5Main/Game/box.cpp +++ b/TR5Main/Game/box.cpp @@ -364,7 +364,7 @@ void CreatureFloat(short itemNumber) void CreatureJoint(ITEM_INFO* item, short joint, short required) { - if (item->data == NULL) + if (!item->data) return; CREATURE_INFO* creature = (CREATURE_INFO*)item->data; @@ -403,7 +403,7 @@ void CreatureTilt(ITEM_INFO* item, short angle) short CreatureTurn(ITEM_INFO* item, short maximumTurn) { - if (item->data == NULL || maximumTurn == 0) + if (!item->data || maximumTurn == 0) return 0; CREATURE_INFO* creature; @@ -446,7 +446,7 @@ int CreatureAnimation(short itemNumber, short angle, short tilt) int boxHeight, height, nextHeight, nextBox; item = &g_Level.Items[itemNumber]; - if (item->data == NULL) + if (!item->data) return false; creature = (CREATURE_INFO*)item->data; @@ -1398,9 +1398,9 @@ void FindAITargetObject(CREATURE_INFO* creature, short objectNumber) if (foundObject != NULL) { - ITEM_INFO* aiItem = &creature->aiTarget; + CREATURE_TARGET* aiItem = &creature->aiTarget; - creature->enemy = aiItem; + creature->enemy = nullptr; aiItem->objectNumber = foundObject->objectNumber; aiItem->roomNumber = foundObject->roomNumber; @@ -1423,7 +1423,7 @@ void FindAITargetObject(CREATURE_INFO* creature, short objectNumber) void CreatureAIInfo(ITEM_INFO* item, AI_INFO* info) { - if (item->data == NULL) + if (!item->data) return; CREATURE_INFO * creature; @@ -1525,7 +1525,7 @@ void CreatureAIInfo(ITEM_INFO* item, AI_INFO* info) void CreatureMood(ITEM_INFO* item, AI_INFO* info, int violent) { - if (item->data == NULL) + if (!item->data) return; CREATURE_INFO* creature; @@ -1645,7 +1645,7 @@ void CreatureMood(ITEM_INFO* item, AI_INFO* info, int violent) void GetCreatureMood(ITEM_INFO* item, AI_INFO* info, int isViolent) { - if (item->data == NULL) + if (!item->data) return; CREATURE_INFO* creature; diff --git a/TR5Main/Game/creature_info.h b/TR5Main/Game/creature_info.h index 67cb0f892..f77b8ec0c 100644 --- a/TR5Main/Game/creature_info.h +++ b/TR5Main/Game/creature_info.h @@ -53,6 +53,16 @@ enum MOOD_TYPE { ESCAPE_MOOD, STALK_MOOD }; + +struct CREATURE_TARGET { + GAME_OBJECT_ID objectNumber; + int boxNumber; + PHD_3DPOS pos; + uint16_t flags; // ItemFlags enum + uint16_t triggerFlags; + short roomNumber; + +}; struct CREATURE_INFO { short jointRotation[4]; short maximumTurn; @@ -67,7 +77,7 @@ struct CREATURE_INFO { bool monkeyAhead; MOOD_TYPE mood; ITEM_INFO* enemy; - ITEM_INFO aiTarget; + CREATURE_TARGET aiTarget; short pad; short itemNum; PHD_VECTOR target; diff --git a/TR5Main/Game/door_data.h b/TR5Main/Game/door_data.h index 0dccd059c..f2c589e03 100644 --- a/TR5Main/Game/door_data.h +++ b/TR5Main/Game/door_data.h @@ -1,5 +1,6 @@ #pragma once #include "floordata.h" +struct ITEM_INFO; struct DOORPOS_DATA { FLOOR_INFO* floor; FLOOR_INFO data; diff --git a/TR5Main/Game/floordata.cpp b/TR5Main/Game/floordata.cpp index d07e215af..290eb750c 100644 --- a/TR5Main/Game/floordata.cpp +++ b/TR5Main/Game/floordata.cpp @@ -1,6 +1,6 @@ #include "framework.h" -#include "trmath.h" #include "floordata.h" +#include "trmath.h" #include "room.h" #include "level.h" #include "setup.h" diff --git a/TR5Main/Game/floordata.h b/TR5Main/Game/floordata.h index b5323543c..c5e08a1b6 100644 --- a/TR5Main/Game/floordata.h +++ b/TR5Main/Game/floordata.h @@ -1,7 +1,7 @@ #pragma once #include "trmath.h" -#include "items.h" - +#include +#include "roomvector.h" struct SECTOR_COLLISION_INFO { float SplitAngle; @@ -9,9 +9,8 @@ struct SECTOR_COLLISION_INFO Vector3 Planes[2]; }; -class FLOOR_INFO +struct FLOOR_INFO { -public: int index; int box; int fx; diff --git a/TR5Main/Game/item.h b/TR5Main/Game/item.h index 0ff8592f1..69d1a3536 100644 --- a/TR5Main/Game/item.h +++ b/TR5Main/Game/item.h @@ -2,12 +2,11 @@ #include #include "phd_global.h" #include +#include "itemdata.h" +#include "roomvector.h" enum GAME_OBJECT_ID : short; -struct ROOM_VECTOR { - int roomNumber; - int yNumber; -}; + struct ITEM_INFO { int floor; @@ -35,7 +34,7 @@ struct ITEM_INFO { short afterDeath; short firedWeapon; short itemFlags[8]; - void* data; + ITEM_DATA data; PHD_3DPOS pos; bool active; short status; // ItemStatus enum diff --git a/TR5Main/Game/itemdata/itemdata.cpp b/TR5Main/Game/itemdata/itemdata.cpp new file mode 100644 index 000000000..a4c2abcb8 --- /dev/null +++ b/TR5Main/Game/itemdata/itemdata.cpp @@ -0,0 +1,4 @@ +#include "framework.h" +#include "itemdata.h" + +ITEM_DATA::ITEM_DATA() : ITEM_DATA(ITEM_DATA_TYPE()) {} diff --git a/TR5Main/Game/itemdata/itemdata.h b/TR5Main/Game/itemdata/itemdata.h index c6385c096..b03ad092c 100644 --- a/TR5Main/Game/itemdata/itemdata.h +++ b/TR5Main/Game/itemdata/itemdata.h @@ -9,11 +9,21 @@ #include "lara_struct.h" #include "jeep_info.h" #include "motorbike_info.h" +#include "minecart_info.h" #include "biggun_info.h" #include "quad_info.h" #include "tr5_laserhead_info.h" #include "creature_info.h" +#include "boat_info.h" +#include "rubberboat_info.h" #include +#include "phd_global.h" +#include "tr4_wraith_info.h" +#include "tr5_pushableblock_info.h" + +template struct overload : Ts... { using Ts::operator()...; }; +template overload(Ts...)->overload; // line not needed in C++20... + struct ITEM_INFO; //Type Wrapper to construct a ITEM_DATA @@ -23,10 +33,20 @@ struct ITEM_DATA_TYPE { }; class ITEM_DATA { std::variant data; - + public: + ITEM_DATA(); //we have to use a wrapper for a type, because the compiler needs to distinguish different overloads template - ITEM_DATA(ITEM_DATA_TYPE type) : data(ITEM_DATA_TYPE::type{}) { - } + ITEM_DATA(ITEM_DATA_TYPE type) : data(ITEM_DATA_TYPE::type{}) {} + + template + ITEM_DATA(D&& type) : data(type) {} // conversion operators to keep original syntax! @@ -67,8 +96,34 @@ class ITEM_DATA { } template - T& operator=(T* newData){ + ITEM_DATA& operator=(T* newData) { data = *newData; return *this; } + + ITEM_DATA& operator=(std::nullptr_t null) { + data = nullptr; + return *this; + } + + template + ITEM_DATA& operator=(T& newData) { + data = newData; + return *this; + } + template + ITEM_DATA& operator=(T&& newData) { + data = newData; + return *this; + } + operator bool() { + return !std::holds_alternative(data); + } + struct foo { + void operator()(double& d) {} + }; + + auto& get() const { + return data; + } }; diff --git a/TR5Main/Game/items.cpp b/TR5Main/Game/items.cpp index 19ebcc987..52006b29f 100644 --- a/TR5Main/Game/items.cpp +++ b/TR5Main/Game/items.cpp @@ -13,7 +13,7 @@ void ClearItem(short itemNum) ROOM_INFO* room = &g_Level.Rooms[item->roomNumber]; item->collidable = true; - item->data = NULL; + item->data = nullptr; item->drawRoom = (((item->pos.zPos - room->z) / SECTOR(1)) & 0xFF) | ((((item->pos.xPos - room->x) / SECTOR(1)) & 0xFF) * 256); item->TOSSPAD = item->pos.yRot & 0xE000; item->itemFlags[2] = item->roomNumber | ((item->pos.yPos - room->minfloor) & 0xFF00); diff --git a/TR5Main/Game/roomvector.h b/TR5Main/Game/roomvector.h new file mode 100644 index 000000000..ca9026480 --- /dev/null +++ b/TR5Main/Game/roomvector.h @@ -0,0 +1,5 @@ +#pragma once +struct ROOM_VECTOR { + int roomNumber; + int yNumber; +}; \ No newline at end of file diff --git a/TR5Main/Game/savegame.cpp b/TR5Main/Game/savegame.cpp index 86bc021e3..7585d4573 100644 --- a/TR5Main/Game/savegame.cpp +++ b/TR5Main/Game/savegame.cpp @@ -1022,7 +1022,7 @@ bool SaveGame::readItemChunks(ChunkId* chunkId, int maxSize, int itemNumber) QUAD_INFO* quadInfo = game_malloc(); m_stream->ReadBytes(reinterpret_cast(quadInfo), sizeof(QUAD_INFO)); if (item->objectNumber == ID_QUAD) - item->data = (void*)quadInfo; + item->data = quadInfo; return true; } @@ -1418,7 +1418,7 @@ bool SaveGame::readFlare() AddActiveItem(itemNumber); // Flare age - item->data = (void*)LEB128::ReadInt32(m_stream); + item->data = LEB128::ReadInt32(m_stream); return true; } @@ -1465,7 +1465,8 @@ bool SaveGame::readTorpedo() void SaveGame::saveItemQuadInfo(int itemNumber, int arg2) { - m_stream->WriteBytes(reinterpret_cast(g_Level.Items[itemNumber].data), sizeof(QUAD_INFO)); + + //m_stream->WriteBytes(reinterpret_cast(g_Level.Items[itemNumber].data), sizeof(QUAD_INFO)); } void SaveGame::saveRats(int arg1, int arg2) diff --git a/TR5Main/Objects/Generic/Switches/generic_switch.cpp b/TR5Main/Objects/Generic/Switches/generic_switch.cpp index ad105eaab..c64849a04 100644 --- a/TR5Main/Objects/Generic/Switches/generic_switch.cpp +++ b/TR5Main/Objects/Generic/Switches/generic_switch.cpp @@ -6,6 +6,7 @@ #include "sphere.h" #include "draw.h" #include "collide.h" +#include "floordata.h" namespace TEN::Entities::Switches { OBJECT_COLLISION_BOUNDS SwitchBounds = diff --git a/TR5Main/Objects/TR1/Entity/tr1_doppelganger.cpp b/TR5Main/Objects/TR1/Entity/tr1_doppelganger.cpp index f217b12b1..87ae0b6b4 100644 --- a/TR5Main/Objects/TR1/Entity/tr1_doppelganger.cpp +++ b/TR5Main/Objects/TR1/Entity/tr1_doppelganger.cpp @@ -61,7 +61,7 @@ void DoppelgangerControl(short itemNum) ref = findReference(item, ID_BACON_REFERENCE); // find reference point - if (item->data == NULL) + if (!item->data) { if (ref == nullptr) // if no reference found, she doesn't move { @@ -106,7 +106,7 @@ void DoppelgangerControl(short itemNum) item->gravityStatus = true; item->fallspeed = 0; item->speed = 0; - item->data = (void*)-1; + item->data = -1; item->pos.yPos += 50; } } diff --git a/TR5Main/Objects/TR2/Entity/tr2_dragon.cpp b/TR5Main/Objects/TR2/Entity/tr2_dragon.cpp index 2594cb618..8c47b28a7 100644 --- a/TR5Main/Objects/TR2/Entity/tr2_dragon.cpp +++ b/TR5Main/Objects/TR2/Entity/tr2_dragon.cpp @@ -478,7 +478,7 @@ void InitialiseBartoli(short itemNum) InitialiseItem(back_item); back->meshBits = 0x1FFFFF; - item->data = (void*)back_item; + item->data = back_item; front = &g_Level.Items[front_item]; front->objectNumber = ID_DRAGON_FRONT; @@ -492,7 +492,7 @@ void InitialiseBartoli(short itemNum) InitialiseItem(front_item); - back->data = (void*)front_item; + back->data = front_item; g_Level.NumItems += 2; } diff --git a/TR5Main/Objects/TR2/Entity/tr2_knifethrower.cpp b/TR5Main/Objects/TR2/Entity/tr2_knifethrower.cpp index 525843423..8c311b7b7 100644 --- a/TR5Main/Objects/TR2/Entity/tr2_knifethrower.cpp +++ b/TR5Main/Objects/TR2/Entity/tr2_knifethrower.cpp @@ -9,6 +9,7 @@ #include "lara.h" #include "sound.h" #include "creature_info.h" +#include "floordata.h" BITE_INFO knifeLeft = { 0, 0, 0, 5 }; BITE_INFO knifeRight = { 0, 0, 0, 8 }; diff --git a/TR5Main/Objects/TR2/Entity/tr2_skidman.cpp b/TR5Main/Objects/TR2/Entity/tr2_skidman.cpp index f61d007c9..a50372f05 100644 --- a/TR5Main/Objects/TR2/Entity/tr2_skidman.cpp +++ b/TR5Main/Objects/TR2/Entity/tr2_skidman.cpp @@ -45,7 +45,7 @@ void InitialiseSkidman(short itemNum) InitialiseItem(skidoo_item); // The skidman remembers his skidoo - item->data = (void*)skidoo_item; + item->data = skidoo_item; g_Level.NumItems++; } diff --git a/TR5Main/Objects/TR2/Vehicles/boat.cpp b/TR5Main/Objects/TR2/Vehicles/boat.cpp index fc22249ad..9a944b660 100644 --- a/TR5Main/Objects/TR2/Vehicles/boat.cpp +++ b/TR5Main/Objects/TR2/Vehicles/boat.cpp @@ -495,7 +495,7 @@ int SpeedBoatDynamics(short itemNum) int newspeed; boat = &g_Level.Items[itemNum]; - binfo = (BOAT_INFO*)boat->data; + binfo = boat->data; boat->pos.zRot -= binfo->tiltAngle; @@ -815,8 +815,8 @@ void InitialiseSpeedBoat(short itemNum) BOAT_INFO* binfo; boat = &g_Level.Items[itemNum]; - binfo = game_malloc(); - boat->data = (void*)binfo; + boat->data = ITEM_DATA(ITEM_DATA_TYPE()); + binfo = boat->data; binfo->boatTurn = 0; binfo->leftFallspeed = 0; binfo->rightFallspeed = 0; diff --git a/TR5Main/Objects/TR2/Vehicles/snowmobile.cpp b/TR5Main/Objects/TR2/Vehicles/snowmobile.cpp index e076f48d7..dc6d994b2 100644 --- a/TR5Main/Objects/TR2/Vehicles/snowmobile.cpp +++ b/TR5Main/Objects/TR2/Vehicles/snowmobile.cpp @@ -79,9 +79,8 @@ enum SKIDOO_STATE void InitialiseSkidoo(short itemNum) { ITEM_INFO* skidoo = &g_Level.Items[itemNum]; - - SKIDOO_INFO* skinfo = game_malloc(); - skidoo->data = (void*)skinfo; + skidoo->data = ITEM_DATA(ITEM_DATA_TYPE()); + SKIDOO_INFO* skinfo = skidoo->data; skinfo->alreadyCdPlayed = false; diff --git a/TR5Main/Objects/TR3/Vehicles/biggun.cpp b/TR5Main/Objects/TR3/Vehicles/biggun.cpp index 613f94a07..f613d9811 100644 --- a/TR5Main/Objects/TR3/Vehicles/biggun.cpp +++ b/TR5Main/Objects/TR3/Vehicles/biggun.cpp @@ -121,10 +121,9 @@ void BigGunInitialise(short itemNum) BIGGUNINFO *gun; obj = &g_Level.Items[itemNum]; + obj->data = ITEM_DATA(ITEM_DATA_TYPE()); - gun = (BIGGUNINFO*)malloc(sizeof(BIGGUNINFO)); - obj->data = malloc(sizeof(BIGGUNINFO)); - + gun = obj->data; gun->flags = 0; gun->fireCount = 0; gun->xRot = GETOFF_FRAME; diff --git a/TR5Main/Objects/TR3/Vehicles/minecart.cpp b/TR5Main/Objects/TR3/Vehicles/minecart.cpp index 1eb9befd3..18bf75c70 100644 --- a/TR5Main/Objects/TR3/Vehicles/minecart.cpp +++ b/TR5Main/Objects/TR3/Vehicles/minecart.cpp @@ -775,8 +775,8 @@ void InitialiseMineCart(short itemNum) CART_INFO* cart; v = &g_Level.Items[itemNum]; - cart = game_malloc(); - v->data = (void*)cart; + v->data = CART_INFO(); + cart = v->data; cart->Flags = NULL; cart->Speed = 0; cart->YVel = 0; @@ -842,8 +842,8 @@ int MineCartControl(void) short roomNumber; v = &g_Level.Items[Lara.Vehicle]; - if (v->data == NULL) { printf("v->data is nullptr !"); return 0; } - cart = (CART_INFO*)v->data; + if (!v->data) { printf("v->data is nullptr !"); return 0; } + cart = v->data; DoUserInput(v, LaraItem, cart); diff --git a/TR5Main/Objects/TR3/Vehicles/rubberboat.cpp b/TR5Main/Objects/TR3/Vehicles/rubberboat.cpp index edf6257ca..f1f965475 100644 --- a/TR5Main/Objects/TR3/Vehicles/rubberboat.cpp +++ b/TR5Main/Objects/TR3/Vehicles/rubberboat.cpp @@ -49,10 +49,10 @@ void DrawRubberBoat(ITEM_INFO *item) { RUBBER_BOAT_INFO *b; - b = (RUBBER_BOAT_INFO*)item->data; + b = item->data; item->data = &b->propRot; DrawAnimatingItem(item); - item->data = (void *)b; + item->data = b; } int RubberBoatCheckGeton(short itemNum, COLL_INFO *coll) diff --git a/TR5Main/Objects/TR3/Vehicles/upv.cpp b/TR5Main/Objects/TR3/Vehicles/upv.cpp index 9d30e854f..554fc6eab 100644 --- a/TR5Main/Objects/TR3/Vehicles/upv.cpp +++ b/TR5Main/Objects/TR3/Vehicles/upv.cpp @@ -832,11 +832,10 @@ static void UserInput(ITEM_INFO* v, ITEM_INFO* l, SUB_INFO* sub) void SubInitialise(short itemNum) { ITEM_INFO* v; - SUB_INFO* sub; v = &g_Level.Items[itemNum]; - sub = game_malloc(); - v->data = (void*)sub; + v->data = ITEM_DATA(ITEM_DATA_TYPE()); + SUB_INFO* sub = v->data; sub->Vel = sub->Rot = 0; sub->Flags = UPV_SURFACE; sub->WeaponTimer = 0; diff --git a/TR5Main/Objects/TR4/Entity/tr4_enemy_jeep.cpp b/TR5Main/Objects/TR4/Entity/tr4_enemy_jeep.cpp index 68de3f6be..17538b86a 100644 --- a/TR5Main/Objects/TR4/Entity/tr4_enemy_jeep.cpp +++ b/TR5Main/Objects/TR4/Entity/tr4_enemy_jeep.cpp @@ -145,16 +145,10 @@ void EnemyJeepControl(short itemNumber) AI_INFO info; CreatureAIInfo(item, &info); - ITEM_INFO* target = &creature->aiTarget; - creature->enemy = target; + creature->enemy = nullptr; + CREATURE_TARGET* target = &creature->aiTarget; short angle; int distance; - if (target == LaraItem) - { - angle = info.angle; - distance = info.distance; - } - else { dx = LaraItem->pos.xPos - item->pos.xPos; dz = LaraItem->pos.zPos - item->pos.zPos; @@ -326,7 +320,7 @@ void EnemyJeepControl(short itemNumber) if (aiObject != NULL) { - creature->enemy = target; + creature->enemy = nullptr; target->objectNumber = aiObject->objectNumber; target->roomNumber = aiObject->roomNumber; target->pos.xPos = aiObject->x; diff --git a/TR5Main/Objects/TR4/Entity/tr4_sas.cpp b/TR5Main/Objects/TR4/Entity/tr4_sas.cpp index e69601882..de1eddbee 100644 --- a/TR5Main/Objects/TR4/Entity/tr4_sas.cpp +++ b/TR5Main/Objects/TR4/Entity/tr4_sas.cpp @@ -13,7 +13,6 @@ #include #include "creature_info.h" #include "control.h" -void SasControl(short itemNumber) namespace TEN::Entities::TR4 { enum SAS_STATES diff --git a/TR5Main/Objects/TR4/Entity/tr4_skeleton.cpp b/TR5Main/Objects/TR4/Entity/tr4_skeleton.cpp index d822e6b22..2c0b69d0a 100644 --- a/TR5Main/Objects/TR4/Entity/tr4_skeleton.cpp +++ b/TR5Main/Objects/TR4/Entity/tr4_skeleton.cpp @@ -14,7 +14,7 @@ #include "tomb4fx.h" #include "level.h" #include "creature_info.h" - +#include "floordata.h" namespace TEN::Entities::TR4 { BITE_INFO skeletonBite = { 0, -16, 200, 11 }; diff --git a/TR5Main/Objects/TR4/Entity/tr4_wraith.cpp b/TR5Main/Objects/TR4/Entity/tr4_wraith.cpp index 4801319a1..d2bf005f6 100644 --- a/TR5Main/Objects/TR4/Entity/tr4_wraith.cpp +++ b/TR5Main/Objects/TR4/Entity/tr4_wraith.cpp @@ -9,7 +9,7 @@ #include #include #include - +#include "tr4_wraith_info.h" constexpr auto WRAITH_COUNT = 8; short WraithSpeed = 64; diff --git a/TR5Main/Objects/TR4/Entity/tr4_wraith.h b/TR5Main/Objects/TR4/Entity/tr4_wraith.h index 33b931895..323539a0e 100644 --- a/TR5Main/Objects/TR4/Entity/tr4_wraith.h +++ b/TR5Main/Objects/TR4/Entity/tr4_wraith.h @@ -1,18 +1,7 @@ #pragma once -#include "items.h" +struct ITEM_INFO; + -struct WRAITH_INFO -{ - int xPos; - int yPos; - int zPos; - short xRot; - short yRot; - short zRot; - byte r; - byte g; - byte b; -}; void InitialiseWraith(short itemNumber); void WraithControl(short itemNumber); diff --git a/TR5Main/Objects/TR4/Entity/tr4_wraith_info.h b/TR5Main/Objects/TR4/Entity/tr4_wraith_info.h new file mode 100644 index 000000000..1a3328e1d --- /dev/null +++ b/TR5Main/Objects/TR4/Entity/tr4_wraith_info.h @@ -0,0 +1,12 @@ +#pragma once +struct WRAITH_INFO { + int xPos; + int yPos; + int zPos; + short xRot; + short yRot; + short zRot; + unsigned char r; + unsigned char g; + unsigned char b; +}; \ No newline at end of file diff --git a/TR5Main/Objects/TR4/Object/tr4_senet.cpp b/TR5Main/Objects/TR4/Object/tr4_senet.cpp index a74e8ea23..08ac8488a 100644 --- a/TR5Main/Objects/TR4/Object/tr4_senet.cpp +++ b/TR5Main/Objects/TR4/Object/tr4_senet.cpp @@ -28,7 +28,8 @@ void InitialiseGameStix(short itemNumber) item = &g_Level.Items[itemNumber]; item->itemFlags[7] = -1; - item->data = &item->itemFlags; + //not needed + //item->data = &item->itemFlags; ActivePiece = -1; SenetDisplacement = 0; } diff --git a/TR5Main/Objects/TR4/Vehicles/motorbike.cpp b/TR5Main/Objects/TR4/Vehicles/motorbike.cpp index 5a9f62a3e..4a492381d 100644 --- a/TR5Main/Objects/TR4/Vehicles/motorbike.cpp +++ b/TR5Main/Objects/TR4/Vehicles/motorbike.cpp @@ -140,8 +140,8 @@ void InitialiseMotorbike(short itemNumber) MOTORBIKE_INFO* motorbike; item = &g_Level.Items[itemNumber]; - motorbike = game_malloc(); - item->data = (void*)motorbike; + item->data = ITEM_DATA(MOTORBIKE_INFO()); + motorbike = item->data; motorbike->velocity = 0; motorbike->bikeTurn = 0; motorbike->pitch = 0; diff --git a/TR5Main/Objects/TR5/Object/tr5_pushableblock.cpp b/TR5Main/Objects/TR5/Object/tr5_pushableblock.cpp index 3ab02c96e..712c7e378 100644 --- a/TR5Main/Objects/TR5/Object/tr5_pushableblock.cpp +++ b/TR5Main/Objects/TR5/Object/tr5_pushableblock.cpp @@ -10,7 +10,7 @@ #include "input.h" #include "sound.h" #include "setup.h" -#define GET_PUSHABLEINFO(item) ((PUSHABLE_INFO*) item->data) +#include "tr5_pushableblock_info.h" static OBJECT_COLLISION_BOUNDS PushableBlockBounds = { 0x0000, 0x0000, 0xFFC0, 0x0000, @@ -70,7 +70,8 @@ void InitialisePushableBlock(short itemNum) ClearMovableBlockSplitters(item->pos.xPos, item->pos.yPos, item->pos.zPos, item->roomNumber); // allocate new pushable info - PUSHABLE_INFO* pushable = new PUSHABLE_INFO; + item->data = PUSHABLE_INFO(); + PUSHABLE_INFO* pushable = item->data; pushable->stackLimit = 3; // LUA pushable->gravity = 8; // LUA @@ -112,8 +113,6 @@ void InitialisePushableBlock(short itemNum) pushable->stopSound = SFX_TR4_PUSH_BLOCK_END; // LUA pushable->fallSound = SFX_TR4_BOULDER_FALL; // LUA - item->data = (void*) pushable; - FindStack(itemNum); // check for stack formation when pushables are initialised } @@ -133,7 +132,7 @@ void PushableBlockControl(short itemNumber) short roomNumber; FLOOR_INFO* floor; ROOM_INFO* r; - PUSHABLE_INFO* pushable = GET_PUSHABLEINFO(item); + PUSHABLE_INFO* pushable = item->data; int blockHeight = GetStackHeight(item); // do sound effects, it works for now @@ -382,7 +381,7 @@ void PushableBlockCollision(short itemNum, ITEM_INFO* l, COLL_INFO* coll) short roomNumber = item->roomNumber; FLOOR_INFO* floor = GetFloor(item->pos.xPos, item->pos.yPos - 256, item->pos.zPos, &roomNumber); - PUSHABLE_INFO* pushable = GET_PUSHABLEINFO(item); + PUSHABLE_INFO* pushable = item->data; int blockHeight = GetStackHeight(item); @@ -593,7 +592,7 @@ int TestBlockPush(ITEM_INFO* item, int blockhite, unsigned short quadrant) if (HeightType) return 0; - if (GET_PUSHABLEINFO(item)->canFall) + if (((PUSHABLE_INFO*)item->data)->canFall) { if (floorHeight < y) return 0; @@ -834,8 +833,8 @@ void MoveStackY(short itemNum, int y) void AddBridgeStack(short itemNum) { auto item = &g_Level.Items[itemNum]; - - if (GET_PUSHABLEINFO(item)->hasFloorCeiling) + PUSHABLE_INFO* pushable = item->data; + if (pushable->hasFloorCeiling) ten::Floordata::AddBridge(itemNum); int stackIndex = g_Level.Items[itemNum].itemFlags[1]; @@ -843,7 +842,7 @@ void AddBridgeStack(short itemNum) { auto stackItem = &g_Level.Items[stackIndex]; - if (GET_PUSHABLEINFO(stackItem)->hasFloorCeiling) + if (pushable->hasFloorCeiling) ten::Floordata::AddBridge(stackIndex); stackIndex = g_Level.Items[stackIndex].itemFlags[1]; @@ -853,8 +852,9 @@ void AddBridgeStack(short itemNum) void RemoveBridgeStack(short itemNum) { auto item = &g_Level.Items[itemNum]; + PUSHABLE_INFO* pushable = item->data; - if (GET_PUSHABLEINFO(item)->hasFloorCeiling) + if (pushable->hasFloorCeiling) ten::Floordata::RemoveBridge(itemNum); int stackIndex = g_Level.Items[itemNum].itemFlags[1]; @@ -862,7 +862,7 @@ void RemoveBridgeStack(short itemNum) { auto stackItem = &g_Level.Items[stackIndex]; - if (GET_PUSHABLEINFO(stackItem)->hasFloorCeiling) + if (pushable->hasFloorCeiling) ten::Floordata::RemoveBridge(stackIndex); stackIndex = g_Level.Items[stackIndex].itemFlags[1]; @@ -929,13 +929,14 @@ int FindStack(short itemNum) int GetStackHeight(ITEM_INFO* item) { - int height = GET_PUSHABLEINFO(item)->height; + PUSHABLE_INFO* pushable = item->data; + int height = pushable->height; auto stackItem = item; while (stackItem->itemFlags[1] != NO_ITEM) { stackItem = &g_Level.Items[stackItem->itemFlags[1]]; - height += GET_PUSHABLEINFO(stackItem)->height; + height += pushable->height; } return height; @@ -943,7 +944,9 @@ int GetStackHeight(ITEM_INFO* item) bool CheckStackLimit(ITEM_INFO* item) { - int limit = GET_PUSHABLEINFO(item)->stackLimit; + PUSHABLE_INFO* pushable = item->data; + + int limit = pushable->stackLimit; int count = 1; auto stackItem = item; @@ -962,7 +965,7 @@ bool CheckStackLimit(ITEM_INFO* item) std::optional PushableBlockFloor(short itemNumber, int x, int y, int z) { const auto& item = g_Level.Items[itemNumber]; - const auto& pushable = *(PUSHABLE_INFO*)item.data; + const auto& pushable = (PUSHABLE_INFO&)item.data; if (item.status != ITEM_INVISIBLE && pushable.hasFloorCeiling) { @@ -975,7 +978,7 @@ std::optional PushableBlockFloor(short itemNumber, int x, int y, int z) std::optional PushableBlockCeiling(short itemNumber, int x, int y, int z) { const auto& item = g_Level.Items[itemNumber]; - const auto& pushable = *(PUSHABLE_INFO*)item.data; + const auto& pushable = (PUSHABLE_INFO&)item.data; if (item.status != ITEM_INVISIBLE && pushable.hasFloorCeiling) return std::optional{item.pos.yPos}; diff --git a/TR5Main/Objects/TR5/Object/tr5_pushableblock.h b/TR5Main/Objects/TR5/Object/tr5_pushableblock.h index 0d853aff0..75b49e2fd 100644 --- a/TR5Main/Objects/TR5/Object/tr5_pushableblock.h +++ b/TR5Main/Objects/TR5/Object/tr5_pushableblock.h @@ -2,28 +2,7 @@ struct ITEM_INFO; struct COLL_INFO; -struct PUSHABLE_INFO -{ - int height; // height for collision, also in floor procedure - int weight; - int stackLimit; - int moveX; // used for pushable movement code - int moveZ; // used for pushable movement code - short linkedIndex; // using itemFlags[1] for now - short gravity; // fall acceleration - short loopSound; // looped sound index for movement - short stopSound; // ending sound index - short fallSound; // sound on hitting floor (if dropped) - short climb; // not used for now - bool canFall; // OCB 32 - bool hasFloorCeiling; // has floor and ceiling procedures (OCB 64) - bool disablePull; // OCB 128 - bool disablePush; // OCB 256 - bool disableW; // OCB 512 (W+E) - bool disableE; // OCB 512 (W+E) - bool disableN; // OCB 1024 (N+S) - bool disableS; // OCB 1024 (N+S) -}; + void ClearMovableBlockSplitters(int x, int y, int z, short roomNumber); void InitialisePushableBlock(short itemNum); diff --git a/TR5Main/Objects/TR5/Object/tr5_pushableblock_info.h b/TR5Main/Objects/TR5/Object/tr5_pushableblock_info.h new file mode 100644 index 000000000..a1a41638b --- /dev/null +++ b/TR5Main/Objects/TR5/Object/tr5_pushableblock_info.h @@ -0,0 +1,22 @@ +#pragma once +struct PUSHABLE_INFO { + int height; // height for collision, also in floor procedure + int weight; + int stackLimit; + int moveX; // used for pushable movement code + int moveZ; // used for pushable movement code + short linkedIndex; // using itemFlags[1] for now + short gravity; // fall acceleration + short loopSound; // looped sound index for movement + short stopSound; // ending sound index + short fallSound; // sound on hitting floor (if dropped) + short climb; // not used for now + bool canFall; // OCB 32 + bool hasFloorCeiling; // has floor and ceiling procedures (OCB 64) + bool disablePull; // OCB 128 + bool disablePush; // OCB 256 + bool disableW; // OCB 512 (W+E) + bool disableE; // OCB 512 (W+E) + bool disableN; // OCB 1024 (N+S) + bool disableS; // OCB 1024 (N+S) +}; \ No newline at end of file diff --git a/TR5Main/Renderer/Render11Helper.cpp b/TR5Main/Renderer/Render11Helper.cpp index 12b865395..a218a7277 100644 --- a/TR5Main/Renderer/Render11Helper.cpp +++ b/TR5Main/Renderer/Render11Helper.cpp @@ -223,91 +223,76 @@ namespace ten::renderer { RendererBone *currentBone = moveableObj.LinearizedBones[j]; currentBone->ExtraRotation = Vector3(0.0f, 0.0f, 0.0f); - - if (item->objectNumber == ID_QUAD) - { - QUAD_INFO* quad = (QUAD_INFO*)item->data; - if (j == 3 || j == 4) { - currentBone->ExtraRotation.x = TO_RAD(quad->rearRot); + auto& data = item->data.get(); + std::visit(overload{ + [&j,¤tBone](QUAD_INFO& quad) { + if(j == 3 || j == 4) { + currentBone->ExtraRotation.x = TO_RAD(quad.rearRot); + } else if(j == 6 || j == 7) { + currentBone->ExtraRotation.x = TO_RAD(quad.frontRot); } - else if (j == 6 || j == 7) { - currentBone->ExtraRotation.x = TO_RAD(quad->frontRot); - } - } - else if (item->objectNumber == ID_JEEP) { - JEEP_INFO* jeep = (JEEP_INFO*)item->data; - switch (j) { + }, + [&j,¤tBone](JEEP_INFO& jeep) { + switch(j) { case 9: - currentBone->ExtraRotation.x = TO_RAD(jeep->rot1); + currentBone->ExtraRotation.x = TO_RAD(jeep.rot1); break; case 10: - currentBone->ExtraRotation.x = TO_RAD(jeep->rot2); + currentBone->ExtraRotation.x = TO_RAD(jeep.rot2); break; case 12: - currentBone->ExtraRotation.x = TO_RAD(jeep->rot3); + currentBone->ExtraRotation.x = TO_RAD(jeep.rot3); break; case 13: - currentBone->ExtraRotation.x = TO_RAD(jeep->rot4); + currentBone->ExtraRotation.x = TO_RAD(jeep.rot4); break; } - } - else if (item->objectNumber == ID_MOTORBIKE) { - MOTORBIKE_INFO* bike = (MOTORBIKE_INFO*)item->data; - switch (j) { + }, + [&j,¤tBone](MOTORBIKE_INFO& bike) { + switch(j) { case 2: case 4: - currentBone->ExtraRotation.x = TO_RAD(bike->wheelRight); + currentBone->ExtraRotation.x = TO_RAD(bike.wheelRight); break; case 10: - currentBone->ExtraRotation.x = TO_RAD(bike->wheelLeft); + currentBone->ExtraRotation.x = TO_RAD(bike.wheelLeft); } - } - else if (item->objectNumber == ID_RUBBER_BOAT) - { - RUBBER_BOAT_INFO* boat = (RUBBER_BOAT_INFO*)item->data; - if (j == 2) - currentBone->ExtraRotation.z = TO_RAD(boat->propRot); - } - else if (item->objectNumber == ID_UPV) - { - SUB_INFO* upv = (SUB_INFO*)item->data; - if (j == 3) - currentBone->ExtraRotation.z = TO_RAD(upv->FanRot); - } - else if (item->objectNumber == ID_BIGGUN) - { - BIGGUNINFO* biggun = (BIGGUNINFO*)item->data; - if (j == 2) - currentBone->ExtraRotation.z = biggun->barrelZ; - } - else - { - CREATURE_INFO* creature = (CREATURE_INFO*)item->data; - - if (creature != NULL) - { - if (currentBone->ExtraRotationFlags & ROT_Y) - { - currentBone->ExtraRotation.y = TO_RAD(creature->jointRotation[lastJoint]); - lastJoint++; - } - - if (currentBone->ExtraRotationFlags & ROT_X) - { - currentBone->ExtraRotation.x = TO_RAD(creature->jointRotation[lastJoint]); - lastJoint++; - } - - if (currentBone->ExtraRotationFlags & ROT_Z) - { - currentBone->ExtraRotation.z = TO_RAD(creature->jointRotation[lastJoint]); - lastJoint++; - } + }, + [&j,¤tBone](RUBBER_BOAT_INFO& boat) { + if(j == 2) + currentBone->ExtraRotation.z = TO_RAD(boat.propRot); + }, + [&j, ¤tBone](SUB_INFO& upv) { + if(j == 3) + currentBone->ExtraRotation.z = TO_RAD(upv.FanRot); + }, + [&j, ¤tBone](BIGGUNINFO& biggun) { + if(j == 2) + currentBone->ExtraRotation.z = biggun.barrelZ; + }, + [&j,¤tBone,&lastJoint](CREATURE_INFO& creature) { + if(currentBone->ExtraRotationFlags & ROT_Y) { + currentBone->ExtraRotation.y = TO_RAD(creature.jointRotation[lastJoint]); + lastJoint++; } - } + + if(currentBone->ExtraRotationFlags & ROT_X) { + currentBone->ExtraRotation.x = TO_RAD(creature.jointRotation[lastJoint]); + lastJoint++; + } + + if(currentBone->ExtraRotationFlags & ROT_Z) { + currentBone->ExtraRotation.z = TO_RAD(creature.jointRotation[lastJoint]); + lastJoint++; + } + }, + [](auto&) {}, + }, data + ); + } ANIM_FRAME* framePtr[2]; @@ -331,7 +316,6 @@ namespace ten::renderer { RendererItem *itemToDraw = view.itemsToDraw[i]; ITEM_INFO *item = itemToDraw->Item; - CREATURE_INFO *creature = (CREATURE_INFO *)item->data; // Lara has her own routine if (item->objectNumber == ID_LARA) diff --git a/TR5Main/TombEngine.vcxproj b/TR5Main/TombEngine.vcxproj index b17223374..6e584159e 100644 --- a/TR5Main/TombEngine.vcxproj +++ b/TR5Main/TombEngine.vcxproj @@ -146,6 +146,7 @@ xcopy /Y "$(ProjectDir)Shaders\HUD\*.hlsl" "$(TargetDir)\Shaders\HUD\" + @@ -193,9 +194,11 @@ xcopy /Y "$(ProjectDir)Shaders\HUD\*.hlsl" "$(TargetDir)\Shaders\HUD\" + + @@ -517,6 +520,7 @@ xcopy /Y "$(ProjectDir)Shaders\HUD\*.hlsl" "$(TargetDir)\Shaders\HUD\" + diff --git a/TR5Main/TombEngine.vcxproj.filters b/TR5Main/TombEngine.vcxproj.filters index 46426f2fd..a30672aeb 100644 --- a/TR5Main/TombEngine.vcxproj.filters +++ b/TR5Main/TombEngine.vcxproj.filters @@ -1128,6 +1128,15 @@ File di intestazione + + File di intestazione + + + File di intestazione + + + File di intestazione + @@ -2033,6 +2042,9 @@ File di origine + + File di origine +