My Project
Static Public Member Functions | List of all members
ParaScripting::ParaGlobal Class Reference

ParaGlobal namespace contains a list of HAPI functions to globally control the engine. More...

#include <ParaScriptingGlobal.h>

Static Public Member Functions

static void ExitApp ()
 exit the applications.
 
static void Exit (int nReturnCode)
 This is same as ExitApp, except that it supports a return code. More...
 
static void SelectAttributeObject (const ParaAttributeObject &obj)
 select a given attribute object. More...
 
static void WriteToConsole (const char *strMessage)
 write const char* to console, usually for debugging purposes.
 
static void WriteToLogFile (const char *strMessage)
 write const char* to log file, usually for debugging purposes.
 
static int GetLogPos ()
 get the current log file position. More...
 
static const char * GetLog (int fromPos, int nCount)
 get log text between two Log positions. More...
 
static ParaServiceLogger GetLogger (const object &name)
 Get a service logger. More...
 
static ParaServiceLogger GetLogger_ (const char *name)
 
static bool WriteToFile (const char *filename, const char *strMessage)
 write const char* to specific file. More...
 
static void SetGameStatus (const char *strState)
 set the game status More...
 
static double GetGameTime ()
 
static std::string GetDateFormat (const object &sFormat)
 get the date in string [thread safe] More...
 
static std::string GetTimeFormat (const object &sFormat)
 get the time in string [thread safe] More...
 
static DWORD timeGetTime ()
 The timeGetTime function retrieves the system time, in milliseconds. More...
 
static double getAccurateTime ()
 get the elapsed time using high-resolution timing function in seconds. More...
 
static double random ()
 the random seed is set at application start More...
 
static double GetSysDateTime ()
 Get the system date and time in seconds. More...
 
static std::string GenerateUniqueID ()
 generate a unique ID as a string. More...
 
static void SaveObject (const char *strObjectName, const object &objObject)
 global object dictionary functions: this is a way for different script runtime to share some global information. More...
 
static object LoadObject (const object &strObjectName)
 global object dictionary functions: this is a way for different script runtime to share some global information. More...
 
static void SetGameLoop (const char *scriptName)
 reset the game loop script. More...
 
static void SetGameLoopInterval (float fInterval)
 set the game loop activation interval. More...
 
static bool CreateProcess (const char *lpApplicationName, const char *lpCommandLine, bool bWaitOnReturn)
 run an external application. More...
 
static bool ShellExecute (const char *lpOperation, const char *lpFile, const char *lpParameters, const char *lpDirectory, int nShowCmd)
 Performs an operation on a specified file. More...
 
static bool OpenFileDialog (const object &inout)
 create a open file dialog. More...
 
static bool WriteRegStr (const string &root_key, const string &sSubKey, const string &name, const string &value)
 Write a string to the registry. More...
 
static const char * ReadRegStr (const string &root_key, const string &sSubKey, const string &name)
 Read string from the registry. More...
 
static bool WriteRegDWORD (const string &root_key, const string &sSubKey, const string &name, DWORD value)
 Write a DWORD to the registry. More...
 
static DWORD ReadRegDWORD (const string &root_key, const string &sSubKey, const string &name)
 Read DWORD from the registry. More...
 

Detailed Description

ParaGlobal namespace contains a list of HAPI functions to globally control the engine.

Member Function Documentation

§ CreateProcess()

bool ParaGlobal::CreateProcess ( const char *  lpApplicationName,
const char *  lpCommandLine,
bool  bWaitOnReturn 
)
static

run an external application.

creates a new process and its primary thread. The new process runs the specified executable file in the security context of the calling process.

