예제 #1
0
    void Start()
    {
        if (heightmapGameObject != null)
        {
            heightmap = UnityEngineHelper.GetInterface <IHeightmap>(heightmapGameObject);
        }

        if (heightmap == null)
        {
            Debug.LogError("MockAllotment needs a reference to a game object containing at least one component that implements IHeightmap");
            return;
        }

        if (!heightmap.Finished())
        {
            Debug.LogError("MockAllotment script can only execute after the components that implements IHeightmap (Configure execution order that in Edit > Project Settings > Script Execution Order)");
            return;
        }

        if (allotmentBuilderGameObject != null)
        {
            allotmentBuilders = UnityEngineHelper.GetInterfaces <IAllotmentBuilder>(allotmentBuilderGameObject);
        }
        if (allotmentBuilders == null)
        {
            Debug.LogError("MockAllotment needs a reference to a game object containing at least one component that implements IAllotmentBuilder");
            return;
        }

        Generate();
    }
        private void SetupHeightmap()
        {
            const int width = 3;
            const int height = 3;

            var mock = new Mock<IHeightmap>();

            mock.SetupGet(heightmap => heightmap.Width).Returns(width);
            mock.SetupGet(heightmap => heightmap.Height).Returns(height);

            for (int x = 0; x < width; x++)
            {
                for(int y = 0; y < height; y++)
                {
                    int xPosition = x;
                    int yPosition = y;

                    if (xPosition < (width - 1) && yPosition < (height - 1))
                    {
                        mock.SetupGet(heightmap => heightmap[xPosition, yPosition])
                            .Returns(0);
                    }
                    else
                    {
                        mock.SetupGet(heightmap => heightmap[xPosition, yPosition])
                            .Returns(2);
                    }
                }
            }

                _mockHeightmap = mock.Object;
        }
예제 #3
0
        private void SetupHeightmap()
        {
            const int width  = 3;
            const int height = 3;

            var mock = new Mock <IHeightmap>();

            mock.SetupGet(heightmap => heightmap.Width).Returns(width);
            mock.SetupGet(heightmap => heightmap.Height).Returns(height);

            for (int x = 0; x < width; x++)
            {
                for (int y = 0; y < height; y++)
                {
                    int xPosition = x;
                    int yPosition = y;

                    if (xPosition < (width - 1) && yPosition < (height - 1))
                    {
                        mock.SetupGet(heightmap => heightmap[xPosition, yPosition])
                        .Returns(0);
                    }
                    else
                    {
                        mock.SetupGet(heightmap => heightmap[xPosition, yPosition])
                        .Returns(2);
                    }
                }
            }

            _mockHeightmap = mock.Object;
        }
        private void SetupHeightmapMock()
        {
            var mock = new Mock <IHeightmap>();

            mock.SetupGet(heightmap => heightmap.Height).Returns(8);
            mock.SetupGet(heightmap => heightmap.Width).Returns(8);

            var random = new Random();

            //Upper-left quadrant
            mock.Setup(heightmap => heightmap[It.IsInRange(0, 3, Range.Inclusive),
                                              It.IsInRange(0, 3, Range.Inclusive)])
            .Returns(() => random.Next(0, 50));

            //Upper-right quadrant
            mock.Setup(heightmap => heightmap[It.IsInRange(4, 7, Range.Inclusive),
                                              It.IsInRange(0, 3, Range.Inclusive)])
            .Returns(() => random.Next(51, 150));

            //Lower-left quadrant
            mock.Setup(heightmap => heightmap[It.IsInRange(0, 3, Range.Inclusive),
                                              It.IsInRange(4, 7, Range.Inclusive)])
            .Returns(() => random.Next(151, 200));

            //Lower-right quadrant
            mock.Setup(heightmap => heightmap[It.IsInRange(4, 7, Range.Inclusive),
                                              It.IsInRange(4, 7, Range.Inclusive)])
            .Returns(() => random.Next(201, 255));

            _mockHeightmap = mock.Object;
        }
