Skip to content

Commit

Permalink
Refactor internal room collections (LostArtefacts#635)
Browse files Browse the repository at this point in the history
  • Loading branch information
lahm86 authored Apr 29, 2024
1 parent e334bef commit c5ac7bf
Show file tree
Hide file tree
Showing 62 changed files with 860 additions and 1,881 deletions.
Binary file modified Deps/TRGE.Coord.dll
Binary file not shown.
33 changes: 9 additions & 24 deletions TREnvironmentEditor/Model/BaseEMFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,53 +49,38 @@ public static List<TRVertex> GetTileVertices(short x, short y, short z, bool asC

public static int CreateRoomVertex(TR1Room room, TRVertex vert, short lighting = 6574)
{
TR1RoomVertex v = new()
room.RoomData.Vertices.Add(new()
{
Lighting = lighting,
Vertex = vert
};

List<TR1RoomVertex> verts = room.RoomData.Vertices.ToList();
verts.Add(v);
room.RoomData.Vertices = verts.ToArray();
room.RoomData.NumVertices++;
return verts.Count - 1;
});
return room.RoomData.Vertices.Count - 1;
}

public static int CreateRoomVertex(TR2Room room, TRVertex vert, short lighting = 6574, short lighting2 = 6574)
{
TR2RoomVertex v = new()
room.RoomData.Vertices.Add(new()
{
Attributes = 32784, // This stops it shimmering if viewed from underwater, should be configurable
Lighting = lighting,
Lighting2 = lighting2,
Vertex = vert
};

List<TR2RoomVertex> verts = room.RoomData.Vertices.ToList();
verts.Add(v);
room.RoomData.Vertices = verts.ToArray();
room.RoomData.NumVertices++;
return verts.Count - 1;
});
return room.RoomData.Vertices.Count - 1;
}

public static int CreateRoomVertex(TR3Room room, TRVertex vert, short lighting = 6574, ushort colour = 6574, bool useCaustics = false, bool useWaveMovement = false)
{
TR3RoomVertex v = new()
room.RoomData.Vertices.Add(new()
{
Attributes = 32784,
Lighting = lighting,
Colour = colour,
UseCaustics = useCaustics,
UseWaveMovement = useWaveMovement,
Vertex = vert
};

List<TR3RoomVertex> verts = room.RoomData.Vertices.ToList();
verts.Add(v);
room.RoomData.Vertices = verts.ToArray();
room.RoomData.NumVertices++;
return verts.Count - 1;
});
return room.RoomData.Vertices.Count - 1;
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ protected override bool Evaluate(TR2Level level)
{
EMLevelData data = EMLevelData.GetData(level);
TR2Room room = level.Rooms[data.ConvertRoom(Location.Room)];
return room.SectorList[GetSectorIndex(room.Info, Location, room.NumZSectors)].IsWall;
return room.Sectors[GetSectorIndex(room.Info, Location, room.NumZSectors)].IsWall;
}

protected override bool Evaluate(TR3Level level)
Expand Down
12 changes: 3 additions & 9 deletions TREnvironmentEditor/Model/Types/Mirroring/EMMirrorFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,9 +123,7 @@ private static void MirrorFloorData(TR1Level level)

foreach (TR1Room room in level.Rooms)
{
List<TRRoomSector> sectors = room.Sectors.ToList();
MirrorSectors(sectors, room.NumXSectors, room.NumZSectors, floorData);
room.Sectors = sectors.ToArray();
MirrorSectors(room.Sectors, room.NumXSectors, room.NumZSectors, floorData);
}

floorData.WriteToLevel(level);
Expand All @@ -138,9 +136,7 @@ private static void MirrorFloorData(TR2Level level)

foreach (TR2Room room in level.Rooms)
{
List<TRRoomSector> sectors = room.SectorList.ToList();
MirrorSectors(sectors, room.NumXSectors, room.NumZSectors, floorData);
room.SectorList = sectors.ToArray();
MirrorSectors(room.Sectors, room.NumXSectors, room.NumZSectors, floorData);
}

