Fixed ASCII rasterizer, abstracted out input and audio, and created CLI client (untested)

Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
2026-03-16 14:47:10 +01:00
parent 6f7885a924
commit ede2c3fa31
18 changed files with 353 additions and 166 deletions

View File

@@ -0,0 +1,47 @@
import 'package:wolf_3d_entities/wolf_3d_entities.dart';
import 'package:wolf_3d_input/src/wolf_3d_input.dart';
class CliInput extends Wolf3dInput {
// Pending buffer for asynchronous stdin events
bool _pForward = false;
bool _pBackward = false;
bool _pLeft = false;
bool _pRight = false;
bool _pFire = false;
bool _pInteract = false;
WeaponType? _pWeapon;
/// Call this directly from the stdin listener to queue inputs for the next frame
void handleKey(List<int> bytes) {
String char = String.fromCharCodes(bytes).toLowerCase();
if (char == 'w') _pForward = true;
if (char == 's') _pBackward = true;
if (char == 'a') _pLeft = true;
if (char == 'd') _pRight = true;
if (char == 'f' || char == ' ') _pFire = true;
if (char == 'e') _pInteract = true;
if (char == '1') _pWeapon = WeaponType.knife;
if (char == '2') _pWeapon = WeaponType.pistol;
if (char == '3') _pWeapon = WeaponType.machineGun;
if (char == '4') _pWeapon = WeaponType.chainGun;
}
@override
void update() {
// 1. Move pending inputs to the active state
isMovingForward = _pForward;
isMovingBackward = _pBackward;
isTurningLeft = _pLeft;
isTurningRight = _pRight;
isFiring = _pFire;
isInteracting = _pInteract;
requestedWeapon = _pWeapon;
// 2. Wipe the pending slate clean for the next frame
_pForward = _pBackward = _pLeft = _pRight = _pFire = _pInteract = false;
_pWeapon = null;
}
}

View File

@@ -0,0 +1,27 @@
import 'package:wolf_3d_engine/wolf_3d_engine.dart';
import 'package:wolf_3d_entities/wolf_3d_entities.dart';
abstract class Wolf3dInput {
bool isMovingForward = false;
bool isMovingBackward = false;
bool isTurningLeft = false;
bool isTurningRight = false;
bool isInteracting = false;
bool isFiring = false;
WeaponType? requestedWeapon;
/// Called once per frame by the game loop to refresh the state.
void update();
/// Exports the current state as a clean DTO for the engine.
/// Subclasses do not need to override this.
EngineInput get currentInput => EngineInput(
isMovingForward: isMovingForward,
isMovingBackward: isMovingBackward,
isTurningLeft: isTurningLeft,
isTurningRight: isTurningRight,
isFiring: isFiring,
isInteracting: isInteracting,
requestedWeapon: requestedWeapon,
);
}

View File

@@ -1,58 +1,4 @@
import 'package:flutter/services.dart';
import 'package:wolf_3d_engine/wolf_3d_engine.dart';
import 'package:wolf_3d_entities/wolf_3d_entities.dart';
library;
class WolfInput {
Set<LogicalKeyboardKey> _previousKeys = {};
bool isMovingForward = false;
bool isMovingBackward = false;
bool isTurningLeft = false;
bool isTurningRight = false;
bool isInteracting = false;
bool isFiring = false;
WeaponType? requestedWeapon;
void update() {
final pressedKeys = HardwareKeyboard.instance.logicalKeysPressed;
final newlyPressedKeys = pressedKeys.difference(_previousKeys);
isMovingForward = pressedKeys.contains(LogicalKeyboardKey.keyW);
isMovingBackward = pressedKeys.contains(LogicalKeyboardKey.keyS);
isTurningLeft = pressedKeys.contains(LogicalKeyboardKey.keyA);
isTurningRight = pressedKeys.contains(LogicalKeyboardKey.keyD);
isInteracting = newlyPressedKeys.contains(LogicalKeyboardKey.space);
isFiring =
pressedKeys.contains(LogicalKeyboardKey.controlLeft) &&
!pressedKeys.contains(LogicalKeyboardKey.space);
requestedWeapon = null;
for (final LogicalKeyboardKey key in newlyPressedKeys) {
switch (key) {
case LogicalKeyboardKey.digit1:
requestedWeapon = WeaponType.knife;
case LogicalKeyboardKey.digit2:
requestedWeapon = WeaponType.pistol;
case LogicalKeyboardKey.digit3:
requestedWeapon = WeaponType.machineGun;
case LogicalKeyboardKey.digit4:
requestedWeapon = WeaponType.chainGun;
}
}
_previousKeys = Set.from(pressedKeys);
}
/// Exports the current state as a clean DTO for the engine
EngineInput get currentInput => EngineInput(
isMovingForward: isMovingForward,
isMovingBackward: isMovingBackward,
isTurningLeft: isTurningLeft,
isTurningRight: isTurningRight,
isFiring: isFiring,
isInteracting: isInteracting,
requestedWeapon: requestedWeapon,
);
}
export 'src/cli_input.dart';
export 'src/wolf_3d_input.dart';

View File

@@ -5,54 +5,9 @@ homepage:
environment:
sdk: ^3.11.1
flutter: ">=1.17.0"
resolution: workspace
dependencies:
flutter:
sdk: flutter
wolf_3d_entities: any
wolf_3d_engine: any
dev_dependencies:
flutter_test:
sdk: flutter
flutter_lints: ^6.0.0
# For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec
# The following section is specific to Flutter packages.
flutter:
# To add assets to your package, add an assets section, like this:
# assets:
# - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg
#
# For details regarding assets in packages, see
# https://flutter.dev/to/asset-from-package
#
# An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/to/resolution-aware-images
# To add custom fonts to your package, add a fonts section here,
# in this "flutter" section. Each entry in this list should have a
# "family" key with the font family name, and a "fonts" key with a
# list giving the asset and other descriptors for the font. For
# example:
# fonts:
# - family: Schyler
# fonts:
# - asset: fonts/Schyler-Regular.ttf
# - asset: fonts/Schyler-Italic.ttf
# style: italic
# - family: Trajan Pro
# fonts:
# - asset: fonts/TrajanPro.ttf
# - asset: fonts/TrajanPro_Bold.ttf
# weight: 700
#
# For details regarding fonts in packages, see
# https://flutter.dev/to/font-from-package