From 7feba1e9478decc7800448b03476238863ebc5ec Mon Sep 17 00:00:00 2001 From: Muzychenko Andrey <33288308+k4zmu2a@users.noreply.github.com> Date: Thu, 18 Aug 2022 16:23:29 +0300 Subject: [PATCH] Code from FT: simplified score access in TPinballComponent. --- SpaceCadetPinball/TBumper.cpp | 12 ------------ SpaceCadetPinball/TBumper.h | 3 --- SpaceCadetPinball/TFlagSpinner.cpp | 11 ----------- SpaceCadetPinball/TFlagSpinner.h | 3 --- SpaceCadetPinball/TKickout.cpp | 11 ----------- SpaceCadetPinball/TKickout.h | 3 --- SpaceCadetPinball/TOneway.cpp | 11 ----------- SpaceCadetPinball/TOneway.h | 3 --- SpaceCadetPinball/TPinballComponent.cpp | 10 ++++------ SpaceCadetPinball/TPinballComponent.h | 3 +-- SpaceCadetPinball/TPopupTarget.cpp | 11 ----------- SpaceCadetPinball/TPopupTarget.h | 3 --- SpaceCadetPinball/TRamp.cpp | 11 ----------- SpaceCadetPinball/TRamp.h | 3 --- SpaceCadetPinball/TRollover.cpp | 12 ------------ SpaceCadetPinball/TRollover.h | 3 --- SpaceCadetPinball/TSink.cpp | 11 ----------- SpaceCadetPinball/TSink.h | 3 --- SpaceCadetPinball/TSoloTarget.cpp | 11 ----------- SpaceCadetPinball/TSoloTarget.h | 3 --- SpaceCadetPinball/TWall.cpp | 11 ----------- SpaceCadetPinball/TWall.h | 3 --- SpaceCadetPinball/control.cpp | 24 ++++++------------------ SpaceCadetPinball/control.h | 4 ++-- 24 files changed, 13 insertions(+), 170 deletions(-) diff --git a/SpaceCadetPinball/TBumper.cpp b/SpaceCadetPinball/TBumper.cpp index ecb6fcc..3cc9cf1 100644 --- a/SpaceCadetPinball/TBumper.cpp +++ b/SpaceCadetPinball/TBumper.cpp @@ -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) { auto bump = static_cast(caller); diff --git a/SpaceCadetPinball/TBumper.h b/SpaceCadetPinball/TBumper.h index 99e7213..6dcdb29 100644 --- a/SpaceCadetPinball/TBumper.h +++ b/SpaceCadetPinball/TBumper.h @@ -16,8 +16,6 @@ public: int Message(int code, float value) override; void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) override; - void put_scoring(int index, int score) override; - int get_scoring(int index) override; void Fire(); static void TimerExpired(int timerId, void* caller); @@ -28,6 +26,5 @@ public: float OriginalThreshold; int SoundIndex4; int SoundIndex3; - int Scores[4]{}; TBumper_player_backup PlayerData[4]{}; }; diff --git a/SpaceCadetPinball/TFlagSpinner.cpp b/SpaceCadetPinball/TFlagSpinner.cpp index 7f80429..68db0cf 100644 --- a/SpaceCadetPinball/TFlagSpinner.cpp +++ b/SpaceCadetPinball/TFlagSpinner.cpp @@ -92,17 +92,6 @@ void TFlagSpinner::Collision(TBall* ball, vector2* nextPosition, vector2* direct 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() { BmpIndex += SpinDirection; diff --git a/SpaceCadetPinball/TFlagSpinner.h b/SpaceCadetPinball/TFlagSpinner.h index eb4e4da..bda4896 100644 --- a/SpaceCadetPinball/TFlagSpinner.h +++ b/SpaceCadetPinball/TFlagSpinner.h @@ -9,8 +9,6 @@ public: int Message(int code, float value) override; void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) override; - void put_scoring(int index, int score) override; - int get_scoring(int index) override; void NextFrame(); static void SpinTimer(int timerId, void* caller); @@ -23,6 +21,5 @@ public: int BmpIndex{}; int Timer; TEdgeSegment* PrevCollider; - int Scores[2]{}; }; diff --git a/SpaceCadetPinball/TKickout.cpp b/SpaceCadetPinball/TKickout.cpp index 0f6ff34..2567a55 100644 --- a/SpaceCadetPinball/TKickout.cpp +++ b/SpaceCadetPinball/TKickout.cpp @@ -93,17 +93,6 @@ int TKickout::Message(int code, float value) 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) { if (!KickFlag1) diff --git a/SpaceCadetPinball/TKickout.h b/SpaceCadetPinball/TKickout.h index e29859a..b16ea57 100644 --- a/SpaceCadetPinball/TKickout.h +++ b/SpaceCadetPinball/TKickout.h @@ -9,8 +9,6 @@ class TKickout : public: TKickout(TPinballTable* table, int groupIndex, bool someFlag); 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, TEdgeSegment* edge) override; int FieldEffect(TBall* ball, vector2* vecDst) override; @@ -33,5 +31,4 @@ public: float ThrowSpeedMult1; float ThrowSpeedMult2; field_effect_type Field{}; - int Scores[5]{}; }; diff --git a/SpaceCadetPinball/TOneway.cpp b/SpaceCadetPinball/TOneway.cpp index 3c2b70e..e4959b0 100644 --- a/SpaceCadetPinball/TOneway.cpp +++ b/SpaceCadetPinball/TOneway.cpp @@ -72,14 +72,3 @@ void TOneway::Collision(TBall* ball, vector2* nextPosition, vector2* direction, 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; -} diff --git a/SpaceCadetPinball/TOneway.h b/SpaceCadetPinball/TOneway.h index f85afe0..107e194 100644 --- a/SpaceCadetPinball/TOneway.h +++ b/SpaceCadetPinball/TOneway.h @@ -10,9 +10,6 @@ public: ~TOneway() override = default; void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) override; - void put_scoring(int index, int score) override; - int get_scoring(int index) override; TLine* Line; - int Scores[6]{}; }; diff --git a/SpaceCadetPinball/TPinballComponent.cpp b/SpaceCadetPinball/TPinballComponent.cpp index 64664e2..85db1da 100644 --- a/SpaceCadetPinball/TPinballComponent.cpp +++ b/SpaceCadetPinball/TPinballComponent.cpp @@ -1,5 +1,7 @@ #include "pch.h" #include "TPinballComponent.h" + +#include "control.h" #include "loader.h" #include "proj.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 { -} - -int TPinballComponent::get_scoring(int index) -{ - return 0; + return Control == nullptr || index >= Control->ScoreCount ? 0 : Control->Scores[index]; } vector2 TPinballComponent::get_coordinates() diff --git a/SpaceCadetPinball/TPinballComponent.h b/SpaceCadetPinball/TPinballComponent.h index c68d41c..23e8719 100644 --- a/SpaceCadetPinball/TPinballComponent.h +++ b/SpaceCadetPinball/TPinballComponent.h @@ -22,8 +22,7 @@ public: virtual ~TPinballComponent(); virtual int Message(int code, float value); virtual void port_draw(); - virtual void put_scoring(int index, int score); - virtual int get_scoring(int index); + int get_scoring(unsigned int index) const; virtual vector2 get_coordinates(); char UnusedBaseFlag; diff --git a/SpaceCadetPinball/TPopupTarget.cpp b/SpaceCadetPinball/TPopupTarget.cpp index 98bc56a..fb85100 100644 --- a/SpaceCadetPinball/TPopupTarget.cpp +++ b/SpaceCadetPinball/TPopupTarget.cpp @@ -51,17 +51,6 @@ int TPopupTarget::Message(int code, float value) 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, TEdgeSegment* edge) { diff --git a/SpaceCadetPinball/TPopupTarget.h b/SpaceCadetPinball/TPopupTarget.h index 422bdf0..c7cffd7 100644 --- a/SpaceCadetPinball/TPopupTarget.h +++ b/SpaceCadetPinball/TPopupTarget.h @@ -7,8 +7,6 @@ class TPopupTarget : public: TPopupTarget(TPinballTable* table, int groupIndex); 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, TEdgeSegment* edge) override; @@ -16,6 +14,5 @@ public: int Timer; float TimerTime; - int Scores[3]{}; int PlayerMessagefieldBackup[4]{}; }; diff --git a/SpaceCadetPinball/TRamp.cpp b/SpaceCadetPinball/TRamp.cpp index 7214fcc..b6e9c54 100644 --- a/SpaceCadetPinball/TRamp.cpp +++ b/SpaceCadetPinball/TRamp.cpp @@ -127,17 +127,6 @@ TRamp::TRamp(TPinballTable* table, int groupIndex) : TCollisionComponent(table, 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) { ball->not_again(edge); diff --git a/SpaceCadetPinball/TRamp.h b/SpaceCadetPinball/TRamp.h index 3635134..453610e 100644 --- a/SpaceCadetPinball/TRamp.h +++ b/SpaceCadetPinball/TRamp.h @@ -10,14 +10,11 @@ class TRamp : { public: 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, TEdgeSegment* edge) override; int FieldEffect(TBall* ball, vector2* vecDst) override; void port_draw() override; - int Scores[4]{}; field_effect_type Field{}; int CollisionGroup; bool BallZOffsetFlag; diff --git a/SpaceCadetPinball/TRollover.cpp b/SpaceCadetPinball/TRollover.cpp index 45a35eb..14f3c9f 100644 --- a/SpaceCadetPinball/TRollover.cpp +++ b/SpaceCadetPinball/TRollover.cpp @@ -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) { visualStruct visual{}; diff --git a/SpaceCadetPinball/TRollover.h b/SpaceCadetPinball/TRollover.h index b90893f..6ac27c1 100644 --- a/SpaceCadetPinball/TRollover.h +++ b/SpaceCadetPinball/TRollover.h @@ -12,12 +12,9 @@ public: int Message(int code, float value) override; void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) override; - void put_scoring(int index, int score) override; - int get_scoring(int index) override; void build_walls(int groupIndex); static void TimerExpired(int timerId, void* caller); char RolloverFlag{}; - int Scores[2]{}; }; diff --git a/SpaceCadetPinball/TSink.cpp b/SpaceCadetPinball/TSink.cpp index 70a5904..16f144d 100644 --- a/SpaceCadetPinball/TSink.cpp +++ b/SpaceCadetPinball/TSink.cpp @@ -64,17 +64,6 @@ int TSink::Message(int code, float value) 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) { Timer = 0; diff --git a/SpaceCadetPinball/TSink.h b/SpaceCadetPinball/TSink.h index 21c080e..fd9e099 100644 --- a/SpaceCadetPinball/TSink.h +++ b/SpaceCadetPinball/TSink.h @@ -8,8 +8,6 @@ class TSink : public: TSink(TPinballTable* table, int groupIndex); 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, TEdgeSegment* edge) override; @@ -24,6 +22,5 @@ public: float ThrowSpeedMult2; int SoundIndex4; int SoundIndex3; - int Scores[3]{}; int PlayerMessagefieldBackup[4]{}; }; diff --git a/SpaceCadetPinball/TSoloTarget.cpp b/SpaceCadetPinball/TSoloTarget.cpp index f7b494f..20c3b3a 100644 --- a/SpaceCadetPinball/TSoloTarget.cpp +++ b/SpaceCadetPinball/TSoloTarget.cpp @@ -53,17 +53,6 @@ int TSoloTarget::Message(int code, float value) 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, TEdgeSegment* edge) { diff --git a/SpaceCadetPinball/TSoloTarget.h b/SpaceCadetPinball/TSoloTarget.h index 26d7342..4088fc0 100644 --- a/SpaceCadetPinball/TSoloTarget.h +++ b/SpaceCadetPinball/TSoloTarget.h @@ -7,8 +7,6 @@ class TSoloTarget : public: TSoloTarget(TPinballTable* table, int groupIndex); 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, TEdgeSegment* edge) override; @@ -17,5 +15,4 @@ public: int Timer; float TimerTime; int SoundIndex4; - int Scores[1]{}; }; diff --git a/SpaceCadetPinball/TWall.cpp b/SpaceCadetPinball/TWall.cpp index 94716cb..8392895 100644 --- a/SpaceCadetPinball/TWall.cpp +++ b/SpaceCadetPinball/TWall.cpp @@ -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) { auto wall = static_cast(caller); diff --git a/SpaceCadetPinball/TWall.h b/SpaceCadetPinball/TWall.h index 9e2dd59..d3849c1 100644 --- a/SpaceCadetPinball/TWall.h +++ b/SpaceCadetPinball/TWall.h @@ -12,12 +12,9 @@ public: int Message(int code, float value) override; void Collision(TBall* ball, vector2* nextPosition, vector2* direction, float distance, TEdgeSegment* edge) override; - void put_scoring(int index, int score) override; - int get_scoring(int index) override; static void TimerExpired(int timerId, void* caller); int Timer{}; gdrv_bitmap8* BmpPtr{}; - int Scores[1]{}; }; diff --git a/SpaceCadetPinball/control.cpp b/SpaceCadetPinball/control.cpp index b7a8a69..8881e19 100644 --- a/SpaceCadetPinball/control.cpp +++ b/SpaceCadetPinball/control.cpp @@ -806,22 +806,17 @@ void control::make_links(TPinballTable* table) { TableG = table; - for (int index = 0; index < 88; index++) + for (auto& score_component : score_components) { - auto compPtr = &score_components[index]; - TPinballComponent* comp = make_component_link(compPtr->Tag); - if (comp) + auto linkedComp = make_component_link(score_component.Tag); + if (linkedComp) { - comp->Control = &compPtr->Control; - for (int scoreId = 0; scoreId < compPtr->Control.ScoreCount; scoreId++) - { - comp->put_scoring(scoreId, compPtr->Control.Scores[scoreId]); - } + linkedComp->Control = &score_component.Control; } } - for (int i = 0; i < 142; ++i) - make_component_link(*simple_components[i]); + for (auto& simple_component : simple_components) + make_component_link(*simple_component); } void control::ClearLinks() @@ -859,13 +854,6 @@ void control::handler(int code, TPinballComponent* cmp) if (control) { - if (code == 1019) - { - for (auto scoreInd = 0; scoreInd < control->ScoreCount; ++scoreInd) - { - cmp->put_scoring(scoreInd, control->Scores[scoreInd]); - } - } control->ControlFunc(code, cmp); } MissionControl(code, cmp); diff --git a/SpaceCadetPinball/control.h b/SpaceCadetPinball/control.h index e78d923..e608060 100644 --- a/SpaceCadetPinball/control.h +++ b/SpaceCadetPinball/control.h @@ -47,8 +47,8 @@ struct component_tag : component_tag_base struct component_control { void (* ControlFunc)(int, TPinballComponent*); - int ScoreCount; - int* Scores; + unsigned int ScoreCount; + const int* Scores; }; struct component_info