mirror of
https://github.com/brues-code/ClassicAPI.git
synced 2026-11-16 08:00:42 +00:00
perf(smf): BackFillMessage shifts in place and skips layouts it cannot change
BackFillMessage made every older message move up one record. It copied the record span into a vector and back, built a new Lua table for the extra arguments, and laid the lines out again on every call. pfUI's combat-log refilter calls it once per frame for up to 300 lines, and its chat history up to 30 times per frame at login. The records now rotate in place (std::rotate over the 0x18-byte records), and the extra-argument tables follow each cycle of the rotation in the same table, so a call makes no garbage. RemoveMessagesByPredicate shares the rotation. A shown frame whose lines do not reach the oldest message (+0x350, the top flag the layout 0x00788750 sets) cannot show the new oldest one. The layout would place the same lines again, so it is skipped. The one thing it would change, each laid-out node's record pointer (node+0xC, written by ShowLine 0x00788AF0), moves one record up with its message. The fader 0x00788460, RearmLines 0x00788B80 and RebuildLinkButtons 0x00788C00 read records only through that pointer, for nodes 0..+0x34C-1. Clear leaves +0x350 at 0 on an empty frame, so the skip also needs existing messages. An empty or hidden frame is laid out as before.
This commit is contained in:
@@ -1063,6 +1063,7 @@ enum Offsets {
|
||||
OFF_SMF_LINE_ARRAY = 0x3A4, // base of the stride-0x10 line-entry array
|
||||
SMF_LINE_STRIDE = 0x10, // per-line-entry stride
|
||||
OFF_SMF_LINE_FONTSTRING = 0x8, // entry+8 = the line's CSimpleFontString
|
||||
OFF_SMF_LINE_RECORD = 0xC, // entry+0xC = the ring record it shows (ShowLine 0x00788AF0)
|
||||
// THE pen↔anchor unit bridge. RebuildString (0x7724A0) multiplies every
|
||||
// text-unit quantity by region+0x7C when crossing into node creation:
|
||||
// nodePos = inset×s + rect corner, nodeFontH = fontPx×s, spacing = +0xF4×s,
|
||||
@@ -13324,6 +13325,17 @@ enum Offsets {
|
||||
// The record the lines are laid out from (4.3.4's m_currentScroll);
|
||||
// FUN_SMF_DISPLAY_REFRESH stores its argument here.
|
||||
OFF_SCROLLINGMESSAGEFRAME_SCROLL_RECORD = 0x348,
|
||||
// The lines the last layout of a shown frame laid out (4.3.4's
|
||||
// m_numDisplayed): FUN_SMF_DISPLAY_REFRESH zeroes it and counts each line
|
||||
// it places, and the fader (0x00788460), RearmLines (0x00788B80) and the
|
||||
// link-button rebuild (0x00788C00) walk display nodes 0..this-1, each
|
||||
// through its record pointer (OFF_SMF_LINE_RECORD).
|
||||
OFF_SCROLLINGMESSAGEFRAME_LINES_SHOWN = 0x34C,
|
||||
// The top flag (4.3.4's m_atTop): the layout sets it when the lines it
|
||||
// placed reach the oldest message (0x00788A37). Clear (0x007882B0) zeroes
|
||||
// it, and a layout of an empty frame returns before it, so it is only
|
||||
// meaningful while the frame has messages.
|
||||
OFF_SCROLLINGMESSAGEFRAME_AT_TOP = 0x350,
|
||||
// A ring that is not full holds records 0..count-1: the writer fills
|
||||
// them in order from an empty ring (Clear: position -1), and only a full
|
||||
// ring wraps. ScrollOffset and ScrollToOffset (below) wrap by the count,
|
||||
|
||||
@@ -57,8 +57,10 @@
|
||||
#include "Offsets.h"
|
||||
#include "scrollingmessageframe/DisplayRefreshed.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdint>
|
||||
#include <cstring>
|
||||
#include <numeric>
|
||||
#include <vector>
|
||||
|
||||
namespace ScrollingMessageFrame::MessageInfo {
|
||||
@@ -131,16 +133,22 @@ int ExtraCount(void *L, int extras) {
|
||||
// too (Clear and the writer leave a free slot's old text for the writer to
|
||||
// free when it reuses the slot). The lines still show the records they were
|
||||
// laid out from; the caller lays them out again. Self at stack slot 1.
|
||||
//
|
||||
// Both move in place. The records rotate as whole 0x18-byte values, and the
|
||||
// extra-argument tables follow each cycle of the rotation, every one moved
|
||||
// once, so a call makes no garbage table.
|
||||
void RotateRecords(void *L, void *frame, int span, int by) {
|
||||
using namespace Game::Lua;
|
||||
by %= span;
|
||||
if (span <= 1 || by == 0)
|
||||
struct Record {
|
||||
uint8_t bytes[Offsets::SCROLLINGMESSAGEFRAME_MESSAGE_STRIDE];
|
||||
};
|
||||
if (span <= 1)
|
||||
return;
|
||||
constexpr size_t kStride = Offsets::SCROLLINGMESSAGEFRAME_MESSAGE_STRIDE;
|
||||
uint8_t *records = Game::Read<uint8_t *>(frame, Offsets::OFF_SCROLLINGMESSAGEFRAME_MESSAGES);
|
||||
const std::vector<uint8_t> was(records, records + span * kStride);
|
||||
for (int i = 0; i < span; ++i)
|
||||
std::memcpy(records + i * kStride, was.data() + ((i + by) % span) * kStride, kStride);
|
||||
by %= span;
|
||||
if (by == 0)
|
||||
return;
|
||||
auto *records = Game::Read<Record *>(frame, Offsets::OFF_SCROLLINGMESSAGEFRAME_MESSAGES);
|
||||
std::rotate(records, records + by, records + span);
|
||||
int &scroll = Game::Ref<int>(frame, Offsets::OFF_SCROLLINGMESSAGEFRAME_SCROLL_RECORD);
|
||||
if (scroll >= 0 && scroll < span)
|
||||
scroll = (scroll - by + span) % span;
|
||||
@@ -148,17 +156,21 @@ void RotateRecords(void *L, void *frame, int span, int by) {
|
||||
PushRecords(L, false);
|
||||
const int table = GetTop(L);
|
||||
if (Type(L, table) == TYPE_TABLE) {
|
||||
NewTable(L);
|
||||
const int moved = GetTop(L);
|
||||
for (int i = 0; i < span; ++i) {
|
||||
const int cycles = std::gcd(span, by);
|
||||
for (int start = 0; start < cycles; ++start) {
|
||||
RawGetI(L, table, start); // the cycle's first table, until its slot comes round
|
||||
const int held = GetTop(L);
|
||||
int i = start;
|
||||
for (int next = (i + by) % span; next != start; next = (i + by) % span) {
|
||||
PushNumber(L, i);
|
||||
RawGetI(L, table, next);
|
||||
RawSet(L, table); // records[i] = records[next]
|
||||
i = next;
|
||||
}
|
||||
PushNumber(L, i);
|
||||
RawGetI(L, table, (i + by) % span);
|
||||
RawSet(L, moved);
|
||||
}
|
||||
for (int i = 0; i < span; ++i) {
|
||||
PushNumber(L, i);
|
||||
RawGetI(L, moved, i);
|
||||
PushValue(L, held);
|
||||
RawSet(L, table);
|
||||
SetTop(L, held - 1);
|
||||
}
|
||||
}
|
||||
SetTop(L, table - 1);
|
||||
@@ -241,6 +253,16 @@ uint32_t MessageColor(void *L, void *frame) {
|
||||
// as the writer does, which shows the new line when there is room above the
|
||||
// others; scrolled up from the scroll record, which moved with its message,
|
||||
// so the view stays.
|
||||
//
|
||||
// A shown frame whose lines do not reach the oldest message (its top flag
|
||||
// clear) cannot show the new one, so that layout would place the same lines
|
||||
// again: the same texts, the same scroll record, no scroll script. Retail
|
||||
// only marks its display dirty. The layout is skipped there, and the one
|
||||
// thing it would change, each laid-out node's record pointer (the fader,
|
||||
// RearmLines and the link-button rebuild read the record through it), moves
|
||||
// one record up with the message it shows. The top flag is only kept while
|
||||
// the frame has messages and is shown, so an empty or hidden frame is laid
|
||||
// out as before (a hidden frame's layout places nothing).
|
||||
int __fastcall Script_BackFillMessage(void *L) {
|
||||
using namespace Game::Lua;
|
||||
using StormAlloc_t = void *(__stdcall *)(size_t size, const char *file, int line, int flags);
|
||||
@@ -267,6 +289,8 @@ int __fastcall Script_BackFillMessage(void *L) {
|
||||
return 0;
|
||||
std::memcpy(copy, text, bytes);
|
||||
|
||||
const bool offScreen = count > 0 && Game::Read<int>(frame, Offsets::OFF_FRAME_VISIBLE) != 0 &&
|
||||
Game::Read<int>(frame, Offsets::OFF_SCROLLINGMESSAGEFRAME_AT_TOP) == 0;
|
||||
RotateRecords(L, frame, count + 1, count);
|
||||
++count;
|
||||
int &pos = Game::Ref<int>(frame, Offsets::OFF_SCROLLINGMESSAGEFRAME_MESSAGE_POS);
|
||||
@@ -285,6 +309,15 @@ int __fastcall Script_BackFillMessage(void *L) {
|
||||
*reinterpret_cast<int *>(record + Offsets::OFF_SCROLLINGMESSAGEFRAME_MESSAGE_ID) = 0;
|
||||
StoreExtras(L, 0, top);
|
||||
|
||||
if (offScreen) {
|
||||
const int shown = Game::Read<int>(frame, Offsets::OFF_SCROLLINGMESSAGEFRAME_LINES_SHOWN);
|
||||
auto *lines = Game::Read<uint8_t *>(frame, Offsets::OFF_SMF_LINE_ARRAY);
|
||||
for (int i = 0; i < shown; ++i)
|
||||
Game::Ref<uint8_t *>(lines + i * Offsets::SMF_LINE_STRIDE, Offsets::OFF_SMF_LINE_RECORD) +=
|
||||
Offsets::SCROLLINGMESSAGEFRAME_MESSAGE_STRIDE;
|
||||
DisplayRefreshed::MarkDirty(frame);
|
||||
return 0;
|
||||
}
|
||||
reinterpret_cast<Layout_t>(Offsets::FUN_SMF_DISPLAY_REFRESH)(
|
||||
frame, nullptr,
|
||||
Game::Read<int>(frame, Offsets::OFF_SCROLLINGMESSAGEFRAME_AT_BOTTOM) != 0
|
||||
|
||||
Reference in New Issue
Block a user