Skip to content

Commit acfdaaf

Browse files
committed
Server: Win7: Use int8 (short) datatype for player role
1 parent 2adc26e commit acfdaaf

File tree

12 files changed

+34
-35
lines changed

12 files changed

+34
-35
lines changed

InternetGamesServer/Match.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ class Match
2626
}
2727
virtual ~Match() = default;
2828

29-
virtual size_t GetRequiredPlayerCount() const { return 2; }
29+
virtual int8_t GetRequiredPlayerCount() const { return 2; }
3030
inline REFGUID GetGUID() const { return m_guid; }
3131

3232
protected:

InternetGamesServer/Win7/BackgammonMatch.cpp

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,16 @@
33
#include "PlayerSocket.hpp"
44
#include "../Util.hpp"
55

6-
#define BackgammonInvertRole(role) (role == 0 ? 1 : 0)
7-
#define BackgammonIsStoneIdxPlayer0(stoneIdx) (stoneIdx < BackgammonPlayerStones)
8-
#define BackgammonIsStoneIdxPlayer1(stoneIdx) (stoneIdx >= BackgammonPlayerStones && stoneIdx < BackgammonPlayerStones * 2)
9-
106
static const std::uniform_int_distribution<> s_dieDistribution(1, 6);
117

128
namespace Win7 {
139

10+
#define BackgammonBarX 24
11+
12+
#define BackgammonInvertRole(role) (role == 0 ? 1 : 0)
13+
#define BackgammonIsStoneIdxPlayer0(stoneIdx) (stoneIdx < BackgammonPlayerStones)
14+
#define BackgammonIsStoneIdxPlayer1(stoneIdx) (stoneIdx >= BackgammonPlayerStones && stoneIdx < BackgammonPlayerStones * 2)
15+
1416
BackgammonMatch::BackgammonMatch(PlayerSocket& player) :
1517
Match(player),
1618
m_playerPoints(),
@@ -56,7 +58,6 @@ BackgammonMatch::ClearGameState()
5658
m_playersBorneOff = {};
5759
m_initialRollStarted = false;
5860
m_doubleRequested = false;
59-
m_doubleRequested = false;
6061
m_doubleCubeValue = 1;
6162
m_doubleCubeOwner = -1;
6263
m_resignPointsOffered = 0;
@@ -65,7 +66,7 @@ BackgammonMatch::ClearGameState()
6566
}
6667

