From 2eb583e9e168e4e2de0249d304c6338eae72d007 Mon Sep 17 00:00:00 2001 From: Florent Rougon <f.rougon@free.fr> Date: Sat, 13 Jan 2018 22:06:39 +0100 Subject: [PATCH] FGMouseInput: improve initialization sequence Create the FGMouseInputPrivate instance in FGMouseInput::init() instead of in FGMouseInput's constructor. This will allow straightforward implementation of reinit() via shutdown() and init(). Also get rid of the 'initialized' bool, since bool(d) is now equivalent (d being the std::unique_ptr<FGMouseInputPrivate> data member of FGMouseInput). --- src/Input/FGMouseInput.cxx | 25 ++++++------------------- 1 file changed, 6 insertions(+), 19 deletions(-) diff --git a/src/Input/FGMouseInput.cxx b/src/Input/FGMouseInput.cxx index 11f061c3f..62bf07203 100644 --- a/src/Input/FGMouseInput.cxx +++ b/src/Input/FGMouseInput.cxx @@ -155,7 +155,6 @@ class FGMouseInput::FGMouseInputPrivate : public SGPropertyChangeListener { public: FGMouseInputPrivate() : - initialized(false), haveWarped(false), xSizeNode(fgGetNode("/sim/startup/xsize", false ) ), ySizeNode(fgGetNode("/sim/startup/ysize", false ) ), @@ -326,7 +325,6 @@ public: mouse mice[MAX_MICE]; - bool initialized; bool hideCursor, haveWarped; bool tooltipTimeoutDone; bool clickTriggersTooltip; @@ -365,8 +363,7 @@ static void mouseMotionHandler(int x, int y, const osgGA::GUIEventAdapter* ea) -FGMouseInput::FGMouseInput() : - d(new FGMouseInputPrivate) +FGMouseInput::FGMouseInput() { global_mouseInput = this; } @@ -378,15 +375,8 @@ FGMouseInput::~FGMouseInput() void FGMouseInput::init() { - if (d->initialized) { - SG_LOG(SG_INPUT, SG_WARN, "Duplicate init of FGMouseInput"); - - return; - } - - d->initialized = true; - SG_LOG(SG_INPUT, SG_DEBUG, "Initializing mouse bindings"); + d.reset(new FGMouseInputPrivate()); std::string module = ""; SGPropertyNode * mouse_nodes = fgGetNode("/input/mice"); @@ -471,7 +461,7 @@ void FGMouseInput::init() void FGMouseInput::update ( double dt ) { - if (!d->initialized) { + if (!d) { SG_LOG(SG_INPUT, SG_WARN, "update of mouse before init"); } @@ -546,7 +536,7 @@ mouse_mode::~mouse_mode () void FGMouseInput::doMouseClick (int b, int updown, int x, int y, bool mainWindow, const osgGA::GUIEventAdapter* ea) { - if (!d->initialized) { + if (!d) { // can occur during reset return; } @@ -680,7 +670,7 @@ void FGMouseInput::processMotion(int x, int y, const osgGA::GUIEventAdapter* ea) void FGMouseInput::doMouseMotion (int x, int y, const osgGA::GUIEventAdapter* ea) { - if (!d->initialized) { + if (!d) { // can occur during reset return; } @@ -710,12 +700,9 @@ void FGMouseInput::doMouseMotion (int x, int y, const osgGA::GUIEventAdapter* ea bool FGMouseInput::isRightDragToLookEnabled() const { - if (!d->initialized) { + if (!d) { return false; } return (d->rightClickModeCycle == false); } - - -