My Project
|
CNPLRuntime is a wrapper of the NPL application programming interface (NPL API). More...
#include <NPLRuntime.h>
Public Member Functions | |
CNPLRuntime () | |
command line: local="config/local.ini" | |
virtual void | Init () |
initialize NPL runtime environment | |
virtual void | Run (bool bToEnd=true) |
call this function regularly, to process packages. More... | |
virtual void | Cleanup () |
clean up the NPL runtime environment | |
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 | InstallFields (ParaEngine::CAttributeClass *pClass, bool bOverride) |
this class should be implemented if one wants to add new attribute. More... | |
virtual int | GetChildAttributeObjectCount (int nColumnIndex=0) |
get the number of child objects (row count) in the given column. More... | |
virtual ParaEngine::IAttributeFields * | GetChildAttributeObject (int nRowIndex, int nColumnIndex=0) |
ATTRIBUTE_METHOD1 (CNPLRuntime, IsServerStarted_s, bool *) | |
ATTRIBUTE_METHOD1 (CNPLRuntime, GetHostIP_s, const char **) | |
ATTRIBUTE_METHOD1 (CNPLRuntime, GetHostPort_s, const char **) | |
ATTRIBUTE_METHOD1 (CNPLRuntime, IsTCPKeepAliveEnabled_s, bool *) | |
ATTRIBUTE_METHOD1 (CNPLRuntime, SetTCPKeepAlive_s, bool) | |
ATTRIBUTE_METHOD1 (CNPLRuntime, IsKeepAliveEnabled_s, bool *) | |
ATTRIBUTE_METHOD1 (CNPLRuntime, SetKeepAlive_s, bool) | |
ATTRIBUTE_METHOD1 (CNPLRuntime, IsIdleTimeoutEnabled_s, bool *) | |
ATTRIBUTE_METHOD1 (CNPLRuntime, EnableIdleTimeout_s, bool) | |
ATTRIBUTE_METHOD1 (CNPLRuntime, GetIdleTimeoutPeriod_s, int *) | |
ATTRIBUTE_METHOD1 (CNPLRuntime, SetIdleTimeoutPeriod_s, int) | |
ATTRIBUTE_METHOD1 (CNPLRuntime, GetCompressionLevel_s, int *) | |
ATTRIBUTE_METHOD1 (CNPLRuntime, SetCompressionLevel_s, int) | |
ATTRIBUTE_METHOD1 (CNPLRuntime, GetCompressionThreshold_s, int *) | |
ATTRIBUTE_METHOD1 (CNPLRuntime, SetCompressionThreshold_s, int) | |
ATTRIBUTE_METHOD1 (CNPLRuntime, IsAnsiMode_s, bool *) | |
ATTRIBUTE_METHOD1 (CNPLRuntime, EnableAnsiMode_s, bool) | |
ATTRIBUTE_METHOD1 (CNPLRuntime, GetMaxPendingConnections_s, int *) | |
ATTRIBUTE_METHOD1 (CNPLRuntime, SetMaxPendingConnections_s, int) | |
ATTRIBUTE_METHOD1 (CNPLRuntime, GetLogLevel_s, int *) | |
ATTRIBUTE_METHOD1 (CNPLRuntime, SetLogLevel_s, int) | |
virtual void | SetUseCompression (bool bCompressIncoming, bool bCompressOutgoing) |
whether to use compression on transport layer for incoming and outgoing connections More... | |
virtual void | SetCompressionKey (const byte *sKey=0, int nSize=0, int nUsePlainTextEncoding=0) |
set the compression method of incoming the outgoing messages. More... | |
virtual void | SetCompressionLevel (int nLevel) |
Set the zlib compression level to use in case compression is enabled. More... | |
virtual int | GetCompressionLevel () |
virtual void | SetCompressionThreshold (int nThreshold) |
set the default compression threshold for all connections on this machine. More... | |
virtual int | GetCompressionThreshold () |
virtual void | SetTCPKeepAlive (bool bEnable) |
System level Enable/disable SO_KEEPALIVE. More... | |
virtual bool | IsTCPKeepAliveEnabled () |
whether SO_KEEPALIVE is enabled. More... | |
virtual void | SetKeepAlive (bool bEnable) |
enable application level keep alive. More... | |
virtual bool | IsKeepAliveEnabled () |
virtual void | EnableIdleTimeout (bool bEnable) |
Enable idle timeout. More... | |
virtual bool | IsIdleTimeoutEnabled () |
virtual void | SetIdleTimeoutPeriod (int nMilliseconds) |
how many milliseconds of inactivity to assume this connection should be timed out. More... | |
virtual int | GetIdleTimeoutPeriod () |
virtual void | EnableAnsiMode (bool bEnable) |
whether the first line of the NPL protocol is in ansi code page. More... | |
virtual bool | IsAnsiMode () |
virtual int | GetMaxPendingConnections () |
queue size of the server acceptor's queue. More... | |
virtual void | SetMaxPendingConnections (int val) |
virtual const std::string & | GetHostPort () |
get the host port of this NPL runtime | |
virtual const std::string & | GetHostIP () |
get the host IP of this NPL runtime | |
virtual bool | IsServerStarted () |
whether the NPL runtime's http server is started. More... | |
void | NPL_LoadFile (NPLRuntimeState_ptr runtime_state, const char *filePath, bool bReload) |
load a file (in the specified runtime state) without running it. More... | |
int | NPL_Activate (NPLRuntimeState_ptr runtime_state, const char *sNeuronFile, const char *code=NULL, int nLength=0, int channel=0, int priority=2, int reliability=3) |
activate the specified file. More... | |
virtual int | Activate (INPLRuntimeState *pRuntimeState, const char *sNeuronFile, const char *code=NULL, int nLength=0, int channel=0, int priority=2, int reliability=3) |
same as NPL_Activate | |
virtual int | ActivateLocalNow (const char *sNeuronFile, const char *code=NULL, int nLength=0) |
activate immediately for the local file (may be in different thread). More... | |
void | NPL_StartNetServer (const char *server=NULL, const char *port=NULL) |
start the NPL net server's io_service loop. More... | |
void | NPL_StopNetServer () |
stop the net server | |
void | NPL_AddPublicFile (const string &filename, int nID) |
add a nID, filename pair to the public file list. More... | |
void | NPL_ClearPublicFiles () |
clear all public files, so that the NPL server will be completely private. More... | |
string | NPL_GetIP (const char *nid) |
get the ip address of given NPL connection. More... | |
void | NPL_accept (const char *tid, const char *nid=NULL) |
accept a given connection. More... | |
void | NPL_SetProtocol (const char *nid, int protocolType=0) |
set transmission protocol, default value is 0. More... | |
void | NPL_reject (const char *nid, int nReason=0) |
reject and close a given connection. More... | |
virtual void | StartNetServer (const char *server=NULL, const char *port=NULL) |
start the NPL net server's io_service loop. More... | |
virtual void | StopNetServer () |
stop the net server | |
virtual void | AddPublicFile (const string &filename, int nID) |
virtual void | ClearPublicFiles () |
clear all public files, so that the NPL server will be completely private. More... | |
virtual void | GetIP (const char *nid, char *pOutput) |
get the ip address of given NPL connection. More... | |
virtual void | accept (const char *tid, const char *nid=NULL) |
accept a given connection. More... | |
virtual void | reject (const char *nid, int nReason=0) |
reject and close a given connection. More... | |
virtual ParaEngine::INPLJabberClient * | GetJabberClient (const char *sJID) |
get an existing jabber client instance interface by its JID. More... | |
virtual ParaEngine::INPLJabberClient * | CreateJabberClient (const char *sJID) |
Create a new jabber client instance with the given jabber client ID. More... | |
virtual bool | CloseJabberClient (const char *sJID) |
close a given jabber client instance. More... | |
virtual bool | AppendURLRequest (ParaEngine::CURLRequestTask *pUrlTask, const char *sPoolName=NULL) |
Append URL request to a pool. More... | |
virtual bool | ChangeRequestPoolSize (const char *sPoolName, int nCount) |
There is generally no limit to the number of requests sent. More... | |
virtual void | AsyncDownload (const char *url, const char *destFolder, const char *callbackScript, const char *DownloaderName) |
Asynchronously download a file from the url. More... | |
virtual void | CancelDownload (const char *DownloaderName) |
cancel all asynchronous downloads that matches a certain downloader name pattern More... | |
virtual int | Download (const char *url, const char *destFolder, const char *callbackScript, const char *DownloaderName) |
Synchronous call of the function AsyncDownload(). More... | |
void | NPL_RegisterWSCallBack (const char *sWebServiceFile, const char *sCode) |
this method will associate a web service (method) with either a sCode, which will be called when the web service returned. More... | |
void | NPL_UnregisterWSCallBack (const char *sWebServiceFile) |
unregister web service call back for a given file. More... | |
bool | NPL_SetTimer (NPLRuntimeState_ptr runtime_state, int nIDEvent, float fElapse, const char *sNeuronFile) |
creates a timer with the specified time-out value [thread safe] More... | |
bool | NPL_KillTimer (NPLRuntimeState_ptr runtime_state, int nIDEvent) |
Destroys the specified timer [thread safe]. More... | |
bool | NPL_ChangeTimer (NPLRuntimeState_ptr runtime_state, 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 void | NPL_AddDNSRecord (const char *sDNSName, const char *sAddress) |
add a DNS server record to the current NPL runtime. More... | |
virtual void | NPL_SetDefaultChannel (int channel_ID) |
Set the default channel ID, default value is 0. More... | |
virtual int | NPL_GetDefaultChannel () |
Get the default channel ID, default value is 0. More... | |
virtual void | NPL_SetChannelProperty (int channel_ID, int priority, int reliability) |
Messages can be sent via predefined channels. More... | |
virtual void | NPL_ResetChannelProperties () |
reset all 16 predefined channel properties. More... | |
virtual void | NPL_GetChannelProperty (int channel_ID, int *priority, int *reliability) |
see also NPL_SetChannelProperty More... | |
void | NPL_EnableNetwork (bool bEnable, const char *CenterName, const char *password) |
OBSOLETED: Enable the network, by default the network layer is disabled. More... | |
const string & | NPL_GetSourceName () |
get the current activation's source name. More... | |
void | NPL_SetSourceName (const char *sName) |
Set the current activation's source name. More... | |
int | GetLogLevel () const |
void | SetLogLevel (int val) |
virtual INPLRuntimeState * | CreateState (const char *name, NPLRuntimeStateType type_=NPLRuntimeStateType_NPL) |
create a new runtime state. More... | |
virtual INPLRuntimeState * | GetState (const char *name) |
get a runtime state with an explicit name. More... | |
virtual INPLRuntimeState * | CreateGetState (const char *name, NPLRuntimeStateType type_=NPLRuntimeStateType_NPL) |
it get runtime state first, if none exist, it will create one and add it to the main threaded state | |
virtual bool | DeleteState (INPLRuntimeState *pRuntime_state) |
create a given runtime state. More... | |
virtual INPLRuntimeState * | GetMainState () |
get the default (main) runtime state. More... | |
virtual bool | AddToMainThread (INPLRuntimeState *runtime_state) |
add a given runtime state to the main game thread. More... | |
NPLRuntimeState_ptr | CreateRuntimeState (const string &name, NPLRuntimeStateType type_=NPLRuntimeStateType_NPL) |
create a new runtime state. More... | |
NPLRuntimeState_ptr | GetRuntimeState (const string &name) |
get a runtime state with an explicit name. More... | |
NPLRuntimeState_ptr | CreateGetRuntimeState (const string &name, NPLRuntimeStateType type_=NPLRuntimeStateType_NPL) |
it get runtime state first, if none exist, it will create one and add it to the main threaded state | |
bool | DeleteRuntimeState (NPLRuntimeState_ptr runtime_state) |
create a given runtime state. More... | |
NPLRuntimeState_ptr | GetMainRuntimeState () |
get the default (main) runtime state. More... | |
bool | AddStateToMainThread (NPLRuntimeState_ptr runtime_state) |
add a given runtime state to the main game thread. More... | |
bool | RemoveStateFromMainThread (NPLRuntimeState_ptr runtime_state) |
remove a given runtime state from the main game thread. More... | |
CNPLNetServer * | GetNetServer () |
get the NPL net server | |
ParaEngine::CNPLNetClient * | GetNetClient () |
get the Net client implementation. More... | |
void | SetHostMainStatesInFrameMove (bool bHostMainStatesInFrameMove) |
whether we will process messages in the main threads in the frame move function. More... | |
![]() | |
virtual int | GetChildAttributeColumnCount () |
we support multi-dimensional child object. More... | |
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 const std::string & | GetIdentifier () |
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 void | AddPublicFile (const std::string &filename, int nID)=0 |
add a nID, filename pair to the public file list. More... | |
Static Public Member Functions | |
static CNPLRuntime * | GetInstance () |
the singleton instance | |
static void | SetDefaultNPLStateType (NPL::NPLRuntimeStateType val) |
if one wants to change the default runtime state, such as using external luastate, one need to call this function before GetInstance(). More... | |
static INPLStimulationPipe * | GetNetworkLayerPipe () |
Get the network layer pipe. More... | |
![]() | |
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... | |
Additional Inherited Members | |
![]() | |
typedef ParaEngine::weak_ptr< IObject, IAttributeFields > | WeakPtr_type |
![]() | |
typedef ParaEngine::weak_ptr< IObject > | WeakPtr_type |
![]() | |
virtual CAttributeClass * | CreateAttributeClass () |
initialize fields | |
virtual CDynamicAttributesSet * | GetDynamicAttributes (bool bCreateIfNotExist=false) |
![]() | |
WeakPtr_type | m_weak_reference |
![]() | |
int | m_refcount |
CNPLRuntime is a wrapper of the NPL application programming interface (NPL API).
it is normally used as a singleton class.
|
virtual |
accept a given connection.
The connection will be regarded as authenticated once accepted. [thread safe]
tid | the temporary id or NID of the connection to be accepted. usually it is from msg.tid or msg.nid. |
nid | if this is not nil, tid will be renamed to nid after accepted. |
Implements NPL::INPLRuntime.
|
virtual |
activate immediately for the local file (may be in different thread).
bool CNPLRuntime::AddStateToMainThread | ( | NPLRuntimeState_ptr | runtime_state | ) |
add a given runtime state to the main game thread.
this function is thread safe
|
virtual |
add a given runtime state to the main game thread.
this function is thread safe
Implements NPL::INPLRuntime.
|
virtual |
Append URL request to a pool.
pUrlTask | must be new CURLRequestTask(), the ownership of the task is transfered to the manager. so the caller should never delete the pointer. |
sPoolName | the request pool name. If the pool does not exist, it will be created. If null, the default pool is used. |
Implements NPL::INPLRuntime.
|
virtual |
Asynchronously download a file from the url.
callbackScript | script code to be called, a global variable called msg is assigned, as below msg = {DownloadState=""|"complete"|"terminated", totalFileSize=number, currentFileSize=number, PercentDone=number} |
Implements NPL::INPLRuntime.
|
virtual |
cancel all asynchronous downloads that matches a certain downloader name pattern
DownloaderName:regular | expression. such as "proc1", "proc1.*", ".*" |
Implements NPL::INPLRuntime.
|
virtual |
There is generally no limit to the number of requests sent.
However, each pool has a specified maximum number of concurrent worker slots. the default number is 1. One can change this number with this function.
Implements NPL::INPLRuntime.
|
virtual |
clear all public files, so that the NPL server will be completely private.
[thread safe]
Implements NPL::INPLRuntime.
|
virtual |
close a given jabber client instance.
Basically, there is no need to close a web service, unless one wants to reopen it with different credentials
sJID | such as "lixizhi@paraweb3d.com" |
Implements NPL::INPLRuntime.
|
virtual |
Create a new jabber client instance with the given jabber client ID.
It does not open a connection immediately.
sJID | such as "lixizhi@paraweb3d.com" |
Implements NPL::INPLRuntime.
NPL::NPLRuntimeState_ptr CNPLRuntime::CreateRuntimeState | ( | const string & | name, |
NPLRuntimeStateType | type_ = NPLRuntimeStateType_NPL |
||
) |
create a new runtime state.
this function is thread safe
name | if "", it is an anonymous runtime state. otherwise it should be a unique name. |
type_ | the runtime state type. |
|
virtual |
create a new runtime state.
this function is thread safe
name | if "", it is an anonymous runtime state. otherwise it should be a unique name. |
type_ | the runtime state type. |
Implements NPL::INPLRuntime.
bool CNPLRuntime::DeleteRuntimeState | ( | NPLRuntimeState_ptr | runtime_state | ) |
create a given runtime state.
this function is thread safe
|
virtual |
|
virtual |
Synchronous call of the function AsyncDownload().
This function will not return until download is complete or an error occurs. this function is rarely used. AsyncDownload() is used.
Implements NPL::INPLRuntime.
|
virtual |
|
virtual |
Enable idle timeout.
This is the application level timeout setting. We will create a global timer which examines all send/receive time of all open connections, if a connection is inactive (idle for GetIdleTimeoutPeriod()) we will
Implements NPL::INPLRuntime.
|
inlinevirtual |
attribute class ID should be identical, unless one knows how overriding rules work.
Reimplemented from ParaEngine::IAttributeFields.
|
virtual |
get the number of child objects (row count) in the given column.
please note different columns can have different row count.
Reimplemented from ParaEngine::IAttributeFields.
|
virtual |
get the ip address of given NPL connection.
this function is usually called by the server for connected clients.
nid | nid or tid. |
pOutPut | it must be at least [256] bytes big, that receives the output. |
Implements NPL::INPLRuntime.
|
virtual |
get an existing jabber client instance interface by its JID.
If the client is not created using CreateJabberClient() before, function may return NULL.
sJID | such as "lixizhi@paraweb3d.com" |
Implements NPL::INPLRuntime.
NPL::NPLRuntimeState_ptr CNPLRuntime::GetMainRuntimeState | ( | ) |
get the default (main) runtime state.
|
virtual |
get the default (main) runtime state.
Implements NPL::INPLRuntime.
|
virtual |
queue size of the server acceptor's queue.
ParaEngine::CNPLNetClient* NPL::CNPLRuntime::GetNetClient | ( | ) |
get the Net client implementation.
|
static |
Get the network layer pipe.
NPL::NPLRuntimeState_ptr CNPLRuntime::GetRuntimeState | ( | const string & | name | ) |
get a runtime state with an explicit name.
this function is thread safe
name | the name of the runtime state. if empty or "main", the main runtime state is returned. |
|
virtual |
get a runtime state with an explicit name.
this function is thread safe
name | the name of the runtime state. if NULL or "main", the main runtime state is returned. |
Implements NPL::INPLRuntime.
|
virtual |
this class should be implemented if one wants to add new attribute.
This function is always called internally.
Reimplemented from ParaEngine::IAttributeFields.
|
virtual |
whether the NPL runtime's http server is started.
|
virtual |
void CNPLRuntime::NPL_accept | ( | const char * | tid, |
const char * | nid = NULL |
||
) |
accept a given connection.
The connection will be regarded as authenticated once accepted. [thread safe]
tid | the temporary id or NID of the connection to be accepted. usually it is from msg.tid or msg.nid. |
nid | if this is not nil, tid will be renamed to nid after accepted. |
int CNPLRuntime::NPL_Activate | ( | NPLRuntimeState_ptr | runtime_state, |
const char * | sNeuronFile, | ||
const char * | code = NULL , |
||
int | nLength = 0 , |
||
int | channel = 0 , |
||
int | priority = 2 , |
||
int | reliability = 3 |
||
) |
activate the specified file.
It can either be local or remote file.
pState | the source runtime state that initiated this activation. If pState is NULL, the main runtime state is used. |
sNPLFileName | a globally unique name of a NPL file name instance. The string format of an NPL file name is like below. [(sRuntimeStateName|gl)][sNID:]sRelativePath[] |
the following is a list of all valid file name combinations: "user001@paraengine.com:script/hello.lua" – a file of user001 in its default gaming thread "(world1)server001@paraengine.com:script/hello.lua" – a file of server001 in its thread world1 "(worker1)script/hello.lua" – a local file in the thread worker1 "(gl)script/hello.lua" – a glia (local) file in the current runtime state's thread "script/hello.lua" – a file in the current thread. For a single threaded application, this is usually enough.
code | it is a chunk of pure data table init code that would be transmitted to the destination file. |
nLength | the code length. if this is 0, length is determined from code by finding '\0', but, it must not exceed 4096 bytes. If length is explicitly specified, there is no such a limit. |
channel:On | which channel to send the package. It can be a number in [0,15]. In case it is nil, the default channel (0) is used. |
priority | From high to low.If this is nil, medium priority(0) is used. following enumerations are used to describe when packets are delivered. enum PacketPriority { SYSTEM_PRIORITY, /// internally Used to send above-high priority messages. HIGH_PRIORITY, /// High priority messages are send before medium priority messages. MEDIUM_PRIORITY, /// Medium priority messages are send before low priority messages. LOW_PRIORITY, /// Low priority messages are only sent when no other messages are waiting. }; |
reliability:From | unreliable to reliable sequenced. 0 stands for unreliable. If this is nil, RELIABLE_ORDERED(3) is used. following enumerations are used to describe how packets are delivered. enum PacketReliability { UNRELIABLE, /// Same as regular UDP, except that it will also discard duplicate datagrams. It adds (6 to 17) + 21 bits of overhead, 16 of which is used to detect duplicate packets and 6 to 17 of which is used for message length. UNRELIABLE_SEQUENCED, /// Regular UDP with a sequence counter. Out of order messages will be discarded. This adds an additional 13 bits on top what is used for UNRELIABLE. RELIABLE, /// The message is sent reliably, but not necessarily in any order. Same overhead as UNRELIABLE. RELIABLE_ORDERED, /// This message is reliable and will arrive in the order you sent it. Messages will be delayed while waiting for out of order messages. Same overhead as UNRELIABLE_SEQUENCED. RELIABLE_SEQUENCED /// This message is reliable and will arrive in the sequence you sent it. Out or order messages will be dropped. Same overhead as UNRELIABLE_SEQUENCED. }; |
|
virtual |
add a DNS server record to the current NPL runtime.
DNS server record is a mapping from name to (IP:port) if one maps several IP:port to the same name, the former ones will be overridden.
sDNSName | the DNS server name. the DNS name "_world" is used for the current world DNS server. It is commonly used as a DNS reference to the current world that the user is exploring. |
sAddress | "IP:port". e.g. "192.168.1.10:4000" |
TODO: add security: we cannot allow every one to change this as they wish. The user must be informed before this can be changed.
Implements NPL::INPLRuntime.
void CNPLRuntime::NPL_AddPublicFile | ( | const string & | filename, |
int | nID | ||
) |
add a nID, filename pair to the public file list.
we only allow remote NPL runtime to activate files in the public file list. Each public file has a user defined ID. The NPL network layer always try to use its ID for transmission to minimize bandwidth. There are some negotiations between sender and receiver to sync the string to ID map before they use it. [thread safe]
nID | the integer to encode the string. it is usually small and positive number. |
sString | the string for the id. if input is empty, it means removing the mapping of nID. |
bool CNPLRuntime::NPL_ChangeTimer | ( | NPLRuntimeState_ptr | runtime_state, |
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.
[thread safe]
runtime_state | in which runtime state the timer is. Timer ID is unique only within a given runtime state. |
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. |
void CNPLRuntime::NPL_ClearPublicFiles | ( | ) |
clear all public files, so that the NPL server will be completely private.
[thread safe]
void CNPLRuntime::NPL_EnableNetwork | ( | bool | bEnable, |
const char * | CenterName, | ||
const char * | password | ||
) |
OBSOLETED: Enable the network, by default the network layer is disabled.
calling this function multiple time with different CenterName will restart the network layer with a different center name.
bEnable | true to enable, false to disable.If this is false, the CenterName and Password are ignored. |
CenterName | the local nerve center name. it is also the user name which local receptor will use in the credentials to login in other NPL runtime. |
Password |
|
virtual |
see also NPL_SetChannelProperty
channel_ID | |
priority | [out] |
reliability | [out] |
Implements NPL::INPLRuntime.
|
virtual |
Get the default channel ID, default value is 0.
Default channel is used when NPL.activate() call¡¯s does not contain the channel property.
Implements NPL::INPLRuntime.
string CNPLRuntime::NPL_GetIP | ( | const char * | nid | ) |
get the ip address of given NPL connection.
this function is usually called by the server for connected clients.
nid | nid or tid. |
const string & CNPLRuntime::NPL_GetSourceName | ( | ) |
get the current activation's source name.
Each NPL activation has a source name which started the activation. This is usually "" for local activation and some kind of "name@server" for network activation.
bool CNPLRuntime::NPL_KillTimer | ( | NPLRuntimeState_ptr | runtime_state, |
int | nIDEvent | ||
) |
Destroys the specified timer [thread safe].
runtime_state | in which runtime state the timer is. Timer ID is unique only within a given runtime state. |
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. |
void CNPLRuntime::NPL_LoadFile | ( | NPLRuntimeState_ptr | runtime_state, |
const char * | filePath, | ||
bool | bReload | ||
) |
load a file (in the specified runtime state) without running it.
If the file is already loaded, it will not be loaded again unless bReload is true. IMPORTANT: this function is synchronous; unlike the asynchronous activation function. LoadFile is more like "include in C++".When the function returns, contents in the file is loaded to memory. For source file: when loading an NPL file, we will first find if there is an up to date compiled version in the bin directory. if there is, we will load the compiled version, otherwise we will use the text version. use bin version, if source version does not exist; use bin version, if source and bin versions are both on disk (instead of zip) and that bin version is newer than the source version. e.g. we can compile source to bin directory with file extension ".o", e.g. "script/abc.lua" can be compiled to "bin/script/abc.o", The latter will be used if available and up-to-date.
pState | In which runtime state to load the file. If pState is NULL, the main runtime state is used. |
filePath | the local relative file path. 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. |
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. |
void CNPLRuntime::NPL_RegisterWSCallBack | ( | const char * | sWebServiceFile, |
const char * | sCode | ||
) |
this method will associate a web service (method) with either a sCode, which will be called when the web service returned.
The returned message, if any, will be passed via a global parameter called msg. For example: Function callbackFunc1() If(msg.username~=nil) then end End NPL.RegisterWSCallBack("http://paraengine.com/login.aspx",callbackFunc1); NPL.activate("http://paraengine.com/login.aspx", {username=¡±lxz¡±});
sWebServiceFile | URL of the web service |
sCode | code to be executed when the web service is called. When a two-way web service call is invoked; it internally will create a thread for the returning message. Please refer to .Net 3.0 network communication architecture. |
void CNPLRuntime::NPL_reject | ( | const char * | nid, |
int | nReason = 0 |
||
) |
reject and close a given connection.
The connection will be closed once rejected. [thread safe]
nid | the temporary id or NID of the connection to be rejected. usually it is from msg.tid or msg.nid. |
nReason | default to 0.
|
|
virtual |
reset all 16 predefined channel properties.
according to table1. Default NPL channel properties. see also NPL_SetChannelProperty The following table shows the default NPL channel properties. It is advised for users to stick to this default mapping when developing their own applications. Table 1. Default NPL channel properties channel_ID Priority Reliability Usage 0 med RELIABLE_ORDERED System message 1 med UNRELIABLE_SEQUENCED Character positions 2 med RELIABLE_ORDERED Large Simulation Object transmission, such as terrain height field. 4 med RELIABLE_ORDERED Chat message 14 med RELIABLE files transmission and advertisement 15 med RELIABLE_SEQUENCED Voice transmission 11-15 med RELIABLE_ORDERED
Implements NPL::INPLRuntime.
|
virtual |
Messages can be sent via predefined channels.
There are 16 channels from 0 to 15 to be used. 0 is the default channel. This method sets the channel property for a given channel. The default channel property is given in table. The following table shows the default NPL channel properties. It is advised for users to stick to this default mapping when developing their own applications. Table 1. Default NPL channel properties channel_ID Priority Reliability Usage 0 med RELIABLE_ORDERED System message 1 med UNRELIABLE_SEQUENCED Character positions 2 med RELIABLE_ORDERED Large Simulation Object transmission, such as terrain height field. 4 med RELIABLE_ORDERED Chat message 14 med RELIABLE files transmission and advertisement 15 med RELIABLE_SEQUENCED Voice transmission 11-15 med RELIABLE_ORDERED
channel_ID | |
priority | |
reliability |
Implements NPL::INPLRuntime.
|
virtual |
Set the default channel ID, default value is 0.
Default channel is used when NPL.activate() call¡¯s does not contain the channel property.
channel_ID | It can be a number in [0,15].default is 0 |
Implements NPL::INPLRuntime.
void CNPLRuntime::NPL_SetProtocol | ( | const char * | nid, |
int | protocolType = 0 |
||
) |
set transmission protocol, default value is 0.
void CNPLRuntime::NPL_SetSourceName | ( | const char * | sName | ) |
Set the current activation's source name.
Each NPL activation has a source name which started the activation. This function is called automatically when a new activation occurs.So only call this function if one wants to override the old one for special code logics.
sName | This is usually "" for local activation and some kind of "name@server" for network activation. |
bool CNPLRuntime::NPL_SetTimer | ( | NPLRuntimeState_ptr | runtime_state, |
int | nIDEvent, | ||
float | fElapse, | ||
const char * | sNeuronFile | ||
) |
creates a timer with the specified time-out value [thread safe]
runtime_state | in which runtime state the timer is. Timer ID is unique only within a given runtime state. |
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(). |
void CNPLRuntime::NPL_StartNetServer | ( | const char * | server = NULL , |
const char * | port = NULL |
||
) |
start the NPL net server's io_service loop.
This function returns immediately. it will spawn the accept and dispatcher thread. call this function only once per process.
server | default to "127.0.0.1" |
port | default to "60001" |
void CNPLRuntime::NPL_UnregisterWSCallBack | ( | const char * | sWebServiceFile | ) |
unregister web service call back for a given file.
sWebServiceFile | if this is nil or "", all call backs will be unregistered. |
|
virtual |
reject and close a given connection.
The connection will be closed once rejected. [thread safe]
nid | the temporary id or NID of the connection to be rejected. usually it is from msg.tid or msg.nid. |
nReason | default to 0. if 1 it means connection overriden |
Implements NPL::INPLRuntime.
bool CNPLRuntime::RemoveStateFromMainThread | ( | NPLRuntimeState_ptr | runtime_state | ) |
remove a given runtime state from the main game thread.
this function is thread safe
|
virtual |
call this function regularly, to process packages.
bToEnd | if true, the function will only return when there is no more input packages in the queue |
dispatch events in NPL.
activate all timers
process results from NPL web service client
Implements NPL::INPLRuntime.
|
virtual |
set the compression method of incoming the outgoing messages.
If this is not called, the default internal key is used for message encoding. [Not Thread Safe]: one must call this function before sending or receiving any encoded messages. so it is usually called when the game engine starts.
sKey | the byte array of key. the generic key that is used for encoding/decoding |
nSize | size in bytes of the sKey. default is 64 bytes |
nUsePlainTextEncoding | default to 0. if 0, the key is used as it is. if 1, the input key will be modified so that the encoded message looks like plain text(this can be useful to pass some firewalls). if -1, the input key will be modified so that the encoded message is binary. |
Implements NPL::INPLRuntime.
|
virtual |
Set the zlib compression level to use in case compression is enabled.
default to 0, which means no compression. Compression level, which is an integer in the range of -1 to 9. Lower compression levels result in faster execution, but less compression. Higher levels result in greater compression, but slower execution. The zlib constant Z_DEFAULT_COMPRESSION, equal to -1, provides a good compromise between compression and speed and is equivalent to level 6. Level 0 actually does no compression at all, and in fact expands the data slightly to produce the zlib format (it is not a byte-for-byte copy of the input).
Implements NPL::INPLRuntime.
|
virtual |
set the default compression threshold for all connections on this machine.
when the message size is bigger than this number of bytes, we will use m_nCompressionLevel for compression. For message smaller than the threshold, we will not compress even m_nCompressionLevel is not 0.
Implements NPL::INPLRuntime.
|
static |
if one wants to change the default runtime state, such as using external luastate, one need to call this function before GetInstance().
|
virtual |
whether we will process messages in the main threads in the frame move function.
It is default to true; However, it is possible for server to set to false, if one wants to have a more responsive main state on the server. For example, it does high-frequency dispatcher jobs, instead of monitoring. But client application, it is only advised to set to true, otherwise the scripting and render modules will be run in different threads, leading to complexity and bugs. : One can only call this function once to set to false. This function is only used by the ParaEngineServer
Implements NPL::INPLRuntime.
|
virtual |
how many milliseconds of inactivity to assume this connection should be timed out.
if 0 it is never timed out.
Implements NPL::INPLRuntime.
|
virtual |
enable application level keep alive.
we will use a global idle timer to detect if a connection has been inactive for GetIdleTimeoutPeriod(), if so, we may send the keep alive message.
bEnable | enable keep alive will automatically enable EnableIdleTimeout() |
Implements NPL::INPLRuntime.
|
virtual |
System level Enable/disable SO_KEEPALIVE.
one needs set following values in linux procfs or windows registry in order to work as expected.
bEnable | true to enable. |
Implements NPL::INPLRuntime.
|
virtual |
whether to use compression on transport layer for incoming and outgoing connections
bCompressIncoming | if true, compression is used for all incoming connections. default to false. |
bCompressIncoming | if true, compression is used for all outgoing connections. default to false. |
Implements NPL::INPLRuntime.
|
virtual |
start the NPL net server's io_service loop.
This function returns immediately. it will spawn the accept and dispatcher thread. call this function only once per process.
server | default to "127.0.0.1" |
port | default to "60001" |
Implements NPL::INPLRuntime.