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

#545 #546

Open
wants to merge 2 commits into
base: dev
Choose a base branch
from
Open

#545 #546

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
15 changes: 9 additions & 6 deletions lua/entities/gmod_mus_clock_analog/cl_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function ENT:Think()
--self.Arrows[i] = ents.CreateClientProp("models/metrostroi/81-717/reverser.mdl")
--self.Arrows[i]:SetModel( model )
self.Arrows[i] = ClientsideModel(model,RENDERGROUP_OPAQUE)
if not IsValid(self.Arrows[i]) then break end
self.Arrows[i]:SetPos(self:GetPos())
self.Arrows[i]:SetAngles(self:GetAngles())
self.Arrows[i]:SetParent(self)
Expand All @@ -23,13 +24,15 @@ function ENT:Think()
self:EmitSound("mus/clock_click"..math.random(1,8)..".wav",65,math.random(95,105),0.5)
self.OldSec = d.sec
self.SecPull = RealTime()+0.05
self.Arrows[1]:SetPoseParameter("position",(0.5+d.hour/24+d.min/1440)%1)
self.Arrows[2]:SetPoseParameter("position",d.min/60+d.sec/3600)
if IsValid(self.Arrows[1]) then self.Arrows[1]:SetPoseParameter("position",(0.5+d.hour/24+d.min/1440)%1) end
if IsValid(self.Arrows[2]) then self.Arrows[2]:SetPoseParameter("position",d.min/60+d.sec/3600) end
end
if RealTime()-self.SecPull > 0 or d.sec < 30 then
self.Arrows[3]:SetPoseParameter("position",d.sec/60)
else
self.Arrows[3]:SetPoseParameter("position",d.sec/60 +(d.sec-15)/60*0.002)
if IsValid(self.Arrows[3]) then
if RealTime()-self.SecPull > 0 or d.sec < 30 then
self.Arrows[3]:SetPoseParameter("position",d.sec/60)
else
self.Arrows[3]:SetPoseParameter("position",d.sec/60 +(d.sec-15)/60*0.002)
end
end

