Ejemplo n.º 1
0
        private void button3_Click(object sender, EventArgs e)
        {
            var openDialog = new OpenFileDialog();
            var path       = string.Format(Application.StartupPath + "\\Map Collision obj files\\");

            openDialog.InitialDirectory = path;
            openDialog.FilterIndex      = 0;
            if (openDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }
            var zoneFilename = openDialog.FileName;

            Logger.AddDebugText(rtbDebug, $@"Obj File Selected = {zoneFilename}");
            try
            {
                var stopWatch = new Stopwatch();
                var result    = Path.GetFileName(zoneFilename);
                var result2   = result.Substring(0, result.LastIndexOf(".", StringComparison.Ordinal) + 1);
                if (File.Exists($@"{Application.StartupPath}\\Dumped NavMeshes\\{result2}nav"))
                {
                    var box = MessageBox.Show($@"Are you sure you want to overwrite {result2}.nav", @"Question",
                                              MessageBoxButtons.YesNoCancel);
                    if (box == DialogResult.Yes)
                    {
                        Logger.AddDebugText(rtbDebug, $@"Dumping NavMesh for {result}");
                        Thread.Sleep(100);
                        if (!NavBuilder.DumpingMesh)
                        {
                            stopWatch.Start();
                            NavBuilder.Dump_NavMesh(zoneFilename);
                            stopWatch.Stop();
                            var ts2 = stopWatch.Elapsed;

                            // Format and display the TimeSpan value.
                            var elapsedTime2 =
                                $"{ts2.Hours:00}:{ts2.Minutes:00}:{ts2.Seconds:00}.{ts2.Milliseconds / 10:00}";
                            Logger.AddDebugText(rtbDebug, string.Format(@"Time Taken to dump mesh = " + elapsedTime2));
                        }
                    }
                    else if (box == DialogResult.Cancel)
                    {
                        DumpMeshes.CancelAsync();
                        return;
                    }
                    else if (box == DialogResult.No)
                    {
                        return;
                    }
                }

                if (File.Exists($@"{Application.StartupPath}\\Dumped NavMeshes\\{result2}nav"))
                {
                    return;
                }
                stopWatch.Start();
                Logger.AddDebugText(rtbDebug, $@"Dumping NavMesh for {zoneFilename}");
                NavBuilder.Dump_NavMesh(zoneFilename);
                stopWatch.Stop();
                var ts = stopWatch.Elapsed;

                // Format and display the TimeSpan value.
                var elapsedTime = $"{ts.Hours:00}:{ts.Minutes:00}:{ts.Seconds:00}.{ts.Milliseconds / 10:00}";
                Logger.AddDebugText(rtbDebug, $@"Finished dumping NavMesh for {zoneFilename}");
                Logger.AddDebugText(rtbDebug, string.Format(@"Time Taken to dump NavMesh = " + elapsedTime));
            }
            catch (Exception ex)
            {
                Logger.AddDebugText(rtbDebug, string.Format(ex.ToString()));
            }
        }
