diff --git a/CMakeLists.txt b/CMakeLists.txt index 591a1dc..ed035a9 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -54,7 +54,8 @@ set(SOURCES src/game/input/input_identity.h src/utilities/magic_enum.hpp src/game/player/player_spawner.cpp - src/game/player/player_spawner.hpp) + src/game/player/player_spawner.hpp + ) set(PHYSICS_00_SOURCES src/prototypes/physics_00.cpp) diff --git a/src/debug/grid_debug_layer.cpp b/src/debug/grid_debug_layer.cpp index 469288e..8635db7 100644 --- a/src/debug/grid_debug_layer.cpp +++ b/src/debug/grid_debug_layer.cpp @@ -45,7 +45,7 @@ void GridDebugLayer::draw(sf::RenderWindow *window) const } } -void GridDebugLayer::update(Game *game) +void GridDebugLayer::update() { } diff --git a/src/debug/grid_debug_layer.h b/src/debug/grid_debug_layer.h index 9d806a5..1ed5cbb 100644 --- a/src/debug/grid_debug_layer.h +++ b/src/debug/grid_debug_layer.h @@ -11,7 +11,7 @@ public: ~GridDebugLayer(); void draw(sf::RenderWindow *window) const override; - void update(Game *game) override; + void update() override; private: std::vector marker; diff --git a/src/game/camera/tracking_view.cpp b/src/game/camera/tracking_view.cpp index 45c8b0b..d494eec 100644 --- a/src/game/camera/tracking_view.cpp +++ b/src/game/camera/tracking_view.cpp @@ -8,6 +8,7 @@ TrackingView::TrackingView(float freeMoveRadius, float dynamicFollowRadius) : fr { trackables = std::vector(); marker = new CircleObject(2, sf::Color::Yellow); + Game::getInstance()->registerView(this); } TrackingView::~TrackingView() @@ -16,19 +17,19 @@ TrackingView::~TrackingView() delete marker; } -void TrackingView::lateUpdate(Game *game) +void TrackingView::lateUpdate() { // Initialize if necessary if (view == nullptr) { - initializeView(game); + initializeView(); } processTrackableStates(); // Update size // TODO: Update size based on distance of tracked objects - setSize(game->window->getSize()); + setSize(Game::getInstance()->window->getSize()); if (!trackables.empty()) { @@ -38,14 +39,14 @@ void TrackingView::lateUpdate(Game *game) // Update window if necessary if (hasViewChanged) { - game->window->setView(*this->view); + Game::getInstance()->window->setView(*this->view); hasViewChanged = false; } } -void TrackingView::initializeView(Game *game) +void TrackingView::initializeView() { - auto size = game->window->getView().getSize(); + auto size = Game::getInstance()->window->getView().getSize(); view = new sf::View({0, 0}, size); } @@ -78,6 +79,7 @@ void TrackingView::followTarget() { auto trackingPoint = getCollectiveTrackingPoint(); marker->coordinates.set(IsometricCoordinates(trackingPoint)); + moveCenter(trackingPoint - getCenter()); return; // if (isTargetInArea(freeMoveArea)) diff --git a/src/game/camera/tracking_view.h b/src/game/camera/tracking_view.h index 44ad55d..4844a61 100644 --- a/src/game/camera/tracking_view.h +++ b/src/game/camera/tracking_view.h @@ -3,10 +3,11 @@ #include "../game_object.h" -#include "../game.h" #include "ITrackable.h" #include "../../primitives/circle_object.h" +class CircleObject; + class TrackingView : public GameObject { public: @@ -17,11 +18,13 @@ public: void draw(sf::RenderWindow *window) const override; - void lateUpdate(Game *game) override; + + void lateUpdate() override; void addTrackable(ITrackable *trackable); sf::Vector2f getSize() const; + sf::Vector2f getCenter() const; private: @@ -33,26 +36,14 @@ private: CircleObject *marker; - void initializeView(Game *game); + void initializeView(); void setSize(sf::Vector2u windowSize); void followTarget(); - bool isTargetInArea(sf::Vector2f areaSize); - - sf::Vector2f getClosestPositionInArea(sf::Vector2f areaSize) const; - - /// Calculates the hardDirection the target should be pulled back in. - /// \return Normalized vector, pointing from center to target. - sf::Vector2f getRubber() const; - - void performHardFollow(); - void moveCenter(sf::Vector2 delta); - void performDynamicFollow(); - sf::Vector2f getCollectiveTrackingPoint() const; void processTrackableStates(); diff --git a/src/game/game.cpp b/src/game/game.cpp index 5663470..d151fe4 100644 --- a/src/game/game.cpp +++ b/src/game/game.cpp @@ -5,7 +5,8 @@ #include "game.h" Game::Game(std::shared_ptr window) : window(std::move(window)), - gameObjects() + gameObjects(), + views() { } @@ -70,7 +71,7 @@ void Game::update() { if (gameObject->isActive) { - gameObject->update(this); + gameObject->update(); } } @@ -79,7 +80,7 @@ void Game::update() { if (gameObject->isActive) { - gameObject->lateUpdate(this); + gameObject->lateUpdate(); } } @@ -107,3 +108,8 @@ std::shared_ptr Game::constructInstance(const std::shared_ptr window; + std::vector views; private: static inline std::shared_ptr singletonInstance = nullptr; std::vector gameObjects; diff --git a/src/game/game_object.h b/src/game/game_object.h index 27f8de3..c8062f3 100644 --- a/src/game/game_object.h +++ b/src/game/game_object.h @@ -6,9 +6,6 @@ #include #include #include "../coordinates/translated_coordinates.h" -#include "game.h" - -class Game; class GameObject { @@ -18,10 +15,10 @@ public: virtual void draw(sf::RenderWindow *window) const {} - virtual void update(Game *game) + virtual void update() {} - virtual void lateUpdate(Game *game) + virtual void lateUpdate() {} TranslatedCoordinates coordinates; diff --git a/src/game/player/player.cpp b/src/game/player/player.cpp index a0bbea8..c7504b6 100644 --- a/src/game/player/player.cpp +++ b/src/game/player/player.cpp @@ -13,7 +13,7 @@ sf::Vector2f Player::getTrackableSize() const return {static_cast(circle->getRadius() * 2), static_cast(circle->getRadius() * 2)}; } -void Player::update(Game *game) +void Player::update() { if (!input->isActive) { isActive = false; diff --git a/src/game/player/player.hpp b/src/game/player/player.hpp index f9d9f88..ff7d9c6 100644 --- a/src/game/player/player.hpp +++ b/src/game/player/player.hpp @@ -14,7 +14,7 @@ public: void draw(sf::RenderWindow *window) const override; - void update(Game *game) override; + void update() override; sf::Vector2f getTrackablePosition() const override; diff --git a/src/game/player/player_spawner.cpp b/src/game/player/player_spawner.cpp index 006a6fe..db91fc2 100644 --- a/src/game/player/player_spawner.cpp +++ b/src/game/player/player_spawner.cpp @@ -1,12 +1,13 @@ #include "player_spawner.hpp" #include "player.hpp" -void PlayerSpawner::update(Game *game) +void PlayerSpawner::update() { // Create player for new input identities for (auto &inputIdentity: InputMapper::getInstance()->newInputIdentities) { auto player = new Player(inputIdentity, sf::Color::Red, {0, 0}); - game->addGameObject(player); + Game::getInstance()->addGameObject(player); + Game::getInstance()->views[0]->addTrackable(player); } } diff --git a/src/game/player/player_spawner.hpp b/src/game/player/player_spawner.hpp index 7bd3678..06ad24a 100644 --- a/src/game/player/player_spawner.hpp +++ b/src/game/player/player_spawner.hpp @@ -7,7 +7,7 @@ class PlayerSpawner : public GameObject { public: - void update(Game *game) override; + void update() override; }; diff --git a/src/primitives/circle_object.cpp b/src/primitives/circle_object.cpp index 6752545..8ba7bb1 100644 --- a/src/primitives/circle_object.cpp +++ b/src/primitives/circle_object.cpp @@ -15,7 +15,7 @@ void CircleObject::draw(sf::RenderWindow *window) const window->draw(circle); } -void CircleObject::update(Game *game) +void CircleObject::update() { } diff --git a/src/primitives/circle_object.h b/src/primitives/circle_object.h index f4081da..92ef083 100644 --- a/src/primitives/circle_object.h +++ b/src/primitives/circle_object.h @@ -2,15 +2,16 @@ #define HOLESOME_CIRCLE_OBJECT_H -#include "../game/game_object.h" #include +#include +#include "../game/game.h" class CircleObject : public GameObject { public: CircleObject(int radius, sf::Color color); void draw(sf::RenderWindow *window) const override; - void update(Game *game) override; + void update() override; int getRadius() const;