devilutionX icon indicating copy to clipboard operation
devilutionX copied to clipboard

Add STL-like container for entities added/removed from a fixed buffer

Open ephphatha opened this issue 4 years ago • 0 comments

One possible approach for #2586, this container represents the way Items and Missiles are used (requiring both push_back and erase) as well as Monsters and Objects (typically created soon after initialisation then mostly erased)

This is an incomplete implementation, the current test cases run but I want to be able to delete ranges (despite that not having a use case in the current code...) and ensure that the iterator definitions are actually correct. Any help will be appreciated as this certainly isn't an area I'm familiar with 😅 .

The naming scheme is meant to mirror other STL containers as much as possible. push_back should throw exceptions to match the behaviour of e.g. std::vector but I've left that commented out for now.

The aim is to extend this for entities which have an associated dungeon location array (e.g. dItems and Items). This requires different behaviour based on the entity type through so it may not be feasible for some classes. Items and Objects are "easy" in that only one entity can occupy a given tile and they don't move. Monsters (and Players) move but still have a single entity per tile making them only slightly more complicated. Multiple missiles can occupy a single tile, #2671 makes this a bit simpler in that there's no need to maintain dMissiles, but will still need to keep dFlags in sync.

Once I get AllocateItem cleaned up I intend to start using this container for Items and build on it from there, mainly opening this as a draft for feedback.

ephphatha avatar Sep 26 '21 02:09 ephphatha