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 'package:wolf_dart/classes/sprite.dart';
import 'package:wolf_3d_data/wolf_3d_data.dart';
import 'package:wolf_dart/features/map/door.dart';
class DoorManager {

View File

@@ -1,12 +1,12 @@
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';
class Pushwall {
int x;
int y;
int mapId; // The wall texture ID
int mapId;
int dirX = 0;
int dirY = 0;
double offset = 0.0;
@@ -19,7 +19,7 @@ class PushwallManager {
final Map<String, Pushwall> pushwalls = {};
Pushwall? activePushwall;
void initPushwalls(Matrix<int> wallGrid, Matrix<int> objectGrid) {
void initPushwalls(Sprite wallGrid, Sprite objectGrid) {
pushwalls.clear();
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;
final pw = activePushwall!;
@@ -85,7 +85,7 @@ class PushwallManager {
double playerX,
double playerY,
double playerAngle,
Matrix<int> wallGrid,
Sprite wallGrid,
) {
// Only one pushwall can move at a time in the original engine!
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 {
final String name;
final int width; // Always 64 in standard Wolf3D
final int height; // Always 64
final Matrix<int> wallGrid;
final Matrix<int> objectGrid;
final Sprite wallGrid;
final Sprite objectGrid;
WolfLevel({
required this.name,

View File

@@ -1,14 +1,13 @@
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_map_parser.dart';
import 'package:wolf_dart/vswap_parser.dart';
class WolfMap {
/// The fully parsed and decompressed levels from the game files.
final List<WolfLevel> levels;
final List<Matrix<int>> textures;
final List<Matrix<int>> sprites;
final List<Sprite> textures;
final List<Sprite> sprites;
// A private constructor so we can only instantiate this from the async loader
WolfMap._(

View File

@@ -1,7 +1,7 @@
import 'dart:convert';
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/map/wolf_level.dart';
@@ -86,8 +86,8 @@ abstract class WolfMapParser {
}
}
Matrix<int> wallGrid = [];
Matrix<int> objectGrid = []; // NEW
Sprite wallGrid = [];
Sprite objectGrid = []; // NEW
for (int y = 0; y < height; y++) {
List<int> wallRow = [];

View File

@@ -1,21 +1,21 @@
import 'dart:math' as math;
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/matrix.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/renderer/color_palette.dart';
class RaycasterPainter extends CustomPainter {
final Matrix<int> map;
final List<Matrix<int>> textures;
final Level map;
final List<Sprite> textures;
final Player player;
final double fov;
final Map<String, double> doorOffsets;
final Pushwall? activePushwall; // NEW
final List<Matrix<int>> sprites;
final Pushwall? activePushwall;
final List<Sprite> sprites;
final List<Entity> entities;
RaycasterPainter({
@@ -24,7 +24,7 @@ class RaycasterPainter extends CustomPainter {
required this.player,
required this.fov,
required this.doorOffsets,
this.activePushwall, // NEW
this.activePushwall,
required this.sprites,
required this.entities,
});
@@ -289,7 +289,7 @@ class RaycasterPainter extends CustomPainter {
double drawX = stripe * columnWidth;
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++) {
int colorByte = spritePixels[texX][ty];
@@ -322,7 +322,7 @@ class RaycasterPainter extends CustomPainter {
int side,
Size size,
int hitWallId,
List<Matrix<int>> textures,
List<Sprite> textures,
double textureOffset,
Paint paint,
) {

View File

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

View File

@@ -1,5 +1,5 @@
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';
class WeaponPainter extends CustomPainter {

View File

@@ -1,9 +1,9 @@
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';
class SpriteGallery extends StatelessWidget {
final List<Matrix<int>> sprites;
final List<Sprite> sprites;
const SpriteGallery({super.key, required this.sprites});
@@ -42,7 +42,7 @@ class SpriteGallery extends StatelessWidget {
}
class SingleSpritePainter extends CustomPainter {
final Matrix<int> sprite;
final Sprite sprite;
SingleSpritePainter({required this.sprite});
@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 'package:wolf_dart/classes/matrix.dart';
import 'package:wolf_dart/classes/sprite.dart';
import 'classes/sprite.dart';
class VswapParser {
/// Extracts the 64x64 wall textures from VSWAP.WL1
static List<Matrix<int>> parseWalls(ByteData vswap) {
static List<Sprite> parseWalls(ByteData vswap) {
// 1. Read Header
int chunks = vswap.getUint16(0, Endian.little);
int spriteStart = vswap.getUint16(2, Endian.little);
@@ -42,7 +41,7 @@ class VswapParser {
}
/// 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 spriteStart = vswap.getUint16(2, Endian.little);
int soundStart = vswap.getUint16(4, Endian.little);
@@ -52,7 +51,7 @@ class VswapParser {
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
for (int i = spriteStart; i < soundStart; i++) {
@@ -60,7 +59,7 @@ class VswapParser {
if (offset == 0) continue; // Some chunks are empty placeholders
// 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 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
dependencies:
wolf_3d_data: any
flutter:
sdk: flutter
@@ -19,3 +20,6 @@ flutter:
uses-material-design: true
assets:
- assets/
workspace:
- packages/wolf_3d_data