A collection with quick delete / iteration / insert that processes objects in Android / Java programs?

I am programming a game for Android. For example, a game may include bullets, enemies, gems, etc., which should be:

  • created and destroyed in the game world during the game, for example. A bullet is a fire, and then disappears when it hits a wall.

  • access to the set sequentially, for example. all updated in sequence, then everything is in order.

Based on what I still know from my work in Android, in order to maintain frame rate, I need to consider the following:

  • Do not select objects when you do not need it, because the garbage collector will kick and destroy your frame rate.

  • They prefer, for example, a local access variable to access object fields and calling functions.

For the game objects mentioned above in a computer game, I usually used something like Vector or LinkedList. However, they will not recycle the objects, and using Iterator will create a new object and also call several function calls during iteration.

What is a suitable collection?

What I found works well at the moment, is to create, for example, a standard array of 100 bullets in which all 100 bullets are created in advance. Then I save the number of active bullets when all active bullets appear at the beginning of the array. Whenever I repeat an array of bullets and I need to destroy it, I simply replace the current bullet index with the last active bullet index, and then reduce the number of active bullets. This changes the order of the bullet, but it's fine.

This works pretty well:

: , / : , ( ),

- ? , , .

.

+5
2

80-, Java . , , LinkedList Vector Java, , , . , . , " ". , .

, , "" ( " ", " " , ).

(20,30,3) (10, 50, 2) (30, 40, -3) (50, 50, 5)

, (20,30) 3 ( 3 , ) ( , ), (10,50) 2 , 3 (30,40), 3 ( ), (50,50,5) 5 .

?

, int []:

int [] = {4, 20, 30, 3, 10, 50, 2, 30, 40, -3, 50, 50, 5,...,...,...};

4 , " 4 . , 3 ( ).

, 2 , ?

:

int [] = {3, 20, 30, 3, 50, 50, 5, 30, 40, -3, 50, 50, 5,...,...,...};

int 3, , 3 , (50, 50, 5) "2", (10, 50,2) - (50, 50, 5). , ( ), " [] " ".

, "" " ": (50,50,5) , , 3 , .

, :

int [] = {3, 20, 30, 3, 50, 50, 5, 30, 40, -3, 50, 50, 5,...,...,...};

:

int [] = {3, 20, 30, 3, 50, 50, 5, 30, 40, -3,...,...,...,...,...,...};

THAT, : " " . , .

int [] , /.

" ".

, Java- - , , LinkedList Vector, , : 50 GC.

, , , OO : , , , .

"" ( ) 3 . ;)

: , , ennemies, , , whatnots:)

, , , / , , , , Vector LinkedList.

+7

, /

:

- . - , , . , , , , , .

, , .

+2

All Articles