public MovingBlocksRaycastResult?Raycast(Vector3 start, Vector3 end, bool extendToFillCells)
        {
            Ray3        ray         = new Ray3(start, Vector3.Normalize(end - start));
            BoundingBox boundingBox = new BoundingBox(Vector3.Min(start, end), Vector3.Max(start, end));

            m_result.Clear();
            FindMovingBlocks(boundingBox, extendToFillCells, m_result);
            float          num            = float.MaxValue;
            MovingBlockSet movingBlockSet = null;

            foreach (MovingBlockSet item in m_result)
            {
                BoundingBox box  = item.BoundingBox(extendToFillCells);
                float?      num2 = ray.Intersection(box);
                if (num2.HasValue && num2.Value < num)
                {
                    num            = num2.Value;
                    movingBlockSet = item;
                }
            }
            if (movingBlockSet != null)
            {
                MovingBlocksRaycastResult value = default(MovingBlocksRaycastResult);
                value.Ray            = ray;
                value.Distance       = num;
                value.MovingBlockSet = movingBlockSet;
                return(value);
            }
            return(null);
        }
        public void ClearTest()
        {
            for (int i = 2; i <= 32; i *= 2)
            {
                currentArray.Add(i);
            }

            Assert.AreEqual(currentArray.Count, 5);
            currentArray.Clear();
            Assert.AreEqual(currentArray.Count, 0);
            currentArray.Clear();
            Assert.AreEqual(currentArray.Count, 0);

            Assert.Pass();
        }
Ejemplo n.º 3
0
 public void LoadString(string data)
 {
     string[] array = data.Split(new char[1]
     {
         ';'
     }, StringSplitOptions.RemoveEmptyEntries);
     if (array.Length >= 1)
     {
         string text = array[0];
         text = text.TrimEnd('0');
         Data.Clear();
         for (int i = 0; i < MathUtils.Min(text.Length, 256); i++)
         {
             int num = m_hexChars.IndexOf(char.ToUpperInvariant(text[i]));
             if (num < 0)
             {
                 num = 0;
             }
             Data.Add((byte)num);
         }
     }
     if (array.Length >= 2)
     {
         string text2 = array[1];
         int    num2  = m_hexChars.IndexOf(char.ToUpperInvariant(text2[0]));
         if (num2 < 0)
         {
             num2 = 0;
         }
         LastOutput = (byte)num2;
     }
 }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            var array = new DynamicArray<string>();
            array.Add("Georgi");
            array.Add("Nikolai");
            Console.WriteLine(array.IndexOf("Nikolai"));
            Console.WriteLine(array.Cointains("Kiril"));
            array.Remove("Georgi");
            array.InsertAt(1, "Ivan");
            array.Clear();
            Console.WriteLine(array.Capacity);
            Console.WriteLine(array.Count);

            array.Add("Stefan");
            array.Add("Krum");
            var arr = array.ToArray();
            Console.WriteLine();
            foreach (var item in array)
            {
                Console.WriteLine(item);
            }
            Console.WriteLine();

            foreach (var item in arr)
            {
                Console.WriteLine(item);
            }
        }
Ejemplo n.º 5
0
        public void FindMovingBlocksCollisionBoxes(Vector3 position, DynamicArray <CollisionBox> result)
        {
            Vector3     boxSize     = BoxSize;
            BoundingBox boundingBox = new BoundingBox(position - new Vector3(boxSize.X / 2f, 0f, boxSize.Z / 2f), position + new Vector3(boxSize.X / 2f, boxSize.Y, boxSize.Z / 2f));

            boundingBox.Min -= new Vector3(1f);
            boundingBox.Max += new Vector3(1f);
            m_movingBlockSets.Clear();
            m_subsystemMovingBlocks.FindMovingBlocks(boundingBox, extendToFillCells: false, m_movingBlockSets);
            for (int i = 0; i < m_movingBlockSets.Count; i++)
            {
                IMovingBlockSet movingBlockSet = m_movingBlockSets.Array[i];
                for (int j = 0; j < movingBlockSet.Blocks.Count; j++)
                {
                    MovingBlock movingBlock = movingBlockSet.Blocks[j];
                    int         num         = Terrain.ExtractContents(movingBlock.Value);
                    Block       block       = BlocksManager.Blocks[num];
                    if (block.IsCollidable)
                    {
                        BoundingBox[] customCollisionBoxes = block.GetCustomCollisionBoxes(m_subsystemTerrain, movingBlock.Value);
                        Vector3       v = new Vector3(movingBlock.Offset) + movingBlockSet.Position;
                        for (int k = 0; k < customCollisionBoxes.Length; k++)
                        {
                            result.Add(new CollisionBox
                            {
                                Box           = new BoundingBox(v + customCollisionBoxes[k].Min, v + customCollisionBoxes[k].Max),
                                BlockValue    = movingBlock.Value,
                                BlockVelocity = movingBlockSet.CurrentVelocity
                            });
                        }
                    }
                }
            }
        }
