public override void Update()
 {
     Layer.lighting = true;
     if (this._initialized)
     {
         return;
     }
     this._geo = MTSpriteBatch.CreateGeometryItem();
     this.DrawLight();
     this._initialized = true;
 }
 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);
 }
 public MTSpriteBatcher(GraphicsDevice device, MTSpriteBatch batch)
 {
     this._device                    = device;
     this._batch                     = batch;
     this._batchItemList             = new List <MTSpriteBatchItem>(256);
     this._freeBatchItemQueue        = new Queue <MTSpriteBatchItem>(256);
     this._simpleBatchItemList       = new List <MTSimpleSpriteBatchItem>(256);
     this._freeSimpleBatchItemQueue  = new Queue <MTSimpleSpriteBatchItem>(256);
     this._geometryBatch             = new List <GeometryItem>(1);
     this._freeGeometryBatch         = new Queue <GeometryItem>(1);
     this._geometryBatchTextured     = new List <GeometryItemTexture>(1);
     this._freeGeometryBatchTextured = new Queue <GeometryItemTexture>(1);
     this.EnsureArrayCapacity(256);
     this.EnsureSimpleArrayCapacity(256);
     this.EnsureGeometryArrayCapacity(256);
     this.EnsureTexturedGeometryArrayCapacity(256);
 }
        private static void DoPreviewRender()
        {
            MTSpriteBatch screen = DuckGame.Graphics.screen;

            DuckGame.Graphics.screen = DuckGame.Content._previewBatch;
            Viewport viewport = DuckGame.Graphics.viewport;

            DuckGame.Graphics.SetRenderTarget(DuckGame.Content._currentPreviewTarget);
            DuckGame.Graphics.viewport = new Viewport(0, 0, DuckGame.Content._currentPreviewTarget.width, DuckGame.Content._currentPreviewTarget.height);
            string str1 = Custom.data[CustomType.Block][0];

            if (Custom.previewData[CustomType.Block][0] != null)
            {
                Custom.ApplyCustomData(Custom.previewData[CustomType.Block][0].GetTileData(), 0, CustomType.Block);
            }
            string str2 = Custom.data[CustomType.Block][1];

            if (Custom.previewData[CustomType.Block][1] != null)
            {
                Custom.ApplyCustomData(Custom.previewData[CustomType.Block][1].GetTileData(), 1, CustomType.Block);
            }
            string str3 = Custom.data[CustomType.Block][2];

            if (Custom.previewData[CustomType.Block][2] != null)
            {
                Custom.ApplyCustomData(Custom.previewData[CustomType.Block][2].GetTileData(), 2, CustomType.Block);
            }
            string str4 = Custom.data[CustomType.Background][0];

            if (Custom.previewData[CustomType.Background][0] != null)
            {
                Custom.ApplyCustomData(Custom.previewData[CustomType.Background][0].GetTileData(), 0, CustomType.Background);
            }
            string str5 = Custom.data[CustomType.Background][1];

            if (Custom.previewData[CustomType.Background][1] != null)
            {
                Custom.ApplyCustomData(Custom.previewData[CustomType.Background][1].GetTileData(), 1, CustomType.Background);
            }
            string str6 = Custom.data[CustomType.Background][2];

            if (Custom.previewData[CustomType.Background][2] != null)
            {
                Custom.ApplyCustomData(Custom.previewData[CustomType.Background][2].GetTileData(), 2, CustomType.Background);
            }
            string str7 = Custom.data[CustomType.Platform][0];

            if (Custom.previewData[CustomType.Platform][0] != null)
            {
                Custom.ApplyCustomData(Custom.previewData[CustomType.Platform][0].GetTileData(), 0, CustomType.Platform);
            }
            string str8 = Custom.data[CustomType.Platform][1];

            if (Custom.previewData[CustomType.Platform][1] != null)
            {
                Custom.ApplyCustomData(Custom.previewData[CustomType.Platform][1].GetTileData(), 1, CustomType.Platform);
            }
            string str9 = Custom.data[CustomType.Platform][2];

            if (Custom.previewData[CustomType.Platform][2] != null)
            {
                Custom.ApplyCustomData(Custom.previewData[CustomType.Platform][2].GetTileData(), 2, CustomType.Platform);
            }
            if (DuckGame.Content._previewBackground)
            {
                Level     activeLevel  = Level.activeLevel;
                Level     currentLevel = Level.core.currentLevel;
                LayerCore core         = Layer.core;
                if (DuckGame.Content._previewLayerCore != null)
                {
                    Layer.core = DuckGame.Content._previewLayerCore;
                }
                Level.activeLevel       = (Level)DuckGame.Content.previewLevel;
                Level.core.currentLevel = (Level)DuckGame.Content.previewLevel;
                DuckGame.Graphics.defaultRenderTarget = DuckGame.Content._currentPreviewTarget;
                Layer.HUD.visible = false;
                DuckGame.Content.previewLevel.camera          = DuckGame.Content._previewCamera;
                DuckGame.Content.previewLevel.simulatePhysics = false;
                DuckGame.Content.previewLevel.DoUpdate();
                DuckGame.Content.previewLevel.DoUpdate();
                DuckGame.Content.previewLevel.DoDraw();
                Layer.HUD.visible = true;
                DuckGame.Graphics.defaultRenderTarget = (RenderTarget2D)null;
                Level.activeLevel       = activeLevel;
                Level.core.currentLevel = currentLevel;
                Layer.core = core;
            }
            else
            {
                DuckGame.Graphics.Clear(Color.Black);
                DuckGame.Graphics.screen.Begin(SpriteSortMode.BackToFront, BlendState.AlphaBlend, SamplerState.PointClamp, DepthStencilState.Default, RasterizerState.CullNone, (MTEffect)null, DuckGame.Content._previewCamera.getMatrix());
                foreach (Thing thing in DuckGame.Content.previewLevel.things)
                {
                    if (thing.layer == Layer.Game || thing.layer == Layer.Blocks || thing.layer == null)
                    {
                        thing.Draw();
                    }
                    DuckGame.Graphics.material = (Material)null;
                }
                DuckGame.Graphics.screen.End();
            }
            DuckGame.Graphics.screen = screen;
            DuckGame.Graphics.SetRenderTarget((RenderTarget2D)null);
            Custom.data[CustomType.Block][0]      = str1;
            Custom.data[CustomType.Block][1]      = str2;
            Custom.data[CustomType.Block][2]      = str3;
            Custom.data[CustomType.Background][0] = str4;
            Custom.data[CustomType.Background][1] = str5;
            Custom.data[CustomType.Background][2] = str6;
            Custom.data[CustomType.Platform][0]   = str7;
            Custom.data[CustomType.Platform][1]   = str8;
            Custom.data[CustomType.Platform][2]   = str9;
        }