简体   繁体   English

碰撞检测矩阵-快速移除和添加阵列

[英]Collision detection matrix - fast array removal and addition

I am creating a custom collision detection matrix. 我正在创建一个自定义的碰撞检测矩阵。 When my objects fall within a certain matrix I place them in a category and only check collision within that category. 当我的对象落在某个矩阵内时,我将它们放在一个类别中,仅检查该类别内的碰撞。 That is because I am creating hundreds of thousands of objects. 那是因为我正在创建数十万个对象。 Right now I am using two to three ArrayLists to add and remove things. 现在,我正在使用两到三个ArrayList来添加和删除内容。 What would be the most efficient class to use for this kind of behavior 什么是最有效的用于此类行为的类

//master object list
//matrix list
//checks all the master object list and if something meets criteria place in the specific matrix list
//remove from matrix list when no longer meets criteria

as you can imagine I am doing thousands upon thousands of loops so what datatype/class can allow me to quickly add and remove items from an array like object. 可以想象,我正在做成千上万的循环,所以什么样的数据类型/类可以让我快速地从对象之类的数组中添加和删除项目。

It seems like just a simple LinkedList would suffice for you here. 在这里看起来像一个简单的LinkedList就足够了。

You just want to iterate through the "master" list, and if it meets a criteria add to the "matrix" list? 您只想遍历“主”列表,如果符合条件,则添加到“矩阵”列表中? Iteration would be O(n) and adding to the end of a linked list is O(1). 迭代将是O(n),并且添加到链接列表的末尾将是O(1)。

Then, you want to iterate through the "matrix" list and remove any that no longer meet the criteria? 然后,您要遍历“矩阵”列表并删除不再符合条件的列表? Again, you can iterate through this list in O(n) and removals are O(1) for a linked list. 同样,您可以在O(n)中循环访问此列表,而对链表的删除为O(1)。

Of course if you do not want to iterate through the whole matrix list to find the ones that need to be removed, then you can get fancier depending on the criteria, how it is updated, etc. 当然,如果您不想遍历整个矩阵列表以查找需要删除的列表,则可以根据条件,更新方式等来获得更高级的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM