コード例 #1
0
ファイル: GuiRenderJob.cs プロジェクト: edkek/Sharp2D
        protected override SpriteBatch[] CreateCulledBatches()
        {
            var drawPasses = base.DrawPasses;

            var batches = new DrawBatch[drawPasses.Count];

            for (int i = 0; i < batches.Length; i++)
            {
                batches[i] = new DrawBatch();
                DrawBatch batch = batches[i];
                DrawPass  pass  = drawPasses[i];

                pass.SetupBatch(batch);
            }

            Batch.ForEach(delegate(Sprite sprite)
            {
                if (sprite.IsOffScreen || !sprite.IsVisible)
                {
                    return;
                }
                for (int i = 0; i < batches.Length; i++)
                {
                    if (drawPasses[i].MeetsRequirements(sprite))
                    {
                        batches[i].Add(sprite);
                    }
                }
            });

            return(batches);
        }
コード例 #2
0
        protected override SpriteBatch[] CreateCulledBatches()
        {
            var drawPasses = base.DrawPasses;

            var batches = new DrawBatch[drawPasses.Count];

            for (int i = 0; i < batches.Length; i++)
            {
                batches[i] = new DrawBatch();
                DrawBatch batch = batches[i];
                DrawPass  pass  = drawPasses[i];

                pass.SetupBatch(batch);
            }

            Batch.ForEach(delegate(Sprite sprite)
            {
                if (sprite.IsOffScreen || !sprite.IsVisible || Math.Abs(sprite.Alpha) < 0.001f)
                {
                    return;
                }
                CullLights(sprite);
                for (int i = 0; i < batches.Length; i++)
                {
                    if (drawPasses[i].MeetsRequirements(sprite))
                    {
                        batches[i].Add(sprite);
                    }
                }
            });

            float cx = -Screen.Camera.X;
            float cy = Screen.Camera.Y;

            float cullWidth  = 380f * (Screen.Camera.Z / 100f);
            float cullHeight = 256f * (Screen.Camera.Z / 100f);

            cullWidth  *= (Screen.Settings.GameSize.Width / 1024f);
            cullHeight *= (Screen.Settings.GameSize.Height / 720f);
            cullWidth  /= 2f;
            cullHeight /= 2f;
            var parent = base.ParentWorld;

            foreach (Layer layer in parent.Layers)
            {
                if (!layer.IsTileLayer)
                {
                    continue;
                }
                float ex = cx + (cullWidth + (3f * parent.TileWidth));
                float ey = cy + cullHeight;
                float sx = cx - cullWidth;
                float sy = cy - cullHeight;

                int sIx = Math.Max((int)(sx / parent.TileWidth), 0);
                int sIy = Math.Max((int)Math.Ceiling((sy - 8f) / parent.TileHeight), 0);

                int eIx = Math.Max((int)(ex / parent.TileWidth), 0);
                int eIy = Math.Max((int)Math.Ceiling((ey - 8f) / parent.TileHeight), 0);


                for (int x = sIx; x <= eIx; x++)
                {
                    for (int y = sIy; y < eIy; y++)
                    {
                        TileSprite sprite = layer[x, y];
                        if (sprite == null)
                        {
                            continue;
                        }

                        CullLights(sprite);
                        for (int i = 0; i < batches.Length; i++)
                        {
                            if (drawPasses[i].MeetsRequirements(sprite))
                            {
                                batches[i].Add(sprite);
                            }
                        }
                    }
                }
            }

            return(batches);
        }