Howto:Exposing Subsystems to Nasal: Difference between revisions

Jump to navigation Jump to search
 
(One intermediate revision by the same user not shown)
Line 6: Line 6:


== Focus ==
== Focus ==
{{Main article|Resource Tracking for FlightGear}}
This article will specifically cover how to access the FlightGear event manager (SGEventMgr) and the listener API (SGPropertyChangeListener) to track registration and invocation of Nasal callbacks per frame.
This article will specifically cover how to access the FlightGear event manager (SGEventMgr) and the listener API (SGPropertyChangeListener) to track registration and invocation of Nasal callbacks per frame.


Line 171: Line 172:


</syntaxhighlight>
</syntaxhighlight>
To make the whole thing more useful, we will lower the logging priority and instead change the name of the added event to include the file name of the Nasal module and the line number where the settimer() call is invoked (which will be primarily useful in conjunction with the simgear patch above):
<syntaxhighlight lang="diff">
diff --git a/src/Scripting/NasalSys.cxx b/src/Scripting/NasalSys.cxx
index dcd9965..7f49b18 100644
--- a/src/Scripting/NasalSys.cxx
+++ b/src/Scripting/NasalSys.cxx
@@ -1307,7 +1307,25 @@ void FGNasalSys::setTimer(naContext c, int argc, naRef* args)
    t->gcKey = gcSave(handler);
    t->nasal = this;
-    globals->get_event_mgr()->addEvent("NasalTimer",
+    SG_LOG(SG_NASAL, SG_DEBUG,
+ "Nasal timer registration via settimer():\n"
+ "\tfile: " << naStr_data(naGetSourceFile(c,0)) <<
+ "\tline: " << naGetLine(c,0) << std::endl
+
+    );
+
+    if(delta.num <= 0.1)
+ SG_LOG(SG_NASAL, SG_ALERT, "Warning: settimer() should rarely be used per-frame !!");
+
+    std::string timerName("NasalTimer: ");
+
+    std::stringstream line;
+    line << naGetLine(c,0);
+
+    timerName += std::string(naStr_data(naGetSourceFile(c,0))) +" via line:"+line.str() ;
+   
+
+    globals->get_event_mgr()->addEvent(timerName,
                                        t, &NasalTimer::timerExpired,
                                        delta.num, simtime);
}
</syntaxhighlight>
Next, we can explore logging everything via properties, i.e. so that all this info shows up in the property tree using property objects


=== Base Package ===
=== Base Package ===

Navigation menu