Browse Source

Merge pull request #1444 from rlofc/next

Allow clearing all scheduled events using Game::clearSchedule
Sean Taylor 11 years ago
parent
commit
3da57cafba
4 changed files with 45 additions and 0 deletions
  1. 6 0
      gameplay/src/Game.cpp
  2. 5 0
      gameplay/src/Game.h
  3. 33 0
      gameplay/src/lua/lua_Game.cpp
  4. 1 0
      gameplay/src/lua/lua_Game.h

+ 6 - 0
gameplay/src/Game.cpp

@@ -548,6 +548,12 @@ void Game::schedule(float timeOffset, const char* function)
     schedule(timeOffset, listener, NULL);
 }
 
+void Game::clearSchedule()
+{
+    SAFE_DELETE(_timeEvents);
+    _timeEvents = new std::priority_queue<TimeEvent, std::vector<TimeEvent>, std::less<TimeEvent> >();
+}
+
 void Game::fireTimeEvents(double frameTime)
 {
     while (_timeEvents->size() > 0)

+ 5 - 0
gameplay/src/Game.h

@@ -598,6 +598,11 @@ public:
      */
     void schedule(float timeOffset, const char* function);
 
+    /**
+     * Clears all scheduled time events.
+     */
+    void clearSchedule();
+
     /**
      * Opens an URL in an external browser, if available.
      *

+ 33 - 0
gameplay/src/lua/lua_Game.cpp

@@ -27,6 +27,7 @@ void luaRegister_Game()
     {
         {"canExit", lua_Game_canExit},
         {"clear", lua_Game_clear},
+        {"clearSchedule", lua_Game_clearSchedule},
         {"displayKeyboard", lua_Game_displayKeyboard},
         {"exit", lua_Game_exit},
         {"frame", lua_Game_frame},
@@ -274,6 +275,38 @@ int lua_Game_clear(lua_State* state)
     return 0;
 }
 
+int lua_Game_clearSchedule(lua_State* state)
+{
+    // Get the number of parameters.
+    int paramCount = lua_gettop(state);
+
+    // Attempt to match the parameters to a valid binding.
+    switch (paramCount)
+    {
+        case 1:
+        {
+            if ((lua_type(state, 1) == LUA_TUSERDATA))
+            {
+                Game* instance = getInstance(state);
+                instance->clearSchedule();
+                
+                return 0;
+            }
+
+            lua_pushstring(state, "lua_Game_clearSchedule - Failed to match the given parameters to a valid function signature.");
+            lua_error(state);
+            break;
+        }
+        default:
+        {
+            lua_pushstring(state, "Invalid number of parameters (expected 1).");
+            lua_error(state);
+            break;
+        }
+    }
+    return 0;
+}
+
 int lua_Game_displayKeyboard(lua_State* state)
 {
     // Get the number of parameters.

+ 1 - 0
gameplay/src/lua/lua_Game.h

@@ -8,6 +8,7 @@ namespace gameplay
 int lua_Game__gc(lua_State* state);
 int lua_Game_canExit(lua_State* state);
 int lua_Game_clear(lua_State* state);
+int lua_Game_clearSchedule(lua_State* state);
 int lua_Game_displayKeyboard(lua_State* state);
 int lua_Game_exit(lua_State* state);
 int lua_Game_frame(lua_State* state);