예제 #1
0
 public DungeonBuilder(string world, string meshDir)
 {
     Dungeon  = world;
     _meshDir = meshDir;
     Config   = RecastConfig.Dungeon;
     MapId    = PhaseHelper.GetMapIdByName(Dungeon);
 }
예제 #2
0
 public TileBuilder(string world, int x, int y)
 {
     World  = world;
     X      = x;
     Y      = y;
     Config = RecastConfig.Default;
     MapId  = PhaseHelper.GetMapIdByName(World);
 }
예제 #3
0
        public TileBuilder(string world, int x, int y)
        {
            World  = world;
            X      = x;
            Y      = y;
            Config = RecastConfig.Default;
            MapId  = PhaseHelper.GetMapIdByName(World);

            // Now create a global mutex
            if (_mutex == null)
            {
                string appGuid = ((GuidAttribute)Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(GuidAttribute), false).GetValue(0)).Value.ToString();
                string mutexId = string.Format("Global\\{{{0}}}", appGuid);
                _mutex = new Mutex(false, mutexId);
                MutexAccessRule allowEveryoneRule = new MutexAccessRule(new SecurityIdentifier(WellKnownSidType.WorldSid, null), MutexRights.FullControl, AccessControlType.Allow);
                MutexSecurity   securitySettings  = new MutexSecurity();
                securitySettings.AddAccessRule(allowEveryoneRule);
                _mutex.SetAccessControl(securitySettings);
            }
        }
예제 #4
0
        public void PrepareData(BaseLog log)
        {
            if (log == null)
            {
                throw new ArgumentNullException("log");
            }

            Log = log;
            Cache.Clear();

            Geometry = new Geometry {
                Transform = true
            };
            //List<ADT> adtList = new List<ADT>();

            bool hasHandle = false;

            try
            {
                try
                {
                    hasHandle = _mutex.WaitOne(Timeout.Infinite, false);
                    if (hasHandle == false)
                    {
                        throw new TimeoutException("Timeout waiting for exclusive access");
                    }
                }
                catch (AbandonedMutexException)
                {
                    // The mutex was abandoned in another process, it will still get aquired
                    hasHandle = true;
                }

                // Do the work which require this mutex locking (useless with CACS)
                //{
                ADT main = GetAdt(World, X, Y);
                Geometry.AddAdt(main);
                InsertAllGameobjectGeometry(X, Y, MapId);
                // Geometry.CreateDemoDump("X:\\Meshes\\" + MapId + "_" + X + "_" + Y + ".obj");
                //}

                if (Geometry.Vertices.Count == 0 && Geometry.Triangles.Count == 0)
                {
                    throw new InvalidOperationException("Can't build tile with empty geometry");
                }

                // again, we load everything - wasteful but who cares
                for (int ty = Y - 1; ty <= Y + 1; ty++)
                {
                    for (int tx = X - 1; tx <= X + 1; tx++)
                    {
                        // don't load main tile again
                        if (tx == X && ty == Y)
                        {
                            continue;
                        }

                        ADT adt = GetAdt(World, tx, ty);
                        if (adt.HasObjectData)
                        {
                            //Console.WriteLine("-> " + World + "_" + tx + "_" + ty);
                            Geometry.AddAdt(adt);
                            InsertAllGameobjectGeometry(tx, ty, MapId);
                        }
                        else
                        {
                            string parentMap = PhaseHelper.GetParentMap(World);
                            if (parentMap != string.Empty)
                            {
                                ADT adtParent = GetAdt(parentMap, tx, ty);
                                if (adtParent.HasObjectData)
                                {
                                    Console.WriteLine("-> " + parentMap + "_" + tx + "_" + ty);
                                    Geometry.AddAdt(adtParent);
                                    InsertAllGameobjectGeometry(tx, ty, PhaseHelper.GetMapIdByName(parentMap));
                                }
                            }
                        }
                    }
                }
            }
            finally
            {
                if (hasHandle)
                {
                    _mutex.ReleaseMutex();
                }
            }

            Context = new RecastContext();
            Context.SetContextHandler(Log);
        }
