My Project
IObjectScriptingInterface.h
1 
2 #pragma once
3 
4 namespace ParaEngine
5 {
7  {
8  public:
10 
13  {
15  int func_type;
18  std::string script_func;
19  std::string m_sFilename;
20  std::string m_sCode;
22  unsigned int m_nLastTick;
23  public:
24  ScriptCallback(int type, const std::string& script): func_type(type), m_nLastTick(0){
25  SetScriptFunc(script);
26  };
27  ScriptCallback(): func_type(-1), m_nLastTick(0) {};
28 
30  void SetScriptFunc(const std::string& script);
31 
32  const std::string& GetCode(){ return m_sCode;}
33  const std::string& GetFileName(){ return m_sFilename;}
34  const std::string& GetScriptFunc(){ return script_func;}
35 
36  unsigned int GetLastTick() const { return m_nLastTick;}
37  void SetLastTick(unsigned int nTick) {m_nLastTick = nTick;}
38 
40  int ActivateAsync(const std::string& code);
42  int ActivateLocalNow(const std::string& script);
43  };
44  typedef std::vector<ScriptCallback> ObjectCallbackPool_Type;
45 
46 #ifndef DEFINE_SCRIPT_EVENT
47 #define DEFINE_SCRIPT_EVENT(clsName, name) \
48  ATTRIBUTE_METHOD1(clsName, Get##name##_s, const char**){\
49  ScriptCallback* pCallBack = cls->GetScriptCallback(Type_##name);\
50  *p1 = (pCallBack!=NULL) ? pCallBack->script_func.c_str() : CGlobals::GetString(G_STR_EMPTY).c_str();\
51  return S_OK;\
52  }\
53  ATTRIBUTE_METHOD1(clsName, Set##name##_s, const char*) {cls->AddScriptCallback(Type_##name, p1); return S_OK;}
54 
55 #endif
56 #ifndef DEFINE_SCRIPT_EVENT_GET
57 #define DEFINE_SCRIPT_EVENT_GET(clsName, name) \
58  ATTRIBUTE_METHOD1(clsName, Get##name##_s, const char**){\
59  ScriptCallback* pCallBack = cls->GetScriptCallback(Type_##name);\
60  *p1 = (pCallBack!=NULL) ? pCallBack->script_func.c_str() : CGlobals::GetString(G_STR_EMPTY).c_str();\
61  return S_OK;\
62  }
63 #endif
64  public:
72  virtual bool AddScriptCallback(int func_type, const string& script_func);
73 
75  virtual ScriptCallback* GetScriptCallback(int func_type);
76 
78  virtual bool RemoveScriptCallback(int func_type);
79 
80  protected:
82  ObjectCallbackPool_Type m_callback_scripts;
83  };
84 }
int ActivateLocalNow(const std::string &script)
activate the script callback locally now.
Definition: IObjectScriptingInterface.cpp:87
the game object will keep a list of script call backs.
Definition: IObjectScriptingInterface.h:12
int func_type
function type
Definition: IObjectScriptingInterface.h:15
different physics engine has different winding order.
Definition: EventBinding.h:32
virtual bool AddScriptCallback(int func_type, const string &script_func)
add a new call back handler.
Definition: IObjectScriptingInterface.cpp:24
virtual bool RemoveScriptCallback(int func_type)
remove a call back handler
Definition: IObjectScriptingInterface.cpp:58
ObjectCallbackPool_Type m_callback_scripts
the NPL script handlers
Definition: IObjectScriptingInterface.h:82
std::string script_func
the NPL file and function to be activated.
Definition: IObjectScriptingInterface.h:18
unsigned int m_nLastTick
last time this function is called.
Definition: IObjectScriptingInterface.h:22
int ActivateAsync(const std::string &code)
activate the script callback with the given code.
Definition: IObjectScriptingInterface.cpp:79
Definition: inftrees.h:24
Definition: IObjectScriptingInterface.h:6
virtual ScriptCallback * GetScriptCallback(int func_type)
return NULL if there is no associated script.
Definition: IObjectScriptingInterface.cpp:46
void SetScriptFunc(const std::string &script)
set the script function
Definition: IObjectScriptingInterface.cpp:71