#include <simgear/math/sg_random.h>
#include <simgear/misc/sg_path.hxx>
#include <simgear/misc/sg_dir.hxx>
-#include <simgear/misc/interpolator.hxx>
#include <simgear/structure/commands.hxx>
#include <simgear/math/sg_geodesy.hxx>
#include <simgear/structure/event_mgr.hxx>
#include <Main/util.hxx>
#include <Main/fg_props.hxx>
-
using std::map;
void postinitNasalGUI(naRef globals, naContext c);
_sys->gcRelease(_gcSelf);
}
+ bool isRunning() const { return _isRunning; }
+
void stop()
{
if (_isRunning) {
{
naRef *args = NULL;
_sys->callMethod(_func, _self, 0, args, naNil() /* locals */);
+ if (_singleShot) {
+ _isRunning = false;
+ }
}
void setSingleShot(bool aSingleShot)
// value/delta numbers.
static naRef f_interpolate(naContext c, naRef me, int argc, naRef* args)
{
- SGPropertyNode* node;
- naRef prop = argc > 0 ? args[0] : naNil();
- if(naIsString(prop)) node = fgGetNode(naStr_data(prop), true);
- else if(naIsGhost(prop)) node = *(SGPropertyNode_ptr*)naGhost_ptr(prop);
- else return naNil();
-
- naRef curve = argc > 1 ? args[1] : naNil();
- if(!naIsVector(curve)) return naNil();
- int nPoints = naVec_size(curve) / 2;
- double* values = new double[nPoints];
- double* deltas = new double[nPoints];
- for(int i=0; i<nPoints; i++) {
- values[i] = naNumValue(naVec_get(curve, 2*i)).num;
- deltas[i] = naNumValue(naVec_get(curve, 2*i+1)).num;
- }
+ SGPropertyNode* node;
+ naRef prop = argc > 0 ? args[0] : naNil();
+ if(naIsString(prop)) node = fgGetNode(naStr_data(prop), true);
+ else if(naIsGhost(prop)) node = *(SGPropertyNode_ptr*)naGhost_ptr(prop);
+ else return naNil();
- ((SGInterpolator*)globals->get_subsystem_mgr()
- ->get_group(SGSubsystemMgr::INIT)->get_subsystem("interpolator"))
- ->interpolate(node, nPoints, values, deltas);
+ naRef curve = argc > 1 ? args[1] : naNil();
+ if(!naIsVector(curve)) return naNil();
+ int nPoints = naVec_size(curve) / 2;
- delete[] values;
- delete[] deltas;
- return naNil();
+ simgear::PropertyList value_nodes;
+ value_nodes.reserve(nPoints);
+ double_list deltas;
+ deltas.reserve(nPoints);
+
+ for( int i = 0; i < nPoints; ++i )
+ {
+ SGPropertyNode* val = new SGPropertyNode;
+ val->setDoubleValue(naNumValue(naVec_get(curve, 2*i)).num);
+ value_nodes.push_back(val);
+ deltas.push_back(naNumValue(naVec_get(curve, 2*i+1)).num);
+ }
+
+ node->interpolate("numeric", value_nodes, deltas, "linear");
+ return naNil();
}
// This is a better RNG than the one in the default Nasal distribution
.method("start", &TimerObj::start)
.method("stop", &TimerObj::stop)
.method("restart", &TimerObj::restart)
- .member("singleShot", &TimerObj::isSingleShot, &TimerObj::setSingleShot);
+ .member("singleShot", &TimerObj::isSingleShot, &TimerObj::setSingleShot)
+ .member("isRunning", &TimerObj::isRunning);
// Now load the various source files in the Nasal directory
simgear::Dir nasalDir(SGPath(globals->get_fg_root(), "Nasal"));
{
static naRef wrapNodeFunc = naNil();
if (naIsNil(wrapNodeFunc)) {
- nasal::Hash g(_globals, _context);
- nasal::Hash props = g.get<nasal::Hash>("props");
+ nasal::Hash props = getGlobals().get<nasal::Hash>("props");
wrapNodeFunc = props.get("wrapNode");
}
if (!_loadList.empty())
{
- // process Nasal load hook (only one per update loop to avoid excessive lags)
- _loadList.pop()->load();
+ if( _delay_load )
+ _delay_load = false;
+ else
+ // process Nasal load hook (only one per update loop to avoid excessive lags)
+ _loadList.pop()->load();
}
else
if (!_unloadList.empty())
// Create module with list of scripts
void FGNasalSys::addModule(string moduleName, simgear::PathList scripts)
{
- if (scripts.size()>0)
+ if (! scripts.empty())
{
SGPropertyNode* nasal = globals->get_props()->getNode("nasal");
SGPropertyNode* module_node = nasal->getChild(moduleName,0,true);
void FGNasalSys::registerToLoad(FGNasalModelData *data)
{
- _loadList.push(data);
+ if( _loadList.empty() )
+ _delay_load = true;
+ _loadList.push(data);
}
void FGNasalSys::registerToUnload(FGNasalModelData *data)