|
15 | 15 | * [Storage](#storage) |
16 | 16 | * [The Registry, the Entity and the Component](#the-registry-the-entity-and-the-component) |
17 | 17 | * [Observe changes](#observe-changes) |
| 18 | + * [Intent versus outcome](#intent-versus-outcome) |
18 | 19 | * [Listeners disconnection](#listeners-disconnection) |
19 | 20 | * [They call me Reactive System](#they-call-me-reactive-system) |
20 | 21 | * [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, |
409 | 410 | such as the connection objects or the possibility to attach listeners with a |
410 | 411 | list of parameters that is shorter than that of the signal itself. |
411 | 412 |
|
| 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 | +
|
412 | 445 | ### Listeners disconnection |
413 | 446 |
|
414 | 447 | The destruction order of the storage classes and therefore the disconnection of |
|
0 commit comments