Beispiel #1
0
        public override void GetTriangles(TriangleCollection to, float min_x, float min_y, float max_x, float max_y)
        {
            Console.WriteLine("TotalMemory " + System.GC.GetTotalMemory(false) / (1024 * 1024) + " MB");
            foreach (WMOInstance wi in wdt.gwmois)
            {
                AddTriangles(to, wi);
            }
            SparseMatrix3D <WMO> instances = new SparseMatrix3D <WMO>();

            for (float x = min_x; x < max_x; x += ChunkReader.TILESIZE)
            {
                for (float y = min_y; y < max_y; y += ChunkReader.TILESIZE)
                {
                    int chunk_x, chunk_y;
                    GetChunkCoord(x, y, out chunk_x, out chunk_y);
                    /*ChunkData d = */ GetChunkData(to, chunk_x, chunk_y, instances);

                    //to.AddAllTrianglesFrom(d.triangles);
                }
            }
        }
        private void GetChunkData(TriangleCollection triangles, int chunk_x, int chunk_y, SparseMatrix3D <WMO> instances)
        {
            if (chunk_x < 0)
            {
                return;
            }
            if (chunk_y < 0)
            {
                return;
            }
            if (chunk_x > 63)
            {
                return;
            }
            if (chunk_y > 63)
            {
                return;
            }

            if (triangles == null)
            {
                return;
            }

            if (wdtf == null)
            {
                return;
            }
            if (wdt == null)
            {
                return;
            }
            wdtf.LoadMapTile(chunk_x, chunk_y);

            MapTile t = wdt.maptiles[chunk_x, chunk_y];

            if (t != null)
            {
                //System.Diagnostics.Debug.Write(" render");
                // Map tiles
                for (int ci = 0; ci < 16; ci++)
                {
                    for (int cj = 0; cj < 16; cj++)
                    {
                        MapChunk c = t.chunks[ci, cj];
                        if (c != null)
                        {
                            AddTriangles(triangles, c);
                        }
                    }
                }

                // World objects

                foreach (WMOInstance wi in t.wmois)
                {
                    if (wi != null && wi.wmo != null)
                    {
                        String fn   = wi.wmo.fileName;
                        int    last = fn.LastIndexOf('\\');
                        fn = fn.Substring(last + 1);
                        // logger.WriteLine("    wmo: " + fn + " at " + wi.pos);
                        if (fn != null)
                        {
                            WMO old = instances.Get((int)wi.pos.x, (int)wi.pos.y, (int)wi.pos.z);
                            if (old == wi.wmo)
                            {
                                //logger.WriteLine("Already got " + fn);
                            }
                            else
                            {
                                instances.Set((int)wi.pos.x, (int)wi.pos.y, (int)wi.pos.z, wi.wmo);
                                AddTriangles(triangles, wi);
                            }
                        }
                    }
                }

                foreach (ModelInstance mi in t.modelis)
                {
                    if (mi != null && mi.model != null)
                    {
                        String fn   = mi.model.fileName;
                        int    last = fn.LastIndexOf('\\');
                        // fn = fn.Substring(last + 1);
                        //logger.WriteLine("    wmi: " + fn + " at " + mi.pos);
                        AddTriangles(triangles, mi);

                        //logger.WriteLine("    model: " + fn);
                    }
                }

                logger.WriteLine("wee");

                /*logger.WriteLine(
                 *                      String.Format(" Triangles - Map: {0,6} Objects: {1,6} Models: {2,6}",
                 *                                                map_triangles.GetNumberOfTriangles(),
                 *                                                obj_triangles.GetNumberOfTriangles(),
                 *                                                model_triangles.GetNumberOfTriangles()));
                 */
            }
            logger.WriteLine(" done");
            wdt.maptiles[chunk_x, chunk_y] = null; // clear it atain
                                                   //myChunk.triangles.ClearVertexMatrix(); // not needed anymore
                                                   //return myChunk;
        }
Beispiel #3
0
        private void GetChunkData(TriangleCollection triangles, int chunk_x, int chunk_y, SparseMatrix3D <WMO> instances)
        {
            if (chunk_x < 0)
            {
                return;
            }
            if (chunk_y < 0)
            {
                return;
            }
            if (chunk_x > 63)
            {
                return;
            }
            if (chunk_y > 63)
            {
                return;
            }

            /*
             * if (chunkCache[chunk_x, chunk_y] != null)
             * {
             *  chunkCache[chunk_x, chunk_y].LRU = NOW++;
             *  return chunkCache[chunk_x, chunk_y];
             * }
             * else
             * {
             *  EvictFromChunkCache();
             * }
             *
             *
             * float max_x = ChunkReader.ZEROPOINT - (float)(chunk_y) * ChunkReader.TILESIZE;
             * float max_y = ChunkReader.ZEROPOINT - (float)(chunk_x) * ChunkReader.TILESIZE;
             * float min_x = max_x - ChunkReader.TILESIZE;
             * float min_y = max_y - ChunkReader.TILESIZE;
             *
             *
             * ChunkData myChunk = new ChunkData();
             * myChunk.LRU = NOW++;
             * chunkCache[chunk_x, chunk_y] = myChunk;
             * chunkCacheItems++;
             *
             * TriangleCollection triangles = new TriangleCollection();
             * myChunk.triangles = triangles;
             * triangles.SetLimits(min_x, min_y, -1E30f, max_x, max_y, 1E30f);
             */

            //Console.WriteLine("x " + max_x + " y " + max_y);

            // Console.Write(String.Format(" Tile {0,2} {1,2}", chunk_x, chunk_y));
            //  Console.Write(" load");
            if (triangles == null)
            {
                return;
            }

            if (wdtf == null)
            {
                return;
            }
            if (wdt == null)
            {
                return;
            }
            wdtf.LoadMapTile(chunk_x, chunk_y);


            MapTile t = wdt.maptiles[chunk_x, chunk_y];

            if (t != null)
            {
                //Console.Write(" render");
                // Map tiles
                for (int ci = 0; ci < 16; ci++)
                {
                    for (int cj = 0; cj < 16; cj++)
                    {
                        MapChunk c = t.chunks[ci, cj];
                        if (c != null)
                        {
                            AddTriangles(triangles, c);
                        }
                    }
                }

                // World objects

                foreach (WMOInstance wi in t.wmois)
                {
                    if (wi != null && wi.wmo != null)
                    {
                        String fn   = wi.wmo.fileName;
                        int    last = fn.LastIndexOf('\\');
                        fn = fn.Substring(last + 1);
                        // Console.WriteLine("    wmo: " + fn + " at " + wi.pos);
                        if (fn != null)
                        {
                            WMO old = instances.Get((int)wi.pos.x, (int)wi.pos.y, (int)wi.pos.z);
                            if (old == wi.wmo)
                            {
                                //Console.WriteLine("Already got " + fn);
                            }
                            else
                            {
                                instances.Set((int)wi.pos.x, (int)wi.pos.y, (int)wi.pos.z, wi.wmo);
                                AddTriangles(triangles, wi);
                            }
                        }
                    }
                }

                foreach (ModelInstance mi in t.modelis)
                {
                    if (mi != null && mi.model != null)
                    {
                        String fn   = mi.model.fileName;
                        int    last = fn.LastIndexOf('\\');
                        // fn = fn.Substring(last + 1);
                        //Console.WriteLine("    wmi: " + fn + " at " + mi.pos);
                        AddTriangles(triangles, mi);

                        //Console.WriteLine("    model: " + fn);
                    }
                }



                Console.WriteLine("wee");

                /*Console.WriteLine(
                 *  String.Format(" Triangles - Map: {0,6} Objects: {1,6} Models: {2,6}",
                 *                map_triangles.GetNumberOfTriangles(),
                 *                obj_triangles.GetNumberOfTriangles(),
                 *                model_triangles.GetNumberOfTriangles()));
                 */
            }
            Console.WriteLine(" done");
            wdt.maptiles[chunk_x, chunk_y] = null; // clear it atain
            //myChunk.triangles.ClearVertexMatrix(); // not needed anymore
            //return myChunk;
        }