2012-04-19 14:35:52 +08:00
|
|
|
/****************************************************************************
|
2012-06-08 14:11:48 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
2012-04-19 14:35:52 +08:00
|
|
|
Copyright (c) 2010 Ricardo Quesada
|
|
|
|
|
|
|
|
http://www.cocos2d-x.org
|
|
|
|
|
|
|
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
of this software and associated documentation files (the "Software"), to deal
|
|
|
|
in the Software without restriction, including without limitation the rights
|
|
|
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
copies of the Software, and to permit persons to whom the Software is
|
|
|
|
furnished to do so, subject to the following conditions:
|
|
|
|
|
|
|
|
The above copyright notice and this permission notice shall be included in
|
|
|
|
all copies or substantial portions of the Software.
|
|
|
|
|
|
|
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
THE SOFTWARE.
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "CCConfiguration.h"
|
|
|
|
#include "ccMacros.h"
|
|
|
|
#include "ccConfig.h"
|
|
|
|
#include <string.h>
|
2013-05-23 04:00:34 +08:00
|
|
|
#include "cocoa/CCDictionary.h"
|
|
|
|
#include "cocoa/CCInteger.h"
|
|
|
|
#include "cocoa/CCBool.h"
|
|
|
|
#include "cocos2d.h"
|
2013-05-23 09:11:37 +08:00
|
|
|
#include "platform/CCFileUtils.h"
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
using namespace std;
|
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2013-05-23 04:00:34 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Configuration* Configuration::s_gSharedConfiguration = NULL;
|
2012-04-20 11:39:12 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Configuration::Configuration(void)
|
2013-06-15 14:03:30 +08:00
|
|
|
: _maxTextureSize(0)
|
|
|
|
, _maxModelviewStackDepth(0)
|
|
|
|
, _supportsPVRTC(false)
|
2013-07-01 17:40:57 +08:00
|
|
|
, _supportsETC(false)
|
2013-08-06 11:19:45 +08:00
|
|
|
, _supportsS3TC(false)
|
2013-06-15 14:03:30 +08:00
|
|
|
, _supportsNPOT(false)
|
|
|
|
, _supportsBGRA8888(false)
|
|
|
|
, _supportsDiscardFramebuffer(false)
|
|
|
|
, _supportsShareableVAO(false)
|
|
|
|
, _maxSamplesAllowed(0)
|
|
|
|
, _maxTextureUnits(0)
|
|
|
|
, _glExtensions(NULL)
|
|
|
|
, _valueDict(NULL)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool Configuration::init(void)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
_valueDict = Dictionary::create();
|
2013-06-15 14:03:30 +08:00
|
|
|
_valueDict->retain();
|
2013-05-23 04:00:34 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
_valueDict->setObject( String::create( cocos2dVersion() ), "cocos2d.x.version");
|
2013-05-23 04:00:34 +08:00
|
|
|
|
|
|
|
|
|
|
|
#if CC_ENABLE_PROFILERS
|
2013-06-20 14:13:12 +08:00
|
|
|
_valueDict->setObject( Bool::create(true), "cocos2d.x.compiled_with_profiler");
|
2013-05-23 04:00:34 +08:00
|
|
|
#else
|
2013-06-20 14:13:12 +08:00
|
|
|
_valueDict->setObject( Bool::create(false), "cocos2d.x.compiled_with_profiler");
|
2013-05-23 04:00:34 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CC_ENABLE_GL_STATE_CACHE == 0
|
2013-06-20 14:13:12 +08:00
|
|
|
_valueDict->setObject( Bool::create(false), "cocos2d.x.compiled_with_gl_state_cache");
|
2013-05-23 04:00:34 +08:00
|
|
|
#else
|
2013-06-20 14:13:12 +08:00
|
|
|
_valueDict->setObject( Bool::create(true), "cocos2d.x.compiled_with_gl_state_cache");
|
2013-05-23 04:00:34 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Configuration::~Configuration(void)
|
2013-05-23 04:00:34 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_valueDict->release();
|
2013-05-23 04:00:34 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Configuration::dumpInfo(void) const
|
2013-05-23 04:00:34 +08:00
|
|
|
{
|
|
|
|
// Dump
|
2013-06-20 14:13:12 +08:00
|
|
|
PrettyPrinter visitor(0);
|
2013-06-15 14:03:30 +08:00
|
|
|
_valueDict->acceptVisitor(visitor);
|
2013-05-23 04:00:34 +08:00
|
|
|
|
|
|
|
CCLOG("%s", visitor.getResult().c_str());
|
|
|
|
|
|
|
|
|
|
|
|
// And Dump some warnings as well
|
|
|
|
#if CC_ENABLE_PROFILERS
|
|
|
|
CCLOG("cocos2d: **** WARNING **** CC_ENABLE_PROFILERS is defined. Disable it when you finish profiling (from ccConfig.h)");
|
|
|
|
printf("\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CC_ENABLE_GL_STATE_CACHE == 0
|
|
|
|
CCLOG("");
|
|
|
|
CCLOG("cocos2d: **** WARNING **** CC_ENABLE_GL_STATE_CACHE is disabled. To improve performance, enable it (from ccConfig.h)");
|
|
|
|
printf("\n");
|
|
|
|
#endif
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Configuration::gatherGPUInfo()
|
2013-05-23 04:00:34 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
_valueDict->setObject( String::create( (const char*)glGetString(GL_VENDOR)), "gl.vendor");
|
|
|
|
_valueDict->setObject( String::create( (const char*)glGetString(GL_RENDERER)), "gl.renderer");
|
|
|
|
_valueDict->setObject( String::create( (const char*)glGetString(GL_VERSION)), "gl.version");
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_glExtensions = (char *)glGetString(GL_EXTENSIONS);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &_maxTextureSize);
|
2013-06-20 14:13:12 +08:00
|
|
|
_valueDict->setObject( Integer::create((int)_maxTextureSize), "gl.max_texture_size");
|
2013-05-23 04:00:34 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &_maxTextureUnits);
|
2013-06-20 14:13:12 +08:00
|
|
|
_valueDict->setObject( Integer::create((int)_maxTextureUnits), "gl.max_texture_units");
|
2013-05-23 04:00:34 +08:00
|
|
|
|
2012-04-20 15:12:20 +08:00
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
2013-06-15 14:03:30 +08:00
|
|
|
glGetIntegerv(GL_MAX_SAMPLES_APPLE, &_maxSamplesAllowed);
|
2013-06-20 14:13:12 +08:00
|
|
|
_valueDict->setObject( Integer::create((int)_maxSamplesAllowed), "gl.max_samples_allowed");
|
2012-04-20 15:12:20 +08:00
|
|
|
#endif
|
2013-07-01 17:40:57 +08:00
|
|
|
|
|
|
|
_supportsETC = checkForGLExtension("GL_OES_compressed_ETC1_RGB8_texture");
|
|
|
|
_valueDict->setObject( Bool::create(_supportsETC), "gl.supports_ETC");
|
|
|
|
|
2013-08-06 11:19:45 +08:00
|
|
|
_supportsS3TC = checkForGLExtension("GL_EXT_texture_compression_s3tc");
|
|
|
|
_valueDict->setObject( Bool::create(_supportsS3TC), "gl.supports_S3TC");
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_supportsPVRTC = checkForGLExtension("GL_IMG_texture_compression_pvrtc");
|
2013-06-20 14:13:12 +08:00
|
|
|
_valueDict->setObject( Bool::create(_supportsPVRTC), "gl.supports_PVRTC");
|
2013-05-23 04:00:34 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_supportsNPOT = true;
|
2013-06-20 14:13:12 +08:00
|
|
|
_valueDict->setObject( Bool::create(_supportsNPOT), "gl.supports_NPOT");
|
2013-05-23 04:00:34 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_supportsBGRA8888 = checkForGLExtension("GL_IMG_texture_format_BGRA888");
|
2013-06-20 14:13:12 +08:00
|
|
|
_valueDict->setObject( Bool::create(_supportsBGRA8888), "gl.supports_BGRA8888");
|
2013-05-23 04:00:34 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_supportsDiscardFramebuffer = checkForGLExtension("GL_EXT_discard_framebuffer");
|
2013-06-20 14:13:12 +08:00
|
|
|
_valueDict->setObject( Bool::create(_supportsDiscardFramebuffer), "gl.supports_discard_framebuffer");
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_supportsShareableVAO = checkForGLExtension("vertex_array_object");
|
2013-06-20 14:13:12 +08:00
|
|
|
_valueDict->setObject( Bool::create(_supportsShareableVAO), "gl.supports_vertex_array_object");
|
2012-04-20 11:39:12 +08:00
|
|
|
|
|
|
|
CHECK_GL_ERROR_DEBUG();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
Configuration* Configuration::getInstance()
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2012-04-20 11:39:12 +08:00
|
|
|
if (! s_gSharedConfiguration)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
s_gSharedConfiguration = new Configuration();
|
2012-04-20 11:39:12 +08:00
|
|
|
s_gSharedConfiguration->init();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2012-04-20 11:39:12 +08:00
|
|
|
return s_gSharedConfiguration;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
void Configuration::destroyInstance()
|
2012-05-23 12:11:53 +08:00
|
|
|
{
|
|
|
|
CC_SAFE_RELEASE_NULL(s_gSharedConfiguration);
|
|
|
|
}
|
|
|
|
|
2013-07-12 06:24:23 +08:00
|
|
|
// XXX: deprecated
|
|
|
|
Configuration* Configuration::sharedConfiguration(void)
|
|
|
|
{
|
|
|
|
return Configuration::getInstance();
|
|
|
|
}
|
|
|
|
|
|
|
|
// XXX: deprecated
|
|
|
|
void Configuration::purgeConfiguration(void)
|
|
|
|
{
|
|
|
|
Configuration::destroyInstance();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool Configuration::checkForGLExtension(const string &searchName) const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
bool bRet = false;
|
|
|
|
const char *kSearchName = searchName.c_str();
|
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
if (_glExtensions &&
|
|
|
|
strstr(_glExtensions, kSearchName))
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
|
|
|
bRet = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return bRet;
|
|
|
|
}
|
|
|
|
|
2013-05-23 04:00:34 +08:00
|
|
|
//
|
|
|
|
// getters for specific variables.
|
|
|
|
// Mantained for backward compatiblity reasons only.
|
|
|
|
//
|
2013-06-20 14:13:12 +08:00
|
|
|
int Configuration::getMaxTextureSize(void) const
|
2013-05-23 04:00:34 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _maxTextureSize;
|
2013-05-23 04:00:34 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
int Configuration::getMaxModelviewStackDepth(void) const
|
2013-05-23 04:00:34 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _maxModelviewStackDepth;
|
2013-05-23 04:00:34 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
int Configuration::getMaxTextureUnits(void) const
|
2013-05-23 04:00:34 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _maxTextureUnits;
|
2013-05-23 04:00:34 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool Configuration::supportsNPOT(void) const
|
2013-05-23 04:00:34 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _supportsNPOT;
|
2013-05-23 04:00:34 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool Configuration::supportsPVRTC(void) const
|
2013-05-23 04:00:34 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _supportsPVRTC;
|
2013-05-23 04:00:34 +08:00
|
|
|
}
|
|
|
|
|
2013-07-01 17:40:57 +08:00
|
|
|
bool Configuration::supportsETC() const
|
|
|
|
{
|
2013-07-02 15:36:47 +08:00
|
|
|
//GL_ETC1_RGB8_OES is not defined in old opengl version
|
|
|
|
#ifdef GL_ETC1_RGB8_OES
|
2013-07-01 17:40:57 +08:00
|
|
|
return _supportsETC;
|
2013-07-02 15:36:47 +08:00
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
2013-07-01 17:40:57 +08:00
|
|
|
}
|
|
|
|
|
2013-08-06 11:19:45 +08:00
|
|
|
bool Configuration::supportsS3TC() const
|
|
|
|
{
|
|
|
|
return _supportsS3TC;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool Configuration::supportsBGRA8888(void) const
|
2013-05-23 04:00:34 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _supportsBGRA8888;
|
2013-05-23 04:00:34 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool Configuration::supportsDiscardFramebuffer(void) const
|
2013-05-23 04:00:34 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _supportsDiscardFramebuffer;
|
2013-05-23 04:00:34 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
bool Configuration::supportsShareableVAO(void) const
|
2013-05-23 04:00:34 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _supportsShareableVAO;
|
2013-05-23 04:00:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
//
|
|
|
|
// generic getters for properties
|
|
|
|
//
|
2013-06-20 14:13:12 +08:00
|
|
|
const char *Configuration::getCString( const char *key, const char *default_value ) const
|
2013-05-23 04:00:34 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
Object *ret = _valueDict->objectForKey(key);
|
2013-05-23 08:03:00 +08:00
|
|
|
if( ret ) {
|
2013-06-20 14:13:12 +08:00
|
|
|
if( String *str=dynamic_cast<String*>(ret) )
|
2013-05-23 04:00:34 +08:00
|
|
|
return str->getCString();
|
|
|
|
|
2013-07-20 13:01:27 +08:00
|
|
|
CCASSERT(false, "Key found, but from different type");
|
2013-05-23 08:03:00 +08:00
|
|
|
}
|
|
|
|
|
2013-05-23 04:00:34 +08:00
|
|
|
// XXX: Should it throw an exception ?
|
2013-05-31 07:10:31 +08:00
|
|
|
return default_value;
|
2013-05-23 04:00:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/** returns the value of a given key as a boolean */
|
2013-06-20 14:13:12 +08:00
|
|
|
bool Configuration::getBool( const char *key, bool default_value ) const
|
2013-05-23 04:00:34 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
Object *ret = _valueDict->objectForKey(key);
|
2013-05-23 08:03:00 +08:00
|
|
|
if( ret ) {
|
2013-06-20 14:13:12 +08:00
|
|
|
if( Bool *boolobj=dynamic_cast<Bool*>(ret) )
|
2013-05-30 06:49:34 +08:00
|
|
|
return boolobj->getValue();
|
2013-06-20 14:13:12 +08:00
|
|
|
if( String *strobj=dynamic_cast<String*>(ret) )
|
2013-05-30 06:49:34 +08:00
|
|
|
return strobj->boolValue();
|
2013-07-20 13:01:27 +08:00
|
|
|
CCASSERT(false, "Key found, but from different type");
|
2013-05-23 08:03:00 +08:00
|
|
|
}
|
2013-05-23 04:00:34 +08:00
|
|
|
|
|
|
|
// XXX: Should it throw an exception ?
|
2013-05-31 07:10:31 +08:00
|
|
|
return default_value;
|
2013-05-23 04:00:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/** returns the value of a given key as a double */
|
2013-06-20 14:13:12 +08:00
|
|
|
double Configuration::getNumber( const char *key, double default_value ) const
|
2013-05-23 04:00:34 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
Object *ret = _valueDict->objectForKey(key);
|
2013-05-23 04:00:34 +08:00
|
|
|
if( ret ) {
|
2013-06-20 14:13:12 +08:00
|
|
|
if( Double *obj=dynamic_cast<Double*>(ret) )
|
2013-05-23 04:00:34 +08:00
|
|
|
return obj->getValue();
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
if( Integer *obj=dynamic_cast<Integer*>(ret) )
|
2013-05-23 04:00:34 +08:00
|
|
|
return obj->getValue();
|
2013-05-23 08:03:00 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
if( String *strobj=dynamic_cast<String*>(ret) )
|
2013-05-30 06:49:34 +08:00
|
|
|
return strobj->doubleValue();
|
|
|
|
|
2013-07-20 13:01:27 +08:00
|
|
|
CCASSERT(false, "Key found, but from different type");
|
2013-05-23 04:00:34 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// XXX: Should it throw an exception ?
|
2013-05-31 07:10:31 +08:00
|
|
|
return default_value;
|
2013-05-23 04:00:34 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Object * Configuration::getObject( const char *key ) const
|
2013-05-23 04:00:34 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
return _valueDict->objectForKey(key);
|
2013-05-23 04:00:34 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Configuration::setObject( const char *key, Object *value )
|
2013-06-04 04:49:06 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
_valueDict->setObject(value, key);
|
2013-06-04 04:49:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-23 08:03:00 +08:00
|
|
|
//
|
|
|
|
// load file
|
|
|
|
//
|
2013-06-20 14:13:12 +08:00
|
|
|
void Configuration::loadConfigFile( const char *filename )
|
2013-05-23 04:00:34 +08:00
|
|
|
{
|
2013-06-20 14:13:12 +08:00
|
|
|
Dictionary *dict = Dictionary::createWithContentsOfFile(filename);
|
2013-07-20 13:01:27 +08:00
|
|
|
CCASSERT(dict, "cannot create dictionary");
|
2013-05-23 08:03:00 +08:00
|
|
|
|
2013-05-29 09:15:16 +08:00
|
|
|
// search for metadata
|
|
|
|
bool metadata_ok = false;
|
2013-06-20 14:13:12 +08:00
|
|
|
Object *metadata = dict->objectForKey("metadata");
|
|
|
|
if( metadata && dynamic_cast<Dictionary*>(metadata) ) {
|
|
|
|
Object *format_o = static_cast<Dictionary*>(metadata)->objectForKey("format");
|
2013-05-29 09:15:16 +08:00
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
// XXX: cocos2d-x returns Strings when importing from .plist. This bug will be addressed in cocos2d-x v3.x
|
|
|
|
if( format_o && dynamic_cast<String*>(format_o) ) {
|
|
|
|
int format = static_cast<String*>(format_o)->intValue();
|
2013-05-29 09:15:16 +08:00
|
|
|
|
|
|
|
// Support format: 1
|
|
|
|
if( format == 1 ) {
|
|
|
|
metadata_ok = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( ! metadata_ok ) {
|
|
|
|
CCLOG("Invalid config format for file: %s", filename);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
Object *data = dict->objectForKey("data");
|
|
|
|
if( !data || !dynamic_cast<Dictionary*>(data) ) {
|
2013-05-29 09:15:16 +08:00
|
|
|
CCLOG("Expected 'data' dict, but not found. Config file: %s", filename);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-23 08:03:00 +08:00
|
|
|
// Add all keys in the existing dictionary
|
2013-06-20 14:13:12 +08:00
|
|
|
Dictionary *data_dict = static_cast<Dictionary*>(data);
|
|
|
|
DictElement* element;
|
2013-05-29 09:15:16 +08:00
|
|
|
CCDICT_FOREACH(data_dict, element)
|
2013-05-23 08:03:00 +08:00
|
|
|
{
|
2013-06-15 14:03:30 +08:00
|
|
|
if( ! _valueDict->objectForKey( element->getStrKey() ) )
|
|
|
|
_valueDict->setObject(element->getObject(), element->getStrKey() );
|
2013-05-23 08:03:00 +08:00
|
|
|
else
|
|
|
|
CCLOG("Key already present. Ignoring '%s'", element->getStrKey() );
|
|
|
|
}
|
2013-05-23 04:00:34 +08:00
|
|
|
}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
NS_CC_END
|