Skip to content
This repository was archived by the owner on Jan 5, 2024. It is now read-only.

Commit d3a53f5

Browse files
authored
Merge pull request #562 from cortex-command-community/multiplayer-fixes
Fix multiplayer mouse buttons and glows
2 parents ac055c1 + 0911023 commit d3a53f5

File tree

4 files changed

+45
-32
lines changed

4 files changed

+45
-32
lines changed

Managers/PostProcessMan.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -177,29 +177,29 @@ namespace RTE {
177177

178178
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
179179

180-
void PostProcessMan::AdjustEffectsPosToPlayerScreen(int playerScreen, BITMAP *targetBitmap, const Vector &targetBitmapOffset, std::list<PostEffect> &screenRelativeEffectsList, std::list<Box> &screenRelativeGlowBoxesList) const {
180+
void PostProcessMan::AdjustEffectsPosToPlayerScreen(int playerScreen, BITMAP *targetBitmap, const Vector &targetBitmapOffset, std::list<PostEffect> &screenRelativeEffectsList, std::list<Box> &screenRelativeGlowBoxesList) {
181181
int screenOcclusionOffsetX = g_CameraMan.GetScreenOcclusion(playerScreen).GetFloorIntX();
182182
int screenOcclusionOffsetY = g_CameraMan.GetScreenOcclusion(playerScreen).GetFloorIntY();
183183
int occludedOffsetX = targetBitmap->w + screenOcclusionOffsetX;
184184
int occludedOffsetY = targetBitmap->h + screenOcclusionOffsetY;
185185

186186
// Copy post effects received by client if in network mode
187187
if (g_FrameMan.GetDrawNetworkBackBuffer()) {
188-
g_PostProcessMan.GetNetworkPostEffectsList(0, screenRelativeEffectsList);
188+
GetNetworkPostEffectsList(0, screenRelativeEffectsList);
189189
}
190190

191191
// Adjust for the player screen's position on the final buffer
192192
for (const PostEffect &postEffect : screenRelativeEffectsList) {
193193
// Make sure we won't be adding any effects to a part of the screen that is occluded by menus and such
194194
if (postEffect.m_Pos.GetFloorIntX() > screenOcclusionOffsetX && postEffect.m_Pos.GetFloorIntY() > screenOcclusionOffsetY && postEffect.m_Pos.GetFloorIntX() < occludedOffsetX && postEffect.m_Pos.GetFloorIntY() < occludedOffsetY) {
195-
g_PostProcessMan.GetPostScreenEffectsList()->push_back(PostEffect(postEffect.m_Pos + targetBitmapOffset, postEffect.m_Bitmap, postEffect.m_BitmapHash, postEffect.m_Strength, postEffect.m_Angle));
195+
m_PostSceneEffects.emplace_back(postEffect.m_Pos + targetBitmapOffset, postEffect.m_Bitmap, postEffect.m_BitmapHash, postEffect.m_Strength, postEffect.m_Angle);
196196
}
197197
}
198198
// Adjust glow areas for the player screen's position on the final buffer
199199
for (const Box &glowBox : screenRelativeGlowBoxesList) {
200-
g_PostProcessMan.GetPostScreenGlowBoxesList()->push_back(glowBox);
200+
m_PostScreenGlowBoxes.push_back(glowBox);
201201
// Adjust each added glow area for the player screen's position on the final buffer
202-
g_PostProcessMan.GetPostScreenGlowBoxesList()->back().m_Corner += targetBitmapOffset;
202+
m_PostScreenGlowBoxes.back().m_Corner += targetBitmapOffset;
203203
}
204204
}
205205

@@ -208,9 +208,6 @@ namespace RTE {
208208
void PostProcessMan::RegisterPostEffect(const Vector &effectPos, BITMAP *effect, size_t hash, int strength, float angle) {
209209
// These effects get applied when there's a drawn frame that followed one or more sim updates.
210210
// They are not only registered on drawn sim updates; flashes and stuff could be missed otherwise if they occur on undrawn sim updates.
211-
if (effect && !effect->extra) {
212-
LazyInitBitmap(effect);
213-
}
214211

215212
if (effect && g_TimerMan.SimUpdatesSinceDrawn() >= 0) {
216213
m_PostSceneEffects.push_back(PostEffect(effectPos, effect, hash, strength, angle));
@@ -516,7 +513,7 @@ namespace RTE {
516513

517514
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
518515

519-
void PostProcessMan::DrawPostScreenEffects() const {
516+
void PostProcessMan::DrawPostScreenEffects() {
520517
BITMAP *effectBitmap = nullptr;
521518
float effectPosX = 0;
522519
float effectPosY = 0;
@@ -530,6 +527,9 @@ namespace RTE {
530527

531528
for (const PostEffect &postEffect : m_PostScreenEffects) {
532529
if (postEffect.m_Bitmap) {
530+
if (!postEffect.m_Bitmap->extra) {
531+
LazyInitBitmap(postEffect.m_Bitmap);
532+
}
533533
effectBitmap = postEffect.m_Bitmap;
534534
effectStrength = postEffect.m_Strength / 255.f;
535535
effectPosX = postEffect.m_Pos.m_X;

Managers/PostProcessMan.h

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -95,16 +95,10 @@ namespace RTE {
9595
/// <param name="targetBitmapOffset">The position of the specified player's draw screen on the backbuffer.</param>
9696
/// <param name="screenRelativeEffectsList">List of the specified player's accumulated post effects for this frame.</param>
9797
/// <param name="screenRelativeGlowBoxesList">List of the specified player's accumulated glow boxes for this frame.</param>
98-
void AdjustEffectsPosToPlayerScreen(int playerScreen, BITMAP *targetBitmap, const Vector &targetBitmapOffset, std::list<PostEffect> &screenRelativeEffectsList, std::list<Box> &screenRelativeGlowBoxesList) const;
98+
void AdjustEffectsPosToPlayerScreen(int playerScreen, BITMAP *targetBitmap, const Vector &targetBitmapOffset, std::list<PostEffect> &screenRelativeEffectsList, std::list<Box> &screenRelativeGlowBoxesList);
9999
#pragma endregion
100100

101101
#pragma region Post Effect Handling
102-
/// <summary>
103-
/// Gets the list of effects to apply at the end of each frame.
104-
/// </summary>
105-
/// <returns>The list of effects to apply at the end of each frame.</returns>
106-
std::list<PostEffect> * GetPostScreenEffectsList() { return &m_PostScreenEffects; }
107-
108102
/// <summary>
109103
/// Registers a post effect to be added at the very last stage of 32bpp rendering by the FrameMan.
110104
/// </summary>
@@ -136,11 +130,6 @@ namespace RTE {
136130
#pragma endregion
137131

138132
#pragma region Post Pixel Glow Handling
139-
/// <summary>
140-
/// Gets the list of areas that will be processed with glow.
141-
/// </summary>
142-
/// <returns>The list of areas that will be processed with glow.</returns>
143-
std::list<Box> * GetPostScreenGlowBoxesList() { return &m_PostScreenGlowBoxes; }
144133

145134
/// <summary>
146135
/// Registers a specific IntRect to be post-processed and have special pixel colors lit up by glow effects in it.
@@ -284,7 +273,7 @@ namespace RTE {
284273
/// <summary>
285274
/// Draws all the glow effects registered for this frame. This is called from PostProcess().
286275
/// </summary>
287-
void DrawPostScreenEffects() const;
276+
void DrawPostScreenEffects();
288277
#pragma endregion
289278

290279
/// <summary>

Managers/UInputMan.cpp

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -651,16 +651,7 @@ namespace RTE {
651651
return false;
652652
}
653653
if (IsInMultiplayerMode()) {
654-
if (whichPlayer < Players::PlayerOne || whichPlayer >= Players::MaxPlayerCount) {
655-
for (int player = Players::PlayerOne; player < Players::MaxPlayerCount; player++) {
656-
if (m_NetworkServerChangedMouseButtonState[player][whichButton]) {
657-
return m_NetworkServerChangedMouseButtonState[player][whichButton];
658-
}
659-
}
660-
return m_NetworkServerChangedMouseButtonState[Players::PlayerOne][whichButton];
661-
} else {
662-
return m_NetworkServerChangedMouseButtonState[whichPlayer][whichButton];
663-
}
654+
return GetNetworkMouseButtonState(whichPlayer, whichButton, whichState);
664655
}
665656

666657
switch (whichState) {
@@ -676,6 +667,30 @@ namespace RTE {
676667
}
677668
}
678669

670+
bool UInputMan::GetNetworkMouseButtonState(int whichPlayer, int whichButton, InputState whichState) const {
671+
672+
if (whichPlayer == Players::NoPlayer || whichPlayer >= Players::MaxPlayerCount) {
673+
for (int player = Players::PlayerOne; player < Players::MaxPlayerCount; ++player) {
674+
if (GetNetworkMouseButtonState(player, whichButton, whichState)) {
675+
return true;
676+
}
677+
}
678+
return false;
679+
}
680+
681+
switch (whichState) {
682+
case InputState::Held:
683+
return m_NetworkServerPreviousMouseButtonState[whichPlayer][whichButton];
684+
case InputState::Pressed:
685+
return m_NetworkServerPreviousMouseButtonState[whichPlayer][whichButton] && m_NetworkServerChangedMouseButtonState[whichPlayer][whichButton];
686+
case InputState::Released:
687+
return !m_NetworkServerPreviousMouseButtonState[whichPlayer][whichButton] && m_NetworkServerChangedMouseButtonState[whichPlayer][whichButton];
688+
default:
689+
RTEAbort("Undefined InputState value passed in. See InputState enumeration.");
690+
return false;
691+
}
692+
}
693+
679694
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
680695

681696
bool UInputMan::GetJoystickButtonState(int whichJoy, int whichButton, InputState whichState) const {

Managers/UInputMan.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -757,6 +757,15 @@ namespace RTE {
757757
/// <returns>Whether the mouse button is in the specified state or not.</returns>
758758
bool GetMouseButtonState(int whichPlayer, int whichButton, InputState whichState) const;
759759

760+
/// <summary>
761+
/// Gets whether a multiplayer mouse button is in the specified state.
762+
/// </summary>
763+
/// <param name="whichPlayer">Which player to check for. See Players enumeration.</param>
764+
/// <param name="whichButton">Which mouse button to check for. See MouseButtons enumeration.</param>
765+
/// <param name="whichState">Which state to check for. See InputState enumeration.</param>
766+
/// <returns>Whether the mouse button is in the specified state or not.</returns>
767+
bool GetNetworkMouseButtonState(int whichPlayer, int whichButton, InputState whichState) const;
768+
760769
/// <summary>
761770
/// Gets whether a joystick button is in the specified state.
762771
/// </summary>

0 commit comments

Comments
 (0)