Skip to content

Commit

Permalink
#5338: Move the "focus all cameras" and "get active cam" functionalit…
Browse files Browse the repository at this point in the history
…y to the CameraManager
  • Loading branch information
codereader committed Sep 27, 2020
1 parent 9040df9 commit bb3002e
Show file tree
Hide file tree
Showing 19 changed files with 52 additions and 66 deletions.
14 changes: 0 additions & 14 deletions include/icamera.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,27 +7,13 @@
namespace camera
{

enum
{
CAMERA_PITCH = 0, // up / down
CAMERA_YAW = 1, // left / right
CAMERA_ROLL = 2, // fall over
};

/**
* The "global" interface of DarkRadiant's camera module.
*/
class ICameraManager :
public RegisterableModule
{
public:
/**
* greebo: Sets the camera origin to the given <point> using the given <angles>.
*/
virtual void focusCamera(const Vector3& point, const Vector3& angles) = 0;

// A reference to the currently active view. Will throw a std::runtime_error if no camera is present
virtual ICameraView& getActiveView() = 0;
};
typedef std::shared_ptr<ICameraManager> ICameraPtr;

Expand Down
16 changes: 13 additions & 3 deletions include/icameraview.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,16 @@ template<typename Element>class BasicVector3;
typedef BasicVector3<double> Vector3;
class Matrix4;

namespace camera
{

enum
{
CAMERA_PITCH = 0, // up / down
CAMERA_YAW = 1, // left / right
CAMERA_ROLL = 2, // fall over
};

// Abstract class used when handling mouse events
// see also: class IOrthoView in iorthoview.h
class ICameraView :
Expand Down Expand Up @@ -58,9 +68,6 @@ class IFreeMoveView :
virtual bool freeMoveEnabled() const = 0;
};

namespace camera
{

class ICameraViewManager :
public RegisterableModule
{
Expand All @@ -80,6 +87,9 @@ class ICameraViewManager :
// Sets the position and angles of all active cameras to the given values
virtual void focusAllCameras(const Vector3& position, const Vector3& angles) = 0;

// A reference to the currently active view. Will throw a std::runtime_error if no camera is present
virtual ICameraView& getActiveView() = 0;

// Signal emitted when any camera position or angles changed
virtual sigc::signal<void>& signal_cameraChanged() = 0;
};
Expand Down
2 changes: 1 addition & 1 deletion radiant/camera/CamWnd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -895,7 +895,7 @@ void CamWnd::update()
queueDraw();
}

ICameraView& CamWnd::getCamera()
camera::ICameraView& CamWnd::getCamera()
{
return *_camera;
}
Expand Down
6 changes: 3 additions & 3 deletions radiant/camera/CamWnd.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ namespace ui

class CamWnd :
public wxEvtHandler,
public ICameraView,
public IFreeMoveView,
public camera::ICameraView,
public camera::IFreeMoveView,
public scene::Graph::Observer,
public util::Noncopyable,
public sigc::trackable,
Expand Down Expand Up @@ -119,7 +119,7 @@ class CamWnd :
static void captureStates();
static void releaseStates();

ICameraView& getCamera();
camera::ICameraView& getCamera();

const Vector3& getCameraOrigin() const override;
void setCameraOrigin(const Vector3& origin) override;
Expand Down
17 changes: 0 additions & 17 deletions radiant/camera/GlobalCameraWndManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,23 +266,6 @@ void GlobalCameraWndManager::farClipPlaneOut(const cmd::ArgumentList& args)
doWithActiveCamWnd([](CamWnd& camWnd) { camWnd.farClipPlaneOut(); });
}

void GlobalCameraWndManager::focusCamera(const Vector3& point, const Vector3& angles)
{
doWithActiveCamWnd([&](CamWnd& camWnd)
{
camWnd.setOriginAndAngles(point, angles);
});
}

ICameraView& GlobalCameraWndManager::getActiveView()
{
auto camWnd = getActiveCamWnd();

if (!camWnd) throw std::runtime_error("No active camera view present");

return camWnd->getCamera();
}

// --------------- Keyboard movement methods ------------------------------------------

void GlobalCameraWndManager::moveCameraCmd(const cmd::ArgumentList& args)
Expand Down
5 changes: 0 additions & 5 deletions radiant/camera/GlobalCameraWndManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,11 +63,6 @@ class GlobalCameraWndManager :
// Resets the camera angles of the currently active Camera
void resetCameraAngles(const cmd::ArgumentList& args);

