Skip to content

Commit

Permalink
Added support for loading any object that can load from a Properties …
Browse files Browse the repository at this point in the history
…object using a url instead of just a file name.
  • Loading branch information
chrisculy committed May 1, 2012
1 parent ce50dc0 commit bee1a68
Show file tree
Hide file tree
Showing 20 changed files with 200 additions and 85 deletions.
8 changes: 4 additions & 4 deletions gameplay/src/Animation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,14 @@ unsigned long Animation::getDuration() const
return _duration;
}

void Animation::createClips(const char* animationFile)
void Animation::createClips(const char* url)
{
assert(animationFile);
assert(url);

Properties* properties = Properties::create(animationFile);
Properties* properties = Properties::create(url);
assert(properties);

Properties* pAnimation = properties->getNextNamespace();
Properties* pAnimation = (strlen(properties->getNamespace()) > 0) ? properties : properties->getNextNamespace();
assert(pAnimation);

int frameCount = pAnimation->getInt("frameCount");
Expand Down
8 changes: 6 additions & 2 deletions gameplay/src/Animation.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,13 @@ class Animation : public Ref
unsigned long getDuration() const;

/**
* Creates an AnimationClip from an .animation file.
* Creates an AnimationClip from the Properties object defined at the specified URL,
* where the URL is of the format "<file-path>.<extension>#<namespace-id>/<namespace-id>/.../<namespace-id>"
* (and "#<namespace-id>/<namespace-id>/.../<namespace-id>" is optional).
*
* @param url The URL pointing to the Properties object containing the clip definitions.
*/
void createClips(const char* animationFile);
void createClips(const char* url);

/**
* Creates an AnimationClip from the Animation.
Expand Down
8 changes: 4 additions & 4 deletions gameplay/src/AnimationTarget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,14 @@ Animation* AnimationTarget::createAnimation(const char* id, int propertyId, unsi
return animation;
}

Animation* AnimationTarget::createAnimation(const char* id, const char* animationFile)
Animation* AnimationTarget::createAnimation(const char* id, const char* url)
{
assert(animationFile);
assert(url);

Properties* p = Properties::create(animationFile);
Properties* p = Properties::create(url);
assert(p);

Animation* animation = createAnimation(id, p->getNextNamespace());
Animation* animation = createAnimation(id, (strlen(p->getNamespace()) > 0) ? p : p->getNextNamespace());

SAFE_DELETE(p);

Expand Down
8 changes: 5 additions & 3 deletions gameplay/src/AnimationTarget.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,16 @@ class AnimationTarget
Animation* createAnimation(const char* id, int propertyId, unsigned int keyCount, unsigned long* keyTimes, float* keyValues, float* keyInValue, float* keyOutValue, Curve::InterpolationType type);

/**
* Creates an animation on this target using the data from the given properties object.
* Creates an animation on this target using the data from the Properties object defined at the specified URL,
* where the URL is of the format "<file-path>.<extension>#<namespace-id>/<namespace-id>/.../<namespace-id>"
* (and "#<namespace-id>/<namespace-id>/.../<namespace-id>" is optional).
*
* @param id The ID of the animation.
* @param animationFile The animation file defining the animation data.
* @param url The URL pointing to the Properties object defining the animation data.
*
* @return The newly created animation.
*/
Animation* createAnimation(const char* id, const char* animationFile);
Animation* createAnimation(const char* id, const char* url);

/**
* Creates an animation on this target using the data from the given properties object.
Expand Down
14 changes: 7 additions & 7 deletions gameplay/src/AudioSource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,28 +104,28 @@ AudioSource::~AudioSource()
SAFE_RELEASE(_buffer);
}

AudioSource* AudioSource::create(const char* path)
AudioSource* AudioSource::create(const char* url)
{
assert(path);
assert(url);

// Load from a .audio file.
std::string pathStr = path;
std::string pathStr = url;
if (pathStr.find(".audio") != pathStr.npos)
{
Properties* properties = Properties::create(path);
Properties* properties = Properties::create(url);
assert(properties);
if (properties == NULL)
{
return NULL;
}

AudioSource* audioSource = create(properties->getNextNamespace());
AudioSource* audioSource = create((strlen(properties->getNamespace()) > 0) ? properties : properties->getNextNamespace());
SAFE_DELETE(properties);
return audioSource;
}

// Create an audio buffer from this path.
AudioBuffer* buffer = AudioBuffer::create(path);
// Create an audio buffer from this URL.
AudioBuffer* buffer = AudioBuffer::create(url);
if (buffer == NULL)
return NULL;

Expand Down
9 changes: 5 additions & 4 deletions gameplay/src/AudioSource.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@ class AudioSource : public Ref, public Transform::Listener
};

/**
* Create an audio source. This is used to instantiate an Audio Source. Currently only wav, au, raw and .audio files are supported.
*
* @param path The relative location on disk of the sound file or .audio file.
* Create an audio source. This is used to instantiate an Audio Source. Currently only wav, au, and raw files are supported.
* Alternately, a URL specifying a Properties object that defines an audio source can be used (where the URL is of the format
* "<file-path>.<extension>#<namespace-id>/<namespace-id>/.../<namespace-id>" and "#<namespace-id>/<namespace-id>/.../<namespace-id>" is optional).
*
* @param url The relative location on disk of the sound file or a URL specifying a Properties object defining an audio source.
* @return The newly created audio source, or NULL if an audio source cannot be created.
*/
static AudioSource* create(const char* path);
static AudioSource* create(const char* url);

/**
* Create an audio source from the given properties object.
Expand Down
8 changes: 4 additions & 4 deletions gameplay/src/Form.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -36,18 +36,18 @@ namespace gameplay
}
}

Form* Form::create(const char* path)
Form* Form::create(const char* url)
{
// Load Form from .form file.
assert(path);
assert(url);

Properties* properties = Properties::create(path);
Properties* properties = Properties::create(url);
assert(properties);
if (properties == NULL)
return NULL;

// Check if the Properties is valid and has a valid namespace.
Properties* formProperties = properties->getNextNamespace();
Properties* formProperties = (strlen(properties->getNamespace()) > 0) ? properties : properties->getNextNamespace();
assert(formProperties);
if (!formProperties || !(strcmp(formProperties->getNamespace(), "form") == 0))
{
Expand Down
10 changes: 6 additions & 4 deletions gameplay/src/Form.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,13 @@ class Form : public Container
public:

/**
* Create from properties file.
*
* @param path Path to the properties file to create a new form from.
* Creates a form using the data from the Properties object defined at the specified URL,
* where the URL is of the format "<file-path>.<extension>#<namespace-id>/<namespace-id>/.../<namespace-id>"
* (and "#<namespace-id>/<namespace-id>/.../<namespace-id>" is optional).
*
* @param url The URL pointing to the Properties object defining the animation data.
*/
static Form* create(const char* path);
static Form* create(const char* url);

/**
* Get a form from its ID.
Expand Down
8 changes: 4 additions & 4 deletions gameplay/src/Material.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,19 +32,19 @@ Material::~Material()
}
}

Material* Material::create(const char* materialPath)
Material* Material::create(const char* url)
{
assert(materialPath);
assert(url);

// Load the material properties from file
Properties* properties = Properties::create(materialPath);
Properties* properties = Properties::create(url);
assert(properties);
if (properties == NULL)
{
return NULL;
}

Material* material = create(properties->getNextNamespace());
Material* material = create((strlen(properties->getNamespace()) > 0) ? properties : properties->getNextNamespace());
SAFE_DELETE(properties);

return material;
Expand Down
10 changes: 6 additions & 4 deletions gameplay/src/Material.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ class Material : public RenderState
public:

/**
* Creates a material from a specified file path.
*
* @param materialPath Path path to the material file.
* Creates a material using the data from the Properties object defined at the specified URL,
* where the URL is of the format "<file-path>.<extension>#<namespace-id>/<namespace-id>/.../<namespace-id>"
* (and "#<namespace-id>/<namespace-id>/.../<namespace-id>" is optional).
*
* @param url The URL pointing to the Properties object defining the material.
*
* @return A new Material.
*/
static Material* create(const char* materialPath);
static Material* create(const char* url);

/**
* Creates a material from the specified properties object.
Expand Down
8 changes: 4 additions & 4 deletions gameplay/src/Node.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -994,18 +994,18 @@ PhysicsCollisionObject* Node::setCollisionObject(PhysicsCollisionObject::Type ty
return _collisionObject;
}

PhysicsCollisionObject* Node::setCollisionObject(const char* filePath)
PhysicsCollisionObject* Node::setCollisionObject(const char* url)
{
// Load the collision object properties from file.
Properties* properties = Properties::create(filePath);
Properties* properties = Properties::create(url);
assert(properties);
if (properties == NULL)
{
WARN_VARG("Failed to load collision object file: %s", filePath);
WARN_VARG("Failed to load collision object file: %s", url);
return NULL;
}

PhysicsCollisionObject* collisionObject = setCollisionObject(properties->getNextNamespace());
PhysicsCollisionObject* collisionObject = setCollisionObject((strlen(properties->getNamespace()) > 0) ? properties : properties->getNextNamespace());
SAFE_DELETE(properties);

return collisionObject;
Expand Down
8 changes: 5 additions & 3 deletions gameplay/src/Node.h
Original file line number Diff line number Diff line change
Expand Up @@ -520,11 +520,13 @@ class Node : public Transform, public Ref
PhysicsCollisionObject* setCollisionObject(PhysicsCollisionObject::Type type, const PhysicsCollisionShape::Definition& shape, PhysicsRigidBody::Parameters* rigidBodyParameters = NULL);

/**
* Sets the physics collision object for this node using the definition in the given file.
* Sets the physics collision object for this node using the data from the Properties object defined at the specified URL,
* where the URL is of the format "<file-path>.<extension>#<namespace-id>/<namespace-id>/.../<namespace-id>"
* (and "#<namespace-id>/<namespace-id>/.../<namespace-id>" is optional).
*
* @param filePath The path to the file that set the collision object definition.
* @param url The URL pointing to the Properties object defining the physics collision object.
*/
PhysicsCollisionObject* setCollisionObject(const char* filePath);
PhysicsCollisionObject* setCollisionObject(const char* url);

/**
* Sets the physics collision object for this node from the given properties object.
Expand Down
10 changes: 5 additions & 5 deletions gameplay/src/ParticleEmitter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -82,18 +82,18 @@ ParticleEmitter* ParticleEmitter::create(const char* textureFile, TextureBlendin
return emitter;
}

ParticleEmitter* ParticleEmitter::create(const char* particleFile)
ParticleEmitter* ParticleEmitter::create(const char* url)
{
assert(particleFile);
assert(url);

Properties* properties = Properties::create(particleFile);
Properties* properties = Properties::create(url);
if (!properties)
{
LOG_ERROR_VARG("Error loading ParticleEmitter: Could not load file: %s", particleFile);
LOG_ERROR_VARG("Error loading ParticleEmitter: Could not load file: %s", url);
return NULL;
}

ParticleEmitter* particle = create(properties->getNextNamespace());
ParticleEmitter* particle = create((strlen(properties->getNamespace()) > 0) ? properties : properties->getNextNamespace());
SAFE_DELETE(properties);

return particle;
Expand Down
10 changes: 6 additions & 4 deletions gameplay/src/ParticleEmitter.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,13 +154,15 @@ class ParticleEmitter : public Ref
};

/**
* Creates a particle emitter from a .particle file.
*
* @param particleFile The .particle file to load.
* Creates a particle emitter using the data from the Properties object defined at the specified URL,
* where the URL is of the format "<file-path>.<extension>#<namespace-id>/<namespace-id>/.../<namespace-id>"
* (and "#<namespace-id>/<namespace-id>/.../<namespace-id>" is optional).
*
* @param url The URL pointing to the Properties object defining the particle emitter.
*
* @return An initialized ParticleEmitter.
*/
static ParticleEmitter* create(const char* particleFile);
static ParticleEmitter* create(const char* url);

/**
* Creates a particle emitter from the specified properties object.
Expand Down
Loading

0 comments on commit bee1a68

Please sign in to comment.