Ejemplo n.º 1
0
        /// <summary>
        /// Loads the backing store landblock structure<para />
        /// This function is thread safe
        /// </summary>
        /// <param name="blockCellID">Any landblock + cell ID within the landblock</param>
        public static Landblock get_landblock(uint blockCellID)
        {
            // client implementation

            /*if (Landblocks == null || Landblocks.Count == 0)
             *  return null;
             *
             * if (!LandDefs.inbound_valid_cellid(cellID) || cellID >= 0x100)
             *  return null;
             *
             * var local_lcoord = LandDefs.blockid_to_lcoord(LoadedCellID);
             * var global_lcoord = LandDefs.gid_to_lcoord(cellID);
             *
             * var xDiff = ((int)global_lcoord.Value.X + 8 * MidRadius - (int)local_lcoord.Value.X) / 8;
             * var yDiff = ((int)global_lcoord.Value.Y + 8 * MidRadius - (int)local_lcoord.Value.Y) / 8;
             *
             * if (xDiff < 0 || yDiff < 0 || xDiff < MidWidth || yDiff < MidWidth)
             *  return null;
             *
             * return Landblocks[yDiff + xDiff * MidWidth];*/

            var landblockID = blockCellID | 0xFFFF;

            // check if landblock is already cached
            if (Landblocks.TryGetValue(landblockID, out var landblock))
            {
                return(landblock);
            }

            lock (landblockMutex)
            {
                // check if landblock is already cached, this time under the lock.
                if (Landblocks.TryGetValue(landblockID, out landblock))
                {
                    return(landblock);
                }

                // if not, load into cache
                landblock = new Landblock(DBObj.GetCellLandblock(landblockID));
                if (Landblocks.TryAdd(landblockID, landblock))
                {
                    landblock.PostInit();

                    // ensure landblock manager loaded
                    var lbid = new LandblockId(landblockID);
                    if (!LandblockManager.IsLoaded(lbid))
                    {
                        // this can happen from encounter spawns sliding down walkable slopes...
                        //log.Debug($"{landblockID:X8} requested from LScape, but not loaded from LandblockManager, adding");
                        LandblockManager.GetLandblock(lbid, false, false);
                    }
                }
                else
                {
                    Landblocks.TryGetValue(landblockID, out landblock);
                }

                return(landblock);
            }
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Loads the backing store landblock structure<para />
        /// This function is thread safe
        /// </summary>
        /// <param name="blockCellID">Any landblock + cell ID within the landblock</param>
        public static Landblock get_landblock(uint blockCellID)
        {
            var landblockID = blockCellID | 0xFFFF;

            if (PhysicsEngine.Instance.Server)
            {
                var lbid         = new LandblockId(landblockID);
                var lbmLandblock = LandblockManager.GetLandblock(lbid, false, false);

                return(lbmLandblock.PhysicsLandblock);
            }

            // client implementation

            /*if (Landblocks == null || Landblocks.Count == 0)
             *  return null;
             *
             * if (!LandDefs.inbound_valid_cellid(cellID) || cellID >= 0x100)
             *  return null;
             *
             * var local_lcoord = LandDefs.blockid_to_lcoord(LoadedCellID);
             * var global_lcoord = LandDefs.gid_to_lcoord(cellID);
             *
             * var xDiff = ((int)global_lcoord.Value.X + 8 * MidRadius - (int)local_lcoord.Value.X) / 8;
             * var yDiff = ((int)global_lcoord.Value.Y + 8 * MidRadius - (int)local_lcoord.Value.Y) / 8;
             *
             * if (xDiff < 0 || yDiff < 0 || xDiff < MidWidth || yDiff < MidWidth)
             *  return null;
             *
             * return Landblocks[yDiff + xDiff * MidWidth];*/

            // check if landblock is already cached
            if (Landblocks.TryGetValue(landblockID, out var landblock))
            {
                return(landblock);
            }

            lock (landblockMutex)
            {
                // check if landblock is already cached, this time under the lock.
                if (Landblocks.TryGetValue(landblockID, out landblock))
                {
                    return(landblock);
                }

                // if not, load into cache
                landblock = new Landblock(DBObj.GetCellLandblock(landblockID));
                if (Landblocks.TryAdd(landblockID, landblock))
                {
                    landblock.PostInit();
                }
                else
                {
                    Landblocks.TryGetValue(landblockID, out landblock);
                }

                return(landblock);
            }
        }
Ejemplo n.º 3
0
        /// <summary>
        /// Loads the backing store landblock structure
        /// </summary>
        /// <param name="blockCellID">Any landblock + cell ID within the landblock</param>
        public static Landblock get_landblock(uint blockCellID)
        {
            // client implementation

            /*if (Landblocks == null || Landblocks.Count == 0)
             *  return null;
             *
             * if (!LandDefs.inbound_valid_cellid(cellID) || cellID >= 0x100)
             *  return null;
             *
             * var local_lcoord = LandDefs.blockid_to_lcoord(LoadedCellID);
             * var global_lcoord = LandDefs.gid_to_lcoord(cellID);
             *
             * var xDiff = ((int)global_lcoord.Value.X + 8 * MidRadius - (int)local_lcoord.Value.X) / 8;
             * var yDiff = ((int)global_lcoord.Value.Y + 8 * MidRadius - (int)local_lcoord.Value.Y) / 8;
             *
             * if (xDiff < 0 || yDiff < 0 || xDiff < MidWidth || yDiff < MidWidth)
             *  return null;
             *
             * return Landblocks[yDiff + xDiff * MidWidth];*/

            var landblockID = blockCellID | 0xFFFF;

            // check if landblock is already cached
            if (Landblocks.TryGetValue(landblockID, out var landblock))
            {
                return(landblock);
            }

            // if not, load into cache
            landblock = new Landblock(DBObj.GetCellLandblock(landblockID));
            if (Landblocks.TryAdd(landblockID, landblock))
            {
                landblock.PostInit();
            }
            else
            {
                Landblocks.TryGetValue(landblockID, out landblock);
            }

            return(landblock);
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Loads the backing store landblock structure<para />
        /// This function is thread safe
        /// </summary>
        /// <param name="iBlockCellID">Any instance + landblock + cell ID within the landblock</param>
        public static Landblock get_landblock(ulong iBlockCellID)
        {
            /*if ((iBlockCellID | 0xFFFF) == 0x1D9FFFF)
             * {
             *  Console.WriteLine(System.Environment.StackTrace);
             *  var debug = true;
             * }*/

            if (PhysicsEngine.Instance.Server)
            {
                var lbmLandblock = LandblockManager.GetLandblock(iBlockCellID, false, false);

                return(lbmLandblock.PhysicsLandblock);
            }

            // client implementation

            /*if (Landblocks == null || Landblocks.Count == 0)
             *  return null;
             *
             * if (!LandDefs.inbound_valid_cellid(cellID) || cellID >= 0x100)
             *  return null;
             *
             * var local_lcoord = LandDefs.blockid_to_lcoord(LoadedCellID);
             * var global_lcoord = LandDefs.gid_to_lcoord(cellID);
             *
             * var xDiff = ((int)global_lcoord.Value.X + 8 * MidRadius - (int)local_lcoord.Value.X) / 8;
             * var yDiff = ((int)global_lcoord.Value.Y + 8 * MidRadius - (int)local_lcoord.Value.Y) / 8;
             *
             * if (xDiff < 0 || yDiff < 0 || xDiff < MidWidth || yDiff < MidWidth)
             *  return null;
             *
             * return Landblocks[yDiff + xDiff * MidWidth];*/

            var iLandblockID = iBlockCellID | 0xFFFF;

            // check if landblock is already cached
            if (Landblocks.TryGetValue(iLandblockID, out var landblock))
            {
                return(landblock);
            }

            lock (landblockMutex)
            {
                // check if landblock is already cached, this time under the lock.
                if (Landblocks.TryGetValue(iLandblockID, out landblock))
                {
                    return(landblock);
                }

                // if not, load into cache
                var instance = BlockCell.GetInstance(iLandblockID);

                landblock = new Landblock(DBObj.GetCellLandblock((uint)iLandblockID), instance);
                if (Landblocks.TryAdd(iLandblockID, landblock))
                {
                    landblock.PostInit();
                }
                else
                {
                    Landblocks.TryGetValue(iLandblockID, out landblock);
                }

                return(landblock);
            }
        }