Prechádzať zdrojové kódy

Merge pull request #1261 from seanpaultaylor/next

Added back static Scene::getScene to access active current scenes from s...
Sean Taylor 12 rokov pred
rodič
commit
6b9b314751

+ 25 - 6
gameplay/src/Scene.cpp

@@ -10,6 +10,9 @@
 namespace gameplay
 {
 
+// Global list of active scenes
+static std::vector<Scene*> __sceneList;
+
 static inline char lowercase(char c)
 {
     if (c >= 'A' && c <='Z')
@@ -60,6 +63,7 @@ Scene::Scene()
     : _id(""), _activeCamera(NULL), _firstNode(NULL), _lastNode(NULL), _nodeCount(0), _bindAudioListenerToCamera(true), 
       _nextItr(NULL), _nextReset(true)
 {
+    __sceneList.push_back(this);
 }
 
 Scene::~Scene()
@@ -78,6 +82,11 @@ Scene::~Scene()
 
     // Remove all nodes from the scene
     removeAllNodes();
+
+    // Remove the scene from global list
+    std::vector<Scene*>::iterator itr = std::find(__sceneList.begin(), __sceneList.end(), this);
+    if (itr != __sceneList.end())
+        __sceneList.erase(itr);
 }
 
 Scene* Scene::create(const char* id)
@@ -103,6 +112,21 @@ Scene* Scene::load(const char* filePath)
     return SceneLoader::load(filePath);
 }
 
+Scene* Scene::getScene(const char* id)
+{
+    if (id == NULL)
+        return __sceneList.size() ? __sceneList[0] : NULL;
+
+    for (size_t i = 0, count = __sceneList.size(); i < count; ++i)
+    {
+        if (__sceneList[i]->_id == id)
+            return __sceneList[i];
+    }
+
+    return NULL;
+}
+
+
 const char* Scene::getId() const
 {
     return _id.c_str();
@@ -300,7 +324,7 @@ Node* Scene::getFirstNode() const
     return _firstNode;
 }
 
-Camera* Scene::getActiveCamera() const
+Camera* Scene::getActiveCamera()
 {
     return _activeCamera;
 }
@@ -369,11 +393,6 @@ void Scene::update(float elapsedTime)
     }
 }
 
