Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
#5338: Remove CameraObserver interface in favour of a signal exposed …
…by the CameraManager.
  • Loading branch information
codereader committed Sep 27, 2020
1 parent 71032a5 commit 0b2e4df
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 82 deletions.
3 changes: 3 additions & 0 deletions include/icameraview.h
Expand Up @@ -66,6 +66,9 @@ class ICameraViewManager :

virtual ICameraView::Ptr createCamera(render::IRenderView& view,
const std::function<void()>& queueDraw, const std::function<void()>& forceRedraw) = 0;

// Signal emitted when any camera position or angles changed
virtual sigc::signal<void>& signal_cameraChanged() = 0;
};

}
Expand Down
3 changes: 0 additions & 3 deletions radiant/camera/CamWnd.cpp
Expand Up @@ -431,7 +431,6 @@ void CamWnd::changeFloor(const bool up)
_camera->setCameraOrigin(Vector3(org[0], org[1], current + 48));

update();
GlobalCamera().movedNotify();
}

void CamWnd::setFreeMoveFlags(unsigned int mask)
Expand Down Expand Up @@ -521,7 +520,6 @@ void CamWnd::onFreeMoveTimer(wxTimerEvent& ev)
handleFreeMovement(time_seconds * 5.0f);

queueDraw();
GlobalCamera().movedNotify();
}

void CamWnd::enableFreeMove()
Expand Down Expand Up @@ -601,7 +599,6 @@ void CamWnd::onDeferredMotionDelta(int x, int y)
{
performFreeMove(-x, -y);
queueDraw();
GlobalCamera().movedNotify();
}

void CamWnd::Cam_Draw()
Expand Down
18 changes: 0 additions & 18 deletions radiant/camera/CameraObserver.h

This file was deleted.

33 changes: 0 additions & 33 deletions radiant/camera/GlobalCameraWndManager.cpp
Expand Up @@ -252,39 +252,6 @@ void GlobalCameraWndManager::changeFloorDown(const cmd::ArgumentList& args)
doWithActiveCamWnd([](CamWnd& camWnd) { camWnd.changeFloor(false); });
}

void GlobalCameraWndManager::addCameraObserver(CameraObserver* observer) {
if (observer != NULL) {
// Add the passed observer to the list
_cameraObservers.push_back(observer);
}
}

void GlobalCameraWndManager::removeCameraObserver(CameraObserver* observer)
{
// Cycle through the list of observers and call the moved method
for (CameraObserverList::iterator i = _cameraObservers.begin(); i != _cameraObservers.end(); i++)
{
CameraObserver* registered = *i;

if (registered == observer) {
_cameraObservers.erase(i++);
return; // Don't continue the loop, the iterator is obsolete
}
}
}

void GlobalCameraWndManager::movedNotify()
{
// Cycle through the list of observers and call the moved method
for (CameraObserver* observer : _cameraObservers)
{
if (observer != nullptr)
{
observer->cameraMoved();
}
}
}

void GlobalCameraWndManager::toggleLightingMode(const cmd::ArgumentList& args) {
getCameraSettings()->toggleLightingMode();
}
Expand Down
11 changes: 0 additions & 11 deletions radiant/camera/GlobalCameraWndManager.h
Expand Up @@ -8,7 +8,6 @@

#include "CamWnd.h"
#include "FloatingCamWnd.h"
#include "CameraObserver.h"

class wxWindow;

Expand All @@ -32,9 +31,6 @@ class GlobalCameraWndManager :
// The currently active camera window (-1 if no cam active)
int _activeCam;

// The connected callbacks (get invoked when movedNotify() is called)
CameraObserverList _cameraObservers;

unsigned int _toggleStrafeModifierFlags;
unsigned int _toggleStrafeForwardModifierFlags;

Expand Down Expand Up @@ -95,13 +91,6 @@ class GlobalCameraWndManager :
void update();
void forceDraw();

// Add a "CameraMoved" callback to the signal member
void addCameraObserver(CameraObserver* observer);
void removeCameraObserver(CameraObserver* observer);

// Notify the attached "CameraMoved" callbacks
void movedNotify();

// Movement commands (the calls are passed on to the Camera class)
void moveCameraCmd(const cmd::ArgumentList& args);
void moveLeftDiscrete(const cmd::ArgumentList& args);
Expand Down
15 changes: 8 additions & 7 deletions radiant/xyview/XYWnd.cpp
Expand Up @@ -36,6 +36,7 @@
#include "render/RenderableCollectionWalker.h"

#include <fmt/format.h>
#include <sigc++/functors/mem_fun.h>
#include <functional>

namespace ui
Expand Down Expand Up @@ -136,7 +137,8 @@ XYWnd::XYWnd(int id, wxWindow* parent) :
GlobalSceneGraph().addSceneObserver(this);

// greebo: Connect <self> as CameraObserver to the CamWindow. This way this class gets notified on camera change
GlobalCamera().addCameraObserver(this);
_sigCameraChanged = GlobalCameraManager().signal_cameraChanged().connect(
sigc::mem_fun(this, &XYWnd::onCameraMoved));
}

// Destructor
Expand All @@ -163,9 +165,7 @@ void XYWnd::destroyXYView()
// Remove <self> from the scene change callback list
GlobalSceneGraph().removeSceneObserver(this);

// greebo: Remove <self> as CameraObserver from the CamWindow.
GlobalCamera().removeCameraObserver(this);

_sigCameraChanged.disconnect();
_wxGLWidget = nullptr;
}

Expand Down Expand Up @@ -431,9 +431,10 @@ void XYWnd::setCursorType(CursorType type)
};
}

// Callback that gets invoked on camera move
void XYWnd::cameraMoved() {
if (GlobalXYWnd().camXYUpdate()) {
void XYWnd::onCameraMoved()
{
if (GlobalXYWnd().camXYUpdate())
{
queueDraw();
}
}
Expand Down
9 changes: 4 additions & 5 deletions radiant/xyview/XYWnd.h
Expand Up @@ -12,8 +12,8 @@

#include <wx/cursor.h>
#include <wx/stopwatch.h>
#include <sigc++/connection.h>

#include "camera/CameraObserver.h"
#include "render/View.h"
#include "imousetool.h"
#include "tools/XYMouseToolEvent.h"
Expand All @@ -25,7 +25,6 @@ namespace ui
class XYWnd :
public wxEvtHandler,
public IOrthoView,
public CameraObserver,
public scene::Graph::Observer,
protected wxutil::MouseToolHandler
{
Expand Down Expand Up @@ -85,6 +84,8 @@ class XYWnd :
int _width;
int _height;

sigc::connection _sigCameraChanged;

public:
// Constructor, this allocates the GL widget
XYWnd(int uniqueId, wxWindow* parent);
Expand Down Expand Up @@ -149,9 +150,6 @@ class XYWnd :
int getWidth() const override;
int getHeight() const override;

// greebo: CameraObserver implementation; gets called when the camera is moved
void cameraMoved() override;

// greebo: This gets called upon scene change
void onSceneGraphChange() override;

Expand All @@ -177,6 +175,7 @@ class XYWnd :
bool checkChaseMouse(unsigned int state);
void performChaseMouse();
void onIdle(wxIdleEvent& ev);
void onCameraMoved();

// The method responsible for mouseMove situations according to <event>
void handleGLMouseMotion(int x, int y, unsigned int state, bool isDelta);
Expand Down
7 changes: 6 additions & 1 deletion radiantcore/camera/CameraManager.cpp
Expand Up @@ -29,9 +29,14 @@ ICameraView::Ptr CameraManager::createCamera(render::IRenderView& view,
return std::make_shared<Camera>(view, queueDraw, forceRedraw);
}

sigc::signal<void>& CameraManager::signal_cameraChanged()
{
return _sigCameraChanged;
}

void CameraManager::onCameraViewChanged()
{
// TODO
_sigCameraChanged.emit();
}

CameraManager& CameraManager::GetInstanceInternal()
Expand Down
5 changes: 5 additions & 0 deletions radiantcore/camera/CameraManager.h
Expand Up @@ -9,6 +9,9 @@ namespace camera
class CameraManager :
public ICameraViewManager
{
private:
sigc::signal<void> _sigCameraChanged;

public:
// RegisterableModule
const std::string& getName() const override;
Expand All @@ -19,6 +22,8 @@ class CameraManager :
ICameraView::Ptr createCamera(render::IRenderView& view,
const std::function<void()>& queueDraw, const std::function<void()>& forceRedraw) override;

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

void onCameraViewChanged();

// Module-internal accessor
Expand Down
1 change: 0 additions & 1 deletion tools/msvc/DarkRadiant.vcxproj
Expand Up @@ -455,7 +455,6 @@
<ClInclude Include="..\..\radiant\ui\modelexport\ExportAsModelDialog.h" />
<ClInclude Include="..\..\radiant\ui\modelexport\ExportCollisionModelDialog.h" />
<ClInclude Include="..\..\radiant\ui\modelselector\MaterialsList.h" />
<ClInclude Include="..\..\radiant\camera\CameraObserver.h" />
<ClInclude Include="..\..\radiant\camera\CameraSettings.h" />
<ClInclude Include="..\..\radiant\camera\CamRenderer.h" />
<ClInclude Include="..\..\radiant\camera\CamWnd.h" />
Expand Down
3 changes: 0 additions & 3 deletions tools/msvc/DarkRadiant.vcxproj.filters
Expand Up @@ -675,9 +675,6 @@
</ClCompile>
</ItemGroup>
<ItemGroup>
<ClInclude Include="..\..\radiant\camera\CameraObserver.h">
<Filter>src\camera</Filter>
</ClInclude>
<ClInclude Include="..\..\radiant\camera\CameraSettings.h">
<Filter>src\camera</Filter>
</ClInclude>
Expand Down

0 comments on commit 0b2e4df

Please sign in to comment.