Merge pull request #44 from lvlonggame/v3

modify bug about parent index is -1
This commit is contained in:
XiaoYang 2014-06-27 15:55:29 +08:00
commit 39dfda1ebe
7 changed files with 13450 additions and 139 deletions

View File

@ -102,6 +102,7 @@ void getChildMap(std::map<int, std::vector<int> >& map, SkinData* skinData, cons
{
skinData->addNodeBoneNames(parent_name);
skinData->nodeBoneOriginMatrices.push_back(transform);
parent_name_index = skinData->getBoneNameIndex(parent_name);
}
else if (parent_name_index < skinData->skinBoneNames.size())
{
@ -110,12 +111,7 @@ void getChildMap(std::map<int, std::vector<int> >& map, SkinData* skinData, cons
// set root bone index
if(skinData->rootBoneIndex < 0)
{
if (parent_name_index < 0)
parent_name_index = skinData->getBoneNameIndex(parent_name);
skinData->rootBoneIndex = parent_name_index;
}
if (!val.HasMember(SKINDATA_CHILDREN))
return;
@ -485,7 +481,7 @@ bool Bundle3D::loadBinary(const std::string& path)
// Read all refs
CC_SAFE_DELETE_ARRAY(_references);
_references = new Reference[_referenceCount];
for (size_t i = 0; i < _referenceCount; ++i)
for (ssize_t i = 0; i < _referenceCount; ++i)
{
if ((_references[i].id = _binaryReader.readString()).empty() ||
_binaryReader.read(&_references[i].type, 4, 1) != 1 ||
@ -546,12 +542,12 @@ bool Bundle3D::loadMeshDataBinary(MeshData* meshdata)
}
// Read index data
size_t meshPartCount = 1;
ssize_t meshPartCount = 1;
//_binaryReader.read(&meshPartCount, 4, 1);
for (size_t i = 0; i < meshPartCount; ++i)
for (ssize_t i = 0; i < meshPartCount; ++i)
{
size_t nIndexCount;
ssize_t nIndexCount;
if (_binaryReader.read(&nIndexCount, 4, 1) != 1)
{
CCLOGINFO("Failed to read meshdata: nIndexCount '%s'.", _path.c_str());
@ -706,24 +702,24 @@ bool Bundle3D::loadAnimationDataBinary(Animation3DData* animationdata)
return false;
}
size_t animNum;
ssize_t animNum;
if (!_binaryReader.read(&animNum))
{
CCLOGINFO("Failed to read AnimationData: animNum '%s'.", _path.c_str());
return false;
}
for (size_t i = 0; i < animNum; ++i)
for (ssize_t i = 0; i < animNum; ++i)
{
std::string boneName = _binaryReader.readString();
size_t keyframeNum;
ssize_t keyframeNum;
if (!_binaryReader.read(&keyframeNum))
{
CCLOGINFO("Failed to read AnimationData: keyframeNum '%s'.", _path.c_str());
return false;
}
for (size_t j = 0; j < keyframeNum; ++j)
for (ssize_t j = 0; j < keyframeNum; ++j)
{
float keytime;
if (!_binaryReader.read(&keytime))

View File

@ -12,7 +12,7 @@ BundleReader::BundleReader()
BundleReader::~BundleReader()
{
//close();
};
void BundleReader::init(char* lpbuffer, unsigned int length)
@ -22,55 +22,38 @@ void BundleReader::init(char* lpbuffer, unsigned int length)
m_length = length;
}
//BundleReader* BundleReader::create(char* lpbuffer, unsigned int length)
//{
// if (lpbuffer)
// {
// BundleReader* stream = new BundleReader();
// stream->init(lpbuffer, length);
// return stream;
// }
// return NULL;
//}
//void BundleReader::close()
//{
// CC_SAFE_DELETE(m_buffer);
//}
size_t BundleReader::read(void* ptr, size_t size, size_t count)
ssize_t BundleReader::read(void* ptr, ssize_t size, ssize_t count)
{
if (!m_buffer || eof())
return 0;
size_t validCount;
size_t validLength = m_length - m_position;
size_t needLength = size*count;
char* ptr1 = (char*)ptr;
if(validLength <= needLength)
{
validCount = validLength/size;
size_t readLength = size*validCount;
memcpy(ptr1,(char*)m_buffer+m_position,readLength);
ptr1 += readLength;
m_position += readLength;
readLength = validLength - readLength;
if(readLength>0)
{
memcpy(ptr1,(char*)m_buffer+m_position,readLength);
m_position += readLength;
validCount+=1;
}
}
else
{
memcpy(ptr1,(char*)m_buffer+m_position,needLength);
m_position += needLength;
validCount = count;
}
//*ptr1 = 0;
ssize_t validCount;
ssize_t validLength = m_length - m_position;
ssize_t needLength = size*count;
char* ptr1 = (char*)ptr;
if(validLength <= needLength)
{
validCount = validLength/size;
ssize_t readLength = size*validCount;
memcpy(ptr1,(char*)m_buffer+m_position,readLength);
ptr1 += readLength;
m_position += readLength;
readLength = validLength - readLength;
if(readLength>0)
{
memcpy(ptr1,(char*)m_buffer+m_position,readLength);
m_position += readLength;
validCount+=1;
}
}
else
{
memcpy(ptr1,(char*)m_buffer+m_position,needLength);
m_position += needLength;
validCount = count;
}
return validCount;
return validCount;
}
char* BundleReader::readLine(int num,char* line)
@ -78,33 +61,32 @@ char* BundleReader::readLine(int num,char* line)
if (!m_buffer)
return 0;
//char* str = new char[num];
char* buffer = (char*)m_buffer+m_position;
char* buffer = (char*)m_buffer+m_position;
char* p = line;
char c;
ssize_t readNum = 0;
while((c=*buffer) != 10 && readNum < (ssize_t)num && m_position<(long int)m_length)
{
*p = c;
p++;
buffer++;
m_position++;
readNum++;
}
*p = '\0';
char* p = line;
char c;
size_t readNum = 0;
while((c=*buffer) != 10 && readNum < (size_t)num && m_position<(long int)m_length)
{
*p = c;
p++;
buffer++;
m_position++;
readNum++;
}
*p = '\0';
return line;
return line;
}
bool BundleReader::eof()
{
if (!m_buffer)
return true;
return ((size_t)tell()) >= length();
return ((ssize_t)tell()) >= length();
}
size_t BundleReader::length()
ssize_t BundleReader::length()
{
return m_length;
}
@ -121,30 +103,30 @@ bool BundleReader::seek(long int offset, int origin)
if (!m_buffer)
return false;
if(origin == SEEK_CUR)
{
m_position += offset;
}
else if(origin == SEEK_SET)
{
m_position = offset;
}
else if(origin == SEEK_END)
{
m_position = m_length+offset;
}
else
return false;
if(origin == SEEK_CUR)
{
m_position += offset;
}
else if(origin == SEEK_SET)
{
m_position = offset;
}
else if(origin == SEEK_END)
{
m_position = m_length+offset;
}
else
return false;
return true;
return true;
}
bool BundleReader::rewind()
{
if (m_buffer != NULL)
{
m_position = 0;
return true;
m_position = 0;
return true;
}
return false;
}
@ -152,7 +134,7 @@ bool BundleReader::rewind()
std::string BundleReader::readString()
{
unsigned int length;
if(read(&length, 4, 1) != 1)
if(read(&length, 4, 1) != 1)
{
return std::string();
}
@ -161,7 +143,7 @@ std::string BundleReader::readString()
if (length > 0)
{
str.resize(length);
if (read(&str[0], 1, length) != length)
if (read(&str[0], 1, length) != length)
{
return std::string();
}

View File

@ -42,94 +42,84 @@ class BundleReader: public cocos2d::Ref
public:
/**
* Structor
*/
*/
BundleReader();
/**
* inicial
*/
*/
~BundleReader();
/**
* initialise
* @param lpbuffer The data buffer pointer
* @param length The data buffer size
*/
void init(char* lpbuffer, unsigned int length);
/** creates an BundleReader with lpbuffer and length
* @param lpbuffer The pointer to the file data
* @param length The size for lpbuffer in bytes
*/
//static BundleReader* create(char* lpbuffer, unsigned int length);
void init(char* lpbuffer, unsigned int length);
/**
* Close and delete buffer
*/
//void close();
/**
* Reads an array of elements.
*
* @param ptr The pointer to the memory to copy into.
* The available size should be at least bytes.
* @param size The size of each element to be read, in bytes.
* @param count The number of elements to read.
*
* @return The number of elements read.
*
* @param ptr The pointer to the memory to copy into.
* The available size should be at least bytes.
* @param size The size of each element to be read, in bytes.
* @param count The number of elements to read.
*
* @return The number of elements read.
*/
size_t read(void* ptr, size_t size, size_t count);
ssize_t read(void* ptr, ssize_t size, ssize_t count);
/**
/**
* Reads a line from the buffer.
*/
char* readLine(int num, char* line);
char* readLine(int num, char* line);
/**
/**
* Returns true if the end of the buffer has been reached.
*/
bool eof();
/**
/**
* Returns the length of the buffer in bytes.
*/
size_t length();
ssize_t length();
/**
/**
* Returns the position of the file pointer.
*/
long int tell();
/**
/**
* Sets the position of the file pointer.
*/
bool seek(long int offset, int origin);
/**
* Sets the file pointer at the start of the file.
*/
/**
* Sets the file pointer at the start of the file.
*/
bool rewind();
/**
* read binary typed value.
*/
template<typename T> bool read(T* ptr);
template<typename T> bool readArray(unsigned int* length, std::vector<T>* values);
/**
* read binary typed value.
*/
template<typename T> bool read(T* ptr);
template<typename T> bool readArray(unsigned int* length, std::vector<T>* values);
/**
* first read length, then read string text
*/
/**
* first read length, then read string text
*/
std::string readString();
bool readMatrix(float* m);
private:
long int m_position;
size_t m_length;
ssize_t m_length;
char* m_buffer;
};
// template read routines
/**
* template read routines
*/
template<typename T>
inline bool BundleReader::read(T *ptr)
{

View File

@ -542,8 +542,10 @@ std::string Sprite3DWithSkinTest::subtitle() const
void Sprite3DWithSkinTest::addNewSpriteWithCoords(Vec2 p)
{
std::string fileName = "Sprite3DTest/girl.c3b";
std::string fileName = "Sprite3DTest/orc.c3b";
auto sprite = Sprite3D::create(fileName);
sprite->setScale(3);
sprite->setRotation3D(Vec3(0,180,0));
addChild(sprite);
sprite->setPosition( Vec2( p.x, p.y) );

Binary file not shown.

After

Width:  |  Height:  |  Size: 256 KiB

Binary file not shown.

File diff suppressed because it is too large Load Diff