Skip to content

Commit e31c969

Browse files
MAJigsaw77AbnormalPoofKarimAkra
committed
Implement SDL3
Co-Authored-By: Abnormal <86753001+AbnormalPoof@users.noreply.github.com> Co-Authored-By: Karim Akra <144803230+KarimAkra@users.noreply.github.com>
1 parent 9a1a24d commit e31c969

27 files changed

Lines changed: 266 additions & 449 deletions

hmm.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,14 @@
5252
"name": "flixel",
5353
"type": "git",
5454
"dir": null,
55-
"ref": "c8e79d2a42f9c11c639519ef2a6fd7ef2379a8aa",
55+
"ref": "ab6cc8c14878be3a1a918d85668efc3b6a6263f2",
5656
"url": "https://github.com/FunkinCrew/flixel"
5757
},
5858
{
5959
"name": "flixel-addons",
6060
"type": "git",
6161
"dir": null,
62-
"ref": "6fa30b3f5209146c852c25f3d1003e08898083e2",
62+
"ref": "60e3076e1ed8cc6ad0cad5e72fe3c3d5e91207b7",
6363
"url": "https://github.com/FunkinCrew/flixel-addons"
6464
},
6565
{
@@ -169,7 +169,7 @@
169169
"name": "lime",
170170
"type": "git",
171171
"dir": null,
172-
"ref": "0125dc5dc1116b65e49c51cf8f2769577e668999",
172+
"ref": "248ea4175a9150320243378107b3820e154f328b",
173173
"url": "https://github.com/FunkinCrew/lime"
174174
},
175175
{
@@ -183,7 +183,7 @@
183183
"name": "openfl",
184184
"type": "git",
185185
"dir": null,
186-
"ref": "92d7607f309c6c0705456a2e943f1aa0f052463d",
186+
"ref": "0600b18e624aa8054ea86fc795c4d8e5bc004fbe",
187187
"url": "https://github.com/FunkinCrew/openfl"
188188
},
189189
{

source/Main.hx

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,9 @@ class Main extends Sprite
177177
// This allows the blend mode shader to work everywhere.
178178
untyped FlxG.cameras = new funkin.graphics.FunkinCameraFrontEnd();
179179

180-
var game:FlxGame = new FlxGame(gameWidth, gameHeight, initialState, Preferences.framerate, Preferences.framerate, skipSplash,
180+
var framerate:Int = Preferences.unlockedFramerate ? 0 : Preferences.framerate;
181+
182+
var game:FlxGame = new FlxGame(gameWidth, gameHeight, initialState, framerate, framerate, skipSplash,
181183
(FlxG.stage.window.fullscreen || Preferences.autoFullscreen));
182184

183185
// FlxG.game._customSoundTray wants just the class, it calls new from
@@ -251,28 +253,23 @@ class Main extends Sprite
251253
function repositionCounters(lerp:Bool):Void
252254
{
253255
// Calling this so it gets scaled based on the resolution of the game and device's resolution.
254-
var scale:Float = Math.min(FlxG.stage.stageWidth / FlxG.width, FlxG.stage.stageHeight / FlxG.height);
255-
256-
#if android
257-
scale = Math.max(scale, 1);
258-
#else
259-
scale = Math.min(scale, 1);
260-
#end
261-
final thypos:Float = Math.max(FullScreenScaleMode.notchSize.x, 10);
256+
var scale:Float = Math.max(Math.min(FlxG.stage.stageWidth / FlxG.width, FlxG.stage.stageHeight / FlxG.height), 1);
262257

263258
if (debugDisplay != null)
264259
{
265260
debugDisplay.scaleX = debugDisplay.scaleY = scale;
266261

267262
if (FlxG.game != null)
268263
{
264+
final thypos:Float = Math.max(FullScreenScaleMode.notchSize.x, 10);
265+
269266
if (lerp)
270267
{
271268
debugDisplay.x = flixel.math.FlxMath.lerp(debugDisplay.x, FlxG.game.x + thypos, FlxG.elapsed * 3);
272269
}
273270
else
274271
{
275-
debugDisplay.x = FlxG.game.x + FullScreenScaleMode.notchSize.x + 10;
272+
debugDisplay.x = FlxG.game.x + thypos;
276273
}
277274

278275
debugDisplay.y = FlxG.game.y + (3 * scale);

source/funkin/InitState.hx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -311,19 +311,34 @@ class InitState extends FlxState
311311
#if FEATURE_LOST_FOCUS_VOLUME
312312
@:noCompletion var _lastFocusVolume:Null<Float>;
313313

314-
function onLostFocus()
314+
function onLostFocus():Void
315315
{
316316
if (FlxG.sound.muted || FlxG.sound.volume == 0 || FlxG.autoPause) return;
317317
_lastFocusVolume = FlxG.sound.volume;
318318
FlxG.sound.volume *= Constants.LOST_FOCUS_VOLUME_MULTIPLIER;
319319
}
320+
#end
320321

321-
function onGainFocus()
322+
function onGainFocus():Void
322323
{
324+
#if !mobile
325+
if (Preferences.unlockedFramerate)
326+
{
327+
FlxG.updateFramerate = 0;
328+
FlxG.drawFramerate = 0;
329+
}
330+
else
331+
{
332+
FlxG.updateFramerate = Preferences.framerate;
333+
FlxG.drawFramerate = Preferences.framerate;
334+
}
335+
#end
336+
337+
#if FEATURE_LOST_FOCUS_VOLUME
323338
if (FlxG.sound.muted || FlxG.autoPause) return;
324339
if (_lastFocusVolume != null) FlxG.sound.volume = _lastFocusVolume;
340+
#end
325341
}
326-
#end
327342

328343
/**
329344
* Start the game.

source/funkin/Preferences.hx

Lines changed: 47 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,23 @@ class Preferences
4141
{
4242
#if web
4343
return 60;
44+
#elseif mobile
45+
var refreshRate:Int = FlxG.stage.window.displayMode.refreshRate;
46+
47+
if (refreshRate < 60) refreshRate = 60;
48+
49+
return refreshRate;
4450
#else
4551
var save:Save = Save.instance;
4652
save.options.framerate = value;
4753
Save.system.flush();
48-
FlxG.updateFramerate = value;
49-
FlxG.drawFramerate = value;
54+
55+
if (!unlockedFramerate)
56+
{
57+
FlxG.updateFramerate = value;
58+
FlxG.drawFramerate = value;
59+
}
60+
5061
return value;
5162
#end
5263
}
@@ -69,13 +80,13 @@ class Preferences
6980
static function set_naughtyness(value:Bool):Bool
7081
{
7182
#if NO_FEATURE_NAUGHTYNESS
72-
value = false;
73-
#end
74-
83+
return false;
84+
#else
7585
var save:Save = Save.instance;
7686
save.options.naughtyness = value;
7787
Save.system.flush();
7888
return value;
89+
#end
7990
}
8091

8192
/**
@@ -146,8 +157,7 @@ class Preferences
146157
{
147158
#if NO_FEATURE_DEBUG_DISPLAY
148159
return DebugDisplayMode.Off;
149-
#end
150-
160+
#else
151161
#if hl
152162
// Account for when debugDisplay used to be a boolean
153163
var options:Null<SaveDataOptions> = Save.instance?.options;
@@ -158,18 +168,22 @@ class Preferences
158168
Save.system.flush();
159169
}
160170
#end
161-
162171
return Save?.instance?.options?.debugDisplay ?? 'Off';
172+
#end
163173
}
164174

165175
static function set_debugDisplay(value:DebugDisplayMode):DebugDisplayMode
166176
{
177+
#if NO_FEATURE_DEBUG_DISPLAY
178+
return DebugDisplayMode.Off;
179+
#else
167180
if (value != Save.instance.options.debugDisplay) setDebugDisplayMode(value);
168181

169182
var save = Save.instance;
170183
save.options.debugDisplay = value;
171184
Save.system.flush();
172185
return value;
186+
#end
173187
}
174188

175189
/**
@@ -264,18 +278,23 @@ class Preferences
264278
{
265279
#if mobile
266280
return false;
267-
#end
281+
#else
268282
return Save?.instance?.options?.autoPause ?? true;
283+
#end
269284
}
270285

271286
static function set_autoPause(value:Bool):Bool
272287
{
288+
#if mobile
289+
return false;
290+
#else
273291
if (value != Save.instance.options.autoPause) FlxG.autoPause = value;
274292

275293
var save:Save = Save.instance;
276294
save.options.autoPause = value;
277295
Save.system.flush();
278296
return value;
297+
#end
279298
}
280299

281300
/**
@@ -325,6 +344,9 @@ class Preferences
325344

326345
static function get_vsyncMode():lime.ui.WindowVSyncMode
327346
{
347+
#if mobile
348+
return lime.ui.WindowVSyncMode.OFF;
349+
#else
328350
var value = Save?.instance?.options?.vsyncMode ?? "Off";
329351

330352
return switch (value)
@@ -338,10 +360,14 @@ class Preferences
338360
default:
339361
lime.ui.WindowVSyncMode.OFF;
340362
};
363+
#end
341364
}
342365

343366
static function set_vsyncMode(value:lime.ui.WindowVSyncMode):lime.ui.WindowVSyncMode
344367
{
368+
#if mobile
369+
return lime.ui.WindowVSyncMode.OFF;
370+
#else
345371
var string;
346372

347373
switch (value)
@@ -362,28 +388,35 @@ class Preferences
362388
save.options.vsyncMode = string;
363389
Save.system.flush();
364390
return value;
391+
#end
365392
}
366393

367394
public static var unlockedFramerate(get, set):Bool;
368395

369396
static function get_unlockedFramerate():Bool
370397
{
398+
#if mobile
399+
return false;
400+
#else
371401
return Save?.instance?.options?.unlockedFramerate ?? false;
402+
#end
372403
}
373404

374405
static function set_unlockedFramerate(value:Bool):Bool
375406
{
407+
#if mobile
408+
return false;
409+
#else
376410
if (value != Save.instance.options.unlockedFramerate)
377411
{
378-
#if web
379412
toggleFramerateCap(value);
380-
#end
381413
}
382414

383415
var save:Save = Save.instance;
384416
save.options.unlockedFramerate = value;
385417
Save.system.flush();
386418
return value;
419+
#end
387420
}
388421

389422
#if web
@@ -496,9 +529,7 @@ class Preferences
496529
setDebugDisplayMode(Preferences.debugDisplay);
497530
setDebugDisplayBGOpacity(Preferences.debugDisplayBGOpacity / 100);
498531

499-
#if web
500532
toggleFramerateCap(Preferences.unlockedFramerate);
501-
#end
502533

503534
#if mobile
504535
// Apply the allowScreenTimeout setting.
@@ -511,6 +542,9 @@ class Preferences
511542
#if web
512543
var framerateFunction = unlocked ? unlockedFramerateFunction : lockedFramerateFunction;
513544
untyped js.Syntax.code("window.requestAnimationFrame = framerateFunction;");
545+
#else
546+
FlxG.drawFramerate = unlocked ? 0 : framerate;
547+
FlxG.updateFramerate = unlocked ? 0 : framerate;
514548
#end
515549
}
516550

source/funkin/external/apple/project/src/ScreenUtil.mm

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,18 @@ void Apple_ScreenUtil_GetSafeAreaInsets(double* top, double* bottom, double* lef
1111
#if TARGET_OS_IOS
1212
if (@available(iOS 11, *))
1313
{
14-
UIWindow* window = [UIApplication sharedApplication].windows[0];
15-
UIEdgeInsets safeAreaInsets = window.safeAreaInsets;
16-
float scale = [UIScreen mainScreen].scale;
14+
UIWindow *window = [UIApplication sharedApplication].windows[0];
15+
if (window)
16+
{
17+
UIEdgeInsets insets = window.safeAreaInsets;
18+
CGFloat scale = window.screen.nativeScale;
1719

18-
(*top) = safeAreaInsets.top * scale;
19-
(*bottom) = safeAreaInsets.bottom * scale;
20-
(*left) = safeAreaInsets.left * scale;
21-
(*right) = safeAreaInsets.right * scale;
22-
23-
return;
20+
(*top) = (double)(insets.top * scale);
21+
(*bottom) = (double)(insets.bottom * scale);
22+
(*left) = (double)(insets.left * scale);
23+
(*right) = (double)(insets.right * scale);
24+
return;
25+
}
2426
}
2527
#endif
2628

@@ -33,13 +35,22 @@ void Apple_ScreenUtil_GetSafeAreaInsets(double* top, double* bottom, double* lef
3335
void Apple_ScreenUtil_GetScreenSize(double* width, double* height)
3436
{
3537
#if TARGET_OS_IOS
36-
CGRect screenRect = [[UIScreen mainScreen] bounds];
37-
float scale = [UIScreen mainScreen].scale;
38+
if (@available(iOS 11, *))
39+
{
40+
UIWindow *window = [UIApplication sharedApplication].windows[0];
41+
if (window && window.rootViewController)
42+
{
43+
UIView *view = window.rootViewController.view;
44+
CGSize size = view.bounds.size;
45+
CGFloat scale = window.screen.nativeScale;
3846

39-
(*width) = (double)screenRect.size.width * scale;
40-
(*height) = (double)screenRect.size.height * scale;
41-
#else
42-
(*width) = 0.0;
43-
(*width) = 0.0;
47+
(*width) = (double)((int)(size.width * scale));
48+
(*height) = (double)((int)(size.height * scale));
49+
return;
50+
}
51+
}
4452
#endif
53+
54+
(*width) = 0.0;
55+
(*height) = 0.0;
4556
}

0 commit comments

Comments
 (0)