ScriptManager.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. #ifndef SCRIPT_MANAGER_H
  2. #define SCRIPT_MANAGER_H
  3. #include <OgreSingleton.h>
  4. #include <OgreString.h>
  5. #include "Event.h"
  6. #include "LuaIncludes.h"
  7. class Entity;
  8. struct ScriptId
  9. {
  10. ScriptId(): entity( "" ), function( "" ){}
  11. Ogre::String entity;
  12. Ogre::String function;
  13. };
  14. struct ScriptEntity;
  15. struct QueueScript
  16. {
  17. QueueScript():
  18. function( "" ),
  19. argument1( "" ),
  20. argument2( "" ),
  21. priority( 0 ),
  22. state( NULL ),
  23. seconds_to_wait( 0 ),
  24. wait( false ),
  25. yield( false )
  26. {}
  27. Ogre::String function;
  28. Ogre::String argument1;
  29. Ogre::String argument2;
  30. int priority;
  31. lua_State* state;
  32. int state_id; // for storing and deleating thread
  33. float seconds_to_wait;
  34. bool wait;
  35. bool yield;
  36. ScriptId paused_script_start; // script paused by call of this script.
  37. ScriptId paused_script_end; // script paused by call of this script.
  38. };
  39. class ScriptManager : public Ogre::Singleton< ScriptManager >
  40. {
  41. public:
  42. enum Type
  43. {
  44. SYSTEM,
  45. ENTITY,
  46. UI
  47. };
  48. ScriptManager();
  49. virtual ~ScriptManager();
  50. void Input(const QGears::Event& event);
  51. void Update( const Type type );
  52. void RunString( const Ogre::String& lua );
  53. void RunFile( const Ogre::String& file );
  54. // binds
  55. void InitBinds();
  56. void InitCmd();
  57. void AddEntity( const Type type, const Ogre::String& entity_name, Entity* entity );
  58. void RemoveEntity( const Type type, const Ogre::String& entity_name );
  59. void AddEntityScript( const Ogre::String& entity_name, const Ogre::String& function_name, int priority );
  60. void RemoveEntityTopScript( ScriptEntity& entity );
  61. luabind::object GetTableByEntityName( const ScriptManager::Type type, const Ogre::String& name, lua_State* state ) const;
  62. QueueScript* GetScriptByScriptId( const ScriptId& script ) const;
  63. ScriptEntity* GetScriptEntityByName( const Type type, const Ogre::String& entity_name ) const;
  64. const ScriptId GetCurrentScriptId() const;
  65. void ContinueScriptExecution( const ScriptId& script );
  66. int ScriptWait( const float seconds );
  67. void ScriptRequest( const Type type, const char* entity, const char* function, const int priority );
  68. int ScriptRequestStartSync( const Type type, const char* entity, const char* function, const int priority );
  69. int ScriptRequestEndSync( const Type type, const char* entity, const char* function, const int priority );
  70. bool ScriptRequest( ScriptEntity* script_entity, const Ogre::String& function, const int priority, const Ogre::String& argument1, const Ogre::String& argument2, bool start_sync, bool end_sync );
  71. void AddValueToStack( const float value );
  72. private:
  73. lua_State* m_LuaState;
  74. Ogre::String m_SystemTableName;
  75. Ogre::String m_EntityTableName;
  76. Ogre::String m_UiTableName;
  77. std::vector< ScriptEntity > m_ScriptEntity;
  78. ScriptId m_CurrentScriptId;
  79. };
  80. struct ScriptEntity
  81. {
  82. ScriptEntity():
  83. name( "" ),
  84. type( ScriptManager::SYSTEM ),
  85. resort( false )
  86. {
  87. }
  88. Ogre::String name;
  89. ScriptManager::Type type;
  90. std::vector< QueueScript > queue;
  91. bool resort;
  92. };
  93. #endif // SCRIPT_MANAGER_H