Ejemplo n.º 6
0
 public static void Main()
 {
     DynamicArray<string> arrey = new DynamicArray<string>();
     arrey.Add("Pesho");
     arrey.Add("Gosho");
     Console.WriteLine(arrey.IndexOf("Pesho"));
     Console.WriteLine(arrey.Contains("Gosho"));
     Console.WriteLine(arrey.Contains("Ivan"));
     arrey.Remove("Pesho");
     arrey.InsertAt(1, "Pesho");
     arrey.Clear();
     Console.WriteLine(arrey.Capacity);
     Console.WriteLine(arrey.Count);
     arrey.Add("Ivo");
     arrey[0] = "Gosho";
     var newArrey = arrey.ToArray();
     Console.WriteLine();
     foreach (var item in arrey)
     {
         Console.WriteLine(item);
     }
     Console.WriteLine();
     foreach (var item in newArrey)
     {
         Console.WriteLine(item);
     }
 }
 public void Update(float dt)
 {
     if (tranca.Array.Length > 0)
     {
         if (tranFLag)
         {
             try
             {
                 mcomponentBody.m_position = tranca.Array[0];
                 SubsystemTerrain.TerrainUpdater.UpdateChunkSingleStep(SubsystemTerrain.Terrain.GetChunkAtCell(Terrain.ToCell(tranca.Array[0].X), Terrain.ToCell(tranca.Array[0].Z)), 15);
                 mcomponentBody.Entity.FindComponent <ComponentPlayer>().ComponentGui.DisplaySmallMessage($"传送开始 {tranca.Array[0].ToString()}", false, false);
                 tranFLag = false;
             }
             catch (Exception e)
             {
                 Log.Information(e.ToString());
             }
         }
         else
         {
             if (Vector3.Distance(mcomponentBody.Position, tranca.Array[0]) > 2f)
             {
                 leftFLag = true;
                 tranca.Clear();
             }
         }
     }
 }
Ejemplo n.º 8
0
 public override void Clear()
 {
     LineVertices.Clear();
     LineIndices.Clear();
     TriangleVertices.Clear();
     TriangleIndices.Clear();
 }
        public float ScoreSafePlace(Vector3 currentPosition, Vector3 safePosition, Vector3?lookDirection)
        {
            float   num      = 16f;
            Vector3 position = m_componentCreature.ComponentBody.Position;

            m_componentBodies.Clear();
            m_subsystemBodies.FindBodiesAroundPoint(new Vector2(position.X, position.Z), 16f, m_componentBodies);
            for (int i = 0; i < m_componentBodies.Count; i++)
            {
                ComponentBody componentBody = m_componentBodies.Array[i];
                if (!IsPredator(componentBody.Entity))
                {
                    continue;
                }
                Vector3 position2 = componentBody.Position;
                Vector3 v         = safePosition - position2;
                if (!lookDirection.HasValue || 0f - Vector3.Dot(lookDirection.Value, v) > 0f)
                {
                    if (v.Y >= 4f)
                    {
                        v *= 2f;
                    }
                    num = MathUtils.Min(num, v.Length());
                }
            }
            float num2 = Vector3.Distance(currentPosition, safePosition);

            if (num2 < 8f)
            {
                return(num * 0.5f);
            }
            return(num * MathUtils.Lerp(1f, 0.75f, MathUtils.Saturate(num2 / 20f)));
        }
        public float CalculateMotionVoltage()
        {
            float num = 0f;

            m_bodies.Clear();
            m_subsystemBodies.FindBodiesInArea(m_corner1, m_corner2, m_bodies);
            for (int i = 0; i < m_bodies.Count; i++)
            {
                ComponentBody componentBody = m_bodies.Array[i];
                if (componentBody.Velocity.LengthSquared() > 0.0625f)
                {
                    Vector3 vector = componentBody.Position + new Vector3(0f, 0.5f * componentBody.BoxSize.Y, 0f);
                    float   num2   = Vector3.DistanceSquared(vector, m_center);
                    if (num2 < 64f && Vector3.Dot(Vector3.Normalize(vector - (m_center - 0.75f * m_direction)), m_direction) > 0.5f && !base.SubsystemElectricity.SubsystemTerrain.Raycast(m_center, vector, useInteractionBoxes: false, skipAirBlocks: true, delegate(int value, float d)
                    {
                        Block block = BlocksManager.Blocks[Terrain.ExtractContents(value)];
                        return(block.IsCollidable && block.BlockIndex != 15 && block.BlockIndex != 60 && block.BlockIndex != 44 && block.BlockIndex != 18);
                    }).HasValue)
                    {
                        num = MathUtils.Max(num, MathUtils.Saturate(1f - MathUtils.Sqrt(num2) / 8f));
                    }
                }
            }
            if (!(num > 0f))
            {
                return(0f);
            }
            return(MathUtils.Lerp(0.51f, 1f, MathUtils.Saturate(num * 1.1f)));
        }
