diff --git a/TR5Main/Game/box.cpp b/TR5Main/Game/box.cpp index d4d4cd75c..0fd52ee51 100644 --- a/TR5Main/Game/box.cpp +++ b/TR5Main/Game/box.cpp @@ -22,7 +22,15 @@ #define BIFF_AVOID_TURN 1536 #define FEELER_DISTANCE 512 #define FEELER_ANGLE ANGLE(45.0f) +#ifdef CREATURE_AI_PRIORITY_OPTIMIZATION +constexpr int HIGH_PRIO = 8; +constexpr int MEDIUM_PRIO = HIGH_PRIO + HIGH_PRIO * (HIGH_PRIO / 6.0f); +constexpr int LOW_PRIO = MEDIUM_PRIO + MEDIUM_PRIO * (MEDIUM_PRIO / 24.0f); +constexpr int NONE_PRIO = LOW_PRIO + LOW_PRIO * (LOW_PRIO / 32.0f); +constexpr auto FRAME_PRIO_BASE = 4; +constexpr auto FRAME_PRIO_EXP = 1.5; +#endif // CREATURE_AI_PRIORITY_OPTIMIZATION void DropBaddyPickups(ITEM_INFO* item) { ITEM_INFO* pickup = NULL; @@ -1071,7 +1079,23 @@ int SearchLOT(LOT_INFO* LOT, int depth) return true; } -int CreatureActive(short itemNumber) + +#if CREATURE_AI_PRIORITY_OPTIMIZATION +CREATURE_AI_PRIORITY GetCreatureLOTPriority(ITEM_INFO* item) { + Vector3 itemPos = Vector3(item->pos.xPos, item->pos.yPos, item->pos.zPos); + Vector3 cameraPos = Vector3(Camera.pos.x, Camera.pos.y, Camera.pos.z); + float distance = Vector3::Distance(itemPos, cameraPos); + distance /= SECTOR(1); + if(distance <= HIGH_PRIO) + return CREATURE_AI_PRIORITY::HIGH; + if(distance <= MEDIUM_PRIO) + return CREATURE_AI_PRIORITY::MEDIUM; + if(distance <= LOW_PRIO) + return CREATURE_AI_PRIORITY::LOW; + return CREATURE_AI_PRIORITY::NONE; +} +#endif +int CreatureActive(short itemNumber) { ITEM_INFO* item = &g_Level.Items[itemNumber]; @@ -1088,6 +1112,10 @@ int CreatureActive(short itemNumber) } item->status = ITEM_ACTIVE; } +#ifdef CREATURE_AI_PRIORITY_OPTIMIZATION + CREATURE_INFO* creature = (CREATURE_INFO*)item->data; + creature->priority = GetCreatureLOTPriority(item); +#endif // CREATURE_AI_PRIORITY_OPTIMIZATION return true; } @@ -1611,8 +1639,37 @@ void CreatureMood(ITEM_INFO* item, AI_INFO* info, int violent) if (LOT->targetBox == NO_BOX) TargetBox(LOT, item->boxNumber); +#ifdef CREATURE_AI_PRIORITY_OPTIMIZATION + bool shouldUpdateTarget = false; + switch(creature->priority) { + case CREATURE_AI_PRIORITY::HIGH: + shouldUpdateTarget = true; + break; + case CREATURE_AI_PRIORITY::MEDIUM: + { + if(creature->framesSinceLOTUpdate > std::pow(FRAME_PRIO_BASE, FRAME_PRIO_EXP)) + shouldUpdateTarget = true; + } + break; + case CREATURE_AI_PRIORITY::LOW: + { + if(creature->framesSinceLOTUpdate > std::pow(FRAME_PRIO_BASE,FRAME_PRIO_EXP*2)) + shouldUpdateTarget = true; + } + break; + default: + break; + } + if(shouldUpdateTarget) { + CalculateTarget(&creature->target, item, &creature->LOT); + creature->framesSinceLOTUpdate = 0; + } else { + creature->framesSinceLOTUpdate++; + } +#else CalculateTarget(&creature->target, item, &creature->LOT); +#endif // CREATURE_AI_PRIORITY_OPTIMIZATION creature->jumpAhead = false; creature->monkeyAhead = false; diff --git a/TR5Main/Game/creature_info.h b/TR5Main/Game/creature_info.h index 749a470db..f90684097 100644 --- a/TR5Main/Game/creature_info.h +++ b/TR5Main/Game/creature_info.h @@ -64,6 +64,14 @@ struct CREATURE_TARGET { short roomNumber; }; + +enum class CREATURE_AI_PRIORITY { + HIGH, + MEDIUM, + LOW, + NONE +}; + struct CREATURE_INFO { short jointRotation[4]; short maximumTurn; @@ -83,4 +91,8 @@ struct CREATURE_INFO { short itemNum; PHD_VECTOR target; LOT_INFO LOT; +#ifdef CREATURE_AI_PRIORITY_OPTIMIZATION + CREATURE_AI_PRIORITY priority; + size_t framesSinceLOTUpdate; +#endif }; \ No newline at end of file diff --git a/TR5Main/Game/lot.cpp b/TR5Main/Game/lot.cpp index 0f7062db0..7e669ba96 100644 --- a/TR5Main/Game/lot.cpp +++ b/TR5Main/Game/lot.cpp @@ -105,8 +105,9 @@ void DisableBaddieAI(short itemNumber) if (creature) { creature->itemNum = NO_ITEM; - item->data = nullptr; ActiveCreatures.erase(std::find(ActiveCreatures.begin(), ActiveCreatures.end(), creature)); + item->data = nullptr; + } } diff --git a/TR5Main/TombEngine.vcxproj b/TR5Main/TombEngine.vcxproj index c5fac96e1..ddd401679 100644 --- a/TR5Main/TombEngine.vcxproj +++ b/TR5Main/TombEngine.vcxproj @@ -64,7 +64,7 @@ Use TurnOffAllWarnings true - _CRT_SECURE_NO_WARNINGS;WIN32;TR5MAIN_EXPORTS;_WINDOWS;_USRDLL;NOMINMAX;NEW_INV;%(PreprocessorDefinitions) + _CRT_SECURE_NO_WARNINGS;WIN32;TR5MAIN_EXPORTS;_WINDOWS;_USRDLL;NOMINMAX;NEW_INV;CREATURE_AI_PRIORITY_OPTIMIZATION;%(PreprocessorDefinitions) false D:\Dokumente\TR5Main\TR5Main\Game\itemdata;$(SolutionDir)TR5Main\Game\itemdata;$(SolutionDir)TR5Main;$(SolutionDir)TR5Main\Game;$(SolutionDir)TR5Main\Game\Lara;$(SolutionDir)TR5Main\Objects;$(SolutionDir)TR5Main\Objects\Utils;$(SolutionDir)TR5Main\Objects\Effects;$(SolutionDir)TR5Main\Objects\Generic;$(SolutionDir)TR5Main\Objects\Generic\Switches;$(SolutionDir)TR5Main\Objects\Generic\Object;$(SolutionDir)TR5Main\Objects\TR1;$(SolutionDir)TR5Main\Objects\TR1\Entity;$(SolutionDir)TR5Main\Objects\TR1\Trap;$(SolutionDir)TR5Main\Objects\TR2;$(SolutionDir)TR5Main\Objects\TR2\Entity;$(SolutionDir)TR5Main\Objects\TR2\Trap;$(SolutionDir)TR5Main\Objects\TR2\Vehicles;$(SolutionDir)TR5Main\Objects\TR3;$(SolutionDir)TR5Main\Objects\TR3\Entity;$(SolutionDir)TR5Main\Objects\TR3\Trap;$(SolutionDir)TR5Main\Objects\TR3\Vehicles;$(SolutionDir)TR5Main\Objects\TR4;$(SolutionDir)TR5Main\Objects\TR4\Entity;$(SolutionDir)TR5Main\Objects\TR4\Trap;$(SolutionDir)TR5Main\Objects\TR4\Object;$(SolutionDir)TR5Main\Objects\TR4\Floor;$(SolutionDir)TR5Main\Objects\TR4\Switch;$(SolutionDir)TR5Main\Objects\TR4\Vehicles;$(SolutionDir)TR5Main\Objects\TR5;$(SolutionDir)TR5Main\Objects\TR5\Entity;$(SolutionDir)TR5Main\Objects\TR5\Trap;$(SolutionDir)TR5Main\Objects\TR5\Light;$(SolutionDir)TR5Main\Objects\TR5\Emitter;$(SolutionDir)TR5Main\Objects\TR5\Shatter;$(SolutionDir)TR5Main\Objects\TR5\Switch;$(SolutionDir)TR5Main\Objects\TR5\Object;$(SolutionDir)TR5Main\Objects\Vehicles;$(SolutionDir)TR5Main\Renderer;$(SolutionDir)TR5Main\Scripting;$(SolutionDir)TR5Main\Specific;$(SolutionDir)TR5Main\Specific\IO;%(AdditionalIncludeDirectories) MultiThreadedDebugDLL @@ -95,7 +95,7 @@ xcopy /Y "$(ProjectDir)Shaders\HUD\*.hlsl" "$(TargetDir)\Shaders\HUD\" Use TurnOffAllWarnings false - _CRT_SECURE_NO_WARNINGS;WIN32;TR5MAIN_EXPORTS;_WINDOWS;_USRDLL;NOMINMAX;NEW_INV;%(PreprocessorDefinitions) + _CRT_SECURE_NO_WARNINGS;WIN32;TR5MAIN_EXPORTS;_WINDOWS;_USRDLL;NOMINMAX;NEW_INV;CREATURE_AI_PRIORITY_OPTIMIZATION;%(PreprocessorDefinitions) false $(SolutionDir)TR5Main;$(SolutionDir)TR5Main\Game;$(SolutionDir)TR5Main\Game\Lara;$(SolutionDir)TR5Main\Objects;$(SolutionDir)TR5Main\Objects\Utils;$(SolutionDir)TR5Main\Objects\Effects;$(SolutionDir)TR5Main\Objects\Generic;$(SolutionDir)TR5Main\Objects\Generic\Switches;$(SolutionDir)TR5Main\Objects\Generic\Object;$(SolutionDir)TR5Main\Objects\TR1;$(SolutionDir)TR5Main\Objects\TR1\Entity;$(SolutionDir)TR5Main\Objects\TR1\Trap;$(SolutionDir)TR5Main\Objects\TR2;$(SolutionDir)TR5Main\Objects\TR2\Entity;$(SolutionDir)TR5Main\Objects\TR2\Trap;$(SolutionDir)TR5Main\Objects\TR2\Vehicles;$(SolutionDir)TR5Main\Objects\TR3;$(SolutionDir)TR5Main\Objects\TR3\Entity;$(SolutionDir)TR5Main\Objects\TR3\Trap;$(SolutionDir)TR5Main\Objects\TR3\Vehicles;$(SolutionDir)TR5Main\Objects\TR4;$(SolutionDir)TR5Main\Objects\TR4\Entity;$(SolutionDir)TR5Main\Objects\TR4\Trap;$(SolutionDir)TR5Main\Objects\TR4\Object;$(SolutionDir)TR5Main\Objects\TR4\Floor;$(SolutionDir)TR5Main\Objects\TR4\Switch;$(SolutionDir)TR5Main\Objects\TR4\Vehicles;$(SolutionDir)TR5Main\Objects\TR5;$(SolutionDir)TR5Main\Objects\TR5\Entity;$(SolutionDir)TR5Main\Objects\TR5\Trap;$(SolutionDir)TR5Main\Objects\TR5\Light;$(SolutionDir)TR5Main\Objects\TR5\Emitter;$(SolutionDir)TR5Main\Objects\TR5\Shatter;$(SolutionDir)TR5Main\Objects\TR5\Switch;$(SolutionDir)TR5Main\Objects\TR5\Object;$(SolutionDir)TR5Main\Objects\Vehicles;$(SolutionDir)TR5Main\Renderer;$(SolutionDir)TR5Main\Scripting;$(SolutionDir)TR5Main\Specific;$(SolutionDir)TR5Main\Specific\IO;%(AdditionalIncludeDirectories) MultiThreadedDLL diff --git a/TR5Main/TombEngine.vcxproj.filters b/TR5Main/TombEngine.vcxproj.filters index 777517b7d..74eabd8cb 100644 --- a/TR5Main/TombEngine.vcxproj.filters +++ b/TR5Main/TombEngine.vcxproj.filters @@ -780,9 +780,6 @@ File di intestazione - - File di intestazione - File di intestazione @@ -1086,6 +1083,63 @@ File di intestazione + + File di intestazione + + + File di intestazione + + + File di intestazione + + + File di intestazione + + + File di intestazione + + + File di intestazione + + + File di intestazione + + + File di intestazione + + + File di intestazione + + + File di intestazione + + + File di intestazione + + + File di intestazione + + + File di intestazione + + + File di intestazione + + + File di intestazione + + + File di intestazione + + + File di intestazione + + + File di intestazione + + + File di intestazione + @@ -1736,9 +1790,6 @@ File di origine - - File di origine - File di origine @@ -1997,6 +2048,9 @@ File di origine + + File di origine +