Ver código fonte

Merge pull request #102 from blackberry-gaming/next-dgough

Next dgough
Sean Paul Taylor 14 anos atrás
pai
commit
470a82ac3b

+ 1 - 1
gameplay-encoder/gameplay-encoder.vcxproj

@@ -145,7 +145,7 @@
       </PrecompiledHeader>
       <WarningLevel>Level4</WarningLevel>
       <Optimization>Disabled</Optimization>
-      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;NO_BOOST;NO_ZAE;USE_FBX;%(PreprocessorDefinitions)</PreprocessorDefinitions>
+      <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;NO_BOOST;NO_ZAE;%(PreprocessorDefinitions)</PreprocessorDefinitions>
       <AdditionalIncludeDirectories>../external-deps/freetype2/include;../external-deps/collada-dom/include;../external-deps/collada-dom/include/1.4;../external-deps/libpng/include;../external-deps/zlib/include;C:/Program Files/Autodesk/FBX/FbxSdk/2012.2/include</AdditionalIncludeDirectories>
       <DisableLanguageExtensions>
       </DisableLanguageExtensions>

+ 14 - 6
gameplay-encoder/src/DAESceneEncoder.cpp

@@ -272,23 +272,31 @@ void DAESceneEncoder::write(const std::string& filepath, const EncoderArguments&
         {
             if (nodeId == NULL)
             {
-                // If the -n <node_id> parameter was not passed then write out the entire scene.
+                // If the -i <node_id> parameter was not passed then write out the entire scene.
                 begin();
                 loadScene((domVisual_scene*)scene);
                 end("load scene");
             }
             else
             {
-                // Resolve/Search for the node the user specified with the -n <node_id> parameter.
+                // Resolve/Search for the node the user specified with the -i <node_id> parameter.
                 daeSIDResolver resolver(scene, nodeId);
-                const domNode* node = daeSafeCast<domNode>(resolver.getElement());
-                if (node)
+                domNode* nodeElement = daeSafeCast<domNode>(resolver.getElement());
+                if (nodeElement)
                 {
-                    //createNode(node, NULL);
+                    Node* node = loadNode(nodeElement, NULL);
+                    if (node)
+                    {
+                        _gamePlayFile.addScenelessNode(node);
+                    }
+                    else
+                    {
+                        fprintf(stderr,"COLLADA File loaded to the dom, but failed to load node %s.\n", nodeId);
+                    }
                 }
                 else
                 {
-                    fprintf(stderr,"COLLADA File loaded to the dom, but node was not found with -n%s.\n", nodeId);
+                    fprintf(stderr,"COLLADA File loaded to the dom, but node was not found with node ID %s.\n", nodeId);
                 }
             }
         }

+ 1 - 1
gameplay-encoder/src/EncoderArguments.cpp

@@ -141,7 +141,7 @@ void EncoderArguments::printUsage() const
     fprintf(stderr,"  .ttf\t(TrueType Font)\n");
     fprintf(stderr,"\n");
     fprintf(stderr,"COLLADA and FBX file options:\n");
-    fprintf(stderr,"  -i<id>\t\tFilter by node ID.\n");
+    fprintf(stderr,"  -i <id>\t\tFilter by node ID.\n");
     fprintf(stderr,"  -t\t\t\tWrite text/xml.\n");
     fprintf(stderr,"  -groupAnimations <node id> <animation id>\n" \
         "\t\t\tGroup all animation channels targetting the nodes into a new animation.\n");

+ 10 - 0
gameplay-encoder/src/GPBFile.cpp

@@ -115,6 +115,16 @@ void GPBFile::addNode(Node* node)
     _nodes.push_back(node);
 }
 
