Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimisation pass #1365

Open
wants to merge 7 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 7 additions & 9 deletions lua/autorun/netstream.lua
TW1STaL1CKY marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
net.Stream.MaxWriteStreams = 1024 --The maximum number of write data items to store
net.Stream.MaxReadStreams = 128 --The maximum number of queued read data items to store
net.Stream.MaxChunks = 3200 --Maximum number of pieces the stream can send to the server. 64 MB
net.Stream.MaxSize = net.Stream.SendSize*net.Stream.MaxChunks

Check warning on line 11 in lua/autorun/netstream.lua

View workflow job for this annotation

GitHub Actions / lua-lint / lint

"Whitespace style"

Style: Please put some whitespace before the operator
net.Stream.MaxTries = 3 --Maximum times the client may retry downloading the whole data

local WriteStreamQueue = {
Expand All @@ -26,8 +26,8 @@
end
self.curidentifier = identifier % net.Stream.MaxWriteStreams + 1

if next(self.queue)==nil then

Check warning on line 29 in lua/autorun/netstream.lua

View workflow job for this annotation

GitHub Actions / lua-lint / lint

"Whitespace style"

Style: Please put some whitespace after ')'
self.activitytimeout = CurTime()+net.Stream.Timeout

Check warning on line 30 in lua/autorun/netstream.lua

View workflow job for this annotation

GitHub Actions / lua-lint / lint

"Whitespace style"

Style: Please put some whitespace after ')'
timer.Create("netstream_queueclean", 5, 0, function() self:Clean() end)
end
self.queue[identifier] = stream
Expand All @@ -42,8 +42,8 @@
--print("Got request", identifier, chunkidx, stream)
if stream then
if stream:Write(ply, chunkidx) then
self.activitytimeout = CurTime()+net.Stream.Timeout

Check warning on line 45 in lua/autorun/netstream.lua

View workflow job for this annotation

GitHub Actions / lua-lint / lint

"Whitespace style"

Style: Please put some whitespace after ')'
stream.timeout = CurTime()+net.Stream.Timeout

Check warning on line 46 in lua/autorun/netstream.lua

View workflow job for this annotation

GitHub Actions / lua-lint / lint

"Whitespace style"

Style: Please put some whitespace after ')'
end
else
-- Tell them the stream doesn't exist
Expand All @@ -57,19 +57,19 @@
Clean = function(self)
local t = CurTime()
for k, stream in pairs(self.queue) do
if (next(stream.clients)~=nil and t >= stream.timeout) or t >= self.activitytimeout then

Check warning on line 60 in lua/autorun/netstream.lua

View workflow job for this annotation

GitHub Actions / lua-lint / lint

"Whitespace style"

Style: Please put some whitespace after ')'
stream:Remove()
self.queue[k] = nil
end
end
if next(self.queue)==nil then

Check warning on line 65 in lua/autorun/netstream.lua

View workflow job for this annotation

GitHub Actions / lua-lint / lint

"Whitespace style"

Style: Please put some whitespace after ')'
timer.Remove("netstream_queueclean")
end
end,
},
__call = function(t)
return setmetatable({
activitytimeout = CurTime()+net.Stream.Timeout,

Check warning on line 72 in lua/autorun/netstream.lua

View workflow job for this annotation

GitHub Actions / lua-lint / lint

"Whitespace style"

Style: Please put some whitespace after ')'
curidentifier = 1,
queue = {}
}, t)
Expand All @@ -87,7 +87,7 @@
ErrorNoHalt("Receiving too many ReadStream requests!")
return
end

for _, v in ipairs(queue) do
if v.identifier == stream.identifier then
ErrorNoHalt("Tried to start a new ReadStream for an already existing stream!")
Expand All @@ -95,7 +95,7 @@
end
end

queue[#queue+1] = stream

Check warning on line 98 in lua/autorun/netstream.lua

View workflow job for this annotation

GitHub Actions / lua-lint / lint

"Whitespace style"

Style: Please put some whitespace before the operator
if #queue == 1 then
stream:Request()
end
Expand Down Expand Up @@ -134,7 +134,7 @@
},
__call = function(t)
return setmetatable({
queues = setmetatable({}, {__index = function(t,k) local r={} t[k]=r return r end})

Check warning on line 137 in lua/autorun/netstream.lua

View workflow job for this annotation

GitHub Actions / lua-lint / lint

"Space after comma"

Style: Please add a space after the comma
}, t)
end
}
Expand Down Expand Up @@ -296,7 +296,6 @@
}
setmetatable(ReadingDataItem, ReadingDataItem)


function net.WriteStream(data, callback, dontcompress)
if not isstring(data) then
error("bad argument #1 to 'WriteStream' (string expected, got " .. type(data) .. ")", 2)
Expand All @@ -310,20 +309,18 @@
data = util.Compress(data) or ""
end

if #data == 0 then
if not data[1] then
net.WriteUInt(0, 32)
return
end

if #data > net.Stream.MaxSize then
ErrorNoHalt("net.WriteStream request is too large! ", #data/1048576, "MiB")
elseif #data > net.Stream.MaxSize then
ErrorNoHalt("net.WriteStream request is too large! ", #data / 1048576, "MiB")
net.WriteUInt(0, 32)
return
end

local stream = net.Stream.WriteStreams:Add(WritingDataItem(data, callback, compressed))
if not stream then return end

--print("WriteStream", #stream.chunks, stream.identifier, compressed)
net.WriteUInt(#stream.chunks, 32)
net.WriteUInt(stream.identifier, 32)
Expand All @@ -344,10 +341,11 @@
error("bad argument #1 to 'ReadStream' (Tried to use a NULL entity!)", 2)
end
end

if not isfunction(callback) then
error("bad argument #2 to 'ReadStream' (function expected, got " .. type(callback) .. ")", 2)
end

local numchunks = net.ReadUInt(32)
if numchunks == nil then
return
Expand Down
41 changes: 24 additions & 17 deletions lua/pac3/core/client/base_drawable.lua
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
local pac = pac

local table_insert = table.insert
local table_remove = table.remove
local render_OverrideAlphaWriteEnable = render.OverrideAlphaWriteEnable
local render_OverrideColorWriteEnable = render.OverrideColorWriteEnable
local render_OverrideBlendFunc = render.OverrideBlendFunc
local ProtectedCall = ProtectedCall
local cam_IgnoreZ = cam.IgnoreZ
local pac = pac
local ipairs = ipairs
local table = table
local TEXFILTER_POINT = TEXFILTER.POINT
local render_PopFilterMag = render.PopFilterMag
local render_PopFilterMin = render.PopFilterMin
Expand Down Expand Up @@ -111,13 +112,13 @@ do -- modifiers

function PART:AddModifier(part)
self:RemoveModifier(part)
table.insert(self.modifiers, part)
table_insert(self.modifiers, part)
end

function PART:RemoveModifier(part)
for i, v in ipairs(self.modifiers) do
if v == part then
table.remove(self.modifiers, i)
for i = 1, #self.modifiers do
if self.modifiers[i] == part then
table_remove(self.modifiers, i)
break
end
end
Expand All @@ -126,9 +127,10 @@ do -- modifiers
function PART:ModifiersPreEvent(event)
if not self.modifiers[1] then return end

for _, part in ipairs(self.modifiers) do
if not part:IsHidden() then
for i = 1, #self.modifiers do
local part = self.modifiers[i]

if not part:IsHidden() then
if not part.pre_draw_events then part.pre_draw_events = {} end
if not part.pre_draw_events[event] then part.pre_draw_events[event] = "Pre" .. event end

Expand All @@ -142,9 +144,10 @@ do -- modifiers
function PART:ModifiersPostEvent(event)
if not self.modifiers[1] then return end

for _, part in ipairs(self.modifiers) do
if not part:IsHidden() then
for i = 1, #self.modifiers do
local part = self.modifiers[i]

if not part:IsHidden() then
if not part.post_draw_events then part.post_draw_events = {} end
if not part.post_draw_events[event] then part.post_draw_events[event] = "Post" .. event end

Expand All @@ -167,15 +170,19 @@ local function call_draw()
_self:OnDraw()
end

local type_opaque = "opaque"
local type_translucent = "translucent"
local type_viewmodel = "viewmodel"
local type_hands = "hands"

function PART:Draw(draw_type)
if not self.OnDraw or not self.Enabled or self:IsHiddenCached() then return end

if
draw_type == "viewmodel" or draw_type == "hands" or
((self.Translucent == true or self.force_translucent == true) and draw_type == "translucent") or
((self.Translucent == false or self.force_translucent == false) and draw_type == "opaque")
if ((self.Translucent == false or self.force_translucent == false) and draw_type == type_opaque)
or ((self.Translucent == true or self.force_translucent == true) and draw_type == type_translucent)
or draw_type == type_viewmodel or draw_type == type_hands
then
if not self.HandleModifiersManually then self:ModifiersPreEvent('OnDraw', draw_type) end
if not self.HandleModifiersManually then self:ModifiersPreEvent("OnDraw", draw_type) end

if self.IgnoreZ then cam_IgnoreZ(true) end

Expand All @@ -199,7 +206,7 @@ function PART:Draw(draw_type)

if self.IgnoreZ then cam_IgnoreZ(false) end

if not self.HandleModifiersManually then self:ModifiersPostEvent('OnDraw', draw_type) end
if not self.HandleModifiersManually then self:ModifiersPostEvent("OnDraw", draw_type) end
end
end

Expand Down
23 changes: 14 additions & 9 deletions lua/pac3/core/client/base_part.lua
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
local string_format = string.format
local tostring = tostring
local pac = pac
local pace = pace
local assert = assert

local debug_traceback = debug.traceback
local string_format = string.format
local math_random = math.random
local table_insert = table.insert
local table_copy = table.Copy
local tostring = tostring
local assert = assert
local xpcall = xpcall
local pac = pac
local pairs = pairs
local ipairs = ipairs
local table = table
local Color = Color
local NULL = NULL
local table_insert = table.insert

local pac_editor_scale = GetConVar("pac_editor_scale")
local pac_popups_preferred_location = GetConVar("pac_popups_preferred_location")
Expand Down Expand Up @@ -485,14 +487,15 @@ do -- scene graph
function PART:CallRecursive(func, a, b, c)
assert(c == nil, "EXTEND ME")
if self[func] then
self[func](self, a,b,c)
self[func](self, a, b, c)
end

local children = self:GetChildrenList()
for i = 1, #children do
local child = children[i]

if child[func] then
child[func](child, a,b,c)
child[func](child, a, b, c)
end
end
end
Expand All @@ -506,6 +509,7 @@ do -- scene graph
local children = self:GetChildrenList()
for i = 1, #children do
local child = children[i]

if child[func] and self.ClassName == class_name then
child[func](child, a,b,c)
end
Expand Down Expand Up @@ -1064,7 +1068,7 @@ do -- serializing

if copy_id then
local pepper, uid_list
tbl, pepper, uid_list = make_copy(table.Copy(tbl), copy_id)
tbl, pepper, uid_list = make_copy(table_copy(tbl), copy_id)
update_uids(uid_list, pepper)
end

Expand Down Expand Up @@ -1246,8 +1250,9 @@ do
end

if self.delayed_variables then
for i = 1, #self.delayed_variables do
local data = self.delayed_variables[i]

for _, data in ipairs(self.delayed_variables) do
self["Set" .. data.key](self, data.val)
end

Expand Down
Loading
Loading