rewrite TargetInspector to directly access memory, and add experimental ShouldVibrate bool

This commit is contained in:
somewhatlurker
2019-08-14 21:46:38 +10:00
parent 226d0d33d9
commit e1fe198376
7 changed files with 61 additions and 30 deletions
@@ -3,6 +3,7 @@
namespace TLAC::Components
{
bool TargetInspector::repressTbl[maxTargetSlots];
bool TargetInspector::ShouldVibrate;
TargetInspector::TargetInspector()
{
@@ -14,15 +15,13 @@ namespace TLAC::Components
void TargetInspector::Initialize(ComponentsManager*)
{
tgtTypePtr = (int*)TGT_TYPE_BASE_ADDRESS;
tgtHitStatePtr = (int*)TGT_HIT_STATE_BASE_ADDRESS;
tgtRemainingTimePtr = (float*)TGT_REMAINING_DURATION_BASE_ADDRESS;
tgtStates = (TargetState*)TGT_STATES_BASE_ADDRESS;
}
void TargetInspector::Update()
{
GetTargetStates();
UpdateRepressTbl();
UpdateShouldVibrate();
}
const char* TargetInspector::GetDisplayName()
@@ -30,16 +29,6 @@ namespace TLAC::Components
return "target_inspector";
}
void TargetInspector::GetTargetStates()
{
for (int i = 0; i < maxTargetSlots; ++i)
{
tgtStates[i].tgtType = *((int*)((char*)tgtTypePtr + (i * offset)));
tgtStates[i].tgtHitState = *((int*)((char*)tgtHitStatePtr + (i * offset)));
tgtStates[i].tgtRemainingTime = *((float*)((char*)tgtRemainingTimePtr + (i * offset)));
}
}
void TargetInspector::UpdateRepressTbl()
{
for (int i = 0; i < maxTargetSlots; ++i)
@@ -50,6 +39,22 @@ namespace TLAC::Components
}
}
void TargetInspector::UpdateShouldVibrate()
{
for (int i = 0; i < maxTargetSlots; ++i)
{
if (IsWithinRange(tgtStates[i].tgtRemainingTime)
&& (tgtStates[i].tgtType == SLIDE_LONG_L || tgtStates[i].tgtType == SLIDE_LONG_R)
&& tgtStates[i].tgtHitState == NONE)
{
//printf("%d\n", tgtStates[i].tgtHitState);
ShouldVibrate = true;
return;
}
}
ShouldVibrate = false;
}
bool TargetInspector::IsWithinRange(float time)
{
return time < timingThreshold && time > -timingThreshold && time != 0;