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?


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

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})
	self.draw.tl = false
	table.insert(self.draw.tbl, {x = 0, y = 0})

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})
	self.draw.tr = false
	table.insert(self.draw.tbl, {x = w, y = 0})

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})
	self.draw.br = false
	table.insert(self.draw.tbl, {x = w, y = h})

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})
	self.draw.bl = false
	table.insert(self.draw.tbl, {x = 0, y = h})


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))
		surface.SetDrawColor( 255, 255, 0, 50 )


draw.SimpleText(self.icon, self.font, self.adjust.x, self.adjust.y, Color(255, 255, 0, 150))

self:PaintInfo( w, h )


All this code isn’t optimized yet, all raw from the brain.

Then I use surface.DrawLine, draw.RoundedBox, draw.SimpleText and surface.DrawPoly alot.