-
Notifications
You must be signed in to change notification settings - Fork 333
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Will be a separate addon] Wire Advanced Microphone and Speaker #2722
Conversation
Is this intended to mimic the functionality of the env_microphone? Was always wishing for something like this so this is awesome to see. |
Yes, it is. In fact, I plan to make it better, as |
…p fix for speaker playing looping sound
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is draft but putting these here since these are design decisions
-- because some sounds are played clientside only | ||
|
||
-- array(Entity(gmod_wire_adv_microphone)) | ||
-- Array instead of lookup table because sounds are emitted more often than microphones switched on or off, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there any notable difference in speed between ipairs and pairs in this case with a small amount of items?
Cause I'd really prefer a lookup table over using table.RemoveByValue
and table.insert
. Even if I know there won't be more than maybe ten microphones placed in a server at once. At worst you could maintain both a lookup table and an array for the best of both worlds.
I know ipairs can jit but that's just on the x86_64 branch. Although you could use a manual for loop, but you aren't doing that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can only agree on this. And I just don't get it why it such a problem to just change it. It is not like you are going to need to add like extra 1000 lines of code for it.
How's the PlayerCanHearPlayersVoice going to work? It seems right now it doesn't mute players that are too far away from the mic, but it will force you to be able to hear anyone close enough to it if you are close enough to a speaker? Aren't you able to hear players at any distance by default in sandbox? If this is intended for DarkRP, maybe the hook should only be added when in DarkRP? |
Yes, it should work (and probably does) exactly as you supposed it does. |
This pull request has been marked as stale as there haven't been any changes in the past month. It will be closed in 15 days. |
So, I need to test player voice reproduction and PR will be ready |
This pull request has been marked as stale as there haven't been any changes in the past month. It will be closed in 15 days. |
This pull request has been marked as stale as there haven't been any changes in the past month. It will be closed in 15 days. |
…unctions to soundlib.
Can this PR me merged? |
please wiremod gods make this happen |
May you fix the lint errors (trailing whitespace)? It seems okay, there's still a few concerns about performance but I think it's alright for the purpose it has. |
Fixed all warnings except |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's alright as it is. There's room for micro-optimizations but either way it's just going to be a heavy addition.
Would like to see a stress test done but not holding you to it.
This microphone system was used on a live server from the first commit, and there were no performance issues reported. The most intensive usage pattern is: 5-7 microphones and screens active, 2-3 connected pairs, 1-2 players spoke into each connected microphone. I don't know how and with whom to do a proper stress testing, though. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That table.HasValue
issue is still there. But whatever, just pull that thing and have somebody else optimize it if needed afterwards in the case the author still refuses to make the requested changes. Better than being stuck having pullrequest-drama on Discord.
This needs a lot of cleanup. I would prefer something like. local MicrophoneSystem = {}
MicrophoneSystem.ActiveMics = {}
MicrophoneSystem.ActiveSpeakers = {}
local PlayerSpeakerCache = {
__index = {
reset = function(self)
-- Clear all of our tables
for v in pairs(self.hearableMics) do self.hearableMics[v] = nil end
for v in pairs(self.hearableSpeakers) do self.hearableSpeakers[v] = nil end
for v in pairs(self.hearablePlayerMics) do self.hearablePlayerMics[v] = nil end
end,
calcHearableDevices = function(self)
-- Calculate distances to devices
end,
calcHearablePlayers = function(self)
-- Using the speakers this player can hear, see what corresponding mics other players can hear and put this players in self.hearablePlayerMics
end,
canHearPlayer = function(self, ply)
return self.hearablePlayerMics[ply] ~= nil
end,
canHearSound = function(self, snd, soundpos)
end
},
__call = function(t, ply)
return setmetatable({
player = ply,
hearableSpeakers = {},
hearableMics = {},
hearablePlayerMics = {}
}, t)
end
}
setmetatable(PlayerSpeakerCache, PlayerSpeakerCache)
MicrophoneSystem.PlayerSpeakerCaches = WireLib.RegisterPlayerTable(setmetatable({}, {
__index = function(t,k) local r=PlayerSpeakerCache(k) t[k]=r return r end
}))
function MicrophoneSystem.AddActiveMic(ent)
MicrophoneSystem.ActiveMics[MicrophoneSystem.ActiveMics+1] = ent
MicrophoneSystem.AddHooks()
end
function MicrophoneSystem.RemoveActiveMic(ent)
table.RemoveByValue(MicrophoneSystem.ActiveMics, ent)
MicrophoneSystem.RemoveHooks()
end
function MicrophoneSystem.AddActiveSpeaker(ent)
MicrophoneSystem.ActiveSpeakers[MicrophoneSystem.ActiveSpeakers+1] = ent
MicrophoneSystem.AddHooks()
end
function MicrophoneSystem.RemoveActiveSpeaker(ent)
table.RemoveByValue(MicrophoneSystem.ActiveSpeakers, ent)
MicrophoneSystem.RemoveHooks()
end
function MicrophoneSystem.AddHooks()
if #MicrophoneSystem.ActiveMics == 0 or #MicrophoneSystem.ActiveSpeakers == 0 then return end
hook.Add("Think", "Wirelib_Microphones", MicrophoneSystem.Think)
hook.Add("PlayerCanHearPlayersVoice", "Wirelib_Microphones", MicrophoneSystem.PlayerCanHearPlayersVoice)
end
function MicrophoneSystem.RemoveHooks()
if #MicrophoneSystem.ActiveMics ~= 0 and #MicrophoneSystem.ActiveSpeakers ~= 0 then return end
hook.Remove("Think", "Wirelib_Microphones")
hook.Remove("PlayerCanHearPlayersVoice", "Wirelib_Microphones")
end
function MicrophoneSystem.Think()
for _, ply in player.iterator() do
MicrophoneSystem.PlayerSpeakerCaches[ply]:reset()
end
for _, ply in player.iterator() do
MicrophoneSystem.PlayerSpeakerCaches[ply]:calcHearableDevices()
end
for _, ply in player.iterator() do
MicrophoneSystem.PlayerSpeakerCaches[ply]:calcHearablePlayers()
end
end
function MicrophoneSystem.PlayerCanHearPlayersVoice(talker, listener)
if MicrophoneSystem.PlayerSpeakerCaches[listener]:canHearPlayer(talker) then
return true
end
end
|
Note how 'PlayerCanHearPlayersVoice' is a single line, which is necessary because that hook runs very frequently iirc. |
Also the PlayerCanHearPlayersVoice hook and calcHearablePlayers should only be used if global voice is not enabled, and it needs to not conflict with DarkRP's hook. |
It would be better to have everything necessary inlined for performance. |
You can replace the canHearPlayer call with the line inside that function, sure. |
why are you requesting my review, i aint a wiremod dev my guy |
Is it alright to close this if you're planning on separating it to its own addon? |
I'll close it |
! This PR will be made into separate addon. It can be used as-is until I get to make this addon.
I'll close this PR when I make the addon.
EntityEmitSound
(both clientside and serverside).sound.Play
.What will not be implemented in this PR:
sound.PlayFile
andsound.PlayURL
support - should be implementableENT:StopSound
hooking - no way to hook engineStopSound
s. Wait for Request for GM:EntityStopSound hook, SoundLooped function Facepunch/garrysmod-requests#2176StopSound
hooksPLY:SetVoiceVolumeScale
with wrapper