예제 #5
0
        static void Main(string[] args)
        {
            if (args.Length == 0)
            {
                Console.WriteLine("Please supply continent name");
                return;
            }

            var continent = args[0];
            var path      = @"C:\\Users\\Sebastian\\CactusWOW\\MeshReader\\meshReader\\meshBuilderGui\\bin\\Debug\\" + continent;

            if (!Directory.Exists(path))
            {
                Console.WriteLine("Can't find mesh directory: " + path);
                return;
            }

            Console.Write("Setting up data storage.. ");
            string floodDir = "C:\\Users\\Sebastian\\CactusWOW\\MeshReader\\meshReader\\meshBuilderGui\\bin\\Debug\\FloodFill\\";

            if (!Directory.Exists(floodDir))
            {
                Directory.CreateDirectory(floodDir);
            }
            floodDir += continent;
            if (Directory.Exists(floodDir))
            {
                Directory.Delete(floodDir, true);
            }
            Directory.CreateDirectory(floodDir);
            floodDir += "\\";
            Console.WriteLine("done");

            var files = Directory.GetFiles(path).Where(f => f.EndsWith(".tile"));

            Console.WriteLine("Total amount of tiles: " + files.Count());
            if (files.Count() > 4096)
            {
                Console.WriteLine("Too many tiles. Increase maxTiles.");
                return;
            }

            Console.WriteLine("Initializing mesh..");
            var mesh = new NavMesh();

            if ((mesh.Initialize(32768, 4096, Utility.Origin, Utility.TileSize, Utility.TileSize) & DetourStatus.Failure) != 0)
            {
                Console.WriteLine("Failed to initialize mesh.");
                return;
            }

            Console.WriteLine("Loading all tiles..");
            var tiles = new List <MeshTile>(files.Count());

            foreach (var file in files)
            {
                var      data = File.ReadAllBytes(file);
                MeshTile tile;
                if ((mesh.AddTile(data, out tile) & DetourStatus.Failure) != 0)
                {
                    Console.WriteLine("Failed to load tile: " + file);
                    return;
                }
                tiles.Add(tile);
            }

            Console.WriteLine("Initializing DBC backend...");
            MpqManager.InitializeDBC(@"L:\World of Warcraft 3.3.5a");

            Console.Write("Identifiying map id.. ");
            int mapId = PhaseHelper.GetMapIdByName(continent);

            if (mapId < 0)
            {
                Console.WriteLine("failed");
                return;
            }
            Console.WriteLine(mapId);
            Console.Write("Identifying source points.. ");
            var sourcePoints = new List <Vector3>(100);

            sourcePoints.AddRange(from record in TaxiHelper.TaxiNodesDBC.Records
                                  select new TaxiNode(record)
                                  into node where node.IsValid && node.MapId == mapId select node.Location.ToRecast());
            Console.WriteLine(sourcePoints.Count);

            Console.WriteLine("Initializing flood fill..");
            var floodFill = new FloodFill(mesh);

            Console.WriteLine("Flooding.. ");
            foreach (var source in sourcePoints)
            {
                floodFill.ExecuteFrom(source);
            }
            Console.WriteLine("Finished, visited " + floodFill.Marked + " polygons");

            Console.WriteLine("Rebuilding tiles...");
            var  config     = RecastConfig.Default;
            long sizeBefore = 0;
            long sizeAfter  = 0;

            foreach (var tile in tiles)
            {
                sizeBefore += tile.DataSize;
                byte[] rebuiltData;

                if (!tile.Rebuild(floodFill.Visited, floodFill.VisitedMask, config.CellHeight, config.MaxVertsPerPoly, out rebuiltData))
                {
                    Console.WriteLine("Failed to rebuild tile " + tile.Header.X + " " + tile.Header.Y);
                    continue;
                }

                if (rebuiltData == null)
                {
                    Console.WriteLine("Tile " + tile.Header.X + " " + tile.Header.Y + " ceases to exist.");
                    continue;
                }

                sizeAfter += rebuiltData.Length;
                File.WriteAllBytes(floodDir + continent + "_" + tile.Header.X + "_" + tile.Header.Y + ".tile", rebuiltData);
            }

            Console.WriteLine("All done, size before: " + (sizeBefore / 1024 / 1024) + "MiB after: " + (sizeAfter / 1024 / 1024) + "MiB");
            Console.ReadKey(true);
        }