From 90e0c70ebb1004b08fa79a148e83b38d69aa7f3c Mon Sep 17 00:00:00 2001 From: Nebual Date: Tue, 30 Oct 2012 13:55:40 -0700 Subject: [PATCH 1/8] Updated WireLib.AddNotify to Net library --- lua/wire/WireShared.lua | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/lua/wire/WireShared.lua b/lua/wire/WireShared.lua index 0dffc1d105..f8ea66a773 100644 --- a/lua/wire/WireShared.lua +++ b/lua/wire/WireShared.lua @@ -282,7 +282,7 @@ do } function WireLib.AddNotify(ply, Message, Type, Duration, Sound) - if type(ply) == "string" then + if isstring(ply) then Message, Type, Duration, Sound = ply, Message, Type, Duration elseif ply ~= LocalPlayer() then return @@ -291,11 +291,11 @@ do if Sound and sounds[Sound] then surface.PlaySound(sounds[Sound]) end end - usermessage.Hook("wire_addnotify", function(um) - local Message = um:ReadString() - local Type = um:ReadChar() - local Duration = um:ReadFloat() - local Sound = um:ReadChar() + net.Receive("wire_addnotify", function(netlen) + local Message = net.ReadString() + local Type = net.ReadUInt(8) + local Duration = net.ReadFloat() + local Sound = net.ReadUInt(8) WireLib.AddNotify(LocalPlayer(), Message, Type, Duration, Sound) end) @@ -307,16 +307,17 @@ do NOTIFY_UNDO = 2 NOTIFY_HINT = 3 NOTIFY_CLEANUP = 4 - + + util.AddNetworkString("wire_addnotify") function WireLib.AddNotify(ply, Message, Type, Duration, Sound) - if type(ply) == "string" then ply, Message, Type, Duration, Sound = nil, ply, Message, Type, Duration end + if isstring(ply) then ply, Message, Type, Duration, Sound = nil, ply, Message, Type, Duration end if ply && !ply:IsValid() then return end - umsg.Start("wire_addnotify", ply) - umsg.String(Message) - umsg.Char(Type) - umsg.Float(Duration) - umsg.Char(Sound or 0) - umsg.End() + net.Start("wire_addnotify") + net.WriteString(Message) + net.WriteUInt(Type or 0,8) + net.WriteFloat(Duration) + net.WriteUInt(Sound or 0,8) + if ply then net.Send(ply) else net.Broadcast() end end end From 8452bf00076ae982b0cf132bacfe1d7b2ebb610d Mon Sep 17 00:00:00 2001 From: Nebual Date: Tue, 30 Oct 2012 15:48:06 -0700 Subject: [PATCH 2/8] Updated "wire_ports" umsg to use the Net Library --- lua/wire/WireShared.lua | 245 ++++++++++++++++++---------------------- 1 file changed, 110 insertions(+), 135 deletions(-) diff --git a/lua/wire/WireShared.lua b/lua/wire/WireShared.lua index f8ea66a773..1024a9ea0a 100644 --- a/lua/wire/WireShared.lua +++ b/lua/wire/WireShared.lua @@ -448,9 +448,14 @@ if SERVER then local ents_with_inputs = {} local ents_with_outputs = {} --local IOlookup = { [INPUT] = ents_with_inputs, [OUTPUT] = ents_with_outputs } - - local queue = WireLib.containers.deque:new() - local rp = RecipientFilter() + + util.AddNetworkString("wire_ports") + timer.Create("Debugger.PoolTypeStrings",1,1,function() + if WireLib.Debugger and WireLib.Debugger.formatPort then + for typename,_ in pairs(WireLib.Debugger.formatPort) do util.AddNetworkString(typename) end -- Reduce bandwidth + end + end) + local queue = {} function WireLib.GetPorts(ent) local eid = ent:EntIndex() @@ -463,22 +468,20 @@ if SERVER then ents_with_inputs[eid] = nil ents_with_outputs[eid] = nil if not DontSend then - umsg.Start("wire_ports", rp) - umsg.Char(-3) -- set eid - umsg.Short(eid) -- entity id - if hasinputs then umsg.Char(-1) end -- delete inputs - if hasoutputs then umsg.Char(-2) end -- delete outputs - umsg.Char(0) -- break - umsg.End() + net.Start("wire_ports") + net.WriteInt(-3, 8) -- set eid + net.WriteUInt(eid, 16) -- entity id + if hasinputs then net.WriteInt(-1, 8) end -- delete inputs + if hasoutputs then net.WriteInt(-2, 8) end -- delete outputs + net.WriteInt(0, 8) -- break + net.Broadcast() end end end hook.Add("EntityRemoved", "wire_ports", function(ent) if not IsValid(ent) then return end - if ent:IsPlayer() then - rp:RemovePlayer(ent) - else + if not ent:IsPlayer() then WireLib._RemoveWire(ent:EntIndex()) end end) @@ -487,12 +490,12 @@ if SERVER then local queue = lqueue or queue local eid = ent:EntIndex() - queue:push({ eid, DELETE, INPUT }) + queue[#queue+1] = { eid, DELETE, INPUT } for Name, CurPort in pairs_sortvalues(ent.Inputs, WireLib.PortComparator) do local entry = { Name, CurPort.Type, CurPort.Desc or "" } ents_with_inputs[eid] = entry - queue:push({ eid, PORT, INPUT, entry, CurPort.Num }) + queue[#queue+1] = { eid, PORT, INPUT, entry, CurPort.Num } end for Name, CurPort in pairs_sortvalues(ent.Inputs, WireLib.PortComparator) do WireLib._SetLink(CurPort, lqueue) @@ -503,12 +506,12 @@ if SERVER then local queue = lqueue or queue local eid = ent:EntIndex() - queue:push({ eid, DELETE, OUTPUT }) + queue[#queue+1] = { eid, DELETE, OUTPUT } for Name, CurPort in pairs_sortvalues(ent.Outputs, WireLib.PortComparator) do local entry = { Name, CurPort.Type, CurPort.Desc or "" } ents_with_outputs[eid] = entry - queue:push({ eid, PORT, OUTPUT, entry, CurPort.Num }) + queue[#queue+1] = { eid, PORT, OUTPUT, entry, CurPort.Num } end end @@ -520,93 +523,83 @@ if SERVER then local queue = lqueue or queue local eid = ent:EntIndex() - queue:push({eid, LINK, num, state}) + queue[#queue+1] = {eid, LINK, num, state} end - - local function FlushQueue(lqueue, ply) - ply = ply or rp - local eid = 0 - local ports_msg = nil - local function parsemsg(msg) - local same_eid = msg[1] == eid - local bytes, ret - if same_eid then - bytes = 0 - ret = {} - else - eid = msg[1] - bytes = 3 - ret = { { umsg.Char, -3 }, { umsg.Short, eid } } - ports_msg = nil + + local eid = 0 + local numports, firstportnum, portstrings = {}, {}, {} + local function writeCurrentStrings() + -- Write the current (input or output) string information + for IO=OUTPUT,INPUT,2 do -- so, k= -1 and k= 1 + if numports[IO] then + net.WriteInt(firstportnum[IO], 8) -- Control code for inputs/outputs is also the offset (the first port number we're writing over) + net.WriteUInt(numports[IO], 8) -- Send number of ports + net.WriteBit(IO==OUTPUT) + for i=1,numports[IO]*3 do net.WriteString(portstrings[IO][i] or "") end + numports[IO] = nil end + end + end + local function writemsg(msg) + -- First write a signed int for the command code + -- Then sometimes write extra data specific to the command (type varies) + + if msg[1] ~= eid then + eid = msg[1] + writeCurrentStrings() -- We're switching to talking about a different entity, lets send port information + net.WriteInt(-3,8) + net.WriteUInt(eid,16) + end - local msgtype = msg[2] - - if msgtype == DELETE then - ports_msg = nil - bytes = bytes + 1 - table.insert(ret, { umsg.Char, msg[3] == INPUT and -1 or -2 }) - - elseif msgtype == PORT then - local _,_,IO,entry,num = unpack(msg) - - if not ports_msg then - bytes = bytes + 2 - table.insert(ret, { umsg.Char, num }) - ports_msg = { umsg.Char, 0 } - table.insert(ret, ports_msg) - end - - ports_msg[2] = ports_msg[2]+IO + local msgtype = msg[2] - bytes = bytes + #entry[1] + #entry[2] + #entry[3]+3 - table.insert(ret, { umsg.String, entry[1] }) - table.insert(ret, { umsg.String, entry[2] }) - table.insert(ret, { umsg.String, entry[3] }) + if msgtype == DELETE then + numports[msg[3]] = nil + net.WriteInt(msg[3] == INPUT and -1 or -2, 8) + elseif msgtype == PORT then + local _,_,IO,entry,num = unpack(msg) - elseif msgtype == LINK then - local _,_,num,state = unpack(msg) - bytes = bytes + 3 - table.insert(ret, { umsg.Char, -4 }) - table.insert(ret, { umsg.Char, num }) - table.insert(ret, { umsg.Bool, state }) + if not numports[IO] then + firstportnum[IO] = num + numports[IO] = 0 + portstrings[IO] = {} end - return bytes, ret + local i = numports[IO]*3 + portstrings[IO][i+1] = entry[1] + portstrings[IO][i+2] = entry[2] + portstrings[IO][i+3] = entry[3] + numports[IO] = numports[IO]+1 + elseif msgtype == LINK then + local _,_,num,state = unpack(msg) + net.WriteInt(-4, 8) + net.WriteUInt(num, 8) + net.WriteBit(state) end + end - umsg.Start("wire_ports", ply or rp) - local maxsize = 240 - local bytes = 0 - local msgs = {} - while lqueue:size()>0 do - local msg = lqueue:bottom() - local size,contents = parsemsg(msg) - bytes = bytes+size - if bytes>maxsize then break end + local function FlushQueue(lqueue, ply) + ply = ply or rp + // Zero these two for the writemsg function + eid = 0 + numports = {} - table.insert(msgs, contents) - lqueue:shift() - end - for _,contents in ipairs(msgs) do - for _,func,value in ipairs_map(contents,unpack) do - func(value) - end + net.Start("wire_ports") + for i=1,#lqueue do + writemsg(lqueue[i]) end - umsg.Char(0) - umsg.End() - - if lqueue:size() == 0 then return end - return FlushQueue(lqueue, ply) + writeCurrentStrings() + net.WriteInt(0,8) + if ply then net.Send(ply) else net.Broadcast() end end hook.Add("Think", "wire_ports", function() - if queue:size() == 0 then return end - return FlushQueue(queue) + if not next(queue) then return end + FlushQueue(queue) + queue = {} end) hook.Add("PlayerInitialSpawn", "wire_ports", function(ply) - rp:AddPlayer(ply) - local lqueue = WireLib.containers.deque:new() + local lqueue = {} for eid, entry in pairs(ents_with_inputs) do WireLib._SetInputs(Entity(eid), lqueue) end @@ -620,48 +613,27 @@ elseif CLIENT then local ents_with_inputs = {} local ents_with_outputs = {} - usermessage.Hook("wire_ports", function(um) + net.Receive("wire_ports", function(netlen) local eid = 0 - - while not (function() - local start = um:ReadChar() - if start == 0 then - -- break - return true - elseif start == -1 then - -- delete input entry + local connections = {} -- In case any cmd -4's come in before link strings + while true do + local cmd = net.ReadInt(8) + if cmd == 0 then + break + elseif cmd == -1 then ents_with_inputs[eid] = nil - return false - elseif start == -2 then - -- delete output entry + elseif cmd == -2 then ents_with_outputs[eid] = nil - return false - elseif start == -3 then - -- set eid - eid = um:ReadShort() - return false - elseif start == -4 then - -- connection state - local num = um:ReadChar() - local state = um:ReadBool() - - local entry = ents_with_inputs[eid] - if not entry then - entry = {} - ents_with_inputs[eid] = entry - end - - if not entry[num] then return false end - entry[num][4] = state - - return false - elseif start > 0 then + elseif cmd == -3 then + eid = net.ReadUInt(16) + elseif cmd == -4 then + connections[#connections+1] = {eid, net.ReadUInt(8), net.ReadBit() ~= 0} -- Delay this process till after the loop + elseif cmd > 0 then local entry - local amount = um:ReadChar() - if amount < 0 then + local amount = net.ReadUInt(8) + if net.ReadBit() ~= 0 then -- outputs - amount = -amount entry = ents_with_outputs[eid] if not entry then entry = {} @@ -676,19 +648,22 @@ elseif CLIENT then end end - local endindex = start+amount-1 - for i = start,endindex do - local name = um:ReadString() - local tp = um:ReadString() - local desc = um:ReadString() - - entry[i] = { name, tp, desc } + local endindex = cmd+amount-1 + for i = cmd,endindex do + entry[i] = {net.ReadString(), net.ReadString(), net.ReadString()} end - - return false end - - end)() do end + end + for i=1, #connections do + local eid, num, state = unpack(connections[i]) + local entry = ents_with_inputs[eid] + if not entry then + entry = {} + ents_with_inputs[eid] = entry + elseif entry[num] then + entry[num][4] = state + end + end end) function WireLib.GetPorts(ent) From 31e4e02ee8b3108f0af68618d487b58e45198656 Mon Sep 17 00:00:00 2001 From: Nebual Date: Tue, 30 Oct 2012 20:02:48 -0700 Subject: [PATCH 3/8] Fixes #90 (sometimes table[3]s were passed in instead of vectors) --- lua/entities/gmod_wire_cam/init.lua | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/lua/entities/gmod_wire_cam/init.lua b/lua/entities/gmod_wire_cam/init.lua index 2ad0897d9c..10ccc152e6 100644 --- a/lua/entities/gmod_wire_cam/init.lua +++ b/lua/entities/gmod_wire_cam/init.lua @@ -38,25 +38,32 @@ function ENT:ReceiveInfo(iname, value) self.IdealPos.z = value self:SetPos(self.IdealPos) elseif iname == "Position" then + if not isvector(value) then + if istable(value) and #value == 3 then + value = Vector(unpack(value)) + else + return + end + end self.IdealPos = value self:SetPos(self.IdealPos) - elseif iname == "Pitch" then self.IdealAng.p = value - --self:SetAngles(self.IdealAng) elseif iname == "Yaw" then self.IdealAng.y = value - --self:SetAngles(self.IdealAng) elseif iname == "Roll" then self.IdealAng.r = value - --self:SetAngles(self.IdealAng) elseif iname == "Angle" then self.IdealAng = value - --self:SetAngles(self.IdealAng) - elseif iname == "Direction" then + if not isvector(value) then + if istable(value) and #value == 3 then + value = Vector(unpack(value)) + else + return + end + end self.IdealAng = value:Angle() - --self:SetAngles(self.IdealAng) elseif iname == "Velocity" then self.IdealVel = value self.phys:SetVelocity(self.IdealVel) From 5bbabdcb27fdecc27b9c98b33a12d7cad33c5dc5 Mon Sep 17 00:00:00 2001 From: Nebual Date: Tue, 30 Oct 2012 20:31:08 -0700 Subject: [PATCH 4/8] Changed some ownership checks to be CPPI compliant --- lua/entities/gmod_wire_expression2/core/wirelink.lua | 9 +-------- lua/wire/gates/entity.lua | 8 ++++---- 2 files changed, 5 insertions(+), 12 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/core/wirelink.lua b/lua/entities/gmod_wire_expression2/core/wirelink.lua index 95a1c9b228..aa3939c235 100644 --- a/lua/entities/gmod_wire_expression2/core/wirelink.lua +++ b/lua/entities/gmod_wire_expression2/core/wirelink.lua @@ -29,14 +29,7 @@ end local function validWirelink(self, ent) if not IsValid(ent) then return false end if not ent.extended then return false end - local player = E2Lib.getOwner(self, ent) - if player == nil then return false end - if not player:IsValid() then return false end - if player != self.player then - -- E2Lib.abuse(self.player) - return false - end - + if not isOwner(self, ent) then return false end return true end diff --git a/lua/wire/gates/entity.lua b/lua/wire/gates/entity.lua index 5094db90bc..bc0f69337f 100644 --- a/lua/wire/gates/entity.lua +++ b/lua/wire/gates/entity.lua @@ -24,7 +24,7 @@ GateActions["entity_applyf"] = { output = function(gate, Ent , Vec ) if !Ent then return end if !Ent:IsValid() or !Ent:GetPhysicsObject():IsValid() then return end - if !(E2Lib.getOwner(gate, Ent) == E2Lib.getOwner(gate, gate)) then return end + if not E2Lib.isOwner(gate, Ent) then return end if !IsVector(Vec) then Vec = Vector(0, 0, 0) end if checkv(Vec) then Ent:GetPhysicsObject():ApplyForceCenter(Vec) @@ -43,7 +43,7 @@ GateActions["entity_applyof"] = { output = function(gate, Ent , Vec , Offset ) if !Ent then return end if !Ent:IsValid() or !Ent:GetPhysicsObject():IsValid() then return end - if !(E2Lib.getOwner(gate, Ent) == E2Lib.getOwner(gate, gate)) then return end + if not E2Lib.isOwner(gate, Ent) then return end if !IsVector(Vec) then Vec = Vector (0, 0, 0) end if !IsVector(Offset) then Offset = Vector (0, 0, 0) end if checkv(Vec) and checkv(Offset) then @@ -65,7 +65,7 @@ GateActions["entity_applyaf"] = { output = function(gate, Ent , angForce ) if !Ent then return end if !Ent:IsValid() or !Ent:GetPhysicsObject():IsValid() then return end - if !(E2Lib.getOwner(gate, Ent) == E2Lib.getOwner(gate, gate)) then return end + if not E2Lib.isOwner(gate, Ent) then return end if angForce.p == 0 and angForce.y == 0 and angForce.r == 0 then return end if not checka(angForce) then return end @@ -115,7 +115,7 @@ GateActions["entity_applytorq"] = { output = function(gate, Ent , Vec ) if !Ent then return end if not Ent:IsValid() then return end - if !(E2Lib.getOwner(gate, Ent) == E2Lib.getOwner(gate, gate)) then return end + if not E2Lib.isOwner(gate, Ent) then return end if Vec.x == 0 and Vec.y == 0 and Vec.z == 0 then return end if not checkv(Vec) then return end From 44c99d5fcda44c8124139c7d5c3389c0b07895df Mon Sep 17 00:00:00 2001 From: Nebual Date: Tue, 30 Oct 2012 20:31:48 -0700 Subject: [PATCH 5/8] May have fixed the laserpointer erroring on invalid models --- lua/weapons/laserpointer/cl_init.lua | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/lua/weapons/laserpointer/cl_init.lua b/lua/weapons/laserpointer/cl_init.lua index 7fd985b2d6..355e5da35c 100644 --- a/lua/weapons/laserpointer/cl_init.lua +++ b/lua/weapons/laserpointer/cl_init.lua @@ -9,16 +9,19 @@ local LASER = Material('cable/redlaser') function SWEP:SetVM(ply) if ply.GetViewModel and ply:GetViewModel():IsValid() then - self.VM = ply:GetViewModel() - local attachmentIndex = self.VM:LookupAttachment("muzzle") - if attachmentIndex == 0 then attachmentIndex = self.VM:LookupAttachment("1") end - self.Attach = attachmentIndex + local attachmentIndex = ply:GetViewModel():LookupAttachment("muzzle") + if attachmentIndex == 0 then attachmentIndex = ply:GetViewModel():LookupAttachment("1") end + if LocalPlayer():GetAttachment(attachmentIndex) then + self.VM = ply:GetViewModel() + self.Attach = attachmentIndex + end end if ply:IsValid() then local attachmentIndex = ply:LookupAttachment("anim_attachment_RH") - if attachmentIndex == 0 then return end - self.WM = ply - self.WAttach = attachmentIndex + if ply:GetAttachment(attachmentIndex) then + self.WM = ply + self.WAttach = attachmentIndex + end end end function SWEP:Initialize() From b79ba369b49802a1eb2098a839a1335cd4df78e4 Mon Sep 17 00:00:00 2001 From: Nebual Date: Tue, 30 Oct 2012 20:35:39 -0700 Subject: [PATCH 6/8] Made wire_debugger more bandwidth efficient - No longer sends a WireDbgCount every tick, only on change - No longer calculates in a Think hook, instead uses a slower timer as it only used to send messages to the player occasionally anyway --- .../gmod_tool/stools/wire_debugger.lua | 184 +++++++++--------- 1 file changed, 89 insertions(+), 95 deletions(-) diff --git a/lua/weapons/gmod_tool/stools/wire_debugger.lua b/lua/weapons/gmod_tool/stools/wire_debugger.lua index 86cb1e899a..f56c433c4b 100644 --- a/lua/weapons/gmod_tool/stools/wire_debugger.lua +++ b/lua/weapons/gmod_tool/stools/wire_debugger.lua @@ -20,6 +20,8 @@ TOOL.ClientConVar[ "showports" ] = "1" TOOL.ClientConVar[ "orientvertical" ] = "1" local Components = {} +local UpdateLineCount +local dbg_line_cache local function IsWire(entity) --try to find out if the entity is wire if (WireLib.HasPorts(entity)) then return true end @@ -33,38 +35,47 @@ function TOOL:LeftClick(trace) if (!IsWire(trace.Entity)) then return end if (CLIENT) then return true end - ply_idx = self:GetOwner() - Components[ply_idx] = Components[ply_idx] or {} + local ply = self:GetOwner() + Components[ply] = Components[ply] or {} - for k,cmp in ipairs(Components[ply_idx]) do + for k,cmp in ipairs(Components[ply]) do if (cmp == trace.Entity) then return end end - table.insert(Components[ply_idx], trace.Entity) + table.insert(Components[ply], trace.Entity) return true end +if SERVER then + local dbg_linecount_cache = {} + function UpdateLineCount(ply, count) + if dbg_linecount_cache[ply] != count then + dbg_linecount_cache[ply] = count + net.Start("WireDbgCount") net.WriteUInt(count,16) net.Send(ply) + end + end +end + function TOOL:RightClick(trace) if (!trace.Entity:IsValid()) then return end if (!IsWire(trace.Entity)) then return end if (CLIENT) then return true end - ply_idx = self:GetOwner() - if not Components[ply_idx] then return end + local ply = self:GetOwner() + if not Components[ply] then return end - for k,cmp in ipairs(Components[ply_idx]) do + for k,cmp in ipairs(Components[ply]) do if (cmp == trace.Entity) then - table.remove(Components[ply_idx], k) + table.remove(Components[ply], k) + dbg_line_cache[ply] = nil return true end end - if not next(Components[ply_idx]) then - net.Start("WireDbgCount") - net.WriteUInt(0,16) - net.Send(ply_idx) - Components[ply_idx] = nil + if not next(Components[ply]) then + UpdateLineCount(ply, 0) + Components[ply] = nil end end @@ -142,17 +153,15 @@ end function TOOL:Reload(trace) if (CLIENT) then return end - net.Start("WireDbgCount") - net.WriteUInt(0,16) - net.Send(self:GetOwner()) + UpdateLineCount(self:GetOwner(), 0) Components[self:GetOwner()] = nil + dbg_line_cache[self:GetOwner()] = nil end if (SERVER) then - local dbg_line_cache = {} - local dbg_line_time = {} + dbg_line_cache = {} local formatPort = {} WireLib.Debugger = { formatPort = formatPort } -- Make it global @@ -173,7 +182,7 @@ if (SERVER) then end formatPort.ENTITY = function(ent) - if not IsValid(ent) then return "(null)" end -- this uses IsValid from E2, which is faster, but maybe we shouldn't use it. + if not IsValid(ent) then return "(null)" end return tostring(ent) end formatPort.BONE = e2_tostring_bone @@ -327,12 +336,9 @@ if (SERVER) then -- TODO: Add EntityRemoved hook to clean up Components array. table.Compact(cmps, function(cmp) return cmp:IsValid() and IsWire(cmp) end) - -- TODO: only send in TOOL:*Click/Reload hooks maybe. - net.Start("WireDbgCount") - net.WriteUInt(#cmps,16) - net.Send(ply) + UpdateLineCount(ply, #cmps) - if #cmps == 0 then Components[ply] = nil end + if #cmps == 0 then Components[ply] = nil continue end for l,cmp in ipairs(cmps) do local dbginfo = cmp.WireDebugName @@ -389,112 +395,98 @@ if (SERVER) then end dbg_line_cache[ply] = dbg_line_cache[ply] or {} - dbg_line_time[ply] = dbg_line_time[ply] or {} if (dbg_line_cache[ply][l] ~= dbginfo) then - if (not dbg_line_time[ply][l]) or (CurTime() > dbg_line_time[ply][l]) then - --split the message up into managable chuncks and send them - net.Start("WireDbg") - net.WriteBit(OrientVertical) - net.WriteUInt(l,16) - net.WriteString(dbginfo) - net.Send(ply) - - dbg_line_cache[ply][l] = dbginfo - if (game.SinglePlayer()) then - dbg_line_time[ply][l] = CurTime() + 0.05 - else - dbg_line_time[ply][l] = CurTime() + 0.2 - end - end + --split the message up into managable chuncks and send them + net.Start("WireDbg") + net.WriteBit(OrientVertical) + net.WriteUInt(l,16) + net.WriteString(dbginfo) + net.Send(ply) + + dbg_line_cache[ply][l] = dbginfo end end - end - end end - hook.Add("Think", "Wire_DebuggerThink", Wire_DebuggerThink) + timer.Create("Wire_DebuggerThink", game.SinglePlayer() and 0.05 or 0.1, 0, Wire_DebuggerThink) + //hook.Add("Think", "Wire_DebuggerThink", Wire_DebuggerThink) end if (CLIENT) then - local dbg_line_count = 0 local dbg_lines = {} local dgb_orient_vert = false local BoxWidth = 300 - local LastBoxUpdate = CurTime()-5 + local LastBoxUpdate = 0 local function DebuggerDrawHUD() local dbginfo = "" - if (dbg_line_count <= 0) then return end + if not next(dbg_lines) then return end --setup the font surface.SetFont("Default") --buid the table of entries - local Entry_Count = dbg_line_count local Line_Count = 0 local ColorType = 0 local Entries = {} - for i = 1,dbg_line_count do - local Line = dbg_lines[i] - if(Line) then - local CurEntry = {} - CurEntry.Lines = {} - - local ExplodeLines = string.Explode("\n", Line) - - for Index, ExplodeLine in ipairs(ExplodeLines) do --break it into multible lines for 1 entry - if(string.Trim(ExplodeLine) != "") then - - local XPos = 0 - if(Index > 1) then - if dgb_orient_vert then --if the string is not the first and it is vertical, line it up acordingly - if(string.Trim(ExplodeLine) == "OUT:" or string.Trim(ExplodeLine) == "IN:") then - XPos = 17 - else - XPos = 42 - end - else --if the string is not the first and it is not vertical, line it up with the IN on the first line - if(CurEntry.Lines[1].LineText and string.find(CurEntry.Lines[1].LineText,"IN:")) then - local TextPos = string.find(CurEntry.Lines[1].LineText,"IN:")-1 - XPos = surface.GetTextSize( string.Left(CurEntry.Lines[1].LineText, TextPos) ) - end - end + for _, Line in pairs(dbg_lines) do + local CurEntry = {} + CurEntry.Lines = {} - end + local ExplodeLines = string.Explode("\n", Line) - local TrimLine = { - LineText = string.Trim(ExplodeLine), - OffsetPos = { XPos, Line_Count*14 } --move the next text down some for each line - } - table.insert(CurEntry.Lines, TrimLine ) - Line_Count = Line_Count+1 + for Index, ExplodeLine in ipairs(ExplodeLines) do --break it into multible lines for 1 entry + if(string.Trim(ExplodeLine) != "") then + + local XPos = 0 + if(Index > 1) then + if dgb_orient_vert then --if the string is not the first and it is vertical, line it up acordingly + if(string.Trim(ExplodeLine) == "OUT:" or string.Trim(ExplodeLine) == "IN:") then + XPos = 17 + else + XPos = 42 + end + else --if the string is not the first and it is not vertical, line it up with the IN on the first line + if(CurEntry.Lines[1].LineText and string.find(CurEntry.Lines[1].LineText,"IN:")) then + local TextPos = string.find(CurEntry.Lines[1].LineText,"IN:")-1 + XPos = surface.GetTextSize( string.Left(CurEntry.Lines[1].LineText, TextPos) ) + end + end end - end - --set the color - if(ColorType == 0) then - CurEntry.TextColor = Color(255,255,255) - else - CurEntry.TextColor = Color(130,255,158) - end + local TrimLine = { + LineText = string.Trim(ExplodeLine), + OffsetPos = { XPos, Line_Count*14 } --move the next text down some for each line + } + table.insert(CurEntry.Lines, TrimLine ) + Line_Count = Line_Count+1 - --put it in the table - table.insert(Entries, CurEntry) + end + end - --switch the color - ColorType = 1-ColorType + --set the color + if(ColorType == 0) then + CurEntry.TextColor = Color(255,255,255) + else + CurEntry.TextColor = Color(130,255,158) end + + --put it in the table + table.insert(Entries, CurEntry) + + --switch the color + ColorType = 1-ColorType end --determine the box width every second - if(LastBoxUpdate < CurTime()-1) then + if(LastBoxUpdate < CurTime()) then local LongestWidth = 0 local TextWidth, TextHeight for EntryIndex, Entry in ipairs(Entries) do @@ -508,7 +500,7 @@ if (CLIENT) then end end BoxWidth = LongestWidth+16 - LastBoxUpdate = CurTime() + LastBoxUpdate = CurTime()+1 end @@ -543,10 +535,12 @@ if (CLIENT) then end hook.Add("HUDPaint", "DebuggerDrawHUD", DebuggerDrawHUD) - net.Receive("WireDbgCount", function(len) - dbg_line_count = net.ReadUInt(16) + net.Receive("WireDbgCount", function(netlen) + for k=net.ReadUInt(16)+1, #dbg_lines do + dbg_lines[k] = nil + end end) - net.Receive("WireDbg", function(len) + net.Receive("WireDbg", function(netlen) dgb_orient_vert = net.ReadBit() != 0 dbg_lines[net.ReadUInt(16)] = net.ReadString() end) From 567b129ccfab36da77fd7fde76fc44b6f509aa9d Mon Sep 17 00:00:00 2001 From: Nebual Date: Tue, 30 Oct 2012 23:06:41 -0700 Subject: [PATCH 7/8] E2: Added more Ply:key* functions --- .../gmod_wire_expression2/core/player.lua | 48 +++++++++++++------ 1 file changed, 33 insertions(+), 15 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/core/player.lua b/lua/entities/gmod_wire_expression2/core/player.lua index 84c88485ae..65b53bb3fd 100644 --- a/lua/entities/gmod_wire_expression2/core/player.lua +++ b/lua/entities/gmod_wire_expression2/core/player.lua @@ -151,34 +151,52 @@ end /******************************************************************************/ +e2function number entity:keyForward() + return (IsValid(this) and this:IsPlayer() and this:KeyDown(IN_FORWARD)) and 1 or 0 +end + +e2function number entity:keyLeft() + return (IsValid(this) and this:IsPlayer() and this:KeyDown(IN_MOVELEFT)) and 1 or 0 +end + +e2function number entity:keyBack() + return (IsValid(this) and this:IsPlayer() and this:KeyDown(IN_BACK)) and 1 or 0 +end + +e2function number entity:keyRight() + return (IsValid(this) and this:IsPlayer() and this:KeyDown(IN_MOVERIGHT)) and 1 or 0 +end + +e2function number entity:keyJump() + return (IsValid(this) and this:IsPlayer() and this:KeyDown(IN_JUMP)) and 1 or 0 +end + e2function number entity:keyAttack1() - if not IsValid(this) then return 0 end - if this:IsPlayer() and this:KeyDown(1) then return 1 end -- IN_ATTACK - return 0 + return (IsValid(this) and this:IsPlayer() and this:KeyDown(IN_ATTACK)) and 1 or 0 end e2function number entity:keyAttack2() - if not IsValid(this) then return 0 end - if this:IsPlayer() and this:KeyDown(2048) then return 1 end -- IN_ATTACK2 - return 0 + return (IsValid(this) and this:IsPlayer() and this:KeyDown(IN_ATTACK2)) and 1 or 0 end e2function number entity:keyUse() - if not IsValid(this) then return 0 end - if this:IsPlayer() and this:KeyDown(32) then return 1 end -- IN_USE - return 0 + return (IsValid(this) and this:IsPlayer() and this:KeyDown(IN_USE)) and 1 or 0 end e2function number entity:keyReload() - if not IsValid(this) then return 0 end - if this:IsPlayer() and this:KeyDown( IN_RELOAD ) then return 1 end - return 0 + return (IsValid(this) and this:IsPlayer() and this:KeyDown(IN_RELOAD)) and 1 or 0 end e2function number entity:keyZoom() - if not IsValid(this) then return 0 end - if this:IsPlayer() and this:KeyDown( IN_ZOOM ) then return 1 end - return 0 + return (IsValid(this) and this:IsPlayer() and this:KeyDown(IN_ZOOM)) and 1 or 0 +end + +e2function number entity:keyWalk() + return (IsValid(this) and this:IsPlayer() and this:KeyDown(IN_WALK)) and 1 or 0 +end + +e2function number entity:keySprint() + return (IsValid(this) and this:IsPlayer() and this:KeyDown(IN_SPEED)) and 1 or 0 end -- isTyping From 840ed1a1bca4ea6fc8f7a61437bf5f95395d6b49 Mon Sep 17 00:00:00 2001 From: Nebual Date: Wed, 31 Oct 2012 00:43:17 -0700 Subject: [PATCH 8/8] E2: Restored holoScale's fidelity - Switched holoScale to using 3x net.WriteFloat rather than net.WriteVector - Fixes #93 --- lua/entities/gmod_wire_expression2/core/hologram.lua | 4 +++- lua/entities/gmod_wire_hologram/cl_init.lua | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lua/entities/gmod_wire_expression2/core/hologram.lua b/lua/entities/gmod_wire_expression2/core/hologram.lua index 243c1abd09..ae709fa7c7 100644 --- a/lua/entities/gmod_wire_expression2/core/hologram.lua +++ b/lua/entities/gmod_wire_expression2/core/hologram.lua @@ -141,7 +141,9 @@ local function flush_scale_queue(queue, recipient) net.Start("wire_holograms_set_scale") for _,Holo,scale in ipairs_map(queue, unpack) do net.WriteUInt(Holo.ent:EntIndex(), 16) - net.WriteVector(scale) -- These are more efficient than 3 floats + net.WriteFloat(scale.x) + net.WriteFloat(scale.y) + net.WriteFloat(scale.z) end net.WriteUInt(0, 16) if recipient then net.Send(recipient) else net.Broadcast() end diff --git a/lua/entities/gmod_wire_hologram/cl_init.lua b/lua/entities/gmod_wire_hologram/cl_init.lua index 95a4285fd9..a562b6319d 100644 --- a/lua/entities/gmod_wire_hologram/cl_init.lua +++ b/lua/entities/gmod_wire_hologram/cl_init.lua @@ -155,7 +155,7 @@ net.Receive("wire_holograms_set_scale", function( netlen ) local index = net.ReadUInt(16) while index ~= 0 do - SetScale(index, net.ReadVector()) + SetScale(index, Vector(net.ReadFloat(),net.ReadFloat(),net.ReadFloat())) index = net.ReadUInt(16) end end)