Browse Source

Changed Scene::load() so it can load from ".gpb" files
Updated the samples to use Scene::load instead of creating a bundle.

Darryl Gough 13 years ago
parent
commit
077b0e2503
2 changed files with 60 additions and 2 deletions
  1. 58 0
      gameplay/src/Scene.cpp
  2. 2 2
      gameplay/src/Scene.h

+ 58 - 0
gameplay/src/Scene.cpp

@@ -5,6 +5,7 @@
 #include "MeshSkin.h"
 #include "Joint.h"
 #include "Terrain.h"
+#include "Bundle.h"
 
 namespace gameplay
 {
@@ -12,6 +13,52 @@ namespace gameplay
 // Global list of active scenes
 static std::vector<Scene*> __sceneList;
 
+static inline char lowercase(char c)
+{
+    if (c >= 'A' && c <='Z')
+    {
+        c |= 0x20;
+    }
+    return c;
+}
+
+// Returns true if 'str' ends with 'suffix'; false otherwise.
+static bool endsWith(const char* str, const char* suffix, bool ignoreCase)
+{
+    if (str == NULL || suffix == NULL)
+        return false;
+    size_t length = strlen(str);
+    size_t suffixLength = strlen(suffix);
+
+    if (suffixLength > length)
+    {
+        return false;
+    }
+
+    size_t offset = length - suffixLength;
+
+    const char* p = str + offset;
+    while (*p != '\0' && *suffix != '\0')
+    {
+        if (ignoreCase)
+        {
+            if (lowercase(*p) != lowercase(*suffix))
+            {
+                return false;
+            }
+        }
+        else if (*p != *suffix)
+        {
+            return false;
+        }
+        
+        ++p;
+        ++suffix;
+    }
+    return true;
+}
+
+
 Scene::Scene(const char* id)
     : _id(id ? id : ""), _activeCamera(NULL), _firstNode(NULL), _lastNode(NULL), _nodeCount(0), 
     _lightColor(1,1,1), _lightDirection(0,-1,0), _bindAudioListenerToCamera(true), _debugBatch(NULL)
@@ -50,6 +97,17 @@ Scene* Scene::create(const char* id)
 
 Scene* Scene::load(const char* filePath)
 {
+    if (endsWith(filePath, ".gpb", true))
+    {
+        Scene* scene = NULL;
+        Bundle* bundle = Bundle::create(filePath);
+        if (bundle)
+        {
+            scene = bundle->loadScene();
+            SAFE_RELEASE(bundle);
+        }
+        return scene;
+    }
     return SceneLoader::load(filePath);
 }
 

+ 2 - 2
gameplay/src/Scene.h

@@ -36,9 +36,9 @@ public:
     static Scene* create(const char* id = NULL);
 
     /**
-     * Loads a scene from the given '.scene' file.
+     * Loads a scene from the given '.scene' or '.gpb' file.
      * 
-     * @param filePath The path to the '.scene' file to load from.
+     * @param filePath The path to the '.scene' or '.gpb' file to load from.
      * @return The loaded scene or <code>NULL</code> if the scene
      *      could not be loaded from the given file.
      * @script{create}