예제 #5
0
    public GameObject Build(Allotment allotment, IHeightmap heightmap)
    {
        GameObject allotmentGO = new GameObject("Allotment");
        float      z           = heightmap.GetHeight(allotment.Center.x, allotment.Center.y);

        allotmentGO.AddComponent <MeshFilter>().mesh       = StandardGeometry.CreateCubeMesh(allotment.Corners, height, z);
        allotmentGO.AddComponent <MeshRenderer>().material = material;
        return(allotmentGO);
    }
 public HeightmapTextureProcessor(IHeightmap heightmap,
     ITextureGroupResolver textureGroupResolver,
     ITextureGroupTransitionRepository textureGroupTransitionRepository)
 {
     _heightmap = heightmap;
     _textureGroupResolver = textureGroupResolver;
     _textureGroupTransitionRepository = textureGroupTransitionRepository;
     _textures = new Lazy<short[,]>(InitializeTextures);
 }
예제 #7
0
 public HeightmapTextureProcessor(IHeightmap heightmap,
                                  ITextureGroupResolver textureGroupResolver,
                                  ITextureGroupTransitionRepository textureGroupTransitionRepository)
 {
     _heightmap                        = heightmap;
     _textureGroupResolver             = textureGroupResolver;
     _textureGroupTransitionRepository = textureGroupTransitionRepository;
     _textures = new Lazy <short[, ]>(InitializeTextures);
 }
예제 #8
0
파일: World.cs 프로젝트: JohnMcCaffery/XMRM
 public World(Scene internalScene, ISecurityCredential securityCredential, bool isGod)
 {
     m_security = securityCredential;
     m_internalScene = internalScene;
     m_heights = new HeightmapWrapper(new Heightmap(m_internalScene, this));
     m_rawObjs = new ObjectAccessor(m_internalScene, securityCredential, isGod);
     m_objs = new ObjectAccessorWrapper(m_rawObjs);
     _chatListeners = new List<OnChatDelegate>();
     _newUserListeners = new List<OnNewUserDelegate>();
     CurrentCount++;
     TotalCount++;
 }
예제 #9
0
 /// <summary>
 /// Creates a new instance of Surface.
 /// The default vertex format is VertexPositionColorNormalTexture.
 /// </summary>
 /// <param name="graphics">Graphics device.</param>
 /// <param name="heightmap">The heightmap geometry to create from.</param>
 /// <param name="patchSegmentCount">Number of the smallest square block that made up the surface patch.</param>
 public Surface(GraphicsDevice graphics, IHeightmap heightmap, int patchSegmentCount, Type vertexType)
     : this(graphics)
 {
     var supportInitialize = (ISupportInitialize)this;
     supportInitialize.BeginInit();
     {
         PatchSegmentCount = patchSegmentCount;
         VertexType        = VertexType;
         Heightmap         = heightmap;
     }
     supportInitialize.EndInit();
 }
        public HeightmapTextureGroupResolver(IHeightmap heightmap, ITextureGroupRepository <TextureGroupRange> textureGroupRepository)
        {
            if (heightmap == null)
            {
                throw new ArgumentNullException("heightmap");
            }

            if (textureGroupRepository == null)
            {
                throw new ArgumentNullException("textureGroupRepository");
            }

            _heightmap = heightmap;
            _textureGroupRepository = textureGroupRepository;
        }
        public HeightmapTextureGroupResolver(IHeightmap heightmap, ITextureGroupRepository<TextureGroupRange> textureGroupRepository)
        {
            if(heightmap == null)
            {
                throw new ArgumentNullException("heightmap");
            }

            if(textureGroupRepository == null)
            {
                throw new ArgumentNullException("textureGroupRepository");
            }

            _heightmap = heightmap;
            _textureGroupRepository = textureGroupRepository;
        }
예제 #12
0
        private static TerrainShape CreateTerrainShape(IHeightmap heightmap)
        {
            int xLength = heightmap.Width + 1;
            int zLength = heightmap.Height + 1;

            var heights = new float[xLength, zLength];

            for (int x = 0; x < xLength; ++x)
            {
                for (int z = 0; z < zLength; z++)
                {
                    heights[x, z] = heightmap.GetHeight(x, z);
                }
            }

            return(new TerrainShape(heights));
        }
