-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlightseq.cpp
1774 lines (1585 loc) · 53.9 KB
/
lightseq.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#include "StdAfx.h"
LightSeq::LightSeq()
{
m_lightseqanim.m_pLightSeq = this;
}
LightSeq::~LightSeq()
{
}
HRESULT LightSeq::Init(PinTable *ptable, float x, float y, bool fromMouseClick)
{
m_ptable = ptable;
m_d.m_v.x = x;
m_d.m_v.y = y;
SetDefaults(fromMouseClick);
return InitVBA(fTrue, 0, NULL);
}
void LightSeq::SetDefaults(bool fromMouseClick)
{
m_d.m_updateinterval = fromMouseClick ? LoadValueIntWithDefault("DefaultProps\\LightSequence", "UpdateInterval", 25) : 25;
char tmp[MAXNAMEBUFFER];
const HRESULT hr = LoadValueString("DefaultProps\\LightSequence", "Collection", tmp, MAXNAMEBUFFER);
if ((hr != S_OK) || !fromMouseClick)
m_d.m_wzCollection[0] = 0x00;
else
{
UNICODE_FROM_ANSI(m_d.m_wzCollection, tmp, lstrlen(tmp));
m_d.m_wzCollection[lstrlen(tmp)] = '\0';
}
m_d.m_vCenter.x = fromMouseClick ? LoadValueFloatWithDefault("DefaultProps\\LightSequence", "CenterX", EDITOR_BG_WIDTH / 2) : (EDITOR_BG_WIDTH / 2);
m_d.m_vCenter.y = fromMouseClick ? LoadValueFloatWithDefault("DefaultProps\\LightSequence", "CenterY", (2 * EDITOR_BG_WIDTH) / 2) : ((2 * EDITOR_BG_WIDTH) / 2);
m_d.m_tdr.m_TimerEnabled = fromMouseClick ? LoadValueBoolWithDefault("DefaultProps\\LightSequence", "TimerEnabled", false) : false;
m_d.m_tdr.m_TimerInterval = fromMouseClick ? LoadValueIntWithDefault("DefaultProps\\LightSequence", "TimerInterval", 100) : 100;
}
void LightSeq::WriteRegDefaults()
{
MAKE_ANSIPTR_FROMWIDE(strTmp, (WCHAR *)m_d.m_wzCollection);
SaveValueInt("DefaultProps\\LightSequence", "UpdateInterval", m_d.m_updateinterval);
SaveValueString("DefaultProps\\LightSequence", "Collection", strTmp);
SaveValueFloat("DefaultProps\\LightSequence", "CenterX", m_d.m_vCenter.x);
SaveValueFloat("DefaultProps\\LightSequence", "CenterY", m_d.m_vCenter.y);
SaveValueBool("DefaultProps\\LightSequence", "TimerEnabled", m_d.m_tdr.m_TimerEnabled);
SaveValueInt("DefaultProps\\LightSequence", "TimerInterval", m_d.m_tdr.m_TimerInterval);
}
void LightSeq::SetObjectPos()
{
g_pvp->SetObjectPosCur(m_d.m_v.x, m_d.m_v.y);
}
void LightSeq::MoveOffset(const float dx, const float dy)
{
m_d.m_v.x += dx;
m_d.m_v.y += dy;
}
Vertex2D LightSeq::GetCenter() const
{
return m_d.m_v;
}
void LightSeq::PutCenter(const Vertex2D& pv)
{
m_d.m_v = pv;
}
// this function draws the shape of the object with a solid fill
// only used in the editor and not the game
//
// this is called before the grid lines are drawn on the map
//
void LightSeq::UIRenderPass1(Sur * const psur)
{
psur->SetBorderColor(RGB(0, 0, 0), false, 0);
psur->SetObject(this);
for (int i = 0; i < 8; ++i)
{
psur->SetFillColor((i % 2 == 0) ? RGB(255, 0, 0) : RGB(128, 0, 0));
const float angle = (float)((M_PI*2.0) / 8.0)*(float)i;
const float sn = sinf(angle);
const float cs = cosf(angle);
psur->Ellipse(m_d.m_v.x + sn*12.0f, m_d.m_v.y - cs*12.0f, 4.0f);
}
psur->SetFillColor(RGB(255, 0, 0));
psur->Ellipse(m_d.m_v.x, m_d.m_v.y - 3.0f, 4.0f);
}
// this function draws the shape of the object with a black outline (no solid fill)
// only used in the editor and not the game
//
// this is called after the grid lines have been drawn on the map. draws a solid
// outline over the grid lines
//
void LightSeq::UIRenderPass2(Sur * const psur)
{
psur->SetFillColor(-1);
psur->SetBorderColor(RGB(0, 0, 0), false, 0);
psur->SetObject(this);
psur->Ellipse(m_d.m_v.x, m_d.m_v.y, 18.0f);
for (int i = 0; i < 8; ++i)
{
const float angle = (float)((M_PI*2.0) / 8.0)*(float)i;
const float sn = sinf(angle);
const float cs = cosf(angle);
psur->Ellipse(m_d.m_v.x + sn*12.0f, m_d.m_v.y - cs*12.0f, 4.0f);
}
psur->Ellipse(m_d.m_v.x, m_d.m_v.y - 3.0f, 4.0f);
RenderOutline(psur);
}
// this function draw the little center marker which is a cross with the usual LS circles on it
void LightSeq::RenderOutline(Sur * const psur)
{
psur->SetBorderColor(RGB(0, 0, 0), false, 0);
psur->SetObject((ISelect *)this);
psur->Line(m_d.m_vCenter.x - 10.0f, m_d.m_vCenter.y, m_d.m_vCenter.x + 10.0f, m_d.m_vCenter.y);
psur->Line(m_d.m_vCenter.x, m_d.m_vCenter.y - 10.0f, m_d.m_vCenter.x, m_d.m_vCenter.y + 10.0f);
for (int i = 0; i < 8; ++i)
{
psur->SetFillColor((i % 2 == 0) ? RGB(255, 0, 0) : RGB(128, 0, 0));
const float angle = (float)((M_PI*2.0) / 8.0)*(float)i;
const float sn = sinf(angle);
const float cs = cosf(angle);
psur->Ellipse(m_d.m_vCenter.x + sn*7.0f, m_d.m_vCenter.y - cs*7.0f, 2.0f);
}
psur->SetFillColor(RGB(255, 0, 0));
psur->Ellipse(m_d.m_vCenter.x, m_d.m_vCenter.y - 2.5f, 2.0f);
}
// Renders the image onto the Blueprint
//
// We don't want this on the blue print as it is non-essensial
//
void LightSeq::RenderBlueprint(Sur *psur, const bool solid)
{
}
// Registers the timer with the game call which then makes a call back when the interval
// has expired.
//
// for this sort of object it is basically not really required but hey, somebody might use it..
//
void LightSeq::GetTimers(vector<HitTimer*> &pvht)
{
HitTimer * const pht = new HitTimer();
pht->m_interval = m_d.m_tdr.m_TimerInterval >= 0 ? max(m_d.m_tdr.m_TimerInterval, MAX_TIMER_MSEC_INTERVAL) : -1;
pht->m_nextfire = pht->m_interval;
pht->m_pfe = (IFireEvents *)this;
m_phittimer = pht;
if (m_d.m_tdr.m_TimerEnabled)
pvht.push_back(pht);
}
void LightSeq::GetHitShapes(vector<HitObject*> &pvho)
{
}
void LightSeq::GetHitShapesDebug(vector<HitObject*> &pvho)
{
}
// This method is called as the game exits..
// it cleans up any allocated memory used by the instace of the object
//
void LightSeq::EndPlay()
{
if (m_pgridData != NULL)
{
delete[] m_pgridData;
m_pgridData = NULL;
}
IEditable::EndPlay();
}
void LightSeq::RenderDynamic()
{
}
void LightSeq::RenderSetup()
{
// zero pointers as a safe guard
m_pcollection = NULL;
m_pgridData = NULL;
// no animation in progress
m_playInProgress = false;
m_pauseInProgress = false;
// turn off any tracers
m_th1.type = eSeqNull;
m_th2.type = eSeqNull;
m_tt1.type = eSeqNull;
m_tt2.type = eSeqNull;
// flush the queue
m_queue.Head = 0;
m_queue.Tail = 0;
// get a BSTR version of the collection we are to use
CComBSTR bstrCollection = m_d.m_wzCollection;
// get the number of collections available
int size = m_ptable->m_vcollection.Size();
for (int i = 0; i < size; ++i)
{
// get the name of this collection
CComBSTR bstr;
m_ptable->m_vcollection.ElementAt(i)->get_Name(&bstr);
// is it the one we are to use?
if (WideStrCmp(bstr, bstrCollection) == 0)
{
// yep, set a pointer to this sub-collection
m_pcollection = m_ptable->m_vcollection.ElementAt(i);
break;
}
}
// if the collection wasn't found or there are no collections available then bomb out
if (m_pcollection == NULL)
return;
// get the grid demensions (from the table size)
const float tablewidth = m_ptable->m_right - m_ptable->m_left;
const float tableheight = m_ptable->m_bottom - m_ptable->m_top;
m_lightSeqGridWidth = (int)tablewidth / LIGHTSEQGRIDSCALE;
m_lightSeqGridHeight = (int)tableheight / LIGHTSEQGRIDSCALE;
// set the centre point of the grid for effects which start from the center
m_GridXCenter = floorf(m_d.m_vCenter.x * (float)(1.0 / LIGHTSEQGRIDSCALE));
m_GridYCenter = floorf(m_d.m_vCenter.y * (float)(1.0 / LIGHTSEQGRIDSCALE));
m_GridXCenterAdjust = abs(m_lightSeqGridWidth / 2 - (int)m_GridXCenter);
m_GridYCenterAdjust = abs(m_lightSeqGridHeight / 2 - (int)m_GridYCenter);
// allocate the grid for this sequence
m_pgridData = new short[m_lightSeqGridHeight*m_lightSeqGridWidth];
if (m_pgridData == NULL)
{
// make the entire collection (for the sequencer) invalid and bomb out
m_pcollection = NULL;
return;
}
else
ZeroMemory((void *)m_pgridData, (size_t)((m_lightSeqGridHeight*m_lightSeqGridWidth)*sizeof(short)));
// get the number of elements (objects) in the collection (referenced by m_visel)
size = m_pcollection->m_visel.Size();
// go though the collection and get the cordinates of all the lights
for (int i = 0; i < size; ++i)
{
// get the type of object
const ItemTypeEnum type = m_pcollection->m_visel.ElementAt(i)->GetIEditable()->GetItemType();
// must be a light
if (type == eItemLight)
{
float x, y;
// process a light
Light * const pLight = (Light *)m_pcollection->m_visel.ElementAt(i);
pLight->get_X(&x);
pLight->get_Y(&y);
if (pLight->m_backglass)
{
// if the light is on the backglass then scale up its Y position
y *= 2.666f; // 2 little devils ;-)
}
// scale down to suit the size of the light sequence grid
const unsigned int ix = (int)(x * (float)(1.0 / LIGHTSEQGRIDSCALE));
const unsigned int iy = (int)(y * (float)(1.0 / LIGHTSEQGRIDSCALE));
// if on the playfield
if ( /*(ix >= 0) &&*/ (ix < (unsigned int)m_lightSeqGridWidth) && //>=0 handled by unsigned int
/*(iy >= 0) &&*/ (iy < (unsigned int)m_lightSeqGridHeight)) //>=0 handled by unsigned int
{
const int gridIndex = iy * m_lightSeqGridWidth + ix;
// then store the index offset into the grid (plus 1, 0 is no object)
m_pgridData[gridIndex] = i + 1;
}
}
}
}
void LightSeq::RenderStatic()
{
}
// This function is called during Animate(). It basically checks to see if the update
// interval has expired and if so handles the light effect
void LightSeq::Animate()
{
if (m_playInProgress)
{
while (g_pplayer->m_time_msec >= m_timeNextUpdate && m_playInProgress)
{
if (!m_pauseInProgress)
{
m_timeNextUpdate += m_updateRate;
// process the head tracers
const bool th1finished = ProcessTracer(&m_th1, LightStateOn);
const bool th2finished = ProcessTracer(&m_th2, LightStateOn);
// and any tail tracers
const bool tt1finished = ProcessTracer(&m_tt1, LightStateOff);
const bool tt2finished = ProcessTracer(&m_tt2, LightStateOff);
// has the animation finished
if (th1finished && th2finished && tt1finished && tt2finished)
{
// the sequence has finished, paused for the specified value or a single interval
// (bit of a breather or load balance)
m_timeNextUpdate = g_pplayer->m_time_msec + max(m_updateRate, m_pauseValue);
m_pauseInProgress = true;
}
}
else
{
// test the remaining replays?
m_replayCount--;
if (m_replayCount != 0)
{
// if not zero then restart the same animation again
SetupTracers(m_playAnimation, m_tailLength, m_replayCount, m_pauseValue);
}
else
{
// move the tail to the next position
++m_queue.Tail;
if (m_queue.Tail >= LIGHTSEQQUEUESIZE)
m_queue.Tail = 0;
// not playing at the moment
m_playInProgress = false;
// if the queue is empty then reset the lights to their real state
if (m_queue.Head == m_queue.Tail)
{
StopPlay();
// and signal the script ( Sub <LIGHTSEQNAME>_PlayDone() )
FireVoidEvent(DISPID_LightSeqEvents_PlayDone);
}
}
}
}
}
else
{
// is there something in the queue?
if (m_queue.Head != m_queue.Tail)
{
// yes
const int Tail = m_queue.Tail;
// set the update rate for this sequence
m_updateRate = m_queue.Data[Tail].UpdateRate;
// set up the tracers and start the ball rolling again
SetupTracers(m_queue.Data[Tail].Animation,
m_queue.Data[Tail].TailLength,
m_queue.Data[Tail].Repeat,
m_queue.Data[Tail].Pause);
}
}
}
STDMETHODIMP LightSeq::InterfaceSupportsErrorInfo(REFIID riid)
{
static const IID* arr[] =
{
&IID_ILightSeq,
};
for (int i = 0; i < sizeof(arr) / sizeof(arr[0]); ++i)
{
if (InlineIsEqualGUID(*arr[i], riid))
return S_OK;
}
return S_FALSE;
}
HRESULT LightSeq::SaveData(IStream *pstm, HCRYPTHASH hcrypthash, const bool backupForPlay)
{
BiffWriter bw(pstm, hcrypthash);
bw.WriteStruct(FID(VCEN), &m_d.m_v, sizeof(Vertex2D));
bw.WriteWideString(FID(COLC), (WCHAR *)m_d.m_wzCollection);
bw.WriteFloat(FID(CTRX), m_d.m_vCenter.x);
bw.WriteFloat(FID(CTRY), m_d.m_vCenter.y);
bw.WriteInt(FID(UPTM), m_d.m_updateinterval);
bw.WriteBool(FID(TMON), m_d.m_tdr.m_TimerEnabled);
bw.WriteInt(FID(TMIN), m_d.m_tdr.m_TimerInterval);
bw.WriteWideString(FID(NAME), (WCHAR *)m_wzName);
bw.WriteBool(FID(BGLS), m_backglass);
bw.WriteTag(FID(ENDB));
return S_OK;
}
HRESULT LightSeq::InitLoad(IStream *pstm, PinTable *ptable, int *pid, int version, HCRYPTHASH hcrypthash, HCRYPTKEY hcryptkey)
{
SetDefaults(false);
BiffReader br(pstm, this, pid, version, hcrypthash, hcryptkey);
m_ptable = ptable;
br.Load();
return S_OK;
}
bool LightSeq::LoadToken(const int id, BiffReader * const pbr)
{
switch(id)
{
case FID(PIID): pbr->GetInt((int *)pbr->m_pdata); break;
case FID(VCEN): pbr->GetStruct(&m_d.m_v, sizeof(Vertex2D)); break;
case FID(COLC): pbr->GetWideString((WCHAR *)m_d.m_wzCollection); break;
case FID(CTRX): pbr->GetFloat(&m_d.m_vCenter.x); break;
case FID(CTRY): pbr->GetFloat(&m_d.m_vCenter.y); break;
case FID(UPTM): pbr->GetInt(&m_d.m_updateinterval); break;
case FID(TMON): pbr->GetBool(&m_d.m_tdr.m_TimerEnabled); break;
case FID(TMIN): pbr->GetInt(&m_d.m_tdr.m_TimerInterval); break;
case FID(NAME): pbr->GetWideString((WCHAR *)m_wzName); break;
case FID(BGLS): pbr->GetBool(&m_backglass); break;
}
return true;
}
HRESULT LightSeq::InitPostLoad()
{
return S_OK;
}
STDMETHODIMP LightSeq::get_Collection(BSTR *pVal)
{
WCHAR wz[sizeof(m_d.m_wzCollection)];
memcpy(wz, m_d.m_wzCollection, sizeof(m_d.m_wzCollection));
*pVal = SysAllocString(wz);
return S_OK;
}
STDMETHODIMP LightSeq::put_Collection(BSTR newVal)
{
memcpy(m_d.m_wzCollection, (void *)newVal, sizeof(m_d.m_wzCollection));
return S_OK;
}
STDMETHODIMP LightSeq::get_CenterX(float *pVal)
{
*pVal = GetX();
return S_OK;
}
STDMETHODIMP LightSeq::put_CenterX(float newVal)
{
if ((newVal < 0.f) || (newVal >= (float)EDITOR_BG_WIDTH))
return E_FAIL;
SetX(newVal);
return S_OK;
}
STDMETHODIMP LightSeq::get_CenterY(float *pVal)
{
*pVal = GetY();
return S_OK;
}
STDMETHODIMP LightSeq::put_CenterY(float newVal)
{
if ((newVal < 0.f) || (newVal >= (float)(2 * EDITOR_BG_WIDTH)))
return E_FAIL;
SetY(newVal);
return S_OK;
}
STDMETHODIMP LightSeq::get_UpdateInterval(long *pVal)
{
*pVal = GetUpdateInterval();
return S_OK;
}
STDMETHODIMP LightSeq::put_UpdateInterval(long newVal)
{
SetUpdateInterval(newVal);
return S_OK;
}
STDMETHODIMP LightSeq::Play(SequencerState Animation, long TailLength, long Repeat, long Pause)
{
HRESULT rc = S_OK;
// sanity check the parameters
if (TailLength < 0)
{
TailLength = 0;
}
if (Repeat <= 0)
{
Repeat = 1;
}
if (Pause < 0)
{
Pause = 0;
}
// 'all lights on' and 'all lights off' are directly processed and not put into the queue
if (Animation == SeqAllOn)
{
// turn on all lights
SetAllLightsToState(LightStateOn);
}
else
{
if (Animation == SeqAllOff)
{
// turn off all lights
SetAllLightsToState(LightStateOff);
}
else
{
// move the head of the queue to the next position
int newHead = m_queue.Head + 1;
// handle the wrap around (circlular queue)
if (newHead >= LIGHTSEQQUEUESIZE)
{
newHead = 0;
}
// if the queue is full, then bomb out
if (newHead == m_queue.Tail)
{
rc = E_FAIL;
}
else
{
// else load up the queue
m_queue.Data[m_queue.Head].Animation = Animation;
m_queue.Data[m_queue.Head].TailLength = TailLength;
m_queue.Data[m_queue.Head].Repeat = Repeat;
m_queue.Data[m_queue.Head].Pause = Pause;
m_queue.Data[m_queue.Head].UpdateRate = m_d.m_updateinterval;
m_queue.Head = newHead;
}
}
}
return rc;
}
STDMETHODIMP LightSeq::StopPlay()
{
// no animation in progress
m_playInProgress = false;
m_pauseInProgress = false;
// turn off any tracers
m_th1.type = eSeqNull;
m_th2.type = eSeqNull;
m_tt1.type = eSeqNull;
m_tt2.type = eSeqNull;
// flush the queue
m_queue.Head = 0;
m_queue.Tail = 0;
// Reset lights back to original state
if (m_pcollection != NULL)
{
const int size = m_pcollection->m_visel.Size();
for (int i = 0; i < size; ++i)
{
const ItemTypeEnum type = m_pcollection->m_visel.ElementAt(i)->GetIEditable()->GetItemType();
if (type == eItemLight)
{
Light * const pLight = (Light *)m_pcollection->m_visel.ElementAt(i);
LightState state;
pLight->get_State(&state);
pLight->m_lockedByLS = false;
pLight->put_State(state);
}
}
}
return S_OK;
}
void LightSeq::SetupTracers(const SequencerState Animation, long TailLength, long Repeat, long Pause)
{
bool inverse = false;
// no animation in progress
m_playInProgress = false;
m_pauseInProgress = false;
// turn off any tracers
m_th1.type = eSeqNull;
m_th2.type = eSeqNull;
m_tt1.type = eSeqNull;
m_tt2.type = eSeqNull;
// remember the current sequence (before it gets altered)
m_playAnimation = Animation;
m_tailLength = TailLength;
m_replayCount = Repeat;
m_pauseValue = Pause;
switch (Animation)
{
// blink all lights on and off
case SeqBlinking:
m_th1.type = eSeqBlink;
m_th1.length = 0;
m_th1.frameCount = 2;
break;
// Randomly turn lights on and off for the pause period
case SeqRandom:
m_th1.type = eSeqRandom;
m_th1.length = TailLength;
m_th1.frameCount = Pause / m_updateRate;
// no repeat or pause for this effect and certainly no tail
TailLength = 0;
Repeat = 1;
Pause = 0;
m_tailLength = TailLength;
m_replayCount = Repeat;
m_pauseValue = Pause;
break;
// Turn on all lights starting at the bottom of the playfield and moving up
case SeqUpOff:
inverse = true;
case SeqUpOn:
m_th1.type = eSeqLine;
m_th1.x = 0;
m_th1.stepX = 0;
m_th1.processStepX = 1.0f;
m_th1.y = (float)(m_lightSeqGridHeight - 1);
m_th1.stepY = -1.0f;
m_th1.processStepY = 0;
m_th1.length = m_lightSeqGridWidth;
m_th1.frameCount = m_lightSeqGridHeight;
break;
// Turn on all lights starting at the top of the playfield and moving down
case SeqDownOff:
inverse = true;
case SeqDownOn:
m_th1.type = eSeqLine;
m_th1.x = 0;
m_th1.stepX = 0;
m_th1.processStepX = 1.0f;
m_th1.y = 0;
m_th1.stepY = 1.0f;
m_th1.processStepY = 0;
m_th1.length = m_lightSeqGridWidth;
m_th1.frameCount = m_lightSeqGridHeight;
break;
// Turn on all lights starting at the left of the playfield and moving right
case SeqRightOff:
inverse = true;
case SeqRightOn:
m_th1.type = eSeqLine;
m_th1.x = 0;
m_th1.stepX = 1.0f;
m_th1.processStepX = 0;
m_th1.y = 0;
m_th1.stepY = 0;
m_th1.processStepY = 1.0f;
m_th1.length = m_lightSeqGridHeight;
m_th1.frameCount = m_lightSeqGridWidth;
TailLength /= 2;
break;
// Turn on all lights starting at the right of the playfield and moving left
case SeqLeftOff:
inverse = true;
case SeqLeftOn:
m_th1.type = eSeqLine;
m_th1.x = (float)(m_lightSeqGridWidth - 1);
m_th1.stepX = -1.0f;
m_th1.processStepX = 0;
m_th1.y = 0;
m_th1.stepY = 0;
m_th1.processStepY = 1.0f;
m_th1.length = m_lightSeqGridHeight;
m_th1.frameCount = m_lightSeqGridWidth;
TailLength /= 2;
break;
// Turn on all lights starting at the bottom/left of the playfield and diagonally up
case SeqDiagUpRightOff:
inverse = true;
case SeqDiagUpRightOn:
m_th1.type = eSeqLine;
m_th1.x = 0;
m_th1.stepX = 0;
m_th1.processStepX = 0.5f;
m_th1.y = (float)m_lightSeqGridHeight - 1;
m_th1.stepY = -1.0f;
m_th1.processStepY = 1.0f;
m_th1.length = m_lightSeqGridWidth * 2;
m_th1.frameCount = m_lightSeqGridHeight + (m_lightSeqGridWidth * 2);
break;
// Turn on all lights starting at the bottom/right of the playfield and diagonally up
case SeqDiagUpLeftOff:
inverse = true;
case SeqDiagUpLeftOn:
m_th1.type = eSeqLine;
m_th1.x = (float)(m_lightSeqGridWidth - 1);
m_th1.stepX = 0;
m_th1.processStepX = -0.5f;
m_th1.y = (float)(m_lightSeqGridHeight - 1);
m_th1.stepY = -1.0f;
m_th1.processStepY = 1.0f;
m_th1.length = m_lightSeqGridWidth * 2;
m_th1.frameCount = m_lightSeqGridHeight + (m_lightSeqGridWidth * 2);
break;
// Turn on all lights starting at the top/left of the playfield and diagonally down
case SeqDiagDownRightOff:
inverse = true;
case SeqDiagDownRightOn:
m_th1.type = eSeqLine;
m_th1.x = 0;
m_th1.stepX = 0;
m_th1.processStepX = 0.5f;
m_th1.y = 0;
m_th1.stepY = 1.0f;
m_th1.processStepY = -1.0f;
m_th1.length = m_lightSeqGridWidth * 2;
m_th1.frameCount = m_lightSeqGridHeight + (m_lightSeqGridWidth * 2);
break;
// Turn on all lights starting at the top/right of the playfield and diagonally down
case SeqDiagDownLeftOff:
inverse = true;
case SeqDiagDownLeftOn:
m_th1.type = eSeqLine;
m_th1.x = (float)(m_lightSeqGridWidth - 1);
m_th1.stepX = 0;
m_th1.processStepX = -0.5f;
m_th1.y = 0;
m_th1.stepY = 1.0f;
m_th1.processStepY = -1.0f;
m_th1.length = m_lightSeqGridWidth * 2;
m_th1.frameCount = m_lightSeqGridHeight + (m_lightSeqGridWidth * 2);
break;
// Turn on all lights starting in the middle and moving outwards to the side edges
case SeqMiddleOutHorizOff:
inverse = true;
case SeqMiddleOutHorizOn:
m_th1.type = eSeqLine;
m_th1.x = m_GridXCenter - 1.0f;
m_th1.stepX = -1.0f;
m_th1.processStepX = 0;
m_th1.y = 0;
m_th1.stepY = 0;
m_th1.processStepY = 1.0f;
m_th1.length = m_lightSeqGridHeight;
m_th1.frameCount = m_lightSeqGridWidth / 2 + m_GridXCenterAdjust;
m_th2.type = eSeqLine;
m_th2.x = m_GridXCenter;
m_th2.stepX = 1.0f;
m_th2.processStepX = 0;
m_th2.y = 0;
m_th2.stepY = 0;
m_th2.processStepY = 1.0f;
m_th2.length = m_lightSeqGridHeight;
m_th2.frameCount = m_lightSeqGridWidth / 2 + m_GridXCenterAdjust;
TailLength /= 4;
break;
// Turn on all lights starting on the side edges and moving into the middle
case SeqMiddleInHorizOff:
inverse = true;
case SeqMiddleInHorizOn:
{
const float effectlength = (float)(m_lightSeqGridWidth / 2 + m_GridXCenterAdjust);
m_th1.type = eSeqLine;
m_th1.x = m_GridXCenter - effectlength;
m_th1.stepX = 1.0f;
m_th1.processStepX = 0;
m_th1.y = 0;
m_th1.stepY = 0;
m_th1.processStepY = 1.0f;
m_th1.length = m_lightSeqGridHeight;
m_th1.frameCount = (int)effectlength + 1;
m_th2.type = eSeqLine;
m_th2.x = m_GridXCenter + effectlength;
m_th2.stepX = -1.0f;
m_th2.processStepX = 0;
m_th2.y = 0;
m_th2.stepY = 0;
m_th2.processStepY = 1.0f;
m_th2.length = m_lightSeqGridHeight;
m_th2.frameCount = (int)effectlength;
TailLength /= 4;
}
break;
// Turn on all lights starting in the middle and moving outwards to the top and bottom
case SeqMiddleOutVertOff:
inverse = true;
case SeqMiddleOutVertOn:
m_th1.type = eSeqLine;
m_th1.x = 0;
m_th1.stepX = 0;
m_th1.processStepX = 1.0f;
m_th1.y = m_GridYCenter - 1.0f;
m_th1.stepY = -1;
m_th1.processStepY = 0;
m_th1.length = m_lightSeqGridWidth;
m_th1.frameCount = m_lightSeqGridHeight / 2 + m_GridYCenterAdjust;
m_th2.type = eSeqLine;
m_th2.x = 0;
m_th2.stepX = 0;
m_th2.processStepX = 1.0f;
m_th2.y = m_GridYCenter;
m_th2.stepY = 1.0f;
m_th2.processStepY = 0;
m_th2.length = m_lightSeqGridWidth;
m_th2.frameCount = m_lightSeqGridHeight / 2 + m_GridYCenterAdjust;
TailLength /= 2;
break;
// Turn on all lights starting on the top and bottom edges and moving inwards to the middle
case SeqMiddleInVertOff:
inverse = true;
case SeqMiddleInVertOn:
{
const float effectlength = (float)(m_lightSeqGridHeight / 2 + m_GridYCenterAdjust);
m_th1.type = eSeqLine;
m_th1.x = 0;
m_th1.stepX = 0;
m_th1.processStepX = 1.0f;
m_th1.y = m_GridYCenter - effectlength;
m_th1.stepY = 1.0f;
m_th1.processStepY = 0;
m_th1.length = m_lightSeqGridWidth;
m_th1.frameCount = (int)effectlength + 1;
m_th2.type = eSeqLine;
m_th2.x = 0;
m_th2.stepX = 0;
m_th2.processStepX = 1.0f;
m_th2.y = m_GridYCenter + effectlength;
m_th2.stepY = -1.0f;
m_th2.processStepY = 0;
m_th2.length = m_lightSeqGridWidth;
m_th2.frameCount = (int)effectlength;
TailLength /= 2;
}
break;
// top half of the playfield wipes on to the right while the bottom half wipes on to the left
case SeqStripe1HorizOff:
inverse = true;
case SeqStripe1HorizOn:
m_th1.type = eSeqLine;
m_th1.x = 0;
m_th1.stepX = 1.0f;
m_th1.processStepX = 0;
m_th1.y = m_GridYCenter - 1.0f;
m_th1.stepY = 0;
m_th1.processStepY = -1.0f;
m_th1.length = m_lightSeqGridHeight / 2 + m_GridYCenterAdjust;
m_th1.frameCount = m_lightSeqGridWidth;
m_th2.type = eSeqLine;
m_th2.x = (float)(m_lightSeqGridWidth - 1);
m_th2.stepX = -1.0f;
m_th2.processStepX = 0;
m_th2.y = m_GridYCenter;
m_th2.stepY = 0;
m_th2.processStepY = 1.0f;
m_th2.length = m_lightSeqGridHeight / 2 + m_GridXCenterAdjust;
m_th2.frameCount = m_lightSeqGridWidth;
TailLength /= 2;
break;
// top half of the playfield wipes on to the left while the bottom half wipes on to the right
case SeqStripe2HorizOff:
inverse = true;
case SeqStripe2HorizOn:
m_th1.type = eSeqLine;
m_th1.x = (float)(m_lightSeqGridWidth - 1);
m_th1.stepX = -1.0f;
m_th1.processStepX = 0;
m_th1.y = m_GridYCenter - 1.0f;
m_th1.stepY = 0;
m_th1.processStepY = -1.0f;
m_th1.length = m_lightSeqGridHeight / 2 + m_GridYCenterAdjust;
m_th1.frameCount = m_lightSeqGridWidth;
m_th2.type = eSeqLine;
m_th2.x = 0;
m_th2.stepX = 1.0f;
m_th2.processStepX = 0;
m_th2.y = m_GridYCenter;
m_th2.stepY = 0;
m_th2.processStepY = 1.0f;
m_th2.length = m_lightSeqGridHeight / 2 + m_GridYCenterAdjust;
m_th2.frameCount = m_lightSeqGridWidth;
TailLength /= 2;
break;
// left side of the playfield wipes on going up while the right side wipes on doing down
case SeqStripe1VertOff:
inverse = true;
case SeqStripe1VertOn:
m_th1.type = eSeqLine;
m_th1.x = m_GridXCenter - 1.0f;
m_th1.stepX = 0;
m_th1.processStepX = -1.0f;
m_th1.y = (float)(m_lightSeqGridHeight - 1);
m_th1.stepY = -1.0f;
m_th1.processStepY = 0;
m_th1.length = m_lightSeqGridWidth / 2 + m_GridXCenterAdjust;
m_th1.frameCount = m_lightSeqGridHeight;
m_th2.type = eSeqLine;
m_th2.x = m_GridXCenter;
m_th2.stepX = 0;
m_th2.processStepX = 1.0f;
m_th2.y = 0;
m_th2.stepY = 1.0f;
m_th2.processStepY = 0;
m_th2.length = m_lightSeqGridWidth / 2 + m_GridXCenterAdjust;
m_th2.frameCount = m_lightSeqGridHeight;
break;
// left side of the playfield wipes on going down while the right side wipes on doing up
case SeqStripe2VertOff:
inverse = true;
case SeqStripe2VertOn:
m_th1.type = eSeqLine;
m_th1.x = m_GridXCenter - 1.0f;
m_th1.stepX = 0;
m_th1.processStepX = -1.0f;
m_th1.y = 0;
m_th1.stepY = 1.0f;
m_th1.processStepY = 0;
m_th1.length = m_lightSeqGridWidth / 2 + m_GridXCenterAdjust;
m_th1.frameCount = m_lightSeqGridHeight;
m_th2.type = eSeqLine;
m_th2.x = m_GridXCenter;
m_th2.stepX = 0;
m_th2.processStepX = 1.0f;
m_th2.y = (float)(m_lightSeqGridHeight - 1);
m_th2.stepY = -1.0f;
m_th2.processStepY = 0;
m_th2.length = m_lightSeqGridWidth / 2 + m_GridXCenterAdjust;
m_th2.frameCount = m_lightSeqGridHeight;
break;
// turn lights on, cross-hatch with even lines going right and odd lines going left
case SeqHatch1HorizOff:
inverse = true;
case SeqHatch1HorizOn:
m_th1.type = eSeqLine;
m_th1.x = 0;
m_th1.stepX = 1.0f;
m_th1.processStepX = 0;
m_th1.y = 0;
m_th1.stepY = 0;