Skip to content

Commit

Permalink
Redraw 2D when unimportant lighting updates happen
Browse files Browse the repository at this point in the history
  • Loading branch information
riperiperi committed Nov 30, 2023
1 parent 2108284 commit 11a274a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 7 deletions.
21 changes: 15 additions & 6 deletions TSOClient/tso.world/LMap/LMapBatch.cs
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,13 @@ public void InvalidateRoom(ushort room, bool important)
AddDirtyRoom(room, important);
}

public void ParseInvalidated(sbyte floorLimit, WorldState state)
/// <summary>
/// Redraw any rooms flagged as dirty.
/// </summary>
/// <param name="floorLimit">Floor to render lighting up to</param>
/// <param name="state">World state</param>
/// <returns>True if there are still rooms in the unimportant lighting queue</returns>
public bool ParseInvalidated(sbyte floorLimit, WorldState state)
{
GD.BlendState = BlendState.AlphaBlend;
SetMapLayout(3, 2);
Expand All @@ -270,7 +276,7 @@ public void ParseInvalidated(sbyte floorLimit, WorldState state)
RedrawFloor = 6;
}

if (DirtyRooms.Count == 0) return;
if (DirtyRooms.Count == 0) return false;

//initialize lighteffect with default params
sbyte floor = 0;
Expand All @@ -285,17 +291,18 @@ public void ParseInvalidated(sbyte floorLimit, WorldState state)

foreach (var rm in ordered)
{
if (unimportantRoomsProcessed >= rm.Priority)
var room = rooms[rm.RoomID];
if (room.WallLines == null || room.Floor > floorLimit)
{
DirtyRooms.Remove(rm);
continue;
}

var room = rooms[rm.RoomID];
if (room.WallLines == null || room.Floor > floorLimit)
if (unimportantRoomsProcessed >= rm.Priority)
{
DirtyRooms.Remove(rm);
continue;
}

if (room.Floor != floor)
{
floor = room.Floor;
Expand All @@ -313,6 +320,8 @@ public void ParseInvalidated(sbyte floorLimit, WorldState state)
}

GD.SetRenderTarget(null);

return DirtyRooms.Count > 0;
}

public void InvalidateAll()
Expand Down
11 changes: 10 additions & 1 deletion TSOClient/tso.world/Model/BlueprintChanges.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ public void PreDraw(GraphicsDevice gd, WorldState state)
DrawImmediate = true;
}

if ((Dirty & BlueprintGlobalChanges.LIGHTING_UNIMPORTANT) > 0)
{
StaticSurfaceDirty = true;
}

if ((Dirty & BlueprintGlobalChanges.LIGHTING_ANY) > 0)
{
UpdateColor = true;
Expand Down Expand Up @@ -180,7 +185,10 @@ public void PreDraw(GraphicsDevice gd, WorldState state)
}
Dirty = 0;

state.Light?.ParseInvalidated((sbyte)(state.Level + ((state.DrawRoofs) ? 1 : 0)), state);
if (state.Light?.ParseInvalidated((sbyte)(state.Level + ((state.DrawRoofs) ? 1 : 0)), state) == true)
{
Dirty |= BlueprintGlobalChanges.LIGHTING_UNIMPORTANT;
}

//for moved objects, regenerate depth and move them to dynamic if they aren't already there.
foreach (var obj in ObjectMoved)
Expand Down Expand Up @@ -249,6 +257,7 @@ public enum BlueprintGlobalChanges : int
WALL_CHANGED = 1 << 10, //global invalidation of scroll buffer, but more specific invalidation for regions
WALL_CUT_CHANGED = 1 << 11, //global invalidation of scroll buffer, but more specific invalidation for regions
ROOM_CHANGED = 1 << 12,
LIGHTING_UNIMPORTANT = 1 << 13, //unimportant lights still need to be updated

VIEW_CHANGE_2D = ROTATE | ZOOM | LEVEL_CHANGED, //all of these invalidate the scroll buffers.
ARCH_CHANGED = WALL_CHANGED | FLOOR_CHANGED | ROOM_CHANGED,
Expand Down

0 comments on commit 11a274a

Please sign in to comment.