Beispiel #1
0
        private void ManageNMGenRequests()
        {
            mLogger.ResetLog();

            TileBuildData tdata = mContext.Build.BuildData;

            // Due to concurrency with the input build, this method
            // does not log things via the context.

            List <NMGenTask> requests = mContext.NMGenTasks;

            for (int i = requests.Count - 1; i >= 0; i--)
            {
                NMGenTask item = requests[i];

                if (item.IsFinished)
                {
                    requests.RemoveAt(i);

                    NavmeshBuild build = mContext.Build;

                    if (!build)
                    {
                        // Asset was deleted.
                        continue;
                    }

                    string tileText = string.Format("({0},{1})", item.TileX, item.TileZ);

                    switch (item.TaskState)
                    {
                    case BuildTaskState.Aborted:

                        mLogger.Log(item.Messages);
                        mLogger.PostError("Tile build failed: " + tileText, build);

                        tdata.SetAsFailed(item.TileX, item.TileZ);

                        break;

                    case BuildTaskState.Complete:

                        NMGenAssets r = item.Result;

                        if (r.NoResult)
                        {
                            mLogger.PostTrace("NMGen build complete. Tile is empty: " + tileText
                                              , item.Messages, build);

                            tdata.SetAsEmpty(r.TileX, r.TileZ);
                        }
                        else
                        {
                            tdata.SetWorkingData(r.TileX, r.TileZ, r.PolyMesh, r.DetailMesh);

                            mLogger.PostTrace("NMGen build complete: " + tileText
                                              , item.Messages, build);

                            mContext.QueueTask(mLogger, r.TileX, r.TileZ
                                               , r.PolyMesh, r.DetailMesh
                                               , (build.Config.BuildFlags & NMGenBuildFlag.BVTreeEnabled) != 0
                                               , item.Priority);
                        }

                        break;
                    }
                }
                else if (item.TaskState == BuildTaskState.InProgress &&
                         tdata.GetState(item.TileX, item.TileZ) != TileBuildState.InProgress)
                {
                    // Transition to the in-progress state.
                    tdata.SetAsInProgress(item.TileX, item.TileZ);
                }
            }
        }
Beispiel #2
0
        private void UpdateBuilder()
        {
            if (!mBuilder.IsFinished)
            {
                mBuilder.Build();
                return;
            }

            mLogger.Log(mBuilder.Messages);

            NavmeshBuild build = mContext.Build;  // Caller has validated.

            if (mBuilder.State == InputBuildState.Aborted)
            {
                FinalizeOnFail("Input data compile failed: Builder aborted.", true);
                return;
            }

            mAssets = mBuilder.Result;

            TriangleMesh mesh = mAssets.geometry;

            if (!InputGeometryBuilder.IsValid(mesh, mAssets.areas))
            {
                FinalizeOnFail("Input geometry failed validation. (Malformed data.)", true);
                return;
            }

            InputGeometryBuilder gbuilder = InputGeometryBuilder.UnsafeCreate(mesh
                                                                              , mAssets.areas
                                                                              , build.Config.GetConfig().WalkableSlope
                                                                              , true);

            if (gbuilder == null)
            {
                FinalizeOnFail("Could not create input geometry builder. (Internal error.)", true);
                return;
            }

            // Release unneeded assets.
            mAssets.geometry = null;
            mAssets.areas    = null;
            mBuilder         = null;

            mTask = InputBuildTask.Create(gbuilder, BuildTaskProcessor.HighPriority);

            if (mTask == null)
            {
                FinalizeOnFail("Task creation failed. (Internal error.)", true);
            }
            else if (mContext.QueueTask(mTask))
            {
                mLogger.PostTrace("Completed input build. Submitted geometry build task."
                                  , mContext.Build);
                mState = State.Task;
            }
            else
            {
                FinalizeOnFail("Task submission failed. (Internal error.)", true);
            }
        }