Ejemplo n.º 1
0
        /// <summary>Sets up the current batch based on the isolation settings requested by a property.</summary>
        /// <param name="property">The displayable property which wants the batch.</param>
        /// <param name="fontTexture">The font texture to use with this batch.</param>
        public void SetupBatch(DisplayableProperty property, TextureAtlas graphics, TextureAtlas font)
        {
            if (property.Isolated)
            {
                if (property.GotBatchAlready)
                {
                    // The property already got a batch on this layout - it doesn't need another.
                    return;
                }

                // Isolated properties always get a new batch every time.
                CurrentBatch = UIBatchPool.Get(this);

                if (CurrentBatch == null)
                {
                    CurrentBatch = new UIBatch(this);
                }

                property.GotBatchAlready = true;

                // And push it to the active stack:
                AddBatch(CurrentBatch);

                // Make sure it knows it's isolated:
                CurrentBatch.IsIsolated(property);
            }
            else
            {
                if (CurrentBatch != null && !CurrentBatch.Isolated)
                {
                    // Re-use existing batch?

                    if (font != null)
                    {
                        if (CurrentBatch.FontAtlas == null)
                        {
                            // Didn't have one assigned before. Assign now:
                            CurrentBatch.SetFontAtlas(font);
                        }
                        else if (font != CurrentBatch.FontAtlas)
                        {
                            // Font atlas changed. Can't share.
                            CurrentBatch = null;
                        }
                    }

                    if (graphics != null)
                    {
                        if (CurrentBatch.GraphicsAtlas == null)
                        {
                            // Didn't have one assigned before. Assign now:
                            CurrentBatch.SetGraphicsAtlas(graphics);
                        }
                        else if (graphics != CurrentBatch.GraphicsAtlas)
                        {
                            // Atlas changed. Can't share.
                            CurrentBatch = null;
                        }
                    }

                    if (CurrentBatch != null)
                    {
                        // Yep - reuse it.
                        return;
                    }
                }

                // Pull a batch from the pool and set it to currentbatch. May need to generate a new one.
                CurrentBatch = UIBatchPool.Get(this);

                if (CurrentBatch == null)
                {
                    CurrentBatch = new UIBatch(this);
                }

                // And push it to the active stack:
                AddBatch(CurrentBatch);

                // Make sure it knows it's not isolated:
                CurrentBatch.NotIsolated(graphics, font);
            }

            // Finally, prepare it for layout:
            CurrentBatch.PrepareForLayout();
        }