예제 #1
0
 public static RenderTarget2D GeneratePreview(
     string levelPath,
     RenderTarget2D target = null,
     bool background       = false)
 {
     DuckGame.Content._previewBackground   = background;
     DuckGame.Content.readyToRenderPreview = false;
     if (DuckGame.Content._previewThread != null && DuckGame.Content._previewThread.IsAlive)
     {
         DuckGame.Content.cancelPreview = true;
         int num = 250;
         while (DuckGame.Content._previewThread.IsAlive)
         {
             Tasker.RunTasks();
             Thread.Sleep(2);
             --num;
         }
         DuckGame.Content.readyToRenderPreview = false;
     }
     DuckGame.Content._previewThread = (Thread)null;
     DuckGame.Content.cancelPreview  = false;
     Thing.skipLayerAdding           = false;
     Level.skipInitialize            = false;
     if (DuckGame.Content._previewBatch == null)
     {
         DuckGame.Content._previewBatch = new MTSpriteBatch(DuckGame.Graphics.device);
     }
     DuckGame.Content._previewPath = levelPath;
     if (DuckGame.Content._previewTarget == null)
     {
         DuckGame.Content._previewTarget = new RenderTarget2D(MonoMain.screenWidth, MonoMain.screenHeight);
     }
     DuckGame.Content._currentPreviewTarget = target == null ? DuckGame.Content._previewTarget : target;
     if (DuckGame.Content._previewBackground)
     {
         DuckGame.Content.renderingPreview     = true;
         DuckGame.Content.readyToRenderPreview = true;
         DuckGame.Content.PreviewThread();
         DuckGame.Content.DoPreviewRender();
         DuckGame.Content.renderingPreview     = false;
         DuckGame.Content.readyToRenderPreview = false;
     }
     else
     {
         DuckGame.Content._previewThread = new Thread(new ThreadStart(DuckGame.Content.PreviewThread));
         DuckGame.Content._previewThread.CurrentCulture = CultureInfo.InvariantCulture;
         DuckGame.Content._previewThread.Priority       = ThreadPriority.BelowNormal;
         DuckGame.Content._previewThread.IsBackground   = true;
         DuckGame.Content._previewThread.Start();
     }
     return(DuckGame.Content._currentPreviewTarget);
 }
예제 #2
0
        public static LevelData LoadLevel(byte[] data)
        {
            LevelData levelData = BinaryClassChunk.FromData <LevelData>(new BitBuffer(data, false));

            if (levelData != null && levelData.GetResult() != DeserializeResult.InvalidMagicNumber)
            {
                return(levelData);
            }
            Promise <LevelData> promise = Tasker.Task <LevelData>((Func <LevelData>)(() => DuckFile.ConvertLevel(data)));

            promise.WaitForComplete();
            return(promise.Result);
        }