Ejemplo n.º 11
0
        public ComponentBody FindNearestBodyInFront(Vector3 position, Vector2 direction)
        {
            if (m_subsystemTime.GameTime >= m_nextBodiesUpdateTime)
            {
                m_nextBodiesUpdateTime = m_subsystemTime.GameTime + 0.5;
                m_nearbyBodies.Clear();
                m_subsystemBodies.FindBodiesAroundPoint(m_componentCreature.ComponentBody.Position.XZ, 4f, m_nearbyBodies);
            }
            ComponentBody result = null;
            float         num    = float.MaxValue;

            foreach (ComponentBody nearbyBody in m_nearbyBodies)
            {
                if (nearbyBody != m_componentCreature.ComponentBody && !(MathUtils.Abs(nearbyBody.Position.Y - m_componentCreature.ComponentBody.Position.Y) > 1.1f) && Vector2.Dot(nearbyBody.Position.XZ - position.XZ, direction) > 0f)
                {
                    float num2 = Vector2.DistanceSquared(nearbyBody.Position.XZ, position.XZ);
                    if (num2 < num)
                    {
                        num    = num2;
                        result = nearbyBody;
                    }
                }
            }
            return(result);
        }
        /// <summary>
        /// Handles the situation where there is a missing vector from the vector field.
        /// </summary>
        /// <param name="selfCell">This unit's current cell.</param>
        /// <param name="vectorField">The vector field.</param>
        /// <param name="input">The steering input.</param>
        /// <param name="output">The steering output.</param>
        private void HandleMissingVectorFromField(Cell selfCell, IVectorField vectorField, SteeringInput input, SteeringOutput output)
        {
            var     unit    = input.unit;
            Vector3 unitPos = unit.position;

            // find all (up to) 8 neighbours
            _neighbours.Clear();
            input.grid.GetConcentricNeighbours(selfCell, 1, _neighbours);

            // sort the neighbours depending on their distance to the unit, i.e. nearest cell neighbours first
            _cellComparer.compareTo = unitPos;
            _neighbours.Sort(_cellComparer);

            // loop through cell neighbours and try to escape to the nearest one that is walkable and has a vector field cell
            int neighboursCount = _neighbours.count;

            for (int i = 0; i < neighboursCount; i++)
            {
                var     neighbour    = _neighbours[i];
                Vector3 neighbourPos = neighbour.position;
                if (neighbour.IsWalkableWithClearance(unit) && vectorField.GetFieldCellAtPos(neighbour).direction.sqrMagnitude != 0f && neighbourPos.y <= unitPos.y)
                {
                    // if the neighbour cell is walkable, has a vector field vector and is at a lower or same height as the unit
                    output.maxAllowedSpeed     = unit.maximumSpeed;
                    output.desiredAcceleration = Seek(neighbourPos, input);
                    return;
                }
            }

            // only request path if we can't find a neighbouring cell to escape to, if there is a valid destination and if the unit is actually movable
            if (unit.isMovable && vectorField.destination != null)
            {
                RequestPath(vectorField.destination.position, input);
            }
        }
Ejemplo n.º 13
0
 public override void Update(float dt)
 {
     foreach (var @event in StoredEvents)
     {
         ExecuteEvent(@event);
     }
     StoredEvents.Clear();
 }
Ejemplo n.º 14
0
 public void AddElectricElement(ElectricElement electricElement)
 {
     m_electricElements.Add(electricElement, value: true);
     foreach (CellFace cellFace2 in electricElement.CellFaces)
     {
         m_electricElementsByCellFace.Add(cellFace2, electricElement);
         m_tmpConnectionPaths.Clear();
         GetAllConnectedNeighbors(cellFace2.X, cellFace2.Y, cellFace2.Z, cellFace2.Face, m_tmpConnectionPaths);
         foreach (ElectricConnectionPath tmpConnectionPath in m_tmpConnectionPaths)
         {
             CellFace cellFace = new CellFace(cellFace2.X + tmpConnectionPath.NeighborOffsetX, cellFace2.Y + tmpConnectionPath.NeighborOffsetY, cellFace2.Z + tmpConnectionPath.NeighborOffsetZ, tmpConnectionPath.NeighborFace);
             if (m_electricElementsByCellFace.TryGetValue(cellFace, out ElectricElement value) && value != electricElement)
             {
                 int cellValue = SubsystemTerrain.Terrain.GetCellValue(cellFace2.X, cellFace2.Y, cellFace2.Z);
                 int num       = Terrain.ExtractContents(cellValue);
                 ElectricConnectorType value2 = ((IElectricElementBlock)BlocksManager.Blocks[num]).GetConnectorType(SubsystemTerrain, cellValue, cellFace2.Face, tmpConnectionPath.ConnectorFace, cellFace2.X, cellFace2.Y, cellFace2.Z).Value;
                 int cellValue2 = SubsystemTerrain.Terrain.GetCellValue(cellFace.X, cellFace.Y, cellFace.Z);
                 int num2       = Terrain.ExtractContents(cellValue2);
                 ElectricConnectorType value3 = ((IElectricElementBlock)BlocksManager.Blocks[num2]).GetConnectorType(SubsystemTerrain, cellValue2, cellFace.Face, tmpConnectionPath.NeighborConnectorFace, cellFace.X, cellFace.Y, cellFace.Z).Value;
                 electricElement.Connections.Add(new ElectricConnection
                 {
                     CellFace                = cellFace2,
                     ConnectorFace           = tmpConnectionPath.ConnectorFace,
                     ConnectorType           = value2,
                     NeighborElectricElement = value,
                     NeighborCellFace        = cellFace,
                     NeighborConnectorFace   = tmpConnectionPath.NeighborConnectorFace,
                     NeighborConnectorType   = value3
                 });
                 value.Connections.Add(new ElectricConnection
                 {
                     CellFace                = cellFace,
                     ConnectorFace           = tmpConnectionPath.NeighborConnectorFace,
                     ConnectorType           = value3,
                     NeighborElectricElement = electricElement,
                     NeighborCellFace        = cellFace2,
                     NeighborConnectorFace   = tmpConnectionPath.ConnectorFace,
                     NeighborConnectorType   = value2
                 });
             }
         }
     }
     QueueElectricElementForSimulation(electricElement, CircuitStep + 1);
     QueueElectricElementConnectionsForSimulation(electricElement, CircuitStep + 2);
     electricElement.OnAdded();
 }
