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;
        }
Example #2
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;
        }