local EntityHudRenderSystem = inherited("EntityHudRenderSystem", SystemLinear)

function EntityHudRenderSystem:new()
	local ms = instance(self)
	return ms
end

function EntityHudRenderSystem:wants(ent)
	return ent.aspects.name_render
end

function EntityHudRenderSystem:ent_added(ent)
	ent.rx = ent.x
	ent.ry = ent.y
	ent.rz = ent.z
end

function EntityHudRenderSystem:ent_removed(ent)
end

local function ry_sort(a,b)
	return a.ry < b.ry
end

function EntityHudRenderSystem:step()
	shellsort(self.ents, ry_sort)
end

function EntityHudRenderSystem:render(x, y, scale, perspective, angle, a, r, g, b)
	for index, ent in ipairs(self.ents) do
		local rx = x + ent.rx*scale
		local ry = y + ent.ry*scale*perspective -ent.rz*scale
		ent:render_hud(rx, ry, scale, perspective, angle, a, r, g, b)
	end
end

return EntityHudRenderSystem