Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WorldviewCommandModeTableStreamline #6585

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from

Conversation

clyfordv
Copy link
Contributor

  • Modifies controls/worldview.lua to call GetCommandMode once and store as a local table.
  • Modifies commandmode.lua to only update the commandModeTable (what's returned by GetCommandMode) when the command mode changes.
  • Minor: removes an unecessary check for the alt attack move cursor that didn't respect preferences.

Copy link
Contributor

@lL1l1 lL1l1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Functionally it makes sense.
It is possible to dirty the command mode table and then that would get used by other UI elements looking for the command mode, but that was already possible before (get table -> change table -> yield -> someone else gets the table and resets your changes) without issues so I don't think it'll become a problem. Perhaps a simple warning that the table shouldn't be modified would be suitable?

@@ -635,7 +633,7 @@ WorldView = ClassUI(moho.UIWorldView, Control) {
local cursor = self.Cursor
cursor[1], cursor[2], cursor[3], cursor[4], cursor[5] = UIUtil.GetCursor(identifier)
self:ApplyCursor()
CommandMode.GetCommandMode()[2].reticle = TeleportReticle(self)
commandModeTable[2].reticle = TeleportReticle(self)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels wrong to stuff data into the commad mode data that is UI related. Imagine if this is a script command with a reticle and we pass unserializable userdata inside a table: the game would immediately crash (as I discovered when annotating script tasks, and I doubt that LuaParams gets passed with any other orders, as it is logically not necessary).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that line can just be taken out; originally I had the idea that the command mode table was a good vehicle for different UI elements to get access to the reticle (or anything) but it doesn't apply in this case.

(believe I said this before)

@lL1l1 lL1l1 added the area: ui Anything to do with the User Interface of the Game label Dec 22, 2024
@lL1l1 lL1l1 added this to the Development I of 2025 milestone Dec 22, 2024
@Garanas
Copy link
Member

Garanas commented Dec 25, 2024

I do not fully understand what the issue is that these changes solve. At the same time, it increases coupling and makes it more difficult to understand how commandModeTable operates for future maintainers. Initially it would appear to just update magically 😄 !

Could you help me understand?

@clyfordv
Copy link
Contributor Author

clyfordv commented Jan 2, 2025

I think it's a good question and I'm not sure what the best answer is.

On one hand we have the issues you describe where it updates magically. But that behavior occurs in other places (see controls.lua--also not terribly intuitive).

On the other we have a function needlessly called every frame to update a table which is mostly (on a frame basis) the same. But the performance improvements to be had in that area are marginal.

@Garanas
Copy link
Member

Garanas commented Jan 25, 2025

I think the readability of the code outweighs the possible performance improvements. There's a tiny bit of overhead of a function call, but I do not believe it is a significant factor in the code that is changed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area: ui Anything to do with the User Interface of the Game
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants