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

Logic jump UI enhancement #10108

Draft
wants to merge 8 commits into
base: master
Choose a base branch
from

Conversation

code-explorer786
Copy link
Contributor

@code-explorer786 code-explorer786 commented Aug 11, 2024

If your pull request is not translation or serverlist-related, read the list of requirements below and check each box:

  • I have read the contribution guidelines.
  • I have ensured that my code compiles, if applicable.
  • I have ensured that any new features in this PR function correctly in-game, if applicable.
    • I have formally proven that the methods used are valid.
    • I have ensured that this is a good enough implementation.

Warning

I often reorder my commits and force push to this branch, so be careful while pulling from it!

Note

I am not that good in computer science.
If anyone has a better method1, I'd recommend discussing it here, in general-programming, or make a competing PR.
I got the not-in-#development treatment, so I can't really access the #pulls channel right now.
I'd love to hear your ideas!

Overview

The goal of this PR is to improve jump UI.
As such, this competes with @MEEPofFaith's #9925 and Foo's Client's implementation.

This PR adds in three features2:

  • Dynamic Jump Heights: Jump curves now adjust themselves to be more legible.
  • Colored Jumps: Jump curves are colored based on their destination. (Contributed by @Ilya246)
  • Trapezoidal Jumps: Jump curves now look trapezoidal to improve performance3 (Suggested by @Arkanic)

image

Tested feature combinations

Dynamic Jump Heights Colored Jumps Trapezoidal Jumps Result
✔️ Works as intended.4
✔️ ❌ Jumps merge.
✔️ ✔️ Works as intended.4
✔️ ✔️ ❌ Jumps merge.
✔️ ✔️ Works as intended.4
✔️ ✔️ ✔️ Works as intended.
✔️ ✔️ ✔️ Works as intended.4
✔️ ✔️ ✔️ ✔️ Works as intended.

I think fixing Trapezoidal Jumps and Colored + Trapezoidal Jumps implies reimplementing Dynamic Jump Heights in some form or another.
I don't think there's an alternative, but I could make Trapezoidal Jumps require Dynamic Jump Heights.

Footnotes

  1. With both Dynamic Jump Heights and Trapezoidal Jumps, I'd estimate the complexity determining jump heights is about O(k^2 + n) where k is the number of unique end destinations and n the number of jump curves.

  2. I've decided that these three features belong in one PR because they complement each other.
    Still, I've made them configurable in separate settings anyway.

  3. It improves both graphical rendering of the jumps and the implementation of Dynamic Jump Heights.

  4. Runs slower on logic with a lot of jumps.
    (I removed maxJumpsDrawn) 2 3 4

code-explorer786 and others added 8 commits August 11, 2024 08:52
Original canvas.jumps is now a reference to canvas.statements.jumps.
Please remove canvas.jumps in favour of canvas.statements.jumps in a
future release. Thanks!
Note that this is very incomplete, for two different reasons:
- it's O(n^2) or potentially worse
- it makes the GC work hard (it invokes `new` in
  `LCanvas.DragLayout.layout()`)

For the second reason this does not clearly fit the criteria of
CONTRIBUTING.md, but I have yet to figure out ways to work around this
(or make the algorithm more efficient).
It feels hacky, but it works regardless. The GC should be working as
hard as it was beforehand.
This method uses signaling (through a boolean) and I feel like it's
extremely hacky, but I tested this and it (kind of?) works.
Unfortunately I found this to potentially lag when resizing.

I am not sure if this is guaranteed to work (as in, produce correct
behaviour) or not, but to my understanding only LogicDialog uses LCanvas
(grep out "LCanvas\|canvas" and see) so it will most likely work?

I tested this and accidentally found an unrelated issue related to
LCanvas.maxJumpsDrawn, but I hope this will be fixed in the near future.
It looks good.
See #general-programming in the Mindustry Discord server:
https://discord.com/channels/391020510269669376/663854113418641429/1256146387834372106

Co-authored-by: Ilya246 <ilyukarno@gmail.com>
I haven't checked this yet, but it seems like it also reduces the
complexity (runtime) from ≈O(n^2) to ≈O(k^2 + n)
(n = number of jump curves)
(k = number of unique destinations)

The worst case, that is k = n, is still O(n^2) but generally it's much
more (scalably) performant.

Thanks Arkanic for suggesting this!
https://discord.com/channels/391020510269669376/663854113418641429/1256161815503704104

Co-authored-by: Arkanic <50847107+Arkanic@users.noreply.github.com>
@Twcash
Copy link

Twcash commented Aug 11, 2024

I like

@BlueTheCube
Copy link
Contributor

jump color based on jumping to instruction color?

@code-explorer786
Copy link
Contributor Author

jump color based on jumping to instruction color?

It's based on the destination's index/line number.

https://github.com/code-explorer786/Mindustry/blob/0d2d406f4dd3376f142d62e36555f780a95477e2/core/src/mindustry/logic/LCanvas.java#L318

                    int idx = e2.button.to.get().index;
                    if(dragging != null && idx >= dragging.index) idx += 1;
                    e2.button.defaultColor.set(jumpColors[idx]);
                });
            }

@way-zer
Copy link
Contributor

way-zer commented Sep 7, 2024

If you like, you can merge some from this commit TinyLake@b7be5a3.

I implemented the culling support for jumping, getting better performance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants