Skip to content

Commit 68c057e

Browse files
Merge pull request #165 from Longwater1234/dev
major code cleanup
2 parents 84ba99d + 9055894 commit 68c057e

File tree

9 files changed

+66
-55
lines changed

9 files changed

+66
-55
lines changed

BUILDING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
1. Just import this project directly in Visual Studio 2022 (or newer), with native CMake extension installed.
66
2. Wait as Visual Studio auto-configures this project for you.
77
3. Next, from top toolbar, change mode to **'Release'**, and click **Build** > **Build All**.
8-
4. Done. That's it! Your game `.exe` will be inside `{project_dir}/out/Release/bin/`. Enjoy!
8+
4. Done. That's it! Your game `.exe` will be inside `{PROJECT_DIR}/out/Release/bin/`. Enjoy!
99

1010
## On MacOS & Linux (using Terminal)
1111

@@ -21,7 +21,7 @@ cmake --build . --config Release -j
2121

2222
```
2323

24-
4. Done. Your optimized game executable (`.app` on MacOS) will be found inside `{project_dir}/out/bin/`
24+
4. Done. Your optimized game executable (`.app` on MacOS) will be found inside `{PROJECT_DIR}/out/bin/`
2525
5. Alternatively, if you have CLion IDE, you can skip ALL steps above, and use it to build in "Release" mode.
2626

2727
## Using CMake GUI (all desktop platforms)

CMakeLists.txt

Lines changed: 41 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,76 @@
11
cmake_minimum_required(VERSION 3.20 FATAL_ERROR)
22

3-
project("SpaceCheckers" VERSION 1.0.11
4-
HOMEPAGE_URL "https://github.com/Longwater1234/space-checkers")
3+
project(
4+
"SpaceCheckers"
5+
VERSION 1.0.12
6+
HOMEPAGE_URL "https://github.com/Longwater1234/space-checkers")
57

68
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
79

810
set(CMAKE_CXX_STANDARD 17)
911
set(CMAKE_CXX_STANDARD_REQUIRED TRUE)
1012
set(CMAKE_CXX_EXTENSIONS OFF)
11-
12-
if (NOT APPLE)
13-
set(SFML_STATIC_LIBRARIES TRUE)
14-
endif()
13+
# Only macOS links SFML as Frameworks, not static
14+
if(NOT APPLE)
15+
set(SFML_STATIC_LIBRARIES TRUE)
16+
endif()
1517

1618
# write app version into Header
17-
configure_file(
18-
${CMAKE_CURRENT_SOURCE_DIR}/src/proto_schema/AppVersion.hpp.in
19-
${CMAKE_CURRENT_SOURCE_DIR}/src/AppVersion.hpp
20-
)
19+
configure_file(${CMAKE_CURRENT_SOURCE_DIR}/src/proto_schema/AppVersion.hpp.in
20+
${CMAKE_CURRENT_SOURCE_DIR}/src/AppVersion.hpp)
2121

2222
# ==== UPDATE ME HERE ===========
2323
# Absolute path where you installed SFML (Required on Windows)
24-
set(SFML_HOME "C:/SFML/SFML-2.6.1")
25-
set(SFML_DIR ${SFML_HOME}/lib/cmake/SFML)
24+
set(SFML_HOME "C:/SFML/SFML-2.6.1")
25+
set(SFML_DIR ${SFML_HOME}/lib/cmake/SFML)
2626
# ==========================
2727

2828
# Collect all sources
29-
file(GLOB_RECURSE GAME_SRC "src/*.cpp" "src/*.hpp")
30-
find_package(SFML 2.6 REQUIRED COMPONENTS "graphics" "window" "system")
29+
file(GLOB_RECURSE GAME_SRC "src/*.cpp" "src/*.hpp")
30+
find_package(SFML 2.6 REQUIRED COMPONENTS "graphics" "window" "system")
3131

32-
# download extra libs
33-
add_subdirectory(dependencies)
32+
# download extra libs
33+
add_subdirectory(dependencies)
3434

3535
if(WIN32)
3636
add_executable(SpaceCheckers WIN32 ${GAME_SRC} ${CMAKE_SOURCE_DIR}/resources/win-icon.rc)
3737
target_link_libraries(SpaceCheckers PRIVATE sfml-main)
38-
elseif(APPLE)
38+
elseif(APPLE)
3939
include(${CMAKE_SOURCE_DIR}/cmake/macbundle.cmake)
4040
find_library(FOUNDATION_FRAMEWORK Foundation)
4141
target_link_libraries(SpaceCheckers PRIVATE ${FOUNDATION_FRAMEWORK})
42-
else()
43-
add_executable(SpaceCheckers ${GAME_SRC})
44-
endif()
42+
else()
43+
add_executable(SpaceCheckers ${GAME_SRC})
44+
endif()
4545

46-
# link all required libraries
47-
target_link_libraries(SpaceCheckers PRIVATE sfml-graphics sfml-window sfml-system ImGui-SFML
48-
ixwebsocket spdlog::spdlog cpr::cpr simdjson::simdjson protobuf::libprotobuf)
46+
# link all required libraries
47+
target_link_libraries(
48+
SpaceCheckers
49+
PRIVATE sfml-graphics
50+
sfml-window
51+
sfml-system
52+
ImGui-SFML
53+
ixwebsocket
54+
spdlog::spdlog
55+
cpr::cpr
56+
simdjson::simdjson
57+
protobuf::libprotobuf)
4958

5059
# include SFML headers
5160
target_include_directories(SpaceCheckers PUBLIC ${SFML_HOME}/include)
5261

5362
# show warnings (depending on C++ compiler)
54-
if (MSVC)
55-
target_compile_options(SpaceCheckers PRIVATE /W4 /sdl /Qvec-report:1)
56-
else()
57-
target_compile_options(SpaceCheckers PRIVATE -Wall -Werror=constant-conversion)
63+
if(MSVC)
64+
target_compile_options(SpaceCheckers PRIVATE /W4 /sdl)
65+
else()
66+
target_compile_options(SpaceCheckers PRIVATE -Wall -Werror=constant-conversion)
5867
endif()
59-
68+
6069
# COPY resources folder to destination
61-
if (NOT APPLE)
62-
add_custom_command(
63-
TARGET SpaceCheckers
70+
if(NOT APPLE)
71+
add_custom_command(
72+
TARGET SpaceCheckers
6473
POST_BUILD
6574
COMMAND ${CMAKE_COMMAND} -E copy_directory ${PROJECT_SOURCE_DIR}/resources
6675
$<TARGET_FILE_DIR:SpaceCheckers>/resources)
67-
endif()
76+
endif()

TODO.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22

33
- [ ] (Online mode) Display countdown timer (40 s), waiting for player's move. Reset it when they make a move.
44
- [ ] Record and list all previous moves and captures (for current match), in a scroll panel.
5+
- [ ] highlight cell color blue after clicking a piece, reset when click srcCell = null
6+
- [ ] write unit tests using googletests
57

68
### (Extras) Standard CJK font paths
79

@@ -10,5 +12,5 @@
1012
- How to load CJK font in imGui:
1113

1214
```cpp
13-
ImFont* font = io.Fonts->AddFontFromFileTTF("/path/to/font.ext", 18.0f, nullptr, io.Fonts->GetGlyphRangesChineseFull());
14-
```
15+
ImFont* font = io.Fonts->AddFontFromFileTTF("/path/to/font.file", 18.0f, nullptr, io.Fonts->GetGlyphRangesChineseFull());
16+
```

