예제 #1
0
        public EnvCell(DatLoader.FileTypes.EnvCell envCell) : base()
        {
            _envCell = envCell;

            Flags              = envCell.Flags;
            ID                 = envCell.Id;
            ShadowObjectIDs    = envCell.Surfaces;
            Pos                = new Position(ID, new AFrame(envCell.Position));
            Portals            = envCell.CellPortals;
            NumPortals         = Portals.Count;
            StaticObjectIDs    = new List <uint>();
            StaticObjectFrames = new List <AFrame>();
            NumStaticObjects   = envCell.StaticObjects.Count;
            foreach (var staticObj in envCell.StaticObjects)
            {
                StaticObjectIDs.Add(staticObj.Id);
                StaticObjectFrames.Add(new AFrame(staticObj.Frame));
            }
            NumStabs       = StaticObjectIDs.Count;
            VisibleCellIDs = envCell.VisibleCells;
            RestrictionObj = envCell.RestrictionObj;
            SeenOutside    = envCell.SeenOutside;

            EnvironmentID   = envCell.EnvironmentId;
            Environment     = DBObj.GetEnvironment(EnvironmentID);
            CellStructureID = envCell.CellStructure;    // environment can contain multiple?
            if (Environment.Cells != null && Environment.Cells.ContainsKey(CellStructureID))
            {
                CellStructure = new CellStruct(Environment.Cells[CellStructureID]);
            }

            NumSurfaces = envCell.Surfaces.Count;
        }
예제 #2
0
파일: EnvCell.cs 프로젝트: jacobtipp/trACE
        public EnvCell add_visible_cell(uint cellID)
        {
            var envCell = DBObj.GetEnvCell(cellID);

            VisibleCells.Add(cellID, envCell);
            return(envCell);
        }
예제 #3
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);
            }
        }
예제 #4
0
        public EnvCell add_visible_cell(uint cellID)
        {
            var envCell = (EnvCell)DBObj.Get(new QualifiedDataID(3, cellID));

            VisibleCells.Add(cellID, envCell);
            return(envCell);
        }
예제 #5
0
        public EnvCell(DatLoader.FileTypes.EnvCell envCell) : base()
        {
            Bitfield           = envCell.Bitfield;
            ID                 = envCell.Id;
            ShadowObjectIDs    = envCell.Shadows;
            Pos                = new Position(ID, new AFrame(envCell.Position));
            Portals            = envCell.CellPortals;
            NumPortals         = Portals.Count;
            StaticObjectIDs    = new List <uint>();
            StaticObjectFrames = new List <AFrame>();
            foreach (var staticObj in envCell.StaticObjects)
            {
                StaticObjectIDs.Add(staticObj.Id);
                StaticObjectFrames.Add(new AFrame(staticObj.Frame));
            }
            NumStabs       = StaticObjectIDs.Count;
            VisibleCellIDs = envCell.VisibleCells;
            RestrictionObj = envCell.RestrictionObj;
            SeenOutside    = envCell.SeenOutside;

            EnvironmentID   = envCell.EnvironmentId;
            Environment     = (DatLoader.FileTypes.Environment)DBObj.Get(new QualifiedDataID(16, EnvironmentID));
            CellStructureID = envCell.CellStructure;
            if (Environment.Cells != null && Environment.Cells.ContainsKey(CellStructureID))
            {
                CellStructure = new CellStruct(Environment.Cells[CellStructureID]);
            }
        }
예제 #6
0
파일: TexMerge.cs 프로젝트: jacobtipp/trACE
        public bool CopyAndTile(byte[] data, uint texSize, TerrainTex terrainTex)
        {
            var baseTexture = terrainTex.BaseTexture;

            if (baseTexture != null)
            {
                ImgTex.CopyCSI(data, texSize, texSize, baseTexture, terrainTex.TexTiling);
                return(true);
            }

            if (terrainTex.TexGID != 0) // stru_841760
            {
                var qdid = new QualifiedDataID(11, terrainTex.TexGID);

                var surfaceTexture = DBObj.GetSurfaceTexture(terrainTex.TexGID);
                terrainTex.BaseTexture = new ImgTex(surfaceTexture);
            }
            baseTexture = terrainTex.BaseTexture;

            if (baseTexture != null)
            {
                ImgTex.CopyCSI(data, texSize, texSize, baseTexture, terrainTex.TexTiling);
                return(true);
            }
            else
            {
                ImgTex.CopyCSI(data, texSize, texSize, null, 1);
                return(false);
            }
        }
예제 #7
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);
            }
        }
