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

Speedometer improvements #3271

Merged
merged 2 commits into from
Feb 21, 2025
Merged
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
73 changes: 31 additions & 42 deletions lua/entities/gmod_wire_speedometer.lua
Original file line number Diff line number Diff line change
@@ -1,103 +1,92 @@
AddCSLuaFile()
DEFINE_BASECLASS( "base_wire_entity" )
ENT.PrintName = "Wire Speedometer"
ENT.WireDebugName = "Speedo"
DEFINE_BASECLASS("base_wire_entity")
ENT.PrintName = "Wire Speedometer"
ENT.WireDebugName = "Speedo"

function ENT:GetXYZMode()
return self:GetNWBool( 0 )
function ENT:SetupDataTables()
self:NetworkVar("Bool", 0, "XYZMode")
end

function ENT:GetAngVel()
return self:GetNWBool( 1 )
end

function ENT:SetModes( XYZMode, AngVel )
self:SetNWBool( 0, XYZMode )
self:SetNWBool( 1, AngVel )
function ENT:SetModes(XYZMode)
self:SetXYZMode(XYZMode)
end

if CLIENT then
function ENT:Think()
BaseClass.Think(self)

local txt
if (self:GetXYZMode()) then
local vel = self:WorldToLocal(self:GetVelocity()+self:GetPos())
txt = "Velocity = " .. math.Round((-vel.y or 0)*1000)/1000 .. "," .. math.Round((vel.x or 0)*1000)/1000 .. "," .. math.Round((vel.z or 0)*1000)/1000

if self:GetXYZMode() then
local vel = self:WorldToLocal(self:GetVelocity() + self:GetPos())
txt = string.format("Velocity = %.3f,%.3f,%.3f", -vel.y, vel.x, vel.z)
else
local vel = self:GetVelocity():Length()
txt = "Speed = " .. math.Round((vel or 0)*1000)/1000
txt = "Speed = " .. math.Round(self:GetVelocity():Length(), 3)
end

--sadly self:GetPhysicsObject():GetAngleVelocity() does work client side, so read out is unlikely
/*if (self:GetAngVel()) then
local ang = self:GetPhysicsObject():GetAngleVelocity()
txt = txt .. "\nAngVel = P " .. math.Round((ang.y or 0)*1000)/1000 .. ", Y " .. math.Round((ang.z or 0)*1000) /1000 .. ", R " .. math.Round((ang.x or 0)*1000)/1000
end*/
self:SetOverlayText(txt)
self:NextThink(CurTime() + 0.04)

self:SetOverlayText( txt )

self:NextThink(CurTime()+0.04)
return true
end

return -- No more client
end

local MODEL = Model("models/jaanus/wiretool/wiretool_speed.mdl")

function ENT:Initialize()
self:SetModel( MODEL )
self:PhysicsInit( SOLID_VPHYSICS )
self:SetMoveType( MOVETYPE_VPHYSICS )
self:SetSolid( SOLID_VPHYSICS )
self:SetModel("models/jaanus/wiretool/wiretool_speed.mdl")
self:PhysicsInit(SOLID_VPHYSICS)
self:SetMoveType(MOVETYPE_VPHYSICS)
self:SetSolid(SOLID_VPHYSICS)

self.Outputs = Wire_CreateOutputs(self, { "Out", "MPH", "KPH" })
end

function ENT:Setup( xyz_mode, AngVel )
function ENT:Setup(xyz_mode, AngVel)
self.z_only = xyz_mode --was renamed but kept for dupesaves
self.XYZMode = xyz_mode
self.AngVel = AngVel
self:SetModes( xyz_mode,AngVel )
self:SetModes(xyz_mode)

local outs = {}

if (xyz_mode) then
outs = { "X", "Y", "Z" }
else
outs = { "Out", "MPH", "KPH", }
outs = { "Out", "MPH", "KPH" }
end
if (AngVel) then

if AngVel then
table.Add(outs, {"AngVel_P", "AngVel_Y", "AngVel_R" } )
end

Wire_AdjustOutputs(self, outs)
end

function ENT:Think()
BaseClass.Think(self)

if (self.XYZMode) then
local vel = self:WorldToLocal(self:GetVelocity()+self:GetPos())
if (COLOSSAL_SANDBOX) then vel = vel * 6.25 end
if self.XYZMode then
local vel = self:WorldToLocal(self:GetVelocity() + self:GetPos())
Wire_TriggerOutput(self, "X", -vel.y)
Wire_TriggerOutput(self, "Y", vel.x)
Wire_TriggerOutput(self, "Z", vel.z)
else
local vel = self:GetVelocity():Length()
if (COLOSSAL_SANDBOX) then vel = vel * 6.25 end
Wire_TriggerOutput(self, "Out", vel) // vel = Source Units / sec, Source Units = Inch * 0.75 , more info here: http://developer.valvesoftware.com/wiki/Dimensions#Map_Grid_Units:_quick_reference
Wire_TriggerOutput(self, "Out", vel) -- vel = Source Units / sec, Source Units = Inch * 0.75 , more info here: https://developer.valvesoftware.com/wiki/Dimensions#Map_Grid_Units:_quick_reference
Wire_TriggerOutput(self, "MPH", vel * 3600 / 63360 * 0.75)
Wire_TriggerOutput(self, "KPH", vel * 3600 * 0.0000254 * 0.75)
end

if (self.AngVel) then
if self.AngVel then
local ang = self:GetPhysicsObject():GetAngleVelocity()
Wire_TriggerOutput(self, "AngVel_P", ang.y)
Wire_TriggerOutput(self, "AngVel_Y", ang.z)
Wire_TriggerOutput(self, "AngVel_R", ang.x)
end

self:NextThink(CurTime()+0.04)
self:NextThink(CurTime() + 0.04)

return true
end

Expand Down
Loading