Delete oldest Actor - Perfomance Issues

Hello,

i need a little bit of help. I have a working solution, but its very ineffective and causing huge frame drops.
So maybe someone of you know a better way.

Gameinfo: Everytime when you move the finger on the screen, a spawner spawns a line (consists of a lot of small actors (called LineActor for now) along the finger move. The line gets destroyed when moving out of screen or when the device is shaken.

Goal I want to archive: When a certain limit of LineActors is reached it should destroy the oldest line actor.

Here my solution:

I have these game. attributes: game.Total Count ; game.ActorsAlive
In the LineActor: self.ID; self.rowForDelete; self.currentTableRow
And a LineActorTable with Columns: ActorID(int) and DeleteMe(int)

Now the logic:

Spawner:
Before each spawn, I check if a Limit (50 at the moment) is reached.
If its reached then in ChangeTableValue: Row 1 (because this should be the oldest) Column 2 —> 1 (please look at LineActor explanation for the Reason)

LineActor:
game.ActorsAlive + 1;
game.TotalCount + 1;
Self.ID = game.TotalCount
And Add Table Row at End

ChangeTable(LineActorTable)
Row: TableRowCount(LineActorTable) -1
Column: 1 = self.ID

Short explanation:
So the Counter is counting up with every spawn and its always creating a new row at the and
with the ID of the current cloud.
So the newest are always at the bottom of the table and oldest are at the top.

Than an Rule which always check if Row: 1 and Column: 1 is same as the current ID and if
Column 2 is 1 (1 stands for true). If this is true, delete first row and Actors alive -1 and delete this actor.

This part is working fine. Eveyrtime when the limit is reached it deletes the first row and the lineActor. But like mentioned above, there are some other possibilities which are destroying the LineActor. Par example when moving Out of Screen.
So I’ve to find the correct table entry and delete it.

Here the Rule:
Rule: When Out of Screen
Rule: self.currentTableRow <= TableRowCount(LineActor) (looping over each table Row)
Rule: TableCellValue(LineActorTable, currentTableRow, 1) == self.ID
- Than Remove this Row and destroy actor and so on

Explanation: Rule is looping over the table until its find the current ID and than delete this row + lineActor.

The problem is when there are 50 LineActors moving Out of Screen at the same time and within each actor its searching the Row, this has a heavy impact on the frame rate. And not all LineActors are destroying by this way, maybe because there are overlapping when deleting the Rows and some of them couldn’t find their ID in the table.

I’m sure that there is a much more effective and simpler way but I’m not getting it.

Thanks to everybody who has red this bunch of text. If I’m explaining it to complicated, I can upload a Demo. Please tell me.

Thank you guys
Justin

Comments

  • JayJayDJayJayD Member Posts: 48
    edited September 2015

    Still stucking at this problem. Anyone here who can help?

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    Thats a lot of information! Not sure I can catch it all.

    First, if you want to delete an actor when it is out of the scene -- its easiest to just test to see it it is out of the scene and then delete it. No tables need be consulted.

    Second, if you want to delete those line actors just check its ID number. If self.ID is less than game.TotalCount-50 then destroy.

  • JayJayDJayJayD Member Posts: 48

    I can't believe it.. It is working! Thank you so much!
    Such a simple rule replaces my complicated bunch of code.

    Thanks, have a great day ;)

  • RThurmanRThurman Member, Sous Chef, PRO Posts: 2,880

    You are welcome! Glad its working for you.

Sign In or Register to comment.