Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
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
77 changes: 77 additions & 0 deletions lua/pac3/core/client/base_part.lua
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,83 @@ do -- scene graph
end
end

do
local function filter_list(source, keep)
local out = {}

for i = 1, #source do
local part = source[i]

if keep(part) then
out[#out + 1] = part
end
end

return out
end

local function can_draw(part)
if not part.Draw then return false end

if not part.OnDraw then
local drawable = pac.GetTemplate("base_drawable")
if drawable and part.Draw == drawable.PART.Draw then return false end
end

return true
end

local function can_build_bones(part)
return part.BuildBonePositions ~= PART.BuildBonePositions or part.OnBuildBonePositions ~= PART.OnBuildBonePositions
end

function PART:GetDrawableChildrenList()
local source = self:GetChildrenList()

if self.drawable_children_source ~= source then
self.drawable_children_source = source
self.drawable_children_list = filter_list(source, can_draw)
end

return self.drawable_children_list
end

function PART:GetBoneBuilderChildrenList()
local source = self:GetChildrenList()

if self.bone_builder_children_source ~= source then
self.bone_builder_children_source = source
self.bone_builder_children_list = filter_list(source, can_build_bones)
end

return self.bone_builder_children_list
end

function PART:CallRecursiveDraw(draw_type)
if self.Draw then
self:Draw(draw_type)
end

local list = self:GetDrawableChildrenList()

for i = 1, #list do
list[i]:Draw(draw_type)
end
end

function PART:CallRecursiveBuildBonePositions()
if self.BuildBonePositions then
self:BuildBonePositions()
end

local list = self:GetBoneBuilderChildrenList()

for i = 1, #list do
list[i]:BuildBonePositions()
end
end
end

function PART:CallRecursiveOnClassName(class_name, func, a,b,c)
assert(c == nil, "EXTEND ME")
if self[func] and self.ClassName == class_name then
Expand Down
6 changes: 4 additions & 2 deletions lua/pac3/core/client/part_pool.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
local next = next

local entMeta = FindMetaTable('Entity')
local plyMeta = FindMetaTable('Player')

Check warning on line 16 in lua/pac3/core/client/part_pool.lua

View workflow job for this annotation

GitHub Actions / lint

"Syntax inconsistency"

Inconsistent use of 'double quoted strings' and 'single quoted strings'
local IsValid = entMeta.IsValid
local Alive = plyMeta.Alive

Expand Down Expand Up @@ -66,16 +66,16 @@

if parts == nil or next(parts) == nil then
pac.UnhookEntityRender(ent)
goto CEASE_FUNCTION

Check warning on line 69 in lua/pac3/core/client/part_pool.lua

View workflow job for this annotation

GitHub Actions / lint

"Goto"

Don't use labels and gotos unless you're jumping out of multiple loops.
end

if type == "update_legacy_bones" then

Check warning on line 72 in lua/pac3/core/client/part_pool.lua

View workflow job for this annotation

GitHub Actions / lint

"Syntax inconsistency"

Inconsistent use of 'double quoted strings' and 'single quoted strings'
pac.ResetBones(ent)

for key, part in next, parts do
if part:IsValid() then
if not part:HasParent() then
part:CallRecursive("BuildBonePositions")
part:CallRecursiveBuildBonePositions()
end
else
parts[key] = nil
Expand All @@ -95,14 +95,14 @@
for key, part in next, parts do
if part:IsValid() then
if not part:HasParent() then
if
part.OwnerName == "viewmodel" and type == "viewmodel" or
part.OwnerName == "hands" and type == "hands" or
part.OwnerName ~= "viewmodel" and part.OwnerName ~= "hands" and type ~= "viewmodel" and type ~= "hands"
then
if not part:IsDrawHidden() then
part:CallRecursive("Draw", type)
part:CallRecursiveDraw(type)
end

Check warning on line 105 in lua/pac3/core/client/part_pool.lua

View workflow job for this annotation

GitHub Actions / lint

"Double if-statement"

Double if statement. Please combine the condition of this if statement with that of the outer if statement using `and`.
end

Check warning on line 106 in lua/pac3/core/client/part_pool.lua

View workflow job for this annotation

GitHub Actions / lint

"Double if-statement"

Double if statement. Please combine the condition of this if statement with that of the outer if statement using `and`.
end
else
Expand Down Expand Up @@ -289,7 +289,7 @@

ent:SetParent(NULL)
ent:SetNoDraw(true)
ent:PhysicsInitBox(Vector(1,1,1) * -5, Vector(1,1,1) * 5)

Check warning on line 292 in lua/pac3/core/client/part_pool.lua

View workflow job for this annotation

GitHub Actions / lint

"Space after comma"

Style: Please add a space after the comma

Check warning on line 292 in lua/pac3/core/client/part_pool.lua

View workflow job for this annotation

GitHub Actions / lint

"Space after comma"

Style: Please add a space after the comma

Check warning on line 292 in lua/pac3/core/client/part_pool.lua

View workflow job for this annotation

GitHub Actions / lint

"Space after comma"

Style: Please add a space after the comma

Check warning on line 292 in lua/pac3/core/client/part_pool.lua

View workflow job for this annotation

GitHub Actions / lint

"Space after comma"

Style: Please add a space after the comma
ent:SetCollisionGroup(COLLISION_GROUP_DEBRIS)

local phys = ent:GetPhysicsObject()
Expand Down Expand Up @@ -343,7 +343,7 @@

lamp:SetTexture( "effects/flashlight001" )
lamp:SetFarZ( 5000 )
lamp:SetColor(Color(0,0,0,255))

Check warning on line 346 in lua/pac3/core/client/part_pool.lua

View workflow job for this annotation

GitHub Actions / lint

"Space after comma"

Style: Please add a space after the comma

lamp:SetPos( pac.LocalPlayer:EyePos() - pac.LocalPlayer:GetAimVector()*400 )
lamp:SetAngles( pac.LocalPlayer:EyeAngles() )
Expand Down Expand Up @@ -459,6 +459,8 @@
part[k] = v
end
end

part:InvalidateChildrenList()
end
end
end
Expand Down
Loading