Skip to content

Commit

Permalink
Merge pull request #1343 from wiremod/master-2016-08-21-23-50-50
Browse files Browse the repository at this point in the history
Update Workshop to Include recent changes (Redo of the update from 2016-08-21 23:50:50)
  • Loading branch information
Divran authored Mar 7, 2017
2 parents 1d91864 + 0b3367e commit 83ab802
Show file tree
Hide file tree
Showing 28 changed files with 524 additions and 308 deletions.
276 changes: 149 additions & 127 deletions lua/entities/gmod_wire_cameracontroller.lua

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion lua/entities/gmod_wire_colorer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ function ENT:TriggerInput(iname, value)
filter = { self }
}
if not IsValid(trace.Entity) then return end
if not hook.Run( "CanTool", self:GetOwner(), trace, "colour" ) then return end
if not hook.Run( "CanTool", self:GetPlayer(), trace, "colour" ) then return end

if trace.Entity:IsPlayer() then
trace.Entity:SetColor(Color(self.InColor.r, self.InColor.g, self.InColor.b, 255))
Expand Down
18 changes: 9 additions & 9 deletions lua/entities/gmod_wire_expression2/base/preprocessor.lua
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ end
function PreProcessor:FindComments(line)
local ret, count, pos, found = {}, 0, 1, nil
repeat
found = line:find('[#"]', pos)
found = line:find('[#"\\]', pos)
if found then -- We found something
local char = line:sub(found, found)
if char == "#" then -- We found a comment
Expand All @@ -67,13 +67,11 @@ function PreProcessor:FindComments(line)
end
elseif char == '"' then -- We found a string
local before = line:sub(found - 1, found - 1)
if before == "\\" and line:sub(found - 2, found - 2) ~= "\\" then -- It was an escaped character
pos = found + 1 -- Skip it
else -- It's a string
count = count + 1
ret[count] = { type = "string", pos = found }
pos = found + 1
end
count = count + 1
ret[count] = { type = "string", pos = found }
pos = found + 1
elseif char == '\\' then -- We found an escape character
pos = found + 2 -- Skip the escape character and the character following it
end
end
until (not found)
Expand Down Expand Up @@ -292,9 +290,11 @@ function PreProcessor:ParsePorts(ports, startoffset)
local names = {}
local types = {}
local columns = {}

-- Preprocess [Foo Bar]:entity into [Foo,Bar]:entity so we don't have to deal with split-up multi-variable definitions in the main loop
ports = ports:gsub("%[.-%]", function(s)
return s:gsub(" ", ",")
end) -- preprocess multi-variable definitions.
end)

for column, key in ports:gmatch("()([^ ]+)") do
column = startoffset + column
Expand Down
10 changes: 5 additions & 5 deletions lua/entities/gmod_wire_expression2/core/array.lua
Original file line number Diff line number Diff line change
Expand Up @@ -410,8 +410,8 @@ e2function number array:minIndex()
for k,v in pairs( this ) do
indexes = indexes + 1
local val = tonumber(v) or 0
if (num == nil or v < num) then
num = v
if (num == nil or val < num) then
num = val
index = k
end
end
Expand Down Expand Up @@ -469,12 +469,12 @@ local clamp = math.Clamp
local function concat( tab, delimeter, startindex, endindex )
local ret = {}
local len = #tab

startindex = startindex or 1
if startindex > len then return "" end

endindex = clamp(endindex or len, startindex, len)

for i=startindex, endindex do
ret[#ret+1] = tostring(tab[i])
end
Expand Down
7 changes: 7 additions & 0 deletions lua/entities/gmod_wire_expression2/core/bone.lua
Original file line number Diff line number Diff line change
Expand Up @@ -308,11 +308,14 @@ end
--[[************************************************************************]]--
__e2setcost(30)

local check = WireLib.checkForce

--- Applies force to <this> according to <force>'s direction and magnitude
e2function void bone:applyForce(vector force)
local ent = isValidBone(this)
if not ent then return end
if not isOwner(self, ent) then return end
if not check(force) then return end
this:ApplyForceCenter(Vector(force[1], force[2], force[3]))
end

Expand All @@ -321,6 +324,7 @@ e2function void bone:applyOffsetForce(vector force, vector pos)
local ent = isValidBone(this)
if not ent then return end
if not isOwner(self, ent) then return end
if not check(force) or not check(pos) then return end
this:ApplyForceOffset(Vector(force[1], force[2], force[3]), Vector(pos[1], pos[2], pos[3]))
end

Expand All @@ -331,6 +335,7 @@ e2function void bone:applyAngForce(angle angForce)
if not isOwner(self, ent) then return end

if angForce[1] == 0 and angForce[2] == 0 and angForce[3] == 0 then return end
if not check(angForce) then return end

-- assign vectors
local pos = this:GetPos()
Expand Down Expand Up @@ -368,6 +373,7 @@ e2function void bone:applyTorque(vector torque)
local phys = this

if torque[1] == 0 and torque[2] == 0 and torque[3] == 0 then return end
if not check(torque) then return end

local tq = Vector(torque[1], torque[2], torque[3])
local torqueamount = tq:Length()
Expand All @@ -386,6 +392,7 @@ e2function void bone:applyTorque(vector torque)

local dir = ( tq:Cross(off) ):GetNormal()

if not check( dir ) or not check( off ) then return end
phys:ApplyForceOffset( dir, off )
phys:ApplyForceOffset( dir * -1, off * -1 )
end
Expand Down
7 changes: 7 additions & 0 deletions lua/entities/gmod_wire_expression2/core/compat.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,18 +28,23 @@ end

__e2setcost(30) -- temporary

local check = WireLib.checkForce

e2function void applyForce(vector force)
if not check(force) then return end
local phys = self.entity:GetPhysicsObject()
phys:ApplyForceCenter(Vector(force[1],force[2],force[3]))
end

e2function void applyOffsetForce(vector force, vector position)
if not check(force) or not check(position) then return end
local phys = self.entity:GetPhysicsObject()
phys:ApplyForceOffset(Vector(force[1],force[2],force[3]), Vector(position[1],position[2],position[3]))
end

e2function void applyAngForce(angle angForce)
if angForce[1] == 0 and angForce[2] == 0 and angForce[3] == 0 then return end
if not check(angForce) then return end

local ent = self.entity
local phys = ent:GetPhysicsObject()
Expand Down Expand Up @@ -73,6 +78,7 @@ end

e2function void applyTorque(vector torque)
if torque[1] == 0 and torque[2] == 0 and torque[3] == 0 then return end
if not check( torque ) then return end

local phys = self.entity:GetPhysicsObject()

Expand All @@ -93,6 +99,7 @@ e2function void applyTorque(vector torque)

local dir = ( tq:Cross(off) ):GetNormal()

if not check( dir ) or not check( off ) then return end
phys:ApplyForceOffset( dir, off )
phys:ApplyForceOffset( dir * -1, off * -1 )
end
Expand Down
13 changes: 9 additions & 4 deletions lua/entities/gmod_wire_expression2/core/core.lua
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,11 @@ __e2setcost(100) -- approximation
e2function void reset()
if self.data.last or self.entity.first then error("exit", 0) end

if self.entity.last_reset and self.entity.last_reset == CurTime() then
error("Attempted to reset the E2 twice in the same tick!", 2)
end
self.entity.last_reset = CurTime()

self.data.reset = true
error("exit", 0)
end
Expand Down Expand Up @@ -526,16 +531,16 @@ end)

registerOperator("include", "", "", function(self, args)
local Include = self.includes[ args[2] ]

if Include and Include[2] then
local Script = Include[2]

local OldScopes = self:SaveScopes()
self:InitScope() -- Create a new Scope Enviroment
self:PushScope()

Script[1](self, Script)

self:PopScope()
self:LoadScopes(OldScopes)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,20 @@ language.Add("Undone_e2_slider", "Undone E2 Slider")
language.Add("Undone_e2_nocollide", "Undone E2 Nocollide")
language.Add("Undone_e2_weld", "Undone E2 Weld")
E2Helper.Descriptions["enableConstraintUndo"] = "If 0, suppresses creation of undo entries for constraints"
E2Helper.Descriptions["axis"] = "Creates an axis constraint between two entities at vectors local to each entity"
E2Helper.Descriptions["axis(evev)"] = "Creates an axis constraint between two entities at vectors local to each entity"
E2Helper.Descriptions["axis(evevn)"] = "Creates an axis constraint between two entities at vectors local to each entity with friction"
E2Helper.Descriptions["axis(evevnv)"] = "Creates an axis constraint between two entities at vectors local to each entity with friction and local rotation axis"
E2Helper.Descriptions["ballsocket"] = "Creates a ballsocket constraint between two entities at a vector local to ent1"
E2Helper.Descriptions["ballsocket(evevvv)"] = "Creates an AdvBallsocket constraint between two entities at a vector local to ent1, using the specified mins, maxs, and frictions)"
E2Helper.Descriptions["ballsocket(evevvvn)"] = "Creates an AdvBallsocket constraint between two entities at a vector local to ent1, using the specified mins, maxs, frictions, rotateonly)"
E2Helper.Descriptions["weldAng"] = "Creates an angular weld constraint (angles are fixed, position is free) between two entities at a vector local to ent1"
E2Helper.Descriptions["winch"] = "Creates a winch constraint with a referenceid, between two entities, at vectors local to each"
E2Helper.Descriptions["hydraulic"] = "Creates a hydraulic constraint with a referenceid, between two entities, at vectors local to each"
E2Helper.Descriptions["rope"] = "Creates a rope constraint with a referenceid, between two entities, at vectors local to each"
E2Helper.Descriptions["hydraulic(nevevn)"] = "Creates a hydraulic constraint with a referenceid, between two entities, at vectors local to each"
E2Helper.Descriptions["hydraulic(nevevnnsnn)"] = "Creates a hydraulic constraint with a referenceid, between two entities, at vectors local to each, with constant, damping, and stretch only"
E2Helper.Descriptions["hydraulic(nevevnnnsnn)"] = "Creates a hydraulic constraint with a referenceid, between two entities, at vectors local to each, with constant, damping, relative damping and stretch only"
E2Helper.Descriptions["rope(nevev)"] = "Creates a rope constraint with a referenceid, between two entities, at vectors local to each"
E2Helper.Descriptions["rope(nevevnns)"] = "Creates a rope constraint with a referenceid, between two entities, at vectors local to each with add length, width, and material"
E2Helper.Descriptions["rope(nevevnnsn)"] = "Creates a rope constraint with a referenceid, between two entities, at vectors local to each with add length, width, material, and rigidity"
E2Helper.Descriptions["setLength(e:nn)"] = "Sets the length of a winch/hydraulic/rope stored in this entity at a referenceid"
E2Helper.Descriptions["slider"] = "Creates a slider constraint between two entities at vectors local to each entity"
E2Helper.Descriptions["noCollide"] = "Creates a nocollide constraint between two entities"
Expand Down
116 changes: 106 additions & 10 deletions lua/entities/gmod_wire_expression2/core/custom/constraintcore.lua
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,25 @@ __e2setcost(30)

--- Creates an axis between <ent1> and <ent2> at vector positions local to each ent.
e2function void axis(entity ent1, vector v1, entity ent2, vector v2)
if !checkEnts(self, ent1, ent2) then return end
if not checkEnts(self, ent1, ent2) then return end
local vec1, vec2 = Vector(v1[1], v1[2], v1[3]), Vector(v2[1], v2[2], v2[3])
addundo(self, constraint.Axis(ent1, ent2, 0, 0, vec1, vec2, 0, 0, 0, 0), "axis")
end

--- Creates an axis between <ent1> and <ent2> at vector positions local to each ent, with <friction> friction.
e2function void axis(entity ent1, vector v1, entity ent2, vector v2, friction)
if !checkEnts(self, ent1, ent2) then return end
if not checkEnts(self, ent1, ent2) then return end
local vec1, vec2 = Vector(v1[1], v1[2], v1[3]), Vector(v2[1], v2[2], v2[3])
addundo(self, constraint.Axis(ent1, ent2, 0, 0, vec1, vec2, 0, 0, friction, 0), "axis")
end

--- Creates an axis between <ent1> and <ent2> at vector positions local to each ent, with <friction> friction and <localaxis> rotation axis.
e2function void axis(entity ent1, vector v1, entity ent2, vector v2, friction, vector localaxis)
if not checkEnts(self, ent1, ent2) then return end
local vec1, vec2, laxis = Vector(v1[1], v1[2], v1[3]), Vector(v2[1], v2[2], v2[3]), Vector(localaxis[1], localaxis[2], localaxis[3])
addundo(self, constraint.Axis(ent1, ent2, 0, 0, vec1, vec2, 0, 0, friction, 0, laxis), "axis")
end

--- Creates a ballsocket between <ent1> and <ent2> at <v>, which is local to <ent1>
e2function void ballsocket(entity ent1, vector v, entity ent2)
if !checkEnts(self, ent1, ent2) then return end
Expand Down Expand Up @@ -134,11 +141,43 @@ e2function void hydraulic(index, entity ent1, vector v1, entity ent2, vector v2,
addundo(self, ent1.data.Ropes[index], "hydraulic")
end

--- Makes a hydraulic constraint (stored at index <index>) between <ent1> and <ent2>, at vectors local to their respective ents, constant and damping, with <width> width, <mat> material, and <stretch> stretch only option.
e2function void hydraulic(index, entity ent1, vector v1, entity ent2, vector v2, constant, damping, string mat, width, stretch)
if not checkEnts(self, ent1, ent2) then return end
if not ent1.data then ent1.data = {} end
if not ent1.data.Ropes then ent1.data.Ropes = {} end
local vec1, vec2 = Vector(v1[1],v1[2],v1[3]), Vector(v2[1],v2[2],v2[3])
if width < 0 or width > 50 then width = 1 end

if IsValid(ent1.data.Ropes[index]) then
ent1.data.Ropes[index]:Remove()
end

ent1.data.Ropes[index] = constraint.Elastic( ent1, ent2, 0, 0, vec1, vec2, constant, damping, 0, mat, width, tobool(stretch) )
addundo(self, ent1.data.Ropes[index], "hydraulic")
end

--- Makes a hydraulic constraint (stored at index <index>) between <ent1> and <ent2>, at vectors local to their respective ents, constant, damping and relative damping, with <width> width, <mat> material, and <stretch> stretch only option.
e2function void hydraulic(index, entity ent1, vector v1, entity ent2, vector v2, constant, damping, rdamping, string mat, width, stretch)
if not checkEnts(self, ent1, ent2) then return end
if not ent1.data then ent1.data = {} end
if not ent1.data.Ropes then ent1.data.Ropes = {} end
local vec1, vec2 = Vector(v1[1],v1[2],v1[3]), Vector(v2[1],v2[2],v2[3])
if width < 0 or width > 50 then width = 1 end

if IsValid(ent1.data.Ropes[index]) then
ent1.data.Ropes[index]:Remove()
end

ent1.data.Ropes[index] = constraint.Elastic( ent1, ent2, 0, 0, vec1, vec2, constant, damping, rdamping, mat, width, tobool(stretch) )
addundo(self, ent1.data.Ropes[index], "hydraulic")
end

--- Creates a rope between <ent1> and <ent2> at vector positions local to each ent.
e2function void rope(index, entity ent1, vector v1, entity ent2, vector v2)
if !checkEnts(self, ent1, ent2) then return end
if !ent1.data then ent1.data = {} end
if !ent1.data.Ropes then ent1.data.Ropes = {} end
if not checkEnts(self, ent1, ent2) then return end
if not ent1.data then ent1.data = {} end
if not ent1.data.Ropes then ent1.data.Ropes = {} end
local vec1, vec2 = Vector(v1[1], v1[2], v1[3]), Vector(v2[1], v2[2], v2[3])
local length = (ent1:LocalToWorld(vec1) - ent2:LocalToWorld(vec2)):Length()

Expand All @@ -152,9 +191,9 @@ end

--- Creates a rope between <ent1> and <ent2> at vector positions local to each ent, with <addlength> additional length, <width> width, and <mat> material.
e2function void rope(index, entity ent1, vector v1, entity ent2, vector v2, addlength, width, string mat)
if !checkEnts(self, ent1, ent2) then return end
if !ent1.data then ent1.data = {} end
if !ent1.data.Ropes then ent1.data.Ropes = {} end
if not checkEnts(self, ent1, ent2) then return end
if not ent1.data then ent1.data = {} end
if not ent1.data.Ropes then ent1.data.Ropes = {} end
local vec1, vec2 = Vector(v1[1], v1[2], v1[3]), Vector(v2[1], v2[2], v2[3])
local length = (ent1:LocalToWorld(vec1) - ent2:LocalToWorld(vec2)):Length()

Expand All @@ -166,12 +205,28 @@ e2function void rope(index, entity ent1, vector v1, entity ent2, vector v2, addl
addundo(self, ent1.data.Ropes[index], "rope")
end

--- Creates a rope between <ent1> and <ent2> at vector positions local to each ent, with <addlength> additional length, <width> width, and <mat> material.
e2function void rope(index, entity ent1, vector v1, entity ent2, vector v2, addlength, width, string mat, rigid )
if not checkEnts(self, ent1, ent2) then return end
if not ent1.data then ent1.data = {} end
if not ent1.data.Ropes then ent1.data.Ropes = {} end
local vec1, vec2 = Vector(v1[1], v1[2], v1[3]), Vector(v2[1], v2[2], v2[3])
local length = (ent1:LocalToWorld(vec1) - ent2:LocalToWorld(vec2)):Length()

if IsValid(ent1.data.Ropes[index]) then
ent1.data.Ropes[index]:Remove()
end

ent1.data.Ropes[index] = constraint.Rope( ent1, ent2, 0, 0, vec1, vec2, length, addlength, 0, width, mat, tobool(rigid) )
addundo(self, ent1.data.Ropes[index], "rope")
end

__e2setcost(5)

--- Sets a rope/hydraulic/winch stored at index <index> inside <this> (the first entity) to be <length> long.
e2function void entity:setLength(index, length)
if !IsValid(this) then return end
if !isOwner(self, this) then return false end
if not IsValid(this) then return end
if not isOwner(self, this) then return false end
if length < 0 then length = 0 end
if this.data.Ropes then
local con = this.data.Ropes[index]
Expand All @@ -185,6 +240,47 @@ e2function void entity:setLength(index, length)
end
end

--- Sets a hydraulic/winch stored at index <index> inside <this> (the first entity) to be <constant> constant.
e2function void entity:setConstant(index, constant)
if not IsValid(this) then return end
if not isOwner(self, this) then return false end
if constant < 0 then constant = 0 end
if this.data.Ropes then
local con = this.data.Ropes[index]
if IsValid(con) then
con:Fire("SetSpringConstant", constant, 0)
end
end
end

--- Sets a hydraulic/winch stored at index <index> inside <this> (the first entity) to be <constant> constant and <dampen> damping.
e2function void entity:setConstant(index, constant, damping)
if not IsValid(this) then return end
if not isOwner(self, this) then return false end
if constant < 0 then constant = 0 end
if damping < 0 then damping = 0 end
if this.data.Ropes then
local con = this.data.Ropes[index]
if IsValid(con) then
con:Fire("SetSpringConstant", constant, 0)
con:Fire("SetSpringDamping", damping, 0)
end
end
end

--- Sets a hydraulic/winch stored at index <index> inside <this> (the first entity) to be <dampen> damping.
e2function void entity:setDamping(index, damping)
if not IsValid(this) then return end
if not isOwner(self, this) then return false end
if damping < 0 then damping = 0 end
if this.data.Ropes then
local con = this.data.Ropes[index]
if IsValid(con) then
con:Fire("SetSpringDamping", damping, 0)
end
end
end

__e2setcost(30)

--- Creates a slider between <ent1> and <ent2> at vector positions local to each ent.
Expand Down
Loading

0 comments on commit 83ab802

Please sign in to comment.