Thread Tools Display Modes
05/28/24, 01:41 PM   #1
imPDA
Join Date: Mar 2022
Posts: 3
Question Updating multiple controls (textures) at once

Hello developers! I wonder if it possible to "Set3DRenderSpace(Forward/Right/Up)" for a, lets say, all child textures with one command or with some workaround? A little bit of context: I have parent control

Lua Code:
  1. win = WINDOW_MANAGER:CreateTopLevelWindow("MyTopLevel")
  2.  
  3.   win:SetClampedToScreen(true)
  4.   win:SetMouseEnabled(false)
  5.   win:SetMovable(false)
  6.   win:SetAnchorFill(GuiRoot)
  7.   win:SetDrawTier(DT_LOW)
  8.   win:SetDrawLayer(DL_BACKGROUND)
  9.   win:SetDrawLevel(0)

and bunch of child controls

Lua Code:
  1. local marker = win:CreateControl(name, CT_TEXTURE)
  2.  
  3.   marker:SetTextureReleaseOption(RELEASE_TEXTURE_AT_ZERO_REFERENCES)
  4.   marker:Create3DRenderSpace()
  5.   marker:SetTexture(textureFile)
  6.   marker:SetColor(0, 1, 0)
  7.   marker:SetDrawTier(DT_LOW)
  8.   marker:SetDrawLayer(DL_BACKGROUND)
  9.   marker:Set3DLocalDimensions(1, 1)
  10.   marker:Set3DRenderSpaceUsesDepthBuffer(true)
  11.   marker:SetHidden(false)
  12.   marker:Set3DRenderSpaceOrigin(x, y, z)

