Jump to content

Question about client performance in dx


Recommended Posts

So today I was making a new HUD for players in dx, due this HUD will be displayed all the time I started thinking about how I can optimize it as maximun as possible...

Going from this classic code:

local screenW, screenH = guiGetScreenSize()
local scaleX, scaleY = screenW/1920, screenH/1080

addEventHandler("onClientRender", root, function()
    dxDrawText("30/", screenW * 0.7786, screenH * 0.0648, screenW * 0.8380, screenH * 0.1426, tocolor(241, 173, 11, 255), scaleX, scaleY, dxfont0_excelsior_sans, "left", "top", false, false, false, false, false)
    dxDrawText("9999", screenW * 0.8354, screenH * 0.0657, screenW * 0.8807, screenH * 0.1130, tocolor(241, 173, 11, 255), scaleX, scaleY, dxfont1_excelsior_sans, "left", "top", false, false, false, false, false)
end)

to this "more optimized" one:

local screenW, screenH = guiGetScreenSize()
local scaleX, scaleY = screenW/1920, screenH/1080

local hudSizes = {
	(screenW * 0.7786), (screenH * 0.0648), (screenW * 0.8380), (screenH * 0.1426), (screenW * 0.8354), (screenH * 0.0657), (screenW * 0.8807), (screenH * 0.1130)
}

addEventHandler("onClientRender", root, function()
	dxDrawText("30/", hudSizes[1], hudSizes[2], hudSizes[3], hudSizes[4], 0xFFF1AD0B, scaleX, scaleY, dxfont0_excelsior_sans, "left", "top", false, false, false, false, false)
	dxDrawText("9999", hudSizes[5], hudSizes[6], hudSizes[7], hudSizes[8], 0xFFF1AD0B, scaleX, scaleY, dxfont1_excelsior_sans, "left", "top", false, false, false, false, false)
end)

As you can see I replaced the multiplications with some variables that represent the calculations (so it doesn't need to multiply the number everytime that "onClientRender" is triggered) and the same goes for the tocolor function.

So as far as my understanding goes this would increase the performance, right? or atleast that's my question doing this would have any impact in clients performance? or it's just complicating the code for no reason?

Link to comment
6 hours ago, Awang said:

I reccomend to use this resource to monitor the usages of your scripts:

https://community.multitheftauto.com/index.php?p=resources&s=details&id=12364

But basicly, I dont believe, that your precalculate will decrease the usage. Multiply two number is not a hard task for the CPU, even in every frame. 

Well, I haven't shown the complete code in this post, we're talking about 30+ multiplications, anyways thanks for posting that script I didn't know we had something like that, so useful

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...