Browse Source

Remove camera component and use the camera system directly

master
C. J. Howard 5 years ago
parent
commit
03e58efbbf
Signed by: cjhoward GPG Key ID: 03E1FABA9C3EC195
6 changed files with 23 additions and 92 deletions
  1. +0
    -29
      src/entity/components/camera-component.cpp
  2. +0
    -38
      src/entity/components/camera-component.hpp
  3. +0
    -1
      src/entity/components/component-type.hpp
  4. +14
    -14
      src/entity/systems/camera-system.cpp
  5. +7
    -10
      src/entity/systems/camera-system.hpp
  6. +2
    -0
      src/game.cpp

+ 0
- 29
src/entity/components/camera-component.cpp View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#include "camera-component.hpp"
ComponentBase* CameraComponent::clone() const
{
CameraComponent* component = new CameraComponent();
component->camera = camera;
return component;
}

+ 0
- 38
src/entity/components/camera-component.hpp View File

@ -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 <http://www.gnu.org/licenses/>.
*/
#ifndef CAMERA_COMPONENT_HPP
#define CAMERA_COMPONENT_HPP
#include "../component.hpp"
#include "component-type.hpp"
#include <emergent/emergent.hpp>
using namespace Emergent;
class CameraComponent: public Component<ComponentType::CAMERA>
{
public:
virtual ComponentBase* clone() const;
Camera camera;
};
#endif // CAMERA_COMPONENT_HPP

+ 0
- 1
src/entity/components/component-type.hpp View File

@ -25,7 +25,6 @@ enum class ComponentType
ANIMATION,
ANT_HILL,
BEHAVIOR,
CAMERA,
COLLISION,
LEGGED_LOCOMOTION,
MODEL,

+ 14
- 14
src/entity/systems/camera-system.cpp View File

@ -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)
{}
{
}

+ 7
- 10
src/entity/systems/camera-system.hpp View File

@ -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 <emergent/emergent.hpp>
using namespace Emergent;
typedef EntityGroup<CameraComponent, TransformComponent> CameraGroup;
class CameraSystem:
public System,
public CameraGroup::Observer,
public EventHandler<MouseMovedEvent>
{
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

+ 2
- 0
src/game.cpp View File

@ -509,6 +509,8 @@ void Game::setup()
soundSystem = new SoundSystem(componentManager);
collisionSystem = new CollisionSystem(componentManager);
cameraSystem = new CameraSystem(componentManager);
cameraSystem->setCamera(&camera);
eventDispatcher.subscribe<MouseMovedEvent>(cameraSystem);
renderSystem = new RenderSystem(componentManager, worldScene);
toolSystem = new ToolSystem(componentManager);
toolSystem->setPickingCamera(&camera);

Loading…
Cancel
Save