示例#1
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);
            }
        }