示例#1
0
文件: World.cs 项目: barronds/XNARTS
        public void Init(xCoord bounds, T init_value)
        {
            XUtils.Assert(bounds.x > 0 && bounds.y > 0);
            mData   = new T[bounds.x, bounds.y];
            mBounds = bounds;

            Iterate((grid, x, y) => { grid.mData[x, y] = init_value; });
        }
示例#2
0
            public ScreenWidget()
            {
                xCoord screen_dim = XRenderManager.Instance().GetScreenDim();

                InitWidget(null, XUI.Instance().GetStyle(eStyle.Screen),
                           new xAABB2(Vector2.Zero, new Vector2(screen_dim.x, screen_dim.y)));
                SetInputEnabled(false);
            }
示例#3
0
文件: Coord.cs 项目: barronds/XNARTS
        public xCoord clamp(xCoord min, xCoord max)
        {
            XUtils.Assert(!(min.x > max.x || min.y > max.y));
            int clamped_x = System.Math.Max(System.Math.Min(max.x, this.x), min.x);
            int clamped_y = System.Math.Max(System.Math.Min(max.y, this.y), min.y);

            return(new xCoord(clamped_x, clamped_y));
        }
示例#4
0
文件: Camera.cs 项目: barronds/XNARTS
        public XScreenCam(xCoord screen_dim)
        {
            Vector2 min = new Vector2(0, 0);
            Vector2 max = new Vector2(screen_dim.x, screen_dim.y);

            mViewAABB   = new xAABB2(min, max);
            mView       = Matrix.CreateLookAt(new Vector3(0f, 0f, 1f), new Vector3(0f, 0f, 0f), new Vector3(0f, 1f, 0f));
            mProjection = Matrix.CreateOrthographicOffCenter(min.X, max.X, max.Y, min.Y, -1f, 1f);
        }
示例#5
0
文件: Camera.cs 项目: barronds/XNARTS
        public XWorldCam(xCoord screen_dim)
        {
            mScreenDim = screen_dim;
            mAspect    = ((float)(screen_dim.y)) / screen_dim.x;
            InitFromWorld();

            mListener_MultiDrag = new XListener <XTouch.MultiDragData>(1, eEventQueueFullBehaviour.IgnoreOldest,
                                                                       "worldcammultidrag");
            XBulletinBoard.Instance().mBroadcaster_MultiDrag.Subscribe(mListener_MultiDrag);

            mListener_WorldRegenerated = new XListener <XWorld.WorldRegenerated>(1, eEventQueueFullBehaviour.IgnoreOldest,
                                                                                 "worldcamworldregenerated");
            XWorld.Instance().GetBroadcaster_WorldRegenerated().Subscribe(mListener_WorldRegenerated);
        }
示例#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);
        }
示例#7
0
文件: Camera.cs 项目: barronds/XNARTS
        private void InitFromWorld()
        {
            mWorldSize = XWorld.Instance().GetMapSize();

            // initial view of map
            xAABB2 world_view = new xAABB2(new Vector2(0, 0), new Vector2(mWorldSize.x, mWorldSize.y));

            mWorldView = ClampWorldView(world_view);

            // view matrix is unchanging
            Vector3 pos    = new Vector3(0, 0, 1f);
            Vector3 target = pos - 2f * Vector3.UnitZ;

            mViewMatrix = Matrix.CreateLookAt(pos, target, Vector3.UnitY);
            CalcProjectionMatrix();

            mMultiDragPrev             = new XTouch.MultiDragData(Vector2.Zero, 1f, 0);
            mDampedMaxScreenSeparation = -1f;
        }
示例#8
0
            public Selector(_Position pos, String title, eStyle style, eStyle button_style, eStyle title_style,
                            long id, String[] texts)
            {
                mRenderEnabled   = true;
                mID              = id;
                mPos             = pos.GetPosition();
                mPosition        = pos;
                mTitle           = title;
                mStyle           = style;
                mButtonStyle     = button_style;
                mTitleStyle      = title_style;
                this.mSelections = new _IButton[texts.Length];

                // create a default button to see how big it is vertically
                // size and position border accordingly, factoring in width of largest button including title
                // destroy that button
                // create all the proper buttons in the right spot
                // create title 'button' as disabled button
                XUI xui_inst = XUI.Instance();

                _IButton test          = xui_inst._CreateRectangularButton(Vector2.Zero, "Test", style);
                xAABB2   button_size   = test.GetAABB();
                float    button_size_y = button_size.GetSize().Y;

                xui_inst._DestroyButton(test);

                const float k_border_padding_scalar = 0.5f;
                float       border_padding          = k_border_padding_scalar * button_size_y;

                const float k_spacing_scalar = 0.2f;
                float       spacing          = k_spacing_scalar * button_size_y;

                // pad out the text strings so the buttons can be wide if the text is small
                int longest = GetLongestString(texts);

                PadButtonTexts(texts, longest);

                // create buttons
                PositionAndCreateButtons(texts, mSelections, border_padding, spacing, button_size_y, button_style, 0);

                // track largest
                float largest_x = GetWidest(mSelections);

                // create title button (non-functional) and see if it's the largest
                Vector2 title_pos = mPos + new Vector2(border_padding, border_padding);

                mTitleButton = xui_inst._CreateRectangularButton(title_pos, title, title_style);
                mTitleButton.SetActive(false);
                largest_x = Math.Max(largest_x, mTitleButton.GetAABB().GetSize().X);

                // calculate aabb
                const float title_padding_scalar = 4.0f;
                float       title_padding        = border_padding * title_padding_scalar;
                Vector2     title_padding_v      = new Vector2(0, title_padding);
                float       full_width           = largest_x + 2 * border_padding;

                float full_height = button_size_y * (mSelections.Length) +
                                    (mSelections.Length - 1) * spacing +
                                    2 * border_padding +
                                    title_padding;

                mAABB.Set(mPos, mPos + new Vector2(full_width, full_height));

                // translate each button to be centered, and account for title
                CenterButtons(mSelections, largest_x, title_padding);
                CenterButton(mTitleButton, largest_x, 0);

                // if the selector has a non-trivial Position, fix it
                if (mPosition.IsCentered())
                {
                    // see where it is now, figure out where it should be, translate.
                    // apply to aabb for selector plus translate all the buttons
                    xCoord  screen_dim     = XRenderManager.Instance().GetScreenDim();
                    Vector2 span           = mAABB.GetSize();
                    Vector2 screen_dim_vec = new Vector2(screen_dim.x, screen_dim.y);
                    Vector2 edge           = 0.5f * (screen_dim_vec - span);
                    Translate(edge);
                }
            }
示例#9
0
文件: Mouse.cs 项目: barronds/XNARTS
        public void Init()
        {
            XRenderManager render_manager = XRenderManager.Instance();

            mScreenDim = render_manager.mScreenDim;
        }
示例#10
0
文件: World.cs 项目: barronds/XNARTS
        private void Generate_Physical()
        {
            // set up the grid
            xCoord min_map_size = mGen.GetMinMapSize();
            xCoord map_size     = mMapScale * min_map_size;

            mMap = new XSafeGrid <xMapCell>();
            xMapCell init_val = new xMapCell();

            init_val.mTerrain = xeTerrainType.Invalid;
            init_val.mColor   = new Color();
            mMap.Init(map_size, init_val);

            Random rand = new Random();

            // tuning derrivatives
            double min_spike_height    = mGenSet.mSpikeHeight * (1d - mGenSet.mSpikeVariance);
            double max_spike_height    = mGenSet.mSpikeHeight * (1d + mGenSet.mSpikeVariance);
            double spike_height_spread = max_spike_height - min_spike_height;
            int    num_spikes          = (int)(mGenSet.mSpikeDensity * mMap.mBounds.x * mMap.mBounds.y);

            XSafeGrid <double>[] heights = new XSafeGrid <double> [2];

            for (int h = 0; h < 2; ++h)
            {
                heights[h] = new XSafeGrid <double>();
                heights[h].Init(mMap.mBounds, 0d);
            }

            // assign spikes
            for (int i = 0; i < num_spikes; ++i)
            {
                int x = rand.Next() % mMap.mBounds.x;
                int y = rand.Next() % mMap.mBounds.y;

                double spike_height = min_spike_height + rand.NextDouble() * spike_height_spread;
                heights[0].mData[x, y] = spike_height;
            }

            // smooth
            int n = 0;
            int smoothing_passes = (mGenSet.mSmoothingPasses % 2) == 1     ?
                                   mGenSet.mSmoothingPasses + 1            :
                                   mGenSet.mSmoothingPasses;

            for (int i = 0; i < smoothing_passes; ++i)
            {
                int target = n == 0 ? 1 : 0;

                heights[n].Iterate((grid, x, y) =>
                {
                    double lo_x    = grid.GetValueSafe(x - 1, y);
                    double hi_x    = grid.GetValueSafe(x + 1, y);
                    double lo_y    = grid.GetValueSafe(x, y - 1);
                    double hi_y    = grid.GetValueSafe(x, y + 1);
                    double here    = grid.mData[x, y];
                    double blended = 0.25d * (lo_x + lo_y + hi_x + hi_y);
                    double result  = mGenSet.mSmoothingScalar * here + (1d - mGenSet.mSmoothingScalar) * blended;
                    heights[target].mData[x, y] = result;
                });

                n = n == 0 ? 1 : 0;
            }

            // normalize
            double max_height = 0.0d;

            heights[0].Iterate((grid, x, y) =>
            {
                if (grid.mData[x, y] > max_height)
                {
                    max_height = grid.mData[x, y];
                }
            });

            double normalizer = max_height > 0.0d ? 1d / max_height : 1d;

            heights[0].Iterate((grid, x, y) =>
            {
                grid.mData[x, y] *= normalizer;
            });

            // height capping
            heights[0].Iterate((grid, x, y) =>
            {
                grid.mData[x, y] = XMath.Clamp(grid.mData[x, y], mGenSet.mMinNormalizedHeight, mGenSet.mMaxNormalizedHeight);
            });

            mMap.Iterate((grid, x, y) =>
            {
                xeTerrainType terrain = xeTerrainType.Snow;

                for (int t = 0; t < (int)xeTerrainType.Num - 1; ++t)
                {
                    if (heights[0].mData[x, y] <= mGenSet.mHeightThresh[t])
                    {
                        terrain = (xeTerrainType)t;
                        break;
                    }
                }

                grid.mData[x, y].mTerrain = terrain;
            });

            mGenSet.mPostProcess(mMap);
        }