예제 #13
0
        /// <summary>
        /// Constructor is for internal use only.
        /// </summary>
        internal SurfacePatch(Surface surface, int xPatch, int zPatch)
        {
            var patchSegmentCount = surface.PatchSegmentCount;

            if (6 * patchSegmentCount * patchSegmentCount > ushort.MaxValue)
            {
                throw new ArgumentOutOfRangeException();
            }

            if (!IsPowerOfTwo(patchSegmentCount))
            {
                throw new ArgumentOutOfRangeException("PatchSegmentCount must be a power of two.");
            }

            this.surface        = surface;
            this.heightmap      = surface.Heightmap;
            this.GraphicsDevice = surface.GraphicsDevice;
            this.segmentCount   = patchSegmentCount;
            this.X = xPatch;
            this.Z = zPatch;
        }
예제 #14
0
 // Note: the heightmap is optional.
 public void Awake(Vector3 origin, int numRows, int numCols, float cellSize, bool show, IHeightmap heightmap)
 {
     base.Awake(origin, numRows, numCols, cellSize, show);
     m_heightmap = heightmap;
 }
예제 #15
0
 public PathGrid()
 {
     m_heightmap = null;
 }
예제 #16
0
 public HeightMapEventArgs(IHeightmap map)
 {
     Map = map;
 }
예제 #17
0
 /// <summary>
 /// Creates a new instance of Surface.
 /// The default vertex format is VertexPositionColorNormalTexture.
 /// </summary>
 /// <param name="graphics">Graphics device.</param>
 /// <param name="heightmap">The heightmap geometry to create from.</param>
 /// <param name="patchSegmentCount">Number of the smallest square block that made up the surface patch.</param>
 public Surface(GraphicsDevice graphics, IHeightmap heightmap, int patchSegmentCount)
     : this(graphics, heightmap, patchSegmentCount, null)
 {
 }
예제 #18
0
 /// <summary>
 /// Creates a new instance of Surface.
 /// The default vertex format is VertexPositionColorNormalTexture.
 /// </summary>
 /// <param name="graphics">Graphics device.</param>
 /// <param name="heightmap">The heightmap geometry to create from.</param>
 public Surface(GraphicsDevice graphics, IHeightmap heightmap)
     : this(graphics, heightmap, 32)
 {
 }
예제 #19
0
		public PathGrid()
		{
			m_heightmap = null;
		}
예제 #20
0
 public HeightmapWrapper(IHeightmap heightmap)
 {
     m_heightmap = heightmap;
 }
예제 #21
0
		// Note: the heightmap is optional.
		public void Awake (Vector3 origin, int numRows, int numCols, float cellSize, bool show, IHeightmap heightmap)
		{
			base.Awake(origin, numRows, numCols, cellSize, show);
			m_heightmap = heightmap;
		}
