This checkout had no git history at all, so this one commit carries the whole
of the Everwood work as a single import on top of chairmanpow/benilla-octo's
`main` (706cd71). The two trees have genuinely diverged — each has files the
other does not — so this is a fork point, not a catch-up.
Today's work, which is the reason a baseline exists at all:
- Booth previews no longer cast world shadows (`NO_BOOTH_SHADOW`). Portrait
characters were entering the sun's shadow cascades, so every skinned-rig
shadow specialization compiled live mid-frame; the hitch detector logged
"main thread blocked 1316 ms" beside a `compiled LIVE` warning. This was
the Fashion/Tmog stutter.
- Per-pane dress-up: each `DressUpModel` pane assembles and stages its own
tried-on look instead of every pane mirroring the live player.
- Item template cache is append-only JSONL written on the IO pool, replacing
an 11.6 MB whole-map JSON rewrite on the main thread every 10 s.
- `WOW_SYSTEM_TIMING` rebuilt per-thread: it took 2 mutexes per system enter
and 4 per exit, costing 15 ms a frame (590 fps -> 60) and corrupting the
measurements it was taken to produce.
- The visibility-churn sweep moved to its own `WOW_FLASH_CHURN` switch, so a
frame-cost reading no longer pays 2.7 ms a frame for it.
Local state (`benilla-config/`, `logs/`, `target/`) is excluded by the
existing .gitignore; the account credential it holds is not in this commit.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01SgstFWtn1RxEJ5kVrpgYwn
219 lines
9.5 KiB
Rust
219 lines
9.5 KiB
Rust
//! The small ClassicAPI namespaces with one or two functions each: `Currency`
|
|
//! (`C_CurrencyInfo`), `Events` (`C_EventUtils` + `GetFramesRegisteredForEvent`), `System`, and
|
|
//! `Combat`. Grouped in one file because a file per function would say less than this header does.
|
|
//!
|
|
//! Not built, each for want of state rather than by choice (`docs/ADDON_COMPAT.md` carries the same
|
|
//! list):
|
|
//! - `CopyToClipboard(text[, removeMarkup])`: `benilla-ui` is deliberately engine-free — no
|
|
//! windowing, no OS handles — and a clipboard is an OS capability. The workspace does pull
|
|
//! `arboard` in, but only behind the app's dev tooling; reaching it from here would mean a new
|
|
//! host-callback seam through `Model`, which is a real plumbing job and not a binding.
|
|
//! - `C_EventUtils.IsEventValid(eventName)`: nothing in this crate knows the valid-event set.
|
|
//! `RegisterEvent` accepts any string (`script/event.rs`), and the only 1.12 event catalogue is
|
|
//! `reference/1.12-events.tsv`, a test fixture that is not compiled in. Answering `true` for
|
|
//! everything would make the getter a lie an addon branches on; answering from a half-known set
|
|
//! would be worse.
|
|
//! - `GetInstanceInfo()`: `script/instance.rs` feeds only the instance *type* (`IsInInstance`'s
|
|
//! second return). The modern tuple additionally wants the instance name, a difficulty index and
|
|
//! name, and the max-player count — none of which this client tracks, and the first of which
|
|
//! would have to be guessed from zone text.
|
|
//! - `StartAttack`/`StopAttack`: these are 1.12's own verbs, not ClassicAPI additions, and benilla
|
|
//! has not built either yet. Registering them from `compat/` would put a stock gap in the wrong
|
|
//! layer and hide it from the reference-surface accounting; they belong beside the other combat
|
|
//! verbs when the attack-request plumbing lands.
|
|
//! - `Totem`'s `GetTotemTimeLeft`/`GetTotemDuration`/`TargetTotem`: no totem state exists in the
|
|
//! model at all — 1.12's own totem bar is unbuilt, so there is nothing to wrap. **`GetTotemInfo`
|
|
//! and the slot constants have since moved to `totem.rs`**, not because the data appeared but
|
|
//! because the absence turned out to cost most of pfUI's UI (it keys a table with the constants
|
|
//! at module scope, and pfUI loops its modules with no `pcall`). That file explains the trade;
|
|
//! the three above stay unbuilt because nothing reaches them at load time.
|
|
//! - `Tracking` (`GetNumTrackingTypes`/`GetTrackingInfo`/`SetTracking`): `Model::tracking` is the
|
|
//! one *active* tracking aura (behind the stock `GetTrackingTexture`), not the enumerable list of
|
|
//! known tracking spells these three index into.
|
|
|
|
use mlua::{Lua, Table, Value};
|
|
|
|
use crate::script::Model;
|
|
|
|
/// `C_CurrencyInfo`. Only `GetCoinTextureString`, and it delegates: 1.12 defines that function in
|
|
/// FrameXML's own `MoneyFrame.lua`, loaded off the player's patch chain *after* this installs, so
|
|
/// the real one is the authority and a Rust copy would be both a second source of truth and dead
|
|
/// (FrameXML's would overwrite a bare global of the same name anyway). This reads the global at
|
|
/// call time and answers nil before FrameXML has loaded.
|
|
fn currency_info(lua: &Lua) -> mlua::Result<Table> {
|
|
let t = lua.create_table()?;
|
|
t.set(
|
|
"GetCoinTextureString",
|
|
lua.create_function(|lua, (amount, font_height): (Value, Option<Value>)| {
|
|
let Ok(f) = lua.globals().get::<mlua::Function>("GetCoinTextureString") else {
|
|
return Ok(Value::Nil);
|
|
};
|
|
match font_height {
|
|
Some(h) => f.call::<Value>((amount, h)),
|
|
None => f.call::<Value>(amount),
|
|
}
|
|
})?,
|
|
)?;
|
|
Ok(t)
|
|
}
|
|
|
|
/// `C_EventUtils`. `IsEventValid` is absent by design — see this file's header.
|
|
fn event_utils(lua: &Lua) -> mlua::Result<Table> {
|
|
lua.create_table()
|
|
}
|
|
|
|
pub(super) fn install(lua: &Lua) -> mlua::Result<()> {
|
|
let g = lua.globals();
|
|
g.set("C_CurrencyInfo", currency_info(lua)?)?;
|
|
g.set("C_EventUtils", event_utils(lua)?)?;
|
|
|
|
// `GetFramesRegisteredForEvent(event)`: the registry's own list for that event, in registration
|
|
// order — the same order `fire_event` walks (`script/tick.rs`), so a caller inspecting it sees
|
|
// dispatch order and not an arbitrary one. An event nothing registered answers an empty table,
|
|
// never nil, so `#result` is always safe.
|
|
g.set(
|
|
"GetFramesRegisteredForEvent",
|
|
lua.create_function(|lua, event: Option<String>| {
|
|
let out = lua.create_table()?;
|
|
let Some(event) = event else { return Ok(out) };
|
|
let handles = {
|
|
let model = lua.app_data_ref::<Model>().expect("model app_data");
|
|
model
|
|
.event_to_frames
|
|
.get(&event)
|
|
.cloned()
|
|
.unwrap_or_default()
|
|
};
|
|
for (i, h) in (1..).zip(handles) {
|
|
let id = {
|
|
let mut model = lua.app_data_mut::<Model>().expect("model app_data");
|
|
model.frame_id(h)
|
|
};
|
|
out.set(i, crate::script::object::frame_wrapper(lua, id)?)?;
|
|
}
|
|
Ok(out)
|
|
})?,
|
|
)?;
|
|
|
|
// `GetPhysicalScreenSize()`: the UI screen rect's own size. Deviation worth knowing: modern
|
|
// WoW's returns true *device* pixels, where this is the logical rect the host pushes through
|
|
// `set_screen_size` — the two differ under a non-1 UI scale or DPI factor, which this crate
|
|
// cannot see. Callers use it for aspect and rough layout, which the logical size answers.
|
|
g.set(
|
|
"GetPhysicalScreenSize",
|
|
lua.create_function(|lua, ()| {
|
|
let model = lua.app_data_ref::<Model>().expect("model app_data");
|
|
Ok((model.screen.width(), model.screen.height()))
|
|
})?,
|
|
)?;
|
|
|
|
// `InCombatLockdown()`: always false, and that is the honest answer rather than a stub — the
|
|
// lockdown exists on modern clients to refuse secure-frame edits mid-combat, and 1.12 has no
|
|
// secure-template system at all, so nothing here is ever locked down.
|
|
g.set("InCombatLockdown", lua.create_function(|_, ()| Ok(false))?)?;
|
|
|
|
Ok(())
|
|
}
|
|
|
|
#[cfg(test)]
|
|
mod tests {
|
|
use crate::script::UiScript;
|
|
|
|
#[test]
|
|
/// Uses `PLAYER_MONEY` deliberately: the VM installs its own listeners for lifecycle events
|
|
/// (`EventUtil`'s watcher takes `PLAYER_LOGIN`/`ADDON_LOADED`), so asserting an exact count on
|
|
/// one of those would couple this test to whatever else `compat/` registers.
|
|
fn get_frames_registered_for_event_reads_the_registry_in_dispatch_order() {
|
|
let s = UiScript::new().unwrap();
|
|
s.run(
|
|
r#"
|
|
a = CreateFrame("Frame", "RegA")
|
|
b = CreateFrame("Frame", "RegB")
|
|
a:RegisterEvent("PLAYER_MONEY")
|
|
b:RegisterEvent("PLAYER_MONEY")
|
|
"#,
|
|
)
|
|
.unwrap();
|
|
|
|
assert_eq!(
|
|
s.eval::<i64>(r#"return table.getn(GetFramesRegisteredForEvent("PLAYER_MONEY"))"#)
|
|
.unwrap(),
|
|
2
|
|
);
|
|
// Registration order, which is also the order `fire_event` walks.
|
|
assert_eq!(
|
|
s.eval::<String>(
|
|
r#"local f = GetFramesRegisteredForEvent("PLAYER_MONEY") return f[1]:GetName()"#
|
|
)
|
|
.unwrap(),
|
|
"RegA"
|
|
);
|
|
assert_eq!(
|
|
s.eval::<String>(
|
|
r#"local f = GetFramesRegisteredForEvent("PLAYER_MONEY") return f[2]:GetName()"#
|
|
)
|
|
.unwrap(),
|
|
"RegB"
|
|
);
|
|
|
|
// An event nothing registered is an empty table, not nil, so `#`/`getn` is always safe.
|
|
assert_eq!(
|
|
s.eval::<i64>(r#"return table.getn(GetFramesRegisteredForEvent("NOT_AN_EVENT"))"#)
|
|
.unwrap(),
|
|
0
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn screen_size_follows_the_pushed_rect() {
|
|
let mut s = UiScript::new().unwrap();
|
|
// The VM's own default until the host pushes one.
|
|
assert_eq!(
|
|
s.eval::<(f64, f64)>("return GetPhysicalScreenSize()")
|
|
.unwrap(),
|
|
(1024.0, 768.0)
|
|
);
|
|
s.set_screen_size(1920.0, 1080.0);
|
|
assert_eq!(
|
|
s.eval::<(f64, f64)>("return GetPhysicalScreenSize()")
|
|
.unwrap(),
|
|
(1920.0, 1080.0)
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn in_combat_lockdown_is_always_false_because_1_12_has_no_secure_frames() {
|
|
let s = UiScript::new().unwrap();
|
|
assert!(!s.eval::<bool>("return InCombatLockdown()").unwrap());
|
|
}
|
|
|
|
/// Before FrameXML publishes its own `GetCoinTextureString`, the delegate answers nil rather
|
|
/// than a second, drifting implementation.
|
|
#[test]
|
|
fn coin_texture_string_delegates_to_framexml() {
|
|
let s = UiScript::new().unwrap();
|
|
assert_eq!(
|
|
s.eval::<Option<String>>("return C_CurrencyInfo.GetCoinTextureString(100)")
|
|
.unwrap(),
|
|
None
|
|
);
|
|
// Stand in for FrameXML's own, and confirm the delegate reaches it and passes arguments.
|
|
s.run(
|
|
"function GetCoinTextureString(amount, h) return \
|
|
tostring(amount) .. '/' .. tostring(h) end",
|
|
)
|
|
.unwrap();
|
|
assert_eq!(
|
|
s.eval::<String>("return C_CurrencyInfo.GetCoinTextureString(250)")
|
|
.unwrap(),
|
|
"250/nil"
|
|
);
|
|
assert_eq!(
|
|
s.eval::<String>("return C_CurrencyInfo.GetCoinTextureString(250, 12)")
|
|
.unwrap(),
|
|
"250/12",
|
|
"the optional font height is forwarded"
|
|
);
|
|
}
|
|
}
|