예제 #8
0
파일: TexMerge.cs 프로젝트: jacobtipp/trACE
        public TerrainAlphaMap FindTerrainAlpha(uint pcode, uint tcode, out LandDefs.Rotation rot, out int alphaIdx)
        {
            List <TerrainAlphaMap> terrainMaps = null;
            var baseIdx = 0;

            // corner tcodes - sw / se / ne / nw
            if (tcode != 1 && tcode != 2 && tcode != 4 && tcode != 8)
            {
                baseIdx     = 4;
                terrainMaps = SideTerrainMaps;   // common tcode: 9
            }
            else
            {
                terrainMaps = CornerTerrainMaps; // common tcode: 8
            }
            var numTerrains = terrainMaps.Count;

            var prng = (int)Math.Floor((1379576222 * pcode - 1372186442) * 2.3283064e-10 * numTerrains);

            if (prng >= numTerrains)
            {
                prng = 0;
            }

            var alpha = terrainMaps[prng];

            alphaIdx = baseIdx + prng;

            rot = LandDefs.Rotation.Rot0;

            var i         = 0;
            var alphaCode = alpha.TCode;

            while (alphaCode != tcode)
            {
                // corners: 8 -> 1 -> 2 -> 4
                // sides: 9 -> 3 -> 6 -> 12
                // west / south / east / north?
                alphaCode *= 2;
                if (alphaCode >= 16)
                {
                    alphaCode -= 15;
                }
                if (++i >= 4)
                {
                    return(null);
                }
            }
            rot = (LandDefs.Rotation)i;

            if (alpha.Texture == null && alpha.TexGID != 0)
            {
                var qdid = new QualifiedDataID(11, alpha.TexGID);
                alpha.Texture = new ImgTex(DBObj.GetSurfaceTexture(alpha.TexGID));
            }
            return(alpha);
        }
예제 #9
0
        /// <summary>s
        /// Gets the landcell from a landblock. If the cell is an indoor cell and hasn't been loaded, it will be loaded.<para />
        /// This function is thread safe
        /// </summary>
        public static ObjCell get_landcell(ulong iBlockCellID)
        {
            /*if ((iBlockCellID | 0xFFFF) == 0x1D9FFFF)
             * {
             *  Console.WriteLine(System.Environment.StackTrace);
             *  var debug = true;
             * }*/

            //Console.WriteLine($"get_landcell({blockCellID:X8}");

            var landblock = get_landblock(iBlockCellID);

            if (landblock == null)
            {
                return(null);
            }

            var     cellID = iBlockCellID & 0xFFFF;
            ObjCell cell   = null;

            // outdoor cells
            if (cellID < 0x100)
            {
                var lcoord = LandDefs.gid_to_lcoord((uint)iBlockCellID, false);
                if (lcoord == null)
                {
                    return(null);
                }
                var landCellIdx = ((int)lcoord.Value.Y % 8) + ((int)lcoord.Value.X % 8) * landblock.SideCellCount;
                landblock.LandCells.TryGetValue(landCellIdx, out cell);
            }
            // indoor cells
            else
            {
                if (landblock.LandCells.TryGetValue((int)cellID, out cell))
                {
                    return(cell);
                }

                lock (landblock.LandCellMutex)
                {
                    if (landblock.LandCells.TryGetValue((int)cellID, out cell))
                    {
                        return(cell);
                    }

                    cell = DBObj.GetEnvCell((uint)iBlockCellID);
                    cell.CurLandblock = landblock;

                    landblock.LandCells.TryAdd((int)cellID, cell);
                    var envCell = (EnvCell)cell;
                    envCell.PostInit();
                }
            }
            return(cell);
        }
예제 #10
0
파일: LScape.cs 프로젝트: PyrealMote/ACE
        public static Landblock get_all(uint landblockID)
        {
            var landblock = (DatLoader.FileTypes.CellLandblock)DBObj.Get(new QualifiedDataID(1, landblockID));

            if (landblock != null)
            {
                return(new Landblock(landblock));
            }
            else
            {
                return(null);
            }
        }
예제 #11
0
파일: Landblock.cs 프로젝트: PyrealMote/ACE
        public Landblock(CellLandblock landblock)
            : base(landblock)
        {
            Init();

            ID = landblock.Id;
            BlockInfoExists = landblock.HasObjects;
            if (BlockInfoExists)
            {
                Info = (LandblockInfo)DBObj.Get(new QualifiedDataID(2, ID - 1));
            }
            BlockCoord = LandDefs.blockid_to_lcoord(landblock.Id).Value;
            _landblock = landblock;
            get_land_limits();
        }
예제 #12
0
        /// <summary>
        /// Gets the landcell from a landblock. If the cell is an indoor cell and hasn't been loaded, it will be loaded.<para />
        /// This function is thread safe
        /// </summary>
        public static ObjCell get_landcell(uint blockCellID)
        {
            //Console.WriteLine($"get_landcell({blockCellID:X8}");

            var landblock = get_landblock(blockCellID);

            if (landblock == null)
            {
                return(null);
            }

            var     cellID = blockCellID & 0xFFFF;
            ObjCell cell   = null;

            // outdoor cells
            if (cellID < 0x100)
            {
                var lcoord = LandDefs.gid_to_lcoord(blockCellID, false);
                if (lcoord == null)
                {
                    return(null);
                }
                var landCellIdx = ((int)lcoord.Value.Y % 8) + ((int)lcoord.Value.X % 8) * landblock.SideCellCount;
                landblock.LandCells.TryGetValue(landCellIdx, out cell);
            }
            // indoor cells
            else
            {
                if (landblock.LandCells.TryGetValue((int)cellID, out cell))
                {
                    return(cell);
                }

                lock (landblock.LandCellMutex)
                {
                    if (landblock.LandCells.TryGetValue((int)cellID, out cell))
                    {
                        return(cell);
                    }

                    cell = DBObj.GetEnvCell(blockCellID);
                    landblock.LandCells.TryAdd((int)cellID, cell);
                    var envCell = (EnvCell)cell;
                    envCell.PostInit();
                }
            }
            return(cell);
        }