예제 #22
0
 private static Terrain CreateTerrain(IHeightmap heightmap)
 {
     return(heightmap != null ? new Terrain(CreateTerrainShape(heightmap), AffineTransform.Identity) : null);
 }
        private void SetupHeightmapMock()
        {
            var mock = new Mock<IHeightmap>();

            mock.SetupGet(heightmap => heightmap.Height).Returns(8);
            mock.SetupGet(heightmap => heightmap.Width).Returns(8);

            var random = new Random();

            //Upper-left quadrant
            mock.Setup(heightmap => heightmap[It.IsInRange(0, 3, Range.Inclusive),
                                              It.IsInRange(0, 3, Range.Inclusive)])
                .Returns(() => random.Next(0, 50));

            //Upper-right quadrant
            mock.Setup(heightmap => heightmap[It.IsInRange(4, 7, Range.Inclusive),
                                              It.IsInRange(0, 3, Range.Inclusive)])
                .Returns(() => random.Next(51, 150));

            //Lower-left quadrant
            mock.Setup(heightmap => heightmap[It.IsInRange(0, 3, Range.Inclusive),
                                              It.IsInRange(4, 7, Range.Inclusive)])
                .Returns(() => random.Next(151, 200));

            //Lower-right quadrant
            mock.Setup(heightmap => heightmap[It.IsInRange(4, 7, Range.Inclusive),
                                              It.IsInRange(4, 7, Range.Inclusive)])
                .Returns(() => random.Next(201, 255));

            _mockHeightmap = mock.Object;
        }
    void Start()
    {
        if (roadNetwork == null)
        {
            Debug.LogError("RoadDensityBasedSettlementSpawner needs a reference to a RoadNetwork");
            return;
        }

        if (!roadNetwork.Finished)
        {
            Debug.LogError("RoadDensityBasedSettlementSpawner script can only execute after RoadNetwork (Configure execution order that in Edit > Project Settings > Script Execution Order)");
            return;
        }

        if (roadDensityMap == null)
        {
            Debug.LogError("RoadDensityBasedSettlementSpawner needs a reference to a RoadDensityMap");
            return;
        }

        if (!roadDensityMap.Finished())
        {
            Debug.LogError("RoadDensityBasedSettlementSpawner script can only execute after RoadDensityMap (Configure execution order that in Edit > Project Settings > Script Execution Order)");
            return;
        }

        if (heightmapGameObject != null)
        {
            heightmap = UnityEngineHelper.GetInterface <IHeightmap>(heightmapGameObject);
        }

        if (heightmap == null)
        {
            Debug.LogError("RoadDensityBasedSettlementSpawner needs a reference to a game object containing at least one component that implements IHeightmap");
            return;
        }

        if (!heightmap.Finished())
        {
            Debug.LogError("RoadDensityBasedSettlementSpawner script can only execute after the components that implements IHeightmap (Configure execution order that in Edit > Project Settings > Script Execution Order)");
            return;
        }

        List <IAllotmentBuilder> allotmentBuilders = null;

        if (allotmentBuilderGameObject != null)
        {
            allotmentBuilders = UnityEngineHelper.GetInterfaces <IAllotmentBuilder>(allotmentBuilderGameObject);
        }
        if (allotmentBuilders == null)
        {
            Debug.LogError("RoadDensityBasedSettlementSpawner needs a reference to a game object containing at least one component that implements IAllotmentBuilder");
            return;
        }

        {
            float minThreshold = -float.MaxValue;
            foreach (var densityTier in densityTiers)
            {
                if (densityTier.threshold < minThreshold)
                {
                    Debug.LogError("Density tier has a threshold smaller than it's predecessor");
                    return;
                }
                minThreshold = densityTier.threshold;
            }
        }

        minAllotmentWidth = Allotment.GetWidth(Config.allotmentMinHalfDiagonal, Config.allotmentMinAspect);

        allotments = new List <Tuple <float, Allotment> >();
        HashSet <Segment> visited = new HashSet <Segment>();

        foreach (var segment in roadNetwork.Segments)
        {
            RoadNetworkTraversal.PreOrder(segment, SegmentVisitor, roadNetwork.Mask, ref visited);
        }
        if (maxNumAllotments > 0 && allotments.Count > maxNumAllotments)
        {
            allotments.Sort((a, b) => b.Item1.CompareTo(a.Item1));
            allotments = allotments.GetRange(0, maxNumAllotments);
        }
        GameObject allotmentsGO = new GameObject("Allotments");

        allotmentsGO.transform.parent = transform;
        {
            foreach (var allotment in allotments)
            {
                foreach (var allotmentBuilder in allotmentBuilders)
                {
                    GameObject allotmentGO = allotmentBuilder.Build(allotment.Item2, heightmap);
                    allotmentGO.transform.parent = allotmentsGO.transform;
                }
            }
        }
        Debug.Log(allotments.Count + " allotments spawned");
    }
