This repository has been archived by the owner on Dec 1, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ArPlay.lua
1399 lines (1261 loc) · 37.7 KB
/
ArPlay.lua
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
-- Aerials/Pragma/ArPlay.script
go.property("fumen_id", 0)
go.property("sound_speed", 1)
go.property("display_losts", false)
go.property("options", false)
---------------- Important Note ----------------
--
--
-- A.Steps Before Creating An ArPlay Instance
--
-- I.Register Components of Current Song. Check ArState for Details.
-- Ar__current_song_id = false
-- Ar__current_plate = false
-- Ar__current_sound = false
-- Ar__current_illust = false
--
-- II.Set Dimfunc and Dedimfunc Following the Template below.
-- function ArTr__dimfunc()
-- -- Loads the Arf File.
-- local fm_string = sys.load_resource(WHICH_CHART)
-- local fm_func = loadstring(demofm_string)
-- Ar__fumens = fm_func() -- For multiple Arfs: {Arf1,Arf2,···}
-- demofm_string = nil
-- demofm_func = nil
-- -- For multiple Arfs, Specify the Fumen Id for Each Arf.
-- sound.stop(Ar__current_sound)
-- factory.create("Ar:/Pragma#ArcPlay",_,_,{sound_speed = SOUND_SPEED, display_losts = true, options=true})
-- end
--
-- function ArTr__dedimfunc()
-- -- Records the Init Time.
-- Ar__init_time = socket.gettime() * 1000
-- Ar__paused_time = 0
-- sound.play(Ar__current_sound)
-- end
--
-- III.Dim Down.
-- ArTr__dim()
--
--
-- B.Traits to be Implemented
--
-- ArPlay Properties:
-- ◆ Multiinstance with Fumen Id
-- ◆ Sound Speed [0.2,3)
-- -- Supports Changing Sound Speed At Runtime:
-- if Ar__arplays[1]>0 then
-- for i=3,Ar__arplays[2] do
-- if Ar__arplays[i] then msg.post(Ar__arplays[i], "ar_sound_speed", {VALUE}) end
-- end
-- end
-- ◆ Optional Lost Counter
-- ◆ Options Panel
--
-- ArPlay Built-in:
-- ◇ Another
-- A. Display Another Wish/Hint
-- B. Terminate Unselected ArPlay Instance
-- ◆ ArIf Array
-- {2,mstime1,false,mstime2,"Won't Show the Score"}
-- ◆ Camera Array
-- See the Function ArCamera()
-- ◆ DTime Array
-- See the Function ArDTime()
-- After Enabling this Trait, Make the WishIndex Distributed by DTime.
--
-- In the Plate:
-- ◆ Toggle DayMode
-- if Ar__arplays[3] then msg.post(Ar__arplays[3], "ar_toggle_daymode") end
-- ◇ Optional Illust Tint Effect
-- ◇ Attach Script Component with ArPlay's Message Posting
--
-- -- In Arf
-- Arf.Info.Traits.Attach = hash("Spec")
--
-- -- In Plate#Spec
-- function on_message(self, message_id, message)
-- if message_id == hash_ar_enable then
-- elseif message_id == hash_ar_update then
-- elseif message_id == hash_ar_disable then
-- end
--
--
-- C.Arf Format Requirement
--
-- -- Header
-- local v = vmath.vector4
-- local t = vmath.vector3
-- local e = {}
--
-- -- Arf Emobdiment
-- local f={
-- Aerials = "Arf",
-- Info = {
-- Traits = e,
-- Madeby = "··|·· Inherited from Project Solace",
-- Init = -152,
-- End = 225554, -- ms_of_last_object + index_scale
-- Hints = 1029
-- },
-- Wish = {
-- {3,0,v(6,1,-152,0),v(6,1,630,0),···},
-- ···
-- },
-- Hint = {v(6,1,630,0),···},
-- Index = {
-- Scale = 512,
-- Wish = {{1},{1},···},
-- Hint = {e,{1},···},
-- Wgo = {0,0,···}, -- The amount of 0 depends on the max size of WishIndex Group.
-- Hgo = {0,0,···}, -- The amount of 0 depends on the maxium value of #HintIndex[k-1]+#HintIndex[k]+#HintIndex[k+1].
-- Ago = {0,0,···}, -- The amount of 0 depends on the maxium value of #HintIndex[k-1]+#HintIndex[k]+#HintIndex[k+1].
-- Vecs = {t(),t(),···}, -- The amount of 0 depends on the max size of WishIndex Group.
-- Tints = {0,0,···} -- The amount of 0 depends on the max size of WishIndex Group.
-- }
-- }
--
-- -- Tailer
-- return f
--
-- 1. At the Head of Each Wish Group, Poll Progress(3) and ZIndex(z) Are Contained.
-- 2. x[0,16] y[0,8] z: zlayer(int[1,16]) + zdelta(float[0,0.9])
-- 3. Wish Node: v(x,y,time,easetype); Hint: v(x,y,mstime,z).
-- 4. "time" Refers to mstime if DTime is Disabled, or DTime if DTime is Enabled.
-- 5. For "easetype", See the Function ease().
-- 6. For Empty Tables( {} ), Replace them with e.
-- 7. Wish&Hint Index Begins at 1.
-- 8. Madeby: "Level Author"
--
--
--------------------------------------------------
local v3 = vmath.vector3
local v4 = vmath.vector4
local current_interpolated = v4(0)
-- System Settings --
--
local HINTSIZE2 = 337.5 -- Size of A Hint.
local HITZONE = 37 -- Must Smaller than 510-ANIM_LENGTH(=140).
local SWEEP = 100 -- And Also Smaller than 370.
local OPTANIM_LENGTH = 0.37
local PLAYBACK = go.PLAYBACK_ONCE_FORWARD
local EASE_EXPAND = go.EASING_OUTCUBIC
local EASE_CLOSE = go.EASING_OUTCUBIC
local DELIT = v4(0.2037, 0.2037, 0.2037, 1)
local NJLIT = v4(0.3737, 0.3737, 0.3737, 1)
local HITCOMMON = v4(0.73, 0.73, 0.73, 1)
local HITDAY = v4(0.73, 0.6244921875, 0.4591015625, 1)
local EAR = v4(0.3125, 0.5625, 0.63671875, 1)
local LAT = v4(0.63671875, 0.38671875, 0.3125, 1)
local INIT = v4(0.1337, 0.1337, 0.1337, 1)
local LST = v4(1, 0.51, 0.51, 1)
local hlratio = 0
local HIT = HITCOMMON
local function hintinit(dt)
hlratio = 0.07 * (510+dt) / 140
INIT.x = 0.1337 + hlratio
INIT.y = 0.1337 + hlratio
INIT.z = 0.1337 + hlratio
return INIT
end
local function hintlost(dt)
hlratio = 0.437 - dt*0.00037
LST.x = hlratio
LST.y = 0.51*hlratio
LST.z = 0.51*hlratio
return LST
end
--
-----------------------------
-- Update: Haptics Related.
--
local haptics_supported = false
local hapticsfunc = false
local iosh = false
local has_hint_judged = false
local last_vibration_time = 0
if Ar__mobile=="Android" then
if vibrate then
haptics_supported = true
hapticsfunc = vibrate.trigger
end
elseif Ar__mobile then
if (taptic_engine) and taptic_engine.isSupported() then
haptics_supported = true
hapticsfunc = taptic_engine.impact
iosh = taptic_engine.IMPACT_MEDIUM
end
end
--
-----------------------------
local Ar = hash("Ar")
local url = msg.url
local Exit = url("Ar:/ArIf#Exit")
local Options = url("Ar:/ArIf#Options")
local ArcWish = url("Ar:/Pragma#ArcWish")
local ArcHint = url("Ar:/Pragma#ArcHint")
local ArcAnim = url("Ar:/Pragma#ArcAnim")
local ArIf = url("Ar:/ArIf#Label")
local hash = hash
local hash_sprite = hash("Sprite")
local hash_px = hash("position.x")
local hash_py = hash("position.y")
local hash_pz = hash("position.z")
local hash_tint = hash("tint")
local hash_tintw = hash("tint.w")
local hash_sound_speed = hash("speed")
local tdelay = timer.delay
local gc = collectgarbage
local str_step = "step"
local str_setpause = "setpause"
local str_collect = "collect"
local send = msg.post
local spawn_from = factory.create
local playflp = sprite.play_flipbook
local goanimc = go.cancel_animations
local parent = go.set_parent
local scale = go.set_scale
local animg = go.animate
local del = go.delete
local set = go.set
local intfrac = math.modf
local floor = math.floor
local hash_enable = hash("enable")
local hash_disable = hash("disable")
local hash_ar_update = hash("ar_update")
local hash_ar_enable = hash("ar_enable")
local hash_ar_disable = hash("ar_disable")
local hash_ar_ui_final = hash("ar_ui_final")
local set_position = go.set_position
local self_pos = go.get_position
local tostr = tostring
local fmt = string.format
local label_set_text = label.set_text
local str_empty = ""
local fmt_score = "◇ %d"
local fmt_score_max = "◇ %d · Perfection Obtained"
local fmt_score_and_lost = "◇ %d · %d"
-- Easing System
--
local P = PartialEase
local PHint = P._PHint
local PWish = P._PWish
local IpCam = P._IpCam
local IpWish = P._IpWish
local PHint_hasCam = P._PHint_hasCam
local PWish_hasCam = P._PWish_hasCam
local V3V4Apply = P.V3V4Apply
local Ctint = P.Ctint
local HAPos = P.HAPos
local GetLVL = P.GetLVL
-- Table Utils
local tu = require("AcTableUtil.main")
local NewTable = tu.newtable
local TableAppend = tu.tableappend
local LCDiscard = tu.lcdiscard
local LEN = tu.LEN
--
-- Input: Detection
--
local HINTSIZE = HINTSIZE2/2
local tdx,tdy,ofi = false,false,false
local function has_touch_near(x,y,of,selfx)
for i=5,of[4] do
ofi = of[i]
if ofi.z>0 then
tdy = ofi.y - y
if tdy<=HINTSIZE and tdy>=-HINTSIZE then
tdx = ofi.x - x - selfx
if tdx<=HINTSIZE and tdx>=-HINTSIZE then
return true
end
end
end
end
end
--
-- Input: Block "Covered" Hints
--
local blocked = NewTable(32,0)
local blnum = 0
local bdx = 0
local bdy = 0
local function safe(x,y)
if blnum==0 then
blnum = 1
blocked[1] = x
blocked[2] = y
return true
elseif blnum==1 then
bdx = x - blocked[1]
bdy = y - blocked[2]
if bdx<=HINTSIZE2 and bdy<=HINTSIZE2 and bdx>=-HINTSIZE2 and bdy>=-HINTSIZE2 then
return false
else
blnum = 2
blocked[3] = x
blocked[4] = y
return true
end
else
for i=blnum,1,-1 do
bdx = x - blocked[i*2-1]
bdy = y - blocked[i*2]
if bdx<=HINTSIZE2 and bdy<=HINTSIZE2 and bdx>=-HINTSIZE2 and bdy>=-HINTSIZE2 then
return false
end
end
blnum = blnum + 1
blocked[blnum*2-1] = x
blocked[blnum*2] = y
return true
end
end
--
-- Update: DTime and Camera System
--
local last_since = NewTable(16,0)
local last_to = NewTable(16,0)
local last_base = NewTable(16,0)
local last_ratio = NewTable(16,0)
local function ArDTime(nodes, progress, zindex)
--
-- DTime Nodes:
-- {
-- [ZIndex] = {2,t(since_ms,base,ratio),···},
-- ···
-- }
--
-- To Control the Size of Arf, Please Clamp Your DTime into [0,512000].
--
if nodes then
local zn = nodes[zindex]
if (zn) and LEN[zn]>1 and progress>=zn[2].x then
local ls = last_since[zindex]
if progress>=ls and progress<last_to[zindex] then
return last_base[zindex] + (progress-ls)*last_ratio[zindex]
else
-- Gets Poll Progress, and Guards the Progress.
local znlen = LEN[zn]
local poll_progress = zn[1]
while poll_progress > 2 and progress < zn[poll_progress].x do
poll_progress = poll_progress - 1
end
-- Interpolate
local result = false
while not(poll_progress>znlen or result) do
local p = zn[poll_progress+1]
if (p) and progress>=zn[poll_progress].x and progress<p.x then
--
last_to[zindex] = p.x
--
p = zn[poll_progress]
local sincems = p.x
local base = p.y
local ratio = p.z
result = base + (progress-sincems)*ratio
--
last_since[zindex] = sincems
last_base[zindex] = base
last_ratio[zindex] = ratio
--
zn[1] = poll_progress
elseif poll_progress==znlen then
p = zn[poll_progress]
local sincems = p.x
local base = p.y
local ratio = p.z
result = base + (progress-sincems)*ratio
--
last_since[zindex] = sincems
last_to[zindex] = 512000
last_base[zindex] = base
last_ratio[zindex] = ratio
--
zn[1] = poll_progress
else
poll_progress = poll_progress+1
end
end
return result or 2
end
else
return progress
end
else
for i=1,16 do
last_since[i],last_to[i],last_base[i],last_ratio[i] = 0,0,0,0
end
end
end
local function ArCamera(nodes, progress, zindex)
--
-- Cam Nodes:
-- {
-- [ZIndex] = {
-- [1] = {2,t(node_ms,value,easetype),···}, -- xscale
-- [2] = {2,t(node_ms,value,easetype),···}, -- yscale
-- [3] = {2,t(node_ms,value,easetype),···}, -- rotrad
-- [4] = {2,t(node_ms,value,easetype),···}, -- xdelta
-- [5] = {2,t(node_ms,value,easetype),···} -- ydelta
-- },
-- ···
-- }
--
-- Return Order: xscale,yscale,rotrad,xdelta,ydelta
--
if progress then
local zf, xscale, yscale, rotrad, xdelta, ydelta = floor(zindex)
if nodes[zf] then
local zn = nodes[zf]
local znt,zntlen
if (zn[1]) and LEN[zn[1]] > 1 and progress>=zn[1][2].x then
znt = zn[1]
zntlen = LEN[znt]
if progress >= znt[zntlen].x then xscale = znt[zntlen].y
else
local poll_progress = znt[1]
while poll_progress ~= zntlen and not xscale do
if znt[poll_progress].x <= progress and znt[poll_progress+1].x > progress then
xscale = IpCam(progress, znt[poll_progress], znt[poll_progress+1])
znt[1] = poll_progress
else
poll_progress = poll_progress + 1
end
end
end
end
if (zn[2]) and LEN[zn[2]] > 1 and progress>=zn[2][2].x then
znt = zn[2]
zntlen = LEN[znt]
if progress >= znt[zntlen].x then yscale = znt[zntlen].y
else
local poll_progress = znt[1]
while poll_progress ~= zntlen and not yscale do
if znt[poll_progress].x <= progress and znt[poll_progress+1].x > progress then
yscale = IpCam(progress, znt[poll_progress], znt[poll_progress+1])
znt[1] = poll_progress
else
poll_progress = poll_progress + 1
end
end
end
end
if (zn[3]) and LEN[zn[3]] > 1 and progress>=zn[3][2].x then
znt = zn[3]
zntlen = LEN[znt]
if progress >= znt[zntlen].x then rotrad = znt[zntlen].y
else
local poll_progress = znt[1]
while poll_progress ~= zntlen and not rotrad do
if znt[poll_progress].x <= progress and znt[poll_progress+1].x > progress then
rotrad = IpCam(progress, znt[poll_progress], znt[poll_progress+1])
znt[1] = poll_progress
else
poll_progress = poll_progress + 1
end
end
end
end
if (zn[4]) and LEN[zn[4]] > 1 and progress>=zn[4][2].x then
znt = zn[4]
zntlen = LEN[znt]
if progress >= znt[zntlen].x then xdelta = znt[zntlen].y
else
local poll_progress = znt[1]
while poll_progress ~= zntlen and not xdelta do
if znt[poll_progress].x <= progress and znt[poll_progress+1].x > progress then
xdelta = IpCam(progress, znt[poll_progress], znt[poll_progress+1])
znt[1] = poll_progress
else
poll_progress = poll_progress + 1
end
end
end
end
if (zn[5]) and LEN[zn[5]] > 1 and progress>=zn[5][2].x then
znt = zn[5]
zntlen = LEN[znt]
if progress >= znt[zntlen].x then ydelta = znt[zntlen].y
else
local poll_progress = znt[1]
while poll_progress ~= zntlen and not ydelta do
if znt[poll_progress].x <= progress and znt[poll_progress+1].x > progress then
ydelta = IpCam(progress, znt[poll_progress], znt[poll_progress+1])
znt[1] = poll_progress
else
poll_progress = poll_progress + 1
end
end
end
end
end
return xscale or 1, yscale or 1, rotrad or 0, xdelta or 0, ydelta or 0
else
for zi=1,16 do
local zn = nodes[zi]
if zn then
if zn[1] then zn[1][1] = 2 end
if zn[2] then zn[2][1] = 2 end
if zn[3] then zn[3][1] = 2 end
if zn[4] then zn[4][1] = 2 end
if zn[5] then zn[5][1] = 2 end
end
end
end
end
---------------- DEFOLD LIFECYCLE FUNCTIONS ----------------
--
local last_arif_progress = 0
function init(self)
-- Registers the ArPlay Instance to the Input System.
local fm = false
local self_url = url().path
if self.fumen_id==0 then
Ar__arplays[1],Ar__arplays[2],Ar__arplays[3] = 1, 3, self_url
else
local fmno = self.fumen_id + 2
Ar__arplays[1] = Ar__arplays[1] + 1
if Ar__arplays[2] < fmno then Ar__arplays[2] = fmno end
Ar__arplays[fmno] = self_url
end
self.url = self_url
-- Transfers an Arf's Reference.
if self.fumen_id == 0 then
fm = Ar__fumens
Ar__current_total_hints = fm.Info.Hints
Ar__fumens = {}
else
fm = Ar__fumens[self.fumen_id]
self.totalhints = fm.Info.Hints
Ar__current_total_hints = Ar__current_total_hints + self.totalhints
Ar__fumens[self.fumen_id] = nil
end
-- Does Stuff about Tags.
-- Tag System is Under Construction.
--
local traited = fm.Info.Traits
if traited.Camera then
local cam_prim = traited.Camera
self.Camera = NewTable(16,0)
for i=1,16 do
if cam_prim[i] then self.Camera[i] = cam_prim[i] end
end
end
if traited.DTime then
local dt_prim = traited.DTime
self.DTime = NewTable(16,0)
for i=1,16 do
if dt_prim[i] then self.DTime[i] = dt_prim[i] end
end
ArDTime()
self.has = NewTable(16,0)
local w = fm.Wish
local h = fm.Hint
local zg = 0
for g=1,LEN[w] do
zg = floor(w[g][2])
self.has[zg] = true
end
for hi=1,LEN[h] do
zg = floor(h[hi].w)
self.has[zg] = true
end
end
if traited.ArIf then
local _if = traited.ArIf
if _if[3] ~= nil and LEN[_if] % 2 == 1 then
last_arif_progress = 0
self.ArIf = _if
end
end
--
--
-- Sets the Info, and Decreases the Index Depth when Polling.
-- Note that Defold doesn't support the method collectgarbage("stop").
if self.fumen_id < 2 then
gc(str_setpause, 104857600)
set(Ar__current_sound, hash_sound_speed, self.sound_speed)
label_set_text(ArIf, fm.Info.Madeby)
end
self.Init = fm.Info.Init
self.End = fm.Info.End
self.Wish = fm.Wish
self.Hint = fm.Hint
self.index_scale = fm.Index.Scale
self.Windex = fm.Index.Wish
self.Hindex = fm.Index.Hint
self.Wgo = fm.Index.Wgo
self.Hgo = fm.Index.Hgo
self.Vecs = fm.Index.Vecs
self.Tints = fm.Index.Tints
if Ar__play_animation then
self.play_animation = true
self.Ago = fm.Index.Ago
end
fm = nil
-- Precaculates Hints' Actual Positions.
local hints = self.Hint
if self.Camera then
local cam = self.Camera
local pos = false
for i=1, LEN[hints] do
pos = hints[i]
PHint_hasCam(pos, ArCamera(cam, pos.z, pos.w))
end
ArCamera(cam)
else
for i=1, LEN[hints] do PHint(hints[i]) end
end
-- Loads the Object Group, with Disable/Enable Messages.
local currenthash = 0
local w = self.Wgo
local typ = hash(tostr(Ar__current_song_id))
for i=1, LEN[w] do
currenthash = spawn_from(ArcWish)
parent(currenthash, self_url)
currenthash = url(Ar, currenthash, hash_sprite)
playflp(currenthash, typ)
send(currenthash, hash_disable)
w[i] = currenthash
end
local h = self.Hgo
for i=1, LEN[h] do
currenthash = spawn_from(ArcHint)
parent(currenthash, self_url)
currenthash = url(Ar, currenthash, hash_sprite)
if Ar__expand_hints then
scale(1.37, currenthash)
end
send(currenthash, hash_disable)
h[i] = currenthash
end
if self.play_animation then
local a = self.Ago
for i=1, LEN[a] do
currenthash = spawn_from(ArcAnim)
parent(currenthash, self_url)
send(currenthash, hash_disable)
a[i] = currenthash
end
end
-- Update: Loads UI Nodes.
if self.options and Ar__current_song_id == 1001 then
self.options = spawn_from(Options)
elseif self.fumen_id < 2 then
self.exit = spawn_from(Exit)
end
end
local daymode = false
local hash_ar_judge = hash("ar_judge")
local hash_ar_sound_speed = hash("ar_sound_speed")
local hash_ar_show_options = hash("ar_show_options")
local hash_ar_hide_options = hash("ar_hide_options")
local hash_ar_toggle_daymode = hash("ar_toggle_daymode")
local hash_ar_update_time = hash("ar_update_time")
function on_message(self, message_id, message, _sender)
--
-- Hint(x,y,z,w)
-- z: Target Hit Time(ms)
-- w:
-- (-inf, -1) Lit, Judged
-- -1 Lit, NonJudged
-- 0 Nonlit, NonJudged
-- 1 Nonhit Lost(Sweeped)
-- (1, +inf) Judged
--
if message_id==hash_ar_judge then
-- Preparations.
--
local spd, origtime = self.sound_speed, message[1]
local itime = (origtime - Ar__init_time - Ar__paused_time)*spd - Ar__audio_delay + Ar__input_delay
if itime<2 then itime=2 end
-- Optimization for Multiple ArPlay Instances.
--
if itime>=self.Init and itime<self.End then
local current_index_group = floor(itime/self.index_scale) + 1
if current_index_group < 1 then current_index_group = 1 end
local touch = message
local hindex = self.Hindex
local target = false
-- local g1 = hindex[current_index_group-1]
-- local g2 = hindex[current_index_group]
-- local g3 = hindex[current_index_group+1]
local hint = self.Hint
local chid = false
local chint = false
local selfx = 0
if self.options and Ar__current_song_id == 1001 then
selfx = self_pos().x
end
-- Reset the Safety Condition if There is Any Finger Released.
--
if touch[3] then
if blnum ~= 0 then
for i=blnum*2, 1, -1 do blocked[i] = nil end
blnum = 0
end
end
--
-- Light&Delit Hints, then Judge.
--
local mint, dt, chz, chw = 0
if touch[2] then
has_hint_judged = false
-------- Judge Start --------
for t=-1,1 do
target = hindex[current_index_group+t]
if (target) and LEN[target] ~= 0 then
for i=1, LEN[target] do
chid = target[i]
chint = hint[chid]
chz = chint.z
chw = chint.w
-- Asserted to be Sorted
dt = (itime - chz) / spd
if dt <- SWEEP then break end
local htn = has_touch_near(chint.x, chint.y, touch, selfx)
if chw == 0 or chw == -1 then
if htn then
chint.w = -1
chw = -1
else
chint.w = 0
end
elseif (chw < -1) and not htn then
chint.w = -chw
end
if chw == -1 and dt<SWEEP then
local issafe = safe(chint.x, chint.y) -- Must Register the Current Pivot.
if mint == 0 or mint == chz then
if dt<HITZONE and dt>-HITZONE then Ar__current_score = Ar__current_score + 1
else Ar__current_lost = Ar__current_lost + 1
end
chint.w = -itime
has_hint_judged = true
if mint==0 then mint=chz end
elseif issafe then
if dt<HITZONE and dt>-HITZONE then Ar__current_score = Ar__current_score + 1
else Ar__current_lost = Ar__current_lost + 1
end
chint.w = -itime
has_hint_judged = true
end
end
end
end
end
-------- Judge Complete --------
if has_hint_judged and haptics_supported and Ar__haptics then
if origtime-last_vibration_time <= 37 then
else last_vibration_time = origtime
if iosh then hapticsfunc(iosh)
else hapticsfunc()
end
end
end
else
for t=-1,1 do
target = hindex[current_index_group+t]
if (target) and LEN[target] ~= 0 then
for i=1, LEN[target] do
chid = target[i]
chint = hint[chid]
chz = chint.z
chw = chint.w
-- Asserted to be Sorted
dt = (itime - chz) / spd
if dt <- SWEEP then break end
local htn = has_touch_near(chint.x, chint.y, touch, selfx)
if chw==0 or chw==-1 then
if htn then chint.w = -1
else chint.w = 0
end
elseif (chw < -1) and not htn then chint.w = -chw
end
end
end
end
end
end
elseif message_id==hash_ar_update_time then
self.arloc = false
elseif message_id==hash_ar_toggle_daymode and self.fumen_id<2 then
if daymode then
HIT = HITCOMMON
if Ar__play_animation then send(self.Ago[1], hash_ar_toggle_daymode) end
daymode = false
else
HIT = HITDAY
if Ar__play_animation then send(self.Ago[1], hash_ar_toggle_daymode) end
daymode = true
end
elseif message_id==hash_ar_sound_speed then
local last_spd = self.sound_speed
local spd = message[1] or 1; if spd<0.2 or spd>=3 then spd=1 end
if self.fumen_id<2 then
set(Ar__current_sound, hash_sound_speed, spd)
Ar__paused_time = Ar__paused_time + (self.arloc or 0)*(spd-last_spd)/spd
end
self.sound_speed = spd
self.arloc = false
elseif self.options and Ar__current_song_id == 1001 then
if message_id == hash_ar_show_options then
goanimc(self.url, hash_px)
animg(self.url, hash_px, PLAYBACK, -337.5, EASE_EXPAND, OPTANIM_LENGTH)
elseif message_id == hash_ar_hide_options then
goanimc(self.url, hash_px)
animg(self.url, hash_px, PLAYBACK, 0, EASE_CLOSE, OPTANIM_LENGTH)
end
end
end
local frame_limit_gc = 0
local time = socket.gettime
local last_culled,last_hgo,last_ago = 0,0,0
local last_score,last_losts,last_string = false,false,""
local last_vec = NewTable(16,0)
local lvls = NewTable(16,0)
for i=1,16 do
last_vec[i] = NewTable(0,256)
lvls[i] = NewTable(256,0)
end
function update(self, tslf)
if Ar__active and (not Ar__focuslost) then
-- Obtains the Time Variables.
-- Ar__time: A Global Variable Updated in the Render Script, As an Endeavor to Make the Timestep Stable.
-- tslf: Time Since Last Frame. There are lots of "dt" used below.
if self.arloc then self.arloc = self.arloc + tslf*1000
else self.arloc = time()*1000 - Ar__init_time - Ar__paused_time
end
local spd = self.sound_speed
local progress = self.arloc*spd - Ar__audio_delay
-- local progress = ( Ar__time + tslf*1000 )*spd - Ar__audio_delay
if progress >= self.End then del()
elseif progress >= self.Init then
---------------- GAME LOGICS ----------------
-- Sets the Current Index Group.
local current_index_group = floor(progress/self.index_scale) + 1
if current_index_group < 1 then current_index_group = 1 end
-- Transfers a Vector Group.
local vecs = self.Vecs
local tints = self.Tints
-- Draws Wishes.
local wgo = self.Wgo
local ip_index = 1 -- Tracks How Many Wishes are Interpolated.
local culled_index = 1 -- Tracks How Many Wishes Should be Drawed.
if self.DTime then
local zip1 = 2
for zi = 1,16 do
if self.has[zi] then
zip1 = zi+1
local dtime = ArDTime(self.DTime, progress, zi)
if dtime < 2 then dtime = 2 end
local dgroup = floor(dtime/self.index_scale) + 1
if dgroup < 1 then dgroup = 1 end
if (self.Windex[dgroup]) and LEN[self.Windex[dgroup]] ~= 0 then
--
-- I.Interpolate the Positions, Append them after the Repetition Detection.
--
local group_id = 0 -- the Index of Current Wish Group.
local current_wish = false
local current_indexes = self.Windex[dgroup]
for i=1, LEN[current_indexes] do
group_id = current_indexes[i]
--
-- Group Scale
-- A.Interpolate
--
current_wish = self.Wish[group_id]
current_interpolated.z = current_wish[2]
local current_wish_len = LEN[current_wish]
local wish_interpolated = false
if current_wish_len > 3 and current_wish[2] >= zi and current_wish[2] < zip1 then
--
-- Node Scale
--
-- DTime: Poll Progress Guard
local poll_progress = current_wish[1]
while poll_progress>3 and current_wish[poll_progress].z > dtime do
poll_progress = poll_progress-1
end
while poll_progress ~= current_wish_len and not wish_interpolated do
if current_wish[poll_progress].z <= dtime and current_wish[poll_progress+1].z > dtime then
wish_interpolated = IpWish(dtime, poll_progress, current_wish[poll_progress], current_wish[poll_progress+1], current_interpolated)
current_wish[1] = poll_progress
else
poll_progress = poll_progress + 1
end
end
end
if wish_interpolated then
local _lastvec, _lvls, _lvl = last_vec[zi], lvls[zi], GetLVL(current_interpolated)
--
-- B.Appending for Initial Condition.
--
if ip_index == 1 then
tints[1] = V3V4Apply( vecs[1], current_interpolated )
TableAppend(_lvls, _lvl)