Skip to content

Commit 9db3b56

Browse files
Merge pull request #159 from Longwater1234/dev
2 parents 0fc088b + 655718c commit 9db3b56

File tree

6 files changed

+42
-15
lines changed

6 files changed

+42
-15
lines changed

BUILDING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
mkdir build
1818
cd build
1919
cmake . . -DCMAKE_BUILD_TYPE=Release
20-
cmake --build . --config Release --target all
20+
cmake --build . --config Release --target all -j
2121

2222
```
2323

CMakeLists.txt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,12 @@ if (NOT APPLE)
1313
set(SFML_STATIC_LIBRARIES TRUE)
1414
endif()
1515

16+
# defualt to building in "RELEASE" mode
17+
if (NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES)
18+
set(CMAKE_BUILD_TYPE "Release" CACHE STRING
19+
"Choose the type of build." FORCE)
20+
endif()
21+
1622
# write app version into Header
1723
configure_file(
1824
${CMAKE_CURRENT_SOURCE_DIR}/src/proto_schema/AppVersion.hpp.in

cmake/macbundle.cmake

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,14 @@ set_source_files_properties(${application_icon}
66

77
# images
88
file(GLOB_RECURSE my_images "${CMAKE_SOURCE_DIR}/resources/*")
9-
foreach(FILE ${my_images})
10-
file(RELATIVE_PATH NEW_FILE "${CMAKE_SOURCE_DIR}/" ${FILE})
11-
get_filename_component(NEW_FILE_PATH ${NEW_FILE} DIRECTORY)
12-
set_source_files_properties(${FILE} PROPERTIES MACOSX_PACKAGE_LOCATION
13-
"Resources/${NEW_FILE_PATH}")
9+
foreach(FILE ${my_images})
10+
get_filename_component(FILENAME ${FILE} DIRECTORY)
11+
# SKIP .DS_Store files
12+
if (NOT FILENAME STREQUAL ".DS_Store")
13+
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}")
16+
endif()
1417
endforeach()
1518

1619
add_executable(${CMAKE_PROJECT_NAME} MACOSX_BUNDLE

src/CircularBuffer.hpp

Lines changed: 25 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,11 @@ template <typename T> class CircularBuffer
2424
CircularBuffer() = delete;
2525
CircularBuffer &operator=(const CircularBuffer &) = delete;
2626
CircularBuffer(CircularBuffer &other) = delete;
27-
void addItem(const T &item);
28-
T &getTop() noexcept;
27+
void addItem(const T &item); // copy overload
28+
void addItem(T &&item); // Move overload
29+
T &getFront() noexcept;
2930
void removeFirst();
30-
[[nodiscard]] bool isEmpty() const;
31+
[[nodiscard]] bool isEmpty() const noexcept;
3132
const std::deque<T> &getAll() const;
3233
void clean();
3334

@@ -50,7 +51,7 @@ template <typename T> void CircularBuffer<T>::clean()
5051
* @tparam T any type
5152
* @return TRUE or FALSE
5253
*/
53-
template <typename T> bool CircularBuffer<T>::isEmpty() const
54+
template <typename T> bool CircularBuffer<T>::isEmpty() const noexcept
5455
{
5556
return m_deque.empty();
5657
}
@@ -68,7 +69,7 @@ template <typename T> inline const std::deque<T> &CircularBuffer<T>::getAll() co
6869
* @tparam T any type
6970
* @return The first element in queue
7071
*/
71-
template <typename T> T &CircularBuffer<T>::getTop() noexcept
72+
template <typename T> T &CircularBuffer<T>::getFront() noexcept
7273
{
7374
return m_deque.front();
7475
}
@@ -78,11 +79,14 @@ template <typename T> T &CircularBuffer<T>::getTop() noexcept
7879
*/
7980
template <typename T> void CircularBuffer<T>::removeFirst()
8081
{
81-
m_deque.pop_front();
82+
if (!m_deque.empty())
83+
{
84+
m_deque.pop_front();
85+
}
8286
}
8387

8488
/**
85-
* Add new element to buffer
89+
* Add new element to buffer (using copy)
8690
* @tparam T any type
8791
* @param item the element to be inserted
8892
*/
@@ -95,4 +99,18 @@ template <typename T> void CircularBuffer<T>::addItem(const T &item)
9599
}
96100
m_deque.emplace_back(item);
97101
}
102+
103+
/**
104+
* Move element into the buffer
105+
* @tparam T any type
106+
* @param item the element to be inserted
107+
*/
108+
template <typename T> void CircularBuffer<T>::addItem(T &&item)
109+
{
110+
if (m_deque.size() >= max_capacity)
111+
{
112+
m_deque.pop_front();
113+
}
114+
m_deque.emplace_back(std::move(item));
115+
}
98116
} // namespace chk

src/managers/GameManager.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,7 +314,7 @@ void chk::GameManager::handleCellTap(const chk::PlayerPtr &hunter, const chk::Pl
314314
// Cell is Empty! Let's judge if this is SIMPLE move or ATTACK move
315315
if (!buffer.isEmpty())
316316
{
317-
const short movablePieceId = buffer.getTop();
317+
const short movablePieceId = buffer.getFront();
318318
if (!hunter->hasThisPiece(movablePieceId))
319319
{
320320
return;

src/managers/OnlineGameManager.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -417,7 +417,7 @@ inline void OnlineGameManager::handleCellTap(const chk::PlayerPtr &hunter, const
417417
// Cell is Empty! Let's judge if this is SIMPLE move or ATTACK move
418418
if (!buffer.isEmpty())
419419
{
420-
const short movablePieceId = buffer.getTop();
420+
const short movablePieceId = buffer.getFront();
421421
if (!hunter->hasThisPiece(movablePieceId))
422422
{
423423
return;

0 commit comments

Comments
 (0)