Залив
This commit is contained in:
189
lua/weapons/mg_base/modules/reverb/mw_reverb.lua
Normal file
189
lua/weapons/mg_base/modules/reverb/mw_reverb.lua
Normal file
@@ -0,0 +1,189 @@
|
||||
AddCSLuaFile()
|
||||
|
||||
--[[local MW_REVERB_SOUNDS = {
|
||||
["default"] = {
|
||||
Outside = {
|
||||
Layer = "Atmo_AR.Outside",
|
||||
Reflection = "Reflection_AR.Outside",
|
||||
},
|
||||
Inside = "Atmo_AR.Inside",
|
||||
},
|
||||
|
||||
["assault_rifle_1"] = {
|
||||
Outside = {
|
||||
Layer = "Atmo_AR.Outside",
|
||||
Reflection = "Reflection_AR.Outside",
|
||||
},
|
||||
Inside = "Atmo_AR.Inside",
|
||||
},
|
||||
|
||||
["assault_rifle_2"] = {
|
||||
Outside = {
|
||||
Layer = "Atmo_AR2.Outside",
|
||||
Reflection = "Reflection_AR.Outside",
|
||||
},
|
||||
Inside = "Atmo_AR.Inside",
|
||||
},
|
||||
|
||||
["assault_rifle_3"] = {
|
||||
Outside = {
|
||||
Layer = "Atmo_AR3.Outside",
|
||||
Reflection = "Reflection_AR.Outside",
|
||||
},
|
||||
Inside = "Atmo_AR.Inside",
|
||||
},
|
||||
|
||||
["assault_rifle_4"] = {
|
||||
Outside = {
|
||||
Layer = "Atmo_AR4.Outside",
|
||||
Reflection = "Reflection_AR.Outside",
|
||||
},
|
||||
Inside = "Atmo_AR.Inside",
|
||||
},
|
||||
|
||||
["assault_rifle_5"] = {
|
||||
Outside = {
|
||||
Layer = "Atmo_AR6.Outside",
|
||||
Reflection = "Reflection_AR.Outside",
|
||||
},
|
||||
Inside = "Atmo_AR.Inside",
|
||||
},
|
||||
|
||||
["pistol"] = {
|
||||
Outside = {
|
||||
Layer = "Atmo_Pistol.Outside",
|
||||
Reflection = "Reflection_Pistol.Outside",
|
||||
},
|
||||
Inside = "Atmo_Pistol.Inside",
|
||||
},
|
||||
|
||||
["suppressed_pistol"] = {
|
||||
Outside = {
|
||||
Layer = "Atmo_Pistol_Sup.Outside",
|
||||
Reflection = "Reflection_Pistol.Outside",
|
||||
},
|
||||
Inside = "Atmo_Pistol_Sup.Inside",
|
||||
},
|
||||
|
||||
["suppressed_assault_rifle"] = {
|
||||
Outside = {
|
||||
Layer = "Atmo_AR2_Sup.Outside",
|
||||
Reflection = "Reflection_Rifle.Outside",
|
||||
},
|
||||
Inside = "Atmo_AR_Sup.Inside",
|
||||
},
|
||||
|
||||
["pistol_heavy"] = {
|
||||
Outside = {
|
||||
Layer = "Atmo_Pistol_Mag2.Outside",
|
||||
Reflection = "Reflection_Pistol.Outside",
|
||||
},
|
||||
Inside = "Atmo_Shotgun.Inside",
|
||||
},
|
||||
|
||||
["smg"] = {
|
||||
Outside = {
|
||||
Layer = "Atmo_SMG.Outside",
|
||||
Reflection = "Reflection_Pistol.Outside",
|
||||
},
|
||||
Inside = "Atmo_SMG.Inside",
|
||||
},
|
||||
|
||||
["shotgun"] = {
|
||||
Outside = {
|
||||
Layer = "Atmo_Shotgun.Outside",
|
||||
Reflection = "Reflection_Shotgun.Outside",
|
||||
},
|
||||
Inside = "Atmo_Shotgun.Inside",
|
||||
},
|
||||
|
||||
["sniper"] = {
|
||||
Outside = {
|
||||
Layer = "Atmo_Sniper.Outside",
|
||||
Reflection = "Reflection_Sniper.Outside",
|
||||
},
|
||||
Inside = "Atmo_Sniper.Inside",
|
||||
},
|
||||
|
||||
["LMG"] = {
|
||||
Outside = {
|
||||
Layer = "Atmo_LMG.Outside",
|
||||
Reflection = "Reflection_AR.Outside",
|
||||
},
|
||||
Inside = "Atmo_LMG.Inside",
|
||||
},
|
||||
|
||||
["DMR"] = {
|
||||
Outside = {
|
||||
Layer = "Atmo_DMR.Outside",
|
||||
Reflection = "Reflection_Sniper.Outside",
|
||||
},
|
||||
Inside = "Atmo_Sniper.Inside",
|
||||
},
|
||||
|
||||
["RPG"] = {
|
||||
Outside = {
|
||||
Layer = "Atmo_RPG.Outside",
|
||||
Reflection = "Atmo_RPG.Outside",
|
||||
},
|
||||
Inside = "Atmo_RPG.Outside",
|
||||
},
|
||||
}]] --IM LEAVING THESE HERE FOR REFERENCE
|
||||
|
||||
function SWEP:HandleReverb()
|
||||
if (!IsValid(self:GetOwner()) || !IsFirstTimePredicted()) then
|
||||
return
|
||||
end
|
||||
|
||||
if (self.Reverb == nil) then
|
||||
return
|
||||
end
|
||||
|
||||
local layer = ""
|
||||
local reflection = ""
|
||||
|
||||
if self.Reverb.Sounds then
|
||||
local outside = self.LastReverbState
|
||||
|
||||
if (outside) then
|
||||
layer = self.Reverb.Sounds.Outside.Layer
|
||||
reflection = self.Reverb.Sounds.Outside.Reflection
|
||||
else
|
||||
layer = self.Reverb.Sounds.Inside.Layer != nil && self.Reverb.Sounds.Inside.Layer || self.Reverb.Sounds.Inside
|
||||
reflection = self.Reverb.Sounds.Inside.Reflection != nil && self.Reverb.Sounds.Inside.Reflection || ""
|
||||
end
|
||||
|
||||
if layer != "" then
|
||||
if (!game.SinglePlayer()) then
|
||||
self:EmitSound(layer)
|
||||
else
|
||||
self:GetOwner():SendLua("LocalPlayer():EmitSound('"..layer.."')")
|
||||
end
|
||||
end
|
||||
|
||||
if reflection != "" then
|
||||
if (!game.SinglePlayer()) then
|
||||
self:EmitSound(reflection)
|
||||
else
|
||||
self:GetOwner():SendLua("LocalPlayer():EmitSound('"..reflection.."')")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function SWEP:CreateAndResumeReverbJob()
|
||||
if (self.ReverbJob == nil) then
|
||||
self.ReverbJob = coroutine.create(function()
|
||||
while (true) do
|
||||
self:mg_IsPlayerReverbOutside()
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
local success, yield = coroutine.resume(self.ReverbJob)
|
||||
|
||||
if (yield != nil) then
|
||||
self.LastReverbState = yield
|
||||
end
|
||||
--self.LastReverbState = true
|
||||
end
|
||||
74
lua/weapons/mg_base/modules/reverb/mw_reverbimpl.lua
Normal file
74
lua/weapons/mg_base/modules/reverb/mw_reverbimpl.lua
Normal file
@@ -0,0 +1,74 @@
|
||||
AddCSLuaFile()
|
||||
|
||||
local REVERB_RESOLUTION = 0.25 --Default: 0.1. Less means more raycasts.
|
||||
local REVERB_ROOMSIZE = 2048
|
||||
local REVERB_TINYROOMSIZE = 320
|
||||
|
||||
function SWEP:CheckRoomScale(dist)
|
||||
return dist > (REVERB_ROOMSIZE * REVERB_ROOMSIZE);
|
||||
end
|
||||
|
||||
local reverbSize = Vector(4, 4, 4)
|
||||
|
||||
function SWEP:mg_IsPlayerReverbOutside()
|
||||
if (!IsValid(self:GetOwner()) || !IsFirstTimePredicted()) then
|
||||
coroutine.yield(nil)
|
||||
end
|
||||
|
||||
coroutine.wait(0.1)
|
||||
|
||||
local dist = 0
|
||||
local start = self:GetOwner():EyePos()
|
||||
local len = math.pow(self.Reverb.RoomScale, 1/3) * 100
|
||||
local resolution = 1
|
||||
|
||||
for r = 0.5, 0.1, (REVERB_RESOLUTION / resolution) * -0.5 do
|
||||
local hCos = math.sin(r * math.pi)
|
||||
for i = -1, 1, (REVERB_RESOLUTION / resolution) do
|
||||
local sin = math.sin(i * math.pi) * hCos
|
||||
local cos = math.cos(i * math.pi) * hCos
|
||||
|
||||
local dir = Vector(sin, cos, math.cos(r * math.pi))
|
||||
local tr = util.TraceHull({
|
||||
start = start,
|
||||
endpos = start + dir * 32768,
|
||||
mask = MASK_SHOT,
|
||||
mins = -reverbSize,
|
||||
maxs = reverbSize,
|
||||
filter = self:GetOwner()
|
||||
})
|
||||
|
||||
local distToHitPos = start:DistToSqr(tr.HitPos)
|
||||
local acceptableCloseDistance = REVERB_TINYROOMSIZE * REVERB_TINYROOMSIZE
|
||||
|
||||
if (tr.HitSky || self:CheckRoomScale(distToHitPos)) then
|
||||
dist = dist + (REVERB_ROOMSIZE * REVERB_ROOMSIZE) * 0.3
|
||||
else
|
||||
if (distToHitPos <= acceptableCloseDistance) then
|
||||
dist = dist - (REVERB_ROOMSIZE * REVERB_ROOMSIZE) * 0.15
|
||||
else
|
||||
dist = dist - (distToHitPos * 0.4)
|
||||
end
|
||||
end
|
||||
|
||||
if (GetConVar("mgbase_debug_reverb"):GetInt() > 0) then
|
||||
local color = distToHitPos <= acceptableCloseDistance && Color(0, 255, 0, 1) || Color(255, 150, 0, 1)
|
||||
debugoverlay.Line(start, tr.HitPos, 1, color)
|
||||
debugoverlay.Box(tr.HitPos, -reverbSize, reverbSize, 1, color)
|
||||
debugoverlay.Text(tr.HitPos, math.Round(math.sqrt(distToHitPos)), 1)
|
||||
end
|
||||
|
||||
--If room scale is already big enough, no need to cast any more rays.
|
||||
if self:CheckRoomScale(dist) then
|
||||
break
|
||||
end
|
||||
end
|
||||
coroutine.wait(0)
|
||||
end
|
||||
|
||||
if (GetConVar("mgbase_debug_reverb"):GetInt() > 0) then
|
||||
debugoverlay.ScreenText(0, 0.1, "Room scale: "..math.Round(math.sqrt(dist)), 0, Color(255, 150, 0, 255))
|
||||
end
|
||||
|
||||
coroutine.yield(self:CheckRoomScale(dist))
|
||||
end
|
||||
Reference in New Issue
Block a user