From 15e63094fdaf9abb6119b03106f6391f19f5e41a Mon Sep 17 00:00:00 2001 From: Maximilian Giller Date: Tue, 23 May 2023 23:38:37 +0200 Subject: [PATCH] Rebranded world view to tracking view --- CMakeLists.txt | 6 ++-- src/coordinates/translated_coordinates.cpp | 2 +- src/game/{world => camera}/ITrackable.h | 0 .../tracking_view.cpp} | 32 +++++++++---------- .../world_view.h => camera/tracking_view.h} | 16 +++++----- src/game/player/player.hpp | 2 +- src/main.cpp | 4 +-- src/prototypes/physics_00.cpp | 6 ++-- 8 files changed, 34 insertions(+), 34 deletions(-) rename src/game/{world => camera}/ITrackable.h (100%) rename src/game/{world/world_view.cpp => camera/tracking_view.cpp} (82%) rename src/game/{world/world_view.h => camera/tracking_view.h} (73%) diff --git a/CMakeLists.txt b/CMakeLists.txt index e47e5ce..591a1dc 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -45,12 +45,12 @@ set(SOURCES src/game/player/player.cpp src/game/player/player.hpp src/game/input/key_features.hpp - src/game/world/world_view.cpp - src/game/world/world_view.h + src/game/camera/tracking_view.cpp + src/game/camera/tracking_view.h src/utilities/smart_list.cpp src/utilities/smart_list.h src/utilities/vector_utils.hpp - src/game/world/ITrackable.h + src/game/camera/ITrackable.h src/game/input/input_identity.h src/utilities/magic_enum.hpp src/game/player/player_spawner.cpp diff --git a/src/coordinates/translated_coordinates.cpp b/src/coordinates/translated_coordinates.cpp index 53039f3..60197f1 100644 --- a/src/coordinates/translated_coordinates.cpp +++ b/src/coordinates/translated_coordinates.cpp @@ -9,7 +9,7 @@ IsometricCoordinates TranslatedCoordinates::isometric() const { } GridCoordinates TranslatedCoordinates::grid() const { - // Grid coords are just world coords without height, and scaled differently + // Grid coords are just camera coords without height, and scaled differently return {worldCoordinates.x * worldToGridFactor, worldCoordinates.y * worldToGridFactor}; } diff --git a/src/game/world/ITrackable.h b/src/game/camera/ITrackable.h similarity index 100% rename from src/game/world/ITrackable.h rename to src/game/camera/ITrackable.h diff --git a/src/game/world/world_view.cpp b/src/game/camera/tracking_view.cpp similarity index 82% rename from src/game/world/world_view.cpp rename to src/game/camera/tracking_view.cpp index e54cb08..dd1a0b7 100644 --- a/src/game/world/world_view.cpp +++ b/src/game/camera/tracking_view.cpp @@ -1,13 +1,13 @@ -#include "world_view.h" +#include "tracking_view.h" #include "../../utilities/vector_utils.hpp" -WorldView::~WorldView() +TrackingView::~TrackingView() { delete view; delete marker; } -void WorldView::lateUpdate(Game *game) +void TrackingView::lateUpdate(Game *game) { // Initialize if necessary if (view == nullptr) @@ -31,13 +31,13 @@ void WorldView::lateUpdate(Game *game) } } -void WorldView::initializeView(Game *game) +void TrackingView::initializeView(Game *game) { auto size = game->window->getView().getSize(); view = new sf::View({0, 0}, size); } -void WorldView::setSize(sf::Vector2u windowSize) +void TrackingView::setSize(sf::Vector2u windowSize) { // TODO: Maybe listen to resize events instead of checking every frame? // Is different? @@ -52,24 +52,24 @@ void WorldView::setSize(sf::Vector2u windowSize) hasViewChanged = true; } -WorldView::WorldView(ITrackable *trackable, sf::Vector2f freeMoveArea, sf::Vector2f dynamicFollowArea) +TrackingView::TrackingView(ITrackable *trackable, sf::Vector2f freeMoveArea, sf::Vector2f dynamicFollowArea) : target(trackable), freeMoveArea(freeMoveArea), dynamicFollowArea(dynamicFollowArea), view(nullptr), hasViewChanged(false) { marker = new CircleObject(2, sf::Color::Yellow); } -sf::Vector2f WorldView::getSize() const +sf::Vector2f TrackingView::getSize() const { return view->getSize(); } -sf::Vector2f WorldView::getCenter() const +sf::Vector2f TrackingView::getCenter() const { return view->getCenter(); } -void WorldView::followTarget() +void TrackingView::followTarget() { // TODO auto closestPositionInDynamic = getClosestPositionInArea(dynamicFollowArea); @@ -94,7 +94,7 @@ void WorldView::followTarget() // } } -bool WorldView::isTargetInArea(sf::Vector2f areaSize) +bool TrackingView::isTargetInArea(sf::Vector2f areaSize) { // Assuming target is not null @@ -119,7 +119,7 @@ bool WorldView::isTargetInArea(sf::Vector2f areaSize) return true; } -sf::Vector2f WorldView::getClosestPositionInArea(sf::Vector2f areaSize) const +sf::Vector2f TrackingView::getClosestPositionInArea(sf::Vector2f areaSize) const { // Reduce area to only consider target position, not size auto positionOnlyAreaSize = areaSize - target->getTrackableSize(); @@ -148,32 +148,32 @@ sf::Vector2f WorldView::getClosestPositionInArea(sf::Vector2f areaSize) const return rubber * length; } -sf::Vector2f WorldView::getRubber() const +sf::Vector2f TrackingView::getRubber() const { return normalize(target->getTrackablePosition() - getCenter()); } -void WorldView::performHardFollow() +void TrackingView::performHardFollow() { auto closestPositionInDynamic = getClosestPositionInArea(dynamicFollowArea); auto delta = getCenter() - closestPositionInDynamic; moveCenter(-delta); } -void WorldView::moveCenter(sf::Vector2 delta) +void TrackingView::moveCenter(sf::Vector2 delta) { view->move(delta); hasViewChanged = true; } -void WorldView::performDynamicFollow() +void TrackingView::performDynamicFollow() { auto closestPositionInDynamic = getClosestPositionInArea(freeMoveArea); auto delta = getCenter() - closestPositionInDynamic; moveCenter(delta * VIEW_RUBBER_FOLLOW_SPEED * FRAME_TIME.asSeconds()); } -void WorldView::draw(sf::RenderWindow *window) const +void TrackingView::draw(sf::RenderWindow *window) const { marker->draw(window); } diff --git a/src/game/world/world_view.h b/src/game/camera/tracking_view.h similarity index 73% rename from src/game/world/world_view.h rename to src/game/camera/tracking_view.h index 3c31886..c62edbb 100644 --- a/src/game/world/world_view.h +++ b/src/game/camera/tracking_view.h @@ -1,5 +1,5 @@ -#ifndef HOLESOME_WORLD_VIEW_H -#define HOLESOME_WORLD_VIEW_H +#ifndef HOLESOME_TRACKING_VIEW_H +#define HOLESOME_TRACKING_VIEW_H #include "../game_object.h" @@ -7,14 +7,14 @@ #include "ITrackable.h" #include "../../primitives/circle_object.h" -class WorldView : public GameObject +class TrackingView : public GameObject { public: - explicit WorldView(ITrackable *trackable = nullptr, - sf::Vector2f freeMoveArea = {200, 200}, - sf::Vector2f dynamicFollowArea = {500, 500}); + explicit TrackingView(ITrackable *trackable = nullptr, + sf::Vector2f freeMoveArea = {200, 200}, + sf::Vector2f dynamicFollowArea = {500, 500}); - ~WorldView(); + ~TrackingView(); void draw(sf::RenderWindow *window) const override; @@ -54,4 +54,4 @@ private: }; -#endif //HOLESOME_WORLD_VIEW_H +#endif //HOLESOME_TRACKING_VIEW_H diff --git a/src/game/player/player.hpp b/src/game/player/player.hpp index 329699d..b07384e 100644 --- a/src/game/player/player.hpp +++ b/src/game/player/player.hpp @@ -2,7 +2,7 @@ #define HOLESOME_PLAYER_HPP #include "../game_object.h" -#include "../world/ITrackable.h" +#include "../camera/ITrackable.h" #include "../../primitives/circle_object.h" class Player : public GameObject, public ITrackable diff --git a/src/main.cpp b/src/main.cpp index f51ee24..d093e7a 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -2,7 +2,7 @@ #include "logging/easylogging++.h" #include "game/game_factory.hpp" #include "debug/grid_debug_layer.h" -#include "game/world/world_view.h" +#include "game/camera/tracking_view.h" #include "game/player/player_spawner.hpp" INITIALIZE_EASYLOGGINGPP @@ -14,7 +14,7 @@ int main(int argc, char *argv[]) auto game = GameFactory::createWindowed("Holesome"); game->addGameObject(new GridDebugLayer(0, 50, 0, 50)); - game->addGameObject(new WorldView()); + game->addGameObject(new TrackingView()); game->addGameObject(new PlayerSpawner()); game->run(); diff --git a/src/prototypes/physics_00.cpp b/src/prototypes/physics_00.cpp index ed8850b..61111b8 100644 --- a/src/prototypes/physics_00.cpp +++ b/src/prototypes/physics_00.cpp @@ -9,14 +9,14 @@ int main(int argc, char** argv) { // First you need to create the PhysicsCommon object. // This is a factory module that you can use to create physics - // world and other objects. It is also responsible for + // camera and other objects. It is also responsible for // logging and memory management PhysicsCommon physicsCommon; - // Create a physics world + // Create a physics camera PhysicsWorld* world = physicsCommon.createPhysicsWorld(); - // Create a rigid body in the world + // Create a rigid body in the camera Vector3 position(0, 20, 0); Quaternion orientation = Quaternion::identity(); Transform transform(position, orientation);