Skip to content

Commit

Permalink
Use flutter_sdl_gamepads to compile SDL binaries (#175)
Browse files Browse the repository at this point in the history
Shoutout to @Gold872 for putting in much of the work behind
`package:flutter_sdl_gamepad`
  • Loading branch information
Levi-Lesches authored Oct 15, 2024
1 parent 362a2da commit fb9a6c0
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 7 deletions.
Binary file removed SDL3.dll
Binary file not shown.
4 changes: 4 additions & 0 deletions lib/src/services/files.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ class FilesService extends Service {
/// The encoder to convert a Map<> to a json string with a nice indent
final JsonEncoder jsonEncoder = const JsonEncoder.withIndent(" ");

bool _isInit = false;

/// Ensure that files and directories that are expected to be present actually
/// exist on the system. If not, create them.
@override
Expand All @@ -58,6 +60,7 @@ class FilesService extends Service {
loggingDir = await Directory("${outputDir.path}/logs/${DateTime.now().timeStamp}").create(recursive: true);
if (!settingsFile.existsSync()) await writeSettings(null);
dataLogger = Timer.periodic(const Duration(seconds: 5), logAllData);
_isInit = true;
}

@override
Expand Down Expand Up @@ -139,6 +142,7 @@ class FilesService extends Service {

/// Outputs error to log file
Future<void> logError(Object error, StackTrace stack) async{
if (!_isInit) return;
final file = loggingDir / "errors.log";
await file.writeAsString("${DateTime.now().timeStamp} $error $stack\n", mode: FileMode.writeOnlyAppend);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/services/gamepad/sdl.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import "package:sdl_gamepad/sdl_gamepad.dart" as sdl;
import "package:flutter_sdl_gamepad/flutter_sdl_gamepad.dart" as sdl;

import "state.dart";
import "gamepad.dart";
Expand Down
6 changes: 4 additions & 2 deletions lib/src/services/gamepad/service.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import "package:sdl_gamepad/sdl_gamepad.dart";
import "package:flutter_sdl_gamepad/flutter_sdl_gamepad.dart";

import "../service.dart";
import "gamepad.dart";
Expand Down Expand Up @@ -45,7 +45,9 @@ class GamepadService extends Service {

@override
Future<void> init() async {
SdlLibrary.init();
if (!SdlLibrary.init()) {
throw StateError("Could not initialize SDL libraries");
}
gamepads = List.generate(maxGamepads, MockGamepad.new);
for (var i = 0; i < maxGamepads; i++) {
await connect(i);
Expand Down
Binary file removed libSDL3.so
Binary file not shown.
1 change: 1 addition & 0 deletions linux/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ list(APPEND FLUTTER_PLUGIN_LIST
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
flutter_sdl_gamepad
)

set(PLUGIN_BUNDLED_LIBRARIES)
Expand Down
14 changes: 11 additions & 3 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,14 @@ packages:
url: "https://pub.dev"
source: hosted
version: "3.0.0"
flutter_sdl_gamepad:
dependency: "direct main"
description:
name: flutter_sdl_gamepad
sha256: "513910280591bdc5362dda0c0a8d53b310f0d9e5f53c4188ddaf13f7339847b0"
url: "https://pub.dev"
source: hosted
version: "1.0.0"
flutter_test:
dependency: "direct dev"
description: flutter
Expand Down Expand Up @@ -498,13 +506,13 @@ packages:
source: hosted
version: "0.1.34"
sdl_gamepad:
dependency: "direct main"
dependency: transitive
description:
name: sdl_gamepad
sha256: "5d1931dc4e4831dc298a1964b94d4e5a257b027ad5ce268620c6b5e15a46c70b"
sha256: "3bce11dbf7da9a543ce17177342171d5033a2b7198dbfa51b5bee7cdc45d4ac2"
url: "https://pub.dev"
source: hosted
version: "1.0.1"
version: "1.0.2"
sky_engine:
dependency: transitive
description: flutter
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ dependencies:
url_launcher: ^6.1.10
just_audio: ^0.9.36
collection: ^1.18.0
sdl_gamepad: ^1.0.1
flutter_sdl_gamepad: ^1.0.0

# Prefer to use `flutter pub add --dev packageName` rather than modify this section by hand.
dev_dependencies:
Expand Down
1 change: 1 addition & 0 deletions windows/flutter/generated_plugins.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ list(APPEND FLUTTER_PLUGIN_LIST
)

list(APPEND FLUTTER_FFI_PLUGIN_LIST
flutter_sdl_gamepad
)

set(PLUGIN_BUNDLED_LIBRARIES)
Expand Down

0 comments on commit fb9a6c0

Please sign in to comment.