/** greebo: Sets the camera to the given point/angle.
*/
void focusCamera(const Vector3& point, const Vector3& angles) override;
ICameraView& getActiveView() override;

// Toggles between lighting and solid rendering mode (passes the call to the CameraSettings class)
void toggleLightingMode(const cmd::ArgumentList& args);

Expand Down
8 changes: 4 additions & 4 deletions radiant/camera/tools/CameraMouseToolEvent.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,20 @@ class CameraMouseToolEvent :
public MouseToolEvent
{
private:
ICameraView& _view;
camera::ICameraView& _view;

public:
CameraMouseToolEvent(ICameraView& view, const Vector2& devicePos) :
CameraMouseToolEvent(camera::ICameraView& view, const Vector2& devicePos) :
MouseToolEvent(view, devicePos),
_view(view)
{}

CameraMouseToolEvent(ICameraView& view, const Vector2& devicePos, const Vector2& delta) :
CameraMouseToolEvent(camera::ICameraView& view, const Vector2& devicePos, const Vector2& delta) :
MouseToolEvent(view, devicePos, delta),
_view(view)
{}

ICameraView& getView()
camera::ICameraView& getView()
{
return _view;
}
Expand Down
6 changes: 3 additions & 3 deletions radiant/camera/tools/FreeMoveTool.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class FreeMoveTool :
{
try
{
auto& freeMoveView = dynamic_cast<IFreeMoveView&>(ev.getInteractiveView());
auto& freeMoveView = dynamic_cast<camera::IFreeMoveView&>(ev.getInteractiveView());

if (getCameraSettings()->toggleFreelook())
{
Expand Down Expand Up @@ -75,7 +75,7 @@ class FreeMoveTool :
{
try
{
auto& freeMoveView = dynamic_cast<IFreeMoveView&>(ev.getInteractiveView());
auto& freeMoveView = dynamic_cast<camera::IFreeMoveView&>(ev.getInteractiveView());

// MouseUp events are ignored when in toggle mode
// In non-toggle mode, we just reset the freelook status to disabled
Expand All @@ -99,7 +99,7 @@ class FreeMoveTool :
{
try
{
auto& freeMoveView = dynamic_cast<IFreeMoveView&>(view);
auto& freeMoveView = dynamic_cast<camera::IFreeMoveView&>(view);

if (freeMoveView.freeMoveEnabled())
{
Expand Down
2 changes: 1 addition & 1 deletion radiant/camera/tools/JumpToObjectTool.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class JumpToObjectTool :

// Focus the view at the center of the found AABB
// Set the camera and the views to the given point
GlobalCameraWndManager().focusCamera(found.origin, camEvent.getView().getCameraAngles());
GlobalCameraManager().focusAllCameras(found.origin, camEvent.getView().getCameraAngles());
GlobalXYWndManager().setOrigin(found.origin);
}

Expand Down
4 changes: 2 additions & 2 deletions radiant/camera/tools/PanViewTool.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class PanViewTool :
{
try
{
auto& freeMoveView = dynamic_cast<IFreeMoveView&>(ev.getInteractiveView());
auto& freeMoveView = dynamic_cast<camera::IFreeMoveView&>(ev.getInteractiveView());

// Don't operate when the camera is already in free look mode
if (freeMoveView.freeMoveEnabled())
Expand All @@ -57,7 +57,7 @@ class PanViewTool :
{
// We use capture mode, so xy event will contain the delta only
CameraMouseToolEvent& camEvent = dynamic_cast<CameraMouseToolEvent&>(ev);
ICameraView& view = camEvent.getView();
auto& view = camEvent.getView();

const float strafespeed = GlobalCamera().getCameraStrafeSpeed();

Expand Down
4 changes: 2 additions & 2 deletions radiant/ui/entitylist/EntityList.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "registry/Widgets.h"
#include "entitylib.h"
#include "iselectable.h"
#include "icamera.h"
#include "icameraview.h"
#include "i18n.h"

#include "wxutil/TreeView.h"
Expand Down Expand Up @@ -343,7 +343,7 @@ void EntityList::onSelection(wxDataViewEvent& ev)
Vector3 angles(0, 0, 0);
angles[camera::CAMERA_PITCH] = -30;

GlobalCameraWndManager().focusCamera(origin, angles);
GlobalCameraManager().focusAllCameras(origin, angles);
}

// Now reactivate the callbacks
Expand Down
10 changes: 10 additions & 0 deletions radiantcore/camera/CameraManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,16 @@ void CameraManager::focusAllCameras(const Vector3& position, const Vector3& angl
}
}

camera::ICameraView& CameraManager::getActiveView()
{
if (_cameras.empty())
{
throw std::runtime_error("No active camera view present");
}

return *_cameras.front();
}

sigc::signal<void>& CameraManager::signal_cameraChanged()
{
return _sigCameraChanged;
Expand Down
2 changes: 2 additions & 0 deletions radiantcore/camera/CameraManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ class CameraManager :

void focusAllCameras(const Vector3& position, const Vector3& angles) override;

ICameraView& getActiveView() override;

sigc::signal<void>& signal_cameraChanged() override;

void onCameraViewChanged();
Expand Down
2 changes: 1 addition & 1 deletion radiantcore/map/Map.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ sigc::signal<void>& Map::signal_modifiedChanged()
void Map::focusViews(const Vector3& point, const Vector3& angles)
{
// Set the camera and the views to the given point
GlobalCameraWndManager().focusCamera(point, angles);
GlobalCameraManager().focusAllCameras(point, angles);
GlobalXYWndManager().setOrigin(point);
}

Expand Down
4 changes: 2 additions & 2 deletions radiantcore/map/MapPosition.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "MapPosition.h"

#include "ientity.h"
#include "icamera.h"
#include "icameraview.h"
#include "itextstream.h"
#include "string/string.h"
#include "map/Map.h"
Expand Down Expand Up @@ -115,7 +115,7 @@ void MapPosition::store(const cmd::ArgumentList& args)

try
{
auto& cameraView = GlobalCameraWndManager().getActiveView();
auto& cameraView = GlobalCameraManager().getActiveView();

_position = cameraView.getCameraOrigin();
_angle = cameraView.getCameraAngles();
Expand Down
4 changes: 2 additions & 2 deletions radiantcore/map/MapPositionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

#include "maplib.h"
#include "ientity.h"
#include "icamera.h"
#include "icameraview.h"
#include "gamelib.h"
#include "ieventmanager.h"
#include "iregistry.h"
Expand Down Expand Up @@ -183,7 +183,7 @@ void MapPositionManager::saveLastCameraPosition(const scene::IMapRootNodePtr& ro

try
{
auto& camView = GlobalCameraWndManager().getActiveView();
auto& camView = GlobalCameraManager().getActiveView();

root->setProperty(LAST_CAM_POSITION_KEY, string::to_string(camView.getCameraOrigin()));
root->setProperty(LAST_CAM_ANGLE_KEY, string::to_string(camView.getCameraAngles()));
Expand Down
4 changes: 2 additions & 2 deletions radiantcore/map/PointFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include "igl.h"
#include "iscenegraph.h"
#include "itextstream.h"
#include "icamera.h"
#include "icameraview.h"
#include "iorthoview.h"
#include <fstream>
#include <iostream>
Expand Down Expand Up @@ -129,7 +129,7 @@ void PointFile::advance(bool forward)

try
{
auto& cam = GlobalCameraWndManager().getActiveView();
auto& cam = GlobalCameraManager().getActiveView();

cam.setCameraOrigin(_points[_curPos].vertex);

Expand Down
4 changes: 2 additions & 2 deletions radiantcore/map/RegionManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "i18n.h"
#include "brush/TexDef.h"
#include "ibrush.h"
#include "icamera.h"
#include "icameraview.h"
#include "iorthoview.h"
#include "ientity.h"
#include "ieclass.h"
Expand Down Expand Up @@ -171,7 +171,7 @@ void RegionManager::addRegionBrushes()

try
{
auto& camView = GlobalCameraWndManager().getActiveView();
auto& camView = GlobalCameraManager().getActiveView();

// Obtain the camera origin = player start point
Vector3 camOrigin = camView.getCameraOrigin();
Expand Down
4 changes: 2 additions & 2 deletions radiantcore/selection/clipboard/Clipboard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#include "i18n.h"
#include "iselection.h"
#include "igrid.h"
#include "icamera.h"
#include "icameraview.h"
#include "imapformat.h"
#include "iclipboard.h"

Expand Down Expand Up @@ -73,7 +73,7 @@ void pasteToCamera(const cmd::ArgumentList& args)
{
try
{
auto& camWnd = GlobalCameraWndManager().getActiveView();
auto& camWnd = GlobalCameraManager().getActiveView();

UndoableCommand undo("pasteToCamera");
pasteToMap();
Expand Down

0 comments on commit bb3002e

Please sign in to comment.