mirror of
https://github.com/wiremod/wire.git
synced 2025-03-04 03:03:04 -05:00
Speedometer improvements (#3271)
* Speedometer code improvements * Minor changes
This commit is contained in:
parent
62d6a66461
commit
3c4b5fddc2
@ -1,19 +1,14 @@
|
|||||||
AddCSLuaFile()
|
AddCSLuaFile()
|
||||||
DEFINE_BASECLASS( "base_wire_entity" )
|
DEFINE_BASECLASS("base_wire_entity")
|
||||||
ENT.PrintName = "Wire Speedometer"
|
ENT.PrintName = "Wire Speedometer"
|
||||||
ENT.WireDebugName = "Speedo"
|
ENT.WireDebugName = "Speedo"
|
||||||
|
|
||||||
function ENT:GetXYZMode()
|
function ENT:SetupDataTables()
|
||||||
return self:GetNWBool( 0 )
|
self:NetworkVar("Bool", 0, "XYZMode")
|
||||||
end
|
end
|
||||||
|
|
||||||
function ENT:GetAngVel()
|
function ENT:SetModes(XYZMode)
|
||||||
return self:GetNWBool( 1 )
|
self:SetXYZMode(XYZMode)
|
||||||
end
|
|
||||||
|
|
||||||
function ENT:SetModes( XYZMode, AngVel )
|
|
||||||
self:SetNWBool( 0, XYZMode )
|
|
||||||
self:SetNWBool( 1, AngVel )
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if CLIENT then
|
if CLIENT then
|
||||||
@ -21,83 +16,77 @@ if CLIENT then
|
|||||||
BaseClass.Think(self)
|
BaseClass.Think(self)
|
||||||
|
|
||||||
local txt
|
local txt
|
||||||
if (self:GetXYZMode()) then
|
|
||||||
local vel = self:WorldToLocal(self:GetVelocity()+self:GetPos())
|
if self:GetXYZMode() then
|
||||||
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
|
local vel = self:WorldToLocal(self:GetVelocity() + self:GetPos())
|
||||||
|
txt = string.format("Velocity = %.3f,%.3f,%.3f", -vel.y, vel.x, vel.z)
|
||||||
else
|
else
|
||||||
local vel = self:GetVelocity():Length()
|
txt = "Speed = " .. math.Round(self:GetVelocity():Length(), 3)
|
||||||
txt = "Speed = " .. math.Round((vel or 0)*1000)/1000
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--sadly self:GetPhysicsObject():GetAngleVelocity() does work client side, so read out is unlikely
|
self:SetOverlayText(txt)
|
||||||
/*if (self:GetAngVel()) then
|
self:NextThink(CurTime() + 0.04)
|
||||||
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)
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
return -- No more client
|
return -- No more client
|
||||||
end
|
end
|
||||||
|
|
||||||
local MODEL = Model("models/jaanus/wiretool/wiretool_speed.mdl")
|
|
||||||
|
|
||||||
function ENT:Initialize()
|
function ENT:Initialize()
|
||||||
self:SetModel( MODEL )
|
self:SetModel("models/jaanus/wiretool/wiretool_speed.mdl")
|
||||||
self:PhysicsInit( SOLID_VPHYSICS )
|
self:PhysicsInit(SOLID_VPHYSICS)
|
||||||
self:SetMoveType( MOVETYPE_VPHYSICS )
|
self:SetMoveType(MOVETYPE_VPHYSICS)
|
||||||
self:SetSolid( SOLID_VPHYSICS )
|
self:SetSolid(SOLID_VPHYSICS)
|
||||||
|
|
||||||
self.Outputs = Wire_CreateOutputs(self, { "Out", "MPH", "KPH" })
|
self.Outputs = Wire_CreateOutputs(self, { "Out", "MPH", "KPH" })
|
||||||
end
|
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.z_only = xyz_mode --was renamed but kept for dupesaves
|
||||||
self.XYZMode = xyz_mode
|
self.XYZMode = xyz_mode
|
||||||
self.AngVel = AngVel
|
self.AngVel = AngVel
|
||||||
self:SetModes( xyz_mode,AngVel )
|
self:SetModes(xyz_mode)
|
||||||
|
|
||||||
local outs = {}
|
local outs = {}
|
||||||
|
|
||||||
if (xyz_mode) then
|
if (xyz_mode) then
|
||||||
outs = { "X", "Y", "Z" }
|
outs = { "X", "Y", "Z" }
|
||||||
else
|
else
|
||||||
outs = { "Out", "MPH", "KPH", }
|
outs = { "Out", "MPH", "KPH" }
|
||||||
end
|
end
|
||||||
if (AngVel) then
|
|
||||||
|
if AngVel then
|
||||||
table.Add(outs, {"AngVel_P", "AngVel_Y", "AngVel_R" } )
|
table.Add(outs, {"AngVel_P", "AngVel_Y", "AngVel_R" } )
|
||||||
end
|
end
|
||||||
|
|
||||||
Wire_AdjustOutputs(self, outs)
|
Wire_AdjustOutputs(self, outs)
|
||||||
end
|
end
|
||||||
|
|
||||||
function ENT:Think()
|
function ENT:Think()
|
||||||
BaseClass.Think(self)
|
BaseClass.Think(self)
|
||||||
|
|
||||||
if (self.XYZMode) then
|
if self.XYZMode then
|
||||||
local vel = self:WorldToLocal(self:GetVelocity()+self:GetPos())
|
local vel = self:WorldToLocal(self:GetVelocity() + self:GetPos())
|
||||||
if (COLOSSAL_SANDBOX) then vel = vel * 6.25 end
|
|
||||||
Wire_TriggerOutput(self, "X", -vel.y)
|
Wire_TriggerOutput(self, "X", -vel.y)
|
||||||
Wire_TriggerOutput(self, "Y", vel.x)
|
Wire_TriggerOutput(self, "Y", vel.x)
|
||||||
Wire_TriggerOutput(self, "Z", vel.z)
|
Wire_TriggerOutput(self, "Z", vel.z)
|
||||||
else
|
else
|
||||||
local vel = self:GetVelocity():Length()
|
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: https://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: http://developer.valvesoftware.com/wiki/Dimensions#Map_Grid_Units:_quick_reference
|
|
||||||
Wire_TriggerOutput(self, "MPH", vel * 3600 / 63360 * 0.75)
|
Wire_TriggerOutput(self, "MPH", vel * 3600 / 63360 * 0.75)
|
||||||
Wire_TriggerOutput(self, "KPH", vel * 3600 * 0.0000254 * 0.75)
|
Wire_TriggerOutput(self, "KPH", vel * 3600 * 0.0000254 * 0.75)
|
||||||
end
|
end
|
||||||
|
|
||||||
if (self.AngVel) then
|
if self.AngVel then
|
||||||
local ang = self:GetPhysicsObject():GetAngleVelocity()
|
local ang = self:GetPhysicsObject():GetAngleVelocity()
|
||||||
Wire_TriggerOutput(self, "AngVel_P", ang.y)
|
Wire_TriggerOutput(self, "AngVel_P", ang.y)
|
||||||
Wire_TriggerOutput(self, "AngVel_Y", ang.z)
|
Wire_TriggerOutput(self, "AngVel_Y", ang.z)
|
||||||
Wire_TriggerOutput(self, "AngVel_R", ang.x)
|
Wire_TriggerOutput(self, "AngVel_R", ang.x)
|
||||||
end
|
end
|
||||||
|
|
||||||
self:NextThink(CurTime()+0.04)
|
self:NextThink(CurTime() + 0.04)
|
||||||
|
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user