Author Topic: Depth when spawning healthbars with Panel  (Read 4290 times)

breakmachine

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 3
  • Posts: 71
    • View Profile
Depth when spawning healthbars with Panel
« on: October 10, 2013, 02:00:33 AM »
I have these healthbars consisting of a panel with two sprites underneath ("a" & "b"). When spawning the healthbars they all get the same panel depth. This means that sprite "a" shares the same depth as all other sprite "a". And for some reason this results in two drawcalls per panel.

Do I have to manage the depth of the spawned panels to prevent this and if so are there any shortcuts such as finding next available depth?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Depth when spawning healthbars with Panel
« Reply #1 on: October 10, 2013, 05:21:42 AM »
The panel will split up its draw calls if there is another panel with the same depth that has widgets sharing the depths with the original panel, but not the materials. Easiest way to fix it is to ensure that your instantiated health bars are sitting on a panel that has a depth that only matches other health bars.

breakmachine

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 3
  • Posts: 71
    • View Profile
Re: Depth when spawning healthbars with Panel
« Reply #2 on: October 10, 2013, 06:27:35 AM »
But if I have one panel per healthbar (since they are "ever moving" and I need to reduce GC )that means I have to manage the depth of all those panels so they aren't the same. Would be handy to have some function to get next available depth or something.

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Depth when spawning healthbars with Panel
« Reply #3 on: October 10, 2013, 06:32:33 AM »
Have one HealthBar parent, which has a panel that holds all health bars (and nothing else). Since they all move all the time anyway, there's little gained by having them in each of their own panel.

breakmachine

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 3
  • Posts: 71
    • View Profile
Re: Depth when spawning healthbars with Panel
« Reply #4 on: October 10, 2013, 06:47:03 AM »
@Nicki
Hi Nicki. I'm having trouble keeping down memory allocation on the heap in my game so I don't want new mesh to be generated every frame. Therefore, by making one panel per healthbar and moving that healthbar instead of the sprite I can make them static.

Nicki

  • Global Moderator
  • Hero Member
  • *****
  • Thank You
  • -Given: 33
  • -Receive: 141
  • Posts: 1,768
    • View Profile
Re: Depth when spawning healthbars with Panel
« Reply #5 on: October 10, 2013, 06:56:54 AM »
Ah ok, I see your issue then.

You'll likely have to make a little system that handles depths for those panels - so you have a pool of ints that you can use, and keep track of which are being used and hold it like that in a sort of depth pool.

Alternatively, you do the same thing for each individual widget inside the health bar, but that can quickly become complicated.

For this particular issue, the old way NGUI did it would have been easier.

Maybe each panel should have some sort of "isolate draw call" bool, so its draw calls can be its own?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Depth when spawning healthbars with Panel
« Reply #6 on: October 10, 2013, 07:10:35 AM »
Each panel generates its own draw calls. Extra panels can separate draw calls further, but they will never merge draw calls. For example you will never have widgets from panel A end up in the same draw call as widgets in panel B.

So to that extent, all panel draw calls are already isolated. Having health bar panels have the same depth as each other is not an issue here. Panels moving will only affect their own draw calls.

breakmachine

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 3
  • Posts: 71
    • View Profile
Re: Depth when spawning healthbars with Panel
« Reply #7 on: October 10, 2013, 07:19:58 AM »
Thank you for your quick replies!

Since I'm pooling my healthbars I just added a counter that gives them unique depths. But I'm still getting GC Alloc. Could it be that I have filled sprite in my static panel? Woud changing fillAmount cause a redraw?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Depth when spawning healthbars with Panel
« Reply #8 on: October 10, 2013, 07:30:55 AM »
Of course it does. Any and all changes to sprites cause the draw buffer to get re-generated.

breakmachine

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 3
  • Posts: 71
    • View Profile
Re: Depth when spawning healthbars with Panel
« Reply #9 on: October 10, 2013, 08:03:33 AM »
And I guess an anchor that isn't set to run once will do the same  :)

breakmachine

  • Jr. Member
  • **
  • Thank You
  • -Given: 0
  • -Receive: 3
  • Posts: 71
    • View Profile
Re: Depth when spawning healthbars with Panel
« Reply #10 on: October 10, 2013, 08:55:56 AM »
I'm almost there...
When setting the depth of my spawned healthbars the setter function sets all drawcalls to isDirty and mFullRebuild to true. That includes the drawcall from my static panel. Which of course results in a large allocation.

I'm thinking of doing and extension with a function to set depth without marking everything as dirty but maybe there's a better way?
« Last Edit: October 10, 2013, 09:02:11 AM by breakmachine »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Depth when spawning healthbars with Panel
« Reply #11 on: October 11, 2013, 08:39:46 AM »
Problem with that is changing depth has potential to alter the draw calls themselves as it changes the draw order and alters how widgets get broken up into draw calls. This is why a full rebuild is needed. Can it be optimized? Certainly. But I haven't done any clever hacks on this yet.