24
24
THE SOFTWARE.
25
25
****************************************************************************/
26
26
27
+ cc . ConfigurationType = { ConfigurationError :0 , ConfigurationString :1 , ConfigurationInt :2 , ConfigurationDouble :3 , ConfigurationBoolean :4 } ;
28
+
27
29
/**
28
30
* cc.Configuration contains some openGL variables
29
31
* @class
@@ -40,6 +42,21 @@ cc.Configuration = cc.Class.extend(/** @lends cc.Configuration# */{
40
42
_maxSamplesAllowed :0 ,
41
43
_maxTextureUnits :0 ,
42
44
_GlExtensions :"" ,
45
+ _valueDict :null ,
46
+
47
+ ctor : function ( ) {
48
+ this . _maxTextureSize = 0 ;
49
+ this . _maxModelviewStackDepth = 0 ;
50
+ this . _supportsPVRTC = false ;
51
+ this . _supportsNPOT = false ;
52
+ this . _supportsBGRA8888 = false ;
53
+ this . _supportsDiscardFramebuffer = false ;
54
+ this . _supportsShareableVAO = false ;
55
+ this . _maxSamplesAllowed = 0 ;
56
+ this . _maxTextureUnits = 0 ;
57
+ this . _GlExtensions = "" ;
58
+ this . _valueDict = { } ;
59
+ } ,
43
60
44
61
/**
45
62
* OpenGL Max texture size.
@@ -115,43 +132,150 @@ cc.Configuration = cc.Class.extend(/** @lends cc.Configuration# */{
115
132
} ,
116
133
117
134
init :function ( ) {
135
+ var locValueDict = this . _valueDict ;
136
+ locValueDict [ "cocos2d.x.version" ] = cc . ENGINE_VERSION ;
137
+ locValueDict [ "cocos2d.x.compiled_with_profiler" ] = false ;
138
+ locValueDict [ "cocos2d.x.compiled_with_gl_state_cache" ] = cc . ENABLE_GL_STATE_CACHE ;
139
+ return true ;
140
+ } ,
141
+
142
+ /**
143
+ * returns the value of a given key as a string. If the key is not found, it will return the default value
144
+ * @param {String } key
145
+ * @param {String } [default_value=null]
146
+ * @returns {String }
147
+ */
148
+ getCString :function ( key , default_value ) {
149
+ var locValueDict = this . _valueDict ;
150
+ if ( locValueDict . hasOwnProperty ( key ) )
151
+ return locValueDict [ key ] ;
152
+ return default_value ;
153
+ } ,
154
+
155
+ /**
156
+ * returns the value of a given key as a boolean. If the key is not found, it will return the default value
157
+ * @param {string } key
158
+ * @param {boolean|null } [default_value=false]
159
+ * @returns {boolean }
160
+ */
161
+ getBool : function ( key , default_value ) {
162
+ if ( default_value == null )
163
+ default_value = false ;
164
+ var locValueDict = this . _valueDict ;
165
+ if ( locValueDict . hasOwnProperty ( key ) )
166
+ return locValueDict [ key ] ;
167
+ return default_value ;
168
+ } ,
169
+
170
+ /**
171
+ * returns the value of a given key as a double. If the key is not found, it will return the default value
172
+ * @param {string } key
173
+ * @param {number } [default_value=0]
174
+ * @returns {number }
175
+ */
176
+ getNumber : function ( key , default_value ) {
177
+ if ( default_value == null )
178
+ default_value = 0 ;
179
+ var locValueDict = this . _valueDict ;
180
+ if ( locValueDict . hasOwnProperty ( key ) )
181
+ return locValueDict [ key ] ;
182
+ return default_value ;
183
+ } ,
184
+
185
+ /**
186
+ * returns the value of a given key as a double
187
+ * @param {string } key
188
+ * @returns {Object|null }
189
+ */
190
+ getObject :function ( key ) {
191
+ var locValueDict = this . _valueDict ;
192
+ if ( locValueDict . hasOwnProperty ( key ) )
193
+ return locValueDict [ key ] ;
194
+ return null ;
195
+ } ,
196
+
197
+ /**
198
+ * sets a new key/value pair in the configuration dictionary
199
+ * @param {string } key
200
+ * @param {Object } value
201
+ */
202
+ setObject : function ( key , value ) {
203
+ this . _valueDict [ key ] = value ;
204
+ } ,
205
+
206
+ /**
207
+ * dumps the current configuration on the console
208
+ */
209
+ dumpInfo : function ( ) {
210
+ if ( cc . ENABLE_GL_STATE_CACHE === 0 ) {
211
+ cc . log ( "" ) ;
212
+ cc . log ( "cocos2d: **** WARNING **** CC_ENABLE_PROFILERS is defined. Disable it when you finish profiling (from ccConfig.js)" ) ;
213
+ cc . log ( "" )
214
+ }
215
+ } ,
216
+
217
+ /**
218
+ * gathers OpenGL / GPU information
219
+ */
220
+ gatherGPUInfo : function ( ) {
118
221
if ( cc . renderContextType === cc . CANVAS )
119
- return true ;
222
+ return ;
120
223
121
224
var gl = cc . renderContext ;
122
- cc . log ( "cocos2d: GL_VENDOR: " + gl . getParameter ( gl . VENDOR ) ) ;
123
- cc . log ( "cocos2d: GL_RENDERER: " + gl . getParameter ( gl . RENDERER ) ) ;
124
- cc . log ( "cocos2d: GL_VERSION: " + gl . getParameter ( gl . VERSION ) ) ;
225
+ var locValueDict = this . _valueDict ;
226
+ locValueDict [ "gl.vendor" ] = gl . getParameter ( gl . VENDOR ) ;
227
+ locValueDict [ "gl.renderer" ] = gl . getParameter ( gl . RENDERER ) ;
228
+ locValueDict [ "gl.version" ] = gl . getParameter ( gl . VERSION ) ;
125
229
126
230
this . _GlExtensions = "" ;
127
231
var extArr = gl . getSupportedExtensions ( ) ;
128
232
for ( var i = 0 ; i < extArr . length ; i ++ )
129
233
this . _GlExtensions += extArr [ i ] + " " ;
130
- cc . log ( "cocos2d: GL_EXTENSIONS: " + this . _GlExtensions ) ;
131
234
132
235
this . _maxTextureSize = gl . getParameter ( gl . MAX_TEXTURE_SIZE ) ;
236
+ locValueDict [ "gl.max_texture_size" ] = this . _maxTextureSize ;
133
237
this . _maxTextureUnits = gl . getParameter ( gl . MAX_COMBINED_TEXTURE_IMAGE_UNITS ) ;
238
+ locValueDict [ "gl.max_texture_units" ] = this . _maxTextureUnits ;
134
239
135
240
this . _supportsPVRTC = this . checkForGLExtension ( "GL_IMG_texture_compression_pvrtc" ) ;
136
- this . _supportsNPOT = true ;
241
+ locValueDict [ "gl.supports_PVRTC" ] = this . _supportsPVRTC ;
242
+
243
+ this . _supportsNPOT = false ; //true;
244
+ locValueDict [ "gl.supports_NPOT" ] = this . _supportsNPOT ;
245
+
137
246
this . _supportsBGRA8888 = this . checkForGLExtension ( "GL_IMG_texture_format_BGRA888" ) ;
247
+ locValueDict [ "gl.supports_BGRA8888" ] = this . _supportsBGRA8888 ;
248
+
138
249
this . _supportsDiscardFramebuffer = this . checkForGLExtension ( "GL_EXT_discard_framebuffer" ) ;
250
+ locValueDict [ "gl.supports_discard_framebuffer" ] = this . _supportsDiscardFramebuffer ;
139
251
140
252
this . _supportsShareableVAO = this . checkForGLExtension ( "vertex_array_object" ) ;
253
+ locValueDict [ "gl.supports_vertex_array_object" ] = this . _supportsShareableVAO ;
141
254
142
- cc . log ( "cocos2d: GL_MAX_TEXTURE_SIZE: " + this . _maxTextureSize ) ;
143
- cc . log ( "cocos2d: GL_MAX_TEXTURE_UNITS: " + this . _maxTextureUnits ) ;
144
- cc . log ( "cocos2d: GL supports PVRTC: " + ( this . _supportsPVRTC ? "YES" : "NO" ) ) ;
145
- cc . log ( "cocos2d: GL supports BGRA8888 textures: " + ( this . _supportsBGRA8888 ? "YES" : "NO" ) ) ;
146
- cc . log ( "cocos2d: GL supports NPOT textures: " + ( this . _supportsNPOT ? "YES" : "NO" ) ) ;
147
- cc . log ( "cocos2d: GL supports discard_framebuffer: " + ( this . _supportsDiscardFramebuffer ? "YES" : "NO" ) ) ;
148
- cc . log ( "cocos2d: GL supports shareable VAO: " + ( this . _supportsShareableVAO ? "YES" : "NO" ) ) ;
255
+ cc . CHECK_GL_ERROR_DEBUG ( ) ;
256
+ } ,
149
257
150
- if ( cc . ENABLE_GL_STATE_CACHE == 0 )
151
- cc . log ( "cocos2d: **** WARNING **** CC_ENABLE_GL_STATE_CACHE is disabled. To improve performance, enable it by editing ccConfig.h" ) ;
258
+ /**
259
+ * Loads a config file. If the keys are already present, then they are going to be replaced. Otherwise the new keys are added.
260
+ * @param {string } filename
261
+ */
262
+ loadConfigFile : function ( filename ) {
263
+ var fileUtils = cc . FileUtils . getInstance ( ) ;
264
+ var fullPath = fileUtils . fullPathForFilename ( filename ) ;
265
+ var dict = fileUtils . dictionaryWithContentsOfFileThreadSafe ( fullPath ) ;
152
266
153
- cc . CHECK_GL_ERROR_DEBUG ( ) ;
154
- return true ;
267
+ if ( dict == null )
268
+ return ;
269
+
270
+ var getDatas = dict [ "data" ] ;
271
+ if ( ! getDatas ) {
272
+ cc . log ( "Expected 'data' dict, but not found. Config file: " + filename ) ;
273
+ return ;
274
+ }
275
+
276
+ // Add all keys in the existing dictionary
277
+ for ( var selKey in getDatas )
278
+ this . _valueDict [ selKey ] = getDatas [ selKey ] ;
155
279
}
156
280
} ) ;
157
281
0 commit comments