Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 4 additions & 2 deletions entities/effects/lambda_pointer.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ EFFECT.Mat2 = Material("lambda/ring2.png")
EFFECT.Mat3 = Material("lambda/ring3.png")
EFFECT.Mat4 = Material("lambda/run_point.vmt")

local math_clamp = math.Clamp

function EFFECT:Init(data)
local size = 64
local ply = data:GetEntity()
Expand Down Expand Up @@ -48,8 +50,8 @@ function EFFECT:Render()
render.DrawQuadEasy(self:GetPos() + normal, normal, self.Size, self.Size, Color(255, 255, 255, (self.Alpha ^ 1.1) * 255), self.Alpha * 500)
render.SetMaterial(self.Mat3)
render.DrawQuadEasy(self:GetPos() + normal, normal, self.Size, self.Size, Color(255, 255, 255, (self.Alpha ^ 1.1) * 255), -(self.Alpha * 800))
local signsize = math.Clamp(dist / 20, self.Size / 2, self.Size * 5)
local offset_z = math.Clamp(dist / 20, 50, 200)
local signsize = math_clamp(dist / 20, self.Size / 2, self.Size * 5)
local offset_z = math_clamp(dist / 20, 50, 200)
render.SetMaterial(self.Mat4)
render.DrawQuadEasy(self:GetPos() + (dir:Forward() * (offset_z + self.Dist)), ang, signsize, signsize, Color(255, 255, 255, (self.Alpha ^ 1.1) * 255), 180)
end
16 changes: 12 additions & 4 deletions entities/entities/lambda_npcmaker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ local math = math
local ents = ents
local player = player
local IsValid = IsValid
local math_clamp = math.Clamp

DEFINE_BASECLASS("lambda_entity")
ENT.Base = "lambda_entity"
ENT.Type = "point"
Expand Down Expand Up @@ -177,8 +179,11 @@ function ENT:GetScaledMaxLiveChildren()
local maxLiveChildren = self:GetNWVar("MaxLiveChildren")
local maxScaledLiveChildren = self:GetNWVar("MaxScaledLiveChildren")
local scaledCount = self:GetScaleCount()
local res = math.Clamp(maxLiveChildren + scaledCount, 0, 100)
if maxScaledLiveChildren > 0 then res = math.Clamp(res, 0, maxScaledLiveChildren) end
local res = math_clamp(maxLiveChildren + scaledCount, 0, 100)
if maxScaledLiveChildren > 0 then
res = math_clamp(res, 0, maxScaledLiveChildren)
end

self.CachedMaxLiveChildren = res
return res
end
Expand All @@ -188,8 +193,11 @@ function ENT:GetScaledMaxNPCs()
local maxNPCCount = self:GetNWVar("MaxNPCCount")
local maxScaledNPCCount = self:GetNWVar("MaxScaledNPCCount")
local scaledCount = self:GetScaleCount()
local res = math.Clamp(maxNPCCount + scaledCount, 0, 100)
if maxScaledNPCCount > 0 then res = math.Clamp(res, 0, maxScaledNPCCount) end
local res = math_clamp(maxNPCCount + scaledCount, 0, 100)
if maxScaledNPCCount > 0 then
res = math_clamp(res, 0, maxScaledNPCCount)
end

self.CachedMaxNPCCount = res
return res
end
Expand Down
5 changes: 3 additions & 2 deletions entities/entities/lambda_player_tracker.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ end
local IsValid = IsValid
local Vector = Vector
local util = util
local math = math
local math_clamp = math.Clamp

ENT.Base = "base_anim"
ENT.Type = "anim"
ENT.RenderGroup = RENDERGROUP_TRANSLUCENT
Expand Down Expand Up @@ -182,7 +183,7 @@ if CLIENT then
ang:RotateAroundAxis(ang:Forward(), 90)
ang:RotateAroundAxis(ang:Right(), 90)
local dist = pos:Distance(localPly:GetPos())
dist = math.Clamp(dist, 0, 3000)
dist = math_clamp(dist, 0, 3000)
local distScale = (2 * (dist / 3000))
local distZ = distScale * 50
local scale = 0.12 + distScale
Expand Down
8 changes: 5 additions & 3 deletions entities/weapons/weapon_lambda_medkit.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ if SERVER then
end

local DbgPrint = GetLogging("Medkit")
local math_clamp = math.Clamp

SWEP.PrintName = "Medkit"
SWEP.Author = "Lambda"
SWEP.Instructions = ""
Expand Down Expand Up @@ -113,7 +115,7 @@ function SWEP:Recharge()
self:SetNextRechargeTime(CurTime() + RECHARGE_DELAY)

local currentEnergy = self:GetEnergy()
local energy = math.Clamp(currentEnergy + RECHARGE_AMOUNT, 0, RECHARGE_TARGET)
local energy = math_clamp(currentEnergy + RECHARGE_AMOUNT, 0, RECHARGE_TARGET)
self:SetEnergy(energy)

