-
-
Notifications
You must be signed in to change notification settings - Fork 177
check who is dead at the start of meetings and don't let them talk at… #369
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
base: nightly
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -263,6 +263,12 @@ const Voice: React.FC<VoiceProps> = function ({ t, error: initialError }: VoiceP | |
| const [mutedState, setMuted] = useState(false); | ||
| const [connected, setConnected] = useState(false); | ||
|
|
||
| const [playersThatHaveDiedThisGame, setPlayersThatHaveDiedThisGame] = useState<number[]>([]); | ||
|
|
||
| const checkIfPlayerWasDeadAtStartOfMeeting = (ptr: number) => { | ||
| return playersThatHaveDiedThisGame.includes(ptr); | ||
| } | ||
|
|
||
| function applyEffect(gain: AudioNode, effectNode: AudioNode, destination: AudioNode, player: Player) { | ||
| console.log('Apply effect->', effectNode); | ||
| try { | ||
|
|
@@ -702,6 +708,7 @@ const Voice: React.FC<VoiceProps> = function ({ t, error: initialError }: VoiceP | |
| // Set dead player data | ||
| useEffect(() => { | ||
| if (gameState.gameState === GameState.LOBBY) { | ||
| setPlayersThatHaveDiedThisGame([]); | ||
| setOtherDead({}); | ||
| } else if (gameState.gameState !== GameState.TASKS) { | ||
| if (!gameState.players) return; | ||
|
|
@@ -711,6 +718,14 @@ const Voice: React.FC<VoiceProps> = function ({ t, error: initialError }: VoiceP | |
| } | ||
| return { ...old }; | ||
| }); | ||
| setPlayersThatHaveDiedThisGame((prevState) => { | ||
| for (const player of gameState.players) { | ||
| if ((player.isDead || player.disconnected) && !prevState.includes(player.ptr)) { | ||
| prevState.push(player.ptr); | ||
| } | ||
| } | ||
| return [...prevState]; | ||
| }); | ||
| } | ||
| }, [gameState.gameState]); | ||
|
|
||
|
|
@@ -1194,6 +1209,13 @@ const Voice: React.FC<VoiceProps> = function ({ t, error: initialError }: VoiceP | |
| const tempTalking = { ...otherTalking }; | ||
| let talkingUpdate = false; | ||
| for (const player of otherPlayers) { | ||
| // bug with TOH where all players are considered alive during the ejection screen. This is a workaround | ||
| if (checkIfPlayerWasDeadAtStartOfMeeting(player.ptr) && !player.isDead) { | ||
| player.isDead = true; | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. O(n^2), this is what lead me to look for other ways to do it and found the otherDead variable previously mentioned. It uses an indexed type so instead of iterating the entire player list for every player you can directly look it up. I know the performance difference is probably negligible but it should be slightly faster to use a look up type and I believe this is ran for basically every frame of the game. |
||
| if (checkIfPlayerWasDeadAtStartOfMeeting(myPlayer.ptr) && !myPlayer.isDead) { | ||
| myPlayer.isDead = true; | ||
| } | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could be refactored out of the loop as we don't need to check the local players dead state for every other player. |
||
| const peerId = playerSocketIds[player.clientId]; | ||
| const audio = player.clientId === myPlayer.clientId ? undefined : audioElements.current[peerId]; | ||
| if ( | ||
|
|
||
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 might be missing something but couldn't you use the above
otherDeadvariable? It appears to be set at the time time and to the same values.