2020-11-01 16:45:29 +01:00
|
|
|
#include "pch.h"
|
|
|
|
#include "TLightGroup.h"
|
2021-01-05 10:02:43 +01:00
|
|
|
|
|
|
|
|
|
|
|
#include "control.h"
|
|
|
|
#include "loader.h"
|
|
|
|
#include "timer.h"
|
|
|
|
#include "TLight.h"
|
|
|
|
#include "TPinballTable.h"
|
|
|
|
|
2022-09-06 15:57:56 +02:00
|
|
|
TLightGroup::TLightGroup(TPinballTable* table, int groupIndex) : TPinballComponent(table, groupIndex, false)
|
2021-01-05 10:02:43 +01:00
|
|
|
{
|
|
|
|
Timer = 0;
|
|
|
|
NotifyTimer = 0;
|
2021-10-01 17:55:44 +02:00
|
|
|
TLightGroup::Reset();
|
2021-01-05 10:02:43 +01:00
|
|
|
if (groupIndex > 0)
|
|
|
|
{
|
|
|
|
int count;
|
|
|
|
Timer1TimeDefault = *loader::query_float_attribute(groupIndex, 0, 903);
|
2021-02-16 17:03:45 +01:00
|
|
|
int16_t* groupIndArr = loader::query_iattribute(groupIndex, 1027, &count);
|
2021-01-05 10:02:43 +01:00
|
|
|
for (int index = 0; index < count; ++groupIndArr)
|
|
|
|
{
|
2021-01-30 12:19:25 +01:00
|
|
|
auto comp = dynamic_cast<TLight*>(table->find_component(*groupIndArr));
|
2021-01-05 10:02:43 +01:00
|
|
|
if (comp)
|
2021-10-01 17:55:44 +02:00
|
|
|
List.push_back(comp);
|
2021-01-05 10:02:43 +01:00
|
|
|
++index;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-06 15:57:56 +02:00
|
|
|
int TLightGroup::Message(MessageCode code, float value)
|
2021-01-05 10:02:43 +01:00
|
|
|
{
|
2021-10-07 13:17:43 +02:00
|
|
|
auto const count = static_cast<int>(List.size());
|
2021-01-05 10:02:43 +01:00
|
|
|
switch (code)
|
|
|
|
{
|
2022-09-06 15:48:09 +02:00
|
|
|
case MessageCode::SetTiltLock:
|
|
|
|
case MessageCode::GameOver:
|
2021-01-05 10:02:43 +01:00
|
|
|
break;
|
2022-09-06 15:48:09 +02:00
|
|
|
case MessageCode::PlayerChanged:
|
2021-01-05 10:02:43 +01:00
|
|
|
{
|
|
|
|
auto playerPtr = &PlayerData[PinballTable->CurrentPlayer];
|
|
|
|
playerPtr->MessageField = MessageField;
|
|
|
|
playerPtr->MessageField2 = MessageField2;
|
|
|
|
playerPtr->Timer1Time = Timer1Time;
|
|
|
|
|
|
|
|
Reset();
|
|
|
|
|
|
|
|
playerPtr = &PlayerData[static_cast<int>(floor(value))];
|
|
|
|
MessageField = playerPtr->MessageField;
|
|
|
|
MessageField2 = playerPtr->MessageField2;
|
|
|
|
Timer1Time = playerPtr->Timer1Time;
|
|
|
|
if (!(MessageField == 0))
|
|
|
|
TimerExpired(0, this);
|
|
|
|
break;
|
|
|
|
}
|
2022-09-06 15:48:09 +02:00
|
|
|
case MessageCode::Reset:
|
2021-01-05 10:02:43 +01:00
|
|
|
Reset();
|
|
|
|
for (auto index = 0; index < PinballTable->PlayerCount; index++)
|
|
|
|
{
|
|
|
|
auto playerPtr = &PlayerData[index];
|
|
|
|
playerPtr->MessageField = MessageField;
|
|
|
|
playerPtr->MessageField2 = MessageField2;
|
|
|
|
playerPtr->Timer1Time = Timer1Time;
|
|
|
|
}
|
|
|
|
break;
|
2022-09-06 15:48:09 +02:00
|
|
|
case MessageCode::TLightGroupStepBackward:
|
2021-01-05 10:02:43 +01:00
|
|
|
{
|
2021-10-01 17:55:44 +02:00
|
|
|
auto lastLight = List.at(count - 1);
|
2022-08-24 12:32:35 +02:00
|
|
|
if (lastLight->FlasherOnFlag || lastLight->ToggledOnFlag || lastLight->ToggledOffFlag)
|
2021-01-05 10:02:43 +01:00
|
|
|
break;
|
2022-09-06 15:48:09 +02:00
|
|
|
if (MessageField2 != MessageCode::TLightGroupNull)
|
2021-01-05 10:02:43 +01:00
|
|
|
{
|
2022-09-06 15:57:56 +02:00
|
|
|
TLightGroup::Message(MessageCode::TLightGroupReset, 0.0);
|
2021-01-05 10:02:43 +01:00
|
|
|
}
|
|
|
|
AnimationFlag = 1;
|
|
|
|
MessageField2 = code;
|
2022-09-06 15:48:09 +02:00
|
|
|
auto lastMessage = lastLight->MessageField;
|
|
|
|
auto lastStatus = lastLight->LightOnFlag;
|
2021-01-05 10:02:43 +01:00
|
|
|
for (auto index = count - 1; index > 0; --index)
|
|
|
|
{
|
2021-10-01 17:55:44 +02:00
|
|
|
auto lightCur = List.at(index);
|
|
|
|
auto lightPrev = List.at(index - 1);
|
2022-09-06 15:57:56 +02:00
|
|
|
lightCur->Message(lightPrev->LightOnFlag ? MessageCode::TLightTurnOn : MessageCode::TLightTurnOff, 0.0);
|
2021-01-05 10:02:43 +01:00
|
|
|
lightCur->MessageField = lightPrev->MessageField;
|
|
|
|
}
|
2021-10-01 17:55:44 +02:00
|
|
|
auto firstLight = List.at(0);
|
2022-09-06 15:57:56 +02:00
|
|
|
firstLight->Message(lastStatus ? MessageCode::TLightTurnOn : MessageCode::TLightTurnOff, 0.0);
|
2022-09-06 15:48:09 +02:00
|
|
|
firstLight->MessageField = lastMessage;
|
2021-01-05 10:02:43 +01:00
|
|
|
reschedule_animation(value);
|
|
|
|
break;
|
|
|
|
}
|
2022-09-06 15:48:09 +02:00
|
|
|
case MessageCode::TLightGroupStepForward:
|
2021-01-05 10:02:43 +01:00
|
|
|
{
|
2021-10-01 17:55:44 +02:00
|
|
|
auto lastLight = List.at(count - 1);
|
2022-08-24 12:32:35 +02:00
|
|
|
if (lastLight->FlasherOnFlag || lastLight->ToggledOnFlag || lastLight->ToggledOffFlag)
|
2021-01-05 10:02:43 +01:00
|
|
|
break;
|
2022-09-06 15:48:09 +02:00
|
|
|
if (MessageField2 != MessageCode::TLightGroupNull)
|
2021-01-05 10:02:43 +01:00
|
|
|
{
|
2022-09-06 15:57:56 +02:00
|
|
|
TLightGroup::Message(MessageCode::TLightGroupReset, 0.0);
|
2021-01-05 10:02:43 +01:00
|
|
|
}
|
2021-10-01 17:55:44 +02:00
|
|
|
auto firstLight = List.at(0);
|
2021-01-05 10:02:43 +01:00
|
|
|
AnimationFlag = 1;
|
|
|
|
MessageField2 = code;
|
2022-09-06 15:48:09 +02:00
|
|
|
auto firstMessage = firstLight->MessageField;
|
|
|
|
auto firstStatus = firstLight->LightOnFlag;
|
2021-01-05 10:02:43 +01:00
|
|
|
for (auto index = 0; index < count - 1; index++)
|
|
|
|
{
|
2021-10-01 17:55:44 +02:00
|
|
|
auto lightCur = List.at(index);
|
|
|
|
auto lightNext = List.at(index + 1);
|
2022-09-06 15:57:56 +02:00
|
|
|
lightCur->Message(lightNext->LightOnFlag ? MessageCode::TLightTurnOn : MessageCode::TLightTurnOff, 0.0);
|
2021-01-05 10:02:43 +01:00
|
|
|
lightCur->MessageField = lightNext->MessageField;
|
|
|
|
}
|
2022-09-06 15:57:56 +02:00
|
|
|
lastLight->Message(firstStatus ? MessageCode::TLightTurnOn : MessageCode::TLightTurnOff, 0.0);
|
2022-09-06 15:48:09 +02:00
|
|
|
lastLight->MessageField = firstMessage;
|
2021-01-05 10:02:43 +01:00
|
|
|
reschedule_animation(value);
|
|
|
|
break;
|
|
|
|
}
|
2022-09-06 15:48:09 +02:00
|
|
|
case MessageCode::TLightGroupAnimationBackward:
|
2021-01-05 10:02:43 +01:00
|
|
|
{
|
2022-09-06 15:48:09 +02:00
|
|
|
if (AnimationFlag || MessageField2 == MessageCode::TLightGroupNull)
|
2021-01-05 10:02:43 +01:00
|
|
|
start_animation();
|
|
|
|
MessageField2 = code;
|
|
|
|
AnimationFlag = 0;
|
2021-10-01 17:55:44 +02:00
|
|
|
auto lastLight = List.at(count - 1);
|
2022-09-06 15:48:09 +02:00
|
|
|
auto lastStatus = lastLight->ToggledOnFlag;
|
2021-01-05 10:02:43 +01:00
|
|
|
for (auto i = count - 1; i > 0; --i)
|
|
|
|
{
|
2021-10-01 17:55:44 +02:00
|
|
|
auto lightCur = List.at(i);
|
|
|
|
auto lightPrev = List.at(i - 1);
|
2022-09-06 15:57:56 +02:00
|
|
|
lightCur->Message(lightPrev->ToggledOnFlag ? MessageCode::TLightTurnOnTimed : MessageCode::TLightTurnOffTimed, 0.0);
|
2021-01-05 10:02:43 +01:00
|
|
|
}
|
2021-10-01 17:55:44 +02:00
|
|
|
auto firstLight = List.at(0);
|
2022-09-06 15:57:56 +02:00
|
|
|
firstLight->Message(lastStatus ? MessageCode::TLightTurnOnTimed : MessageCode::TLightTurnOffTimed, 0);
|
2021-01-05 10:02:43 +01:00
|
|
|
reschedule_animation(value);
|
|
|
|
break;
|
|
|
|
}
|
2022-09-06 15:48:09 +02:00
|
|
|
case MessageCode::TLightGroupAnimationForward:
|
2021-01-05 10:02:43 +01:00
|
|
|
{
|
2022-09-06 15:48:09 +02:00
|
|
|
if (AnimationFlag || MessageField2 == MessageCode::TLightGroupNull)
|
2021-01-05 10:02:43 +01:00
|
|
|
start_animation();
|
|
|
|
MessageField2 = code;
|
|
|
|
AnimationFlag = 0;
|
2021-10-01 17:55:44 +02:00
|
|
|
auto firstLight = List.at(0);
|
2022-09-06 15:48:09 +02:00
|
|
|
auto firstStatus = firstLight->ToggledOnFlag;
|
2021-01-05 10:02:43 +01:00
|
|
|
for (auto i = 0; i < count - 1; i++)
|
|
|
|
{
|
2021-10-01 17:55:44 +02:00
|
|
|
auto lightCur = List.at(i);
|
|
|
|
auto lightNext = List.at(i + 1);
|
2022-09-06 15:57:56 +02:00
|
|
|
lightCur->Message(lightNext->ToggledOnFlag ? MessageCode::TLightTurnOnTimed : MessageCode::TLightTurnOffTimed, 0.0);
|
2021-01-05 10:02:43 +01:00
|
|
|
}
|
2021-10-01 17:55:44 +02:00
|
|
|
auto lastLight = List.at(count - 1);
|
2022-09-06 15:57:56 +02:00
|
|
|
lastLight->Message(firstStatus ? MessageCode::TLightTurnOnTimed : MessageCode::TLightTurnOffTimed, 0);
|
2021-01-05 10:02:43 +01:00
|
|
|
reschedule_animation(value);
|
|
|
|
break;
|
|
|
|
}
|
2022-09-06 15:48:09 +02:00
|
|
|
case MessageCode::TLightGroupLightShowAnimation:
|
2021-01-05 10:02:43 +01:00
|
|
|
{
|
2022-09-06 15:48:09 +02:00
|
|
|
if (AnimationFlag || MessageField2 == MessageCode::TLightGroupNull)
|
2021-01-05 10:02:43 +01:00
|
|
|
start_animation();
|
|
|
|
MessageField2 = code;
|
|
|
|
AnimationFlag = 0;
|
2021-10-01 17:55:44 +02:00
|
|
|
for (auto light : List)
|
2021-01-05 10:02:43 +01:00
|
|
|
{
|
|
|
|
if (rand() % 100 > 70)
|
|
|
|
{
|
2021-09-09 10:40:54 +02:00
|
|
|
auto randVal = RandFloat() * value * 3.0f + 0.1f;
|
2022-09-06 15:57:56 +02:00
|
|
|
light->Message(MessageCode::TLightTurnOnTimed, randVal);
|
2021-01-05 10:02:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
reschedule_animation(value);
|
|
|
|
break;
|
|
|
|
}
|
2022-09-06 15:48:09 +02:00
|
|
|
case MessageCode::TLightGroupGameOverAnimation:
|
2021-01-05 10:02:43 +01:00
|
|
|
{
|
2022-09-06 15:48:09 +02:00
|
|
|
if (AnimationFlag || MessageField2 == MessageCode::TLightGroupNull)
|
2021-01-05 10:02:43 +01:00
|
|
|
start_animation();
|
|
|
|
MessageField2 = code;
|
|
|
|
AnimationFlag = 0;
|
2021-10-01 17:55:44 +02:00
|
|
|
for (auto light : List)
|
2021-01-05 10:02:43 +01:00
|
|
|
{
|
|
|
|
auto randVal = static_cast<float>(rand() % 100 > 70);
|
2022-09-06 15:57:56 +02:00
|
|
|
light->Message(MessageCode::TLightResetAndToggleValue, randVal);
|
2021-01-05 10:02:43 +01:00
|
|
|
}
|
|
|
|
reschedule_animation(value);
|
|
|
|
break;
|
|
|
|
}
|
2022-09-06 15:48:09 +02:00
|
|
|
case MessageCode::TLightGroupRandomAnimationSaturation:
|
2021-01-05 10:02:43 +01:00
|
|
|
{
|
|
|
|
auto noBmpInd1Count = 0;
|
2021-10-01 17:55:44 +02:00
|
|
|
for (auto light : List)
|
2021-01-05 10:02:43 +01:00
|
|
|
{
|
2022-08-24 12:32:35 +02:00
|
|
|
if (!light->LightOnFlag)
|
2021-01-05 10:02:43 +01:00
|
|
|
++noBmpInd1Count;
|
|
|
|
}
|
|
|
|
if (!noBmpInd1Count)
|
|
|
|
break;
|
|
|
|
|
|
|
|
auto randModCount = rand() % noBmpInd1Count;
|
2021-10-01 17:55:44 +02:00
|
|
|
for (auto it = List.rbegin(); it != List.rend(); ++it)
|
2021-01-05 10:02:43 +01:00
|
|
|
{
|
2021-10-01 17:55:44 +02:00
|
|
|
auto light = *it;
|
2022-08-24 12:32:35 +02:00
|
|
|
if (!light->LightOnFlag && randModCount-- == 0)
|
2021-01-05 10:02:43 +01:00
|
|
|
{
|
2022-09-06 15:57:56 +02:00
|
|
|
light->Message(MessageCode::TLightTurnOn, 0.0);
|
2021-01-05 10:02:43 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-06 15:48:09 +02:00
|
|
|
if (MessageField2 != MessageCode::TLightGroupNull)
|
2021-01-05 10:02:43 +01:00
|
|
|
start_animation();
|
|
|
|
break;
|
|
|
|
}
|
2022-09-06 15:48:09 +02:00
|
|
|
case MessageCode::TLightGroupRandomAnimationDesaturation:
|
2021-01-05 10:02:43 +01:00
|
|
|
{
|
|
|
|
auto bmpInd1Count = 0;
|
2021-10-01 17:55:44 +02:00
|
|
|
for (auto light : List)
|
2021-01-05 10:02:43 +01:00
|
|
|
{
|
2022-08-24 12:32:35 +02:00
|
|
|
if (light->LightOnFlag)
|
2021-01-05 10:02:43 +01:00
|
|
|
++bmpInd1Count;
|
|
|
|
}
|
|
|
|
if (!bmpInd1Count)
|
|
|
|
break;
|
|
|
|
|
|
|
|
auto randModCount = rand() % bmpInd1Count;
|
2021-10-01 17:55:44 +02:00
|
|
|
for (auto it = List.rbegin(); it != List.rend(); ++it)
|
2021-01-05 10:02:43 +01:00
|
|
|
{
|
2021-10-01 17:55:44 +02:00
|
|
|
auto light = *it;
|
2022-08-24 12:32:35 +02:00
|
|
|
if (light->LightOnFlag && randModCount-- == 0)
|
2021-01-05 10:02:43 +01:00
|
|
|
{
|
2022-09-06 15:57:56 +02:00
|
|
|
light->Message(MessageCode::TLightTurnOff, 0.0);
|
2021-01-05 10:02:43 +01:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-09-06 15:48:09 +02:00
|
|
|
if (MessageField2 != MessageCode::TLightGroupNull)
|
2021-01-05 10:02:43 +01:00
|
|
|
start_animation();
|
|
|
|
break;
|
|
|
|
}
|
2022-09-06 15:48:09 +02:00
|
|
|
case MessageCode::TLightGroupOffsetAnimationForward:
|
2021-01-05 10:02:43 +01:00
|
|
|
{
|
|
|
|
auto index = next_light_up();
|
|
|
|
if (index < 0)
|
|
|
|
break;
|
2022-09-06 15:57:56 +02:00
|
|
|
List.at(index)->Message(MessageCode::TLightTurnOn, 0.0);
|
2022-09-06 15:48:09 +02:00
|
|
|
if (MessageField2 != MessageCode::TLightGroupNull)
|
2021-01-05 10:02:43 +01:00
|
|
|
start_animation();
|
|
|
|
return 1;
|
|
|
|
}
|
2022-09-06 15:48:09 +02:00
|
|
|
case MessageCode::TLightGroupOffsetAnimationBackward:
|
2021-01-05 10:02:43 +01:00
|
|
|
{
|
|
|
|
auto index = next_light_down();
|
|
|
|
if (index < 0)
|
|
|
|
break;
|
2022-09-06 15:57:56 +02:00
|
|
|
List.at(index)->Message(MessageCode::TLightTurnOff, 0.0);
|
2022-09-06 15:48:09 +02:00
|
|
|
if (MessageField2 != MessageCode::TLightGroupNull)
|
2021-01-05 10:02:43 +01:00
|
|
|
start_animation();
|
|
|
|
return 1;
|
|
|
|
}
|
2022-09-06 15:48:09 +02:00
|
|
|
case MessageCode::TLightGroupReset:
|
2021-01-05 10:02:43 +01:00
|
|
|
{
|
|
|
|
if (Timer)
|
|
|
|
timer::kill(Timer);
|
|
|
|
Timer = 0;
|
2022-09-06 15:48:09 +02:00
|
|
|
if (MessageField2 == MessageCode::TLightGroupAnimationBackward ||
|
|
|
|
MessageField2 == MessageCode::TLightGroupAnimationForward || MessageField2 == MessageCode::TLightGroupLightShowAnimation)
|
2022-09-06 15:57:56 +02:00
|
|
|
TLightGroup::Message(MessageCode::TLightResetTimed, 0.0);
|
2022-09-06 15:48:09 +02:00
|
|
|
MessageField2 = MessageCode::TLightGroupNull;
|
2021-01-05 10:02:43 +01:00
|
|
|
AnimationFlag = 0;
|
|
|
|
break;
|
|
|
|
}
|
2022-09-06 15:48:09 +02:00
|
|
|
case MessageCode::TLightGroupTurnOnAtIndex:
|
2021-01-05 10:02:43 +01:00
|
|
|
{
|
|
|
|
auto index = static_cast<int>(floor(value));
|
2021-10-01 17:55:44 +02:00
|
|
|
if (index >= count || index < 0)
|
2021-01-05 10:02:43 +01:00
|
|
|
break;
|
|
|
|
|
2021-10-01 17:55:44 +02:00
|
|
|
auto light = List.at(index);
|
2022-09-06 15:57:56 +02:00
|
|
|
light->Message(MessageCode::TLightTurnOn, 0.0);
|
2022-09-06 15:48:09 +02:00
|
|
|
if (MessageField2 != MessageCode::TLightGroupNull)
|
2021-01-05 10:02:43 +01:00
|
|
|
start_animation();
|
|
|
|
break;
|
|
|
|
}
|
2022-09-06 15:48:09 +02:00
|
|
|
case MessageCode::TLightGroupTurnOffAtIndex:
|
2021-01-05 10:02:43 +01:00
|
|
|
{
|
|
|
|
auto index = static_cast<int>(floor(value));
|
2021-10-01 17:55:44 +02:00
|
|
|
if (index >= count || index < 0)
|
2021-01-05 10:02:43 +01:00
|
|
|
break;
|
|
|
|
|
2021-10-01 17:55:44 +02:00
|
|
|
auto light = List.at(index);
|
2022-09-06 15:57:56 +02:00
|
|
|
light->Message(MessageCode::TLightTurnOff, 0.0);
|
2022-09-06 15:48:09 +02:00
|
|
|
if (MessageField2 != MessageCode::TLightGroupNull)
|
2021-01-05 10:02:43 +01:00
|
|
|
start_animation();
|
|
|
|
break;
|
|
|
|
}
|
2022-09-06 15:48:09 +02:00
|
|
|
case MessageCode::TLightGroupGetOnCount:
|
2021-01-05 10:02:43 +01:00
|
|
|
{
|
|
|
|
auto bmp1Count = 0;
|
2021-10-01 17:55:44 +02:00
|
|
|
for (auto light : List)
|
2021-01-05 10:02:43 +01:00
|
|
|
{
|
2022-08-24 12:32:35 +02:00
|
|
|
if (light->LightOnFlag)
|
2021-01-21 15:58:05 +01:00
|
|
|
++bmp1Count;
|
2021-01-05 10:02:43 +01:00
|
|
|
}
|
|
|
|
return bmp1Count;
|
|
|
|
}
|
2022-09-06 15:48:09 +02:00
|
|
|
case MessageCode::TLightGroupGetLightCount:
|
2021-10-01 17:55:44 +02:00
|
|
|
return count;
|
2022-09-06 15:48:09 +02:00
|
|
|
case MessageCode::TLightGroupGetMessage2:
|
2022-09-08 09:51:33 +02:00
|
|
|
return static_cast<int>(MessageField2);
|
2022-09-06 15:48:09 +02:00
|
|
|
case MessageCode::TLightGroupGetAnimationFlag:
|
2021-01-05 10:02:43 +01:00
|
|
|
return AnimationFlag;
|
2022-09-06 15:48:09 +02:00
|
|
|
case MessageCode::TLightGroupResetAndTurnOn:
|
2021-01-05 10:02:43 +01:00
|
|
|
{
|
|
|
|
auto index = next_light_up();
|
|
|
|
if (index < 0)
|
|
|
|
break;
|
2022-09-06 15:48:09 +02:00
|
|
|
if (MessageField2 != MessageCode::TLightGroupNull || AnimationFlag)
|
2022-09-06 15:57:56 +02:00
|
|
|
TLightGroup::Message(MessageCode::TLightGroupReset, 0.0);
|
|
|
|
List.at(index)->Message(MessageCode::TLightFlasherStartTimedThenStayOn, value);
|
2021-01-05 10:02:43 +01:00
|
|
|
return 1;
|
|
|
|
}
|
2022-09-06 15:48:09 +02:00
|
|
|
case MessageCode::TLightGroupResetAndTurnOff:
|
2021-01-05 10:02:43 +01:00
|
|
|
{
|
|
|
|
auto index = next_light_down();
|
|
|
|
if (index < 0)
|
|
|
|
break;
|
2022-09-06 15:48:09 +02:00
|
|
|
if (MessageField2 != MessageCode::TLightGroupNull || AnimationFlag)
|
2022-09-06 15:57:56 +02:00
|
|
|
TLightGroup::Message(MessageCode::TLightGroupReset, 0.0);
|
|
|
|
List.at(index)->Message(MessageCode::TLightFlasherStartTimedThenStayOff, value);
|
2021-01-05 10:02:43 +01:00
|
|
|
return 1;
|
|
|
|
}
|
2022-09-06 15:48:09 +02:00
|
|
|
case MessageCode::TLightGroupRestartNotifyTimer:
|
2021-01-05 10:02:43 +01:00
|
|
|
if (NotifyTimer)
|
|
|
|
timer::kill(NotifyTimer);
|
|
|
|
NotifyTimer = 0;
|
2021-02-18 10:53:25 +01:00
|
|
|
if (value > 0.0f)
|
2021-01-05 10:02:43 +01:00
|
|
|
NotifyTimer = timer::set(value, this, NotifyTimerExpired);
|
|
|
|
break;
|
2022-09-06 15:48:09 +02:00
|
|
|
case MessageCode::TLightGroupFlashWhenOn:
|
2021-01-05 10:02:43 +01:00
|
|
|
{
|
2021-10-01 17:55:44 +02:00
|
|
|
for (auto it = List.rbegin(); it != List.rend(); ++it)
|
2021-01-05 10:02:43 +01:00
|
|
|
{
|
2021-10-01 17:55:44 +02:00
|
|
|
auto light = *it;
|
2022-08-24 12:32:35 +02:00
|
|
|
if (light->LightOnFlag)
|
2021-01-05 10:02:43 +01:00
|
|
|
{
|
2022-09-06 15:57:56 +02:00
|
|
|
light->Message(MessageCode::TLightTurnOff, 0.0);
|
|
|
|
light->Message(MessageCode::TLightFlasherStartTimedThenStayOff, value);
|
2021-01-05 10:02:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
break;
|
|
|
|
}
|
2022-09-06 15:48:09 +02:00
|
|
|
case MessageCode::TLightGroupToggleSplitIndex:
|
2021-01-05 10:02:43 +01:00
|
|
|
{
|
2022-09-07 15:01:38 +02:00
|
|
|
control::handler(code, this);
|
2021-01-05 10:02:43 +01:00
|
|
|
auto index = static_cast<int>(floor(value));
|
2021-10-07 13:17:43 +02:00
|
|
|
if (index >= 0 && index < count)
|
2021-01-05 10:02:43 +01:00
|
|
|
{
|
2021-10-07 13:17:43 +02:00
|
|
|
// Turn off lights (index, end]
|
|
|
|
for (auto i = count - 1; i > index; i--)
|
2021-01-05 10:02:43 +01:00
|
|
|
{
|
2022-09-06 15:57:56 +02:00
|
|
|
List.at(i)->Message(MessageCode::TLightResetAndTurnOff, 0.0);
|
2021-10-07 13:17:43 +02:00
|
|
|
}
|
2021-10-01 17:55:44 +02:00
|
|
|
|
2021-10-07 13:17:43 +02:00
|
|
|
// Turn on lights [begin, index]
|
|
|
|
for (auto i = index; i >= 0; i--)
|
|
|
|
{
|
2022-09-06 15:57:56 +02:00
|
|
|
List.at(i)->Message(MessageCode::TLightResetAndTurnOn, 0.0);
|
2021-01-05 10:02:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
2022-09-06 15:48:09 +02:00
|
|
|
case MessageCode::TLightGroupStartFlasher:
|
2021-01-05 10:02:43 +01:00
|
|
|
{
|
|
|
|
auto index = next_light_down();
|
|
|
|
if (index >= 0)
|
|
|
|
{
|
2022-09-06 15:57:56 +02:00
|
|
|
List.at(index)->Message(MessageCode::TLightFlasherStart, 0.0);
|
2021-01-05 10:02:43 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2021-10-01 17:55:44 +02:00
|
|
|
for (auto it = List.rbegin(); it != List.rend(); ++it)
|
2021-01-05 10:02:43 +01:00
|
|
|
{
|
2022-09-06 15:57:56 +02:00
|
|
|
(*it)->Message(code, value);
|
2021-01-05 10:02:43 +01:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TLightGroup::Reset()
|
|
|
|
{
|
|
|
|
if (Timer)
|
|
|
|
timer::kill(Timer);
|
|
|
|
Timer = 0;
|
|
|
|
if (NotifyTimer)
|
|
|
|
timer::kill(NotifyTimer);
|
|
|
|
NotifyTimer = 0;
|
2022-09-06 15:48:09 +02:00
|
|
|
MessageField2 = MessageCode::TLightGroupNull;
|
2021-01-05 10:02:43 +01:00
|
|
|
AnimationFlag = 0;
|
|
|
|
Timer1Time = Timer1TimeDefault;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TLightGroup::reschedule_animation(float time)
|
|
|
|
{
|
|
|
|
if (Timer)
|
|
|
|
timer::kill(Timer);
|
|
|
|
Timer = 0;
|
|
|
|
if (time == 0)
|
|
|
|
{
|
2022-09-06 15:48:09 +02:00
|
|
|
MessageField2 = MessageCode::TLightGroupNull;
|
2021-01-05 10:02:43 +01:00
|
|
|
AnimationFlag = 0;
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-02-18 10:53:25 +01:00
|
|
|
Timer1Time = time > 0.0f ? time : Timer1TimeDefault;
|
2021-01-05 10:02:43 +01:00
|
|
|
Timer = timer::set(Timer1Time, this, TimerExpired);
|
|
|
|
}
|
|
|
|
|
|
|
|
void TLightGroup::start_animation()
|
|
|
|
{
|
2021-10-01 17:55:44 +02:00
|
|
|
for (auto it = List.rbegin(); it != List.rend(); ++it)
|
2021-01-05 10:02:43 +01:00
|
|
|
{
|
2021-10-01 17:55:44 +02:00
|
|
|
auto light = *it;
|
2022-08-24 12:32:35 +02:00
|
|
|
if (light->LightOnFlag)
|
2022-09-06 15:57:56 +02:00
|
|
|
light->Message(MessageCode::TLightTurnOnTimed, 0.0);
|
2021-01-05 10:02:43 +01:00
|
|
|
else
|
2022-09-06 15:57:56 +02:00
|
|
|
light->Message(MessageCode::TLightTurnOffTimed, 0.0);
|
2021-01-05 10:02:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int TLightGroup::next_light_up()
|
|
|
|
{
|
2021-10-01 17:55:44 +02:00
|
|
|
for (auto index = 0u; index < List.size(); ++index)
|
2021-01-05 10:02:43 +01:00
|
|
|
{
|
2022-08-24 12:32:35 +02:00
|
|
|
if (!List[index]->LightOnFlag)
|
2021-10-01 17:55:44 +02:00
|
|
|
return static_cast<int>(index);
|
2021-01-05 10:02:43 +01:00
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int TLightGroup::next_light_down()
|
|
|
|
{
|
2021-10-01 17:55:44 +02:00
|
|
|
for (auto index = static_cast<int>(List.size()) - 1; index >= 0; --index)
|
2021-01-05 10:02:43 +01:00
|
|
|
{
|
2022-08-24 12:32:35 +02:00
|
|
|
if (List.at(index)->LightOnFlag)
|
2021-01-05 10:02:43 +01:00
|
|
|
return index;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
void TLightGroup::TimerExpired(int timerId, void* caller)
|
|
|
|
{
|
|
|
|
auto group = static_cast<TLightGroup*>(caller);
|
|
|
|
group->Timer = 0;
|
2022-09-06 15:57:56 +02:00
|
|
|
group->Message(group->MessageField2, group->Timer1Time);
|
2021-01-05 10:02:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
void TLightGroup::NotifyTimerExpired(int timerId, void* caller)
|
|
|
|
{
|
|
|
|
auto group = static_cast<TLightGroup*>(caller);
|
|
|
|
group->NotifyTimer = 0;
|
2022-09-07 15:01:38 +02:00
|
|
|
control::handler(MessageCode::ControlNotifyTimerExpired, group);
|
2021-01-05 10:02:43 +01:00
|
|
|
}
|