+void GPBFile::addScenelessNode(Node* node)
+{
+    addToRefTable(node);
+    _nodes.push_back(node);
+    // Nodes are normally written to file as part of a scene. 
+    // Nodes that don't belong to a scene need to be written on their own (outside a scene).
+    // That is why node is added to the list of objects here.
+    _objects.push_back(node);
+}
+
 void GPBFile::addAnimation(Animation* animation)
 {
     _animations.add(animation);

+ 4 - 0
gameplay-encoder/src/GPBFile.h

@@ -65,6 +65,10 @@ public:
     void addLight(Light* light);
     void addMesh(Mesh* mesh);
     void addNode(Node* node);
+    /**
+     * Adds a node that does not belong to a scene.
+     */
+    void addScenelessNode(Node* node);
     void addAnimation(Animation* animation);
 
     /**

+ 4 - 0
gameplay/src/Game.h

@@ -191,6 +191,7 @@ public:
      * @param evt The key event that occured.
      * @param key The key code that was pressed, released or repeated.
      * 
+     * @see Keyboard::KeyEvent
      * @see Keyboard::Key
      */
     virtual void keyEvent(Keyboard::KeyEvent evt, int key);
@@ -199,6 +200,9 @@ public:
      * Touch callback on touch events.
      *
      * @param evt The touch event that occurred.
+     * @param x The x position of the touch in pixels. Left edge is zero.
+     * @param y The y position of the touch in pixels. Top edge is zero.
+     * @param contactIndex The order of occurrence for multiple touch contacts starting at zero.
      *
      * @see Touch::TouchEvent
      */

+ 36 - 42
gameplay/src/Package.cpp

@@ -66,12 +66,30 @@ bool Package::readArray(unsigned int* length, T** ptr)
     }
     if (*length > 0)
     {
-       *ptr = new T[*length];
-       if (fread(*ptr, sizeof(T), *length, _file) != *length)
-       {
-           SAFE_DELETE_ARRAY(*ptr);
-           return false;
-       }
+        *ptr = new T[*length];
+        if (fread(*ptr, sizeof(T), *length, _file) != *length)
+        {
+            SAFE_DELETE_ARRAY(*ptr);
+            return false;
+        }
+    }
+    return true;
+}
+
+template <class T>
+bool Package::readArray(unsigned int* length, std::vector<T>* values)
+{
+    if (!read(length))
+    {
+        return false;
+    }
+    if (*length > 0 && values)
+    {
+        values->resize(*length);
+        if (fread(&(*values)[0], sizeof(T), *length, _file) != *length)
+        {
+            return false;
+        }
     }
     return true;
 }
@@ -87,20 +105,16 @@ std::string readString(FILE* fp)
     // Sanity check to detect if string length is far too big
     assert(length < PACKAGE_MAX_STRING_LENGTH);
 
-    char* str = new char[length + 1];
+    std::string str;
     if (length > 0)
     {
-        if (fread(str, 1, length, fp) != length)
+        str.resize(length);
+        if (fread(&str[0], 1, length, fp) != length)
         {
-            SAFE_DELETE_ARRAY(str);
             return std::string();
         }
     }
-
-    str[length] = '\0';
-    std::string result(str);
-    SAFE_DELETE_ARRAY(str);
-    return result;
+    return str;
 }
 
 Package* Package::create(const char* path)
@@ -907,11 +921,11 @@ Animation* Package::readAnimationChannel(Scene* scene, Animation* animation, con
         }
     }
 
-    unsigned long* keyTimes = NULL;
-    float* values = NULL;
-    float* tangentsIn = NULL;
-    float* tangentsOut = NULL;
-    unsigned int* interpolation = NULL;
+    std::vector<unsigned long> keyTimes;
+    std::vector<float> values;
+    std::vector<float> tangentsIn;
+    std::vector<float> tangentsOut;
+    std::vector<unsigned long> interpolation;
 
     // length of the arrays
     unsigned int keyTimesCount;
