BARE2D
LuaScriptQueue.hpp
Go to the documentation of this file.
1 #pragma once
2 
3 #include <map>
4 #include <string>
5 
6 namespace BARE2D {
7 
8  class LuaScript;
9 
10  /**
11  * @class LuaScriptQueue
12  * @file LuaScriptQueue.hpp
13  * @brief This class essentially just collects all of the scripts that need to be run from all the various end-user sources in a single update loop, and then "reports them" to the LuaScriptEngine, who actually runs them. Note that this is a singleton class.
14  */
16  {
17  public:
18  /**
19  * @brief Returns a pointer to the singleton object - creates the object if one doesn't already exist.
20  * @return A pointer to the LuaScriptQueue.
21  */
22  static LuaScriptQueue* getInstance();
23  /**
24  * @brief Destroys the singleton
25  */
26  static void destroyInstance();
27 
28  /**
29  * @brief Adds a script to the queue to be run.
30  * @param script A reference to the LuaScript to add to the queue.
31  * @return An unsigned int which represents the UUID of the script added. This UUID will persist throughout all of the pipeline.
32  */
33  unsigned int addLuaScript(LuaScript& script);
34 
35  /**
36  * @brief Adds a script to the queue to be run by its source code.
37  * @param script The code to run.
38  * @return An unsigned int which represents the UUID of the script added. This UUID will persist throughout all of the pipeline
39  */
40  unsigned int addLuaScript(std::string script);
41 
42  /**
43  * @brief Returns the queue of scripts to activate
44  * @return A reference to m_scripts.
45  */
46  std::map<unsigned int, LuaScript*>& getQueue();
47 
48  /**
49  * @brief Clears the stored script queue - for regular use by tbe Script Engine. Deallocates memory that was in use in the m_scripts map.
50  */
51  void clearQueue();
52 
53  private:
56 
57  // The singleton object.
59 
60  // All of the scripts to be run. We use an ordered map so that we can store both the UUID and script together.
61  std::map<unsigned int, LuaScript*> m_scripts;
62 
63  // The "counter" we're on for our UUIDs (I know, I know - not a 'true' UUID. It works though, doesn't it?) - set to -1 initially so our first script is 0
64  unsigned int m_lastUUID = -1;
65 
66  };
67 
68 }
69 
BARE2D::LuaScriptQueue::getQueue
std::map< unsigned int, LuaScript * > & getQueue()
Returns the queue of scripts to activate.
Definition: LuaScriptQueue.cpp:51
BARE2D
Definition: App.cpp:13
BARE2D::LuaScriptQueue::m_scripts
std::map< unsigned int, LuaScript * > m_scripts
Definition: LuaScriptQueue.hpp:61
BARE2D::LuaScriptQueue::m_lastUUID
unsigned int m_lastUUID
Definition: LuaScriptQueue.hpp:64
BARE2D::LuaScript
Definition: LuaScript.hpp:14
BARE2D::LuaScriptQueue::clearQueue
void clearQueue()
Clears the stored script queue - for regular use by tbe Script Engine. Deallocates memory that was in...
Definition: LuaScriptQueue.cpp:56
BARE2D::LuaScriptQueue::getInstance
static LuaScriptQueue * getInstance()
Returns a pointer to the singleton object - creates the object if one doesn't already exist.
Definition: LuaScriptQueue.cpp:19
BARE2D::LuaScriptQueue::LuaScriptQueue
LuaScriptQueue()
Definition: LuaScriptQueue.cpp:9
BARE2D::LuaScriptQueue::m_instance
static LuaScriptQueue * m_instance
Definition: LuaScriptQueue.hpp:58
BARE2D::LuaScriptQueue::~LuaScriptQueue
~LuaScriptQueue()
Definition: LuaScriptQueue.cpp:14
BARE2D::LuaScriptQueue
Definition: LuaScriptQueue.hpp:15
BARE2D::LuaScriptQueue::addLuaScript
unsigned int addLuaScript(LuaScript &script)
Adds a script to the queue to be run.
Definition: LuaScriptQueue.cpp:31
BARE2D::LuaScriptQueue::destroyInstance
static void destroyInstance()
Destroys the singleton.
Definition: LuaScriptQueue.cpp:27