Skip to content

Commit 6ac9b2b

Browse files
committed
Removed constant variables from GameCommands and replace them with static constants
1 parent 8760986 commit 6ac9b2b

File tree

2 files changed

+13
-20
lines changed

2 files changed

+13
-20
lines changed

common_src/game_commands.cpp

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,34 +2,35 @@
22

33
#include <algorithm>
44

5+
static const char CLIENT_ATTACK_CMD_NAME[] = "CLIENT_ATTACK";
6+
static const char SERVER_START_BROADCAST_CMD_NAME[] = "SERVER_START_BROADCAST";
7+
static const char ENEMY_DIED_CMD_NAME[] = "ENEMY_DIED";
8+
static const char ENEMY_REVIVED_CMD_NAME[] = "ENEMY_REVIVED";
9+
510
GameCommands::GameCommands():
6-
CLIENT_ATTACK_CMD_NAME("CLIENT_ATTACK"),
7-
SERVER_START_BROADCAST_CMD_NAME("SERVER_START_BROADCAST"),
8-
ENEMY_DIED_CMD_NAME("ENEMY_DIED"),
9-
ENEMY_REVIVED_CMD_NAME("ENEMY_REVIVED"),
10-
game_commands_map({{this->CLIENT_ATTACK_CMD_NAME, 0x03},
11-
{this->SERVER_START_BROADCAST_CMD_NAME, 0x06},
12-
{this->ENEMY_DIED_CMD_NAME, 0x04},
13-
{this->ENEMY_REVIVED_CMD_NAME, 0x05}}) {}
11+
game_commands_map({{CLIENT_ATTACK_CMD_NAME, 0x03},
12+
{SERVER_START_BROADCAST_CMD_NAME, 0x06},
13+
{ENEMY_DIED_CMD_NAME, 0x04},
14+
{ENEMY_REVIVED_CMD_NAME, 0x05}}) {}
1415

1516

1617
const uint8_t GameCommands::get_client_attack_code() const {
17-
return this->game_commands_map.at(this->CLIENT_ATTACK_CMD_NAME);
18+
return this->game_commands_map.at(CLIENT_ATTACK_CMD_NAME);
1819
}
1920

2021

2122
const uint8_t GameCommands::get_server_start_broadcast_code() const {
22-
return this->game_commands_map.at(this->SERVER_START_BROADCAST_CMD_NAME);
23+
return this->game_commands_map.at(SERVER_START_BROADCAST_CMD_NAME);
2324
}
2425

2526

2627
const uint8_t GameCommands::get_enemy_died_code() const {
27-
return this->game_commands_map.at(this->ENEMY_DIED_CMD_NAME);
28+
return this->game_commands_map.at(ENEMY_DIED_CMD_NAME);
2829
}
2930

3031

3132
const uint8_t GameCommands::get_enemy_revived_code() const {
32-
return this->game_commands_map.at(this->ENEMY_REVIVED_CMD_NAME);
33+
return this->game_commands_map.at(ENEMY_REVIVED_CMD_NAME);
3334
}
3435

3536

common_src/game_commands.h

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,6 @@
77

88
class GameCommands {
99
private:
10-
// cppcheck-suppress unusedStructMember
11-
const std::string CLIENT_ATTACK_CMD_NAME;
12-
// cppcheck-suppress unusedStructMember
13-
const std::string SERVER_START_BROADCAST_CMD_NAME;
14-
// cppcheck-suppress unusedStructMember
15-
const std::string ENEMY_DIED_CMD_NAME;
16-
// cppcheck-suppress unusedStructMember
17-
const std::string ENEMY_REVIVED_CMD_NAME;
1810
// cppcheck-suppress unusedStructMember
1911
const std::unordered_map<std::string, uint8_t> game_commands_map;
2012

0 commit comments

Comments
 (0)