Пример #1
0
        private void UpdateTask()
        {
            if (!mTask.IsFinished)
            {
                return;
            }

            mLogger.Log(mTask.Messages);

            if (mTask.TaskState == BuildTaskState.Aborted)
            {
                FinalizeOnFail("Input geometry build failed.", true);
                return;
            }

            mGeometry = mTask.Result;

            mLogger.PostTrace("Completed input geometry build.", mTask.Messages, mContext.Build);
            mTask = null;

            mState = State.Finished;
        }
Пример #2
0
        private bool BuildSingleTile()
        {
            TileBuildData tdata  = mBuild.BuildData;
            NMGenConfig   config = mBuild.Config;
            InputGeometry geom   = mBuild.InputGeom;

            mContext.ResetLog();

            /*
             * Design note:
             *
             * Not using the build task since it doesn't provide enough progress
             * feedback for a single tile.
             *
             */

            // Create the NMGen builder.

            IncrementalBuilder builder = IncrementalBuilder.Create(config.GetConfig()
                                                                   , config.ResultOptions
                                                                   , geom
                                                                   , mBuild.NMGenProcessors);

            if (builder == null)
            {
                mContext.PostError("Unexpected failure creating NMGen builder.", mBuild);
                tdata.SetAsFailed(0, 0);
                return(false);
            }
            else if (builder.IsFinished)
            {
                if (builder.State == NMGenState.NoResult)
                {
                    mContext.PostError("NMGen build did not produce a result. (Early exit.)"
                                       , builder.GetMessages(), mBuild);
                    tdata.SetAsFailed(0, 0);
                    return(false);
                }
                else
                {
                    mContext.PostError("Unexpected NMGen builder completion."
                                       , builder.GetMessages(), mBuild);
                    tdata.SetAsFailed(0, 0);
                    return(false);
                }
            }

            mBuild.BuildData.SetAsInProgress(0, 0);

            // Run the NMGen builder.

            while (!builder.IsFinished)
            {
                if (EditorUtility.DisplayCancelableProgressBar("Build Single Tile Mesh"
                                                               , IncrementalBuilder.ToLabel(builder.State)
                                                               , IncrementalBuilder.ToProgress(builder.State)))
                {
                    return(false);
                }

                builder.Build();
            }

            // Handle NMGen failures.

            mContext.Log(builder.GetMessages());   // Single tile build.  So go ahead an record.

            switch (builder.State)
            {
            case NMGenState.Aborted:

                mContext.PostError("NMGen build failed.", mBuild);
                tdata.SetAsFailed(0, 0);
                return(false);

            case NMGenState.NoResult:

                mContext.PostError("NMGen build did not produce a result.", mBuild);
                tdata.SetAsFailed(0, 0);
                return(false);
            }

            mContext.Log(string.Format("Completed NMGen build: {0} polygons."
                                       , builder.Result.PolyMesh.PolyCount)
                         , mBuild);

            // Build the tile.

            NMGenAssets result = builder.Result;

            if (result.DetailMesh == null)
            {
                Debug.LogError("result.DetailMesh ==null!");
            }

            NavmeshTileBuildData tbd = org.critterai.nmbuild.NMBuild.GetBuildData(
                mContext, 0, 0
                , result.PolyMesh.GetData(false), result.DetailMesh.GetData(false)
                , mBuild.Connections
                , (config.BuildFlags & NMGenBuildFlag.BVTreeEnabled) != 0);

            if (tbd == null)
            {
                // No need to log the error.  The above method takes care of that.
                tdata.SetAsFailed(0, 0);
                return(false);
            }

            NavmeshTileData td = NavmeshTileData.Create(tbd);

            if (td.Size == 0)
            {
                mContext.PostError(
                    "Could not create {0} object. Cause unknown." + typeof(NavmeshTileData)
                    , mBuild);
                tdata.SetAsFailed(0, 0);
                return(false);
            }

            // Finalize the tile.

            tdata.SetWorkingData(0, 0, result.PolyMesh, result.DetailMesh);
            tdata.SetWorkingData(0, 0, td, tbd.PolyCount);

            mContext.PostTrace("Completed single tile build.", mBuild);

            return(true);
        }
Пример #3
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);
                }
            }
        }