Code from FT: simplified score access in TPinballComponent.

This commit is contained in:
Muzychenko Andrey 2022-08-18 16:23:29 +03:00
parent e9a4791322
commit 7feba1e947
24 changed files with 13 additions and 170 deletions

View File

@ -109,18 +109,6 @@ void TBumper::Collision(TBall* ball, vector2* nextPosition, vector2* direction,
} }
} }
void TBumper::put_scoring(int index, int score)
{
if (index < 4)
Scores[index] = score;
}
int TBumper::get_scoring(int index)
{
return index < 4 ? Scores[index] : 0;
}
void TBumper::TimerExpired(int timerId, void* caller) void TBumper::TimerExpired(int timerId, void* caller)
{ {
auto bump = static_cast<TBumper*>(caller); auto bump = static_cast<TBumper*>(caller);

View File

@ -16,8 +16,6 @@ public:
int Message(int code, float value) override; int Message(int code, float value) override;
void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance,
TEdgeSegment* edge) override; TEdgeSegment* edge) override;
void put_scoring(int index, int score) override;
int get_scoring(int index) override;
void Fire(); void Fire();
static void TimerExpired(int timerId, void* caller); static void TimerExpired(int timerId, void* caller);
@ -28,6 +26,5 @@ public:
float OriginalThreshold; float OriginalThreshold;
int SoundIndex4; int SoundIndex4;
int SoundIndex3; int SoundIndex3;
int Scores[4]{};
TBumper_player_backup PlayerData[4]{}; TBumper_player_backup PlayerData[4]{};
}; };

View File

@ -92,17 +92,6 @@ void TFlagSpinner::Collision(TBall* ball, vector2* nextPosition, vector2* direct
NextFrame(); NextFrame();
} }
void TFlagSpinner::put_scoring(int index, int score)
{
if (index < 2)
Scores[index] = score;
}
int TFlagSpinner::get_scoring(int index)
{
return index < 2 ? Scores[index] : 0;
}
void TFlagSpinner::NextFrame() void TFlagSpinner::NextFrame()
{ {
BmpIndex += SpinDirection; BmpIndex += SpinDirection;

View File

@ -9,8 +9,6 @@ public:
int Message(int code, float value) override; int Message(int code, float value) override;
void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance,
TEdgeSegment* edge) override; TEdgeSegment* edge) override;
void put_scoring(int index, int score) override;
int get_scoring(int index) override;
void NextFrame(); void NextFrame();
static void SpinTimer(int timerId, void* caller); static void SpinTimer(int timerId, void* caller);
@ -23,6 +21,5 @@ public:
int BmpIndex{}; int BmpIndex{};
int Timer; int Timer;
TEdgeSegment* PrevCollider; TEdgeSegment* PrevCollider;
int Scores[2]{};
}; };

View File

@ -93,17 +93,6 @@ int TKickout::Message(int code, float value)
return 0; return 0;
} }
void TKickout::put_scoring(int index, int score)
{
if (index < 5)
Scores[index] = score;
}
int TKickout::get_scoring(int index)
{
return index < 5 ? Scores[index] : 0;
}
void TKickout::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) void TKickout::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge)
{ {
if (!KickFlag1) if (!KickFlag1)

View File

@ -9,8 +9,6 @@ class TKickout :
public: public:
TKickout(TPinballTable* table, int groupIndex, bool someFlag); TKickout(TPinballTable* table, int groupIndex, bool someFlag);
int Message(int code, float value) override; int Message(int code, float value) override;
void put_scoring(int index, int score) override;
int get_scoring(int index) override;
void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance,
TEdgeSegment* edge) override; TEdgeSegment* edge) override;
int FieldEffect(TBall* ball, vector2* vecDst) override; int FieldEffect(TBall* ball, vector2* vecDst) override;
@ -33,5 +31,4 @@ public:
float ThrowSpeedMult1; float ThrowSpeedMult1;
float ThrowSpeedMult2; float ThrowSpeedMult2;
field_effect_type Field{}; field_effect_type Field{};
int Scores[5]{};
}; };

View File

@ -72,14 +72,3 @@ void TOneway::Collision(TBall* ball, vector2* nextPosition, vector2* direction,
loader::play_sound(SoftHitSoundId, ball, "TOneway2"); loader::play_sound(SoftHitSoundId, ball, "TOneway2");
} }
} }
void TOneway::put_scoring(int index, int score)
{
if (index < 6)
Scores[index] = score;
}
int TOneway::get_scoring(int index)
{
return index < 6 ? Scores[index] : 0;
}

View File

@ -10,9 +10,6 @@ public:
~TOneway() override = default; ~TOneway() override = default;
void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance,
TEdgeSegment* edge) override; TEdgeSegment* edge) override;
void put_scoring(int index, int score) override;
int get_scoring(int index) override;
TLine* Line; TLine* Line;
int Scores[6]{};
}; };

View File

