mirror of https://github.com/axmolengine/axmol.git
Adds setObject to CCConfiguration
also adds the test Conflicts: scripting/javascript/bindings/generated
This commit is contained in:
parent
823cffb1d2
commit
d27da88c06
|
@ -51,28 +51,28 @@ CCConfiguration::CCConfiguration(void)
|
||||||
, m_nMaxSamplesAllowed(0)
|
, m_nMaxSamplesAllowed(0)
|
||||||
, m_nMaxTextureUnits(0)
|
, m_nMaxTextureUnits(0)
|
||||||
, m_pGlExtensions(NULL)
|
, m_pGlExtensions(NULL)
|
||||||
, m_pDefaults(NULL)
|
, m_pValueDict(NULL)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CCConfiguration::init(void)
|
bool CCConfiguration::init(void)
|
||||||
{
|
{
|
||||||
m_pDefaults = CCDictionary::create();
|
m_pValueDict = CCDictionary::create();
|
||||||
m_pDefaults->retain();
|
m_pValueDict->retain();
|
||||||
|
|
||||||
m_pDefaults->setObject( CCString::create( cocos2dVersion() ), "cocos2d.x.version");
|
m_pValueDict->setObject( CCString::create( cocos2dVersion() ), "cocos2d.x.version");
|
||||||
|
|
||||||
|
|
||||||
#if CC_ENABLE_PROFILERS
|
#if CC_ENABLE_PROFILERS
|
||||||
m_pDefaults->setObject( CCBool::create(true), "cocos2d.x.compiled_with_profiler");
|
m_pValueDict->setObject( CCBool::create(true), "cocos2d.x.compiled_with_profiler");
|
||||||
#else
|
#else
|
||||||
m_pDefaults->setObject( CCBool::create(false), "cocos2d.x.compiled_with_profiler");
|
m_pValueDict->setObject( CCBool::create(false), "cocos2d.x.compiled_with_profiler");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if CC_ENABLE_GL_STATE_CACHE == 0
|
#if CC_ENABLE_GL_STATE_CACHE == 0
|
||||||
m_pDefaults->setObject( CCBool::create(false), "cocos2d.x.compiled_with_gl_state_cache");
|
m_pValueDict->setObject( CCBool::create(false), "cocos2d.x.compiled_with_gl_state_cache");
|
||||||
#else
|
#else
|
||||||
m_pDefaults->setObject( CCBool::create(true), "cocos2d.x.compiled_with_gl_state_cache");
|
m_pValueDict->setObject( CCBool::create(true), "cocos2d.x.compiled_with_gl_state_cache");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -80,14 +80,14 @@ bool CCConfiguration::init(void)
|
||||||
|
|
||||||
CCConfiguration::~CCConfiguration(void)
|
CCConfiguration::~CCConfiguration(void)
|
||||||
{
|
{
|
||||||
m_pDefaults->release();
|
m_pValueDict->release();
|
||||||
}
|
}
|
||||||
|
|
||||||
void CCConfiguration::dumpInfo(void) const
|
void CCConfiguration::dumpInfo(void) const
|
||||||
{
|
{
|
||||||
// Dump
|
// Dump
|
||||||
CCPrettyPrinter visitor(0);
|
CCPrettyPrinter visitor(0);
|
||||||
m_pDefaults->acceptVisitor(visitor);
|
m_pValueDict->acceptVisitor(visitor);
|
||||||
|
|
||||||
CCLOG("%s", visitor.getResult().c_str());
|
CCLOG("%s", visitor.getResult().c_str());
|
||||||
|
|
||||||
|
@ -108,37 +108,37 @@ void CCConfiguration::dumpInfo(void) const
|
||||||
|
|
||||||
void CCConfiguration::gatherGPUInfo()
|
void CCConfiguration::gatherGPUInfo()
|
||||||
{
|
{
|
||||||
m_pDefaults->setObject( CCString::create( (const char*)glGetString(GL_VENDOR)), "gl.vendor");
|
m_pValueDict->setObject( CCString::create( (const char*)glGetString(GL_VENDOR)), "gl.vendor");
|
||||||
m_pDefaults->setObject( CCString::create( (const char*)glGetString(GL_RENDERER)), "gl.renderer");
|
m_pValueDict->setObject( CCString::create( (const char*)glGetString(GL_RENDERER)), "gl.renderer");
|
||||||
m_pDefaults->setObject( CCString::create( (const char*)glGetString(GL_VERSION)), "gl.version");
|
m_pValueDict->setObject( CCString::create( (const char*)glGetString(GL_VERSION)), "gl.version");
|
||||||
|
|
||||||
m_pGlExtensions = (char *)glGetString(GL_EXTENSIONS);
|
m_pGlExtensions = (char *)glGetString(GL_EXTENSIONS);
|
||||||
|
|
||||||
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &m_nMaxTextureSize);
|
glGetIntegerv(GL_MAX_TEXTURE_SIZE, &m_nMaxTextureSize);
|
||||||
m_pDefaults->setObject( CCInteger::create((int)m_nMaxTextureSize), "gl.max_texture_size");
|
m_pValueDict->setObject( CCInteger::create((int)m_nMaxTextureSize), "gl.max_texture_size");
|
||||||
|
|
||||||
glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &m_nMaxTextureUnits);
|
glGetIntegerv(GL_MAX_COMBINED_TEXTURE_IMAGE_UNITS, &m_nMaxTextureUnits);
|
||||||
m_pDefaults->setObject( CCInteger::create((int)m_nMaxTextureUnits), "gl.max_texture_units");
|
m_pValueDict->setObject( CCInteger::create((int)m_nMaxTextureUnits), "gl.max_texture_units");
|
||||||
|
|
||||||
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
|
||||||
glGetIntegerv(GL_MAX_SAMPLES_APPLE, &m_nMaxSamplesAllowed);
|
glGetIntegerv(GL_MAX_SAMPLES_APPLE, &m_nMaxSamplesAllowed);
|
||||||
m_pDefaults->setObject( CCInteger::create((int)m_nMaxSamplesAllowed), "gl.max_samples_allowed");
|
m_pValueDict->setObject( CCInteger::create((int)m_nMaxSamplesAllowed), "gl.max_samples_allowed");
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
m_bSupportsPVRTC = checkForGLExtension("GL_IMG_texture_compression_pvrtc");
|
m_bSupportsPVRTC = checkForGLExtension("GL_IMG_texture_compression_pvrtc");
|
||||||
m_pDefaults->setObject( CCBool::create(m_bSupportsPVRTC), "gl.supports_PVRTC");
|
m_pValueDict->setObject( CCBool::create(m_bSupportsPVRTC), "gl.supports_PVRTC");
|
||||||
|
|
||||||
m_bSupportsNPOT = true;
|
m_bSupportsNPOT = true;
|
||||||
m_pDefaults->setObject( CCBool::create(m_bSupportsNPOT), "gl.supports_NPOT");
|
m_pValueDict->setObject( CCBool::create(m_bSupportsNPOT), "gl.supports_NPOT");
|
||||||
|
|
||||||
m_bSupportsBGRA8888 = checkForGLExtension("GL_IMG_texture_format_BGRA888");
|
m_bSupportsBGRA8888 = checkForGLExtension("GL_IMG_texture_format_BGRA888");
|
||||||
m_pDefaults->setObject( CCBool::create(m_bSupportsBGRA8888), "gl.supports_BGRA8888");
|
m_pValueDict->setObject( CCBool::create(m_bSupportsBGRA8888), "gl.supports_BGRA8888");
|
||||||
|
|
||||||
m_bSupportsDiscardFramebuffer = checkForGLExtension("GL_EXT_discard_framebuffer");
|
m_bSupportsDiscardFramebuffer = checkForGLExtension("GL_EXT_discard_framebuffer");
|
||||||
m_pDefaults->setObject( CCBool::create(m_bSupportsDiscardFramebuffer), "gl.supports_discard_framebuffer");
|
m_pValueDict->setObject( CCBool::create(m_bSupportsDiscardFramebuffer), "gl.supports_discard_framebuffer");
|
||||||
|
|
||||||
m_bSupportsShareableVAO = checkForGLExtension("vertex_array_object");
|
m_bSupportsShareableVAO = checkForGLExtension("vertex_array_object");
|
||||||
m_pDefaults->setObject( CCBool::create(m_bSupportsShareableVAO), "gl.supports_vertex_array_object");
|
m_pValueDict->setObject( CCBool::create(m_bSupportsShareableVAO), "gl.supports_vertex_array_object");
|
||||||
|
|
||||||
CHECK_GL_ERROR_DEBUG();
|
CHECK_GL_ERROR_DEBUG();
|
||||||
}
|
}
|
||||||
|
@ -222,7 +222,7 @@ bool CCConfiguration::supportsShareableVAO(void) const
|
||||||
//
|
//
|
||||||
const char *CCConfiguration::getCString( const char *key, const char *default_value ) const
|
const char *CCConfiguration::getCString( const char *key, const char *default_value ) const
|
||||||
{
|
{
|
||||||
CCObject *ret = m_pDefaults->objectForKey(key);
|
CCObject *ret = m_pValueDict->objectForKey(key);
|
||||||
if( ret ) {
|
if( ret ) {
|
||||||
if( CCString *str=dynamic_cast<CCString*>(ret) )
|
if( CCString *str=dynamic_cast<CCString*>(ret) )
|
||||||
return str->getCString();
|
return str->getCString();
|
||||||
|
@ -237,7 +237,7 @@ const char *CCConfiguration::getCString( const char *key, const char *default_va
|
||||||
/** returns the value of a given key as a boolean */
|
/** returns the value of a given key as a boolean */
|
||||||
bool CCConfiguration::getBool( const char *key, bool default_value ) const
|
bool CCConfiguration::getBool( const char *key, bool default_value ) const
|
||||||
{
|
{
|
||||||
CCObject *ret = m_pDefaults->objectForKey(key);
|
CCObject *ret = m_pValueDict->objectForKey(key);
|
||||||
if( ret ) {
|
if( ret ) {
|
||||||
if( CCBool *boolobj=dynamic_cast<CCBool*>(ret) )
|
if( CCBool *boolobj=dynamic_cast<CCBool*>(ret) )
|
||||||
return boolobj->getValue();
|
return boolobj->getValue();
|
||||||
|
@ -253,7 +253,7 @@ bool CCConfiguration::getBool( const char *key, bool default_value ) const
|
||||||
/** returns the value of a given key as a double */
|
/** returns the value of a given key as a double */
|
||||||
double CCConfiguration::getNumber( const char *key, double default_value ) const
|
double CCConfiguration::getNumber( const char *key, double default_value ) const
|
||||||
{
|
{
|
||||||
CCObject *ret = m_pDefaults->objectForKey(key);
|
CCObject *ret = m_pValueDict->objectForKey(key);
|
||||||
if( ret ) {
|
if( ret ) {
|
||||||
if( CCDouble *obj=dynamic_cast<CCDouble*>(ret) )
|
if( CCDouble *obj=dynamic_cast<CCDouble*>(ret) )
|
||||||
return obj->getValue();
|
return obj->getValue();
|
||||||
|
@ -273,9 +273,15 @@ double CCConfiguration::getNumber( const char *key, double default_value ) const
|
||||||
|
|
||||||
CCObject * CCConfiguration::getObject( const char *key ) const
|
CCObject * CCConfiguration::getObject( const char *key ) const
|
||||||
{
|
{
|
||||||
return m_pDefaults->objectForKey(key);
|
return m_pValueDict->objectForKey(key);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CCConfiguration::setObject( const char *key, CCObject *value )
|
||||||
|
{
|
||||||
|
m_pValueDict->setObject(value, key);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//
|
//
|
||||||
// load file
|
// load file
|
||||||
//
|
//
|
||||||
|
@ -317,8 +323,8 @@ void CCConfiguration::loadConfigFile( const char *filename )
|
||||||
CCDictElement* element;
|
CCDictElement* element;
|
||||||
CCDICT_FOREACH(data_dict, element)
|
CCDICT_FOREACH(data_dict, element)
|
||||||
{
|
{
|
||||||
if( ! m_pDefaults->objectForKey( element->getStrKey() ) )
|
if( ! m_pValueDict->objectForKey( element->getStrKey() ) )
|
||||||
m_pDefaults->setObject(element->getObject(), element->getStrKey() );
|
m_pValueDict->setObject(element->getObject(), element->getStrKey() );
|
||||||
else
|
else
|
||||||
CCLOG("Key already present. Ignoring '%s'", element->getStrKey() );
|
CCLOG("Key already present. Ignoring '%s'", element->getStrKey() );
|
||||||
}
|
}
|
||||||
|
|
|
@ -121,6 +121,9 @@ public:
|
||||||
/** returns the value of a given key as a double */
|
/** returns the value of a given key as a double */
|
||||||
CCObject * getObject( const char *key ) const;
|
CCObject * getObject( const char *key ) const;
|
||||||
|
|
||||||
|
/** sets a new key/value pair in the configuration dictionary */
|
||||||
|
void setObject( const char *key, CCObject *value );
|
||||||
|
|
||||||
/** dumps the current configuration on the console */
|
/** dumps the current configuration on the console */
|
||||||
void dumpInfo(void) const;
|
void dumpInfo(void) const;
|
||||||
|
|
||||||
|
@ -146,7 +149,8 @@ protected:
|
||||||
GLint m_nMaxSamplesAllowed;
|
GLint m_nMaxSamplesAllowed;
|
||||||
GLint m_nMaxTextureUnits;
|
GLint m_nMaxTextureUnits;
|
||||||
char * m_pGlExtensions;
|
char * m_pGlExtensions;
|
||||||
CCDictionary *m_pDefaults;
|
|
||||||
|
CCDictionary *m_pValueDict;
|
||||||
};
|
};
|
||||||
|
|
||||||
// end of global group
|
// end of global group
|
||||||
|
|
|
@ -7,12 +7,14 @@ TESTLAYER_CREATE_FUNC(ConfigurationLoadConfig);
|
||||||
TESTLAYER_CREATE_FUNC(ConfigurationQuery);
|
TESTLAYER_CREATE_FUNC(ConfigurationQuery);
|
||||||
TESTLAYER_CREATE_FUNC(ConfigurationInvalid);
|
TESTLAYER_CREATE_FUNC(ConfigurationInvalid);
|
||||||
TESTLAYER_CREATE_FUNC(ConfigurationDefault);
|
TESTLAYER_CREATE_FUNC(ConfigurationDefault);
|
||||||
|
TESTLAYER_CREATE_FUNC(ConfigurationSet);
|
||||||
|
|
||||||
static NEWTESTFUNC createFunctions[] = {
|
static NEWTESTFUNC createFunctions[] = {
|
||||||
CF(ConfigurationLoadConfig),
|
CF(ConfigurationLoadConfig),
|
||||||
CF(ConfigurationQuery),
|
CF(ConfigurationQuery),
|
||||||
CF(ConfigurationInvalid),
|
CF(ConfigurationInvalid),
|
||||||
CF(ConfigurationDefault)
|
CF(ConfigurationDefault),
|
||||||
|
CF(ConfigurationSet)
|
||||||
};
|
};
|
||||||
|
|
||||||
static int sceneIdx=-1;
|
static int sceneIdx=-1;
|
||||||
|
@ -222,3 +224,27 @@ std::string ConfigurationDefault::subtitle()
|
||||||
{
|
{
|
||||||
return "Tests defaults values";
|
return "Tests defaults values";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//------------------------------------------------------------------
|
||||||
|
//
|
||||||
|
// ConfigurationSet
|
||||||
|
//
|
||||||
|
//------------------------------------------------------------------
|
||||||
|
void ConfigurationSet::onEnter()
|
||||||
|
{
|
||||||
|
ConfigurationBase::onEnter();
|
||||||
|
|
||||||
|
CCConfiguration *conf = CCConfiguration::sharedConfiguration();
|
||||||
|
|
||||||
|
conf->setObject("this.is.an.int.key", CCInteger::create(10) );
|
||||||
|
conf->setObject("this.is.a.bool.key", CCBool::create(true) );
|
||||||
|
conf->setObject("this.is.a.string.key", CCString::create("hello world") );
|
||||||
|
|
||||||
|
conf->dumpInfo();
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string ConfigurationSet::subtitle()
|
||||||
|
{
|
||||||
|
return "Tests setting values manually";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
|
@ -59,5 +59,12 @@ public:
|
||||||
virtual std::string subtitle();
|
virtual std::string subtitle();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class ConfigurationSet : public ConfigurationBase
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
virtual void onEnter();
|
||||||
|
virtual std::string subtitle();
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
#endif // __CONFIGURATIONTEST_H__
|
#endif // __CONFIGURATIONTEST_H__
|
||||||
|
|
Loading…
Reference in New Issue