Repository navigation
One more UI function at 100%: ScrollingHandler::handleScrolling - #460
Open
kotijekriv wants to merge 1 commit into
Open
kotijekriv wants to merge 1 commit into
kotijekriv wants to merge 1 commit into
Conversation
ScrollingHandler::handleScrolling, from Gynt's draft (4c73c67 at 23.6% on his closed sourcehold#256's reimpl/UI-Core; the same percentage at 10280b1 on his fork's reimpl/UI-Core-development and at 3d17527 on reimpl/UI-MenuItems-development). The draft is the decompiler's output. One behaviour fix against it: with no direction the original resets the scroll state and returns (0x00468BD3). In these drafts the block has no return, so it went on into the scrolling code, set isScrolling again and overwrote the base distance and timeScrolling with those of an elapsed time of about 0. His fork's reimpl/Wilps-2026-10-18 (8ca7861), a copy with other field names, has the return. Rewritten against the original instructions: - the direction is one if / else if chain on up, down, left and right, with left tested before right under up and under down; - isScrolling is set in both arms of the direction test, and a second if on it holds the rest of the no-direction block. As far as we can tell, the compiler knows the flag on both paths and drops the second test, but only after it has placed the blocks: the block keeps the second if's place, and the switch's compare chain and slow case then move up in front of it. That is the original, which has the block between the slow and the fast case (0x00468BAF). As one if with a return, in front of the store, the block stays in front of the switch (86.9%); as the else arm of the direction test it goes behind the function's end, with its stores reordered; - the speed is a switch, with interval -= interval / 3 for fast and interval += interval / 2 for slow. For the fast case the compiler divides by -3 and adds, as the original does (0x00468BD4); interval += interval / -3, or the third in a local of its own, gives the same listing; - (int)scrollDistanceLimit, as the original divides it signed (the field is undefined4 in the header, like the interval and the minimum, which it also uses as int); - the elapsed time goes straight into timeScrolling and the quotient into scrollDistanceBase (locals for them give the same listing); the four flags are cleared down, up, right, left in both places, which the compiler emits last one first here, as the original has them (left, right, up, down). No line for cmake/compiler-flags-gl.txt: the file reads 100.0% off the /GL list, and 100.0% on it too. It calls nothing but timeGetTime. reccmp in a build of main's whole /GL list (the 133 files that exist) and this file as committed, off the list, with every resolver of those files on: 144 functions, average 99.56. handleScrolling 100.0% raw and normalised, no differing line, and the same with the file on the list. The same build without the file has 143 functions, and each of them reads the same. The sources are main's at 3458fea; main's two commits since (02fab42, 812d149) add cmake files only, with the new option off. Co-authored-by: Gynt <gynt@users.noreply.github.com> Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
One more function at 100%, with no header changes and no line for
cmake/compiler-flags-gl.txt. One behaviour fix against the draft, one a copy on his fork also has (below).ScrollingHandler::handleScrollingturns the four scroll flags into one of eight directions, or none (while no dialog is open, the four key-down flags set them too), and works out how far a scroll step goes: the longer the scrolling lasts, the further, up to a maximum, with the scroll speed setting changing both the rate and the maximum. It is from gynt's draft (4c73c67 on #256's reimpl/UI-Core, 23.6%; his fork's reimpl/UI-Core-development and reimpl/UI-MenuItems-development carry it at 23.6% too), and the commit credits him as co-author.ScrollingHandler::handleScrolling/GLlist and on itMeasured.
Stronghold Crusader.exe(3bb0a8c1…5387ac5a), both resolver sets enabled locally (not committed), and sourcehold's reccmp with--resolve-wrapped-calls --ignore-security-cookie./GLlist and with 0x004314E0 (theMapEditorLandscaping_GeneralButtonshandler) left out and its resolver off, as in main's baseline: 0 failed of 2,424 compile steps, 99.57 over 2,440 functions, against 99.58 over 2,439 for main alone (built at f489b72; 3458fea only adds files undertools/, and cmake: optional wrapper units built from function-visibility.txt #399 and cmake: function-visibility.txt, which callers must see which callees' bodies #398 add the optional function-visibility units, off by default).handleScrollingreads 100.0 raw and normalised there too, with no diff entry, and its callerGlobal::WinMainreads what it read before. Two functions on main read lower, and it is how reccmp prints a constant, not their code:Menu::handleMenuItems(0x004F6280) reads 97.9 (91.4 normalised) andMenu::Constructor_Menu(0x004F4100) reads 98.4 (95.2), both 100.0 before. Both compare a menu item's type with the constant 0x11000000, five compares in all. In this build's layout a symbol of our DLL lies at exactly the address 0x11000000, so reccmp prints the constant as that symbol's name on our side. The instructions are the same on both sides; UI: three more functions at 100%: the building menu's DoInitial, the credits' prepare and activateModalDialog2 #435 and UI: the credits scroll's fade and the win/defeat window at 100% #437 describe the same two readings. Every other main function reads exactly what it read before (unrounded 99.5746 against 99.5759 raw, all of the difference in those two functions)./GLlist that exist on main, and the file as committed, off the list: 144 functions, average 99.56. The function reads 100.0% raw and normalised, with no diff entries. The same build without the file has 143 functions, and each of them reads the same. The sources were main's at 3458fea; main's two commits since (02fab42, 812d149) add cmake files only, with the new option off.The behaviour fix
retat 0x00468BD3):isScrollingis cleared, the base distance goes back to the minimum, the four flags are cleared, and the stop time and the scrolling time are both set to now. In the drafts in the table that block has no return. They went on into the scrolling code:isScrollingwas set again,timeScrollingbecame the time since the stamp just taken (about 0), and the base distance became that time divided by the interval (0, not the minimum). SoisScrollingread TRUE after every call, scrolling or not; main has three readers of it (HandleWallTerrainMouseDrag, the in-game menu's place-wall handler andGameCore::viewportAndScrollingRelated). His fork's reimpl/Wilps-2026-10-18 has the return (return; // 0x468BD3in 8ca7861, a copy with other field names and a 0.0% status line); his later 3d17527 is without it.Everything else in the draft computes the original's values: the eight directions, the maximum distance of two thirds of the limit, the fast setting's interval less a third and maximum at 133%, and the slow setting's interval plus a half and half the maximum. The draft's divisions are unsigned where the original's are signed (below), which differs only for a limit of 2^30 or more, or an interval of 2^31 or more.
What got it to 100%
The draft is the decompiler's output, with a
gotoand the division by -3 written as its multiply and shifts. The function is rewritten against the original instructions, in two steps on our dev branch (not public): 86.9%, then 100.0%.isScrollingis set in both arms of the direction test, and a secondifon it holds the rest of the no-direction block (86.9% to 100.0%). The original places that block in the middle of the speed switch: behind the slow case, in front of the fast one (0x00468BAF). As far as we can tell, the compiler knows the flag on both paths and drops the second test, but only after it has placed the blocks, so the block keeps the place of the secondif; the switch's compare chain then moves up to the store, and its slow case with it. That fits the listing: the FALSE store sits in the block (0x00468BB2) and the TRUE store in the switch's dispatch (0x00468B95). Written as oneifwith a return in front of the store, the block stays in front of the switch (86.9%: the block's 15 instructions in front of the switch, with ajnearound them where the original has ajeto them). Written as theelsearm of the direction test, it goes behind the function's end, and the compiler reorders its stores (78.2%). Testing the direction twice does not do it either (quick_diff 0.9769: the direction is then loaded into a register for the two compares).interval -= interval / 3for fast andinterval += interval / 2for slow. For the fast case the compiler divides by -3 and adds (imulby 0x55555555,sub edx, ebx,sar edx, 1, the sign added, thenadd ebx, ecx), which is what the original has (0x00468BD4 to 0x00468BFB). Writteninterval += interval / -3, or with the third in a local of its own, the listing is the same.(int)scrollDistanceLimit: the original divides it signed (see the header finding below).timeScrolling, and the quotient intoscrollDistanceBase. With a local for each, the listing is the same, so the fields are used.quick_diff reads 1.0000: 130 instructions against 130.
No line for
cmake/compiler-flags-gl.txt/GLlist, and 100.0% on it too (the same build with the line added). So it needs no line.timeGetTime, so it needs no line incmake/function-visibility.txt(cmake: function-visibility.txt, which callers must see which callees' bodies #398) either.Kept as they are
isScrollingis set from the direction and tested right behind. A comment in the code says that the plain form loses the match.timeScrollinggets the time stamp itself when scrolling stops (not 0): the original storestimeGetTime()into both fields (0x00468BCA, 0x00468BCD). Nothing on main readstimeScrolling.Header finding (nothing changed here)
ScrollingHandler::scrollDistanceLimit,scrollAccelerationIntervalandscrollDistanceMinareundefined4, but the original uses them asint. It divides the doubled limit by 3 signed (imulby 0x55555556 at 0x00468AE2), halves the interval signed (0x00468B9F) and divides by it withidiv(0x00468C0E), and copies the minimum into theintscrollDistanceBase. Asint, the(int)cast here would go. Nothing on main reads the three fields.Other PRs
reimpl/UI-Core, closed) holdshandleScrolling.cppat 23.6%; his fork's UI branches carry the same 23.6% text, and its reimpl/Wilps-2026-10-18 a copy with the return (above). We know of no open PR that holds the file; his open Reimplement 10 UI constructors and helpers #295 addsConstructor_ScrollingHandler.cppin the same folder, which does not conflict. A branch that holds this file will have an add/add conflict on it and a different status line at 0x00468AD0, and can take main's version once this lands.🤖 Generated with Claude Code