From 5aff6f6326783a9cc6b4aaed6987ca60e60c745d Mon Sep 17 00:00:00 2001 From: Sarah Faey Date: Wed, 7 May 2025 17:59:50 +0200 Subject: [PATCH] fixed windows build --- CMakeLists.txt | 13 ++++++++----- src/Actors/Actor.h | 4 ++-- src/Actors/ActorFactory.cpp | 8 ++++---- src/Actors/ActorFactory.h | 4 ++-- src/Actors/MovingActor.cpp | 2 +- src/Actors/MovingActor.h | 2 +- src/Components/MoveComponent.h | 2 +- src/DataStructures/DirectionButtonStatus.cpp | 4 ++-- src/DataStructures/DirectionButtonStatus.h | 2 +- src/DataStructures/NormalizedDirection.cpp | 2 +- src/DataStructures/NormalizedDirection.h | 2 +- src/Game.cpp | 11 +++++++---- src/Game.h | 4 ++-- 13 files changed, 33 insertions(+), 27 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 01861ab..60997e2 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -6,9 +6,12 @@ cmake_minimum_required(VERSION 3.24) # Set the project name project(Witch-Game) - -#find_package(SDL3 REQUIRED) -#find_package(SDL3_image REQUIRED) +#disable big libraries +#AVIF needs special compilers +set(SDLIMAGE_AVIF OFF) +set(SDLIMAGE_TIF OFF) +set(SDLIMAGE_WEBP OFF) +set(SDLIMAGE_JXL OFF) #download SDL if not installed #use git ls-remote --tags https://github.com/libsdl-org/SDL.git | tail -n 1 @@ -42,11 +45,11 @@ set(DATA_STRUCTURES src/DataStructures/NormalizedDirection.cpp src/DataStructure add_executable(Witch-Game main.cpp src/Game.cpp ${ACTORS} ${COMPONENTS} ${DATA_STRUCTURES}) target_compile_features(Witch-Game PRIVATE cxx_std_17) -target_link_libraries(Witch-Game SDL3 SDL3_image SDL3_ttf) +target_link_libraries(Witch-Game SDL3::SDL3 SDL3_image::SDL3_image SDL3_ttf::SDL3_ttf) #set compiler flags for warnings if(MSVC) - target_compile_options(Witch-Game PRIVATE /W4 /WX) +# target_compile_options(Witch-Game PRIVATE /W4 /WX) else() target_compile_options(Witch-Game PRIVATE -Wall -Wextra -Wpedantic) endif() diff --git a/src/Actors/Actor.h b/src/Actors/Actor.h index 50ce4df..f82150e 100644 --- a/src/Actors/Actor.h +++ b/src/Actors/Actor.h @@ -26,10 +26,10 @@ protected: Vector2D m_Position; Hitbox m_MoveHitbox; Hitbox m_CombatHitbox; - std::shared_ptr m_InputComponent; //Input or AI + /*std::shared_ptr m_InputComponent; //Input or AI std::shared_ptr m_MoveComponent; std::shared_ptr m_ActionComponent; //Skills, hit with Axe, Fiery rush,... - std::shared_ptr m_SpriteComponent; //Sprites or anim Sprites + std::shared_ptr m_SpriteComponent; //Sprites or anim Sprites*/ //every other action needs a sprite //move needs input, input maybe needs move? diff --git a/src/Actors/ActorFactory.cpp b/src/Actors/ActorFactory.cpp index bcda890..4c3a6dd 100644 --- a/src/Actors/ActorFactory.cpp +++ b/src/Actors/ActorFactory.cpp @@ -2,16 +2,16 @@ #include -std::shared_ptr ActorFactory::CreateActor(SDL_FRect hitbox) +std::shared_ptr ActorFactory::CreateActor(Vector2D position, Hitbox moveHitbox, Hitbox combatHitbox) { - auto actor = std::make_shared(Actor(hitbox)); + auto actor = std::make_shared(Actor(position, moveHitbox, combatHitbox)); actor ->Init(); return actor; } -std::shared_ptr ActorFactory::CreateMovingActor(SDL_FRect hitbox) +std::shared_ptr ActorFactory::CreateMovingActor(Vector2D position, Hitbox moveHitbox, Hitbox combatHitbox) { - auto actor = std::make_shared(MovingActor(hitbox)); + auto actor = std::make_shared(MovingActor(position, moveHitbox, combatHitbox)); actor ->Init(); return actor; } \ No newline at end of file diff --git a/src/Actors/ActorFactory.h b/src/Actors/ActorFactory.h index c1df167..c32213f 100644 --- a/src/Actors/ActorFactory.h +++ b/src/Actors/ActorFactory.h @@ -9,8 +9,8 @@ class ActorFactory { public: - static std::shared_ptr CreateActor(SDL_FRect hitbox); - static std::shared_ptr CreateMovingActor(SDL_FRect hitbox); + static std::shared_ptr CreateActor(Vector2D position, Hitbox moveHitbox, Hitbox combatHitbox); + static std::shared_ptr CreateMovingActor(Vector2D position, Hitbox moveHitbox, Hitbox combatHitbox); }; diff --git a/src/Actors/MovingActor.cpp b/src/Actors/MovingActor.cpp index 3d47c88..f0b8230 100644 --- a/src/Actors/MovingActor.cpp +++ b/src/Actors/MovingActor.cpp @@ -6,7 +6,7 @@ void MovingActor::Init() m_MoveComponent = std::make_shared(MoveComponent(shared_from_this())); } -MovingActor::MovingActor(SDL_FRect hitbox) : Actor(hitbox) +MovingActor::MovingActor(Vector2D position, Hitbox moveHitbox, Hitbox combatHitbox) : Actor(position, moveHitbox, combatHitbox) { //m_MoveComponent = std::make_unique(MoveComponent(shared_from_this())); //m_MoveComponent = std::make_shared(MoveComponent(shared_from_this())); diff --git a/src/Actors/MovingActor.h b/src/Actors/MovingActor.h index f2d5525..9b3e71f 100644 --- a/src/Actors/MovingActor.h +++ b/src/Actors/MovingActor.h @@ -17,7 +17,7 @@ public: friend class ActorFactory; protected: - MovingActor(SDL_FRect hitbox); + MovingActor(Vector2D position, Hitbox moveHitbox, Hitbox combatHitbox); //MovingActor(const MovingActor&) = default; //MovingActor& operator=(const MovingActor&) = default; void Init() override; diff --git a/src/Components/MoveComponent.h b/src/Components/MoveComponent.h index 5a6c054..55d2d7d 100644 --- a/src/Components/MoveComponent.h +++ b/src/Components/MoveComponent.h @@ -10,7 +10,7 @@ class MoveComponent { public: - MoveComponent(std::weak_ptr actor): m_Actor(actor), m_Speed(50) {}; //TODO: speed + MoveComponent(std::weak_ptr actor) : m_Actor(actor), m_Direction(NormalizedDirection()), m_Speed(50), m_ForcedDistance(0) {}; //TODO: speed void Update(float deltaTime); void SetDirection(const NormalizedDirection & direction); void SetSpeed(float speed); diff --git a/src/DataStructures/DirectionButtonStatus.cpp b/src/DataStructures/DirectionButtonStatus.cpp index bbb3b03..bd701ff 100644 --- a/src/DataStructures/DirectionButtonStatus.cpp +++ b/src/DataStructures/DirectionButtonStatus.cpp @@ -11,8 +11,8 @@ bool DirectionButtonStatus::GetDirection(NormalizedDirection & ref_direction) if(LeftPressed) direction.x -= 1; if(RightPressed) direction.x += 1; - float x = direction.x; - float y = direction.y; + float x = (float)direction.x; + float y = (float)direction.y; if((direction.y == 1 || direction.y == -1) && (direction.x == 1 || direction.x == -1)) { diff --git a/src/DataStructures/DirectionButtonStatus.h b/src/DataStructures/DirectionButtonStatus.h index 327177b..0cd5363 100644 --- a/src/DataStructures/DirectionButtonStatus.h +++ b/src/DataStructures/DirectionButtonStatus.h @@ -12,7 +12,7 @@ public: bool DownPressed = false; bool LeftPressed = false; bool RightPressed = false; - const float c_NormalizedDiagonal = 1 / sqrt(2); + const float c_NormalizedDiagonal = (float)(1.0 / sqrt(2)); bool GetDirection(NormalizedDirection & ref_direction); }; diff --git a/src/DataStructures/NormalizedDirection.cpp b/src/DataStructures/NormalizedDirection.cpp index e319d6a..ef990e7 100644 --- a/src/DataStructures/NormalizedDirection.cpp +++ b/src/DataStructures/NormalizedDirection.cpp @@ -10,7 +10,7 @@ NormalizedDirection::NormalizedDirection(float x, float y, bool isNormalized) } else { - float normalizeValue = 1 / sqrt(pow(x,2) + pow(y,2)); + float normalizeValue = (float)(1.0 / sqrt(pow(x,2) + pow(y,2))); m_Direction.x = x * normalizeValue; m_Direction.y = y * normalizeValue; } diff --git a/src/DataStructures/NormalizedDirection.h b/src/DataStructures/NormalizedDirection.h index 457f7f7..96ccf0f 100644 --- a/src/DataStructures/NormalizedDirection.h +++ b/src/DataStructures/NormalizedDirection.h @@ -8,7 +8,7 @@ class NormalizedDirection { public: - NormalizedDirection() {}; + NormalizedDirection() : m_Direction(Vector2D()){}; NormalizedDirection(float x, float y, bool isNormalized); NormalizedDirection(SDL_FPoint direction, bool isNormalized); NormalizedDirection(Vector2D direction, bool isNormalized); diff --git a/src/Game.cpp b/src/Game.cpp index d798315..f8d71d1 100644 --- a/src/Game.cpp +++ b/src/Game.cpp @@ -17,14 +17,17 @@ Game::Game(SDL_Window *window, SDL_Renderer *renderer) : m_Window(window, SDL_DestroyWindow), m_Renderer(renderer, SDL_DestroyRenderer), - m_Gamepad1(nullptr, SDL_CloseGamepad) + m_Gamepad1(nullptr, SDL_CloseGamepad), + m_TickCount(0), + m_Player1DirectionInput({ 0,0 }), + m_Player2DirectionInput({ 0,0 }) { SDL_FRect player1Hitbox; player1Hitbox.x = 0; player1Hitbox.y = 0; player1Hitbox.w = 20; player1Hitbox.h = 20; - m_Player1 = ActorFactory::CreateMovingActor(player1Hitbox); + m_Player1 = ActorFactory::CreateMovingActor(Vector2D(0,0), player1Hitbox, player1Hitbox); //TODO: read keybinds from config if it exists. otherwise initialze standard and write file m_KeyboardCommandMap.emplace(SDL_SCANCODE_ESCAPE, new EndGameCommand(this)); @@ -46,7 +49,7 @@ void Game::Run() float deltaTime = (SDL_GetTicks() - m_TickCount) / 1000.0f; uint64_t ticks = SDL_GetTicks() - m_TickCount; ticks = ticks > 0 ? ticks : 1; - int fps = 1000/(ticks); + long fps = 1000/(ticks); m_TickCount = SDL_GetTicks(); HandleMovement(); m_Player1->Update(deltaTime); @@ -56,7 +59,7 @@ void Game::Run() SDL_SetRenderDrawColor(m_Renderer.get(), 255, 255, 255, 255); - SDL_RenderDebugTextFormat(m_Renderer.get(), 10, 440, "%" SDL_PRIu64 " fps", fps); + SDL_RenderDebugTextFormat(m_Renderer.get(), 10, 440, "%" SDL_PRIu32 " fps", fps); SDL_SetRenderDrawColor(m_Renderer.get(), 150, 0, 150, 255); SDL_FRect player = m_Player1->GetMovementHitbox(); SDL_RenderFillRect(m_Renderer.get(), &player); diff --git a/src/Game.h b/src/Game.h index 68f49a8..46fc70a 100644 --- a/src/Game.h +++ b/src/Game.h @@ -23,10 +23,10 @@ public: void RemoveGamepad(SDL_JoystickID id); void EndGame(); private: - const float c_GamepadAxisDeadzone = 0.2; //TODO: make this a setting? + const float c_GamepadAxisDeadzone = (float)0.2; //TODO: make this a setting? bool m_running = true; - uint64_t m_TickCount; + uint64_t m_TickCount = 0; std::map m_KeyboardCommandMap; std::map m_Gamepad1ButtonCommandMap; std::map m_Gamepad2ButtonCommandMap;