Differences
This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision | ||
en:toolworks:docs:apparatus:iterating [2021/08/29 15:13] – [C++ Workflow] vladius | en:toolworks:docs:apparatus:iterating [2022/06/05 15:26] (current) – Пофиксил ссылки, чтобы они указывали на существующую страницу. jispar | ||
---|---|---|---|
Line 1: | Line 1: | ||
====== Iterating ====== | ====== Iterating ====== | ||
- | In order to implement your actual Mechanic logic you have to be able to process all of the [[en: | + | In order to implement your actual Mechanic logic you have to be able to process all of the [[en: |
- | Chains are iterated with the help of Cursors. Those are very much like container iterators. Multiple Cursors are available but this is more of a multi-threading future-proofing. For now, you should really use a single default Cursor only. | + | Chains are iterated with the help of Cursors. Those are very much like container iterators. |
===== C++ Workflow ===== | ===== C++ Workflow ===== | ||
Line 45: | Line 45: | ||
Please note, that the Chain gets disposed automatically when all | Please note, that the Chain gets disposed automatically when all | ||
of the iterating Cursors have finished providing (iterating) the slots. | of the iterating Cursors have finished providing (iterating) the slots. | ||
- | To suppress this behavior use explicit '' | + | To suppress this behavior use explicit '' |
for a custom lifetime organization: | for a custom lifetime organization: | ||
Line 53: | Line 53: | ||
while (Cursor.Provide()) | while (Cursor.Provide()) | ||
{ | { | ||
- | auto Trait = Cursor.GetTrait< | ||
... | ... | ||
} | } | ||
+ | // Do some other stuff with the chain. | ||
+ | // It's now guaranteed to not be disposed. | ||
... | ... | ||
Chain-> | Chain-> | ||
Line 91: | Line 92: | ||
When the Chain Cursor is gone past the last available Subject/ | When the Chain Cursor is gone past the last available Subject/ | ||
+ | ==== Direct Iterating ==== | ||
+ | |||
+ | If you want to iterate the Chunks directly you can utilize the Chunks Proxies. | ||
+ | You will basically need to iterate all of the Proxies collected | ||
+ | through the corresponding [[appi> | ||
+ | within each Chunk iterate all of its Subjects-containing Slots. | ||
+ | |||
+ | An example is as such:< | ||
+ | TArray< | ||
+ | Mechanism-> | ||
+ | for (int32 i = 0; i < ChunkProxies.Num(); | ||
+ | { | ||
+ | auto& ChunkProxy = ChunkProxies[i]; | ||
+ | for (int32 j = 0; j < ChunkProxy.Num(); | ||
+ | { | ||
+ | // Perform the necessary logic... | ||
+ | ChunkProxy.TraitRefAt< | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | Please note however, that this approach is totally manual, and doesn' | ||
+ | |||
+ | If you're also performing some topology-changing logic within your loops your Subjects can change their Chunks and Slots in an arbitrary way, so perhaps you also have to be checking for Slots to be (non-)stale. | ||
+ | |||
+ | You would do it like so:<code cpp> | ||
+ | for (int32 j = 0; j < ChunkProxy.Num(); | ||
+ | { | ||
+ | if (ChunkProxy.IsStaleAt(j)) continue; // Skip the Subject if it's either moved or despawned... | ||
+ | ChunkProxy.SubjectAt(j).SetTrait(FSpeedBoostTrait{10.0f}); | ||
+ | } | ||
+ | </ | ||
+ | Iterating the Chunks directly (via Proxies) can introduce a certain performance boost as compared to normal iterating and [[en: |