Use std::function for callbacks
This commit is contained in:
parent
83694eabde
commit
5051d90487
8 changed files with 31 additions and 31 deletions
|
@ -149,8 +149,8 @@ SGSubsystem::InitStatus FGEnvironmentMgr::incrementalInit()
|
|||
if (r == INIT_DONE) {
|
||||
fgClouds->Init();
|
||||
_multiplayerListener = new FGEnvironmentMgrMultiplayerListener(this);
|
||||
globals->get_event_mgr()->addTask("updateClosestAirport", this,
|
||||
&FGEnvironmentMgr::updateClosestAirport, 10 );
|
||||
globals->get_event_mgr()->addTask("updateClosestAirport",
|
||||
[this](){ this->updateClosestAirport(); }, 10 );
|
||||
}
|
||||
|
||||
return r;
|
||||
|
|
|
@ -282,8 +282,8 @@ void BasicRealWxController::init()
|
|||
checkNearbyMetar();
|
||||
update(0); // fetch data ASAP
|
||||
|
||||
globals->get_event_mgr()->addTask("checkNearbyMetar", this,
|
||||
&BasicRealWxController::checkNearbyMetar, 10 );
|
||||
globals->get_event_mgr()->addTask("checkNearbyMetar",
|
||||
[this](){ this->checkNearbyMetar(); }, 10 );
|
||||
}
|
||||
|
||||
void BasicRealWxController::reinit()
|
||||
|
|
|
@ -7,6 +7,7 @@
|
|||
#include "WaypointList.hxx"
|
||||
|
||||
#include <algorithm>
|
||||
#include <utility>
|
||||
|
||||
#include <plib/puAux.h>
|
||||
|
||||
|
@ -107,7 +108,7 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
virtual void setUpdateCallback(SGCallback* cb)
|
||||
virtual void setUpdateCallback(simgear::Callback cb)
|
||||
{
|
||||
_cb = cb;
|
||||
}
|
||||
|
@ -117,7 +118,7 @@ public:
|
|||
{
|
||||
if (prop->getNameString() == "edited") {
|
||||
if (_cb) {
|
||||
(*_cb)();
|
||||
_cb();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -128,7 +129,7 @@ public:
|
|||
}
|
||||
private:
|
||||
flightgear::FlightPlan* _fp;
|
||||
SGCallback* _cb;
|
||||
simgear::Callback _cb;
|
||||
};
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////////
|
||||
|
@ -179,18 +180,16 @@ WaypointList::WaypointList(int x, int y, int width, int height) :
|
|||
WaypointList::~WaypointList()
|
||||
{
|
||||
delete _model;
|
||||
delete _updateCallback;
|
||||
delete _scrollCallback;
|
||||
}
|
||||
|
||||
void WaypointList::setUpdateCallback(SGCallback* cb)
|
||||
void WaypointList::setUpdateCallback(simgear::Callback cb)
|
||||
{
|
||||
_updateCallback = cb;
|
||||
_updateCallback = std::move(cb);
|
||||
}
|
||||
|
||||
void WaypointList::setScrollCallback(SGCallback* cb)
|
||||
void WaypointList::setScrollCallback(simgear::Callback cb)
|
||||
{
|
||||
_scrollCallback = cb;
|
||||
_scrollCallback = std::move(cb);
|
||||
}
|
||||
|
||||
void WaypointList::setSize(int width, int height)
|
||||
|
@ -568,7 +567,7 @@ void WaypointList::doDragScroll()
|
|||
}
|
||||
|
||||
if (_scrollCallback) {
|
||||
(*_scrollCallback)();
|
||||
_scrollCallback();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -608,7 +607,7 @@ void WaypointList::ensureRowVisible(int rowIndex)
|
|||
|
||||
puPostRefresh();
|
||||
if (_scrollCallback) { // keep scroll observers in sync
|
||||
(*_scrollCallback)();
|
||||
_scrollCallback();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -711,7 +710,7 @@ void WaypointList::setModel(Model* model)
|
|||
}
|
||||
|
||||
_model = model;
|
||||
_model->setUpdateCallback(make_callback(this, &WaypointList::modelUpdateCallback));
|
||||
_model->setUpdateCallback([this](){ this->modelUpdateCallback(); });
|
||||
|
||||
puPostRefresh();
|
||||
}
|
||||
|
@ -813,7 +812,7 @@ void WaypointList::modelUpdateCallback()
|
|||
// local stuff
|
||||
|
||||
if (_updateCallback) {
|
||||
(*_updateCallback)();
|
||||
_updateCallback();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -859,12 +858,12 @@ void ScrolledWaypointList::setValue(int v)
|
|||
void ScrolledWaypointList::init(int w, int h)
|
||||
{
|
||||
_list = new WaypointList(0, 0, w, h);
|
||||
_list->setUpdateCallback(make_callback(this, &ScrolledWaypointList::modelUpdated));
|
||||
_list->setUpdateCallback([this](){ this->modelUpdated(); });
|
||||
_hasVScroll = _list->wantsVScroll();
|
||||
_list->setUserData(this);
|
||||
_list->setCallback(waypointListCb);
|
||||
|
||||
_list->setScrollCallback(make_callback(this, &ScrolledWaypointList::updateScroll));
|
||||
_list->setScrollCallback([this](){ this->updateScroll(); });
|
||||
|
||||
_scrollbar = new puaScrollBar(w - _scrollWidth, 0, h,
|
||||
1 /*arrow*/, 1 /* vertical */, _scrollWidth);
|
||||
|
|
|
@ -8,6 +8,7 @@
|
|||
#include <simgear/compiler.h>
|
||||
#include <simgear/timing/timestamp.hxx>
|
||||
#include <simgear/misc/strutils.hxx>
|
||||
#include <simgear/structure/callback.hxx>
|
||||
|
||||
#include "FGPUIDialog.hxx" // for GUI_ID
|
||||
|
||||
|
@ -62,8 +63,8 @@ public:
|
|||
|
||||
void ensureRowVisible(int row);
|
||||
|
||||
void setUpdateCallback(SGCallback* cb);
|
||||
void setScrollCallback(SGCallback* cb);
|
||||
void setUpdateCallback(simgear::Callback cb);
|
||||
void setScrollCallback(simgear::Callback cb);
|
||||
|
||||
/**
|
||||
* Abstract interface for waypoint source
|
||||
|
@ -80,7 +81,7 @@ public:
|
|||
virtual flightgear::FlightPlan* flightplan() const = 0;
|
||||
|
||||
// update notifications
|
||||
virtual void setUpdateCallback(SGCallback* cb) = 0;
|
||||
virtual void setUpdateCallback(simgear::Callback cb) = 0;
|
||||
|
||||
// editing operations
|
||||
virtual void deleteAt(unsigned int index) = 0;
|
||||
|
@ -143,8 +144,8 @@ private:
|
|||
|
||||
bool _showLatLon;
|
||||
Model* _model;
|
||||
SGCallback* _updateCallback;
|
||||
SGCallback* _scrollCallback;
|
||||
simgear::Callback _updateCallback;
|
||||
simgear::Callback _scrollCallback;
|
||||
|
||||
SGTimeStamp _blinkTimer;
|
||||
bool _blink;
|
||||
|
|
|
@ -527,7 +527,7 @@ namespace
|
|||
FGRenderer *renderer = globals->get_renderer();
|
||||
renderer->resize(_xsize, _ysize);
|
||||
globals->get_event_mgr()->addTask("SnapShotTimer",
|
||||
this, &GUISnapShotOperation::timerExpired,
|
||||
[this](){ this->timerExpired(); },
|
||||
0.1, false);
|
||||
}
|
||||
|
||||
|
|
|
@ -198,6 +198,6 @@ MPServerResolver::run ()
|
|||
}
|
||||
|
||||
// Relinguish control, call me back on the next frame
|
||||
globals->get_event_mgr ()->addEvent ("MPServerResolver_update", this, &MPServerResolver::run, .0);
|
||||
globals->get_event_mgr ()->addEvent ("MPServerResolver_update", [this](){ this->run(); }, .0);
|
||||
}
|
||||
|
||||
|
|
|
@ -174,9 +174,9 @@ public:
|
|||
|
||||
_isRunning = true;
|
||||
if (_singleShot) {
|
||||
globals->get_event_mgr()->addEvent(_name, this, &TimerObj::invoke, _interval, _isSimTime);
|
||||
globals->get_event_mgr()->addEvent(_name, [this](){ this->invoke(); }, _interval, _isSimTime);
|
||||
} else {
|
||||
globals->get_event_mgr()->addTask(_name, this, &TimerObj::invoke,
|
||||
globals->get_event_mgr()->addTask(_name, [this](){ this->invoke(); },
|
||||
_interval, _interval /* delay */,
|
||||
_isSimTime);
|
||||
}
|
||||
|
@ -1708,7 +1708,7 @@ void FGNasalSys::setTimer(naContext c, int argc, naRef* args)
|
|||
NasalTimer* t = new NasalTimer(handler, this);
|
||||
_nasalTimers.push_back(t);
|
||||
globals->get_event_mgr()->addEvent(name,
|
||||
t, &NasalTimer::timerExpired,
|
||||
[t](){ t->timerExpired(); },
|
||||
delta.num, simtime);
|
||||
}
|
||||
|
||||
|
|
|
@ -75,8 +75,8 @@ void FGLight::init () {
|
|||
_sky_tbl = std::make_unique<SGInterpTable>( sky_path );
|
||||
|
||||
// update all solar system body positions of interest
|
||||
globals->get_event_mgr()->addTask("updateObjects", this,
|
||||
&FGLight::updateObjects, 0.5 );
|
||||
globals->get_event_mgr()->addTask("updateObjects",
|
||||
[this](){ this->updateObjects(); }, 0.5 );
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue