Example #1
0
        public SmartSpriteBatchManager(SmartSpriteBatch smartSpriteBatch, SpriteSortMode sortMode = SpriteSortMode.Immediate, BlendState blendState = null, SamplerState samplerState = null, DepthStencilState depthStencilState = null, RasterizerState rasterizerState = null, Effect effect = null, Matrix?transformMatrix = null, FloatRectangle?scissorRect = null)
        {
            this.smartSpriteBatch = smartSpriteBatch;
            if (blendState == null)
            {
                blendState = BlendState.NonPremultiplied;
            }

            if (scissorRect.HasValue)
            {
                this.smartSpriteBatch.GraphicsDevice.ScissorRectangle = scissorRect.ToRectangle();
            }

            this.smartSpriteBatch.Begin(sortMode, blendState, samplerState, depthStencilState, rasterizerState, effect, transformMatrix, scissorRect.ToRectangle());
        }
Example #2
0
        public void Draw(SmartSpriteBatch spriteBatch, GameTime gameTime)
        {
            try
            {
                Solids.Instance.Bounds = spriteBatch.GraphicsDevice.Viewport.Bounds;

                Texture2D previousTexture = null;


                var smartList = SmartList().ToList();

                if (smartList.Any(t => t.IsBackgroundBlocking))
                {
                    int zindex = smartList.OrderBy(t => t.ZIndex).First(t => t.IsBackgroundBlocking).ZIndex;

                    smartList = smartList.Where(t => t.ZIndex >= zindex).ToList();
                }

                //smartList.RemoveAll(x => x is FSLoadingScreen);

                //if (Solids.Screens.SmartList().Any(x=>x is FSLoadingScreen))
                //{
                //    smartList.Add(Solids.Screens.SmartList().First(y => y is FSLoadingScreen));
                //}

                foreach (BaseScreen screen in smartList)
                {
                    {
                        if (screen.RenderTarget == null || screen.RenderTarget.Bounds != Solids.Instance.Bounds)
                        {
                            screen.RenderTarget = new RenderTarget2D(Solids.Instance.SpriteBatch.GraphicsDevice, Solids.Instance.Bounds.Width, Solids.Instance.Bounds.Height);
                        }

                        Solids.Instance.SpriteBatch.GraphicsDevice.SetRenderTarget(screen.RenderTarget);
                        Solids.Instance.SpriteBatch.GraphicsDevice.Clear(Color.Transparent);
                        screen.Draw(gameTime, screen.OpenCloseOpacity, previousTexture);

                        previousTexture = screen.RenderTarget;
                    }
                }

                Solids.Instance.SpriteBatch.GraphicsDevice.SetRenderTarget(null);
                Solids.Instance.SpriteBatch.GraphicsDevice.Clear(Color.TransparentBlack);

                if (smartList.Count > 0)
                {
                    using (new SmartSpriteBatchManager(Solids.Instance.SpriteBatch, SpriteSortMode.Immediate, BlendState.Opaque, SamplerState.AnisotropicClamp, DepthStencilState.None, RasterizerState.CullNone, null, null))
                    {
                        Solids.Instance.SpriteBatch.Draw(previousTexture, Solids.Instance.Bounds, null, Color.White);
                    }
                }

                //foreach (BaseScreen screen in Solids.Screens.SmartList())
                //{
                //    if (screen.RenderTarget != null)
                //    {
                //        Solids.Instance.SpriteBatch.Draw(screen.RenderTarget, Solids.Bounds, null, Color.White);
                //    }
                //    else
                //    {
                //        BreezeDebug.WriteLine(screen.ToString()+" has a null render target?");
                //    }
                //}


                //Solids.Instance.SpriteBatch.GraphicsDevice.SetRenderTarget(null);
                //Solids.Instance.SpriteBatch.GraphicsDevice.Clear(Color.Pink);
                //Solids.Instance.SpriteBatch.ForceBegin(SpriteSortMode.Immediate,BlendState.Opaque,SamplerState.AnisotropicClamp, DepthStencilState.None, RasterizerState.CullNone, null, null);
                //Solids.Instance.SpriteBatch.Draw(texture, Solids.Bounds, null, Color.White);
                //Solids.Instance.SpriteBatch.Draw(txt, Solids.Bounds, null, Color.White);

                //int width = (Solids.Bounds.Width / 20);

                //float ratio= ((float)txt.Width / (float)txt.Height);
                //int height = (int)((float)width/ ratio);

                //Solids.Instance.SpriteBatch.Draw(txt, new Rectangle(Solids.Bounds.X - width, Solids.Bounds.Y-height,width,height),null, Color.White);
                //Solids.Instance.SpriteBatch.ForceEnd();

                //     if (spriteBatch.GraphicsDevice.Viewport.Bounds != previousScreenBounds || Solids.Instance.ScreenManager.ToList().Any(t => t is BaseScreen && !((BaseScreen)t).BoundsSet))
                {
                    foreach (BaseScreen screen in SmartList().Where(t => t is BaseScreen && ((BaseScreen)t).IsFullScreen))
                    {
                        screen.SetBounds(spriteBatch.GraphicsDevice.Viewport.Bounds);
                    }

                    //  previousScreenBounds = spriteBatch.GraphicsDevice.Viewport.Bounds;
                }

                //if (Solids.Instance.InputService != null)
                //{
                //    spriteBatch.Begin();
                //    spriteBatch.Draw(Helpers.TextureHelpers.GetPoint(spriteBatch), new Rectangle((int)Solids.Instance.InputService.MousePosition.X, (int)Solids.Instance.InputService.MousePosition.Y, 1, 1), Color.Black);
                //    spriteBatch.End();
                //}
            }
            catch
            {
            }

            HandleScreenUpdate();
        }
Example #3
0
        public BreezeInstance(ContentManager contentManager, SpriteBatch spriteBatch, Game game)
        {
            ScreenManager = new ScreenManager();
            SpriteBatch   = new SmartSpriteBatch(spriteBatch.GraphicsDevice);
            AssetLibrary  = new AssetLibrary(SpriteBatch);
            GaussianBlur  = new Breeze.Helpers.GaussianBlur(game);
            InputService  = new InputService();



#if WINDOWS_UAP
            StorageFolder folder = Windows.ApplicationModel.Package.Current.InstalledLocation;

            ContentPath         = folder.Path + "\\";
            ContentPathRelative = "\\";
#elif ANDROID
            Solids.ContentPath         = "Content\\";
            Solids.ContentPathRelative = "Content\\";
#else
            Solids.ContentPath         = "\\Ezmuze.Content\\";
            Solids.ContentPathRelative = "\\Ezmuze.Content\\";
#endif

#if WINDOWS_UAP
            //string pakPath = ContentPathRelative.GetFilePath("Content.pak");
            Debug.WriteLine(FileLocation.InstalledLocation);

            if (Storage.FileSystemStorage.FileExists(ContentPath.GetFilePath("Content.pak")))
            {
                string cpath = ContentPathRelative.GetFilePath("Content.pak");
                Debug.WriteLine("content pak path: " + cpath);
                StorageFile packBuffer = Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(cpath).GetAwaiter().GetResult();

                Stream stream       = packBuffer.OpenStreamForReadAsync().Result;
                int    streamLength = (int)stream.Length;
                byte[] tmp          = new byte[streamLength];
                stream.Read(tmp, 0, tmp.Length);

                string tocPath = ContentPathRelative.GetFilePath("Content.toc");

                Debug.WriteLine("Toc path: " + tocPath);
                var tocBuffer = Windows.ApplicationModel.Package.Current.InstalledLocation.GetFileAsync(tocPath).GetAwaiter().GetResult();

                string json = FileIO.ReadTextAsync(tocBuffer).GetAwaiter().GetResult();



                Storage.DatfileStorage.TabletOfContents = JsonConvert.DeserializeObject <List <FileEntry> >(json);
                Storage.DatfileStorage.DataStorage      = tmp;
            }

            Debug.WriteLine("test!");
            //Solids.Breeze.Storage.Init(Solids.ContentPathRelative,tmp).ConfigureAwait(false).GetAwaiter().GetResult();
#elif ANDROID
            string pakPath = ("Content.pak");
            string tocPath = ("Content.toc");

            Stream tocBuffer = tocPath.FromAsset();
            var    sr        = new StreamReader(tocBuffer);
            string json      = sr.ReadToEnd();

            Solids.DatfileStorage.TabletOfContents = JsonConvert.DeserializeObject <List <Storage.FileEntry> >(json);

            var pakBuffer = pakPath.ToStream().Result;

            int length = Solids.DatfileStorage.TabletOfContents.Last().Start + Solids.DatfileStorage.TabletOfContents.Last().Length;

            byte[] data = new byte[length];
            pakBuffer.Read(data, 0, (int)length);
            Solids.DatfileStorage.DataStorage = data;
#endif
            Solids.Instance = this;



            //todo - this needs to be hella more dynamic
            Fonts = new Font
            {
                EuroStile  = new FontFamily("EuroStile", "eurostile"),
                Consolas   = new FontFamily("Consolas", "consolas"),
                MDL2       = new FontFamily("MDL2", "mdl"),
                Segoe      = new FontFamily("SegoeUI", "SegoeUI"),
                SegoeLight = new FontFamily("SegoeUILight", "SegoeUILight")
            };

            Fonts.Fonts.Add("EuroStile", Fonts.EuroStile);
            Fonts.Fonts.Add("Consolas", Fonts.Consolas);
            Fonts.Fonts.Add("MDL2", Fonts.MDL2);
            Fonts.Fonts.Add("Segoe", Fonts.Segoe);
            Fonts.Fonts.Add("SegoeLight", Fonts.SegoeLight);
        }
