Skip to content

Commit

Permalink
Bug fixes from master:
Browse files Browse the repository at this point in the history
Demangled and simplified cheat controller.
TKickout temp Z in FT mode.
Flipper animation frame advance.
Fuel bar graph light states.
  • Loading branch information
k4zmu2a committed Oct 9, 2021
1 parent b995b02 commit de76557
Show file tree
Hide file tree
Showing 16 changed files with 144 additions and 305 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ bld/
[Bb]in/
[Oo]bj/
[Ll]og/
ARM/
ARM64/
win32/

# Visual Studio 2015 cache/options directory
.vs/
Expand Down
90 changes: 41 additions & 49 deletions SpaceCadetPinball/TFlipper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ TFlipper::TFlipper(TPinballTable* table, int groupIndex) : TCollisionComponent(t
Smoothness = visual.Smoothness;

auto collMult = *loader::query_float_attribute(groupIndex, 0, 803);
auto bmpCoef2 = *loader::query_float_attribute(groupIndex, 0, 805);
auto bmpCoef1 = *loader::query_float_attribute(groupIndex, 0, 804);
auto retractTime = *loader::query_float_attribute(groupIndex, 0, 805);
auto extendTime = *loader::query_float_attribute(groupIndex, 0, 804);

/*Full tilt hack: different flipper speed*/
if (pb::FullTiltMode)
{
bmpCoef2 = 0.08f;
bmpCoef1 = 0.04f;
retractTime = 0.08f;
extendTime = 0.04f;
}
auto vecT2 = reinterpret_cast<vector_type*>(loader::query_float_attribute(groupIndex, 0, 802));
auto vecT1 = reinterpret_cast<vector_type*>(loader::query_float_attribute(groupIndex, 0, 801));
Expand All @@ -42,17 +42,17 @@ TFlipper::TFlipper(TPinballTable* table, int groupIndex) : TCollisionComponent(t
origin,
vecT1,
vecT2,
bmpCoef1,
bmpCoef2,
extendTime,
retractTime,
collMult,
Elasticity,
Smoothness);

FlipperEdge = flipperEdge;
if (flipperEdge)
{
BmpCoef1 = flipperEdge->BmpCoef1 / static_cast<float>(ListBitmap->GetCount() - 1);
BmpCoef2 = flipperEdge->BmpCoef2 / static_cast<float>(ListBitmap->GetCount() - 1);
ExtendAnimationFrameTime = flipperEdge->ExtendTime / static_cast<float>(ListBitmap->GetCount() - 1);
RetractAnimationFrameTime = flipperEdge->RetractTime / static_cast<float>(ListBitmap->GetCount() - 1);
}
BmpIndex = 0;
InputTime = 0.0;
Expand All @@ -68,46 +68,44 @@ int TFlipper::Message(int code, float value)
if (code == 1 || code == 2 || code > 1008 && code <= 1011 || code == 1022)
{
float timerTime;
int soundIndex = 0, code2 = code;
int command = code;
if (code == 1)
{
control::handler(1, this);
TimerTime = BmpCoef1;
soundIndex = HardHitSoundId;
TimerTime = ExtendAnimationFrameTime;
loader::play_sound(HardHitSoundId);
}
else if (code == 2)
{
TimerTime = BmpCoef2;
soundIndex = SoftHitSoundId;
TimerTime = RetractAnimationFrameTime;
loader::play_sound(SoftHitSoundId);
}
else
{
code2 = 2;
TimerTime = BmpCoef2;
// Retract for all non-input messages
command = 2;
TimerTime = RetractAnimationFrameTime;
}

if (soundIndex)
loader::play_sound(soundIndex);
if (Timer)
{
timer::kill(Timer);
Timer = 0;
}
if (MessageField)
{
auto v10 = value - FlipperEdge->InputTime;
timerTime = v10 - floor(v10 / TimerTime) * TimerTime;
// Message arrived before animation is finished
auto inputDt = value - FlipperEdge->InputTime;
timerTime = inputDt - floor(inputDt / TimerTime) * TimerTime;
if (timerTime < 0.0f)
timerTime = 0.0;
}
else
{
timerTime = TimerTime;
}
MessageField = code2;

MessageField = command;
InputTime = value;
if (Timer)
timer::kill(Timer);
Timer = timer::set(timerTime, this, TimerExpired);
FlipperEdge->SetMotion(code2, value);
FlipperEdge->SetMotion(command, value);
}

if (code == 1020 || code == 1024)
Expand Down Expand Up @@ -137,49 +135,43 @@ void TFlipper::Collision(TBall* ball, vector_type* nextPosition, vector_type* di
void TFlipper::TimerExpired(int timerId, void* caller)
{
auto flip = static_cast<TFlipper*>(caller);
int timer; // eax

bool bmpIndexOutOfBounds = false;
auto bmpIndexAdvance = static_cast<int>(floor((pb::time_now - flip->InputTime) / flip->TimerTime + 0.5f));
int bmpCount = flip->ListBitmap->GetCount();
if (bmpIndexAdvance > bmpCount)
bmpIndexAdvance = bmpCount;
if (bmpIndexAdvance < 0)
bmpIndexAdvance = 0;
int bmpCountSub1 = flip->ListBitmap->GetCount() - 1;

if (!bmpIndexAdvance)
bmpIndexAdvance = 1;
auto newBmpIndex = static_cast<int>(floor((pb::time_now - flip->InputTime) / flip->TimerTime));
if (newBmpIndex > bmpCountSub1)
newBmpIndex = bmpCountSub1;
if (newBmpIndex < 0)
newBmpIndex = 0;

bool bmpIndexOutOfBounds = false;
if (flip->MessageField == 1)
{
flip->BmpIndex += bmpIndexAdvance;
int countSub1 = flip->ListBitmap->GetCount() - 1;
if (flip->BmpIndex >= countSub1)
flip->BmpIndex = newBmpIndex;
if (flip->BmpIndex >= bmpCountSub1)
{
flip->BmpIndex = countSub1;
flip->BmpIndex = bmpCountSub1;
bmpIndexOutOfBounds = true;
}
}
if (flip->MessageField == 2)
{
flip->BmpIndex -= bmpIndexAdvance;
timer = 0;
flip->BmpIndex = bmpCountSub1 - newBmpIndex;
if (flip->BmpIndex <= 0)
{
flip->BmpIndex = 0;
bmpIndexOutOfBounds = true;
}
}
else
{
timer = 0;
}

if (bmpIndexOutOfBounds)
{
flip->MessageField = 0;
flip->Timer = 0;
}
else
timer = timer::set(flip->TimerTime, flip, TimerExpired);
flip->Timer = timer;
{
flip->Timer = timer::set(flip->TimerTime, flip, TimerExpired);
}

auto bmp = flip->ListBitmap->Get(flip->BmpIndex);
auto zMap = flip->ListZMap->Get(flip->BmpIndex);
Expand Down
4 changes: 2 additions & 2 deletions SpaceCadetPinball/TFlipper.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ class TFlipper :
int BmpIndex;
TFlipperEdge* FlipperEdge;
int Timer;
float BmpCoef1;
float BmpCoef2;
float ExtendAnimationFrameTime;
float RetractAnimationFrameTime;
float TimerTime;
float InputTime;
};
14 changes: 7 additions & 7 deletions SpaceCadetPinball/TFlipperEdge.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ line_type TFlipperEdge::lineA, TFlipperEdge::lineB;
circle_type TFlipperEdge::circlebase, TFlipperEdge::circleT1;

TFlipperEdge::TFlipperEdge(TCollisionComponent* collComp, char* activeFlag, unsigned int collisionGroup, TPinballTable* table,
vector_type* origin, vector_type* vecT1, vector_type* vecT2, float bmpCoef1, float bmpCoef2,
vector_type* origin, vector_type* vecT1, vector_type* vecT2, float extendTime, float retractTime,
float collMult, float elasticity, float smoothness): TEdgeSegment(collComp, activeFlag, collisionGroup)
{
vector_type crossProd{}, vecDir1{}, vecDir2{};

Elasticity = elasticity;
Smoothness = smoothness;
BmpCoef1 = bmpCoef1;
BmpCoef2 = bmpCoef2;
ExtendTime = extendTime;
RetractTime = retractTime;
CollisionMult = collMult;

T1Src = *vecT1;
Expand Down Expand Up @@ -78,9 +78,9 @@ TFlipperEdge::TFlipperEdge(TCollisionComponent* collComp, char* activeFlag, unsi
auto distance1 = sqrt(dy * dy + dx * dx) + table->CollisionCompOffset + vecT1->Z;
DistanceDivSq = distance1 * distance1;

float bmpCoef = min(BmpCoef1, BmpCoef2);
float minMoveTime = min(ExtendTime, RetractTime);
auto distance = maths::Distance(vecT1, vecT2);
CollisionTimeAdvance = bmpCoef / (distance / CircleT1Radius + distance / CircleT1Radius);
CollisionTimeAdvance = minMoveTime / (distance / CircleT1Radius + distance / CircleT1Radius);

TFlipperEdge::place_in_grid();
EdgeCollisionFlag = 0;
Expand Down Expand Up @@ -469,12 +469,12 @@ void TFlipperEdge::SetMotion(int code, float value)
case 1:
Angle2 = flipper_angle(value);
Angle1 = AngleMax;
AngleMult = BmpCoef1;
AngleMult = ExtendTime;
break;
case 2:
Angle2 = flipper_angle(value);
Angle1 = 0.0;
AngleMult = BmpCoef2;
AngleMult = RetractTime;
break;
case 1024:
FlipperFlag = 0;
Expand Down
6 changes: 3 additions & 3 deletions SpaceCadetPinball/TFlipperEdge.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class TFlipperEdge : public TEdgeSegment
{
public:
TFlipperEdge(TCollisionComponent* collComp, char* activeFlag, unsigned int collisionGroup, TPinballTable* table,
vector_type* origin, vector_type* vecT1, vector_type* vecT2, float bmpCoef1, float bmpCoef2, float collMult,
vector_type* origin, vector_type* vecT1, vector_type* vecT2, float extendTime, float retractTime, float collMult,
float elasticity, float smoothness);
void port_draw() override;
float FindCollisionDistance(ray_type* ray) override;
Expand Down Expand Up @@ -50,8 +50,8 @@ class TFlipperEdge : public TEdgeSegment
float InputTime;
float AngleStopTime;
float AngleMult;
float BmpCoef1;
float BmpCoef2;
float ExtendTime;
float RetractTime;
vector_type NextBallPosition;

static float flipper_sin_angle, flipper_cos_angle;
Expand Down
4 changes: 3 additions & 1 deletion SpaceCadetPinball/TKickout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "control.h"
#include "loader.h"
#include "objlist_class.h"
#include "pb.h"
#include "TBall.h"
#include "TCircle.h"
#include "timer.h"
Expand Down Expand Up @@ -44,7 +45,8 @@ TKickout::TKickout(TPinballTable* table, int groupIndex, bool someFlag): TCollis
}

Circle.RadiusSq = visual.FloatArr[2] * visual.FloatArr[2];
CollisionBallSetZ = loader::query_float_attribute(groupIndex, 0, 408)[2];
auto zAttr = loader::query_float_attribute(groupIndex, 0, 408);
CollisionBallSetZ = pb::FullTiltMode ? zAttr[3] : zAttr[2];
ThrowSpeedMult2 = visual.Kicker.ThrowBallMult * 0.01f;
BallAcceleration = visual.Kicker.ThrowBallAcceleration;
ThrowAngleMult = visual.Kicker.ThrowBallAngleMult;
Expand Down
5 changes: 2 additions & 3 deletions SpaceCadetPinball/TLightBargraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,8 @@ int TLightBargraph::Message(int code, float value)
TLightGroup::Message(45, static_cast<float>(timeIndex / 2));
if (!(timeIndex & 1))
TLightGroup::Message(46, 0.0);
float* timeArray = TimerTimeArray;
if (timeArray)
TimerBargraph = timer::set(timeArray[timeIndex], this, BargraphTimerExpired);
if (TimerTimeArray)
TimerBargraph = timer::set(TimerTimeArray[timeIndex], this, BargraphTimerExpired);
TimeIndex = timeIndex;
}
else
Expand Down
34 changes: 12 additions & 22 deletions SpaceCadetPinball/TLightGroup.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -374,31 +374,21 @@ int TLightGroup::Message(int code, float value)
}
case 45:
{
auto count = List->GetCount();
control::handler(code, this);
auto index = static_cast<int>(floor(value));
if (index >= 0)
if (index >= 0 && index < count)
{
auto count = List->GetCount();
if (index <= count)
// Turn off lights (index, end]
for (auto i = count - 1; i > index; i--)
{
List->Get(i)->Message(20, 0.0);
}

// Turn on lights [begin, index]
for (auto i = index; i >= 0; i--)
{
auto countSub1 = count - 1;
if (countSub1 > index)
{
countSub1 = index;
for (auto i = countSub1, k = countSub1 - index; k != 0; i--, k--)
{
auto light = List->Get(i);
light->Message(20, 0.0);
}
}
if (countSub1 >= 0)
{
for (auto i = countSub1; i != 0; i--)
{
auto light = List->Get(i);
light->Message(19, 0.0);
}
}
List->Get(i)->Message(19, 0.0);
}
}
break;
Expand Down Expand Up @@ -477,7 +467,7 @@ int TLightGroup::next_light_down()
{
for (int index = List->GetCount() - 1; index >= 0; --index)
{
if (!List->Get(index)->BmpIndex1)
if (List->Get(index)->BmpIndex1)
return index;
}
return -1;
Expand Down
2 changes: 1 addition & 1 deletion SpaceCadetPinball/TTextBox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ void TTextBox::Clear()
}
}

void TTextBox::Display(char* text, float time)
void TTextBox::Display(const char* text, float time)
{
if (!text)
return;
Expand Down
2 changes: 1 addition & 1 deletion SpaceCadetPinball/TTextBox.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class TTextBox :
~TTextBox() override;
int Message(int code, float value) override;
void Clear();
void Display(char* text, float time);
void Display(const char* text, float time);
void Draw();

static void TimerExpired(int timerId, void* tb);
Expand Down
2 changes: 1 addition & 1 deletion SpaceCadetPinball/TTextBoxMessage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "memory.h"
#include "pb.h"

TTextBoxMessage::TTextBoxMessage(char* text, float time)
TTextBoxMessage::TTextBoxMessage(const char* text, float time)
{
NextMessage = nullptr;
Time = time;
Expand Down
2 changes: 1 addition & 1 deletion SpaceCadetPinball/TTextBoxMessage.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class TTextBoxMessage
float Time;
int EndTicks;

TTextBoxMessage(char* text, float time);
TTextBoxMessage(const char* text, float time);
~TTextBoxMessage();
float TimeLeft() const;
void Refresh(float time);
Expand Down
Loading

0 comments on commit de76557

Please sign in to comment.