if energy >= RECHARGE_TARGET then
Expand Down Expand Up @@ -322,7 +324,7 @@ end

function SWEP:ConsumeEnergy(amount)
local energy = self:GetEnergy()
energy = math.Clamp(energy - amount, 0, 100)
energy = math_clamp(energy - amount, 0, 100)
self:SetEnergy(energy)
end

Expand Down Expand Up @@ -596,7 +598,7 @@ function SWEP:PreDrawViewModel(vm, wep, ply)
self.EnergyLevel = math.Approach(self.EnergyLevel or 0, energy, FrameTime() * 100)

self.ChargeBlink = math.Approach(self.ChargeBlink, 0, FrameTime() * 350)
local glow = math.Clamp(self.EnergyLevel / 100, 0, 1)
local glow = math_clamp(self.EnergyLevel / 100, 0, 1)
local c = Color(0, 255, 0, 255)
c.r = (255 * (1 - glow)) * 1
c.g = ((1000 * glow) - (c.r * 0.8))
Expand Down
3 changes: 2 additions & 1 deletion entities/weapons/weapon_physcannon.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ local TraceLine = util.TraceLine
local TraceHull = util.TraceHull
local Color = Color
local CurTime = CurTime
local math_clamp = math.Clamp
local EffectsInvalidated = false
local TraceMask = bor(MASK_SHOT, CONTENTS_GRATE)
local ATTACHMENTS_GAPS_FP = {"fork1t", "fork2t"}
Expand Down Expand Up @@ -809,7 +810,7 @@ function SWEP:UpdateObject()
if attachedObject:IsEFlagSet(EFL_NO_PHYSCANNON_INTERACTION) == true then return false end
if owner:GetGroundEntity() == attachedObject then return false end
local fwd = owner:GetAimVector()
fwd.x = math.Clamp(fwd.x, -75, 75)
fwd.x = math_clamp(fwd.x, -75, 75)
local start = owner:GetShootPos()
local minDist = 24
local playerLen = owner:OBBMaxs():Length2D()
Expand Down
16 changes: 13 additions & 3 deletions gamemode/cl_init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ local CurTime = CurTime
local Vector = Vector
local math = math
local IsValid = IsValid
local math_clamp = math.Clamp

-- This is nasty
function GM:OnSpawnMenuOpen()
RunConsoleCommand("lastinv")
Expand Down Expand Up @@ -96,7 +98,7 @@ function GM:CalcViewModelBob(wep, vm, oldPos, oldAng, pos, ang)
speed = Lerp(dt * 2, self.LastPlayerSpeed, 0)
end

speed = math.Clamp(speed, -MAX_SPEED, MAX_SPEED)
speed = math_clamp(speed, -MAX_SPEED, MAX_SPEED)
self.LastPlayerSpeed = speed
local bob_offset = math.Remap(speed, 0, MAX_SPEED, 0.0, 1.0)
self.ViewBobTime = (self.ViewBobTime or 0) + (dt * 1.3) * bob_offset
Expand All @@ -110,7 +112,7 @@ function GM:CalcViewModelBob(wep, vm, oldPos, oldAng, pos, ang)

local vertBob = speed * 0.005
vertBob = vertBob * 0.3 + vertBob * 0.7 * math.sin(cycle)
vertBob = math.Clamp(vertBob, -7.0, 4.0)
vertBob = math_clamp(vertBob, -7.0, 4.0)
cycle = self.ViewBobTime - math.Round(self.ViewBobTime / HL2_BOB_CYCLE_MAX * 2, 0) * HL2_BOB_CYCLE_MAX * 2
cycle = cycle / (HL2_BOB_CYCLE_MAX * 2)
if cycle < HL2_BOB_UP then
Expand All @@ -121,7 +123,7 @@ function GM:CalcViewModelBob(wep, vm, oldPos, oldAng, pos, ang)

local lateralBob = speed * 0.005
lateralBob = lateralBob * 0.3 + lateralBob * 0.7 * math.sin(cycle)
lateralBob = math.Clamp(lateralBob, -7.0, 4.0)
lateralBob = math_clamp(lateralBob, -7.0, 4.0)
local fwd = oldAng:Forward()
local right = oldAng:Right()
local newPos = oldPos + (fwd * (vertBob * 0.1))
Expand Down Expand Up @@ -339,6 +341,14 @@ function GM:ShouldDrawLocalPlayer(ply)
if viewlock == VIEWLOCK_SETTINGS_ON or viewlock == VIEWLOCK_SETTINGS_RELEASE then return true end
end

function GM:PrePlayerDraw(ply)
-- TODO: If the player is close to our camera we should disable
-- rendering of the player model to avoid clipping issues.
end

function GM:PostPlayerDraw(ply)
end

function GM:OnContextMenuOpen()
self:ShowTauntSelection(true)
end
Expand Down
3 changes: 2 additions & 1 deletion gamemode/cl_postprocess.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
local CurTime = CurTime
local Vector = Vector
local math = math
local math_clamp = math.Clamp
local IsValid = IsValid
GRAIN_RT = GRAIN_RT or GetRenderTarget("LambdaFilmGrain", ScrW(), ScrH(), true)

