1
0
Fork 0

- some code rearrangement for readability and maintainability

- commented out some destructor code that's causing crashes
  (temporarily creates a minor memory leak, triggered only when
  reloading the panel)
This commit is contained in:
curt 2001-08-10 05:17:40 +00:00
parent 79b25c850e
commit db7b3ec096
2 changed files with 105 additions and 31 deletions

View file

@ -181,7 +181,7 @@ FGInput::FGInput ()
FGInput::~FGInput () FGInput::~FGInput ()
{ {
// TODO: delete all FGBinding objects explicitly // no op
} }
void void
@ -632,6 +632,70 @@ FGInput::_find_key_bindings (unsigned int k, int modifiers)
} }
////////////////////////////////////////////////////////////////////////
// Implementation of FGInput::button.
////////////////////////////////////////////////////////////////////////
FGInput::button::button ()
: is_repeatable(false),
last_state(-1)
{
}
FGInput::button::~button ()
{
// FIXME: memory leak
// for (int i = 0; i < FG_MOD_MAX; i++)
// for (int j = 0; i < bindings[i].size(); j++)
// delete bindings[i][j];
}
////////////////////////////////////////////////////////////////////////
// Implementation of FGInput::axis.
////////////////////////////////////////////////////////////////////////
FGInput::axis::axis ()
: last_value(9999999),
tolerance(0.002),
low_threshold(-0.9),
high_threshold(0.9)
{
}
FGInput::axis::~axis ()
{
for (int i = 0; i < FG_MOD_MAX; i++)
for (unsigned int j = 0; i < bindings[i].size(); j++)
delete bindings[i][j];
}
////////////////////////////////////////////////////////////////////////
// Implementation of FGInput::joystick.
////////////////////////////////////////////////////////////////////////
FGInput::joystick::joystick ()
{
}
FGInput::joystick::~joystick ()
{
delete js;
delete[] axes;
delete[] buttons;
}
////////////////////////////////////////////////////////////////////////
// Implementation of GLUT callbacks.
////////////////////////////////////////////////////////////////////////
/** /**
* Construct the modifiers. * Construct the modifiers.
*/ */

View file

@ -44,6 +44,13 @@
SG_USING_STD(map); SG_USING_STD(map);
SG_USING_STD(vector); SG_USING_STD(vector);
////////////////////////////////////////////////////////////////////////
// General binding support.
////////////////////////////////////////////////////////////////////////
/** /**
* An input binding of some sort. * An input binding of some sort.
* *
@ -134,6 +141,12 @@ private:
}; };
////////////////////////////////////////////////////////////////////////
// General input mapping support.
////////////////////////////////////////////////////////////////////////
/** /**
* Generic input module. * Generic input module.
* *
@ -154,7 +167,16 @@ public:
FG_MOD_MAX = 16 // enough to handle all combinations FG_MOD_MAX = 16 // enough to handle all combinations
}; };
FGInput();
/**
* Default constructor.
*/
FGInput ();
/**
* Destructor.
*/
virtual ~FGInput(); virtual ~FGInput();
// //
@ -184,7 +206,6 @@ public:
private: private:
// Constants // Constants
enum enum
{ {
@ -206,15 +227,8 @@ private:
* Settings for a key or button. * Settings for a key or button.
*/ */
struct button { struct button {
button () button ();
: is_repeatable(false), virtual ~button ();
last_state(-1)
{}
virtual ~button () {
for (int i = 0; i < FG_MOD_MAX; i++)
for (int j = 0; i < bindings[i].size(); j++)
delete bindings[i][j];
}
bool is_repeatable; bool is_repeatable;
int last_state; int last_state;
binding_list_t bindings[FG_MOD_MAX]; binding_list_t bindings[FG_MOD_MAX];
@ -225,17 +239,8 @@ private:
* Settings for a single joystick axis. * Settings for a single joystick axis.
*/ */
struct axis { struct axis {
axis () axis ();
: last_value(9999999), virtual ~axis ();
tolerance(0.002),
low_threshold(-0.9),
high_threshold(0.9)
{}
virtual ~axis () {
for (int i = 0; i < FG_MOD_MAX; i++)
for (int j = 0; i < bindings[i].size(); j++)
delete bindings[i][j];
}
float last_value; float last_value;
float tolerance; float tolerance;
binding_list_t bindings[FG_MOD_MAX]; binding_list_t bindings[FG_MOD_MAX];
@ -250,14 +255,12 @@ private:
* Settings for a joystick. * Settings for a joystick.
*/ */
struct joystick { struct joystick {
virtual ~joystick () { joystick ();
delete js; virtual ~joystick ();
delete[] axes; int jsnum;
delete[] buttons; jsJoystick * js;
}
int naxes; int naxes;
int nbuttons; int nbuttons;
jsJoystick * js;
axis * axes; axis * axes;
button * buttons; button * buttons;
}; };
@ -319,12 +322,19 @@ private:
}; };
extern FGInput current_input;
////////////////////////////////////////////////////////////////////////
// GLUT callbacks.
////////////////////////////////////////////////////////////////////////
// Handle keyboard events // Handle keyboard events
void GLUTkey(unsigned char k, int x, int y); void GLUTkey(unsigned char k, int x, int y);
void GLUTkeyup(unsigned char k, int x, int y); void GLUTkeyup(unsigned char k, int x, int y);
void GLUTspecialkey(int k, int x, int y); void GLUTspecialkey(int k, int x, int y);
void GLUTspecialkeyup(int k, int x, int y); void GLUTspecialkeyup(int k, int x, int y);
extern FGInput current_input;
#endif // _CONTROLS_HXX #endif // _CONTROLS_HXX