fix: topbar stale resource#8145
Conversation
So I just drew the numbers outside the cached texture. In gui_top_bar.lua: I added drawResbarNumbersLive() So what it does it draws the current value, pull and income, and storage directly through the font2:Print() each frame, reusing the existing resbarDrawinfo positions and short() formatter. Also I removed renderResbarText, the scissor block, the r2tHelper.RenderToTexture(uiTex, renderResbarText) call, and the storageScissors pre clear you mentioned in beyond-all-reason#7644. Then I removed the now unused drawResbarValue, drawResbarPullIncome, drawResbarStorage, and clearFn helpers. The bar fills, glow, and overflow warnings still go through uiTex like before only the four numbers per resource are drawn live. The reason I did it this way was because you said the issue, measured width clear rects don't fully cover the anchor shift cases. So the problem is not really just the clear rect width. It is the text anchor positions shift when switching spectated players or when layout changes. So a perfectly sized clear rect can miss the old digits and drawing live sidesteps the whole cache scissor path. There is nothing to clear because the numbers are never stored. The perf cost is negligible since font2:Print() is already on the draw path. Fixes beyond-all-reason#7996
sprunk
left a comment
There was a problem hiding this comment.
instead of trying to size the clear rects better I just drew the four numbers per resource live for each frame with "font2:Print()" Which bypasses the "uiTex" cache all together. So there is nothing to clear because the numbers are never stored in the texture now.
the texture was there for a reason though, now it's slower. why not size the clear rects better?
That makes sense, you saying that, but the texture cache was there to avoid the re rendering text for every frame and the old code only updated the numbers 20 times per second. So every 50 millsecond through "timers.nextBarsupdate" instead of every time. Also the issue is not just the clear rect width. Actually the text anchor positions shift when switching spectated players or when the layout changes. So meaning that a perfectly sized clear rect at the current position can still miss the old digits that were drawn at the previous position. So then you would have to track and clear both the old and new positions every time the anchor moves. As for the perf, adding up to 8 more "font2:Print()" calls per frame "(4 numbers x 2 resources, storage is conditional)" the bar fills, glow, and overflow warnings still go through "uiTex" like before and only the numbers are drawn live. I can switch to a clear rect way if you really prefer, but the only thing is that it would need to track the old positions anchor positions to clear them aswell. Also I can look into doing a hybrid way by keeping the "uiTex cache" but also clear the old anchor positions when refreshUi triggers a reposition. |
Co-authored-by: sprunk <spr.ng@o2.pl>
Closes #7996
FIXED "Top bar stale resource"
The resource numbers on the topbar (value, pull, income, storage) were baked into "uiTex" through RenderToTexture with a fixed size clear rects. So when values got wide or anchored the positions shifted. Also spectator switches, layout changes and the old digits escaped the clear rects and piled up on the bar.
So instead of trying to size the clear rects better I just drew the four numbers per resource live for each frame with "font2:Print()" Which bypasses the "uiTex" cache all together. So there is nothing to clear because the numbers are never stored in the texture now.
As for the Bar fills and glow and overflow warnings and wind, tidal, coms text. It still goes through the uiTex like before. The only the resource numbers are drawn live. So Perf cost is negligible. So the font2:Print() is already on the draw path.
Also so a few things I removed were the now unused "renderResbarText" "drawResbarValue" "drawResbarPullIncome" "drawResbarStorage" "clearFn" and the scissor block, aswell the storageScissors pre-clear that was mentioned in "#7644" #7644
Also here is the short clip of the results visually.
https://www.loom.com/share/bff658dff76144999b8cdafad8c74cb2