示例#11
0
文件: World.cs 项目: barronds/XNARTS
 public xMapCell GetMapCell(xCoord coord)
 {
     XUtils.Assert(coord.x >= 0 && coord.y >= 0 && coord.x < mMap.mBounds.x && coord.y < mMap.mBounds.y);
     return(mMap.mData[coord.x, coord.y]);
 }
示例#12
0
文件: Coord.cs 项目: barronds/XNARTS
        public static void unitTest()
        {
            //XUtils.Assert( false, "hello" );
            xCoord a = new xCoord();

            XUtils.Assert(a.x == 0);
            XUtils.Assert(a.y == 0);

            xCoord b = a;

            XUtils.Assert(b.x == 0);
            XUtils.Assert(b.y == 0);

            xCoord c = new xCoord(-10, 20.0f);

            XUtils.Assert(c.x == -10);
            XUtils.Assert(c.y == 20);

            xCoord d = 5 * c;
            xCoord e = new xCoord(-50, 100);

            XUtils.Assert(d == e);
            XUtils.Assert(d != b);
            XUtils.Assert(d.Equals(e));
            XUtils.Assert(!d.Equals(a));

#pragma warning disable CS1718
            XUtils.Assert(d == d);
#pragma warning restore CS1718

            xCoord f = new xCoord(2, 6);
            xCoord g = new xCoord(-11, 33);
            xCoord h = f + g;
            xCoord i = f - g;
            xCoord j = f - f;
            xCoord k = g - g - g;
            XUtils.Assert(h == new xCoord(-9, 39));
            XUtils.Assert(i == new xCoord(13, -27));
            XUtils.Assert(j == new xCoord());
            XUtils.Assert(k == -g);

            xCoord l = new xCoord(2, -5);
            xCoord m = 4 * l;
            xCoord n = -3.5f * l;
            xCoord o = l * 4;
            XUtils.Assert(m == new xCoord(8, -20));
            XUtils.Assert(n == new xCoord(-7, 17));
            XUtils.Assert(o == m);

            xCoord p = new xCoord(11.4, -55.6);
            xCoord q = new xCoord(11.6, -55.4);
            XUtils.Assert(p == new xCoord(11, -55));
            XUtils.Assert(p == new xCoord(11, -55));

            XUtils.AssertVal(a.getLength(), 0, 0.0001);
            XUtils.AssertVal(f.getLength(), System.Math.Sqrt(40), 0.0001);
            XUtils.AssertVal(g.getLength(), System.Math.Sqrt(33 * 33 + 11 * 11), 0.001);

            xCoord r = g.clamp(new xCoord(0, 0), new xCoord(100, 100));
            xCoord s = g.clamp(new xCoord(-30, -10), new xCoord(0, -1));
            xCoord t = g.clamp(new xCoord(-1000, -1000), new xCoord(1000, 1000));
            xCoord u = g.clamp(new xCoord(), new xCoord());
            XUtils.Assert(r == new xCoord(0, 33));
            XUtils.Assert(s == new xCoord(-11, -1));
            XUtils.Assert(t == g);
            XUtils.Assert(u == new xCoord(0, 0));
        }