private void LoadSnoCache() { if (!USE_SNO_CACHE) { return; } if (!Directory.Exists(SCENE_SNO_CACHE_DIR)) { Directory.CreateDirectory(SCENE_SNO_CACHE_DIR); return; } if (!File.Exists(SCENE_SNO_CACHE_DIR + SCENE_SNO_CACHE_FILE)) { return; } try { using (FileStream fs = File.OpenRead(SCENE_SNO_CACHE_DIR + SCENE_SNO_CACHE_FILE)) using (BinaryReader br = new BinaryReader(fs)) { int scenes_count = br.ReadInt32(); for (int i = 0; i < scenes_count; ++i) { int scene_sno_id = br.ReadInt32(); m_SnoCache[scene_sno_id] = new SceneSnoNavData(scene_sno_id, br); } } } catch (Exception) { Log("Failed to load scene sno cache. Try removing sno cache directory."); m_SnoCache.Clear(); } }
private void FetchSceneData() { List <SceneData> new_scene_data = new List <SceneData>(); //using (new Nav.Profiler("[Nav.D3.Navigation] Navmesh data aquired [{t}]", 70)) { foreach (Enigma.D3.Scene scene in m_Engine.ObjectManager.x998_Scenes.Dereference()) { if (scene == null || scene.x000_Id < 0) { continue; } SceneData scene_data = new SceneData(scene); if (m_AllowedAreasSnoId.Count > 0 && !m_AllowedAreasSnoId.Contains(scene_data.AreaSnoId) && !m_AllowedGridCellsId.Contains(scene_data.SceneSnoId)) { continue; } if (m_ProcessedSceneId.Contains(scene_data.SceneUid)) { continue; } new_scene_data.Add(scene_data); } } //using (new Nav.Profiler("[Nav.D3.Navigation] Navmesh data added [{t}]")) { int grid_cells_added = 0; foreach (SceneData scene_data in new_scene_data) { SceneSnoNavData sno_nav_data = null; // allow empty grids m_SnoCache.TryGetValue(scene_data.SceneSnoId, out sno_nav_data); GridCell grid_cell = new GridCell(scene_data.Min, scene_data.Max, scene_data.SceneSnoId, scene_data.AreaSnoId); grid_cell.UserData = scene_data.AreaSnoId; if (sno_nav_data != null) { int cell_id = 0; foreach (Cell cell in sno_nav_data.Cells) { grid_cell.Add(new Cell(cell.Min + scene_data.Min, cell.Max + scene_data.Min, cell.Flags, cell_id++)); } } if (Add(grid_cell, false)) { ++grid_cells_added; } m_ProcessedSceneId.Add(scene_data.SceneUid); } if (grid_cells_added > 0) { Log("[Nav.D3] " + grid_cells_added + " grid cells added" + (Explorator == null ? " (EXPLORATOR NOT PRESENT!!!)" : "") + "."); if (Explorator != null) { Explorator.OnNavDataChange(); } } } }
private void FetchSceneData() { List <SceneData> new_scene_data = new List <SceneData>(); //using (new Nav.Profiler("[Nav.D3.Navigation] Navmesh data aquired [%t]", 70)) { int scenes_available = 0; foreach (var scene in m_MemoryContext.DataSegment.ObjectManager.Scenes) { if (scene == null || scene.ID == -1) { continue; } ++scenes_available; SceneData scene_data = new SceneData(scene); if (m_AllowedAreasSnoId.Count > 0 && !m_AllowedAreasSnoId.Contains(scene_data.AreaSnoId) && !m_AllowedGridCellsId.Contains(scene_data.SceneSnoId)) { continue; } if (m_ProcessedSceneId.Contains(scene_data.SceneUid)) { continue; } new_scene_data.Add(scene_data); } } //using (new Nav.Profiler("[Nav.D3.Navigation] Navmesh data added [%t]")) { int grid_cells_added = 0; foreach (SceneData scene_data in new_scene_data) { SceneSnoNavData sno_nav_data = null; m_SnoCache.TryGetValue(scene_data.SceneSnoId, out sno_nav_data); if (sno_nav_data == null) { //wait for navigation data to be fetched before processing this scene continue; } GridCell grid_cell = new GridCell(scene_data.Min, scene_data.Max, scene_data.SceneSnoId, scene_data.AreaSnoId); grid_cell.UserData = scene_data.AreaSnoId; if (sno_nav_data != null) { int cell_id = 0; foreach (Cell cell in sno_nav_data.Cells) { grid_cell.Add(new Cell(cell.Min + scene_data.Min, cell.Max + scene_data.Min, cell.Flags, cell_id++)); } } else { Log("[Nav.D3] Couldn't find SNO data for scene " + scene_data.SceneSnoId); } if (Add(grid_cell, false)) { ++grid_cells_added; } m_ProcessedSceneId.Add(scene_data.SceneUid); } if (grid_cells_added > 0) { Log("[Nav.D3] " + grid_cells_added + " grid cells added."); NotifyOnNavDataChanged(); } else if (new_scene_data.Count > 0) { Log("[Nav.D3] New scene data found but no grid cells added!"); } } }