-Scene* Scene::getScene()
-{
-    return this;
-}
-
 void Scene::reset()
 {
     _nextItr = NULL;

+ 13 - 6
gameplay/src/Scene.h

@@ -37,6 +37,17 @@ public:
      */
     static Scene* load(const char* filePath);
 
+    /**
+     * Gets a currently active scene.
+     *
+     * If id is an NULL, the first active scene is returned.
+     *
+     * @param id ID of the scene to retrieve, or NULL to retrieve the first active scene.
+     *
+     * @return The scene that matches the specified ID, or NULL if no matching scene could be found.
+     */
+    static Scene* getScene(const char* id = NULL);
+
     /**
      * Gets the identifier for the scene.
      *
@@ -123,8 +134,9 @@ public:
      * Gets the active camera for the scene.
      *
      * @return The active camera for the scene.
+     * @see VisibleSet#getActiveCamera
      */
-    Camera* getActiveCamera() const;
+    Camera* getActiveCamera();
 
     /**
      * Sets the active camera on the scene.
@@ -226,11 +238,6 @@ public:
      */
     void update(float elapsedTime);
 
-    /**
-     * @see VisibleSet#getScene
-     */
-    Scene* getScene();
-
     /**
      * @see VisibleSet#getNext
      */

+ 4 - 4
gameplay/src/VisibleSet.h

@@ -8,7 +8,7 @@ class Scene;
 
 /**
  * Represents a set of nodes that are visible from the
- * scenes active camera. This provides an enumerator
+ * active camera. This provides an enumerator
  * to traverse the scene returning only visible nodes.
  */
 class VisibleSet
@@ -21,11 +21,11 @@ public:
     virtual ~VisibleSet() { }
 
     /**
-     * Gets the scene to determine the visible set from.
+     * Gets the active camera being used to test the visibility.
      *
-     * @return The scene to determine the visible set from.
+     * @return The active camera being used to test the visibility.
      */
-    virtual Scene* getScene() = 0;
+    virtual Camera* getActiveCamera() = 0;
 
     /**
      * Resets the enumerator for enumerating the visible set.

+ 1 - 8
gameplay/src/lua/lua_Container.cpp

@@ -5,24 +5,17 @@
 #include "Animation.h"
 #include "AnimationTarget.h"
 #include "Base.h"
-#include "Button.h"
-#include "CheckBox.h"
 #include "Container.h"
 #include "Control.h"
+#include "ControlFactory.h"
 #include "FlowLayout.h"
 #include "Form.h"
 #include "Game.h"
-#include "ImageControl.h"
-#include "Joystick.h"
-#include "Label.h"
 #include "Layout.h"
 #include "Node.h"
-#include "RadioButton.h"
 #include "Ref.h"
 #include "ScriptController.h"
 #include "ScriptTarget.h"
-#include "Slider.h"
-#include "TextBox.h"
 #include "VerticalLayout.h"
 #include "lua_ContainerScroll.h"
 #include "lua_ControlAlignment.h"

+ 1 - 5
gameplay/src/lua/lua_Form.cpp

@@ -9,21 +9,17 @@
 #include "CheckBox.h"
 #include "Container.h"
 #include "Control.h"
+#include "ControlFactory.h"
 #include "FlowLayout.h"
 #include "Form.h"
 #include "Game.h"
-#include "ImageControl.h"
-#include "Joystick.h"
 #include "Label.h"
 #include "Layout.h"
 #include "Node.h"
-#include "RadioButton.h"
 #include "Ref.h"
 #include "Scene.h"
 #include "ScriptController.h"
 #include "ScriptTarget.h"
-#include "Slider.h"
-#include "TextBox.h"
 #include "Theme.h"
 #include "VerticalLayout.h"
 #include "lua_ContainerScroll.h"

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

@@ -2,6 +2,7 @@
 #include "ScriptController.h"
 #include "lua_Game.h"
 #include "Base.h"
+#include "ControlFactory.h"
 #include "FileSystem.h"
 #include "FrameBuffer.h"
 #include "Game.h"

+ 66 - 45
gameplay/src/lua/lua_Scene.cpp

@@ -30,7 +30,6 @@ void luaRegister_Scene()
         {"getNext", lua_Scene_getNext},
         {"getNodeCount", lua_Scene_getNodeCount},
         {"getRefCount", lua_Scene_getRefCount},
-        {"getScene", lua_Scene_getScene},
         {"release", lua_Scene_release},
         {"removeAllNodes", lua_Scene_removeAllNodes},
         {"removeNode", lua_Scene_removeNode},
@@ -45,6 +44,7 @@ void luaRegister_Scene()
     const luaL_Reg lua_statics[] = 
     {
         {"create", lua_Scene_static_create},
+        {"getScene", lua_Scene_static_getScene},
         {"load", lua_Scene_static_load},
         {NULL, NULL}
     };
@@ -665,50 +665,6 @@ int lua_Scene_getRefCount(lua_State* state)
     return 0;
 }
 
-int lua_Scene_getScene(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))
-            {
-                Scene* instance = getInstance(state);
-                void* returnPtr = (void*)instance->getScene();
-                if (returnPtr)
-                {
-                    gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
-                    object->instance = returnPtr;
-                    object->owns = false;
-                    luaL_getmetatable(state, "Scene");
-                    lua_setmetatable(state, -2);
-                }
-                else
-                {
-                    lua_pushnil(state);
-                }
-
-                return 1;
-            }
-
-            lua_pushstring(state, "lua_Scene_getScene - 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_Scene_release(lua_State* state)
 {
     // Get the number of parameters.
@@ -1034,6 +990,71 @@ int lua_Scene_static_create(lua_State* state)
     return 0;
 }
 
+int lua_Scene_static_getScene(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 0:
+        {
+            void* returnPtr = (void*)Scene::getScene();
+            if (returnPtr)
+            {
+                gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
+                object->instance = returnPtr;
+                object->owns = false;
+                luaL_getmetatable(state, "Scene");
+                lua_setmetatable(state, -2);
+            }
+            else
+            {
+                lua_pushnil(state);
+            }
+
+            return 1;
+            break;
+        }
+        case 1:
+        {
+            if ((lua_type(state, 1) == LUA_TSTRING || lua_type(state, 1) == LUA_TNIL))
+            {
+                // Get parameter 1 off the stack.
+                const char* param1 = gameplay::ScriptUtil::getString(1, false);
+
+                void* returnPtr = (void*)Scene::getScene(param1);
+                if (returnPtr)
+                {
+                    gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
+                    object->instance = returnPtr;
+                    object->owns = false;
+                    luaL_getmetatable(state, "Scene");
+                    lua_setmetatable(state, -2);
+                }
+                else
+                {
+                    lua_pushnil(state);
+                }
+
+                return 1;
+            }
+
+            lua_pushstring(state, "lua_Scene_static_getScene - Failed to match the given parameters to a valid function signature.");
+            lua_error(state);
+            break;
+        }
+        default:
+        {
+            lua_pushstring(state, "Invalid number of parameters (expected 0 or 1).");
+            lua_error(state);
+            break;
+        }
+    }
+    return 0;
+}
+
 int lua_Scene_static_load(lua_State* state)
 {
     // Get the number of parameters.

+ 1 - 1
gameplay/src/lua/lua_Scene.h

@@ -17,7 +17,6 @@ int lua_Scene_getId(lua_State* state);
 int lua_Scene_getNext(lua_State* state);
 int lua_Scene_getNodeCount(lua_State* state);
 int lua_Scene_getRefCount(lua_State* state);
-int lua_Scene_getScene(lua_State* state);
 int lua_Scene_release(lua_State* state);
 int lua_Scene_removeAllNodes(lua_State* state);
 int lua_Scene_removeNode(lua_State* state);
@@ -26,6 +25,7 @@ int lua_Scene_setActiveCamera(lua_State* state);
 int lua_Scene_setAmbientColor(lua_State* state);
 int lua_Scene_setId(lua_State* state);
 int lua_Scene_static_create(lua_State* state);
+int lua_Scene_static_getScene(lua_State* state);
 int lua_Scene_static_load(lua_State* state);
 int lua_Scene_update(lua_State* state);
 int lua_Scene_visit(lua_State* state);

+ 9 - 9
gameplay/src/lua/lua_VisibleSet.cpp

@@ -10,8 +10,8 @@ void luaRegister_VisibleSet()
 {
     const luaL_Reg lua_members[] = 
     {
+        {"getActiveCamera", lua_VisibleSet_getActiveCamera},
         {"getNext", lua_VisibleSet_getNext},
-        {"getScene", lua_VisibleSet_getScene},
         {"reset", lua_VisibleSet_reset},
         {NULL, NULL}
     };
@@ -66,7 +66,7 @@ int lua_VisibleSet__gc(lua_State* state)
     return 0;
 }
 
-int lua_VisibleSet_getNext(lua_State* state)
+int lua_VisibleSet_getActiveCamera(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -79,13 +79,13 @@ int lua_VisibleSet_getNext(lua_State* state)
             if ((lua_type(state, 1) == LUA_TUSERDATA))
             {
                 VisibleSet* instance = getInstance(state);
-                void* returnPtr = (void*)instance->getNext();
+                void* returnPtr = (void*)instance->getActiveCamera();
                 if (returnPtr)
                 {
                     gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
                     object->instance = returnPtr;
                     object->owns = false;
-                    luaL_getmetatable(state, "Node");
+                    luaL_getmetatable(state, "Camera");
                     lua_setmetatable(state, -2);
                 }
                 else
@@ -96,7 +96,7 @@ int lua_VisibleSet_getNext(lua_State* state)
                 return 1;
             }
 
-            lua_pushstring(state, "lua_VisibleSet_getNext - Failed to match the given parameters to a valid function signature.");
+            lua_pushstring(state, "lua_VisibleSet_getActiveCamera - Failed to match the given parameters to a valid function signature.");
             lua_error(state);
             break;
         }
@@ -110,7 +110,7 @@ int lua_VisibleSet_getNext(lua_State* state)
     return 0;
 }
 
-int lua_VisibleSet_getScene(lua_State* state)
+int lua_VisibleSet_getNext(lua_State* state)
 {
     // Get the number of parameters.
     int paramCount = lua_gettop(state);
@@ -123,13 +123,13 @@ int lua_VisibleSet_getScene(lua_State* state)
             if ((lua_type(state, 1) == LUA_TUSERDATA))
             {
                 VisibleSet* instance = getInstance(state);
-                void* returnPtr = (void*)instance->getScene();
+                void* returnPtr = (void*)instance->getNext();
                 if (returnPtr)
                 {
                     gameplay::ScriptUtil::LuaObject* object = (gameplay::ScriptUtil::LuaObject*)lua_newuserdata(state, sizeof(gameplay::ScriptUtil::LuaObject));
                     object->instance = returnPtr;
                     object->owns = false;
-                    luaL_getmetatable(state, "Scene");
+                    luaL_getmetatable(state, "Node");
                     lua_setmetatable(state, -2);
                 }
                 else
@@ -140,7 +140,7 @@ int lua_VisibleSet_getScene(lua_State* state)
                 return 1;
             }
 
-            lua_pushstring(state, "lua_VisibleSet_getScene - Failed to match the given parameters to a valid function signature.");
+            lua_pushstring(state, "lua_VisibleSet_getNext - Failed to match the given parameters to a valid function signature.");
             lua_error(state);
             break;
         }

+ 1 - 1
gameplay/src/lua/lua_VisibleSet.h

@@ -6,8 +6,8 @@ namespace gameplay
 
 // Lua bindings for VisibleSet.
 int lua_VisibleSet__gc(lua_State* state);
+int lua_VisibleSet_getActiveCamera(lua_State* state);
 int lua_VisibleSet_getNext(lua_State* state);
-int lua_VisibleSet_getScene(lua_State* state);
 int lua_VisibleSet_reset(lua_State* state);
 
 void luaRegister_VisibleSet();