begin process at 2008 07 20 13:51:17
1 213 234 membres
151 nouveaux aujourd'hui
14 166 membres club

Vous ne trouvez pas de réponse à votre problème ? Alors posez la question dans le forum.
Souvenez-vous qu'il n'y a jamais de question bête, mais rester dans l'ignorance parce que l'on n'ose pas poser une question, ça c'est une erreur !

Sujet : Mon code mange toute la mémoire ! [ Scripts / ActionScript ] (barn333)

Mon code mange toute la mémoire ! le 20/02/2007 16:18:40

barn333
Bonjour, je suis un super noob et je bricole des trucs en récupérant des fragments de code ici et là. l'anime tourne bien mais ralentir fortement au bout d'un certain temps je pense que le problème vient des nombreuses variables qui restent après utilisations mais je ne sais pas trop comment les gérer. merci d'avance pour vos conseils voici le code : // menu bneutre.swapDepths(1000000); borange.swapDepths(1000001); brouge.swapDepths(1000002); bvert.swapDepths(1000003); bnoir.swapDepths(1000004); bbleu.swapDepths(1000005); bneutre.onPress = function() { Entite.apply(); } borange.onPress = function() { nb_orange++ ; Orange.apply(); } brouge.onPress = function() { nb_rouge++ ; Rouge.apply(); } bvert.onPress = function() { nb_vert++ ; Vert.apply(); } bnoir.onPress = function() { nb_noir++ ; Noir.apply(); } bbleu.onPress = function() { nb_bleu++ ; Bleu.apply(); } // params control = "ok"; repr = "ok"; repo = "ok"; repv = "ok"; repn = "ok"; repb = "ok"; LARG = Stage.width; HAUT = Stage.height; nb_points_courbe = 12; nb_entite = 0; tb_entite = []; nb_orange = 0; tb_orange = []; nb_rouge = 0; tb_rouge = []; nb_vert = 0; tb_vert = []; nb_noir = 0; tb_noir = []; nb_bleu = 0; tb_bleu = []; _global.PI_4 = Math.PI / 4; /// ------Creation bordure -------- _root.createEmptyMovieClip("circuit", 100); // ----------------entite---------------------------------------- Entite = function(caste,val) { this.caste = "entite"; this.val = "vale"; nb_entite++; var entite = _root.createEmptyMovieClip(caste + "_" + nb_entite, 20000 + nb_entite); tb_entite.push(entite); entite.lineStyle(9, 0xcccccc); entite.lineTo(0, 1); entite.lineStyle(5, 0xffffff); entite.lineTo(0.2, 0.2); entite._x = LARG / 3 + Math.floor(Math.random()*333+1) ; entite._y = HAUT / 3 + Math.floor(Math.random()*333+1) ; entite.vitesse = 0; entite.virage = 0; entite.vitesse_maxi = 10// + nb_entite / 5; var palp = _root.createEmptyMovieClip("palpeur_" + nb_entite, -1500 + nb_entite); entite.palpeur = palp; // val orange if (val == "valo") { entite.lineStyle(9, 0xcc6600); entite.lineTo(0, 10); entite.lineStyle(6, 0xff9900); entite.lineTo(0.2, 0.2); tb_orange.push(entite); } // val rouge if (val == "valr") { entite.lineStyle(9, 0xaa0000); entite.lineTo(0, 10); entite.lineStyle(6, 0xff5555); entite.lineTo(0.2, 0.2); tb_rouge.push(entite); } // val vert if (val == "valv") { entite.lineStyle(9, 0x00aa00); entite.lineTo(0, 10); entite.lineStyle(6, 0x00ff00); entite.lineTo(0.2, 0.2); tb_vert.push(entite); } // val noir if (val == "valn") { entite.lineStyle(9, 0x000000); entite.lineTo(0, 10); entite.lineStyle(6, 0xaaaaaa); entite.lineTo(0.2, 0.2); tb_noir.push(entite); } // val bleu if (val == "valb") { entite.lineStyle(9, 0x0000aa); entite.lineTo(0, 10); entite.lineStyle(6, 0x5555ff); entite.lineTo(0.2, 0.2); tb_bleu.push(entite); } // ------- supprimer--------------- MovieClip.prototype.confrontation = function(){ if (control == "ok") { for (var i = 0; i < nb_entite+1; i++) { for (var j = 0; j < nb_entite+1; j++) { vicr = tb_rouge[i]; vicv = tb_vert[i]; vico = tb_orange[i]; vicn = tb_noir[i]; vicb = tb_bleu[i]; // ---sup rouge-------- if (vicr.hitTest(tb_orange[j]) || vicr.hitTest(tb_noir[j])) { removeMovieClip(vicr); nb_rouge-- ;} // ---sup orange-------- if (vico.hitTest(tb_vert[j])) { removeMovieClip(vico); nb_orange-- ;} // ---sup vert-------- if (vicv.hitTest(tb_noir[j]) || vicv.hitTest(tb_rouge[j])) { removeMovieClip(vicv); nb_vert-- ;} // ---sup noir-------- if (vicn.hitTest(tb_orange[j])) { removeMovieClip(vicn); nb_noir-- ;} // ---sup bleu-------- if (vicb.hitTest(tb_noir[j]) || vicb.hitTest(tb_rouge[j]) || vicb.hitTest(tb_vert[j])) { removeMovieClip(vicb); nb_bleu-- ;} }}} }; // ------- reproduction--------------- MovieClip.prototype.reproduction = function(){ if (control == "ok") { for (var i = 0; i < nb_entite+1; i++) { for (var j = 0; j < nb_entite+1; j++) { // ---rep rouge-------- if (repr == "ok" && i != j && tb_rouge[i].hitTest(tb_rouge[j])) { nb_rouge++ ; Rouge.apply(); repr = "bad";} // ---rep orange-------- if (repo == "ok" && i != j && tb_orange[i].hitTest(tb_orange[j])) { nb_orange++ ; Orange.apply(); repo = "bad";} // ---rep vert-------- if (repv == "ok" && i != j && tb_vert[i].hitTest(tb_vert[j])) { nb_vert++ ; Vert.apply(); repv = "bad";} // ---rep noir-------- if (repn == "ok" && i != j && tb_noir[i].hitTest(tb_noir[j])) { nb_noir++ ; Noir.apply(); repn = "bad";} // ---rep bleu-------- if (repb == "ok" && i != j && tb_bleu[i].hitTest(tb_bleu[j])) { nb_bleu++ ; Bleu.apply(); repb = "bad";} if (repb == "ok" && i != j && tb_bleu[i].hitTest(tb_orange[j])) { nb_bleu++ ; Bleu.apply(); repb = "bad";} }} control = "bad";} }; }; // fin création entite // orange ------- Orange = function() { var orange = new Entite("orange", "valo"); }; // rouge ------- Rouge = function() { var rouge = new Entite("rouge", "valr"); }; // vert ------- Vert = function() { var vert = new Entite("vert", "valv"); }; // noir ------- Noir = function() { var noir = new Entite("noir", "valn"); }; // bleu ------- Bleu = function() { var bleu = new Entite("bleu", "valb"); }; // -------creation des points d'ancrage de la bordure ---- tb = []; for (var i = 0; i < nb_points_courbe; i++) { tb[i] = createEmptyMovieClip("c" + i, i); phase = 2 * Math.PI * i / nb_points_courbe; with (tb[i]) { lineStyle(0, 0, 0); lineTo(0, 1); _x = LARG / 2 + LARG / 2 * Math.sin(phase); _y = HAUT / 2 + HAUT / 2 * Math.cos(phase); } tb[i]._x0 = tb[i]._x; tb[i]._y0 = tb[i]._y; } // --------permet de tracé de la bordure ----------- MovieClip.prototype.polycourbe_JL = function(epaisseur, couleur, transparence) { this.clear(); this.beginFill(couleur, 100); this.moveTo(0, 0); this.lineTo(LARG, 0); this.lineTo(LARG, HAUT); this.lineTo(0, HAUT); this.lineTo(0, 0); this.lineStyle(epaisseur, couleur, transparence); // ---------------------------- var ptx; var pty; var i = 0; var ptx0 = (tb[0]._x + tb[1]._x) / 2; var pty0 = (tb[0]._y + tb[1]._y) / 2; this.moveTo(ptx0, pty0); var i = 0; while (++i < tb.length - 1) { ptx = (tb[i]._x + tb[i + 1]._x) / 2; pty = (tb[i]._y + tb[i + 1]._y) / 2; this.curveTo(tb[i]._x, tb[i]._y, ptx, pty); } ptx = (tb[0]._x + tb[i]._x) / 2; pty = (tb[0]._y + tb[i]._y) / 2; this.curveTo(tb[i]._x, tb[i]._y, ptx, pty); this.curveTo(tb[0]._x, tb[0]._y, ptx0, pty0); this.lineStyle(0, couleur, transparence); this.endFill(); }; // ---------permet des mouvements harmonieux ------------ MovieClip.prototype.ANGUINEA = function(obj, duree, rebond) { //rebond = 0 ou inexistant --> normal, entre 0 et 1 rebond, conseil .7 this.ANGUI = {FL: true, OB: obj, TB: [], PT: 0}; var inc = 1 / duree; for (var n = 0; n <= 1.0; n += inc) { var s = 1 - (2 - rebond) / (n + (1 / n * (1 - rebond))); for (var prop in this.ANGUI.OB) { this.ANGUI.TB.push(this.ANGUI.OB[prop] - s * (this.ANGUI.OB[prop] - this[prop])); } } this.ID_ANGUINEA = setInterval(function (_this) { var control_fin = (_this.ANGUI.PT >= _this.ANGUI.TB.length); for (var prop in _this.ANGUI.OB) { _this[prop] = (control_fin) ? _this.ANGUI.OB[prop] : _this.ANGUI.TB[_this.ANGUI.PT++]; } if (control_fin) { delete _this.ANGUI; clearInterval(_this.ID_ANGUINEA); } }, duree, this); }; //--------mouvement de la bordure ---------------- hasard_bordure = function () { h = (h++ >= tb.length) ? 0 : h; var phase = 2 * Math.PI * h / tb.length; var px = tb[h]._x0 + random(LARG / 60) * Math.sin(phase); var py = tb[h]._y0 + random(HAUT / 60) * Math.cos(phase); clearInterval(this.ID_ANGUINEA); tb[h].ANGUINEA({_x: px, _y: py}, 50, .9); // --- ramener le robot sil sort de l'écran-- for (var j = 0; j < nb_entite; j++) { var entite = tb_entite[j]; if (entite._x < 0 || entite._x > LARG || entite._y < 0 || entite._y > HAUT) { entite._x = entite._y = HAUT / 2; } } }; // ------- mouvement du robot --------------- MovieClip.prototype.bouger = function() { this.vitesse += (this.vitesse_maxi - this.vitesse) / 12; var rot = this._rotation * Math.PI / 180; this._x += Math.sin(rot) * this.vitesse; this._y -= Math.cos(rot) * this.vitesse; }; // ---- test de chocs du robot avec son environnement --------- MovieClip.prototype.test_contact = function(autre_clip) { this._rayon = 3 + this.vitesse * 5; this._rayon_AV = 2 * this._rayon; var rot = this._rotation * Math.PI / 180; rot_plus_PI_4 = rot + PI_4; rot_moin_PI_4 = rot - PI_4; rot_plus_PI_4_AV = rot + .08; rot_moin_PI_4_AV = rot - .08; this.x1 = this._x + Math.sin((rot_plus_PI_4)) * this._rayon; this.y1 = this._y - Math.cos((rot_plus_PI_4)) * this._rayon; if (autre_clip.hitTest(this.x1, this.y1, true)) { this.virage = -2 * (this.vitesse_maxi - this.vitesse); this._rotation += this.virage; this.vitesse *= .8; } this.x2 = this._x + Math.sin((rot_moin_PI_4)) * this._rayon; this.y2 = this._y - Math.cos((rot_moin_PI_4)) * this._rayon; if (autre_clip.hitTest(this.x2, this.y2, true)) { this.virage = 2 * (this.vitesse_maxi - this.vitesse); this._rotation += this.virage; this.vitesse *= .8; } this.x3 = this._x + Math.sin(rot_plus_PI_4_AV) * this._rayon_AV; this.y3 = this._y - Math.cos(rot_plus_PI_4_AV) * this._rayon_AV; if (autre_clip.hitTest(this.x3, this.y3, true)) { this._rotation += this.virage; this.vitesse *= .4; } this.x4 = this._x + Math.sin(rot_moin_PI_4_AV) * this._rayon_AV; this.y4 = this._y - Math.cos(rot_moin_PI_4_AV) * this._rayon_AV; if (autre_clip.hitTest(this.x4, this.y4, true)) { this._rotation += this.virage; this.vitesse *= .4; } //this.Representer_palpeurs(); }; // ------------------------------------------------------- MovieClip.prototype.Representer_palpeurs = function() { with (this.palpeur) { clear(); lineStyle(0, 0xff0000, 20); moveTo(this.x1, this.y1); lineTo(this.x1, this.y1); lineTo(this.x3, this.y3); lineTo(this.x4, this.y4); lineTo(this.x2, this.y2); } }; // -------------faire bouger ------------------------------------------ function faire_bouger() { for (var i = 0; i < nb_entite; i++) { for (var j = 0; j < nb_entite; j++){ if (i != j) { tb_entite[i].test_contact(tb_entite[j]); } } tb_entite[i].test_contact(_root.circuit); tb_entite[i].bouger(); tb_entite[i].confrontation(); tb_entite[i].reproduction(); } } // ------------------------------------------------------- tracer_circuit = function () { circuit.polycourbe_JL(10, 0x999999, 100); }; // ----------- controltest -------- controltest = function () { if( control == "bad"){ control = "ok";} else { control = "bad";} }; // -----------compteur repro -------------------------------------------- repgor = function () { repr = "ok"; }; repgoo = function () { repo = "ok"; }; repgov = function () { repv = "ok"; }; repgon = function () { repn = "ok"; }; repgob = function () { repb = "ok"; }; setInterval(controltest, 100); setInterval(tracer_circuit, 70); setInterval(faire_bouger, 15); setInterval(hasard_bordure, 500); setInterval(repgor, 4000); setInterval(repgoo, 5000); setInterval(repgov, 4000); setInterval(repgon, 6000); setInterval(repgob, 2500); stop();

