2012-04-19 14:35:52 +08:00
|
|
|
/****************************************************************************
|
|
|
|
Copyright (c) 2010 Ricardo Quesada
|
2014-01-07 11:25:07 +08:00
|
|
|
Copyright (c) 2010-2012 cocos2d-x.org
|
|
|
|
Copyright (c) 2013-2014 Chukong Technologies Inc.
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
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.
|
|
|
|
****************************************************************************/
|
|
|
|
|
2014-05-01 10:09:13 +08:00
|
|
|
#include "base/CCConfiguration.h"
|
2014-05-17 05:36:00 +08:00
|
|
|
#include "platform/CCFileUtils.h"
|
2015-07-24 16:38:30 +08:00
|
|
|
#include "base/CCEventCustom.h"
|
|
|
|
#include "base/CCDirector.h"
|
|
|
|
#include "base/CCEventDispatcher.h"
|
2012-04-19 14:35:52 +08:00
|
|
|
|
|
|
|
NS_CC_BEGIN
|
|
|
|
|
2014-01-17 13:35:58 +08:00
|
|
|
extern const char* cocos2dVersion();
|
2013-05-23 04:00:34 +08:00
|
|
|
|
2013-08-08 16:31:44 +08:00
|
|
|
Configuration* Configuration::s_sharedConfiguration = nullptr;
|
2012-04-20 11:39:12 +08:00
|
|
|
|
2015-07-24 16:38:30 +08:00
|
|
|
const char* Configuration::CONFIG_FILE_LOADED = "config_file_loaded";
|
|
|
|
|
2013-08-08 16:31:44 +08:00
|
|
|
Configuration::Configuration()
|
2013-06-15 14:03:30 +08:00
|
|
|
: _maxTextureSize(0)
|
|
|
|
, _maxModelviewStackDepth(0)
|
|
|
|
, _supportsPVRTC(false)
|
2013-09-24 08:03:28 +08:00
|
|
|
, _supportsETC1(false)
|
2013-08-06 11:19:45 +08:00
|
|
|
, _supportsS3TC(false)
|
2013-08-16 11:02:44 +08:00
|
|
|
, _supportsATITC(false)
|
2013-06-15 14:03:30 +08:00
|
|
|
, _supportsNPOT(false)
|
|
|
|
, _supportsBGRA8888(false)
|
|
|
|
, _supportsDiscardFramebuffer(false)
|
|
|
|
, _supportsShareableVAO(false)
|
2015-12-17 14:40:16 +08:00
|
|
|
, _supportsOESDepth24(false)
|
|
|
|
, _supportsOESPackedDepthStencil(false)
|
2016-07-15 07:45:04 +08:00
|
|
|
, _supportsOESMapBuffer(false)
|
2013-06-15 14:03:30 +08:00
|
|
|
, _maxSamplesAllowed(0)
|
|
|
|
, _maxTextureUnits(0)
|
2013-08-08 16:31:44 +08:00
|
|
|
, _glExtensions(nullptr)
|
2014-09-25 15:29:32 +08:00
|
|
|
, _maxDirLightInShader(1)
|
|
|
|
, _maxPointLightInShader(1)
|
|
|
|
, _maxSpotLightInShader(1)
|
2015-07-09 17:54:21 +08:00
|
|
|
, _animate3DQuality(Animate3DQuality::QUALITY_LOW)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2015-12-16 14:02:55 +08:00
|
|
|
_loadedEvent = new (std::nothrow) EventCustom(CONFIG_FILE_LOADED);
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-08-08 16:31:44 +08:00
|
|
|
bool Configuration::init()
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2013-12-11 14:39:21 +08:00
|
|
|
_valueDict["cocos2d.x.version"] = Value(cocos2dVersion());
|
2013-05-23 04:00:34 +08:00
|
|
|
|
|
|
|
|
|
|
|
#if CC_ENABLE_PROFILERS
|
2013-12-11 14:39:21 +08:00
|
|
|
_valueDict["cocos2d.x.compiled_with_profiler"] = Value(true);
|
2013-05-23 04:00:34 +08:00
|
|
|
#else
|
2013-12-11 14:39:21 +08:00
|
|
|
_valueDict["cocos2d.x.compiled_with_profiler"] = Value(false);
|
2013-05-23 04:00:34 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CC_ENABLE_GL_STATE_CACHE == 0
|
2013-12-11 14:39:21 +08:00
|
|
|
_valueDict["cocos2d.x.compiled_with_gl_state_cache"] = Value(false);
|
2013-05-23 04:00:34 +08:00
|
|
|
#else
|
2013-12-11 14:39:21 +08:00
|
|
|
_valueDict["cocos2d.x.compiled_with_gl_state_cache"] = Value(true);
|
2013-05-23 04:00:34 +08:00
|
|
|
#endif
|
|
|
|
|
2014-01-26 11:16:25 +08:00
|
|
|
#if COCOS2D_DEBUG
|
2013-12-11 14:39:21 +08:00
|
|
|
_valueDict["cocos2d.x.build_type"] = Value("DEBUG");
|
2013-11-27 06:36:31 +08:00
|
|
|
#else
|
2013-12-11 14:39:21 +08:00
|
|
|
_valueDict["cocos2d.x.build_type"] = Value("RELEASE");
|
2013-11-27 06:36:31 +08:00
|
|
|
#endif
|
|
|
|
|
2013-05-23 04:00:34 +08:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2013-08-08 16:31:44 +08:00
|
|
|
Configuration::~Configuration()
|
2013-05-23 04:00:34 +08:00
|
|
|
{
|
2015-07-24 16:38:30 +08:00
|
|
|
CC_SAFE_DELETE(_loadedEvent);
|
2013-05-23 04:00:34 +08:00
|
|
|
}
|
|
|
|
|
2014-01-15 09:22:45 +08:00
|
|
|
std::string Configuration::getInfo() const
|
2013-05-23 04:00:34 +08:00
|
|
|
{
|
|
|
|
// And Dump some warnings as well
|
|
|
|
#if CC_ENABLE_PROFILERS
|
2014-01-15 09:22:45 +08:00
|
|
|
CCLOG("cocos2d: **** WARNING **** CC_ENABLE_PROFILERS is defined. Disable it when you finish profiling (from ccConfig.h)\n");
|
2013-05-23 04:00:34 +08:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#if CC_ENABLE_GL_STATE_CACHE == 0
|
2014-01-15 09:22:45 +08:00
|
|
|
CCLOG("cocos2d: **** WARNING **** CC_ENABLE_GL_STATE_CACHE is disabled. To improve performance, enable it (from ccConfig.h)\n");
|
2013-05-23 04:00:34 +08:00
|
|
|
#endif
|
|
|
|
|
2014-01-15 09:22:45 +08:00
|
|
|
// Dump
|
|
|
|
Value forDump = Value(_valueDict);
|
|
|
|
return forDump.getDescription();
|
2013-05-23 04:00:34 +08:00
|
|
|
}
|
|
|
|
|
2013-06-20 14:13:12 +08:00
|
|
|
void Configuration::gatherGPUInfo()
|
2013-05-23 04:00:34 +08:00
|
|
|
{
|
2013-12-11 14:39:21 +08:00
|
|
|
_valueDict["gl.vendor"] = Value((const char*)glGetString(GL_VENDOR));
|
|
|
|
_valueDict["gl.renderer"] = Value((const char*)glGetString(GL_RENDERER));
|
|
|
|
_valueDict["gl.version"] = Value((const char*)glGetString(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-12-11 14:39:21 +08:00
|
|
|
_valueDict["gl.max_texture_size"] = Value((int)_maxTextureSize);
|
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-12-11 14:39:21 +08:00
|
|
|
_valueDict["gl.max_texture_units"] = Value((int)_maxTextureUnits);
|
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-12-11 14:39:21 +08:00
|
|
|
_valueDict["gl.max_samples_allowed"] = Value((int)_maxSamplesAllowed);
|
2012-04-20 15:12:20 +08:00
|
|
|
#endif
|
2013-07-01 17:40:57 +08:00
|
|
|
|
2013-09-24 08:03:28 +08:00
|
|
|
_supportsETC1 = checkForGLExtension("GL_OES_compressed_ETC1_RGB8_texture");
|
2013-12-11 14:39:21 +08:00
|
|
|
_valueDict["gl.supports_ETC1"] = Value(_supportsETC1);
|
2013-07-01 17:40:57 +08:00
|
|
|
|
2013-08-06 11:19:45 +08:00
|
|
|
_supportsS3TC = checkForGLExtension("GL_EXT_texture_compression_s3tc");
|
2013-12-11 14:39:21 +08:00
|
|
|
_valueDict["gl.supports_S3TC"] = Value(_supportsS3TC);
|
2013-08-16 11:02:44 +08:00
|
|
|
|
|
|
|
_supportsATITC = checkForGLExtension("GL_AMD_compressed_ATC_texture");
|
2013-12-11 14:39:21 +08:00
|
|
|
_valueDict["gl.supports_ATITC"] = Value(_supportsATITC);
|
2013-08-06 11:19:45 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_supportsPVRTC = checkForGLExtension("GL_IMG_texture_compression_pvrtc");
|
2013-12-11 14:39:21 +08:00
|
|
|
_valueDict["gl.supports_PVRTC"] = Value(_supportsPVRTC);
|
2013-05-23 04:00:34 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_supportsNPOT = true;
|
2013-12-11 14:39:21 +08:00
|
|
|
_valueDict["gl.supports_NPOT"] = Value(_supportsNPOT);
|
2013-05-23 04:00:34 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_supportsBGRA8888 = checkForGLExtension("GL_IMG_texture_format_BGRA888");
|
2013-12-11 14:39:21 +08:00
|
|
|
_valueDict["gl.supports_BGRA8888"] = Value(_supportsBGRA8888);
|
2013-05-23 04:00:34 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_supportsDiscardFramebuffer = checkForGLExtension("GL_EXT_discard_framebuffer");
|
2013-12-11 14:39:21 +08:00
|
|
|
_valueDict["gl.supports_discard_framebuffer"] = Value(_supportsDiscardFramebuffer);
|
2012-04-19 14:35:52 +08:00
|
|
|
|
2013-06-15 14:03:30 +08:00
|
|
|
_supportsShareableVAO = checkForGLExtension("vertex_array_object");
|
2016-07-15 07:45:04 +08:00
|
|
|
_valueDict["gl.supports_vertex_array_object"] = Value(_supportsShareableVAO);
|
|
|
|
|
|
|
|
_supportsOESMapBuffer = checkForGLExtension("GL_OES_mapbuffer");
|
|
|
|
_valueDict["gl.supports_OES_map_buffer"] = Value(_supportsOESMapBuffer);
|
|
|
|
|
2015-12-17 14:40:16 +08:00
|
|
|
_supportsOESDepth24 = checkForGLExtension("GL_OES_depth24");
|
|
|
|
_valueDict["gl.supports_OES_depth24"] = Value(_supportsOESDepth24);
|
|
|
|
|
|
|
|
|
|
|
|
_supportsOESPackedDepthStencil = checkForGLExtension("GL_OES_packed_depth_stencil");
|
|
|
|
_valueDict["gl.supports_OES_packed_depth_stencil"] = Value(_supportsOESPackedDepthStencil);
|
|
|
|
|
2014-01-17 07:02:39 +08:00
|
|
|
|
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
|
|
|
{
|
2013-08-08 16:31:44 +08:00
|
|
|
if (! s_sharedConfiguration)
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2014-08-28 07:31:57 +08:00
|
|
|
s_sharedConfiguration = new (std::nothrow) Configuration();
|
2013-08-08 16:31:44 +08:00
|
|
|
s_sharedConfiguration->init();
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-08-08 16:31:44 +08:00
|
|
|
return s_sharedConfiguration;
|
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
|
|
|
{
|
2013-08-08 16:31:44 +08:00
|
|
|
CC_SAFE_RELEASE_NULL(s_sharedConfiguration);
|
2012-05-23 12:11:53 +08:00
|
|
|
}
|
|
|
|
|
2014-08-30 03:54:24 +08:00
|
|
|
// FIXME: deprecated
|
2013-08-08 16:31:44 +08:00
|
|
|
Configuration* Configuration::sharedConfiguration()
|
2013-07-12 06:24:23 +08:00
|
|
|
{
|
|
|
|
return Configuration::getInstance();
|
|
|
|
}
|
|
|
|
|
2014-08-30 03:54:24 +08:00
|
|
|
// FIXME: deprecated
|
2013-08-08 16:31:44 +08:00
|
|
|
void Configuration::purgeConfiguration()
|
2013-07-12 06:24:23 +08:00
|
|
|
{
|
|
|
|
Configuration::destroyInstance();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2014-04-09 23:54:40 +08:00
|
|
|
bool Configuration::checkForGLExtension(const std::string &searchName) const
|
2012-04-19 14:35:52 +08:00
|
|
|
{
|
2014-01-08 09:09:43 +08:00
|
|
|
return (_glExtensions && strstr(_glExtensions, searchName.c_str() ) ) ? true : false;
|
2012-04-19 14:35:52 +08:00
|
|
|
}
|
|
|
|
|
2013-05-23 04:00:34 +08:00
|
|
|
//
|
|
|
|
// getters for specific variables.
|
2015-09-22 16:08:23 +08:00
|
|
|
// Maintained for backward compatibility reasons only.
|
2013-05-23 04:00:34 +08:00
|
|
|
//
|
2013-08-08 16:31:44 +08:00
|
|
|
int Configuration::getMaxTextureSize() 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-08-08 16:31:44 +08:00
|
|
|
int Configuration::getMaxModelviewStackDepth() 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-08-08 16:31:44 +08:00
|
|
|
int Configuration::getMaxTextureUnits() 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-08-08 16:31:44 +08:00
|
|
|
bool Configuration::supportsNPOT() 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-08-08 16:31:44 +08:00
|
|
|
bool Configuration::supportsPVRTC() 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-09-24 08:03:28 +08:00
|
|
|
return _supportsETC1;
|
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
|
|
|
|
{
|
2015-06-24 16:11:36 +08:00
|
|
|
#ifdef GL_EXT_texture_compression_s3tc
|
2013-08-06 11:19:45 +08:00
|
|
|
return _supportsS3TC;
|
2015-06-24 16:11:36 +08:00
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
2013-08-06 11:19:45 +08:00
|
|
|
}
|
|
|
|
|
2013-08-16 11:02:44 +08:00
|
|
|
bool Configuration::supportsATITC() const
|
|
|
|
{
|
|
|
|
return _supportsATITC;
|
|
|
|
}
|
|
|
|
|
2013-08-08 16:31:44 +08:00
|
|
|
bool Configuration::supportsBGRA8888() 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-08-08 16:31:44 +08:00
|
|
|
bool Configuration::supportsDiscardFramebuffer() 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-08-08 16:31:44 +08:00
|
|
|
bool Configuration::supportsShareableVAO() const
|
2013-05-23 04:00:34 +08:00
|
|
|
{
|
2013-12-11 14:39:21 +08:00
|
|
|
#if CC_TEXTURE_ATLAS_USE_VAO
|
|
|
|
return _supportsShareableVAO;
|
|
|
|
#else
|
|
|
|
return false;
|
|
|
|
#endif
|
2013-05-23 04:00:34 +08:00
|
|
|
}
|
|
|
|
|
2016-07-15 07:45:04 +08:00
|
|
|
bool Configuration::supportsMapBuffer() const
|
|
|
|
{
|
|
|
|
// Fixes Github issue #16123
|
|
|
|
//
|
|
|
|
// XXX: Fixme. Should check GL ES and not iOS or Android
|
|
|
|
// For example, linux could be compiled with GL ES. Or perhaps in the future Android will
|
|
|
|
// support OpenGL. This is because glMapBufferOES() is an extension of OpenGL ES. And glMapBuffer()
|
|
|
|
// is always implemented in OpenGL.
|
|
|
|
|
|
|
|
// XXX: Warning. On iOS this is always `true`. Avoiding the comparison.
|
|
|
|
#if (CC_TARGET_PLATFORM == CC_PLATFORM_ANDROID)
|
|
|
|
return _supportsOESMapBuffer;
|
|
|
|
#else
|
|
|
|
return true;
|
|
|
|
#endif
|
|
|
|
}
|
2015-12-17 14:40:16 +08:00
|
|
|
|
2015-12-17 15:24:29 +08:00
|
|
|
bool Configuration::supportsOESDepth24() const
|
2015-12-17 14:40:16 +08:00
|
|
|
{
|
|
|
|
return _supportsOESDepth24;
|
|
|
|
|
|
|
|
}
|
2015-12-17 15:24:29 +08:00
|
|
|
bool Configuration::supportsOESPackedDepthStencil() const
|
2015-12-17 14:40:16 +08:00
|
|
|
{
|
|
|
|
return _supportsOESPackedDepthStencil;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2014-09-25 15:29:32 +08:00
|
|
|
int Configuration::getMaxSupportDirLightInShader() const
|
|
|
|
{
|
|
|
|
return _maxDirLightInShader;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Configuration::getMaxSupportPointLightInShader() const
|
|
|
|
{
|
|
|
|
return _maxPointLightInShader;
|
|
|
|
}
|
|
|
|
|
|
|
|
int Configuration::getMaxSupportSpotLightInShader() const
|
|
|
|
{
|
|
|
|
return _maxSpotLightInShader;
|
|
|
|
}
|
|
|
|
|
2015-04-24 11:49:28 +08:00
|
|
|
Animate3DQuality Configuration::getAnimate3DQuality() const
|
2015-03-26 11:30:22 +08:00
|
|
|
{
|
2015-04-24 11:49:28 +08:00
|
|
|
return _animate3DQuality;
|
2015-03-26 11:30:22 +08:00
|
|
|
}
|
|
|
|
|
2013-05-23 04:00:34 +08:00
|
|
|
//
|
|
|
|
// generic getters for properties
|
|
|
|
//
|
2013-12-11 14:39:21 +08:00
|
|
|
const Value& Configuration::getValue(const std::string& key, const Value& defaultValue) const
|
2013-05-23 04:00:34 +08:00
|
|
|
{
|
2013-12-11 14:39:21 +08:00
|
|
|
auto iter = _valueDict.find(key);
|
2014-01-08 09:09:43 +08:00
|
|
|
if (iter != _valueDict.cend())
|
2013-12-11 14:39:21 +08:00
|
|
|
return _valueDict.at(key);
|
2013-08-08 16:31:44 +08:00
|
|
|
return defaultValue;
|
2013-05-23 04:00:34 +08:00
|
|
|
}
|
|
|
|
|
2013-12-11 14:39:21 +08:00
|
|
|
void Configuration::setValue(const std::string& key, const Value& value)
|
2013-06-04 04:49:06 +08:00
|
|
|
{
|
2013-12-11 14:39:21 +08:00
|
|
|
_valueDict[key] = value;
|
2013-06-04 04:49:06 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-23 08:03:00 +08:00
|
|
|
//
|
|
|
|
// load file
|
|
|
|
//
|
2013-12-24 10:51:47 +08:00
|
|
|
void Configuration::loadConfigFile(const std::string& filename)
|
2013-05-23 04:00:34 +08:00
|
|
|
{
|
2013-12-11 14:39:21 +08:00
|
|
|
ValueMap dict = FileUtils::getInstance()->getValueMapFromFile(filename);
|
|
|
|
CCASSERT(!dict.empty(), "cannot create dictionary");
|
2013-05-23 08:03:00 +08:00
|
|
|
|
2013-05-29 09:15:16 +08:00
|
|
|
// search for metadata
|
2013-08-08 16:31:44 +08:00
|
|
|
bool validMetadata = false;
|
2013-12-11 14:39:21 +08:00
|
|
|
auto metadataIter = dict.find("metadata");
|
2014-01-08 09:09:43 +08:00
|
|
|
if (metadataIter != dict.cend() && metadataIter->second.getType() == Value::Type::MAP)
|
2013-08-08 16:31:44 +08:00
|
|
|
{
|
2013-12-11 14:39:21 +08:00
|
|
|
|
|
|
|
const auto& metadata = metadataIter->second.asValueMap();
|
|
|
|
auto formatIter = metadata.find("format");
|
|
|
|
|
2014-01-08 09:09:43 +08:00
|
|
|
if (formatIter != metadata.cend())
|
2013-08-08 16:31:44 +08:00
|
|
|
{
|
2013-12-11 14:39:21 +08:00
|
|
|
int format = formatIter->second.asInt();
|
2013-05-29 09:15:16 +08:00
|
|
|
|
|
|
|
// Support format: 1
|
2013-08-08 16:31:44 +08:00
|
|
|
if (format == 1)
|
|
|
|
{
|
|
|
|
validMetadata = true;
|
2013-05-29 09:15:16 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-08-08 16:31:44 +08:00
|
|
|
if (! validMetadata)
|
|
|
|
{
|
2013-12-24 10:51:47 +08:00
|
|
|
CCLOG("Invalid config format for file: %s", filename.c_str());
|
2013-05-29 09:15:16 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-12-11 14:39:21 +08:00
|
|
|
auto dataIter = dict.find("data");
|
2014-01-08 09:09:43 +08:00
|
|
|
if (dataIter == dict.cend() || dataIter->second.getType() != Value::Type::MAP)
|
2013-08-08 16:31:44 +08:00
|
|
|
{
|
2013-12-24 10:51:47 +08:00
|
|
|
CCLOG("Expected 'data' dict, but not found. Config file: %s", filename.c_str());
|
2013-05-29 09:15:16 +08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2013-05-23 08:03:00 +08:00
|
|
|
// Add all keys in the existing dictionary
|
2013-12-11 14:39:21 +08:00
|
|
|
|
|
|
|
const auto& dataMap = dataIter->second.asValueMap();
|
2014-01-08 09:09:43 +08:00
|
|
|
for (auto dataMapIter = dataMap.cbegin(); dataMapIter != dataMap.cend(); ++dataMapIter)
|
2013-05-23 08:03:00 +08:00
|
|
|
{
|
2014-01-08 09:09:43 +08:00
|
|
|
if (_valueDict.find(dataMapIter->first) == _valueDict.cend())
|
2013-12-11 14:39:21 +08:00
|
|
|
_valueDict[dataMapIter->first] = dataMapIter->second;
|
|
|
|
else
|
|
|
|
CCLOG("Key already present. Ignoring '%s'",dataMapIter->first.c_str());
|
2013-05-23 08:03:00 +08:00
|
|
|
}
|
2014-09-25 15:29:32 +08:00
|
|
|
|
|
|
|
//light info
|
|
|
|
std::string name = "cocos2d.x.3d.max_dir_light_in_shader";
|
2014-10-03 06:46:47 +08:00
|
|
|
if (_valueDict.find(name) != _valueDict.end())
|
2014-09-25 15:29:32 +08:00
|
|
|
_maxDirLightInShader = _valueDict[name].asInt();
|
|
|
|
else
|
|
|
|
_valueDict[name] = Value(_maxDirLightInShader);
|
|
|
|
|
|
|
|
name = "cocos2d.x.3d.max_point_light_in_shader";
|
2014-10-03 06:46:47 +08:00
|
|
|
if (_valueDict.find(name) != _valueDict.end())
|
2014-09-25 15:29:32 +08:00
|
|
|
_maxPointLightInShader = _valueDict[name].asInt();
|
|
|
|
else
|
|
|
|
_valueDict[name] = Value(_maxPointLightInShader);
|
|
|
|
|
|
|
|
name = "cocos2d.x.3d.max_spot_light_in_shader";
|
2014-10-03 06:46:47 +08:00
|
|
|
if (_valueDict.find(name) != _valueDict.end())
|
2014-09-25 15:29:32 +08:00
|
|
|
_maxSpotLightInShader = _valueDict[name].asInt();
|
|
|
|
else
|
|
|
|
_valueDict[name] = Value(_maxSpotLightInShader);
|
2015-03-26 11:30:22 +08:00
|
|
|
|
2015-04-24 11:49:28 +08:00
|
|
|
name = "cocos2d.x.3d.animate_quality";
|
2015-03-26 11:30:22 +08:00
|
|
|
if (_valueDict.find(name) != _valueDict.end())
|
2015-04-24 11:49:28 +08:00
|
|
|
_animate3DQuality = (Animate3DQuality)_valueDict[name].asInt();
|
2015-03-26 11:30:22 +08:00
|
|
|
else
|
2015-04-24 11:49:28 +08:00
|
|
|
_valueDict[name] = Value((int)_animate3DQuality);
|
2015-07-15 11:36:53 +08:00
|
|
|
|
2015-07-24 16:38:30 +08:00
|
|
|
Director::getInstance()->getEventDispatcher()->dispatchEvent(_loadedEvent);
|
2013-05-23 04:00:34 +08:00
|
|
|
}
|
|
|
|
|
2012-04-19 14:35:52 +08:00
|
|
|
NS_CC_END
|