itHyperoX Posted June 15, 2018 Share Posted June 15, 2018 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 Patrick Posted June 15, 2018 Moderators Share Posted June 15, 2018 (edited) 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 June 15, 2018 by Patrick2562 1 Link to comment
itHyperoX Posted June 15, 2018 Author Share Posted June 15, 2018 (edited) 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. Edited June 15, 2018 by TheMOG Link to comment
Moderators Patrick Posted June 16, 2018 Moderators Share Posted June 16, 2018 (edited) 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 June 16, 2018 by Patrick2562 1 Link to comment
Discord Moderators Pirulax Posted June 16, 2018 Discord Moderators Share Posted June 16, 2018 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
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now