From ac289c7f489a625b484958e19544375eee6bf063 Mon Sep 17 00:00:00 2001 From: Muzychenko Andrey <33288308+k4zmu2a@users.noreply.github.com> Date: Thu, 7 Oct 2021 14:17:43 +0300 Subject: [PATCH] Fixed TLightGroup message 45 and 46, used by TLightBargraph. Issue #25. --- SpaceCadetPinball/TLightBargraph.cpp | 5 ++--- SpaceCadetPinball/TLightGroup.cpp | 28 +++++++++++----------------- 2 files changed, 13 insertions(+), 20 deletions(-) diff --git a/SpaceCadetPinball/TLightBargraph.cpp b/SpaceCadetPinball/TLightBargraph.cpp index 3098078..2551f0f 100644 --- a/SpaceCadetPinball/TLightBargraph.cpp +++ b/SpaceCadetPinball/TLightBargraph.cpp @@ -54,9 +54,8 @@ int TLightBargraph::Message(int code, float value) TLightGroup::Message(45, static_cast(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 diff --git a/SpaceCadetPinball/TLightGroup.cpp b/SpaceCadetPinball/TLightGroup.cpp index 4999775..2cc1dee 100644 --- a/SpaceCadetPinball/TLightGroup.cpp +++ b/SpaceCadetPinball/TLightGroup.cpp @@ -30,7 +30,7 @@ TLightGroup::TLightGroup(TPinballTable* table, int groupIndex) : TPinballCompone int TLightGroup::Message(int code, float value) { - auto count = static_cast(List.size()); + auto const count = static_cast(List.size()); switch (code) { case 1011: @@ -352,24 +352,18 @@ int TLightGroup::Message(int code, float value) { control::handler(code, this); auto index = static_cast(floor(value)); - if (index >= 0) + if (index >= 0 && index < count) { - if (index <= count) + // Turn off lights (index, end] + for (auto i = count - 1; i > index; i--) { - auto countSub1 = count - 1; - if (countSub1 > index) - { - for (auto i = countSub1, k = countSub1 - index; k != 0; i--, k--) - { - auto light = List.at(i); - light->Message(20, 0.0); - } - } + List.at(i)->Message(20, 0.0); + } - for (auto it = List.rbegin(); it != List.rend(); ++it) - { - (*it)->Message(19, 0.0); - } + // Turn on lights [begin, index] + for (auto i = index; i >= 0; i--) + { + List.at(i)->Message(19, 0.0); } } break; @@ -448,7 +442,7 @@ int TLightGroup::next_light_down() { for (auto index = static_cast(List.size()) - 1; index >= 0; --index) { - if (!List.at(index)->BmpIndex1) + if (List.at(index)->BmpIndex1) return index; } return -1;