Allow redrawing Lua while multiple scripts are open#4682
Allow redrawing Lua while multiple scripts are open#4682SuuperW wants to merge 3 commits intoTASEmulators:masterfrom
Conversation
…hroughout the years such that the comment accidentally got put with the wrong code and the right code doesn't exist anymore
…awings (except clear APIs, about to be deprecated)
…multiple Lua scripts running at once
YoshiRulz
left a comment
There was a problem hiding this comment.
But this clears everything drawn by other scripts as well, without giving them an opportunity to re-draw.
Does that opportunity not come when the script yields? Scripts can clear in a event.onframestart callback then draw in a yield loop.
|
|
||
| public void AddDrawCallback(Action callback) => _displayManager.OnDraw += callback; | ||
|
|
||
| public void RemoveDrawCallback(Action callback) => _displayManager.OnDraw -= callback; |
There was a problem hiding this comment.
ApiHawk already has a draw call batching/scoping method, WithSurface.
There was a problem hiding this comment.
That's completely unrelated. WithSurface(surfaceId, action) is just a wrapper for UseSurface(surfaceId); action(); UseSurface(originalSurfaceId). The new callbacks don't care about which surface is being drawn, it's just a signal to draw.
There was a problem hiding this comment.
I know, I'm saying if you're going to limit draw calls to callbacks, use the callback which already exists and which I've been promoting for this reason.
There was a problem hiding this comment.
I don't understand how WithSurface could be used in a way that is similar to AddDrawCallback.
And if you were to change how WithSurface works, that would be an API change that I think is better done while changing the name, so that existing code will fail at compile time instead of run time. (better yet, have both so existing code keeps working, at least until the old way is deprecated)
EDIT:
if you're going to limit draw calls to callbacks
This PR does not do that. Old Lua scripts should continue to work exactly as they have before.
|
Text written with Drawing in Plus, drawing in a yield loop wastes a bit of CPU while paused. |
Currently if a Lua script wants to re-draw it has to do one or more of:
and then draw it's stuff. But this clears everything drawn by other scripts as well, without giving them an opportunity to re-draw.
Having multiple Lua scripts that draw was also made difficult by the fact that some things that Lua draws weren't being cleared on each new frame. This means if any Lua script wants to clear what it drew, it must call
clearGraphicswhich again can interfere with other scripts.So this PR does two things:
DrawString, which makes no sense)A Lua script can now do something like:
and another script can call
gui.draw()to clear its drawings. Thegui.drawcall will end up calling the first Lua'sonDrawfunction so that it isn't affected by the second script's wanting to clear.We could also make it so that the Lua Console calls
IGuiApi.Drawwhen a script is stopped. But this should happen only if the user manually stops it, since a Lua script may want to just draw once and exit, leaving the drawings on screen until the next frame.Check if completed: