Skip to content

Commit

Permalink
Ok, I thought setting index to 0 was a good idea.
Browse files Browse the repository at this point in the history
Revert "Save wiremod holograms from NaN indexes"

This reverts commit d17a525.
  • Loading branch information
Zvbhrf committed Sep 6, 2024
1 parent c51d602 commit 6862b58
Showing 1 changed file with 27 additions and 43 deletions.
70 changes: 27 additions & 43 deletions lua/entities/gmod_wire_expression2/core/hologram.lua
Original file line number Diff line number Diff line change
Expand Up @@ -510,19 +510,6 @@ end)

-- -----------------------------------------------------------------------------

local MAX_INDEX = 2 ^ 31
local function makeAppropriateIndex(index)
if not isnumber(index) then
return 0
end

if index ~= index then
return 0
end

return math.Clamp(math.floor(index), -MAX_INDEX, MAX_INDEX)
end

local function MakeHolo(Player, Pos, Ang, model)
local prop = ents.Create( "gmod_wire_hologram" )
WireLib.setPos(prop, Pos)
Expand All @@ -535,17 +522,15 @@ end
-- Returns the hologram with the given index or nil if it doesn't exist.
-- if shouldbenil is nil or false, assert that the hologram exists on @strict with an error. Otherwise, don't check (for holo creation, etc)
local function CheckIndex(self, index, shouldbenil)
index = makeAppropriateIndex(index)

index = math.Clamp(math.floor(index), -2^31, 2^31)
local Holo
if index < 0 then
if index<0 then
Holo = E2HoloRepo[self.uid][-index]
else
Holo = self.data.holos[index]
end
if (not Holo or not IsValid(Holo.ent)) and not shouldbenil then return self:throw("Holo at index " .. index .. " does not exist!", nil) end

return Holo, index
return Holo
end

-- checks if a bone id is valid for a holo, throws an error for @strict if not.
Expand Down Expand Up @@ -576,8 +561,7 @@ local function CreateHolo(self, index, pos, scale, ang, color, model)

model = GetModel(self, model or "cube") or "models/holograms/cube.mdl"

local Holo, index = CheckIndex(self, index, true)

local Holo = CheckIndex(self, index, true)
if not Holo then
Holo = {}
SetIndex(self, index, Holo)
Expand All @@ -601,7 +585,7 @@ local function CreateHolo(self, index, pos, scale, ang, color, model)
Holo.e2owner = self

prop:CallOnRemove( "holo_cleanup", function( ent, self, index ) --Give the player more holograms if we get removed
local Holo, index = CheckIndex( self, index )
local Holo = CheckIndex( self, index )
if not Holo then return end

PlayerAmount[self.uid] = PlayerAmount[self.uid] - 1
Expand Down Expand Up @@ -692,7 +676,7 @@ __e2setcost(30) -- temporary
e2function entity holoCreate(index, vector position, vector scale, angle ang, vector color, string model)
if not checkOwner(self) then return end
if BlockList[self.player:SteamID()] == true or CheckSpawnTimer( self ) == false then return end
local Holo, index = CheckIndex(self, index, true)
local Holo = CheckIndex(self, index, true)
if not Holo and checkHoloCount(self) then return end

position = Vector(position[1], position[2], position[3])
Expand All @@ -704,7 +688,7 @@ end
e2function entity holoCreate(index, vector position, vector scale, angle ang, vector4 color, string model)
if not checkOwner(self) then return end
if BlockList[self.player:SteamID()] == true or CheckSpawnTimer( self ) == false then return end
local Holo, index = CheckIndex(self, index, true)
local Holo = CheckIndex(self, index, true)
if not Holo and checkHoloCount(self) then return end

position = Vector(position[1], position[2], position[3])
Expand All @@ -716,7 +700,7 @@ end
e2function entity holoCreate(index, vector position, vector scale, angle ang, vector color)
if not checkOwner(self) then return end
if BlockList[self.player:SteamID()] == true or CheckSpawnTimer( self ) == false then return end
local Holo, index = CheckIndex(self, index, true)
local Holo = CheckIndex(self, index, true)
if not Holo and checkHoloCount(self) then return end

position = Vector(position[1], position[2], position[3])
Expand All @@ -728,7 +712,7 @@ end
e2function entity holoCreate(index, vector position, vector scale, angle ang, vector4 color)
if not checkOwner(self) then return end
if BlockList[self.player:SteamID()] == true or CheckSpawnTimer( self ) == false then return end
local Holo, index = CheckIndex(self, index, true)
local Holo = CheckIndex(self, index, true)
if not Holo and checkHoloCount(self) then return end

position = Vector(position[1], position[2], position[3])
Expand All @@ -740,7 +724,7 @@ end
e2function entity holoCreate(index, vector position, vector scale, angle ang)
if not checkOwner(self) then return end
if BlockList[self.player:SteamID()] == true or CheckSpawnTimer( self ) == false then return end
local Holo, index = CheckIndex(self, index, true)
local Holo = CheckIndex(self, index, true)
if not Holo and checkHoloCount(self) then return end

position = Vector(position[1], position[2], position[3])
Expand All @@ -752,7 +736,7 @@ end
e2function entity holoCreate(index, vector position, vector scale)
if not checkOwner(self) then return end
if BlockList[self.player:SteamID()] == true or CheckSpawnTimer( self ) == false then return end
local Holo, index = CheckIndex(self, index, true)
local Holo = CheckIndex(self, index, true)
if not Holo and checkHoloCount(self) then return end

position = Vector(position[1],position[2],position[3])
Expand All @@ -763,7 +747,7 @@ end
e2function entity holoCreate(index, vector position)
if not checkOwner(self) then return end
if BlockList[self.player:SteamID()] == true or CheckSpawnTimer( self ) == false then return end
local Holo, index = CheckIndex(self, index, true)
local Holo = CheckIndex(self, index, true)
if not Holo and checkHoloCount(self) then return end

position = Vector(position[1],position[2],position[3])
Expand All @@ -774,7 +758,7 @@ end
e2function entity holoCreate(index)
if not checkOwner(self) then return end
if BlockList[self.player:SteamID()] == true or CheckSpawnTimer( self ) == false then return end
local Holo, index = CheckIndex(self, index, true)
local Holo = CheckIndex(self, index, true)
if not Holo and PlayerAmount[self.uid] >= wire_holograms_max:GetInt() then return end

local ret = CreateHolo(self, index)
Expand All @@ -783,7 +767,7 @@ end

__e2setcost(20)
e2function void holoDelete(index)
local Holo, index = CheckIndex(self, index)
local Holo = CheckIndex(self, index)
if not Holo then return end

remove_holo(Holo)
Expand All @@ -804,7 +788,7 @@ end
e2function void holoReset(index, string model, vector scale, vector color, string material)
model = GetModel(self, model)
if not model then return end
local Holo, index = CheckIndex(self, index)
local Holo = CheckIndex(self, index)
if not Holo then return end

Holo.ent:SetModel(model)
Expand Down Expand Up @@ -845,21 +829,21 @@ end
__e2setcost(30) -- temporary

e2function void holoScale(index, vector scale)
local Holo, index = CheckIndex(self, index)
local Holo = CheckIndex(self, index)
if not Holo then return end

rescale(Holo, scale)
end

e2function vector holoScale(index)
local Holo, index = CheckIndex(self, index)
local Holo = CheckIndex(self, index)
if not Holo then return end

return Holo.scale or Vector(0, 0, 0) -- TODO: maybe 1,1,1?
end

e2function void holoScaleUnits(index, vector size)
local Holo, index = CheckIndex(self, index)
local Holo = CheckIndex(self, index)
if not Holo then return end

local propsize = Holo.ent:OBBMaxs()-Holo.ent:OBBMins()
Expand All @@ -872,7 +856,7 @@ e2function void holoScaleUnits(index, vector size)
end

e2function vector holoScaleUnits(index)
local Holo, index = CheckIndex(self, index)
local Holo = CheckIndex(self, index)
if not Holo then return self:throw("Holo at index " .. index .. " does not exist!", Vector(0, 0, 0)) end

local scale = Holo.scale or Vector(0, 0, 0) -- TODO: maybe 1,1,1?
Expand All @@ -885,15 +869,15 @@ end
-- -----------------------------------------------------------------------------

e2function void holoBoneScale(index, boneindex, vector scale)
local Holo, index = CheckIndex(self, index)
local Holo = CheckIndex(self, index)
if not Holo then return end
if not CheckBone(self, index, boneindex, Holo) then return end

rescale(Holo, nil, {boneindex, scale})
end

e2function void holoBoneScale(index, string bone, vector scale)
local Holo, index = CheckIndex(self, index)
local Holo = CheckIndex(self, index)
if not Holo then return end
local boneindex = Holo.ent:LookupBone(bone)
if boneindex == nil then return self:throw("Holo at index " .. index .. " does not have a bone ['" .. bone .. "']!", nil) end
Expand All @@ -902,15 +886,15 @@ e2function void holoBoneScale(index, string bone, vector scale)
end

e2function vector holoBoneScale(index, boneindex)
local Holo, index = CheckIndex(self, index)
local Holo = CheckIndex(self, index)
if not Holo then return Vector(0, 0, 0) end
if not CheckBone(self, index, boneindex, Holo) then return Vector(0, 0, 0) end

return Holo.bone_scale[boneindex] or Vector(1, 1, 1)
end

e2function vector holoBoneScale(index, string bone)
local Holo, index = CheckIndex(self, index)
local Holo = CheckIndex(self, index)
if not Holo then return Vector(0, 0, 0) end
local boneindex = Holo.ent:LookupBone(bone)

Expand All @@ -919,7 +903,7 @@ e2function vector holoBoneScale(index, string bone)
end

e2function vector holoBonePos(index, boneindex)
local Holo, index = CheckIndex(self, index)
local Holo = CheckIndex(self, index)
if not Holo then return Vector(0, 0, 0) end
if not CheckBone(self, index, boneindex, Holo) then return Vector(0, 0, 0) end

Expand All @@ -928,7 +912,7 @@ end


e2function vector holoBonePos(index, string bone)
local Holo, index = CheckIndex(self, index)
local Holo = CheckIndex(self, index)
if not Holo then return self:throw("Holo at index " .. index .. " does not exist!", Vector(0, 0, 0)) end

local boneindex = Holo.ent:LookupBone(bone)
Expand All @@ -937,7 +921,7 @@ e2function vector holoBonePos(index, string bone)
end

e2function angle holoBoneAng(index, boneindex)
local Holo, index = CheckIndex(self, index)
local Holo = CheckIndex(self, index)
if not Holo then return Angle(0, 0, 0) end
if not CheckBone(self, index, boneindex, Holo) then return Angle(0, 0, 0) end

Expand All @@ -946,7 +930,7 @@ end


e2function angle holoBoneAng(index, string bone)
local Holo, index = CheckIndex(self, index)
local Holo = CheckIndex(self, index)
if not Holo then return self:throw("Holo at index " .. index .. " does not exist!", Angle(0, 0, 0)) end

local boneindex = Holo.ent:LookupBone(bone)
Expand Down

0 comments on commit 6862b58

Please sign in to comment.