Expand Down Expand Up @@ -49,7 +50,7 @@ local LAST_GEIGER_RANGE = 1000

function GM:RenderRadiationEffects(ply)
GenerateFilmGrain()
local curGeigerRange = math.Clamp(ply:GetGeigerRange() * 4, 0, 1000)
local curGeigerRange = math_clamp(ply:GetGeigerRange() * 4, 0, 1000)
local geigerRange = Lerp(FrameTime(), LAST_GEIGER_RANGE, curGeigerRange)
LAST_GEIGER_RANGE = geigerRange
local rv = LAST_GEIGER_RANGE / 1000
Expand Down
2 changes: 1 addition & 1 deletion gamemode/cl_taunts.lua
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ function GM:TauntSelectionInput(ply, bind, pressed)
if taunts == nil then
return
end
tauntIndex = math.Clamp(tauntIndex, 1, #taunts)
tauntIndex = math_Clamp(tauntIndex, 1, #taunts)
TauntIndex:SetInt(tauntIndex)
end

Expand Down
5 changes: 3 additions & 2 deletions gamemode/huds/hud_deathnotice.lua
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ local Color_Icon = Color(230, 230, 230, 130)
local NPC_Color = Color(250, 50, 50, 255)
local times_color = Color(255, 255, 255, 255)
local font = "LambdaKillFont"
local math_Clamp = math.Clamp

local function CreateFonts()
surface.CreateFont(font, {
Expand Down Expand Up @@ -245,7 +246,7 @@ local function ComputeDeathNoticeSize(death, bounds)
end

local function DrawDeathEntry(bounds, y, data, margin, remaining)
local alpha = math.Clamp(remaining * 255, 0, 255)
local alpha = math_Clamp(remaining * 255, 0, 255)
data.color1.a = alpha
data.color2.a = alpha
times_color.a = alpha
Expand Down Expand Up @@ -324,7 +325,7 @@ function GM:DrawDeathNotice()
local remaining = 1.0

if elapsed > visibleTime then
remaining = math.Clamp(1.0 - ((elapsed - visibleTime) / fadeTime), 0.0, 1.0)
remaining = math_Clamp(1.0 - ((elapsed - visibleTime) / fadeTime), 0.0, 1.0)
end

if remaining > 0.0 then
Expand Down
5 changes: 4 additions & 1 deletion gamemode/huds/hud_health.lua
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
include("hud_numeric.lua")

local math_Clamp = math.Clamp

local PANEL = {}

function PANEL:Init()
Expand Down Expand Up @@ -52,7 +55,7 @@ function PANEL:Think()
end
end

local health = math.Clamp(ply:Health(), 0, ply:GetMaxHealth())
local health = math_Clamp(ply:Health(), 0, ply:GetMaxHealth())
if health == self.LastHealth then return end
self.LastHealth = health

Expand Down
17 changes: 10 additions & 7 deletions gamemode/huds/hud_hint.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
local math_Clamp = math.Clamp
local math_Round = math.Round

GM.HintHistory = {}
GM.HintHistoryLast = 0
GM.HintHistoryMax = 3
Expand Down Expand Up @@ -99,16 +102,16 @@ function GM:HUDDrawHintHistory()

-- Fade in/out
if (delta > 1 - v.fadein) then
alpha = math.Clamp((1.0 - delta) * (255 / v.fadein), 0, 255)
alpha = math_Clamp((1.0 - delta) * (255 / v.fadein), 0, 255)
elseif (delta < v.fadeout) then
alpha = math.Clamp(delta * (255 / v.fadeout), 0, 255)
alpha = math_Clamp(delta * (255 / v.fadeout), 0, 255)
end

v.x = x - v.width + (v.width - ((v.width + 20) * (alpha / 255))) + 20
local rx = math.Round(v.x)
local ry = math.Round(v.y - (v.height / 2) - 4)
local rw = math.Round(v.width)
local rh = math.Round(v.height)
local rx = math_Round(v.x)
local ry = math_Round(v.y - (v.height / 2) - 4)
local rw = math_Round(v.width)
local rh = math_Round(v.height)
self:DrawHintHistory(rx, ry, rw, rh, v, alpha)
y = y + (v.height + 2)
tall = tall + v.height + 18
Expand All @@ -129,7 +132,7 @@ function GM:UpdateHintHistory()
local i = 0

for _, v in pairs(self.HintHistory) do
v.timescale = math.Clamp(table.Count(self.HintHistory) - i / self.HintHistoryMax * 10, 1, 10)
v.timescale = math_Clamp(table.Count(self.HintHistory) - i / self.HintHistoryMax * 10, 1, 10)
v.targetY = (ScrH() * 0.8) - ((i + 1) * (HINT_HEIGHT + HINT_SPACING))
i = i + 1
end
Expand Down
Loading