cmake/macbundle.cmake

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,21 +4,21 @@ set(application_icon "${CMAKE_SOURCE_DIR}/resources/${MACOSX_BUNDLE_ICON_FILE}")
44
set_source_files_properties(${application_icon}
55
PROPERTIES MACOSX_PACKAGE_LOCATION "Resources")
66

7-
# images
8-
file(GLOB_RECURSE my_images "${CMAKE_SOURCE_DIR}/resources/*")
9-
foreach(FILE ${my_images})
10-
get_filename_component(FILENAME ${FILE} DIRECTORY)
11-
# SKIP .DS_Store files
7+
# images and fonts
8+
file(GLOB_RECURSE assets "${CMAKE_SOURCE_DIR}/resources/*")
9+
foreach(FILE ${assets})
10+
get_filename_component(FILENAME ${FILE} NAME)
11+
# skip .DS_Store files
1212
if (NOT FILENAME STREQUAL ".DS_Store")
1313
file(RELATIVE_PATH NEW_FILE "${CMAKE_SOURCE_DIR}/" ${FILE})
14-
get_filename_component(NEW_FILE_PATH ${NEW_FILE} DIRECTORY)
15-
set_source_files_properties(${FILE} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources/${NEW_FILE_PATH}")
14+
get_filename_component(PARENT_DIR ${NEW_FILE} DIRECTORY) # parent dir
15+
set_source_files_properties(${PARENT_DIR} PROPERTIES MACOSX_PACKAGE_LOCATION "Resources/${PARENT_DIR}")
1616
endif()
1717
endforeach()
1818

1919
add_executable(${CMAKE_PROJECT_NAME} MACOSX_BUNDLE
2020
${GAME_SRC} "${CMAKE_SOURCE_DIR}/src/utils/ResourcePath.mm"
21-
${application_icon} "${my_images}")
21+
${application_icon} "${assets}")
2222

2323
set_target_properties(
2424
${CMAKE_PROJECT_NAME}
@@ -31,4 +31,4 @@ set_target_properties(
3131
MACOSX_BUNDLE_COPYRIGHT "(c) 2024, Davis Tibbz"
3232
MACOSX_BUNDLE_BUNDLE_VERSION ${PROJECT_VERSION}
3333
MACOSX_BUNDLE_SHORT_VERSION_STRING ${PROJECT_VERSION}
34-
RESOURCE "${my_images}")
34+
RESOURCE "${assets}")

src/AppVersion.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
// clang-format off
77
namespace chk {
8-
constexpr const char* APP_VERSION = "1.0.11";
8+
constexpr const char* APP_VERSION = "1.0.12";
99
}
1010

1111
#endif // APP_VERSION_HPP

src/GameManager.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,11 +82,11 @@ class GameManager
8282
// collection of Player's next targets (Map<HunterPieceID, CaptureTarget>)
8383
std::unordered_map<short, chk::CaptureTarget> forcedMoves{};
8484

85-
[[nodiscard]] const bool isPlayerRedTurn() const;
85+
[[nodiscard]] bool isPlayerRedTurn() const;
8686
[[nodiscard]] short getPieceFromCell(const int cell_idx) const;
8787
[[nodiscard]] const std::vector<chk::Block> &getBlockList() const;
8888
[[nodiscard]] bool isHunterActive() const;
89-
[[nodiscard]] const bool isGameOver() const;
89+
[[nodiscard]] bool isGameOver() const;
9090
void setSourceCell(const int src_cell);
9191
void doCleanup();
9292
void identifyTargets(const chk::PlayerPtr &hunter, const chk::Block &singleCell = nullptr);

src/Player.hpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ class Player final
2424
void losePiece(const short targetId);
2525
[[nodiscard]] const std::unordered_map<short, chk::PiecePtr> &getOwnPieces() const;
2626
void showMyHunters(const std::set<short> &hunterPieces) const;
27-
void emptyBasket();
27+
void clearBasket();
2828
[[nodiscard]] size_t getPieceCount() const;
2929
[[nodiscard]] const std::string &getName() const;
3030
[[nodiscard]] PlayerType getPlayerType() const;
@@ -89,7 +89,7 @@ inline void Player::showMyHunters(const std::set<short> &hunterPieces) const
8989
/**
9090
* Remove all pieces from this player's ownership
9191
*/
92-
inline void Player::emptyBasket()
92+
inline void Player::clearBasket()
9393
{
9494
this->basket.clear();
9595
}

src/managers/GameManager.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ void GameManager::handleCapturePiece(const chk::PlayerPtr &hunter, const chk::Pl
181181
* Whether it's Red player's turn
182182
* @return TRUE or FALSE
183183
*/
184-
const bool GameManager::isPlayerRedTurn() const
184+
bool GameManager::isPlayerRedTurn() const
185185
{
186186
return this->playerRedTurn;
187187
}
@@ -202,8 +202,8 @@ void chk::GameManager::doCleanup()
202202
{
203203
this->gameMap.clear();
204204
this->forcedMoves.clear();
205-
this->playerRed->emptyBasket();
206-
this->playerBlack->emptyBasket();
205+
this->playerRed->clearBasket();
206+
this->playerBlack->clearBasket();
207207
this->gameOver = true;
208208
this->alreadyCached = false;
209209
this->sourceCell = std::nullopt;
@@ -368,7 +368,7 @@ void chk::GameManager::showForcedMoves(const chk::PlayerPtr &player, const chk::
368368
* Whether game is over
369369
* @return TRUE or FALSE
370370
*/
371-
const bool GameManager::isGameOver() const
371+
bool GameManager::isGameOver() const
372372
{
373373
return this->gameOver;
374374
}

src/managers/OnlineGameManager.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ inline void chk::OnlineGameManager::createAllPieces()
9696
{
9797
if ((row + col) % 2 != 0)
9898
{
99-
sf::CircleShape circle(0.5 * chk::SIZE_CELL);
99+
sf::CircleShape circle{0.5 * chk::SIZE_CELL};
100100
const float x = static_cast<float>(col % NUM_COLS) * chk::SIZE_CELL;
101101
circle.setPosition(sf::Vector2f{x, row * chk::SIZE_CELL});
102102
if (row < 3 && blackItr != payload.pieces_black().end())

0 commit comments

Comments
 (0)