Re : Mon code mange toute la mémoire ! le 20/02/2007 16:21:07

barn333
cela aurait été surement mieux avec des retours à la ligne ... ^^'

Re : Mon code mange toute la mémoire ! le 20/02/2007 20:28:40

Darkrats
Sans vouloir être défetiste ... mais je crois que tu n'auras jamais de réponse avec un message comme ça

En tout cas, pas par moi, j'ai abandonné après le 3ème mot

Sorry


Bon, j'ai lu la première ligne ...
Pour la variables, celles définies dans un calque sont gardées en mémoire ... tandis que celles créées dans une fonction sont effacées une fois la fonction terminée.

Pour le reste, je peux pas t'aider, j'arrive pas à lire la suite sans une présentation correcte ... Ca serait bien aussi (si tu réécris le code) de dire à quoi il sert. Ca aidera éventuellement pour trouver la solution.

Re : Mon code mange toute la mémoire ! le 21/02/2007 14:38:10

barn333
je crois que l'on peut supprimer ce post, j'en ferais un autre plus tard un peu plus clair


Classé sous : function, math, nb, tb, entite

Participer à cet échange

Pub



Appels d'offres

Dessins techniques
Budget : 60€
Animation Flash - Doma...
Budget : 370€
Application flash medi...
Budget : 1 000€

CalendriCode

Juillet 2008
LMMJVSD
 123456
78910111213
14151617181920
21222324252627
28293031   

Téléchargements

Logiciels à télécharger sur le même thème :

Boutique

Boutique de goodies CodeS-SourceS