1
0
mirror of https://github.com/metrostroi-repo/MetrostroiAddon.git synced 2026-05-02 00:42:29 +00:00

Дебаг сигнализации.

Почистил мусор
Перенес всю отрисовку дебаг информации в ENT:Draw()
This commit is contained in:
kosmik641
2025-12-06 02:51:30 +03:00
parent e393387043
commit aca7d7aa0a
7 changed files with 245 additions and 243 deletions

View File

@@ -576,11 +576,22 @@ function ENT:Think()
return true
end
function ENT:Draw()
local C_SignalDebug = GetConVar("metrostroi_drawsignaldebug")
function ENT:Draw(flags)
-- Draw model
self:DrawModel()
self:DrawModel(flags)
if not C_SignalDebug:GetBool() then return end
if LocalPlayer():GetPos():DistToSqr(self:GetPos()) > 200000 then return end
if EyeVector():Dot(self:LocalToWorldAngles(Angle(0,90,90)):Forward()) > 0.1 then return end
local pos = self:LocalToWorld(Vector(48,0,150))
local ang = self:LocalToWorldAngles(Angle(0,180,90))
cam.Start3D2D(pos, ang, 0.25)
self:DrawDebug()
cam.End3D2D()
end
local debug = GetConVar("metrostroi_drawsignaldebug")
local ars = {
{"275 Hz", "0 KM/H"},
@@ -594,7 +605,6 @@ local ars = {
{"75 Hz", "80 KM/H"},
}
local cols = {
R = Color(200,0,0),
Y = Color(200,200,0),
@@ -602,127 +612,114 @@ local cols = {
W = Color(200,200,200),
B = Color(0,0,200),
}
local function enableDebug()
if debug:GetBool() then
hook.Add("PreDrawEffects","MetrostroiSignalDebug",function()
for _,sig in pairs(ents.FindByClass("gmod_track_signal")) do
if IsValid(sig) and LocalPlayer():GetPos():DistToSqr(sig:GetPos()) < 147456 then
local pos = sig:LocalToWorld(Vector(48,0,150))
local ang = sig:LocalToWorldAngles(Angle(0,180,90))
cam.Start3D2D(pos, ang, 0.25)
if sig:GetNW2Bool("Debug",false) then
surface.SetDrawColor(sig.ARSOnly and 255 or 125, 125, 0, 255)
surface.DrawRect(0, -60, 364, 210)
if not sig.ARSOnly then
surface.DrawRect(0, 155, 240, 170)
surface.DrawRect(0, 330, 240, 190)
surface.SetDrawColor(0,0,0, 255)
surface.DrawRect(245, 155, 119, 365)
else
surface.DrawRect(0, 155, 364, 150)
surface.DrawRect(0, 310, 364, 190)
end
function ENT:DrawDebug()
surface.SetDrawColor(self.ARSOnly and 255 or 125, 125, 0, 255)
if not self:GetNW2Bool("Debug",false) then
surface.DrawRect(0, 0, 364, 25)
draw.DrawText("Debug disabled...","Trebuchet24",5,0,Color(0, 0, 0, 255))
return
end
if sig.Name then
draw.DrawText(Format("Joint main info (%d)",sig:EntIndex()),"Trebuchet24",5,-60,Color(200,0,0,255))
draw.DrawText("Signal name: "..sig.Name,"Trebuchet24", 15, -40,Color(0, 0, 0, 255))
draw.DrawText("TrackID: "..sig:GetNW2Int("PosID",0),"Trebuchet24", 25, -20,Color(0, 0, 0, 255))
draw.DrawText(Format("PosX: %.02f",sig:GetNW2Float("Pos",0)),"Trebuchet24", 135, -20,Color(0, 0, 0, 255))
draw.DrawText(Format("NextSignalName: %s",sig:GetNW2String("NextSignalName","N/A")),"Trebuchet24", 15, 0,Color(0, 0, 0, 255))
draw.DrawText(Format("TrackID: %s",sig:GetNW2Int("NextPosID",0)),"Trebuchet24", 25, 20,Color(0, 0, 0, 255))
draw.DrawText(Format("PosX: %.02f",sig:GetNW2Float("NextPos",0)),"Trebuchet24", 135, 20,Color(0, 0, 0, 255))
draw.DrawText(Format("Dist: %.02f",sig:GetNW2Float("DistanceToNext",0)),"Trebuchet24", 15, 40,Color(0, 0, 0, 255))
draw.DrawText(Format("PrevSignalName: %s",sig:GetNW2String("PrevSignalName","N/A")),"Trebuchet24", 15, 60,Color(0, 0, 0, 255))
draw.DrawText(Format("TrackID: %s",sig:GetNW2Int("PrevPosID",0)),"Trebuchet24", 25, 80,Color(0, 0, 0, 255))
draw.DrawText(Format("PosX: %.02f",sig:GetNW2Float("PrevPos",0)),"Trebuchet24", 135, 80,Color(0, 0, 0, 255))
draw.DrawText(Format("DistPrev: %.02f",sig:GetNW2Float("DistanceToPrev",0)),"Trebuchet24", 15, 100,Color(0, 0, 0, 255))
draw.DrawText(Format("Current route: %d",sig:GetNW2Int("CurrentRoute",-1)),"Trebuchet24", 15, 120,Color(0, 0, 0, 255))
if not self.Name then
surface.DrawRect(0, 0, 364, 25)
draw.DrawText("No data...","Trebuchet24",5,0,Color(0, 0, 0, 255))
return
end
draw.DrawText("AB info","Trebuchet24",5,160,Color(200,0,0,255))
draw.DrawText(Format("Occupied: %s",sig:GetNW2Bool("Occupied",false) and "Y" or "N"),"Trebuchet24",5,180,Color(0, 0, 0, 255))
draw.DrawText(Format("Linked to controller: %s",sig:GetNW2Bool("LinkedToController",false) and "Y" or "N"),"Trebuchet24",5,200,Color(0, 0, 0, 255))
draw.DrawText(Format("Num: %d",sig:GetNW2Int("ControllersNumber",0)),"Trebuchet24",10,220,Color(0, 0, 0, 255))
draw.DrawText(Format("Controller logic: %s",sig:GetNW2Bool("BlockedByController",false) and "Y" or "N"),"Trebuchet24",5,240,Color(0, 0, 0, 255))
draw.DrawText(Format("Autostop: %s",not sig.ARSOnly and sig.AutostopPresent and (sig:GetNW2Bool("Autostop") and "Up" or "Down") or "No present"),"Trebuchet24",5,260,Color(0, 0, 0, 255))
draw.DrawText(Format("2/6: %s",sig:GetNW2Bool("2/6",false) and "Y" or "N"),"Trebuchet24",5,280,Color(0, 0, 0, 255))
draw.DrawText(Format("FreeBS: %d",sig:GetNW2Int("FreeBS")),"Trebuchet24",5,300,Color(0, 0, 0, 255))
surface.DrawRect(0, -60, 364, 210)
draw.DrawText("ARS info","Trebuchet24",5,335,Color(200,0,0,255))
local num = 0
for i,tbl in pairs(ars) do
if not tbl then continue end
if sig:GetNW2Bool("CurrentARS"..(i-1),false) then
draw.DrawText(Format("(% s)",tbl[1]),"Trebuchet24",5,355+num*20,Color(0,100,0,255))
draw.DrawText(Format("%s",tbl[2]),"Trebuchet24",105,355+num*20,Color(0,100,0,255))
else
draw.DrawText(Format("(% s)",tbl[1]),"Trebuchet24",5,355+num*20,Color(0, 0, 0, 255))
draw.DrawText(Format("%s",tbl[2]),"Trebuchet24",105,355+num*20,Color(0, 0, 0, 255))
end
num = num+1
end
if sig:GetNW2Bool("CurrentARS325",false) or sig:GetNW2Bool("CurrentARS325_2",false) then
draw.DrawText("(325 Hz)","Trebuchet24",5,355+num*20,Color(0,100,0,255))
draw.DrawText(Format("LN:%s Apr0:%s",sig:GetNW2Bool("CurrentARS325",false) and "Y" or "N",sig:GetNW2Bool("CurrentARS325_2",false) and "Y" or "N"),"Trebuchet24",105,355+num*20,Color(0,100,0,255))
else
draw.DrawText("(325 Hz)","Trebuchet24",5,355+num*20,Color(0, 0, 0, 255))
draw.DrawText(Format("LN:%s Apr0:%s",sig:GetNW2Bool("CurrentARS325",false) and "Y" or "N",sig:GetNW2Bool("CurrentARS325_2",false) and "Y" or "N"),"Trebuchet24",105,355+num*20,Color(0, 0, 0, 255))
end
if not sig.ARSOnly then
draw.DrawText("Signal info","Trebuchet24",250,160,Color(200,0,0,255))
local ID = 0
local ID2 = 0
local first = true
for _,v in ipairs(sig.LensesTBL) do
local data
if not sig.TrafficLightModels[sig.LightType][v] then
data = sig.TrafficLightModels[sig.LightType][#v-1]
else
data = sig.TrafficLightModels[sig.LightType][v]
end
if not data then continue end
--sig.NamesOffset = sig.NamesOffset + Vector(0,0,data[1])
if v ~= "M" then
for i = 1,#v do
ID2 = ID2 + 1
local n = tonumber(sig.Sig[ID2])
local State = n == 1 and "X" or (n == 2 and (RealTime() % 1.2 > 0.4)) and "B" or false
draw.DrawText(Format(v[i],sig:EntIndex()),"Trebuchet24",250,160 + ID*20 + ID2*20,cols[v[i]])
if State then
draw.DrawText(State,"Trebuchet24",280,160 + ID*20 + ID2*20,cols[v[i]])
end
end
else
ID2 = ID2 + 1
draw.DrawText("M","Trebuchet24",250,160 + ID*20 + ID2*20,Color(200,200,200))
draw.DrawText(sig.Num or "none","Trebuchet24",280,160 + ID*20 + ID2*20,Color(200,200,200))
--if Metrostroi.RoutePointer[sig.Num[1]] then sig.Models[1][sig.RouteNumber]:SetSkin(Metrostroi.RoutePointer[sig.Num[1]]) end
end
ID = ID + 1
end
end
else
draw.DrawText("No data...","Trebuchet24",5,0,Color(0, 0, 0, 255))
end
else
surface.SetDrawColor(sig.ARSOnly and 255 or 125, 125, 0, 255)
surface.DrawRect(0, 0, 364, 25)
draw.DrawText("Debug disabled...","Trebuchet24",5,0,Color(0, 0, 0, 255))
end
cam.End3D2D()
end
end
end)
if not self.ARSOnly then
surface.DrawRect(0, 155, 240, 165)
surface.DrawRect(0, 325, 240, 190)
surface.SetDrawColor(0,0,0, 255)
surface.DrawRect(245, 155, 119, 365)
else
hook.Remove("PreDrawEffects","MetrostroiSignalDebug")
surface.DrawRect(0, 155, 364, 165)
surface.DrawRect(0, 325, 364, 190)
end
draw.DrawText(Format("Joint main info (%d)",self:EntIndex()),"Trebuchet24",5,-60,Color(200,0,0,255))
draw.DrawText("Signal name: "..self.Name,"Trebuchet24", 5, -40,Color(0, 0, 0, 255))
draw.DrawText("TrackID: "..self:GetNW2Int("PosID",0),"Trebuchet24", 25, -20,Color(0, 0, 0, 255))
draw.DrawText(Format("PosX: %.02f",self:GetNW2Float("Pos",0)),"Trebuchet24", 135, -20,Color(0, 0, 0, 255))
draw.DrawText(Format("NextSignalName: %s",self:GetNW2String("NextSignalName","N/A")),"Trebuchet24", 5, 0,Color(0, 0, 0, 255))
draw.DrawText(Format("TrackID: %s",self:GetNW2Int("NextPosID",0)),"Trebuchet24", 25, 20,Color(0, 0, 0, 255))
draw.DrawText(Format("PosX: %.02f",self:GetNW2Float("NextPos",0)),"Trebuchet24", 135, 20,Color(0, 0, 0, 255))
draw.DrawText(Format("Dist: %.02f",self:GetNW2Float("DistanceToNext",0)),"Trebuchet24", 5, 40,Color(0, 0, 0, 255))
draw.DrawText(Format("PrevSignalName: %s",self:GetNW2String("PrevSignalName","N/A")),"Trebuchet24", 5, 60,Color(0, 0, 0, 255))
draw.DrawText(Format("TrackID: %s",self:GetNW2Int("PrevPosID",0)),"Trebuchet24", 25, 80,Color(0, 0, 0, 255))
draw.DrawText(Format("PosX: %.02f",self:GetNW2Float("PrevPos",0)),"Trebuchet24", 135, 80,Color(0, 0, 0, 255))
draw.DrawText(Format("DistPrev: %.02f",self:GetNW2Float("DistanceToPrev",0)),"Trebuchet24", 5, 100,Color(0, 0, 0, 255))
draw.DrawText(Format("Current route: %d",self:GetNW2Int("CurrentRoute",-1)),"Trebuchet24", 5, 120,Color(0, 0, 0, 255))
draw.DrawText("AB info","Trebuchet24",5,155,Color(200,0,0,255))
draw.DrawText(Format("Occupied: %s",self:GetNW2Bool("Occupied",false) and "Y" or "N"),"Trebuchet24",5,175,Color(0, 0, 0, 255))
draw.DrawText(Format("Linked to controller: %s",self:GetNW2Bool("LinkedToController",false) and "Y" or "N"),"Trebuchet24",5,195,Color(0, 0, 0, 255))
draw.DrawText(Format("Num: %d",self:GetNW2Int("ControllersNumber",0)),"Trebuchet24",25,215,Color(0, 0, 0, 255))
draw.DrawText(Format("Controller logic: %s",self:GetNW2Bool("BlockedByController",false) and "Y" or "N"),"Trebuchet24",5,235,Color(0, 0, 0, 255))
draw.DrawText(Format("Autostop: %s",not self.ARSOnly and self.AutostopPresent and (self:GetNW2Bool("Autostop") and "Up" or "Down") or "No present"),"Trebuchet24",5,255,Color(0, 0, 0, 255))
draw.DrawText(Format("2/6: %s",self:GetNW2Bool("2/6",false) and "Y" or "N"),"Trebuchet24",5,275,Color(0, 0, 0, 255))
draw.DrawText(Format("FreeBS: %d",self:GetNW2Int("FreeBS")),"Trebuchet24",5,295,Color(0, 0, 0, 255))
draw.DrawText("ARS info","Trebuchet24",5,325,Color(200,0,0,255))
local num = 0
for i,tbl in pairs(ars) do
if not tbl then continue end
if self:GetNW2Bool("CurrentARS"..(i-1),false) then
draw.DrawText(Format("(% s)",tbl[1]),"Trebuchet24",5,345+num*20,Color(0,100,0,255))
draw.DrawText(Format("%s",tbl[2]),"Trebuchet24",105,345+num*20,Color(0,100,0,255))
else
draw.DrawText(Format("(% s)",tbl[1]),"Trebuchet24",5,345+num*20,Color(0, 0, 0, 255))
draw.DrawText(Format("%s",tbl[2]),"Trebuchet24",105,345+num*20,Color(0, 0, 0, 255))
end
num = num+1
end
if self:GetNW2Bool("CurrentARS325",false) or self:GetNW2Bool("CurrentARS325_2",false) then
draw.DrawText("(325 Hz)","Trebuchet24",5,345+num*20,Color(0,100,0,255))
draw.DrawText(Format("LN:%s Apr0:%s",self:GetNW2Bool("CurrentARS325",false) and "Y" or "N",self:GetNW2Bool("CurrentARS325_2",false) and "Y" or "N"),"Trebuchet24",105,345+num*20,Color(0,100,0,255))
else
draw.DrawText("(325 Hz)","Trebuchet24",5,345+num*20,Color(0, 0, 0, 255))
draw.DrawText(Format("LN:%s Apr0:%s",self:GetNW2Bool("CurrentARS325",false) and "Y" or "N",self:GetNW2Bool("CurrentARS325_2",false) and "Y" or "N"),"Trebuchet24",105,345+num*20,Color(0, 0, 0, 255))
end
if not self.ARSOnly then
draw.DrawText("Signal info","Trebuchet24",250,160,Color(200,0,0,255))
local ID = 0
local ID2 = 0
local first = true
for _,v in ipairs(self.LensesTBL) do
local data
if not self.TrafficLightModels[self.LightType][v] then
data = self.TrafficLightModels[self.LightType][#v-1]
else
data = self.TrafficLightModels[self.LightType][v]
end
if not data then continue end
--self.NamesOffset = self.NamesOffset + Vector(0,0,data[1])
if v ~= "M" then
for i = 1,#v do
ID2 = ID2 + 1
local n = tonumber(self.Sig[ID2])
local State = n == 1 and "X" or (n == 2 and (RealTime() % 1.2 > 0.4)) and "B" or false
draw.DrawText(Format(v[i],self:EntIndex()),"Trebuchet24",250,160 + ID*20 + ID2*20,cols[v[i]])
if State then
draw.DrawText(State,"Trebuchet24",280,160 + ID*20 + ID2*20,cols[v[i]])
end
end
else
ID2 = ID2 + 1
draw.DrawText("M","Trebuchet24",250,160 + ID*20 + ID2*20,Color(200,200,200))
draw.DrawText(self.Num or "none","Trebuchet24",280,160 + ID*20 + ID2*20,Color(200,200,200))
--if Metrostroi.RoutePointer[self.Num[1]] then self.Models[1][self.RouteNumber]:SetSkin(Metrostroi.RoutePointer[self.Num[1]]) end
end
ID = ID + 1
end
end
end
hook.Remove("PreDrawEffects","MetrostroiSignalDebug")
cvars.AddChangeCallback( "metrostroi_drawsignaldebug", enableDebug)
enableDebug()
Metrostroi.OptimisationPatch()