Skip to content

Commit

Permalink
[AbstractClientController] Added to fix ClientScene.
Browse files Browse the repository at this point in the history
  • Loading branch information
Unarelith committed Oct 29, 2023
1 parent 534c37a commit 60c0fa5
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 20 deletions.
13 changes: 9 additions & 4 deletions source/client/scene/ClientScene.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

7 changes: 5 additions & 2 deletions source/client/scene/ClientScene.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,7 @@
#include <deque>
#include <memory>

#include <entt/entt.hpp>

#include "AbstractClientController.hpp"
#include "Drawable.hpp"
#include "Scene.hpp"

Expand All @@ -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<std::unique_ptr<AbstractClientController>> m_clientControllers;
};

#endif // CLIENTSCENE_HPP_
42 changes: 42 additions & 0 deletions source/client/scene/controller/AbstractClientController.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
/*
* =====================================================================================
*
* OpenMiner
*
* Copyright (C) 2018-2020 Unarelith, Quentin Bazin <[email protected]>
* 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_
2 changes: 0 additions & 2 deletions source/client/scene/controller/RenderingController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ void RenderingController::update(entt::registry &registry) {
});
}

#ifdef OM_NOT_IMPLEMENTED_SCENE_DRAW
void RenderingController::draw(entt::registry &registry, RenderTarget &target, RenderStates states) {
registry.view<DrawableComponent, PositionComponent, RotationComponent>().each([&](auto, auto &drawable, auto &position, auto &rotation) {
gk::Transformable transformable;
Expand All @@ -61,4 +60,3 @@ void RenderingController::draw(entt::registry &registry, RenderTarget &target, R
drawable.draw(target, drawStates);
});
}
#endif // OM_NOT_IMPLEMENTED_SCENE_DRAW
6 changes: 2 additions & 4 deletions source/client/scene/controller/RenderingController.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 &registry) override;

#ifdef OM_NOT_IMPLEMENTED_SCENE_DRAW
void draw(entt::registry &registry, RenderTarget &target, RenderStates states) override;
#endif // OM_NOT_IMPLEMENTED_SCENE_DRAW
};

#endif // RENDERINGCONTROLLER_HPP_
8 changes: 0 additions & 8 deletions source/common/scene/controller/AbstractController.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,19 +29,11 @@

#include <entt/entt.hpp>

#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_

0 comments on commit 60c0fa5

Please sign in to comment.