Skip to content
Open
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
22 changes: 22 additions & 0 deletions src/renderer/Voice.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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;
Expand All @@ -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];
});
Copy link
Copy Markdown
Collaborator

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 otherDead variable? It appears to be set at the time time and to the same values.

}
}, [gameState.gameState]);

Expand Down Expand Up @@ -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;
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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;
}
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The 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 (
Expand Down