예제 #25
0
    void Start()
    {
        if (roadNetwork == null)
        {
            Debug.LogError("RoadNetworkMesh needs a reference to a RoadNetwork");
            return;
        }

        if (!roadNetwork.Finished)
        {
            Debug.LogError("RoadNetworkMesh script can only execute after RoadNetwork (Configure execution order that in Edit > Project Settings > Script Execution Order)");
            return;
        }

        IHeightmap heightmap = null;

        if (heightmapGameObject != null)
        {
            heightmap = UnityEngineHelper.GetInterface <IHeightmap>(heightmapGameObject);
        }

        if (heightmap == null)
        {
            Debug.LogError("RoadNetworkMesh needs a reference to a game object containing at least one component that implements IHeightmap");
            return;
        }

        if (!heightmap.Finished())
        {
            Debug.LogError("RoadNetworkMesh script can only execute after the components that implements IHeightmap (Configure execution order that in Edit > Project Settings > Script Execution Order)");
            return;
        }

        var geometry = RoadNetworkGeometryBuilder.Build(
            1.0f,
            Config.highwaySegmentWidth,
            Config.streetSegmentWidth,
            lengthStep,
            roadNetwork.Segments,
            roadNetwork.Mask
            );

        GameObject     roadGO   = new GameObject("Road");
        List <Vector3> vertices = new List <Vector3>();

        geometry.GetSegmentPositions().ForEach((p) =>
        {
            vertices.Add(new Vector3(p.x, heightmap.GetHeight(p.x, p.y) + zOffset, p.y));
        });
        Mesh mesh = new Mesh();

        mesh.vertices  = vertices.ToArray();
        mesh.triangles = geometry.GetSegmentIndices().ToArray();
        mesh.uv        = geometry.GetSegmentUvs().ToArray();
        mesh.RecalculateNormals();
        GameObject segmentsGO = new GameObject("Segments");

        segmentsGO.AddComponent <MeshFilter>().mesh = mesh;
        var meshRenderer = segmentsGO.AddComponent <MeshRenderer>();

        meshRenderer.material          = roadSegmentsMaterial;
        meshRenderer.shadowCastingMode = ShadowCastingMode.Off;
        segmentsGO.transform.parent    = roadGO.transform;
        vertices = new List <Vector3>();
        geometry.GetCrossingPositions().ForEach((p) =>
        {
            vertices.Add(new Vector3(p.x, heightmap.GetHeight(p.x, p.y) + zOffset, p.y));
        });
        mesh           = new Mesh();
        mesh.vertices  = vertices.ToArray();
        mesh.triangles = geometry.GetCrossingIndices().ToArray();
        mesh.uv        = geometry.GetCrossingUvs().ToArray();
        mesh.RecalculateNormals();
        GameObject crossingsGO = new GameObject("Crossings");

        crossingsGO.AddComponent <MeshFilter>().mesh = mesh;
        meshRenderer                   = crossingsGO.AddComponent <MeshRenderer>();
        meshRenderer.material          = roadCrossingsMaterial;
        meshRenderer.shadowCastingMode = ShadowCastingMode.Off;
        crossingsGO.transform.parent   = roadGO.transform;
        roadGO.transform.parent        = transform;
    }
예제 #26
0
    void Start()
    {
        if (roadNetwork == null)
        {
            Debug.LogError("RandomSettlementsSpawner needs a reference to a RoadNetwork");
            return;
        }

        if (!roadNetwork.Finished)
        {
            Debug.LogError("RandomSettlementsSpawner script can only execute after RoadNetwork (Configure execution order that in Edit > Project Settings > Script Execution Order)");
            return;
        }

        if (heightmapGameObject != null)
        {
            heightmap = UnityEngineHelper.GetInterface <IHeightmap>(heightmapGameObject);
        }

        if (heightmap == null)
        {
            Debug.LogError("RandomSettlementsSpawner needs a reference to a game object containing at least one component that implements IHeightmap");
            return;
        }

        if (!heightmap.Finished())
        {
            Debug.LogError("RandomSettlementsSpawner script can only execute after the components that implements IHeightmap (Configure execution order that in Edit > Project Settings > Script Execution Order)");
            return;
        }

        List <IAllotmentBuilder> allotmentBuilders = null;

        if (allotmentBuilderGameObject != null)
        {
            allotmentBuilders = UnityEngineHelper.GetInterfaces <IAllotmentBuilder>(allotmentBuilderGameObject);
        }
        if (allotmentBuilders == null)
        {
            Debug.LogError("RoadDensitySettlementSpawner needs a reference to a game object containing at least one component that implements IAllotmentBuilder");
            return;
        }

        Context           context = new Context(roadNetwork.Quadtree);
        HashSet <Segment> visited = new HashSet <Segment>();

        foreach (var segment in roadNetwork.Segments)
        {
            RoadNetworkTraversal.PreOrder(segment, ref context, -1, SegmentVisitor, roadNetwork.Mask, ref visited);
        }
        GameObject allotmentsGO = new GameObject("Allotments");

        allotmentsGO.transform.parent = transform;
        foreach (var allotment in context.allotments)
        {
            foreach (var allotmentBuilder in allotmentBuilders)
            {
                GameObject allotmentGO = allotmentBuilder.Build(allotment, heightmap);
                allotmentGO.transform.parent = allotmentsGO.transform;
            }
        }
        Debug.Log(context.allotments.Count + " allotments spawned");
    }