@@ -1285,17 +1285,23 @@ class PlayState extends MusicBeatState
1285
1285
if (updateIconPositions != null )
1286
1286
updateIconPositions ();
1287
1287
1288
- if (startingSong )
1289
- {
1290
- if (startedCountdown )
1291
- {
1288
+ if (startingSong ) {
1289
+ if (startedCountdown ) {
1292
1290
Conductor .songPosition + = Conductor .songOffset + elapsed * 1000 ;
1293
1291
if (Conductor .songPosition >= 0 )
1294
1292
startSong ();
1295
1293
}
1296
1294
} else if (FlxG .sound .music != null ) {
1297
1295
var instTime = FlxG .sound .music .time ;
1298
- var isOffsync = vocals .time != instTime || [for (strumLine in strumLines .members ) strumLine .vocals .time != instTime ].contains (true );
1296
+ var isOffsync : Bool = vocals .time != instTime ;
1297
+ if (! isOffsync ) {
1298
+ for (strumLine in strumLines .members ) {
1299
+ if (strumLine .vocals .time != instTime ) {
1300
+ isOffsync = true ;
1301
+ break ;
1302
+ }
1303
+ }
1304
+ }
1299
1305
__vocalOffsetViolation = Math .max (0 , __vocalOffsetViolation + (isOffsync ? elapsed : - elapsed / 2 ));
1300
1306
if (__vocalOffsetViolation > 25 ) {
1301
1307
resyncVocals ();
@@ -1309,31 +1315,17 @@ class PlayState extends MusicBeatState
1309
1315
if (controls. PAUSE && startedCountdown && canPause )
1310
1316
pauseGame ();
1311
1317
1312
- if (generatedMusic && strumLines .members [curCameraTarget ] != null )
1313
- {
1314
- var pos = FlxPoint .get ();
1315
- var r = 0 ;
1316
- for (c in strumLines .members [curCameraTarget ].characters ) {
1317
- if (c == null || ! c .visible ) continue ;
1318
- var cpos = c .getCameraPosition ();
1319
- pos .x + = cpos .x ;
1320
- pos .y + = cpos .y ;
1321
- r ++ ;
1322
- // cpos.put();
1323
- }
1324
- if (r > 0 ) {
1325
- pos .x / = r ;
1326
- pos .y / = r ;
1327
-
1328
- var event = scripts .event (" onCameraMove" , EventManager .get (CamMoveEvent ).recycle (pos , strumLines .members [curCameraTarget ], r ));
1318
+ if (generatedMusic && strumLines .members [curCameraTarget ] != null ) {
1319
+ var data : CamPosData = getStrumlineCamPos (curCameraTarget );
1320
+ if (data .amount > 0 ) {
1321
+ var event = scripts .event (" onCameraMove" , EventManager .get (CamMoveEvent ).recycle (data .pos , strumLines .members [curCameraTarget ], data .amount ));
1329
1322
if (! event .cancelled )
1330
- camFollow .setPosition (pos . x , pos .y );
1323
+ camFollow .setPosition (event . position . x , event . position .y );
1331
1324
}
1332
- pos .put ();
1325
+ data .put ();
1333
1326
}
1334
1327
1335
- if (camZooming )
1336
- {
1328
+ if (camZooming ) {
1337
1329
FlxG .camera .zoom = lerp (FlxG .camera .zoom , defaultCamZoom , camGameZoomLerp );
1338
1330
camHUD .zoom = lerp (camHUD .zoom , defaultHudZoom , camHUDZoomLerp );
1339
1331
}
@@ -1367,6 +1359,41 @@ class PlayState extends MusicBeatState
1367
1359
scripts .event (" postDraw" , e );
1368
1360
}
1369
1361
1362
+ /**
1363
+ * Returns the camera position of the specified strumline.
1364
+ * @param strumLine The strumline to get the camera position of.
1365
+ * @param pos The position to put the camera position in. If `null`, a new FlxPoint will be created.
1366
+ * @param ignoreInvisible Whenever invisible characters should be ignored.
1367
+ **/
1368
+ public inline function getStrumlineCamPos (strumLine : Int , ? pos : FlxPoint = null , ? ignoreInvisible : Bool = true ): CamPosData {
1369
+ return getCharactersCamPos (strumLines .members [strumLine ].characters , pos , ignoreInvisible );
1370
+ }
1371
+
1372
+ /**
1373
+ * Returns the camera position of the specified characters.
1374
+ * @param chars The characters to get the camera position of.
1375
+ * @param pos The position to put the camera position in. If `null`, a new FlxPoint will be created.
1376
+ * @param ignoreInvisible Whenever invisible characters should be ignored.
1377
+ **/
1378
+ public function getCharactersCamPos (chars : Array <Character >, ? pos : FlxPoint = null , ? ignoreInvisible : Bool = true ): CamPosData {
1379
+ if (pos == null ) pos = FlxPoint .get ();
1380
+ var amount = 0 ;
1381
+ for (c in chars ) {
1382
+ if (c == null || (ignoreInvisible && ! c .visible )) continue ;
1383
+ var cpos = c .getCameraPosition ();
1384
+ pos .x + = cpos .x ;
1385
+ pos .y + = cpos .y ;
1386
+ amount ++ ;
1387
+ // cpos.put(); // not actually in the pool, so no need
1388
+ }
1389
+ if (amount > 0 ) {
1390
+ pos .x / = amount ;
1391
+ pos .y / = amount ;
1392
+ }
1393
+ return new CamPosData (pos , amount );
1394
+ }
1395
+
1396
+
1370
1397
public var scrollSpeedTween : FlxTween = null ;
1371
1398
1372
1399
public function executeEvent (event : ChartEvent ) @:privateAccess {
@@ -1995,3 +2022,28 @@ typedef PlayStateTransitionData = {
1995
2022
var camFollowY : Float ;
1996
2023
var camZoom : Float ;
1997
2024
}
2025
+
2026
+ class CamPosData {
2027
+ /**
2028
+ * The camera position.
2029
+ **/
2030
+ public var pos : FlxPoint ;
2031
+ /**
2032
+ * The amount of characters that was involved in the calculation.
2033
+ **/
2034
+ public var amount : Int ;
2035
+
2036
+ public function new (pos : FlxPoint , amount : Int ) {
2037
+ this .pos = pos ;
2038
+ this .amount = amount ;
2039
+ }
2040
+
2041
+ /**
2042
+ * Puts the position back into the pool, making it reusable.
2043
+ **/
2044
+ public function put () {
2045
+ if (pos == null ) return ;
2046
+ pos .put ();
2047
+ pos = null ;
2048
+ }
2049
+ }
0 commit comments