refactor: introduce SpriteOp/SpriteFlags, rename SpriteId to KnownSpriteId
Browse filesReplace raw u32 sprite_flags with typed SpriteOp (packed sprite index +
transform flags) and SpriteFlags (bitflags for the 13 known blit flags).
Follows the same pattern as SoundId/KnownSoundId in the audio system.
- SpriteId enum renamed to KnownSpriteId (non-exhaustive catalog)
- SpriteOp: #[repr(transparent)] newtype with index()/flags() accessors
- SpriteFlags: bitflags! type replacing raw 0x0080_0000-style masks
- Updated through the full pipeline: DrawSpriteCmd, RenderMessage,
vtable signature, dispatcher, and blit_sprite implementation
- Added bitflags 2 as direct dep (already transitive via windows crate)
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
- Cargo.lock +1 -0
- crates/openwa-core/Cargo.toml +1 -0
- crates/openwa-core/src/render/display/vtable.rs +2 -1
- crates/openwa-core/src/render/message.rs +2 -3
- crates/openwa-core/src/render/mod.rs +3 -1
- crates/openwa-core/src/render/queue.rs +2 -3
- crates/openwa-core/src/render/queue_dispatch.rs +10 -9
- crates/openwa-core/src/render/sprite/mod.rs +4 -2
- crates/openwa-core/src/render/sprite/sprite.rs +3 -4
- crates/openwa-core/src/render/sprite/sprite_id.rs +5 -3
- crates/openwa-core/src/render/sprite/sprite_op.rs +99 -0
- crates/openwa-core/src/task/cloud.rs +2 -1
- crates/openwa-dll/src/replacements/render.rs +22 -36
Cargo.lock
CHANGED
|
@@ -1498,6 +1498,7 @@ dependencies = [
|
|
| 1498 |
name = "openwa-core"
|
| 1499 |
version = "0.1.0"
|
| 1500 |
dependencies = [
|
|
|
|
| 1501 |
"gif",
|
| 1502 |
"heapless",
|
| 1503 |
"hound",
|
|
|
|
| 1498 |
name = "openwa-core"
|
| 1499 |
version = "0.1.0"
|
| 1500 |
dependencies = [
|
| 1501 |
+
"bitflags 2.11.0",
|
| 1502 |
"gif",
|
| 1503 |
"heapless",
|
| 1504 |
"hound",
|
crates/openwa-core/Cargo.toml
CHANGED
|
@@ -5,6 +5,7 @@ edition = "2021"
|
|
| 5 |
description = "Core library for Worms Armageddon reverse engineering — types, addresses, and runtime utilities"
|
| 6 |
|
| 7 |
[dependencies]
|
|
|
|
| 8 |
heapless = "0.9"
|
| 9 |
hound = "3"
|
| 10 |
inventory = "0.3.22"
|
|
|
|
| 5 |
description = "Core library for Worms Armageddon reverse engineering — types, addresses, and runtime utilities"
|
| 6 |
|
| 7 |
[dependencies]
|
| 8 |
+
bitflags = "2"
|
| 9 |
heapless = "0.9"
|
| 10 |
hound = "3"
|
| 11 |
inventory = "0.3.22"
|
crates/openwa-core/src/render/display/vtable.rs
CHANGED
|
@@ -11,6 +11,7 @@ use crate::render::display::layer::Layer;
|
|
| 11 |
use crate::render::display::line_draw::Vertex;
|
| 12 |
use crate::render::sprite::gfx_dir::GfxDir;
|
| 13 |
use crate::render::sprite::sprite::{LayerSprite, LayerSpriteFrame};
|
|
|
|
| 14 |
use crate::render::SpriteCache;
|
| 15 |
use crate::wa_alloc::wa_malloc_struct_zeroed;
|
| 16 |
|
|
@@ -208,7 +209,7 @@ pub struct DisplayGfxVtable {
|
|
| 208 |
/// (sprite width, sprite height, extra flags) via callee-saved registers.
|
| 209 |
/// These are not part of the thiscall ABI and cannot be expressed here.
|
| 210 |
#[slot(19)]
|
| 211 |
-
pub blit_sprite: fn(this: *mut DisplayGfx, x: Fixed, y: Fixed,
|
| 212 |
/// draw scaled/rotated sprite (0x56B660, RET 0x20)
|
| 213 |
///
|
| 214 |
/// x/y are fixed-point world coordinates.
|
|
|
|
| 11 |
use crate::render::display::line_draw::Vertex;
|
| 12 |
use crate::render::sprite::gfx_dir::GfxDir;
|
| 13 |
use crate::render::sprite::sprite::{LayerSprite, LayerSpriteFrame};
|
| 14 |
+
use crate::render::sprite::sprite_op::SpriteOp;
|
| 15 |
use crate::render::SpriteCache;
|
| 16 |
use crate::wa_alloc::wa_malloc_struct_zeroed;
|
| 17 |
|
|
|
|
| 209 |
/// (sprite width, sprite height, extra flags) via callee-saved registers.
|
| 210 |
/// These are not part of the thiscall ABI and cannot be expressed here.
|
| 211 |
#[slot(19)]
|
| 212 |
+
pub blit_sprite: fn(this: *mut DisplayGfx, x: Fixed, y: Fixed, sprite: SpriteOp, palette: u32),
|
| 213 |
/// draw scaled/rotated sprite (0x56B660, RET 0x20)
|
| 214 |
///
|
| 215 |
/// x/y are fixed-point world coordinates.
|
crates/openwa-core/src/render/message.rs
CHANGED
|
@@ -14,6 +14,7 @@
|
|
| 14 |
//! commands simultaneously until all producers are migrated.
|
| 15 |
|
| 16 |
use crate::fixed::Fixed;
|
|
|
|
| 17 |
|
| 18 |
/// Sentinel `command_type` value for [`TypedRenderCmd`]. Sits outside
|
| 19 |
/// the legacy 0..=0xE range so the existing per-case dispatcher arms
|
|
@@ -41,9 +42,7 @@ pub enum RenderMessage {
|
|
| 41 |
local: bool,
|
| 42 |
x: Fixed,
|
| 43 |
y: Fixed,
|
| 44 |
-
|
| 45 |
-
/// `DisplayGfx::blit_sprite` slot 19 as `sprite_flags`.
|
| 46 |
-
sprite_flags: u32,
|
| 47 |
/// Palette context — passed to `blit_sprite` as the last arg.
|
| 48 |
/// Semantics vary by producer (palette pointer, animation index, etc.).
|
| 49 |
palette: u32,
|
|
|
|
| 14 |
//! commands simultaneously until all producers are migrated.
|
| 15 |
|
| 16 |
use crate::fixed::Fixed;
|
| 17 |
+
use crate::render::sprite::sprite_op::SpriteOp;
|
| 18 |
|
| 19 |
/// Sentinel `command_type` value for [`TypedRenderCmd`]. Sits outside
|
| 20 |
/// the legacy 0..=0xE range so the existing per-case dispatcher arms
|
|
|
|
| 42 |
local: bool,
|
| 43 |
x: Fixed,
|
| 44 |
y: Fixed,
|
| 45 |
+
sprite: SpriteOp,
|
|
|
|
|
|
|
| 46 |
/// Palette context — passed to `blit_sprite` as the last arg.
|
| 47 |
/// Semantics vary by producer (palette pointer, animation index, etc.).
|
| 48 |
palette: u32,
|
crates/openwa-core/src/render/mod.rs
CHANGED
|
@@ -22,7 +22,9 @@ pub use queue::{
|
|
| 22 |
DrawBitmapGlobalCmd, DrawCrosshairCmd, DrawLineStripHeader, DrawPolygonHeader, DrawRectCmd,
|
| 23 |
DrawSpriteCmd, DrawSpriteOffsetCmd, DrawTextboxLocalCmd, DrawTiledBitmapCmd, RenderQueue,
|
| 24 |
};
|
| 25 |
-
pub use sprite::{
|
|
|
|
|
|
|
| 26 |
pub use turn_order::{
|
| 27 |
AnimatedItemList, TurnOrderAllianceGroup, TurnOrderTeamEntry, TurnOrderWidget,
|
| 28 |
};
|
|
|
|
| 22 |
DrawBitmapGlobalCmd, DrawCrosshairCmd, DrawLineStripHeader, DrawPolygonHeader, DrawRectCmd,
|
| 23 |
DrawSpriteCmd, DrawSpriteOffsetCmd, DrawTextboxLocalCmd, DrawTiledBitmapCmd, RenderQueue,
|
| 24 |
};
|
| 25 |
+
pub use sprite::{
|
| 26 |
+
KnownSpriteId, ParsedSprite, Sprite, SpriteBank, SpriteFlags, SpriteFrame, SpriteOp,
|
| 27 |
+
};
|
| 28 |
pub use turn_order::{
|
| 29 |
AnimatedItemList, TurnOrderAllianceGroup, TurnOrderTeamEntry, TurnOrderWidget,
|
| 30 |
};
|
crates/openwa-core/src/render/queue.rs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
| 1 |
use super::message::{RenderMessage, TypedRenderCmd, COMMAND_TYPE_TYPED};
|
|
|
|
| 2 |
|
| 3 |
/// Render command entry (0x18 bytes).
|
| 4 |
///
|
|
@@ -13,9 +14,7 @@ pub struct DrawSpriteCmd {
|
|
| 13 |
pub x_pos: u32,
|
| 14 |
/// Y position, upper 16 bits used (Fixed16 format)
|
| 15 |
pub y_pos: u32,
|
| 16 |
-
|
| 17 |
-
/// `DisplayGfx::blit_sprite` (vtable slot 19) as `sprite_flags`.
|
| 18 |
-
pub sprite_flags: u32,
|
| 19 |
/// Palette context — passed to `blit_sprite` as the last arg.
|
| 20 |
/// Semantics vary by producer (palette pointer, animation index, etc.).
|
| 21 |
pub palette: u32,
|
|
|
|
| 1 |
use super::message::{RenderMessage, TypedRenderCmd, COMMAND_TYPE_TYPED};
|
| 2 |
+
use super::sprite::sprite_op::SpriteOp;
|
| 3 |
|
| 4 |
/// Render command entry (0x18 bytes).
|
| 5 |
///
|
|
|
|
| 14 |
pub x_pos: u32,
|
| 15 |
/// Y position, upper 16 bits used (Fixed16 format)
|
| 16 |
pub y_pos: u32,
|
| 17 |
+
pub sprite: SpriteOp,
|
|
|
|
|
|
|
| 18 |
/// Palette context — passed to `blit_sprite` as the last arg.
|
| 19 |
/// Semantics vary by producer (palette pointer, animation index, etc.).
|
| 20 |
pub palette: u32,
|
crates/openwa-core/src/render/queue_dispatch.rs
CHANGED
|
@@ -56,6 +56,7 @@ use crate::fixed::Fixed;
|
|
| 56 |
use crate::render::display::gfx::DisplayGfx;
|
| 57 |
use crate::render::message::{RenderMessage, TypedRenderCmd, COMMAND_TYPE_TYPED};
|
| 58 |
use crate::render::queue::RenderQueue;
|
|
|
|
| 59 |
|
| 60 |
// =============================================================================
|
| 61 |
// ClipContext — the 4-i32 anchor/pivot block GameRender_Maybe builds on stack
|
|
@@ -533,9 +534,9 @@ unsafe fn dispatch_case_3_via_callback(
|
|
| 533 |
unsafe fn dispatch_case_4_sprite_global(display: *mut DisplayGfx, cmd: *const u32) {
|
| 534 |
let x = read_fixed(cmd, 2);
|
| 535 |
let y = read_fixed(cmd, 3);
|
| 536 |
-
let
|
| 537 |
let palette = *(cmd.add(5));
|
| 538 |
-
DisplayGfx::blit_sprite_raw(display, x, y,
|
| 539 |
}
|
| 540 |
|
| 541 |
// ---- case 5: DRAW_SPRITE_LOCAL → slot 19 (blit_sprite) ---------------------
|
|
@@ -550,9 +551,9 @@ unsafe fn dispatch_case_5_sprite_local(
|
|
| 550 |
let mut x = Fixed::ZERO;
|
| 551 |
let mut y = Fixed::ZERO;
|
| 552 |
rq_translate_coordinates(clip, read_fixed(cmd, 2), read_fixed(cmd, 3), &mut x, &mut y);
|
| 553 |
-
let
|
| 554 |
let palette = *(cmd.add(5));
|
| 555 |
-
DisplayGfx::blit_sprite_raw(display, x, y,
|
| 556 |
}
|
| 557 |
|
| 558 |
// ---- case 6: DRAW_SPRITE_OFFSET → slot 19 (blit_sprite) --------------------
|
|
@@ -624,9 +625,9 @@ unsafe fn dispatch_case_6_sprite_offset(
|
|
| 624 |
}
|
| 625 |
}
|
| 626 |
|
| 627 |
-
let
|
| 628 |
let palette = *(cmd.add(8));
|
| 629 |
-
DisplayGfx::blit_sprite_raw(display, x, y,
|
| 630 |
}
|
| 631 |
|
| 632 |
// ---- case 7 → slot 12 (draw_polyline) --------------------------------------
|
|
@@ -930,7 +931,7 @@ unsafe fn dispatch_typed(display: *mut DisplayGfx, clip: &ClipContext, msg: &Ren
|
|
| 930 |
local,
|
| 931 |
x,
|
| 932 |
y,
|
| 933 |
-
|
| 934 |
palette,
|
| 935 |
} => {
|
| 936 |
if local {
|
|
@@ -938,10 +939,10 @@ unsafe fn dispatch_typed(display: *mut DisplayGfx, clip: &ClipContext, msg: &Ren
|
|
| 938 |
let mut out_x = Fixed::ZERO;
|
| 939 |
let mut out_y = Fixed::ZERO;
|
| 940 |
rq_translate_coordinates(clip, x, y, &mut out_x, &mut out_y);
|
| 941 |
-
DisplayGfx::blit_sprite_raw(display, out_x, out_y,
|
| 942 |
} else {
|
| 943 |
// World-space: pass through directly (same as case 4).
|
| 944 |
-
DisplayGfx::blit_sprite_raw(display, x, y,
|
| 945 |
}
|
| 946 |
}
|
| 947 |
}
|
|
|
|
| 56 |
use crate::render::display::gfx::DisplayGfx;
|
| 57 |
use crate::render::message::{RenderMessage, TypedRenderCmd, COMMAND_TYPE_TYPED};
|
| 58 |
use crate::render::queue::RenderQueue;
|
| 59 |
+
use crate::render::sprite::sprite_op::SpriteOp;
|
| 60 |
|
| 61 |
// =============================================================================
|
| 62 |
// ClipContext — the 4-i32 anchor/pivot block GameRender_Maybe builds on stack
|
|
|
|
| 534 |
unsafe fn dispatch_case_4_sprite_global(display: *mut DisplayGfx, cmd: *const u32) {
|
| 535 |
let x = read_fixed(cmd, 2);
|
| 536 |
let y = read_fixed(cmd, 3);
|
| 537 |
+
let sprite = SpriteOp(*(cmd.add(4)));
|
| 538 |
let palette = *(cmd.add(5));
|
| 539 |
+
DisplayGfx::blit_sprite_raw(display, x, y, sprite, palette);
|
| 540 |
}
|
| 541 |
|
| 542 |
// ---- case 5: DRAW_SPRITE_LOCAL → slot 19 (blit_sprite) ---------------------
|
|
|
|
| 551 |
let mut x = Fixed::ZERO;
|
| 552 |
let mut y = Fixed::ZERO;
|
| 553 |
rq_translate_coordinates(clip, read_fixed(cmd, 2), read_fixed(cmd, 3), &mut x, &mut y);
|
| 554 |
+
let sprite = SpriteOp(*(cmd.add(4)));
|
| 555 |
let palette = *(cmd.add(5));
|
| 556 |
+
DisplayGfx::blit_sprite_raw(display, x, y, sprite, palette);
|
| 557 |
}
|
| 558 |
|
| 559 |
// ---- case 6: DRAW_SPRITE_OFFSET → slot 19 (blit_sprite) --------------------
|
|
|
|
| 625 |
}
|
| 626 |
}
|
| 627 |
|
| 628 |
+
let sprite = SpriteOp(*(cmd.add(7)));
|
| 629 |
let palette = *(cmd.add(8));
|
| 630 |
+
DisplayGfx::blit_sprite_raw(display, x, y, sprite, palette);
|
| 631 |
}
|
| 632 |
|
| 633 |
// ---- case 7 → slot 12 (draw_polyline) --------------------------------------
|
|
|
|
| 931 |
local,
|
| 932 |
x,
|
| 933 |
y,
|
| 934 |
+
sprite,
|
| 935 |
palette,
|
| 936 |
} => {
|
| 937 |
if local {
|
|
|
|
| 939 |
let mut out_x = Fixed::ZERO;
|
| 940 |
let mut out_y = Fixed::ZERO;
|
| 941 |
rq_translate_coordinates(clip, x, y, &mut out_x, &mut out_y);
|
| 942 |
+
DisplayGfx::blit_sprite_raw(display, out_x, out_y, sprite, palette);
|
| 943 |
} else {
|
| 944 |
// World-space: pass through directly (same as case 4).
|
| 945 |
+
DisplayGfx::blit_sprite_raw(display, x, y, sprite, palette);
|
| 946 |
}
|
| 947 |
}
|
| 948 |
}
|
crates/openwa-core/src/render/sprite/mod.rs
CHANGED
|
@@ -4,11 +4,13 @@ pub mod lzss;
|
|
| 4 |
pub mod spr;
|
| 5 |
pub mod sprite;
|
| 6 |
pub mod sprite_id;
|
|
|
|
| 7 |
|
| 8 |
pub use frame_cache::frame_cache_allocate;
|
| 9 |
pub use lzss::sprite_lzss_decode;
|
| 10 |
pub use spr::{ParsedSprite, SprError, SprHeader};
|
| 11 |
pub use sprite::{
|
| 12 |
-
Sprite, SpriteBank, SpriteBankBboxEntry, SpriteBankFrame,
|
| 13 |
-
|
|
|
|
| 14 |
};
|
|
|
|
| 4 |
pub mod spr;
|
| 5 |
pub mod sprite;
|
| 6 |
pub mod sprite_id;
|
| 7 |
+
pub mod sprite_op;
|
| 8 |
|
| 9 |
pub use frame_cache::frame_cache_allocate;
|
| 10 |
pub use lzss::sprite_lzss_decode;
|
| 11 |
pub use spr::{ParsedSprite, SprError, SprHeader};
|
| 12 |
pub use sprite::{
|
| 13 |
+
KnownSpriteId, Sprite, SpriteBank, SpriteBankBboxEntry, SpriteBankFrame,
|
| 14 |
+
SpriteBankSubframeCache, SpriteBankVtable, SpriteFlags, SpriteFrame, SpriteOp,
|
| 15 |
+
SpriteSubframeCache, SpriteVtable,
|
| 16 |
};
|
crates/openwa-core/src/render/sprite/sprite.rs
CHANGED
|
@@ -2,10 +2,9 @@ use crate::render::{
|
|
| 2 |
display::gfx::DisplayGfx, palette::PaletteContext, sprite::gfx_dir::GfxDir, SpriteCache,
|
| 3 |
};
|
| 4 |
|
| 5 |
-
// Re-export
|
| 6 |
-
pub use super::sprite_id::
|
| 7 |
-
|
| 8 |
-
// (SpriteId enum moved to sprite_id.rs)
|
| 9 |
/// Per-frame metadata within a Sprite (0x0C bytes).
|
| 10 |
///
|
| 11 |
/// Describes the bounding box and bitmap data offset for one animation frame.
|
|
|
|
| 2 |
display::gfx::DisplayGfx, palette::PaletteContext, sprite::gfx_dir::GfxDir, SpriteCache,
|
| 3 |
};
|
| 4 |
|
| 5 |
+
// Re-export sprite types from their own modules to keep this file focused on struct layouts.
|
| 6 |
+
pub use super::sprite_id::KnownSpriteId;
|
| 7 |
+
pub use super::sprite_op::{SpriteFlags, SpriteOp};
|
|
|
|
| 8 |
/// Per-frame metadata within a Sprite (0x0C bytes).
|
| 9 |
///
|
| 10 |
/// Describes the bounding box and bitmap data offset for one animation frame.
|
crates/openwa-core/src/render/sprite/sprite_id.rs
CHANGED
|
@@ -1,13 +1,15 @@
|
|
| 1 |
-
///
|
| 2 |
///
|
| 3 |
/// Names preserved from the original sprite file names in the game data.
|
| 4 |
/// The original names are terse 8-character identifiers from the game's
|
| 5 |
/// sprite sheets.
|
| 6 |
///
|
|
|
|
|
|
|
| 7 |
/// Source: wkJellyWorm Constants.h
|
| 8 |
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
| 9 |
#[repr(u32)]
|
| 10 |
-
pub enum
|
| 11 |
Cdrom = 1,
|
| 12 |
CrshairR = 2,
|
| 13 |
CrshairB = 3,
|
|
@@ -705,7 +707,7 @@ pub enum SpriteId {
|
|
| 705 |
WBz5LnkD = 696,
|
| 706 |
}
|
| 707 |
|
| 708 |
-
impl TryFrom<u32> for
|
| 709 |
type Error = u32;
|
| 710 |
|
| 711 |
fn try_from(value: u32) -> Result<Self, Self::Error> {
|
|
|
|
| 1 |
+
/// Known sprite/animation frame IDs. Range 1-696 with gaps at 620-621.
|
| 2 |
///
|
| 3 |
/// Names preserved from the original sprite file names in the game data.
|
| 4 |
/// The original names are terse 8-character identifiers from the game's
|
| 5 |
/// sprite sheets.
|
| 6 |
///
|
| 7 |
+
/// Not exhaustive — unknown IDs can still be represented via [`SpriteOp`].
|
| 8 |
+
///
|
| 9 |
/// Source: wkJellyWorm Constants.h
|
| 10 |
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
| 11 |
#[repr(u32)]
|
| 12 |
+
pub enum KnownSpriteId {
|
| 13 |
Cdrom = 1,
|
| 14 |
CrshairR = 2,
|
| 15 |
CrshairB = 3,
|
|
|
|
| 707 |
WBz5LnkD = 696,
|
| 708 |
}
|
| 709 |
|
| 710 |
+
impl TryFrom<u32> for KnownSpriteId {
|
| 711 |
type Error = u32;
|
| 712 |
|
| 713 |
fn try_from(value: u32) -> Result<Self, Self::Error> {
|
crates/openwa-core/src/render/sprite/sprite_op.rs
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
use core::fmt;
|
| 2 |
+
|
| 3 |
+
use super::sprite_id::KnownSpriteId;
|
| 4 |
+
|
| 5 |
+
/// Packed sprite index + transform flags, passed as a single u32.
|
| 6 |
+
///
|
| 7 |
+
/// Layout (from `DisplayGfx::blit_sprite` at 0x56B080):
|
| 8 |
+
/// - Bits 0-15: sprite index (0 = none, 1-696 for known sprites)
|
| 9 |
+
/// - Bits 16-28: transform/rendering flags (see [`SpriteFlags`])
|
| 10 |
+
///
|
| 11 |
+
/// Used throughout the render pipeline: enqueue functions write it,
|
| 12 |
+
/// the render queue stores it, and `blit_sprite` unpacks it.
|
| 13 |
+
#[derive(Clone, Copy, PartialEq, Eq, Hash)]
|
| 14 |
+
#[repr(transparent)]
|
| 15 |
+
pub struct SpriteOp(pub u32);
|
| 16 |
+
|
| 17 |
+
impl SpriteOp {
|
| 18 |
+
/// No sprite (index 0).
|
| 19 |
+
pub const NONE: Self = Self(0);
|
| 20 |
+
|
| 21 |
+
/// Sprite index (low 16 bits). 0 = no sprite.
|
| 22 |
+
#[inline]
|
| 23 |
+
pub const fn index(self) -> u16 {
|
| 24 |
+
(self.0 & 0xFFFF) as u16
|
| 25 |
+
}
|
| 26 |
+
|
| 27 |
+
/// Transform/rendering flag bits (high 16 bits).
|
| 28 |
+
#[inline]
|
| 29 |
+
pub fn flags(self) -> SpriteFlags {
|
| 30 |
+
SpriteFlags::from_bits_truncate(self.0 & 0xFFFF_0000)
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
/// Construct from sprite index only (no flags).
|
| 34 |
+
#[inline]
|
| 35 |
+
pub const fn from_index(index: u16) -> Self {
|
| 36 |
+
Self(index as u32)
|
| 37 |
+
}
|
| 38 |
+
|
| 39 |
+
/// Construct from index + flags.
|
| 40 |
+
#[inline]
|
| 41 |
+
pub const fn new(index: u16, flags: SpriteFlags) -> Self {
|
| 42 |
+
Self(index as u32 | flags.bits())
|
| 43 |
+
}
|
| 44 |
+
}
|
| 45 |
+
|
| 46 |
+
impl fmt::Debug for SpriteOp {
|
| 47 |
+
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
| 48 |
+
let idx = self.index();
|
| 49 |
+
let flags = self.flags();
|
| 50 |
+
if flags.is_empty() {
|
| 51 |
+
write!(f, "SpriteOp({idx})")
|
| 52 |
+
} else {
|
| 53 |
+
write!(f, "SpriteOp({idx}, {flags:?})")
|
| 54 |
+
}
|
| 55 |
+
}
|
| 56 |
+
}
|
| 57 |
+
|
| 58 |
+
impl From<KnownSpriteId> for SpriteOp {
|
| 59 |
+
#[inline]
|
| 60 |
+
fn from(known: KnownSpriteId) -> Self {
|
| 61 |
+
Self(known as u32)
|
| 62 |
+
}
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
bitflags::bitflags! {
|
| 66 |
+
/// Transform/rendering flags for sprite blit operations (high 16 bits
|
| 67 |
+
/// of [`SpriteOp`]).
|
| 68 |
+
///
|
| 69 |
+
/// Documented from `DisplayGfx::blit_sprite` at 0x56B080.
|
| 70 |
+
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
|
| 71 |
+
pub struct SpriteFlags: u32 {
|
| 72 |
+
/// Tiled rendering mode.
|
| 73 |
+
const TILED = 0x0001_0000;
|
| 74 |
+
/// Additional orientation bit.
|
| 75 |
+
const ORIENTATION = 0x0002_0000;
|
| 76 |
+
/// Extra horizontal mirror.
|
| 77 |
+
const MIRROR_X = 0x0004_0000;
|
| 78 |
+
/// Extra vertical mirror.
|
| 79 |
+
const MIRROR_Y = 0x0008_0000;
|
| 80 |
+
/// Stippled palette adjustment.
|
| 81 |
+
const STIPPLED_PAL = 0x0010_0000;
|
| 82 |
+
/// Additive blend mode.
|
| 83 |
+
const ADDITIVE = 0x0020_0000;
|
| 84 |
+
/// Shadow clear mode.
|
| 85 |
+
const SHADOW_CLEAR = 0x0040_0000;
|
| 86 |
+
/// Invert palette values.
|
| 87 |
+
const INVERT_PALETTE = 0x0080_0000;
|
| 88 |
+
/// Palette ×4 adjustment.
|
| 89 |
+
const PALETTE_X4 = 0x0100_0000;
|
| 90 |
+
/// Palette transform (color cycling).
|
| 91 |
+
const PALETTE_XFORM = 0x0200_0000;
|
| 92 |
+
/// Color blend mode.
|
| 93 |
+
const COLOR_BLEND = 0x0400_0000;
|
| 94 |
+
/// Stippled rendering mode 0.
|
| 95 |
+
const STIPPLED_0 = 0x0800_0000;
|
| 96 |
+
/// Stippled rendering mode 1.
|
| 97 |
+
const STIPPLED_1 = 0x1000_0000;
|
| 98 |
+
}
|
| 99 |
+
}
|
crates/openwa-core/src/task/cloud.rs
CHANGED
|
@@ -109,6 +109,7 @@ bind_CTaskCloudVTable!(CTaskCloud, base.vtable);
|
|
| 109 |
|
| 110 |
use crate::game::TaskMessage;
|
| 111 |
use crate::render::message::RenderMessage;
|
|
|
|
| 112 |
|
| 113 |
/// CTaskCloud::HandleMessage replacement — pure game logic.
|
| 114 |
///
|
|
@@ -183,7 +184,7 @@ pub unsafe extern "thiscall" fn cloud_handle_message(
|
|
| 183 |
local: true,
|
| 184 |
x: Fixed(x).floor(),
|
| 185 |
y: (*this).render_y.floor(),
|
| 186 |
-
|
| 187 |
palette: (*this).anim_phase.0 as u32,
|
| 188 |
},
|
| 189 |
);
|
|
|
|
| 109 |
|
| 110 |
use crate::game::TaskMessage;
|
| 111 |
use crate::render::message::RenderMessage;
|
| 112 |
+
use crate::render::sprite::sprite_op::SpriteOp;
|
| 113 |
|
| 114 |
/// CTaskCloud::HandleMessage replacement — pure game logic.
|
| 115 |
///
|
|
|
|
| 184 |
local: true,
|
| 185 |
x: Fixed(x).floor(),
|
| 186 |
y: (*this).render_y.floor(),
|
| 187 |
+
sprite: SpriteOp((*this).sprite_id),
|
| 188 |
palette: (*this).anim_phase.0 as u32,
|
| 189 |
},
|
| 190 |
);
|
crates/openwa-dll/src/replacements/render.rs
CHANGED
|
@@ -11,6 +11,7 @@ use openwa_core::address::va;
|
|
| 11 |
use openwa_core::rebase::rb;
|
| 12 |
use openwa_core::render::queue::*;
|
| 13 |
use openwa_core::render::sprite::gfx_dir::GfxDir;
|
|
|
|
| 14 |
use openwa_core::task::{BungeeTrailTask, WeaponAimTask};
|
| 15 |
|
| 16 |
use crate::hook::{self, usercall_trampoline};
|
|
@@ -211,7 +212,7 @@ unsafe extern "cdecl" fn draw_sprite_global_impl(
|
|
| 211 |
layer,
|
| 212 |
x_pos: x_pos & 0xFFFF0000,
|
| 213 |
y_pos: y_pos & 0xFFFF0000,
|
| 214 |
-
|
| 215 |
palette: frame,
|
| 216 |
};
|
| 217 |
}
|
|
@@ -240,7 +241,7 @@ unsafe extern "cdecl" fn draw_sprite_local_impl(
|
|
| 240 |
layer,
|
| 241 |
x_pos: x_pos & 0xFFFF0000,
|
| 242 |
y_pos: y_pos & 0xFFFF0000,
|
| 243 |
-
|
| 244 |
palette: frame,
|
| 245 |
};
|
| 246 |
}
|
|
@@ -419,7 +420,7 @@ unsafe extern "stdcall" fn draw_bungee_trail_impl(task_ptr: u32, style: u32, fil
|
|
| 419 |
layer: 0xDFFFF,
|
| 420 |
x_pos: x as u32 & 0xFFFF0000,
|
| 421 |
y_pos: y as u32 & 0xFFFF0000,
|
| 422 |
-
|
| 423 |
palette: (first_angle + 0x8100) as u32,
|
| 424 |
};
|
| 425 |
}
|
|
@@ -592,7 +593,7 @@ unsafe extern "cdecl" fn draw_crosshair_line_impl(task_ptr: u32) {
|
|
| 592 |
layer: 0x4_0000,
|
| 593 |
x_pos: endpoint_x as u32 & 0xFFFF0000,
|
| 594 |
y_pos: endpoint_y as u32 & 0xFFFF0000,
|
| 595 |
-
|
| 596 |
palette: (0x8000u32).wrapping_sub(angle),
|
| 597 |
};
|
| 598 |
}
|
|
@@ -766,22 +767,6 @@ unsafe extern "thiscall" fn headless_destructor(
|
|
| 766 |
///
|
| 767 |
/// Standard thiscall: ECX=this, stack params: x, y, sprite_flags, palette (RET 0x10).
|
| 768 |
///
|
| 769 |
-
/// sprite_flags layout:
|
| 770 |
-
/// low 16 bits = sprite ID (0 = no sprite)
|
| 771 |
-
/// high 16 bits = orientation/flags:
|
| 772 |
-
/// bit 16 (0x10000): tiled mode
|
| 773 |
-
/// bit 17: additional orientation
|
| 774 |
-
/// bit 18 (0x40000): extra mirror X
|
| 775 |
-
/// bit 19 (0x80000): extra mirror Y
|
| 776 |
-
/// bit 20 (0x100000): stippled palette adjust
|
| 777 |
-
/// bit 21 (0x200000): additive blend
|
| 778 |
-
/// bit 22 (0x400000): shadow clear
|
| 779 |
-
/// bit 23 (0x800000): invert palette
|
| 780 |
-
/// bit 24 (0x1000000): palette x4 adjust
|
| 781 |
-
/// bit 25 (0x2000000): palette transform
|
| 782 |
-
/// bit 26 (0x4000000): color blend
|
| 783 |
-
/// bit 27 (0x8000000): stippled mode 0
|
| 784 |
-
/// bit 28 (0x10000000): stippled mode 1
|
| 785 |
unsafe extern "thiscall" fn blit_sprite(
|
| 786 |
this: *mut DisplayGfx,
|
| 787 |
x: Fixed,
|
|
@@ -791,15 +776,17 @@ unsafe extern "thiscall" fn blit_sprite(
|
|
| 791 |
) {
|
| 792 |
use openwa_core::render::display::gfx::DisplayGfx;
|
| 793 |
use openwa_core::render::display::vtable as display_vtable;
|
|
|
|
| 794 |
|
| 795 |
let gfx = this as *mut DisplayGfx;
|
| 796 |
let base = this as *const u8;
|
| 797 |
|
| 798 |
// ---------------------------------------------------------------
|
| 799 |
-
// Extract sprite
|
| 800 |
// ---------------------------------------------------------------
|
| 801 |
-
let
|
| 802 |
-
let
|
|
|
|
| 803 |
|
| 804 |
if sprite_id == 0 {
|
| 805 |
return;
|
|
@@ -809,15 +796,14 @@ unsafe extern "thiscall" fn blit_sprite(
|
|
| 809 |
// Palette manipulation
|
| 810 |
// ---------------------------------------------------------------
|
| 811 |
let mut pal: u32 = palette;
|
| 812 |
-
if (
|
| 813 |
-
// Bit 23: invert palette
|
| 814 |
pal = 0x10000u32.wrapping_sub(palette);
|
| 815 |
if sprite_id.wrapping_sub(0x1D5) < 3 {
|
| 816 |
// Special sprite IDs: scale by 8/18
|
| 817 |
pal = (0x10000u32.wrapping_sub(palette).wrapping_mul(8)) / 0x12;
|
| 818 |
}
|
| 819 |
}
|
| 820 |
-
if (
|
| 821 |
// Bit 25: palette transform (modular arithmetic for color cycling)
|
| 822 |
let tmp = ((pal.wrapping_mul(0x1F) as i32)
|
| 823 |
.wrapping_add(((pal.wrapping_mul(0x1F) as i32) >> 31) & 0x1F)
|
|
@@ -871,7 +857,7 @@ unsafe extern "thiscall" fn blit_sprite(
|
|
| 871 |
let dst_x = (x.0 >> 16) + (camera_x - half_w) + rect_left;
|
| 872 |
let dst_y = (y.0 >> 16) + (camera_y - half_h) + rect_top;
|
| 873 |
|
| 874 |
-
if (
|
| 875 |
// Non-tiled: clipped blit at (dst_x, dst_y).
|
| 876 |
display_vtable::blit_bitmap_clipped_native(
|
| 877 |
gfx, dst_x, dst_y, sprite_w, blit_h, frame_data, 2,
|
|
@@ -892,7 +878,7 @@ unsafe extern "thiscall" fn blit_sprite(
|
|
| 892 |
// that writes extra orientation bits into the local orient variable.
|
| 893 |
// For now, handle the simple case:
|
| 894 |
let mut orient_local: u32 = 0x0000_0001; // blend=1 (ColorTable/transparency), orientation=0 (Normal)
|
| 895 |
-
if (
|
| 896 |
// The ASM computes: pal = pal * 4 + 0x8000, then maps (pal >> 16) & 3
|
| 897 |
// to set specific orient values (0x80001, 0xC0001, 0x40001)
|
| 898 |
let scaled = pal.wrapping_mul(4).wrapping_add(0x8000);
|
|
@@ -955,7 +941,7 @@ unsafe extern "thiscall" fn blit_sprite(
|
|
| 955 |
// ---------------------------------------------------------------
|
| 956 |
// Shadow clear (high_flags bit 22)
|
| 957 |
// ---------------------------------------------------------------
|
| 958 |
-
if (
|
| 959 |
// Blit sprite to layer_2 as shadow base
|
| 960 |
let layer2 = (*gfx).layer_2;
|
| 961 |
super::bitgrid::blit_impl(
|
|
@@ -990,10 +976,10 @@ unsafe extern "thiscall" fn blit_sprite(
|
|
| 990 |
// ---------------------------------------------------------------
|
| 991 |
// Extra orientation flags from high_flags
|
| 992 |
// ---------------------------------------------------------------
|
| 993 |
-
if (
|
| 994 |
orient_local |= 0x0001_0000;
|
| 995 |
}
|
| 996 |
-
if (
|
| 997 |
orient_local |= 0x0002_0000;
|
| 998 |
}
|
| 999 |
|
|
@@ -1081,8 +1067,8 @@ unsafe extern "thiscall" fn blit_sprite(
|
|
| 1081 |
}
|
| 1082 |
|
| 1083 |
// Stippled mode (checkerboard per-pixel blit)
|
| 1084 |
-
if (
|
| 1085 |
-
let stipple_mode: u32 = if (
|
| 1086 |
1
|
| 1087 |
} else {
|
| 1088 |
0
|
|
@@ -1107,7 +1093,7 @@ unsafe extern "thiscall" fn blit_sprite(
|
|
| 1107 |
}
|
| 1108 |
|
| 1109 |
// Tiled mode (horizontal sprite tiling)
|
| 1110 |
-
if (
|
| 1111 |
display_vtable::acquire_render_lock(gfx);
|
| 1112 |
|
| 1113 |
super::bitgrid::blit_tiled_raw(
|
|
@@ -1125,9 +1111,9 @@ unsafe extern "thiscall" fn blit_sprite(
|
|
| 1125 |
}
|
| 1126 |
|
| 1127 |
// Determine color table pointer
|
| 1128 |
-
let color_table: *const u8 = if (
|
| 1129 |
(*gfx).color_add_table.as_ptr()
|
| 1130 |
-
} else if (
|
| 1131 |
(*gfx).color_blend_table.as_ptr()
|
| 1132 |
} else {
|
| 1133 |
core::ptr::null()
|
|
|
|
| 11 |
use openwa_core::rebase::rb;
|
| 12 |
use openwa_core::render::queue::*;
|
| 13 |
use openwa_core::render::sprite::gfx_dir::GfxDir;
|
| 14 |
+
use openwa_core::render::SpriteOp;
|
| 15 |
use openwa_core::task::{BungeeTrailTask, WeaponAimTask};
|
| 16 |
|
| 17 |
use crate::hook::{self, usercall_trampoline};
|
|
|
|
| 212 |
layer,
|
| 213 |
x_pos: x_pos & 0xFFFF0000,
|
| 214 |
y_pos: y_pos & 0xFFFF0000,
|
| 215 |
+
sprite: SpriteOp(sprite_id),
|
| 216 |
palette: frame,
|
| 217 |
};
|
| 218 |
}
|
|
|
|
| 241 |
layer,
|
| 242 |
x_pos: x_pos & 0xFFFF0000,
|
| 243 |
y_pos: y_pos & 0xFFFF0000,
|
| 244 |
+
sprite: SpriteOp(sprite_id),
|
| 245 |
palette: frame,
|
| 246 |
};
|
| 247 |
}
|
|
|
|
| 420 |
layer: 0xDFFFF,
|
| 421 |
x_pos: x as u32 & 0xFFFF0000,
|
| 422 |
y_pos: y as u32 & 0xFFFF0000,
|
| 423 |
+
sprite: SpriteOp(0x45),
|
| 424 |
palette: (first_angle + 0x8100) as u32,
|
| 425 |
};
|
| 426 |
}
|
|
|
|
| 593 |
layer: 0x4_0000,
|
| 594 |
x_pos: endpoint_x as u32 & 0xFFFF0000,
|
| 595 |
y_pos: endpoint_y as u32 & 0xFFFF0000,
|
| 596 |
+
sprite: SpriteOp(0x44),
|
| 597 |
palette: (0x8000u32).wrapping_sub(angle),
|
| 598 |
};
|
| 599 |
}
|
|
|
|
| 767 |
///
|
| 768 |
/// Standard thiscall: ECX=this, stack params: x, y, sprite_flags, palette (RET 0x10).
|
| 769 |
///
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 770 |
unsafe extern "thiscall" fn blit_sprite(
|
| 771 |
this: *mut DisplayGfx,
|
| 772 |
x: Fixed,
|
|
|
|
| 776 |
) {
|
| 777 |
use openwa_core::render::display::gfx::DisplayGfx;
|
| 778 |
use openwa_core::render::display::vtable as display_vtable;
|
| 779 |
+
use openwa_core::render::SpriteFlags;
|
| 780 |
|
| 781 |
let gfx = this as *mut DisplayGfx;
|
| 782 |
let base = this as *const u8;
|
| 783 |
|
| 784 |
// ---------------------------------------------------------------
|
| 785 |
+
// Extract sprite index and flags
|
| 786 |
// ---------------------------------------------------------------
|
| 787 |
+
let sprite = SpriteOp(sprite_flags);
|
| 788 |
+
let flags = sprite.flags();
|
| 789 |
+
let sprite_id = sprite.index() as u32;
|
| 790 |
|
| 791 |
if sprite_id == 0 {
|
| 792 |
return;
|
|
|
|
| 796 |
// Palette manipulation
|
| 797 |
// ---------------------------------------------------------------
|
| 798 |
let mut pal: u32 = palette;
|
| 799 |
+
if flags.contains(SpriteFlags::INVERT_PALETTE) {
|
|
|
|
| 800 |
pal = 0x10000u32.wrapping_sub(palette);
|
| 801 |
if sprite_id.wrapping_sub(0x1D5) < 3 {
|
| 802 |
// Special sprite IDs: scale by 8/18
|
| 803 |
pal = (0x10000u32.wrapping_sub(palette).wrapping_mul(8)) / 0x12;
|
| 804 |
}
|
| 805 |
}
|
| 806 |
+
if flags.contains(SpriteFlags::PALETTE_XFORM) {
|
| 807 |
// Bit 25: palette transform (modular arithmetic for color cycling)
|
| 808 |
let tmp = ((pal.wrapping_mul(0x1F) as i32)
|
| 809 |
.wrapping_add(((pal.wrapping_mul(0x1F) as i32) >> 31) & 0x1F)
|
|
|
|
| 857 |
let dst_x = (x.0 >> 16) + (camera_x - half_w) + rect_left;
|
| 858 |
let dst_y = (y.0 >> 16) + (camera_y - half_h) + rect_top;
|
| 859 |
|
| 860 |
+
if !flags.contains(SpriteFlags::TILED) {
|
| 861 |
// Non-tiled: clipped blit at (dst_x, dst_y).
|
| 862 |
display_vtable::blit_bitmap_clipped_native(
|
| 863 |
gfx, dst_x, dst_y, sprite_w, blit_h, frame_data, 2,
|
|
|
|
| 878 |
// that writes extra orientation bits into the local orient variable.
|
| 879 |
// For now, handle the simple case:
|
| 880 |
let mut orient_local: u32 = 0x0000_0001; // blend=1 (ColorTable/transparency), orientation=0 (Normal)
|
| 881 |
+
if flags.contains(SpriteFlags::PALETTE_X4) {
|
| 882 |
// The ASM computes: pal = pal * 4 + 0x8000, then maps (pal >> 16) & 3
|
| 883 |
// to set specific orient values (0x80001, 0xC0001, 0x40001)
|
| 884 |
let scaled = pal.wrapping_mul(4).wrapping_add(0x8000);
|
|
|
|
| 941 |
// ---------------------------------------------------------------
|
| 942 |
// Shadow clear (high_flags bit 22)
|
| 943 |
// ---------------------------------------------------------------
|
| 944 |
+
if flags.contains(SpriteFlags::SHADOW_CLEAR) {
|
| 945 |
// Blit sprite to layer_2 as shadow base
|
| 946 |
let layer2 = (*gfx).layer_2;
|
| 947 |
super::bitgrid::blit_impl(
|
|
|
|
| 976 |
// ---------------------------------------------------------------
|
| 977 |
// Extra orientation flags from high_flags
|
| 978 |
// ---------------------------------------------------------------
|
| 979 |
+
if flags.contains(SpriteFlags::MIRROR_X) {
|
| 980 |
orient_local |= 0x0001_0000;
|
| 981 |
}
|
| 982 |
+
if flags.contains(SpriteFlags::MIRROR_Y) {
|
| 983 |
orient_local |= 0x0002_0000;
|
| 984 |
}
|
| 985 |
|
|
|
|
| 1067 |
}
|
| 1068 |
|
| 1069 |
// Stippled mode (checkerboard per-pixel blit)
|
| 1070 |
+
if flags.intersects(SpriteFlags::STIPPLED_0 | SpriteFlags::STIPPLED_1) {
|
| 1071 |
+
let stipple_mode: u32 = if flags.contains(SpriteFlags::STIPPLED_1) {
|
| 1072 |
1
|
| 1073 |
} else {
|
| 1074 |
0
|
|
|
|
| 1093 |
}
|
| 1094 |
|
| 1095 |
// Tiled mode (horizontal sprite tiling)
|
| 1096 |
+
if flags.contains(SpriteFlags::TILED) {
|
| 1097 |
display_vtable::acquire_render_lock(gfx);
|
| 1098 |
|
| 1099 |
super::bitgrid::blit_tiled_raw(
|
|
|
|
| 1111 |
}
|
| 1112 |
|
| 1113 |
// Determine color table pointer
|
| 1114 |
+
let color_table: *const u8 = if flags.contains(SpriteFlags::ADDITIVE) {
|
| 1115 |
(*gfx).color_add_table.as_ptr()
|
| 1116 |
+
} else if flags.contains(SpriteFlags::COLOR_BLEND) {
|
| 1117 |
(*gfx).color_blend_table.as_ptr()
|
| 1118 |
} else {
|
| 1119 |
core::ptr::null()
|