Starting to move data loader to its own package

Signed-off-by: Hans Kokx <hans.d.kokx@gmail.com>
This commit is contained in:
2026-03-14 19:34:39 +01:00
parent 052b5afd2e
commit f225ca728e
21 changed files with 146 additions and 39 deletions

View File

@@ -1 +0,0 @@
typedef Sprite = List<List<int>>;

View File

@@ -1,6 +1,6 @@
import 'dart:math' as math; import 'dart:math' as math;
import 'package:wolf_dart/classes/sprite.dart'; import 'package:wolf_3d_data/wolf_3d_data.dart';
import 'package:wolf_dart/features/map/door.dart'; import 'package:wolf_dart/features/map/door.dart';
class DoorManager { class DoorManager {

View File

@@ -1,12 +1,12 @@
import 'dart:math' as math; import 'dart:math' as math;
import 'package:wolf_dart/classes/matrix.dart'; import 'package:wolf_3d_data/wolf_3d_data.dart';
import 'package:wolf_dart/features/entities/map_objects.dart'; import 'package:wolf_dart/features/entities/map_objects.dart';
class Pushwall { class Pushwall {
int x; int x;
int y; int y;
int mapId; // The wall texture ID int mapId;
int dirX = 0; int dirX = 0;
int dirY = 0; int dirY = 0;
double offset = 0.0; double offset = 0.0;
@@ -19,7 +19,7 @@ class PushwallManager {
final Map<String, Pushwall> pushwalls = {}; final Map<String, Pushwall> pushwalls = {};
Pushwall? activePushwall; Pushwall? activePushwall;
void initPushwalls(Matrix<int> wallGrid, Matrix<int> objectGrid) { void initPushwalls(Sprite wallGrid, Sprite objectGrid) {
pushwalls.clear(); pushwalls.clear();
activePushwall = null; activePushwall = null;
@@ -32,7 +32,7 @@ class PushwallManager {
} }
} }
void update(Duration elapsed, Matrix<int> wallGrid) { void update(Duration elapsed, Sprite wallGrid) {
if (activePushwall == null) return; if (activePushwall == null) return;
final pw = activePushwall!; final pw = activePushwall!;
@@ -85,7 +85,7 @@ class PushwallManager {
double playerX, double playerX,
double playerY, double playerY,
double playerAngle, double playerAngle,
Matrix<int> wallGrid, Sprite wallGrid,
) { ) {
// Only one pushwall can move at a time in the original engine! // Only one pushwall can move at a time in the original engine!
if (activePushwall != null) return; if (activePushwall != null) return;

View File

@@ -1,11 +1,11 @@
import 'package:wolf_dart/classes/matrix.dart'; import 'package:wolf_3d_data/wolf_3d_data.dart';
class WolfLevel { class WolfLevel {
final String name; final String name;
final int width; // Always 64 in standard Wolf3D final int width; // Always 64 in standard Wolf3D
final int height; // Always 64 final int height; // Always 64
final Matrix<int> wallGrid; final Sprite wallGrid;
final Matrix<int> objectGrid; final Sprite objectGrid;
WolfLevel({ WolfLevel({
required this.name, required this.name,

View File

@@ -1,14 +1,13 @@
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:wolf_dart/classes/matrix.dart'; import 'package:wolf_3d_data/wolf_3d_data.dart';
import 'package:wolf_dart/features/map/wolf_level.dart'; import 'package:wolf_dart/features/map/wolf_level.dart';
import 'package:wolf_dart/features/map/wolf_map_parser.dart'; import 'package:wolf_dart/features/map/wolf_map_parser.dart';
import 'package:wolf_dart/vswap_parser.dart';
class WolfMap { class WolfMap {
/// The fully parsed and decompressed levels from the game files. /// The fully parsed and decompressed levels from the game files.
final List<WolfLevel> levels; final List<WolfLevel> levels;
final List<Matrix<int>> textures; final List<Sprite> textures;
final List<Matrix<int>> sprites; final List<Sprite> sprites;
// A private constructor so we can only instantiate this from the async loader // A private constructor so we can only instantiate this from the async loader
WolfMap._( WolfMap._(

View File

@@ -1,7 +1,7 @@
import 'dart:convert'; import 'dart:convert';
import 'dart:typed_data'; import 'dart:typed_data';
import 'package:wolf_dart/classes/matrix.dart'; import 'package:wolf_3d_data/wolf_3d_data.dart';
import 'package:wolf_dart/features/entities/map_objects.dart'; import 'package:wolf_dart/features/entities/map_objects.dart';
import 'package:wolf_dart/features/map/wolf_level.dart'; import 'package:wolf_dart/features/map/wolf_level.dart';
@@ -86,8 +86,8 @@ abstract class WolfMapParser {
} }
} }
Matrix<int> wallGrid = []; Sprite wallGrid = [];
Matrix<int> objectGrid = []; // NEW Sprite objectGrid = []; // NEW
for (int y = 0; y < height; y++) { for (int y = 0; y < height; y++) {
List<int> wallRow = []; List<int> wallRow = [];

View File

@@ -1,21 +1,21 @@
import 'dart:math' as math; import 'dart:math' as math;
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:wolf_3d_data/wolf_3d_data.dart';
import 'package:wolf_dart/classes/coordinate_2d.dart'; import 'package:wolf_dart/classes/coordinate_2d.dart';
import 'package:wolf_dart/classes/matrix.dart';
import 'package:wolf_dart/features/entities/entity.dart'; import 'package:wolf_dart/features/entities/entity.dart';
import 'package:wolf_dart/features/entities/pushwall_manager.dart'; // NEW IMPORT import 'package:wolf_dart/features/entities/pushwall_manager.dart';
import 'package:wolf_dart/features/player/player.dart'; import 'package:wolf_dart/features/player/player.dart';
import 'package:wolf_dart/features/renderer/color_palette.dart'; import 'package:wolf_dart/features/renderer/color_palette.dart';
class RaycasterPainter extends CustomPainter { class RaycasterPainter extends CustomPainter {
final Matrix<int> map; final Level map;
final List<Matrix<int>> textures; final List<Sprite> textures;
final Player player; final Player player;
final double fov; final double fov;
final Map<String, double> doorOffsets; final Map<String, double> doorOffsets;
final Pushwall? activePushwall; // NEW final Pushwall? activePushwall;
final List<Matrix<int>> sprites; final List<Sprite> sprites;
final List<Entity> entities; final List<Entity> entities;
RaycasterPainter({ RaycasterPainter({
@@ -24,7 +24,7 @@ class RaycasterPainter extends CustomPainter {
required this.player, required this.player,
required this.fov, required this.fov,
required this.doorOffsets, required this.doorOffsets,
this.activePushwall, // NEW this.activePushwall,
required this.sprites, required this.sprites,
required this.entities, required this.entities,
}); });
@@ -289,7 +289,7 @@ class RaycasterPainter extends CustomPainter {
double drawX = stripe * columnWidth; double drawX = stripe * columnWidth;
int safeIndex = entity.spriteIndex.clamp(0, sprites.length - 1); int safeIndex = entity.spriteIndex.clamp(0, sprites.length - 1);
Matrix<int> spritePixels = sprites[safeIndex]; Sprite spritePixels = sprites[safeIndex];
for (int ty = 0; ty < 64; ty++) { for (int ty = 0; ty < 64; ty++) {
int colorByte = spritePixels[texX][ty]; int colorByte = spritePixels[texX][ty];
@@ -322,7 +322,7 @@ class RaycasterPainter extends CustomPainter {
int side, int side,
Size size, Size size,
int hitWallId, int hitWallId,
List<Matrix<int>> textures, List<Sprite> textures,
double textureOffset, double textureOffset,
Paint paint, Paint paint,
) { ) {

View File

@@ -2,8 +2,8 @@ import 'dart:math' as math;
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/scheduler.dart'; import 'package:flutter/scheduler.dart';
import 'package:wolf_3d_data/wolf_3d_data.dart';
import 'package:wolf_dart/classes/coordinate_2d.dart'; import 'package:wolf_dart/classes/coordinate_2d.dart';
import 'package:wolf_dart/classes/matrix.dart';
import 'package:wolf_dart/features/difficulty/difficulty.dart'; import 'package:wolf_dart/features/difficulty/difficulty.dart';
import 'package:wolf_dart/features/entities/collectible.dart'; import 'package:wolf_dart/features/entities/collectible.dart';
import 'package:wolf_dart/features/entities/door_manager.dart'; import 'package:wolf_dart/features/entities/door_manager.dart';
@@ -45,7 +45,7 @@ class _WolfRendererState extends State<WolfRenderer>
late Ticker _gameLoop; late Ticker _gameLoop;
final FocusNode _focusNode = FocusNode(); final FocusNode _focusNode = FocusNode();
late WolfMap gameMap; late WolfMap gameMap;
late Matrix<int> currentLevel; late Level currentLevel;
final double fov = math.pi / 3; final double fov = math.pi / 3;
@@ -71,7 +71,7 @@ class _WolfRendererState extends State<WolfRenderer>
doorManager.initDoors(currentLevel); doorManager.initDoors(currentLevel);
final Matrix<int> objectLevel = gameMap.levels[0].objectGrid; final Level objectLevel = gameMap.levels[0].objectGrid;
pushwallManager.initPushwalls(currentLevel, objectLevel); pushwallManager.initPushwalls(currentLevel, objectLevel);

View File

@@ -1,5 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:wolf_dart/classes/sprite.dart'; import 'package:wolf_3d_data/wolf_3d_data.dart';
import 'package:wolf_dart/features/renderer/color_palette.dart'; import 'package:wolf_dart/features/renderer/color_palette.dart';
class WeaponPainter extends CustomPainter { class WeaponPainter extends CustomPainter {

View File

@@ -1,9 +1,9 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:wolf_dart/classes/matrix.dart'; import 'package:wolf_3d_data/wolf_3d_data.dart';
import 'package:wolf_dart/features/renderer/color_palette.dart'; import 'package:wolf_dart/features/renderer/color_palette.dart';
class SpriteGallery extends StatelessWidget { class SpriteGallery extends StatelessWidget {
final List<Matrix<int>> sprites; final List<Sprite> sprites;
const SpriteGallery({super.key, required this.sprites}); const SpriteGallery({super.key, required this.sprites});
@@ -42,7 +42,7 @@ class SpriteGallery extends StatelessWidget {
} }
class SingleSpritePainter extends CustomPainter { class SingleSpritePainter extends CustomPainter {
final Matrix<int> sprite; final Sprite sprite;
SingleSpritePainter({required this.sprite}); SingleSpritePainter({required this.sprite});
@override @override

7
packages/wolf_3d_data/.gitignore vendored Normal file
View File

@@ -0,0 +1,7 @@
# https://dart.dev/guides/libraries/private-files
# Created by `dart pub`
.dart_tool/
# Avoid committing pubspec.lock for library packages; see
# https://dart.dev/guides/libraries/private-files#pubspeclock.
pubspec.lock

View File

@@ -0,0 +1,3 @@
## 1.0.0
- Initial version.

View File

@@ -0,0 +1,39 @@
<!--
This README describes the package. If you publish this package to pub.dev,
this README's contents appear on the landing page for your package.
For information about how to write a good package README, see the guide for
[writing package pages](https://dart.dev/tools/pub/writing-package-pages).
For general information about developing packages, see the Dart guide for
[creating packages](https://dart.dev/guides/libraries/create-packages)
and the Flutter guide for
[developing packages and plugins](https://flutter.dev/to/develop-packages).
-->
TODO: Put a short description of the package here that helps potential users
know whether this package might be useful for them.
## Features
TODO: List what your package can do. Maybe include images, gifs, or videos.
## Getting started
TODO: List prerequisites and provide or point to information on how to
start using the package.
## Usage
TODO: Include short and useful examples for package users. Add longer examples
to `/example` folder.
```dart
const like = 'sample';
```
## Additional information
TODO: Tell users more about the package: where to find more information, how to
contribute to the package, how to file issues, what response they can expect
from the package authors, and more.

View File

@@ -0,0 +1,30 @@
# This file configures the static analysis results for your project (errors,
# warnings, and lints).
#
# This enables the 'recommended' set of lints from `package:lints`.
# This set helps identify many issues that may lead to problems when running
# or consuming Dart code, and enforces writing Dart using a single, idiomatic
# style and format.
#
# If you want a smaller set of lints you can change this to specify
# 'package:lints/core.yaml'. These are just the most critical lints
# (the recommended set includes the core lints).
# The core lints are also what is used by pub.dev for scoring packages.
include: package:lints/recommended.yaml
# Uncomment the following section to specify additional rules.
# linter:
# rules:
# - camel_case_types
# analyzer:
# exclude:
# - path/to/excluded/files/**
# For more information about the core and recommended set of lints, see
# https://dart.dev/go/core-lints
# For additional information about configuring this file, see
# https://dart.dev/guides/language/analysis-options

View File

@@ -0,0 +1,3 @@
import 'matrix.dart';
typedef Level = Matrix<int>;

View File

@@ -0,0 +1,3 @@
import 'matrix.dart';
typedef Sprite = Matrix<int>;

View File

@@ -1,11 +1,10 @@
import 'dart:typed_data'; import 'dart:typed_data';
import 'package:wolf_dart/classes/matrix.dart'; import 'classes/sprite.dart';
import 'package:wolf_dart/classes/sprite.dart';
class VswapParser { class VswapParser {
/// Extracts the 64x64 wall textures from VSWAP.WL1 /// Extracts the 64x64 wall textures from VSWAP.WL1
static List<Matrix<int>> parseWalls(ByteData vswap) { static List<Sprite> parseWalls(ByteData vswap) {
// 1. Read Header // 1. Read Header
int chunks = vswap.getUint16(0, Endian.little); int chunks = vswap.getUint16(0, Endian.little);
int spriteStart = vswap.getUint16(2, Endian.little); int spriteStart = vswap.getUint16(2, Endian.little);
@@ -42,7 +41,7 @@ class VswapParser {
} }
/// Extracts the compiled scaled sprites from VSWAP.WL1 /// Extracts the compiled scaled sprites from VSWAP.WL1
static List<Matrix<int>> parseSprites(ByteData vswap) { static List<Sprite> parseSprites(ByteData vswap) {
int chunks = vswap.getUint16(0, Endian.little); int chunks = vswap.getUint16(0, Endian.little);
int spriteStart = vswap.getUint16(2, Endian.little); int spriteStart = vswap.getUint16(2, Endian.little);
int soundStart = vswap.getUint16(4, Endian.little); int soundStart = vswap.getUint16(4, Endian.little);
@@ -52,7 +51,7 @@ class VswapParser {
offsets.add(vswap.getUint32(6 + (i * 4), Endian.little)); offsets.add(vswap.getUint32(6 + (i * 4), Endian.little));
} }
List<Matrix<int>> sprites = []; List<Sprite> sprites = [];
// Sprites are located between the walls and the sounds // Sprites are located between the walls and the sounds
for (int i = spriteStart; i < soundStart; i++) { for (int i = spriteStart; i < soundStart; i++) {
@@ -60,7 +59,7 @@ class VswapParser {
if (offset == 0) continue; // Some chunks are empty placeholders if (offset == 0) continue; // Some chunks are empty placeholders
// Initialize the 64x64 grid with 255 (The Magenta Transparency Color!) // Initialize the 64x64 grid with 255 (The Magenta Transparency Color!)
Matrix<int> sprite = List.generate(64, (_) => List.filled(64, 255)); Sprite sprite = List.generate(64, (_) => List.filled(64, 255));
int leftPix = vswap.getUint16(offset, Endian.little); int leftPix = vswap.getUint16(offset, Endian.little);
int rightPix = vswap.getUint16(offset + 2, Endian.little); int rightPix = vswap.getUint16(offset + 2, Endian.little);

View File

@@ -0,0 +1,8 @@
/// Support for doing something awesome.
///
/// More dartdocs go here.
library;
export 'src/classes/level.dart' show Level;
export 'src/classes/sprite.dart' show Sprite;
export 'src/vswap_parser.dart' show VswapParser;

View File

@@ -0,0 +1,13 @@
name: wolf_3d_data
description: A starting point for Dart libraries or applications.
version: 1.0.0
# repository: https://github.com/my_org/my_repo
environment:
sdk: ^3.11.1
resolution: workspace
dev_dependencies:
lints: ^6.0.0
test: ^1.25.6

View File

@@ -7,6 +7,7 @@ environment:
sdk: ^3.11.1 sdk: ^3.11.1
dependencies: dependencies:
wolf_3d_data: any
flutter: flutter:
sdk: flutter sdk: flutter
@@ -19,3 +20,6 @@ flutter:
uses-material-design: true uses-material-design: true
assets: assets:
- assets/ - assets/
workspace:
- packages/wolf_3d_data