Esempio n. 1
0
        public void RenderWorld(GameTime game_time, xAABB2 view_aabb)
        {
            if (!mRendered)
            {
                XSimpleDraw   simple_draw = XSimpleDraw.Instance(xeSimpleDrawType.WorldSpace_Persistent_Map);
                System.Random rand        = new Random();

                mMap.Iterate((grid, x, y) =>
                {
                    Vector3 low  = new Vector3(x, y, 0f);
                    Vector3 high = new Vector3(x + 1, y + 1, 0f);
                    Color color  = grid.mData[x, y].mColor;

                    simple_draw.DrawQuad(low, high, color);
                });

                // render world lines in here if they are static
                // RenderWorldLines_Static();

                mRendered = true;
            }

            // render world lines here if they are dynamic
            RenderWorldLines_Dynamic(view_aabb);
        }
Esempio n. 2
0
        public void RenderWorldLines_Static()
        {
            XSimpleDraw simple_draw_world = XSimpleDraw.Instance(xeSimpleDrawType.WorldSpace_Persistent_Map);

            Vector3 start = new Vector3();
            Vector3 end   = new Vector3();
            Color   k_transparent_black = new Color(0.0f, 0.0f, 0.0f, 0.05f);

            // each cell is 1 unit on edge in world space
            start.Y = 0;
            end.Y   = mMap.mBounds.y;

            for (int x = 0; x <= mMap.mBounds.x; ++x)
            {
                start.X = x;
                end.X   = x;

                simple_draw_world.DrawLine(start, end, k_transparent_black);
            }

            start.X = 0;
            end.X   = mMap.mBounds.x;

            for (int y = 0; y <= mMap.mBounds.y; ++y)
            {
                start.Y = y;
                end.Y   = y;

                simple_draw_world.DrawLine(start, end, k_transparent_black);
            }
        }
Esempio n. 3
0
 public void Draw(XSimpleDraw simple_draw)
 {
     // draw the text
     if (mText.Length > 50)
     {
         Console.WriteLine(mTextOffset + ", " + mText);
     }
     XFontDraw.Instance().DrawString(mStyle.mNormalFont, mPos + mTextOffset, mStyle.mTextColor, mText);
 }
Esempio n. 4
0
            public override void Render(XSimpleDraw simple_draw)
            {
                base.Render(simple_draw);
                xAABB2 aabb = GetPosition().GetScreenAABB();

                XUI.Instance().Util_DrawBox(simple_draw, GetStyle(), aabb);

                for (int i = 0; i < mChildren.Count; ++i)
                {
                    mChildren[i].Render(simple_draw);
                }
            }
Esempio n. 5
0
        public void Util_DrawBox(XSimpleDraw simple_draw, Style style, xAABB2 screen_aabb)
        {
            Vector3 lo_x_lo_y = new Vector3(screen_aabb.GetMin(), 0);
            Vector3 hi_x_hi_y = new Vector3(screen_aabb.GetMax(), 0);

            Vector2 size      = screen_aabb.GetSize();
            Vector3 lo_x_hi_y = lo_x_lo_y + new Vector3(0, size.Y, 0);
            Vector3 hi_x_lo_y = lo_x_lo_y + new Vector3(size.X, 0, 0);

            simple_draw.DrawQuad(lo_x_lo_y, hi_x_hi_y, style.mBackgroundColor);

            simple_draw.DrawLine(lo_x_lo_y, hi_x_lo_y, style.mBorderColor);
            simple_draw.DrawLine(hi_x_lo_y, hi_x_hi_y, style.mBorderColor);
            simple_draw.DrawLine(hi_x_hi_y, lo_x_hi_y, style.mBorderColor);
            simple_draw.DrawLine(lo_x_hi_y, lo_x_lo_y, style.mBorderColor);
        }
Esempio n. 6
0
        public void Initialize(GraphicsDevice graphics_device,
                               GraphicsDeviceManager graphics_device_manager,
                               ContentManager content_manager)
        {
            mGraphicsDeviceManager = graphics_device_manager;
            mGraphicsDevice        = graphics_device;
            mContentManager        = content_manager;

            var current_display_mode = GraphicsAdapter.DefaultAdapter.CurrentDisplayMode;

            mScreenDim = new xCoord(current_display_mode.Width, current_display_mode.Height);

            mGraphicsDeviceManager.IsFullScreen              = false; // true;
            mGraphicsDeviceManager.PreferredBackBufferWidth  = mScreenDim.x;
            mGraphicsDeviceManager.PreferredBackBufferHeight = mScreenDim.y;
            mGraphicsDeviceManager.ApplyChanges();

            XSimpleDraw.Initialize();
            XSimpleDraw.CreateInstance(xeSimpleDrawType.WorldSpace_Transient).Init(graphics_device,
                                                                                   persistent: false,
                                                                                   max_lines: 2000,
                                                                                   max_triangles: 50);

            XSimpleDraw.CreateInstance(xeSimpleDrawType.WorldSpace_Persistent).Init(graphics_device,
                                                                                    persistent: true,
                                                                                    max_lines: 50,
                                                                                    max_triangles: 50);

            XSimpleDraw.CreateInstance(xeSimpleDrawType.ScreenSpace_Transient).Init(graphics_device,
                                                                                    persistent: false,
                                                                                    max_lines: 200,
                                                                                    max_triangles: 50);

            XSimpleDraw.CreateInstance(xeSimpleDrawType.ScreenSpace_Persistent).Init(graphics_device,
                                                                                     persistent: true,
                                                                                     max_lines: 50,
                                                                                     max_triangles: 50);

            XSimpleDraw.CreateInstance(xeSimpleDrawType.WorldSpace_Persistent_Map).Init(graphics_device,
                                                                                        persistent: true,
                                                                                        max_lines: 50,
                                                                                        max_triangles: 1600000);
            mMainWorldCam = new XWorldCam(mScreenDim);
            mScreenCam    = new XScreenCam(mScreenDim);
        }
Esempio n. 7
0
            void _IButton.Draw(XSimpleDraw simple_draw)
            {
                // draw border and background, then draw core
                Vector3 lo = new Vector3(mAABB.GetMin(), 2);                   // zero might not be right z
                Vector3 hi = new Vector3(mAABB.GetMax(), 2);

                Color body_color   = mButtonCore.mPressed ? mButtonCore.mPressedColor : mButtonCore.mStyle.mBackgroundColor;
                Color border_color = mButtonCore.mStyle.mBorderColor;

                simple_draw.DrawQuad(lo, hi, body_color);

                simple_draw.DrawLine(lo, mCorner2, border_color);
                simple_draw.DrawLine(mCorner2, hi, border_color);
                simple_draw.DrawLine(hi, mCorner3, border_color);
                simple_draw.DrawLine(mCorner3, lo, border_color);

                mButtonCore.Draw(simple_draw);
            }
Esempio n. 8
0
        public void RenderWorldLines_Dynamic(xAABB2 view_aabb)
        {
            XSimpleDraw simple_draw_world = XSimpleDraw.Instance(xeSimpleDrawType.WorldSpace_Transient);

            // calculate color to use based on how much world is being drawn
            const float k_large_view_size = 200;
            const float k_small_view_size = 5;
            float       view_width        = view_aabb.GetMax().X - view_aabb.GetMin().X;
            float       lightness         = view_width > k_large_view_size ? 1.0f :
                                            view_width < k_small_view_size ? 0.0f :
                                            (view_width - k_small_view_size) / (k_large_view_size - k_small_view_size);

            lightness = XMath.Sqrt(lightness);

            Color k_lightest_color = new Color(0.0f, 0.0f, 0.0f, 0.025f);
            Color k_darkest_color  = new Color(0.0f, 0.0f, 0.0f, 0.33f);
            Color result_color     = Color.Lerp(k_darkest_color, k_lightest_color, lightness);

            // each cell is 1 unit on edge in world space
            Vector3 start = new Vector3();
            Vector3 end   = new Vector3();

            start.Y = 0;
            end.Y   = mMap.mBounds.y;

            for (int x = 0; x <= mMap.mBounds.x; ++x)
            {
                start.X = x;
                end.X   = x;

                simple_draw_world.DrawLine(start, end, result_color);
            }

            start.X = 0;
            end.X   = mMap.mBounds.x;

            for (int y = 0; y <= mMap.mBounds.y; ++y)
            {
                start.Y = y;
                end.Y   = y;

                simple_draw_world.DrawLine(start, end, result_color);
            }
        }
Esempio n. 9
0
            void _ISelector.Draw(XSimpleDraw simple_draw)
            {
                if (mRenderEnabled)
                {
                    // draw the title and background, buttons will draw themselves
                    Style style        = XUI.Instance().GetStyle(mStyle);
                    Color widget_color = style.mBackgroundColor;
                    Color border_color = style.mBorderColor;

                    Vector3 lo_x_lo_y = new Vector3(mAABB.GetMin(), 1);
                    Vector3 hi_x_hi_y = new Vector3(mAABB.GetMax(), 1);

                    Vector2 size      = mAABB.GetSize();
                    Vector3 lo_x_hi_y = lo_x_lo_y + new Vector3(0, size.Y, 0);
                    Vector3 hi_x_lo_y = lo_x_lo_y + new Vector3(size.X, 0, 0);

                    simple_draw.DrawQuad(lo_x_lo_y, hi_x_hi_y, widget_color);

                    simple_draw.DrawLine(lo_x_lo_y, hi_x_lo_y, border_color);
                    simple_draw.DrawLine(hi_x_lo_y, hi_x_hi_y, border_color);
                    simple_draw.DrawLine(hi_x_hi_y, lo_x_hi_y, border_color);
                    simple_draw.DrawLine(lo_x_hi_y, lo_x_lo_y, border_color);
                }
            }
Esempio n. 10
0
 public virtual void Render(XSimpleDraw simple_draw)
 {
     XUtils.Assert(mInitialized);
 }
Esempio n. 11
0
        private void ProcessInput()
        {
            bool generate_map    = false;
            bool resize_map      = false;
            bool change_map_type = false;

            var key_enumerator = mListenter_KeyUp.CreateEnumerator();

            while (key_enumerator.MoveNext())
            {
                if (key_enumerator.GetCurrent().mKey == Microsoft.Xna.Framework.Input.Keys.W)
                {
                    generate_map = true;
                }
                else if (key_enumerator.GetCurrent().mKey == Microsoft.Xna.Framework.Input.Keys.T)
                {
                    change_map_type = true;
                }
                else if (key_enumerator.GetCurrent().mKey == Microsoft.Xna.Framework.Input.Keys.S)
                {
                    resize_map = true;
                }
            }

            var button_enumerator = mListener_Button.CreateEnumerator();

            while (button_enumerator.MoveNext())
            {
                if (button_enumerator.GetCurrent().mID == mRegnerateMapButton.GetID())
                {
                    generate_map = true;
                }
                else if (button_enumerator.GetCurrent().mID == mMapTypeButton.GetID())
                {
                    change_map_type = true;
                }
                else if (button_enumerator.GetCurrent().mID == mMapSizeButton.GetID())
                {
                    resize_map = true;
                }
            }

            if (change_map_type)
            {
                // loop through map types
                mMapType     = (XWorldGen.eMapType)(((int)mMapType + 1) % (int)XWorldGen.eMapType.Num);
                mGenSet      = mGen.GetTuningSet(mMapType);
                generate_map = true;
            }

            if (resize_map)
            {
                ++mMapScale;
                generate_map = true;

                if (mMapScale > mGen.GetMaxMapScale())
                {
                    mMapScale = 1;
                }
            }

            if (generate_map)
            {
                XSimpleDraw simple_draw = XSimpleDraw.Instance(xeSimpleDrawType.WorldSpace_Persistent_Map);
                simple_draw.CancelPrimitives();
                mRendered = false;
                Generate();

                WorldRegenerated world_regenerated = new WorldRegenerated();
                mBroadcaster_WorldRegenerated.Post(world_regenerated);
            }
        }
Esempio n. 12
0
        public void Draw(GameTime game_time)
        {
            mGraphicsDevice.Clear(Color.CornflowerBlue);

            RasterizerState rasterizerState = new RasterizerState();

            rasterizerState.CullMode        = CullMode.None;
            mGraphicsDevice.RasterizerState = rasterizerState;

            // maybe not the best place for this
            // also, screen cam not updating anywhere
            mMainWorldCam.Update(game_time);
            UpdateCameras();

            // simple draw only clients
            XWorld.Instance().RenderWorld(game_time, mMainWorldCam.GetViewAABB());
            XMouse mouse = XMouse.Instance();

            mouse.RenderWorld(game_time);
            mouse.RenderScreen(game_time);
            XUI.Instance().Draw();

            mBasicEffect_World.VertexColorEnabled = true;

            XSimpleDraw simple_draw_world_transient      = XSimpleDraw.Instance(xeSimpleDrawType.WorldSpace_Transient);
            XSimpleDraw simple_draw_world_persistent     = XSimpleDraw.Instance(xeSimpleDrawType.WorldSpace_Persistent);
            XSimpleDraw simple_draw_screen_transient     = XSimpleDraw.Instance(xeSimpleDrawType.ScreenSpace_Transient);
            XSimpleDraw simple_draw_screen_persistent    = XSimpleDraw.Instance(xeSimpleDrawType.ScreenSpace_Persistent);
            XSimpleDraw simple_draw_world_map_persistent = XSimpleDraw.Instance(xeSimpleDrawType.WorldSpace_Persistent_Map);

            foreach (EffectPass pass in mBasicEffect_World.CurrentTechnique.Passes)
            {
                pass.Apply();

                // actually render simple draw stuff.  possible layers needed.
                simple_draw_world_map_persistent.DrawAllPrimitives();
                simple_draw_world_persistent.DrawAllPrimitives();
                simple_draw_world_transient.DrawAllPrimitives();

                // render clients who do their own rendering.  they should probably have pre-renders like simple draw, especially if there is more than one pass.
            }

            // simple draw screen
            mBasicEffect_Screen.VertexColorEnabled = true;

            //foreach ( EffectPass pass in effectPassCollection )
            foreach (EffectPass pass in mBasicEffect_Screen.CurrentTechnique.Passes)
            {
                pass.Apply();

                // actually render simple draw stuff.  possible layers needed.
                simple_draw_screen_persistent.DrawAllPrimitives();
                simple_draw_screen_transient.DrawAllPrimitives();

                // render clients who do their own rendering.  they should probably have pre-renders like simple draw, especially if there is more than one pass.
            }

            //mSpriteBatch.Begin();
            // do sprite batch rendering here
            //mSpriteBatch.End();

            XFontDraw.Instance().Draw();
        }
Esempio n. 13
0
 public override void Render(XSimpleDraw simple_draw)
 {
     base.Render(simple_draw);
     XFontDraw.Instance().DrawString(GetStyle().mNormalFont, GetPosition().GetScreenAABB().GetMin(),
                                     GetStyle().mTextColor, mText);
 }
Esempio n. 14
0
 private void Init_Render()
 {
     mSimpleDraw = XSimpleDraw.GetInstance(xeSimpleDrawType.ScreenSpace_Transient);
 }