Skip to content

Commit 2e9ec6d

Browse files
Merge pull request #152 from Longwater1234/dev
2 parents 1a10eef + b0ecf25 commit 2e9ec6d

File tree

12 files changed

+62
-62
lines changed

12 files changed

+62
-62
lines changed

BUILDING.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ cmake --build . --config Release --target all
3434
![cmake_screenshot](cmake/cmake_gui_screenshot.png)
3535

3636
- Set "Source Folder" (1) to this project root. Then set "Build Folder" (2) to a NEW _relative_ folder `/build` or `/out`. See image above. Then (3) click "**Configure**",
37-
- In the next screen, Choose **Unix Makefiles** on Linux; choose **Xcode** on Mac. Choose **Visual Studio** on Windows. Then click OK to save.
37+
- In the next screen, Choose **Unix Makefiles** if on Linux; choose **XCode** if on Mac. Choose **Visual Studio** if on Windows. Then click OK to save.
3838
- Make sure CMAKE_BUILD_TYPE is **Release**.
3939
- Click Configure once again, then **Generate**.
40-
- Finally, open build folder, then run `make all` in Terminal (Linux). On Windows and MacOS, click open project for building.
40+
- Finally, on Windows and MacOS, click **Open Project** for building in respective IDE. On Linux desktop, open build folder, then run `make all` in Terminal.

CMakeLists.txt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
cmake_minimum_required(VERSION 3.20 FATAL_ERROR)
22

3-
project("SpaceCheckers" VERSION 1.0.9
3+
project("SpaceCheckers" VERSION 1.0.10
44
HOMEPAGE_URL "https://github.com/Longwater1234/space-checkers")
55

66
set(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_BINARY_DIR}/bin)
@@ -14,12 +14,11 @@ endif()
1414
# ==== UPDATE ME HERE ===========
1515
# Absolute path where you installed SFML (Required on Windows)
1616
set(SFML_HOME "C:/SFML/SFML-2.6.1")
17+
set(SFML_DIR ${SFML_HOME}/lib/cmake/SFML)
1718
# ==========================
1819

1920
# Collect all sources
2021
file(GLOB_RECURSE GAME_SRC "src/*.cpp" "src/*.hpp")
21-
set(SFML_DIR ${SFML_HOME}/lib/cmake/SFML)
22-
2322
find_package(SFML 2.6 REQUIRED COMPONENTS "graphics" "window" "system")
2423

2524
# download extra libs
@@ -47,7 +46,7 @@ include_directories(${SFML_HOME}/include)
4746
if(MSVC)
4847
target_compile_options(SpaceCheckers PRIVATE /W4 /sdl /Qvec-report:1)
4948
else()
50-
target_compile_options(SpaceCheckers PRIVATE -Wall)
49+
target_compile_options(SpaceCheckers PRIVATE -Wall -Werror=overflow)
5150
endif()
5251

5352
# COPY resources folder to destination

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ The only dependency you need pre-installed on your OS is SFML 2.6.x (or newer).
5656

5757
## Building Instructions
5858

59-
Please see [BUILDING.md](BUILDING.md) for detailed instructions. For macOS-specific build guide with XCode, please refer to [instructions](cmake/macbundle.cmake)
59+
Please see [BUILDING.md](BUILDING.md) for detailed instructions. For macOS-specific build guide with XCode, please [see this doc](cmake/README.md)
6060

6161
### License
6262

cmake/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
## What's 'macbundle.cmake' for?
22

3-
This contains cmake instructions to build MacOS GUI `.app` bundle. It embeds the icon to the app bundle. It also copies all static assets into the bundle at build time.
3+
This contains CMake script to build MacOS GUI `.app` bundle. It embeds the icon to the app bundle. It also copies all static assets into the bundle at build time.
44

55
If you installed SFML as "Frameworks", you will need to tell XCode to copy them into the bundle before Building. Follow these steps:
66

src/CaptureTarget.hpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
#pragma once
2-
#include <ostream>
32

43
namespace chk
54
{
@@ -11,14 +10,6 @@ struct CaptureTarget
1110
short preyPieceId{-1}; // ID of the piece that MUST be captured
1211
int preyCellIdx{-1}; // the cell hosting this piece
1312
int hunterNextCell{-1}; // destination of hunter AFTER capturing enemy
14-
15-
// override output operator
16-
friend std::ostream &operator<<(std::ostream &os, const CaptureTarget &target)
17-
{
18-
os << "preyPieceId: " << target.preyPieceId << " preyCellIdx: " << target.preyCellIdx
19-
<< "hunterNextCell: " << target.hunterNextCell;
20-
return os;
21-
}
2213
};
2314

2415
} // namespace chk

src/Cell.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ inline void Cell::draw(sf::RenderTarget &target, sf::RenderStates states) const
6060
}
6161

6262
/**
63-
* Whether this cell is in even numbered row
63+
* Whether this cell is in even-numbered row
6464
* @return TRUE or FALSE
6565
*/
6666
inline bool Cell::getIsEvenRow() const

src/CircularBuffer.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ template <typename T> class CircularBuffer
2222
m_deque.resize(max_capacity);
2323
}
2424
CircularBuffer() = delete;
25-
CircularBuffer(CircularBuffer &&other) = delete;
25+
CircularBuffer &operator=(const CircularBuffer &) = delete;
2626
CircularBuffer(CircularBuffer &other) = delete;
2727
void addItem(const T &item);
2828
T &getTop() noexcept;

src/MainMenu.hpp

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,28 +14,35 @@
1414
#include <SFML/Window/Mouse.hpp>
1515
#include <memory>
1616
#include <string>
17+
1718
namespace chk
1819
{
1920
constexpr auto ICON_PATH = "win-icon-16.png";
2021
constexpr auto FONT_PATH = "notosans-regular.ttf";
21-
constexpr auto APP_VERSION = "v1.0.9";
22+
constexpr auto APP_VERSION = "v1.0.10";
2223

2324
enum class UserChoice
2425
{
2526
LOCAL_PLAY = 38483, // playing offline
2627
ONLINE_PLAY, // playing online
2728
};
2829

30+
/**
31+
* Shown first when game is launched
32+
*/
2933
class MainMenu final
3034
{
3135
public:
3236
explicit MainMenu(sf::RenderWindow *windowPtr);
37+
MainMenu() = delete;
38+
MainMenu(const MainMenu &) = delete;
39+
MainMenu &operator=(const MainMenu &) = delete;
3340
chk::UserChoice runMainLoop();
3441

3542
private:
3643
void init();
3744
sf::RenderWindow *window;
38-
sf::Texture mainImage;
45+
sf::Texture bgroundImage;
3946
sf::RectangleShape mainFrame;
4047
sf::RectangleShape localBtn;
4148
sf::RectangleShape onlineBtn;
@@ -49,12 +56,12 @@ inline MainMenu::MainMenu(sf::RenderWindow *windowPtr)
4956
{
5057
this->window = windowPtr;
5158
this->mainFrame = sf::RectangleShape(sf::Vector2f(600, 700));
52-
if (!this->mainImage.loadFromFile(chk::getResourcePath("main_menu_en.png")))
59+
if (!this->bgroundImage.loadFromFile(chk::getResourcePath("main_menu_en.png")))
5360
{
54-
perror("cannot find home image");
61+
perror("cannot find background image");
5562
exit(EXIT_FAILURE);
5663
}
57-
mainFrame.setTexture(&this->mainImage);
64+
mainFrame.setTexture(&this->bgroundImage);
5865
mainFrame.setPosition(0, 0);
5966
sf::Image appIcon;
6067
if (appIcon.loadFromFile(chk::getResourcePath(ICON_PATH)))
@@ -92,6 +99,7 @@ inline void MainMenu::init()
9299

93100
/**
94101
* Listen for GUI events, and store the selected choice to `result`
102+
* @param result Output will be written into this
95103
*/
96104
inline void MainMenu::handleEvents(chk::UserChoice &result)
97105
{
@@ -123,8 +131,8 @@ inline void MainMenu::handleEvents(chk::UserChoice &result)
123131
}
124132

125133
/**
126-
* The main loop, renders the main menu screen, returning user choice for game Mode
127-
* @return The selected result
134+
* The main loop, renders the main menu screen at 60FPS
135+
* @return user choice for game Mode
128136
*/
129137
inline chk::UserChoice MainMenu::runMainLoop()
130138
{
@@ -148,7 +156,7 @@ inline chk::UserChoice MainMenu::runMainLoop()
148156
{
149157
this->localBtn.setOutlineThickness(0);
150158
}
151-
if (this->onlineBtn.getGlobalBounds().contains(sf::Vector2f(mousePos)))
159+
if (this->onlineBtn.getGlobalBounds().contains(sf::Vector2f{mousePos}))
152160
{
153161
this->onlineBtn.setOutlineColor(DARK_BROWN);
154162
this->onlineBtn.setOutlineThickness(5.0f);

src/WsClient.cpp

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
#include "WsClient.hpp"
22

3-
using namespace chk;
4-
3+
namespace chk
4+
{
55
chk::WsClient::WsClient()
66
{
77
ix::initNetSystem();
@@ -87,10 +87,10 @@ void WsClient::showPublicServerWindow(bool &showPublic)
8787
ImGui::SetNextWindowSize(ImVec2{300.0f, 300.0f});
8888
if (ImGui::Begin("Public Servers", nullptr, ImGuiWindowFlags_NoResize | ImGuiWindowFlags_NoCollapse))
8989
{
90-
static int current_idx = 0;
90+
static size_t current_idx{0};
9191
if (ImGui::BeginListBox("Select One"))
9292
{
93-
for (int i = 0; i < publicServers.size(); ++i)
93+
for (size_t i = 0; i < publicServers.size(); ++i)
9494
{
9595
const bool selected = (i == current_idx);
9696
if (ImGui::Selectable(publicServers.at(i).name.c_str(), selected))
@@ -138,7 +138,7 @@ void WsClient::asyncFetchPublicServers()
138138
* Parse the JSON response of server list then display them
139139
* @param response From the previous request
140140
*/
141-
void chk::WsClient::parseServerList(const cpr::Response &response)
141+
void WsClient::parseServerList(const cpr::Response &response)
142142
{
143143
if (response.status_code != 200)
144144
{
@@ -174,7 +174,7 @@ void chk::WsClient::parseServerList(const cpr::Response &response)
174174
/**
175175
* Reset all local states to FALSE or empty string
176176
*/
177-
void chk::WsClient::resetAllStates()
177+
void WsClient::resetAllStates()
178178
{
179179
this->isConnected = false;
180180
this->connClicked = false;
@@ -186,13 +186,13 @@ void chk::WsClient::resetAllStates()
186186
/**
187187
* Run main loop of showing connection window, tryConnect, and handle exchanges
188188
*/
189-
void chk::WsClient::runMainLoop()
189+
void WsClient::runMainLoop()
190190
{
191191

192192
// clang-format off
193193
if (!isConnected) {
194194
if (!connClicked) {
195-
this->showConnectWindow();
195+
this->showConnectWindow();
196196
} else {
197197
this->tryConnect(final_address);
198198
}
@@ -201,12 +201,12 @@ void chk::WsClient::runMainLoop()
201201
else {
202202
this->runServerLoop();
203203
}
204-
205-
if (this->isDead) {
206-
// some error happened 🙁
207-
if (this->_onDeathCallback != nullptr) {
208-
_onDeathCallback(this->deathNote);
209-
}
204+
205+
if (this->isDead) {
206+
// some error happened 🙁
207+
if (this->_onDeathCallback != nullptr) {
208+
_onDeathCallback(this->deathNote);
209+
}
210210
this->showErrorPopup();
211211
} else if (this->haveWinner) {
212212
this->showWinnerPopup();
@@ -218,7 +218,7 @@ void chk::WsClient::runMainLoop()
218218
* Try to connect to Server
219219
* @param address server IP or URI
220220
*/
221-
void chk::WsClient::tryConnect(std::string_view address)
221+
void WsClient::tryConnect(std::string_view address)
222222
{
223223
this->webSocketPtr->setUrl(address.data());
224224
if (!this->isConnected)
@@ -348,7 +348,7 @@ bool WsClient::replyServer(const chk::payload::BasePayload &payload) const
348348
/**
349349
* Exchange messages with the server and update the game accordingly. if any error happen, close connection
350350
*/
351-
void chk::WsClient::runServerLoop()
351+
void WsClient::runServerLoop()
352352
{
353353
for (const auto &msg : this->msgBuffer.getAll())
354354
{
@@ -454,7 +454,7 @@ void WsClient::showErrorPopup()
454454
/**
455455
* Show winner/loser popup window.
456456
*/
457-
void WsClient::showWinnerPopup()
457+
void chk::WsClient::showWinnerPopup()
458458
{
459459
// Always center this next dialog
460460
ImVec2 center = ImGui::GetMainViewport()->GetCenter();
@@ -472,4 +472,5 @@ void WsClient::showWinnerPopup()
472472
}
473473
ImGui::EndPopup();
474474
}
475-
}
475+
}
476+
} // namespace chk

src/main.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ int main()
6262
// create pieces and give each player their own
6363
manager->createAllPieces();
6464

65-
// Storing currently clicked Piece. (NOTE: using curly braces)
65+
// Storing currently clicked Piece. (NOTE: using curly braces for constructor)
6666
chk::CircularBuffer<short> circularBuffer{1};
6767

6868
// THE STATUS TEXT

0 commit comments

Comments
 (0)