Skip to content

Commit af14aa4

Browse files
committed
doc: more about signals (sigh_storage_mixin)
1 parent 24d6b98 commit af14aa4

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed

docs/md/entity.md

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
* [Storage](#storage)
1616
* [The Registry, the Entity and the Component](#the-registry-the-entity-and-the-component)
1717
* [Observe changes](#observe-changes)
18+
* [Intent versus outcome](#intent-versus-outcome)
1819
* [Listeners disconnection](#listeners-disconnection)
1920
* [They call me Reactive System](#they-call-me-reactive-system)
2021
* [Sorting: is it possible?](#sorting-is-it-possible)
@@ -409,6 +410,38 @@ There are many useful but less known functionalities that aren't described here,
409410
such as the connection objects or the possibility to attach listeners with a
410411
list of parameters that is shorter than that of the signal itself.
411412

413+
### Intent versus outcome
414+
415+
The basic implementation of signal support (offered via storage mixin) doesn't
416+
account for the fact that _opaque_ creation or copying of components can fail if
417+
their types aren't default constructible or copyable.<br/>
418+
The mixin sends a signal to the listeners whenever the _intention_ to build a
419+
component is manifested and after this operation has occurred, even in the event
420+
of failure.
421+
422+
Opaque creation and copying occurs when the caller interacts with a storage via
423+
its base class, without actually knowing what type of component it's working
424+
with:
425+
426+
```cpp
427+
using namespace entt::literals;
428+
auto *storage = registry.storage("velocity"_hs);
429+
430+
if(storage && (storage->emplace(entity) != storage->end())) {
431+
// ...
432+
}
433+
```
434+
435+
In this case, the operation may fail at runtime rather than compile-time and
436+
therefore the entity ends up without the desired component.<br/>
437+
The user can detect the error immediately by checking the returned iterator.
438+
However, the signal is sent anyway.
439+
440+
In general, users should make component types default constructible and copyable
441+
regardless.<br/>
442+
However, it's useful to be aware of this eventuality in the event of errors and
443+
to act accordingly.
444+
412445
### Listeners disconnection
413446
414447
The destruction order of the storage classes and therefore the disconnection of

0 commit comments

Comments
 (0)