mirror of https://github.com/axmolengine/axmol.git
Merge pull request #151 from lvlonggame/v3
optimize Bundle3D about multi-animation loading.
This commit is contained in:
commit
75c55651f4
|
@ -1403,9 +1403,22 @@ bool Bundle3D::loadAnimationDataJson(const std::string& id, Animation3DData* ani
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Bundle3D::loadAnimationDataBinary(const std::string& id, Animation3DData* animationdata)
|
bool Bundle3D::loadAnimationDataBinary(const std::string& id, Animation3DData* animationdata)
|
||||||
|
{
|
||||||
|
if(_version == "0.1" || _version == "0.3" || _version == "0.4")
|
||||||
{
|
{
|
||||||
if (!seekToFirstType(BUNDLE_TYPE_ANIMATIONS))
|
if (!seekToFirstType(BUNDLE_TYPE_ANIMATIONS))
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// if id is not a null string, we need to add a suffix of "animation" for seeding.
|
||||||
|
std::string id_ = id;
|
||||||
|
if(id != "") id_ = id + "animation";
|
||||||
|
|
||||||
|
if (!seekToFirstType(BUNDLE_TYPE_ANIMATIONS, id_))
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
unsigned int animNum = 1;
|
unsigned int animNum = 1;
|
||||||
if(_version == "0.3" || _version == "0.4")
|
if(_version == "0.3" || _version == "0.4")
|
||||||
{
|
{
|
||||||
|
@ -1459,7 +1472,7 @@ bool Bundle3D::loadAnimationDataBinary(const std::string& id, Animation3DData* a
|
||||||
|
|
||||||
// transform flag
|
// transform flag
|
||||||
unsigned char transformFlag(0);
|
unsigned char transformFlag(0);
|
||||||
if (_version == "0.4")
|
if (_version != "0.1" && _version != "0.3")
|
||||||
{
|
{
|
||||||
if (!_binaryReader.read(&transformFlag))
|
if (!_binaryReader.read(&transformFlag))
|
||||||
{
|
{
|
||||||
|
@ -1470,7 +1483,7 @@ bool Bundle3D::loadAnimationDataBinary(const std::string& id, Animation3DData* a
|
||||||
|
|
||||||
// rotation
|
// rotation
|
||||||
bool hasRotate = true;
|
bool hasRotate = true;
|
||||||
if (_version == "0.4")
|
if (_version != "0.1" && _version != "0.3")
|
||||||
hasRotate = transformFlag & 0x01;
|
hasRotate = transformFlag & 0x01;
|
||||||
|
|
||||||
if (hasRotate)
|
if (hasRotate)
|
||||||
|
@ -1486,7 +1499,7 @@ bool Bundle3D::loadAnimationDataBinary(const std::string& id, Animation3DData* a
|
||||||
|
|
||||||
// scale
|
// scale
|
||||||
bool hasScale = true;
|
bool hasScale = true;
|
||||||
if (_version == "0.4")
|
if (_version != "0.1" && _version != "0.3")
|
||||||
hasScale = (transformFlag >> 1) & 0x01;
|
hasScale = (transformFlag >> 1) & 0x01;
|
||||||
|
|
||||||
if (hasScale)
|
if (hasScale)
|
||||||
|
@ -1502,7 +1515,7 @@ bool Bundle3D::loadAnimationDataBinary(const std::string& id, Animation3DData* a
|
||||||
|
|
||||||
// translation
|
// translation
|
||||||
bool hasTranslation = true;
|
bool hasTranslation = true;
|
||||||
if (_version == "0.4")
|
if (_version != "0.1" && _version != "0.3")
|
||||||
hasTranslation = (transformFlag >> 2) & 0x01;
|
hasTranslation = (transformFlag >> 2) & 0x01;
|
||||||
|
|
||||||
if (hasTranslation)
|
if (hasTranslation)
|
||||||
|
@ -1938,7 +1951,7 @@ void Bundle3D::getModelRelativePath(const std::string& path)
|
||||||
_modelPath = path.substr(0, index + 1);
|
_modelPath = path.substr(0, index + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
Reference* Bundle3D::seekToFirstType(unsigned int type)
|
Reference* Bundle3D::seekToFirstType(unsigned int type, const std::string& id)
|
||||||
{
|
{
|
||||||
// for each Reference
|
// for each Reference
|
||||||
for (unsigned int i = 0; i < _referenceCount; ++i)
|
for (unsigned int i = 0; i < _referenceCount; ++i)
|
||||||
|
@ -1946,6 +1959,12 @@ Reference* Bundle3D::seekToFirstType(unsigned int type)
|
||||||
Reference* ref = &_references[i];
|
Reference* ref = &_references[i];
|
||||||
if (ref->type == type)
|
if (ref->type == type)
|
||||||
{
|
{
|
||||||
|
// if id is not a null string, we also need to check the Reference's id.
|
||||||
|
if (id != "" && id != ref->id)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
// Found a match
|
// Found a match
|
||||||
if (_binaryReader.seek(ref->offset, SEEK_SET) == false)
|
if (_binaryReader.seek(ref->offset, SEEK_SET) == false)
|
||||||
{
|
{
|
||||||
|
@ -1958,6 +1977,7 @@ Reference* Bundle3D::seekToFirstType(unsigned int type)
|
||||||
return nullptr;
|
return nullptr;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Bundle3D::Bundle3D()
|
Bundle3D::Bundle3D()
|
||||||
:_isBinary(false),
|
:_isBinary(false),
|
||||||
_modelPath(""),
|
_modelPath(""),
|
||||||
|
|
|
@ -146,8 +146,9 @@ protected:
|
||||||
/*
|
/*
|
||||||
* set the read position in buffer to the target type
|
* set the read position in buffer to the target type
|
||||||
* @param The data type
|
* @param The data type
|
||||||
|
* @param The data id
|
||||||
*/
|
*/
|
||||||
Reference* seekToFirstType(unsigned int type);
|
Reference* seekToFirstType(unsigned int type, const std::string& id = "");
|
||||||
|
|
||||||
CC_CONSTRUCTOR_ACCESS:
|
CC_CONSTRUCTOR_ACCESS:
|
||||||
Bundle3D();
|
Bundle3D();
|
||||||
|
|
Loading…
Reference in New Issue