nkligang / ccbi2ccb Goto Github PK
View Code? Open in Web Editor NEWConvert CocosBuilder exported .ccbi to Editable .ccb file format
Convert CocosBuilder exported .ccbi to Editable .ccb file format
I'm looking at a section of this code (line 254-271 in ccbi2ccb.cpp) and right now it looks like this:
} else if (m_mapPropertyCount.size() > 1) {
std::map<std::string, int>::iterator itClass = m_mapPropertyCount.begin();
std::string klass = itClass->first;
int prority = 0;
itClass++;
for (; itClass != m_mapPropertyCount.end(); itClass++)
{
std::map<std::string, int>::iterator parenetIt = m_mapClassPriorty.find(itClass->first);
if (parenetIt != m_mapClassPriorty.end())
{
if (parenetIt->second > prority) {
klass = itClass->first;
prority = parenetIt->second;
}
}
}
return klass;
}
I'm a bit confused by how the first part of it works.
//Okay, make the iterator. That makes sense
std::map<std::string, int>::iterator itClass = m_mapPropertyCount.begin();
//Set klass to the first item. Okay, I guess you could do it like that...
std::string klass = itClass->first;
// Wait what? We are not setting it to the actual priority of the value of klass???
int prority = 0;
itClass++;
So the first class in the list is being set as having a priority of 0, regardless of it's actual priority? I think this part of the function should be written as something like this:
} else if (m_mapPropertyCount.size() > 1) {
std::map<std::string, int>::iterator itClass = m_mapPropertyCount.begin();
std::string klass = "";
int prority = 0;
for (; itClass != m_mapPropertyCount.end(); itClass++)
{
std::map<std::string, int>::iterator parenetIt = m_mapClassPriorty.find(itClass->first);
if (parenetIt != m_mapClassPriorty.end())
{
if (parenetIt->second > prority) {
klass = itClass->first;
prority = parenetIt->second;
}
}
}
return klass;
}
By writing it this way, we start with an empty string, which would be considered as a class that has a priority of 0. All other values would have a priority of 1 or higher, meaning the first class in the list would be set as the value of klass, and the priority would be correct.
Or maybe I am missing something?
size_t ccbiReader::readBytes(void * _DstBuf, size_t _ElementSize, size_t _Count)
{
size_t _s = _ElementSize * _Count;
if (currentByte + _s <= (size_t)byteSize)
{
memcpy(_DstBuf, (char*)bytes + currentByte, _s);
currentByte += (int)_s;
return _s;
}
else if (currentByte < byteSize)
{
memcpy(_DstBuf, (char*)bytes + currentByte, byteSize - currentByte);
currentByte = byteSize;
return byteSize - currentByte; // This is line 158
}
else
{
return 0;
}
}
Line 158 should be returning the number of bytes read, but because of line 157 (currentByte = byteSize;
) , line 158 will always calculate to 0. This is because currentByte was changed before the amount read was calculated. A correction would look something like this:
size_t ccbiReader::readBytes(void * _DstBuf, size_t _ElementSize, size_t _Count)
{
size_t _s = _ElementSize * _Count;
if (currentByte + _s <= (size_t)byteSize)
{
memcpy(_DstBuf, (char*)bytes + currentByte, _s);
currentByte += (int)_s;
return _s;
}
else if (currentByte < byteSize)
{
memcpy(_DstBuf, (char*)bytes + currentByte, byteSize - currentByte);
size_t ret = byteSize - currentByte;
currentByte = byteSize;
return ret;
}
else
{
return 0;
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.