예제 #13
0
        public Landblock(CellLandblock landblock)
            : base(landblock)
        {
            Init();

            ID = landblock.Id;
            //Console.WriteLine("Loading landblock " + ID.ToString("X8"));
            BlockInfoExists = landblock.HasObjects;
            if (BlockInfoExists)
            {
                Info = DBObj.GetLandblockInfo(ID - 1);
            }
            BlockCoord = LandDefs.blockid_to_lcoord(landblock.Id).Value;
            _landblock = landblock;
            get_land_limits();
        }
예제 #14
0
        public static ObjCell Get(uint cellID)
        {
            if (cellID == 0)
            {
                return(null);
            }

            var objCell = new ObjCell(cellID);

            if (cellID >= 0x100)
            {
                return(DBObj.GetEnvCell(cellID));
            }

            return(LandCell.Get(cellID));
        }
예제 #15
0
파일: ObjCell.cs 프로젝트: zarlant/ACE
        public static ObjCell Get(uint cellID)
        {
            if (cellID == 0)
            {
                return(null);
            }

            var objCell = new ObjCell(cellID);

            if (cellID >= 0x100)
            {
                return((EnvCell)DBObj.Get(new QualifiedDataID(3, cellID)));
            }
            else
            {
                return(LandCell.Get(cellID));
            }
        }
예제 #16
0
파일: TexMerge.cs 프로젝트: jacobtipp/trACE
        public RoadAlphaMap FindRoadAlpha(uint pcode, uint rcode, out LandDefs.Rotation rot, out int alphaIdx)
        {
            rot      = LandDefs.Rotation.Rot0;
            alphaIdx = -1;

            var numRoadMaps = RoadMaps.Count;

            if (numRoadMaps == 0)
            {
                return(null);
            }

            var prng = (int)Math.Floor((1379576222 * pcode - 1372186442) * 2.3283064e-10 * numRoadMaps);

            for (var i = 0; i < numRoadMaps; i++)
            {
                var idx   = (i + prng) % numRoadMaps;
                var alpha = RoadMaps[idx];
                rot = LandDefs.Rotation.Rot0;
                var alphaCode = alpha.RCode;
                alphaIdx = 5 + idx;

                for (var j = 0; j < 4; j++)
                {
                    if (alphaCode == rcode)
                    {
                        rot = (LandDefs.Rotation)j;
                        if (alpha.Texture == null && alpha.RoadTexGID != 0)
                        {
                            alpha.Texture = new ImgTex(DBObj.GetSurfaceTexture(alpha.RoadTexGID));
                        }

                        return(alpha);
                    }
                    alphaCode *= 2;
                    if (alphaCode >= 16)
                    {
                        alphaCode -= 15;
                    }
                }
            }
            alphaIdx = -1;
            return(null);
        }
예제 #17
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);
        }
예제 #18
0
        /// <summary>
        /// Loads the backing store landblock structure
        /// </summary>
        /// <param name="cellID">Any cellID within the landblock</param>
        public static Landblock get_landblock(uint cellID)
        {
            // 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 = cellID | 0xFFFF;

            // check if landblock is already cached
            Landblock landblock = null;

            Landblocks.TryGetValue(landblockID, out landblock);
            if (landblock != null)
            {
                return(landblock);
            }

            // if not, load into cache
            landblock = new Landblock((DatLoader.FileTypes.CellLandblock)DBObj.Get(new QualifiedDataID(1, landblockID)));
            Landblocks.Add(landblockID, landblock);
            return(landblock);
        }
예제 #19
0
        public static ObjCell get_landcell(uint blockCellID)
        {
            var landblock = get_landblock(blockCellID);

            if (landblock == null)
            {
                return(null);
            }

            var     cellID = blockCellID & 0xFFFF;
            ObjCell cell   = null;

            // outdoor cells
            if (cellID < 0x100)
            {
                var lcoord = LandDefs.gid_to_lcoord(blockCellID, false);
                if (lcoord == null)
                {
                    return(null);
                }
                var landCellIdx = ((int)lcoord.Value.Y % 8) + ((int)lcoord.Value.X % 8) * landblock.SideCellCount;
                landblock.LandCells.TryGetValue(landCellIdx, out cell);
            }
            // indoor cells
            else
            {
                landblock.LandCells.TryGetValue((int)cellID, out cell);
                if (cell != null)
                {
                    return(cell);
                }
                cell = (EnvCell)DBObj.Get(new QualifiedDataID(3, blockCellID));
                landblock.LandCells.Add((int)cellID, cell);
                ((EnvCell)cell).build_visible_cells();
            }
            return(cell);
        }
예제 #20
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);
            }
        }