a,serious problem

Software: Away3D 4.x

datouaizi, Member
Posted: 04 March 2012 12:53 AM   Total Posts: 98

I clone 3dsmodel just plane with bitmap material 1000 pieces ,then remove them,then create same count planes, use
for method,then remove,create…  every time the creating time more then the before,until firefox dead.cpu 100%.

first time 1s,then 3s.then 6s…  dead!

   

Alex Bogartz, Sr. Member
Posted: 04 March 2012 01:02 AM   Total Posts: 216   [ # 1 ]

Without seeing your code I can’t give you a precise answer, but if you know you’re going to be creating a large number of items, but never a large number at the same time, you should look into creating an object pool.

It’s basically a vector of premade objects of a certain type with check in, check out functions.  When you check out an object, you mark it as unavailable, when you check it in, mark it as available.  When you ask for a new one, simply pick the first available.  This way you only make a handful of items and your memory never goes up.

http://help.adobe.com/en_US/as3/mobile/WS948100b6829bd5a6-19cd3c2412513c24bce-8000.html

 

   

datouaizi, Member
Posted: 04 March 2012 09:00 AM   Total Posts: 98   [ # 2 ]

private function creatDataBrick():void
{
var startTime:Date = new Date();
 
var len:int = brickData_arr.length;

if (len > 0)
{
  var pos:Vector3D;
  var brick_row:int;
  var brick_col:int;
  var modeName:String;
  var brickName:String;

  var X:int;
  var Y:int;
  var Z:int;
 
  var num:int = 0 ;
  var u:int = 0 ;

  brickID = len - 1;

  for (var i:int = 0; i < len; i++)
  {
   
  if (brickData_arr && brickData_arr != null)
  {
  X = brickData_arr[1].x;
  Y = brickData_arr[1].y;
  Z = brickData_arr[1].z;
  pos = new Vector3D(X,Y,Z);

  modeName = brickData_arr[2];
  brickName = brickData_arr[0];

  brick = new Furniture(model,modeName);
  brick.name = brickName;
   
  if (Y == 2.5)
  {
    createBrickLayer(1);
    floor_arr[1].addChild(brick);
   
  }
  else if(Y == 5)
  {
    createBrickLayer(2);
    floor_arr[2].addChild(brick);
   
  }
  else if(Y == 0)
  {
    createBrickLayer(0);
      if(floor_arr[0])
      {
                                                        ObjectContainer3D(floor_arr[0]).addChild(brick);
   
  }
   
  }
   
  brick.pos = pos;
    //num++ ;

  }
}
}

 

   

datouaizi, Member
Posted: 04 March 2012 09:06 AM   Total Posts: 98   [ # 3 ]

brickdata_arr length is not fixed.

 

   

Alex Bogartz, Sr. Member
Posted: 04 March 2012 04:09 PM   Total Posts: 216   [ # 4 ]

Basically you’re using a lot of “new()”.  You’re saying:

brick = new Furniture(model,modeName);

So that creates a new mesh and texture to place into memory.  You’re also creating 1000 new vectors.  So start looking into object pools and create a single object that you re-use, even where you’re creating new vectors or points.  It’s a little time consuming but you’ll see some benefits.  Also, you can create a generic object pool class that will come in handy for things like bullets or particles.

 

   

datouaizi, Member
Posted: 05 March 2012 06:51 AM   Total Posts: 98   [ # 5 ]

var furniture:Furniture = new Furniture(model,furnitureName);
objcetPool.push(furniture);

that`s my creating furniture code. model is 3ds file ,furnitureName is element name,maybe chair or desk or TV .

how to check the furniture element is not the same .

like (the sims 2) game; 

do you have MSN ?

thank u!

 

   

datouaizi, Member
Posted: 05 March 2012 07:26 AM   Total Posts: 98   [ # 6 ]

here is my code file .

I am just a new flasher . Kindly give me your advice please !

my MSN is .(JavaScript must be enabled to view this email address)

 

File Attachments
main.as  (File Size: 116KB - Downloads: 308)
   
   

X

Away3D Forum

Member Login

Username

Password

Remember_me



X