Stephen Seo [Thu, 20 Jan 2022 05:31:23 +0000 (14:31 +0900)]
Fix possible data-race with isAlive() calls
Removed isAlive() calls from functions passed to ThreadPool, and instead use an
unordered_set prior to using ThreadPool to "cache" which entities are not alive.
This is so that if a function passed to ThreadPool modifies the ECManager (e.g.
creating a new entity), then there will be no data race from also calling
isAlive(). (Note that this does not protect against "deleting" entities from the
ECManager during use of ThreadPool. It is expected for the caller to do the
"deleting" after use of stored/called functions is finished.)
Stephen Seo [Wed, 6 Nov 2019 06:47:16 +0000 (15:47 +0900)]
Replace vector with deque for Component storage
When reallocating more data, vector moves the original data to a new
buffer. Deque preserves the location of the original data, preventing
invalidated pointers to existing data when additional allocation is
required.
Stephen Seo [Thu, 11 Jul 2019 12:11:03 +0000 (21:11 +0900)]
Add fn to Manager allowing iterable indices as sig
As an alternative to forMatchingSignatures, which calls the given
function on entities matching the given Components/Tags in the
signature, forMatchingIterable allows filtering entities by an iterable
of indices that corresponds to Components/Tags.
Stephen Seo [Wed, 8 Aug 2018 07:52:12 +0000 (16:52 +0900)]
API change: context/userdata provided to functions
All functions called by EC/Manager now accept an additional parameter
as a void* to support user-provided data (or context) for functions
(useful when the function is not a lambda function and doesn't have any
other data stored with it).
Stephen Seo [Thu, 17 May 2018 08:05:49 +0000 (17:05 +0900)]
Add ability to handle unknown types
EC/Manager and EC/Bitset can now handle types that are not known
(Components or Tags not in the given Components or Tags when created).
Manager::getEntityData now returns a pointer instead of a reference.
Functions passed to Manager::forMatchingFunction (and other similar fns)
should now accept Component fields as pointer types, not reference
types.
Stephen Seo [Fri, 1 Dec 2017 10:20:59 +0000 (19:20 +0900)]
Fix bug with multiple sig/func call
Fixed bug where if an entity is deleted during a multiple
signature/function call but matched a later signature/function, it would
still be called in that later function.
Stephen Seo [Fri, 1 Dec 2017 05:00:49 +0000 (14:00 +0900)]
Replace garbage-collection-like cleanup
Entity IDs are now guaranteed to not change for a living entity.
Cleanup is replaced by using a std::unordered_set to store deleted
Entity IDs to be reclaimed on later calls to addEntity().
Stephen Seo [Wed, 15 Nov 2017 06:36:04 +0000 (15:36 +0900)]
Fix bug with duplicate signatures
Fixed bug where if forMatchingSignatures and forMatchingSignaturesPtr
was called with some signatures in the TypeList being duplicates, then
only the first duplicate and function pair would be called, and all
other functions paired with other duplicate signatures would not be
called.
Stephen Seo [Tue, 14 Nov 2017 04:51:24 +0000 (13:51 +0900)]
Improve efficiency of stored function calling
Previously, every called function iterated through all entities for
calling the function on matching entities.
Now, callForMatchingFunctions iterates through all entities once,
stores matching entities for each function, then calls the functions on
the matching entities.
Stephen Seo [Thu, 9 Nov 2017 12:10:01 +0000 (21:10 +0900)]
Implement forMatchingSignatures for efficiency
EC::Manager::forMatchingSignatures is different from
EC::Manager::forMatchingSignature in that it takes multiple signatures
and functions and iterates through all entities once. The trade-off is
that a vector of vectors is created to store matching entities.
This function can be called to use multiple threads as well, similar
to the "non-plural" version of this function.
See the doxygen-style documentation in src/EC/Manager.hpp for
forMatchingSignatures (or the generated doxygen html) for how to use.
Usage example is in the last unit test function in src/test/ECTest.hpp .
Stephen Seo [Tue, 31 Oct 2017 04:25:27 +0000 (13:25 +0900)]
Fix cleanup function's return value
Unordered map does not preserve order in which items were inserted.
This is a problem because an entity id relocated to a previously deleted
one could be read as deleted when iterating through the unordered map.
Thus, it has been replaced with a queue.