Merge pull request #934 from dumganhar/gles20

fixed #1176: Changed linebreak symbol to UNIX format ('\n'),replaced 'tab' with four spaces.
This commit is contained in:
James Chen 2012-05-29 02:15:58 -07:00
commit 1075b05fa6
46 changed files with 2040 additions and 2040 deletions

View File

@ -51,7 +51,7 @@ private:
static CCNode* ccObjectFromDictionary(CCDictionary* dict, CCDictionary* extraProps, static CCNode* ccObjectFromDictionary(CCDictionary* dict, CCDictionary* extraProps,
const char* assetsDir, CCNode* owner, CCNode* root); const char* assetsDir, CCNode* owner, CCNode* root);
// read different types of values from dict // read different types of values from dict
static int intValFromDict(CCDictionary* dict, const std::string key); static int intValFromDict(CCDictionary* dict, const std::string key);
@ -73,7 +73,7 @@ private:
const std::string key); const std::string key);
private: private:
// set properties // set properties
static void setExtraProp(CCObject* prop, const char* key, int tag, CCDictionary* dict); static void setExtraProp(CCObject* prop, const char* key, int tag, CCDictionary* dict);

View File

@ -33,30 +33,30 @@ USING_NS_CC_EXT;
int CCBReader::intValFromDict(CCDictionary* dict, const std::string key) int CCBReader::intValFromDict(CCDictionary* dict, const std::string key)
{ {
CCString* valueString = (CCString*) dict->objectForKey(key.c_str()); CCString* valueString = (CCString*) dict->objectForKey(key.c_str());
return valueString->intValue(); return valueString->intValue();
} }
float CCBReader::floatValFromDict(CCDictionary* dict, const std::string key) float CCBReader::floatValFromDict(CCDictionary* dict, const std::string key)
{ {
CCString* valueString = (CCString*) dict->objectForKey(key.c_str()); CCString* valueString = (CCString*) dict->objectForKey(key.c_str());
return valueString->floatValue(); return valueString->floatValue();
} }
bool CCBReader::boolValFromDict(CCDictionary* dict, const std::string key) bool CCBReader::boolValFromDict(CCDictionary* dict, const std::string key)
{ {
CCString* valueString = (CCString*) dict->objectForKey(key.c_str()); CCString* valueString = (CCString*) dict->objectForKey(key.c_str());
return (bool) valueString->intValue(); return (bool) valueString->intValue();
} }
CCPoint CCBReader::pointValFromDict(CCDictionary* dict, const std::string key) CCPoint CCBReader::pointValFromDict(CCDictionary* dict, const std::string key)
{ {
CCArray* arr = (CCArray*)dict->objectForKey(key.c_str()); CCArray* arr = (CCArray*)dict->objectForKey(key.c_str());
if (!arr) if (!arr)
{ {
return ccp(0,0); return ccp(0,0);
} }
float x = ((CCString*)arr->objectAtIndex(0))->floatValue(); float x = ((CCString*)arr->objectAtIndex(0))->floatValue();
float y = ((CCString*)arr->objectAtIndex(1))->floatValue(); float y = ((CCString*)arr->objectAtIndex(1))->floatValue();
@ -65,12 +65,12 @@ CCPoint CCBReader::pointValFromDict(CCDictionary* dict, const std::string key)
CCSize CCBReader::sizeValFromDict(CCDictionary* dict, const std::string key) CCSize CCBReader::sizeValFromDict(CCDictionary* dict, const std::string key)
{ {
CCArray* arr = (CCArray*) dict->objectForKey(key.c_str()); CCArray* arr = (CCArray*) dict->objectForKey(key.c_str());
if (!arr) if (!arr)
{ {
return CCSize(0, 0); return CCSize(0, 0);
} }
float w = ((CCString*)arr->objectAtIndex(0))->floatValue(); float w = ((CCString*)arr->objectAtIndex(0))->floatValue();
float h = ((CCString*)arr->objectAtIndex(1))->floatValue(); float h = ((CCString*)arr->objectAtIndex(1))->floatValue();
@ -79,7 +79,7 @@ CCSize CCBReader::sizeValFromDict(CCDictionary* dict, const std::string key)
ccColor3B CCBReader::ccColor3ValFromDict(CCDictionary* dict, const std::string key) ccColor3B CCBReader::ccColor3ValFromDict(CCDictionary* dict, const std::string key)
{ {
CCArray* arr = (CCArray*) dict->objectForKey(key.c_str()); CCArray* arr = (CCArray*) dict->objectForKey(key.c_str());
int r = ((CCString*)arr->objectAtIndex(0))->intValue(); int r = ((CCString*)arr->objectAtIndex(0))->intValue();
int g = ((CCString*)arr->objectAtIndex(1))->intValue(); int g = ((CCString*)arr->objectAtIndex(1))->intValue();
@ -90,7 +90,7 @@ ccColor3B CCBReader::ccColor3ValFromDict(CCDictionary* dict, const std::string k
ccColor4F CCBReader::ccColor4fValFromDict(CCDictionary* dict, const std::string key) ccColor4F CCBReader::ccColor4fValFromDict(CCDictionary* dict, const std::string key)
{ {
CCArray* arr = (CCArray*) dict->objectForKey(key.c_str()); CCArray* arr = (CCArray*) dict->objectForKey(key.c_str());
ccColor4F color; ccColor4F color;
color.r = ((CCString*)arr->objectAtIndex(0))->floatValue(); color.r = ((CCString*)arr->objectAtIndex(0))->floatValue();
@ -103,7 +103,7 @@ ccColor4F CCBReader::ccColor4fValFromDict(CCDictionary* dict, const std::string
ccBlendFunc CCBReader::blendFuncValFromDict(CCDictionary* dict, const std::string key) ccBlendFunc CCBReader::blendFuncValFromDict(CCDictionary* dict, const std::string key)
{ {
CCArray* arr = (CCArray*) dict->objectForKey(key.c_str()); CCArray* arr = (CCArray*) dict->objectForKey(key.c_str());
int src = ((CCString*)arr->objectAtIndex(0))->intValue(); int src = ((CCString*)arr->objectAtIndex(0))->intValue();
int dst = ((CCString*)arr->objectAtIndex(1))->intValue(); int dst = ((CCString*)arr->objectAtIndex(1))->intValue();
@ -119,8 +119,8 @@ ccBlendFunc CCBReader::blendFuncValFromDict(CCDictionary* dict, const std::strin
void CCBReader::setExtraProp(CCObject* prop, const char* key, int tag, CCDictionary* dict) void CCBReader::setExtraProp(CCObject* prop, const char* key, int tag, CCDictionary* dict)
{ {
std::string tagString; std::string tagString;
tagString += tag; tagString += tag;
CCDictionary* props = (CCDictionary*) dict->objectForKey(tagString.c_str()); CCDictionary* props = (CCDictionary*) dict->objectForKey(tagString.c_str());
if (!props) if (!props)
@ -301,15 +301,15 @@ void CCBReader::setPropsForSprite(CCSprite* node, CCDictionary* props, CCDiction
void CCBReader::setPropsForNode(CCNode* node, CCDictionary* props, CCDictionary* extraProps) void CCBReader::setPropsForNode(CCNode* node, CCDictionary* props, CCDictionary* extraProps)
{ {
CCPoint position = pointValFromDict(props, "position"); CCPoint position = pointValFromDict(props, "position");
node->setPosition(position); node->setPosition(position);
if (dynamic_cast<CCSprite*>(node) == NULL && if (dynamic_cast<CCSprite*>(node) == NULL &&
dynamic_cast<CCMenuItemImage*>(node) == NULL && dynamic_cast<CCMenuItemImage*>(node) == NULL &&
dynamic_cast<CCLabelBMFont*>(node) == NULL) dynamic_cast<CCLabelBMFont*>(node) == NULL)
{ {
CCSize size = sizeValFromDict(props, "contentSize"); CCSize size = sizeValFromDict(props, "contentSize");
//node->setContentSize(size); //node->setContentSize(size);
} }
node->setScaleX(floatValFromDict(props, "scaleX")); node->setScaleX(floatValFromDict(props, "scaleX"));
@ -330,7 +330,7 @@ void CCBReader::setPropsForNode(CCNode* node, CCDictionary* props, CCDictionary*
setExtraProp((CCDictionary*) props->objectForKey("customClass"), "customClass", node->getTag(), extraProps); setExtraProp((CCDictionary*) props->objectForKey("customClass"), "customClass", node->getTag(), extraProps);
setExtraProp((CCDictionary*) props->objectForKey("memberVarAssignmentType"), "memberVarAssignmentType", node->getTag(), extraProps); setExtraProp((CCDictionary*) props->objectForKey("memberVarAssignmentType"), "memberVarAssignmentType", node->getTag(), extraProps);
setExtraProp((CCDictionary*) props->objectForKey("memberVarAssignmentName"), "memberVarAssignmentName", node->getTag(), extraProps); setExtraProp((CCDictionary*) props->objectForKey("memberVarAssignmentName"), "memberVarAssignmentName", node->getTag(), extraProps);
setExtraProp((CCDictionary*) props->objectForKey("lockedScaleRatio"), "lockedScaleRatio", node->getTag(), extraProps); setExtraProp((CCDictionary*) props->objectForKey("lockedScaleRatio"), "lockedScaleRatio", node->getTag(), extraProps);
// Expanded nodes // Expanded nodes
@ -338,12 +338,12 @@ void CCBReader::setPropsForNode(CCNode* node, CCDictionary* props, CCDictionary*
CCString* isExpandedObj = (CCString*) props->objectForKey("isExpanded"); CCString* isExpandedObj = (CCString*) props->objectForKey("isExpanded");
if (isExpandedObj) { if (isExpandedObj) {
isExpanded = !isExpandedObj->m_sString.empty(); isExpanded = !isExpandedObj->m_sString.empty();
} else { } else {
isExpanded = true; isExpanded = true;
} }
setExtraProp(isExpandedObj, "isExpanded", node->getTag(), extraProps); setExtraProp(isExpandedObj, "isExpanded", node->getTag(), extraProps);
} }
else else
{ {
@ -355,7 +355,7 @@ void CCBReader::setPropsForNode(CCNode* node, CCDictionary* props, CCDictionary*
CCNode* CCBReader::ccObjectFromDictionary(CCDictionary* dict, CCDictionary* extraProps, CCNode* CCBReader::ccObjectFromDictionary(CCDictionary* dict, CCDictionary* extraProps,
const char* assetsDir, CCNode* owner, CCNode* root) const char* assetsDir, CCNode* owner, CCNode* root)
{ {
CCString* className = (CCString*) dict->objectForKey("class"); CCString* className = (CCString*) dict->objectForKey("class");
CCDictionary* props = (CCDictionary*) dict->objectForKey("properties"); CCDictionary* props = (CCDictionary*) dict->objectForKey("properties");
CCArray* children = (CCArray*) dict->objectForKey("children"); CCArray* children = (CCArray*) dict->objectForKey("children");
@ -365,15 +365,15 @@ CCNode* CCBReader::ccObjectFromDictionary(CCDictionary* dict, CCDictionary* extr
CCNode* node = NULL; CCNode* node = NULL;
if (className->m_sString.compare("CCParticleSystem") == 0) if (className->m_sString.compare("CCParticleSystem") == 0)
{ {
CCString* spriteFile = new CCString(assetsDir); CCString* spriteFile = new CCString(assetsDir);
spriteFile->m_sString += ((CCString*)props->objectForKey("spriteFile"))->m_sString; spriteFile->m_sString += ((CCString*)props->objectForKey("spriteFile"))->m_sString;
CCParticleSystem* sys = new CCParticleSystemQuad(); CCParticleSystem* sys = new CCParticleSystemQuad();
sys->initWithTotalParticles(2048); sys->initWithTotalParticles(2048);
sys->setTexture(CCTextureCache::sharedTextureCache()->addImage(spriteFile->m_sString.c_str())); sys->setTexture(CCTextureCache::sharedTextureCache()->addImage(spriteFile->m_sString.c_str()));
delete spriteFile; delete spriteFile;
node = (CCNode*)sys; node = (CCNode*)sys;
setPropsForNode((CCNode*)node, (CCDictionary*) props, extraProps); setPropsForNode((CCNode*)node, (CCDictionary*) props, extraProps);
@ -382,11 +382,11 @@ CCNode* CCBReader::ccObjectFromDictionary(CCDictionary* dict, CCDictionary* extr
else if (className->m_sString.compare("CCMenuItemImage") == 0) else if (className->m_sString.compare("CCMenuItemImage") == 0)
{ {
CCString* spriteFileNormal = new CCString(assetsDir); CCString* spriteFileNormal = new CCString(assetsDir);
spriteFileNormal->m_sString += ((CCString*)props->objectForKey("spriteFileNormal"))->getCString(); spriteFileNormal->m_sString += ((CCString*)props->objectForKey("spriteFileNormal"))->getCString();
CCString* spriteFileSelected = new CCString(assetsDir); CCString* spriteFileSelected = new CCString(assetsDir);
spriteFileSelected->m_sString += ((CCString*)props->objectForKey("spriteFileSelected"))->getCString(); spriteFileSelected->m_sString += ((CCString*)props->objectForKey("spriteFileSelected"))->getCString();
CCString* spriteFileDisabled = new CCString(assetsDir); CCString* spriteFileDisabled = new CCString(assetsDir);
spriteFileDisabled->m_sString += ((CCString*)props->objectForKey("spriteFileDisabled"))->getCString(); spriteFileDisabled->m_sString += ((CCString*)props->objectForKey("spriteFileDisabled"))->getCString();
CCSprite* spriteNormal = NULL; CCSprite* spriteNormal = NULL;
CCSprite* spriteSelected = NULL; CCSprite* spriteSelected = NULL;
@ -394,12 +394,12 @@ CCNode* CCBReader::ccObjectFromDictionary(CCDictionary* dict, CCDictionary* extr
CCString* spriteSheetFile = (CCString*)props->objectForKey("spriteFramesFile"); CCString* spriteSheetFile = (CCString*)props->objectForKey("spriteFramesFile");
if (spriteSheetFile && !spriteSheetFile->length()) { if (spriteSheetFile && !spriteSheetFile->length()) {
spriteSheetFile->m_sString.insert(0, assetsDir); spriteSheetFile->m_sString.insert(0, assetsDir);
} }
if (spriteSheetFile && !spriteSheetFile->length()) if (spriteSheetFile && !spriteSheetFile->length())
{ {
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(spriteSheetFile->m_sString.c_str()); CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(spriteSheetFile->m_sString.c_str());
spriteNormal = CCSprite::spriteWithSpriteFrameName(((CCString*)props->objectForKey("spriteFileNormal"))->getCString()); spriteNormal = CCSprite::spriteWithSpriteFrameName(((CCString*)props->objectForKey("spriteFileNormal"))->getCString());
spriteSelected = CCSprite::spriteWithSpriteFrameName(((CCString*)props->objectForKey("spriteFileSelected"))->getCString()); spriteSelected = CCSprite::spriteWithSpriteFrameName(((CCString*)props->objectForKey("spriteFileSelected"))->getCString());
@ -413,14 +413,14 @@ CCNode* CCBReader::ccObjectFromDictionary(CCDictionary* dict, CCDictionary* extr
spriteDisabled = CCSprite::spriteWithFile(spriteFileDisabled->m_sString.c_str()); spriteDisabled = CCSprite::spriteWithFile(spriteFileDisabled->m_sString.c_str());
} }
//deallocate //deallocate
CC_SAFE_DELETE(spriteFileNormal); CC_SAFE_DELETE(spriteFileNormal);
CC_SAFE_DELETE(spriteFileSelected); CC_SAFE_DELETE(spriteFileSelected);
CC_SAFE_DELETE(spriteFileDisabled); CC_SAFE_DELETE(spriteFileDisabled);
if (!spriteNormal) spriteNormal = CCSprite::spriteWithFile("missing-texture.png"); if (!spriteNormal) spriteNormal = CCSprite::spriteWithFile("missing-texture.png");
if (!spriteSelected) spriteSelected = CCSprite::spriteWithFile("missing-texture.png"); if (!spriteSelected) spriteSelected = CCSprite::spriteWithFile("missing-texture.png");
if (!spriteDisabled) spriteDisabled = CCSprite::spriteWithFile("missing-texture.png"); if (!spriteDisabled) spriteDisabled = CCSprite::spriteWithFile("missing-texture.png");
CCNode *target = NULL ; CCNode *target = NULL ;
if ( extraProps == NULL ) if ( extraProps == NULL )
@ -446,7 +446,7 @@ CCNode* CCBReader::ccObjectFromDictionary(CCDictionary* dict, CCDictionary* extr
target = NULL ; target = NULL ;
} }
node = (CCNode*)CCMenuItemImage::itemWithNormalSprite((CCNode*) spriteNormal, (CCNode*) spriteSelected, (CCNode*) spriteDisabled, target, sel); node = (CCNode*)CCMenuItemImage::itemWithNormalSprite((CCNode*) spriteNormal, (CCNode*) spriteSelected, (CCNode*) spriteDisabled, target, sel);
setPropsForNode(node, (CCDictionary*) props, extraProps); setPropsForNode(node, (CCDictionary*) props, extraProps);
setPropsForMenuItem((CCMenuItem*) node, (CCDictionary*) props, extraProps); setPropsForMenuItem((CCMenuItem*) node, (CCDictionary*) props, extraProps);
@ -455,38 +455,38 @@ CCNode* CCBReader::ccObjectFromDictionary(CCDictionary* dict, CCDictionary* extr
else if (className->m_sString.compare("CCMenu") == 0) else if (className->m_sString.compare("CCMenu") == 0)
{ {
node = (CCNode*)CCMenu::menuWithItems(NULL); node = (CCNode*)CCMenu::menuWithItems(NULL);
setPropsForNode(node, (CCDictionary*) props, extraProps); setPropsForNode(node, (CCDictionary*) props, extraProps);
setPropsForLayer((CCLayer*) node, (CCDictionary*) props, extraProps); setPropsForLayer((CCLayer*) node, (CCDictionary*) props, extraProps);
setPropsForMenu((CCMenu*)node, (CCDictionary*) props, extraProps); setPropsForMenu((CCMenu*)node, (CCDictionary*) props, extraProps);
} }
else if (className->m_sString.compare("CCLabelBMFont") == 0) else if (className->m_sString.compare("CCLabelBMFont") == 0)
{ {
CCString* fontFile = new CCString(assetsDir); CCString* fontFile = new CCString(assetsDir);
fontFile->m_sString += ((CCString*)props->objectForKey("fontFile"))->m_sString; fontFile->m_sString += ((CCString*)props->objectForKey("fontFile"))->m_sString;
CCString* stringText = ((CCString*)props->objectForKey("string")); CCString* stringText = ((CCString*)props->objectForKey("string"));
node = (CCNode*)CCLabelBMFont::labelWithString(stringText->m_sString.c_str(), node = (CCNode*)CCLabelBMFont::labelWithString(stringText->m_sString.c_str(),
fontFile->m_sString.c_str() ); fontFile->m_sString.c_str() );
delete fontFile; delete fontFile;
fontFile = 0; fontFile = 0;
if (!node) node = (CCNode*)CCLabelBMFont::labelWithString(stringText->m_sString.c_str(), "missing-font.fnt"); if (!node) node = (CCNode*)CCLabelBMFont::labelWithString(stringText->m_sString.c_str(), "missing-font.fnt");
setPropsForNode(node, (CCDictionary*) props, extraProps); setPropsForNode(node, (CCDictionary*) props, extraProps);
setPropsForLabelBMFont((CCLabelBMFont*) node, (CCDictionary*) props, extraProps); setPropsForLabelBMFont((CCLabelBMFont*) node, (CCDictionary*) props, extraProps);
} }
else if (className->m_sString.compare("CCSprite") == 0) else if (className->m_sString.compare("CCSprite") == 0)
{ {
CCString* spriteFile = new CCString(assetsDir); CCString* spriteFile = new CCString(assetsDir);
spriteFile->m_sString += ((CCString*)props->objectForKey("spriteFile"))->m_sString; spriteFile->m_sString += ((CCString*)props->objectForKey("spriteFile"))->m_sString;
CCString* spriteSheetFile = (CCString*)props->objectForKey("spriteFramesFile"); CCString* spriteSheetFile = (CCString*)props->objectForKey("spriteFramesFile");
if (spriteSheetFile && !spriteSheetFile->length()) if (spriteSheetFile && !spriteSheetFile->length())
{ {
spriteSheetFile->m_sString.insert(0, assetsDir); spriteSheetFile->m_sString.insert(0, assetsDir);
} }
if (spriteSheetFile && !spriteSheetFile->length()) if (spriteSheetFile && !spriteSheetFile->length())
{ {
@ -515,7 +515,7 @@ CCNode* CCBReader::ccObjectFromDictionary(CCDictionary* dict, CCDictionary* extr
if (dynamic_cast<CCLayerGradient*>(node) == NULL) if (dynamic_cast<CCLayerGradient*>(node) == NULL)
{ {
CCLOG("WARNING! %s is not subclass of CCNode", customClass); CCLOG("WARNING! %s is not subclass of CCNode", customClass);
delete node; delete node;
node = NULL; node = NULL;
} }
} }
@ -538,7 +538,7 @@ CCNode* CCBReader::ccObjectFromDictionary(CCDictionary* dict, CCDictionary* extr
if (dynamic_cast<CCLayerColor*>(node) == NULL) if (dynamic_cast<CCLayerColor*>(node) == NULL)
{ {
CCLOG("WARNING! %s is not subclass of CCNode", customClass); CCLOG("WARNING! %s is not subclass of CCNode", customClass);
delete node; delete node;
node = NULL; node = NULL;
} }
} }
@ -558,7 +558,7 @@ CCNode* CCBReader::ccObjectFromDictionary(CCDictionary* dict, CCDictionary* extr
if (dynamic_cast<CCLayer*>(node) == NULL) if (dynamic_cast<CCLayer*>(node) == NULL)
{ {
CCLOG("WARNING! %s is not subclass of CCNode", customClass); CCLOG("WARNING! %s is not subclass of CCNode", customClass);
delete node; delete node;
node = NULL; node = NULL;
} }
} }
@ -579,7 +579,7 @@ CCNode* CCBReader::ccObjectFromDictionary(CCDictionary* dict, CCDictionary* extr
if (dynamic_cast<CCNode*>(node) == NULL) if (dynamic_cast<CCNode*>(node) == NULL)
{ {
CCLOG("WARNING! %s is not subclass of CCNode", customClass); CCLOG("WARNING! %s is not subclass of CCNode", customClass);
delete node; delete node;
node = NULL; node = NULL;
} }
} }
@ -592,7 +592,7 @@ CCNode* CCBReader::ccObjectFromDictionary(CCDictionary* dict, CCDictionary* extr
} }
else else
{ {
CCLOG("WARNING! Class of type %@ couldn't be found", className); CCLOG("WARNING! Class of type %@ couldn't be found", className);
return NULL; return NULL;
} }
@ -611,7 +611,7 @@ CCNode* CCBReader::ccObjectFromDictionary(CCDictionary* dict, CCDictionary* extr
} }
else else
{ {
CCLOG("WARNING! Failed to add child to node"); CCLOG("WARNING! Failed to add child to node");
} }
} }
@ -660,7 +660,7 @@ CCNode* CCBReader::nodeGraphFromDictionary(CCDictionary* dict,
const char* assetsDir, const char* assetsDir,
CCNode* owner) CCNode* owner)
{ {
if (!dict) if (!dict)
{ {
CCLOG("WARNING! Trying to load invalid file type"); CCLOG("WARNING! Trying to load invalid file type");
return NULL; return NULL;
@ -686,8 +686,8 @@ CCNode* CCBReader::nodeGraphFromDictionary(CCDictionary* dict,
CCNode* CCBReader::nodeGraphFromFile(const char* file, CCNode* owner) CCNode* CCBReader::nodeGraphFromFile(const char* file, CCNode* owner)
{ {
CCLOG("CCBReader path is: %s", file); CCLOG("CCBReader path is: %s", file);
std::string ccbFilePath(file); std::string ccbFilePath(file);
std::string ccbFileDir; std::string ccbFileDir;
// find ccbFileDir before "/" or "\" // find ccbFileDir before "/" or "\"
@ -700,8 +700,8 @@ CCNode* CCBReader::nodeGraphFromFile(const char* file, CCNode* owner)
} }
CCDictionary* dict = CCDictionary::dictionaryWithContentsOfFileThreadSafe(ccbFilePath.c_str()); CCDictionary* dict = CCDictionary::dictionaryWithContentsOfFileThreadSafe(ccbFilePath.c_str());
CCAssert(dict != NULL, "CCBReader: file not found"); CCAssert(dict != NULL, "CCBReader: file not found");
return nodeGraphFromDictionary(dict, NULL, ccbFileDir.c_str(), owner); return nodeGraphFromDictionary(dict, NULL, ccbFileDir.c_str(), owner);
} }

View File

@ -33,30 +33,30 @@ USING_NS_CC_EXT;
int CCBReader::intValFromDict(CCDictionary* dict, const std::string key) int CCBReader::intValFromDict(CCDictionary* dict, const std::string key)
{ {
CCString* valueString = (CCString*) dict->objectForKey(key.c_str()); CCString* valueString = (CCString*) dict->objectForKey(key.c_str());
return valueString? valueString->intValue() : 0; return valueString? valueString->intValue() : 0;
} }
float CCBReader::floatValFromDict(CCDictionary* dict, const std::string key) float CCBReader::floatValFromDict(CCDictionary* dict, const std::string key)
{ {
CCString* valueString = (CCString*) dict->objectForKey(key.c_str()); CCString* valueString = (CCString*) dict->objectForKey(key.c_str());
return valueString? valueString->floatValue() : 0; return valueString? valueString->floatValue() : 0;
} }
bool CCBReader::boolValFromDict(CCDictionary* dict, const std::string key) bool CCBReader::boolValFromDict(CCDictionary* dict, const std::string key)
{ {
CCString* valueString = (CCString*) dict->objectForKey(key.c_str()); CCString* valueString = (CCString*) dict->objectForKey(key.c_str());
return valueString? ((bool)(valueString->intValue())) : false; return valueString? ((bool)(valueString->intValue())) : false;
} }
CCPoint CCBReader::pointValFromDict(CCDictionary* dict, const std::string key) CCPoint CCBReader::pointValFromDict(CCDictionary* dict, const std::string key)
{ {
CCArray* arr = (CCArray*)dict->objectForKey(key.c_str()); CCArray* arr = (CCArray*)dict->objectForKey(key.c_str());
if (!arr) if (!arr)
{ {
return ccp(0,0); return ccp(0,0);
} }
float x = ((CCString*)arr->objectAtIndex(0))->floatValue(); float x = ((CCString*)arr->objectAtIndex(0))->floatValue();
float y = ((CCString*)arr->objectAtIndex(1))->floatValue(); float y = ((CCString*)arr->objectAtIndex(1))->floatValue();
@ -65,12 +65,12 @@ CCPoint CCBReader::pointValFromDict(CCDictionary* dict, const std::string key)
CCSize CCBReader::sizeValFromDict(CCDictionary* dict, const std::string key) CCSize CCBReader::sizeValFromDict(CCDictionary* dict, const std::string key)
{ {
CCArray* arr = (CCArray*) dict->objectForKey(key.c_str()); CCArray* arr = (CCArray*) dict->objectForKey(key.c_str());
if (!arr) if (!arr)
{ {
return CCSize(0, 0); return CCSize(0, 0);
} }
float w = ((CCString*)arr->objectAtIndex(0))->floatValue(); float w = ((CCString*)arr->objectAtIndex(0))->floatValue();
float h = ((CCString*)arr->objectAtIndex(1))->floatValue(); float h = ((CCString*)arr->objectAtIndex(1))->floatValue();
@ -79,7 +79,7 @@ CCSize CCBReader::sizeValFromDict(CCDictionary* dict, const std::string key)
ccColor3B CCBReader::ccColor3ValFromDict(CCDictionary* dict, const std::string key) ccColor3B CCBReader::ccColor3ValFromDict(CCDictionary* dict, const std::string key)
{ {
CCArray* arr = (CCArray*) dict->objectForKey(key.c_str()); CCArray* arr = (CCArray*) dict->objectForKey(key.c_str());
int r = ((CCString*)arr->objectAtIndex(0))->intValue(); int r = ((CCString*)arr->objectAtIndex(0))->intValue();
int g = ((CCString*)arr->objectAtIndex(1))->intValue(); int g = ((CCString*)arr->objectAtIndex(1))->intValue();
@ -90,7 +90,7 @@ ccColor3B CCBReader::ccColor3ValFromDict(CCDictionary* dict, const std::string k
ccColor4F CCBReader::ccColor4fValFromDict(CCDictionary* dict, const std::string key) ccColor4F CCBReader::ccColor4fValFromDict(CCDictionary* dict, const std::string key)
{ {
CCArray* arr = (CCArray*) dict->objectForKey(key.c_str()); CCArray* arr = (CCArray*) dict->objectForKey(key.c_str());
ccColor4F color; ccColor4F color;
color.r = ((CCString*)arr->objectAtIndex(0))->floatValue(); color.r = ((CCString*)arr->objectAtIndex(0))->floatValue();
@ -103,7 +103,7 @@ ccColor4F CCBReader::ccColor4fValFromDict(CCDictionary* dict, const std::string
ccBlendFunc CCBReader::blendFuncValFromDict(CCDictionary* dict, const std::string key) ccBlendFunc CCBReader::blendFuncValFromDict(CCDictionary* dict, const std::string key)
{ {
CCArray* arr = (CCArray*) dict->objectForKey(key.c_str()); CCArray* arr = (CCArray*) dict->objectForKey(key.c_str());
int src = ((CCString*)arr->objectAtIndex(0))->intValue(); int src = ((CCString*)arr->objectAtIndex(0))->intValue();
int dst = ((CCString*)arr->objectAtIndex(1))->intValue(); int dst = ((CCString*)arr->objectAtIndex(1))->intValue();
@ -119,8 +119,8 @@ ccBlendFunc CCBReader::blendFuncValFromDict(CCDictionary* dict, const std::strin
void CCBReader::setExtraProp(CCObject* prop, const char* key, int tag, CCDictionary* dict) void CCBReader::setExtraProp(CCObject* prop, const char* key, int tag, CCDictionary* dict)
{ {
std::string tagString; std::string tagString;
tagString += tag; tagString += tag;
CCDictionary* props = (CCDictionary*) dict->objectForKey(tagString.c_str()); CCDictionary* props = (CCDictionary*) dict->objectForKey(tagString.c_str());
if (!props) if (!props)
@ -301,7 +301,7 @@ void CCBReader::setPropsForSprite(CCSprite* node, CCDictionary* props, CCDiction
void CCBReader::setPropsForNode(CCNode* node, CCDictionary* props, CCDictionary* extraProps) void CCBReader::setPropsForNode(CCNode* node, CCDictionary* props, CCDictionary* extraProps)
{ {
CCPoint position = pointValFromDict(props, "position"); CCPoint position = pointValFromDict(props, "position");
int refPointType = intValFromDict(props, "refPointType"); int refPointType = intValFromDict(props, "refPointType");
if (refPointType == kInvalidRelativePosition) if (refPointType == kInvalidRelativePosition)
@ -369,8 +369,8 @@ void CCBReader::setPropsForNode(CCNode* node, CCDictionary* props, CCDictionary*
dynamic_cast<CCMenuItemImage*>(node) == NULL && dynamic_cast<CCMenuItemImage*>(node) == NULL &&
dynamic_cast<CCLabelBMFont*>(node) == NULL) dynamic_cast<CCLabelBMFont*>(node) == NULL)
{ {
CCSize size = sizeValFromDict(props, "contentSize"); CCSize size = sizeValFromDict(props, "contentSize");
//node->setContentSize(size); //node->setContentSize(size);
} }
node->setScaleX(floatValFromDict(props, "scaleX")); node->setScaleX(floatValFromDict(props, "scaleX"));
@ -391,7 +391,7 @@ void CCBReader::setPropsForNode(CCNode* node, CCDictionary* props, CCDictionary*
setExtraProp((CCDictionary*) props->objectForKey("customClass"), "customClass", node->getTag(), extraProps); setExtraProp((CCDictionary*) props->objectForKey("customClass"), "customClass", node->getTag(), extraProps);
setExtraProp((CCDictionary*) props->objectForKey("memberVarAssignmentType"), "memberVarAssignmentType", node->getTag(), extraProps); setExtraProp((CCDictionary*) props->objectForKey("memberVarAssignmentType"), "memberVarAssignmentType", node->getTag(), extraProps);
setExtraProp((CCDictionary*) props->objectForKey("memberVarAssignmentName"), "memberVarAssignmentName", node->getTag(), extraProps); setExtraProp((CCDictionary*) props->objectForKey("memberVarAssignmentName"), "memberVarAssignmentName", node->getTag(), extraProps);
setExtraProp((CCDictionary*) props->objectForKey("lockedScaleRatio"), "lockedScaleRatio", node->getTag(), extraProps); setExtraProp((CCDictionary*) props->objectForKey("lockedScaleRatio"), "lockedScaleRatio", node->getTag(), extraProps);
// Expanded nodes // Expanded nodes
@ -399,12 +399,12 @@ void CCBReader::setPropsForNode(CCNode* node, CCDictionary* props, CCDictionary*
CCString* isExpandedObj = (CCString*) props->objectForKey("isExpanded"); CCString* isExpandedObj = (CCString*) props->objectForKey("isExpanded");
if (isExpandedObj) { if (isExpandedObj) {
isExpanded = !isExpandedObj->m_sString.empty(); isExpanded = !isExpandedObj->m_sString.empty();
} else { } else {
isExpanded = true; isExpanded = true;
} }
setExtraProp(isExpandedObj, "isExpanded", node->getTag(), extraProps); setExtraProp(isExpandedObj, "isExpanded", node->getTag(), extraProps);
} }
else else
{ {
@ -416,7 +416,7 @@ void CCBReader::setPropsForNode(CCNode* node, CCDictionary* props, CCDictionary*
CCNode* CCBReader::ccObjectFromDictionary(CCDictionary* dict, CCDictionary* extraProps, CCNode* CCBReader::ccObjectFromDictionary(CCDictionary* dict, CCDictionary* extraProps,
const char* assetsDir, CCNode* owner, CCNode* root) const char* assetsDir, CCNode* owner, CCNode* root)
{ {
CCString* className = (CCString*) dict->objectForKey("class"); CCString* className = (CCString*) dict->objectForKey("class");
CCDictionary* props = (CCDictionary*) dict->objectForKey("properties"); CCDictionary* props = (CCDictionary*) dict->objectForKey("properties");
CCArray* children = (CCArray*) dict->objectForKey("children"); CCArray* children = (CCArray*) dict->objectForKey("children");
@ -426,15 +426,15 @@ CCNode* CCBReader::ccObjectFromDictionary(CCDictionary* dict, CCDictionary* extr
CCNode* node = NULL; CCNode* node = NULL;
if (className->m_sString.compare("CCParticleSystem") == 0) if (className->m_sString.compare("CCParticleSystem") == 0)
{ {
CCString* spriteFile = new CCString(assetsDir); CCString* spriteFile = new CCString(assetsDir);
spriteFile->m_sString += ((CCString*)props->objectForKey("spriteFile"))->m_sString; spriteFile->m_sString += ((CCString*)props->objectForKey("spriteFile"))->m_sString;
CCParticleSystem* sys = new CCParticleSystemQuad(); CCParticleSystem* sys = new CCParticleSystemQuad();
sys->initWithTotalParticles(2048); sys->initWithTotalParticles(2048);
sys->setTexture(CCTextureCache::sharedTextureCache()->addImage(spriteFile->m_sString.c_str())); sys->setTexture(CCTextureCache::sharedTextureCache()->addImage(spriteFile->m_sString.c_str()));
delete spriteFile; delete spriteFile;
node = (CCNode*)sys; node = (CCNode*)sys;
setPropsForNode((CCNode*)node, (CCDictionary*) props, extraProps); setPropsForNode((CCNode*)node, (CCDictionary*) props, extraProps);
@ -443,11 +443,11 @@ CCNode* CCBReader::ccObjectFromDictionary(CCDictionary* dict, CCDictionary* extr
else if (className->m_sString.compare("CCMenuItemImage") == 0) else if (className->m_sString.compare("CCMenuItemImage") == 0)
{ {
CCString* spriteFileNormal = new CCString(assetsDir); CCString* spriteFileNormal = new CCString(assetsDir);
spriteFileNormal->m_sString += ((CCString*)props->objectForKey("spriteFileNormal"))->getCString(); spriteFileNormal->m_sString += ((CCString*)props->objectForKey("spriteFileNormal"))->getCString();
CCString* spriteFileSelected = new CCString(assetsDir); CCString* spriteFileSelected = new CCString(assetsDir);
spriteFileSelected->m_sString += ((CCString*)props->objectForKey("spriteFileSelected"))->getCString(); spriteFileSelected->m_sString += ((CCString*)props->objectForKey("spriteFileSelected"))->getCString();
CCString* spriteFileDisabled = new CCString(assetsDir); CCString* spriteFileDisabled = new CCString(assetsDir);
spriteFileDisabled->m_sString += ((CCString*)props->objectForKey("spriteFileDisabled"))->getCString(); spriteFileDisabled->m_sString += ((CCString*)props->objectForKey("spriteFileDisabled"))->getCString();
CCSprite* spriteNormal = NULL; CCSprite* spriteNormal = NULL;
CCSprite* spriteSelected = NULL; CCSprite* spriteSelected = NULL;
@ -455,12 +455,12 @@ CCNode* CCBReader::ccObjectFromDictionary(CCDictionary* dict, CCDictionary* extr
CCString* spriteSheetFile = (CCString*)props->objectForKey("spriteFramesFile"); CCString* spriteSheetFile = (CCString*)props->objectForKey("spriteFramesFile");
if (spriteSheetFile && !spriteSheetFile->length()) { if (spriteSheetFile && !spriteSheetFile->length()) {
spriteSheetFile->m_sString.insert(0, assetsDir); spriteSheetFile->m_sString.insert(0, assetsDir);
} }
if (spriteSheetFile && !spriteSheetFile->length()) if (spriteSheetFile && !spriteSheetFile->length())
{ {
CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(spriteSheetFile->m_sString.c_str()); CCSpriteFrameCache::sharedSpriteFrameCache()->addSpriteFramesWithFile(spriteSheetFile->m_sString.c_str());
spriteNormal = CCSprite::spriteWithSpriteFrameName(((CCString*)props->objectForKey("spriteFileNormal"))->getCString()); spriteNormal = CCSprite::spriteWithSpriteFrameName(((CCString*)props->objectForKey("spriteFileNormal"))->getCString());
spriteSelected = CCSprite::spriteWithSpriteFrameName(((CCString*)props->objectForKey("spriteFileSelected"))->getCString()); spriteSelected = CCSprite::spriteWithSpriteFrameName(((CCString*)props->objectForKey("spriteFileSelected"))->getCString());
@ -474,14 +474,14 @@ CCNode* CCBReader::ccObjectFromDictionary(CCDictionary* dict, CCDictionary* extr
spriteDisabled = CCSprite::spriteWithFile(spriteFileDisabled->m_sString.c_str()); spriteDisabled = CCSprite::spriteWithFile(spriteFileDisabled->m_sString.c_str());
} }
//deallocate //deallocate
CC_SAFE_DELETE(spriteFileNormal); CC_SAFE_DELETE(spriteFileNormal);
CC_SAFE_DELETE(spriteFileSelected); CC_SAFE_DELETE(spriteFileSelected);
CC_SAFE_DELETE(spriteFileDisabled); CC_SAFE_DELETE(spriteFileDisabled);
if (!spriteNormal) spriteNormal = CCSprite::spriteWithFile("missing-texture.png"); if (!spriteNormal) spriteNormal = CCSprite::spriteWithFile("missing-texture.png");
if (!spriteSelected) spriteSelected = CCSprite::spriteWithFile("missing-texture.png"); if (!spriteSelected) spriteSelected = CCSprite::spriteWithFile("missing-texture.png");
if (!spriteDisabled) spriteDisabled = CCSprite::spriteWithFile("missing-texture.png"); if (!spriteDisabled) spriteDisabled = CCSprite::spriteWithFile("missing-texture.png");
CCNode *target = NULL ; CCNode *target = NULL ;
if ( extraProps == NULL ) if ( extraProps == NULL )
@ -507,7 +507,7 @@ CCNode* CCBReader::ccObjectFromDictionary(CCDictionary* dict, CCDictionary* extr
target = NULL ; target = NULL ;
} }
node = (CCNode*)CCMenuItemImage::itemWithNormalSprite((CCNode*) spriteNormal, (CCNode*) spriteSelected, (CCNode*) spriteDisabled, target, sel); node = (CCNode*)CCMenuItemImage::itemWithNormalSprite((CCNode*) spriteNormal, (CCNode*) spriteSelected, (CCNode*) spriteDisabled, target, sel);
setPropsForNode(node, (CCDictionary*) props, extraProps); setPropsForNode(node, (CCDictionary*) props, extraProps);
setPropsForMenuItem((CCMenuItem*) node, (CCDictionary*) props, extraProps); setPropsForMenuItem((CCMenuItem*) node, (CCDictionary*) props, extraProps);
@ -516,38 +516,38 @@ CCNode* CCBReader::ccObjectFromDictionary(CCDictionary* dict, CCDictionary* extr
else if (className->m_sString.compare("CCMenu") == 0) else if (className->m_sString.compare("CCMenu") == 0)
{ {
node = (CCNode*)CCMenu::menuWithItems(NULL); node = (CCNode*)CCMenu::menuWithItems(NULL);
setPropsForNode(node, (CCDictionary*) props, extraProps); setPropsForNode(node, (CCDictionary*) props, extraProps);
setPropsForLayer((CCLayer*) node, (CCDictionary*) props, extraProps); setPropsForLayer((CCLayer*) node, (CCDictionary*) props, extraProps);
setPropsForMenu((CCMenu*)node, (CCDictionary*) props, extraProps); setPropsForMenu((CCMenu*)node, (CCDictionary*) props, extraProps);
} }
else if (className->m_sString.compare("CCLabelBMFont") == 0) else if (className->m_sString.compare("CCLabelBMFont") == 0)
{ {
CCString* fontFile = new CCString(assetsDir); CCString* fontFile = new CCString(assetsDir);
fontFile->m_sString += ((CCString*)props->objectForKey("fontFile"))->m_sString; fontFile->m_sString += ((CCString*)props->objectForKey("fontFile"))->m_sString;
CCString* stringText = ((CCString*)props->objectForKey("string")); CCString* stringText = ((CCString*)props->objectForKey("string"));
node = (CCNode*)CCLabelBMFont::labelWithString(stringText->m_sString.c_str(), node = (CCNode*)CCLabelBMFont::labelWithString(stringText->m_sString.c_str(),
fontFile->m_sString.c_str() ); fontFile->m_sString.c_str() );
delete fontFile; delete fontFile;
fontFile = 0; fontFile = 0;
if (!node) node = (CCNode*)CCLabelBMFont::labelWithString(stringText->m_sString.c_str(), "missing-font.fnt"); if (!node) node = (CCNode*)CCLabelBMFont::labelWithString(stringText->m_sString.c_str(), "missing-font.fnt");
setPropsForNode(node, (CCDictionary*) props, extraProps); setPropsForNode(node, (CCDictionary*) props, extraProps);
setPropsForLabelBMFont((CCLabelBMFont*) node, (CCDictionary*) props, extraProps); setPropsForLabelBMFont((CCLabelBMFont*) node, (CCDictionary*) props, extraProps);
} }
else if (className->m_sString.compare("CCSprite") == 0) else if (className->m_sString.compare("CCSprite") == 0)
{ {
CCString* spriteFile = new CCString(assetsDir); CCString* spriteFile = new CCString(assetsDir);
spriteFile->m_sString += ((CCString*)props->objectForKey("spriteFile"))->m_sString; spriteFile->m_sString += ((CCString*)props->objectForKey("spriteFile"))->m_sString;
CCString* spriteSheetFile = (CCString*)props->objectForKey("spriteFramesFile"); CCString* spriteSheetFile = (CCString*)props->objectForKey("spriteFramesFile");
if (spriteSheetFile && !spriteSheetFile->length()) if (spriteSheetFile && !spriteSheetFile->length())
{ {
spriteSheetFile->m_sString.insert(0, assetsDir); spriteSheetFile->m_sString.insert(0, assetsDir);
} }
if (spriteSheetFile && !spriteSheetFile->length()) if (spriteSheetFile && !spriteSheetFile->length())
{ {
@ -576,7 +576,7 @@ CCNode* CCBReader::ccObjectFromDictionary(CCDictionary* dict, CCDictionary* extr
if (dynamic_cast<CCLayerGradient*>(node) == NULL) if (dynamic_cast<CCLayerGradient*>(node) == NULL)
{ {
CCLOG("WARNING! %s is not subclass of CCNode", customClass); CCLOG("WARNING! %s is not subclass of CCNode", customClass);
delete node; delete node;
node = NULL; node = NULL;
} }
} }
@ -599,7 +599,7 @@ CCNode* CCBReader::ccObjectFromDictionary(CCDictionary* dict, CCDictionary* extr
if (dynamic_cast<CCLayerColor*>(node) == NULL) if (dynamic_cast<CCLayerColor*>(node) == NULL)
{ {
CCLOG("WARNING! %s is not subclass of CCNode", customClass); CCLOG("WARNING! %s is not subclass of CCNode", customClass);
delete node; delete node;
node = NULL; node = NULL;
} }
} }
@ -619,7 +619,7 @@ CCNode* CCBReader::ccObjectFromDictionary(CCDictionary* dict, CCDictionary* extr
if (dynamic_cast<CCLayer*>(node) == NULL) if (dynamic_cast<CCLayer*>(node) == NULL)
{ {
CCLOG("WARNING! %s is not subclass of CCNode", customClass); CCLOG("WARNING! %s is not subclass of CCNode", customClass);
delete node; delete node;
node = NULL; node = NULL;
} }
} }
@ -640,7 +640,7 @@ CCNode* CCBReader::ccObjectFromDictionary(CCDictionary* dict, CCDictionary* extr
if (dynamic_cast<CCNode*>(node) == NULL) if (dynamic_cast<CCNode*>(node) == NULL)
{ {
CCLOG("WARNING! %s is not subclass of CCNode", customClass); CCLOG("WARNING! %s is not subclass of CCNode", customClass);
delete node; delete node;
node = NULL; node = NULL;
} }
} }
@ -653,7 +653,7 @@ CCNode* CCBReader::ccObjectFromDictionary(CCDictionary* dict, CCDictionary* extr
} }
else else
{ {
CCLOG("WARNING! Class of type %@ couldn't be found", className); CCLOG("WARNING! Class of type %@ couldn't be found", className);
return NULL; return NULL;
} }
@ -672,7 +672,7 @@ CCNode* CCBReader::ccObjectFromDictionary(CCDictionary* dict, CCDictionary* extr
} }
else else
{ {
CCLOG("WARNING! Failed to add child to node"); CCLOG("WARNING! Failed to add child to node");
} }
} }
@ -721,7 +721,7 @@ CCNode* CCBReader::nodeGraphFromDictionary(CCDictionary* dict,
const char* assetsDir, const char* assetsDir,
CCNode* owner) CCNode* owner)
{ {
if (!dict) if (!dict)
{ {
CCLOG("WARNING! Trying to load invalid file type"); CCLOG("WARNING! Trying to load invalid file type");
return NULL; return NULL;
@ -747,8 +747,8 @@ CCNode* CCBReader::nodeGraphFromDictionary(CCDictionary* dict,
CCNode* CCBReader::nodeGraphFromFile(const char* file, CCNode* owner) CCNode* CCBReader::nodeGraphFromFile(const char* file, CCNode* owner)
{ {
CCLOG("CCBReader path is: %s", file); CCLOG("CCBReader path is: %s", file);
std::string ccbFilePath(file); std::string ccbFilePath(file);
std::string ccbFileDir; std::string ccbFileDir;
// find ccbFileDir before "/" or "\" // find ccbFileDir before "/" or "\"
@ -761,8 +761,8 @@ CCNode* CCBReader::nodeGraphFromFile(const char* file, CCNode* owner)
} }
CCDictionary* dict = CCDictionary::dictionaryWithContentsOfFileThreadSafe(ccbFilePath.c_str()); CCDictionary* dict = CCDictionary::dictionaryWithContentsOfFileThreadSafe(ccbFilePath.c_str());
CCAssert(dict != NULL, "CCBReader: file not found"); CCAssert(dict != NULL, "CCBReader: file not found");
return nodeGraphFromDictionary(dict, NULL, ccbFileDir.c_str(), owner); return nodeGraphFromDictionary(dict, NULL, ccbFileDir.c_str(), owner);
} }

View File

@ -392,19 +392,19 @@ out:
static tmsize_t _tiffReadProc(thandle_t fd, void* buf, tmsize_t size) static tmsize_t _tiffReadProc(thandle_t fd, void* buf, tmsize_t size)
{ {
tImageSource* isource = (tImageSource*)fd; tImageSource* isource = (tImageSource*)fd;
uint8* ma; uint8* ma;
uint64 mb; uint64 mb;
unsigned long n; unsigned long n;
unsigned long o; unsigned long o;
tmsize_t p; tmsize_t p;
ma=(uint8*)buf; ma=(uint8*)buf;
mb=size; mb=size;
p=0; p=0;
while (mb>0) while (mb>0)
{ {
n=0x80000000UL; n=0x80000000UL;
if ((uint64)n>mb) if ((uint64)n>mb)
n=(unsigned long)mb; n=(unsigned long)mb;
if((int)(isource->offset + n) <= isource->size) if((int)(isource->offset + n) <= isource->size)
@ -418,15 +418,15 @@ static tmsize_t _tiffReadProc(thandle_t fd, void* buf, tmsize_t size)
return 0; return 0;
} }
ma+=o; ma+=o;
mb-=o; mb-=o;
p+=o; p+=o;
if (o!=n) if (o!=n)
{ {
break; break;
} }
} }
return p; return p;
} }
static tmsize_t _tiffWriteProc(thandle_t fd, void* buf, tmsize_t size) static tmsize_t _tiffWriteProc(thandle_t fd, void* buf, tmsize_t size)
@ -434,7 +434,7 @@ static tmsize_t _tiffWriteProc(thandle_t fd, void* buf, tmsize_t size)
CC_UNUSED_PARAM(fd); CC_UNUSED_PARAM(fd);
CC_UNUSED_PARAM(buf); CC_UNUSED_PARAM(buf);
CC_UNUSED_PARAM(size); CC_UNUSED_PARAM(size);
return 0; return 0;
} }
@ -444,7 +444,7 @@ static uint64 _tiffSeekProc(thandle_t fd, uint64 off, int whence)
uint64 ret = -1; uint64 ret = -1;
do do
{ {
if (whence == SEEK_SET) if (whence == SEEK_SET)
{ {
CC_BREAK_IF(off > isource->size-1); CC_BREAK_IF(off > isource->size-1);
ret = isource->offset = (uint32)off; ret = isource->offset = (uint32)off;

View File

@ -16,254 +16,254 @@ using namespace cocos2d;
static JSClass global_class = { static JSClass global_class = {
"global", JSCLASS_GLOBAL_FLAGS, "global", JSCLASS_GLOBAL_FLAGS,
JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub, JS_PropertyStub, JS_PropertyStub, JS_PropertyStub, JS_StrictPropertyStub,
JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub, JS_EnumerateStub, JS_ResolveStub, JS_ConvertStub, JS_FinalizeStub,
JSCLASS_NO_OPTIONAL_MEMBERS JSCLASS_NO_OPTIONAL_MEMBERS
}; };
ScriptingCore::ScriptingCore() ScriptingCore::ScriptingCore()
{ {
this->rt = JS_NewRuntime(8 * 1024 * 1024); this->rt = JS_NewRuntime(8 * 1024 * 1024);
this->cx = JS_NewContext(rt, 8192); this->cx = JS_NewContext(rt, 8192);
JS_SetOptions(this->cx, JSOPTION_VAROBJFIX); JS_SetOptions(this->cx, JSOPTION_VAROBJFIX);
JS_SetVersion(this->cx, JSVERSION_LATEST); JS_SetVersion(this->cx, JSVERSION_LATEST);
JS_SetErrorReporter(this->cx, ScriptingCore::reportError); JS_SetErrorReporter(this->cx, ScriptingCore::reportError);
global = JS_NewCompartmentAndGlobalObject(cx, &global_class, NULL); global = JS_NewCompartmentAndGlobalObject(cx, &global_class, NULL);
if (!JS_InitStandardClasses(cx, global)) { if (!JS_InitStandardClasses(cx, global)) {
CCLog("js error"); CCLog("js error");
} }
// create the cocos namespace // create the cocos namespace
JSObject *cocos = JS_NewObject(cx, NULL, NULL, NULL); JSObject *cocos = JS_NewObject(cx, NULL, NULL, NULL);
jsval cocosVal = OBJECT_TO_JSVAL(cocos); jsval cocosVal = OBJECT_TO_JSVAL(cocos);
JS_SetProperty(cx, global, "cocos", &cocosVal); JS_SetProperty(cx, global, "cocos", &cocosVal);
// register the internal classes // register the internal classes
S_CCPoint::jsCreateClass(this->cx, cocos, "Point"); S_CCPoint::jsCreateClass(this->cx, cocos, "Point");
S_CCSize::jsCreateClass(this->cx, cocos, "Size"); S_CCSize::jsCreateClass(this->cx, cocos, "Size");
S_CCRect::jsCreateClass(this->cx, cocos, "Rect"); S_CCRect::jsCreateClass(this->cx, cocos, "Rect");
S__ccGridSize::jsCreateClass(this->cx, cocos, "GridSize"); S__ccGridSize::jsCreateClass(this->cx, cocos, "GridSize");
S_CCSet::jsCreateClass(this->cx, cocos, "Set"); S_CCSet::jsCreateClass(this->cx, cocos, "Set");
S_CCTouch::jsCreateClass(this->cx, cocos, "Touch"); S_CCTouch::jsCreateClass(this->cx, cocos, "Touch");
S_CCDirector::jsCreateClass(this->cx, cocos, "Director"); S_CCDirector::jsCreateClass(this->cx, cocos, "Director");
S_CCNode::jsCreateClass(this->cx, cocos, "Node"); S_CCNode::jsCreateClass(this->cx, cocos, "Node");
S_CCTextureAtlas::jsCreateClass(this->cx, cocos, "TextureAtlas"); S_CCTextureAtlas::jsCreateClass(this->cx, cocos, "TextureAtlas");
S_CCSpriteBatchNode::jsCreateClass(this->cx, cocos, "SpriteBatchNode"); S_CCSpriteBatchNode::jsCreateClass(this->cx, cocos, "SpriteBatchNode");
S_CCScene::jsCreateClass(this->cx, cocos, "Scene"); S_CCScene::jsCreateClass(this->cx, cocos, "Scene");
S_CCLayer::jsCreateClass(this->cx, cocos, "Layer"); S_CCLayer::jsCreateClass(this->cx, cocos, "Layer");
S_CCSprite::jsCreateClass(this->cx, cocos, "Sprite"); S_CCSprite::jsCreateClass(this->cx, cocos, "Sprite");
S_CCRenderTexture::jsCreateClass(this->cx, cocos, "RenderTexture"); S_CCRenderTexture::jsCreateClass(this->cx, cocos, "RenderTexture");
S_CCMenu::jsCreateClass(this->cx, cocos, "Menu"); S_CCMenu::jsCreateClass(this->cx, cocos, "Menu");
S_CCMenuItem::jsCreateClass(this->cx, cocos, "MenuItem"); S_CCMenuItem::jsCreateClass(this->cx, cocos, "MenuItem");
S_CCMenuItemLabel::jsCreateClass(this->cx, cocos, "MenuItemLabel"); S_CCMenuItemLabel::jsCreateClass(this->cx, cocos, "MenuItemLabel");
S_CCMenuItemSprite::jsCreateClass(this->cx, cocos, "MenuItemSprite"); S_CCMenuItemSprite::jsCreateClass(this->cx, cocos, "MenuItemSprite");
S_CCMenuItemImage::jsCreateClass(this->cx, cocos, "MenuItemImage"); S_CCMenuItemImage::jsCreateClass(this->cx, cocos, "MenuItemImage");
S_CCSpriteFrame::jsCreateClass(this->cx, cocos, "SpriteFrame"); S_CCSpriteFrame::jsCreateClass(this->cx, cocos, "SpriteFrame");
S_CCSpriteFrameCache::jsCreateClass(this->cx, cocos, "SpriteFrameCache"); S_CCSpriteFrameCache::jsCreateClass(this->cx, cocos, "SpriteFrameCache");
S_CCAnimation::jsCreateClass(this->cx, cocos, "Animation"); S_CCAnimation::jsCreateClass(this->cx, cocos, "Animation");
S_CCAction::jsCreateClass(this->cx, cocos, "Action"); S_CCAction::jsCreateClass(this->cx, cocos, "Action");
S_CCActionInterval::jsCreateClass(this->cx, cocos, "ActionInterval"); S_CCActionInterval::jsCreateClass(this->cx, cocos, "ActionInterval");
S_CCFiniteTimeAction::jsCreateClass(this->cx, cocos, "FiniteTimeAction"); S_CCFiniteTimeAction::jsCreateClass(this->cx, cocos, "FiniteTimeAction");
S_CCActionInstant::jsCreateClass(this->cx, cocos, "ActionInstant"); S_CCActionInstant::jsCreateClass(this->cx, cocos, "ActionInstant");
S_CCDelayTime::jsCreateClass(this->cx, cocos, "DelayTime"); S_CCDelayTime::jsCreateClass(this->cx, cocos, "DelayTime");
S_CCAnimate::jsCreateClass(this->cx, cocos, "Animate"); S_CCAnimate::jsCreateClass(this->cx, cocos, "Animate");
S_CCMoveTo::jsCreateClass(this->cx, cocos, "MoveTo"); S_CCMoveTo::jsCreateClass(this->cx, cocos, "MoveTo");
S_CCMoveBy::jsCreateClass(this->cx, cocos, "MoveBy"); S_CCMoveBy::jsCreateClass(this->cx, cocos, "MoveBy");
S_CCRotateBy::jsCreateClass(this->cx, cocos, "RotateBy"); S_CCRotateBy::jsCreateClass(this->cx, cocos, "RotateBy");
S_CCRotateTo::jsCreateClass(this->cx, cocos, "RotateTo"); S_CCRotateTo::jsCreateClass(this->cx, cocos, "RotateTo");
S_CCActionEase::jsCreateClass(this->cx, cocos, "ActionEase"); S_CCActionEase::jsCreateClass(this->cx, cocos, "ActionEase");
S_CCEaseRateAction::jsCreateClass(this->cx, cocos, "EaseRateAction"); S_CCEaseRateAction::jsCreateClass(this->cx, cocos, "EaseRateAction");
S_CCEaseIn::jsCreateClass(this->cx, cocos, "EaseIn"); S_CCEaseIn::jsCreateClass(this->cx, cocos, "EaseIn");
S_CCEaseOut::jsCreateClass(this->cx, cocos, "EaseOut"); S_CCEaseOut::jsCreateClass(this->cx, cocos, "EaseOut");
S_CCEaseInOut::jsCreateClass(this->cx, cocos, "EaseInOut"); S_CCEaseInOut::jsCreateClass(this->cx, cocos, "EaseInOut");
S_CCEaseBackInOut::jsCreateClass(this->cx, cocos, "EaseBackInOut"); S_CCEaseBackInOut::jsCreateClass(this->cx, cocos, "EaseBackInOut");
S_CCEaseBackOut::jsCreateClass(this->cx, cocos, "EaseBackOut"); S_CCEaseBackOut::jsCreateClass(this->cx, cocos, "EaseBackOut");
S_CCEaseElasticIn::jsCreateClass(this->cx, cocos, "EaseElasticIn"); S_CCEaseElasticIn::jsCreateClass(this->cx, cocos, "EaseElasticIn");
S_CCEaseElastic::jsCreateClass(this->cx, cocos, "EaseElastic"); S_CCEaseElastic::jsCreateClass(this->cx, cocos, "EaseElastic");
S_CCEaseElasticOut::jsCreateClass(this->cx, cocos, "EaseElasticOut"); S_CCEaseElasticOut::jsCreateClass(this->cx, cocos, "EaseElasticOut");
S_CCEaseElasticInOut::jsCreateClass(this->cx, cocos, "EaseElasticInOut"); S_CCEaseElasticInOut::jsCreateClass(this->cx, cocos, "EaseElasticInOut");
S_CCEaseBounce::jsCreateClass(this->cx, cocos, "EaseBounce"); S_CCEaseBounce::jsCreateClass(this->cx, cocos, "EaseBounce");
S_CCEaseBounceIn::jsCreateClass(this->cx, cocos, "EaseBounceIn"); S_CCEaseBounceIn::jsCreateClass(this->cx, cocos, "EaseBounceIn");
S_CCEaseBounceInOut::jsCreateClass(this->cx, cocos, "EaseBounceInOut"); S_CCEaseBounceInOut::jsCreateClass(this->cx, cocos, "EaseBounceInOut");
S_CCEaseBackIn::jsCreateClass(this->cx, cocos, "EaseBackIn"); S_CCEaseBackIn::jsCreateClass(this->cx, cocos, "EaseBackIn");
S_CCEaseBounceOut::jsCreateClass(this->cx, cocos, "EaseBounceOut"); S_CCEaseBounceOut::jsCreateClass(this->cx, cocos, "EaseBounceOut");
S_CCEaseExponentialIn::jsCreateClass(this->cx, cocos, "EaseExponentialIn"); S_CCEaseExponentialIn::jsCreateClass(this->cx, cocos, "EaseExponentialIn");
S_CCEaseExponentialOut::jsCreateClass(this->cx, cocos, "EaseExponentialOut"); S_CCEaseExponentialOut::jsCreateClass(this->cx, cocos, "EaseExponentialOut");
S_CCEaseExponentialInOut::jsCreateClass(this->cx, cocos, "EaseExponentialInOut"); S_CCEaseExponentialInOut::jsCreateClass(this->cx, cocos, "EaseExponentialInOut");
S_CCEaseSineIn::jsCreateClass(this->cx, cocos, "EaseSineIn"); S_CCEaseSineIn::jsCreateClass(this->cx, cocos, "EaseSineIn");
S_CCEaseSineOut::jsCreateClass(this->cx, cocos, "EaseSineOut"); S_CCEaseSineOut::jsCreateClass(this->cx, cocos, "EaseSineOut");
S_CCEaseSineInOut::jsCreateClass(this->cx, cocos, "EaseSineInOut"); S_CCEaseSineInOut::jsCreateClass(this->cx, cocos, "EaseSineInOut");
S_CCRepeatForever::jsCreateClass(this->cx, cocos, "RepeatForever"); S_CCRepeatForever::jsCreateClass(this->cx, cocos, "RepeatForever");
S_CCSequence::jsCreateClass(this->cx, cocos, "Sequence"); S_CCSequence::jsCreateClass(this->cx, cocos, "Sequence");
S_CCLabelTTF::jsCreateClass(this->cx, cocos, "LabelTTF"); S_CCLabelTTF::jsCreateClass(this->cx, cocos, "LabelTTF");
S_CCParticleSystem::jsCreateClass(this->cx, cocos, "ParticleSystem"); S_CCParticleSystem::jsCreateClass(this->cx, cocos, "ParticleSystem");
S_CCFileUtils::jsCreateClass(this->cx, cocos, "FileUtils"); S_CCFileUtils::jsCreateClass(this->cx, cocos, "FileUtils");
S_CCTexture2D::jsCreateClass(this->cx, cocos, "Texture2D"); S_CCTexture2D::jsCreateClass(this->cx, cocos, "Texture2D");
S_CCTextureCache::jsCreateClass(this->cx, cocos, "TextureCache"); S_CCTextureCache::jsCreateClass(this->cx, cocos, "TextureCache");
S_CCParallaxNode::jsCreateClass(this->cx, cocos, "ParallaxNode"); S_CCParallaxNode::jsCreateClass(this->cx, cocos, "ParallaxNode");
S_CCTintBy::jsCreateClass(this->cx, cocos, "TintBy"); S_CCTintBy::jsCreateClass(this->cx, cocos, "TintBy");
S_CCTintTo::jsCreateClass(this->cx, cocos, "TintTo"); S_CCTintTo::jsCreateClass(this->cx, cocos, "TintTo");
S_CCLayerColor::jsCreateClass(this->cx, cocos, "LayerColor"); S_CCLayerColor::jsCreateClass(this->cx, cocos, "LayerColor");
S_CCBlink::jsCreateClass(this->cx, cocos, "Blink"); S_CCBlink::jsCreateClass(this->cx, cocos, "Blink");
S_CCSpeed::jsCreateClass(this->cx, cocos, "Speed"); S_CCSpeed::jsCreateClass(this->cx, cocos, "Speed");
S_CCGridAction::jsCreateClass(this->cx, cocos, "GridAction"); S_CCGridAction::jsCreateClass(this->cx, cocos, "GridAction");
S_CCGrid3DAction::jsCreateClass(this->cx, cocos, "Grid3DAction"); S_CCGrid3DAction::jsCreateClass(this->cx, cocos, "Grid3DAction");
S_CCWaves3D::jsCreateClass(this->cx, cocos, "Waves3D"); S_CCWaves3D::jsCreateClass(this->cx, cocos, "Waves3D");
S_CCTransitionScene::jsCreateClass(this->cx, cocos, "TransitionScene"); S_CCTransitionScene::jsCreateClass(this->cx, cocos, "TransitionScene");
S_CCTransitionSceneOriented::jsCreateClass(this->cx, cocos, "TransitionSceneOriented"); S_CCTransitionSceneOriented::jsCreateClass(this->cx, cocos, "TransitionSceneOriented");
S_CCTransitionRotoZoom::jsCreateClass(this->cx, cocos, "TransitionRotoZoom"); S_CCTransitionRotoZoom::jsCreateClass(this->cx, cocos, "TransitionRotoZoom");
S_CCTransitionFadeDown::jsCreateClass(this->cx, cocos, "TransitionFadeDown"); S_CCTransitionFadeDown::jsCreateClass(this->cx, cocos, "TransitionFadeDown");
S_CCTransitionJumpZoom::jsCreateClass(this->cx, cocos, "TransitionJumpZoom"); S_CCTransitionJumpZoom::jsCreateClass(this->cx, cocos, "TransitionJumpZoom");
S_CCTransitionMoveInL::jsCreateClass(this->cx, cocos, "TransitionMoveInL"); S_CCTransitionMoveInL::jsCreateClass(this->cx, cocos, "TransitionMoveInL");
S_CCTransitionMoveInR::jsCreateClass(this->cx, cocos, "TransitionMoveInR"); S_CCTransitionMoveInR::jsCreateClass(this->cx, cocos, "TransitionMoveInR");
S_CCTransitionMoveInT::jsCreateClass(this->cx, cocos, "TransitionMoveInT"); S_CCTransitionMoveInT::jsCreateClass(this->cx, cocos, "TransitionMoveInT");
S_CCTransitionMoveInB::jsCreateClass(this->cx, cocos, "TransitionMoveInB"); S_CCTransitionMoveInB::jsCreateClass(this->cx, cocos, "TransitionMoveInB");
S_CCTransitionSlideInL::jsCreateClass(this->cx, cocos, "TransitionSlideInL"); S_CCTransitionSlideInL::jsCreateClass(this->cx, cocos, "TransitionSlideInL");
S_CCTransitionSlideInR::jsCreateClass(this->cx, cocos, "TransitionSlideInR"); S_CCTransitionSlideInR::jsCreateClass(this->cx, cocos, "TransitionSlideInR");
S_CCTransitionSlideInB::jsCreateClass(this->cx, cocos, "TransitionSlideInB"); S_CCTransitionSlideInB::jsCreateClass(this->cx, cocos, "TransitionSlideInB");
S_CCTransitionSlideInT::jsCreateClass(this->cx, cocos, "TransitionSlideInT"); S_CCTransitionSlideInT::jsCreateClass(this->cx, cocos, "TransitionSlideInT");
S_CCTransitionShrinkGrow::jsCreateClass(this->cx, cocos, "TransitionShrinkGrow"); S_CCTransitionShrinkGrow::jsCreateClass(this->cx, cocos, "TransitionShrinkGrow");
S_CCTransitionFlipX::jsCreateClass(this->cx, cocos, "TransitionFlipX"); S_CCTransitionFlipX::jsCreateClass(this->cx, cocos, "TransitionFlipX");
S_CCTransitionFlipY::jsCreateClass(this->cx, cocos, "TransitionFlipY"); S_CCTransitionFlipY::jsCreateClass(this->cx, cocos, "TransitionFlipY");
S_CCTransitionFlipAngular::jsCreateClass(this->cx, cocos, "TransitionFlipAngular"); S_CCTransitionFlipAngular::jsCreateClass(this->cx, cocos, "TransitionFlipAngular");
S_CCTransitionZoomFlipX::jsCreateClass(this->cx, cocos, "TransitionZoomFlipX"); S_CCTransitionZoomFlipX::jsCreateClass(this->cx, cocos, "TransitionZoomFlipX");
S_CCTransitionZoomFlipY::jsCreateClass(this->cx, cocos, "TransitionZoomFlipY"); S_CCTransitionZoomFlipY::jsCreateClass(this->cx, cocos, "TransitionZoomFlipY");
S_CCTransitionZoomFlipAngular::jsCreateClass(this->cx, cocos, "TransitionZoomFlipAngular"); S_CCTransitionZoomFlipAngular::jsCreateClass(this->cx, cocos, "TransitionZoomFlipAngular");
S_CCTransitionFade::jsCreateClass(this->cx, cocos, "TransitionFade"); S_CCTransitionFade::jsCreateClass(this->cx, cocos, "TransitionFade");
S_CCTransitionCrossFade::jsCreateClass(this->cx, cocos, "TransitionCrossFade"); S_CCTransitionCrossFade::jsCreateClass(this->cx, cocos, "TransitionCrossFade");
S_CCTransitionTurnOffTiles::jsCreateClass(this->cx, cocos, "TransitionTurnOffTiles"); S_CCTransitionTurnOffTiles::jsCreateClass(this->cx, cocos, "TransitionTurnOffTiles");
S_CCTransitionSplitCols::jsCreateClass(this->cx, cocos, "TransitionSplitCols"); S_CCTransitionSplitCols::jsCreateClass(this->cx, cocos, "TransitionSplitCols");
S_CCTransitionSplitRows::jsCreateClass(this->cx, cocos, "TransitionSplitRows"); S_CCTransitionSplitRows::jsCreateClass(this->cx, cocos, "TransitionSplitRows");
S_CCTransitionFadeTR::jsCreateClass(this->cx, cocos, "TransitionFadeTR"); S_CCTransitionFadeTR::jsCreateClass(this->cx, cocos, "TransitionFadeTR");
S_CCTransitionFadeBL::jsCreateClass(this->cx, cocos, "TransitionFadeBL"); S_CCTransitionFadeBL::jsCreateClass(this->cx, cocos, "TransitionFadeBL");
S_CCTransitionFadeUp::jsCreateClass(this->cx, cocos, "TransitionFadeUp"); S_CCTransitionFadeUp::jsCreateClass(this->cx, cocos, "TransitionFadeUp");
S_CCFadeOutBLTiles::jsCreateClass(this->cx, cocos, "FadeOutBLTiles"); S_CCFadeOutBLTiles::jsCreateClass(this->cx, cocos, "FadeOutBLTiles");
S_CCProgressFromTo::jsCreateClass(this->cx, cocos, "ProgressFromTo"); S_CCProgressFromTo::jsCreateClass(this->cx, cocos, "ProgressFromTo");
S_CCFadeOutUpTiles::jsCreateClass(this->cx, cocos, "FadeOutUpTiles"); S_CCFadeOutUpTiles::jsCreateClass(this->cx, cocos, "FadeOutUpTiles");
S_CCAnimationCache::jsCreateClass(this->cx, cocos, "AnimationCache"); S_CCAnimationCache::jsCreateClass(this->cx, cocos, "AnimationCache");
S_CCPlace::jsCreateClass(this->cx, cocos, "Place"); S_CCPlace::jsCreateClass(this->cx, cocos, "Place");
S_CCLabelBMFont::jsCreateClass(this->cx, cocos, "LabelBMFont"); S_CCLabelBMFont::jsCreateClass(this->cx, cocos, "LabelBMFont");
S_CCReverseTime::jsCreateClass(this->cx, cocos, "ReverseTime"); S_CCReverseTime::jsCreateClass(this->cx, cocos, "ReverseTime");
S_CCFadeOutTRTiles::jsCreateClass(this->cx, cocos, "FadeOutTRTiles"); S_CCFadeOutTRTiles::jsCreateClass(this->cx, cocos, "FadeOutTRTiles");
S_CCCamera::jsCreateClass(this->cx, cocos, "Camera"); S_CCCamera::jsCreateClass(this->cx, cocos, "Camera");
S_CCProgressTo::jsCreateClass(this->cx, cocos, "ProgressTo"); S_CCProgressTo::jsCreateClass(this->cx, cocos, "ProgressTo");
S_CCWavesTiles3D::jsCreateClass(this->cx, cocos, "WavesTiles3D"); S_CCWavesTiles3D::jsCreateClass(this->cx, cocos, "WavesTiles3D");
S_CCMotionStreak::jsCreateClass(this->cx, cocos, "MotionStreak"); S_CCMotionStreak::jsCreateClass(this->cx, cocos, "MotionStreak");
S_CCTransitionProgressRadialCCW::jsCreateClass(this->cx, cocos, "TransitionRadialProgressCCW"); S_CCTransitionProgressRadialCCW::jsCreateClass(this->cx, cocos, "TransitionRadialProgressCCW");
S_CCFadeOutDownTiles::jsCreateClass(this->cx, cocos, "FadeOutDownTiles"); S_CCFadeOutDownTiles::jsCreateClass(this->cx, cocos, "FadeOutDownTiles");
S_CCTurnOffTiles::jsCreateClass(this->cx, cocos, "TurnOffTiles"); S_CCTurnOffTiles::jsCreateClass(this->cx, cocos, "TurnOffTiles");
S_CCDeccelAmplitude::jsCreateClass(this->cx, cocos, "DeccelAmplitude"); S_CCDeccelAmplitude::jsCreateClass(this->cx, cocos, "DeccelAmplitude");
S_CCProgressTimer::jsCreateClass(this->cx, cocos, "ProgressTimer"); S_CCProgressTimer::jsCreateClass(this->cx, cocos, "ProgressTimer");
S_CCReuseGrid::jsCreateClass(this->cx, cocos, "ReuseGrid"); S_CCReuseGrid::jsCreateClass(this->cx, cocos, "ReuseGrid");
S_CCStopGrid::jsCreateClass(this->cx, cocos, "StopGrid"); S_CCStopGrid::jsCreateClass(this->cx, cocos, "StopGrid");
S_CCTwirl::jsCreateClass(this->cx, cocos, "Twirl"); S_CCTwirl::jsCreateClass(this->cx, cocos, "Twirl");
S_CCShakyTiles3D::jsCreateClass(this->cx, cocos, "ShakyTiles3D"); S_CCShakyTiles3D::jsCreateClass(this->cx, cocos, "ShakyTiles3D");
S_CCTransitionProgressRadialCW::jsCreateClass(this->cx, cocos, "TransitionProgressRadialCW"); S_CCTransitionProgressRadialCW::jsCreateClass(this->cx, cocos, "TransitionProgressRadialCW");
S_CCAtlasNode::jsCreateClass(this->cx, cocos, "AtlasNode"); S_CCAtlasNode::jsCreateClass(this->cx, cocos, "AtlasNode");
S_CCWaves::jsCreateClass(this->cx, cocos, "Waves"); S_CCWaves::jsCreateClass(this->cx, cocos, "Waves");
S_CCShow::jsCreateClass(this->cx, cocos, "Show"); S_CCShow::jsCreateClass(this->cx, cocos, "Show");
S_CCOrbitCamera::jsCreateClass(this->cx, cocos, "OrbitCamera"); S_CCOrbitCamera::jsCreateClass(this->cx, cocos, "OrbitCamera");
S_CCShatteredTiles3D::jsCreateClass(this->cx, cocos, "ShatteredTiles3D"); S_CCShatteredTiles3D::jsCreateClass(this->cx, cocos, "ShatteredTiles3D");
S_CCHide::jsCreateClass(this->cx, cocos, "Hide"); S_CCHide::jsCreateClass(this->cx, cocos, "Hide");
S_CCToggleVisibility::jsCreateClass(this->cx, cocos, "ToggleVisibility"); S_CCToggleVisibility::jsCreateClass(this->cx, cocos, "ToggleVisibility");
S_CCActionCamera::jsCreateClass(this->cx, cocos, "ActionCamera"); S_CCActionCamera::jsCreateClass(this->cx, cocos, "ActionCamera");
S_CCShuffleTiles::jsCreateClass(this->cx, cocos, "ShuffleTiles"); S_CCShuffleTiles::jsCreateClass(this->cx, cocos, "ShuffleTiles");
S_CCLayerGradient::jsCreateClass(this->cx, cocos, "LayerGradient"); S_CCLayerGradient::jsCreateClass(this->cx, cocos, "LayerGradient");
S_CCFlipX::jsCreateClass(this->cx, cocos, "FlipX"); S_CCFlipX::jsCreateClass(this->cx, cocos, "FlipX");
S_CCRepeat::jsCreateClass(this->cx, cocos, "Repeat"); S_CCRepeat::jsCreateClass(this->cx, cocos, "Repeat");
S_CCFlipY::jsCreateClass(this->cx, cocos, "FlipY"); S_CCFlipY::jsCreateClass(this->cx, cocos, "FlipY");
S_CCBezierBy::jsCreateClass(this->cx, cocos, "BezierBy"); S_CCBezierBy::jsCreateClass(this->cx, cocos, "BezierBy");
S_CCPageTurn3D::jsCreateClass(this->cx, cocos, "PageTurn3D"); S_CCPageTurn3D::jsCreateClass(this->cx, cocos, "PageTurn3D");
S_CCLens3D::jsCreateClass(this->cx, cocos, "Lens3D"); S_CCLens3D::jsCreateClass(this->cx, cocos, "Lens3D");
S_CCRipple3D::jsCreateClass(this->cx, cocos, "Ripple3D"); S_CCRipple3D::jsCreateClass(this->cx, cocos, "Ripple3D");
S_CCApplication::jsCreateClass(this->cx, cocos, "Application"); S_CCApplication::jsCreateClass(this->cx, cocos, "Application");
S_CCFlipX3D::jsCreateClass(this->cx, cocos, "FlipX3D"); S_CCFlipX3D::jsCreateClass(this->cx, cocos, "FlipX3D");
S_CCJumpTo::jsCreateClass(this->cx, cocos, "JumpTo"); S_CCJumpTo::jsCreateClass(this->cx, cocos, "JumpTo");
S_CCTransitionPageTurn::jsCreateClass(this->cx, cocos, "TransitionPageTurn"); S_CCTransitionPageTurn::jsCreateClass(this->cx, cocos, "TransitionPageTurn");
S_CCFlipY3D::jsCreateClass(this->cx, cocos, "FlipY3D"); S_CCFlipY3D::jsCreateClass(this->cx, cocos, "FlipY3D");
S_CCLiquid::jsCreateClass(this->cx, cocos, "Liquid"); S_CCLiquid::jsCreateClass(this->cx, cocos, "Liquid");
S_CCTiledGrid3DAction::jsCreateClass(this->cx, cocos, "TiledGrid3DAction"); S_CCTiledGrid3DAction::jsCreateClass(this->cx, cocos, "TiledGrid3DAction");
S_CCJumpBy::jsCreateClass(this->cx, cocos, "JumpBy"); S_CCJumpBy::jsCreateClass(this->cx, cocos, "JumpBy");
S_CCFollow::jsCreateClass(this->cx, cocos, "Follow"); S_CCFollow::jsCreateClass(this->cx, cocos, "Follow");
S_CCSkewBy::jsCreateClass(this->cx, cocos, "SkewBy"); S_CCSkewBy::jsCreateClass(this->cx, cocos, "SkewBy");
S_CCAccelDeccelAmplitude::jsCreateClass(this->cx, cocos, "AccelDeccelAmplitude"); S_CCAccelDeccelAmplitude::jsCreateClass(this->cx, cocos, "AccelDeccelAmplitude");
S_CCLabelAtlas::jsCreateClass(this->cx, cocos, "LabelAtlas"); S_CCLabelAtlas::jsCreateClass(this->cx, cocos, "LabelAtlas");
S_CCAccelAmplitude::jsCreateClass(this->cx, cocos, "AccelAmplitude"); S_CCAccelAmplitude::jsCreateClass(this->cx, cocos, "AccelAmplitude");
S_CCSkewTo::jsCreateClass(this->cx, cocos, "SkewTo"); S_CCSkewTo::jsCreateClass(this->cx, cocos, "SkewTo");
S_CCShaky3D::jsCreateClass(this->cx, cocos, "Shaky3D"); S_CCShaky3D::jsCreateClass(this->cx, cocos, "Shaky3D");
S_CCSplitCols::jsCreateClass(this->cx, cocos, "SplitCols"); S_CCSplitCols::jsCreateClass(this->cx, cocos, "SplitCols");
S_CCFadeOut::jsCreateClass(this->cx, cocos, "FadeOut"); S_CCFadeOut::jsCreateClass(this->cx, cocos, "FadeOut");
S_CCTileMapAtlas::jsCreateClass(this->cx, cocos, "TileMapAtlas"); S_CCTileMapAtlas::jsCreateClass(this->cx, cocos, "TileMapAtlas");
S_CCFadeTo::jsCreateClass(this->cx, cocos, "FadeTo"); S_CCFadeTo::jsCreateClass(this->cx, cocos, "FadeTo");
S_CCJumpTiles3D::jsCreateClass(this->cx, cocos, "JumpTiles3D"); S_CCJumpTiles3D::jsCreateClass(this->cx, cocos, "JumpTiles3D");
S_CCFadeIn::jsCreateClass(this->cx, cocos, "FadeIn"); S_CCFadeIn::jsCreateClass(this->cx, cocos, "FadeIn");
S_CCSplitRows::jsCreateClass(this->cx, cocos, "SplitRows"); S_CCSplitRows::jsCreateClass(this->cx, cocos, "SplitRows");
S_CCScaleBy::jsCreateClass(this->cx, cocos, "ScaleBy"); S_CCScaleBy::jsCreateClass(this->cx, cocos, "ScaleBy");
S_CCScaleTo::jsCreateClass(this->cx, cocos, "ScaleTo"); S_CCScaleTo::jsCreateClass(this->cx, cocos, "ScaleTo");
S_CCBezierTo::jsCreateClass(this->cx, cocos, "BezierTo"); S_CCBezierTo::jsCreateClass(this->cx, cocos, "BezierTo");
S_CCTMXTiledMap::jsCreateClass(this->cx, cocos, "TMXTiledMap"); S_CCTMXTiledMap::jsCreateClass(this->cx, cocos, "TMXTiledMap");
S_CCTMXLayer::jsCreateClass(this->cx, cocos, "TMXLayer"); S_CCTMXLayer::jsCreateClass(this->cx, cocos, "TMXLayer");
S_SimpleAudioEngine::jsCreateClass(this->cx, cocos, "SimpleAudioEngine"); S_SimpleAudioEngine::jsCreateClass(this->cx, cocos, "SimpleAudioEngine");
// register some global functions // register some global functions
JS_DefineFunction(this->cx, global, "require", ScriptingCore::executeScript, 0, JSPROP_READONLY | JSPROP_PERMANENT); JS_DefineFunction(this->cx, global, "require", ScriptingCore::executeScript, 0, JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(this->cx, cocos, "log", ScriptingCore::log, 0, JSPROP_READONLY | JSPROP_PERMANENT); JS_DefineFunction(this->cx, cocos, "log", ScriptingCore::log, 0, JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(this->cx, cocos, "executeScript", ScriptingCore::executeScript, 1, JSPROP_READONLY | JSPROP_PERMANENT); JS_DefineFunction(this->cx, cocos, "executeScript", ScriptingCore::executeScript, 1, JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(this->cx, cocos, "addGCRootObject", ScriptingCore::addRootJS, 1, JSPROP_READONLY | JSPROP_PERMANENT); JS_DefineFunction(this->cx, cocos, "addGCRootObject", ScriptingCore::addRootJS, 1, JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(this->cx, cocos, "removeGCRootObject", ScriptingCore::removeRootJS, 1, JSPROP_READONLY | JSPROP_PERMANENT); JS_DefineFunction(this->cx, cocos, "removeGCRootObject", ScriptingCore::removeRootJS, 1, JSPROP_READONLY | JSPROP_PERMANENT);
JS_DefineFunction(this->cx, cocos, "forceGC", ScriptingCore::forceGC, 0, JSPROP_READONLY | JSPROP_PERMANENT); JS_DefineFunction(this->cx, cocos, "forceGC", ScriptingCore::forceGC, 0, JSPROP_READONLY | JSPROP_PERMANENT);
} }
bool ScriptingCore::evalString(const char *string, jsval *outVal) bool ScriptingCore::evalString(const char *string, jsval *outVal)
{ {
jsval rval; jsval rval;
JSString *str; JSString *str;
JSBool ok; JSBool ok;
const char *filename = "noname"; const char *filename = "noname";
uint32_t lineno = 0; uint32_t lineno = 0;
if (outVal == NULL) { if (outVal == NULL) {
outVal = &rval; outVal = &rval;
} }
ok = JS_EvaluateScript(cx, global, string, strlen(string), filename, lineno, outVal); ok = JS_EvaluateScript(cx, global, string, strlen(string), filename, lineno, outVal);
if (ok == JS_FALSE) { if (ok == JS_FALSE) {
CCLog("error evaluating script:\n%s", string); CCLog("error evaluating script:\n%s", string);
} }
str = JS_ValueToString(cx, rval); str = JS_ValueToString(cx, rval);
return ok; return ok;
} }
void ScriptingCore::runScript(const char *path) void ScriptingCore::runScript(const char *path)
{ {
#ifdef DEBUG #ifdef DEBUG
/** /**
* dpath should point to the parent directory of the "JS" folder. If this is * dpath should point to the parent directory of the "JS" folder. If this is
* set to "" (as it is now) then it will take the scripts from the app bundle. * set to "" (as it is now) then it will take the scripts from the app bundle.
* By setting the absolute path you can iterate the development only by * By setting the absolute path you can iterate the development only by
* modifying those scripts and reloading from the simulator (no recompiling/ * modifying those scripts and reloading from the simulator (no recompiling/
* relaunching) * relaunching)
*/ */
// std::string dpath("/Users/rabarca/Desktop/testjs/testjs/"); // std::string dpath("/Users/rabarca/Desktop/testjs/testjs/");
std::string dpath(""); std::string dpath("");
dpath += path; dpath += path;
const char *realPath = CCFileUtils::fullPathFromRelativePath(dpath.c_str()); const char *realPath = CCFileUtils::fullPathFromRelativePath(dpath.c_str());
#else #else
const char *realPath = CCFileUtils::fullPathFromRelativePath(path); const char *realPath = CCFileUtils::fullPathFromRelativePath(path);
#endif #endif
const char* content = CCString::stringWithContentsOfFile(realPath)->getCString(); const char* content = CCString::stringWithContentsOfFile(realPath)->getCString();
if (content && strlen(content) > 0) { if (content && strlen(content) > 0) {
JSBool ok; JSBool ok;
jsval rval; jsval rval;
ok = JS_EvaluateScript(this->cx, this->global, (char *)content, strlen(content), path, 1, &rval); ok = JS_EvaluateScript(this->cx, this->global, (char *)content, strlen(content), path, 1, &rval);
if (ok == JS_FALSE) { if (ok == JS_FALSE) {
CCLog("error evaluating script:\n%s", content); CCLog("error evaluating script:\n%s", content);
} }
} }
} }
ScriptingCore::~ScriptingCore() ScriptingCore::~ScriptingCore()
{ {
JS_DestroyContext(cx); JS_DestroyContext(cx);
JS_DestroyRuntime(rt); JS_DestroyRuntime(rt);
JS_ShutDown(); JS_ShutDown();
} }

View File

@ -14,129 +14,129 @@
class ScriptingCore class ScriptingCore
{ {
JSRuntime *rt; JSRuntime *rt;
JSContext *cx; JSContext *cx;
JSObject *global; JSObject *global;
ScriptingCore(); ScriptingCore();
public: public:
~ScriptingCore(); ~ScriptingCore();
static ScriptingCore & getInstance() { static ScriptingCore & getInstance() {
static ScriptingCore instance; static ScriptingCore instance;
return instance; return instance;
}; };
/** /**
* will eval the specified string * will eval the specified string
* @param string The string with the javascript code to be evaluated * @param string The string with the javascript code to be evaluated
* @param outVal The jsval that will hold the return value of the evaluation. * @param outVal The jsval that will hold the return value of the evaluation.
* Can be NULL. * Can be NULL.
*/ */
bool evalString(const char *string, jsval *outVal); bool evalString(const char *string, jsval *outVal);
/** /**
* will run the specified string * will run the specified string
* @param string The path of the script to be run * @param string The path of the script to be run
*/ */
void runScript(const char *path); void runScript(const char *path);
/** /**
* @return the global context * @return the global context
*/ */
JSContext* getGlobalContext() { JSContext* getGlobalContext() {
return cx; return cx;
}; };
/** /**
* @param cx * @param cx
* @param message * @param message
* @param report * @param report
*/ */
static void reportError(JSContext *cx, const char *message, JSErrorReport *report) static void reportError(JSContext *cx, const char *message, JSErrorReport *report)
{ {
fprintf(stderr, "%s:%u:%s\n", fprintf(stderr, "%s:%u:%s\n",
report->filename ? report->filename : "<no filename=\"filename\">", report->filename ? report->filename : "<no filename=\"filename\">",
(unsigned int) report->lineno, (unsigned int) report->lineno,
message); message);
}; };
/** /**
* Log something using CCLog * Log something using CCLog
* @param cx * @param cx
* @param argc * @param argc
* @param vp * @param vp
*/ */
static JSBool log(JSContext *cx, uint32_t argc, jsval *vp) static JSBool log(JSContext *cx, uint32_t argc, jsval *vp)
{ {
if (argc > 0) { if (argc > 0) {
JSString *string = NULL; JSString *string = NULL;
JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "S", &string); JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "S", &string);
if (string) { if (string) {
char *cstr = JS_EncodeString(cx, string); char *cstr = JS_EncodeString(cx, string);
cocos2d::CCLog(cstr); cocos2d::CCLog(cstr);
} }
} }
return JS_TRUE; return JS_TRUE;
}; };
/** /**
* run a script from script :) * run a script from script :)
*/ */
static JSBool executeScript(JSContext *cx, uint32_t argc, jsval *vp) static JSBool executeScript(JSContext *cx, uint32_t argc, jsval *vp)
{ {
if (argc == 1) { if (argc == 1) {
JSString *string; JSString *string;
if (JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "S", &string) == JS_TRUE) { if (JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "S", &string) == JS_TRUE) {
ScriptingCore::getInstance().runScript(JS_EncodeString(cx, string)); ScriptingCore::getInstance().runScript(JS_EncodeString(cx, string));
} }
} }
return JS_TRUE; return JS_TRUE;
}; };
/** /**
* Register an object as a member of the GC's root set, preventing * Register an object as a member of the GC's root set, preventing
* them from being GC'ed * them from being GC'ed
*/ */
static JSBool addRootJS(JSContext *cx, uint32_t argc, jsval *vp) static JSBool addRootJS(JSContext *cx, uint32_t argc, jsval *vp)
{ {
if (argc == 1) { if (argc == 1) {
JSObject *o = NULL; JSObject *o = NULL;
if (JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "o", &o) == JS_TRUE) { if (JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "o", &o) == JS_TRUE) {
if (JS_AddObjectRoot(cx, &o) == JS_FALSE) { if (JS_AddObjectRoot(cx, &o) == JS_FALSE) {
cocos2d::CCLog("something went wrong when setting an object to the root"); cocos2d::CCLog("something went wrong when setting an object to the root");
} }
} }
} }
return JS_TRUE; return JS_TRUE;
}; };
/** /**
* removes an object from the GC's root, allowing them to be GC'ed if no * removes an object from the GC's root, allowing them to be GC'ed if no
* longer referenced. * longer referenced.
*/ */
static JSBool removeRootJS(JSContext *cx, uint32_t argc, jsval *vp) static JSBool removeRootJS(JSContext *cx, uint32_t argc, jsval *vp)
{ {
if (argc == 1) { if (argc == 1) {
JSObject *o = NULL; JSObject *o = NULL;
if (JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "o", &o) == JS_TRUE) { if (JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "o", &o) == JS_TRUE) {
JS_RemoveObjectRoot(cx, &o); JS_RemoveObjectRoot(cx, &o);
} }
} }
return JS_TRUE; return JS_TRUE;
}; };
/** /**
* Force a cycle of GC * Force a cycle of GC
* @param cx * @param cx
* @param argc * @param argc
* @param vp * @param vp
*/ */
static JSBool forceGC(JSContext *cx, uint32_t argc, jsval *vp) static JSBool forceGC(JSContext *cx, uint32_t argc, jsval *vp)
{ {
JS_GC(cx); JS_GC(cx);
return JS_TRUE; return JS_TRUE;
}; };
}; };
#endif #endif

View File

@ -1,379 +1,379 @@
#include "cocos2d_generated.hpp" #include "cocos2d_generated.hpp"
JSBool S_CCNode::jsaddChild(JSContext *cx, uint32_t argc, jsval *vp) { JSBool S_CCNode::jsaddChild(JSContext *cx, uint32_t argc, jsval *vp) {
JSObject* obj = (JSObject *)JS_THIS_OBJECT(cx, vp); JSObject* obj = (JSObject *)JS_THIS_OBJECT(cx, vp);
S_CCNode* self = NULL; JSGET_PTRSHELL(S_CCNode, self, obj); S_CCNode* self = NULL; JSGET_PTRSHELL(S_CCNode, self, obj);
if (self == NULL) return JS_FALSE; if (self == NULL) return JS_FALSE;
if (argc >= 1) { if (argc >= 1) {
JSObject *arg0; JSObject *arg0;
int zorder = 0; int zorder = 0;
int tag = 0; int tag = 0;
JS_ConvertArguments(cx, 1, JS_ARGV(cx, vp), "o/ii", &arg0, &zorder, &tag); JS_ConvertArguments(cx, 1, JS_ARGV(cx, vp), "o/ii", &arg0, &zorder, &tag);
CCNode* narg0; JSGET_PTRSHELL(CCNode, narg0, arg0); CCNode* narg0; JSGET_PTRSHELL(CCNode, narg0, arg0);
// call the proper method // call the proper method
if (argc == 1) { if (argc == 1) {
self->addChild(narg0); self->addChild(narg0);
} else if (argc == 2) { } else if (argc == 2) {
self->addChild(narg0, zorder); self->addChild(narg0, zorder);
} else { } else {
self->addChild(narg0, zorder, tag); self->addChild(narg0, zorder, tag);
} }
JS_SET_RVAL(cx, vp, JSVAL_TRUE); JS_SET_RVAL(cx, vp, JSVAL_TRUE);
return JS_TRUE; return JS_TRUE;
} }
JS_SET_RVAL(cx, vp, JSVAL_TRUE); JS_SET_RVAL(cx, vp, JSVAL_TRUE);
return JS_TRUE; return JS_TRUE;
} }
JSBool S_CCMenuItemSprite::jsinitWithNormalSprite(JSContext *cx, uint32_t argc, jsval *vp) { JSBool S_CCMenuItemSprite::jsinitWithNormalSprite(JSContext *cx, uint32_t argc, jsval *vp) {
JSObject* obj = (JSObject *)JS_THIS_OBJECT(cx, vp); JSObject* obj = (JSObject *)JS_THIS_OBJECT(cx, vp);
S_CCMenuItemSprite* self = NULL; JSGET_PTRSHELL(S_CCMenuItemSprite, self, obj); S_CCMenuItemSprite* self = NULL; JSGET_PTRSHELL(S_CCMenuItemSprite, self, obj);
if (self == NULL) return JS_FALSE; if (self == NULL) return JS_FALSE;
if (argc >= 2) { if (argc >= 2) {
JSObject *arg0; JSObject *arg0;
JSObject *arg1; JSObject *arg1;
JSObject *arg2 = NULL; JSObject *arg2 = NULL;
JS_ConvertArguments(cx, 5, JS_ARGV(cx, vp), "oo/o", &arg0, &arg1, &arg2); JS_ConvertArguments(cx, 5, JS_ARGV(cx, vp), "oo/o", &arg0, &arg1, &arg2);
CCNode* narg0; JSGET_PTRSHELL(CCNode, narg0, arg0); CCNode* narg0; JSGET_PTRSHELL(CCNode, narg0, arg0);
CCNode* narg1; JSGET_PTRSHELL(CCNode, narg1, arg1); CCNode* narg1; JSGET_PTRSHELL(CCNode, narg1, arg1);
CCNode* narg2 = NULL; if (argc == 3) JSGET_PTRSHELL(CCNode, narg2, arg2); CCNode* narg2 = NULL; if (argc == 3) JSGET_PTRSHELL(CCNode, narg2, arg2);
bool ret = self->initWithNormalSprite(narg0, narg1, narg2, self, menu_selector(S_CCMenuItemSprite::menuAction)); bool ret = self->initWithNormalSprite(narg0, narg1, narg2, self, menu_selector(S_CCMenuItemSprite::menuAction));
JS_SET_RVAL(cx, vp, BOOLEAN_TO_JSVAL(ret)); JS_SET_RVAL(cx, vp, BOOLEAN_TO_JSVAL(ret));
return JS_TRUE; return JS_TRUE;
} }
JS_SET_RVAL(cx, vp, JSVAL_TRUE); JS_SET_RVAL(cx, vp, JSVAL_TRUE);
return JS_TRUE; return JS_TRUE;
} }
JSBool S_CCMenuItemImage::jsinitWithNormalImage(JSContext *cx, uint32_t argc, jsval *vp) { JSBool S_CCMenuItemImage::jsinitWithNormalImage(JSContext *cx, uint32_t argc, jsval *vp) {
JSObject* obj = (JSObject *)JS_THIS_OBJECT(cx, vp); JSObject* obj = (JSObject *)JS_THIS_OBJECT(cx, vp);
S_CCMenuItemImage* self = NULL; JSGET_PTRSHELL(S_CCMenuItemImage, self, obj); S_CCMenuItemImage* self = NULL; JSGET_PTRSHELL(S_CCMenuItemImage, self, obj);
if (self == NULL) return JS_FALSE; if (self == NULL) return JS_FALSE;
if (argc >= 2) { if (argc >= 2) {
JSString *arg0; JSString *arg0;
JSString *arg1; JSString *arg1;
JSString *arg2 = NULL; JSString *arg2 = NULL;
JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "SS/S", &arg0, &arg1, &arg2); JS_ConvertArguments(cx, argc, JS_ARGV(cx, vp), "SS/S", &arg0, &arg1, &arg2);
char *narg0 = JS_EncodeString(cx, arg0); char *narg0 = JS_EncodeString(cx, arg0);
char *narg1 = JS_EncodeString(cx, arg1); char *narg1 = JS_EncodeString(cx, arg1);
char *narg2 = (arg2) ? JS_EncodeString(cx, arg2) : NULL; char *narg2 = (arg2) ? JS_EncodeString(cx, arg2) : NULL;
bool ret = self->initWithNormalImage(narg0, narg1, narg2, self, menu_selector(S_CCMenuItemImage::menuAction)); bool ret = self->initWithNormalImage(narg0, narg1, narg2, self, menu_selector(S_CCMenuItemImage::menuAction));
JS_SET_RVAL(cx, vp, BOOLEAN_TO_JSVAL(ret)); JS_SET_RVAL(cx, vp, BOOLEAN_TO_JSVAL(ret));
return JS_TRUE; return JS_TRUE;
} }
JS_SET_RVAL(cx, vp, JSVAL_TRUE); JS_SET_RVAL(cx, vp, JSVAL_TRUE);
return JS_TRUE; return JS_TRUE;
} }
JSBool S_CCSequence::jsactions(JSContext *cx, uint32_t argc, jsval *vp) { JSBool S_CCSequence::jsactions(JSContext *cx, uint32_t argc, jsval *vp) {
// just like CCSequence::actions // just like CCSequence::actions
if (argc > 0) { if (argc > 0) {
jsval* argv = JS_ARGV(cx, vp); jsval* argv = JS_ARGV(cx, vp);
// get first element // get first element
S_CCSequence* prev; S_CCSequence* prev;
JSGET_PTRSHELL(S_CCSequence, prev, JSVAL_TO_OBJECT(argv[0])); JSGET_PTRSHELL(S_CCSequence, prev, JSVAL_TO_OBJECT(argv[0]));
for (int i=1; i < argc; i++) { for (int i=1; i < argc; i++) {
CCFiniteTimeAction *next; JSGET_PTRSHELL(CCFiniteTimeAction, next, JSVAL_TO_OBJECT(argv[i])); CCFiniteTimeAction *next; JSGET_PTRSHELL(CCFiniteTimeAction, next, JSVAL_TO_OBJECT(argv[i]));
prev = (S_CCSequence *)CCSequence::actionOneTwo(prev, next); prev = (S_CCSequence *)CCSequence::actionOneTwo(prev, next);
} }
// wrap prev in an action // wrap prev in an action
// temporary because it's just a wrapper for an autoreleased object // temporary because it's just a wrapper for an autoreleased object
// or worst case, it's an already binded object (if it's just one item in the array) // or worst case, it's an already binded object (if it's just one item in the array)
pointerShell_t* pt = (pointerShell_t *)JS_malloc(cx, sizeof(pointerShell_t)); pointerShell_t* pt = (pointerShell_t *)JS_malloc(cx, sizeof(pointerShell_t));
pt->flags = kPointerTemporary; pt->flags = kPointerTemporary;
pt->data = prev; pt->data = prev;
JSObject* out = JS_NewObject(cx, S_CCSequence::jsClass, S_CCSequence::jsObject, NULL); JSObject* out = JS_NewObject(cx, S_CCSequence::jsClass, S_CCSequence::jsObject, NULL);
prev->jsObject = out; prev->jsObject = out;
JS_SetPrivate(out, pt); JS_SetPrivate(out, pt);
JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(out)); JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(out));
return JS_TRUE; return JS_TRUE;
} }
JS_ReportError(cx, "must call with at least one element"); JS_ReportError(cx, "must call with at least one element");
return JS_FALSE; return JS_FALSE;
} }
JSBool S_CCParticleSystem::jsparticleWithFile(JSContext *cx, uint32_t argc, jsval *vp) { JSBool S_CCParticleSystem::jsparticleWithFile(JSContext *cx, uint32_t argc, jsval *vp) {
if (argc == 1) { if (argc == 1) {
JSString *arg0; JSString *arg0;
JS_ConvertArguments(cx, 1, JS_ARGV(cx, vp), "S", &arg0); JS_ConvertArguments(cx, 1, JS_ARGV(cx, vp), "S", &arg0);
char *narg0 = JS_EncodeString(cx, arg0); char *narg0 = JS_EncodeString(cx, arg0);
CCParticleSystem* ret = CCParticleSystemQuad::particleWithFile(narg0); CCParticleSystem* ret = CCParticleSystemQuad::particleWithFile(narg0);
if (ret == NULL) { if (ret == NULL) {
JS_SET_RVAL(cx, vp, JSVAL_NULL); JS_SET_RVAL(cx, vp, JSVAL_NULL);
return JS_TRUE; return JS_TRUE;
} }
do { do {
JSObject *tmp = JS_NewObject(cx, S_CCParticleSystem::jsClass, S_CCParticleSystem::jsObject, NULL); JSObject *tmp = JS_NewObject(cx, S_CCParticleSystem::jsClass, S_CCParticleSystem::jsObject, NULL);
pointerShell_t *pt = (pointerShell_t *)JS_malloc(cx, sizeof(pointerShell_t)); pointerShell_t *pt = (pointerShell_t *)JS_malloc(cx, sizeof(pointerShell_t));
pt->flags = kPointerTemporary; pt->flags = kPointerTemporary;
pt->data = (void *)ret; pt->data = (void *)ret;
JS_SetPrivate(tmp, pt); JS_SetPrivate(tmp, pt);
JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(tmp)); JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(tmp));
} while (0); } while (0);
return JS_TRUE; return JS_TRUE;
} }
JS_SET_RVAL(cx, vp, JSVAL_TRUE); JS_SET_RVAL(cx, vp, JSVAL_TRUE);
return JS_TRUE; return JS_TRUE;
} }
JSBool S_CCFileUtils::jsgetFileData(JSContext *cx, uint32_t argc, jsval *vp) { JSBool S_CCFileUtils::jsgetFileData(JSContext *cx, uint32_t argc, jsval *vp) {
if (argc == 2) { if (argc == 2) {
JSString *arg0; JSString *arg0;
JSString *arg1; JSString *arg1;
unsigned long len; unsigned long len;
JS_ConvertArguments(cx, 2, JS_ARGV(cx, vp), "SS", &arg0, &arg1); JS_ConvertArguments(cx, 2, JS_ARGV(cx, vp), "SS", &arg0, &arg1);
char *narg0 = JS_EncodeString(cx, arg0); char *narg0 = JS_EncodeString(cx, arg0);
char *narg1 = JS_EncodeString(cx, arg1); char *narg1 = JS_EncodeString(cx, arg1);
unsigned char *ret = CCFileUtils::getFileData(narg0, narg1, &len); unsigned char *ret = CCFileUtils::getFileData(narg0, narg1, &len);
if (ret == NULL) { if (ret == NULL) {
JS_SET_RVAL(cx, vp, JSVAL_NULL); JS_SET_RVAL(cx, vp, JSVAL_NULL);
return JS_TRUE; return JS_TRUE;
} }
JSString *str = JS_NewStringCopyN(cx, (const char *)ret, len); JSString *str = JS_NewStringCopyN(cx, (const char *)ret, len);
JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(str)); JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(str));
return JS_TRUE; return JS_TRUE;
} }
JS_SET_RVAL(cx, vp, JSVAL_TRUE); JS_SET_RVAL(cx, vp, JSVAL_TRUE);
return JS_TRUE; return JS_TRUE;
} }
JSBool S_CCFileUtils::jsfullPathFromRelativePath(JSContext *cx, uint32_t argc, jsval *vp) { JSBool S_CCFileUtils::jsfullPathFromRelativePath(JSContext *cx, uint32_t argc, jsval *vp) {
if (argc == 1) { if (argc == 1) {
JSString *arg0; JSString *arg0;
JS_ConvertArguments(cx, 1, JS_ARGV(cx, vp), "S", &arg0); JS_ConvertArguments(cx, 1, JS_ARGV(cx, vp), "S", &arg0);
char *narg0 = JS_EncodeString(cx, arg0); char *narg0 = JS_EncodeString(cx, arg0);
const char *ret = CCFileUtils::fullPathFromRelativePath(narg0); const char *ret = CCFileUtils::fullPathFromRelativePath(narg0);
if (ret == NULL) { if (ret == NULL) {
JS_SET_RVAL(cx, vp, JSVAL_NULL); JS_SET_RVAL(cx, vp, JSVAL_NULL);
return JS_TRUE; return JS_TRUE;
} }
JSString *str = JS_NewStringCopyN(cx, ret, strlen(ret)); JSString *str = JS_NewStringCopyN(cx, ret, strlen(ret));
JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(str)); JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(str));
return JS_TRUE; return JS_TRUE;
} }
JS_SET_RVAL(cx, vp, JSVAL_TRUE); JS_SET_RVAL(cx, vp, JSVAL_TRUE);
return JS_TRUE; return JS_TRUE;
} }
JSBool S_CCFileUtils::jsfullPathFromRelativeFile(JSContext *cx, uint32_t argc, jsval *vp) { JSBool S_CCFileUtils::jsfullPathFromRelativeFile(JSContext *cx, uint32_t argc, jsval *vp) {
if (argc == 2) { if (argc == 2) {
JSString *arg0; JSString *arg0;
JSString *arg1; JSString *arg1;
JS_ConvertArguments(cx, 2, JS_ARGV(cx, vp), "SS", &arg0, &arg1); JS_ConvertArguments(cx, 2, JS_ARGV(cx, vp), "SS", &arg0, &arg1);
char *narg0 = JS_EncodeString(cx, arg0); char *narg0 = JS_EncodeString(cx, arg0);
char *narg1 = JS_EncodeString(cx, arg1); char *narg1 = JS_EncodeString(cx, arg1);
const char *ret = CCFileUtils::fullPathFromRelativeFile(narg0, narg1); const char *ret = CCFileUtils::fullPathFromRelativeFile(narg0, narg1);
if (ret == NULL) { if (ret == NULL) {
JS_SET_RVAL(cx, vp, JSVAL_NULL); JS_SET_RVAL(cx, vp, JSVAL_NULL);
return JS_TRUE; return JS_TRUE;
} }
JSString *str = JS_NewStringCopyN(cx, ret, strlen(ret)); JSString *str = JS_NewStringCopyN(cx, ret, strlen(ret));
JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(str)); JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(str));
return JS_TRUE; return JS_TRUE;
return JS_TRUE; return JS_TRUE;
} }
JS_SET_RVAL(cx, vp, JSVAL_TRUE); JS_SET_RVAL(cx, vp, JSVAL_TRUE);
return JS_TRUE; return JS_TRUE;
} }
JSBool S_CCLabelTTF::jslabelWithString(JSContext *cx, uint32_t argc, jsval *vp) { JSBool S_CCLabelTTF::jslabelWithString(JSContext *cx, uint32_t argc, jsval *vp) {
if (argc == 5) { if (argc == 5) {
JSString *arg0; JSString *arg0;
JSObject *arg1; JSObject *arg1;
int arg2; int arg2;
JSString *arg3; JSString *arg3;
double arg4; double arg4;
JS_ConvertArguments(cx, 5, JS_ARGV(cx, vp), "SoiSd", &arg0, &arg1, &arg2, &arg3, &arg4); JS_ConvertArguments(cx, 5, JS_ARGV(cx, vp), "SoiSd", &arg0, &arg1, &arg2, &arg3, &arg4);
char *narg0 = JS_EncodeString(cx, arg0); char *narg0 = JS_EncodeString(cx, arg0);
CCSize* narg1; JSGET_PTRSHELL(CCSize, narg1, arg1); CCSize* narg1; JSGET_PTRSHELL(CCSize, narg1, arg1);
char *narg3 = JS_EncodeString(cx, arg3); char *narg3 = JS_EncodeString(cx, arg3);
CCLabelTTF *ret = CCLabelTTF::labelWithString(narg0, *narg1, (CCTextAlignment)arg2, narg3, arg4); CCLabelTTF *ret = CCLabelTTF::labelWithString(narg0, *narg1, (CCTextAlignment)arg2, narg3, arg4);
if (ret == NULL) { if (ret == NULL) {
JS_SET_RVAL(cx, vp, JSVAL_NULL); JS_SET_RVAL(cx, vp, JSVAL_NULL);
return JS_TRUE; return JS_TRUE;
} }
do { do {
JSObject *tmp = JS_NewObject(cx, S_CCLabelTTF::jsClass, S_CCLabelTTF::jsObject, NULL); JSObject *tmp = JS_NewObject(cx, S_CCLabelTTF::jsClass, S_CCLabelTTF::jsObject, NULL);
pointerShell_t *pt = (pointerShell_t *)JS_malloc(cx, sizeof(pointerShell_t)); pointerShell_t *pt = (pointerShell_t *)JS_malloc(cx, sizeof(pointerShell_t));
pt->flags = kPointerTemporary; pt->flags = kPointerTemporary;
pt->data = (void *)ret; pt->data = (void *)ret;
JS_SetPrivate(tmp, pt); JS_SetPrivate(tmp, pt);
JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(tmp)); JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(tmp));
} while (0); } while (0);
return JS_TRUE; return JS_TRUE;
} }
JS_SET_RVAL(cx, vp, JSVAL_TRUE); JS_SET_RVAL(cx, vp, JSVAL_TRUE);
return JS_TRUE; return JS_TRUE;
} }
JSBool S_CCLabelTTF::jsinitWithString(JSContext *cx, uint32_t argc, jsval *vp) { JSBool S_CCLabelTTF::jsinitWithString(JSContext *cx, uint32_t argc, jsval *vp) {
JSObject* obj = (JSObject *)JS_THIS_OBJECT(cx, vp); JSObject* obj = (JSObject *)JS_THIS_OBJECT(cx, vp);
S_CCLabelTTF* self = NULL; JSGET_PTRSHELL(S_CCLabelTTF, self, obj); S_CCLabelTTF* self = NULL; JSGET_PTRSHELL(S_CCLabelTTF, self, obj);
if (self == NULL) return JS_FALSE; if (self == NULL) return JS_FALSE;
if (argc == 5) { if (argc == 5) {
JSString *arg0; JSString *arg0;
JSObject *arg1; JSObject *arg1;
int arg2; int arg2;
JSString *arg3; JSString *arg3;
double arg4; double arg4;
JS_ConvertArguments(cx, 5, JS_ARGV(cx, vp), "SoiSd", &arg0, &arg1, &arg2, &arg3, &arg4); JS_ConvertArguments(cx, 5, JS_ARGV(cx, vp), "SoiSd", &arg0, &arg1, &arg2, &arg3, &arg4);
char *narg0 = JS_EncodeString(cx, arg0); char *narg0 = JS_EncodeString(cx, arg0);
CCSize* narg1; JSGET_PTRSHELL(CCSize, narg1, arg1); CCSize* narg1; JSGET_PTRSHELL(CCSize, narg1, arg1);
char *narg3 = JS_EncodeString(cx, arg3); char *narg3 = JS_EncodeString(cx, arg3);
bool ret = self->initWithString(narg0, *narg1, (CCTextAlignment)arg2, narg3, arg4); bool ret = self->initWithString(narg0, *narg1, (CCTextAlignment)arg2, narg3, arg4);
JS_SET_RVAL(cx, vp, BOOLEAN_TO_JSVAL(ret)); JS_SET_RVAL(cx, vp, BOOLEAN_TO_JSVAL(ret));
return JS_TRUE; return JS_TRUE;
} }
JS_SET_RVAL(cx, vp, JSVAL_TRUE); JS_SET_RVAL(cx, vp, JSVAL_TRUE);
return JS_TRUE; return JS_TRUE;
} }
JSBool S_CCMenuItem::jsinit(JSContext *cx, uint32_t argc, jsval *vp) { JSBool S_CCMenuItem::jsinit(JSContext *cx, uint32_t argc, jsval *vp) {
JSObject* obj = (JSObject *)JS_THIS_OBJECT(cx, vp); JSObject* obj = (JSObject *)JS_THIS_OBJECT(cx, vp);
S_CCMenuItem* self = NULL; JSGET_PTRSHELL(S_CCMenuItem, self, obj); S_CCMenuItem* self = NULL; JSGET_PTRSHELL(S_CCMenuItem, self, obj);
if (self == NULL) return JS_FALSE; if (self == NULL) return JS_FALSE;
if (argc == 0) { if (argc == 0) {
bool ret = self->initWithTarget(self, menu_selector(S_CCMenuItem::menuAction)); bool ret = self->initWithTarget(self, menu_selector(S_CCMenuItem::menuAction));
JS_SET_RVAL(cx, vp, BOOLEAN_TO_JSVAL(ret)); JS_SET_RVAL(cx, vp, BOOLEAN_TO_JSVAL(ret));
return JS_TRUE; return JS_TRUE;
} }
JS_SET_RVAL(cx, vp, JSVAL_TRUE); JS_SET_RVAL(cx, vp, JSVAL_TRUE);
return JS_TRUE; return JS_TRUE;
} }
JSBool S_CCRenderTexture::jsrenderTextureWithWidthAndHeight(JSContext *cx, uint32_t argc, jsval *vp) { JSBool S_CCRenderTexture::jsrenderTextureWithWidthAndHeight(JSContext *cx, uint32_t argc, jsval *vp) {
if (argc == 2) { if (argc == 2) {
int arg0; int arg0;
int arg1; int arg1;
JS_ConvertArguments(cx, 2, JS_ARGV(cx, vp), "ii", &arg0, &arg1); JS_ConvertArguments(cx, 2, JS_ARGV(cx, vp), "ii", &arg0, &arg1);
CCRenderTexture* ret = CCRenderTexture::renderTextureWithWidthAndHeight(arg0, arg1); CCRenderTexture* ret = CCRenderTexture::renderTextureWithWidthAndHeight(arg0, arg1);
do { do {
JSObject *tmp = JS_NewObject(cx, S_CCRenderTexture::jsClass, S_CCRenderTexture::jsObject, NULL); JSObject *tmp = JS_NewObject(cx, S_CCRenderTexture::jsClass, S_CCRenderTexture::jsObject, NULL);
pointerShell_t *pt = (pointerShell_t *)JS_malloc(cx, sizeof(pointerShell_t)); pointerShell_t *pt = (pointerShell_t *)JS_malloc(cx, sizeof(pointerShell_t));
pt->flags = kPointerTemporary; pt->flags = kPointerTemporary;
pt->data = (void *)ret; pt->data = (void *)ret;
JS_SetPrivate(tmp, pt); JS_SetPrivate(tmp, pt);
JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(tmp)); JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(tmp));
} while (0); } while (0);
return JS_TRUE; return JS_TRUE;
} }
JS_SET_RVAL(cx, vp, JSVAL_TRUE); JS_SET_RVAL(cx, vp, JSVAL_TRUE);
return JS_TRUE; return JS_TRUE;
} }
JSBool S_CCRenderTexture::jsinitWithWidthAndHeight(JSContext *cx, uint32_t argc, jsval *vp) { JSBool S_CCRenderTexture::jsinitWithWidthAndHeight(JSContext *cx, uint32_t argc, jsval *vp) {
JSObject* obj = (JSObject *)JS_THIS_OBJECT(cx, vp); JSObject* obj = (JSObject *)JS_THIS_OBJECT(cx, vp);
S_CCRenderTexture* self = NULL; JSGET_PTRSHELL(S_CCRenderTexture, self, obj); S_CCRenderTexture* self = NULL; JSGET_PTRSHELL(S_CCRenderTexture, self, obj);
if (self == NULL) return JS_FALSE; if (self == NULL) return JS_FALSE;
if (argc == 2) { if (argc == 2) {
int arg0; int arg0;
int arg1; int arg1;
JS_ConvertArguments(cx, 2, JS_ARGV(cx, vp), "ii", &arg0, &arg1); JS_ConvertArguments(cx, 2, JS_ARGV(cx, vp), "ii", &arg0, &arg1);
bool ret = self->initWithWidthAndHeight(arg0, arg1, kCCTexture2DPixelFormat_RGBA8888); bool ret = self->initWithWidthAndHeight(arg0, arg1, kCCTexture2DPixelFormat_RGBA8888);
JS_SET_RVAL(cx, vp, BOOLEAN_TO_JSVAL(ret)); JS_SET_RVAL(cx, vp, BOOLEAN_TO_JSVAL(ret));
return JS_TRUE; return JS_TRUE;
} }
JS_SET_RVAL(cx, vp, JSVAL_TRUE); JS_SET_RVAL(cx, vp, JSVAL_TRUE);
return JS_TRUE; return JS_TRUE;
} }
JSBool S_CCMenuItemLabel::jsitemWithLabel(JSContext *cx, uint32_t argc, jsval *vp) { JSBool S_CCMenuItemLabel::jsitemWithLabel(JSContext *cx, uint32_t argc, jsval *vp) {
JSObject* obj = (JSObject *)JS_THIS_OBJECT(cx, vp); JSObject* obj = (JSObject *)JS_THIS_OBJECT(cx, vp);
S_CCRenderTexture* self = NULL; JSGET_PTRSHELL(S_CCRenderTexture, self, obj); S_CCRenderTexture* self = NULL; JSGET_PTRSHELL(S_CCRenderTexture, self, obj);
if (self == NULL) return JS_FALSE; if (self == NULL) return JS_FALSE;
if (argc == 1) { if (argc == 1) {
JSObject *arg0; JSObject *arg0;
JS_ConvertArguments(cx, 1, JS_ARGV(cx, vp), "o", &arg0); JS_ConvertArguments(cx, 1, JS_ARGV(cx, vp), "o", &arg0);
CCNode* narg0; JSGET_PTRSHELL(CCNode, narg0, arg0); CCNode* narg0; JSGET_PTRSHELL(CCNode, narg0, arg0);
CCMenuItemLabel *ret = CCMenuItemLabel::itemWithLabel(narg0, self, menu_selector(S_CCMenuItemLabel::menuAction)); CCMenuItemLabel *ret = CCMenuItemLabel::itemWithLabel(narg0, self, menu_selector(S_CCMenuItemLabel::menuAction));
if (ret == NULL) { if (ret == NULL) {
JS_SET_RVAL(cx, vp, JSVAL_NULL); JS_SET_RVAL(cx, vp, JSVAL_NULL);
return JS_TRUE; return JS_TRUE;
} }
do { do {
JSObject *tmp = JS_NewObject(cx, S_CCMenuItemLabel::jsClass, S_CCMenuItemLabel::jsObject, NULL); JSObject *tmp = JS_NewObject(cx, S_CCMenuItemLabel::jsClass, S_CCMenuItemLabel::jsObject, NULL);
pointerShell_t *pt = (pointerShell_t *)JS_malloc(cx, sizeof(pointerShell_t)); pointerShell_t *pt = (pointerShell_t *)JS_malloc(cx, sizeof(pointerShell_t));
pt->flags = kPointerTemporary; pt->flags = kPointerTemporary;
pt->data = (void *)ret; pt->data = (void *)ret;
JS_SetPrivate(tmp, pt); JS_SetPrivate(tmp, pt);
JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(tmp)); JS_SET_RVAL(cx, vp, OBJECT_TO_JSVAL(tmp));
} while(0); } while(0);
return JS_TRUE; return JS_TRUE;
} }
JS_SET_RVAL(cx, vp, JSVAL_TRUE); JS_SET_RVAL(cx, vp, JSVAL_TRUE);
return JS_TRUE; return JS_TRUE;
} }
JSBool S_CCMenuItemLabel::jsinitWithLabel(JSContext *cx, uint32_t argc, jsval *vp) { JSBool S_CCMenuItemLabel::jsinitWithLabel(JSContext *cx, uint32_t argc, jsval *vp) {
JSObject* obj = (JSObject *)JS_THIS_OBJECT(cx, vp); JSObject* obj = (JSObject *)JS_THIS_OBJECT(cx, vp);
S_CCMenuItemLabel* self = NULL; JSGET_PTRSHELL(S_CCMenuItemLabel, self, obj); S_CCMenuItemLabel* self = NULL; JSGET_PTRSHELL(S_CCMenuItemLabel, self, obj);
if (self == NULL) return JS_FALSE; if (self == NULL) return JS_FALSE;
if (argc == 1) { if (argc == 1) {
JSObject *arg0; JSObject *arg0;
JS_ConvertArguments(cx, 1, JS_ARGV(cx, vp), "o", &arg0); JS_ConvertArguments(cx, 1, JS_ARGV(cx, vp), "o", &arg0);
CCNode* narg0; JSGET_PTRSHELL(CCNode, narg0, arg0); CCNode* narg0; JSGET_PTRSHELL(CCNode, narg0, arg0);
bool ret = self->initWithLabel(narg0, self, menu_selector(S_CCMenuItemLabel::menuAction)); bool ret = self->initWithLabel(narg0, self, menu_selector(S_CCMenuItemLabel::menuAction));
JS_SET_RVAL(cx, vp, BOOLEAN_TO_JSVAL(ret)); JS_SET_RVAL(cx, vp, BOOLEAN_TO_JSVAL(ret));
return JS_TRUE; return JS_TRUE;
} }
JS_SET_RVAL(cx, vp, JSVAL_TRUE); JS_SET_RVAL(cx, vp, JSVAL_TRUE);
return JS_TRUE; return JS_TRUE;
} }
JSBool S_CCApplication::jsgetCurrentLanguage(JSContext *cx, uint32_t argc, jsval *vp) { JSBool S_CCApplication::jsgetCurrentLanguage(JSContext *cx, uint32_t argc, jsval *vp) {
JSObject* obj = (JSObject *)JS_THIS_OBJECT(cx, vp); JSObject* obj = (JSObject *)JS_THIS_OBJECT(cx, vp);
CCApplication* self = NULL; JSGET_PTRSHELL(CCApplication, self, obj); CCApplication* self = NULL; JSGET_PTRSHELL(CCApplication, self, obj);
if (self == NULL) return JS_FALSE; if (self == NULL) return JS_FALSE;
jsval result; JS_NewNumberValue(cx, self->getCurrentLanguage(), &result); jsval result; JS_NewNumberValue(cx, self->getCurrentLanguage(), &result);
JS_SET_RVAL(cx, vp, result); JS_SET_RVAL(cx, vp, result);
return JS_TRUE; return JS_TRUE;
} }
JSBool S_CCUserDefault::jsgetStringForKey(JSContext *cx, uint32_t argc, jsval *vp) { JSBool S_CCUserDefault::jsgetStringForKey(JSContext *cx, uint32_t argc, jsval *vp) {
JSObject* obj = (JSObject *)JS_THIS_OBJECT(cx, vp); JSObject* obj = (JSObject *)JS_THIS_OBJECT(cx, vp);
S_CCUserDefault* self = NULL; JSGET_PTRSHELL(S_CCUserDefault, self, obj); S_CCUserDefault* self = NULL; JSGET_PTRSHELL(S_CCUserDefault, self, obj);
if (self == NULL) return JS_FALSE; if (self == NULL) return JS_FALSE;
if (argc == 2) { if (argc == 2) {
JSString *arg0; JSString *arg0;
JSString *arg1; JSString *arg1;
JS_ConvertArguments(cx, 2, JS_ARGV(cx, vp), "SS", &arg0, &arg1); JS_ConvertArguments(cx, 2, JS_ARGV(cx, vp), "SS", &arg0, &arg1);
char *narg0 = JS_EncodeString(cx, arg0); char *narg0 = JS_EncodeString(cx, arg0);
std::string narg1(JS_EncodeString(cx, arg1)); std::string narg1(JS_EncodeString(cx, arg1));
std::string ret = self->getStringForKey(narg0, narg1); std::string ret = self->getStringForKey(narg0, narg1);
JSString *jsret = JS_NewStringCopyZ(cx, ret.c_str()); JSString *jsret = JS_NewStringCopyZ(cx, ret.c_str());
JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(jsret)); JS_SET_RVAL(cx, vp, STRING_TO_JSVAL(jsret));
return JS_TRUE; return JS_TRUE;
} }
JS_SET_RVAL(cx, vp, JSVAL_TRUE); JS_SET_RVAL(cx, vp, JSVAL_TRUE);
return JS_TRUE; return JS_TRUE;
} }
JSBool S_CCUserDefault::jssetStringForKey(JSContext *cx, uint32_t argc, jsval *vp) { JSBool S_CCUserDefault::jssetStringForKey(JSContext *cx, uint32_t argc, jsval *vp) {
JSObject* obj = (JSObject *)JS_THIS_OBJECT(cx, vp); JSObject* obj = (JSObject *)JS_THIS_OBJECT(cx, vp);
S_CCUserDefault* self = NULL; JSGET_PTRSHELL(S_CCUserDefault, self, obj); S_CCUserDefault* self = NULL; JSGET_PTRSHELL(S_CCUserDefault, self, obj);
if (self == NULL) return JS_FALSE; if (self == NULL) return JS_FALSE;
if (argc == 2) { if (argc == 2) {
JSString *arg0; JSString *arg0;
JSString *arg1; JSString *arg1;
JS_ConvertArguments(cx, 2, JS_ARGV(cx, vp), "SS", &arg0, &arg1); JS_ConvertArguments(cx, 2, JS_ARGV(cx, vp), "SS", &arg0, &arg1);
char *narg0 = JS_EncodeString(cx, arg0); char *narg0 = JS_EncodeString(cx, arg0);
std::string narg1(JS_EncodeString(cx, arg1)); std::string narg1(JS_EncodeString(cx, arg1));
self->setStringForKey(narg0, narg1); self->setStringForKey(narg0, narg1);
JS_SET_RVAL(cx, vp, JSVAL_TRUE); JS_SET_RVAL(cx, vp, JSVAL_TRUE);
return JS_TRUE; return JS_TRUE;
} }
JS_SET_RVAL(cx, vp, JSVAL_TRUE); JS_SET_RVAL(cx, vp, JSVAL_TRUE);
return JS_TRUE; return JS_TRUE;
} }

View File

@ -1 +1 @@
215941887bb3ecde65ca64e6e1b5ddaacded6a7c 5a1155c9dcd8585864efa8080d8fd42059f9ea52

View File

@ -7,40 +7,40 @@ LOCAL_MODULE_FILENAME := liblua
LOCAL_SRC_FILES :=../../lua/lapi.c \ LOCAL_SRC_FILES :=../../lua/lapi.c \
../../lua/lauxlib.c \ ../../lua/lauxlib.c \
../../lua/lbaselib.c \ ../../lua/lbaselib.c \
../../lua/lcode.c \ ../../lua/lcode.c \
../../lua/ldblib.c \ ../../lua/ldblib.c \
../../lua/ldebug.c \ ../../lua/ldebug.c \
../../lua/ldo.c \ ../../lua/ldo.c \
../../lua/ldump.c \ ../../lua/ldump.c \
../../lua/lfunc.c \ ../../lua/lfunc.c \
../../lua/lgc.c \ ../../lua/lgc.c \
../../lua/linit.c \ ../../lua/linit.c \
../../lua/liolib.c \ ../../lua/liolib.c \
../../lua/llex.c \ ../../lua/llex.c \
../../lua/lmathlib.c \ ../../lua/lmathlib.c \
../../lua/lmem.c \ ../../lua/lmem.c \
../../lua/loadlib.c \ ../../lua/loadlib.c \
../../lua/lobject.c \ ../../lua/lobject.c \
../../lua/lopcodes.c \ ../../lua/lopcodes.c \
../../lua/loslib.c \ ../../lua/loslib.c \
../../lua/lparser.c \ ../../lua/lparser.c \
../../lua/lstate.c \ ../../lua/lstate.c \
../../lua/lstring.c \ ../../lua/lstring.c \
../../lua/lstrlib.c \ ../../lua/lstrlib.c \
../../lua/ltable.c \ ../../lua/ltable.c \
../../lua/ltablib.c \ ../../lua/ltablib.c \
../../lua/ltm.c \ ../../lua/ltm.c \
../../lua/lua.c \ ../../lua/lua.c \
../../lua/lundump.c \ ../../lua/lundump.c \
../../lua/lvm.c \ ../../lua/lvm.c \
../../lua/lzio.c \ ../../lua/lzio.c \
../../lua/print.c \ ../../lua/print.c \
../../tolua/tolua_event.c \ ../../tolua/tolua_event.c \
../../tolua/tolua_is.c \ ../../tolua/tolua_is.c \
../../tolua/tolua_map.c \ ../../tolua/tolua_map.c \
../../tolua/tolua_push.c \ ../../tolua/tolua_push.c \
../../tolua/tolua_to.c ../../tolua/tolua_to.c
LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../../lua \ LOCAL_EXPORT_C_INCLUDES := $(LOCAL_PATH)/../../lua \
$(LOCAL_PATH)/../../tolua \ $(LOCAL_PATH)/../../tolua \

View File

@ -31,7 +31,7 @@ bool AppDelegate::applicationDidFinishLaunching()
CCDirector *pDirector = CCDirector::sharedDirector(); CCDirector *pDirector = CCDirector::sharedDirector();
pDirector->setOpenGLView(&CCEGLView::sharedOpenGLView()); pDirector->setOpenGLView(&CCEGLView::sharedOpenGLView());
// enable High Resource Mode(2x, such as iphone4) and maintains low resource on other devices. // enable High Resource Mode(2x, such as iphone4) and maintains low resource on other devices.
// pDirector->enableRetinaDisplay(true); // pDirector->enableRetinaDisplay(true);
// turn on display FPS // turn on display FPS
@ -52,7 +52,7 @@ bool AppDelegate::applicationDidFinishLaunching()
pEngine->executeString(pstrFileContent->getCString()); pEngine->executeString(pstrFileContent->getCString());
} }
#else #else
std::string path = CCFileUtils::fullPathFromRelativePath("hello.lua"); std::string path = CCFileUtils::fullPathFromRelativePath("hello.lua");
pEngine->addSearchPath(path.substr(0, path.find_last_of("/")).c_str()); pEngine->addSearchPath(path.substr(0, path.find_last_of("/")).c_str());
pEngine->executeScriptFile(path.c_str()); pEngine->executeScriptFile(path.c_str());
#endif #endif

View File

@ -4,7 +4,7 @@
#include "CCApplication.h" #include "CCApplication.h"
/** /**
@brief The cocos2d Application. @brief The cocos2d Application.
The reason for implement as private inheritance is to hide some interface call by CCDirector. The reason for implement as private inheritance is to hide some interface call by CCDirector.
*/ */
@ -15,7 +15,7 @@ public:
virtual ~AppDelegate(); virtual ~AppDelegate();
/** /**
@brief Implement CCDirector and CCScene init code here. @brief Implement CCDirector and CCScene init code here.
@return true Initialize success, app continue. @return true Initialize success, app continue.
@return false Initialize failed, app terminate. @return false Initialize failed, app terminate.
*/ */

View File

@ -8,12 +8,12 @@ USING_NS_CC;
// #define USE_WIN32_CONSOLE // #define USE_WIN32_CONSOLE
int APIENTRY _tWinMain(HINSTANCE hInstance, int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance, HINSTANCE hPrevInstance,
LPTSTR lpCmdLine, LPTSTR lpCmdLine,
int nCmdShow) int nCmdShow)
{ {
UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine); UNREFERENCED_PARAMETER(lpCmdLine);
#ifdef USE_WIN32_CONSOLE #ifdef USE_WIN32_CONSOLE
AllocConsole(); AllocConsole();
@ -22,13 +22,13 @@ int APIENTRY _tWinMain(HINSTANCE hInstance,
freopen("CONOUT$", "w", stderr); freopen("CONOUT$", "w", stderr);
#endif #endif
// create the application instance // create the application instance
AppDelegate app; AppDelegate app;
CCEGLView& eglView = CCEGLView::sharedOpenGLView(); CCEGLView& eglView = CCEGLView::sharedOpenGLView();
eglView.setViewName("Hello World"); eglView.setViewName("Hello World");
eglView.setFrameSize(480, 320); eglView.setFrameSize(480, 320);
// set the design resolution screen size, if you want to use Design Resoulution scaled to current screen, please uncomment next line. // set the design resolution screen size, if you want to use Design Resoulution scaled to current screen, please uncomment next line.
// eglView.setDesignResolutionSize(480, 320); // eglView.setDesignResolutionSize(480, 320);
int ret = CCApplication::sharedApplication().run(); int ret = CCApplication::sharedApplication().run();

View File

@ -10,4 +10,4 @@
// C RunTime Header Files // C RunTime Header Files
#include "CCStdC.h" #include "CCStdC.h"
#endif // __WINMAIN_H__ #endif // __WINMAIN_H__

View File

@ -4,19 +4,19 @@
// //
[!if WTL_COM_SERVER] [!if WTL_COM_SERVER]
#define IDS_PROJNAME 100 #define IDS_PROJNAME 100
#define IDR_[!output UPPERCASE_SAFE_PROJECT_NAME] 100 #define IDR_[!output UPPERCASE_SAFE_PROJECT_NAME] 100
[!endif] [!endif]
#define ID_FILE_NEW_WINDOW 32771 #define ID_FILE_NEW_WINDOW 32771
// Next default values for new objects // Next default values for new objects
// //
#ifdef APSTUDIO_INVOKED #ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS #ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 201 #define _APS_NEXT_RESOURCE_VALUE 201
#define _APS_NEXT_CONTROL_VALUE 1000 #define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 101 #define _APS_NEXT_SYMED_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 32775 #define _APS_NEXT_COMMAND_VALUE 32775
#endif #endif
#endif #endif

View File

@ -25,45 +25,45 @@ AppDelegate::~AppDelegate()
bool AppDelegate::applicationDidFinishLaunching() bool AppDelegate::applicationDidFinishLaunching()
{ {
// initialize director // initialize director
CCDirector *pDirector = CCDirector::sharedDirector(); CCDirector *pDirector = CCDirector::sharedDirector();
pDirector->setOpenGLView(&CCEGLView::sharedOpenGLView()); pDirector->setOpenGLView(&CCEGLView::sharedOpenGLView());
// enable High Resource Mode(2x, such as iphone4) and maintains low resource on other devices. // enable High Resource Mode(2x, such as iphone4) and maintains low resource on other devices.
// pDirector->enableRetinaDisplay(true); // pDirector->enableRetinaDisplay(true);
// sets landscape mode // sets landscape mode
// pDirector->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft); // pDirector->setDeviceOrientation(kCCDeviceOrientationLandscapeLeft);
// turn on display FPS // turn on display FPS
pDirector->setDisplayStats(true); pDirector->setDisplayStats(true);
// set FPS. the default value is 1.0/60 if you don't call this // set FPS. the default value is 1.0/60 if you don't call this
pDirector->setAnimationInterval(1.0 / 60); pDirector->setAnimationInterval(1.0 / 60);
// add our generated bindings // add our generated bindings
/* /*
JSContext *cx = ScriptingCore::getInstance().getGlobalContext(); JSContext *cx = ScriptingCore::getInstance().getGlobalContext();
JSObject *obj = JS_GetGlobalObject(cx); JSObject *obj = JS_GetGlobalObject(cx);
// since we pass the global object as the second argument, so these classes // since we pass the global object as the second argument, so these classes
// will also be "global" much like properties added to "window" or "document" // will also be "global" much like properties added to "window" or "document"
// in a browser // in a browser
S_SimpleNativeClass::jsCreateClass(cx, obj, "SimpleNativeClass"); S_SimpleNativeClass::jsCreateClass(cx, obj, "SimpleNativeClass");
S_AnotherClass::jsCreateClass(cx, obj, "AnotherClass"); S_AnotherClass::jsCreateClass(cx, obj, "AnotherClass");
register_enums_simple_native_generated(obj); register_enums_simple_native_generated(obj);
ScriptingCore::getInstance().runScript("Javascript/1to1/test_bindings.js"); ScriptingCore::getInstance().runScript("Javascript/1to1/test_bindings.js");
*/ */
// run the main script // run the main script
ScriptingCore::getInstance().runScript("JS/1to1/test_actions.js"); ScriptingCore::getInstance().runScript("JS/1to1/test_actions.js");
// ScriptingCore::getInstance().runScript("JS/1to1/test_ease_actions.js"); // ScriptingCore::getInstance().runScript("JS/1to1/test_ease_actions.js");
// ScriptingCore::getInstance().runScript("JS/1to1/test_particles.js"); // ScriptingCore::getInstance().runScript("JS/1to1/test_particles.js");
// ScriptingCore::getInstance().runScript("JS/1to1/test_layer.js"); // ScriptingCore::getInstance().runScript("JS/1to1/test_layer.js");
// ScriptingCore::getInstance().runScript("JS/1to1/test_sound.js"); // ScriptingCore::getInstance().runScript("JS/1to1/test_sound.js");
// ScriptingCore::getInstance().runScript("JS/1to1/test_transitions.js"); // ScriptingCore::getInstance().runScript("JS/1to1/test_transitions.js");
// ScriptingCore::getInstance().runScript("JS/1to1/test_require.js"); // ScriptingCore::getInstance().runScript("JS/1to1/test_require.js");
return true; return true;
} }
// This function will be called when the app is inactive. When comes a phone call,it's be invoked too // This function will be called when the app is inactive. When comes a phone call,it's be invoked too
@ -71,8 +71,8 @@ void AppDelegate::applicationDidEnterBackground()
{ {
CCDirector::sharedDirector()->pause(); CCDirector::sharedDirector()->pause();
// if you use SimpleAudioEngine, it must be pause // if you use SimpleAudioEngine, it must be pause
// SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic(); // SimpleAudioEngine::sharedEngine()->pauseBackgroundMusic();
} }
// this function will be called when the app is active again // this function will be called when the app is active again
@ -80,6 +80,6 @@ void AppDelegate::applicationWillEnterForeground()
{ {
CCDirector::sharedDirector()->resume(); CCDirector::sharedDirector()->resume();
// if you use SimpleAudioEngine, it must resume here // if you use SimpleAudioEngine, it must resume here
// SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic(); // SimpleAudioEngine::sharedEngine()->resumeBackgroundMusic();
} }

View File

@ -13,18 +13,18 @@
#include "ScriptingCore.h" #include "ScriptingCore.h"
/** /**
@brief The cocos2d Application. @brief The cocos2d Application.
The reason for implement as private inheritance is to hide some interface call by CCDirector. The reason for implement as private inheritance is to hide some interface call by CCDirector.
*/ */
class AppDelegate : private cocos2d::CCApplication class AppDelegate : private cocos2d::CCApplication
{ {
public: public:
AppDelegate(); AppDelegate();
virtual ~AppDelegate(); virtual ~AppDelegate();
/** /**
@brief Implement CCDirector and CCScene init code here. @brief Implement CCDirector and CCScene init code here.
@return true Initialize success, app continue. @return true Initialize success, app continue.
@return false Initialize failed, app terminate. @return false Initialize failed, app terminate.
*/ */

View File

@ -7,10 +7,10 @@
SimpleNativeClass::SimpleNativeClass() SimpleNativeClass::SimpleNativeClass()
{ {
// just set some fields // just set some fields
m_someField = 0; m_someField = 0;
m_someOtherField = 10; m_someOtherField = 10;
m_anotherMoreComplexField = NULL; m_anotherMoreComplexField = NULL;
} }
// empty destructor // empty destructor
@ -21,25 +21,25 @@ SimpleNativeClass::~SimpleNativeClass()
// just a very simple function :) // just a very simple function :)
int SimpleNativeClass::doSomeProcessing(std::string arg1, std::string arg2) int SimpleNativeClass::doSomeProcessing(std::string arg1, std::string arg2)
{ {
return arg1.length() + arg2.length(); return arg1.length() + arg2.length();
} }
void SimpleNativeClass::setAnotherMoreComplexField(const char *str) void SimpleNativeClass::setAnotherMoreComplexField(const char *str)
{ {
if (m_anotherMoreComplexField) { if (m_anotherMoreComplexField) {
free(m_anotherMoreComplexField); free(m_anotherMoreComplexField);
} }
size_t len = strlen(str); size_t len = strlen(str);
m_anotherMoreComplexField = (char *)malloc(len); m_anotherMoreComplexField = (char *)malloc(len);
memcpy(m_anotherMoreComplexField, str, len); memcpy(m_anotherMoreComplexField, str, len);
} }
namespace SomeNamespace namespace SomeNamespace
{ {
AnotherClass::AnotherClass() AnotherClass::AnotherClass()
{ {
justOneField = 1313; justOneField = 1313;
aPublicField = 1337; aPublicField = 1337;
} }
// empty destructor // empty destructor
AnotherClass::~AnotherClass() AnotherClass::~AnotherClass()
@ -47,6 +47,6 @@ AnotherClass::~AnotherClass()
} }
void AnotherClass::doSomethingSimple() { void AnotherClass::doSomethingSimple() {
fprintf(stderr, "just doing something simple\n"); fprintf(stderr, "just doing something simple\n");
} }
}; };

View File

@ -6,57 +6,57 @@
class SimpleNativeClass class SimpleNativeClass
{ {
protected: protected:
int m_someField; int m_someField;
int m_someOtherField; int m_someOtherField;
char* m_anotherMoreComplexField; char* m_anotherMoreComplexField;
public: public:
SimpleNativeClass(); SimpleNativeClass();
~SimpleNativeClass(); ~SimpleNativeClass();
// these methods are simple, can be defined inline // these methods are simple, can be defined inline
int getSomeField() { int getSomeField() {
return m_someField; return m_someField;
}; };
int getSomeOtherField() { int getSomeOtherField() {
return m_someOtherField; return m_someOtherField;
}; };
char *getAnotherMoreComplexField() { char *getAnotherMoreComplexField() {
return m_anotherMoreComplexField; return m_anotherMoreComplexField;
} }
void setSomeField(int f) { void setSomeField(int f) {
m_someField = f; m_someField = f;
} }
void setSomeOtherField(int f) { void setSomeOtherField(int f) {
m_someOtherField = f; m_someOtherField = f;
} }
void setAnotherMoreComplexField(const char *str); void setAnotherMoreComplexField(const char *str);
// std::string not working yet! // std::string not working yet!
int doSomeProcessing(std::string arg1, std::string arg2); int doSomeProcessing(std::string arg1, std::string arg2);
}; };
namespace SomeNamespace { namespace SomeNamespace {
class AnotherClass { class AnotherClass {
protected: protected:
int justOneField; int justOneField;
public: public:
int aPublicField; int aPublicField;
AnotherClass(); AnotherClass();
~AnotherClass(); ~AnotherClass();
// also simple methods, can be defined inline // also simple methods, can be defined inline
int getJustOneField() { int getJustOneField() {
return justOneField; return justOneField;
} }
// wrong setter - won't work (needs ONLY one parameter in order to work) // wrong setter - won't work (needs ONLY one parameter in order to work)
void setJustOneField() { void setJustOneField() {
justOneField = 999; justOneField = 999;
} }
void doSomethingSimple(); void doSomethingSimple();
}; };
}; };

View File

@ -10,7 +10,7 @@
@interface AppController : NSObject <UIAccelerometerDelegate, UIAlertViewDelegate, UITextFieldDelegate,UIApplicationDelegate> { @interface AppController : NSObject <UIAccelerometerDelegate, UIAlertViewDelegate, UITextFieldDelegate,UIApplicationDelegate> {
UIWindow *window; UIWindow *window;
RootViewController *viewController; RootViewController *viewController;
} }
@end @end

View File

@ -56,14 +56,14 @@ static AppDelegate s_sharedApplication;
Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state. Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game. Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
*/ */
cocos2d::CCDirector::sharedDirector()->pause(); cocos2d::CCDirector::sharedDirector()->pause();
} }
- (void)applicationDidBecomeActive:(UIApplication *)application { - (void)applicationDidBecomeActive:(UIApplication *)application {
/* /*
Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface. Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
*/ */
cocos2d::CCDirector::sharedDirector()->resume(); cocos2d::CCDirector::sharedDirector()->resume();
} }
- (void)applicationDidEnterBackground:(UIApplication *)application { - (void)applicationDidEnterBackground:(UIApplication *)application {

View File

@ -36,10 +36,10 @@
*/ */
// Override to allow orientations other than the default landscape orientation. // Override to allow orientations other than the default landscape orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation { - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
return UIInterfaceOrientationIsLandscape( interfaceOrientation ); return UIInterfaceOrientationIsLandscape( interfaceOrientation );
// switch to this line if you want to set portrait view // switch to this line if you want to set portrait view
// return UIInterfaceOrientationIsPortrait( interfaceOrientation ); // return UIInterfaceOrientationIsPortrait( interfaceOrientation );
} }
- (void)didReceiveMemoryWarning { - (void)didReceiveMemoryWarning {

View File

@ -8,12 +8,12 @@ USING_NS_CC;
// #define USE_WIN32_CONSOLE // #define USE_WIN32_CONSOLE
int APIENTRY _tWinMain(HINSTANCE hInstance, int APIENTRY _tWinMain(HINSTANCE hInstance,
HINSTANCE hPrevInstance, HINSTANCE hPrevInstance,
LPTSTR lpCmdLine, LPTSTR lpCmdLine,
int nCmdShow) int nCmdShow)
{ {
UNREFERENCED_PARAMETER(hPrevInstance); UNREFERENCED_PARAMETER(hPrevInstance);
UNREFERENCED_PARAMETER(lpCmdLine); UNREFERENCED_PARAMETER(lpCmdLine);
#ifdef USE_WIN32_CONSOLE #ifdef USE_WIN32_CONSOLE
AllocConsole(); AllocConsole();
@ -22,13 +22,13 @@ int APIENTRY _tWinMain(HINSTANCE hInstance,
freopen("CONOUT$", "w", stderr); freopen("CONOUT$", "w", stderr);
#endif #endif
// create the application instance // create the application instance
AppDelegate app; AppDelegate app;
CCEGLView& eglView = CCEGLView::sharedOpenGLView(); CCEGLView& eglView = CCEGLView::sharedOpenGLView();
eglView.setViewName("Hello World"); eglView.setViewName("Hello World");
eglView.setFrameSize(480, 320); eglView.setFrameSize(480, 320);
// set the design resolution screen size, if you want to use Design Resoulution scaled to current screen, please uncomment next line. // set the design resolution screen size, if you want to use Design Resoulution scaled to current screen, please uncomment next line.
// eglView.setDesignResolutionSize(480, 320); // eglView.setDesignResolutionSize(480, 320);
int ret = CCApplication::sharedApplication().run(); int ret = CCApplication::sharedApplication().run();

View File

@ -10,4 +10,4 @@
// C RunTime Header Files // C RunTime Header Files
#include "CCStdC.h" #include "CCStdC.h"
#endif // __WINMAIN_H__ #endif // __WINMAIN_H__

View File

@ -3,18 +3,18 @@
// Used by testjs.RC // Used by testjs.RC
// //
#define IDS_PROJNAME 100 #define IDS_PROJNAME 100
#define IDR_TESTJS 100 #define IDR_TESTJS 100
#define ID_FILE_NEW_WINDOW 32771 #define ID_FILE_NEW_WINDOW 32771
// Next default values for new objects // Next default values for new objects
// //
#ifdef APSTUDIO_INVOKED #ifdef APSTUDIO_INVOKED
#ifndef APSTUDIO_READONLY_SYMBOLS #ifndef APSTUDIO_READONLY_SYMBOLS
#define _APS_NEXT_RESOURCE_VALUE 201 #define _APS_NEXT_RESOURCE_VALUE 201
#define _APS_NEXT_CONTROL_VALUE 1000 #define _APS_NEXT_CONTROL_VALUE 1000
#define _APS_NEXT_SYMED_VALUE 101 #define _APS_NEXT_SYMED_VALUE 101
#define _APS_NEXT_COMMAND_VALUE 32775 #define _APS_NEXT_COMMAND_VALUE 32775
#endif #endif
#endif #endif

View File

@ -36,7 +36,7 @@ void CocosBuilderTestScene::runThisTest()
HelloCocosBuilder::createInstance); HelloCocosBuilder::createInstance);
CCNode* node = CCBReader::nodeGraphFromFile("CocosBuilder_v2/example_relativeposition.ccb"); CCNode* node = CCBReader::nodeGraphFromFile("CocosBuilder_v2/example_relativeposition.ccb");
this->addChild(node) ; this->addChild(node) ;
CCDirector::sharedDirector()->replaceScene(this); CCDirector::sharedDirector()->replaceScene(this);
} }

View File

@ -5,7 +5,7 @@ subdirs := $(addprefix $(LOCAL_PATH)/../../../,$(addsuffix /Android.mk, \
cocos2dx \ cocos2dx \
CocosDenshion/android \ CocosDenshion/android \
lua/proj.android/jni \ lua/proj.android/jni \
)) ))
subdirs += $(LOCAL_PATH)/LuaProjectTemplate/Android.mk subdirs += $(LOCAL_PATH)/LuaProjectTemplate/Android.mk
include $(subdirs) include $(subdirs)

View File

@ -25,9 +25,9 @@ LOCAL_C_INCLUDES := $(LOCAL_PATH)/../../../../cocos2dx \
# because the new Windows toolchain doesn't support Cygwin's drive # because the new Windows toolchain doesn't support Cygwin's drive
# mapping (i.e /cygdrive/c/ instead of C:/) # mapping (i.e /cygdrive/c/ instead of C:/)
LOCAL_LDLIBS := -L$(call host-path, $(LOCAL_PATH)/../../libs/armeabi) \ LOCAL_LDLIBS := -L$(call host-path, $(LOCAL_PATH)/../../libs/armeabi) \
-L$(call host-path, $(LOCAL_PATH)/../../../../cocos2dx/platform/third_party/android/libraries) -lcurl \ -L$(call host-path, $(LOCAL_PATH)/../../../../cocos2dx/platform/third_party/android/libraries) -lcurl \
-lcocos2d \ -lcocos2d \
-lcocosdenshion \ -lcocosdenshion \
-llua -llua
include $(BUILD_SHARED_LIBRARY) include $(BUILD_SHARED_LIBRARY)