@@ -924,7 +938,6 @@ Animation* Package::readAnimationChannel(Scene* scene, Animation* animation, con
     if (!readArray(&keyTimesCount, &keyTimes))
     {
         LOG_ERROR_VARG("Failed to read %s for %s: %s", "keyTimes", "animation", id);
-        SAFE_DELETE_ARRAY(keyTimes);
         return NULL;
     }
     
@@ -932,8 +945,6 @@ Animation* Package::readAnimationChannel(Scene* scene, Animation* animation, con
     if (!readArray(&valuesCount, &values))
     {
         LOG_ERROR_VARG("Failed to read %s for %s: %s", "values", "animation", id);
-        SAFE_DELETE_ARRAY(keyTimes);
-        SAFE_DELETE_ARRAY(values);
         return NULL;
     }
     
@@ -941,9 +952,6 @@ Animation* Package::readAnimationChannel(Scene* scene, Animation* animation, con
     if (!readArray(&tangentsInCount, &tangentsIn))
     {
         LOG_ERROR_VARG("Failed to read %s for %s: %s", "tangentsIn", "animation", id);
-        SAFE_DELETE_ARRAY(keyTimes);
-        SAFE_DELETE_ARRAY(values);
-        SAFE_DELETE_ARRAY(tangentsIn);
         return NULL;
     }
     
@@ -951,10 +959,6 @@ Animation* Package::readAnimationChannel(Scene* scene, Animation* animation, con
     if (!readArray(&tangentsOutCount, &tangentsOut))
     {
         LOG_ERROR_VARG("Failed to read %s for %s: %s", "tangentsOut", "animation", id);
-        SAFE_DELETE_ARRAY(keyTimes);
-        SAFE_DELETE_ARRAY(values);
-        SAFE_DELETE_ARRAY(tangentsIn);
-        SAFE_DELETE_ARRAY(tangentsOut);
         return NULL;
     }
     
@@ -962,11 +966,6 @@ Animation* Package::readAnimationChannel(Scene* scene, Animation* animation, con
     if (!readArray(&interpolationCount, &interpolation))
     {
         LOG_ERROR_VARG("Failed to read %s for %s: %s", "interpolation", "animation", id);
-        SAFE_DELETE_ARRAY(keyTimes);
-        SAFE_DELETE_ARRAY(values);
-        SAFE_DELETE_ARRAY(tangentsIn);
-        SAFE_DELETE_ARRAY(tangentsOut);
-        SAFE_DELETE_ARRAY(interpolation);
         return NULL;
     }
 
@@ -976,23 +975,18 @@ Animation* Package::readAnimationChannel(Scene* scene, Animation* animation, con
     // TODO: Handle other target attributes later.
     if (targetAttribute > 0)
     {
+        assert(keyTimes.size() > 0 && values.size() > 0);
         if (animation == NULL)
         {
             // TODO: This code currently assumes LINEAR only
-            animation = controller->createAnimation(animationId, target, targetAttribute, keyTimesCount, keyTimes, values, Curve::LINEAR);
+            animation = controller->createAnimation(animationId, target, targetAttribute, keyTimesCount, &keyTimes[0], &values[0], Curve::LINEAR);
         }
         else
         {
-            animation->createChannel(target, targetAttribute, keyTimesCount, keyTimes, values, Curve::LINEAR);
+            animation->createChannel(target, targetAttribute, keyTimesCount, &keyTimes[0], &values[0], Curve::LINEAR);
         }
     }
 
-    SAFE_DELETE_ARRAY(keyTimes);
-    SAFE_DELETE_ARRAY(values);
-    SAFE_DELETE_ARRAY(tangentsIn);
-    SAFE_DELETE_ARRAY(tangentsOut);
-    SAFE_DELETE_ARRAY(interpolation);
-
     return animation;
 }
 

+ 11 - 0
gameplay/src/Package.h

@@ -252,6 +252,17 @@ private:
     template <class T>
     bool readArray(unsigned int* length, T** ptr);
 
+    /**
+     * Reads an array of values and the array length from the current file position.
+     * 
+     * @param length A pointer to where the length of the array will be copied to.
+     * @param values A pointer to the vector to copy the values to. The vector will be resized if it is smaller than length.
+     * 
+     * @return True if successful, false if an error occurred.
+     */
+    template <class T>
+    bool readArray(unsigned int* length, std::vector<T>* values);
+
     /**
      * Reads 16 floats from the current file position.
      *