Skip to content

Commit

Permalink
Pass Distance
Browse files Browse the repository at this point in the history
  • Loading branch information
Hellss committed Aug 16, 2022
1 parent 61e0165 commit 76cddb2
Show file tree
Hide file tree
Showing 14 changed files with 66 additions and 22 deletions.
47 changes: 34 additions & 13 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 @@ -865,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 @@ -1363,7 +1364,7 @@ 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
Expand All @@ -1386,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 @@ -1405,22 +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)
if not IsValid(ent) then break end
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 @@ -2644,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 @@ -2690,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
16 changes: 13 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 @@ -247,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 @@ -323,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 @@ -333,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
14 changes: 8 additions & 6 deletions lua/entities/gmod_train_bogey/cl_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -461,11 +461,13 @@ net.Receive("metrostroi_bogey_contact",function()
util.Effect("stunstickimpact", effectdata, true, true)

local light = ents.CreateClientside("gmod_train_dlight")
light:SetPos(effectdata:GetOrigin())
light:SetDColor(Color(100,220,255))
light:SetSize(256)
light:SetBrightness(5)
light:Spawn()
SafeRemoveEntityDelayed(light,0.1)
if IsValid(light) then
light:SetPos(effectdata:GetOrigin())
light:SetDColor(Color(100,220,255))
light:SetSize(256)
light:SetBrightness(5)
light:Spawn()
SafeRemoveEntityDelayed(light,0.1)
end
sound.Play("subway_trains/bogey/spark.mp3",effectdata:GetOrigin(),75,math.random(100,150),volume)
end)
1 change: 1 addition & 0 deletions lua/metrostroi/cl_cpanel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ local function ClientPanel(panel)
panel:NumSlider(Metrostroi.GetPhrase("Panel.Z"),"metrostroi_cabz",-10,10)
panel:NumSlider(Metrostroi.GetPhrase("Panel.RenderDistance"),"metrostroi_renderdistance",960,3072)
panel:NumSlider(Metrostroi.GetPhrase("Panel.RenderSignals"),"metrostroi_signal_distance",6144,16384)
panel:NumSlider(Metrostroi.GetPhrase("Panel.RenderPassengers"),"metrostroi_passengers_distance",40,110)
panel:Button(Metrostroi.GetPhrase("Panel.ReloadClient"),"metrostroi_reload_client",true)

function DRouteNumber:OnChange()
Expand Down
1 change: 1 addition & 0 deletions lua/metrostroi/convars.lua
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ CreateClientConVar("metrostroi_debugger_data_timeout",2,true,false)
CreateClientConVar("metrostroi_disablehud",0,true)
CreateClientConVar("metrostroi_renderdistance",1024,true)
CreateClientConVar("metrostroi_signal_distance",8192,true)
CreateClientConVar("metrostroi_passengers_distance",75,true)
CreateClientConVar("metrostroi_screenshotmode",0,true)
CreateClientConVar("metrostroi_disableseatshadows",0,true)
CreateClientConVar("metrostroi_softdrawmultipier",100,true)
Expand Down
1 change: 1 addition & 0 deletions lua/metrostroi_data/languages/cz_base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Panel.FOV = FOV
Panel.Z = Výška kamery
Panel.RenderDistance = Vykreslovací\nvzdálenost
Panel.RenderSignals = Traced signals #NEW #FIXME
Panel.RenderPassengers = Traced passengers #NEW #FIXME
Panel.ReloadClient = Znovu načíst klienta
Panel.ClientAdvanced = Klient (pokročilý)
Expand Down
1 change: 1 addition & 0 deletions lua/metrostroi_data/languages/de_base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Panel.FOV = Sichtfeld
Panel.Z = Camera height #NEW
Panel.RenderDistance = Render distanz
Panel.RenderSignals = Traced signals #NEW #FIXME
Panel.RenderPassengers = Traced passengers #NEW #FIXME
Panel.ReloadClient = Clientseitig neuladen
Panel.ClientAdvanced = Client (Fortgeschritten)
Expand Down
1 change: 1 addition & 0 deletions lua/metrostroi_data/languages/en_base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Panel.FOV = FOV
Panel.Z = Camera height #NEW
Panel.RenderDistance = Render distance
Panel.RenderSignals = Traced signals #NEW #FIXME
Panel.RenderPassengers = Traced passengers #NEW #FIXME
Panel.ReloadClient = Reload client side
Panel.ClientAdvanced = Client (advanced)
Expand Down
1 change: 1 addition & 0 deletions lua/metrostroi_data/languages/fr_base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Panel.FOV = Champ de vision (FOV)
Panel.Z = Hauteur de caméra
Panel.RenderDistance = Rendu à distance
Panel.RenderSignals = Traced signals #NEW #FIXME
Panel.RenderPassengers = Traced passengers #NEW #FIXME
Panel.ReloadClient = Redémarrer le client
Panel.ClientAdvanced = Client (avancé)
Expand Down
1 change: 1 addition & 0 deletions lua/metrostroi_data/languages/hu_base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Panel.FOV = FOV
Panel.Z = Kamera magassága
Panel.RenderDistance = Renderelési távolság
Panel.RenderSignals = Traced signals #NEW #FIXME
Panel.RenderPassengers = Traced passengers #NEW #FIXME
Panel.ReloadClient = Kliens oldal újraindítása
Panel.ClientAdvanced = Kliens (haladó)
Expand Down
1 change: 1 addition & 0 deletions lua/metrostroi_data/languages/it_base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ Panel.FOV = FOV
Panel.Z = Altezza della videocamera
Panel.RenderDistance = Distanza di rendering
Panel.RenderSignals = Traced signals #NEW #FIXME
Panel.RenderPassengers = Traced passengers #NEW #FIXME
Panel.ReloadClient = Ricarica lato utente
Panel.ClientAdvanced = Utente (Avanzato)
Expand Down
1 change: 1 addition & 0 deletions lua/metrostroi_data/languages/kr_base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Panel.FOV = 시야각(FOV)
Panel.Z = 시점 높이
Panel.RenderDistance = 렌더링 거리
Panel.RenderSignals = Traced signals #NEW #FIXME
Panel.RenderPassengers = Traced passengers #NEW #FIXME
Panel.ReloadClient = 사용자 시스템 다시 불러오기
Panel.ClientAdvanced = 사용자 (고급설정)
Expand Down
1 change: 1 addition & 0 deletions lua/metrostroi_data/languages/pl_base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ Panel.FOV = FOV (pole widzenia)
Panel.Z = Camera height #NEW
Panel.RenderDistance = Odległość rysowania
Panel.RenderSignals = Traced signals #NEW #FIXME
Panel.RenderPassengers = Traced passengers #NEW #FIXME
Panel.ReloadClient = Przeładuj zasoby (klient)
Panel.ClientAdvanced = Klient (zaawansowane)
Expand Down
1 change: 1 addition & 0 deletions lua/metrostroi_data/languages/ru_base.lua
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ Panel.FOV = Поле зрения
Panel.Z = Высота камеры
Panel.RenderDistance = Дальность прорисовки
Panel.RenderSignals = Прорисовка светофоров
Panel.RenderPassengers = Прорисовка пассажиров
Panel.ReloadClient = Перезагрузить клиентскую часть
Panel.ClientAdvanced = Клиент (дополнительно)
Expand Down

0 comments on commit 76cddb2

Please sign in to comment.