@ -1,5 +1,7 @@
#include "pch.h" #include "pch.h"
#include "TPinballComponent.h" #include "TPinballComponent.h"
#include "control.h"
#include "loader.h" #include "loader.h"
#include "proj.h" #include "proj.h"
#include "render.h" #include "render.h"
@ -115,13 +117,9 @@ void TPinballComponent::port_draw()
{ {
} }
void TPinballComponent::put_scoring(int index, int score) int TPinballComponent::get_scoring(unsigned int index) const
{ {
} return Control == nullptr || index >= Control->ScoreCount ? 0 : Control->Scores[index];
int TPinballComponent::get_scoring(int index)
{
return 0;
} }
vector2 TPinballComponent::get_coordinates() vector2 TPinballComponent::get_coordinates()

View File

@ -22,8 +22,7 @@ public:
virtual ~TPinballComponent(); virtual ~TPinballComponent();
virtual int Message(int code, float value); virtual int Message(int code, float value);
virtual void port_draw(); virtual void port_draw();
virtual void put_scoring(int index, int score); int get_scoring(unsigned int index) const;
virtual int get_scoring(int index);
virtual vector2 get_coordinates(); virtual vector2 get_coordinates();
char UnusedBaseFlag; char UnusedBaseFlag;

View File

@ -51,17 +51,6 @@ int TPopupTarget::Message(int code, float value)
return 0; return 0;
} }
void TPopupTarget::put_scoring(int index, int score)
{
if (index < 3)
Scores[index] = score;
}
int TPopupTarget::get_scoring(int index)
{
return index < 3 ? Scores[index] : 0;
}
void TPopupTarget::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, void TPopupTarget::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance,
TEdgeSegment* edge) TEdgeSegment* edge)
{ {

View File

@ -7,8 +7,6 @@ class TPopupTarget :
public: public:
TPopupTarget(TPinballTable* table, int groupIndex); TPopupTarget(TPinballTable* table, int groupIndex);
int Message(int code, float value) override; int Message(int code, float value) override;
void put_scoring(int index, int score) override;
int get_scoring(int index) override;
void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance,
TEdgeSegment* edge) override; TEdgeSegment* edge) override;
@ -16,6 +14,5 @@ public:
int Timer; int Timer;
float TimerTime; float TimerTime;
int Scores[3]{};
int PlayerMessagefieldBackup[4]{}; int PlayerMessagefieldBackup[4]{};
}; };

View File

@ -127,17 +127,6 @@ TRamp::TRamp(TPinballTable* table, int groupIndex) : TCollisionComponent(table,
TTableLayer::edges_insert_square(y0, x0, y1, x1, nullptr, &Field); TTableLayer::edges_insert_square(y0, x0, y1, x1, nullptr, &Field);
} }
void TRamp::put_scoring(int index, int score)
{
if (index < 4)
Scores[index] = score;
}
int TRamp::get_scoring(int index)
{
return index < 4 ? Scores[index] : 0;
}
void TRamp::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) void TRamp::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge)
{ {
ball->not_again(edge); ball->not_again(edge);

View File

@ -10,14 +10,11 @@ class TRamp :
{ {
public: public:
TRamp(TPinballTable* table, int groupIndex); TRamp(TPinballTable* table, int groupIndex);
void put_scoring(int index, int score) override;
int get_scoring(int index) override;
void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance,
TEdgeSegment* edge) override; TEdgeSegment* edge) override;
int FieldEffect(TBall* ball, vector2* vecDst) override; int FieldEffect(TBall* ball, vector2* vecDst) override;
void port_draw() override; void port_draw() override;
int Scores[4]{};
field_effect_type Field{}; field_effect_type Field{};
int CollisionGroup; int CollisionGroup;
bool BallZOffsetFlag; bool BallZOffsetFlag;

View File

@ -67,18 +67,6 @@ void TRollover::Collision(TBall* ball, vector2* nextPosition, vector2* direction
} }
} }
void TRollover::put_scoring(int index, int score)
{
if (index < 2)
Scores[index] = score;
}
int TRollover::get_scoring(int index)
{
return index < 2 ? Scores[index] : 0;
}
void TRollover::build_walls(int groupIndex) void TRollover::build_walls(int groupIndex)
{ {
visualStruct visual{}; visualStruct visual{};

View File

@ -12,12 +12,9 @@ public:
int Message(int code, float value) override; int Message(int code, float value) override;
void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance,
TEdgeSegment* edge) override; TEdgeSegment* edge) override;
void put_scoring(int index, int score) override;
int get_scoring(int index) override;
void build_walls(int groupIndex); void build_walls(int groupIndex);
static void TimerExpired(int timerId, void* caller); static void TimerExpired(int timerId, void* caller);
char RolloverFlag{}; char RolloverFlag{};
int Scores[2]{};
}; };

View File

