From a833ef0770548dca1ca2d9b804bd1ede54b36e31 Mon Sep 17 00:00:00 2001 From: Matei Date: Sat, 15 Jul 2006 21:17:02 +0000 Subject: [PATCH] Optimized entityInitQuasi to reduce number of CJSComplex property accesses, and fixed a bug in performGather. This was SVN commit r4119. --- .../mods/official/scripts/entity_functions.js | 35 +++++++++++-------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/binaries/data/mods/official/scripts/entity_functions.js b/binaries/data/mods/official/scripts/entity_functions.js index 5c77bd471c..5ad5772656 100644 --- a/binaries/data/mods/official/scripts/entity_functions.js +++ b/binaries/data/mods/official/scripts/entity_functions.js @@ -350,27 +350,28 @@ function entityInitQuasi() startXTimer(6); - if (this.traits.supply) + var s = this.traits.supply; + if (s) { // If entity has supply, set current to same. - if (this.traits.supply.max) - this.traits.supply.curr = this.traits.supply.max; + s.curr = s.max; // If entity has type of supply and no subtype, set subtype to same // (so we don't have to say type="wood", subtype="wood" - if (this.traits.supply.type && !this.traits.supply.subtype) - this.traits.supply.subtype = this.traits.supply.type; + if (s.type && !s.subtype) + s.subtype = s.type; // The "dropsitecount" array holds the number of units with gather aura in range of the object; // this is important so that if you have two mills near something and one of them is destroyed, // you can still gather from the thing. Initialize it to 0 (ungatherable) for every player unless // the entity is forageable (e.g. for huntable animals). - this.traits.supply.dropsitecount = new Array(); - initialCount = this.traits.supply.subtype.meat ? 1 : 0; + var ar = new Array(); + initialCount = s.subtype.meat ? 1 : 0; for( i=0; i<=8; i++ ) { - this.traits.supply.dropsitecount[i] = initialCount; + ar[i] = initialCount; } + s.dropsitecount = ar; } stopXTimer(6); @@ -380,19 +381,21 @@ function entityInitQuasi() var id = this.traits.id; if (id && id.civ) { - id.civ_code = id.civ.toString().substring (0, 4); - id.civ_code = id.civ_code.toString().toLowerCase(); + var civCode = id.civ.toString().substring (0, 4); + civCode = civCode.toString().toLowerCase(); // Exception to make the Romans into rome. - if (id.civ_code == "roma") id.civ_code = "rome"; + if (civCode == "roma") civCode = "rome"; // Exception to make the Hellenes into hele. - if (id.civ_code == "hell") id.civ_code = "hele"; + if (civCode == "hell") civCode = "hele"; + + id.civ_code = civCode; } stopXTimer(7); startXTimer(8); - if(!this.traits.id) + if(!id) { this.traits.id = new Object(); } @@ -419,6 +422,7 @@ function entityInitQuasi() startXTimer(9); + // ~100 MS with ob = new Object() as above, ~400 MS with ob = this if (ob.traits.id && ob.traits.id.civ) { var id = ob.traits.id; @@ -671,11 +675,12 @@ function performGather( evt ) { if( s.curr <= gather_amt ) { - gather_amt = s.curr; + gather_amt = s.curr.valueOf(); } - + // Remove amount from target. s.curr -= gather_amt; + // Add extracted resources to player's resource pool. this.player.resources[s.type.toString()] += gather_amt;