| 856 | } |
| 857 | |
| 858 | Level *World::load_level(StringId64 name, u32 flags, const Vector3 &pos, const Quaternion &rot) |
| 859 | { |
| 860 | const LevelResource *lr = (LevelResource *)_resource_manager->get(RESOURCE_TYPE_LEVEL, name); |
| 861 | const UnitResource *ur = level_resource::unit_resource(lr); |
| 862 | |
| 863 | Level *level = level::create(*_allocator, lr); |
| 864 | |
| 865 | // Create IDs for units. |
| 866 | for (u32 i = 0; i < ur->num_units; ++i) |
| 867 | level->_unit_lookup[i] = _unit_manager->create(); |
| 868 | |
| 869 | create_components(*this, ur, level->_unit_lookup, flags, pos, rot, VECTOR3_ONE); |
| 870 | |
| 871 | array::push(_units, level->_unit_lookup, ur->num_units); |
| 872 | #if CROWN_CAN_RELOAD |
| 873 | array::push_back(_unit_resources, ur); |
| 874 | for (u32 i = 0; i < ur->num_units - 1; ++i) |
| 875 | array::push_back(_unit_resources, (const UnitResource *)NULL); |
| 876 | #endif |
| 877 | |
| 878 | post_unit_spawned_events(level->_unit_lookup, ur->num_units); |
| 879 | script_world::spawned(*_script_world, level->_unit_lookup, ur->num_units); |
| 880 | |
| 881 | spawn_skydome(lr->skydome_unit); |
| 882 | |
| 883 | for (u32 i = 0; i < lr->num_sounds; ++i) { |
| 884 | const LevelSound *ls = level_resource::get_sound(lr, i); |
| 885 | play_sound(ls->name, ls->loop, ls->volume, ls->range, PlaySoundFlags::ENABLE_ATTENUATION, ls->position, ls->group); |
| 886 | } |
| 887 | |
| 888 | list::add(level->_node, _levels); |
| 889 | |
| 890 | post_level_loaded_event(); |
| 891 | return level; |
| 892 | } |
| 893 | |
| 894 | void World::destroy_level(Level &level) |
| 895 | { |