My first assumption was to change parent 3D render space, but it doesn`t help, so I believe, properties of children do not inherited from parents. I have to iterate through all child controls and set one by one. I want to set 3D render space to make all "markers" be parallel to camera's RightUp plane and rotate with camera. I update it every frame.

The problem is I want to create really massive amount of "markers" and after I reach 1000 ones I have some FPS decrease (not noticeable by eye, but FPS meter says so). After I profiled it, without any surprise, I have discovered what the most expensive operation - "Set3DRenderSpace(Forward/Right/Up)" ~1.5ms peak and ~1ms in average, so I do need somehow decrease it to keep FPS stable.

It is more research question, how far can I push limits of ESO API, but I also have some thoughts about addon where I can apply this.

Please let me know if there is any elegant way to solve this problem

Also I would like to notice, that entire execution of my update function takes 2.415ms in average according to profiler, so it is not such an heavy operation to my mind and ESO is capable to execute it every frame. Strange thing (for me) is that most of time on a timeline view is empty: 2.4ms my function, 0.6ms other functions, 4.5ms of empty space between frames, so FPS is 1000/7.5 ~ 133 which is perfectly corresponds to what I see. So why they are there? Is there a way to decrease them?

P.S. I know about OSI, and it performs worse (144 -> 80-90 FPS drop vs 144 -> 120-130 with my addon), mostly because I believe it was not architectured to handle so much icons and moreover I optimized my addon as much as I can at this point (I was starting from huge FPS drop, but then optimized step by step researching profile).
  Reply With Quote
05/29/24, 02:50 AM   #2
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 5,016
Edit:
As Sirinsidiator mentioned below you should switch to use ZO_ObjectPool (control pool):
https://wiki.esoui.com/How_to_use_ZO_ObjectPool


As far as I know only SetHidden on a parent will change the relating child controls automatically.
All other attributes need to be set manually (maybe there are others, like SetMouseEnabled and such, but no "visual" ones I know off).

So looping the childs will be one thing to do it.
Another would be to add all controls to a sub-table, key = child's index and value = childControl.
Main table would hold the parent controls then.
Loop the tables then and apply your needed methods/functions/attributes.

Lua Code:
  1. myAddon.controlsToUpdate = {
  2.    [parentCtrl] = {
  3.       [childIndex1] = childControl,
  4.       [childIndex2] = childControl,
  5.    }
  6. }

But that's bascially the same as the control's already do now, so maybe only extra loss of performance. You'd have to profile that again I guess if looping pre-filled tables with only the control as value you need is more performant than using something like this

Lua Code:
  1. for i=1, parentCtrl:GetNumChilds() do
  2. local childCtrl = parent:GetChild(i)
  3. if childCtrl.myControlToUpdate then --I assume you have set some identifier like that to the child control upon creating them to speed up finding them in the childs loop here. Because using GetName() and compare strings is slow



Btw: Please keep in mind that addons must not draw 3d markers in dungeons!
https://www.esoui.com/forums/showthread.php?t=9865

ZOs explicitly did not want their API to do that and they once said it is nothing they officially support, nor like.
So it's a gray zone again, but we fear loosing API or get others restricted the more addons will be created which draw 3d markers inside dungeons!
So please: Don't or at least get the official OK from ZOs DanBatson and/or ZOsSethl here:
https://app.gitter.im/#/room/#esoui_esoui:gitter.im

Last edited by Baertram : 05/29/24 at 04:44 AM.
  Reply With Quote
05/29/24, 04:18 AM   #3
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,580
Originally Posted by imPDA View Post
The problem is I want to create really massive amount of "markers" and after I reach 1000 ones I have some FPS decrease (not noticeable by eye, but FPS meter says so). After I profiled it, without any surprise, I have discovered what the most expensive operation - "Set3DRenderSpace(Forward/Right/Up)" ~1.5ms peak and ~1ms in average, so I do need somehow decrease it to keep FPS stable.
Do you mean you are creating new markers every update? If that's the case, please be aware that controls, once created are never destroyed. Meaning you cannot discard them without creating a memory leak. Instead you should use ZO_ObjectPool in order to reuse any markers you have already created. That would probably also solve your issue, since you do not need to call Set3DRenderSpace again after a marker was set up.

Originally Posted by imPDA View Post
Also I would like to notice, that entire execution of my update function takes 2.415ms in average according to profiler, so it is not such an heavy operation to my mind and ESO is capable to execute it every frame. Strange thing (for me) is that most of time on a timeline view is empty: 2.4ms my function, 0.6ms other functions, 4.5ms of empty space between frames, so FPS is 1000/7.5 ~ 133 which is perfectly corresponds to what I see. So why they are there? Is there a way to decrease them?
2.4ms is a massive amount of time for one single addon to waste. You need to keep in mind that addons are running on the same thread as the rest of the game loop, so you are sharing the available time per frame not just with other addons, but also with the game itself. That's the empty space you are seeing between frames.

At 60 fps one single frame can at most take 16.6ms. The majority of that time is taken up by the game for things like graphics, physics and other calculations. So addons have somewhere around 5ms (guestimated) they can use without making the framerate drop.
Meaning your addon is taking up almost 50% of the available time budget for addons at 60 fps and (apparently) more than 100% at 144 fps.
  Reply With Quote
05/30/24, 01:03 AM   #4
imPDA
Join Date: Mar 2022
Posts: 3
Originally Posted by Baertram View Post
...
ZOs explicitly did not want their API to do that and they once said it is nothing they officially support, nor like.
So it's a gray zone again, but we fear loosing API or get others restricted the more addons will be created which draw 3d markers inside dungeons!
So please: Don't or at least get the official OK from ZOs DanBatson and/or ZOsSethl here:
https://app.gitter.im/#/room/#esoui_esoui:gitter.im
OK, I get it and I'm fine with it, was not going to draw it BUT I can't get this (link):
This information, coupled with some math, can allow an addon to position
an element in the 2D UI space in such a way that it gives off the illusion that it's in a fixed position in 3D space. It's quite hackish, and it involves recalcuating positions and constantly moving those textures many times per second! -> Remember: "Anything that affects server performance"
If I understand things correctly, if you draw some texture on your UI, it doesn't connected with server at all, so even I will redraw and recalculate 1M objects and get 1 FPS, it will do nothing to the server. It is just my UI and CPU on fire. SO ZOs just doesn't want any super helpful and OP addons in dungeons? But isn't this Marker addon violates ZOs will

It is just because of my curiosity.

Btw, I had not enough time to properly dive into ObjectPool, from the first glance it is not proper instrument I need, but neither I heard about it before, so maybe searching around it will succeeded.
  Reply With Quote
05/30/24, 01:20 AM   #5
imPDA
Join Date: Mar 2022
Posts: 3
Originally Posted by sirinsidiator View Post
Do you mean you are creating new markers every update?
No, I'm using separate table to keep all created markers and add new on demand, don't delete so far, by I will need to delete them, so 'Pool' will be very handy for it if I get its description right. As I mentioned above, had not enough time to study it properly -_-

Originally Posted by sirinsidiator View Post
you are sharing the available time per frame not just with other addons, but also with the game itself. That's the empty space you are seeing between frames.
I wish I had better control on threads, because as far as I can understand, there is something in the game which handles in separate thread (which is multi-threading rendering in setting stands for). And multi-threading in fact helps with performance ALOT (at least for me). But I can see profile only for one timeline, and unfortunately can't see how much free time I have. If I could see, lets say, some process named "internal", which will include all game cycle and it would take 4.5ms, then I would easily realized, what I only have 6.9-4.5=1.4ms for my addon at most, but likely even less, so no questions. But it is what it is, going to learn it the hard way.

SO I am limited only by ~1ms ATM based on my experience (and if we take into consideration other addons - even less than 1ms), I need to do some sneaky business to optimize this.

Last edited by imPDA : 05/30/24 at 01:24 AM.
  Reply With Quote
05/30/24, 09:23 AM   #6
Baertram
Super Moderator
 
Baertram's Avatar
WoWInterface Super Mod
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 5,016
Originally Posted by imPDA View Post
OK, I get it and I'm fine with it, was not going to draw it BUT I can't get this (link):


If I understand things correctly, if you draw some texture on your UI, it doesn't connected with server at all, so even I will redraw and recalculate 1M objects and get 1 FPS, it will do nothing to the server. It is just my UI and CPU on fire. SO ZOs just doesn't want any super helpful and OP addons in dungeons?
Yes, correct. The Wiki is wrong about the server performance there, unless I'm missing any side effects to the server.
Changed the description.


Originally Posted by imPDA View Post
But isn't this Marker addon violates ZOs will
Yes and I had asked the author already by addon comment (seems to have been deleted...) and private message to respect ZOs' wish about markers in dungeons.


Originally Posted by imPDA View Post
SO ZOs just doesn't want any super helpful and OP addons in dungeons?
They did not like to add those themselves and they explicitly disabled 3d controls inside dungeons -> Which should be indicator enough what they dislike...

Basically all those addons providing hacks for dungeons, to help with positioning etc. by showing textures are just tolerated atm by ZOs, afai understand it. For now ...

To be fair some dungeons are really ahrd to play because of all the effects and even buggy fights, and addons helping thre "must be tolerated for now, imo". But not all are. As I said, seems to be a gray zone.

Last edited by Baertram : 05/30/24 at 09:27 AM.
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » Updating multiple controls (textures) at once


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off