From cfeddd58d709de10ec46d20465c901232908c686 Mon Sep 17 00:00:00 2001 From: Bilal Kahraman <45990633+bilalkah@users.noreply.github.com> Date: Mon, 26 Aug 2024 23:57:28 +0300 Subject: [PATCH] Ft add path planning (#7) * Add path-planning as submodule * Add modules - Walk animation and tbs animation - navigation_manager and use path-planning inside - Render animation 2d and move enemy with planned path * Lint --- .gitmodules | 3 + CMakeLists.txt | 8 ++- app/main.cpp | 2 +- src/Animation/CMakeLists.txt | 3 +- src/Animation/include/Animation/animation.h | 23 +++---- src/Animation/include/Animation/animator.h | 38 ++++++++++++ .../Animation/time_based_single_animation.h | 39 ++++++++++++ .../include/Animation/walk_animation.h | 40 ++++++++++++ src/Animation/src/animator.cpp | 0 ...on.cpp => time_based_single_animation.cpp} | 12 ++-- src/Animation/src/walk_animation.cpp | 26 ++++++++ src/Camera/include/Camera/camera.h | 14 ++--- src/Camera/include/Camera/ray.h | 2 +- src/Camera/include/Camera/raycaster.h | 8 +-- src/Camera/src/camera.cpp | 8 +-- src/Camera/src/ray.cpp | 2 +- src/Camera/src/raycaster.cpp | 2 +- src/Characters/CMakeLists.txt | 11 ++-- src/Characters/include/Characters/character.h | 3 +- src/Characters/include/Characters/enemy.h | 14 ++++- src/Characters/include/Characters/player.h | 6 +- src/Characters/src/enemy.cpp | 33 ++++++++-- src/Characters/src/player.cpp | 18 +++--- .../CollisionManager/collision_manager.h | 6 +- .../src/collision_manager.cpp | 2 +- src/Core/CMakeLists.txt | 7 ++- src/Core/include/Core/game.h | 19 +++--- src/Core/src/game.cpp | 57 +++++++++++------ .../include/GameObjects/dynamic_object.h | 10 +-- .../include/GameObjects/game_object.h | 4 +- .../include/GameObjects/static_object.h | 6 +- src/GameObjects/src/dynamic_object.cpp | 7 +-- src/GameObjects/src/static_object.cpp | 6 +- src/Graphics/CMakeLists.txt | 2 + src/Graphics/include/Graphics/renderer.h | 9 ++- src/Graphics/include/Graphics/scene.h | 9 ++- src/Graphics/src/renderer.cpp | 28 ++++++--- src/Graphics/src/scene.cpp | 14 ++++- src/Map/CMakeLists.txt | 18 ++++-- src/Map/include/Map/map.h | 12 +++- src/Map/src/map.cpp | 47 ++++++++++---- src/Math/include/Math/vector.h | 2 + src/Math/src/vector.cpp | 10 ++- src/NavigationManager/CMakeLists.txt | 26 ++++++++ .../NavigationManager/navigation_helper.h | 30 +++++++++ .../NavigationManager/navigation_manager.h | 48 +++++++++++++++ .../src/navigation_manager.cpp | 61 +++++++++++++++++++ src/TextureManager/src/texture_manager.cpp | 2 +- src/TimeManager/src/time_manager.cpp | 2 +- src/Utility/CMakeLists.txt | 2 +- src/Utility/include/Utility/uuid_generator.h | 2 +- src/Utility/src/logger.cpp | 2 +- src/Utility/src/uuid_generator.cpp | 2 +- third-party/path-planning | 1 + 54 files changed, 605 insertions(+), 163 deletions(-) create mode 100644 src/Animation/include/Animation/animator.h create mode 100644 src/Animation/include/Animation/time_based_single_animation.h create mode 100644 src/Animation/include/Animation/walk_animation.h create mode 100644 src/Animation/src/animator.cpp rename src/Animation/src/{animation.cpp => time_based_single_animation.cpp} (54%) create mode 100644 src/Animation/src/walk_animation.cpp create mode 100644 src/NavigationManager/CMakeLists.txt create mode 100644 src/NavigationManager/include/NavigationManager/navigation_helper.h create mode 100644 src/NavigationManager/include/NavigationManager/navigation_manager.h create mode 100644 src/NavigationManager/src/navigation_manager.cpp create mode 160000 third-party/path-planning diff --git a/.gitmodules b/.gitmodules index 9732d84..90fb6b9 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "third-party/uuid_v4"] path = third-party/uuid_v4 url = https://github.com/crashoz/uuid_v4.git +[submodule "third-party/path-planning"] + path = third-party/path-planning + url = https://github.com/bilalkah/path-planning.git diff --git a/CMakeLists.txt b/CMakeLists.txt index ca37839..fa84baa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 3.16) +cmake_minimum_required(VERSION 3.5) project(wolfenstein VERSION 1.0 LANGUAGES CXX) add_definitions("-Wall" "-g") @@ -37,6 +37,10 @@ if(NOT EXISTS "${PROJECT_SOURCE_DIR}/third-party/uuid_v4/CMakeLists.txt") message(FATAL_ERROR "The submodules were not downloaded! GIT_SUBMODULE was turned off or failed. Please update submodules and try again.") endif() +if(NOT EXISTS "${PROJECT_SOURCE_DIR}/third-party/path-planning/CMakeLists.txt") + message(FATAL_ERROR "The submodules were not downloaded! GIT_SUBMODULE was turned off or failed. Please update submodules and try again.") +endif() + # internal libraries add_subdirectory(app) add_subdirectory(src/Animation) @@ -48,12 +52,14 @@ add_subdirectory(src/GameObjects) add_subdirectory(src/Graphics) add_subdirectory(src/Map) add_subdirectory(src/Math) +add_subdirectory(src/NavigationManager) add_subdirectory(src/TextureManager) add_subdirectory(src/TimeManager) add_subdirectory(src/Utility) # external libraries add_subdirectory(third-party/uuid_v4) +add_subdirectory(third-party/path-planning) find_package(SDL2 REQUIRED) diff --git a/app/main.cpp b/app/main.cpp index c9986fb..cc5ca86 100644 --- a/app/main.cpp +++ b/app/main.cpp @@ -13,7 +13,7 @@ int main() { using namespace wolfenstein; - GeneralConfig config(1280, 768, 0, 50, 120, 10.0, ToRadians(60.0)); + GeneralConfig config(2560, 1440, 0, 50, 120, 10.0, ToRadians(60.0), true); Game game(config); game.Run(); diff --git a/src/Animation/CMakeLists.txt b/src/Animation/CMakeLists.txt index 3c89e7c..8fd6467 100644 --- a/src/Animation/CMakeLists.txt +++ b/src/Animation/CMakeLists.txt @@ -6,7 +6,8 @@ link_directories( add_library( animation STATIC - src/animation.cpp + src/time_based_single_animation.cpp + src/walk_animation.cpp ) target_include_directories(animation PUBLIC diff --git a/src/Animation/include/Animation/animation.h b/src/Animation/include/Animation/animation.h index 7b67844..7f11be5 100644 --- a/src/Animation/include/Animation/animation.h +++ b/src/Animation/include/Animation/animation.h @@ -3,7 +3,7 @@ * @author Bilal Kahraman (kahramannbilal@gmail.com) * @brief * @version 0.1 - * @date 2024-08-18 + * @date 2024-08-19 * * @copyright Copyright (c) 2024 * @@ -12,27 +12,18 @@ #ifndef ANIMATION_INCLUDE_ANIMATION_ANIMATION_H_ #define ANIMATION_INCLUDE_ANIMATION_ANIMATION_H_ -#include - namespace wolfenstein { -class Animation +class IAnimation { public: - Animation(const std::vector& tex_ids, const double animation_speed); - ~Animation() = default; - - void Update(const double& delta_time); - void Reset(); + virtual ~IAnimation() = default; - int GetCurrentFrame() const; - - private: - std::vector tex_ids; - int current_frame; - double animation_speed; - double counter; + virtual void Update(const double& delta_time) = 0; + virtual void Reset() = 0; + virtual int GetCurrentFrame() const = 0; }; } // namespace wolfenstein + #endif // ANIMATION_INCLUDE_ANIMATION_ANIMATION_H_ diff --git a/src/Animation/include/Animation/animator.h b/src/Animation/include/Animation/animator.h new file mode 100644 index 0000000..0ffe26d --- /dev/null +++ b/src/Animation/include/Animation/animator.h @@ -0,0 +1,38 @@ +/** + * @file animator.h + * @author Bilal Kahraman (kahramannbilal@gmail.com) + * @brief + * @version 0.1 + * @date 2024-08-26 + * + * @copyright Copyright (c) 2024 + * + */ + +#ifndef ANIMATION_INCLUDE_ANIMATION_ANIMATOR_H_ +#define ANIMATION_INCLUDE_ANIMATION_ANIMATOR_H_ + +#include "Animation/animation.h" +#include +#include + +namespace wolfenstein { + +class Animator +{ + public: + Animator(); + ~Animator() = default; + + void AddAnimation(std::shared_ptr animation); + void Update(const double& delta_time); + void Reset(); + int GetCurrentFrame() const; + + private: + std::vector> animations; +}; + +} // namespace wolfenstein + +#endif // ANIMATION_INCLUDE_ANIMATION_ANIMATOR_H_ diff --git a/src/Animation/include/Animation/time_based_single_animation.h b/src/Animation/include/Animation/time_based_single_animation.h new file mode 100644 index 0000000..0e55214 --- /dev/null +++ b/src/Animation/include/Animation/time_based_single_animation.h @@ -0,0 +1,39 @@ +/** + * @file animation.h + * @author Bilal Kahraman (kahramannbilal@gmail.com) + * @brief + * @version 0.1 + * @date 2024-08-18 + * + * @copyright Copyright (c) 2024 + * + */ + +#ifndef ANIMATION_INCLUDE_ANIMATION_TIME_BASED_SINGLE_ANIMATION_H_ +#define ANIMATION_INCLUDE_ANIMATION_TIME_BASED_SINGLE_ANIMATION_H_ + +#include "Animation/animation.h" +#include + +namespace wolfenstein { + +class TBSAnimation : public IAnimation +{ + public: + TBSAnimation(const std::vector& tex_ids, const double animation_speed); + ~TBSAnimation() = default; + + void Update(const double& delta_time) override; + void Reset() override; + + int GetCurrentFrame() const override; + + private: + std::vector tex_ids; + int current_frame; + double animation_speed; + double counter; +}; + +} // namespace wolfenstein +#endif // ANIMATION_INCLUDE_ANIMATION_TIME_BASED_SINGLE_ANIMATION_H_ diff --git a/src/Animation/include/Animation/walk_animation.h b/src/Animation/include/Animation/walk_animation.h new file mode 100644 index 0000000..4452073 --- /dev/null +++ b/src/Animation/include/Animation/walk_animation.h @@ -0,0 +1,40 @@ +/** + * @file state_based_animation.h + * @author Bilal Kahraman (kahramannbilal@gmail.com) + * @brief + * @version 0.1 + * @date 2024-08-26 + * + * @copyright Copyright (c) 2024 + * + */ + +#ifndef ANIMATION_INCLUDE_ANIMATION_STATE_BASED_ANIMATION_H_ +#define ANIMATION_INCLUDE_ANIMATION_STATE_BASED_ANIMATION_H_ + +#include "Animation/animation.h" +#include + +namespace wolfenstein { + +class WalkAnimation : public IAnimation +{ + public: + WalkAnimation(const std::vector& tex_ids, const double step_size); + ~WalkAnimation() = default; + + void Update(const double& delta_time) override; + void Reset() override; + + int GetCurrentFrame() const override; + + private: + std::vector tex_ids; + int current_frame; + double step_size; + double counter; +}; + +} // namespace wolfenstein + +#endif // ANIMATION_INCLUDE_ANIMATION_STATE_BASED_ANIMATION_H_ diff --git a/src/Animation/src/animator.cpp b/src/Animation/src/animator.cpp new file mode 100644 index 0000000..e69de29 diff --git a/src/Animation/src/animation.cpp b/src/Animation/src/time_based_single_animation.cpp similarity index 54% rename from src/Animation/src/animation.cpp rename to src/Animation/src/time_based_single_animation.cpp index c1af43e..1e5f454 100644 --- a/src/Animation/src/animation.cpp +++ b/src/Animation/src/time_based_single_animation.cpp @@ -1,12 +1,12 @@ -#include +#include "Animation/time_based_single_animation.h" namespace wolfenstein { -Animation::Animation(const std::vector& tex_ids, - const double animation_speed) +TBSAnimation::TBSAnimation(const std::vector& tex_ids, + const double animation_speed) : tex_ids(tex_ids), current_frame(0), animation_speed(animation_speed) {} -void Animation::Update(const double& delta_time) { +void TBSAnimation::Update(const double& delta_time) { counter += delta_time; if (counter > animation_speed) { current_frame = (current_frame + 1) % tex_ids.size(); @@ -14,12 +14,12 @@ void Animation::Update(const double& delta_time) { } } -void Animation::Reset() { +void TBSAnimation::Reset() { current_frame = 0; counter = 0; } -int Animation::GetCurrentFrame() const { +int TBSAnimation::GetCurrentFrame() const { return tex_ids[current_frame]; } diff --git a/src/Animation/src/walk_animation.cpp b/src/Animation/src/walk_animation.cpp new file mode 100644 index 0000000..aeb2cfc --- /dev/null +++ b/src/Animation/src/walk_animation.cpp @@ -0,0 +1,26 @@ +#include "Animation/walk_animation.h" + +namespace wolfenstein { + +WalkAnimation::WalkAnimation(const std::vector& tex_ids, + const double step_size) + : tex_ids(tex_ids), current_frame(1), step_size(step_size), counter(0) {} + +void WalkAnimation::Update(const double& delta_time) { + counter += delta_time; + if (counter > step_size) { + current_frame = (current_frame + 1) % tex_ids.size(); + counter = 0; + } +} + +void WalkAnimation::Reset() { + current_frame = 1; + counter = 0; +} + +int WalkAnimation::GetCurrentFrame() const { + return tex_ids[current_frame]; +} + +} // namespace wolfenstein diff --git a/src/Camera/include/Camera/camera.h b/src/Camera/include/Camera/camera.h index 57eb961..6cce717 100644 --- a/src/Camera/include/Camera/camera.h +++ b/src/Camera/include/Camera/camera.h @@ -12,13 +12,13 @@ #ifndef CAMERA_INCLUDE_CAMERA_H #define CAMERA_INCLUDE_CAMERA_H -#include -#include -#include -#include -#include -#include -#include +#include "Camera/ray.h" +#include "Camera/raycaster.h" +#include "Characters/character.h" +#include "GameObjects/game_object.h" +#include "GameObjects/static_object.h" +#include "Graphics/scene.h" +#include "Map/map.h" #include #include diff --git a/src/Camera/include/Camera/ray.h b/src/Camera/include/Camera/ray.h index 37c43e4..80f39a6 100644 --- a/src/Camera/include/Camera/ray.h +++ b/src/Camera/include/Camera/ray.h @@ -12,7 +12,7 @@ #ifndef CAMERA_INCLUDE_CAMERA_RAY_H_ #define CAMERA_INCLUDE_CAMERA_RAY_H_ -#include +#include "Math/vector.h" #include diff --git a/src/Camera/include/Camera/raycaster.h b/src/Camera/include/Camera/raycaster.h index c5ad5dc..74bb628 100644 --- a/src/Camera/include/Camera/raycaster.h +++ b/src/Camera/include/Camera/raycaster.h @@ -12,10 +12,10 @@ #ifndef CAMERA_INCLUDE_CAMERA_RAYCASTER_H_ #define CAMERA_INCLUDE_CAMERA_RAYCASTER_H_ -#include -#include -#include -#include +#include "Camera/ray.h" +#include "Characters/character.h" +#include "Map/map.h" +#include "Math/vector.h" #include diff --git a/src/Camera/src/camera.cpp b/src/Camera/src/camera.cpp index 1be9f3b..0771f84 100644 --- a/src/Camera/src/camera.cpp +++ b/src/Camera/src/camera.cpp @@ -9,10 +9,10 @@ * */ -#include -#include -#include -#include +#include "Camera/camera.h" +#include "Camera/ray.h" +#include "Math/vector.h" +#include "TextureManager/texture_manager.h" #include #include diff --git a/src/Camera/src/ray.cpp b/src/Camera/src/ray.cpp index 377b091..b1ea5c4 100644 --- a/src/Camera/src/ray.cpp +++ b/src/Camera/src/ray.cpp @@ -1,4 +1,4 @@ -#include +#include "Camera/ray.h" #include diff --git a/src/Camera/src/raycaster.cpp b/src/Camera/src/raycaster.cpp index 7d9757a..7849e73 100644 --- a/src/Camera/src/raycaster.cpp +++ b/src/Camera/src/raycaster.cpp @@ -1,4 +1,4 @@ -#include +#include "Camera/raycaster.h" #include #include diff --git a/src/Characters/CMakeLists.txt b/src/Characters/CMakeLists.txt index 54d8409..ffb3f76 100644 --- a/src/Characters/CMakeLists.txt +++ b/src/Characters/CMakeLists.txt @@ -1,8 +1,3 @@ -link_directories( - ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/include -) - add_library( character STATIC @@ -15,11 +10,17 @@ target_include_directories(character PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include ) +target_link_directories(character PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/include +) + target_link_libraries( character PUBLIC game_object vector collision_manager + animation ) diff --git a/src/Characters/include/Characters/character.h b/src/Characters/include/Characters/character.h index 9b29fea..4972461 100644 --- a/src/Characters/include/Characters/character.h +++ b/src/Characters/include/Characters/character.h @@ -12,7 +12,7 @@ #ifndef CHARACTERS_INCLUDE_CHARACTER_H #define CHARACTERS_INCLUDE_CHARACTER_H -#include +#include "GameObjects/game_object.h" namespace wolfenstein { @@ -41,7 +41,6 @@ class ICharacter virtual void SetPosition(Position2D position) = 0; virtual Position2D GetPosition() const = 0; - }; } // namespace wolfenstein diff --git a/src/Characters/include/Characters/enemy.h b/src/Characters/include/Characters/enemy.h index d224406..75923a6 100644 --- a/src/Characters/include/Characters/enemy.h +++ b/src/Characters/include/Characters/enemy.h @@ -12,14 +12,17 @@ #ifndef CHARACTERS_INCLUDE_ENEMY_H_ #define CHARACTERS_INCLUDE_ENEMY_H_ -#include +#include "Animation/walk_animation.h" +#include "Characters/character.h" +#include "Math/vector.h" namespace wolfenstein { class Enemy : public ICharacter, public IGameObject { public: - explicit Enemy(); + explicit Enemy(CharacterConfig config, double width, double height, + WalkAnimation animation); ~Enemy() = default; void Update(double delta_time) override; @@ -35,14 +38,19 @@ class Enemy : public ICharacter, public IGameObject double GetWidth() const override; double GetHeight() const override; + void SetNextPose(vector2d pose); + private: void Move(double delta_time); Position2D position_; + double rotation_speed_; + double translation_speed_; std::string id_; - int texture_id; double width; double height; + vector2d next_pose; + WalkAnimation animation; }; } // namespace wolfenstein diff --git a/src/Characters/include/Characters/player.h b/src/Characters/include/Characters/player.h index 7c47cde..168d923 100644 --- a/src/Characters/include/Characters/player.h +++ b/src/Characters/include/Characters/player.h @@ -12,7 +12,7 @@ #ifndef CHARACTERS_PLAYER_H #define CHARACTERS_PLAYER_H -#include +#include "Characters/character.h" #include namespace wolfenstein { @@ -35,7 +35,7 @@ class Player : public ICharacter, public IGameObject int GetTextureId() const override { return -1; } double GetWidth() const override { return -1; } double GetHeight() const override { return -1; } - void SetCameraPositionUpdator(std::function updator); + void SubscribeToPlayerPosition(std::function subscriber); private: void Move(double delta_time); @@ -45,7 +45,7 @@ class Player : public ICharacter, public IGameObject double rotation_speed_; double translation_speed_; std::string id_; - std::function camera_position_updator_; + std::vector> player_position_subscribers_; }; } // namespace wolfenstein diff --git a/src/Characters/src/enemy.cpp b/src/Characters/src/enemy.cpp index fd7e285..30d405c 100644 --- a/src/Characters/src/enemy.cpp +++ b/src/Characters/src/enemy.cpp @@ -1,14 +1,27 @@ -#include -#include +#include "Characters/enemy.h" +#include "Utility/uuid_generator.h" namespace wolfenstein { -Enemy::Enemy() { +Enemy::Enemy(CharacterConfig config, double width, double height, + WalkAnimation animation) + : position_(config.initial_position), + rotation_speed_(config.rotation_speed), + translation_speed_(config.translation_speed), + width(width), + height(height), + animation(animation) { id_ = UuidGenerator::GetInstance().GenerateUuid().bytes(); } void Enemy::Update(double delta_time) { - Move(delta_time); + if (next_pose != position_.pose) { + Move(delta_time); + animation.Update(delta_time); + } + else { + animation.Reset(); + } } void Enemy::SetPose(const vector2d& pose) { @@ -36,11 +49,19 @@ std::string Enemy::GetId() const { } void Enemy::Move(double delta_time) { - (void)delta_time; + vector2d direction = next_pose - position_.pose; + direction.Norm(); + vector2d new_pose = + position_.pose + direction * translation_speed_ * delta_time; + position_.pose = new_pose; +} + +void Enemy::SetNextPose(vector2d pose) { + next_pose = pose; } int Enemy::GetTextureId() const { - return texture_id; + return animation.GetCurrentFrame(); } double Enemy::GetWidth() const { diff --git a/src/Characters/src/player.cpp b/src/Characters/src/player.cpp index 48d1cfd..a498899 100644 --- a/src/Characters/src/player.cpp +++ b/src/Characters/src/player.cpp @@ -1,8 +1,8 @@ -#include -#include -#include +#include "Characters/player.h" +#include "CollisionManager/collision_manager.h" +#include "Math/vector.h" +#include "Utility/uuid_generator.h" #include -#include namespace wolfenstein { @@ -16,8 +16,9 @@ Player::Player(CharacterConfig& config) void Player::Update(double delta_time) { Move(delta_time); Rotate(delta_time); - camera_position_updator_(position_); - std::cout << "Player position: " << position_.pose << std::endl; + for (auto& subscriber : player_position_subscribers_) { + subscriber(position_); + } } void Player::SetPose(const vector2d& pose) { @@ -44,8 +45,9 @@ std::string Player::GetId() const { return id_; } -void Player::SetCameraPositionUpdator(std::function updator) { - camera_position_updator_ = updator; +void Player::SubscribeToPlayerPosition( + std::function updator) { + player_position_subscribers_.push_back(updator); } void Player::Move(double delta_time) { diff --git a/src/CollisionManager/include/CollisionManager/collision_manager.h b/src/CollisionManager/include/CollisionManager/collision_manager.h index 613506b..750765c 100644 --- a/src/CollisionManager/include/CollisionManager/collision_manager.h +++ b/src/CollisionManager/include/CollisionManager/collision_manager.h @@ -12,9 +12,9 @@ #ifndef COLLISION_MANAGER_INCLUDE_COLLISION_MANAGER_H #define COLLISION_MANAGER_INCLUDE_COLLISION_MANAGER_H -#include -#include -#include +#include "GameObjects/game_object.h" +#include "Map/map.h" +#include "Math/vector.h" #include namespace wolfenstein { diff --git a/src/CollisionManager/src/collision_manager.cpp b/src/CollisionManager/src/collision_manager.cpp index 27d963b..715a1ba 100644 --- a/src/CollisionManager/src/collision_manager.cpp +++ b/src/CollisionManager/src/collision_manager.cpp @@ -1,4 +1,4 @@ -#include +#include "CollisionManager/collision_manager.h" #include namespace wolfenstein { diff --git a/src/Core/CMakeLists.txt b/src/Core/CMakeLists.txt index 552d473..567c909 100644 --- a/src/Core/CMakeLists.txt +++ b/src/Core/CMakeLists.txt @@ -19,14 +19,15 @@ target_link_libraries( game PUBLIC scene - time_manager - collision_manager - texture_manager camera character game_object map vector renderer + time_manager + collision_manager + texture_manager + navigation_manager SDL2 ) \ No newline at end of file diff --git a/src/Core/include/Core/game.h b/src/Core/include/Core/game.h index 718413a..fba0e13 100644 --- a/src/Core/include/Core/game.h +++ b/src/Core/include/Core/game.h @@ -12,15 +12,15 @@ #ifndef CORE_INCLUDE_CORE_GAME_H_ #define CORE_INCLUDE_CORE_GAME_H_ -#include -#include -#include -#include -#include -#include -#include -#include -#include +#include "Camera/camera.h" +#include "Characters/player.h" +#include "CollisionManager/collision_manager.h" +#include "Graphics/renderer.h" +#include "Graphics/scene.h" +#include "Map/map.h" +#include "Math/vector.h" +#include "TextureManager/texture_manager.h" +#include "TimeManager/time_manager.h" namespace wolfenstein { @@ -35,6 +35,7 @@ struct GeneralConfig int fps; double view_distance; double fov; + bool fullscreen; }; class Game diff --git a/src/Core/src/game.cpp b/src/Core/src/game.cpp index 497de04..7ca6c17 100644 --- a/src/Core/src/game.cpp +++ b/src/Core/src/game.cpp @@ -1,8 +1,12 @@ +#include "Core/game.h" +#include "Animation/time_based_single_animation.h" +#include "Animation/walk_animation.h" +#include "Characters/enemy.h" #include "GameObjects/dynamic_object.h" #include "GameObjects/static_object.h" -#include -#include -#include +#include "Graphics/renderer.h" +#include "Math/vector.h" +#include "NavigationManager/navigation_manager.h" #include #include #include @@ -23,6 +27,7 @@ void Game::Init() { map_ = std::make_shared(); CollisionManager::GetInstance().InitManager(map_); + NavigationManager::GetInstance().InitManager(map_); scene_ = std::make_shared(); scene_->SetMap(map_); @@ -32,7 +37,7 @@ void Game::Init() { RenderConfig render_config = {config_.screen_width, config_.screen_height, config_.padding, config_.scale, config_.fps, config_.view_distance, - config_.fov, false}; + config_.fov, config_.fullscreen}; renderer_ = std::make_shared("Wolfenstein", render_config); Camera2DConfig camera_config = {config_.screen_width, config_.fov, @@ -42,35 +47,47 @@ void Game::Init() { CharacterConfig player_config = {Position2D({3, 1.5}, 1.50), 2.0, 0.4}; player_ = std::make_shared(player_config); - auto camera_position_updator = [this](Position2D position) { - camera_->SetPosition(position); - }; + player_->SubscribeToPlayerPosition(std::bind( + [this](Position2D position) { camera_->SetPosition(position); }, + std::placeholders::_1)); - player_->SetCameraPositionUpdator( - std::bind(camera_position_updator, std::placeholders::_1)); + std::vector caco_walk_tex_ids = {38, 39, 40}; + const WalkAnimation walk_animation(caco_walk_tex_ids, 0.2); + auto enemy = std::make_shared( + CharacterConfig(Position2D({8, 7}, 1.50), 0.8, 0.4), 0.4, 0.8, + walk_animation); std::vector tex_ids = {9, 10, 11, 12}; - const auto animation_green_light = - std::make_shared(tex_ids, 0.2); + const auto animation_green_light = TBSAnimation(tex_ids, 0.1); std::vector tex_ids_2 = {13, 14, 15, 16}; - const auto animation_red_light = - std::make_shared(tex_ids_2, 0.2); + const auto animation_red_light = TBSAnimation(tex_ids_2, 0.1); std::vector tex_ids2 = {86, 87, 88, 89}; scene_->SetPlayer(player_); + scene_->AddObject(enemy); + scene_->AddObject( - std::make_shared(vector2d(3.5, 1.5), 8, 0.2, 0.5)); - scene_->AddObject( - std::make_shared(vector2d(3.5, 7.5), 8, 0.2, 0.5)); + std::make_shared(vector2d(14.5, 9), 8, 0.2, 0.5)); + + scene_->AddObject(std::make_shared( + vector2d(12.1, 8.15), + std::make_shared(animation_red_light), 0.2, 0.9)); + scene_->AddObject(std::make_shared( + vector2d(10.9, 8.15), + std::make_shared(animation_red_light), 0.2, 0.9)); scene_->AddObject(std::make_shared( - vector2d(3.5, 1.9), animation_green_light, 0.2, 0.9)); + vector2d(9.9, 10.9), + std::make_shared(animation_green_light), 0.2, 0.9)); scene_->AddObject(std::make_shared( - vector2d(12.1, 8.15), animation_green_light, 0.2, 0.9)); + vector2d(9.9, 13.10), + std::make_shared(animation_green_light), 0.2, 0.9)); scene_->AddObject(std::make_shared( - vector2d(10.9, 8.15), animation_red_light, 0.2, 0.9)); + vector2d(12.1, 13.1), + std::make_shared(animation_green_light), 0.2, 0.9)); scene_->AddObject(std::make_shared( - vector2d(12.5, 9.5), animation_red_light, 0.2, 0.5)); + vector2d(12.1, 10.9), + std::make_shared(animation_green_light), 0.2, 0.9)); is_running_ = true; time_manager_->InitClock(); } diff --git a/src/GameObjects/include/GameObjects/dynamic_object.h b/src/GameObjects/include/GameObjects/dynamic_object.h index f28a8a9..f133d7b 100644 --- a/src/GameObjects/include/GameObjects/dynamic_object.h +++ b/src/GameObjects/include/GameObjects/dynamic_object.h @@ -12,9 +12,9 @@ #ifndef GAME_OBJECTS_INCLUDE_DYNAMIC_OBJECT_H #define GAME_OBJECTS_INCLUDE_DYNAMIC_OBJECT_H -#include -#include -#include +#include "Animation/time_based_single_animation.h" +#include "GameObjects/game_object.h" +#include "Utility/uuid_generator.h" #include namespace wolfenstein { @@ -23,7 +23,7 @@ class DynamicObject : public IGameObject { public: explicit DynamicObject(const vector2d& pose_, - const std::shared_ptr& animation_, + const std::shared_ptr animation_, const double width_, const double height_); ~DynamicObject(); @@ -39,7 +39,7 @@ class DynamicObject : public IGameObject protected: vector2d pose; - std::shared_ptr animation; + std::shared_ptr animation; double width; double height; std::string id; diff --git a/src/GameObjects/include/GameObjects/game_object.h b/src/GameObjects/include/GameObjects/game_object.h index 9df07b6..c12a633 100644 --- a/src/GameObjects/include/GameObjects/game_object.h +++ b/src/GameObjects/include/GameObjects/game_object.h @@ -12,7 +12,7 @@ #ifndef GAME_OBJECTS_INCLUDE_GAME_OBJECT_H #define GAME_OBJECTS_INCLUDE_GAME_OBJECT_H -#include +#include "Math/vector.h" #include namespace wolfenstein { @@ -32,7 +32,7 @@ class IGameObject virtual void Update(double delta_time) = 0; virtual void SetPose(const vector2d& pose) = 0; - + virtual ObjectType GetObjectType() const = 0; virtual vector2d GetPose() const = 0; virtual std::string GetId() const = 0; diff --git a/src/GameObjects/include/GameObjects/static_object.h b/src/GameObjects/include/GameObjects/static_object.h index 64126e5..3676f8a 100644 --- a/src/GameObjects/include/GameObjects/static_object.h +++ b/src/GameObjects/include/GameObjects/static_object.h @@ -12,9 +12,9 @@ #ifndef GAME_OBJECTS_INCLUDE_STATIC_OBJECT_H #define GAME_OBJECTS_INCLUDE_STATIC_OBJECT_H -#include -#include -#include +#include "Characters/character.h" +#include "GameObjects/game_object.h" +#include "Math/vector.h" namespace wolfenstein { diff --git a/src/GameObjects/src/dynamic_object.cpp b/src/GameObjects/src/dynamic_object.cpp index 36f7e0d..f492872 100644 --- a/src/GameObjects/src/dynamic_object.cpp +++ b/src/GameObjects/src/dynamic_object.cpp @@ -1,11 +1,10 @@ -#include -#include -#include +#include "GameObjects/dynamic_object.h" +#include "Utility/uuid_generator.h" namespace wolfenstein { DynamicObject::DynamicObject(const vector2d& pose_, - const std::shared_ptr& animation_, + const std::shared_ptr animation_, const double width_, const double height_) : pose(pose_), animation(animation_), width(width_), height(height_) { id = UuidGenerator::GetInstance().GenerateUuid().bytes(); diff --git a/src/GameObjects/src/static_object.cpp b/src/GameObjects/src/static_object.cpp index b645142..c3e7101 100644 --- a/src/GameObjects/src/static_object.cpp +++ b/src/GameObjects/src/static_object.cpp @@ -1,6 +1,6 @@ -#include -#include -#include +#include "GameObjects/static_object.h" +#include "GameObjects/game_object.h" +#include "Utility/uuid_generator.h" namespace wolfenstein { diff --git a/src/Graphics/CMakeLists.txt b/src/Graphics/CMakeLists.txt index cfd2dc2..2bd5a67 100644 --- a/src/Graphics/CMakeLists.txt +++ b/src/Graphics/CMakeLists.txt @@ -19,6 +19,7 @@ target_link_libraries( PUBLIC game_object map + navigation_manager ) add_library( @@ -37,4 +38,5 @@ target_link_libraries( PUBLIC camera texture_manager + navigation_manager ) \ No newline at end of file diff --git a/src/Graphics/include/Graphics/renderer.h b/src/Graphics/include/Graphics/renderer.h index 1199e50..6b9c4fd 100644 --- a/src/Graphics/include/Graphics/renderer.h +++ b/src/Graphics/include/Graphics/renderer.h @@ -12,9 +12,10 @@ #ifndef GRAPHICS_INCLUDE_GRAPHICS_RENDERER_H_ #define GRAPHICS_INCLUDE_GRAPHICS_RENDERER_H_ -#include -#include -#include +#include "Camera/camera.h" +#include "Characters/enemy.h" +#include "GameObjects/game_object.h" +#include "Graphics/scene.h" #include #include #include @@ -103,6 +104,8 @@ class Renderer const std::shared_ptr camera_ptr); void RenderObjects(const std::vector>& objects, const std::shared_ptr camera_ptr); + void RenderPaths(const std::vector>& enemies); + void DrawLine(vector2i start, vector2i end); SDL_Renderer* renderer_; diff --git a/src/Graphics/include/Graphics/scene.h b/src/Graphics/include/Graphics/scene.h index 294675e..59f19b9 100644 --- a/src/Graphics/include/Graphics/scene.h +++ b/src/Graphics/include/Graphics/scene.h @@ -15,9 +15,10 @@ #include #include -#include -#include -#include +#include "Characters/enemy.h" +#include "Characters/player.h" +#include "GameObjects/game_object.h" +#include "Map/map.h" namespace wolfenstein { @@ -33,6 +34,7 @@ class Scene void Update(double delta_time); std::vector> GetObjects() const; + std::vector> GetEnemies() const; std::shared_ptr GetMap() const; std::shared_ptr GetPlayer() const; @@ -40,6 +42,7 @@ class Scene std::vector> objects; std::shared_ptr map; std::shared_ptr player; + std::vector> enemies; }; } // namespace wolfenstein diff --git a/src/Graphics/src/renderer.cpp b/src/Graphics/src/renderer.cpp index 558459b..b068843 100644 --- a/src/Graphics/src/renderer.cpp +++ b/src/Graphics/src/renderer.cpp @@ -1,12 +1,13 @@ -#include -#include -#include -#include -#include -#include +#include "Graphics/renderer.h" +#include "Camera/ray.h" +#include "Characters/player.h" +#include "GameObjects/static_object.h" +#include "Map/map.h" +#include "Math/vector.h" +#include "NavigationManager/navigation_manager.h" +#include "TextureManager/texture_manager.h" #include #include -#include #include #include #include @@ -217,6 +218,7 @@ void Renderer::RenderScene2D(const std::shared_ptr& scene_ptr, RenderMap(scene_ptr->GetMap()); RenderPlayer(scene_ptr->GetPlayer(), camera_ptr); RenderObjects(scene_ptr->GetObjects(), camera_ptr); + RenderPaths(scene_ptr->GetEnemies()); SDL_RenderPresent(renderer_); } @@ -296,6 +298,18 @@ void Renderer::RenderObjects( } } +void Renderer::RenderPaths(const std::vector>& enemies) { + SetDrawColor({0, 0, 255, 255}); + for (const auto& enemy : enemies) { + const auto path = + NavigationManager::GetInstance().GetPath(enemy->GetId()); + for (unsigned int i = 0; i < path.size() - 1; i++) { + DrawLine(ToVector2i(path[i] * config_.scale), + ToVector2i(path[i + 1] * config_.scale)); + } + } +} + void Renderer::DrawLine(vector2i start, vector2i end) { SDL_RenderDrawLine(renderer_, start.x, start.y, end.x, end.y); } diff --git a/src/Graphics/src/scene.cpp b/src/Graphics/src/scene.cpp index 957fbad..9a29e74 100644 --- a/src/Graphics/src/scene.cpp +++ b/src/Graphics/src/scene.cpp @@ -1,9 +1,13 @@ -#include +#include "Graphics/scene.h" +#include "NavigationManager/navigation_manager.h" namespace wolfenstein { void Scene::AddObject(std::shared_ptr object) { objects.push_back(object); + if (object->GetObjectType() == ObjectType::CHARACTER_ENEMY) { + enemies.push_back(std::dynamic_pointer_cast(object)); + } } void Scene::SetMap(std::shared_ptr map) { @@ -16,6 +20,10 @@ void Scene::SetPlayer(std::shared_ptr player) { void Scene::Update(double delta_time) { player->Update(delta_time); + for (auto& enemy : enemies) { + enemy->SetNextPose(NavigationManager::GetInstance().FindPath( + enemy->GetPosition(), player->GetPosition(), enemy->GetId())); + } for (auto& object : objects) { object->Update(delta_time); } @@ -25,6 +33,10 @@ std::vector> Scene::GetObjects() const { return objects; } +std::vector> Scene::GetEnemies() const { + return enemies; +} + std::shared_ptr Scene::GetMap() const { return map; } diff --git a/src/Map/CMakeLists.txt b/src/Map/CMakeLists.txt index 0da105b..d665b96 100644 --- a/src/Map/CMakeLists.txt +++ b/src/Map/CMakeLists.txt @@ -1,8 +1,3 @@ -link_directories( - ${CMAKE_CURRENT_SOURCE_DIR} - ${CMAKE_CURRENT_SOURCE_DIR}/include -) - add_library( map STATIC @@ -12,4 +7,17 @@ add_library( target_include_directories(map PUBLIC ${CMAKE_CURRENT_SOURCE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/include + ${PROJECT_SOURCE_DIR}/third-party/ +) + +target_link_directories(map PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/include + ${PROJECT_SOURCE_DIR}/third-party/path-planning/planning/utility ) + +target_link_libraries( + map + PUBLIC + common_planning +) \ No newline at end of file diff --git a/src/Map/include/Map/map.h b/src/Map/include/Map/map.h index 27a99a5..7f40a26 100644 --- a/src/Map/include/Map/map.h +++ b/src/Map/include/Map/map.h @@ -12,7 +12,9 @@ #ifndef MAP_INCLUDE_MAP_MAP_H_ #define MAP_INCLUDE_MAP_MAP_H_ +#include "path-planning/planning/utility/common_planning.h" #include +#include #include namespace wolfenstein { @@ -21,17 +23,21 @@ class Map { public: Map(); - void LoadMap(); std::vector> GetMap(); + std::shared_ptr GetPathFinderMap(); uint16_t GetSizeX(); uint16_t GetSizeY(); private: - std::vector> map_; + void LoadMap(); + void MapToPathFinderMap(); + uint16_t size_x_; uint16_t size_y_; + std::shared_ptr path_finder_map_; + std::vector> map_; }; } // namespace wolfenstein -#endif // MAP_INCLUDE_MAP_MAP_H_ +#endif // MAP_INCLUDE_MAP_MAP_H_ diff --git a/src/Map/src/map.cpp b/src/Map/src/map.cpp index 037535a..ed300c6 100644 --- a/src/Map/src/map.cpp +++ b/src/Map/src/map.cpp @@ -1,4 +1,4 @@ -#include +#include "Map/map.h" #include namespace wolfenstein { @@ -10,17 +10,17 @@ std::string simple_map{ "3000000000000003" "3000000000000003" "3001111000000003" - "3001110001111003" - "3001110011000013" - "3000000001000013" - "3000000001111003" + "3000000002222003" + "3001110022000053" + "3000000002000053" + "3000000002222003" "3000000000000003" "3000000000000003" - "3111111100011003" - "3000000000011003" - "3000111100000003" - "3000100000000003" - "3000100000000003" + "3333333300044003" + "3000000000044003" + "3000333300000003" + "3000300000000003" + "3000300000000003" "3111111111111003" "3000000100000003" "3000000100000003" @@ -32,10 +32,13 @@ std::string simple_map{ "3000000000001003" "3000000000001003" "3333333333333333"}; + +constexpr double res{0.1}; } // namespace -Map::Map() { +Map::Map() : size_x_(26), size_y_(16) { LoadMap(); + MapToPathFinderMap(); } void Map::LoadMap() { @@ -70,10 +73,32 @@ void Map::LoadMap() { } } +void Map::MapToPathFinderMap() { + path_finder_map_ = + std::make_shared(size_x_ / res, size_y_ / res); + for (uint16_t i = 0; i < size_x_; i++) { + for (uint16_t j = 0; j < size_y_; j++) { + if (map_[i][j] == 0) { + for (uint16_t k = 0; k < (1 / res) ; k++) { + for (uint16_t l = 0; l < (1 / res) ; l++) { + path_finder_map_->SetNodeState( + planning::Node(i / res + k, j / res + l), + planning::NodeState::kFree); + } + } + } + } + } +} + std::vector> Map::GetMap() { return map_; } +std::shared_ptr Map::GetPathFinderMap() { + return path_finder_map_; +} + uint16_t Map::GetSizeX() { return size_x_; } diff --git a/src/Math/include/Math/vector.h b/src/Math/include/Math/vector.h index 2a4f04f..ff18443 100644 --- a/src/Math/include/Math/vector.h +++ b/src/Math/include/Math/vector.h @@ -34,6 +34,7 @@ struct vector2i vector2i& operator/=(const int scalar); vector2i& operator+=(const vector2i& v); vector2i& operator-=(const vector2i& v); + bool operator==(const vector2i& v) const; }; struct vector2d @@ -52,6 +53,7 @@ struct vector2d vector2d& operator/=(const double scalar); vector2d& operator+=(const vector2d& v); vector2d& operator-=(const vector2d& v); + bool operator==(const vector2d& v) const; vector2d Cross(const vector2d& v) const; double Dot(const vector2d& v) const; diff --git a/src/Math/src/vector.cpp b/src/Math/src/vector.cpp index 40f3b46..ad09a75 100644 --- a/src/Math/src/vector.cpp +++ b/src/Math/src/vector.cpp @@ -1,4 +1,4 @@ -#include +#include "Math/vector.h" #include namespace wolfenstein { @@ -53,6 +53,10 @@ vector2i& vector2i::operator-=(const vector2i& v) { return *this; } +bool vector2i::operator==(const vector2i& v) const { + return x == v.x && y == v.y; +} + // vector2d -------------------------------------------------------------------- vector2d::vector2d() : x(0), y(0) {} @@ -105,6 +109,10 @@ vector2d& vector2d::operator-=(const vector2d& v) { return *this; } +bool vector2d::operator==(const vector2d& v) const { + return x == v.x && y == v.y; +} + vector2d vector2d::Cross(const vector2d& v) const { return {x * v.y - y * v.x, x * v.x + y * v.y}; } diff --git a/src/NavigationManager/CMakeLists.txt b/src/NavigationManager/CMakeLists.txt new file mode 100644 index 0000000..ccc1693 --- /dev/null +++ b/src/NavigationManager/CMakeLists.txt @@ -0,0 +1,26 @@ +add_library( + navigation_manager + STATIC + src/navigation_manager.cpp +) + +target_include_directories(navigation_manager PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/include + ${PROJECT_SOURCE_DIR}/third-party/path-planning +) + +target_link_directories(navigation_manager PUBLIC + ${CMAKE_CURRENT_SOURCE_DIR} + ${CMAKE_CURRENT_SOURCE_DIR}/include + ${PROJECT_SOURCE_DIR}/third-party/path-planning +) + +target_link_libraries( + navigation_manager + PUBLIC + vector + character + astar + map +) \ No newline at end of file diff --git a/src/NavigationManager/include/NavigationManager/navigation_helper.h b/src/NavigationManager/include/NavigationManager/navigation_helper.h new file mode 100644 index 0000000..6aa4b35 --- /dev/null +++ b/src/NavigationManager/include/NavigationManager/navigation_helper.h @@ -0,0 +1,30 @@ +/** + * @file navigation_helper.h + * @author Bilal Kahraman (kahramannbilal@gmail.com) + * @brief + * @version 0.1 + * @date 2024-08-26 + * + * @copyright Copyright (c) 2024 + * + */ + +#ifndef NAVIGATION_MANAGER_INCLUDE_NAVIGATION_MANAGER_NAVIGATION_HELPER_H +#define NAVIGATION_MANAGER_INCLUDE_NAVIGATION_MANAGER_NAVIGATION_HELPER_H + +#include "Math/vector.h" +#include "path-planning/planning/utility/data_types.h" + +namespace wolfenstein { + +inline vector2d FromNode(const planning::Node& node) { + return vector2d(node.x_, node.y_); +} + +inline planning::Node FromVector2d(const vector2d& v) { + return planning::Node(v.x, v.y); +} + +} // namespace wolfenstein + +#endif // NAVIGATION_MANAGER_INCLUDE_NAVIGATION_MANAGER_NAVIGATION_HELPER_H diff --git a/src/NavigationManager/include/NavigationManager/navigation_manager.h b/src/NavigationManager/include/NavigationManager/navigation_manager.h new file mode 100644 index 0000000..10c2e82 --- /dev/null +++ b/src/NavigationManager/include/NavigationManager/navigation_manager.h @@ -0,0 +1,48 @@ +/** + * @file navigation_manager.h + * @author Bilal Kahraman (kahramannbilal@gmail.com) + * @brief + * @version 0.1 + * @date 2024-08-26 + * + * @copyright Copyright (c) 2024 + * + */ + +#ifndef NAVIGATION_MANAGER_INCLUDE_NAVIGATION_MANAGER_NAVIGATION_MANAGER_H +#define NAVIGATION_MANAGER_INCLUDE_NAVIGATION_MANAGER_NAVIGATION_MANAGER_H + +#include "Characters/character.h" +#include "Map/map.h" +#include "Math/vector.h" +#include "path-planning/planning/grid_base/astar/astar.h" +#include +#include +#include + +namespace wolfenstein { + +class NavigationManager +{ + public: + static NavigationManager& GetInstance(); + NavigationManager(const NavigationManager&) = delete; + NavigationManager& operator=(const NavigationManager&) = delete; + ~NavigationManager() = default; + + void InitManager(std::shared_ptr map); + vector2d FindPath(Position2D start, Position2D end, std::string id); + std::vector GetPath(std::string id); + + private: + NavigationManager() = default; + + static NavigationManager* instance_; + std::shared_ptr map_; + std::shared_ptr path_planner_; + std::unordered_map> paths_; +}; + +} // namespace wolfenstein + +#endif // NAVIGATION_MANAGER_INCLUDE_NAVIGATION_MANAGER_NAVIGATION_MANAGER_H \ No newline at end of file diff --git a/src/NavigationManager/src/navigation_manager.cpp b/src/NavigationManager/src/navigation_manager.cpp new file mode 100644 index 0000000..6140958 --- /dev/null +++ b/src/NavigationManager/src/navigation_manager.cpp @@ -0,0 +1,61 @@ +#include "NavigationManager/navigation_manager.h" +#include "Math/vector.h" +#include "NavigationManager/navigation_helper.h" +#include + +namespace wolfenstein { + +NavigationManager* NavigationManager::instance_ = nullptr; + +NavigationManager& NavigationManager::GetInstance() { + if (instance_ == nullptr) { + instance_ = new NavigationManager(); + } + return *instance_; +} + +void NavigationManager::InitManager(std::shared_ptr map) { + map_ = map; + path_planner_ = std::make_shared(0.6, 8); +} + +//@Note apply caching mechanism later +vector2d NavigationManager::FindPath(Position2D start, Position2D end, + std::string id) { + if (start.pose.Distance(end.pose) < 0.1) { + return start.pose; + } + if (start.pose.Distance(end.pose) > 5) { + paths_[id] = {start.pose}; + return start.pose; + } + + planning::Node start_node = FromVector2d(start.pose / 0.1); + planning::Node end_node = FromVector2d(end.pose / 0.1); + planning::Path path = + path_planner_->FindPath(start_node, end_node, map_->GetPathFinderMap()); + if (path.empty()) { + paths_[id] = {start.pose}; + return start.pose; + } + std::vector path_vector; + path.erase(path.begin()); + for (auto node : path) { + path_vector.push_back(FromNode(node) * 0.1); + } + paths_[id] = path_vector; + + if (path_vector.empty()) { + return start.pose; + } + auto next = path_vector.front(); + std::cout << "Next: " << next << std::endl; + path_vector.erase(path_vector.begin()); + return next; +} + +std::vector NavigationManager::GetPath(std::string id) { + return paths_[id]; +} + +} // namespace wolfenstein \ No newline at end of file diff --git a/src/TextureManager/src/texture_manager.cpp b/src/TextureManager/src/texture_manager.cpp index 0d79048..62a69de 100644 --- a/src/TextureManager/src/texture_manager.cpp +++ b/src/TextureManager/src/texture_manager.cpp @@ -1,5 +1,5 @@ +#include "TextureManager/texture_manager.h" #include -#include #include namespace wolfenstein { diff --git a/src/TimeManager/src/time_manager.cpp b/src/TimeManager/src/time_manager.cpp index 019e24d..9a1bc2e 100644 --- a/src/TimeManager/src/time_manager.cpp +++ b/src/TimeManager/src/time_manager.cpp @@ -1,4 +1,4 @@ -#include +#include "TimeManager/time_manager.h" #include namespace wolfenstein { diff --git a/src/Utility/CMakeLists.txt b/src/Utility/CMakeLists.txt index 9102ad1..1bc7fa3 100644 --- a/src/Utility/CMakeLists.txt +++ b/src/Utility/CMakeLists.txt @@ -21,5 +21,5 @@ add_library(uuid_generator target_include_directories(uuid_generator PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}/include - ${PROJECT_SOURCE_DIR} + ${PROJECT_SOURCE_DIR}/third-party ) \ No newline at end of file diff --git a/src/Utility/include/Utility/uuid_generator.h b/src/Utility/include/Utility/uuid_generator.h index d6aaf2e..5450f26 100644 --- a/src/Utility/include/Utility/uuid_generator.h +++ b/src/Utility/include/Utility/uuid_generator.h @@ -12,7 +12,7 @@ #ifndef UTILITY_INCLUDE_UTILITY_UUID_GENERATOR_H #define UTILITY_INCLUDE_UTILITY_UUID_GENERATOR_H -#include +#include "uuid_v4/uuid_v4.h" namespace wolfenstein { diff --git a/src/Utility/src/logger.cpp b/src/Utility/src/logger.cpp index f3d68f8..8fbc7dc 100644 --- a/src/Utility/src/logger.cpp +++ b/src/Utility/src/logger.cpp @@ -1 +1 @@ -#include \ No newline at end of file +#include "Utility/logger.h" \ No newline at end of file diff --git a/src/Utility/src/uuid_generator.cpp b/src/Utility/src/uuid_generator.cpp index d5eb86c..c5f1624 100644 --- a/src/Utility/src/uuid_generator.cpp +++ b/src/Utility/src/uuid_generator.cpp @@ -1,4 +1,4 @@ -#include +#include "Utility/uuid_generator.h" namespace wolfenstein { diff --git a/third-party/path-planning b/third-party/path-planning new file mode 160000 index 0000000..6e5008b --- /dev/null +++ b/third-party/path-planning @@ -0,0 +1 @@ +Subproject commit 6e5008b97776961a5e90fc399172c679fa07b7da