refactor: use TaskMessage enum in CTaskCloud::HandleMessage
Browse filesReplace raw message ID constants (2, 3, 0x54) with TaskMessage enum
variants (FrameFinish, RenderScene, SetWind) for readability.
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
crates/openwa-wormkit/src/replacements/task/cloud.rs
CHANGED
|
@@ -7,19 +7,20 @@ use core::sync::atomic::{AtomicU32, Ordering};
|
|
| 7 |
|
| 8 |
use openwa_core::address::va;
|
| 9 |
use openwa_core::fixed::Fixed;
|
|
|
|
| 10 |
use openwa_core::log::log_line;
|
| 11 |
use openwa_core::task::cloud::CTaskCloud;
|
| 12 |
use openwa_core::task::{CTask, Task};
|
| 13 |
|
| 14 |
-
/// Original CTaskCloud::HandleMessage, saved for
|
| 15 |
static ORIG_HANDLE_MESSAGE: AtomicU32 = AtomicU32::new(0);
|
| 16 |
|
| 17 |
/// CTaskCloud::HandleMessage replacement.
|
| 18 |
///
|
| 19 |
/// Handles three message types:
|
| 20 |
-
/// -
|
| 21 |
-
/// -
|
| 22 |
-
/// -
|
| 23 |
///
|
| 24 |
/// Always calls base CTask::HandleMessage at the end (0x562F30).
|
| 25 |
unsafe extern "thiscall" fn cloud_handle_message(
|
|
@@ -30,10 +31,10 @@ unsafe extern "thiscall" fn cloud_handle_message(
|
|
| 30 |
data: *const u8,
|
| 31 |
) {
|
| 32 |
let cloud = &mut *this;
|
|
|
|
| 33 |
|
| 34 |
-
match
|
| 35 |
-
|
| 36 |
-
2 => {
|
| 37 |
// Advance Y position
|
| 38 |
cloud.pos_y = Fixed(cloud.pos_y.0 + cloud.vel_y.0);
|
| 39 |
|
|
@@ -66,8 +67,8 @@ unsafe extern "thiscall" fn cloud_handle_message(
|
|
| 66 |
}
|
| 67 |
}
|
| 68 |
|
| 69 |
-
|
| 70 |
-
|
| 71 |
let orig = ORIG_HANDLE_MESSAGE.load(Ordering::Relaxed);
|
| 72 |
let orig_fn: unsafe extern "thiscall" fn(
|
| 73 |
*mut CTaskCloud, *mut CTask, u32, u32, *const u8,
|
|
@@ -76,8 +77,7 @@ unsafe extern "thiscall" fn cloud_handle_message(
|
|
| 76 |
return; // original already calls base handler
|
| 77 |
}
|
| 78 |
|
| 79 |
-
|
| 80 |
-
0x54 => {
|
| 81 |
if !data.is_null() {
|
| 82 |
cloud.wind_target = Fixed(*(data as *const i32));
|
| 83 |
}
|
|
|
|
| 7 |
|
| 8 |
use openwa_core::address::va;
|
| 9 |
use openwa_core::fixed::Fixed;
|
| 10 |
+
use openwa_core::game::TaskMessage;
|
| 11 |
use openwa_core::log::log_line;
|
| 12 |
use openwa_core::task::cloud::CTaskCloud;
|
| 13 |
use openwa_core::task::{CTask, Task};
|
| 14 |
|
| 15 |
+
/// Original CTaskCloud::HandleMessage, saved for render call-through.
|
| 16 |
static ORIG_HANDLE_MESSAGE: AtomicU32 = AtomicU32::new(0);
|
| 17 |
|
| 18 |
/// CTaskCloud::HandleMessage replacement.
|
| 19 |
///
|
| 20 |
/// Handles three message types:
|
| 21 |
+
/// - FrameFinish: per-frame position update (parallax scroll with wind drift)
|
| 22 |
+
/// - RenderScene: draw sprite at computed position — delegates to original
|
| 23 |
+
/// - SetWind: set wind target from message data
|
| 24 |
///
|
| 25 |
/// Always calls base CTask::HandleMessage at the end (0x562F30).
|
| 26 |
unsafe extern "thiscall" fn cloud_handle_message(
|
|
|
|
| 31 |
data: *const u8,
|
| 32 |
) {
|
| 33 |
let cloud = &mut *this;
|
| 34 |
+
let msg = TaskMessage::try_from(msg_type);
|
| 35 |
|
| 36 |
+
match msg {
|
| 37 |
+
Ok(TaskMessage::FrameFinish) => {
|
|
|
|
| 38 |
// Advance Y position
|
| 39 |
cloud.pos_y = Fixed(cloud.pos_y.0 + cloud.vel_y.0);
|
| 40 |
|
|
|
|
| 67 |
}
|
| 68 |
}
|
| 69 |
|
| 70 |
+
Ok(TaskMessage::RenderScene) => {
|
| 71 |
+
// Delegate to original (uses usercall for RQ_DrawSpriteLocal)
|
| 72 |
let orig = ORIG_HANDLE_MESSAGE.load(Ordering::Relaxed);
|
| 73 |
let orig_fn: unsafe extern "thiscall" fn(
|
| 74 |
*mut CTaskCloud, *mut CTask, u32, u32, *const u8,
|
|
|
|
| 77 |
return; // original already calls base handler
|
| 78 |
}
|
| 79 |
|
| 80 |
+
Ok(TaskMessage::SetWind) => {
|
|
|
|
| 81 |
if !data.is_null() {
|
| 82 |
cloud.wind_target = Fixed(*(data as *const i32));
|
| 83 |
}
|