| 444 | } |
| 445 | |
| 446 | void sugoi_storage_t::pack_entities() |
| 447 | { |
| 448 | using namespace sugoi; |
| 449 | if (scheduler) |
| 450 | { |
| 451 | SKR_ASSERT(scheduler->is_main_thread(this)); |
| 452 | scheduler->sync_storage(this); |
| 453 | } |
| 454 | skr::stl_vector<EIndex> map; |
| 455 | auto& entries = entities.entries; |
| 456 | map.resize(entries.size()); |
| 457 | entities.freeEntries.clear(); |
| 458 | EIndex j = 0; |
| 459 | forloop (i, 0, entries.size()) |
| 460 | { |
| 461 | if (entries[i].indexInChunk != 0) |
| 462 | { |
| 463 | map[i] = j; |
| 464 | if (i != j) |
| 465 | entries[j] = entries[i]; |
| 466 | j++; |
| 467 | } |
| 468 | } |
| 469 | struct mapper { |
| 470 | skr::stl_vector<EIndex>* data; |
| 471 | void move() {} |
| 472 | void reset() {} |
| 473 | void map(sugoi_entity_t& e) |
| 474 | { |
| 475 | if (e_id(e) < data->size()) |
| 476 | e = e_id(e, (*data)[e_id(e)]); |
| 477 | } |
| 478 | } m; |
| 479 | m.data = ↦ |
| 480 | skr::stl_vector<sugoi_group_t*> gs; |
| 481 | for (auto& pair : groups) |
| 482 | gs.push_back(pair.second); |
| 483 | groups.clear(); |
| 484 | for (auto g : gs) |
| 485 | { |
| 486 | for (auto c : g->chunks) |
| 487 | { |
| 488 | iterator_ref_chunk(c, m); |
| 489 | iterator_ref_view({ c, 0, c->count }, m); |
| 490 | } |
| 491 | auto meta = g->type.meta; |
| 492 | forloop (i, 0, meta.length) |
| 493 | m.map(((sugoi_entity_t*)meta.data)[i]); |
| 494 | std::sort((sugoi_entity_t*)meta.data, (sugoi_entity_t*)meta.data + meta.length); |
| 495 | groups.insert({ g->type, g }); |
| 496 | } |
| 497 | } |
| 498 | |
| 499 | void sugoi_storage_t::cast_impl(const sugoi_chunk_view_t& view, sugoi_group_t* group, sugoi_cast_callback_t callback, void* u) |
| 500 | { |
no test coverage detected