Skip to content

Commit

Permalink
Separate TR1 and common classes (LostArtefacts#630)
Browse files Browse the repository at this point in the history
  • Loading branch information
lahm86 authored Apr 28, 2024
1 parent 80e3186 commit 3835b01
Show file tree
Hide file tree
Showing 85 changed files with 166 additions and 211 deletions.
6 changes: 3 additions & 3 deletions TREnvironmentEditor/Model/BaseEMFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,15 +47,15 @@ public static List<TRVertex> GetTileVertices(short x, short y, short z, bool asC
return vertices;
}

public static int CreateRoomVertex(TRRoom room, TRVertex vert, short lighting = 6574)
public static int CreateRoomVertex(TR1Room room, TRVertex vert, short lighting = 6574)
{
TRRoomVertex v = new()
TR1RoomVertex v = new()
{
Lighting = lighting,
Vertex = vert
};

List<TRRoomVertex> verts = room.RoomData.Vertices.ToList();
List<TR1RoomVertex> verts = room.RoomData.Vertices.ToList();
verts.Add(v);
room.RoomData.Vertices = verts.ToArray();
room.RoomData.NumVertices++;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using TRLevelControl.Model;
using TREnvironmentEditor.Helpers;
using TRLevelControl.Model;

namespace TREnvironmentEditor.Model.Conditions;

Expand All @@ -8,19 +9,19 @@ public class EMRoomContainsWaterCondition : BaseEMCondition

protected override bool Evaluate(TR1Level level)
{
TRRoom room = level.Rooms[RoomIndex];
return room.ContainsWater;
EMLevelData data = EMLevelData.GetData(level);
return level.Rooms[data.ConvertRoom(RoomIndex)].ContainsWater;
}

protected override bool Evaluate(TR2Level level)
{
TR2Room room = level.Rooms[RoomIndex];
return room.ContainsWater;
EMLevelData data = EMLevelData.GetData(level);
return level.Rooms[data.ConvertRoom(RoomIndex)].ContainsWater;
}

protected override bool Evaluate(TR3Level level)
{
TR3Room room = level.Rooms[RoomIndex];
return room.ContainsWater;
EMLevelData data = EMLevelData.GetData(level);
return level.Rooms[data.ConvertRoom(RoomIndex)].ContainsWater;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class EMSectorIsWallCondition : BaseEMCondition
protected override bool Evaluate(TR1Level level)
{
EMLevelData data = EMLevelData.GetData(level);
TRRoom room = level.Rooms[data.ConvertRoom(Location.Room)];
TR1Room room = level.Rooms[data.ConvertRoom(Location.Room)];
return room.Sectors[GetSectorIndex(room.Info, Location, room.NumZSectors)].IsWall;
}
protected override bool Evaluate(TR2Level level)
Expand Down
20 changes: 10 additions & 10 deletions TREnvironmentEditor/Model/Types/Mirroring/EMMirrorFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private void CalculateWorldWidth(TR1Level level)
{
_worldWidth = 0;
_xAdjustment = 0;
foreach (TRRoom room in level.Rooms)
foreach (TR1Room room in level.Rooms)
{
_worldWidth = Math.Max(_worldWidth, room.Info.X + TRConsts.Step4 * room.NumXSectors);
}
Expand Down Expand Up @@ -121,7 +121,7 @@ private static void MirrorFloorData(TR1Level level)
FDControl floorData = new();
floorData.ParseFromLevel(level);

foreach (TRRoom room in level.Rooms)
foreach (TR1Room room in level.Rooms)
{
List<TRRoomSector> sectors = room.Sectors.ToList();
MirrorSectors(sectors, room.NumXSectors, room.NumZSectors, floorData);
Expand Down Expand Up @@ -298,17 +298,17 @@ private static void MirrorSectors(List<TRRoomSector> sectors, ushort numXSectors

private void MirrorRooms(TR1Level level)
{
foreach (TRRoom room in level.Rooms)
foreach (TR1Room room in level.Rooms)
{
int oldRoomX = room.Info.X;
room.Info.X = FlipWorldX(oldRoomX);
room.Info.X -= room.NumXSectors * TRConsts.Step4;
Debug.Assert(room.Info.X >= 0);
// Flip room sprites separately as they don't sit on tile edges
List<TRRoomVertex> processedVerts = new();
List<TR1RoomVertex> processedVerts = new();
foreach (TRRoomSprite sprite in room.RoomData.Sprites)
{
TRRoomVertex roomVertex = room.RoomData.Vertices[sprite.Vertex];
TR1RoomVertex roomVertex = room.RoomData.Vertices[sprite.Vertex];

// Flip the old world coordinate, then subtract the new room position
int x = oldRoomX + roomVertex.Vertex.X;
Expand All @@ -321,7 +321,7 @@ private void MirrorRooms(TR1Level level)
}

// Flip the face vertices
foreach (TRRoomVertex vert in room.RoomData.Vertices)
foreach (TR1RoomVertex vert in room.RoomData.Vertices)
{
if (processedVerts.Contains(vert))
{
Expand All @@ -348,13 +348,13 @@ private void MirrorRooms(TR1Level level)
}

// Move the lights to their new spots
foreach (TRRoomLight light in room.Lights)
foreach (TR1RoomLight light in room.Lights)
{
light.X = FlipWorldX(light.X);
}

// Move the static meshes
foreach (TRRoomStaticMesh mesh in room.StaticMeshes)
foreach (TR1RoomStaticMesh mesh in room.StaticMeshes)
{
mesh.X = (uint)FlipWorldX((int)mesh.X);

Expand Down Expand Up @@ -1013,7 +1013,7 @@ private static void MirrorTextures(TR1Level level)
List<TRStaticMesh> staticMeshes = level.StaticMeshes.ToList();
ISet<TRStaticMesh> processedMeshes = new HashSet<TRStaticMesh>();

foreach (TRRoom room in level.Rooms)
foreach (TR1Room room in level.Rooms)
{
// Invert the faces, otherwise they are inside out
foreach (TRFace4 f in room.RoomData.Rectangles)
Expand All @@ -1029,7 +1029,7 @@ private static void MirrorTextures(TR1Level level)
textureReferences.Add(f.Texture);
}

foreach (TRRoomStaticMesh roomStaticMesh in room.StaticMeshes)
foreach (TR1RoomStaticMesh roomStaticMesh in room.StaticMeshes)
{
TRStaticMesh staticMesh = staticMeshes.Find(m => m.ID == roomStaticMesh.MeshID);
if (!processedMeshes.Add(staticMesh))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ public override void ApplyToLevel(TR1Level level)
FDControl floorData = new();
floorData.ParseFromLevel(level);

TRRoom room1 = level.Rooms[Location1.Room];
TRRoom room2 = level.Rooms[Location2.Room];
TR1Room room1 = level.Rooms[Location1.Room];
TR1Room room2 = level.Rooms[Location2.Room];

TRRoomSector sector1 = room1.Sectors[GetSectorIndex(room1.Info, Location1, room1.NumZSectors)];
TRRoomSector sector2 = room2.Sectors[GetSectorIndex(room2.Info, Location2, room2.NumZSectors)];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public override void ApplyToLevel(TR1Level level)
FDControl floorData = new();
floorData.ParseFromLevel(level);

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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public override void ApplyToLevel(TR1Level level)
foreach (EMVisibilityPortal emPortal in Portals)
{
TRRoomPortal portal = emPortal.ToPortal(data);
TRRoom room = level.Rooms[emPortal.BaseRoom];
TR1Room room = level.Rooms[emPortal.BaseRoom];
List<TRRoomPortal> portals = room.Portals.ToList();
portals.Add(portal);
room.Portals = portals.ToArray();
Expand Down
18 changes: 9 additions & 9 deletions TREnvironmentEditor/Model/Types/Rooms/EMCopyRoomFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ public class EMCopyRoomFunction : BaseEMFunction
public override void ApplyToLevel(TR1Level level)
{
EMLevelData data = GetData(level);
TRRoom baseRoom = level.Rooms[data.ConvertRoom(RoomIndex)];
TR1Room baseRoom = level.Rooms[data.ConvertRoom(RoomIndex)];

int xdiff = NewLocation.X - baseRoom.Info.X;
int ydiff = NewLocation.Y - baseRoom.Info.YBottom;
int zdiff = NewLocation.Z - baseRoom.Info.Z;

TRRoom newRoom = new()
TR1Room newRoom = new()
{
AlternateRoom = -1,
AmbientIntensity = baseRoom.AmbientIntensity,
Expand All @@ -36,7 +36,7 @@ public override void ApplyToLevel(TR1Level level)
YTop = NewLocation.Y + (baseRoom.Info.YTop - baseRoom.Info.YBottom),
Z = NewLocation.Z
},
Lights = new TRRoomLight[baseRoom.NumLights],
Lights = new TR1RoomLight[baseRoom.NumLights],

NumDataWords = baseRoom.NumDataWords,
NumLights = baseRoom.NumLights,
Expand All @@ -45,7 +45,7 @@ public override void ApplyToLevel(TR1Level level)
NumXSectors = baseRoom.NumXSectors,
NumZSectors = baseRoom.NumZSectors,
Portals = Array.Empty<TRRoomPortal>(),
RoomData = new TRRoomData
RoomData = new TR1RoomData
{
NumRectangles = baseRoom.RoomData.NumRectangles,
NumSprites = baseRoom.RoomData.NumSprites,
Expand All @@ -54,16 +54,16 @@ public override void ApplyToLevel(TR1Level level)
Rectangles = new TRFace4[baseRoom.RoomData.NumRectangles],
Sprites = new TRRoomSprite[baseRoom.RoomData.NumSprites],
Triangles = new TRFace3[baseRoom.RoomData.NumTriangles],
Vertices = new TRRoomVertex[baseRoom.RoomData.NumVertices]
Vertices = new TR1RoomVertex[baseRoom.RoomData.NumVertices]
},
Sectors = new TRRoomSector[baseRoom.Sectors.Length],
StaticMeshes = new TRRoomStaticMesh[baseRoom.NumStaticMeshes]
StaticMeshes = new TR1RoomStaticMesh[baseRoom.NumStaticMeshes]
};

// Lights
for (int i = 0; i < newRoom.Lights.Length; i++)
{
newRoom.Lights[i] = new TRRoomLight
newRoom.Lights[i] = new TR1RoomLight
{
Fade = baseRoom.Lights[i].Fade,
Intensity = baseRoom.Lights[i].Intensity,
Expand Down Expand Up @@ -103,7 +103,7 @@ public override void ApplyToLevel(TR1Level level)
// Vertices
for (int i = 0; i < newRoom.RoomData.Vertices.Length; i++)
{
newRoom.RoomData.Vertices[i] = new TRRoomVertex
newRoom.RoomData.Vertices[i] = new TR1RoomVertex
{
Lighting = baseRoom.RoomData.Vertices[i].Lighting,
Vertex = new TRVertex
Expand All @@ -128,7 +128,7 @@ public override void ApplyToLevel(TR1Level level)
// Static Meshes
for (int i = 0; i < newRoom.NumStaticMeshes; i++)
{
newRoom.StaticMeshes[i] = new TRRoomStaticMesh
newRoom.StaticMeshes[i] = new TR1RoomStaticMesh
{
Intensity = baseRoom.StaticMeshes[i].Intensity,
MeshID = baseRoom.StaticMeshes[i].MeshID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public override void ApplyToLevel(TR1Level level)
{
foreach (short roomNumber in FaceMap.Keys)
{
TRRoom room = level.Rooms[data.ConvertRoom(roomNumber)];
TR1Room room = level.Rooms[data.ConvertRoom(roomNumber)];
foreach (EMTextureFaceType faceType in FaceMap[roomNumber].Keys)
{
foreach (int baseFaceIndex in FaceMap[roomNumber][faceType].Keys)
Expand All @@ -39,8 +39,8 @@ public override void ApplyToLevel(TR1Level level)

for (int i = 0; i < baseVertices.Length; i++)
{
TRRoomVertex baseVertex = room.RoomData.Vertices[baseVertices[i]];
TRRoomVertex copyVertex = room.RoomData.Vertices[copyVertices[i]];
TR1RoomVertex baseVertex = room.RoomData.Vertices[baseVertices[i]];
TR1RoomVertex copyVertex = room.RoomData.Vertices[copyVertices[i]];
CopyAttributes(baseVertex, copyVertex);
}
}
Expand All @@ -53,8 +53,8 @@ public override void ApplyToLevel(TR1Level level)
{
foreach (short roomNumber in RoomMap.Keys)
{
TRRoom room = level.Rooms[data.ConvertRoom(roomNumber)];
foreach (TRRoomVertex copyVertex in room.RoomData.Vertices)
TR1Room room = level.Rooms[data.ConvertRoom(roomNumber)];
foreach (TR1RoomVertex copyVertex in room.RoomData.Vertices)
{
CopyAttributes(RoomMap[roomNumber], copyVertex);
}
Expand Down Expand Up @@ -171,12 +171,12 @@ public override void ApplyToLevel(TR3Level level)
}

// TR3RoomVertex is a placeholder in the data to cover all levels
private static void CopyAttributes(TR3RoomVertex baseVertex, TRRoomVertex copyVertex)
private static void CopyAttributes(TR3RoomVertex baseVertex, TR1RoomVertex copyVertex)
{
copyVertex.Lighting = baseVertex.Lighting;
}

private static void CopyAttributes(TRRoomVertex baseVertex, TRRoomVertex copyVertex)
private static void CopyAttributes(TR1RoomVertex baseVertex, TR1RoomVertex copyVertex)
{
copyVertex.Lighting = baseVertex.Lighting;
}
Expand Down
12 changes: 6 additions & 6 deletions TREnvironmentEditor/Model/Types/Rooms/EMCreateRoomFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class EMCreateRoomFunction : BaseEMFunction

public override void ApplyToLevel(TR1Level level)
{
TRRoom room = new()
TR1Room room = new()
{
NumXSectors = Width,
NumZSectors = Depth,
Expand All @@ -33,15 +33,15 @@ public override void ApplyToLevel(TR1Level level)
NumPortals = 0,
NumStaticMeshes = 0,
Portals = Array.Empty<TRRoomPortal>(),
StaticMeshes = Array.Empty<TRRoomStaticMesh>(),
StaticMeshes = Array.Empty<TR1RoomStaticMesh>(),
Info = new TRRoomInfo
{
X = Location.X,
YBottom = Location.Y,
YTop = Location.Y - Height * TRConsts.Step1,
Z = Location.Z
},
RoomData = new TRRoomData
RoomData = new TR1RoomData
{
// Ignored for now
NumSprites = 0,
Expand All @@ -51,11 +51,11 @@ public override void ApplyToLevel(TR1Level level)
}
};

room.Lights = new TRRoomLight[room.NumLights];
room.Lights = new TR1RoomLight[room.NumLights];
for (int i = 0; i < room.NumLights; i++)
{
EMRoomLight light = Lights[i];
room.Lights[i] = new TRRoomLight
room.Lights[i] = new TR1RoomLight
{
X = light.X + Location.X,
Y = light.Y + Location.Y,
Expand Down Expand Up @@ -90,7 +90,7 @@ public override void ApplyToLevel(TR1Level level)
room.RoomData.NumRectangles = (short)faces.Count;
room.RoomData.NumVertices = (short)vertices.Count;
room.RoomData.Rectangles = faces.ToArray();
room.RoomData.Vertices = vertices.Select(v => new TRRoomVertex
room.RoomData.Vertices = vertices.Select(v => new TR1RoomVertex
{
Lighting = DefaultVertex.Lighting,
Vertex = v
Expand Down
10 changes: 5 additions & 5 deletions TREnvironmentEditor/Model/Types/Rooms/EMGenerateLightFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,20 @@ public override void ApplyToLevel(TR1Level level)
EMLevelData data = GetData(level);
foreach (short roomIndex in RoomIndices)
{
TRRoom room = level.Rooms[data.ConvertRoom(roomIndex)];
TR1Room room = level.Rooms[data.ConvertRoom(roomIndex)];
if (room.NumLights == 0)
{
continue;
}

Dictionary<TRRoomLight, Vector3> lightPositions = new();
foreach (TRRoomVertex vertex in room.RoomData.Vertices)
Dictionary<TR1RoomLight, Vector3> lightPositions = new();
foreach (TR1RoomVertex vertex in room.RoomData.Vertices)
{
// Several lights per room - for now just use whichever is nearest this point
Vector3 vertexPosition = new(vertex.Vertex.X, vertex.Vertex.Y, vertex.Vertex.Z);
double smallestDistance = double.MaxValue;
TRRoomLight nearestLight = room.Lights[0];
foreach (TRRoomLight light in room.Lights)
TR1RoomLight nearestLight = room.Lights[0];
foreach (TR1RoomLight light in room.Lights)
{
if (!lightPositions.ContainsKey(light))
{
Expand Down
Loading

0 comments on commit 3835b01

Please sign in to comment.