Author Topic: Making menus appear not jerky  (Read 12053 times)

Ugur

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 60
    • View Profile
Making menus appear not jerky
« on: November 19, 2014, 02:10:15 PM »
So here's the issue:
When i have ngui ui elements enabled and on the screen on app start, all looks fine.
But i have some items which are not enabled by default or added at runtime or resize in between etc.
Menus with scrollviews and header bars and panels which resize fitting to the screen dimensions, list items which reflow based on dimensions of previous elements etc.
And those all come in in jerky way the first time enabled/shown.
Its like it takes a frame or two for all the things to adjust to  dimension changes or content changes, changed anchors etc.
Is there some method(s) one can call to force it making all aligned and adjusted well right away when enabling it and showing it right in that frame the way it would usually display a few frames later?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Making menus appear not jerky
« Reply #1 on: November 19, 2014, 04:09:15 PM »
The first time something is drawn, draw calls need to be created which can take a little bit of time. This results in a stutter. That's what you're seeing. If you like, you can keep things enabled, just keep the panel's alpha at 0 (or widget container's, whatever you like).

Ugur

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 60
    • View Profile
Re: Making menus appear not jerky
« Reply #2 on: November 20, 2014, 01:05:22 PM »
ok, i'll give that a try, thanks =)

Ugur

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 60
    • View Profile
Re: Making menus appear not jerky
« Reply #3 on: December 04, 2014, 06:13:50 AM »
I was busy with a few other things in the meantime and just got to this again now.
So i tried setting the panel's alpha to 0, sadly for some things this does not work due to some i guess optimizations things you did because when the alpha is set to 0 for an object actually some sizing etc code seems to not get executed.
So when i have for example a popup panel and it has text and other elements resizing dynamically and the panel bg and other elements adapting to that and i would set the panel's alpha to 0 and set the text (so the layout, panel bg etc should resize), then it only does that resizing/reflowing of the layout once i set the alpha of the panel to higher again, not while its set to 0.
So setting it to 0 then is useless (despite it is what would be good to do to have it be shown once its properly layouted).
Is there some way to disable your "don't do if alpha ==0" or similar optimisations for that use case then?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Making menus appear not jerky
« Reply #4 on: December 05, 2014, 12:42:45 AM »
No, but you can just keep it enabled but off-screen. Simple solutions are simple.

Ugur

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 60
    • View Profile
Re: Making menus appear not jerky
« Reply #5 on: December 05, 2014, 05:14:02 AM »
Keeping things enabled and "just" off screen is a feasible solution for some things but not for many others.
I can use that way for a simple small popup window for example. But for more complex content like let's say a full splitscreen layout of many elements anchored to different screen edges and among each other, first positioning it off screen would then lead to jerky repositioning/re layouting on first move into the screen then, too, so first positioning all outside the screen is useless then.
Next to the side that having lots of elements which are not used in that moment positioned outside the screen is no good performancewise either.

One should also in general be able to turn that ngui internal "ignore if alpha<x" "optimisation" off for objects since it causes issues on various other ends, too. Like for example when one has buttons with transparent hit area (sprite) and they are supposed to resize to certain screen dimensions but resizing and pressing them does not work cause they have alpha 0 so one then has to set their alpha to a low value but not 0 to make them work properly.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Making menus appear not jerky
« Reply #6 on: December 05, 2014, 03:05:28 PM »
There is no middle ground here. Either things get rendered, and you get a stutter at the very beginning, or things don't get rendered until you enable them, and that's when you get a stutter.

Ugur

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 1
  • Posts: 60
    • View Profile
Re: Making menus appear not jerky
« Reply #7 on: December 06, 2014, 06:00:02 AM »
Yes, got that, so i want to render them, with alpha 0 and need a way to toggle it to have them do all the layouting stuff even when alpha 0 so then when i turn their alpha up they are all properly layouted (all the anchoring stuff etc should have taken place while their alpha was still 0 )

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Making menus appear not jerky
« Reply #8 on: December 07, 2014, 12:17:51 AM »
Anchors are always updated regardless of whether something is alpha 0 or not, so I am not sure I understand the point of what you're asking. If you manually set anchors at some point and then have issues with them not being in the right place after being enabled, then you likely forgot something simple like calling ResetAndUpdateAnchors().