Jump to content

[HELP] Optimization


Recommended Posts

Hi, i made a dx update note. Is there any way to optimize it more ?

function drawPanel()
    latestRow = currentRow + maxRow - 1
    dxDrawRectangle(panelX, panelY, mainW, mainH, tocolor(0, 0, 0, 180))
     for i, v in ipairs(TextsInTable) do
           if i >= currentRow and i <= latestRow then
            i = i - currentRow + 1
            local rowY = panelY + rowH +  ((i - 1) * rowH) - 180
               dxDrawCenterText(v[1].." "..v[2], panelX, rowY, mainW, mainH, Font)
           end
      end

end
addEventHandler("onClientRender", root, drawPanel)

bindKey("mouse_wheel_down", "down", function()
    if currentRow < #TextsInTable - (maxRow - 1) then
        currentRow = currentRow + 1
    end
end)

bindKey("mouse_wheel_up", "down", function()
    if currentRow > 1 then
        currentRow = currentRow - 1
    end
end)

function dxDrawCenterText(text, startX, startY, width, height, color)
    dxDrawText(text, startX, startY, startX + width , startY + height, color, 1, "normal", "center", "center", false, false, false, true)
end

 

Link to comment
  • Moderators

I think it's okay.
Maybe if you define the 'latestRow' once in bindKey functions and not in the 'drawPanel' function.

 

function drawPanel()
    dxDrawRectangle(panelX, panelY, mainW, mainH, tocolor(0, 0, 0, 180))
     for i, v in ipairs(TextsInTable) do
           if i >= currentRow and i <= latestRow then
            i = i - currentRow + 1
            local rowY = panelY + rowH +  ((i - 1) * rowH) - 180
               dxDrawCenterText(v[1].." "..v[2], panelX, rowY, mainW, mainH, Font)
           end
      end

end
addEventHandler("onClientRender", root, drawPanel)

bindKey("mouse_wheel_down", "down", function()
    if currentRow < #TextsInTable - (maxRow - 1) then
        currentRow = currentRow + 1
      	latestRow = currentRow + maxRow - 1
    end
end)

bindKey("mouse_wheel_up", "down", function()
    if currentRow > 1 then
        currentRow = currentRow - 1
      	latestRow = currentRow + maxRow - 1
    end
end)

function dxDrawCenterText(text, startX, startY, width, height, color)
    dxDrawText(text, startX, startY, startX + width , startY + height, color, 1, "normal", "center", "center", false, false, false, true)
end

 

Edited by Patrick2562
  • Like 1
Link to comment
  • Moderators
10 hours ago, TheMOG said:

Thank you for your reply! One more question, if i using custom font (AwesomeFont) ,  is that can make any minus FPS for players ? I never knew this.

Yes. More custom fonts use more video memory.
But I've never been watching this. In negligible part.
I'm paying attention to not creating multiple fonts in a Resource.

Example:

In the resource folder I create a fonts.lua (client) file. And I create the dxfont only here and I can use this custom font in every client file.

Edited by Patrick2562
  • Thanks 1
Link to comment
  • Discord Moderators

I dont think that custom fonts add something to delta time(The more delta time the less FPS, actually, the time between two frames is called 'delta time')

Think about it: MTA uses custom fonts too, but they are created inside of MTA.

And yeah, code:

addEventHandler("onClientRender", root, 
    function()
        dxDrawRectangle(panelX, panelY, mainW, mainH, tocolor(0, 0, 0, 180))
        
        local offsetY = panelY-180
        for i = currentRow, latestRow do
            if not (TextsInTable[i]) then return end
            dxDrawCenterText(v[1].." "..v[2], panelX, offsetY, mainW, mainH, Font)

            offsetY = offsetY + rowH 
        end
    end
)


bindKey("mouse_wheel_down", "down", function()
    if currentRow < #TextsInTable - (maxRow - 1) then
        currentRow = currentRow + 1
      	latestRow = currentRow + maxRow - 1
    end
end)

bindKey("mouse_wheel_up", "down", function()
    if currentRow > 1 then
        currentRow = currentRow - 1
      	latestRow = currentRow + maxRow - 1
    end
end)

function dxDrawCenterText(text, x, y, width, height, color, fontSize, font)
    dxDrawText(text, x, y, x + width , y + height, color, fontSize, font, "center", "center", false, false, false, true)
end

 

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...