Skip to content

Commit 14453f7

Browse files
authored
Merge pull request cocos2d#3138 from IShm/memory_utilization_armatureDM
clear relative data
2 parents 38c8ec5 + a9a261e commit 14453f7

File tree

1 file changed

+40
-36
lines changed

1 file changed

+40
-36
lines changed

extensions/cocostudio/armature/utils/CCArmatureDataManager.js

Lines changed: 40 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -27,19 +27,19 @@
2727
* RelativeData uses to save plist files, armature files, animations and textures for armature data manager.
2828
* @constructor
2929
*/
30-
ccs.RelativeData = function(){
31-
this.plistFiles=[];
32-
this.armatures=[];
33-
this.animations=[];
34-
this.textures=[];
30+
ccs.RelativeData = function () {
31+
this.plistFiles = [];
32+
this.armatures = [];
33+
this.animations = [];
34+
this.textures = [];
3535
};
3636

3737
/**
3838
* ccs.armatureDataManager is a singleton object which format and manage armature configuration and armature animation
3939
* @class
4040
* @name ccs.armatureDataManager
4141
*/
42-
ccs.armatureDataManager = /** @lends ccs.armatureDataManager# */{
42+
ccs.armatureDataManager = /** @lends ccs.armatureDataManager# */ {
4343
_animationDatas: {},
4444
_armatureDatas: {},
4545
_textureDatas: {},
@@ -52,23 +52,23 @@ ccs.armatureDataManager = /** @lends ccs.armatureDataManager# */{
5252
* Removes armature cache data by configFilePath
5353
* @param {String} configFilePath
5454
*/
55-
removeArmatureFileInfo:function(configFilePath){
55+
removeArmatureFileInfo: function (configFilePath) {
5656
var data = this.getRelativeData(configFilePath);
57-
if(data){
57+
if (data) {
5858
var i, obj;
5959
for (i = 0; i < data.armatures.length; i++) {
6060
obj = data.armatures[i];
6161
this.removeArmatureData(obj);
6262
}
63-
for ( i = 0; i < data.animations.length; i++) {
63+
for (i = 0; i < data.animations.length; i++) {
6464
obj = data.animations[i];
6565
this.removeAnimationData(obj);
6666
}
67-
for ( i = 0; i < data.textures.length; i++) {
67+
for (i = 0; i < data.textures.length; i++) {
6868
obj = data.textures[i];
6969
this.removeTextureData(obj);
7070
}
71-
for ( i = 0; i < data.plistFiles.length; i++) {
71+
for (i = 0; i < data.plistFiles.length; i++) {
7272
obj = data.plistFiles[i];
7373
cc.spriteFrameCache.removeSpriteFramesFromFile(obj);
7474
}
@@ -82,9 +82,9 @@ ccs.armatureDataManager = /** @lends ccs.armatureDataManager# */{
8282
* @param {string} id The id of the armature data
8383
* @param {ccs.ArmatureData} armatureData
8484
*/
85-
addArmatureData:function (id, armatureData, configFilePath) {
85+
addArmatureData: function (id, armatureData, configFilePath) {
8686
var data = this.getRelativeData(configFilePath);
87-
if (data){
87+
if (data) {
8888
data.armatures.push(id);
8989
}
9090
this._armatureDatas[id] = armatureData;
@@ -95,7 +95,7 @@ ccs.armatureDataManager = /** @lends ccs.armatureDataManager# */{
9595
* @param {String} id
9696
* @return {ccs.ArmatureData}
9797
*/
98-
getArmatureData:function (id) {
98+
getArmatureData: function (id) {
9999
var armatureData = null;
100100
if (this._armatureDatas) {
101101
armatureData = this._armatureDatas[id];
@@ -107,7 +107,7 @@ ccs.armatureDataManager = /** @lends ccs.armatureDataManager# */{
107107
* Removes armature data from armature data manager.
108108
* @param {string} id
109109
*/
110-
removeArmatureData:function(id){
110+
removeArmatureData: function (id) {
111111
if (this._armatureDatas[id])
112112
delete this._armatureDatas[id];
113113
},
@@ -117,9 +117,9 @@ ccs.armatureDataManager = /** @lends ccs.armatureDataManager# */{
117117
* @param {String} id
118118
* @param {ccs.AnimationData} animationData
119119
*/
120-
addAnimationData:function (id, animationData, configFilePath) {
120+
addAnimationData: function (id, animationData, configFilePath) {
121121
var data = this.getRelativeData(configFilePath);
122-
if(data)
122+
if (data)
123123
data.animations.push(id);
124124
this._animationDatas[id] = animationData;
125125
},
@@ -129,7 +129,7 @@ ccs.armatureDataManager = /** @lends ccs.armatureDataManager# */{
129129
* @param {String} id
130130
* @return {ccs.AnimationData}
131131
*/
132-
getAnimationData:function (id) {
132+
getAnimationData: function (id) {
133133
var animationData = null;
134134
if (this._animationDatas[id]) {
135135
animationData = this._animationDatas[id];
@@ -141,7 +141,7 @@ ccs.armatureDataManager = /** @lends ccs.armatureDataManager# */{
141141
* Removes animation data
142142
* @param {string} id
143143
*/
144-
removeAnimationData:function(id){
144+
removeAnimationData: function (id) {
145145
if (this._animationDatas[id])
146146
delete this._animationDatas[id];
147147
},
@@ -151,7 +151,7 @@ ccs.armatureDataManager = /** @lends ccs.armatureDataManager# */{
151151
* @param {String} id
152152
* @param {ccs.TextureData} textureData
153153
*/
154-
addTextureData:function (id, textureData, configFilePath) {
154+
addTextureData: function (id, textureData, configFilePath) {
155155
var data = this.getRelativeData(configFilePath);
156156
if (data) {
157157
data.textures.push(id);
@@ -164,7 +164,7 @@ ccs.armatureDataManager = /** @lends ccs.armatureDataManager# */{
164164
* @param {String} id
165165
* @return {ccs.TextureData}
166166
*/
167-
getTextureData:function (id) {
167+
getTextureData: function (id) {
168168
var textureData = null;
169169
if (this._textureDatas) {
170170
textureData = this._textureDatas[id];
@@ -176,7 +176,7 @@ ccs.armatureDataManager = /** @lends ccs.armatureDataManager# */{
176176
* Removes texture data by id
177177
* @param {string} id
178178
*/
179-
removeTextureData:function(id){
179+
removeTextureData: function (id) {
180180
if (this._textureDatas[id])
181181
delete this._textureDatas[id];
182182
},
@@ -192,9 +192,9 @@ ccs.armatureDataManager = /** @lends ccs.armatureDataManager# */{
192192
* //example2
193193
* ccs.armatureDataManager.addArmatureFileInfo("res/test.png","res/test.plist","res/test.json");
194194
*/
195-
addArmatureFileInfo:function (/*imagePath, plistPath, configFilePath*/) {
195+
addArmatureFileInfo: function ( /*imagePath, plistPath, configFilePath*/ ) {
196196
var imagePath, plistPath, configFilePath;
197-
switch(arguments.length){
197+
switch (arguments.length) {
198198
case 1:
199199
configFilePath = arguments[0];
200200

@@ -224,16 +224,16 @@ ccs.armatureDataManager = /** @lends ccs.armatureDataManager# */{
224224
* @param {Function} selector
225225
* @param {Object} target
226226
*/
227-
addArmatureFileInfoAsync:function (/*imagePath, plistPath, configFilePath, selector, target*/) {
227+
addArmatureFileInfoAsync: function ( /*imagePath, plistPath, configFilePath, selector, target*/ ) {
228228
var imagePath, plistPath, configFilePath, target, selector;
229-
switch(arguments.length){
229+
switch (arguments.length) {
230230
case 3:
231231
configFilePath = arguments[0];
232232
target = arguments[2];
233233
selector = arguments[1];
234234
this.addRelativeData(configFilePath);
235235
this._autoLoadSpriteFile = true;
236-
ccs.dataReaderHelper.addDataFromFileAsync("", "", configFilePath, selector,target);
236+
ccs.dataReaderHelper.addDataFromFileAsync("", "", configFilePath, selector, target);
237237
break;
238238
case 5:
239239
imagePath = arguments[0];
@@ -255,9 +255,9 @@ ccs.armatureDataManager = /** @lends ccs.armatureDataManager# */{
255255
* @param {String} imagePath
256256
* @param {String} configFilePath
257257
*/
258-
addSpriteFrameFromFile:function (plistPath, imagePath, configFilePath) {
258+
addSpriteFrameFromFile: function (plistPath, imagePath, configFilePath) {
259259
var data = this.getRelativeData(configFilePath);
260-
if(data)
260+
if (data)
261261
data.plistFiles.push(plistPath);
262262
ccs.spriteFrameCacheHelper.addSpriteFrameFromFile(plistPath, imagePath);
263263
},
@@ -266,36 +266,36 @@ ccs.armatureDataManager = /** @lends ccs.armatureDataManager# */{
266266
* Returns whether or not need auto load sprite file
267267
* @returns {boolean}
268268
*/
269-
isAutoLoadSpriteFile:function(){
269+
isAutoLoadSpriteFile: function () {
270270
return this._autoLoadSpriteFile;
271271
},
272272

273273
/**
274274
* Returns armature Data of Armature data manager.
275275
* @return {Object}
276276
*/
277-
getArmatureDatas:function () {
277+
getArmatureDatas: function () {
278278
return this._armatureDatas;
279279
},
280280

281281
/**
282282
* Returns animation data of Armature data manager.
283283
* @return {Object}
284284
*/
285-
getAnimationDatas:function () {
285+
getAnimationDatas: function () {
286286
return this._animationDatas;
287287
},
288288

289289
/**
290290
* Returns texture data of Armature data manager.
291291
* @return {Object}
292292
*/
293-
getTextureDatas:function () {
293+
getTextureDatas: function () {
294294
return this._textureDatas;
295295
},
296296

297297
/**
298-
* Adds Relative data of Armature data manager.
298+
* Adds RelativeData of Armature data manager.
299299
* @param {String} configFilePath
300300
*/
301301
addRelativeData: function (configFilePath) {
@@ -315,11 +315,15 @@ ccs.armatureDataManager = /** @lends ccs.armatureDataManager# */{
315315
/**
316316
* Clear data
317317
*/
318-
clear: function() {
318+
clear: function () {
319+
for (var key in this._relativeDatas) {
320+
this.removeArmatureFileInfo(key);
321+
}
319322
this._animationDatas = {};
320323
this._armatureDatas = {};
321324
this._textureDatas = {};
325+
this._relativeDatas = {};
322326
ccs.spriteFrameCacheHelper.clear();
323327
ccs.dataReaderHelper.clear();
324328
}
325-
};
329+
};

0 commit comments

Comments
 (0)