diff --git a/source/client/scene/ClientScene.cpp b/source/client/scene/ClientScene.cpp index 511a60aa..249dff61 100644 --- a/source/client/scene/ClientScene.cpp +++ b/source/client/scene/ClientScene.cpp @@ -31,19 +31,24 @@ ClientScene::ClientScene() { m_controllers.emplace_back(new AnimationController); - m_controllers.emplace_back(new RenderingController); + m_clientControllers.emplace_back(new RenderingController); +} + +void ClientScene::update() { + Scene::update(); + + for (auto &controller : m_clientControllers) + controller->update(m_registry); } void ClientScene::draw(RenderTarget &target, RenderStates states) const { -#ifdef OM_NOT_IMPLEMENTED_SCENE_DRAW if (!m_camera) return; // Subtract the camera position - see comment in ClientWorld::draw() gk::Vector3d cameraPosition = m_camera->getDPosition(); states.transform.translate((float)-cameraPosition.x, (float)-cameraPosition.y, (float)-cameraPosition.z); - for (auto &controller : m_controllers) + for (auto &controller : m_clientControllers) controller->draw(m_registry, target, states); -#endif // OM_NOT_IMPLEMENTED_SCENE_DRAW } diff --git a/source/client/scene/ClientScene.hpp b/source/client/scene/ClientScene.hpp index f4c61848..8a63edc9 100644 --- a/source/client/scene/ClientScene.hpp +++ b/source/client/scene/ClientScene.hpp @@ -30,8 +30,7 @@ #include #include -#include - +#include "AbstractClientController.hpp" #include "Drawable.hpp" #include "Scene.hpp" @@ -42,12 +41,16 @@ class ClientScene : public Scene, public Drawable { public: ClientScene(); + void update() override; + void setCamera(Camera &camera) { m_camera = &camera; } private: void draw(RenderTarget &target, RenderStates states) const override; Camera *m_camera = nullptr; + + std::deque> m_clientControllers; }; #endif // CLIENTSCENE_HPP_ diff --git a/source/client/scene/controller/AbstractClientController.hpp b/source/client/scene/controller/AbstractClientController.hpp new file mode 100644 index 00000000..97256cbc --- /dev/null +++ b/source/client/scene/controller/AbstractClientController.hpp @@ -0,0 +1,42 @@ +/* + * ===================================================================================== + * + * OpenMiner + * + * Copyright (C) 2018-2020 Unarelith, Quentin Bazin + * Copyright (C) 2019-2020 the OpenMiner contributors (see CONTRIBUTORS.md) + * + * This file is part of OpenMiner. + * + * OpenMiner is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * OpenMiner 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 + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with OpenMiner; if not, write to the Free Software Foundation, Inc., + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA + * + * ===================================================================================== + */ +#ifndef ABSTRACTCLIENTCONTROLLER_HPP_ +#define ABSTRACTCLIENTCONTROLLER_HPP_ + +#include "AbstractController.hpp" +#include "RenderStates.hpp" +#include "RenderTarget.hpp" + +class AbstractClientController : public AbstractController { + public: + virtual ~AbstractClientController() = default; + + virtual void draw(entt::registry &, RenderTarget &, RenderStates) {} +}; + + +#endif // ABSTRACTCLIENTCONTROLLER_HPP_ diff --git a/source/client/scene/controller/RenderingController.cpp b/source/client/scene/controller/RenderingController.cpp index d3fc4a6f..e1b449b1 100644 --- a/source/client/scene/controller/RenderingController.cpp +++ b/source/client/scene/controller/RenderingController.cpp @@ -49,7 +49,6 @@ void RenderingController::update(entt::registry ®istry) { }); } -#ifdef OM_NOT_IMPLEMENTED_SCENE_DRAW void RenderingController::draw(entt::registry ®istry, RenderTarget &target, RenderStates states) { registry.view().each([&](auto, auto &drawable, auto &position, auto &rotation) { gk::Transformable transformable; @@ -61,4 +60,3 @@ void RenderingController::draw(entt::registry ®istry, RenderTarget &target, R drawable.draw(target, drawStates); }); } -#endif // OM_NOT_IMPLEMENTED_SCENE_DRAW diff --git a/source/client/scene/controller/RenderingController.hpp b/source/client/scene/controller/RenderingController.hpp index 8e6f3ee3..1789b616 100644 --- a/source/client/scene/controller/RenderingController.hpp +++ b/source/client/scene/controller/RenderingController.hpp @@ -27,15 +27,13 @@ #ifndef RENDERINGCONTROLLER_HPP_ #define RENDERINGCONTROLLER_HPP_ -#include "AbstractController.hpp" +#include "AbstractClientController.hpp" -class RenderingController : public AbstractController { +class RenderingController : public AbstractClientController { public: void update(entt::registry ®istry) override; -#ifdef OM_NOT_IMPLEMENTED_SCENE_DRAW void draw(entt::registry ®istry, RenderTarget &target, RenderStates states) override; -#endif // OM_NOT_IMPLEMENTED_SCENE_DRAW }; #endif // RENDERINGCONTROLLER_HPP_ diff --git a/source/common/scene/controller/AbstractController.hpp b/source/common/scene/controller/AbstractController.hpp index 2ae5869c..3983891d 100644 --- a/source/common/scene/controller/AbstractController.hpp +++ b/source/common/scene/controller/AbstractController.hpp @@ -29,19 +29,11 @@ #include -#ifdef OM_NOT_IMPLEMENTED_SCENE_DRAW -#include "RenderStates.hpp" -#include "RenderTarget.hpp" -#endif // OM_NOT_IMPLEMENTED_SCENE_DRAW - class AbstractController { public: virtual ~AbstractController() = default; virtual void update(entt::registry &) {} -#ifdef OM_NOT_IMPLEMENTED_SCENE_DRAW - virtual void draw(entt::registry &, RenderTarget &, RenderStates) {} -#endif // OM_NOT_IMPLEMENTED_SCENE_DRAW }; #endif // ABSTRACTCONTROLLER_HPP_