| 2505 | } // namespace |
| 2506 | |
| 2507 | void MapEditor::BringAllToCurrentState(int old_state) { |
| 2508 | // Create map for easy saved-chunk lookup |
| 2509 | Type_ID_Time_ChunkMap save_states; |
| 2510 | // Loop through saved chunks to populate lookup map |
| 2511 | for (auto& chunk : state_history_.chunks) { |
| 2512 | save_states[chunk.type][chunk.obj_id][chunk.state_id] = &chunk; |
| 2513 | } |
| 2514 | |
| 2515 | // Remove all objects with editors |
| 2516 | std::vector<int> selected_ids; |
| 2517 | int index = 0; |
| 2518 | while (index < (int)scenegraph_->objects_.size()) { |
| 2519 | Object* obj = scenegraph_->objects_[index]; |
| 2520 | if (obj->Selected()) { |
| 2521 | selected_ids.push_back(obj->GetID()); |
| 2522 | } |
| 2523 | if (!obj->exclude_from_undo) { |
| 2524 | RemoveObject(scenegraph_->objects_[index], scenegraph_, true); |
| 2525 | } else { |
| 2526 | ++index; |
| 2527 | } |
| 2528 | } |
| 2529 | // Loop through each chunk and set each object to the most appropriate saved chunk |
| 2530 | for (auto& save_state : save_states) { |
| 2531 | const ChunkType::ChunkType& type = save_state.first; |
| 2532 | ID_Time_ChunkMap& submap = save_state.second; |
| 2533 | for (auto& iter : submap) { |
| 2534 | SavedChunk* the_chunk = NULL; |
| 2535 | Time_ChunkMap& timeline = iter.second; |
| 2536 | // Find the last entry that is before the current time |
| 2537 | for (auto& iter2 : timeline) { |
| 2538 | const int& time = iter2.first; |
| 2539 | SavedChunk* chunk = iter2.second; |
| 2540 | if (time == state_history_.current_state) { |
| 2541 | the_chunk = chunk; |
| 2542 | } |
| 2543 | } |
| 2544 | // Apply that entry to the appropriate object or editor |
| 2545 | if (the_chunk) { |
| 2546 | switch (type) { |
| 2547 | case ChunkType::SKY_EDITOR: |
| 2548 | if (sky_editor_->ReadChunk(*the_chunk)) { |
| 2549 | scenegraph_->sky->LightingChanged(scenegraph_->terrain_object_ != NULL); |
| 2550 | } |
| 2551 | break; |
| 2552 | case ChunkType::LEVEL: |
| 2553 | scenegraph_->level->ReadChunk(*the_chunk); |
| 2554 | break; |
| 2555 | default: |
| 2556 | Object* o = CreateObjectFromDesc(the_chunk->desc); |
| 2557 | if (o) { |
| 2558 | if (ActorsEditor_AddEntity(scenegraph_, o, NULL, false, true)) { |
| 2559 | } else { |
| 2560 | LOGE << "Failed at adding object to scenegraph" << std::endl; |
| 2561 | } |
| 2562 | } else { |
| 2563 | LOGE << "Failed at constructing object" << std::endl; |
| 2564 | } |
nothing calls this directly
no test coverage detected