From 03e58efbbf2386c3a412a9ffd27753b697ac9865 Mon Sep 17 00:00:00 2001 From: "C. J. Howard" Date: Sat, 13 Apr 2019 23:08:47 +0800 Subject: [PATCH] Remove camera component and use the camera system directly --- src/entity/components/camera-component.cpp | 29 ----------------- src/entity/components/camera-component.hpp | 38 ---------------------- src/entity/components/component-type.hpp | 1 - src/entity/systems/camera-system.cpp | 28 ++++++++-------- src/entity/systems/camera-system.hpp | 17 ++++------ src/game.cpp | 2 ++ 6 files changed, 23 insertions(+), 92 deletions(-) delete mode 100644 src/entity/components/camera-component.cpp delete mode 100644 src/entity/components/camera-component.hpp diff --git a/src/entity/components/camera-component.cpp b/src/entity/components/camera-component.cpp deleted file mode 100644 index 2f4f81f..0000000 --- a/src/entity/components/camera-component.cpp +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright (C) 2017-2019 Christopher J. Howard - * - * This file is part of Antkeeper Source Code. - * - * Antkeeper Source Code is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Antkeeper Source Code is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Antkeeper Source Code. If not, see . - */ - -#include "camera-component.hpp" - -ComponentBase* CameraComponent::clone() const -{ - CameraComponent* component = new CameraComponent(); - component->camera = camera; - - return component; -} - diff --git a/src/entity/components/camera-component.hpp b/src/entity/components/camera-component.hpp deleted file mode 100644 index de2f60e..0000000 --- a/src/entity/components/camera-component.hpp +++ /dev/null @@ -1,38 +0,0 @@ -/* - * Copyright (C) 2017-2019 Christopher J. Howard - * - * This file is part of Antkeeper Source Code. - * - * Antkeeper Source Code is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * Antkeeper Source Code is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with Antkeeper Source Code. If not, see . - */ - -#ifndef CAMERA_COMPONENT_HPP -#define CAMERA_COMPONENT_HPP - -#include "../component.hpp" -#include "component-type.hpp" - -#include -using namespace Emergent; - -class CameraComponent: public Component -{ -public: - virtual ComponentBase* clone() const; - - Camera camera; -}; - -#endif // CAMERA_COMPONENT_HPP - diff --git a/src/entity/components/component-type.hpp b/src/entity/components/component-type.hpp index 55bec30..d6e6542 100644 --- a/src/entity/components/component-type.hpp +++ b/src/entity/components/component-type.hpp @@ -25,7 +25,6 @@ enum class ComponentType ANIMATION, ANT_HILL, BEHAVIOR, - CAMERA, COLLISION, LEGGED_LOCOMOTION, MODEL, diff --git a/src/entity/systems/camera-system.cpp b/src/entity/systems/camera-system.cpp index adae601..3f1c2f6 100644 --- a/src/entity/systems/camera-system.cpp +++ b/src/entity/systems/camera-system.cpp @@ -21,30 +21,30 @@ CameraSystem::CameraSystem(ComponentManager* componentManager): System(componentManager), - cameraGroup(componentManager) -{ - cameraGroup.addGroupObserver(this); -} + camera(nullptr), + rig(&orbitCam) +{} CameraSystem::~CameraSystem() {} void CameraSystem::update(float t, float dt) { - auto members = cameraGroup.getMembers(); - for (const CameraGroup::Member* member: *members) + if (camera != nullptr) { - CameraComponent* camera = std::get<0>(member->components); - TransformComponent* transform = std::get<1>(member->components); + cameraRig->update(dt); } } -void CameraSystem::memberRegistered(const CameraGroup::Member* member) -{} - -void CameraSystem::memberUnregistered(const CameraGroup::Member* member) -{} +void CameraSystem::setCamera(Camera* camera) +{ + this->camera = camera; + orbitCam.attachCamera(&camera); + freeCam.attachCamera(&camera); +} void CameraSystem::handleEvent(const MouseMovedEvent& event) -{} +{ + +} diff --git a/src/entity/systems/camera-system.hpp b/src/entity/systems/camera-system.hpp index 8f0388d..c7e65b0 100644 --- a/src/entity/systems/camera-system.hpp +++ b/src/entity/systems/camera-system.hpp @@ -20,20 +20,14 @@ #ifndef CAMERA_SYSTEM_HPP #define CAMERA_SYSTEM_HPP -#include "../entity-group.hpp" -#include "../components/camera-component.hpp" -#include "../components/model-component.hpp" -#include "../components/transform-component.hpp" #include "../system.hpp" +#include "game/camera-rig.hpp" #include using namespace Emergent; -typedef EntityGroup CameraGroup; - class CameraSystem: public System, - public CameraGroup::Observer, public EventHandler { public: @@ -42,11 +36,14 @@ public: virtual void update(float t, float dt); + void setCamera(Camera* camera); + private: - virtual void memberRegistered(const CameraGroup::Member* member); - virtual void memberUnregistered(const CameraGroup::Member* member); virtual void handleEvent(const MouseMovedEvent& event); - CameraGroup cameraGroup; + Camera* camera; + CameraRig* rig; + OrbitCam orbitCam; + FreeCam freeCam; }; #endif // CAMERA_SYSTEM_HPP diff --git a/src/game.cpp b/src/game.cpp index b5f1524..55c56ea 100644 --- a/src/game.cpp +++ b/src/game.cpp @@ -509,6 +509,8 @@ void Game::setup() soundSystem = new SoundSystem(componentManager); collisionSystem = new CollisionSystem(componentManager); cameraSystem = new CameraSystem(componentManager); + cameraSystem->setCamera(&camera); + eventDispatcher.subscribe(cameraSystem); renderSystem = new RenderSystem(componentManager, worldScene); toolSystem = new ToolSystem(componentManager); toolSystem->setPickingCamera(&camera);