Bernie Bright:
Here are the Boost-less FGEventMgr updates I promised. Removed Boost dependencies from FGEventMgr. Removed Boost configure check. fgMethodCallback now handles const member functions. I've successfully tested these changes with gcc and msvc.
This commit is contained in:
parent
39fcbc93ba
commit
ab0964384e
5 changed files with 101 additions and 68 deletions
src
|
@ -35,7 +35,6 @@
|
|||
#include <Navaids/mkrbeacons.hxx>
|
||||
#include <Navaids/navlist.hxx>
|
||||
#include <Time/FGEventMgr.hxx>
|
||||
#include <boost/bind.hpp>
|
||||
|
||||
#include "radiostack.hxx"
|
||||
|
||||
|
@ -143,8 +142,7 @@ FGRadioStack::init ()
|
|||
|
||||
// Search radio database once per second
|
||||
global_events.Register( "fgRadioSearch()",
|
||||
boost::bind( &FGRadioStack::search,
|
||||
current_radiostack),
|
||||
current_radiostack, &FGRadioStack::search,
|
||||
1000 );
|
||||
}
|
||||
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
#ifndef _FG_CALLBACK_HXX
|
||||
#define _FG_CALLBACK_HXX
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
// -dw- need size_t for params() function
|
||||
#ifdef __MWERKS__
|
||||
typedef unsigned long size_t;
|
||||
|
@ -114,14 +116,16 @@ fgFunctionCallback::call0v( void** )
|
|||
|
||||
//-----------------------------------------------------------------------------
|
||||
//
|
||||
// Callback for invoking an object method.
|
||||
// Callback for invoking a member function.
|
||||
//
|
||||
//template< typename Ret, class T >
|
||||
template< class T >
|
||||
class fgMethodCallback : public fgCallback
|
||||
{
|
||||
public:
|
||||
// Pointer to method taking no arguments and returning void.
|
||||
typedef void (T::*Method0v)();
|
||||
typedef void (T::*Method0vc)() const;
|
||||
|
||||
// A callback instance to invoke method 'm' of object 'o'
|
||||
fgMethodCallback( T* o, Method0v m )
|
||||
|
@ -130,6 +134,13 @@ public:
|
|||
method0v(m),
|
||||
doPtr(&fgMethodCallback<T>::call0v) {}
|
||||
|
||||
// A callback instance to invoke a const method 'm' of object 'o'
|
||||
fgMethodCallback( T* o, Method0vc m )
|
||||
: fgCallback(0),
|
||||
object(o),
|
||||
method0vc(m),
|
||||
doPtr(&fgMethodCallback<T>::call0v) {}
|
||||
|
||||
// Create a clone on the heap.
|
||||
fgCallback* clone() const;
|
||||
|
||||
|
@ -146,7 +157,10 @@ private:
|
|||
|
||||
private:
|
||||
T* object;
|
||||
Method0v method0v;
|
||||
union {
|
||||
Method0v method0v;
|
||||
Method0vc method0vc;
|
||||
};
|
||||
|
||||
// typedef void * (fgMethodCallback::*DoPtr)( void ** );
|
||||
typedef void * (fgMethodCallback<T>::*DoPtr)( void ** );
|
||||
|
@ -175,4 +189,3 @@ fgMethodCallback<T>::call0v( void** )
|
|||
|
||||
#endif // _FG_CALLBACK_HXX
|
||||
|
||||
|
||||
|
|
|
@ -105,7 +105,6 @@
|
|||
#include <Sound/fg_fx.hxx>
|
||||
#include <Sound/soundmgr.hxx>
|
||||
#include <Time/FGEventMgr.hxx>
|
||||
#include <boost/bind.hpp>
|
||||
#include <Time/light.hxx>
|
||||
#include <Time/sunpos.hxx>
|
||||
#include <Time/moonpos.hxx>
|
||||
|
@ -777,9 +776,8 @@ bool fgInitSubsystems( void ) {
|
|||
global_events.init();
|
||||
|
||||
// Output event stats every 60 seconds
|
||||
global_events.Register( "fgEVENT_MGR::PrintStats()",
|
||||
boost::bind( &FGEventMgr::print_stats,
|
||||
&global_events ),
|
||||
global_events.Register( "FGEventMgr::print_stats()",
|
||||
&global_events, &FGEventMgr::print_stats,
|
||||
60000 );
|
||||
|
||||
|
||||
|
@ -809,7 +807,7 @@ bool fgInitSubsystems( void ) {
|
|||
|
||||
// update the lighting parameters (based on sun angle)
|
||||
global_events.Register( "fgLight::Update()",
|
||||
boost::bind( &fgLIGHT::Update, &cur_light_params ),
|
||||
&cur_light_params, &fgLIGHT::Update,
|
||||
30000 );
|
||||
|
||||
|
||||
|
@ -1128,5 +1126,3 @@ void fgReInitSubsystems( void )
|
|||
fgSetBool("/sim/freeze/master", false);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -4,15 +4,17 @@
|
|||
|
||||
#include <simgear/compiler.h>
|
||||
#include <simgear/debug/logstream.hxx>
|
||||
#include <functional>
|
||||
#include <boost/bind.hpp>
|
||||
// #include <functional>
|
||||
// #include <algorithm>
|
||||
|
||||
#include "FGEventMgr.hxx"
|
||||
|
||||
FGEventMgr::FGEvent::FGEvent()
|
||||
: status(FG_EVENT_SUSP),
|
||||
interval_ms(0),
|
||||
ms_to_go(0),
|
||||
: name_(""),
|
||||
callback_(0),
|
||||
status_(FG_EVENT_SUSP),
|
||||
ms_(0),
|
||||
ms_to_go_(0),
|
||||
cum_time(0),
|
||||
min_time(100000),
|
||||
max_time(0),
|
||||
|
@ -20,15 +22,15 @@ FGEventMgr::FGEvent::FGEvent()
|
|||
{
|
||||
}
|
||||
|
||||
FGEventMgr::FGEvent::FGEvent( const string& desc,
|
||||
callback_type cb,
|
||||
EventState status_,
|
||||
FGEventMgr::FGEvent::FGEvent( const char* name,
|
||||
fgCallback* cb,
|
||||
EventState status,
|
||||
interval_type ms )
|
||||
: description(desc),
|
||||
callback(cb),
|
||||
status(status_),
|
||||
interval_ms(ms),
|
||||
ms_to_go(ms),
|
||||
: name_(name),
|
||||
callback_(cb),
|
||||
status_(status),
|
||||
ms_(ms),
|
||||
ms_to_go_(ms),
|
||||
cum_time(0),
|
||||
min_time(100000),
|
||||
max_time(0),
|
||||
|
@ -39,6 +41,7 @@ FGEventMgr::FGEvent::FGEvent( const string& desc,
|
|||
|
||||
FGEventMgr::FGEvent::~FGEvent()
|
||||
{
|
||||
//delete callback_;
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -50,7 +53,7 @@ FGEventMgr::FGEvent::run()
|
|||
start_time.stamp();
|
||||
|
||||
// run the event
|
||||
this->callback();
|
||||
callback_->call(0);
|
||||
|
||||
finish_time.stamp();
|
||||
|
||||
|
@ -75,8 +78,8 @@ void
|
|||
FGEventMgr::FGEvent::print_stats() const
|
||||
{
|
||||
SG_LOG( SG_EVENT, SG_INFO,
|
||||
" " << description
|
||||
<< " int=" << interval_ms / 1000.0
|
||||
" " << name_
|
||||
<< " int=" << ms_ / 1000.0
|
||||
<< " cum=" << cum_time
|
||||
<< " min=" << min_time
|
||||
<< " max=" << max_time
|
||||
|
@ -126,18 +129,14 @@ FGEventMgr::update( int dt )
|
|||
}
|
||||
|
||||
void
|
||||
FGEventMgr::Register( const string& desc,
|
||||
callback_type cb,
|
||||
EventState state,
|
||||
interval_type ms )
|
||||
FGEventMgr::Register( const FGEvent& event )
|
||||
{
|
||||
FGEvent event( desc, cb, state, ms );
|
||||
if (state == FG_EVENT_READY)
|
||||
event.run();
|
||||
// if (event.is_ready())
|
||||
// event.run();
|
||||
event_table.push_back( event );
|
||||
|
||||
SG_LOG( SG_EVENT, SG_INFO, "Registered event " << desc
|
||||
<< " to run every " << ms << "ms" );
|
||||
SG_LOG( SG_EVENT, SG_INFO, "Registered event " << event.name()
|
||||
<< " to run every " << event.interval() << "ms" );
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -147,8 +146,17 @@ FGEventMgr::print_stats() const
|
|||
SG_LOG( SG_EVENT, SG_INFO, "Event Stats" );
|
||||
SG_LOG( SG_EVENT, SG_INFO, "-----------" );
|
||||
|
||||
#if 1
|
||||
event_container_type::const_iterator first = event_table.begin();
|
||||
event_container_type::const_iterator last = event_table.end();
|
||||
for (; first != last; ++first)
|
||||
{
|
||||
first->print_stats();
|
||||
}
|
||||
#else
|
||||
// #@!$ MSVC can't handle const member functions.
|
||||
std::for_each( event_table.begin(), event_table.end(),
|
||||
boost::bind( &FGEvent::print_stats, _1 ) );
|
||||
|
||||
std::mem_fun_ref( &FGEvent::print_stats ) );
|
||||
#endif
|
||||
SG_LOG( SG_EVENT, SG_INFO, "" );
|
||||
}
|
||||
|
|
|
@ -24,12 +24,12 @@
|
|||
#ifndef FG_EVENT_MGR_H_INCLUDED
|
||||
#define FG_EVENT_MGR_H_INCLUDED 1
|
||||
|
||||
#include <boost/function.hpp>
|
||||
|
||||
#include <simgear/compiler.h>
|
||||
#include <simgear/timing/timestamp.hxx>
|
||||
|
||||
#include <Main/fgfs.hxx>
|
||||
#include <Include/fg_callback.hxx>
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
|
@ -52,7 +52,6 @@ public:
|
|||
FG_EVENT_QUEUED = 2
|
||||
};
|
||||
|
||||
typedef boost::function<void> callback_type;
|
||||
typedef int interval_type;
|
||||
|
||||
private:
|
||||
|
@ -68,9 +67,9 @@ private:
|
|||
*/
|
||||
FGEvent();
|
||||
|
||||
FGEvent( const string& desc,
|
||||
callback_type cb,
|
||||
EventState status_,
|
||||
FGEvent( const char* desc,
|
||||
fgCallback* cb,
|
||||
EventState status,
|
||||
interval_type ms );
|
||||
|
||||
/**
|
||||
|
@ -83,8 +82,8 @@ private:
|
|||
*/
|
||||
void reset()
|
||||
{
|
||||
status = FG_EVENT_READY;
|
||||
ms_to_go = interval_ms;
|
||||
status_ = FG_EVENT_READY;
|
||||
ms_to_go_ = ms_;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -92,6 +91,11 @@ private:
|
|||
*/
|
||||
void run();
|
||||
|
||||
bool is_ready() const { return status_ == FG_EVENT_READY; }
|
||||
|
||||
string name() const { return name_; }
|
||||
interval_type interval() const { return ms_; }
|
||||
|
||||
/**
|
||||
* Display event statistics.
|
||||
*/
|
||||
|
@ -104,19 +108,19 @@ private:
|
|||
*/
|
||||
bool update( int dt_ms )
|
||||
{
|
||||
if (status != FG_EVENT_READY)
|
||||
if (status_ != FG_EVENT_READY)
|
||||
return false;
|
||||
|
||||
ms_to_go -= dt_ms;
|
||||
return ms_to_go <= 0;
|
||||
ms_to_go_ -= dt_ms;
|
||||
return ms_to_go_ <= 0;
|
||||
}
|
||||
|
||||
private:
|
||||
string description;
|
||||
callback_type callback;
|
||||
EventState status;
|
||||
interval_type interval_ms;
|
||||
int ms_to_go;
|
||||
string name_;
|
||||
fgCallback* callback_;
|
||||
EventState status_;
|
||||
interval_type ms_;
|
||||
int ms_to_go_;
|
||||
|
||||
unsigned long cum_time; // cumulative processor time of this event
|
||||
unsigned long min_time; // time of quickest execution
|
||||
|
@ -150,19 +154,30 @@ public:
|
|||
* @param state
|
||||
* @param interval Callback repetition rate in milliseconds.
|
||||
*/
|
||||
void Register( const string& desc,
|
||||
callback_type cb,
|
||||
EventState state,
|
||||
interval_type interval_ms );
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
void Register( const string& desc,
|
||||
callback_type cb,
|
||||
interval_type interval_ms )
|
||||
void Register( const char* name,
|
||||
void (*cb)(),
|
||||
interval_type interval_ms,
|
||||
EventState state = FG_EVENT_READY )
|
||||
{
|
||||
this->Register( desc, cb, FG_EVENT_READY, interval_ms );
|
||||
this->Register( FGEvent( name, new fgFunctionCallback(cb), state, interval_ms ) );
|
||||
}
|
||||
|
||||
template< class Obj >
|
||||
void Register( const char* name,
|
||||
Obj* obj, void (Obj::*pmf)() const,
|
||||
interval_type interval_ms,
|
||||
EventState state = FG_EVENT_READY )
|
||||
{
|
||||
this->Register( FGEvent( name, new fgMethodCallback<Obj>(obj,pmf), state, interval_ms ) );
|
||||
}
|
||||
|
||||
template< class Obj >
|
||||
void Register( const char* name,
|
||||
Obj* obj, void (Obj::*pmf)(),
|
||||
interval_type interval_ms,
|
||||
EventState state = FG_EVENT_READY )
|
||||
{
|
||||
this->Register( FGEvent( name, new fgMethodCallback<Obj>(obj,pmf), state, interval_ms ) );
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -170,6 +185,9 @@ public:
|
|||
*/
|
||||
void print_stats() const;
|
||||
|
||||
private:
|
||||
void Register( const FGEvent& event );
|
||||
|
||||
private:
|
||||
|
||||
typedef vector< FGEvent > event_container_type;
|
||||
|
|
Loading…
Add table
Reference in a new issue