# Optimalisation

Hi all,

I would like to know which function is faster for optimalisation, I’m guessing you guys might be able to help me out?

What is better to draw a line?

• draw.RoundedBox()
• surface.DrawLine() <- Guessing this one

What is better to draw a box?

• surface.DrawPoly()
• surface.DrawRect() <- guessing this one
• draw.RoundedBox()

Is surface.DrawPoly() hard to render when using alot of custom shapes?

Is surface.DrawLine() hard to render when using many of them?

Is transparency hard to render when using it alot?

Is setting a variable in a Paint hook a dumb idea?

Is

``````
math.floor(CurTime() % 2) == 0

``````

hard to calculate to make something flicker?

My beautiful advanced HUD is already slurping 20FPS, and then I haven’t even talked about it’s features.

Thanks for helping!

All the things you’ve described are pretty much just micro-optimisations and won’t help you anything. You’ve probably got something really wrong with your code if it’s hogging that much FPS. A common pitfall is calling Material() in the HUDPaint. Could you show us your code?

I’m not gonna show off my code complete as it is part of my new gamemode which I want to keep for myself hehe. But I can supply some code to show what I do.

I create Derma Objects. EditablePanels, with these Paint functions

[lua]
function PANEL:DrawEx(topleft, topright, bottomright, bottomleft)
local w, h = self:GetSize()
self.draw.tbl = {};

``````if topleft then
self.draw.tl = true
table.insert(self.draw.tbl, {x = 0, y = 20})
table.insert(self.draw.tbl, {x = 20, y = 0})
else
self.draw.tl = false
table.insert(self.draw.tbl, {x = 0, y = 0})
end

if topright then
self.draw.tr = true
table.insert(self.draw.tbl, {x = w - 20, y = 0})
table.insert(self.draw.tbl, {x = w, y = 20})
else
self.draw.tr = false
table.insert(self.draw.tbl, {x = w, y = 0})
end

if bottomright then
self.draw.br = true
table.insert(self.draw.tbl, {x = w, y = h - 20})
table.insert(self.draw.tbl, {x = w - 20, y = h})
else
self.draw.br = false
table.insert(self.draw.tbl, {x = w, y = h})
end

if bottomleft then
self.draw.bl = true
table.insert(self.draw.tbl, {x = 20, y = h})
table.insert(self.draw.tbl, {x = 0, y = h - 20})
else
self.draw.bl = false
table.insert(self.draw.tbl, {x = 0, y = h})
end
``````

end

function PANEL:Paint( w, h )
if self.draw.bool then

``````	if !self.draw.tl and !self.draw.tr and !self.draw.br and !self.draw.bl then
draw.RoundedBox(0, 0, 0, w, h, Color(255, 255, 0, 50))
else
surface.SetDrawColor( 255, 255, 0, 50 )
draw.NoTexture()
surface.DrawPoly(self.draw.tbl);
end

end