Ejemplo n.º 15
0
        public void ClearTest()
        {
            DynamicArray dynamicArray = CreateTestArray();

            dynamicArray.Clear();

            Assert.AreEqual(0, dynamicArray.Count);
        }
Ejemplo n.º 16
0
 public override void Clear()
 {
     lock (GLock)
     {
         _Nodes.Clear();
         _Neighbors.Clear();
         Count = 0;
     }
 }
Ejemplo n.º 17
0
        /// <summary>
        /// Unregisters a portal.
        /// </summary>
        /// <param name="name">The portal name.</param>
        public void UnregisterPortal(string name)
        {
            _portalsLookup.Remove(name);

            _portals.Clear();
            foreach (var p in _portalsLookup.Values)
            {
                _portals.Add(p);
            }
        }
Ejemplo n.º 18
0
        public void PrepareForDrawing(Camera camera)
        {
            Vector2         xZ              = camera.ViewPosition.XZ;
            float           num             = MathUtils.Sqr(m_subsystemSky.VisibilityRange);
            BoundingFrustum viewFrustum     = camera.ViewFrustum;
            int             gameWidgetIndex = camera.GameWidget.GameWidgetIndex;

            m_chunksToDraw.Clear();
            TerrainChunk[] allocatedChunks = m_subsystemTerrain.Terrain.AllocatedChunks;
            foreach (TerrainChunk terrainChunk in allocatedChunks)
            {
                if (terrainChunk.NewGeometryData)
                {
                    lock (terrainChunk.Geometry)
                    {
                        if (terrainChunk.NewGeometryData)
                        {
                            terrainChunk.NewGeometryData = false;
                            SetupTerrainChunkGeometryVertexIndexBuffers(terrainChunk);
                        }
                    }
                }
                terrainChunk.DrawDistanceSquared = Vector2.DistanceSquared(xZ, terrainChunk.Center);
                if (terrainChunk.DrawDistanceSquared <= num)
                {
                    if (viewFrustum.Intersection(terrainChunk.BoundingBox))
                    {
                        m_chunksToDraw.Add(terrainChunk);
                    }
                    if (terrainChunk.State != TerrainChunkState.Valid)
                    {
                        continue;
                    }
                    float num2 = terrainChunk.FogEnds[gameWidgetIndex];
                    if (num2 != float.MaxValue)
                    {
                        if (num2 == 0f)
                        {
                            StartChunkFadeIn(camera, terrainChunk);
                        }
                        else
                        {
                            RunChunkFadeIn(camera, terrainChunk);
                        }
                    }
                }
                else
                {
                    terrainChunk.FogEnds[gameWidgetIndex] = 0f;
                }
            }
            ChunksDrawn         = 0;
            ChunkDrawCalls      = 0;
            ChunkTrianglesDrawn = 0;
        }
Ejemplo n.º 19
0
        public void CanClear()
        {
            var array = new DynamicArray(baseSize, growthFactor, maximumOverheadFactor);

            array.Add(new object());
            array.Add(new object());
            array.Add(new object());

            array.Clear();

            Assert.Equal(0, array.Count);
        }
