Files
wolf_dart/apps/wolf_3d_cli/bin/main.dart
Hans Kokx 0e143892f0 Refactor menu rendering and improve projection sampling
- Updated AsciiRasterizer to support game and episode selection menus with improved layout and cursor handling.
- Enhanced SixelRasterizer and SoftwareRasterizer to modularize menu drawing logic for game and episode selection.
- Introduced new methods for drawing menus and applying fade effects across rasterizers.
- Adjusted wall texture sampling in Rasterizer to anchor to projection height center for consistent rendering.
- Added tests for wall texture sampling behavior to ensure legacy compatibility and new functionality.
- Modified Flutter audio adapter to use nullable access for active game and adjusted game selection logic in the main class.
- Cleaned up input handling in Wolf3dFlutterInput by removing unused menu tap variables.

Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
2026-03-18 20:06:18 +01:00

75 lines
2.0 KiB
Dart

/// CLI entry point for the terminal Wolf3D host.
///
/// This executable locates bundled retail assets, constructs a [WolfEngine]
/// configured for terminal rendering, and then hands control to [CliGameLoop].
library;
import 'dart:io';
import 'package:wolf_3d_cli/cli_game_loop.dart';
import 'package:wolf_3d_dart/wolf_3d_data.dart';
import 'package:wolf_3d_dart/wolf_3d_data_types.dart';
import 'package:wolf_3d_dart/wolf_3d_engine.dart';
import 'package:wolf_3d_dart/wolf_3d_input.dart';
/// Restores terminal state before exiting the process with [code].
void exitCleanly(int code) {
stdout.write('\x1b[0m'); // Reset color
stdout.write('\x1b[2J\x1b[H'); // Clear screen
stdout.write('\x1b[?25h'); // SHOW the cursor again
exit(code);
}
/// Launches the CLI renderer against the bundled retail asset set.
void main() async {
stdout.write("Discovering game data...");
// Resolve the asset package relative to this executable so the CLI can run
// from the repo without additional configuration.
final scriptUri = Platform.script;
final targetUri = scriptUri.resolve(
'../../../packages/wolf_3d_assets/assets/retail',
);
final targetPath = targetUri.toFilePath();
final availableGames = await WolfensteinLoader.discover(
directoryPath: targetPath,
recursive: true,
);
if (availableGames.isEmpty) {
stderr.writeln('\nNo Wolf3D game files were found at: $targetPath');
stderr.writeln(
'Please provide valid game data files before starting the CLI host.',
);
exitCleanly(1);
}
CliGameLoop? gameLoop;
void stopAndExit(int code) {
gameLoop?.stop();
exitCleanly(code);
}
final engine = WolfEngine(
availableGames: availableGames.values.toList(growable: false),
startingEpisode: 0,
frameBuffer: FrameBuffer(
stdout.terminalColumns,
stdout.terminalLines,
),
input: CliInput(),
onGameWon: () => stopAndExit(0),
);
engine.init();
gameLoop = CliGameLoop(
engine: engine,
onExit: stopAndExit,
);
await gameLoop.start();
}