Example #1
0
        private void BuildVertices(Vector4 mapSize)
        {
            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();


            sw.Start();
            WorldGenerator.generateRegionMapLOD(out this.Vertices, out this.sector, out this.resources, (int)mapSize.X, (int)mapSize.Y, (int)mapSize.Z, (int)mapSize.W);
            sw.Stop();
            Console.WriteLine("map generation took: " + sw.ElapsedMilliseconds.ToString() + " ms");
            GameSession.GameStorage storage = new GameSession.GameStorage("map.dat", true);
            storage.Write(mapSize);
            storage.Write(this.Vertices.Length);
            for (int i = 0; i < this.Vertices.Length; i++)
            {
                storage.Write(this.Vertices[i]);
            }
            storage.Write(this.sector.Length);
            for (int i = 0; i < this.sector.Length; i++)
            {
                storage.Write(this.sector[i]);
            }
            storage.Write(this.resources.Length);
            for (int i = 0; i < this.resources.Length; i++)
            {
                this.resources[i].Store(storage);
            }

            storage.Close();
        }
Example #2
0
        public QuadTree(Vector4 mapSize, GraphicsDevice device, GameSession.GameStorage storage)
        {
            //   this.Cull = false;
            this.MinimumDepth = 8;

            int bufferSize = (int)((mapSize.X + 1) * (mapSize.Y + 1)) * 3;

            Device = device;
            //  _position = position;
            //  _topNodeSize =  heightMap.Width - 1;
            _topNodeSize = (int)mapSize.X - 1;

            if (storage == null)
            {
                _vertices = new TreeVertexCollection(mapSize);
            }
            else
            {
                _vertices = new TreeVertexCollection(storage);
            }
            _buffers  = new BufferManager(_vertices.Vertices, device, bufferSize);
            _rootNode = new QuadNode(NodeType.FullNode, _topNodeSize, 1, null, this, 0);
            //   View = viewMatrix;
            //   Projection = projectionMatrix;

            //  ViewFrustrum = new BoundingFrustum(viewMatrix * projectionMatrix);

            //Construct an array large enough to hold all of the indices we'll need.
            //  Indices = new int[((heightMap.Width + 1) * (heightMap.Height + 1)) * 3];
            //Indices = new int[(int)((mapSize.X + 1) * (mapSize.Y + 1)) * 3];
            Indices = new int[bufferSize];
        }
Example #3
0
        public TreeVertexCollection(GameSession.GameStorage storage)
        {
            this.MapSize = storage.ReadVector4();
            _topSize     = (int)this.MapSize.X - 1;
            _halfSize    = _topSize / 2;
            _vertexCount = (int)(this.MapSize.X * this.MapSize.Y);

            int vertexCount = storage.ReadInt();

            //Initialize our array to hold the vertices
            Vertices = new VertexMultitextured[_vertexCount];

            //Our method to populate the vertex collection
            // VertexMultitextured[] Vertices;
            for (int i = 0; i < this.Vertices.Length; i++)
            {
                this.Vertices[i] = storage.ReadVertexMultiTextured();
            }

            // int[] sector;
            sector = new int[storage.ReadInt()];
            for (int i = 0; i < sector.Length; i++)
            {
                sector[i] = storage.ReadInt();
            }

            // ResourceCell[] resources;
            resources = new ResourceCell[storage.ReadInt()];
            for (int i = 0; i < this.resources.Length; i++)
            {
                resources[i] = new ResourceCell();
                resources[i].Restore(storage);
            }

            //Our method to  calculate the normals for all vertices
            CalculateAllNormals();
        }
Example #4
0
        public void Store(GameSession.GameStorage storage)
        {
            storage.Write(MapSize);     //  Vector4 MapSize;

            // VertexMultitextured[] Vertices;
            for (int i = 0; i < this.Vertices.Length; i++)
            {
                storage.Write(this.Vertices[i]);
            }

            // int[] sector;
            storage.Write(sector.Length);
            for (int i = 0; i < sector.Length; i++)
            {
                storage.Write(sector[i]);
            }

            // ResourceCell[] resources;
            storage.Write(resources.Length);
            for (int i = 0; i < this.resources.Length; i++)
            {
                resources[i].Store(storage);
            }
        }
Example #5
0
 public void Store(GameSession.GameStorage storage)
 {
     _quadTree.Store(storage);
 }
Example #6
0
        public void CreateNewMap(int mapNumCellsPerRow, int mapNumCellPerColumn, GraphicsDevice device, GameSession.GameStorage storage)
        {
            entities = new List <Entity>();
            this.mapNumCellsPerRow   = mapNumCellsPerRow;
            this.mapNumCellPerColumn = mapNumCellPerColumn;

            _quadTree = new QuadTree(new Vector4(mapNumCellsPerRow, mapNumCellPerColumn, this.minHeight, this.maxHeight), device, storage);
        }
Example #7
0
        public LODTerrain(GameSession.GameSession RunningGameSession, int mapNumCellsPerRow, int mapNumCellPerColumn, Effect effect, GraphicsDevice device, GameSession.GameStorage storage)
        {
            this.RunningGameSession = RunningGameSession;

            playerLight       = new PPPointLight(new Vector3(0, 0, 0), Color.White * 0.50f, 100);
            this.playerCamera = this.RunningGameSession.PlayerCamera;

            modelEffect = this.RunningGameSession.Content.Load <Effect>("PrelightEffects");


            CreateNewMap(mapNumCellsPerRow, mapNumCellPerColumn, device, storage);

            prelightRender = new PrelightingRenderer(this.RunningGameSession, effect, device, entities);

            this.Initialize();
        }
Example #8
0
 public void Store(GameSession.GameStorage storage)
 {
     this._vertices.Store(storage);
 }