Ejemplo n.º 20
0
        /// <summary>
        /// Gets the cell neighbours and unwalkability - used in vector smoothing.
        /// </summary>
        private bool GetCellNeighboursAndUnwalkability(Cell cell, DynamicArray <Cell> walkableCells, bool preventDiagonals)
        {
            if (walkableCells.count != 0)
            {
                // if the list for holding the cells is not empty, make it empty
                walkableCells.Clear();
            }

            var unitAttributes = _unitProperties.attributes;

            int mx = cell.matrixPosX;
            int mz = cell.matrixPosZ;

            for (int x = -1; x <= 1; x++)
            {
                for (int z = -1; z <= 1; z++)
                {
                    if (x == 0 && z == 0)
                    {
                        // cell in the middle is the cell which neighbours we want, thus ignore the center cell
                        continue;
                    }

                    if (x != 0 && z != 0 && preventDiagonals)
                    {
                        // if we are supposed to prevent diagonal moves, then ignore diagonal cell neighbours
                        continue;
                    }

                    var neighbour = _grid.cellMatrix[mx + x, mz + z];
                    if (neighbour != null)
                    {
                        if (neighbour.isWalkable(unitAttributes) && cell.isWalkableFrom(neighbour, _unitProperties))
                        {
                            // if the neighbour is walkable, and the center cell is walkable from this neighbour, then it is of interest
                            walkableCells.Add(neighbour);
                        }
                        else
                        {
                            // if we find just a single neighbour that is blocked, then we return false
                            return(false);
                        }
                    }
                    else if (_builtInContainment)
                    {
                        // if there is a missing cell, and we want to use built-in containment, then return false on first missing cell (off-grid)
                        return(false);
                    }
                } /* end neighbour traversal on z */
            }     /* end neighbour traversal on x */

            return(true);
        }
        public void Draw(Camera camera, int drawOrder)
        {
            if (!m_componentMiner.DigCellFace.HasValue || !(m_componentMiner.DigProgress > 0f) || !(m_componentMiner.DigTime > 0.2f))
            {
                return;
            }
            Point3 point     = m_componentMiner.DigCellFace.Value.Point;
            int    cellValue = m_subsystemTerrain.Terrain.GetCellValue(point.X, point.Y, point.Z);
            int    num       = Terrain.ExtractContents(cellValue);
            Block  block     = BlocksManager.Blocks[num];

            if (m_geometry == null || cellValue != m_value || point != m_point)
            {
                m_geometry = new Geometry();
                block.GenerateTerrainVertices(m_subsystemTerrain.BlockGeometryGenerator, m_geometry, cellValue, point.X, point.Y, point.Z);
                m_point = point;
                m_value = cellValue;
                m_vertices.Clear();
                CracksVertex item = default(CracksVertex);
                for (int i = 0; i < m_geometry.SubsetOpaque.Vertices.Count; i++)
                {
                    TerrainVertex terrainVertex = m_geometry.SubsetOpaque.Vertices.Array[i];
                    byte          b             = (byte)((terrainVertex.Color.R + terrainVertex.Color.G + terrainVertex.Color.B) / 3);
                    item.X     = terrainVertex.X;
                    item.Y     = terrainVertex.Y;
                    item.Z     = terrainVertex.Z;
                    item.Tx    = (float)terrainVertex.Tx / 32767f * 16f;
                    item.Ty    = (float)terrainVertex.Ty / 32767f * 16f;
                    item.Color = new Color(b, b, b, (byte)128);
                    m_vertices.Add(item);
                }
            }
            Vector3 viewPosition          = camera.ViewPosition;
            Vector3 v                     = new Vector3(MathUtils.Floor(viewPosition.X), 0f, MathUtils.Floor(viewPosition.Z));
            Matrix  value                 = Matrix.CreateTranslation(v - viewPosition) * camera.ViewMatrix.OrientationMatrix * camera.ProjectionMatrix;
            DynamicArray <ushort> indices = m_geometry.SubsetOpaque.Indices;
            float x    = m_subsystemSky.ViewFogRange.X;
            float y    = m_subsystemSky.ViewFogRange.Y;
            int   num2 = MathUtils.Clamp((int)(m_componentMiner.DigProgress * 8f), 0, 7);

            Display.BlendState        = BlendState.NonPremultiplied;
            Display.DepthStencilState = DepthStencilState.Default;
            Display.RasterizerState   = RasterizerState.CullCounterClockwiseScissor;
            m_shader.GetParameter("u_origin").SetValue(v.XZ);
            m_shader.GetParameter("u_viewProjectionMatrix").SetValue(value);
            m_shader.GetParameter("u_viewPosition").SetValue(camera.ViewPosition);
            m_shader.GetParameter("u_texture").SetValue(m_textures[num2]);
            m_shader.GetParameter("u_samplerState").SetValue(SamplerState.PointWrap);
            m_shader.GetParameter("u_fogColor").SetValue(new Vector3(m_subsystemSky.ViewFogColor));
            m_shader.GetParameter("u_fogStartInvLength").SetValue(new Vector2(x, 1f / (y - x)));
            Display.DrawUserIndexed(PrimitiveType.TriangleList, m_shader, CracksVertex.VertexDeclaration, m_vertices.Array, 0, m_vertices.Count, indices.Array, 0, indices.Count);
        }
        public void ClearTest()
        {
            DynamicArray <int> array = new DynamicArray <int>();
            List <int>         list  = new List <int>();

            array.Clear();
            list.Clear();

            if (!HaveEqualsElements(array, list))
            {
                Assert.Fail();
            }

            FillCollections(array, list);

            array.Clear();
            list.Clear();

            if (!HaveEqualsElements(array, list))
            {
                Assert.Fail();
            }
        }
Ejemplo n.º 23
0
        public EditMemeryDialogB(MemoryBankData memoryBankData, Action onCancel)
        {
            memory = memoryBankData;
            Data.Clear();
            Data.AddRange(memory.Data);
            CanvasWidget canvasWidget = new CanvasWidget()
            {
                Size = new Vector2(600f, float.PositiveInfinity), HorizontalAlignment = WidgetAlignment.Center, VerticalAlignment = WidgetAlignment.Center
            };
            RectangleWidget rectangleWidget = new RectangleWidget()
            {
                FillColor = new Color(0, 0, 0, 255), OutlineColor = new Color(128, 128, 128, 128), OutlineThickness = 2
            };
            StackPanelWidget stackPanel = new StackPanelWidget()
            {
                Direction = LayoutDirection.Vertical
            };
            LabelWidget labelWidget = new LabelWidget()
            {
                Text = "M 板编辑器", HorizontalAlignment = WidgetAlignment.Center, Margin = new Vector2(0, 10)
            };
            StackPanelWidget stackPanelWidget = new StackPanelWidget()
            {
                Direction = LayoutDirection.Horizontal, HorizontalAlignment = WidgetAlignment.Near, VerticalAlignment = WidgetAlignment.Near, Margin = new Vector2(10f, 10f)
            };

            Children.Add(canvasWidget);
            canvasWidget.Children.Add(rectangleWidget);
            canvasWidget.Children.Add(stackPanel);
            stackPanel.Children.Add(labelWidget);
            stackPanel.Children.Add(stackPanelWidget);
            stackPanelWidget.Children.Add(initData());
            stackPanelWidget.Children.Add(initButton());
            MainView      = stackPanel;
            this.onCancel = onCancel;
            lastvalue     = memory.Read(0);
        }
Ejemplo n.º 24
0
        public void Clear_WhenCalled_ShouldClearArray(int range)
        {
            // Arrange
            for (var i = 1; i <= range; i++)
            {
                _array.Add(i);
            }

            // Act
            _array.Clear();

            // Assert
            Assert.That(_array.IsEmpty, Is.EqualTo(true));
            Assert.That(_array.Size, Is.EqualTo(0));
        }
        private bool GetCellNeighboursAndUnwalkability(Cell cell, DynamicArray <Cell> walkableCells, bool preventDiagonals)
        {
            if (walkableCells.count != 0)
            {
                // if the list for holding the cells is not empty, make it empty
                walkableCells.Clear();
            }

            for (int x = -1; x <= 1; x++)
            {
                for (int z = -1; z <= 1; z++)
                {
                    if (x == 0 && z == 0)
                    {
                        // cell in the middle is the cell which neighbours we want, thus ignore the center cell
                        continue;
                    }

                    if (x != 0 && z != 0 && preventDiagonals)
                    {
                        // if we are supposed to prevent diagonal moves, then ignore diagonal cell neighbours
                        continue;
                    }

                    var neighbour = GetCellNeighbour(cell, x, z);
                    if (neighbour != null)
                    {
                        if (neighbour.IsWalkableWithClearance(_unitProperties) && cell.IsWalkableFromWithClearance(neighbour, _unitProperties))
                        {
                            // if the neighbour is walkable, and the center cell is walkable from this neighbour, then it is of interest
                            walkableCells.Add(neighbour);
                        }
                        else
                        {
                            // if we find just a single neighbour that is blocked, then we return false
                            return(false);
                        }
                    }
                    else if (_builtInContainment)
                    {
                        // if there is a missing cell, and we want to use built-in containment, then return false on first missing cell (off-grid)
                        return(false);
                    }
                }
            }

            return(true);
        }
Ejemplo n.º 26
0
 public ComponentRider FindNearbyRider(float range)
 {
     m_bodies.Clear();
     m_subsystemBodies.FindBodiesAroundPoint(new Vector2(m_componentCreature.ComponentBody.Position.X, m_componentCreature.ComponentBody.Position.Z), range, m_bodies);
     foreach (ComponentBody body in m_bodies)
     {
         if (Vector3.DistanceSquared(m_componentCreature.ComponentBody.Position, body.Position) < range * range)
         {
             ComponentRider componentRider = body.Entity.FindComponent <ComponentRider>();
             if (componentRider != null)
             {
                 return(componentRider);
             }
         }
     }
     return(null);
 }
Ejemplo n.º 27
0
 public void FindBodiesCollisionBoxes(Vector3 position, DynamicArray <CollisionBox> result)
 {
     m_componentBodies.Clear();
     m_subsystemBodies.FindBodiesAroundPoint(new Vector2(position.X, position.Z), 4f, m_componentBodies);
     for (int i = 0; i < m_componentBodies.Count; i++)
     {
         ComponentBody componentBody = m_componentBodies.Array[i];
         if (componentBody != this && componentBody != m_parentBody && componentBody.m_parentBody != this)
         {
             result.Add(new CollisionBox
             {
                 Box           = componentBody.BoundingBox,
                 ComponentBody = componentBody
             });
         }
     }
 }
Ejemplo n.º 28
0
        public void Draw(Camera camera, int drawOrder)
        {
            m_vertices.Clear();
            m_indices.Clear();
            foreach (MovingBlockSet movingBlockSet2 in m_movingBlockSets)
            {
                DrawMovingBlockSet(camera, movingBlockSet2);
            }
            int num = 0;

            while (num < m_removing.Count)
            {
                MovingBlockSet movingBlockSet = m_removing[num];
                if (movingBlockSet.RemainCounter-- > 0)
                {
                    DrawMovingBlockSet(camera, movingBlockSet);
                    num++;
                }
                else
                {
                    m_removing.RemoveAt(num);
                }
            }
            if (m_vertices.Count > 0)
            {
                Vector3 viewPosition = camera.ViewPosition;
                Vector3 v            = new Vector3(MathUtils.Floor(viewPosition.X), 0f, MathUtils.Floor(viewPosition.Z));
                Matrix  value        = Matrix.CreateTranslation(v - viewPosition) * camera.ViewMatrix.OrientationMatrix * camera.ProjectionMatrix;
                Display.BlendState        = BlendState.Opaque;
                Display.DepthStencilState = DepthStencilState.Default;
                Display.RasterizerState   = RasterizerState.CullCounterClockwiseScissor;
                m_shader.GetParameter("u_origin").SetValue(v.XZ);
                m_shader.GetParameter("u_viewProjectionMatrix").SetValue(value);
                m_shader.GetParameter("u_viewPosition").SetValue(camera.ViewPosition);
                m_shader.GetParameter("u_texture").SetValue(m_subsystemAnimatedTextures.AnimatedBlocksTexture);
                m_shader.GetParameter("u_samplerState").SetValue(SamplerState.PointClamp);
                m_shader.GetParameter("u_fogColor").SetValue(new Vector3(m_subsystemSky.ViewFogColor));
                m_shader.GetParameter("u_fogStartInvLength").SetValue(new Vector2(m_subsystemSky.ViewFogRange.X, 1f / (m_subsystemSky.ViewFogRange.Y - m_subsystemSky.ViewFogRange.X)));
                Display.DrawUserIndexed(PrimitiveType.TriangleList, m_shader, TerrainVertex.VertexDeclaration, m_vertices.Array, 0, m_vertices.Count, m_indices.Array, 0, m_indices.Count);
            }
            if (DebugDrawMovingBlocks)
            {
                DebugDraw();
            }
        }