Remarks
: One can also use ParaEngine C++ or .Net API to write application plug-ins for the game engine, which can be loaded like any other script files. e.g. To open a file in an external notepad editor use ParaGlobal.CreateProcess("c:\\notepad.exe", "\"c:\notepad.exe" c:\test.txt", true);
Parameters
lpApplicationName:Pointerto a null-terminated string that specifies the module to execute. The specified module can be a Windows-based application. The string can specify the full path and file name of the module to execute or it can specify a partial name. In the case of a partial name, the function uses the current drive and current directory to complete the specification. The function will not use the search path. If the file name does not contain an extension, .exe is assumed. If the executable module is a 16-bit application, lpApplicationName should be NULL, and the string pointed to by lpCommandLine should specify the executable module as well as its arguments.
lpCommandLine:Pointerto a null-terminated string that specifies the command line to execute.
bWaitOnReturnif false, the function returns immediately; otherwise it will wait for the editor to return. if this is true, the Child Process will have Redirected Input and Output to current log file.
Returns
true if opened.

§ Exit()

void ParaGlobal::Exit ( int  nReturnCode)
static

This is same as ExitApp, except that it supports a return code.

this is the recommended way of exiting application. this is mainly used for writing test cases. Where a return value of 0 means success, any other value means failure.

§ GenerateUniqueID()

std::string ParaGlobal::GenerateUniqueID ( )
static

generate a unique ID as a string.

This is usually a string. [thread safe]

Returns

§ getAccurateTime()

double ParaGlobal::getAccurateTime ( )
static

get the elapsed time using high-resolution timing function in seconds.

this function is mostly used for profiling on the NPL

§ GetDateFormat()

std::string ParaGlobal::GetDateFormat ( const object sFormat)
static

get the date in string [thread safe]

Parameters
sFormatcan be NULL to use default.e.g. "ddd',' MMM dd yy"
  • d Day of month as digits with no leading zero for single-digit days.
  • dd Day of month as digits with leading zero for single-digit days.
  • ddd Day of week as a three-letter abbreviation. The function uses the LOCALE_SABBREVDAYNAME value associated with the specified locale.
  • dddd Day of week as its full name. The function uses the LOCALE_SDAYNAME value associated with the specified locale.
  • M Month as digits with no leading zero for single-digit months.
  • MM Month as digits with leading zero for single-digit months.
  • MMM Month as a three-letter abbreviation. The function uses the LOCALE_SABBREVMONTHNAME value associated with the specified locale.
  • MMMM Month as its full name. The function uses the LOCALE_SMONTHNAME value associated with the specified locale.
  • y Year as last two digits, but with no leading zero for years less than 10.
  • yy Year as last two digits, but with leading zero for years less than 10.
  • yyyy Year represented by full four digits.
  • gg Period/era string. The function uses the CAL_SERASTRING value associated with the specified locale. This element is ignored if the date to be formatted does not have an associated era or period string.

§ GetGameTime()

double ParaGlobal::GetGameTime ( )
static
Returns
return the current game time in milliseconds.When game is paused, game time is also paused. this is usually used for cinematic movies

§ GetLog()

const char * ParaGlobal::GetLog ( int  fromPos,
int  nCount 
)
static

get log text between two Log positions.

Parameters
fromPosposition in bytes. if nil, it defaults to 0
nCountcount in bytes. if nil, it defaults to end of log file.
Returns
string returned.

§ GetLogger()

ParaScripting::ParaServiceLogger ParaGlobal::GetLogger ( const object name)
static

Get a service logger.

Please see util/LogService.h for more information.

§ GetLogPos()

int ParaGlobal::GetLogPos ( )
static

get the current log file position.

it is equivalent to the log file size in bytes. one can later get log text between two Log positions.

§ GetSysDateTime()

double ParaGlobal::GetSysDateTime ( )
static

Get the system date and time in seconds.

The system time is expressed in Coordinated Universal Time (UTC). Note: there is some trick to make the returned value a valid number in NPL. Only compare time with time returned by the same function. TODO: in the long run, a true unsigned int64 should be returned. [thread safe]

§ GetTimeFormat()

std::string ParaGlobal::GetTimeFormat ( const object sFormat)
static

get the time in string [thread safe]

Parameters
sFormatcan be NULL to use default. e.g. "hh':'mm':'ss tt"
  • h Hours with no leading zero for single-digit hours; 12-hour clock.
  • hh Hours with leading zero for single-digit hours; 12-hour clock.
  • H Hours with no leading zero for single-digit hours; 24-hour clock.
  • HH Hours with leading zero for single-digit hours; 24-hour clock.
  • m Minutes with no leading zero for single-digit minutes.
  • mm Minutes with leading zero for single-digit minutes.
  • s Seconds with no leading zero for single-digit seconds.
  • ss Seconds with leading zero for single-digit seconds.
  • t One character time-marker string, such as A or P.
  • tt Multicharacter time-marker string, such as AM or PM.

§ LoadObject()

object ParaGlobal::LoadObject ( const object strObjectName)
static

global object dictionary functions: this is a way for different script runtime to share some global information.

Currently only value and const char* object can be saved. return nil, if object is not found

Parameters
strObjectNamethe object name

get object from dictionary table

§ OpenFileDialog()

bool ParaGlobal::OpenFileDialog ( const object inout)
static

create a open file dialog.

This function does not return until the user selects a dialog.

Parameters
inoutinput table:{filter="All Files (*.*);*.*;", filterindex, initialdir, flags, } t.filter="All Files (*.*)\0*.*\0" output : {filename, result=true} t.filename: the full path and file name specified by the user t.result: boolean if user clicks the OK button
Returns
: true if user clicks ok. and the inout.filename contains the result.

§ random()

double ParaGlobal::random ( )
static

the random seed is set at application start

Returns
generate a random number between [0,1]

§ ReadRegDWORD()

DWORD ParaGlobal::ReadRegDWORD ( const string &  root_key,
const string &  sSubKey,
const string &  name 
)
static

Read DWORD from the registry.

Valid values for root_key are listed under WriteRegStr. NULL will be returned if the DWORD is not present or type is a string.

Parameters
root_keymust be HKCR or HKEY_CLASSES_ROOT HKLM or HKEY_LOCAL_MACHINE HKCU or HKEY_CURRENT_USER HKU or HKEY_USERS

§ ReadRegStr()

const char * ParaGlobal::ReadRegStr ( const string &  root_key,
const string &  sSubKey,
const string &  name 
)
static

Read string from the registry.

Valid values for root_key are listed under WriteRegStr. NULL will be returned if the string is not present. If the value is present, but is of type REG_DWORD, it will be read and converted to a string.

Parameters
root_keymust be HKCR or HKEY_CLASSES_ROOT HKLM or HKEY_LOCAL_MACHINE HKCU or HKEY_CURRENT_USER HKU or HKEY_USERS

§ SaveObject()

void ParaGlobal::SaveObject ( const char *  strObjectName,
const object objObject 
)
static

global object dictionary functions: this is a way for different script runtime to share some global information.

Currently only value and const char* object can be saved. one can save nil to a object name to delete the object.

Parameters
objObjectobject to save

already exists, then override old value

already exists, then override old value

already exists, delete it.

§ SelectAttributeObject()

void ParaGlobal::SelectAttributeObject ( const ParaAttributeObject obj)
static

select a given attribute object.

this is a static function

§ SetGameLoop()

void ParaGlobal::SetGameLoop ( const char *  scriptName)
static

reset the game loop script.

the game loop script will be activated every 0.5 seconds see SetGameLoopInterval() to change the default interval Please keep the game loop concise. The default game loop is ./script/gameinterface.lua

§ SetGameLoopInterval()

void ParaGlobal::SetGameLoopInterval ( float  fInterval)
static

set the game loop activation interval.

The default value is 0.5 seconds.

§ SetGameStatus()

void ParaGlobal::SetGameStatus ( const char *  strState)
static

set the game status

Parameters
strState
  • "disable" disable the game
  • "enable" enable the game
  • "pause" pause the game
  • "resume" resume the game

§ ShellExecute()

bool ParaGlobal::ShellExecute ( const char *  lpOperation,
const char *  lpFile,
const char *  lpParameters,
const char *  lpDirectory,
int  nShowCmd 
)
static

Performs an operation on a specified file.

e.g. ParaGlobal.ShellExecute("open", "iexplore.exe", "http://www.paraengine.com", nil, 1);

Parameters
lpOperation:[in]Pointer to a null-terminated string,
  • "wait" this is a special one that uses ShellExecuteEx to wait on the process to terminate before return
  • "edit" Launches an editor and opens the document for editing. If lpFile is not a document file, the function will fail.
  • "explore" Explores the folder specified by lpFile.
  • "find" Initiates a search starting from the specified directory.
  • "open" Opens the file specified by the lpFile parameter. The file can be an executable file, a document file, or a folder.
  • "print" Prints the document file specified by lpFile. If lpFile is not a document file, the function will fail.
  • NULL For systems prior to Microsoft Windows 2000, the default verb is used if it is valid and available in the registry. If not, the "open" verb is used.
lpFile[in] Pointer to a null-terminated string that specifies the file or object on which to execute the specified verb. To specify a Shell namespace object, pass the fully qualified parse name. Note that not all verbs are supported on all objects. For example, not all document types support the "print" verb.
lpParameters[in]If the lpFile parameter specifies an executable file, lpParameters is a pointer to a null-terminated string that specifies the parameters to be passed to the application. The format of this string is determined by the verb that is to be invoked. If lpFile specifies a document file, lpParameters should be NULL.
lpDirectory[in] Pointer to a null-terminated string that specifies the default directory.
nShowCmd[in] Flags that specify how an application is to be displayed when it is opened. If lpFile specifies a document file, the flag is simply passed to the associated application. It is up to the application to decide how to handle it.
  • #define SW_HIDE 0
  • #define SW_NORMAL 1
  • #define SW_MAXIMIZE 3
  • #define SW_SHOW 5
  • #define SW_MINIMIZE 6
  • #define SW_RESTORE 9

§ timeGetTime()

DWORD ParaGlobal::timeGetTime ( )
static

The timeGetTime function retrieves the system time, in milliseconds.

The system time is the time elapsed since Windows was started. Note that the value returned by the timeGetTime function is a DWORD value. The return value wraps around to 0 every 2^32 milliseconds, which is about 49.71 days. This can cause problems in code that directly uses the timeGetTime return value in computations, particularly where the value is used to control code execution. You should always use the difference between two timeGetTime return values in computations.

§ WriteRegDWORD()

bool ParaGlobal::WriteRegDWORD ( const string &  root_key,
const string &  sSubKey,
const string &  name,
DWORD  value 
)
static

Write a DWORD to the registry.

see WriteRegStr() for more info

Parameters
root_keymust be HKCR or HKEY_CLASSES_ROOT HKLM or HKEY_LOCAL_MACHINE HKCU or HKEY_CURRENT_USER HKU or HKEY_USERS

§ WriteRegStr()

bool ParaGlobal::WriteRegStr ( const string &  root_key,
const string &  sSubKey,
const string &  name,
const string &  value 
)
static

Write a string to the registry.

e.g. WriteRegStr("HKLM", "Software\My Company\My Software", "string Value", "string Name");

Parameters
root_keymust be HKCR or HKEY_CLASSES_ROOT HKLM or HKEY_LOCAL_MACHINE HKCU or HKEY_CURRENT_USER HKU or HKEY_USERS

§ WriteToFile()

bool ParaGlobal::WriteToFile ( const char *  filename,
const char *  strMessage 
)
static

write const char* to specific file.

obsolete


The documentation for this class was generated from the following files: