| 11 | } |
| 12 | |
| 13 | void WireProcessor::process() { |
| 14 | // First, populate all the working entities that are already live |
| 15 | m_worldStorage->entityMap()->forAllEntities([&](EntityPtr const& entity) { |
| 16 | if (auto wireEntity = as<WireEntity>(entity.get())) |
| 17 | populateWorking(wireEntity); |
| 18 | }); |
| 19 | |
| 20 | // Then, scan the network of each entity in the working set. This may, as a |
| 21 | // side effect, load further unconnected wire entities. Because our policy is |
| 22 | // to try as hard as possible to make sure that the entire wire entity |
| 23 | // network to be loaded at once or not at all, we need to make sure that each |
| 24 | // new disconnected entity also has its network loaded and so on. Thus, if |
| 25 | // the working entities size changes during scanning, simply scan the whole |
| 26 | // thing again until the size stops changing. |
| 27 | while (true) { |
| 28 | size_t oldWorkingSize = m_workingWireEntities.size(); |
| 29 | for (auto const& p : m_workingWireEntities.keys()) { |
| 30 | if (!m_workingWireEntities.get(p).networkLoaded) |
| 31 | loadNetwork(p); |
| 32 | } |
| 33 | if (m_workingWireEntities.size() == oldWorkingSize) |
| 34 | break; |
| 35 | } |
| 36 | |
| 37 | for (auto const& p : m_workingWireEntities) |
| 38 | p.second.wireEntity->evaluate(this); |
| 39 | |
| 40 | m_workingWireEntities.clear(); |
| 41 | } |
| 42 | |
| 43 | bool WireProcessor::readInputConnection(WireConnection const& connection) { |
| 44 | if (auto wes = m_workingWireEntities.ptr(connection.entityLocation)) |