2 #include "NPLMessageQueue.h" 3 #include "NPLScriptingState.h" 5 #include "NeuronFileState.h" 6 #include "INPLRuntimeState.h" 7 #include "INPLScriptingState.h" 8 #include "IAttributeFields.h" 9 #include "util/mutex.h" 10 #include "util/unordered_array.hpp" 13 #include <boost/thread.hpp> 14 #include <boost/noncopyable.hpp> 15 #include <boost/shared_ptr.hpp> 16 #include <boost/enable_shared_from_this.hpp> 21 struct DLLPlugInEntity;
26 class INPLActivationFile;
27 class CNeuronFileState;
39 public boost::enable_shared_from_this<CNPLRuntimeState>,
40 private boost::noncopyable
43 typedef std::map<int,NPLTimer_ptr> NPLTimer_Pool_Type;
44 typedef boost::signals2::signal<void(CNPLRuntimeState* pRuntimeState)> Signal_StateLoaded_t;
47 CNPLRuntimeState(
const string & name, NPLRuntimeStateType type_ = NPLRuntimeStateType_NPL);
55 ATTRIBUTE_METHOD1(
CNPLRuntimeState, GetProcessedMsgCount_s,
int*) { *p1 = cls->GetProcessedMsgCount();
return S_OK; }
56 ATTRIBUTE_METHOD1(
CNPLRuntimeState, GetCurrentQueueSize_s,
int*) { *p1 = cls->GetCurrentQueueSize();
return S_OK; }
57 ATTRIBUTE_METHOD1(
CNPLRuntimeState, GetTimerCount_s,
int*) { *p1 = cls->GetTimerCount();
return S_OK; }
58 ATTRIBUTE_METHOD1(
CNPLRuntimeState, SetMsgQueueSize_s,
int) { cls->SetMsgQueueSize(p1);
return S_OK; }
59 ATTRIBUTE_METHOD1(
CNPLRuntimeState, GetMsgQueueSize_s,
int*) { *p1 = cls->GetMsgQueueSize();
return S_OK; }
60 ATTRIBUTE_METHOD1(
CNPLRuntimeState, HasDebugHook_s,
bool*) { *p1 = cls->HasDebugHook();
return S_OK; }
61 ATTRIBUTE_METHOD1(
CNPLRuntimeState, IsPreemptive_s,
bool*) { *p1 = cls->IsPreemptive();
return S_OK; }
62 ATTRIBUTE_METHOD1(
CNPLRuntimeState, PauseAllPreemptiveFunction_s,
bool) { cls->PauseAllPreemptiveFunction(p1);
return S_OK; }
63 ATTRIBUTE_METHOD1(
CNPLRuntimeState, IsAllPreemptiveFunctionPaused_s,
bool*) { *p1 = cls->IsAllPreemptiveFunctionPaused();
return S_OK; }
64 ATTRIBUTE_METHOD1(
CNPLRuntimeState, GetFileName_s,
const char**) { *p1 = cls->GetCurrentFileName();
return S_OK; }
78 void Reset(
const char* onResetScode = NULL);
99 virtual const string&
GetName()
const {
return m_name;}
114 int GetCurrentQueueSize();
121 int GetProcessedMsgCount();
126 int GetMsgQueueSize();
131 void SetMsgQueueSize(
int nSize = 500);
137 void WaitForMessage(
int nMessageCount = -1);
143 NPLMessage_ptr PeekMessage(
int nIndex);
148 NPLMessage_ptr PopMessageAt(
int nIndex);
151 virtual const std::string& GetIdentifier();
154 virtual int activate(
const char * sNPLFilename,
const char* sCode,
int nCodeLength=0,
int priority=2,
int reliability=4);
168 template <
typename StringType>
169 bool LoadFile_any(
const StringType & filepath,
bool bReload =
false,
lua_State* L = 0,
bool bNoReturn =
false);
175 template <
typename StringType>
176 NPLReturnCode ActivateFile_any(
const StringType& filepath,
const char *
code = NULL,
int nLength=0);
186 virtual NPLReturnCode Activate_async(
const string & filepath,
const char *
code = NULL,
int nLength=0,
int priority=0);
187 virtual NPLReturnCode Loadfile_async(
const string & filepath,
int priority = 0);
195 virtual NPLReturnCode Activate_async(NPLMessage_ptr& msg,
int priority=0);
198 virtual NPLReturnCode ActivateLocal(
const char* filepath,
const char *
code = NULL,
int nLength=0,
int priority=0);
208 virtual NPLReturnCode SendMessage(NPLMessage_ptr& msg,
int priority=0);
212 virtual const char* GetCurrentMsg();
215 virtual int GetCurrentMsgLength();
225 virtual void WriteLog(
const char* text,
int nTextLen=0,
int nLogType = 0);
246 virtual bool SetTimer(
int nIDEvent,
float fElapse,
const char* sNeuronFile);
255 virtual bool KillTimer(
int nIDEvent);
267 virtual bool ChangeTimer(
int nIDEvent,
int dueTime,
int period);
276 virtual void RegisterFile(
const char* sFilename,
INPLActivationFile* pFileHandler = NULL);
279 virtual void call(
const char * sNPLFilename,
const char* sCode,
int nCodeLength = 0);;
282 std::string& GetStringBuffer(
int nIndex = 0);
291 int ProcessMsg(NPLMessage_ptr msg);
297 CNeuronFileState* GetNeuronFileState(
const std::string& filename,
bool bCreateIfNotExist =
true);
310 bool IsAllPreemptiveFunctionPaused()
const;
311 void PauseAllPreemptiveFunction(
bool val);
323 int TickTimers(DWORD nTickCount);
333 m_pState->SetCurrentMessage(msg,nLength);
337 m_pState->SetCurrentMessage(NULL, 0);
342 void SetCurrentMessage(
const char* msg=NULL,
int nLength = 0);
347 void SetPreemptive(
bool val);
349 typedef map<std::string, ParaEngine::DLLPlugInEntity*> DLL_Plugin_Map_Type;
350 typedef std::vector<NPLTimer_ptr> NPLTimer_TempPool_Type;
352 DLL_Plugin_Map_Type m_dll_plugins_map;
358 NPLTimer_Pool_Type m_activeTimers;
360 NPLTimer_TempPool_Type m_temp_timer_pool;
363 const NPLRuntimeStateType m_type;
375 boost::condition_variable m_semaphore;
378 bool m_bUseMessageEvent;
381 bool m_bIsProcessing;
384 bool m_bIsPreemptive;
387 bool m_bPauseAllPreemptiveFunction;
390 const char* m_current_msg;
393 int m_current_msg_length;
398 int m_processed_msg_count;
401 int m_nFrameMoveCount;
407 std::vector <std::string> m_string_buffers;
410 std::map<std::string, INPLActivationFile*> m_act_files_cpp;
415 std::map<std::string, CNeuronFileState*> m_neuron_files;
427 bool operator()(
const NPLRuntimeState_ptr & a,
const NPLRuntimeState_ptr & b )
const 428 {
return a.get() < b.get(); }
compare functions for runtime state ptr
Definition: NPLRuntimeState.h:425
an attribute class is a collection of attribute fields.
Definition: AttributeClass.h:10
virtual const string & GetName() const
return the name of this runtime state.
Definition: NPLRuntimeState.h:99
define this to enable debugging of NPL code in visual studio
Definition: INPL.h:9
virtual INPLRuntimeState * GetNPLStateInterface()
get the INPLRuntimeState state interface.
Definition: NPLRuntimeState.h:270
INPLRuntimeState interface for DLL interface.
Definition: INPLRuntimeState.h:27
different physics engine has different winding order.
Definition: EventBinding.h:32
Definition: unordered_array.hpp:9
A runtime state contains the scripting runtime stack and can be run in a single thread.
Definition: NPLRuntimeState.h:35
Signal_StateLoaded_t StateLoaded
signal: called when state is first loaded
Definition: NPLRuntimeState.h:286
Message queue implementation.
Definition: NPLMessageQueue.h:301
a NPL scripting state (wrapper of lua State), for binding c++ classes to lua.
Definition: NPLScriptingState.h:23
CNPLRuntime is a wrapper of the NPL application programming interface (NPL API).
Definition: NPLRuntime.h:64
Definition: minilua.c:461
A common interface for all classes implementing IAttributeFields By implementing this class's virtual...
Definition: IAttributeFields.h:59
Definition: inftrees.h:24
Definition: INPLAcitvationFile.h:18
construct this to ensure matching calls to SetCurrentMessage().
Definition: NPLRuntimeState.h:328
This is the NPLMono DLL plugin interface.
Definition: INPLScriptingState.h:90
cross platform mutex
Definition: mutex.h:95
NPL Runtime Environment interface.
Definition: INPLRuntime.h:30
each neuron file that is activated will have a CNeuronFileState structure kept.
Definition: NeuronFileState.h:14