[ad_1]
So in a recreation with varied objects that carry out varied duties, a naive method would merely be to replace the state of all of the prevailing objects on this planet each recreation replace. That is what Minecraft does to deal with furnaces, and related objects. A extra environment friendly method can be to schedule a process sooner or later, for instance, when the subsequent merchandise will likely be smelted. Then solely the present occasions must be processed relatively than all of them each replace.
An implementation of this is able to be to have a sorted checklist, and each replace, the beginning of the checklist is iterated and the objects processed till a listing merchandise is reached that’s scheduled to happen in a future replace.
However what information construction can be best suited?
- If I exploit a straight array, then just one allocation is used, however each time a component is inserted or eliminated, that may incur a shift of the remaining parts.
O(n)
complexity. The right insertion level for an occasion scheduled to happen at an arbitrary time could possibly be discovered through binary search withO(log n)
complexity. - If I exploit a linked checklist, then deleting the primary few parts scheduled to happen within the present replace wouldn’t entail traversing the whole checklist. However scheduling a brand new occasion would entail doing so, so as to discover the right insertion level.
What information construction can be best suited for a consistently altering, ordered set like a scheduled occasions checklist? To date my solely choices have linear complexity for insertion and/or deletion. Is there a good higher information construction that may have logarithmic or fixed time complexity for that?
[ad_2]