Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revisionBoth sides next revision | ||
en:toolworks:docs:apparatus:deferred [2022/05/29 15:32] – vladius | en:toolworks:docs:apparatus:deferred [2022/06/01 20:05] – vladius | ||
---|---|---|---|
Line 3: | Line 3: | ||
It's no secret and if fact by design, that you can't execute methods that change a Subject' | It's no secret and if fact by design, that you can't execute methods that change a Subject' | ||
- | So there come handy the deferred operations (or // | + | So there come handy the deferred operations (or // |
+ | ====== Setting Traits ====== | ||
Say, we are implementing a real-time strategy game. A user can select multiple units and assign them orders (tasks). Send them marching to a destination point, for example. We could defer the Trait setting operation while Operating concurrently on the selected units, using the corresponding [[appi> | Say, we are implementing a real-time strategy game. A user can select multiple units and assign them orders (tasks). Send them marching to a destination point, for example. We could defer the Trait setting operation while Operating concurrently on the selected units, using the corresponding [[appi> | ||
Line 12: | Line 12: | ||
SolidChain-> | SolidChain-> | ||
{ | { | ||
- | Unit.SetTraitDeferred(FMoveToPointOrder{Destination}); | + | Unit.SetTraitDeferred(FMoveToPointOrder{Destination}); |
}); | }); | ||
</ | </ | ||
+ | |||
+ | ====== Removing Traits ====== | ||
+ | |||
+ | Removing Traits can also be deferred in a quite similar fashion. Here's an [[appi> | ||
+ | SolidChain-> | ||
+ | { | ||
+ | Buffed.Timeout -= DeltaSeconds; | ||
+ | if (Buffed.Timeout <= 0.0f) | ||
+ | { | ||
+ | Unit.RemoveTraitDeferred< | ||
+ | } | ||
+ | }); | ||
+ | </ | ||
+ | |||
+ | There is also a possibility to remove all the traits altogether. In a deferred fashion of course. This is just a matter of calling the corresponding [[appi> | ||
+ | Unit.RemoveAllTraitsDeferred(); | ||
+ | </ | ||
+ | |||
+ | ====== Spawning Subjects ====== | ||
+ | |||
+ | Not only traits can be added or removed in a deferred fashion but the whole Subjects can be spawned and despawned this way. So, if you have multiple units spawning a projectile when they' | ||
+ | SolidChain-> | ||
+ | { | ||
+ | Charging.Timeout -= DeltaSeconds; | ||
+ | if (Charging.Timeout <= 0.0f) | ||
+ | { | ||
+ | Mechanism-> | ||
+ | } | ||
+ | }); | ||
+ | </ | ||
+ | |||
+ | ====== Despawning Subjects ====== | ||
+ | |||
+ | The process of destroying a Subject is quite analogous. Kill all units once their health is zero or below. Just do something like:< | ||
+ | SolidChain-> | ||
+ | { | ||
+ | if (Health.Level <= 0.0f) | ||
+ | { | ||
+ | Unit.DespawnDeferred(); | ||
+ | } | ||
+ | }); | ||
+ | </ | ||
+ |