Exemplo n.º 1
0
        private void recalculateButton_Click(object sender, EventArgs e)
        {
            worker = new System.ComponentModel.BackgroundWorker();
            recalculateButton.Enabled    = false;
            reachSpecProgressBar.Style   = ProgressBarStyle.Marquee;
            worker.WorkerReportsProgress = true;
            worker.DoWork             += reachSpecCalculatorThread_DoWork;
            worker.ProgressChanged    += reachSpecCalculatorThread_ProgressChanged;
            worker.RunWorkerCompleted += reachSpecCalculatorThread_Done;

            BGThreadOptions bgo = new BGThreadOptions();

            bgo.pcc      = pe.pcc;
            bgo.readOnly = readOnlyCheckbox.Checked;

            worker.RunWorkerAsync(bgo);
        }
Exemplo n.º 2
0
        private void reachSpecCalculatorThread_DoWork(object sender, DoWorkEventArgs e)
        {
            worker.ReportProgress(-1, "Getting list of all used ReachSpecs in pcc");
            //Figure out which exports have PathList.
            BGThreadOptions  bgo = (BGThreadOptions)e.Argument;
            IMEPackage       pcc = bgo.pcc;
            HashSet <int>    reachSpecExportIndexes = new HashSet <int>();
            List <string>    badSpecs = new List <string>();
            HashSet <string> names    = new HashSet <string>();

            foreach (IExportEntry exp in pcc.Exports)
            {
                ArrayProperty <ObjectProperty> pathList = exp.GetProperty <ArrayProperty <ObjectProperty> >("PathList");
                if (pathList != null)
                {
                    foreach (ObjectProperty reachSpecObj in pathList)
                    {
                        reachSpecExportIndexes.Add(reachSpecObj.Value - 1);
                        IExportEntry   spec      = pcc.Exports[reachSpecObj.Value - 1];
                        var            specProps = spec.GetProperties();
                        ObjectProperty start     = specProps.GetProp <ObjectProperty>("Start");
                        if (start.Value != exp.UIndex)
                        {
                            badSpecs.Add((reachSpecObj.Value - 1).ToString() + " " + spec.ObjectName + " start value does not match the node that references it (" + exp.Index + ")");
                        }

                        //get end
                        StructProperty end         = specProps.GetProp <StructProperty>("End");
                        ObjectProperty endActorObj = end.GetProp <ObjectProperty>("Actor");
                        if (endActorObj.Value == start.Value)
                        {
                            badSpecs.Add((reachSpecObj.Value - 1).ToString() + " " + spec.ObjectName + " start and end property is the same. This will crash the game.");
                        }

                        var guid = SharedPathfinding.GetGUIDFromStruct(end.GetProp <StructProperty>("Guid"));
                        if ((guid.A | guid.B | guid.C | guid.D) == 0 && endActorObj.Value == 0)
                        {
                            badSpecs.Add((reachSpecObj.Value - 1).ToString() + " " + spec.ObjectName + " has no guid and has no endactor.");
                        }
                        if (endActorObj.Value - 1 > pcc.ExportCount)
                        {
                            badSpecs.Add((reachSpecObj.Value - 1).ToString() + " " + spec.ObjectName + " has invalid end property (past end of bounds).");
                        }
                        if (endActorObj.Value > 0)
                        {
                            IExportEntry expo = pcc.Exports[endActorObj.Value - 1];
                            names.Add(expo.ClassName);
                        }
                        //
                    }
                }
            }
            int i = 0;

            foreach (string item in names)
            {
                Debug.WriteLine(i + " " + item);
                i++;
            }
            worker.ReportProgress(-1, "Calculating " + reachSpecExportIndexes.Count + " reachspecs");

            int currentCalculationNum = 1; //Start at 1 cause humans.
            int numNeedingRecalc      = 0;

            foreach (int specExportId in reachSpecExportIndexes)
            {
                //worker.ReportProgress(-1, "Calculating reachspecs [" + currentCalculationNum + "/" + reachSpecExportIndexes.Count + "]");
                IExportEntry exp         = pcc.Exports[specExportId];
                bool         needsRecalc = calculateReachSpec(exp, bgo.readOnly);
                if (needsRecalc)
                {
                    numNeedingRecalc++;
                }
                double percent     = (currentCalculationNum / reachSpecExportIndexes.Count) * 100;
                int    feedPercent = RoundDoubleToInt(percent);
                worker.ReportProgress(feedPercent);
                currentCalculationNum++;
            }


            if (bgo.readOnly)
            {
                if (numNeedingRecalc == 0)
                {
                    worker.ReportProgress(-1, "No reachspecs need updated.");
                }
                else
                {
                    worker.ReportProgress(-1, numNeedingRecalc + " reachspec" + ((numNeedingRecalc > 1) ? "s" : "") + " need updated.");
                }
            }
            else
            {
                if (numNeedingRecalc == 0)
                {
                    worker.ReportProgress(-1, "No reachspecs needed updating.");
                }
                else
                {
                    worker.ReportProgress(-1, numNeedingRecalc + " reachspec" + ((numNeedingRecalc > 1) ? "s" : "") + " have been updated.");
                }
            }
            e.Result = badSpecs;
        }