mirror of
https://github.com/TombEngine/TombEngine.git
synced 2025-04-30 08:47:58 +03:00
Update object ID enum; minor target highlighter cleanup
This commit is contained in:
parent
ee0baafd0f
commit
ffa5627834
3 changed files with 35 additions and 45 deletions
|
@ -15,11 +15,11 @@ namespace TEN::Hud
|
||||||
{
|
{
|
||||||
static float GetCrosshairSize(float dist)
|
static float GetCrosshairSize(float dist)
|
||||||
{
|
{
|
||||||
constexpr auto RANGE = BLOCK(10);
|
constexpr auto DIST_RANGE = BLOCK(10);
|
||||||
constexpr auto CROSSHAIR_SIZE_MAX = SCREEN_SPACE_RES.y * 0.25f;
|
constexpr auto CROSSHAIR_SIZE_MAX = SCREEN_SPACE_RES.y * 0.25f;
|
||||||
constexpr auto CROSSHAIR_SIZE_MIN = CROSSHAIR_SIZE_MAX / 5;
|
constexpr auto CROSSHAIR_SIZE_MIN = CROSSHAIR_SIZE_MAX / 5;
|
||||||
|
|
||||||
auto distAlpha = dist / RANGE;
|
auto distAlpha = dist / DIST_RANGE;
|
||||||
return Lerp(CROSSHAIR_SIZE_MAX, CROSSHAIR_SIZE_MIN, distAlpha);
|
return Lerp(CROSSHAIR_SIZE_MAX, CROSSHAIR_SIZE_MIN, distAlpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -91,12 +91,11 @@ namespace TEN::Hud
|
||||||
// Set crosshairs as primary.
|
// Set crosshairs as primary.
|
||||||
for (int entityID : entityIds)
|
for (int entityID : entityIds)
|
||||||
{
|
{
|
||||||
// Matching crosshair; continue.
|
// No crosshair at entity ID key; continue.
|
||||||
if (!Crosshairs.count(entityID))
|
if (!Crosshairs.count(entityID))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
auto& crosshair = Crosshairs.at(entityID);
|
auto& crosshair = Crosshairs.at(entityID);
|
||||||
|
|
||||||
crosshair.IsPrimary = true;
|
crosshair.IsPrimary = true;
|
||||||
crosshair.ColorTarget = CrosshairData::COLOR_GREEN;
|
crosshair.ColorTarget = CrosshairData::COLOR_GREEN;
|
||||||
}
|
}
|
||||||
|
@ -116,12 +115,11 @@ namespace TEN::Hud
|
||||||
// Set crosshairs as peripheral.
|
// Set crosshairs as peripheral.
|
||||||
for (int entityID : entityIds)
|
for (int entityID : entityIds)
|
||||||
{
|
{
|
||||||
// Matching crosshair; continue.
|
// No crosshair at entity ID key; continue.
|
||||||
if (!Crosshairs.count(entityID))
|
if (!Crosshairs.count(entityID))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
auto& crosshair = Crosshairs.at(entityID);
|
auto& crosshair = Crosshairs.at(entityID);
|
||||||
|
|
||||||
crosshair.IsPrimary = false;
|
crosshair.IsPrimary = false;
|
||||||
crosshair.ColorTarget = CrosshairData::COLOR_GRAY;
|
crosshair.ColorTarget = CrosshairData::COLOR_GRAY;
|
||||||
}
|
}
|
||||||
|
@ -134,6 +132,8 @@ namespace TEN::Hud
|
||||||
|
|
||||||
void TargetHighlighterController::Update(std::vector<int> entityIds)
|
void TargetHighlighterController::Update(std::vector<int> entityIds)
|
||||||
{
|
{
|
||||||
|
constexpr auto TARGET_BONE_ID = 0;
|
||||||
|
|
||||||
// No crosshairs to update; return early.
|
// No crosshairs to update; return early.
|
||||||
if (Crosshairs.empty() && entityIds.empty())
|
if (Crosshairs.empty() && entityIds.empty())
|
||||||
return;
|
return;
|
||||||
|
@ -142,9 +142,9 @@ namespace TEN::Hud
|
||||||
for (int entityID : entityIds)
|
for (int entityID : entityIds)
|
||||||
{
|
{
|
||||||
const auto& item = g_Level.Items[entityID];
|
const auto& item = g_Level.Items[entityID];
|
||||||
auto pos = GetJointPosition(item, 0).ToVector3();
|
auto pos = GetJointPosition(item, TARGET_BONE_ID).ToVector3();
|
||||||
|
|
||||||
// Find crosshair.
|
// Find crosshair at entity ID key.
|
||||||
auto it = Crosshairs.find(entityID);
|
auto it = Crosshairs.find(entityID);
|
||||||
|
|
||||||
// Update existing active crosshair.
|
// Update existing active crosshair.
|
||||||
|
@ -156,14 +156,14 @@ namespace TEN::Hud
|
||||||
// Add new active crosshair.
|
// Add new active crosshair.
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
AddTargetHighlight(entityID, pos);
|
AddCrosshair(entityID, pos);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update inactive crosshairs.
|
// Update inactive crosshairs.
|
||||||
for (auto& [entityID, crosshair] : Crosshairs)
|
for (auto& [entityID, crosshair] : Crosshairs)
|
||||||
{
|
{
|
||||||
// Find absent crosshairs.
|
// Find crosshairs at absent entity ID keys.
|
||||||
auto it = std::find(entityIds.begin(), entityIds.end(), entityID);
|
auto it = std::find(entityIds.begin(), entityIds.end(), entityID);
|
||||||
if (it != entityIds.end())
|
if (it != entityIds.end())
|
||||||
continue;
|
continue;
|
||||||
|
@ -176,14 +176,22 @@ namespace TEN::Hud
|
||||||
crosshair.Update(pos, false);
|
crosshair.Update(pos, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
ClearInactiveTargetHighlights();
|
ClearInactiveCrosshairs();
|
||||||
}
|
}
|
||||||
|
|
||||||
void TargetHighlighterController::Update(const ItemInfo& playerItem)
|
void TargetHighlighterController::Update(const ItemInfo& playerItem)
|
||||||
{
|
{
|
||||||
const auto& player = GetLaraInfo(playerItem);
|
const auto& player = GetLaraInfo(playerItem);
|
||||||
|
|
||||||
auto entityIds = GetTargetEntityIds(playerItem);
|
// Get target entity IDs.
|
||||||
|
auto entityIds = std::vector<int>{};
|
||||||
|
for (const auto* targetPtr : player.TargetList)
|
||||||
|
{
|
||||||
|
if (targetPtr == nullptr)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
entityIds.push_back((int)targetPtr->Index);
|
||||||
|
}
|
||||||
|
|
||||||
// Determine peripheral entity IDs.
|
// Determine peripheral entity IDs.
|
||||||
auto peripheralEntityIds = entityIds;
|
auto peripheralEntityIds = entityIds;
|
||||||
|
@ -219,55 +227,36 @@ namespace TEN::Hud
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
g_Renderer.DrawSpriteIn2DSpace(
|
g_Renderer.DrawSpriteIn2DSpace(
|
||||||
(GAME_OBJECT_ID)1380, 0,
|
ID_CROSSHAIR_SEGMENT, 0,
|
||||||
crosshair.Position2D, crosshair.Orientation2D, crosshair.Color, Vector2(crosshair.Size));
|
crosshair.Position2D, crosshair.Orientation2D, crosshair.Color, Vector2(crosshair.Size));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void TargetHighlighterController::Clear()
|
void TargetHighlighterController::Clear()
|
||||||
{
|
{
|
||||||
Crosshairs.clear();
|
*this = {};
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<int> TargetHighlighterController::GetTargetEntityIds(const ItemInfo& playerItem)
|
CrosshairData& TargetHighlighterController::GetNewCrosshair(int entityID)
|
||||||
{
|
|
||||||
if (!playerItem.IsLara())
|
|
||||||
return {};
|
|
||||||
|
|
||||||
auto& player = GetLaraInfo(playerItem);
|
|
||||||
|
|
||||||
auto entityIds = std::vector<int>{};
|
|
||||||
for (const auto* targetPtr : player.TargetList)
|
|
||||||
{
|
|
||||||
if (targetPtr == nullptr)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
entityIds.push_back((int)targetPtr->Index);
|
|
||||||
}
|
|
||||||
|
|
||||||
return entityIds;
|
|
||||||
}
|
|
||||||
|
|
||||||
CrosshairData& TargetHighlighterController::GetNewTargetHighlight(int entityID)
|
|
||||||
{
|
{
|
||||||
constexpr auto COUNT_MAX = 16;
|
constexpr auto COUNT_MAX = 16;
|
||||||
|
|
||||||
// Clear smallest crosshair if map is full.
|
// Clear smallest crosshair if map is full.
|
||||||
if (Crosshairs.size() >= COUNT_MAX)
|
if (Crosshairs.size() >= COUNT_MAX)
|
||||||
{
|
{
|
||||||
int key = 0;
|
int entityIDKey = 0;
|
||||||
float smallestSize = INFINITY;
|
float smallestSize = INFINITY;
|
||||||
|
|
||||||
for (auto& [entityID, crosshair] : Crosshairs)
|
for (auto& [entityID, crosshair] : Crosshairs)
|
||||||
{
|
{
|
||||||
if (crosshair.Size < smallestSize)
|
if (crosshair.Size < smallestSize)
|
||||||
{
|
{
|
||||||
key = entityID;
|
entityIDKey = entityID;
|
||||||
smallestSize = crosshair.Size;
|
smallestSize = crosshair.Size;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Crosshairs.erase(key);
|
Crosshairs.erase(entityIDKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Return new crosshair.
|
// Return new crosshair.
|
||||||
|
@ -277,7 +266,7 @@ namespace TEN::Hud
|
||||||
return crosshair;
|
return crosshair;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TargetHighlighterController::AddTargetHighlight(int entityID, const Vector3& pos)
|
void TargetHighlighterController::AddCrosshair(int entityID, const Vector3& pos)
|
||||||
{
|
{
|
||||||
constexpr auto SIZE_DEFAULT = SCREEN_SPACE_RES.x / 2;
|
constexpr auto SIZE_DEFAULT = SCREEN_SPACE_RES.x / 2;
|
||||||
|
|
||||||
|
@ -286,7 +275,7 @@ namespace TEN::Hud
|
||||||
return;
|
return;
|
||||||
|
|
||||||
// Create new crosshair.
|
// Create new crosshair.
|
||||||
auto& crosshair = GetNewTargetHighlight(entityID);
|
auto& crosshair = GetNewCrosshair(entityID);
|
||||||
|
|
||||||
crosshair.IsActive = true;
|
crosshair.IsActive = true;
|
||||||
crosshair.IsPrimary = false;
|
crosshair.IsPrimary = false;
|
||||||
|
@ -300,7 +289,7 @@ namespace TEN::Hud
|
||||||
crosshair.RadiusScalarTarget = 0.0f;
|
crosshair.RadiusScalarTarget = 0.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TargetHighlighterController::ClearInactiveTargetHighlights()
|
void TargetHighlighterController::ClearInactiveCrosshairs()
|
||||||
{
|
{
|
||||||
for (auto it = Crosshairs.begin(); it != Crosshairs.end();)
|
for (auto it = Crosshairs.begin(); it != Crosshairs.end();)
|
||||||
{
|
{
|
||||||
|
@ -324,7 +313,7 @@ namespace TEN::Hud
|
||||||
for (const auto& [entityID, crosshair] : Crosshairs)
|
for (const auto& [entityID, crosshair] : Crosshairs)
|
||||||
crosshair.IsPrimary ? primaryCount++ : peripheralCount++;
|
crosshair.IsPrimary ? primaryCount++ : peripheralCount++;
|
||||||
|
|
||||||
g_Renderer.PrintDebugMessage("Highlights: %d", Crosshairs.size());
|
g_Renderer.PrintDebugMessage("Crosshairs: %d", Crosshairs.size());
|
||||||
g_Renderer.PrintDebugMessage("Primary crosshairs: %d", primaryCount);
|
g_Renderer.PrintDebugMessage("Primary crosshairs: %d", primaryCount);
|
||||||
g_Renderer.PrintDebugMessage("Peripheral crosshairs: %d", peripheralCount);
|
g_Renderer.PrintDebugMessage("Peripheral crosshairs: %d", peripheralCount);
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,10 +59,9 @@ namespace TEN::Hud
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Helpers
|
// Helpers
|
||||||
std::vector<int> GetTargetEntityIds(const ItemInfo& playerItem);
|
CrosshairData& GetNewCrosshair(int entityID);
|
||||||
CrosshairData& GetNewTargetHighlight(int entityID);
|
void AddCrosshair(int entityID, const Vector3& pos);
|
||||||
void AddTargetHighlight(int entityID, const Vector3& pos);
|
void ClearInactiveCrosshairs();
|
||||||
void ClearInactiveTargetHighlights();
|
|
||||||
|
|
||||||
void DrawDebug() const;
|
void DrawDebug() const;
|
||||||
};
|
};
|
||||||
|
|
|
@ -990,6 +990,8 @@ enum GAME_OBJECT_ID : short
|
||||||
ID_AIR_BAR_TEXTURE,
|
ID_AIR_BAR_TEXTURE,
|
||||||
ID_DASH_BAR_TEXTURE,
|
ID_DASH_BAR_TEXTURE,
|
||||||
ID_SFX_BAR_TEXTURE,
|
ID_SFX_BAR_TEXTURE,
|
||||||
|
// NOTE: 1378 - 1379 reserved for blood effects. -- Sezz 2023.05.29
|
||||||
|
ID_CROSSHAIR_SEGMENT = 1380,
|
||||||
|
|
||||||
ID_PANEL_BORDER = 1400,
|
ID_PANEL_BORDER = 1400,
|
||||||
ID_PANEL_MIDDLE,
|
ID_PANEL_MIDDLE,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue