refactor(frame): one wrapper for each draw-layer invalidate

CSimpleFrame::NotifyLayerChanged (FUN_FRAME_NOTIFY_LAYER_CHANGED,
0x0076A990, __thiscall (frame, layer)) was wrapped by hand in Cooldown,
ModelScene and ClipChildren, and CScriptRegion::NotifyLayerChanged
(FUN_REGION_NOTIFY_LAYER_CHANGED, 0x0077FDF0, __thiscall (region)) in the
inline-texture pool and the texture wrap. Each file carried its own
typedef for the same engine call.

frame/LayerChange.h now holds the two: NotifyFrame and NotifyRegion. All
five files call them.
This commit is contained in:
Brues
2026-11-11 08:07:38 -06:00
parent 2ba1818a6e
commit e27d1e5849
6 changed files with 51 additions and 20 deletions
+2 -2
View File
@@ -69,6 +69,7 @@
#include "frame/AlphaGradient.h"
#include "frame/ClipChildren.h"
#include "frame/Destruction.h"
#include "frame/LayerChange.h"
#include "frame/ParentChange.h"
#include "xml/FrameLoad.h"
@@ -85,7 +86,6 @@ using BatchOp_t = void(__fastcall *)(void *batch);
using Callback_t = void(__fastcall *)(void *arg);
using AddCallback_t = void(__fastcall *)(void *batch, void *edx, Callback_t fn, void *arg);
using SetFrameFlag_t = void(__fastcall *)(void *frame, void *edx, uint32_t mask, int on);
using NotifyLayerChanged_t = void(__fastcall *)(void *frame, void *edx, int layer);
using HitTest_t = int(__fastcall *)(void *frame, void *edx, const float *point);
using Matrix_t = void(__fastcall *)(float *m);
using GetViewport_t = void(__fastcall *)(float *minX, float *maxX, float *minY, float *maxY, float *minZ,
@@ -345,7 +345,7 @@ const Game::HookAutoRegister _hitTestHook{Offsets::FUN_FRAME_HIT_TEST, reinterpr
void MarkLayers(void *frame) {
for (int layer = 0; layer < Offsets::FRAME_LAYER_COUNT; ++layer)
reinterpret_cast<NotifyLayerChanged_t>(Offsets::FUN_FRAME_NOTIFY_LAYER_CHANGED)(frame, nullptr, layer);
Frame::LayerChange::NotifyFrame(frame, layer);
}
// Marks every layer of each frame under `frame` changed.
+5 -7
View File
@@ -83,6 +83,7 @@
#include "api/Documentation.h"
#include "cvar/Factory.h"
#include "frame/ExtraScripts.h"
#include "frame/LayerChange.h"
#include "frame/Region.h"
#include "frame/RenderBatch.h"
#include "frame/ScriptArgs.h"
@@ -259,10 +260,7 @@ void Hide(void *frame) {
Game::Read<Slot_t>(Game::Read<void *>(frame, 0), Offsets::VTBL_FRAME_HIDE)(frame, nullptr);
}
void NotifyLayerChanged(void *frame, int layer) {
using Fn_t = void(__fastcall *)(void *self, void *edx, int layer);
reinterpret_cast<Fn_t>(Offsets::FUN_FRAME_NOTIFY_LAYER_CHANGED)(frame, nullptr, layer);
}
using Frame::LayerChange::NotifyFrame;
// ---- textures ---------------------------------------------------------------
@@ -482,7 +480,7 @@ void SetSlotTexture(void *frame, TextureSlot slot, const char *file, const uint3
if (base != nullptr)
s.base = *base;
f.texturesSet |= 1u << slot;
NotifyLayerChanged(frame, kSlotLayer[slot]);
NotifyFrame(frame, kSlotLayer[slot]);
UpdateColors(frame);
}
@@ -976,7 +974,7 @@ int __fastcall Script_SetDrawSwipe(void *L) {
const uint32_t drawSwipe = Game::Lua::ToFlag(L, 2, true);
if (drawSwipe != f.drawSwipe) {
f.drawSwipe = drawSwipe;
NotifyLayerChanged(frame, kSlotLayer[SLOT_SWIPE]);
NotifyFrame(frame, kSlotLayer[SLOT_SWIPE]);
}
return 0;
}
@@ -1238,7 +1236,7 @@ int __fastcall Script_SetDrawEdge(void *L) {
const uint32_t drawEdge = Game::Lua::ToFlag(L, 2, true);
if (drawEdge != f.drawEdge) {
f.drawEdge = drawEdge;
NotifyLayerChanged(frame, kSlotLayer[SLOT_EDGE]);
NotifyFrame(frame, kSlotLayer[SLOT_EDGE]);
}
return 0;
}
+37
View File
@@ -0,0 +1,37 @@
// This file is part of ClassicAPI.
//
// ClassicAPI is free software: you can redistribute it and/or modify it under the terms
// of the GNU General Public License as published by the Free Software Foundation, either
// version 3 of the License, or (at your option) any later version.
//
// ClassicAPI is distributed in the hope that it will be useful, but WITHOUT ANY
// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
// PURPOSE. See the GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along with
// ClassicAPI. If not, see <https://www.gnu.org/licenses/>.
#pragma once
// The engine's two draw-layer invalidates: what to call after a change to
// what a frame or a region draws, so the next batch rebuild picks it up.
#include "Offsets.h"
namespace Frame::LayerChange {
// CSimpleFrame::NotifyLayerChanged (FUN_FRAME_NOTIFY_LAYER_CHANGED): one of
// the frame's own draw layers.
inline void NotifyFrame(void *frame, int layer) {
using Fn_t = void(__fastcall *)(void *frame, void *edx, int layer);
reinterpret_cast<Fn_t>(Offsets::FUN_FRAME_NOTIFY_LAYER_CHANGED)(frame, nullptr, layer);
}
// CScriptRegion::NotifyLayerChanged (FUN_REGION_NOTIFY_LAYER_CHANGED): the
// layer the region draws in.
inline void NotifyRegion(void *region) {
using Fn_t = void(__fastcall *)(void *region);
reinterpret_cast<Fn_t>(Offsets::FUN_REGION_NOTIFY_LAYER_CHANGED)(region);
}
} // namespace Frame::LayerChange
+3 -7
View File
@@ -99,6 +99,7 @@
#include "Game.h"
#include "Offsets.h"
#include "api/Documentation.h"
#include "frame/LayerChange.h"
#include "frame/Subclass.h"
#include "model/Camera.h"
#include "model/M2.h"
@@ -719,11 +720,6 @@ int __fastcall GetCameraScalar(void *L) {
return 1;
}
void NotifyLayerChanged(void *frame, int layer) {
using Fn_t = void(__fastcall *)(void *self, void *edx, int layer);
reinterpret_cast<Fn_t>(Offsets::FUN_FRAME_NOTIFY_LAYER_CHANGED)(frame, nullptr, layer);
}
int __fastcall Script_SetDrawLayer(void *L) {
using LayerFromName_t = int(__fastcall *)(const char *name, int *layer);
void *frame = Self(L);
@@ -741,8 +737,8 @@ int __fastcall Script_SetDrawLayer(void *L) {
return 0;
const int old = f.drawLayer;
f.drawLayer = layer;
NotifyLayerChanged(frame, old);
NotifyLayerChanged(frame, layer);
Frame::LayerChange::NotifyFrame(frame, old);
Frame::LayerChange::NotifyFrame(frame, layer);
return 0;
}
+2 -2
View File
@@ -20,6 +20,7 @@
#include "Game.h"
#include "Offsets.h"
#include "frame/LayerChange.h"
#include "frame/Region.h"
#include "frame/RegionDestruction.h"
#include "text/PtrProbe.h"
@@ -44,7 +45,6 @@ using Realize_t = void(__thiscall *)(void *anchor, int flag);
using SetTexCoord_t = void(__thiscall *)(void *tex, const float *coords4);
using DeletingDestructor_t = void(__thiscall *)(void *region, int flags);
using Emit_t = void(__fastcall *)(void *region, void *edx, void *batch);
using NotifyLayerChanged_t = void(__fastcall *)(void *region);
using OnColorChanged_t = void(__fastcall *)(void *fs, void *edx, int changed);
// LAA-aware pointer sanity probe: Text::LooksReadable (text/PtrProbe.h).
@@ -225,7 +225,7 @@ void ApplyPlacements(void *fs, FsPlacements &np, uint32_t fsColor) {
np.shown = (want < static_cast<int>(np.regions.size()))
? want
: static_cast<int>(np.regions.size());
reinterpret_cast<NotifyLayerChanged_t>(Offsets::FUN_REGION_NOTIFY_LAYER_CHANGED)(fs);
Frame::LayerChange::NotifyRegion(fs);
}
// Per-frame tick (FrameTick — glue AND world): deletes orphaned textures.
+2 -2
View File
@@ -43,6 +43,7 @@
#include "Game.h"
#include "Offsets.h"
#include "frame/LayerChange.h"
#include "texture/Atlas.h"
#include "texture/Construct.h"
#include "texture/Load.h"
@@ -75,7 +76,6 @@ using SetTexture_t = uint32_t(__fastcall *)(void *texture, void *edx, const char
uint32_t filter, uint32_t shader);
using NameMatch_t = int(__fastcall *)(void *hTexture, const char *name);
using GetUiPixelShader_t = void *(__fastcall *)(uint32_t index);
using NotifyLayerChanged_t = void(__fastcall *)(void *region);
SetTexture_t g_origSetTexture = nullptr;
@@ -108,7 +108,7 @@ uint32_t Load(void *texture, const char *name, bool repeatH, bool repeatV, uint3
reinterpret_cast<GetUiPixelShader_t>(Offsets::FUN_UI_GET_PIXEL_SHADER)(shader);
Texture::ReleaseHandle(held);
Game::Ref<void *>(texture, Offsets::OFF_SIMPLETEXTURE_HTEXTURE) = image;
reinterpret_cast<NotifyLayerChanged_t>(Offsets::FUN_REGION_NOTIFY_LAYER_CHANGED)(texture);
Frame::LayerChange::NotifyRegion(texture);
return 1;
}