@ -64,17 +64,6 @@ int TSink::Message(int code, float value)
return 0; return 0;
} }
void TSink::put_scoring(int index, int score)
{
if (index < 3)
Scores[index] = score;
}
int TSink::get_scoring(int index)
{
return index < 3 ? Scores[index] : 0;
}
void TSink::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) void TSink::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge)
{ {
Timer = 0; Timer = 0;

View File

@ -8,8 +8,6 @@ class TSink :
public: public:
TSink(TPinballTable* table, int groupIndex); TSink(TPinballTable* table, int groupIndex);
int Message(int code, float value) override; int Message(int code, float value) override;
void put_scoring(int index, int score) override;
int get_scoring(int index) override;
void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance,
TEdgeSegment* edge) override; TEdgeSegment* edge) override;
@ -24,6 +22,5 @@ public:
float ThrowSpeedMult2; float ThrowSpeedMult2;
int SoundIndex4; int SoundIndex4;
int SoundIndex3; int SoundIndex3;
int Scores[3]{};
int PlayerMessagefieldBackup[4]{}; int PlayerMessagefieldBackup[4]{};
}; };

View File

@ -53,17 +53,6 @@ int TSoloTarget::Message(int code, float value)
return 0; return 0;
} }
void TSoloTarget::put_scoring(int index, int score)
{
if (index < 1)
Scores[index] = score;
}
int TSoloTarget::get_scoring(int index)
{
return index < 1 ? Scores[index] : 0;
}
void TSoloTarget::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, void TSoloTarget::Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance,
TEdgeSegment* edge) TEdgeSegment* edge)
{ {

View File

@ -7,8 +7,6 @@ class TSoloTarget :
public: public:
TSoloTarget(TPinballTable* table, int groupIndex); TSoloTarget(TPinballTable* table, int groupIndex);
int Message(int code, float value) override; int Message(int code, float value) override;
void put_scoring(int index, int score) override;
int get_scoring(int index) override;
void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance,
TEdgeSegment* edge) override; TEdgeSegment* edge) override;
@ -17,5 +15,4 @@ public:
int Timer; int Timer;
float TimerTime; float TimerTime;
int SoundIndex4; int SoundIndex4;
int Scores[1]{};
}; };

View File

@ -37,17 +37,6 @@ void TWall::Collision(TBall* ball, vector2* nextPosition, vector2* direction, fl
} }
} }
void TWall::put_scoring(int index, int score)
{
if (index < 1)
Scores[index] = score;
}
int TWall::get_scoring(int index)
{
return index < 1 ? Scores[index] : 0;
}
void TWall::TimerExpired(int timerId, void* caller) void TWall::TimerExpired(int timerId, void* caller)
{ {
auto wall = static_cast<TWall*>(caller); auto wall = static_cast<TWall*>(caller);

View File

@ -12,12 +12,9 @@ public:
int Message(int code, float value) override; int Message(int code, float value) override;
void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance,
TEdgeSegment* edge) override; TEdgeSegment* edge) override;
void put_scoring(int index, int score) override;
int get_scoring(int index) override;
static void TimerExpired(int timerId, void* caller); static void TimerExpired(int timerId, void* caller);
int Timer{}; int Timer{};
gdrv_bitmap8* BmpPtr{}; gdrv_bitmap8* BmpPtr{};
int Scores[1]{};
}; };

View File

@ -806,22 +806,17 @@ void control::make_links(TPinballTable* table)
{ {
TableG = table; TableG = table;
for (int index = 0; index < 88; index++) for (auto& score_component : score_components)
{ {
auto compPtr = &score_components[index]; auto linkedComp = make_component_link(score_component.Tag);
TPinballComponent* comp = make_component_link(compPtr->Tag); if (linkedComp)
if (comp)
{ {
comp->Control = &compPtr->Control; linkedComp->Control = &score_component.Control;
for (int scoreId = 0; scoreId < compPtr->Control.ScoreCount; scoreId++)
{
comp->put_scoring(scoreId, compPtr->Control.Scores[scoreId]);
}
} }
} }
for (int i = 0; i < 142; ++i) for (auto& simple_component : simple_components)
make_component_link(*simple_components[i]); make_component_link(*simple_component);
} }
void control::ClearLinks() void control::ClearLinks()
@ -859,13 +854,6 @@ void control::handler(int code, TPinballComponent* cmp)
if (control) if (control)
{ {
if (code == 1019)
{
for (auto scoreInd = 0; scoreInd < control->ScoreCount; ++scoreInd)
{
cmp->put_scoring(scoreInd, control->Scores[scoreInd]);
}
}
control->ControlFunc(code, cmp); control->ControlFunc(code, cmp);
} }
MissionControl(code, cmp); MissionControl(code, cmp);

View File

@ -47,8 +47,8 @@ struct component_tag : component_tag_base
struct component_control struct component_control
{ {
void (* ControlFunc)(int, TPinballComponent*); void (* ControlFunc)(int, TPinballComponent*);
int ScoreCount; unsigned int ScoreCount;
int* Scores; const int* Scores;
}; };
struct component_info struct component_info