示例#1
0
        public void Should_Create_New_Space_With_No_Items()
        {
            var spaceBuilder = new SpaceBuilder();
            var space        = spaceBuilder.Create3DSpace(new List <(I3DShape shape, Position3D position3D)>());

            Assert.Empty(space.Shapes);
        }
示例#2
0
        public void Should_Create_New_Space_With_Items()
        {
            var spaceBuilder = new SpaceBuilder();
            var space        = spaceBuilder.Create3DSpace(new List <(I3DShape shape, Position3D position3D)>
            {
                (new Cube(2), new Position3D(1, 2, 3)),
                (new Cube(3), new Position3D(4, 5, 6))
            });

            Assert.Equal(2, space.Shapes.Count());
        }
示例#3
0
        public void GenerateChunkBuildersForSpace(SpaceBuilder space)
        {
            var min = GetNearestChunkPosition(new IntVector2(space.GetMaximalValue(Directions.Left),
                                                             space.GetMaximalValue(Directions.Down)));

            var max = GetNearestChunkPosition(new IntVector2(space.GetMaximalValue(Directions.Right),
                                                             space.GetMaximalValue(Directions.Up)));

            for (var chunkX = min.X; chunkX <= max.X; chunkX += World.CHUNK_SIZE)
            {
                for (var chunkY = min.Y; chunkY <= max.Y; chunkY += World.CHUNK_SIZE)
                {
                    var pos = new IntVector2(chunkX, chunkY);
                    // Space has not yet validated it does not overlap existing chunks
                    if (!_chunksByWorldPosition.ContainsKey(pos))
                    {
                        GetBuilderAtPosition(pos);
                    }
                }
            }
        }
        private static void LogSpaceHistory(SpaceBuilder changedBuilder)
        {
            var space = changedBuilder.Build();

            if (space is ComplexSpace)
            {
                var complexSpace = space as ComplexSpace;
                foreach (var region in complexSpace.Regions)
                {
                    foreach (var regionSpace in region.Spaces)
                    {
                        if (!_historyPerBuilder.TryGetValue(changedBuilder, out var history))
                        {
                            history = CreateHistory();

                            _historyPerBuilder[changedBuilder] = history;
                        }

                        history.LogChange(regionSpace);
                        _timeline.Add(history);
                    }
                }
            }
            else
            {
                if (!_historyPerBuilder.TryGetValue(changedBuilder, out var history))
                {
                    history = CreateHistory();

                    _historyPerBuilder[changedBuilder] = history;
                }

                history.LogChange(space);
                _timeline.Add(history);
            }
        }