--[[
Expand Down
49 changes: 37 additions & 12 deletions lua/entities/gmod_subway_base/cl_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,7 @@ end

local C_DisableHUD = GetConVar("metrostroi_disablehud")
local C_RenderDistance = GetConVar("metrostroi_renderdistance")
local C_PassRenderDistance = GetConVar("metrostroi_passengers_distance")
local C_SoftDraw = GetConVar("metrostroi_softdrawmultipier")
local C_ScreenshotMode = GetConVar("metrostroi_screenshotmode")
local C_DrawDebug = GetConVar("metrostroi_drawdebug")
Expand Down Expand Up @@ -392,6 +393,7 @@ function ENT:SpawnCSEnt(k,override)
local model = v.model
if v.modelcallback then model = v.modelcallback(self) or v.model end
local cent = ClientsideModel(model,RENDERGROUP_OPAQUE)
if not IsValid(cent) then return false end
cent.GetBodyColor = function()
if not IsValid(self) then return Vector(1) end
return self:GetBodyColor()
Expand Down Expand Up @@ -864,7 +866,7 @@ function ENT:OnRemove(nfinal)
end
end
for _,v in pairs(self.PassengerEnts or {}) do
SafeRemoveEntity(v)
SafeRemoveEntity(v.ent)
end
for _,v in pairs(self.PassengerEntsStucked or {}) do
SafeRemoveEntity(v)
Expand Down Expand Up @@ -1346,6 +1348,7 @@ function ENT:Think()
for i,v in ipairs(self.LeftDoorPositions) do
if self:GetPackedBool("DoorLS"..i) and not IsValid(stucked[i]) then
local ent = ClientsideModel(table.Random(self.PassengerModels),RENDERGROUP_OPAQUE)
if not IsValid(ent) then break end
ent:SetPos(self:LocalToWorld(Vector(v.x,v.y,self:GetStandingArea().z)))
ent:SetAngles(self:LocalToWorldAngles(Angle(0,v.y < 0 and -90 or 90,0)))
ent:SetSkin(math.floor(ent:SkinCount()*math.random()))
Expand All @@ -1361,13 +1364,14 @@ function ENT:Think()
else
self:PlayOnceFromPos("PassStuckL"..i,"subway_trains/common/door/pass_stuck.mp3",5,0.9+math.random()*0.2,150,400,v)
end
elseif not self:GetPackedBool("DoorLS"..i) and IsValid(stucked[i]) then
elseif IsValid(stucked[i]) and (not self:GetPackedBool("DoorLS"..i) or stucked[i]:IsDormant()) then
SafeRemoveEntity(stucked[i])
end
end
for i,v in ipairs(self.RightDoorPositions) do
if self:GetPackedBool("DoorRS"..i) and not IsValid(stucked[-i]) then
local ent = ClientsideModel(table.Random(self.PassengerModels),RENDERGROUP_OPAQUE)
if not IsValid(ent) then break end
ent:SetPos(self:LocalToWorld(Vector(v.x,v.y,self:GetStandingArea().z)))
ent:SetAngles(self:LocalToWorldAngles(Angle(0,v.y < 0 and -90 or 90,0)))
ent:SetSkin(math.floor(ent:SkinCount()*math.random()))
Expand All @@ -1383,17 +1387,17 @@ function ENT:Think()
else
self:PlayOnceFromPos("PassStuckR"..i,"subway_trains/common/door/pass_stuck.mp3",5,0.9+math.random()*0.2,150,400,v)
end
elseif not self:GetPackedBool("DoorRS"..i) and IsValid(stucked[-i]) then
elseif IsValid(stucked[-i]) and (not self:GetPackedBool("DoorRS"..i) or stucked[-i]:IsDormant()) then
SafeRemoveEntity(stucked[-i])
end
end
if #self.PassengerEnts ~= self:GetNW2Float("PassengerCount") then
-- Passengers go out
while #self.PassengerEnts > self:GetNW2Float("PassengerCount") do
local ent = self.PassengerEnts[#self.PassengerEnts]
local tbl = self.PassengerEnts[#self.PassengerEnts]
table.remove(self.PassengerPositions,#self.PassengerPositions)
table.remove(self.PassengerEnts,#self.PassengerEnts)
ent:Remove()
SafeRemoveEntity(tbl.ent)
end
-- Passengers go in
while #self.PassengerEnts < self:GetNW2Float("PassengerCount") do
Expand All @@ -1402,21 +1406,40 @@ function ENT:Think()

--local ent = ents.CreateClientProp("models/metrostroi/81-717/reverser.mdl")
--ent:SetModel(table.Random(self.PassengerModels))
local ent = ClientsideModel(table.Random(self.PassengerModels),RENDERGROUP_OPAQUE)
ent:SetPos(self:LocalToWorld(pos))
ent:SetAngles(Angle(0,math.random(0,360),0))
local tbl = {}
tbl.mdl = table.Random(self.PassengerModels)
tbl.pos = pos
tbl.ang = Angle(0,math.random(0,360),0)
--[[
hook.Add("MetrostroiBigLag",ent,function(ent)
ent:SetPos(self:LocalToWorld(pos))
ent:SetAngles(Angle(0,math.random(0,360),0))
--if ent.Spawned then hook.Remove("MetrostroiBigLag",ent) end
--ent.Spawned = true
end)]]
ent:SetSkin(math.floor(ent:SkinCount()*math.random()))
ent:SetModelScale(0.98 + (-0.02+0.04*math.random()),0)
ent:SetParent(self)
tbl.scale = 0.98 + (-0.02+0.04*math.random())
table.insert(self.PassengerPositions,pos)
table.insert(self.PassengerEnts,ent)
table.insert(self.PassengerEnts,tbl)
end
end
if (CurTime() - (self.ModelCheckTimer or 0) > 1.0) then
self.ModelCheckTimer = CurTime()
local plyPos = LocalPlayer():GetPos()
local dist = C_PassRenderDistance:GetInt()/0.01905
for _,tbl in pairs(self.PassengerEnts) do
if not IsValid(tbl.ent) and plyPos:Distance(tbl.pos) <= dist then
local ent = ClientsideModel(tbl.mdl, RENDERGROUP_OPAQUE)
if not IsValid(ent) then continue end
ent:SetPos(self:LocalToWorld(tbl.pos))
ent:SetAngles(self:LocalToWorldAngles(tbl.ang))
if not tbl.skin then tbl.skin = math.floor(ent:SkinCount()*math.random()) end
ent:SetSkin(tbl.skin)
ent:SetModelScale(tbl.scale,0)
ent:SetParent(self)
tbl.ent = ent
elseif IsValid(tbl.ent) and (plyPos:Distance(tbl.pos) > dist or tbl.ent:IsDormant()) then
SafeRemoveEntity(tbl.ent)
end
end
end
end
Expand Down Expand Up @@ -2640,6 +2663,7 @@ function ENT:SetLightPower(index,power,brightness)
-- Create light
if lightData[1] == "light" or lightData[1] == "glow" then
local light = ents.CreateClientside("gmod_train_sprite")
if not IsValid(light) then return end
light:SetPos(self:LocalToWorld(lightData[2]))
--light:SetLocalAngles(lightData[3])

Expand Down Expand Up @@ -2686,6 +2710,7 @@ function ENT:SetLightPower(index,power,brightness)
self.GlowingLights[index] = light
elseif lightData[1] == "dynamiclight" then
local light = ents.CreateClientside("gmod_train_dlight")
if not IsValid(light) then return end
light:SetParent(self)

-- Set position
Expand Down
1 change: 1 addition & 0 deletions lua/entities/gmod_track_clock_interval/cl_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ function ENT:Think()
-- ent:SetPos(self:LocalToWorld(v[1]))
--end)
self.Digits[k] = ClientsideModel(model, RENDERGROUP_OPAQUE)
if not IsValid(self.Digits[k]) then break end

--if ent.Spawned then hook.Remove("MetrostroiBigLag",ent) end
--ent.Spawned = true
Expand Down
1 change: 1 addition & 0 deletions lua/entities/gmod_track_clock_small/cl_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ function ENT:Think()
-- --ent.Spawned = true
--end)
self.Digits[k] = ClientsideModel(model,RENDERGROUP_OPAQUE)
if not IsValid(self.Digits[k]) then break end
self.Digits[k]:SetPos(self:LocalToWorld(v[1]))
self.Digits[k]:SetAngles(self:GetAngles())
self.Digits[k]:SetSkin(10)
Expand Down
1 change: 1 addition & 0 deletions lua/entities/gmod_track_clock_time/cl_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ function ENT:Think()
-- --ent.Spawned = true
--end)
self.Digits[k] = ClientsideModel(model,RENDERGROUP_OPAQUE)
if not IsValid(self.Digits[k]) then break end
self.Digits[k]:SetPos(self:LocalToWorld(v[1]))
self.Digits[k]:SetAngles(self:GetAngles())
self.Digits[k]:SetSkin(10)
Expand Down
1 change: 1 addition & 0 deletions lua/entities/gmod_track_horlift_signal/cl_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ function ENT:Think()
-- --ent.Spawned = true
--end)
self.Models[k] = ClientsideModel(self.ModelNames[v[2]],RENDERGROUP_OPAQUE)
if not IsValid(self.Models[k]) then break end
self.Models[k]:SetPos(self:LocalToWorld(v[1]))
self.Models[k]:SetAngles(self:LocalToWorldAngles(Angle(v[2]==5 and 90 or 0,0,0)))
if k < 3 then
Expand Down
1 change: 1 addition & 0 deletions lua/entities/gmod_track_mus_elektronika7/cl_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ function ENT:Think()
-- --ent.Spawned = true
--end)
self.Digits[k] = ClientsideModel("models/mus/ussr_clock_model/num_"..(k == 1 and "no" or "").."zero.mdl",RENDERGROUP_OPAQUE)
if not IsValid(self.Digits[k]) then break end
self.Digits[k]:SetPos(self:LocalToWorld(v))
self.Digits[k]:SetAngles(self:GetAngles())
self.Digits[k]:SetSkin(10)
Expand Down
18 changes: 15 additions & 3 deletions lua/entities/gmod_track_platform/cl_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ function ENT:OnRemove()
for k,v in pairs(self.ClientModels) do SafeRemoveEntity(v) end
self.ClientModels = {}
self.ClientsideModels = {}
for k,v in pairs(self.CleanupModels) do SafeRemoveEntity(v.ent) end
self.CleanupModels = {}
self.Pool = nil
self.PassengersLeft = nil
Expand Down Expand Up @@ -149,6 +150,7 @@ function ENT:PopulatePlatform(platformStart,platformEnd,stationCenter)
end
end

local C_PassRenderDistance = GetConVar("metrostroi_passengers_distance")

--------------------------------------------------------------------------------
-- Think loop that manages clientside models
Expand All @@ -164,7 +166,7 @@ function ENT:Think()
self.PrevTime = self.PrevTime or CurTime()
self.DeltaTime = (CurTime() - self.PrevTime)
self.PrevTime = CurTime()
if self:IsDormant() then
if self:IsDormant() or Metrostroi and Metrostroi.ReloadClientside then
if self.Pool then
self:OnRemove()
end
Expand Down Expand Up @@ -214,10 +216,12 @@ function ENT:Think()
self:PopulatePlatform(platformStart,platformEnd,stationCenter)
end

local plyPos = LocalPlayer():GetPos()
local modelCount = 0
-- Check if set of models changed
if (CurTime() - (self.ModelCheckTimer or 0) > 1.0) and poolReady then
self.ModelCheckTimer = CurTime()
local dist = C_PassRenderDistance:GetInt()/0.01905

local WindowStart = self:GetNW2Int("WindowStart")
local WindowEnd = self:GetNW2Int("WindowEnd")
Expand All @@ -227,7 +231,7 @@ function ENT:Think()
if WindowStart > WindowEnd then in_bounds = (i >= WindowStart) or (i <= WindowEnd) end
if in_bounds then
-- Model in window
if not self.ClientModels[i] then
if not self.ClientModels[i] and plyPos:Distance(self.Pool[i].pos) <= dist then
--self.ClientModels[i] = ents.CreateClientProp("models/metrostroi/81-717/reverser.mdl")
--self.ClientModels[i]:SetModel(self.Pool[i].model)
--hook.Add("MetrostroiBigLag",self.ClientModels[i],function(ent)
Expand All @@ -238,6 +242,7 @@ function ENT:Think()
-- --ent.Spawned = true
--end)
self.ClientModels[i] = ClientsideModel(self.Pool[i].model,RENDERGROUP_OPAQUE)
if not IsValid(self.ClientModels[i]) then continue end
self.ClientModels[i]:SetPos(self.Pool[i].pos)
self.ClientModels[i]:SetAngles(self.Pool[i].ang)
self.ClientModels[i]:SetSkin(math.floor(self.ClientModels[i]:SkinCount()*self.Pool[i].skin))
Expand All @@ -246,6 +251,8 @@ function ENT:Think()
self.ClientModels[i]:DrawShadow(false)
modelCount = modelCount + 1
if modelCount > 15 then poolReady = false self.ModelCheckTimer = self.ModelCheckTimer - 0.9 break end
elseif IsValid(self.ClientModels[i]) and (plyPos:Distance(self.Pool[i].pos) > dist or self.ClientModels[i]:IsDormant()) then
SafeRemoveEntity(self.ClientModels[i])
end
else
-- Model found that is not in window
Expand Down Expand Up @@ -292,6 +299,7 @@ function ENT:Think()
-- --ent.Spawned = true
--end)
local ent= ClientsideModel(self.Pool[i].model,RENDERGROUP_OPAQUE)
if not IsValid(ent) then break end
ent:SetPos(pos)
ent:SetSkin(math.floor(ent:SkinCount()*self.Pool[i].skin))
ent:SetModelScale(self.Pool[i].scale,0)
Expand Down Expand Up @@ -321,6 +329,10 @@ function ENT:Think()
if not IsValid(v.ent) then
self.CleanupModels[k] = nil
continue
elseif v.ent:IsDormant() then
v.ent:Remove()
self.CleanupModels[k] = nil
continue
end
-- Get pos and target in XY plane
local pos = v.ent:GetPos()
Expand All @@ -331,7 +343,7 @@ function ENT:Think()
local distance = pos:DistToSqr(target)
local count = self:GetNW2Int("TrainDoorCount",0)
-- Delete if reached the target point
if distance < 2*256--[[threshold]] or math.abs(LocalPlayer():GetPos().z - v.ent:GetPos().z) > 256 or count == 0 then
if distance < 2*256--[[threshold]] or math.abs(plyPos.z - v.ent:GetPos().z) > 256 or count == 0 then
v.ent:Remove()
self.CleanupModels[k] = nil
continue
Expand Down
13 changes: 8 additions & 5 deletions lua/entities/gmod_track_pui/cl_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ function ENT:Think()
-- --ent.Spawned = true
--end)
self.Digits[k] = ClientsideModel("models/metrostroi/mus_clock/pui_ind_"..v[2]..".mdl",RENDERGROUP_OPAQUE)
if not IsValid(self.Digits[k]) then continue end
self.Digits[k]:SetPos(self:LocalToWorld(v[1]))
self.Digits[k]:SetAngles(self:GetAngles())
self.Digits[k]:SetSkin(1)
Expand All @@ -80,11 +81,13 @@ function ENT:Think()
-- --ent.Spawned = true
--end)
self.Digits[0] = ClientsideModel("models/metrostroi/mus_clock/pui_lamp.mdl",RENDERGROUP_OPAQUE)
self.Digits[0]:SetPos(self:GetAttachment(self:LookupAttachment("lamp")).Pos)
self.Digits[0]:SetAngles(self:GetAngles())
self.Digits[0]:SetParent(self)
self.Digits[0]:SetRenderMode( RENDERMODE_TRANSALPHA )
self.Digits[0]:SetColor(Color(255,255,255,lamp*255))
if IsValid(self.Digits[0]) then
self.Digits[0]:SetPos(self:GetAttachment(self:LookupAttachment("lamp")).Pos)
self.Digits[0]:SetAngles(self:GetAngles())
self.Digits[0]:SetParent(self)
self.Digits[0]:SetRenderMode( RENDERMODE_TRANSALPHA )
self.Digits[0]:SetColor(Color(255,255,255,lamp*255))
end
elseif IsValid(self.Digits[0]) and lamp > 0 then
self.Digits[0]:SetColor(Color(255,255,255,lamp*255))
elseif IsValid(self.Digits[0]) and lamp == 0 then
Expand Down
Loading