slowdown and entities
BlitzMax Forums/MiniB3D Module/slowdown and entities
| ||
My game gets slower as time goes by, even though it's largely not doing very much. I think this has to do with the way i'm creating entities. i have my types for enemies ect. set out like this, which inherits from a base type: Type invincibleenemy Extends enemybase Function Create:invincibleenemy(inx:Float, iny:Float, inspeed:Float) Local n:invincibleenemy = New invincibleenemy n.speed = inspeed n.x = inx n.y = iny n.energy = 10000 * difficulty n.value = 0 n.entity = copyentity(someentity) ScaleEntity n.entity, 10, 10, 10 EntityColor n.entity, 150, 150, 150 PositionEntity n.entity, n.x,n.y,0 EntityShininess n.entity, 1 Return n End Function Method Update:Int(p1:player, enemylist:TList, bulletspeed:Float, recuables:TList) Angle = calculateAngle(x, y, p1.x, p1.y) - 90 radius = speed x = radius * Cos(Angle) + x y = radius * Sin(Angle) + y RotateEntity(entity, 0, 0, Angle) PositionEntity entity, x, - y, 0 Return False End Method End Type and i create new enemies using something like the following: local e:enemy=new enemy.create(x,y) somelist.addlast e after the enemy is killed or whatever, i loop through the list and free any entities. this works fine for max2d stuff, where the gc cleans up after me, but i'm worried that i'm creating more entities than i know how to free using this method with minib3d. Cheers Charlie |
| ||
Ok, i've managed to work out i was right. Using functions in types in the way i was using them (setting up the meshes there) is bad, as you can't free any entity you create. You should use a method to do this, not a function. what was weird was that if i did: local e:enemy=new enemy.create() list.addlast e freeentity e.entity it would free the entity from the copy entered into the list too. Cheers Charlie |