diff --git a/TSOClient/FSO.Server/Servers/Lot/Domain/LotContainer.cs b/TSOClient/FSO.Server/Servers/Lot/Domain/LotContainer.cs index 7746dbf52..00bd09aac 100644 --- a/TSOClient/FSO.Server/Servers/Lot/Domain/LotContainer.cs +++ b/TSOClient/FSO.Server/Servers/Lot/Domain/LotContainer.cs @@ -679,8 +679,9 @@ public void ResetVM() Lot.TSOState.LotID = LotPersist.location; Lot.TSOState.SkillMode = LotPersist.skill_mode; Lot.TSOState.PropertyCategory = (byte)LotPersist.category; + var isCommunity = LotPersist.category == LotCategory.community; - if (LotPersist.category == LotCategory.community) + if (isCommunity) { var owner = LotPersist.owner_id ?? 0; if (Lot.TSOState.OwnerID != owner) @@ -726,8 +727,9 @@ public void ResetVM() ReturnInvalidObjects(); if (!JobLot) ReturnOOWObjects(); - if (isMoved || isNew) VMLotTerrainRestoreTools.RestoreTerrain(Lot); - VMLotTerrainRestoreTools.EnsureCoreObjects(Lot); + var restoreType = isCommunity ? RestoreLotType.Community : RestoreLotType.Normal; + if (isMoved || isNew) VMLotTerrainRestoreTools.RestoreTerrain(Lot, restoreType); + VMLotTerrainRestoreTools.EnsureCoreObjects(Lot, restoreType); if (isNew) VMLotTerrainRestoreTools.PopulateBlankTerrain(Lot); Lot.ForwardCommand(new VMNetSetTimeCmd() diff --git a/TSOClient/tso.simantics/Utils/VMLotTerrainRestoreTools.cs b/TSOClient/tso.simantics/Utils/VMLotTerrainRestoreTools.cs index 007127018..44728b813 100644 --- a/TSOClient/tso.simantics/Utils/VMLotTerrainRestoreTools.cs +++ b/TSOClient/tso.simantics/Utils/VMLotTerrainRestoreTools.cs @@ -438,12 +438,12 @@ public static void StampTerrainmap(VMArchitecture arch, byte[] tilemap, short x, } } - public static void RestoreTerrain(VM vm, bool withHeight = true) + public static void RestoreTerrain(VM vm, RestoreLotType type = RestoreLotType.Normal) { //take center of lotstate - RestoreTerrain(vm, vm.TSOState.Terrain.BlendN[1, 1], vm.TSOState.Terrain.Roads[1, 1]); + RestoreTerrain(vm, vm.TSOState.Terrain.BlendN[1, 1], vm.TSOState.Terrain.Roads[1, 1], type); - if (withHeight) RestoreHeight(vm, vm.TSOState.Terrain, 1, 1); + RestoreHeight(vm, vm.TSOState.Terrain, 1, 1); } public static int GetBaseLevel(VM vm, VMTSOSurroundingTerrain terrain, int x, int y) @@ -581,7 +581,7 @@ private static float Cubic(float v0, float v1, float v2, float v3, float fracy) */ } - public static void RestoreTerrain(VM vm, TerrainBlend blend, byte roads) + public static void RestoreTerrain(VM vm, TerrainBlend blend, byte roads, RestoreLotType type) { var arch = vm.Context.Architecture; arch.DisableClip = true; @@ -673,7 +673,7 @@ public static void RestoreTerrain(VM vm, TerrainBlend blend, byte roads) vm.TSOState.Size |= PickRoadDir(roads) << 16; } - PositionLandmarkObjects(vm); + PositionLandmarkObjects(vm, type); arch.SignalTerrainRedraw(); arch.DisableClip = false; @@ -697,9 +697,10 @@ private class GUIDToPosition public short X; public short Y; public int DirOff; //in 8th directions, like blueprint - public GUIDToPosition(uint guid, short x, short y, int dirOff) + public RestoreLotType Type; + public GUIDToPosition(uint guid, short x, short y, int dirOff, RestoreLotType type = RestoreLotType.Generic) { - GUID = guid; X = x; Y = y; DirOff = dirOff; + GUID = guid; X = x; Y = y; DirOff = dirOff; Type = type; } } @@ -715,23 +716,28 @@ public GUIDToPosition(uint guid, short x, short y, int dirOff) //center relative (vertical line above) new GUIDToPosition(0x39CCF441, -1, 0, 0), //mailbox (2tile) new GUIDToPosition(0xA4258067, 1, 1, 0), //bin - new GUIDToPosition(0x313D2F9A, 4, 1, 0), //phone - new GUIDToPosition(0x303CD603, 4, 1, 0), //phone (nhood) + new GUIDToPosition(0x313D2F9A, 4, 1, 0, RestoreLotType.Normal), //phone + new GUIDToPosition(0x303CD603, 4, 1, 0, RestoreLotType.Community), //phone (nhood) new GUIDToPosition(0x865A6812, 0, 3, 2), //car portal 1 new GUIDToPosition(0xD564C66B, -5, 3, 2), //car portal 2 }; - public static void EnsureCoreObjects(VM vm) + public static void EnsureCoreObjects(VM vm, RestoreLotType type) { + var del = MovePositions.Where(x => x.Type != RestoreLotType.Generic && x.Type != type).Select(x => EntityByGUID(vm, x.GUID)).Where(x => x != null).ToList(); + foreach (var ent in del) + { + ent.Delete(true, vm.Context); + } var fail = MovePositions.Where(x => { //find an object of this type var ent = EntityByGUID(vm, x.GUID); - return ent == null || ent.Position == LotTilePos.OUT_OF_WORLD; + return x.Type == type && (ent == null || ent.Position == LotTilePos.OUT_OF_WORLD); }); if (fail.Count() > 0) { - PositionLandmarkObjects(vm); + PositionLandmarkObjects(vm, type); } } @@ -739,7 +745,7 @@ public static void EnsureCoreObjects(VM vm) /// Positions the Landmark objects depending on the lot direction. (npc/car portals, bin, mailbox, phone) /// /// The VM. - public static void PositionLandmarkObjects(VM vm) + public static void PositionLandmarkObjects(VM vm, RestoreLotType type) { var arch = vm.Context.Architecture; var lotSInfo = vm.TSOState.Size; @@ -786,7 +792,7 @@ public static void PositionLandmarkObjects(VM vm) { var rpos = ctr + (pos.X * xperp) + (pos.Y * yperp); var ent = EntityByGUID(vm, pos.GUID); - if (ent == null) + if (type != RestoreLotType.Blank && ent == null && (pos.Type == type || pos.Type == RestoreLotType.Generic)) { ent = vm.Context.CreateObjectInstance(pos.GUID, LotTilePos.OUT_OF_WORLD, Direction.NORTH).BaseObject; } @@ -1027,7 +1033,7 @@ public static void RestoreSurroundings(VM vm, byte[][] hollowAdj) hollow.Deserialize(reader); } tempVM.HollowLoad(hollow); - RestoreTerrain(tempVM, terrain.BlendN[x, y], terrain.Roads[x, y]); + RestoreTerrain(tempVM, terrain.BlendN[x, y], terrain.Roads[x, y], RestoreLotType.Normal); if (hollow.Version < 19) height = RestoreHeight(tempVM, terrain, x, y); else @@ -1061,7 +1067,7 @@ public static void RestoreSurroundings(VM vm, byte[][] hollowAdj) blueprint.Terrain = terrainC; tempVM.Context.Architecture.Terrain.LowQualityGrassState = true; - RestoreTerrain(tempVM, terrain.BlendN[x, y], terrain.Roads[x, y]); + RestoreTerrain(tempVM, terrain.BlendN[x, y], terrain.Roads[x, y], RestoreLotType.Blank); height = RestoreHeight(tempVM, terrain, x, y); tempVM.Context.Blueprint.BaseAlt = (int)((baseHeight - height)); @@ -1083,4 +1089,12 @@ public static void RestoreSurroundings(VM vm, byte[][] hollowAdj) vm.Context.World.InitSubWorlds(); } } + + public enum RestoreLotType + { + Generic = -1, + Normal = 0, + Community = 1, + Blank = 2 + } } diff --git a/TSOClient/tso.world/Components/SkyDomeComponent.cs b/TSOClient/tso.world/Components/SkyDomeComponent.cs index b90bfe0cd..0ade83800 100644 --- a/TSOClient/tso.world/Components/SkyDomeComponent.cs +++ b/TSOClient/tso.world/Components/SkyDomeComponent.cs @@ -1,8 +1,10 @@ using FSO.Common; +using FSO.Common.Rendering.Framework.Camera; using FSO.Common.Utils; using FSO.Files; using FSO.LotView.Model; using FSO.LotView.Utils; +using FSO.LotView.Utils.Camera; using Microsoft.Xna.Framework; using Microsoft.Xna.Framework.Graphics; using System; @@ -26,9 +28,11 @@ public SkyDomeComponent(GraphicsDevice GD, Blueprint bp) : base(GD, (float)bp.Ou public void Draw(GraphicsDevice gd, WorldState state) { + ICamera active3D = (state.Cameras.ActiveCamera as CameraController3D)?.Camera ?? state.Camera3D; + ICamera allowSwitch = state.Cameras.TransitionWeights.Any(x => x.Camera is WorldCamera || x.IsLinear) ? active3D : state.Camera; Draw(gd, state.OutsideColor, - state.Camera3D.View, - state.Camera3D.Projection, //((state.Camera as WorldCamera3D)?.BaseProjection() ?? state.Camera.Projection), + state.Camera.View, + allowSwitch.Projection, //((state.Camera as WorldCamera3D)?.BaseProjection() ?? state.Camera.Projection), (float)BP.OutsideTime, BP.Weather, state.Light?.SunVector ?? diff --git a/TSOClient/tso.world/Components/SubWorldComponent.cs b/TSOClient/tso.world/Components/SubWorldComponent.cs index df2018d0d..67fbd3645 100644 --- a/TSOClient/tso.world/Components/SubWorldComponent.cs +++ b/TSOClient/tso.world/Components/SubWorldComponent.cs @@ -271,9 +271,11 @@ public void SubDraw(GraphicsDevice gd, WorldState parentState, Action a parentState.SilentLevel = oldLevel; - parentState.CenterTile = parentScroll; + if (parentState.CameraMode > CameraRenderMode._2D) parentState.Cameras.ModelTranslation = Vector3.Zero; + else + parentState.CenterTile = parentScroll; parentState.PrepareLighting(); } diff --git a/TSOClient/tso.world/WorldArchitecture.cs b/TSOClient/tso.world/WorldArchitecture.cs index 8a233d023..818afd3eb 100644 --- a/TSOClient/tso.world/WorldArchitecture.cs +++ b/TSOClient/tso.world/WorldArchitecture.cs @@ -114,11 +114,13 @@ public void Draw2D(GraphicsDevice gd, WorldState state) { var pxOffset = -state.WorldSpace.GetScreenOffset(); var changes = Blueprint.Changes; + state.PrepareCulling(pxOffset); if (changes.DrawImmediate) { + DrawSub(gd, state, pxOffset); DrawFloorBuf(gd, state); DrawWallBuf(gd, state, pxOffset); - DrawSub(gd, state, pxOffset); + //foreach (var sub in Blueprint.SubWorlds) sub.SubDraw(gd, state, (pxOffsetSub) => { sub.Architecture.StaticDraw(gd, state, pxOffsetSub); }); }