6768
void
68-
BackgammonMatch::AddGamePoints(int role, uint8_t points)
69+
BackgammonMatch::AddGamePoints(int8_t role, uint8_t points)
6970
{
7071
assert(points > 0);
7172
if ((m_playerPoints[role] += points) >= BackgammonMatchPoints)

InternetGamesServer/Win7/BackgammonMatch.hpp

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ namespace Win7 {
99
#define BackgammonMatchPoints 5
1010
#define BackgammonPlayerStones 15
1111

12-
#define BackgammonBarX 24
13-
1412
class BackgammonMatch final : public Match
1513
{
1614
public:
@@ -26,7 +24,7 @@ class BackgammonMatch final : public Match
2624
private:
2725
void ClearGameState();
2826

29-
void AddGamePoints(int role, uint8_t points);
27+
void AddGamePoints(int8_t role, uint8_t points);
3028

3129
private:
3230
std::array<uint8_t, 2> m_playerPoints;
@@ -41,7 +39,7 @@ class BackgammonMatch final : public Match
4139
bool m_initialRollStarted;
4240
bool m_doubleRequested;
4341
uint8_t m_doubleCubeValue;
44-
int m_doubleCubeOwner;
42+
int8_t m_doubleCubeOwner;
4543
uint8_t m_resignPointsOffered;
4644

4745
enum class GameState
@@ -51,7 +49,7 @@ class BackgammonMatch final : public Match
5149
START_NEXT_REQUESTED_ONCE
5250
};
5351
GameState m_gameState;
54-
int m_startNextGameRequestedOnceBy;
52+
int8_t m_startNextGameRequestedOnceBy;
5553

5654
private:
5755
BackgammonMatch(const BackgammonMatch&) = delete;

InternetGamesServer/Win7/CheckersMatch.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33
#include "PlayerSocket.hpp"
44
#include "../Util.hpp"
55

6-
#define CheckersInvertRole(role) (role == 0 ? 1 : 0)
7-
86
namespace Win7 {
97

8+
#define CheckersInvertRole(role) (role == 0 ? 1 : 0)
9+
1010
CheckersMatch::CheckersMatch(PlayerSocket& player) :
1111
Match(player),
1212
m_playerCheckersLeft({ 12, 12 }),

InternetGamesServer/Win7/CheckersMatch.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class CheckersMatch final : public Match
2323
private:
2424
std::array<int8_t, 2> m_playerCheckersLeft;
2525

26-
int m_drawOfferedBy;
26+
int8_t m_drawOfferedBy;
2727

2828
private:
2929
CheckersMatch(const CheckersMatch&) = delete;

InternetGamesServer/Win7/Match.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ Match::Update()
151151
const int playerCount = static_cast<int>(m_players.size());
152152
const std::vector<int> roles = GenerateUniqueRandomNums(0, playerCount - 1);
153153
for (int i = 0; i < playerCount; i++)
154-
const_cast<int&>(m_players[i]->m_role) = roles[i];
154+
const_cast<int8_t&>(m_players[i]->m_role) = static_cast<int8_t>(roles[i]);
155155

156156
for (PlayerSocket* p : m_players)
157157
p->OnGameStart();

InternetGamesServer/Win7/PlayerSocket.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ class PlayerSocket final : public ::PlayerSocket
6161

6262
public:
6363
// Variables, set by the match
64-
const int m_role;
64+
const int8_t m_role;
6565

6666
private:
6767
PlayerSocket(const PlayerSocket&) = delete;

InternetGamesServer/Win7/SpadesMatch.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ SpadesMatch::ProcessEvent(const tinyxml2::XMLElement& elEvent, const PlayerSocke
120120
{
121121
const bool bidDoubleNil = bid == BID_DOUBLE_NIL;
122122
if (m_playerBids[caller.m_role] != (bidDoubleNil ? BID_HAND_START : BID_SHOWN_CARDS))
123-
return {};
123+
throw std::runtime_error("SpadesMatch::ProcessEvent(): \"Move\": Player is not in a proper start bid state!");
124124

125125
bool moreBidsToSend = m_nextBidPlayer != m_handDealer ||
126126
std::all_of(m_playerBids.begin(), m_playerBids.end(), [](int bid) { return bid <= BID_SHOWN_CARDS; });

InternetGamesServer/Win7/SpadesMatch.hpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ class SpadesMatch final : public Match
1616
SpadesMatch(PlayerSocket& player);
1717

1818
Game GetGame() const override { return Game::SPADES; }
19-
size_t GetRequiredPlayerCount() const override { return 4; }
19+
int8_t GetRequiredPlayerCount() const override { return 4; }
2020

2121
std::vector<std::string> ConstructGameStartMessagesXML(const PlayerSocket& caller) const override;
2222

@@ -52,15 +52,15 @@ class SpadesMatch final : public Match
5252
std::array<int16_t, 2> m_teamPoints;
5353
std::array<int16_t, 2> m_teamBags;
5454

55-
int m_handDealer;
56-
int m_nextBidPlayer;
55+
int8_t m_handDealer;
56+
int8_t m_nextBidPlayer;
5757
std::array<int8_t, 4> m_playerBids;
5858
std::array<CardArray, 4> m_playerCards;
59-
int m_playerTurn;
60-
int m_playerTrickTurn;
59+
int8_t m_playerTurn;
60+
int8_t m_playerTrickTurn;
6161
std::array<int16_t, 4> m_playerTricksTaken;
6262

63-
CardTrick<Card, ZPA_UNSET_CARD> m_currentTrick;
63+
CardTrick<Card, int8_t, ZPA_UNSET_CARD> m_currentTrick;
6464

6565
private:
6666
SpadesMatch(const SpadesMatch&) = delete;

InternetGamesServer/WinCommon/SpadesUtil.hpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ enum class CardSuit
2323
SPADES = 3
2424
};
2525

26-
template<typename C, C UnsetVal>
26+
template<typename C, typename P, C UnsetVal>
2727
class CardTrick final
2828
{
2929
using IsCardValidFunc = bool (*)(C);
@@ -50,7 +50,7 @@ class CardTrick final
5050
m_leadCard = UnsetVal;
5151
m_playerCards = { UnsetVal, UnsetVal, UnsetVal, UnsetVal };
5252
}
53-
void Set(int player, C card)
53+
void Set(P player, C card)
5454
{
5555
assert(!IsFinished());
5656

@@ -84,7 +84,7 @@ class CardTrick final
8484
}
8585
return false;
8686
}
87-
int16_t GetWinner() const
87+
P GetWinner() const
8888
{
8989
const bool hasSpades = std::any_of(m_playerCards.begin(), m_playerCards.end(),
9090
[this](C card) {
@@ -93,8 +93,8 @@ class CardTrick final
9393
const CardSuit targetSuit = hasSpades ? CardSuit::SPADES : m_getCardSuitFunc(m_leadCard);
9494

9595
uint8_t maxRank = 0;
96-
int16_t maxRankPlayer = -1;
97-
for (int16_t i = 0; i < SpadesNumPlayers; ++i)
96+
P maxRankPlayer = -1;
97+
for (P i = 0; i < SpadesNumPlayers; ++i)
9898
{
9999
const C card = m_playerCards[i];
100100
if (m_getCardSuitFunc(card) == targetSuit)

0 commit comments

Comments
 (0)