floorData.WriteToLevel(level);
Expand All @@ -153,9 +149,7 @@ private static void MirrorFloorData(TR3Level level)

foreach (TR3Room room in level.Rooms)
{
List<TRRoomSector> sectors = room.Sectors.ToList();
MirrorSectors(sectors, room.NumXSectors, room.NumZSectors, floorData);
room.Sectors = sectors.ToArray();
MirrorSectors(room.Sectors, room.NumXSectors, room.NumZSectors, floorData);
}

floorData.WriteToLevel(level);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@ public override void ApplyToLevel(TR2Level level)
TR2Room room1 = level.Rooms[Location1.Room];
TR2Room room2 = level.Rooms[Location2.Room];

TRRoomSector sector1 = room1.SectorList[GetSectorIndex(room1.Info, Location1, room1.NumZSectors)];
TRRoomSector sector2 = room2.SectorList[GetSectorIndex(room2.Info, Location2, room2.NumZSectors)];
TRRoomSector sector1 = room1.Sectors[GetSectorIndex(room1.Info, Location1, room1.NumZSectors)];
TRRoomSector sector2 = room2.Sectors[GetSectorIndex(room2.Info, Location2, room2.NumZSectors)];

RemovePortals(sector1, sector2, floorData);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public override void ApplyToLevel(TR2Level level)
floorData.ParseFromLevel(level);

TR2Room room = level.Rooms[data.ConvertRoom(Room)];
TRRoomSector sector = room.SectorList[X * room.NumZSectors + Z];
TRRoomSector sector = room.Sectors[X * room.NumZSectors + Z];
ReplacePortal(sector, (ushort)data.ConvertRoom(AdjoiningRoom), floorData);

floorData.WriteToLevel(level);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,15 @@ public override void ApplyToLevel(TR2Level level)

if (AllSectors)
{
foreach (TRRoomSector sector in level.Rooms[ceilingRoom].SectorList)
foreach (TRRoomSector sector in level.Rooms[ceilingRoom].Sectors)
{
if (!sector.IsWall && sector.RoomBelow != TRConsts.NoRoom)
{
sector.RoomBelow = (byte)floorRoom;
}
}

foreach (TRRoomSector sector in level.Rooms[floorRoom].SectorList)
foreach (TRRoomSector sector in level.Rooms[floorRoom].Sectors)
{
if (!sector.IsWall && sector.RoomAbove != TRConsts.NoRoom)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,7 @@ public override void ApplyToLevel(TR1Level level)
foreach (EMVisibilityPortal emPortal in Portals)
{
TRRoomPortal portal = emPortal.ToPortal(data);
TR1Room room = level.Rooms[emPortal.BaseRoom];
List<TRRoomPortal> portals = room.Portals.ToList();
portals.Add(portal);
room.Portals = portals.ToArray();
room.NumPortals++;
level.Rooms[emPortal.BaseRoom].Portals.Add(portal);
}
}

Expand All @@ -29,11 +25,7 @@ public override void ApplyToLevel(TR2Level level)
foreach (EMVisibilityPortal emPortal in Portals)
{
TRRoomPortal portal = emPortal.ToPortal(data);
TR2Room room = level.Rooms[emPortal.BaseRoom];
List<TRRoomPortal> portals = room.Portals.ToList();
portals.Add(portal);
room.Portals = portals.ToArray();
room.NumPortals++;
level.Rooms[emPortal.BaseRoom].Portals.Add(portal);
}
}

Expand All @@ -44,11 +36,7 @@ public override void ApplyToLevel(TR3Level level)
foreach (EMVisibilityPortal emPortal in Portals)
{
TRRoomPortal portal = emPortal.ToPortal(data);
TR3Room room = level.Rooms[emPortal.BaseRoom];
List<TRRoomPortal> portals = room.Portals.ToList();
portals.Add(portal);
room.Portals = portals.ToArray();
room.NumPortals++;
level.Rooms[emPortal.BaseRoom].Portals.Add(portal);
}
}
}
Loading

0 comments on commit c5ac7bf

Please sign in to comment.