Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Merge pull request #14 from blackberry/next

Next
  • Loading branch information...
commit 4c5a725386ef34d56fd032a796114d5c3928657c 2 parents 2f52ca3 + 35cf175
@seanpaultaylor seanpaultaylor authored
View
8 gameplay-encoder/gameplay-encoder.vcxproj
@@ -145,16 +145,16 @@
</PrecompiledHeader>
<WarningLevel>Level4</WarningLevel>
<Optimization>Disabled</Optimization>
- <PreprocessorDefinitions>WIN32;_DEBUG;_CONSOLE;_CRT_SECURE_NO_WARNINGS;NO_BOOST;NO_ZAE;USE_FBX;%(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>
+ <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</AdditionalIncludeDirectories>
<DisableLanguageExtensions>
</DisableLanguageExtensions>
</ClCompile>
<Link>
<SubSystem>Console</SubSystem>
<GenerateDebugInformation>true</GenerateDebugInformation>
- <AdditionalLibraryDirectories>../external-deps/freetype2/lib/win32;../external-deps/collada-dom/lib/win32;../external-deps/libpng/lib/win32;../external-deps/zlib/lib/win32;C:/Program Files/Autodesk/FBX/FbxSdk/2012.2/lib/vs2010/x86</AdditionalLibraryDirectories>
- <AdditionalDependencies>freetype245.lib;libcollada14dom22-d.lib;libpng14.lib;zlib.lib;fbxsdk-2012.2-mdd.lib;wininet.lib;%(AdditionalDependencies)</AdditionalDependencies>
+ <AdditionalLibraryDirectories>../external-deps/freetype2/lib/win32;../external-deps/collada-dom/lib/win32;../external-deps/libpng/lib/win32;../external-deps/zlib/lib/win32</AdditionalLibraryDirectories>
+ <AdditionalDependencies>freetype245.lib;libcollada14dom22-d.lib;libpng14.lib;zlib.lib;%(AdditionalDependencies)</AdditionalDependencies>
<IgnoreSpecificDefaultLibraries>MSVCRT</IgnoreSpecificDefaultLibraries>
</Link>
<PostBuildEvent>
View
20 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);
}
}
}
View
2  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");
View
10 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);
View
4 gameplay-encoder/src/GPBFile.h
@@ -65,6 +65,10 @@ class GPBFile
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);
/**
View
4 gameplay/src/Game.h
@@ -191,6 +191,7 @@ class Game
* @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 @@ class Game
* 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
*/
View
78 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;
}
View
11 gameplay/src/Package.h
@@ -253,6 +253,17 @@ class Package : public Ref
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.
*
* @param m A pointer to float array of size 16.
Please sign in to comment.
Something went wrong with that request. Please try again.