Skip to content

Commit

Permalink
Minor code changes
Browse files Browse the repository at this point in the history
  • Loading branch information
Arcidev committed Aug 20, 2024
1 parent aff3ae3 commit fb2392f
Show file tree
Hide file tree
Showing 5 changed files with 11 additions and 18 deletions.
2 changes: 1 addition & 1 deletion Server/Server/Achievements/AchievementMgr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ void AchievementManager::updateUserAchievementProgress()
}

m_locker.lock();
auto mapCopy = UserAchievementProgress(m_userAchievementProgress);
auto mapCopy = UserAchievementProgressMap(m_userAchievementProgress);
m_userAchievementProgress.clear();
m_locker.unlock();

Expand Down
4 changes: 2 additions & 2 deletions Server/Server/Achievements/AchievementMgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ typedef std::map<uint32_t, Achievement> AchievementMap;
class AchievementManager
{
private:
typedef std::map<std::tuple<uint32_t, uint32_t>, uint32_t> UserAchievementProgress;
typedef std::map<std::tuple<uint32_t, uint32_t>, uint32_t> UserAchievementProgressMap;

std::mutex m_locker;
UserAchievementProgress m_userAchievementProgress;
UserAchievementProgressMap m_userAchievementProgress;
DbAchievementMap m_achievementMap;
std::thread m_userAchievementProgressThread;
bool m_stopUpdateThread;
Expand Down
16 changes: 5 additions & 11 deletions Server/Server/Game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "PacketHandlers/Packet.h"
#include "Cards/PlayableCard.h"

Game::Game() : m_activePlayerId(0), m_player1(nullptr), m_player2(nullptr), m_nextCardGuid(1) {}
Game::Game() : m_activePlayer(nullptr), m_player1(nullptr), m_player2(nullptr), m_nextCardGuid(1) {}

// Free resources
Game::~Game()
Expand Down Expand Up @@ -71,12 +71,6 @@ Player* Game::GetOpponent(Player const* player) const
return player->GetId() == m_player1->GetId() ? m_player2 : m_player1;
}

// Returns currently active player
Player* Game::GetActivePlayer() const
{
return m_activePlayerId == m_player1->GetId() ? m_player1 : m_player2;
}

// Sends packet to all players in this game
void Game::BroadcastPacket(Packet const& packet) const
{
Expand All @@ -90,12 +84,12 @@ void Game::BroadcastPacket(Packet const& packet) const
// Activates second player and deactives the active one
void Game::ActivateSecondPlayer()
{
if (m_activePlayerId)
m_activePlayerId = (m_player1->GetId() == m_activePlayerId) ? m_player2->GetId() : m_player1->GetId();
if (m_activePlayer)
m_activePlayer = (m_player1 == m_activePlayer) ? m_player2 : m_player1;
else
m_activePlayerId = (rand() % 2) ? m_player1->GetId() : m_player2->GetId();
m_activePlayer = (rand() % 2) ? m_player1 : m_player2;

PlayableCard* currentCard = GetActivePlayer()->GetCurrentCard();
PlayableCard* currentCard = m_activePlayer->GetCurrentCard();
if (!currentCard)
return;

Expand Down
5 changes: 2 additions & 3 deletions Server/Server/Game.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Packet;
class Game
{
private:
uint32_t m_activePlayerId;
Player* m_activePlayer;
Player* m_player1;
Player* m_player2;
uint64_t m_nextCardGuid;
Expand All @@ -27,8 +27,7 @@ class Game

uint64_t GetNextCardGuid() { return m_nextCardGuid++; };
Player* GetOpponent(Player const* player) const;
Player* GetActivePlayer() const;
uint32_t GetActivePlayerId() const { return m_activePlayerId; }
Player* GetActivePlayer() const { return m_activePlayer; }
void BroadcastPacket(Packet const& packet) const;
};

2 changes: 1 addition & 1 deletion Server/Server/Player.h
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,5 @@ class Player
std::string_view GetName() const;
ConnectedUser* GetUser() const { return m_user; }
bool IsPrepared() const { return m_isPrepared; }
bool IsActive() const { return m_game->GetActivePlayerId() == m_id; }
bool IsActive() const { return m_game->GetActivePlayer() == this; }
};

0 comments on commit fb2392f

Please sign in to comment.