Ejemplo n.º 29
0
        public void MakeNoisepublic(ComponentBody sourceBody, Vector3 position, float loudness, float range)
        {
            float num = range * range;

            m_componentBodies.Clear();
            m_subsystemBodies.FindBodiesAroundPoint(new Vector2(position.X, position.Z), range, m_componentBodies);
            for (int i = 0; i < m_componentBodies.Count; i++)
            {
                ComponentBody componentBody = m_componentBodies.Array[i];
                if (componentBody != sourceBody && Vector3.DistanceSquared(componentBody.Position, position) < num)
                {
                    foreach (INoiseListener item in componentBody.Entity.FindComponents <INoiseListener>())
                    {
                        item.HearNoise(sourceBody, position, loudness);
                    }
                }
            }
        }
Ejemplo n.º 30
0
 public void Update(float dt)
 {
     if (m_thermometersToSimulateIndex < m_thermometersToSimulate.Count)
     {
         double period = MathUtils.Max(5.0 / (double)m_thermometersToSimulate.Count, 1.0);
         if (m_subsystemTime.PeriodicGameTimeEvent(period, 0.0))
         {
             Point3 point = m_thermometersToSimulate.Array[m_thermometersToSimulateIndex];
             SimulateThermometer(point.X, point.Y, point.Z, invalidateTerrainOnChange: true);
             m_thermometersToSimulateIndex++;
         }
     }
     else if (m_thermometersByPoint.Count > 0)
     {
         m_thermometersToSimulateIndex = 0;
         m_thermometersToSimulate.Clear();
         m_thermometersToSimulate.AddRange(m_thermometersByPoint.Keys);
     }
 }
Ejemplo n.º 31
0
        public BodyRaycastResult?Raycast(Vector3 start, Vector3 end, float inflateAmount, Func <ComponentBody, float, bool> action)
        {
            float             num               = Vector3.Distance(start, end);
            Ray3              ray               = new Ray3(start, (num > 0f) ? ((end - start) / num) : Vector3.UnitX);
            Vector2           corner            = new Vector2(start.X, start.Z);
            Vector2           corner2           = new Vector2(end.X, end.Z);
            BodyRaycastResult bodyRaycastResult = default(BodyRaycastResult);

            bodyRaycastResult.Ray      = ray;
            bodyRaycastResult.Distance = float.MaxValue;
            BodyRaycastResult value = bodyRaycastResult;

            m_componentBodies.Clear();
            FindBodiesInArea(corner, corner2, m_componentBodies);
            for (int i = 0; i < m_componentBodies.Count; i++)
            {
                ComponentBody componentBody = m_componentBodies.Array[i];
                float?        num2;
                if (inflateAmount > 0f)
                {
                    BoundingBox boundingBox = componentBody.BoundingBox;
                    boundingBox.Min -= new Vector3(inflateAmount);
                    boundingBox.Max += new Vector3(inflateAmount);
                    num2             = ray.Intersection(boundingBox);
                }
                else
                {
                    num2 = ray.Intersection(componentBody.BoundingBox);
                }
                if (num2.HasValue && num2.Value <= num && num2.Value < value.Distance && action(componentBody, num2.Value))
                {
                    value.Distance      = num2.Value;
                    value.ComponentBody = componentBody;
                }
            }
            if (value.ComponentBody == null)
            {
                return(null);
            }
            return(value);
        }
Ejemplo n.º 32
0
        public bool PreProcess(IPathRequest request)
        {
            if (!_enabled)
            {
                return(false);
            }

            var grid = GridManager.instance.GetGrid(request.to);

            if (grid == null)
            {
                return(false);
            }

            var goal = grid.GetCell(request.to, true);

            if (IsItSafe(goal))
            {
                return(false);
            }

            int d = 1;

            do
            {
                _buffer.Clear();
                grid.GetConcentricNeighbours(goal, d++, _buffer);
                var count = _buffer.count;
                for (int i = 0; i < count; i++)
                {
                    if (IsItSafe(_buffer[i]))
                    {
                        request.to = _buffer[i].position;
                        return(true);
                    }
                }
            }while (_buffer.count > 0);

            return(false);
        }
