Skip to content

Commit

Permalink
Merge pull request #137 from t3knomanzer/fix-game-mode-balancing
Browse files Browse the repository at this point in the history
Fix game mode balancing
  • Loading branch information
t3knomanzer authored Aug 19, 2020
2 parents 9078253 + c1c153e commit 5157853
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions Embedded/MaxMix/MaxMix.ino
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ bool ProcessPackage()
{
if(mode == MODE_APPLICATION)
stateApplication = STATE_APPLICATION_NAVIGATE;

return true;
}
}
Expand All @@ -295,7 +295,16 @@ bool ProcessPackage()
UpdateItemVolumeCommand(decodeBuffer, items, index);

if(IsItemActive(index))
{
if(mode == MODE_GAME)
{
if(index == itemIndexGameA && index != itemIndexGameB)
RebalanceGameVolume(items[itemIndexGameA].volume, itemIndexGameB);
if(index == itemIndexGameB && index != itemIndexGameA)
RebalanceGameVolume(items[itemIndexGameB].volume, itemIndexGameA);
}
return true;
}

}
else if(command == MSG_COMMAND_SETTINGS)
Expand Down Expand Up @@ -399,10 +408,10 @@ bool ProcessEncoderRotation()
else if(stateGame == STATE_GAME_EDIT)
{
items[itemIndexGameA].volume = ComputeAcceleratedVolume(encoderDelta, deltaTime, items[itemIndexGameA].volume);
items[itemIndexGameB].volume = ComputeAcceleratedVolume(-encoderDelta, deltaTime, items[itemIndexGameB].volume);

SendItemVolumeCommand(&items[itemIndexGameA], sendBuffer, encodeBuffer);
SendItemVolumeCommand(&items[itemIndexGameB], sendBuffer, encodeBuffer);

if(itemIndexGameA != itemIndexGameB)
RebalanceGameVolume(items[itemIndexGameA].volume, itemIndexGameB);
}
}

Expand Down Expand Up @@ -668,6 +677,12 @@ void ResetGameVolume()
SendItemVolumeCommand(&items[itemIndexGameB], sendBuffer, encodeBuffer);
}

void RebalanceGameVolume(uint8_t sourceVolume, uint8_t targetIndex)
{
items[targetIndex].volume = 100 - sourceVolume;
SendItemVolumeCommand(&items[targetIndex], sendBuffer, encodeBuffer);
}

//---------------------------------------------------------
// Finds the item with the given id.
// Returns the index of the item if found, -1 otherwise.
Expand Down

0 comments on commit 5157853

Please sign in to comment.