Example #4
0
        public void Draw(SmartSpriteBatch spriteBatch, bool showDebug)
        {
            BMFont font = Solids.Instance.AssetLibrary.GetFont("consolas");

            if (font != null)
            {
                if (showDebug)
                {
                    var bounds = spriteBatch.GraphicsDevice.Viewport.Bounds;
                    spriteBatch.DrawSolidRectangle(new FloatRectangle(0, 0, bounds.Width, (int)(bounds.Height * 0.8f)), Color.CornflowerBlue * 0.75f);
                }
                var scale = new Vector2(0.75f, 0.75f);
                int mxh   = 0;
                int mxw   = 0;
                foreach (var i in DebugObjects)
                {
                    var r = font.MeasureString(i.CurrentText) * scale;
                    if (r.X > mxw)
                    {
                        mxw = (int)r.X;
                    }
                    if (r.Y > mxh)
                    {
                        mxh = (int)r.Y;
                    }
                }
                int width = 100 + mxw + 20;

                if (showDebug)
                {
                    spriteBatch.DrawSolidRectangle(new FloatRectangle(spriteBatch.GraphicsDevice.Viewport.Bounds.Width - (int)width - 20, 2, (int)width, (int)mxh * DebugObjects.Count), Color.Black);
                }

                int   ct = 0;
                float mx = 1;

                if (showDebug && false)
                {
                    Vector2 fontscale = new Vector2(0.4f, 0.4f);
                    int     ps        = 50;
                    font.DrawText(spriteBatch, new Vector2(10, 20), "Key", Color.White, fontscale);
                    font.DrawText(spriteBatch, new Vector2(300, 20), "Runs", Color.White, fontscale);
                    font.DrawText(spriteBatch, new Vector2(450, 20), "Avg", Color.White, fontscale);
                    font.DrawText(spriteBatch, new Vector2(600, 20), "Min", Color.White, fontscale);
                    font.DrawText(spriteBatch, new Vector2(750, 20), "Max", Color.White, fontscale);
                    font.DrawText(spriteBatch, new Vector2(900, 20), "Total", Color.White, fontscale);
                    foreach (KeyValuePair <string, BenchMarkDetails> benchMarkDetailse in BenchMarkProvider.BenchMarks)
                    {
                        font.DrawText(spriteBatch, new Vector2(10, ps), benchMarkDetailse.Key, Color.White, new Vector2(0.5f, 0.5f));
                        font.DrawText(spriteBatch, new Vector2(300, ps), benchMarkDetailse.Value.NumberOfTimesRun.ToString(), Color.White, fontscale);
                        font.DrawText(spriteBatch, new Vector2(450, ps), benchMarkDetailse.Value.AverageTime.ToString("c"), Color.White, fontscale);
                        font.DrawText(spriteBatch, new Vector2(600, ps), benchMarkDetailse.Value.ShortestTime.ToString("c"), Color.White, fontscale);
                        font.DrawText(spriteBatch, new Vector2(750, ps), benchMarkDetailse.Value.LongestTime.ToString("c"), Color.White, fontscale);
                        font.DrawText(spriteBatch, new Vector2(900, ps), benchMarkDetailse.Value.TotalTime.ToString("c"), Color.White, fontscale);

                        ps = ps + 30;
                    }
                }

                if (showDebug && true)
                {
                    Vector2 fontscale = new Vector2(0.4f, 0.4f);
                    int     ps        = 50 + (BreezeDebug.ConsoleHistory.Count * 30);

                    if (ps > 700)
                    {
                        ps = 700;
                    }

                    foreach (string history in BreezeDebug.ConsoleHistory)
                    {
                        if (ps > 0)
                        {
                            font.DrawText(spriteBatch, new Vector2(10, ps), history, Color.White, new Vector2(0.5f, 0.5f));
                            ps = ps - 30;
                        }
                    }
                }

                if (false)
                {
                    foreach (var i in DebugObjects)
                    {
                        if (showDebug)
                        {
                            font.DrawText(spriteBatch,
                                          new Vector2(spriteBatch.GraphicsDevice.Viewport.Bounds.Width - width - 10, mxh * ct),
                                          i.CurrentText, Color.White, scale);
                            if (Solids.Instance.FrameCounter.CurrentFramesPerSecond > 59)
                            {
                                if (pointer % 500 == 0)
                                {
                                    mx = Math.Max(i.HistoricValues.Max(), 1);

                                    if (mx > i.MXValue)
                                    {
                                        i.MXValue = mx;
                                    }
                                    else
                                    {
                                        i.MXValue = i.MXValue * 0.995f;
                                    }
                                }

                                mx = i.MXValue;

                                int xct = 0;
                                for (int x = pointer; x < pointer + 49; x++)
                                {
                                    float h1 = (i.HistoricValues[x % 50] / mx) * mxh;
                                    float h2 = (i.HistoricValues[(x + 1) % 50] / mx) * mxh;

                                    int ps = spriteBatch.GraphicsDevice.Viewport.Bounds.Width - 90 + (xct * 2);

                                    spriteBatch.DrawLine(new Vector2(ps, h1 + (ct * mxh)),
                                                         new Vector2(ps + 2, h2 + (ct * mxh)), Color.White);

                                    xct++;
                                }
                            }

                            ct++;
                        }

                        i.HistoricValues[pointer % 50] = i.CurrentValue;
                    }
                }

                pointer++;
            }
        }
Example #5
0
 public AssetLibrary(SmartSpriteBatch sb)
 {
     spriteBatch = sb;
 }