#include <simgear/misc/sg_path.hxx>
#include <simgear/structure/subsystem_mgr.hxx>
#include <simgear/nasal/nasal.h>
+#include <simgear/scene/model/model.hxx>
+
+#include <map>
+SG_USING_STD(map);
+
class FGNasalScript;
+class FGNasalListener;
class FGNasalSys : public SGSubsystem
{
void setTimer(int argc, naRef* args);
// Implementation of the setlistener extension function
- void setListener(int argc, naRef* args);
+ naRef setListener(int argc, naRef* args);
+ naRef removeListener(int argc, naRef* args);
// Returns a ghost wrapper for the current _cmdArg
naRef cmdArgGhost();
-
+
// Callbacks for command and timer bindings
virtual bool handleCommand(const SGPropertyNode* arg);
void createModule(const char* moduleName, const char* fileName,
const char* src, int len);
-
- void screenPrint(const char* src);
-
+
+ void deleteModule(const char* moduleName);
+
private:
friend class FGNasalScript;
friend class FGNasalListener;
FGNasalSys* nasal;
};
+ // Listener
+ map<int, FGNasalListener *> _listener;
+ static int _listenerId;
+
void loadPropertyScripts();
void hashset(naRef hash, const char* key, naRef val);
void logError(naContext);
public: void handleTimer(NasalTimer* t);
};
+
class FGNasalScript {
public:
~FGNasalScript() { _nas->gcRelease(_gcKey); }
FGNasalSys* _nas;
};
+
class FGNasalListener : public SGPropertyChangeListener {
public:
- FGNasalListener(naRef handler, FGNasalSys* nasal, int key)
- : _handler(handler), _gcKey(key), _nas(nasal) {}
+ FGNasalListener(SGPropertyNode_ptr node, naRef handler,
+ FGNasalSys* nasal, int key);
- ~FGNasalListener() {
- _nas->gcRelease(_gcKey);
- }
-
- void valueChanged(SGPropertyNode* node) {
- _nas->_cmdArg = node;
- naContext c = naNewContext();
- naModUnlock();
- naCall(c, _handler, 0, 0, naNil(), naNil());
- naModLock();
- if(naGetError(c))
- _nas->logError(c);
- naFreeContext(c);
- }
+ ~FGNasalListener();
+ void valueChanged(SGPropertyNode* node);
private:
friend class FGNasalSys;
+ SGPropertyNode_ptr _node;
naRef _handler;
int _gcKey;
FGNasalSys* _nas;
+ unsigned int _active;
+};
+
+
+class FGNasalModelData : public SGModelData {
+public:
+ FGNasalModelData() : _unload(0) {}
+ ~FGNasalModelData();
+ void modelLoaded(const string& path, SGPropertyNode *prop, ssgBranch *);
+
+private:
+ string _module;
+ SGConstPropertyNode_ptr _unload;
};
#endif // __NASALSYS_HXX