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; }
public EnvCell add_visible_cell(uint cellID) { var envCell = DBObj.GetEnvCell(cellID); VisibleCells.Add(cellID, envCell); return(envCell); }
/// <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); } }
public EnvCell add_visible_cell(uint cellID) { var envCell = (EnvCell)DBObj.Get(new QualifiedDataID(3, cellID)); VisibleCells.Add(cellID, envCell); return(envCell); }
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]); } }
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); } }
/// <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); } }
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); }
/// <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); }
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); } }
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(); }
/// <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); }
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(); }
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)); }
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)); } }
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); }
/// <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); }
/// <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); }
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); }
/// <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); } }