My Project
|
A runtime state contains the scripting runtime stack and can be run in a single thread. More...
#include <NPLRuntimeState.h>
Classes | |
class | CCurrentMessage |
construct this to ensure matching calls to SetCurrentMessage(). More... | |
Public Types | |
typedef std::map< int, NPLTimer_ptr > | NPLTimer_Pool_Type |
typedef boost::signals2::signal< void(CNPLRuntimeState *pRuntimeState)> | Signal_StateLoaded_t |
![]() | |
typedef ParaEngine::weak_ptr< IObject, IAttributeFields > | WeakPtr_type |
![]() | |
typedef ParaEngine::weak_ptr< IObject > | WeakPtr_type |
![]() | |
enum | NPL_MemAllocatorType { MEM_ALLOC_TYPE_SYS_MALLOC, MEM_ALLOC_TYPE_POOL_MALLOC, MEM_ALLOC_TYPE_DL_MALLOC } |
NPL runs in its own thread. More... | |
Public Member Functions | |
CNPLRuntimeState (const string &name, NPLRuntimeStateType type_=NPLRuntimeStateType_NPL) | |
a type must be provided. More... | |
ATTRIBUTE_DEFINE_CLASS (CNPLRuntimeState) | |
virtual int | InstallFields (ParaEngine::CAttributeClass *pClass, bool bOverride) |
this class should be implemented if one wants to add new attribute. More... | |
ATTRIBUTE_METHOD1 (CNPLRuntimeState, GetProcessedMsgCount_s, int *) | |
ATTRIBUTE_METHOD1 (CNPLRuntimeState, GetCurrentQueueSize_s, int *) | |
ATTRIBUTE_METHOD1 (CNPLRuntimeState, GetTimerCount_s, int *) | |
ATTRIBUTE_METHOD1 (CNPLRuntimeState, SetMsgQueueSize_s, int) | |
ATTRIBUTE_METHOD1 (CNPLRuntimeState, GetMsgQueueSize_s, int *) | |
ATTRIBUTE_METHOD1 (CNPLRuntimeState, HasDebugHook_s, bool *) | |
ATTRIBUTE_METHOD1 (CNPLRuntimeState, IsPreemptive_s, bool *) | |
ATTRIBUTE_METHOD1 (CNPLRuntimeState, PauseAllPreemptiveFunction_s, bool) | |
ATTRIBUTE_METHOD1 (CNPLRuntimeState, IsAllPreemptiveFunctionPaused_s, bool *) | |
ATTRIBUTE_METHOD1 (CNPLRuntimeState, GetFileName_s, const char **) | |
void | Init () |
call this function before calling anything else. More... | |
void | Reset_Imp () |
reset NPL state. More... | |
void | Reset (const char *onResetScode=NULL) |
reset NPL state. More... | |
int | Run_Async () |
this function will create a worker thread to run Run(), and return immediately. More... | |
int | Run () |
this function does not return until the run time state is about to be destroyed. More... | |
int | Process () |
this function should be called whenever there are messages in the input_queue for processing. More... | |
virtual const string & | GetName () const |
return the name of this runtime state. More... | |
int | Stop () |
stop the thread by sending the quit message to this runtime state. More... | |
int | Stop_Async () |
same as Stop(), except that it just send the exist message, but does not wait for termination of the thread. More... | |
int | GetCurrentQueueSize () |
Get the current number of messages in the input message queue. More... | |
int | GetProcessedMsgCount () |
the total number of message processed by this runtime state since start. More... | |
int | GetMsgQueueSize () |
get the message queue size. More... | |
void | SetMsgQueueSize (int nSize=500) |
set the message queue size. More... | |
void | WaitForMessage (int nMessageCount=-1) |
simply wait for the next message to arrive. More... | |
NPLMessage_ptr | PeekMessage (int nIndex) |
NPLMessage_ptr | PopMessageAt (int nIndex) |
pop message at given index. More... | |
virtual const std::string & | GetIdentifier () |
virtual int | activate (const char *sNPLFilename, const char *sCode, int nCodeLength=0, int priority=2, int reliability=4) |
activate any runtime local or remote file. More... | |
template<typename StringType > | |
bool | LoadFile_any (const StringType &filepath, bool bReload=false, lua_State *L=0, bool bNoReturn=false) |
load a file without running it in this runtime state. More... | |
template<typename StringType > | |
NPLReturnCode | ActivateFile_any (const StringType &filepath, const char *code=NULL, int nLength=0) |
Activate a file(script or dll) in this runtime state. More... | |
virtual NPLReturnCode | Activate_async (const string &filepath, const char *code=NULL, int nLength=0, int priority=0) |
activate the specified file in this runtime state. More... | |
virtual NPLReturnCode | Loadfile_async (const string &filepath, int priority=0) |
virtual NPLReturnCode | Activate_async (NPLMessage_ptr &msg, int priority=0) |
same as Activate_async. More... | |
virtual NPLReturnCode | ActivateLocal (const char *filepath, const char *code=NULL, int nLength=0, int priority=0) |
same as Activate_async, except that it is a short cut name. More... | |
virtual NPLReturnCode | SendMessage (NPLMessage_ptr &msg, int priority=0) |
send a message to the current message queue. More... | |
virtual const char * | GetCurrentMsg () |
get a pointer to the current message. More... | |
virtual int | GetCurrentMsgLength () |
get length of the current message. More... | |
virtual INPLRuntime * | GetNPLRuntime () |
get the NPL runtime environment | |
virtual void | WriteLog (const char *text, int nTextLen=0, int nLogType=0) |
write a log message More... | |
int | GetTimerCount () |
[thread safe] | |
virtual bool | SetTimer (int nIDEvent, float fElapse, const char *sNeuronFile) |
creates a timer with the specified time-out value [thread safe] More... | |
virtual bool | KillTimer (int nIDEvent) |
Destroys the specified timer [thread safe]. More... | |
virtual bool | ChangeTimer (int nIDEvent, int dueTime, int period) |
Changes the start time and the interval between method invocations for a timer, using 32-bit signed integers to measure time intervals. More... | |
virtual INPLRuntimeState * | GetNPLStateInterface () |
get the INPLRuntimeState state interface. More... | |
virtual void | RegisterFile (const char *sFilename, INPLActivationFile *pFileHandler=NULL) |
function to register the a file handler in the current NPL state, so that it is callable from NPL script or C++ More... | |
virtual void | call (const char *sNPLFilename, const char *sCode, int nCodeLength=0) |
synchronous function call | |
std::string & | GetStringBuffer (int nIndex=0) |
get string buffer by index. More... | |
int | ProcessMsg (NPLMessage_ptr msg) |
function for processing a given msg More... | |
int | SendTick () |
any cross-frame pending messages are processed. More... | |
CNeuronFileState * | GetNeuronFileState (const std::string &filename, bool bCreateIfNotExist=true) |
get neuron file state. More... | |
bool | HasDebugHook () |
whether there is already a debug hook. More... | |
bool | IsPreemptive () |
whether we are currently running in a preemptive activation function. More... | |
bool | IsAllPreemptiveFunctionPaused () const |
whether all preemptive functions are paused for debugging purposes. More... | |
void | PauseAllPreemptiveFunction (bool val) |
template<typename StringType > | |
NPL::NPLReturnCode | ActivateFile_any (const StringType &filepath, const char *code, int nLength) |
![]() | |
virtual int | GetAttributeClassID () |
attribute class ID should be identical, unless one knows how overriding rules work. More... | |
virtual const char * | GetAttributeClassName () |
a static string, describing the attribute class object's name | |
virtual const char * | GetAttributeClassDescription () |
a static string, describing the attribute class object | |
virtual int | GetChildAttributeColumnCount () |
we support multi-dimensional child object. More... | |
virtual int | GetChildAttributeObjectCount (int nColumnIndex=0) |
get the number of child objects (row count) in the given column. More... | |
virtual IAttributeFields * | GetChildAttributeObject (int nRowIndex, int nColumnIndex=0) |
virtual IAttributeFields * | GetChildAttributeObject (const std::string &sName) |
get attribute by child object. More... | |
ATTRIBUTE_METHOD1 (IAttributeFields, GetName_s, const char **) | |
ATTRIBUTE_METHOD1 (IAttributeFields, SetName_s, const char *) | |
ATTRIBUTE_METHOD (IAttributeFields, PrintObject_s) | |
ATTRIBUTE_METHOD (IAttributeFields, AddRef_s) | |
ATTRIBUTE_METHOD1 (IAttributeFields, GetRefCount_s, int *) | |
ATTRIBUTE_METHOD1 (IAttributeFields, SetTime_s, int) | |
ATTRIBUTE_METHOD1 (IAttributeFields, GetTime_s, int *) | |
ATTRIBUTE_METHOD (IAttributeFields, Release_s) | |
virtual void | SetIdentifier (const std::string &sID) |
virtual bool | IsModified () |
whether some of the fields are modified.It is up to the implementation class to provide this functionality if necessary. More... | |
virtual void | SetModified (bool bModified) |
set whether any field has been modified. More... | |
virtual bool | ValidateFields () |
validate all fields and return true if validation passed. More... | |
virtual string | GetValidationMessage () |
get the recent validation message due to the most recent call to ValidateFields() | |
virtual bool | ResetField (int nFieldID) |
Reset the field to its initial or default value. More... | |
virtual bool | InvokeEditor (int nFieldID, const std::string &sParameters) |
Invoke an (external) editor for a given field. More... | |
virtual bool | AddChildAttributeObject (IAttributeFields *pChild, int nRowIndex=-1, int nColumnIndex=0) |
add child object. More... | |
virtual void * | QueryObjectByName (const std::string &sObjectType) |
convert to object of a given type. More... | |
virtual void * | QueryObject (int nObjectType) |
convert to object of a given type. More... | |
virtual int | GetTime () |
get the current local time in case it is animated in milli seconds frames. More... | |
virtual void | SetTime (int nTime) |
virtual CDynamicAttributeField * | GetDynamicField (const std::string &sName) |
Get a dynamic field with a given name. More... | |
virtual CDynamicAttributeField * | GetDynamicField (int nIndex) |
Get a dynamic field with a given index. More... | |
virtual const char * | GetDynamicFieldNameByIndex (int nIndex) |
get field name by index | |
virtual int | GetDynamicFieldCount () |
how many dynamic field this object currently have. More... | |
virtual int | SetDynamicField (const std::string &sName, const CVariable &value) |
set a dynamic field with a given name. More... | |
virtual int | AddDynamicField (const std::string &sName, ATTRIBUTE_FIELDTYPE dwType) |
add dynamic field and return field index | |
virtual void | RemoveAllDynamicFields () |
remove all dynamic fields | |
virtual int | SaveDynamicFieldsToString (std::string &output) |
save only text dynamic fields to fieldname = value text strings. More... | |
virtual int | LoadDynamicFieldsFromString (const std::string &input) |
load only text dynamic fields from string More... | |
CAttributeClass * | GetAttributeClass () |
get the main attribute class object. More... | |
void | PrintObject () |
print the content of this object to a text file at temp/doc/[ClassName].txt. More... | |
![]() | |
virtual void | Clone (IObject *obj) const |
Clone the object's contains to a pointer. More... | |
virtual IObject * | Clone () const |
Clone the object's contains and return a pointer to the newly created object. More... | |
virtual bool | Equals (const IObject *obj) const |
Compare the object with another object. More... | |
virtual const IType * | GetType () const |
virtual std::string | ToString () const |
WeakPtr_type & | GetWeakReference () |
get weak reference object. More... | |
virtual int | ProcessObjectEvent (const ObjectEvent &event) |
this function is only used to backward compatibility of ParaObject:AddEvent() function. More... | |
![]() | |
void | addref () const |
add reference count of the object. More... | |
bool | delref () const |
decrease reference count of the object. More... | |
int | GetRefCount () const |
get the reference count | |
virtual int | Release () |
CRefCounted * | AddToAutoReleasePool () |
addref and releases the ownership sometime soon automatically (usually at the end of the current frame). More... | |
![]() | |
virtual NPLReturnCode | Activate_async (const std::string &filepath, const char *code=NULL, int nLength=0, int priority=0)=0 |
activate the specified file in this runtime state. More... | |
![]() | |
CNPLScriptingState (bool bCreateState=true) | |
split registration to save compiling time. More... | |
int | GetLastReturnValue () const |
get the last return value from lua_pcall. More... | |
void | SetLastReturnValue (int val) |
lua_State * | GetLuaState () |
get the lua state. | |
bool | IsValid () |
return true if the runtime state is valid | |
void | LoadNPLLib () |
load only NPL related functions. More... | |
void | LoadParaLib () |
load only Para related functions. More... | |
void | LoadHAPI_Globals () |
load functions for scene management | |
void | LoadHAPI_SceneManager () |
load functions for scene management | |
void | LoadHAPI_ResourceManager () |
load functions for resource or assets management | |
void | LoadHAPI_UI () |
load functions for GUI controls and sounds | |
void | LoadHAPI_UI_Extension () |
this function is called by LoadHAPI_UI() | |
void | LoadHAPI_Audio () |
load functions for Audio Engine More... | |
void | LoadHAPI_Network () |
load functions for NPL Network Layer | |
void | LoadHAPI_AI () |
load functions for AI | |
void | LoadHAPI_NPL () |
load functions for neural parallel language | |
void | LoadHAPI_Jabber () |
load jabber related functions | |
bool | IsScriptFileLoaded (const string &filepath) |
whether a given script file is loaded. More... | |
bool | LoadFile (const string &filePath, bool bReload, lua_State *L=0, bool bNoReturn=false) |
load a new NPL script file without running it. More... | |
int | DoString (const char *sCode, int nLength=0, const char *sFileName=NULL, bool bPopReturnValue=true) |
do string in the current state. More... | |
NPL::NPLReturnCode | ActivateFile (const string &filepath, const char *code=NULL, int nLength=0) |
Activate a local file. More... | |
bool | BindFileActivateFunc (const object &funcActivate, const std::string &filename) |
bind the activation function. More... | |
const string & | GetFileName () |
get current file name which is being processed now. More... | |
const char * | GetCurrentFileName (lua_State *L=0) |
get current file that is being loaded or where the current code is defined. More... | |
bool | CreateSetState (lua_State *pLuaState=NULL) |
load or restore the runtime state no need to call LoadLuabind(), if the script runtime is created by this function More... | |
void | SetOwnLuaState (bool bOwn) |
if true, we will delete the luastate when this class is destroyed. More... | |
int | NPL_export (lua_State *L=0) |
set/get exported file module. More... | |
const std::map< std::string, int32 > & | GetLoadedFiles () |
NOT thread-safe: all loaded files mapping from filename to number of cached objects. More... | |
Public Attributes | |
Signal_StateLoaded_t | StateLoaded |
signal: called when state is first loaded | |
Protected Member Functions | |
void | LoadNPLState () |
load all NPL related functions. More... | |
int | TickTimers (DWORD nTickCount) |
this function is called often enough from the NPL runtime's main thread. More... | |
int | FrameMoveTick () |
void | SetCurrentMessage (const char *msg=NULL, int nLength=0) |
set the current message that is being processed. More... | |
IMonoScriptingState * | GetMonoState () |
get the mono scripting state. More... | |
void | SetPreemptive (bool val) |
![]() | |
virtual CAttributeClass * | CreateAttributeClass () |
initialize fields | |
virtual CDynamicAttributesSet * | GetDynamicAttributes (bool bCreateIfNotExist=false) |
![]() | |
void | DestroyState () |
destroy the runtime state careful with this function, it will make the state invalid. | |
void | LoadLuabind () |
the function must be called for the lua state before binding anything to it | |
void | SetRuntimeState (NPL::NPLRuntimeState_ptr runtime_state) |
set the current runtime state. More... | |
void | ProcessResult (int nResult, lua_State *L=0) |
Process return result after calling a function or loading a file in Lua. More... | |
int | CacheFileModule (const std::string &filename, int nResult, lua_State *L=0) |
save nResult objects on stack to file modules More... | |
int | PopFileModule (const std::string &filename, lua_State *L=0) |
pop file module to stack for a given file. More... | |
std::string | GetModuleFilePath (const std::string &modulename, lua_State *L=0) |
get module file path by module name | |
int | GetFileLoadStatus (const string &filepath) |
wrapping the m_loaded_files | |
void | SetFileLoadStatus (const string &filepath, int nStatus) |
Friends | |
class | CNPLRuntime |
Additional Inherited Members | |
![]() | |
static HRESULT | GetAttributeClassID_s (IAttributeFields *cls, int *p1) |
static HRESULT | GetAttributeClassName_s (IAttributeFields *cls, const char **p1) |
static bool | OpenWithDefaultEditor (const char *sFilename, bool bWaitOnReturn=false) |
Open a given file with the default registered editor in the game engine. More... | |
![]() | |
static int | GetNPLCodeFromFile (ParaEngine::CParaFile *pFile, char **pBuffer, int *pBufferSize) |
get the NPL code buffer and size according to a given file. More... | |
static void | AddSearchPath (const char *sSearchPath, bool bIsAdding=true) |
static function: More... | |
static uint32 | GetScriptDiskPath (const string &filePath, string &sFileName) |
we will first find if there is an up-to-date compiled version in the script/bin directory. More... | |
static NPL::NPLRuntimeState_ptr | GetRuntimeStateFromLuaObject (const object &obj) |
get pointer to NPLRuntimeState from the lua state object. More... | |
static NPL::NPLRuntimeState_ptr | GetRuntimeStateFromLuaState (lua_State *L) |
![]() | |
WeakPtr_type | m_weak_reference |
![]() | |
int | m_refcount |
A runtime state contains the scripting runtime stack and can be run in a single thread.
An NPL runtime state is message driven, however we also support timer and several other event callbacks.
NPL::CNPLRuntimeState::CNPLRuntimeState | ( | const string & | name, |
NPLRuntimeStateType | type_ = NPLRuntimeStateType_NPL |
||
) |
a type must be provided.
it defaults to NPL runtime state.
|
virtual |
activate any runtime local or remote file.
This function is usually called by dll interface.
Implements NPL::INPLRuntimeState.
|
virtual |
activate the specified file in this runtime state.
the file can be script or DLL. The function will just insert the message into the message queue and return immediately.
code | it is a chunk of code that should be executed in the destination neuron. this code usually set the values of POL global variables. |
nLength | the code length. if this is 0, length is determined from code, however, it must not exceed 4096 bytes. if it is specified. it can be any code length |
priority | bigger is higher. 0 is the default. if 1, it will be inserted to the front of the queue. |
|
virtual |
same as Activate_async.
except that input are read from NPLMesage. e.g. NPLMessage_ptr msg(new NPLMessage()); return Activate_async(msg, priority);
msg | the caller is should only new but never delete the NPLMessage_ptr. And that the message must be created in the same thread, usually just before calling this function |
Implements NPL::INPLRuntimeState.
NPLReturnCode NPL::CNPLRuntimeState::ActivateFile_any | ( | const StringType & | filepath, |
const char * | code = NULL , |
||
int | nLength = 0 |
||
) |
Activate a file(script or dll) in this runtime state.
The file should be loaded already.
filepath | pointer to the file path. it can be StringBuilder or std::string. |
|
virtual |
same as Activate_async, except that it is a short cut name.
and may be used by external dlls to activate a file on this local state asynchrounously.
Implements NPL::INPLRuntimeState.
|
virtual |
Changes the start time and the interval between method invocations for a timer, using 32-bit signed integers to measure time intervals.
[thread safe]
nIDEvent | Specifies the timer to be destroyed.For nIDEvent<=0, they are reserved for internal uses can not be killed by this function. This value must be the same as the nIDEvent value passed to the SetTimer function that created the timer. |
dueTime | The amount of time to delay before the invoking the callback method specified when the Timer was constructed, in milliseconds. Specify zero (0) to restart the timer immediately. however, the current implementation does not accept dueTime that is larger than MAX_TIMER_DUE_TIME 10000000, which is 10000 seconds. |
period:The | time interval between invocations of the callback method specified when the Timer was constructed, in milliseconds. |
Implements NPL::INPLRuntimeState.
|
virtual |
get a pointer to the current message.
This function is usually called by DLL plugin in the LibActivate function.
Implements NPL::INPLRuntimeState.
|
virtual |
get length of the current message.
This function is usually called by DLL plugin in the LibActivate function.
Implements NPL::INPLRuntimeState.
int NPL::CNPLRuntimeState::GetCurrentQueueSize | ( | ) |
Get the current number of messages in the input message queue.
Sometimes, a monitor or dispatcher logics may need to know the queue size of all NPL runtime states. and a dispatcher will usually need to add new messages to the NPL state with smallest queue size. This function will lock the message queue to retrieve the queue size, so do not call it very often, but use a timer to query it on some interval. [thread safe]
|
protected |
get the mono scripting state.
and create one from the NPLMono plugin, if one does not exist.
int NPL::CNPLRuntimeState::GetMsgQueueSize | ( | ) |
get the message queue size.
default to 500. For busy server side, we can set this to something like 5000 [thread safe]
|
inlinevirtual |
return the name of this runtime state.
if "", it is considered an anonymous name
Implements NPL::INPLRuntimeState.
NPL::CNeuronFileState * NPL::CNPLRuntimeState::GetNeuronFileState | ( | const std::string & | filename, |
bool | bCreateIfNotExist = true |
||
) |
get neuron file state.
|
inlinevirtual |
get the INPLRuntimeState state interface.
int NPL::CNPLRuntimeState::GetProcessedMsgCount | ( | ) |
the total number of message processed by this runtime state since start.
If this number does not increase, perhaps the processing is blocking somewhere, and we should take actions. [Not thread safe] in most cases, it will return correct result even in multi-threaded environment, but since we do not use lock, unexpected result may return. This function is usually used for stat printing and monitoring.
std::string & NPL::CNPLRuntimeState::GetStringBuffer | ( | int | nIndex = 0 | ) |
get string buffer by index.
Internally it is an array of std::strings.
bool NPL::CNPLRuntimeState::HasDebugHook | ( | ) |
whether there is already a debug hook.
Not thread-safe: can only be called from the current thread.
void NPL::CNPLRuntimeState::Init | ( | void | ) |
call this function before calling anything else.
It will load all NPL modules into the runtime state.
|
virtual |
this class should be implemented if one wants to add new attribute.
This function is always called internally.
Reimplemented from ParaEngine::IAttributeFields.
bool NPL::CNPLRuntimeState::IsAllPreemptiveFunctionPaused | ( | ) | const |
whether all preemptive functions are paused for debugging purposes.
bool NPL::CNPLRuntimeState::IsPreemptive | ( | ) |
whether we are currently running in a preemptive activation function.
Not thread-safe: can only be called from the current thread.
|
virtual |
Destroys the specified timer [thread safe].
nIDEvent | Specifies the timer to be destroyed.For nIDEvent<=0, they are reserved for internal uses can not be killed by this function. This value must be the same as the nIDEvent value passed to the SetTimer function that created the timer. |
Implements NPL::INPLRuntimeState.
bool NPL::CNPLRuntimeState::LoadFile_any | ( | const StringType & | filepath, |
bool | bReload = false , |
||
lua_State * | L = 0 , |
||
bool | bNoReturn = false |
||
) |
load a file without running it in this runtime state.
If the file is already loaded,it will not be loaded again. If the file extension is ".dll", it will be treated as a plug-in. if the filepath is "*.dll", it means all DLLs in that directory. IMPORTANT: unlike other activation functions, this is more like "include()", the function will be loaded where it is and returned to the original caller upon finishing.
filePath | the local file path, it can be StringBuilder or std::string. |
bReload | if true, the file will be reloaded even if it is already loaded. otherwise, the file will only be loaded if it is not loaded yet. |
bNoReturn | generate no return on lua_state's stack. |
|
protected |
load all NPL related functions.
This function must be called for all scripting based classes.
NPL::NPLMessage_ptr NPL::CNPLRuntimeState::PeekMessage | ( | int | nIndex | ) |
NPL::NPLMessage_ptr NPL::CNPLRuntimeState::PopMessageAt | ( | int | nIndex | ) |
pop message at given index.
usually we need to call peek() first.
int NPL::CNPLRuntimeState::Process | ( | void | ) |
this function should be called whenever there are messages in the input_queue for processing.
one can call this function regularly using a timer(the main game thread does this), or wait on the m_semaphore object when input_queue has items (almost all other secondary runtime states use this).
int NPL::CNPLRuntimeState::ProcessMsg | ( | NPLMessage_ptr | msg | ) |
function for processing a given msg
|
virtual |
function to register the a file handler in the current NPL state, so that it is callable from NPL script or C++
sFilename | any name with cpp file extension can be used. usually it is "states.cpp". The name does not need to be same as the real cpp file. |
pFileHandler | if NULL it will unregister. If not, it is the file handler pointer, the pointer must be always valid, it is usually a static singleton object. |
Implements NPL::INPLRuntimeState.
void NPL::CNPLRuntimeState::Reset | ( | const char * | onResetScode = NULL | ) |
reset NPL state.
it will put MSG_TYPE_RESET to the input queue of this runtime process, and wait for the next cycle to call Reset_Imp(). all NPL and table memory will be released. This function is usually called in case of a soft ParaEngine restart.
onResetScode | the code to be executed immediately after runtime state is reset. default to NULL. |
void NPL::CNPLRuntimeState::Reset_Imp | ( | ) |
reset NPL state.
This function must not be called by the NPL state itself. all NPL and table memory will be released. This function is usually called in case of a soft ParaEngine restart.
int NPL::CNPLRuntimeState::Run | ( | void | ) |
this function does not return until the run time state is about to be destroyed.
it wait on the m_semaphore object when input_queue has items, and process messages in input_queue.
int NPL::CNPLRuntimeState::Run_Async | ( | ) |
this function will create a worker thread to run Run(), and return immediately.
This is the advised way to start the runtime state.
|
virtual |
send a message to the current message queue.
This function is rarely needed to call directly, use Activate_async instead. e.g. NPLMessage_ptr msg(new NPLMessage()); return SendMessage(msg, priority);
msg | the message to send. Please note that when the function returns, the msg will be reset to null. |
Implements NPL::INPLRuntimeState.
int NPL::CNPLRuntimeState::SendTick | ( | ) |
any cross-frame pending messages are processed.
|
protected |
set the current message that is being processed.
void NPL::CNPLRuntimeState::SetMsgQueueSize | ( | int | nSize = 500 | ) |
set the message queue size.
default to 500. For busy server side, we can set this to something like 5000 [thread safe]
|
virtual |
creates a timer with the specified time-out value [thread safe]
nIDEvent | Specifies a positive timer identifier. For nIDEvent<=0, they are reserved for internal uses. If the NPL runtime already has a timer with the value nIDEvent, then the existing timer is replaced by the new timer. When SetTimer replaces a timer, the timer is reset. |
fElapse | Specifies the time-out value, in seconds. Please note that a timer will not be repeatedly activated if its timeout is shorter than the frame rate of the NPL simulation pipeline . |
sNeuronFile | The NPL file to be activated when the time-out value elapses. For more information about the file name See NPL.activate(). |
Implements NPL::INPLRuntimeState.
int NPL::CNPLRuntimeState::Stop | ( | void | ) |
stop the thread by sending the quit message to this runtime state.
this function will only return when the thread is quit. so never call this function from the same thread, otherwise it is a deadlock. Usually this function is called from the main NPL runtime thread.
int NPL::CNPLRuntimeState::Stop_Async | ( | ) |
same as Stop(), except that it just send the exist message, but does not wait for termination of the thread.
|
protected |
this function is called often enough from the NPL runtime's main thread.
[thread safe]
nTickCount | it should be ::GetTickCount() in millisecond. if 0, we will call the system ::GetTickCount() to get the current tick count. |
void NPL::CNPLRuntimeState::WaitForMessage | ( | int | nMessageCount = -1 | ) |
simply wait for the next message to arrive.
nMessageCount | if not negative, this function will immediately return when the message queue size is bigger than this value. |
|
virtual |
write a log message
text | the content of the log message. |
nTextLen | the log text length in byte. if 0, text length will be determined automatically. |
nLogType | if this is 0, it is a normal log message. if this is 1, we will print current time, and runtime state name with the log message. |
Implements NPL::INPLRuntimeState.