Ejemplo n.º 2
0
        private void DumpMeshes_DoWork(object sender, DoWorkEventArgs e)
        {
            try
            {
                var stopWatch1 = new Stopwatch();
                stopWatch1.Start();
                while (!DumpMeshes.CancellationPending)
                {
                    if (DumpMeshes.CancellationPending)
                    {
                        e.Cancel = true;
                        break;
                    }

                    var path      = $"{Application.StartupPath}\\Map Collision obj files\\";
                    var fileCount = Directory.GetFiles(path, "*.obj", SearchOption.AllDirectories).Length;
                    Logger.AddDebugText(rtbDebug,
                                        $@"{fileCount.ToString()}.obj files fould in Map Collision obj folder");
                    foreach (var file in Directory.EnumerateFiles(string.Format(path, "*.obj")))
                    {
                        if (DumpMeshes.CancellationPending)
                        {
                            button5.BeginInvoke(new MethodInvoker(() =>
                            {
                                button5.Text = @"Start dumping all zone.obj file navmeshes";
                            }));
                            e.Cancel = true;
                            break;
                        }

                        var result  = Path.GetFileName(file);
                        var result2 = result.Substring(0, result.LastIndexOf(".", StringComparison.Ordinal) + 1);
                        if (File.Exists($@"{Application.StartupPath}\\Dumped NavMeshes\\{result2}nav"))
                        {
                            var box = MessageBox.Show($@"Are you sure you want to overwrite {result2}.nav", @"Question",
                                                      MessageBoxButtons.YesNoCancel);
                            if (box == DialogResult.Yes)
                            {
                                if (!NavBuilder.DumpingMesh && !DumpMeshes.CancellationPending)
                                {
                                    var stopWatch = new Stopwatch();
                                    stopWatch.Start();
                                    Logger.AddDebugText(rtbDebug, $@"Dumping NavMesh for {result2}");
                                    if (NavBuilder.Dump_NavMesh(file) && !DumpMeshes.CancellationPending)
                                    {
                                        stopWatch.Stop();
                                        NavBuilder.UnloadMeshBuilder();
                                        var ts = stopWatch.Elapsed;

                                        // Format and display the TimeSpan value.
                                        var elapsedTime =
                                            $"{ts.Hours:00}:{ts.Minutes:00}:{ts.Seconds:00}.{ts.Milliseconds / 10:00}";
                                        Logger.AddDebugText(rtbDebug,
                                                            $@"Time Taken to dump mesh {result2} = {elapsedTime} ");
                                    }
                                }
                            }
                            else if (box == DialogResult.Cancel)
                            {
                                button5.BeginInvoke(new MethodInvoker(() =>
                                {
                                    button5.Text = @"Start dumping all zone.obj file navmeshes";
                                }));
                                DumpMeshes.CancelAsync();
                                break;
                            }
                            else if (box == DialogResult.No)
                            {
                                continue;
                            }
                        }

                        if (!File.Exists($@"{Application.StartupPath}\\Dumped NavMeshes\\{result2}nav"))
                        {
                            if (!NavBuilder.DumpingMesh && !DumpMeshes.CancellationPending)
                            {
                                var stopWatch = new Stopwatch();
                                stopWatch.Start();
                                Logger.AddDebugText(rtbDebug, $@"Dumping NavMesh for {result2}");
                                if (NavBuilder.Dump_NavMesh(file) && !DumpMeshes.CancellationPending)
                                {
                                    stopWatch.Stop();
                                    NavBuilder.UnloadMeshBuilder();
                                    var ts = stopWatch.Elapsed;

                                    // Format and display the TimeSpan value.
                                    var elapsedTime =
                                        $"{ts.Hours:00}:{ts.Minutes:00}:{ts.Seconds:00}.{ts.Milliseconds / 10:00}";
                                    Logger.AddDebugText(rtbDebug,
                                                        $@"Time Taken to dump mesh {result2} = {elapsedTime} ");
                                }
                            }
                        }

                        if (DumpMeshes.CancellationPending)
                        {
                            button5.BeginInvoke(new MethodInvoker(() =>
                            {
                                button5.Text = @"Start dumping all zone.obj file navmeshes";
                            }));
                            e.Cancel = true;
                            break;
                        }
                    }

                    stopWatch1.Stop();
                    var ts1          = stopWatch1.Elapsed;
                    var elapsedTime1 = $"{ts1.Hours:00}:{ts1.Minutes:00}:{ts1.Seconds:00}.{ts1.Milliseconds / 10:00}";
                    Logger.AddDebugText(rtbDebug, @"Finished dumping NavMesh data");
                    Logger.AddDebugText(rtbDebug,
                                        string.Format(@"Time Taken to dump all zones NavMeshes = " + elapsedTime1));
                    var dInfo     = new DirectoryInfo($@"{Application.StartupPath}\Dumped NavMeshes\");
                    var sizeOfDir = DirectorySize(dInfo, true);
                    Logger.AddDebugText(rtbDebug,
                                        $@"NavMeshes data disk space used = {(double)sizeOfDir / (1024 * 1024):N2} MB");
                    button5.BeginInvoke(new MethodInvoker(() =>
                    {
                        button5.Text = @"Start dumping all zone.obj file navmeshes";
                    }));
                    progressBar1.Enabled = false;
                    progressBar1.Visible = false;
                    DumpMeshes.CancelAsync();
                    return;
                }
            }
            catch (Exception es)
            {
                Logger.AddDebugText(rtbDebug, es.ToString());
            }
        }