浏览代码

:bug: fixed some minor issues

Felix Bytow 1 年之前
父节点
当前提交
879ff6950c
共有 3 个文件被更改,包括 14 次插入12 次删除
  1. 10 11
      CMakeLists.txt
  2. 3 0
      game/HighScoreManager.cxx
  3. 1 1
      game/PlayingState.cxx

+ 10 - 11
CMakeLists.txt

@@ -6,12 +6,6 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
 set(CMAKE_CXX_EXTENSIONS OFF)
 
 include(FetchContent)
-FetchContent_Declare(
-    Boost
-    GIT_REPOSITORY https://github.com/boostorg/boost.git
-    GIT_TAG a7090e8ce184501cfc9e80afa6cafb5bfd3b371c # boost-1.74.0
-    FIND_PACKAGE_ARGS 1.74.0 REQUIRED COMPONENTS serialization program_options system
-)
 FetchContent_Declare(
     SDL2
     GIT_REPOSITORY https://github.com/libsdl-org/SDL.git
@@ -30,9 +24,14 @@ FetchContent_Declare(
     GIT_TAG 89d1692fd8fe91a679bb943d377bfbd709b52c23 # release-2.20.2
     FIND_PACKAGE_ARGS
 )
-FetchContent_MakeAvailable(SDL2 SDL2_image SDL2_ttf Boost)
+FetchContent_MakeAvailable(SDL2 SDL2_image SDL2_ttf)
+
+set(Boost_USE_MULTITHREADED ON)
+set(Boost_USE_STATIC_LIBS ON)
+set(Boost_USE_STATIC_RUNTIME OFF)
+find_package(Boost 1.74.0 REQUIRED COMPONENTS serialization program_options)
 
-add_executable(Snake WIN32
+add_executable(Snake WIN32 MACOSX_BUNDLE
     main.cxx
     SDL.cxx SDL.hxx
     SDLWindow.cxx SDLWindow.hxx
@@ -54,8 +53,8 @@ add_executable(Snake WIN32
 )
 
 target_link_libraries(Snake PRIVATE
-    SDL2::SDL2 SDL2::SDL2main
-    SDL2_image::SDL2_image
-    SDL2_ttf::SDL2_ttf
+    SDL2::SDL2-static SDL2::SDL2main
+    SDL2_image::SDL2_image-static
+    SDL2_ttf::SDL2_ttf-static
     Boost::headers Boost::serialization Boost::program_options
 )

+ 3 - 0
game/HighScoreManager.cxx

@@ -70,6 +70,9 @@ void HighScoreManager::set_new_score(unsigned int score)
   if (high_score_.scores_.size()<MAX_SCORES || high_score_.scores_.back().points_<score) {
     new_score_ = score;
   }
+  else {
+    new_score_.reset();
+  }
 }
 
 bool HighScoreManager::has_new_score() const

+ 1 - 1
game/PlayingState.cxx

@@ -169,7 +169,7 @@ void PlayingState::render(SDLRenderer& renderer)
 
 void PlayingState::render_ui(SDLRenderer& renderer, SDL_Rect const& playing_field)
 {
-  auto const score_text = "Score: {}"+std::to_string(length_);
+  auto const score_text = "Score: "+std::to_string(length_);
   SDL_Surface* text_surface = TTF_RenderText_Solid(font_, score_text.c_str(), {255, 255, 255, SDL_ALPHA_OPAQUE});
   SDL_Texture* text = SDL_CreateTextureFromSurface(renderer, text_surface);
   SDL_FreeSurface(text_surface);