Refactor and move things around.

This commit is contained in:
Daniel Weber 2024-09-14 09:40:43 -04:00
parent 6314bc756a
commit 9c31cc66e7
8 changed files with 77 additions and 55 deletions

View File

@ -4,12 +4,21 @@ project(Chess C CXX)
find_package(SDL2 REQUIRED) find_package(SDL2 REQUIRED)
file(GLOB sources file(GLOB_RECURSE sources
CONFIGURE_DEPENDS CONFIGURE_DEPENDS
src/*.cpp) "src/*.cpp")
file (GLOB_RECURSE headers CONFIGURE_DEPENDS "src/*.h")
set (include_dirs "")
foreach (_headerFile ${headers})
get_filename_component(_dir ${_headerFile} PATH)
list (APPEND include_dirs ${_dir})
endforeach()
add_executable(Chess ${sources}) add_executable(Chess ${sources})
set_target_properties(Chess PROPERTIES CXX_STANDARD 17) # set standard level set_target_properties(Chess PROPERTIES CXX_STANDARD 17) # set standard level
target_include_directories(Chess PRIVATE ${include_dirs})
target_compile_options(Chess PRIVATE target_compile_options(Chess PRIVATE
-Wall -Wextra -Wredundant-decls -Wcast-align -Wall -Wextra -Wredundant-decls -Wcast-align
-Wshadow -Wnon-virtual-dtor -Wshadow -Wnon-virtual-dtor

View File

@ -970,7 +970,6 @@ void Board_Changed(uint8_t current_binary_board[8])
} }
Saved_Binary_Board[j] = current_binary_board[j]; Saved_Binary_Board[j] = current_binary_board[j];
} }
} }

View File

@ -28,6 +28,7 @@ int main( int argc, const char* argv[] )
printf("Could not create window: %s\n", SDL_GetError()); printf("Could not create window: %s\n", SDL_GetError());
return 1; return 1;
} }
renderer = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED); renderer = SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED);
SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255); SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255);
SDL_Rect rectangle; SDL_Rect rectangle;

View File

@ -23,6 +23,14 @@ SDL_Texture * bitmapTextures[12] = {NULL};
static uint8_t Current_Binary_Board[8] = {0}; static uint8_t Current_Binary_Board[8] = {0};
/**
* @brief Function for setting the lights on the board to the end game state,
* clearly indicating which player won.
*
* @param p_renderer Sdl Renderer
* @param board_state board state
* @param game_state games state
*/
static void ui_draw_end_game(SDL_Renderer *p_renderer, uint8_t board_state[8][8], uint8_t game_state) static void ui_draw_end_game(SDL_Renderer *p_renderer, uint8_t board_state[8][8], uint8_t game_state)
{ {
SDL_SetRenderTarget(p_renderer, Board_Texture); SDL_SetRenderTarget(p_renderer, Board_Texture);
@ -332,6 +340,11 @@ void ui_click(SDL_Renderer *p_renderer, int x, int y)
} }
} }
/**
* @brief Initialize the ui for the board. Setting all pieces in the correct starting positions
*
* @param p_renderer pointer to the sdl renderer
*/
void ui_init(SDL_Renderer *p_renderer) void ui_init(SDL_Renderer *p_renderer)
{ {
Current_Binary_Board[0] = 0xFF; Current_Binary_Board[0] = 0xFF;