/// <summary> /// Initialize predefined textures<para/> /// Инициализация предзаданных текстур /// </summary> public static void Init() { // Checking for extensions // Проверка расширений CompressionSupported = GLExtensions.Supported("GL_EXT_Texture_Compression_S3TC"); FrameBufferSupported = GLExtensions.Supported("GL_ARB_Framebuffer_Object"); // Load DAT-defined texture dictionaries // Загрузка предопределенных архивов текстур foreach (string TXD in FileManager.TextureFiles) { string name = Path.GetFileNameWithoutExtension(TXD).ToLower(); string path = PathManager.GetAbsolute(TXD); TextureFile f = new TextureFile(path, true); CachedFiles.TryAdd(name, f); TextureDictionary td = new TextureDictionary(f, true, true); Cached.TryAdd(name, td); } // Starting TextureFile thread // Запуск потока чтения TextureFile fileReaderThread = new Thread(FileLoaderProcess); fileReaderThread.IsBackground = true; fileReaderThread.Priority = ThreadPriority.BelowNormal; fileReaderThread.Start(); // Starting model builder thread // Запуск потока постройки Model textureBuilderThread = new Thread(TextureBuilderProcess); textureBuilderThread.IsBackground = true; textureBuilderThread.Priority = ThreadPriority.BelowNormal; textureBuilderThread.Start(); }
/// <summary> /// Initialize predefined models<para/> /// Инициализация предзаданных моделей /// </summary> public static void Init() { // Load DAT-defined texture dictionaries // Загрузка предопределенных архивов текстур foreach (string DFF in FileManager.ModelFiles) { string name = Path.GetFileNameWithoutExtension(DFF).ToLower(); string path = PathManager.GetAbsolute(DFF); ModelFile f = new ModelFile(path, true); CachedFiles.TryAdd(name, f); Model m = new Model(f, true, true); Cached.TryAdd(name, m); } // Starting ModelFile thread // Запуск потока чтения ModelFile fileReaderThread = new Thread(FileLoaderProcess); fileReaderThread.IsBackground = true; fileReaderThread.Priority = ThreadPriority.BelowNormal; fileReaderThread.Start(); // Starting model builder thread // Запуск потока постройки Model modelBuilderThread = new Thread(ModelBuilderProcess); modelBuilderThread.IsBackground = true; modelBuilderThread.Priority = ThreadPriority.BelowNormal; modelBuilderThread.Start(); }
/// <summary> /// Initialize all the meshes<para/> /// Инициализация всех моделей /// </summary> public static void Init() { // Initialize collections // Создание коллекций Collisions = new Dictionary <int, CollisionFile.Group>(); NamedCollisions = new Dictionary <string, CollisionFile.Group>(); // Looping through associated files // Проход через ассоциированные файлы foreach (string file in FileManager.CollisionFiles) { string ffile = PathManager.GetAbsolute(file); if (File.Exists(ffile)) { CollisionFile cf = new CollisionFile(ffile); foreach (CollisionFile.Group g in cf.Collisions) { bool addToIndexed = false; if (g.ID < ObjectManager.Definitions.Length) { if (ObjectManager.Definitions[g.ID] != null) { if (ObjectManager.Definitions[g.ID].ModelName == g.Name) { addToIndexed = true; } } } // Add mesh to indexed list or model-oriented // Добавление меша либо в список if (addToIndexed) { if (!Collisions.ContainsKey(g.ID)) { Collisions.Add(g.ID, g); } } else { if (!NamedCollisions.ContainsKey(g.Name)) { NamedCollisions.Add(g.Name, g); } } } } else { Dev.Console.Log("[CollisionManager] Unable to locate collision archive: " + file); } } }
/// <summary> /// Mount all specified game archives<para/> /// Подключение всех игровых архивов /// </summary> public static void Mount() { // +1 because of hardcoded archive // +1 из-за жёстко зашитого архива archives = new ArchiveFile[FileManager.ArchiveFiles.Length + 1]; // Base GTA3.IMG archive // Основной архив archives[0] = new ArchiveFile(PathManager.GetAbsolute("models/gta3.img")); // Mounting all extension archives // Подключение дополнительных архивов for (int i = 0; i < FileManager.ArchiveFiles.Length; i++) { archives[i + 1] = new ArchiveFile(PathManager.GetAbsolute(FileManager.ArchiveFiles[i])); } Dev.Console.Log("[ArchiveManager] Succesfully mounted " + archives.Length + " IMG archives"); }
/// <summary> /// Parsing IPL files<para/> /// Разбор файлов IPL /// </summary> public static void ReadPlacements() { List <ItemPlacement> pl = new List <ItemPlacement>(); foreach (string IPL in FileManager.PlacementFiles) { TextFile f = new TextFile(PathManager.GetAbsolute(IPL), true, true); foreach (TextFile.Line p in f.Lines) { switch (p.Section.ToLower()) { // Object installation // Расстановка объектов case "inst": ItemPlacement g = new ItemPlacement(); g = new ItemPlacement() { ID = p.Text[0].ToInt(), ModelName = p.Text[1], InteriorID = ItemPlacement.Interior.World, Position = new Vector3(p.Text[p.Text.Length - 10].ToFloat(), p.Text[p.Text.Length - 8].ToFloat(), p.Text[p.Text.Length - 9].ToFloat()), Scale = new Vector3(p.Text[p.Text.Length - 7].ToFloat(), p.Text[p.Text.Length - 5].ToFloat(), p.Text[p.Text.Length - 6].ToFloat()), Angle = new Quaternion(-p.Text[p.Text.Length - 4].ToFloat(), -p.Text[p.Text.Length - 2].ToFloat(), -p.Text[p.Text.Length - 3].ToFloat(), -p.Text[p.Text.Length - 1].ToFloat()), }; if (p.Text.Length > 12) { g.InteriorID = (ItemPlacement.Interior)p.Text[2].ToInt(); } pl.Add(g); break; } // Operation is threadable, so sleep for a while // Операция потоковая, поэтому отдадим времени основному процессу System.Threading.Thread.Sleep(0); } } Placements = pl.ToArray(); Dev.Console.Log("[ObjectManager] Parsed " + FileManager.PlacementFiles.Length + " placement files (" + pl.Count + " entries)"); }
/// <summary> /// Parsing IDE files<para/> /// Разбор файлов IDE /// </summary> public static void ReadDefinitions() { Definitions = new ItemDefinition[8192]; int totalEntries = 0; foreach (string IDE in FileManager.DefinitionFiles) { TextFile f = new TextFile(PathManager.GetAbsolute(IDE), true, true); foreach (TextFile.Line p in f.Lines) { switch (p.Section.ToLower()) { // Common objects // Обычные объекты case "objs": ItemDefinition d = new ItemDefinition() { ID = p.Text[0].ToInt(), ModelName = p.Text[1].ToLower(), TexDictionary = p.Text[2].ToLower(), DrawDistance = new float[p.Text[3].ToInt()], IsTimed = false, Flags = new ItemDefinition.FlagsContainer(p.Text[p.Text.Length - 1].ToUInt()) }; for (int i = 0; i < d.DrawDistance.Length; i++) { d.DrawDistance[i] = p.Text[4 + i].ToFloat(); } Definitions[d.ID] = d; totalEntries++; break; // Timed objects // Временные объекты case "tobj": d = new ItemDefinition() { ID = p.Text[0].ToInt(), ModelName = p.Text[1].ToLower(), TexDictionary = p.Text[2].ToLower(), DrawDistance = new float[p.Text[3].ToInt()], IsTimed = true, Flags = new ItemDefinition.FlagsContainer(p.Text[p.Text.Length - 3].ToUInt()), TimeOn = p.Text[p.Text.Length - 2].ToInt(), TimeOff = p.Text[p.Text.Length - 1].ToInt() }; for (int i = 0; i < d.DrawDistance.Length; i++) { d.DrawDistance[i] = p.Text[4 + i].ToFloat(); } Definitions[d.ID] = d; totalEntries++; break; default: break; } // Operation is threadable, so sleep for a while // Операция потоковая, поэтому отдадим времени основному процессу System.Threading.Thread.Sleep(0); } } Dev.Console.Log("[ObjectManager] Parsed " + FileManager.DefinitionFiles.Length + " definition files (" + totalEntries + " entries)"); }
/// <summary> /// Open GTA_VC.dat and default.dat<para/> /// Чтение GTA_VC.dat и default.dat /// </summary> static void ReadDataFiles() { List <string> ide = new List <string>(), ipl = new List <string>(), col = new List <string>(), tex = new List <string>(), mod = new List <string>(), img = new List <string>(); TextFile d; for (int i = 0; i < 2; i++) { // First gta_vc, then default // Сначала gta_vc, потом default if (i == 0) { d = new TextFile(PathManager.GetAbsolute("data/gta_vc.dat"), false, false); } else { d = new TextFile(PathManager.GetAbsolute("data/default.dat"), false, false); } // Parsing directives // Обработка директив foreach (TextFile.Line l in d.Lines) { switch (l.Text[0].ToLower()) { // Item Definition // Файл IDE case "ide": ide.Add(l.Text[1]); col.Add(System.IO.Path.ChangeExtension(l.Text[1], ".col")); break; // Item placement // Файл IPL case "ipl": ipl.Add(l.Text[1]); break; // Collision files // Файлы коллизий case "colfile": col.Add(l.Text[2]); break; // Texture dictionary // Тектстурный архив case "texdiction": tex.Add(l.Text[1]); break; // Generic DFF file // DFF файл case "modelfile": mod.Add(l.Text[1]); break; // Additive IMG archive // Дополнительный IMG-архив case "cdimage": img.Add(l.Text[1]); break; // Splash image (skip) // Сплэш (пропускаем) case "splash": break; default: throw new Exception("[FileManager] Unknown directive in data file: " + l.Text[0]); } } } // Saving data // Сохранение данных DefinitionFiles = ide.ToArray(); PlacementFiles = ipl.ToArray(); CollisionFiles = col.ToArray(); ModelFiles = mod.ToArray(); TextureFiles = tex.ToArray(); ArchiveFiles = img.ToArray(); }
/// <summary> /// Initialize Timecyc.dat file<para/> /// Чтение файла Timecyc /// </summary> public static void Init() { if (weatherParams == null) { Entry[,] ea = new Entry[7, 24]; TextFile f = new TextFile(PathManager.GetAbsolute("data/Timecyc.dat"), false, false); int w = 0, h = 0; foreach (TextFile.Line l in f.Lines) { Entry e = new Entry(); e.AmbientStatic = new Vector3( l.Text[0].ToFloat() / 255f, l.Text[1].ToFloat() / 255f, l.Text[2].ToFloat() / 255f ); e.AmbientDynamic = new Vector3( l.Text[3].ToFloat() / 255f, l.Text[4].ToFloat() / 255f, l.Text[5].ToFloat() / 255f ); e.DiffuseStatic = new Vector3( l.Text[6].ToFloat() / 255f, l.Text[7].ToFloat() / 255f, l.Text[8].ToFloat() / 255f ); e.DiffuseDynamic = new Vector3( l.Text[9].ToFloat() / 255f, l.Text[10].ToFloat() / 255f, l.Text[11].ToFloat() / 255f ); e.DirectLight = new Vector3( l.Text[12].ToFloat() / 255f, l.Text[13].ToFloat() / 255f, l.Text[14].ToFloat() / 255f ); e.SkyTop = new Vector3( l.Text[15].ToFloat() / 255f, l.Text[16].ToFloat() / 255f, l.Text[17].ToFloat() / 255f ); e.SkyBottom = new Vector3( l.Text[18].ToFloat() / 255f, l.Text[19].ToFloat() / 255f, l.Text[20].ToFloat() / 255f ); e.CameraClip = l.Text[33].ToFloat(); e.FogDistance = l.Text[34].ToFloat(); // Storing data // Сохранение данных ea[w, h] = e; h++; if (h > 23) { h = 0; w++; } } weatherParams = ea; } }