mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2026-04-28 04:51:42 +00:00
k_hud_track.cpp: refactor to use C++ STL
- Use std::vector instead of fixed size array. - Use std::sort instead of custom sorting algorithm.
This commit is contained in:
parent
13762ee4e1
commit
e79ff76758
3 changed files with 19 additions and 62 deletions
|
|
@ -832,7 +832,7 @@ INT32 POSI2_X, POSI2_Y;
|
||||||
INT32 TCOOL_X, TCOOL_Y;
|
INT32 TCOOL_X, TCOOL_Y;
|
||||||
|
|
||||||
// This version of the function was prototyped in Lua by Nev3r ... a HUGE thank you goes out to them!
|
// This version of the function was prototyped in Lua by Nev3r ... a HUGE thank you goes out to them!
|
||||||
void K_ObjectTracking(trackingResult_t *result, vector3_t *point, boolean reverse)
|
void K_ObjectTracking(trackingResult_t *result, const vector3_t *point, boolean reverse)
|
||||||
{
|
{
|
||||||
#define NEWTAN(x) FINETANGENT(((x + ANGLE_90) >> ANGLETOFINESHIFT) & 4095) // tan function used by Lua
|
#define NEWTAN(x) FINETANGENT(((x + ANGLE_90) >> ANGLETOFINESHIFT) & 4095) // tan function used by Lua
|
||||||
#define NEWCOS(x) FINECOSINE((x >> ANGLETOFINESHIFT) & FINEMASK)
|
#define NEWCOS(x) FINECOSINE((x >> ANGLETOFINESHIFT) & FINEMASK)
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ struct trackingResult_t
|
||||||
fixed_t fov;
|
fixed_t fov;
|
||||||
};
|
};
|
||||||
|
|
||||||
void K_ObjectTracking(trackingResult_t *result, vector3_t *point, boolean reverse);
|
void K_ObjectTracking(trackingResult_t *result, const vector3_t *point, boolean reverse);
|
||||||
|
|
||||||
const char *K_GetItemPatch(UINT8 item, boolean tiny);
|
const char *K_GetItemPatch(UINT8 item, boolean tiny);
|
||||||
void K_LoadKartHUDGraphics(void);
|
void K_LoadKartHUDGraphics(void);
|
||||||
|
|
|
||||||
|
|
@ -1,5 +1,6 @@
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cstddef>
|
#include <cstddef>
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
#include "k_hud.h"
|
#include "k_hud.h"
|
||||||
#include "m_fixed.h"
|
#include "m_fixed.h"
|
||||||
|
|
@ -19,12 +20,12 @@ struct TargetTracking
|
||||||
fixed_t camDist;
|
fixed_t camDist;
|
||||||
};
|
};
|
||||||
|
|
||||||
void K_DrawTargetTracking(TargetTracking* target)
|
void K_DrawTargetTracking(const TargetTracking& target)
|
||||||
{
|
{
|
||||||
trackingResult_t result = {};
|
trackingResult_t result = {};
|
||||||
int32_t timer = 0;
|
int32_t timer = 0;
|
||||||
|
|
||||||
K_ObjectTracking(&result, &target->point, false);
|
K_ObjectTracking(&result, &target.point, false);
|
||||||
|
|
||||||
if (result.onScreen == false)
|
if (result.onScreen == false)
|
||||||
{
|
{
|
||||||
|
|
@ -72,7 +73,7 @@ void K_DrawTargetTracking(TargetTracking* target)
|
||||||
borderWin.y = screenSize.y - borderSize;
|
borderWin.y = screenSize.y - borderSize;
|
||||||
|
|
||||||
arrowDir.x = 0;
|
arrowDir.x = 0;
|
||||||
arrowDir.y = P_MobjFlip(target->mobj) * FRACUNIT;
|
arrowDir.y = P_MobjFlip(target.mobj) * FRACUNIT;
|
||||||
|
|
||||||
// Simply pointing towards the result doesn't work, so inaccurate hack...
|
// Simply pointing towards the result doesn't work, so inaccurate hack...
|
||||||
borderDir.x = FixedMul(
|
borderDir.x = FixedMul(
|
||||||
|
|
@ -171,12 +172,12 @@ void K_DrawTargetTracking(TargetTracking* target)
|
||||||
{
|
{
|
||||||
// Draw simple overlay.
|
// Draw simple overlay.
|
||||||
const fixed_t farDistance = 1280 * mapobjectscale;
|
const fixed_t farDistance = 1280 * mapobjectscale;
|
||||||
bool useNear = (target->camDist < farDistance);
|
bool useNear = (target.camDist < farDistance);
|
||||||
|
|
||||||
patch_t* targetPatch = nullptr;
|
patch_t* targetPatch = nullptr;
|
||||||
vector2_t targetPos = {};
|
vector2_t targetPos = {};
|
||||||
|
|
||||||
bool visible = P_CheckSight(stplyr->mo, target->mobj);
|
bool visible = P_CheckSight(stplyr->mo, target.mobj);
|
||||||
|
|
||||||
if (visible == false && (leveltime & 1))
|
if (visible == false && (leveltime & 1))
|
||||||
{
|
{
|
||||||
|
|
@ -209,20 +210,13 @@ void K_DrawTargetTracking(TargetTracking* target)
|
||||||
|
|
||||||
void K_drawTargetHUD(const vector3_t* origin, player_t* player)
|
void K_drawTargetHUD(const vector3_t* origin, player_t* player)
|
||||||
{
|
{
|
||||||
constexpr std::size_t kMaxTargetHUD = 32;
|
std::vector<TargetTracking> targetList;
|
||||||
|
|
||||||
std::size_t i, j;
|
|
||||||
|
|
||||||
TargetTracking targetList[kMaxTargetHUD];
|
|
||||||
std::size_t targetListLen = 0;
|
|
||||||
|
|
||||||
mobj_t* mobj = nullptr;
|
mobj_t* mobj = nullptr;
|
||||||
mobj_t* next = nullptr;
|
mobj_t* next = nullptr;
|
||||||
|
|
||||||
for (mobj = trackercap; mobj; mobj = next)
|
for (mobj = trackercap; mobj; mobj = next)
|
||||||
{
|
{
|
||||||
TargetTracking* target = nullptr;
|
|
||||||
|
|
||||||
next = mobj->itnext;
|
next = mobj->itnext;
|
||||||
|
|
||||||
if (mobj->health <= 0)
|
if (mobj->health <= 0)
|
||||||
|
|
@ -235,55 +229,18 @@ void K_drawTargetHUD(const vector3_t* origin, player_t* player)
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
target = &targetList[targetListLen];
|
vector3_t pos = {
|
||||||
|
R_InterpolateFixed(mobj->old_x, mobj->x),
|
||||||
|
R_InterpolateFixed(mobj->old_y, mobj->y),
|
||||||
|
R_InterpolateFixed(mobj->old_z, mobj->z) + (mobj->height >> 1),
|
||||||
|
};
|
||||||
|
|
||||||
target->mobj = mobj;
|
targetList.push_back({mobj, pos, R_PointToDist2(origin->x, origin->y, pos.x, pos.y)});
|
||||||
target->point.x = R_InterpolateFixed(mobj->old_x, mobj->x);
|
|
||||||
target->point.y = R_InterpolateFixed(mobj->old_y, mobj->y);
|
|
||||||
target->point.z = R_InterpolateFixed(mobj->old_z, mobj->z);
|
|
||||||
target->point.z += (mobj->height >> 1);
|
|
||||||
target->camDist = R_PointToDist2(origin->x, origin->y, target->point.x, target->point.y);
|
|
||||||
|
|
||||||
targetListLen++;
|
|
||||||
|
|
||||||
if (targetListLen >= kMaxTargetHUD)
|
|
||||||
{
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (targetListLen > 0)
|
// Sort by distance from camera. Further trackers get
|
||||||
{
|
// drawn first so nearer ones draw over them.
|
||||||
// Sort by distance from camera.
|
std::sort(targetList.begin(), targetList.end(), [](const auto& a, const auto& b) { return a.camDist > b.camDist; });
|
||||||
if (targetListLen > 1)
|
|
||||||
{
|
|
||||||
for (i = 0; i < targetListLen - 1; i++)
|
|
||||||
{
|
|
||||||
std::size_t swap = i;
|
|
||||||
|
|
||||||
for (j = i + 1; j < targetListLen; j++)
|
std::for_each(targetList.cbegin(), targetList.cend(), K_DrawTargetTracking);
|
||||||
{
|
|
||||||
TargetTracking* cj = &targetList[j];
|
|
||||||
TargetTracking* cSwap = &targetList[swap];
|
|
||||||
|
|
||||||
if (cj->camDist > cSwap->camDist)
|
|
||||||
{
|
|
||||||
swap = j;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (swap != i)
|
|
||||||
{
|
|
||||||
TargetTracking temp = targetList[swap];
|
|
||||||
targetList[swap] = targetList[i];
|
|
||||||
targetList[i] = temp;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
for (i = 0; i < targetListLen; i++)
|
|
||||||
{
|
|
||||||
K_DrawTargetTracking(&targetList[i]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue