FGMouseInput: add shutdown() and reinit() overrides
- Modify global_mouseInput in init() and in shutdown(), because *these* are the places where FGMouseInput is enabled or disabled. - reinit() does shutdown() followed by init(). Note: the commented-out block starting with "FIXME: memory leak" that is removed here was just an outdated comment, because SGBindingList is an std::vector<SGBinding_ptr>, where SGBinding_ptr is a smart pointer type (SGSharedPtr<SGBinding>). In other words, there was no leak in this place---at least, not recently.
This commit is contained in:
parent
2eb583e9e1
commit
99c809dda0
2 changed files with 25 additions and 27 deletions
|
@ -111,7 +111,7 @@ void ActivePickCallbacks::update( double dt, unsigned int keyModState )
|
|||
*/
|
||||
struct mouse_mode {
|
||||
mouse_mode ();
|
||||
virtual ~mouse_mode ();
|
||||
|
||||
FGMouseCursor::Cursor cursor;
|
||||
bool constrained;
|
||||
bool pass_through;
|
||||
|
@ -347,7 +347,7 @@ public:
|
|||
// The Mouse Input Implementation
|
||||
////////////////////////////////////////////////////////////////////////
|
||||
|
||||
static FGMouseInput* global_mouseInput = NULL;
|
||||
static FGMouseInput* global_mouseInput = nullptr;
|
||||
|
||||
static void mouseClickHandler(int button, int updown, int x, int y, bool mainWindow, const osgGA::GUIEventAdapter* ea)
|
||||
{
|
||||
|
@ -361,21 +361,12 @@ static void mouseMotionHandler(int x, int y, const osgGA::GUIEventAdapter* ea)
|
|||
global_mouseInput->doMouseMotion(x, y, ea);
|
||||
}
|
||||
|
||||
|
||||
|
||||
FGMouseInput::FGMouseInput()
|
||||
{
|
||||
global_mouseInput = this;
|
||||
}
|
||||
|
||||
FGMouseInput::~FGMouseInput()
|
||||
{
|
||||
global_mouseInput = NULL;
|
||||
}
|
||||
FGMouseInput::FGMouseInput() = default;
|
||||
|
||||
void FGMouseInput::init()
|
||||
{
|
||||
SG_LOG(SG_INPUT, SG_DEBUG, "Initializing mouse bindings");
|
||||
|
||||
d.reset(new FGMouseInputPrivate());
|
||||
std::string module = "";
|
||||
|
||||
|
@ -457,6 +448,23 @@ void FGMouseInput::init()
|
|||
|
||||
fgRegisterMouseClickHandler(mouseClickHandler);
|
||||
fgRegisterMouseMotionHandler(mouseMotionHandler);
|
||||
global_mouseInput = this;
|
||||
}
|
||||
|
||||
void FGMouseInput::shutdown()
|
||||
{
|
||||
SG_LOG(SG_INPUT, SG_DEBUG, "Shutting down mouse bindings");
|
||||
|
||||
// This ensures that mouseClickHandler and mouseMotionHandler are no-ops.
|
||||
global_mouseInput = nullptr;
|
||||
// Reset the Pimpl
|
||||
d.reset();
|
||||
}
|
||||
|
||||
void FGMouseInput::reinit()
|
||||
{
|
||||
shutdown();
|
||||
init();
|
||||
}
|
||||
|
||||
void FGMouseInput::update ( double dt )
|
||||
|
@ -522,18 +530,6 @@ mouse_mode::mouse_mode ()
|
|||
{
|
||||
}
|
||||
|
||||
mouse_mode::~mouse_mode ()
|
||||
{
|
||||
// FIXME: memory leak
|
||||
// for (int i = 0; i < KEYMOD_MAX; i++) {
|
||||
// int j;
|
||||
// for (j = 0; i < x_bindings[i].size(); j++)
|
||||
// delete bindings[i][j];
|
||||
// for (j = 0; j < y_bindings[i].size(); j++)
|
||||
// delete bindings[i][j];
|
||||
// }
|
||||
}
|
||||
|
||||
void FGMouseInput::doMouseClick (int b, int updown, int x, int y, bool mainWindow, const osgGA::GUIEventAdapter* ea)
|
||||
{
|
||||
if (!d) {
|
||||
|
|
|
@ -40,10 +40,12 @@ namespace osgGA { class GUIEventAdapter; }
|
|||
////////////////////////////////////////////////////////////////////////
|
||||
class FGMouseInput : public SGSubsystem, FGCommonInput {
|
||||
public:
|
||||
FGMouseInput();
|
||||
virtual ~FGMouseInput();
|
||||
FGMouseInput();
|
||||
virtual ~FGMouseInput() = default;
|
||||
|
||||
void init() override;
|
||||
void shutdown() override;
|
||||
void reinit() override;
|
||||
void update( double dt ) override;
|
||||
|
||||
static const char* subsystemName() { return "input-mouse"; }
|
||||
|
|
Loading…
Reference in a new issue