Skip to content

Commit

Permalink
[Server, World] Fix a few things
Browse files Browse the repository at this point in the history
- Fix sky in FPCam
- Fix ground wobbling in 3D cameras
- Fix logic for ensuring required objects are present.
  • Loading branch information
riperiperi committed Oct 31, 2019
1 parent 6ed79ea commit de61a31
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 23 deletions.
8 changes: 5 additions & 3 deletions TSOClient/FSO.Server/Servers/Lot/Domain/LotContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down
46 changes: 30 additions & 16 deletions TSOClient/tso.simantics/Utils/VMLotTerrainRestoreTools.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
}
}

Expand All @@ -715,31 +716,36 @@ 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);
}
}

/// <summary>
/// Positions the Landmark objects depending on the lot direction. (npc/car portals, bin, mailbox, phone)
/// </summary>
/// <param name="vm">The VM.</param>
public static void PositionLandmarkObjects(VM vm)
public static void PositionLandmarkObjects(VM vm, RestoreLotType type)
{
var arch = vm.Context.Architecture;
var lotSInfo = vm.TSOState.Size;
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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));

Expand All @@ -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
}
}
8 changes: 6 additions & 2 deletions TSOClient/tso.world/Components/SkyDomeComponent.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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 ??
Expand Down
4 changes: 3 additions & 1 deletion TSOClient/tso.world/Components/SubWorldComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,11 @@ public void SubDraw(GraphicsDevice gd, WorldState parentState, Action<Vector2> a

parentState.SilentLevel = oldLevel;

parentState.CenterTile = parentScroll;

if (parentState.CameraMode > CameraRenderMode._2D)
parentState.Cameras.ModelTranslation = Vector3.Zero;
else
parentState.CenterTile = parentScroll;
parentState.PrepareLighting();
}

Expand Down
4 changes: 3 additions & 1 deletion TSOClient/tso.world/WorldArchitecture.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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); });
}

Expand Down

0 comments on commit de61a31

Please sign in to comment.