diff --git a/lua/autorun/!!!!!_lithium.lua b/lua/autorun/!!!!!_lithium.lua index 3b50057..50916f5 100644 --- a/lua/autorun/!!!!!_lithium.lua +++ b/lua/autorun/!!!!!_lithium.lua @@ -6,6 +6,7 @@ if SysTime() - _G.LITHIUM_LastAutoReload < 0.1 then return end _G.LITHIUM_LastAutoReload = SysTime() require("lithium") +local math=math concommand.Add("lithium_samplefps_"..(SERVER and "sv" or CLIENT and "cl" or "unk"), function(ply, _, args, _) if not IsValid(ply) and SERVER then diff --git a/lua/autorun/server/sv_lithium_controls.lua b/lua/autorun/server/sv_lithium_controls.lua index 96889d6..cf9ba75 100644 --- a/lua/autorun/server/sv_lithium_controls.lua +++ b/lua/autorun/server/sv_lithium_controls.lua @@ -5,7 +5,7 @@ net.Receive("lithium_controls", function(_, ply) if msg == 1 then -- set bool if not ply:IsAdmin() then return end local cv = net.ReadString() - if not string.StartsWith(cv, "lithium_") then return end + if not cv:StartsWith("lithium_") then return end local cvv = GetConVar(cv) if not cvv then return end cvv:SetBool(net.ReadBool()) @@ -13,7 +13,7 @@ net.Receive("lithium_controls", function(_, ply) end if msg == 0 then -- get bool local name = net.ReadString() - if not string.StartsWith(name, "lithium_") then return end + if not name:StartsWith("lithium_") then return end net.Start("lithium_controls") net.WriteUInt(0, 4) net.WriteString(name) diff --git a/lua/includes/modules/hook_lithium.lua b/lua/includes/modules/hook_lithium.lua index 70a4f3b..cac8054 100644 --- a/lua/includes/modules/hook_lithium.lua +++ b/lua/includes/modules/hook_lithium.lua @@ -149,14 +149,13 @@ end function CallPart(hook_table, event, i, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) if hook_table[i + 1] then return hook_table[i](arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) - else - name = hook_table[i + 2] - if not name then return end - if not name:IsValid() then - return RemoveForce(event, name) - end - return hook_table[i](name, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) end + name = hook_table[i + 2] + if not name then return end + if not name:IsValid() then + return RemoveForce(event, name) + end + return hook_table[i](name, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) end function Call(event, gm, arg0, arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8, arg9) diff --git a/lua/lithium/extensions/caching.lua b/lua/lithium/extensions/caching.lua index 215bad4..5ea23ea 100644 --- a/lua/lithium/extensions/caching.lua +++ b/lua/lithium/extensions/caching.lua @@ -25,27 +25,23 @@ local isnumber = isnumber hook.Add("OnEntityCreated", "LITHIUM_CacheEntity", function(ent) if not ent:IsValid() then return end local idx = ENTITY_EntIndex(ent) - if idx == -1 then return end - if idx == 0 then return end + if idx == -1 or idx == 0 then return end entlist[idx] = ent end) hook.Add("EntityRemoved", "LITHIUM_CacheEntity", function(ent, fullupdate) if fullupdate then return end local idx = ENTITY_EntIndex(ent) - if idx == -1 then return end - if idx == 0 then return end + if idx == -1 or idx == 0 then return end entlist[idx] = nil end) function Entity(entindex) if not isnumber(entindex) then entindex = tonumber(entindex) end local ent = entlist[entindex] - if not ent then - ent = OldEntity(entindex) - - if entindex ~= 0 then - if ent and ENTITY_IsValid(ent) then entlist[entindex] = ent end - end + if ent then return ent end + ent = OldEntity(entindex) + if entindex ~= 0 then + if ent and ENTITY_IsValid(ent) then entlist[entindex] = ent end end return ent end diff --git a/lua/lithium/extensions/client/optimised_draw.lua b/lua/lithium/extensions/client/optimised_draw.lua index 7fb6813..ff90388 100644 --- a/lua/lithium/extensions/client/optimised_draw.lua +++ b/lua/lithium/extensions/client/optimised_draw.lua @@ -84,6 +84,7 @@ local surface_DrawTexturedRectRotated = surface.DrawTexturedRectRotated local string_sub = string.sub +local math = math local math_ceil = math.ceil local Tex_Corner8 = surface.GetTextureID("gui/corner8") @@ -106,6 +107,8 @@ function draw.GetFontHeight(font) return h end +local tbl_concat = table.concat + function draw.SimpleText(text, font, x, y, color, xalign, yalign) surface_SetFont(font or "DermaDefault") @@ -142,27 +145,29 @@ function draw.DrawText(text, font, x, y, color, xalign) local lineHeight = draw.GetFontHeight(font or "DermaDefault") + local line_start = 1 for i=1, #text do local ch = string_sub(text, i, i) if ch == "\n" then + local curString = string_sub(text,line_start,i) if #curString > 0 then draw.SimpleText(curString, font, curX, curY, color, xalign) end curY = curY + lineHeight -- / 2 curX = x - curString = "" + line_start = i+2 elseif ch == "\t" then + local curString = string_sub(text,line_start,i) if #curString > 0 then draw.SimpleText(curString, font, curX, curY, color, xalign) end local tmpSizeX, _ = surface_GetTextSize(curString) curX = math_ceil( (curX + tmpSizeX) / 50 ) * 50 - curString = "" - else - curString = curString .. ch + line_start = i+2 end end + local curString = string_sub(text,line_start,i) if #curString > 0 then draw.SimpleText(curString, font, curX, curY, color, xalign) end diff --git a/lua/lithium/extensions/lastresort.lua b/lua/lithium/extensions/lastresort.lua index a20a09b..0c205b5 100644 --- a/lua/lithium/extensions/lastresort.lua +++ b/lua/lithium/extensions/lastresort.lua @@ -1,21 +1,23 @@ require("niknaks") -- bsp parser if not NikNaks then return end +local math = math +local min,max,abs = math.min,math.max,math.abs local function calc_lighting(pos, normal) local surface = render.GetLightColor(pos + normal) --local exposure = render.ComputeLighting(pos + normal, normal) local final = (surface) - final[1] = math.min(final[1]^(1 / 2.2), 1) - final[2] = math.min(final[2]^(1 / 2.2), 1) - final[3] = math.min(final[3]^(1 / 2.2), 1) + final[1] = min(final[1]^(1 / 2.2), 1) + final[2] = min(final[2]^(1 / 2.2), 1) + final[3] = min(final[3]^(1 / 2.2), 1) final = final * 255 --return final[1], final[2], final[3], 255 - return math.abs(normal.x * 127) + final[1] / 255 * 127, - math.abs(normal.y * 127) + final[2] / 255 * 127, - math.abs(normal.z * 127) + final[3] / 255 * 127, + return abs(normal.x * 127) + final[1] / 255 * 127, + abs(normal.y * 127) + final[2] / 255 * 127, + abs(normal.z * 127) + final[3] / 255 * 127, 255 end @@ -69,37 +71,37 @@ local function generate_map_meshes() do_face(v1, vmid) do_face(v2, vmid) do_face(v3, vmid) - p1 = Vector(math.min(p1.x, v1.pos.x, v2.pos.x, v3.pos.x), -- 0 - math.min(p1.y, v1.pos.y, v2.pos.y, v3.pos.y), -- 0 - math.min(p1.z, v1.pos.z, v2.pos.z, v3.pos.z)) -- 0 + p1 = Vector(min(p1.x, v1.pos.x, v2.pos.x, v3.pos.x), -- 0 + min(p1.y, v1.pos.y, v2.pos.y, v3.pos.y), -- 0 + min(p1.z, v1.pos.z, v2.pos.z, v3.pos.z)) -- 0 - p2 = Vector(math.max(p2.x, v1.pos.x, v2.pos.x, v3.pos.x), -- 1 - math.min(p2.y, v1.pos.y, v2.pos.y, v3.pos.y), -- 0 - math.min(p2.z, v1.pos.z, v2.pos.z, v3.pos.z)) -- 0 + p2 = Vector(max(p2.x, v1.pos.x, v2.pos.x, v3.pos.x), -- 1 + min(p2.y, v1.pos.y, v2.pos.y, v3.pos.y), -- 0 + min(p2.z, v1.pos.z, v2.pos.z, v3.pos.z)) -- 0 - p3 = Vector(math.min(p3.x, v1.pos.x, v2.pos.x, v3.pos.x), -- 0 - math.max(p3.y, v1.pos.y, v2.pos.y, v3.pos.y), -- 1 - math.min(p3.z, v1.pos.z, v2.pos.z, v3.pos.z)) -- 0 + p3 = Vector(min(p3.x, v1.pos.x, v2.pos.x, v3.pos.x), -- 0 + max(p3.y, v1.pos.y, v2.pos.y, v3.pos.y), -- 1 + min(p3.z, v1.pos.z, v2.pos.z, v3.pos.z)) -- 0 - p4 = Vector(math.max(p4.x, v1.pos.x, v2.pos.x, v3.pos.x), -- 1 - math.max(p4.y, v1.pos.y, v2.pos.y, v3.pos.y), -- 1 - math.min(p4.z, v1.pos.z, v2.pos.z, v3.pos.z)) -- 0 + p4 = Vector(max(p4.x, v1.pos.x, v2.pos.x, v3.pos.x), -- 1 + max(p4.y, v1.pos.y, v2.pos.y, v3.pos.y), -- 1 + min(p4.z, v1.pos.z, v2.pos.z, v3.pos.z)) -- 0 - p5 = Vector(math.min(p5.x, v1.pos.x, v2.pos.x, v3.pos.x), -- 0 - math.min(p5.y, v1.pos.y, v2.pos.y, v3.pos.y), -- 0 - math.max(p5.z, v1.pos.z, v2.pos.z, v3.pos.z)) -- 1 + p5 = Vector(min(p5.x, v1.pos.x, v2.pos.x, v3.pos.x), -- 0 + min(p5.y, v1.pos.y, v2.pos.y, v3.pos.y), -- 0 + max(p5.z, v1.pos.z, v2.pos.z, v3.pos.z)) -- 1 - p6 = Vector(math.max(p6.x, v1.pos.x, v2.pos.x, v3.pos.x), -- 1 - math.min(p6.y, v1.pos.y, v2.pos.y, v3.pos.y), -- 0 - math.max(p6.z, v1.pos.z, v2.pos.z, v3.pos.z)) -- 1 + p6 = Vector(max(p6.x, v1.pos.x, v2.pos.x, v3.pos.x), -- 1 + min(p6.y, v1.pos.y, v2.pos.y, v3.pos.y), -- 0 + max(p6.z, v1.pos.z, v2.pos.z, v3.pos.z)) -- 1 - p7 = Vector(math.min(p7.x, v1.pos.x, v2.pos.x, v3.pos.x), -- 0 - math.max(p7.y, v1.pos.y, v2.pos.y, v3.pos.y), -- 1 - math.max(p7.z, v1.pos.z, v2.pos.z, v3.pos.z)) -- 1 + p7 = Vector(min(p7.x, v1.pos.x, v2.pos.x, v3.pos.x), -- 0 + max(p7.y, v1.pos.y, v2.pos.y, v3.pos.y), -- 1 + max(p7.z, v1.pos.z, v2.pos.z, v3.pos.z)) -- 1 - p8 = Vector(math.max(p8.x, v1.pos.x, v2.pos.x, v3.pos.x), -- 1 - math.max(p8.y, v1.pos.y, v2.pos.y, v3.pos.y), -- 1 - math.max(p8.z, v1.pos.z, v2.pos.z, v3.pos.z)) -- 1 + p8 = Vector(max(p8.x, v1.pos.x, v2.pos.x, v3.pos.x), -- 1 + max(p8.y, v1.pos.y, v2.pos.y, v3.pos.y), -- 1 + max(p8.z, v1.pos.z, v2.pos.z, v3.pos.z)) -- 1 end) if not succ then print(str) end @@ -107,8 +109,8 @@ local function generate_map_meshes() if mesh.VertexCount() >= MAX_TRIANGLES then mesh.End() - table.insert(imeshes, imesh) - table.insert(minmaxs, {p1, p2, p3, p4, p5, p6, p7, p8}) + imeshes[#imeshes+1] = imesh + minmaxs[#minmaxs+1] = {p1, p2, p3, p4, p5, p6, p7, p8} imesh = Mesh() mesh.Begin(imesh, MATERIAL_TRIANGLES, MAX_TRIANGLES) @@ -116,8 +118,8 @@ local function generate_map_meshes() end --end mesh.End() - table.insert(imeshes, imesh) - table.insert(minmaxs, {p1, p2, p3, p4, p5, p6, p7, p8}) + imeshes[#imeshes+1] = imesh + minmaxs[#minmaxs+1] = {p1, p2, p3, p4, p5, p6, p7, p8} return imeshes, minmaxs end @@ -137,7 +139,7 @@ function EyePos() return eyepos end function EyeAngles() return eyeang end local vm_fov = GetConVar("viewmodel_fov") - +local RENDERGROUP_OPAQUE, RENDERGROUP_VIEWMODEL, RENDERGROUP_OPAQUE_BRUSH, RENDERGROUP_BOTH = RENDERGROUP_OPAQUE, RENDERGROUP_VIEWMODEL, RENDERGROUP_OPAQUE_BRUSH, RENDERGROUP_BOTH function render.RenderView(view) local vm = LocalPlayer():GetViewModel() local view = table.Copy(view) @@ -160,9 +162,12 @@ function render.RenderView(view) local opaque, translucent = {}, {} local rendergroup for _, ent in ents.Iterator() do - if not IsValid(ent) or ent:GetNoDraw() then continue end - if ent == vm then continue end - if ent:GetClass() == "gmod_hands" then continue end + if not IsValid(ent) + or ent:GetNoDraw() + or ent == vm + or ent:GetClass() == "gmod_hands" then + continue + end -- frustrum culling, if too close dont bother --[[ local pos = ent:GetPos() @@ -185,7 +190,7 @@ function render.RenderView(view) end end - if hook.Run("PreDrawOpaqueRenderables", false, false, false) ~= true then + if not hook.Run("PreDrawOpaqueRenderables", false, false, false) then local ent for i=1, #opaque do ent = opaque[i] @@ -196,7 +201,7 @@ function render.RenderView(view) hook.Run("PostDrawOpaqueRenderables", false, false, false) end - if hook.Run("PreDrawTranslucentRenderables", false, false, false) ~= true then + if not hook.Run("PreDrawTranslucentRenderables", false, false, false) then local ent for i=1, #translucent do ent = translucent[i] @@ -209,8 +214,8 @@ function render.RenderView(view) if view.drawviewmodel then if IsValid(vm) and - hook.Run("PreDrawViewModel", vm, LocalPlayer(), LocalPlayer():GetActiveWeapon()) ~= true and - hook.Run("ShouldDrawLocalPlayer", LocalPlayer()) ~= true and LocalPlayer():ShouldDrawLocalPlayer() ~= true then + not hook.Run("PreDrawViewModel", vm, LocalPlayer(), LocalPlayer():GetActiveWeapon()) and + not hook.Run("ShouldDrawLocalPlayer", LocalPlayer()) ~= true and LocalPlayer():ShouldDrawLocalPlayer() then cam.Start3D(eyepos, eyeang, vm_fov and vm_fov:GetFloat() / 0.75 or 60) render.DepthRange(0, 0.03) vm:DrawModel() diff --git a/lua/lithium/gpusaver.lua b/lua/lithium/gpusaver.lua index f26dbbe..bd687ba 100644 --- a/lua/lithium/gpusaver.lua +++ b/lua/lithium/gpusaver.lua @@ -7,48 +7,51 @@ local show_activity = CreateConVar("lithium_gpusaver_info_activity", 1, {FCVAR_A local show_session = CreateConVar("lithium_gpusaver_info_session", 1, {FCVAR_ARCHIVE}, "GPU Saver Show Session time", 0, 1) local show_velocity = CreateConVar("lithium_gpusaver_info_velocity", 1, {FCVAR_ARCHIVE}, "GPU Saver Show Velocity", 0, 1) +local draw = draw +local surface = surface +local color_white = color_white +local bgcolor, bgcolor_dark = Color(0, 127, 255, 255), Color(24, 24, 32, 255) + + hook.Add("PreRender", "LITHIUM_GPUSaver", function() if system.HasFocus() then return end cam.Start2D() local lp = LocalPlayer() - if not dark_mode:GetBool() then - surface.SetDrawColor(0, 127, 255, 255) - else - surface.SetDrawColor(24, 24, 32, 255) - end - surface.DrawRect(0, 0, ScrW(), ScrH()) - draw.DrawText("Lithium", "DermaDefault", ScrW() * 0.5, ScrH() * 0.25, color_white, TEXT_ALIGN_CENTER) - draw.DrawText("GPU Saver is ACTIVE", "DermaLarge", ScrW() * 0.5, ScrH() * 0.25 + 18, color_white, TEXT_ALIGN_CENTER) + local scrw,scrh = ScrW(),ScrH() + surface.SetDrawColor(dark_mode:GetBool() and bgcolor_dark or bgcolor) + surface.DrawRect(0, 0, scrw, scrh) + draw.DrawText("Lithium", "DermaDefault", scrw * 0.5, scrh * 0.25, color_white, TEXT_ALIGN_CENTER) + draw.DrawText("GPU Saver is ACTIVE", "DermaLarge", scrw * 0.5, scrh * 0.25 + 18, color_white, TEXT_ALIGN_CENTER) draw.DrawText("If you believe this is a mistake, send a bug report at https://github.com/Def-Try/Lithium", "DermaDefault", - ScrW() * 0.5, ScrH() - 18, color_white, TEXT_ALIGN_CENTER) + scrw * 0.5, scrh - 18, color_white, TEXT_ALIGN_CENTER) if draw_info:GetBool() then - local y = ScrH() * 0.25 + 52 + local y = scrh * 0.25 + 52 if not lp then - draw.DrawText("Player stats:", "DermaLarge", ScrW() * 0.1, ScrH() * 0.25 + 18, color_white, TEXT_ALIGN_CENTER) - draw.DrawText("< UNAVALIABLE >", "DermaDefault", ScrW() * 0.1, y, color_white, TEXT_ALIGN_CENTER) + draw.DrawText("Player stats:", "DermaLarge", scrw * 0.1, scrh * 0.25 + 18, color_white, TEXT_ALIGN_CENTER) + draw.DrawText("< UNAVALIABLE >", "DermaDefault", scrw * 0.1, y, color_white, TEXT_ALIGN_CENTER) cam.End2D() return true end - draw.DrawText((show_name:GetBool() and lp:Name() or "Player").." stats:", "DermaLarge", ScrW() * 0.1, ScrH() * 0.25 + 18, color_white, TEXT_ALIGN_CENTER) + draw.DrawText((show_name:GetBool() and lp:Name() or "Player").." stats:", "DermaLarge", scrw * 0.1, scrh * 0.25 + 18, color_white, TEXT_ALIGN_CENTER) if show_health:GetBool() then - draw.DrawText("Health: "..lp:Health().."/"..lp:GetMaxHealth(), "DermaDefault", ScrW() * 0.1, y, color_white, TEXT_ALIGN_CENTER) - draw.DrawText("Armor: "..lp:Armor().."/"..lp:GetMaxArmor(), "DermaDefault", ScrW() * 0.1, y + 18, color_white, TEXT_ALIGN_CENTER) + draw.DrawText("Health: "..lp:Health().."/"..lp:GetMaxHealth(), "DermaDefault", scrw * 0.1, y, color_white, TEXT_ALIGN_CENTER) + draw.DrawText("Armor: "..lp:Armor().."/"..lp:GetMaxArmor(), "DermaDefault", scrw * 0.1, y + 18, color_white, TEXT_ALIGN_CENTER) y = y + 18 * 2 end if show_velocity:GetBool() then - draw.DrawText("Velocity: "..tostring(lp:GetVelocity()), "DermaDefault", ScrW() * 0.1, y, color_white, TEXT_ALIGN_CENTER) + draw.DrawText("Velocity: "..tostring(lp:GetVelocity()), "DermaDefault", scrw * 0.1, y, color_white, TEXT_ALIGN_CENTER) y = y + 18 end if show_activity:GetBool() then - draw.DrawText("Last mouse move time: "..string.FormattedTime(system.UpTime(), "%02i:%02i"), "DermaDefault", ScrW() * 0.1, y, color_white, TEXT_ALIGN_CENTER) + draw.DrawText("Last mouse move time: "..string.FormattedTime(system.UpTime(), "%02i:%02i"), "DermaDefault", scrw * 0.1, y, color_white, TEXT_ALIGN_CENTER) y = y + 18 end if show_session:GetBool() then local apptime = string.FormattedTime(system.AppTime()) apptime = string.format("%02i:%02i:%02i", apptime.h, apptime.m, apptime.s) - draw.DrawText("Application time (as reported by steam): "..apptime, "DermaDefault", ScrW() * 0.1, y, color_white, TEXT_ALIGN_CENTER) + draw.DrawText("Application time (as reported by steam): "..apptime, "DermaDefault", scrw * 0.1, y, color_white, TEXT_ALIGN_CENTER) y = y + 18 end end diff --git a/lua/lithium/util.lua b/lua/lithium/util.lua index acaf48c..f9a860f 100644 --- a/lua/lithium/util.lua +++ b/lua/lithium/util.lua @@ -36,6 +36,7 @@ function GetConVarString(name) end _G.LITHIUM_Material_old = _G.LITHIUM_Material_old or Material +local LITHIUM_Material_old = LITHIUM_Material_old function Material(name, words) if name == "" and words == nil then -- the fuck? return LITHIUM_Material_old(name, words)