Ejemplo n.º 33
0
        private void GetWalkableCellNeighbours(Cell cell, DynamicArray<Cell> walkableCells, bool preventDiagonals)
        {
            if (walkableCells.count != 0)
            {
                // if the list for holding the cells is not empty, make it empty
                walkableCells.Clear();
            }

            int mx = cell.matrixPosX;
            int mz = cell.matrixPosZ;

            // prepare non-diagonal neighbours in all 4 directions (up, down, left, right)
            var n1 = _grid.cellMatrix[mx - 1, mz];
            var n2 = _grid.cellMatrix[mx, mz - 1];
            var n3 = _grid.cellMatrix[mx + 1, mz];
            var n4 = _grid.cellMatrix[mx, mz + 1];

            var unitAttributes = _unitProperties.attributes;

            bool lw = false, rw = false, uw = false, dw = false;

            if (n1 != null)
            {
                // check whether this neighbour has been fast marched
                lw = _fastMarchedCellsSet.ContainsKey(n1.position);
                if (!lw)
                {
                    // if the cell has not been fast marched...
                    if (n1.isWalkable(unitAttributes) && cell.isWalkableFrom(n1, _unitProperties))
                    {
                        // ... and the cell is walkable, then add it to the list
                        walkableCells.Add(n1);
                        lw = true;
                    }
                }
            }

            if (n2 != null)
            {
                dw = _fastMarchedCellsSet.ContainsKey(n2.position);
                if (!dw)
                {
                    if (n2.isWalkable(unitAttributes) && cell.isWalkableFrom(n2, _unitProperties))
                    {
                        walkableCells.Add(n2);
                        dw = true;
                    }
                }
            }

            if (n3 != null)
            {
                rw = _fastMarchedCellsSet.ContainsKey(n3.position);
                if (!rw)
                {
                    if (n3.isWalkable(unitAttributes) && cell.isWalkableFrom(n3, _unitProperties))
                    {
                        walkableCells.Add(n3);
                        rw = true;
                    }
                }
            }

            if (n4 != null)
            {
                uw = _fastMarchedCellsSet.ContainsKey(n4.position);
                if (!uw)
                {
                    if (n4.isWalkable(unitAttributes) && cell.isWalkableFrom(n4, _unitProperties))
                    {
                        walkableCells.Add(n4);
                        uw = true;
                    }
                }
            }

            if (preventDiagonals)
            {
                return;
            }

            bool urw, drw, dlw, ulw;
            if (_allowCornerCutting)
            {
                // if we allow corner cuttting, then just one of the neighbours need to be free to go diagonally
                urw = uw || rw;
                drw = dw || rw;
                dlw = dw || lw;
                ulw = uw || lw;
            }
            else
            {
                // however, if we don't allow corner cutting, then both neighbours need to be free to allow diagonal neighbour
                urw = uw && rw;
                drw = dw && rw;
                dlw = dw && lw;
                ulw = uw && lw;
            }

            if (dlw)
            {
                var n5 = _grid.cellMatrix[mx - 1, mz - 1];
                if (n5 != null && !_fastMarchedCellsSet.ContainsKey(n5.position))
                {
                    if (n5.isWalkable(unitAttributes) && cell.isWalkableFrom(n5, _unitProperties))
                    {
                        walkableCells.Add(n5);
                    }
                }
            }

            if (ulw)
            {
                var n6 = _grid.cellMatrix[mx - 1, mz + 1];
                if (n6 != null && !_fastMarchedCellsSet.ContainsKey(n6.position))
                {
                    if (n6.isWalkable(unitAttributes) && cell.isWalkableFrom(n6, _unitProperties))
                    {
                        walkableCells.Add(n6);
                    }
                }
            }

            if (drw)
            {
                var n7 = _grid.cellMatrix[mx + 1, mz - 1];
                if (n7 != null && !_fastMarchedCellsSet.ContainsKey(n7.position))
                {
                    if (n7.isWalkable(unitAttributes) && cell.isWalkableFrom(n7, _unitProperties))
                    {
                        walkableCells.Add(n7);
                    }
                }
            }

            if (urw)
            {
                var n8 = _grid.cellMatrix[mx + 1, mz + 1];
                if (n8 != null && !_fastMarchedCellsSet.ContainsKey(n8.position))
                {
                    if (n8.isWalkable(unitAttributes) && cell.isWalkableFrom(n8, _unitProperties))
                    {
                        walkableCells.Add(n8);
                    }
                }
            }
        }
Ejemplo n.º 34
0
        private bool GetCellNeighboursAndUnwalkability(Cell cell, DynamicArray<Cell> walkableCells, bool preventDiagonals)
        {
            if (walkableCells.count != 0)
            {
                // if the list for holding the cells is not empty, make it empty
                walkableCells.Clear();
            }

            var unitAttributes = _unitProperties.attributes;

            int mx = cell.matrixPosX;
            int mz = cell.matrixPosZ;

            for (int x = -1; x <= 1; x++)
            {
                for (int z = -1; z <= 1; z++)
                {
                    if (x == 0 && z == 0)
                    {
                        // cell in the middle is the cell which neighbours we want, thus ignore the center cell
                        continue;
                    }

                    if (x != 0 && z != 0 && preventDiagonals)
                    {
                        // if we are supposed to prevent diagonal moves, then ignore diagonal cell neighbours
                        continue;
                    }

                    var neighbour = _grid.cellMatrix[mx + x, mz + z];
                    if (neighbour != null)
                    {
                        if (neighbour.isWalkable(unitAttributes) && cell.isWalkableFrom(neighbour, _unitProperties))
                        {
                            // if the neighbour is walkable, and the center cell is walkable from this neighbour, then it is of interest
                            walkableCells.Add(neighbour);
                        }
                        else
                        {
                            // if we find just a single neighbour that is blocked, then we return false
                            return false;
                        }
                    }
                    else if (_builtInContainment)
                    {
                        // if there is a missing cell, and we want to use built-in containment, then return false on first missing cell (off-grid)
                        return false;
                    }
                }
            }

            return true;
        }