My Project
ParaScriptingGlobal.h
1 //-----------------------------------------------------------------------------
2 // Copyright (C) 2004 - 2006 ParaEngine Dev Studio, All Rights Reserved.
3 // Date: 2005.4
4 // Description: API for global objects
5 //-----------------------------------------------------------------------------
6 #pragma once
7 #include "util/LogService.h"
8 #include "IAttributeFields.h"
9 #include <map>
10 #include <string>
11 
12 struct lua_State;
13 
14 
15 #pragma region StackObjectPtr
16 
17 namespace ParaScripting
18 {
19  class ParaObject;
20  class ParaUIObject;
21  class ParaAttributeObject;
22 
27  template <typename _Ty>
29  {
30  public:
31  StackObjectPtr(_Ty* obj){
32  if(obj!=0)
33  {
34  _Myptr = *obj;
35  }
36  }
37  StackObjectPtr(_Ty const& obj):_Myptr(obj){}
38 
39  operator bool () const
40  {
41  return _Myptr.IsValid();
42  }
43 
44  bool operator! () const
45  {
46  return !(_Myptr.IsValid());
47  }
48 
49  _Ty& operator*() const
50  {
51  return (*get());
52  }
53 
54  _Ty *operator->() const
55  {
56  return (get());
57  }
58 
59  _Ty *get() const
60  {
61  return (_Ty *)&(_Myptr);
62  }
63  private:
64  _Ty _Myptr;
65  };
66 
67  template <typename T>
68  T* get_pointer(StackObjectPtr<T> const& pointer){
69  return pointer.get();
70  }
71 
77  template <typename T>
78  T* get_pointer(T const& pointer){
79  return (T*)(&pointer);
80  }
81 } // namespace ParaScripting
82 
83 namespace luabind
84 {
85  using ParaScripting::get_pointer; // <ParaScripting::ParaCharacter>;
86 }
87 
88 #pragma endregion StackObjectPtr
89 
90 namespace ParaScripting
91 {
92  using namespace std;
93  using namespace luabind;
94  using namespace ParaEngine;
100  {
101  public:
102  enum objecttype{number, string}
103  oType;
104  union
105  {
106  double dNumber;
107  };
108  std::string str;
109 
110  ParaObjectNode(double n){
111  oType = number;
112  dNumber = n;
113  };
114  ParaObjectNode(const char* newstr){
115  oType = string;
116  this->str = newstr;
117  };
118  };
119 
120  typedef struct
121  {
122  bool operator() (const std::string& first, const std::string& second) const
123  {
124  return first.compare(second)<0;
125  }
126  } CStringCompare;
127 
128  typedef pair <const char *, ParaObjectNode> ParaObject_Pair;
129 
130 
136  {
137  public:
138  ParaEngine::CServiceLogger_ptr m_logger_ptr;
139 
140  ParaServiceLogger(){};
141  ParaServiceLogger(ParaEngine::CServiceLogger_ptr& logger);
142  ~ParaServiceLogger(){};
143  public:
145  void log(int level, const object& message);
146 
151  int GetLevel();
152 
154  void SetLevel(const int level1);
155 
160  bool IsEnabledFor(int level);
161 
165  void SetAppendMode(bool bAppendToExistingFile);
166 
171  void SetLogFile(const char* sFileName);
172 
177  void SetForceFlush(bool bForceFlush);
178  };
179 
184  class PE_CORE_DECL ParaGlobal
185  {
186  public:
190  static void ExitApp();
191 
196  static void Exit(int nReturnCode);
197 
199  static void SelectAttributeObject(const ParaAttributeObject& obj);
200 
204  static void WriteToConsole(const char* strMessage);
208  static void WriteToLogFile(const char* strMessage);
209 
213  static int GetLogPos();
214 
220  static const char* GetLog(int fromPos, int nCount);
221 
223  static ParaServiceLogger GetLogger(const object& name);
224  static ParaServiceLogger GetLogger_(const char* name);
225 
230  static bool WriteToFile(const char* filename, const char* strMessage);
239  static void SetGameStatus(const char* strState);
244  static double GetGameTime();
245 
246 
264  static std::string GetDateFormat(const object& sFormat);
265 
282  static std::string GetTimeFormat(const object& sFormat);
283 
290  static DWORD timeGetTime();
291 
293  static double getAccurateTime();
294 
299  static double random();
300 
307  static double GetSysDateTime();
308 
314  static std::string GenerateUniqueID();
315 
322  static void SaveObject(const char* strObjectName, const object& objObject);
323 
330  static object LoadObject(const object& strObjectName);
335  static void SetGameLoop(const char* scriptName);
337  static void SetGameLoopInterval(float fInterval);
351  static bool CreateProcess(const char* lpApplicationName, const char* lpCommandLine, bool bWaitOnReturn);
352 
376  static bool ShellExecute(const char* lpOperation, const char* lpFile, const char* lpParameters, const char* lpDirectory, int nShowCmd);
377 
388  static bool OpenFileDialog(const object& inout);
389 
398  static bool WriteRegStr(const string& root_key, const string& sSubKey, const string& name, const string& value);
399 
409  static const char* ReadRegStr(const string& root_key, const string& sSubKey, const string& name);
410 
419  static bool WriteRegDWORD(const string& root_key, const string& sSubKey, const string& name, DWORD value);
420 
429  static DWORD ReadRegDWORD(const string& root_key, const string& sSubKey, const string& name);
430  };
431 
458  class PE_CORE_DECL ParaAttributeObject
459  {
460  public:
461  IAttributeFields::WeakPtr_type m_pAttribute;
462  CAttributeClass* m_pAttClass;
463 
464  ParaAttributeObject():m_pAttribute(),m_pAttClass(NULL){};
465  ParaAttributeObject(IAttributeFields * pAttribute, CAttributeClass* pAttClass);
467 
469  ParaAttributeObject GetAttributeObject();
470 
471 
475  bool equals(const ParaAttributeObject& obj) const;
476 
480  ParaAttributeObject GetChild(const std::string& sName);
481  ParaAttributeObject GetChildAt(int nIndex);
482  ParaAttributeObject GetChildAt2(int nRowIndex, int nColumnIndex);
483  int GetChildCount();
484  int GetChildCount2(int nColumnIndex);
486  int GetColumnCount();
487 
489  bool AddChild(ParaAttributeObject& obj);
490 
492  const ParaObject& QueryObject();
493  const ParaUIObject& QueryUIObject();
494 
498  bool IsValid() const;
499 
501  int GetClassID() const;
503  const char* GetClassName() const;
504  const char* GetClassName1() const;
506  const char* GetClassDescription() const;
507 
515  void SetOrder(int order);
517  int GetOrder();
518 
520  int GetFieldNum();
522  const char* GetFieldName(int nIndex);
523 
529  int GetFieldIndex(const char* sFieldname);
530 
537  const char* GetFieldType(int nIndex);
543  bool IsFieldReadOnly(int nIndex);
544 
551  const char* GetFieldSchematics(int nIndex);
561  const char* GetSchematicsType(int nIndex);
562 
570  void GetSchematicsMinMax(int nIndex, float fMinIn, float fMaxIn, float& fMin, float& fMax);
571 
584  object GetField(const char* sFieldname, const object& output);
585 
586  object GetField2(const char* sFieldname, lua_State* L);
589  const char* GetStringField(const char* sFieldname);
593  double GetValueField(const char* sFieldname, int nIndex=0);
594 
601  void SetField(const char* sFieldname, const object& input);
604  void SetStringField(const char* sFieldname, const char* input);
608  void SetValueField(const char* sFieldname, int nIndex, double value);
609 
612  void CallField(const char* sFieldname);
613 
617  void PrintObject(const char* file);
618 
624  bool ResetField(int nFieldID);
625 
632  bool InvokeEditor(int nFieldID, const char* sParameters);
633 
634 
636  // dynamic fields
638 
648  object GetDynamicField(const char* sFieldname, const object& output);
649 
653  object GetDynamicField_(int nIndex, const object& output);
654 
655  object GetDynamicFieldImp(CDynamicAttributeField* pField, const object &output);
656 
658  const char* GetDynamicFieldNameByIndex(int nIndex);
659 
661  int GetDynamicFieldCount();
662 
671  int SetDynamicField(const char* sFieldname, const object& input);
672  int SetDynamicField_(int nFieldIndex, const object& input);
673 
674  int GetFieldKeyNums(const char* sFieldname);
675  void SetFieldKeyNums(const char* sFieldname, int nKeyNum);
676 
677  void SetFieldKeyTime(const char* sFieldname, int nKeyIndex, int nTime);
678  int GetFieldKeyTime(const char* sFieldname, int nKeyIndex);
679 
680  void SetFieldKeyValue(const char* sFieldname, int nKeyIndex, const object& input);
681  object GetFieldKeyValue(const char* sFieldname, int nKeyIndex, const object& output);
682 
684  void RemoveAllDynamicFields();
685 
689  int AddDynamicField(const std::string& sName, int dwType);
690  };
691 
700  class PE_CORE_DECL ParaBootStrapper
701  {
702  public:
708  static bool LoadFromFile(const char* sXMLfile);
714  static bool SaveToFile(const char* sXMLfile);
715 
717  static void LoadDefault();
718 
723  static const char* GetMainLoopFile();
728  static void SetMainLoopFile(const char* sMainFile);
729  };
730 }
service logger
Definition: ParaScriptingGlobal.h:135
ParaGlobal namespace contains a list of HAPI functions to access the boot strapper functionality...
Definition: ParaScriptingGlobal.h:700
an attribute class is a collection of attribute fields.
Definition: AttributeClass.h:10
different physics engine has different winding order.
Definition: EventBinding.h:32
this is for luabinding a pointer object on lua stack, instead of invoking new operator each time an o...
Definition: ParaScriptingGlobal.h:28
ParaObject class: it is used to control game scene objects from scripts.
Definition: ParaScriptingScene.h:56
Definition: ParaScriptingGlobal.h:120
double GetSysDateTime()
Get the system date and time in seconds.
Definition: ParaTime.cpp:302
ParaGlobal namespace contains a list of HAPI functions to globally control the engine.
Definition: ParaScriptingGlobal.h:184
Definition: minilua.c:461
Definition: PEtypes.h:507
Definition: enum_maker.hpp:46
it represents an attribute object associated with an object.
Definition: ParaScriptingGlobal.h:458
A common interface for all classes implementing IAttributeFields By implementing this class&#39;s virtual...
Definition: IAttributeFields.h:59
std::string GetDateFormat(const char *sFormat)
get the date in string [thread safe]
Definition: ParaTime.cpp:117
std::string GetTimeFormat(const char *sFormat)
get the time in string [thread safe]
Definition: ParaTime.cpp:200
for luabind, The main drawback of this approach is that the compilation time will increase for the fi...
Definition: luaSQLite.cpp:1971
for a dynamic attribute field.
Definition: DynamicAttributeField.h:11
it represents a GUI object.
Definition: ParaScriptingGUI.h:104
for Para Script global dictionary object
Definition: ParaScriptingGlobal.h:99
T * get_pointer(T const &pointer)
this defines a rule, so that every object defined in ParaScripting namespace will be treated as Stack...
Definition: ParaScriptingGlobal.h:78