| 252 | } |
| 253 | |
| 254 | void World::triggerBlocks() |
| 255 | { |
| 256 | m_state = State::Triggering; |
| 257 | for (auto& block : m_triggerBlocks) |
| 258 | { |
| 259 | auto& p = block.first; |
| 260 | auto& b = block.second; |
| 261 | block.second.getType().trigger(*this, b, {int(p.x), |
| 262 | int(p.y), |
| 263 | int(p.z)}); |
| 264 | } |
| 265 | /* |
| 266 | * When blocks are triggered, they have potential to trigger yet more blocks. |
| 267 | * Usually, you would just clear the triggered blocks here |
| 268 | * But, this would cause the blocks that get triggered during the triggering of blocks to not get |
| 269 | * triggered, because the std::vector would be cleared. |
| 270 | * |
| 271 | * So, instead, I add them into a different std::vector if the block is triggered during this |
| 272 | * state of the world (State::Triggering) |
| 273 | */ |
| 274 | m_triggerBlocks = std::move(m_sheduledTriggerBlocks); |
| 275 | } |
| 276 | |
| 277 | |
| 278 | void World::drawWorld(Renderer::Master& renderer, const Camera& camera) |