From c5ac7bfd568ed1e35186a2520a3b21a93e9aea69 Mon Sep 17 00:00:00 2001 From: lahm86 <33758420+lahm86@users.noreply.github.com> Date: Mon, 29 Apr 2024 19:40:59 +0100 Subject: [PATCH] Refactor internal room collections (#635) Part of #468. --- Deps/TRGE.Coord.dll | Bin 1616896 -> 1616896 bytes TREnvironmentEditor/Model/BaseEMFunction.cs | 33 +-- .../Room/EMSectorIsWallCondition.cs | 2 +- .../Model/Types/Mirroring/EMMirrorFunction.cs | 12 +- .../EMRemoveCollisionalPortalFunction.cs | 4 +- .../EMReplaceCollisionalPortalFunction.cs | 2 +- .../EMVerticalCollisionalPortalFunction.cs | 4 +- .../Portals/EMVisibilityPortalFunction.cs | 18 +- .../Model/Types/Rooms/EMCopyRoomFunction.cs | 212 ++++++++---------- .../Model/Types/Rooms/EMCreateRoomFunction.cs | 147 +++++------- .../Types/Rooms/EMGenerateLightFunction.cs | 6 +- .../Model/Types/Rooms/EMImportRoomFunction.cs | 162 ++++++------- .../Model/Types/Surfaces/BaseWaterFunction.cs | 76 ++----- .../Model/Types/Surfaces/EMCeilingFunction.cs | 2 +- .../Model/Types/Surfaces/EMDrainFunction.cs | 8 +- .../Model/Types/Surfaces/EMFloodFunction.cs | 8 +- .../Model/Types/Surfaces/EMFloorFunction.cs | 89 +++----- .../Model/Types/Textures/EMAddFaceFunction.cs | 52 +---- .../Types/Textures/EMAddRoomSpriteFunction.cs | 45 +--- .../Types/Textures/EMAddStaticMeshFunction.cs | 18 +- .../Types/Textures/EMModifyFaceFunction.cs | 70 ++---- .../Model/Types/Textures/EMRefaceFunction.cs | 2 +- .../Types/Textures/EMRemoveFaceFunction.cs | 31 +-- .../Textures/EMRemoveStaticMeshFunction.cs | 52 +---- .../Types/Triggers/EMCameraTriggerFunction.cs | 2 +- .../EMRemoveEntityTriggersFunction.cs | 2 +- .../Types/Triggers/EMRemoveTriggerFunction.cs | 2 +- .../Model/Types/Triggers/EMTriggerFunction.cs | 2 +- TRFDControl/FDControl.cs | 4 +- TRFDControl/Utilities/FDUtilities.cs | 16 +- TRLevelControl/Control/TR1LevelControl.cs | 174 ++++++-------- TRLevelControl/Control/TR2LevelControl.cs | 180 ++++++--------- TRLevelControl/Control/TR3LevelControl.cs | 152 ++----------- TRLevelControl/Helpers/Pathing/Room.cs | 2 +- TRLevelControl/Helpers/TR2BoxUtilities.cs | 2 +- TRLevelControl/Model/TR1/TR1Room.cs | 99 ++------ TRLevelControl/Model/TR1/TR1RoomData.cs | 31 +-- TRLevelControl/Model/TR2/TR2Room.cs | 148 ++---------- TRLevelControl/Model/TR2/TR2RoomData.cs | 39 +--- TRLevelControl/Model/TR3/TR3Room.cs | 161 +------------ TRLevelControl/Model/TR3/TR3RoomData.cs | 39 +--- TRLevelControl/Model/TR4/TR4Room.cs | 45 +--- TRLevelControl/TR3FileReadUtilities.cs | 79 ++++++- TRLevelControl/TR4FileReadUtilities.cs | 155 ++----------- TRLevelControlTests/TR2/IOTests.cs | 12 +- TRRandomizerCore/Levels/TR2CombinedLevel.cs | 34 +-- .../Randomizers/Shared/AudioRandomizer.cs | 4 +- .../Randomizers/Shared/RandoConsts.cs | 8 + .../Randomizers/TR1/TR1NightModeRandomizer.cs | 19 +- .../Randomizers/TR2/TR2AudioRandomizer.cs | 2 +- .../Randomizers/TR2/TR2EnemyRandomizer.cs | 2 +- .../Randomizers/TR2/TR2NightModeRandomizer.cs | 51 ++++- .../Randomizers/TR2R/TR2RAudioRandomizer.cs | 2 +- .../Randomizers/TR3/TR3NightModeRandomizer.cs | 20 +- .../Randomizers/TR3/TR3VfxRandomizer.cs | 58 ++++- TRRandomizerCore/TRRandomizerController.cs | 2 +- .../Textures/Landmarks/TR2LandmarkImporter.cs | 2 +- TRRandomizerCore/Utilities/FaceUtilities.cs | 10 +- .../Locations/TR2LocationGenerator.cs | 4 +- .../Utilities/RoomWaterUtilities.cs | 94 -------- .../Utilities/TR2EnemyUtilities.cs | 14 +- TextureExport/Types/FaceMapper.cs | 14 +- 62 files changed, 860 insertions(+), 1881 deletions(-) create mode 100644 TRRandomizerCore/Randomizers/Shared/RandoConsts.cs diff --git a/Deps/TRGE.Coord.dll b/Deps/TRGE.Coord.dll index 8a22256aa9d0a1950d5e85bffc1a88152805d331..6ed1e32004cd6d94103779e5b7359ff9eeecc52b 100644 GIT binary patch delta 11033 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 HW{Cd_p=u=x delta 10954 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 diff --git a/TREnvironmentEditor/Model/BaseEMFunction.cs b/TREnvironmentEditor/Model/BaseEMFunction.cs index 12ebd3b68..3fabe0b8d 100644 --- a/TREnvironmentEditor/Model/BaseEMFunction.cs +++ b/TREnvironmentEditor/Model/BaseEMFunction.cs @@ -49,39 +49,29 @@ public static List 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 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 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, @@ -89,13 +79,8 @@ public static int CreateRoomVertex(TR3Room room, TRVertex vert, short lighting = UseCaustics = useCaustics, UseWaveMovement = useWaveMovement, Vertex = vert - }; - - List 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; } /// diff --git a/TREnvironmentEditor/Model/Conditions/Room/EMSectorIsWallCondition.cs b/TREnvironmentEditor/Model/Conditions/Room/EMSectorIsWallCondition.cs index d478cc0bd..110a8d82d 100644 --- a/TREnvironmentEditor/Model/Conditions/Room/EMSectorIsWallCondition.cs +++ b/TREnvironmentEditor/Model/Conditions/Room/EMSectorIsWallCondition.cs @@ -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) diff --git a/TREnvironmentEditor/Model/Types/Mirroring/EMMirrorFunction.cs b/TREnvironmentEditor/Model/Types/Mirroring/EMMirrorFunction.cs index 19c511e4e..9c8c1356d 100644 --- a/TREnvironmentEditor/Model/Types/Mirroring/EMMirrorFunction.cs +++ b/TREnvironmentEditor/Model/Types/Mirroring/EMMirrorFunction.cs @@ -123,9 +123,7 @@ private static void MirrorFloorData(TR1Level level) foreach (TR1Room room in level.Rooms) { - List 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); @@ -138,9 +136,7 @@ private static void MirrorFloorData(TR2Level level) foreach (TR2Room room in level.Rooms) { - List 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); @@ -153,9 +149,7 @@ private static void MirrorFloorData(TR3Level level) foreach (TR3Room room in level.Rooms) { - List 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); diff --git a/TREnvironmentEditor/Model/Types/Portals/EMRemoveCollisionalPortalFunction.cs b/TREnvironmentEditor/Model/Types/Portals/EMRemoveCollisionalPortalFunction.cs index d4719cbba..e0c7cb6f7 100644 --- a/TREnvironmentEditor/Model/Types/Portals/EMRemoveCollisionalPortalFunction.cs +++ b/TREnvironmentEditor/Model/Types/Portals/EMRemoveCollisionalPortalFunction.cs @@ -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); diff --git a/TREnvironmentEditor/Model/Types/Portals/EMReplaceCollisionalPortalFunction.cs b/TREnvironmentEditor/Model/Types/Portals/EMReplaceCollisionalPortalFunction.cs index 342280180..463529e63 100644 --- a/TREnvironmentEditor/Model/Types/Portals/EMReplaceCollisionalPortalFunction.cs +++ b/TREnvironmentEditor/Model/Types/Portals/EMReplaceCollisionalPortalFunction.cs @@ -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); diff --git a/TREnvironmentEditor/Model/Types/Portals/EMVerticalCollisionalPortalFunction.cs b/TREnvironmentEditor/Model/Types/Portals/EMVerticalCollisionalPortalFunction.cs index b6d765dfa..daffcfc5e 100644 --- a/TREnvironmentEditor/Model/Types/Portals/EMVerticalCollisionalPortalFunction.cs +++ b/TREnvironmentEditor/Model/Types/Portals/EMVerticalCollisionalPortalFunction.cs @@ -71,7 +71,7 @@ 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) { @@ -79,7 +79,7 @@ public override void ApplyToLevel(TR2Level level) } } - foreach (TRRoomSector sector in level.Rooms[floorRoom].SectorList) + foreach (TRRoomSector sector in level.Rooms[floorRoom].Sectors) { if (!sector.IsWall && sector.RoomAbove != TRConsts.NoRoom) { diff --git a/TREnvironmentEditor/Model/Types/Portals/EMVisibilityPortalFunction.cs b/TREnvironmentEditor/Model/Types/Portals/EMVisibilityPortalFunction.cs index 2145addd0..836cbe292 100644 --- a/TREnvironmentEditor/Model/Types/Portals/EMVisibilityPortalFunction.cs +++ b/TREnvironmentEditor/Model/Types/Portals/EMVisibilityPortalFunction.cs @@ -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 portals = room.Portals.ToList(); - portals.Add(portal); - room.Portals = portals.ToArray(); - room.NumPortals++; + level.Rooms[emPortal.BaseRoom].Portals.Add(portal); } } @@ -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 portals = room.Portals.ToList(); - portals.Add(portal); - room.Portals = portals.ToArray(); - room.NumPortals++; + level.Rooms[emPortal.BaseRoom].Portals.Add(portal); } } @@ -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 portals = room.Portals.ToList(); - portals.Add(portal); - room.Portals = portals.ToArray(); - room.NumPortals++; + level.Rooms[emPortal.BaseRoom].Portals.Add(portal); } } } diff --git a/TREnvironmentEditor/Model/Types/Rooms/EMCopyRoomFunction.cs b/TREnvironmentEditor/Model/Types/Rooms/EMCopyRoomFunction.cs index 92b52f5df..eb4861f7f 100644 --- a/TREnvironmentEditor/Model/Types/Rooms/EMCopyRoomFunction.cs +++ b/TREnvironmentEditor/Model/Types/Rooms/EMCopyRoomFunction.cs @@ -29,71 +29,63 @@ public override void ApplyToLevel(TR1Level level) AlternateRoom = -1, AmbientIntensity = baseRoom.AmbientIntensity, Flags = baseRoom.Flags, - Info = new TRRoomInfo + Info = new() { X = NewLocation.X, YBottom = NewLocation.Y, YTop = NewLocation.Y + (baseRoom.Info.YTop - baseRoom.Info.YBottom), Z = NewLocation.Z }, - Lights = new TR1RoomLight[baseRoom.NumLights], + Lights = new(), - NumDataWords = baseRoom.NumDataWords, - NumLights = baseRoom.NumLights, - NumPortals = 0, - NumStaticMeshes = baseRoom.NumStaticMeshes, NumXSectors = baseRoom.NumXSectors, NumZSectors = baseRoom.NumZSectors, - Portals = Array.Empty(), - RoomData = new TR1RoomData - { - NumRectangles = baseRoom.RoomData.NumRectangles, - NumSprites = baseRoom.RoomData.NumSprites, - NumTriangles = baseRoom.RoomData.NumTriangles, - NumVertices = baseRoom.RoomData.NumVertices, - Rectangles = new TRFace4[baseRoom.RoomData.NumRectangles], - Sprites = new TRRoomSprite[baseRoom.RoomData.NumSprites], - Triangles = new TRFace3[baseRoom.RoomData.NumTriangles], - Vertices = new TR1RoomVertex[baseRoom.RoomData.NumVertices] + Portals = new(), + RoomData = new() + { + Rectangles = new(), + Sprites = new(), + Triangles = new(), + Vertices = new(), }, - Sectors = new TRRoomSector[baseRoom.Sectors.Length], - StaticMeshes = new TR1RoomStaticMesh[baseRoom.NumStaticMeshes] + Sectors = new(), + StaticMeshes = new() }; // Lights - for (int i = 0; i < newRoom.Lights.Length; i++) + for (int i = 0; i < baseRoom.Lights.Count; i++) { - newRoom.Lights[i] = new TR1RoomLight + newRoom.Lights.Add(new() { Fade = baseRoom.Lights[i].Fade, Intensity = baseRoom.Lights[i].Intensity, X = baseRoom.Lights[i].X + xdiff, Y = baseRoom.Lights[i].Y + ydiff, Z = baseRoom.Lights[i].Z + zdiff - }; + }); } // Faces - for (int i = 0; i < newRoom.RoomData.NumRectangles; i++) + for (int i = 0; i < baseRoom.RoomData.Rectangles.Count; i++) { - newRoom.RoomData.Rectangles[i] = new TRFace4 + newRoom.RoomData.Rectangles.Add(new() { Texture = baseRoom.RoomData.Rectangles[i].Texture, Vertices = new ushort[baseRoom.RoomData.Rectangles[i].Vertices.Length] - }; + }); for (int j = 0; j < newRoom.RoomData.Rectangles[i].Vertices.Length; j++) { newRoom.RoomData.Rectangles[i].Vertices[j] = baseRoom.RoomData.Rectangles[i].Vertices[j]; } } - for (int i = 0; i < newRoom.RoomData.NumTriangles; i++) + for (int i = 0; i < baseRoom.RoomData.Triangles.Count; i++) { - newRoom.RoomData.Triangles[i] = new TRFace3 + newRoom.RoomData.Triangles.Add(new() { Texture = baseRoom.RoomData.Triangles[i].Texture, Vertices = new ushort[baseRoom.RoomData.Triangles[i].Vertices.Length] - }; + }); for (int j = 0; j < newRoom.RoomData.Triangles[i].Vertices.Length; j++) { newRoom.RoomData.Triangles[i].Vertices[j] = baseRoom.RoomData.Triangles[i].Vertices[j]; @@ -101,34 +93,34 @@ public override void ApplyToLevel(TR1Level level) } // Vertices - for (int i = 0; i < newRoom.RoomData.Vertices.Length; i++) + for (int i = 0; i < baseRoom.RoomData.Vertices.Count; i++) { - newRoom.RoomData.Vertices[i] = new TR1RoomVertex + newRoom.RoomData.Vertices.Add(new() { Lighting = baseRoom.RoomData.Vertices[i].Lighting, - Vertex = new TRVertex + Vertex = new() { X = baseRoom.RoomData.Vertices[i].Vertex.X, // Room coords for X and Z Y = (short)(baseRoom.RoomData.Vertices[i].Vertex.Y + ydiff), Z = baseRoom.RoomData.Vertices[i].Vertex.Z } - }; + }); } // Sprites - for (int i = 0; i < newRoom.RoomData.NumSprites; i++) + for (int i = 0; i < baseRoom.RoomData.Sprites.Count; i++) { - newRoom.RoomData.Sprites[i] = new TRRoomSprite + newRoom.RoomData.Sprites.Add(new() { Texture = baseRoom.RoomData.Sprites[i].Texture, Vertex = baseRoom.RoomData.Sprites[i].Vertex - }; + }); } // Static Meshes - for (int i = 0; i < newRoom.NumStaticMeshes; i++) + for (int i = 0; i < baseRoom.StaticMeshes.Count; i++) { - newRoom.StaticMeshes[i] = new TR1RoomStaticMesh + newRoom.StaticMeshes.Add(new() { Intensity = baseRoom.StaticMeshes[i].Intensity, MeshID = baseRoom.StaticMeshes[i].MeshID, @@ -136,16 +128,16 @@ public override void ApplyToLevel(TR1Level level) X = (uint)(baseRoom.StaticMeshes[i].X + xdiff), Y = (uint)(baseRoom.StaticMeshes[i].Y + ydiff), Z = (uint)(baseRoom.StaticMeshes[i].Z + zdiff) - }; + }); } // Rebuild the sectors FDControl floorData = new(); floorData.ParseFromLevel(level); - for (int i = 0; i < newRoom.Sectors.Length; i++) + for (int i = 0; i < baseRoom.Sectors.Count; i++) { - newRoom.Sectors[i] = RebuildSector(baseRoom.Sectors[i], i, floorData, ydiff, baseRoom.Info); + newRoom.Sectors.Add(RebuildSector(baseRoom.Sectors[i], i, floorData, ydiff, baseRoom.Info)); } floorData.WriteToLevel(level); @@ -175,41 +167,33 @@ public override void ApplyToLevel(TR2Level level) AmbientIntensity = baseRoom.AmbientIntensity, AmbientIntensity2 = baseRoom.AmbientIntensity2, Flags = baseRoom.Flags, - Info = new TRRoomInfo + Info = new() { X = NewLocation.X, YBottom = NewLocation.Y, YTop = NewLocation.Y + (baseRoom.Info.YTop - baseRoom.Info.YBottom), Z = NewLocation.Z }, - Lights = new TR2RoomLight[baseRoom.NumLights], + Lights = new(), LightMode = baseRoom.LightMode, - NumDataWords = baseRoom.NumDataWords, - NumLights = baseRoom.NumLights, - NumPortals = 0, - NumStaticMeshes = baseRoom.NumStaticMeshes, NumXSectors = baseRoom.NumXSectors, NumZSectors = baseRoom.NumZSectors, - Portals = Array.Empty(), - RoomData = new TR2RoomData - { - NumRectangles = baseRoom.RoomData.NumRectangles, - NumSprites = baseRoom.RoomData.NumSprites, - NumTriangles = baseRoom.RoomData.NumTriangles, - NumVertices = baseRoom.RoomData.NumVertices, - Rectangles = new TRFace4[baseRoom.RoomData.NumRectangles], - Sprites = new TRRoomSprite[baseRoom.RoomData.NumSprites], - Triangles = new TRFace3[baseRoom.RoomData.NumTriangles], - Vertices = new TR2RoomVertex[baseRoom.RoomData.NumVertices] + Portals = new(), + RoomData = new() + { + Rectangles = new(), + Sprites = new(), + Triangles = new(), + Vertices = new(), }, - SectorList = new TRRoomSector[baseRoom.SectorList.Length], - StaticMeshes = new TR2RoomStaticMesh[baseRoom.NumStaticMeshes] + Sectors = new(), + StaticMeshes = new() }; // Lights - for (int i = 0; i < newRoom.Lights.Length; i++) + for (int i = 0; i < baseRoom.Lights.Count; i++) { - newRoom.Lights[i] = new TR2RoomLight + newRoom.Lights.Add(new() { Fade1 = baseRoom.Lights[i].Fade1, Fade2 = baseRoom.Lights[i].Fade2, @@ -218,30 +202,30 @@ public override void ApplyToLevel(TR2Level level) X = baseRoom.Lights[i].X + xdiff, Y = baseRoom.Lights[i].Y + ydiff, Z = baseRoom.Lights[i].Z + zdiff - }; + }); } // Faces - for (int i = 0; i < newRoom.RoomData.NumRectangles; i++) + for (int i = 0; i < baseRoom.RoomData.Rectangles.Count; i++) { - newRoom.RoomData.Rectangles[i] = new TRFace4 + newRoom.RoomData.Rectangles.Add(new() { Texture = baseRoom.RoomData.Rectangles[i].Texture, Vertices = new ushort[baseRoom.RoomData.Rectangles[i].Vertices.Length] - }; + }); for (int j = 0; j < newRoom.RoomData.Rectangles[i].Vertices.Length; j++) { newRoom.RoomData.Rectangles[i].Vertices[j] = baseRoom.RoomData.Rectangles[i].Vertices[j]; } } - for (int i = 0; i < newRoom.RoomData.NumTriangles; i++) + for (int i = 0; i < baseRoom.RoomData.Triangles.Count; i++) { - newRoom.RoomData.Triangles[i] = new TRFace3 + newRoom.RoomData.Triangles.Add(new() { Texture = baseRoom.RoomData.Triangles[i].Texture, Vertices = new ushort[baseRoom.RoomData.Triangles[i].Vertices.Length] - }; + }); for (int j = 0; j < newRoom.RoomData.Triangles[i].Vertices.Length; j++) { newRoom.RoomData.Triangles[i].Vertices[j] = baseRoom.RoomData.Triangles[i].Vertices[j]; @@ -249,9 +233,9 @@ public override void ApplyToLevel(TR2Level level) } // Vertices - for (int i = 0; i < newRoom.RoomData.Vertices.Length; i++) + for (int i = 0; i < baseRoom.RoomData.Vertices.Count; i++) { - newRoom.RoomData.Vertices[i] = new TR2RoomVertex + newRoom.RoomData.Vertices.Add(new() { Attributes = baseRoom.RoomData.Vertices[i].Attributes, Lighting = baseRoom.RoomData.Vertices[i].Lighting, @@ -262,23 +246,23 @@ public override void ApplyToLevel(TR2Level level) Y = (short)(baseRoom.RoomData.Vertices[i].Vertex.Y + ydiff), Z = baseRoom.RoomData.Vertices[i].Vertex.Z } - }; + }); } // Sprites - for (int i = 0; i < newRoom.RoomData.NumSprites; i++) + for (int i = 0; i < baseRoom.RoomData.Sprites.Count; i++) { - newRoom.RoomData.Sprites[i] = new TRRoomSprite + newRoom.RoomData.Sprites.Add(new() { Texture = baseRoom.RoomData.Sprites[i].Texture, Vertex = baseRoom.RoomData.Sprites[i].Vertex - }; + }); } // Static Meshes - for (int i = 0; i < newRoom.NumStaticMeshes; i++) + for (int i = 0; i < baseRoom.StaticMeshes.Count; i++) { - newRoom.StaticMeshes[i] = new TR2RoomStaticMesh + newRoom.StaticMeshes.Add(new() { Intensity1 = baseRoom.StaticMeshes[i].Intensity1, Intensity2 = baseRoom.StaticMeshes[i].Intensity2, @@ -287,16 +271,16 @@ public override void ApplyToLevel(TR2Level level) X = (uint)(baseRoom.StaticMeshes[i].X + xdiff), Y = (uint)(baseRoom.StaticMeshes[i].Y + ydiff), Z = (uint)(baseRoom.StaticMeshes[i].Z + zdiff) - }; + }); } // Rebuild the sectors FDControl floorData = new(); floorData.ParseFromLevel(level); - for (int i = 0; i < newRoom.SectorList.Length; i++) + for (int i = 0; i < baseRoom.Sectors.Count; i++) { - newRoom.SectorList[i] = RebuildSector(baseRoom.SectorList[i], i, floorData, ydiff, baseRoom.Info); + newRoom.Sectors.Add(RebuildSector(baseRoom.Sectors[i], i, floorData, ydiff, baseRoom.Info)); } floorData.WriteToLevel(level); @@ -326,43 +310,35 @@ public override void ApplyToLevel(TR3Level level) AmbientIntensity = baseRoom.AmbientIntensity, Filler = baseRoom.Filler, Flags = baseRoom.Flags, - Info = new TRRoomInfo + Info = new() { X = NewLocation.X, YBottom = NewLocation.Y, YTop = NewLocation.Y + (baseRoom.Info.YTop - baseRoom.Info.YBottom), Z = NewLocation.Z }, - Lights = new TR3RoomLight[baseRoom.NumLights], + Lights = new(), LightMode = baseRoom.LightMode, - NumDataWords = baseRoom.NumDataWords, - NumLights = baseRoom.NumLights, - NumPortals = 0, - NumStaticMeshes = baseRoom.NumStaticMeshes, NumXSectors = baseRoom.NumXSectors, NumZSectors = baseRoom.NumZSectors, - Portals = Array.Empty(), + Portals = new(), ReverbInfo = baseRoom.ReverbInfo, - RoomData = new TR3RoomData - { - NumRectangles = baseRoom.RoomData.NumRectangles, - NumSprites = baseRoom.RoomData.NumSprites, - NumTriangles = baseRoom.RoomData.NumTriangles, - NumVertices = baseRoom.RoomData.NumVertices, - Rectangles = new TRFace4[baseRoom.RoomData.NumRectangles], - Sprites = new TRRoomSprite[baseRoom.RoomData.NumSprites], - Triangles = new TRFace3[baseRoom.RoomData.NumTriangles], - Vertices = new TR3RoomVertex[baseRoom.RoomData.NumVertices] + RoomData = new() + { + Rectangles = new(), + Sprites = new(), + Triangles = new(), + Vertices = new(), }, - Sectors = new TRRoomSector[baseRoom.Sectors.Length], - StaticMeshes = new TR3RoomStaticMesh[baseRoom.NumStaticMeshes], + Sectors = new(), + StaticMeshes = new(), WaterScheme = baseRoom.WaterScheme }; // Lights - for (int i = 0; i < newRoom.Lights.Length; i++) + for (int i = 0; i < baseRoom.Lights.Count; i++) { - newRoom.Lights[i] = new TR3RoomLight + newRoom.Lights.Add(new() { Colour = baseRoom.Lights[i].Colour, LightProperties = baseRoom.Lights[i].LightProperties, @@ -370,30 +346,30 @@ public override void ApplyToLevel(TR3Level level) X = baseRoom.Lights[i].X + xdiff, Y = baseRoom.Lights[i].Y + ydiff, Z = baseRoom.Lights[i].Z + zdiff - }; + }); } // Faces - for (int i = 0; i < newRoom.RoomData.NumRectangles; i++) + for (int i = 0; i < baseRoom.RoomData.Rectangles.Count; i++) { - newRoom.RoomData.Rectangles[i] = new TRFace4 + newRoom.RoomData.Rectangles.Add(new() { Texture = baseRoom.RoomData.Rectangles[i].Texture, Vertices = new ushort[baseRoom.RoomData.Rectangles[i].Vertices.Length] - }; + }); for (int j = 0; j < newRoom.RoomData.Rectangles[i].Vertices.Length; j++) { newRoom.RoomData.Rectangles[i].Vertices[j] = baseRoom.RoomData.Rectangles[i].Vertices[j]; } } - for (int i = 0; i < newRoom.RoomData.NumTriangles; i++) + for (int i = 0; i < baseRoom.RoomData.Triangles.Count; i++) { - newRoom.RoomData.Triangles[i] = new TRFace3 + newRoom.RoomData.Triangles.Add(new() { Texture = baseRoom.RoomData.Triangles[i].Texture, Vertices = new ushort[baseRoom.RoomData.Triangles[i].Vertices.Length] - }; + }); for (int j = 0; j < newRoom.RoomData.Triangles[i].Vertices.Length; j++) { newRoom.RoomData.Triangles[i].Vertices[j] = baseRoom.RoomData.Triangles[i].Vertices[j]; @@ -401,9 +377,9 @@ public override void ApplyToLevel(TR3Level level) } // Vertices - for (int i = 0; i < newRoom.RoomData.Vertices.Length; i++) + for (int i = 0; i < baseRoom.RoomData.Vertices.Count; i++) { - newRoom.RoomData.Vertices[i] = new TR3RoomVertex + newRoom.RoomData.Vertices.Add(new() { Attributes = baseRoom.RoomData.Vertices[i].Attributes, Colour = baseRoom.RoomData.Vertices[i].Colour, @@ -414,23 +390,23 @@ public override void ApplyToLevel(TR3Level level) Y = (short)(baseRoom.RoomData.Vertices[i].Vertex.Y + ydiff), Z = baseRoom.RoomData.Vertices[i].Vertex.Z } - }; + }); } // Sprites - for (int i = 0; i < newRoom.RoomData.NumSprites; i++) + for (int i = 0; i < baseRoom.RoomData.Sprites.Count; i++) { - newRoom.RoomData.Sprites[i] = new TRRoomSprite + newRoom.RoomData.Sprites.Add(new() { Texture = baseRoom.RoomData.Sprites[i].Texture, Vertex = baseRoom.RoomData.Sprites[i].Vertex - }; + }); } // Static Meshes - for (int i = 0; i < newRoom.NumStaticMeshes; i++) + for (int i = 0; i < baseRoom.StaticMeshes.Count; i++) { - newRoom.StaticMeshes[i] = new TR3RoomStaticMesh + newRoom.StaticMeshes.Add(new() { Colour = baseRoom.StaticMeshes[i].Colour, MeshID = baseRoom.StaticMeshes[i].MeshID, @@ -439,16 +415,16 @@ public override void ApplyToLevel(TR3Level level) X = (uint)(baseRoom.StaticMeshes[i].X + xdiff), Y = (uint)(baseRoom.StaticMeshes[i].Y + ydiff), Z = (uint)(baseRoom.StaticMeshes[i].Z + zdiff) - }; + }); } // Rebuild the sectors FDControl floorData = new(); floorData.ParseFromLevel(level); - for (int i = 0; i < newRoom.Sectors.Length; i++) + for (int i = 0; i < baseRoom.Sectors.Count; i++) { - newRoom.Sectors[i] = RebuildSector(baseRoom.Sectors[i], i, floorData, ydiff, baseRoom.Info); + newRoom.Sectors.Add(RebuildSector(baseRoom.Sectors[i], i, floorData, ydiff, baseRoom.Info)); } floorData.WriteToLevel(level); diff --git a/TREnvironmentEditor/Model/Types/Rooms/EMCreateRoomFunction.cs b/TREnvironmentEditor/Model/Types/Rooms/EMCreateRoomFunction.cs index 563b290e0..267ab2e5d 100644 --- a/TREnvironmentEditor/Model/Types/Rooms/EMCreateRoomFunction.cs +++ b/TREnvironmentEditor/Model/Types/Rooms/EMCreateRoomFunction.cs @@ -29,51 +29,43 @@ public override void ApplyToLevel(TR1Level level) NumZSectors = Depth, AlternateRoom = -1, AmbientIntensity = AmbientLighting, - NumLights = (ushort)(Lights == null ? 0 : Lights.Length), - NumPortals = 0, - NumStaticMeshes = 0, - Portals = Array.Empty(), - StaticMeshes = Array.Empty(), - Info = new TRRoomInfo + Portals = new(), + StaticMeshes = new(), + Info = new() { X = Location.X, YBottom = Location.Y, YTop = Location.Y - Height * TRConsts.Step1, Z = Location.Z }, - RoomData = new TR1RoomData + RoomData = new() { - // Ignored for now - NumSprites = 0, - NumTriangles = 0, - Sprites = Array.Empty(), - Triangles = Array.Empty(), - } + Rectangles = new(), + Triangles = new(), + Vertices = new(), + Sprites = new(), + }, + Lights = new() }; - room.Lights = new TR1RoomLight[room.NumLights]; - for (int i = 0; i < room.NumLights; i++) + for (int i = 0; i < Lights?.Length; i++) { EMRoomLight light = Lights[i]; - room.Lights[i] = new TR1RoomLight + room.Lights.Add(new() { X = light.X + Location.X, Y = light.Y + Location.Y, Z = light.Z + Location.Z, Fade = light.Fade1, Intensity = light.Intensity1 - }; + }); } sbyte ceiling = (sbyte)(room.Info.YTop / TRConsts.Step1); sbyte floor = (sbyte)(room.Info.YBottom / TRConsts.Step1); - List faces = new(); - List vertices = new(); - // Make the sectors first - List sectors = GenerateSectors(ceiling, floor); - room.Sectors = sectors.ToArray(); + room.Sectors = GenerateSectors(ceiling, floor); // Generate the box, zone and overlap data FDControl floorData = new(); @@ -84,19 +76,14 @@ public override void ApplyToLevel(TR1Level level) BoxGenerator.Generate(room, level, linkedSector); // Stride the sectors again and make faces - GenerateFaces(sectors, faces, vertices); + List vertices = new(); + GenerateFaces(room.Sectors, room.RoomData.Rectangles, vertices); - // Write it all to the room - room.RoomData.NumRectangles = (short)faces.Count; - room.RoomData.NumVertices = (short)vertices.Count; - room.RoomData.Rectangles = faces.ToArray(); - room.RoomData.Vertices = vertices.Select(v => new TR1RoomVertex + room.RoomData.Vertices.AddRange(vertices.Select(v => new TR1RoomVertex { Lighting = DefaultVertex.Lighting, Vertex = v - }).ToArray(); - - room.NumDataWords = (uint)(room.RoomData.Serialize().Length / 2); + })); level.Rooms.Add(room); } @@ -109,33 +96,29 @@ public override void ApplyToLevel(TR2Level level) NumZSectors = Depth, AlternateRoom = -1, AmbientIntensity = AmbientLighting, - NumLights = (ushort)(Lights == null ? 0 : Lights.Length), - NumPortals = 0, - NumStaticMeshes = 0, - Portals = Array.Empty(), - StaticMeshes = Array.Empty(), - Info = new TRRoomInfo + Portals = new(), + StaticMeshes = new(), + Info = new() { X = Location.X, YBottom = Location.Y, YTop = Location.Y - Height * TRConsts.Step1, Z = Location.Z }, - RoomData = new TR2RoomData + RoomData = new() { - // Ignored for now - NumSprites = 0, - NumTriangles = 0, - Sprites = Array.Empty(), - Triangles = Array.Empty(), - } + Rectangles = new(), + Triangles = new(), + Vertices = new(), + Sprites = new(), + }, + Lights = new() }; - room.Lights = new TR2RoomLight[room.NumLights]; - for (int i = 0; i < room.NumLights; i++) + for (int i = 0; i < Lights?.Length; i++) { EMRoomLight light = Lights[i]; - room.Lights[i] = new TR2RoomLight + room.Lights.Add(new() { X = light.X + Location.X, Y = light.Y + Location.Y, @@ -144,18 +127,14 @@ public override void ApplyToLevel(TR2Level level) Fade2 = light.Fade2, Intensity1 = light.Intensity1, Intensity2 = light.Intensity2, - }; + }); } sbyte ceiling = (sbyte)(room.Info.YTop / TRConsts.Step1); sbyte floor = (sbyte)(room.Info.YBottom / TRConsts.Step1); - List faces = new(); - List vertices = new(); - // Make the sectors first - List sectors = GenerateSectors(ceiling, floor); - room.SectorList = sectors.ToArray(); + room.Sectors = GenerateSectors(ceiling, floor); // Generate the box, zone and overlap data FDControl floorData = new(); @@ -166,21 +145,16 @@ public override void ApplyToLevel(TR2Level level) BoxGenerator.Generate(room, level, linkedSector); // Stride the sectors again and make faces - GenerateFaces(sectors, faces, vertices); + List vertices = new(); + GenerateFaces(room.Sectors, room.RoomData.Rectangles, vertices); - // Write it all to the room - room.RoomData.NumRectangles = (short)faces.Count; - room.RoomData.NumVertices = (short)vertices.Count; - room.RoomData.Rectangles = faces.ToArray(); - room.RoomData.Vertices = vertices.Select(v => new TR2RoomVertex + room.RoomData.Vertices.AddRange(vertices.Select(v => new TR2RoomVertex { Lighting = DefaultVertex.Lighting, Lighting2 = DefaultVertex.Lighting2, Attributes = DefaultVertex.Attributes, Vertex = v - }).ToArray(); - - room.NumDataWords = (uint)(room.RoomData.Serialize().Length / 2); + })); level.Rooms.Add(room); } @@ -193,33 +167,29 @@ public override void ApplyToLevel(TR3Level level) NumZSectors = Depth, AlternateRoom = -1, AmbientIntensity = AmbientLighting, - NumLights = (ushort)(Lights == null ? 0 : Lights.Length), - NumPortals = 0, - NumStaticMeshes = 0, - Portals = Array.Empty(), - StaticMeshes = Array.Empty(), - Info = new TRRoomInfo + Portals = new(), + StaticMeshes = new(), + Info = new() { X = Location.X, YBottom = Location.Y, YTop = Location.Y - Height * TRConsts.Step1, Z = Location.Z }, - RoomData = new TR3RoomData + RoomData = new() { - // Ignored for now - NumSprites = 0, - NumTriangles = 0, - Sprites = Array.Empty(), - Triangles = Array.Empty(), - } + Rectangles = new(), + Triangles = new(), + Vertices = new(), + Sprites = new(), + }, + Lights = new() }; - room.Lights = new TR3RoomLight[room.NumLights]; - for (int i = 0; i < room.NumLights; i++) + for (int i = 0; i < Lights?.Length; i++) { EMRoomLight light = Lights[i]; - room.Lights[i] = new TR3RoomLight + room.Lights.Add(new() { X = light.X + Location.X, Y = light.Y + Location.Y, @@ -227,18 +197,14 @@ public override void ApplyToLevel(TR3Level level) Colour = light.Colour, LightProperties = light.LightProperties, LightType = light.LightType, - }; + }); } sbyte ceiling = (sbyte)(room.Info.YTop / TRConsts.Step1); sbyte floor = (sbyte)(room.Info.YBottom / TRConsts.Step1); - List faces = new(); - List vertices = new(); - // Make the sectors first - List sectors = GenerateSectors(ceiling, floor); - room.Sectors = sectors.ToArray(); + room.Sectors = GenerateSectors(ceiling, floor); // Generate the box, zone and overlap data FDControl floorData = new(); @@ -249,21 +215,16 @@ public override void ApplyToLevel(TR3Level level) BoxGenerator.Generate(room, level, linkedSector); // Stride the sectors again and make faces - GenerateFaces(sectors, faces, vertices); + List vertices = new(); + GenerateFaces(room.Sectors, room.RoomData.Rectangles, vertices); - // Write it all to the room - room.RoomData.NumRectangles = (short)faces.Count; - room.RoomData.NumVertices = (short)vertices.Count; - room.RoomData.Rectangles = faces.ToArray(); - room.RoomData.Vertices = vertices.Select(v => new TR3RoomVertex + room.RoomData.Vertices.AddRange(vertices.Select(v => new TR3RoomVertex { Lighting = DefaultVertex.Lighting, Attributes = DefaultVertex.Attributes, Colour = DefaultVertex.Colour, Vertex = v - }).ToArray(); - - room.NumDataWords = (uint)(room.RoomData.Serialize().Length / 2); + })); level.Rooms.Add(room); } diff --git a/TREnvironmentEditor/Model/Types/Rooms/EMGenerateLightFunction.cs b/TREnvironmentEditor/Model/Types/Rooms/EMGenerateLightFunction.cs index 0829bddcf..7e597cdab 100644 --- a/TREnvironmentEditor/Model/Types/Rooms/EMGenerateLightFunction.cs +++ b/TREnvironmentEditor/Model/Types/Rooms/EMGenerateLightFunction.cs @@ -14,7 +14,7 @@ public override void ApplyToLevel(TR1Level level) foreach (short roomIndex in RoomIndices) { TR1Room room = level.Rooms[data.ConvertRoom(roomIndex)]; - if (room.NumLights == 0) + if (room.Lights.Count == 0) { continue; } @@ -54,7 +54,7 @@ public override void ApplyToLevel(TR2Level level) foreach (short roomIndex in RoomIndices) { TR2Room room = level.Rooms[data.ConvertRoom(roomIndex)]; - if (room.NumLights == 0) + if (room.Lights.Count == 0) { continue; } @@ -95,7 +95,7 @@ public override void ApplyToLevel(TR3Level level) foreach (short roomIndex in RoomIndices) { TR3Room room = level.Rooms[data.ConvertRoom(roomIndex)]; - if (room.NumLights == 0) + if (room.Lights.Count == 0) { continue; } diff --git a/TREnvironmentEditor/Model/Types/Rooms/EMImportRoomFunction.cs b/TREnvironmentEditor/Model/Types/Rooms/EMImportRoomFunction.cs index 6e54c1900..ef1a76a47 100644 --- a/TREnvironmentEditor/Model/Types/Rooms/EMImportRoomFunction.cs +++ b/TREnvironmentEditor/Model/Types/Rooms/EMImportRoomFunction.cs @@ -50,54 +50,46 @@ public override void ApplyToLevel(TR2Level level) AmbientIntensity = roomDef.Room.AmbientIntensity, AmbientIntensity2 = roomDef.Room.AmbientIntensity2, Flags = roomDef.Room.Flags, - Info = new TRRoomInfo + Info = new() { X = NewLocation.X, YBottom = NewLocation.Y, YTop = NewLocation.Y + (roomDef.Room.Info.YTop - roomDef.Room.Info.YBottom), Z = NewLocation.Z }, - Lights = new TR2RoomLight[roomDef.Room.NumLights], + Lights = new(), LightMode = roomDef.Room.LightMode, - NumDataWords = roomDef.Room.NumDataWords, - NumLights = roomDef.Room.NumLights, - NumPortals = PreservePortals ? roomDef.Room.NumPortals : (ushort)0, - NumStaticMeshes = roomDef.Room.NumStaticMeshes, NumXSectors = roomDef.Room.NumXSectors, NumZSectors = roomDef.Room.NumZSectors, - Portals = new TRRoomPortal[PreservePortals ? roomDef.Room.NumPortals : 0], - RoomData = new TR2RoomData + Portals = new(), + RoomData = new() { - NumRectangles = roomDef.Room.RoomData.NumRectangles, - NumSprites = roomDef.Room.RoomData.NumSprites, - NumTriangles = roomDef.Room.RoomData.NumTriangles, - NumVertices = roomDef.Room.RoomData.NumVertices, - Rectangles = new TRFace4[roomDef.Room.RoomData.NumRectangles], - Sprites = new TRRoomSprite[roomDef.Room.RoomData.NumSprites], - Triangles = new TRFace3[roomDef.Room.RoomData.NumTriangles], - Vertices = new TR2RoomVertex[roomDef.Room.RoomData.NumVertices] + Rectangles = new(), + Triangles = new(), + Vertices = new(), + Sprites = new(), }, - SectorList = new TRRoomSector[roomDef.Room.SectorList.Length], - StaticMeshes = new TR2RoomStaticMesh[roomDef.Room.NumStaticMeshes] + Sectors = new(), + StaticMeshes = new() }; if (PreservePortals) { - for (int i = 0; i < newRoom.Portals.Length; i++) + for (int i = 0; i < roomDef.Room.Portals.Count; i++) { - newRoom.Portals[i] = new TRRoomPortal + newRoom.Portals.Add(new() { AdjoiningRoom = roomDef.Room.Portals[i].AdjoiningRoom, Normal = roomDef.Room.Portals[i].Normal, Vertices = roomDef.Room.Portals[i].Vertices - }; + }); } } // Lights - for (int i = 0; i < newRoom.Lights.Length; i++) + for (int i = 0; i < roomDef.Room.Lights.Count; i++) { - newRoom.Lights[i] = new TR2RoomLight + newRoom.Lights.Add(new() { Fade1 = roomDef.Room.Lights[i].Fade1, Fade2 = roomDef.Room.Lights[i].Fade2, @@ -106,30 +98,30 @@ public override void ApplyToLevel(TR2Level level) X = roomDef.Room.Lights[i].X + xdiff, Y = roomDef.Room.Lights[i].Y + ydiff, Z = roomDef.Room.Lights[i].Z + zdiff - }; + }); } // Faces - for (int i = 0; i < newRoom.RoomData.NumRectangles; i++) + for (int i = 0; i < roomDef.Room.RoomData.Rectangles.Count; i++) { - newRoom.RoomData.Rectangles[i] = new TRFace4 + newRoom.RoomData.Rectangles.Add(new() { Texture = RectangleTexture == ushort.MaxValue ? roomDef.Room.RoomData.Rectangles[i].Texture : RectangleTexture, Vertices = new ushort[roomDef.Room.RoomData.Rectangles[i].Vertices.Length] - }; + }); for (int j = 0; j < newRoom.RoomData.Rectangles[i].Vertices.Length; j++) { newRoom.RoomData.Rectangles[i].Vertices[j] = roomDef.Room.RoomData.Rectangles[i].Vertices[j]; } } - for (int i = 0; i < newRoom.RoomData.NumTriangles; i++) + for (int i = 0; i < roomDef.Room.RoomData.Triangles.Count; i++) { - newRoom.RoomData.Triangles[i] = new TRFace3 + newRoom.RoomData.Triangles.Add(new() { Texture = TriangleTexture == ushort.MaxValue ? roomDef.Room.RoomData.Triangles[i].Texture : TriangleTexture, Vertices = new ushort[roomDef.Room.RoomData.Triangles[i].Vertices.Length] - }; + }); for (int j = 0; j < newRoom.RoomData.Triangles[i].Vertices.Length; j++) { newRoom.RoomData.Triangles[i].Vertices[j] = roomDef.Room.RoomData.Triangles[i].Vertices[j]; @@ -137,36 +129,36 @@ public override void ApplyToLevel(TR2Level level) } // Vertices - for (int i = 0; i < newRoom.RoomData.Vertices.Length; i++) + for (int i = 0; i < roomDef.Room.RoomData.Vertices.Count; i++) { - newRoom.RoomData.Vertices[i] = new TR2RoomVertex + newRoom.RoomData.Vertices.Add(new() { Attributes = roomDef.Room.RoomData.Vertices[i].Attributes, Lighting = roomDef.Room.RoomData.Vertices[i].Lighting, Lighting2 = roomDef.Room.RoomData.Vertices[i].Lighting2, - Vertex = new TRVertex + Vertex = new() { X = roomDef.Room.RoomData.Vertices[i].Vertex.X, // Room coords for X and Z Y = (short)(roomDef.Room.RoomData.Vertices[i].Vertex.Y + ydiff), Z = roomDef.Room.RoomData.Vertices[i].Vertex.Z } - }; + }); } // Sprites - for (int i = 0; i < newRoom.RoomData.NumSprites; i++) + for (int i = 0; i < roomDef.Room.RoomData.Sprites.Count; i++) { - newRoom.RoomData.Sprites[i] = new TRRoomSprite + newRoom.RoomData.Sprites.Add(new() { Texture = roomDef.Room.RoomData.Sprites[i].Texture, Vertex = roomDef.Room.RoomData.Sprites[i].Vertex - }; + }); } // Static Meshes - for (int i = 0; i < newRoom.NumStaticMeshes; i++) + for (int i = 0; i < roomDef.Room.StaticMeshes.Count; i++) { - newRoom.StaticMeshes[i] = new TR2RoomStaticMesh + newRoom.StaticMeshes.Add(new() { Intensity1 = roomDef.Room.StaticMeshes[i].Intensity1, Intensity2 = roomDef.Room.StaticMeshes[i].Intensity2, @@ -175,7 +167,7 @@ public override void ApplyToLevel(TR2Level level) X = (uint)(roomDef.Room.StaticMeshes[i].X + xdiff), Y = (uint)(roomDef.Room.StaticMeshes[i].Y + ydiff), Z = (uint)(roomDef.Room.StaticMeshes[i].Z + zdiff) - }; + }); } // Boxes, zones and sectors @@ -216,12 +208,12 @@ public override void ApplyToLevel(TR2Level level) TR2BoxUtilities.UpdateOverlaps(level, box, new List { (ushort)linkedBoxIndex }); } - for (int i = 0; i < newRoom.SectorList.Length; i++) + for (int i = 0; i < roomDef.Room.Sectors.Count; i++) { int sectorYDiff = 0; - ushort sectorBoxIndex = roomDef.Room.SectorList[i].BoxIndex; + ushort sectorBoxIndex = roomDef.Room.Sectors[i].BoxIndex; // Only change the sector if it's not impenetrable and we don't want to preserve the existing zoning - if (roomDef.Room.SectorList[i].Ceiling != TRConsts.WallClicks || roomDef.Room.SectorList[i].Floor != TRConsts.WallClicks) + if (roomDef.Room.Sectors[i].Ceiling != TRConsts.WallClicks || roomDef.Room.Sectors[i].Floor != TRConsts.WallClicks) { sectorYDiff = ydiff / TRConsts.Step1; if (!PreserveBoxes) @@ -230,19 +222,19 @@ public override void ApplyToLevel(TR2Level level) } } - newRoom.SectorList[i] = new TRRoomSector + newRoom.Sectors.Add(new() { BoxIndex = sectorBoxIndex, - Ceiling = (sbyte)(roomDef.Room.SectorList[i].Ceiling + sectorYDiff), + Ceiling = (sbyte)(roomDef.Room.Sectors[i].Ceiling + sectorYDiff), FDIndex = 0, // Initialise to no FD - Floor = (sbyte)(roomDef.Room.SectorList[i].Floor + sectorYDiff), - RoomAbove = PreservePortals ? roomDef.Room.SectorList[i].RoomAbove : (byte)TRConsts.NoRoom, - RoomBelow = PreservePortals ? roomDef.Room.SectorList[i].RoomBelow : (byte)TRConsts.NoRoom - }; + Floor = (sbyte)(roomDef.Room.Sectors[i].Floor + sectorYDiff), + RoomAbove = PreservePortals ? roomDef.Room.Sectors[i].RoomAbove : (byte)TRConsts.NoRoom, + RoomBelow = PreservePortals ? roomDef.Room.Sectors[i].RoomBelow : (byte)TRConsts.NoRoom + }); // Duplicate the FD too for everything except triggers. Track any portals // so they can be blocked off. - ushort fdIndex = roomDef.Room.SectorList[i].FDIndex; + ushort fdIndex = roomDef.Room.Sectors[i].FDIndex; if (roomDef.FloorData.ContainsKey(fdIndex)) { List entries = roomDef.FloorData[fdIndex]; @@ -254,7 +246,7 @@ public override void ApplyToLevel(TR2Level level) case FDFunctions.PortalSector: // This portal will no longer be valid in the new room's position, // so block off the wall - newRoom.SectorList[i].Floor = newRoom.SectorList[i].Ceiling = TRConsts.WallClicks; + newRoom.Sectors[i].Floor = newRoom.Sectors[i].Ceiling = TRConsts.WallClicks; break; case FDFunctions.FloorSlant: FDSlantEntry slantEntry = entry as FDSlantEntry; @@ -291,8 +283,8 @@ public override void ApplyToLevel(TR2Level level) if (newEntries.Count > 0) { - floorData.CreateFloorData(newRoom.SectorList[i]); - floorData.Entries[newRoom.SectorList[i].FDIndex].AddRange(newEntries); + floorData.CreateFloorData(newRoom.Sectors[i]); + floorData.Entries[newRoom.Sectors[i].FDIndex].AddRange(newEntries); } } } @@ -329,36 +321,28 @@ public override void ApplyToLevel(TR3Level level) YTop = NewLocation.Y + (roomDef.Room.Info.YTop - roomDef.Room.Info.YBottom), Z = NewLocation.Z }, - Lights = new TR3RoomLight[roomDef.Room.NumLights], + Lights = new(), LightMode = roomDef.Room.LightMode, - NumDataWords = roomDef.Room.NumDataWords, - NumLights = roomDef.Room.NumLights, - NumPortals = 0, - NumStaticMeshes = roomDef.Room.NumStaticMeshes, NumXSectors = roomDef.Room.NumXSectors, NumZSectors = roomDef.Room.NumZSectors, - Portals = Array.Empty(), + Portals = new(), ReverbInfo = roomDef.Room.ReverbInfo, - RoomData = new TR3RoomData + RoomData = new() { - NumRectangles = roomDef.Room.RoomData.NumRectangles, - NumSprites = roomDef.Room.RoomData.NumSprites, - NumTriangles = roomDef.Room.RoomData.NumTriangles, - NumVertices = roomDef.Room.RoomData.NumVertices, - Rectangles = new TRFace4[roomDef.Room.RoomData.NumRectangles], - Sprites = new TRRoomSprite[roomDef.Room.RoomData.NumSprites], - Triangles = new TRFace3[roomDef.Room.RoomData.NumTriangles], - Vertices = new TR3RoomVertex[roomDef.Room.RoomData.NumVertices] + Rectangles = new(), + Triangles = new(), + Vertices = new(), + Sprites = new(), }, - Sectors = new TRRoomSector[roomDef.Room.Sectors.Length], - StaticMeshes = new TR3RoomStaticMesh[roomDef.Room.NumStaticMeshes], + Sectors = new(), + StaticMeshes = new(), WaterScheme = roomDef.Room.WaterScheme }; // Lights - for (int i = 0; i < newRoom.Lights.Length; i++) + for (int i = 0; i < roomDef.Room.Lights.Count; i++) { - newRoom.Lights[i] = new TR3RoomLight + newRoom.Lights.Add(new() { Colour = roomDef.Room.Lights[i].Colour, LightProperties = roomDef.Room.Lights[i].LightProperties, @@ -366,30 +350,30 @@ public override void ApplyToLevel(TR3Level level) X = roomDef.Room.Lights[i].X + xdiff, Y = roomDef.Room.Lights[i].Y + ydiff, Z = roomDef.Room.Lights[i].Z + zdiff - }; + }); } // Faces - for (int i = 0; i < newRoom.RoomData.NumRectangles; i++) + for (int i = 0; i < roomDef.Room.RoomData.Rectangles.Count; i++) { - newRoom.RoomData.Rectangles[i] = new TRFace4 + newRoom.RoomData.Rectangles.Add(new() { Texture = RectangleTexture == ushort.MaxValue ? roomDef.Room.RoomData.Rectangles[i].Texture : RectangleTexture, Vertices = new ushort[roomDef.Room.RoomData.Rectangles[i].Vertices.Length] - }; + }); for (int j = 0; j < newRoom.RoomData.Rectangles[i].Vertices.Length; j++) { newRoom.RoomData.Rectangles[i].Vertices[j] = roomDef.Room.RoomData.Rectangles[i].Vertices[j]; } } - for (int i = 0; i < newRoom.RoomData.NumTriangles; i++) + for (int i = 0; i < roomDef.Room.RoomData.Triangles.Count; i++) { - newRoom.RoomData.Triangles[i] = new TRFace3 + newRoom.RoomData.Triangles.Add(new() { Texture = TriangleTexture == ushort.MaxValue ? roomDef.Room.RoomData.Triangles[i].Texture : TriangleTexture, Vertices = new ushort[roomDef.Room.RoomData.Triangles[i].Vertices.Length] - }; + }); for (int j = 0; j < newRoom.RoomData.Triangles[i].Vertices.Length; j++) { newRoom.RoomData.Triangles[i].Vertices[j] = roomDef.Room.RoomData.Triangles[i].Vertices[j]; @@ -397,9 +381,9 @@ public override void ApplyToLevel(TR3Level level) } // Vertices - for (int i = 0; i < newRoom.RoomData.Vertices.Length; i++) + for (int i = 0; i < roomDef.Room.RoomData.Vertices.Count; i++) { - newRoom.RoomData.Vertices[i] = new TR3RoomVertex + newRoom.RoomData.Vertices.Add(new() { Attributes = roomDef.Room.RoomData.Vertices[i].Attributes, Colour = roomDef.Room.RoomData.Vertices[i].Colour, @@ -410,23 +394,23 @@ public override void ApplyToLevel(TR3Level level) Y = (short)(roomDef.Room.RoomData.Vertices[i].Vertex.Y + ydiff), Z = roomDef.Room.RoomData.Vertices[i].Vertex.Z } - }; + }); } // Sprites - for (int i = 0; i < newRoom.RoomData.NumSprites; i++) + for (int i = 0; i < roomDef.Room.RoomData.Sprites.Count; i++) { - newRoom.RoomData.Sprites[i] = new TRRoomSprite + newRoom.RoomData.Sprites.Add(new() { Texture = roomDef.Room.RoomData.Sprites[i].Texture, Vertex = roomDef.Room.RoomData.Sprites[i].Vertex - }; + }); } // Static Meshes - for (int i = 0; i < newRoom.NumStaticMeshes; i++) + for (int i = 0; i < roomDef.Room.StaticMeshes.Count; i++) { - newRoom.StaticMeshes[i] = new TR3RoomStaticMesh + newRoom.StaticMeshes.Add(new() { Colour = roomDef.Room.StaticMeshes[i].Colour, MeshID = roomDef.Room.StaticMeshes[i].MeshID, @@ -435,7 +419,7 @@ public override void ApplyToLevel(TR3Level level) X = (uint)(roomDef.Room.StaticMeshes[i].X + xdiff), Y = (uint)(roomDef.Room.StaticMeshes[i].Y + ydiff), Z = (uint)(roomDef.Room.StaticMeshes[i].Z + zdiff) - }; + }); } // Boxes, zones and sectors @@ -483,7 +467,7 @@ public override void ApplyToLevel(TR3Level level) newBoxIndex <<= 4; newBoxIndex |= (ushort)linkedMaterial; - for (int i = 0; i < newRoom.Sectors.Length; i++) + for (int i = 0; i < newRoom.Sectors.Count; i++) { int sectorYDiff = 0; ushort sectorBoxIndex = roomDef.Room.Sectors[i].BoxIndex; diff --git a/TREnvironmentEditor/Model/Types/Surfaces/BaseWaterFunction.cs b/TREnvironmentEditor/Model/Types/Surfaces/BaseWaterFunction.cs index 7d501d4e2..2d36a2b92 100644 --- a/TREnvironmentEditor/Model/Types/Surfaces/BaseWaterFunction.cs +++ b/TREnvironmentEditor/Model/Types/Surfaces/BaseWaterFunction.cs @@ -18,10 +18,7 @@ public void AddWaterSurface(TR1Room room, bool asCeiling, IEnumerable adjac return; } - List vertices = room.RoomData.Vertices.ToList(); - List rectangles = room.RoomData.Rectangles.ToList(); - - for (int i = 0; i < room.Sectors.Length; i++) + for (int i = 0; i < room.Sectors.Count; i++) { TRRoomSector sector = room.Sectors[i]; @@ -41,7 +38,7 @@ public void AddWaterSurface(TR1Room room, bool asCeiling, IEnumerable adjac for (int k = 0; k < defaultVerts.Count; k++) { TRVertex vert = defaultVerts[k]; - int vi = vertices.FindIndex(v => v.Vertex.X == vert.X && v.Vertex.Z == vert.Z && v.Vertex.Y == vert.Y); + int vi = room.RoomData.Vertices.FindIndex(v => v.Vertex.X == vert.X && v.Vertex.Z == vert.Z && v.Vertex.Y == vert.Y); if (vi == -1) { vi = CreateRoomVertex(room, vert); @@ -53,19 +50,13 @@ public void AddWaterSurface(TR1Room room, bool asCeiling, IEnumerable adjac vertIndices.Add((ushort)vi); } - rectangles.Add(new TRFace4 + room.RoomData.Rectangles.Add(new() { Texture = WaterTextures[0], Vertices = vertIndices.ToArray() }); } } - - room.RoomData.Rectangles = rectangles.ToArray(); - room.RoomData.NumRectangles = (short)rectangles.Count; - - // Account for the added faces - room.NumDataWords = (uint)(room.RoomData.Serialize().Length / 2); } public void AddWaterSurface(TR2Room room, bool asCeiling, IEnumerable adjacentRooms) @@ -76,12 +67,9 @@ public void AddWaterSurface(TR2Room room, bool asCeiling, IEnumerable adjac return; } - List vertices = room.RoomData.Vertices.ToList(); - List rectangles = room.RoomData.Rectangles.ToList(); - - for (int i = 0; i < room.SectorList.Length; i++) + for (int i = 0; i < room.Sectors.Count; i++) { - TRRoomSector sector = room.SectorList[i]; + TRRoomSector sector = room.Sectors[i]; bool ceilingMatch = asCeiling && adjacentRooms.Contains(sector.RoomAbove); bool floorMatch = !asCeiling && adjacentRooms.Contains(sector.RoomBelow); @@ -99,7 +87,7 @@ public void AddWaterSurface(TR2Room room, bool asCeiling, IEnumerable adjac for (int k = 0; k < defaultVerts.Count; k++) { TRVertex vert = defaultVerts[k]; - int vi = vertices.FindIndex(v => v.Vertex.X == vert.X && v.Vertex.Z == vert.Z && v.Vertex.Y == vert.Y); + int vi = room.RoomData.Vertices.FindIndex(v => v.Vertex.X == vert.X && v.Vertex.Z == vert.Z && v.Vertex.Y == vert.Y); if (vi == -1) { vi = CreateRoomVertex(room, vert); @@ -112,19 +100,13 @@ public void AddWaterSurface(TR2Room room, bool asCeiling, IEnumerable adjac vertIndices.Add((ushort)vi); } - rectangles.Add(new TRFace4 + room.RoomData.Rectangles.Add(new() { Texture = WaterTextures[0], Vertices = vertIndices.ToArray() }); } } - - room.RoomData.Rectangles = rectangles.ToArray(); - room.RoomData.NumRectangles = (short)rectangles.Count; - - // Account for the added faces - room.NumDataWords = (uint)(room.RoomData.Serialize().Length / 2); } public void AddWaterSurface(TR3Room room, bool asCeiling, IEnumerable adjacentRooms, FDControl floorData) @@ -135,11 +117,8 @@ public void AddWaterSurface(TR3Room room, bool asCeiling, IEnumerable adjac return; } - List vertices = room.RoomData.Vertices.ToList(); - List rectangles = room.RoomData.Rectangles.ToList(); - int count = 0; - for (int i = 0; i < room.Sectors.Length; i++) + for (int i = 0; i < room.Sectors.Count; i++) { TRRoomSector sector = room.Sectors[i]; @@ -161,65 +140,36 @@ public void AddWaterSurface(TR3Room room, bool asCeiling, IEnumerable adjac for (int k = 0; k < defaultVerts.Count; k++) { TRVertex vert = defaultVerts[k]; - int vi = vertices.FindIndex(v => v.Vertex.X == vert.X && v.Vertex.Z == vert.Z && v.Vertex.Y == vert.Y); + int vi = room.RoomData.Vertices.FindIndex(v => v.Vertex.X == vert.X && v.Vertex.Z == vert.Z && v.Vertex.Y == vert.Y); if (vi == -1) { vi = CreateRoomVertex(room, vert, useCaustics:true, useWaveMovement:true); } - else - { - TR3RoomVertex exVert = room.RoomData.Vertices[vi]; - //exVert.Attributes = 32784; // Stop the shimmering - } vertIndices.Add((ushort)vi); } - rectangles.Add(new TRFace4 + room.RoomData.Rectangles.Add(new() { Texture = (ushort)(WaterTextures[count++ % WaterTextures.Length] | 0x8000), // Cycle through the textures and make them double-sided Vertices = vertIndices.ToArray() }); } } - - room.RoomData.Rectangles = rectangles.ToArray(); - room.RoomData.NumRectangles = (short)rectangles.Count; - - // Account for the added faces - room.NumDataWords = (uint)(room.RoomData.Serialize().Length / 2); } public void RemoveWaterSurface(TR1Room room) { - List rs = room.RoomData.Rectangles.ToList(); - RemoveWaterSurfaces(rs); - - room.RoomData.Rectangles = rs.ToArray(); - room.RoomData.NumRectangles = (short)rs.Count; - - room.NumDataWords = (uint)(room.RoomData.Serialize().Length / 2); + RemoveWaterSurfaces(room.RoomData.Rectangles); } public void RemoveWaterSurface(TR2Room room) { - List rs = room.RoomData.Rectangles.ToList(); - RemoveWaterSurfaces(rs); - - room.RoomData.Rectangles = rs.ToArray(); - room.RoomData.NumRectangles = (short)rs.Count; - - room.NumDataWords = (uint)(room.RoomData.Serialize().Length / 2); + RemoveWaterSurfaces(room.RoomData.Rectangles); } public void RemoveWaterSurface(TR3Room room) { - List rs = room.RoomData.Rectangles.ToList(); - RemoveWaterSurfaces(rs); - - room.RoomData.Rectangles = rs.ToArray(); - room.RoomData.NumRectangles = (short)rs.Count; - - room.NumDataWords = (uint)(room.RoomData.Serialize().Length / 2); + RemoveWaterSurfaces(room.RoomData.Rectangles); } public void RemoveWaterSurfaces(List faces) diff --git a/TREnvironmentEditor/Model/Types/Surfaces/EMCeilingFunction.cs b/TREnvironmentEditor/Model/Types/Surfaces/EMCeilingFunction.cs index b5cb8ec3e..c90c790e3 100644 --- a/TREnvironmentEditor/Model/Types/Surfaces/EMCeilingFunction.cs +++ b/TREnvironmentEditor/Model/Types/Surfaces/EMCeilingFunction.cs @@ -48,7 +48,7 @@ public override void ApplyToLevel(TR2Level level) TR2Room room = level.Rooms[data.ConvertRoom(roomNumber)]; int oldYTop = room.Info.YTop; int min = int.MaxValue; - foreach (TRRoomSector sector in room.SectorList) + foreach (TRRoomSector sector in room.Sectors) { if (!sector.IsWall) { diff --git a/TREnvironmentEditor/Model/Types/Surfaces/EMDrainFunction.cs b/TREnvironmentEditor/Model/Types/Surfaces/EMDrainFunction.cs index 49025ca76..da67fea7b 100644 --- a/TREnvironmentEditor/Model/Types/Surfaces/EMDrainFunction.cs +++ b/TREnvironmentEditor/Model/Types/Surfaces/EMDrainFunction.cs @@ -14,7 +14,7 @@ public override void ApplyToLevel(TR1Level level) foreach (int roomNumber in RoomNumbers) { - level.Rooms[data.ConvertRoom(roomNumber)].Drain(); + level.Rooms[data.ConvertRoom(roomNumber)].ContainsWater = false; } foreach (int roomNumber in RoomNumbers) @@ -53,7 +53,7 @@ public override void ApplyToLevel(TR2Level level) // determining which rooms have water. foreach (int roomNumber in RoomNumbers) { - level.Rooms[data.ConvertRoom(roomNumber)].Drain(); + level.Rooms[data.ConvertRoom(roomNumber)].ContainsWater = false; } // Work out rooms above and below and what needs water textures as ceilings @@ -62,7 +62,7 @@ public override void ApplyToLevel(TR2Level level) { TR2Room room = level.Rooms[data.ConvertRoom(roomNumber)]; - ISet roomsBelow = GetAdjacentRooms(room.SectorList, false); + ISet roomsBelow = GetAdjacentRooms(room.Sectors, false); foreach (byte roomBelowNumber in roomsBelow) { TR2Room roomBelow = level.Rooms[roomBelowNumber]; @@ -73,7 +73,7 @@ public override void ApplyToLevel(TR2Level level) } } - ISet roomsAbove = GetAdjacentRooms(room.SectorList, true); + ISet roomsAbove = GetAdjacentRooms(room.Sectors, true); foreach (byte roomAboveNumber in roomsAbove) { TR2Room roomAbove = level.Rooms[roomAboveNumber]; diff --git a/TREnvironmentEditor/Model/Types/Surfaces/EMFloodFunction.cs b/TREnvironmentEditor/Model/Types/Surfaces/EMFloodFunction.cs index 71607399d..b104556d8 100644 --- a/TREnvironmentEditor/Model/Types/Surfaces/EMFloodFunction.cs +++ b/TREnvironmentEditor/Model/Types/Surfaces/EMFloodFunction.cs @@ -14,7 +14,7 @@ public override void ApplyToLevel(TR1Level level) // determining which rooms have water. foreach (int roomNumber in RoomNumbers) { - level.Rooms[data.ConvertRoom(roomNumber)].Fill(); + level.Rooms[data.ConvertRoom(roomNumber)].ContainsWater = true; } // Work out rooms above and below and what needs water textures as ceilings @@ -55,7 +55,7 @@ public override void ApplyToLevel(TR2Level level) // determining which rooms have water. foreach (int roomNumber in RoomNumbers) { - level.Rooms[data.ConvertRoom(roomNumber)].Fill(); + level.Rooms[data.ConvertRoom(roomNumber)].ContainsWater = true; } // Work out rooms above and below and what needs water textures as ceilings @@ -64,7 +64,7 @@ public override void ApplyToLevel(TR2Level level) { TR2Room room = level.Rooms[data.ConvertRoom(roomNumber)]; - ISet roomsBelow = GetAdjacentRooms(room.SectorList, false); + ISet roomsBelow = GetAdjacentRooms(room.Sectors, false); foreach (byte roomBelowNumber in roomsBelow) { TR2Room roomBelow = level.Rooms[roomBelowNumber]; @@ -75,7 +75,7 @@ public override void ApplyToLevel(TR2Level level) } } - ISet roomsAbove = GetAdjacentRooms(room.SectorList, true); + ISet roomsAbove = GetAdjacentRooms(room.Sectors, true); foreach (byte roomAboveNumber in roomsAbove) { TR2Room roomAbove = level.Rooms[roomAboveNumber]; diff --git a/TREnvironmentEditor/Model/Types/Surfaces/EMFloorFunction.cs b/TREnvironmentEditor/Model/Types/Surfaces/EMFloorFunction.cs index e67e0e00d..19f7ba98f 100644 --- a/TREnvironmentEditor/Model/Types/Surfaces/EMFloorFunction.cs +++ b/TREnvironmentEditor/Model/Types/Surfaces/EMFloorFunction.cs @@ -62,7 +62,6 @@ private void MoveFloor(TR1Level level) short z = (short)(sectorIndex % room.NumZSectors * TRConsts.Step4); short y = (short)(sector.Floor * TRConsts.Step1); - List vertices = room.RoomData.Vertices.ToList(); List oldVertIndices = new(); List defVerts = GetTileVertices(x, y, z, false); @@ -75,7 +74,7 @@ private void MoveFloor(TR1Level level) for (int i = 0; i < defVerts.Count; i++) { TRVertex vert = defVerts[i]; - int vi = vertices.FindIndex(v => v.Vertex.X == vert.X && v.Vertex.Z == vert.Z && v.Vertex.Y == vert.Y); + int vi = room.RoomData.Vertices.FindIndex(v => v.Vertex.X == vert.X && v.Vertex.Z == vert.Z && v.Vertex.Y == vert.Y); if (vi != -1) { oldVertIndices.Add((ushort)vi); @@ -83,7 +82,6 @@ private void MoveFloor(TR1Level level) else { oldVertIndices.Add((ushort)CreateRoomVertex(room, vert)); - vertices = room.RoomData.Vertices.ToList(); } } @@ -92,8 +90,8 @@ private void MoveFloor(TR1Level level) List newVertIndices = new(); foreach (ushort vert in oldVertIndices) { - TR1RoomVertex oldRoomVertex = vertices[vert]; - TRVertex oldVert = vertices[vert].Vertex; + TR1RoomVertex oldRoomVertex = room.RoomData.Vertices[vert]; + TRVertex oldVert = room.RoomData.Vertices[vert].Vertex; TRVertex newVertex = new() { X = oldVert.X, @@ -103,12 +101,8 @@ private void MoveFloor(TR1Level level) newVertIndices.Add((ushort)CreateRoomVertex(room, newVertex, oldRoomVertex.Lighting)); } - // Refresh - vertices = room.RoomData.Vertices.ToList(); - // Get the tile face that matches the vertex list - List rectangles = room.RoomData.Rectangles.ToList(); - TRFace4 floorFace = rectangles.Find(r => r.Vertices.ToList().All(oldVertIndices.Contains)); + TRFace4 floorFace = room.RoomData.Rectangles.Find(r => r.Vertices.ToList().All(oldVertIndices.Contains)); // If the floor has been lowered (remember +Clicks = move down, -Clicks = move up) // then the sides will also need lowering. @@ -116,7 +110,7 @@ private void MoveFloor(TR1Level level) { // Find faces that share 2 of the old vertices int floorY = room.RoomData.Vertices[floorFace.Vertices[0]].Vertex.Y; - foreach (TRFace4 face in rectangles) + foreach (TRFace4 face in room.RoomData.Rectangles) { if (face == floorFace) { @@ -131,10 +125,10 @@ private void MoveFloor(TR1Level level) foreach (ushort sharedVert in sharedVerts) { int i = faceVerts.IndexOf(sharedVert); - TRVertex oldVert = vertices[sharedVert].Vertex; + TRVertex oldVert = room.RoomData.Vertices[sharedVert].Vertex; foreach (ushort newVert in newVertIndices) { - TRVertex newVertex = vertices[newVert].Vertex; + TRVertex newVertex = room.RoomData.Vertices[newVert].Vertex; if (newVertex.X == oldVert.X && newVertex.Z == oldVert.Z) { faceVerts[i] = newVert; @@ -165,7 +159,7 @@ private void MoveFloor(TR1Level level) if (((1 << i) & Flags) > 0) { int j = i == 3 ? 0 : (i + 1); - rectangles.Add(new TRFace4 + room.RoomData.Rectangles.Add(new() { Texture = SideTexture, Vertices = new ushort[] @@ -180,12 +174,6 @@ private void MoveFloor(TR1Level level) } } - // Save the new faces - room.RoomData.Rectangles = rectangles.ToArray(); - room.RoomData.NumRectangles = (short)rectangles.Count; - - // Account for the added faces - room.NumDataWords = (uint)(room.RoomData.Serialize().Length / 2); // Now shift the actual sector info and adjust the box if necessary. // Make the floor solid too. @@ -289,14 +277,13 @@ private void MoveFloor(TR2Level level) short roomNumber = data.ConvertRoom(Location.Room); TR2Room room = level.Rooms[roomNumber]; TRRoomSector sector = FDUtilities.GetRoomSector(Location.X, Location.Y, Location.Z, roomNumber, level, fdc); - int sectorIndex = room.SectorList.ToList().IndexOf(sector); + int sectorIndex = room.Sectors.ToList().IndexOf(sector); // Find the current vertices for this tile short x = (short)(sectorIndex / room.NumZSectors * TRConsts.Step4); short z = (short)(sectorIndex % room.NumZSectors * TRConsts.Step4); short y = (short)(sector.Floor * TRConsts.Step1); - List vertices = room.RoomData.Vertices.ToList(); List oldVertIndices = new(); List defVerts = GetTileVertices(x, y, z, false); @@ -309,7 +296,7 @@ private void MoveFloor(TR2Level level) for (int i = 0; i < defVerts.Count; i++) { TRVertex vert = defVerts[i]; - int vi = vertices.FindIndex(v => v.Vertex.X == vert.X && v.Vertex.Z == vert.Z && v.Vertex.Y == vert.Y); + int vi = room.RoomData.Vertices.FindIndex(v => v.Vertex.X == vert.X && v.Vertex.Z == vert.Z && v.Vertex.Y == vert.Y); if (vi != -1) { oldVertIndices.Add((ushort)vi); @@ -317,7 +304,6 @@ private void MoveFloor(TR2Level level) else { oldVertIndices.Add((ushort)CreateRoomVertex(room, vert)); - vertices = room.RoomData.Vertices.ToList(); } } @@ -326,8 +312,8 @@ private void MoveFloor(TR2Level level) List newVertIndices = new(); foreach (ushort vert in oldVertIndices) { - TR2RoomVertex oldRoomVertex = vertices[vert]; - TRVertex oldVert = vertices[vert].Vertex; + TR2RoomVertex oldRoomVertex = room.RoomData.Vertices[vert]; + TRVertex oldVert = room.RoomData.Vertices[vert].Vertex; TRVertex newVertex = new() { X = oldVert.X, @@ -337,12 +323,8 @@ private void MoveFloor(TR2Level level) newVertIndices.Add((ushort)CreateRoomVertex(room, newVertex, oldRoomVertex.Lighting, oldRoomVertex.Lighting2)); } - // Refresh - vertices = room.RoomData.Vertices.ToList(); - // Get the tile face that matches the vertex list - List rectangles = room.RoomData.Rectangles.ToList(); - TRFace4 floorFace = rectangles.Find(r => r.Vertices.ToList().All(oldVertIndices.Contains)); + TRFace4 floorFace = room.RoomData.Rectangles.Find(r => r.Vertices.ToList().All(oldVertIndices.Contains)); // If the floor has been lowered (remember +Clicks = move down, -Clicks = move up) // then the sides will also need lowering. @@ -350,7 +332,7 @@ private void MoveFloor(TR2Level level) { // Find faces that share 2 of the old vertices int floorY = room.RoomData.Vertices[floorFace.Vertices[0]].Vertex.Y; - foreach (TRFace4 face in rectangles) + foreach (TRFace4 face in room.RoomData.Rectangles) { if (face == floorFace) { @@ -365,10 +347,10 @@ private void MoveFloor(TR2Level level) foreach (ushort sharedVert in sharedVerts) { int i = faceVerts.IndexOf(sharedVert); - TRVertex oldVert = vertices[sharedVert].Vertex; + TRVertex oldVert = room.RoomData.Vertices[sharedVert].Vertex; foreach (ushort newVert in newVertIndices) { - TRVertex newVertex = vertices[newVert].Vertex; + TRVertex newVertex = room.RoomData.Vertices[newVert].Vertex; if (newVertex.X == oldVert.X && newVertex.Z == oldVert.Z) { faceVerts[i] = newVert; @@ -399,7 +381,7 @@ private void MoveFloor(TR2Level level) if (((1 << i) & Flags) > 0) { int j = i == 3 ? 0 : (i + 1); - rectangles.Add(new TRFace4 + room.RoomData.Rectangles.Add(new() { Texture = SideTexture, Vertices = new ushort[] @@ -414,13 +396,6 @@ private void MoveFloor(TR2Level level) } } - // Save the new faces - room.RoomData.Rectangles = rectangles.ToArray(); - room.RoomData.NumRectangles = (short)rectangles.Count; - - // Account for the added faces - room.NumDataWords = (uint)(room.RoomData.Serialize().Length / 2); - // Now shift the actual sector info and adjust the box if necessary. // Make the floor solid too. sector.Floor += Clicks; @@ -443,7 +418,7 @@ private void MoveFloor(TR2Level level) private static void AlterSectorBox(TR2Level level, TR2Room room, int sectorIndex) { - TRRoomSector sector = room.SectorList[sectorIndex]; + TRRoomSector sector = room.Sectors[sectorIndex]; if (sector.BoxIndex == ushort.MaxValue) { return; @@ -550,7 +525,6 @@ private void MoveFloor(TR3Level level) short z = (short)(sectorIndex % room.NumZSectors * TRConsts.Step4); short y = (short)(sector.Floor * TRConsts.Step1); - List vertices = room.RoomData.Vertices.ToList(); List oldVertIndices = new(); List defVerts = GetTileVertices(x, y, z, false); @@ -563,7 +537,7 @@ private void MoveFloor(TR3Level level) for (int i = 0; i < defVerts.Count; i++) { TRVertex vert = defVerts[i]; - int vi = vertices.FindIndex(v => v.Vertex.X == vert.X && v.Vertex.Z == vert.Z && v.Vertex.Y == vert.Y); + int vi = room.RoomData.Vertices.FindIndex(v => v.Vertex.X == vert.X && v.Vertex.Z == vert.Z && v.Vertex.Y == vert.Y); if (vi != -1) { oldVertIndices.Add((ushort)vi); @@ -575,8 +549,8 @@ private void MoveFloor(TR3Level level) List newVertIndices = new(); foreach (ushort vert in oldVertIndices) { - TR3RoomVertex oldRoomVertex = vertices[vert]; - TRVertex oldVert = vertices[vert].Vertex; + TR3RoomVertex oldRoomVertex = room.RoomData.Vertices[vert]; + TRVertex oldVert = room.RoomData.Vertices[vert].Vertex; TRVertex newVertex = new() { X = oldVert.X, @@ -586,12 +560,8 @@ private void MoveFloor(TR3Level level) newVertIndices.Add((ushort)CreateRoomVertex(room, newVertex, oldRoomVertex.Lighting, oldRoomVertex.Colour, oldRoomVertex.UseCaustics, oldRoomVertex.UseWaveMovement)); } - // Refresh - vertices = room.RoomData.Vertices.ToList(); - // Get the tile face that matches the vertex list - List rectangles = room.RoomData.Rectangles.ToList(); - TRFace4 floorFace = rectangles.Find(r => r.Vertices.ToList().All(oldVertIndices.Contains)); + TRFace4 floorFace = room.RoomData.Rectangles.Find(r => r.Vertices.ToList().All(oldVertIndices.Contains)); // If the floor has been lowered (remember +Clicks = move down, -Clicks = move up) // then the sides will also need lowering. @@ -599,7 +569,7 @@ private void MoveFloor(TR3Level level) { // Find faces that share 2 of the old vertices int floorY = room.RoomData.Vertices[floorFace.Vertices[0]].Vertex.Y; - foreach (TRFace4 face in rectangles) + foreach (TRFace4 face in room.RoomData.Rectangles) { if (face == floorFace) { @@ -614,10 +584,10 @@ private void MoveFloor(TR3Level level) foreach (ushort sharedVert in sharedVerts) { int i = faceVerts.IndexOf(sharedVert); - TRVertex oldVert = vertices[sharedVert].Vertex; + TRVertex oldVert = room.RoomData.Vertices[sharedVert].Vertex; foreach (ushort newVert in newVertIndices) { - TRVertex newVertex = vertices[newVert].Vertex; + TRVertex newVertex = room.RoomData.Vertices[newVert].Vertex; if (newVertex.X == oldVert.X && newVertex.Z == oldVert.Z) { faceVerts[i] = newVert; @@ -648,7 +618,7 @@ private void MoveFloor(TR3Level level) if (((1 << i) & Flags) > 0) { int j = i == 3 ? 0 : (i + 1); - rectangles.Add(new TRFace4 + room.RoomData.Rectangles.Add(new() { Texture = SideTexture, Vertices = new ushort[] @@ -663,13 +633,6 @@ private void MoveFloor(TR3Level level) } } - // Save the new faces - room.RoomData.Rectangles = rectangles.ToArray(); - room.RoomData.NumRectangles = (short)rectangles.Count; - - // Account for the added faces - room.NumDataWords = (uint)(room.RoomData.Serialize().Length / 2); - // Now shift the actual sector info and adjust the box if necessary sector.Floor += Clicks; AlterSectorBox(level, room, sectorIndex); diff --git a/TREnvironmentEditor/Model/Types/Textures/EMAddFaceFunction.cs b/TREnvironmentEditor/Model/Types/Textures/EMAddFaceFunction.cs index 530675b9c..6656c206e 100644 --- a/TREnvironmentEditor/Model/Types/Textures/EMAddFaceFunction.cs +++ b/TREnvironmentEditor/Model/Types/Textures/EMAddFaceFunction.cs @@ -17,13 +17,7 @@ public override void ApplyToLevel(TR1Level level) foreach (short roomIndex in Quads.Keys) { TR1Room room = level.Rooms[data.ConvertRoom(roomIndex)]; - List faces = room.RoomData.Rectangles.ToList(); - faces.AddRange(Quads[roomIndex]); - - room.RoomData.Rectangles = faces.ToArray(); - room.RoomData.NumRectangles = (short)faces.Count; - - room.NumDataWords = (uint)(room.RoomData.Serialize().Length / 2); + room.RoomData.Rectangles.AddRange(Quads[roomIndex]); } } @@ -32,13 +26,7 @@ public override void ApplyToLevel(TR1Level level) foreach (short roomIndex in Triangles.Keys) { TR1Room room = level.Rooms[data.ConvertRoom(roomIndex)]; - List faces = room.RoomData.Triangles.ToList(); - faces.AddRange(Triangles[roomIndex]); - - room.RoomData.Triangles = faces.ToArray(); - room.RoomData.NumTriangles = (short)faces.Count; - - room.NumDataWords = (uint)(room.RoomData.Serialize().Length / 2); + room.RoomData.Triangles.AddRange(Triangles[roomIndex]); } } } @@ -52,13 +40,7 @@ public override void ApplyToLevel(TR2Level level) foreach (short roomIndex in Quads.Keys) { TR2Room room = level.Rooms[data.ConvertRoom(roomIndex)]; - List faces = room.RoomData.Rectangles.ToList(); - faces.AddRange(Quads[roomIndex]); - - room.RoomData.Rectangles = faces.ToArray(); - room.RoomData.NumRectangles = (short)faces.Count; - - room.NumDataWords = (uint)(room.RoomData.Serialize().Length / 2); + room.RoomData.Rectangles.AddRange(Quads[roomIndex]); } } @@ -67,13 +49,7 @@ public override void ApplyToLevel(TR2Level level) foreach (short roomIndex in Triangles.Keys) { TR2Room room = level.Rooms[data.ConvertRoom(roomIndex)]; - List faces = room.RoomData.Triangles.ToList(); - faces.AddRange(Triangles[roomIndex]); - - room.RoomData.Triangles = faces.ToArray(); - room.RoomData.NumTriangles = (short)faces.Count; - - room.NumDataWords = (uint)(room.RoomData.Serialize().Length / 2); + room.RoomData.Triangles.AddRange(Triangles[roomIndex]); } } } @@ -87,13 +63,7 @@ public override void ApplyToLevel(TR3Level level) foreach (short roomIndex in Quads.Keys) { TR3Room room = level.Rooms[data.ConvertRoom(roomIndex)]; - List faces = room.RoomData.Rectangles.ToList(); - faces.AddRange(Quads[roomIndex]); - - room.RoomData.Rectangles = faces.ToArray(); - room.RoomData.NumRectangles = (short)faces.Count; - - room.NumDataWords = (uint)(room.RoomData.Serialize().Length / 2); + room.RoomData.Rectangles.AddRange(Quads[roomIndex]); } } @@ -102,13 +72,7 @@ public override void ApplyToLevel(TR3Level level) foreach (short roomIndex in Triangles.Keys) { TR3Room room = level.Rooms[data.ConvertRoom(roomIndex)]; - List faces = room.RoomData.Triangles.ToList(); - faces.AddRange(Triangles[roomIndex]); - - room.RoomData.Triangles = faces.ToArray(); - room.RoomData.NumTriangles = (short)faces.Count; - - room.NumDataWords = (uint)(room.RoomData.Serialize().Length / 2); + room.RoomData.Triangles.AddRange(Triangles[roomIndex]); } } } @@ -117,7 +81,7 @@ public void RemapTextures(Dictionary indexMap) { if (Quads != null) { - foreach (List faces in Quads.Values) + foreach (List faces in Quads?.Values) { foreach (TRFace4 face in faces) { @@ -131,7 +95,7 @@ public void RemapTextures(Dictionary indexMap) if (Triangles != null) { - foreach (List faces in Triangles.Values) + foreach (List faces in Triangles?.Values) { foreach (TRFace3 face in faces) { diff --git a/TREnvironmentEditor/Model/Types/Textures/EMAddRoomSpriteFunction.cs b/TREnvironmentEditor/Model/Types/Textures/EMAddRoomSpriteFunction.cs index 28cc2ba42..d18ccb317 100644 --- a/TREnvironmentEditor/Model/Types/Textures/EMAddRoomSpriteFunction.cs +++ b/TREnvironmentEditor/Model/Types/Textures/EMAddRoomSpriteFunction.cs @@ -15,14 +15,12 @@ public override void ApplyToLevel(TR1Level level) foreach (EMLocation location in Locations) { TR1Room room = level.Rooms[data.ConvertRoom(location.Room)]; - List vertices = room.RoomData.Vertices.ToList(); - List sprites = room.RoomData.Sprites.ToList(); - sprites.Add(new() + room.RoomData.Sprites.Add(new() { Texture = Texture, - Vertex = (short)vertices.Count + Vertex = (short)room.RoomData.Vertices.Count }); - vertices.Add(new() + room.RoomData.Vertices.Add(new() { Lighting = Vertex.Lighting, Vertex = new() @@ -32,13 +30,6 @@ public override void ApplyToLevel(TR1Level level) Z = (short)(location.Z - room.Info.Z) } }); - - room.RoomData.Vertices = vertices.ToArray(); - room.RoomData.Sprites = sprites.ToArray(); - room.RoomData.NumSprites++; - room.RoomData.NumVertices++; - - room.NumDataWords = (uint)(room.RoomData.Serialize().Length / 2); } } @@ -48,14 +39,12 @@ public override void ApplyToLevel(TR2Level level) foreach (EMLocation location in Locations) { TR2Room room = level.Rooms[data.ConvertRoom(location.Room)]; - List vertices = room.RoomData.Vertices.ToList(); - List sprites = room.RoomData.Sprites.ToList(); - sprites.Add(new() + room.RoomData.Sprites.Add(new() { Texture = Texture, - Vertex = (short)vertices.Count + Vertex = (short)room.RoomData.Vertices.Count }); - vertices.Add(new() + room.RoomData.Vertices.Add(new() { Lighting = Vertex.Lighting, Lighting2 = Vertex.Lighting2, @@ -67,13 +56,6 @@ public override void ApplyToLevel(TR2Level level) Z = (short)(location.Z - room.Info.Z) } }); - - room.RoomData.Vertices = vertices.ToArray(); - room.RoomData.Sprites = sprites.ToArray(); - room.RoomData.NumSprites++; - room.RoomData.NumVertices++; - - room.NumDataWords = (uint)(room.RoomData.Serialize().Length / 2); } } @@ -83,14 +65,12 @@ public override void ApplyToLevel(TR3Level level) foreach (EMLocation location in Locations) { TR3Room room = level.Rooms[data.ConvertRoom(location.Room)]; - List vertices = room.RoomData.Vertices.ToList(); - List sprites = room.RoomData.Sprites.ToList(); - sprites.Add(new() + room.RoomData.Sprites.Add(new() { Texture = Texture, - Vertex = (short)vertices.Count + Vertex = (short)room.RoomData.Vertices.Count }); - vertices.Add(new() + room.RoomData.Vertices.Add(new() { Lighting = Vertex.Lighting, Attributes = Vertex.Attributes, @@ -102,13 +82,6 @@ public override void ApplyToLevel(TR3Level level) Z = (short)(location.Z - room.Info.Z) } }); - - room.RoomData.Vertices = vertices.ToArray(); - room.RoomData.Sprites = sprites.ToArray(); - room.RoomData.NumSprites++; - room.RoomData.NumVertices++; - - room.NumDataWords = (uint)(room.RoomData.Serialize().Length / 2); } } } diff --git a/TREnvironmentEditor/Model/Types/Textures/EMAddStaticMeshFunction.cs b/TREnvironmentEditor/Model/Types/Textures/EMAddStaticMeshFunction.cs index 1136d75f8..91c10bf11 100644 --- a/TREnvironmentEditor/Model/Types/Textures/EMAddStaticMeshFunction.cs +++ b/TREnvironmentEditor/Model/Types/Textures/EMAddStaticMeshFunction.cs @@ -47,8 +47,7 @@ public override void ApplyToLevel(TR1Level level) } } - List meshes = room.StaticMeshes.ToList(); - meshes.Add(new() + room.StaticMeshes.Add(new() { X = (uint)location.X, Y = (uint)(location.Y < 0 ? uint.MaxValue + location.Y : location.Y), @@ -57,9 +56,6 @@ public override void ApplyToLevel(TR1Level level) MeshID = Mesh.MeshID, Rotation = (ushort)(location.Angle + short.MaxValue + 1) }); - - room.StaticMeshes = meshes.ToArray(); - room.NumStaticMeshes = (ushort)meshes.Count; } } @@ -99,8 +95,7 @@ public override void ApplyToLevel(TR2Level level) } } - List meshes = room.StaticMeshes.ToList(); - meshes.Add(new() + room.StaticMeshes.Add(new() { X = (uint)location.X, Y = (uint)(location.Y < 0 ? uint.MaxValue + location.Y : location.Y), @@ -110,9 +105,6 @@ public override void ApplyToLevel(TR2Level level) MeshID = Mesh.MeshID, Rotation = (ushort)(location.Angle + short.MaxValue + 1) }); - - room.StaticMeshes = meshes.ToArray(); - room.NumStaticMeshes = (ushort)meshes.Count; } } @@ -152,8 +144,7 @@ public override void ApplyToLevel(TR3Level level) } } - List meshes = room.StaticMeshes.ToList(); - meshes.Add(new() + room.StaticMeshes.Add(new() { X = (uint)location.X, Y = (uint)(location.Y < 0 ? uint.MaxValue + location.Y : location.Y), @@ -162,9 +153,6 @@ public override void ApplyToLevel(TR3Level level) MeshID = Mesh.MeshID, Rotation = (ushort)(location.Angle + short.MaxValue + 1) }); - - room.StaticMeshes = meshes.ToArray(); - room.NumStaticMeshes = (ushort)meshes.Count; } } } diff --git a/TREnvironmentEditor/Model/Types/Textures/EMModifyFaceFunction.cs b/TREnvironmentEditor/Model/Types/Textures/EMModifyFaceFunction.cs index 614d9cf1d..318882c24 100644 --- a/TREnvironmentEditor/Model/Types/Textures/EMModifyFaceFunction.cs +++ b/TREnvironmentEditor/Model/Types/Textures/EMModifyFaceFunction.cs @@ -127,140 +127,110 @@ public override void ApplyToLevel(TR3Level level) private static void ModifyRectangles(TR1Room room, EMFaceModification mod) { - List allVertices = room.RoomData.Vertices.ToList(); foreach (int faceIndex in mod.GetIndices()) { TRFace4 rect = room.RoomData.Rectangles[faceIndex]; foreach (int vertIndex in mod.VertexChanges.Keys) { - TR1RoomVertex currentRoomVertex = allVertices[rect.Vertices[vertIndex]]; + TR1RoomVertex currentRoomVertex = room.RoomData.Vertices[rect.Vertices[vertIndex]]; TRVertex newVertex = mod.VertexChanges[vertIndex]; TR1RoomVertex newRoomVertex = GenerateRoomVertex(currentRoomVertex, newVertex); // Remap the face to use this vertex - rect.Vertices[vertIndex] = (ushort)allVertices.Count; - allVertices.Add(newRoomVertex); + rect.Vertices[vertIndex] = (ushort)room.RoomData.Vertices.Count; + room.RoomData.Vertices.Add(newRoomVertex); } } - - room.RoomData.Vertices = allVertices.ToArray(); - room.RoomData.NumVertices = (short)allVertices.Count; - room.NumDataWords = (uint)(room.RoomData.Serialize().Length / 2); } private static void ModifyRectangles(TR2Room room, EMFaceModification mod) { - List allVertices = room.RoomData.Vertices.ToList(); foreach (int faceIndex in mod.GetIndices()) { TRFace4 rect = room.RoomData.Rectangles[faceIndex]; foreach (int vertIndex in mod.VertexChanges.Keys) { - TR2RoomVertex currentRoomVertex = allVertices[rect.Vertices[vertIndex]]; + TR2RoomVertex currentRoomVertex = room.RoomData.Vertices[rect.Vertices[vertIndex]]; TRVertex newVertex = mod.VertexChanges[vertIndex]; TR2RoomVertex newRoomVertex = GenerateRoomVertex(currentRoomVertex, newVertex); // Remap the face to use this vertex - rect.Vertices[vertIndex] = (ushort)allVertices.Count; - allVertices.Add(newRoomVertex); + rect.Vertices[vertIndex] = (ushort)room.RoomData.Vertices.Count; + room.RoomData.Vertices.Add(newRoomVertex); } } - - room.RoomData.Vertices = allVertices.ToArray(); - room.RoomData.NumVertices = (short)allVertices.Count; - room.NumDataWords = (uint)(room.RoomData.Serialize().Length / 2); } private static void ModifyRectangles(TR3Room room, EMFaceModification mod) { - List allVertices = room.RoomData.Vertices.ToList(); foreach (int faceIndex in mod.GetIndices()) { TRFace4 rect = room.RoomData.Rectangles[faceIndex]; foreach (int vertIndex in mod.VertexChanges.Keys) { - TR3RoomVertex currentRoomVertex = allVertices[rect.Vertices[vertIndex]]; + TR3RoomVertex currentRoomVertex = room.RoomData.Vertices[rect.Vertices[vertIndex]]; TRVertex newVertex = mod.VertexChanges[vertIndex]; TR3RoomVertex newRoomVertex = GenerateRoomVertex(currentRoomVertex, newVertex); // Remap the face to use this vertex - rect.Vertices[vertIndex] = (ushort)allVertices.Count; - allVertices.Add(newRoomVertex); + rect.Vertices[vertIndex] = (ushort)room.RoomData.Vertices.Count; + room.RoomData.Vertices.Add(newRoomVertex); } } - - room.RoomData.Vertices = allVertices.ToArray(); - room.RoomData.NumVertices = (short)allVertices.Count; - room.NumDataWords = (uint)(room.RoomData.Serialize().Length / 2); } private static void ModifyTriangles(TR1Room room, EMFaceModification mod) { - List allVertices = room.RoomData.Vertices.ToList(); foreach (int faceIndex in mod.GetIndices()) { TRFace3 tri = room.RoomData.Triangles[faceIndex]; foreach (int vertIndex in mod.VertexChanges.Keys) { - TR1RoomVertex currentRoomVertex = allVertices[tri.Vertices[vertIndex]]; + TR1RoomVertex currentRoomVertex = room.RoomData.Vertices[tri.Vertices[vertIndex]]; TRVertex newVertex = mod.VertexChanges[vertIndex]; TR1RoomVertex newRoomVertex = GenerateRoomVertex(currentRoomVertex, newVertex); // Remap the face to use this vertex - tri.Vertices[vertIndex] = (ushort)allVertices.Count; - allVertices.Add(newRoomVertex); + tri.Vertices[vertIndex] = (ushort)room.RoomData.Vertices.Count; + room.RoomData.Vertices.Add(newRoomVertex); } } - - room.RoomData.Vertices = allVertices.ToArray(); - room.RoomData.NumVertices = (short)allVertices.Count; - room.NumDataWords = (uint)(room.RoomData.Serialize().Length / 2); } private static void ModifyTriangles(TR2Room room, EMFaceModification mod) { - List allVertices = room.RoomData.Vertices.ToList(); foreach (int faceIndex in mod.GetIndices()) { TRFace3 tri = room.RoomData.Triangles[faceIndex]; foreach (int vertIndex in mod.VertexChanges.Keys) { - TR2RoomVertex currentRoomVertex = allVertices[tri.Vertices[vertIndex]]; + TR2RoomVertex currentRoomVertex = room.RoomData.Vertices[tri.Vertices[vertIndex]]; TRVertex newVertex = mod.VertexChanges[vertIndex]; TR2RoomVertex newRoomVertex = GenerateRoomVertex(currentRoomVertex, newVertex); // Remap the face to use this vertex - tri.Vertices[vertIndex] = (ushort)allVertices.Count; - allVertices.Add(newRoomVertex); + tri.Vertices[vertIndex] = (ushort)room.RoomData.Vertices.Count; + room.RoomData.Vertices.Add(newRoomVertex); } } - - room.RoomData.Vertices = allVertices.ToArray(); - room.RoomData.NumVertices = (short)allVertices.Count; - room.NumDataWords = (uint)(room.RoomData.Serialize().Length / 2); } private static void ModifyTriangles(TR3Room room, EMFaceModification mod) { - List allVertices = room.RoomData.Vertices.ToList(); foreach (int faceIndex in mod.GetIndices()) { TRFace3 tri = room.RoomData.Triangles[faceIndex]; foreach (int vertIndex in mod.VertexChanges.Keys) { - TR3RoomVertex currentRoomVertex = allVertices[tri.Vertices[vertIndex]]; + TR3RoomVertex currentRoomVertex = room.RoomData.Vertices[tri.Vertices[vertIndex]]; TRVertex newVertex = mod.VertexChanges[vertIndex]; TR3RoomVertex newRoomVertex = GenerateRoomVertex(currentRoomVertex, newVertex); // Remap the face to use this vertex - tri.Vertices[vertIndex] = (ushort)allVertices.Count; - allVertices.Add(newRoomVertex); + tri.Vertices[vertIndex] = (ushort)room.RoomData.Vertices.Count; + room.RoomData.Vertices.Add(newRoomVertex); } } - - room.RoomData.Vertices = allVertices.ToArray(); - room.RoomData.NumVertices = (short)allVertices.Count; - room.NumDataWords = (uint)(room.RoomData.Serialize().Length / 2); } private static TR1RoomVertex GenerateRoomVertex(TR1RoomVertex currentRoomVertex, TRVertex newVertex) @@ -312,7 +282,7 @@ private static TR3RoomVertex GenerateRoomVertex(TR3RoomVertex currentRoomVertex, }; } - private static void RotateRectangles(TRFace4[] rectangles, EMFaceRotation rot) + private static void RotateRectangles(List rectangles, EMFaceRotation rot) { foreach (int rectIndex in rot.FaceIndices) { @@ -321,7 +291,7 @@ private static void RotateRectangles(TRFace4[] rectangles, EMFaceRotation rot) } } - private static void RotateTriangles(TRFace3[] triangles, EMFaceRotation rot) + private static void RotateTriangles(List triangles, EMFaceRotation rot) { foreach (int triIndex in rot.FaceIndices) { diff --git a/TREnvironmentEditor/Model/Types/Textures/EMRefaceFunction.cs b/TREnvironmentEditor/Model/Types/Textures/EMRefaceFunction.cs index f3b435ac9..1aab80775 100644 --- a/TREnvironmentEditor/Model/Types/Textures/EMRefaceFunction.cs +++ b/TREnvironmentEditor/Model/Types/Textures/EMRefaceFunction.cs @@ -64,7 +64,7 @@ public void ApplyTextures(TR3Level level) } } - private static void ApplyTextures(ushort texture, Dictionary faceMap, TRFace4[] rectangles, TRFace3[] triangles) + private static void ApplyTextures(ushort texture, Dictionary faceMap, List rectangles, List triangles) { foreach (EMTextureFaceType faceType in faceMap.Keys) { diff --git a/TREnvironmentEditor/Model/Types/Textures/EMRemoveFaceFunction.cs b/TREnvironmentEditor/Model/Types/Textures/EMRemoveFaceFunction.cs index 79b0256ca..08f8a024f 100644 --- a/TREnvironmentEditor/Model/Types/Textures/EMRemoveFaceFunction.cs +++ b/TREnvironmentEditor/Model/Types/Textures/EMRemoveFaceFunction.cs @@ -33,13 +33,8 @@ public override void ApplyToLevel(TR1Level level) } } - room.RoomData.Rectangles = RemoveEntries(room.RoomData.Rectangles, rectangleRemovals); - room.RoomData.Triangles = RemoveEntries(room.RoomData.Triangles, triangleRemovals); - - room.RoomData.NumRectangles = (short)room.RoomData.Rectangles.Length; - room.RoomData.NumTriangles = (short)room.RoomData.Triangles.Length; - - room.NumDataWords = (uint)(room.RoomData.Serialize().Length / 2); + RemoveEntries(room.RoomData.Rectangles, rectangleRemovals); + RemoveEntries(room.RoomData.Triangles, triangleRemovals); } } @@ -69,13 +64,8 @@ public override void ApplyToLevel(TR2Level level) } } - room.RoomData.Rectangles = RemoveEntries(room.RoomData.Rectangles, rectangleRemovals); - room.RoomData.Triangles = RemoveEntries(room.RoomData.Triangles, triangleRemovals); - - room.RoomData.NumRectangles = (short)room.RoomData.Rectangles.Length; - room.RoomData.NumTriangles = (short)room.RoomData.Triangles.Length; - - room.NumDataWords = (uint)(room.RoomData.Serialize().Length / 2); + RemoveEntries(room.RoomData.Rectangles, rectangleRemovals); + RemoveEntries(room.RoomData.Triangles, triangleRemovals); } } @@ -105,17 +95,12 @@ public override void ApplyToLevel(TR3Level level) } } - room.RoomData.Rectangles = RemoveEntries(room.RoomData.Rectangles, rectangleRemovals); - room.RoomData.Triangles = RemoveEntries(room.RoomData.Triangles, triangleRemovals); - - room.RoomData.NumRectangles = (short)room.RoomData.Rectangles.Length; - room.RoomData.NumTriangles = (short)room.RoomData.Triangles.Length; - - room.NumDataWords = (uint)(room.RoomData.Serialize().Length / 2); + RemoveEntries(room.RoomData.Rectangles, rectangleRemovals); + RemoveEntries(room.RoomData.Triangles, triangleRemovals); } } - private static T[] RemoveEntries(T[] items, List indices) + private static void RemoveEntries(List items, List indices) { List itemList = items.ToList(); @@ -124,7 +109,5 @@ private static T[] RemoveEntries(T[] items, List indices) { itemList.RemoveAt(indices[i]); } - - return itemList.ToArray(); } } diff --git a/TREnvironmentEditor/Model/Types/Textures/EMRemoveStaticMeshFunction.cs b/TREnvironmentEditor/Model/Types/Textures/EMRemoveStaticMeshFunction.cs index b2eefc578..0582ec17e 100644 --- a/TREnvironmentEditor/Model/Types/Textures/EMRemoveStaticMeshFunction.cs +++ b/TREnvironmentEditor/Model/Types/Textures/EMRemoveStaticMeshFunction.cs @@ -15,34 +15,22 @@ public override void ApplyToLevel(TR1Level level) if (Location != null) { TR1Room room = level.Rooms[data.ConvertRoom(Location.Room)]; - List meshes = room.StaticMeshes.ToList(); uint x = (uint)Location.X; uint y = (uint)(Location.Y < 0 ? uint.MaxValue + Location.Y : Location.Y); uint z = (uint)Location.Z; - TR1RoomStaticMesh match = meshes.Find(m => m.X == x && m.Y == y && m.Z == z); - if (match != null) - { - meshes.Remove(match); - room.StaticMeshes = meshes.ToArray(); - room.NumStaticMeshes--; - } + room.StaticMeshes.RemoveAll(m => m.X == x && m.Y == y && m.Z == z); } if (ClearFromRooms != null) { - foreach (ushort meshID in ClearFromRooms.Keys) + foreach (var (meshID, roomList) in ClearFromRooms) { - foreach (int roomNumber in ClearFromRooms[meshID]) + foreach (int roomNumber in roomList) { TR1Room room = level.Rooms[data.ConvertRoom(roomNumber)]; - List meshes = room.StaticMeshes.ToList(); - if (meshes.RemoveAll(m => m.MeshID == meshID) > 0) - { - room.StaticMeshes = meshes.ToArray(); - room.NumStaticMeshes = (ushort)meshes.Count; - } + room.StaticMeshes.RemoveAll(m => m.MeshID == meshID); } } } @@ -55,19 +43,12 @@ public override void ApplyToLevel(TR2Level level) if (Location != null) { TR2Room room = level.Rooms[data.ConvertRoom(Location.Room)]; - List meshes = room.StaticMeshes.ToList(); uint x = (uint)Location.X; uint y = (uint)(Location.Y < 0 ? uint.MaxValue + Location.Y : Location.Y); uint z = (uint)Location.Z; - TR2RoomStaticMesh match = meshes.Find(m => m.X == x && m.Y == y && m.Z == z); - if (match != null) - { - meshes.Remove(match); - room.StaticMeshes = meshes.ToArray(); - room.NumStaticMeshes--; - } + room.StaticMeshes.RemoveAll(m => m.X == x && m.Y == y && m.Z == z); } if (ClearFromRooms != null) @@ -77,12 +58,7 @@ public override void ApplyToLevel(TR2Level level) foreach (int roomNumber in ClearFromRooms[meshID]) { TR2Room room = level.Rooms[data.ConvertRoom(roomNumber)]; - List meshes = room.StaticMeshes.ToList(); - if (meshes.RemoveAll(m => m.MeshID == meshID) > 0) - { - room.StaticMeshes = meshes.ToArray(); - room.NumStaticMeshes = (ushort)meshes.Count; - } + room.StaticMeshes.RemoveAll(m => m.MeshID == meshID); } } } @@ -95,19 +71,12 @@ public override void ApplyToLevel(TR3Level level) if (Location != null) { TR3Room room = level.Rooms[data.ConvertRoom(Location.Room)]; - List meshes = room.StaticMeshes.ToList(); uint x = (uint)Location.X; uint y = (uint)(Location.Y < 0 ? uint.MaxValue + Location.Y : Location.Y); uint z = (uint)Location.Z; - TR3RoomStaticMesh match = meshes.Find(m => m.X == x && m.Y == y && m.Z == z); - if (match != null) - { - meshes.Remove(match); - room.StaticMeshes = meshes.ToArray(); - room.NumStaticMeshes--; - } + room.StaticMeshes.RemoveAll(m => m.X == x && m.Y == y && m.Z == z); } if (ClearFromRooms != null) @@ -117,12 +86,7 @@ public override void ApplyToLevel(TR3Level level) foreach (int roomNumber in ClearFromRooms[meshID]) { TR3Room room = level.Rooms[data.ConvertRoom(roomNumber)]; - List meshes = room.StaticMeshes.ToList(); - if (meshes.RemoveAll(m => m.MeshID == meshID) > 0) - { - room.StaticMeshes = meshes.ToArray(); - room.NumStaticMeshes = (ushort)meshes.Count; - } + room.StaticMeshes.RemoveAll(m => m.MeshID == meshID); } } } diff --git a/TREnvironmentEditor/Model/Types/Triggers/EMCameraTriggerFunction.cs b/TREnvironmentEditor/Model/Types/Triggers/EMCameraTriggerFunction.cs index f0eacfab4..6e177d76b 100644 --- a/TREnvironmentEditor/Model/Types/Triggers/EMCameraTriggerFunction.cs +++ b/TREnvironmentEditor/Model/Types/Triggers/EMCameraTriggerFunction.cs @@ -111,7 +111,7 @@ public override void ApplyToLevel(TR2Level level) { foreach (short room in AttachToRooms) { - foreach (TRRoomSector sector in level.Rooms[data.ConvertRoom(room)].SectorList) + foreach (TRRoomSector sector in level.Rooms[data.ConvertRoom(room)].Sectors) { AttachToSector(sector, control, cameraIndex, data); } diff --git a/TREnvironmentEditor/Model/Types/Triggers/EMRemoveEntityTriggersFunction.cs b/TREnvironmentEditor/Model/Types/Triggers/EMRemoveEntityTriggersFunction.cs index e57a60498..1b1055818 100644 --- a/TREnvironmentEditor/Model/Types/Triggers/EMRemoveEntityTriggersFunction.cs +++ b/TREnvironmentEditor/Model/Types/Triggers/EMRemoveEntityTriggersFunction.cs @@ -38,7 +38,7 @@ public override void ApplyToLevel(TR2Level level) foreach (TR2Room room in level.Rooms) { - RemoveSectorTriggers(floorData, room.SectorList, entities, excludedTypes); + RemoveSectorTriggers(floorData, room.Sectors, entities, excludedTypes); } floorData.WriteToLevel(level); diff --git a/TREnvironmentEditor/Model/Types/Triggers/EMRemoveTriggerFunction.cs b/TREnvironmentEditor/Model/Types/Triggers/EMRemoveTriggerFunction.cs index ef777edbe..bb489f9e6 100644 --- a/TREnvironmentEditor/Model/Types/Triggers/EMRemoveTriggerFunction.cs +++ b/TREnvironmentEditor/Model/Types/Triggers/EMRemoveTriggerFunction.cs @@ -59,7 +59,7 @@ public override void ApplyToLevel(TR2Level level) { foreach (int roomNumber in Rooms) { - RemoveSectorListTriggers(level.Rooms[data.ConvertRoom(roomNumber)].SectorList, control); + RemoveSectorListTriggers(level.Rooms[data.ConvertRoom(roomNumber)].Sectors, control); } } diff --git a/TREnvironmentEditor/Model/Types/Triggers/EMTriggerFunction.cs b/TREnvironmentEditor/Model/Types/Triggers/EMTriggerFunction.cs index a85528827..c01cec1ea 100644 --- a/TREnvironmentEditor/Model/Types/Triggers/EMTriggerFunction.cs +++ b/TREnvironmentEditor/Model/Types/Triggers/EMTriggerFunction.cs @@ -79,7 +79,7 @@ public override void ApplyToLevel(TR2Level level) { foreach (short room in Rooms) { - foreach (TRRoomSector sector in level.Rooms[data.ConvertRoom(room)].SectorList) + foreach (TRRoomSector sector in level.Rooms[data.ConvertRoom(room)].Sectors) { if (!sector.IsWall && sector.RoomBelow == TRConsts.NoRoom) { diff --git a/TRFDControl/FDControl.cs b/TRFDControl/FDControl.cs index 62bb94c5e..287d3567b 100644 --- a/TRFDControl/FDControl.cs +++ b/TRFDControl/FDControl.cs @@ -56,7 +56,7 @@ public void ParseFromLevel (TR1Level level) public void ParseFromLevel(TR2Level level) { - ParseLevel(level.Rooms.SelectMany(r => r.SectorList), level.FloorData); + ParseLevel(level.Rooms.SelectMany(r => r.Sectors), level.FloorData); } public void ParseFromLevel(TR3Level level) @@ -257,7 +257,7 @@ public void WriteToLevel(TR1Level level) public void WriteToLevel(TR2Level level) { - Flatten(level.Rooms.SelectMany(r => r.SectorList), level.FloorData); + Flatten(level.Rooms.SelectMany(r => r.Sectors), level.FloorData); } public void WriteToLevel(TR3Level level) diff --git a/TRFDControl/Utilities/FDUtilities.cs b/TRFDControl/Utilities/FDUtilities.cs index 70b1fcd31..57758b1eb 100644 --- a/TRFDControl/Utilities/FDUtilities.cs +++ b/TRFDControl/Utilities/FDUtilities.cs @@ -91,7 +91,7 @@ public static void RemoveEntityTriggers(TR2Level level, int entityIndex, FDContr { foreach (TR2Room room in level.Rooms) { - RemoveEntityTriggers(room.SectorList, entityIndex, control); + RemoveEntityTriggers(room.Sectors, entityIndex, control); } } @@ -134,7 +134,7 @@ public static void RemoveEntityTriggers(IEnumerable sectorList, in } } - public static TRRoomSector GetRoomSector(int x, int z, TRRoomSector[] sectors, TRRoomInfo info, ushort roomDepth) + public static TRRoomSector GetRoomSector(int x, int z, List sectors, TRRoomInfo info, ushort roomDepth) { int xFloor = (x - info.X) >> TRConsts.WallShift; int zFloor = (z - info.Z) >> TRConsts.WallShift; @@ -274,7 +274,7 @@ public static TRRoomSector GetRoomSector(int x, int y, int z, short roomNumber, yFloor = room.NumXSectors - 1; } - sector = room.SectorList[xFloor + yFloor * room.NumZSectors]; + sector = room.Sectors[xFloor + yFloor * room.NumZSectors]; data = GetDoor(sector, floorData); if (data != TRConsts.NoRoom && data >= 0 && data < level.Rooms.Count - 1) { @@ -293,7 +293,7 @@ public static TRRoomSector GetRoomSector(int x, int y, int z, short roomNumber, } room = level.Rooms[sector.RoomBelow]; - sector = room.SectorList[((z - room.Info.Z) >> TRConsts.WallShift) + ((x - room.Info.X) >> TRConsts.WallShift) * room.NumZSectors]; + sector = room.Sectors[((z - room.Info.Z) >> TRConsts.WallShift) + ((x - room.Info.X) >> TRConsts.WallShift) * room.NumZSectors]; } while (y >= (sector.Floor << 8)); } @@ -307,7 +307,7 @@ public static TRRoomSector GetRoomSector(int x, int y, int z, short roomNumber, } room = level.Rooms[sector.RoomAbove]; - sector = room.SectorList[((z - room.Info.Z) >> TRConsts.WallShift) + ((x - room.Info.X) >> TRConsts.WallShift) * room.NumZSectors]; + sector = room.Sectors[((z - room.Info.Z) >> TRConsts.WallShift) + ((x - room.Info.X) >> TRConsts.WallShift) * room.NumZSectors]; } while (y < (sector.RoomAbove << 8)); } @@ -555,7 +555,7 @@ public static int GetHeight(int x, int z, short roomIndex, TR2Level level, FDCon return TRConsts.NoHeight; } - TRRoomSector baseSector = GetRoomSector(x, z, room.SectorList, room.Info, room.NumZSectors); + TRRoomSector baseSector = GetRoomSector(x, z, room.Sectors, room.Info, room.NumZSectors); TRRoomSector floorSector = baseSector; while (floorSector.RoomBelow != TRConsts.NoRoom) { @@ -564,7 +564,7 @@ public static int GetHeight(int x, int z, short roomIndex, TR2Level level, FDCon { break; } - floorSector = GetRoomSector(x, z, room.SectorList, room.Info, room.NumZSectors); + floorSector = GetRoomSector(x, z, room.Sectors, room.Info, room.NumZSectors); } TRRoomSector ceilingSector = baseSector; @@ -575,7 +575,7 @@ public static int GetHeight(int x, int z, short roomIndex, TR2Level level, FDCon { break; } - ceilingSector = GetRoomSector(x, z, room.SectorList, room.Info, room.NumZSectors); + ceilingSector = GetRoomSector(x, z, room.Sectors, room.Info, room.NumZSectors); } return GetHeight(x, z, floorSector, ceilingSector, floorData); diff --git a/TRLevelControl/Control/TR1LevelControl.cs b/TRLevelControl/Control/TR1LevelControl.cs index 611bbf0bc..4dd32f255 100644 --- a/TRLevelControl/Control/TR1LevelControl.cs +++ b/TRLevelControl/Control/TR1LevelControl.cs @@ -54,53 +54,44 @@ protected override void Read(TRLevelReader reader) YBottom = reader.ReadInt32(), YTop = reader.ReadInt32() }, - - //Grab data - NumDataWords = reader.ReadUInt32() }; _level.Rooms.Add(room); - room.Data = new ushort[room.NumDataWords]; - for (int j = 0; j < room.NumDataWords; j++) - { - room.Data[j] = reader.ReadUInt16(); - } - - //Store what we just read - room.RoomData = ConvertToRoomData(room); + uint numWords = reader.ReadUInt32(); + room.RoomData = ConvertToRoomData(reader.ReadUInt16s(numWords)); //Portals - room.NumPortals = reader.ReadUInt16(); - room.Portals = new TRRoomPortal[room.NumPortals]; - for (int j = 0; j < room.NumPortals; j++) + ushort numPortals = reader.ReadUInt16(); + room.Portals = new(); + for (int j = 0; j < numPortals; j++) { - room.Portals[j] = TR2FileReadUtilities.ReadRoomPortal(reader); + room.Portals.Add(TR2FileReadUtilities.ReadRoomPortal(reader)); } //Sectors room.NumZSectors = reader.ReadUInt16(); room.NumXSectors = reader.ReadUInt16(); - room.Sectors = new TRRoomSector[room.NumXSectors * room.NumZSectors]; + room.Sectors = new(); for (int j = 0; j < (room.NumXSectors * room.NumZSectors); j++) { - room.Sectors[j] = TR2FileReadUtilities.ReadRoomSector(reader); + room.Sectors.Add(TR2FileReadUtilities.ReadRoomSector(reader)); } //Lighting room.AmbientIntensity = reader.ReadInt16(); - room.NumLights = reader.ReadUInt16(); - room.Lights = new TR1RoomLight[room.NumLights]; - for (int j = 0; j < room.NumLights; j++) + ushort numLights = reader.ReadUInt16(); + room.Lights = new(); + for (int j = 0; j < numLights; j++) { - room.Lights[j] = TR1FileReadUtilities.ReadRoomLight(reader); + room.Lights.Add(TR1FileReadUtilities.ReadRoomLight(reader)); } //Static meshes - room.NumStaticMeshes = reader.ReadUInt16(); - room.StaticMeshes = new TR1RoomStaticMesh[room.NumStaticMeshes]; - for (int j = 0; j < room.NumStaticMeshes; j++) + ushort numStaticMeshes = reader.ReadUInt16(); + room.StaticMeshes = new(); + for (int j = 0; j < numStaticMeshes; j++) { - room.StaticMeshes[j] = TR1FileReadUtilities.ReadRoomStaticMesh(reader); + room.StaticMeshes.Add(TR1FileReadUtilities.ReadRoomStaticMesh(reader)); } room.AlternateRoom = reader.ReadInt16(); @@ -282,111 +273,78 @@ private void WriteSprites(TRLevelWriter writer) _spriteBuilder.WriteSprites(writer, _level.Sprites); } - private static TR1RoomData ConvertToRoomData(TR1Room room) + private static TR1RoomData ConvertToRoomData(ushort[] rawData) { - int RoomDataOffset = 0; + // This approach is temporarily retained - //Grab detailed room data - TR1RoomData RoomData = new() + TR1RoomData roomData = new() { - //Room vertices - NumVertices = UnsafeConversions.UShortToShort(room.Data[RoomDataOffset]) + Vertices = new() }; - RoomData.Vertices = new TR1RoomVertex[RoomData.NumVertices]; - RoomDataOffset++; - - for (int j = 0; j < RoomData.NumVertices; j++) + int offset = 0; + ushort count = rawData[offset++]; + for (int j = 0; j < count; j++) { - TR1RoomVertex vertex = new() + roomData.Vertices.Add(new() { - Vertex = new TRVertex() - }; - - vertex.Vertex.X = UnsafeConversions.UShortToShort(room.Data[RoomDataOffset]); - RoomDataOffset++; - vertex.Vertex.Y = UnsafeConversions.UShortToShort(room.Data[RoomDataOffset]); - RoomDataOffset++; - vertex.Vertex.Z = UnsafeConversions.UShortToShort(room.Data[RoomDataOffset]); - RoomDataOffset++; - vertex.Lighting = UnsafeConversions.UShortToShort(room.Data[RoomDataOffset]); - RoomDataOffset++; - - RoomData.Vertices[j] = vertex; + Vertex = new() + { + X = UnsafeConversions.UShortToShort(rawData[offset++]), + Y = UnsafeConversions.UShortToShort(rawData[offset++]), + Z = UnsafeConversions.UShortToShort(rawData[offset++]), + }, + Lighting = UnsafeConversions.UShortToShort(rawData[offset++]), + }); } - //Room rectangles - RoomData.NumRectangles = UnsafeConversions.UShortToShort(room.Data[RoomDataOffset]); - RoomData.Rectangles = new TRFace4[RoomData.NumRectangles]; - - RoomDataOffset++; - - for (int j = 0; j < RoomData.NumRectangles; j++) + count = rawData[offset++]; + roomData.Rectangles = new(); + for (int j = 0; j < count; j++) { - TRFace4 face = new() + roomData.Rectangles.Add(new() { - Vertices = new ushort[4] - }; - face.Vertices[0] = room.Data[RoomDataOffset]; - RoomDataOffset++; - face.Vertices[1] = room.Data[RoomDataOffset]; - RoomDataOffset++; - face.Vertices[2] = room.Data[RoomDataOffset]; - RoomDataOffset++; - face.Vertices[3] = room.Data[RoomDataOffset]; - RoomDataOffset++; - face.Texture = room.Data[RoomDataOffset]; - RoomDataOffset++; - - RoomData.Rectangles[j] = face; + Vertices = new ushort[] + { + rawData[offset++], + rawData[offset++], + rawData[offset++], + rawData[offset++], + }, + Texture = rawData[offset++], + }); } - //Room triangles - RoomData.NumTriangles = UnsafeConversions.UShortToShort(room.Data[RoomDataOffset]); - RoomData.Triangles = new TRFace3[RoomData.NumTriangles]; - - RoomDataOffset++; - - for (int j = 0; j < RoomData.NumTriangles; j++) + count = rawData[offset++]; + roomData.Triangles = new(); + for (int j = 0; j < count; j++) { - TRFace3 face = new() + roomData.Triangles.Add(new() { - Vertices = new ushort[3] - }; - face.Vertices[0] = room.Data[RoomDataOffset]; - RoomDataOffset++; - face.Vertices[1] = room.Data[RoomDataOffset]; - RoomDataOffset++; - face.Vertices[2] = room.Data[RoomDataOffset]; - RoomDataOffset++; - face.Texture = room.Data[RoomDataOffset]; - RoomDataOffset++; - - RoomData.Triangles[j] = face; + Vertices = new ushort[] + { + rawData[offset++], + rawData[offset++], + rawData[offset++], + }, + Texture = rawData[offset++], + }); } - //Room sprites - RoomData.NumSprites = UnsafeConversions.UShortToShort(room.Data[RoomDataOffset]); - RoomData.Sprites = new TRRoomSprite[RoomData.NumSprites]; - - RoomDataOffset++; - - for (int j = 0; j < RoomData.NumSprites; j++) + count = rawData[offset++]; + roomData.Sprites = new(); + for (int j = 0; j < count; j++) { - TRRoomSprite face = new() + roomData.Sprites.Add(new() { - Vertex = UnsafeConversions.UShortToShort(room.Data[RoomDataOffset]) - }; - RoomDataOffset++; - face.Texture = UnsafeConversions.UShortToShort(room.Data[RoomDataOffset]); - RoomDataOffset++; - - RoomData.Sprites[j] = face; + Vertex = UnsafeConversions.UShortToShort(rawData[offset++]), + Texture = UnsafeConversions.UShortToShort(rawData[offset++]), + }); } - Debug.Assert(RoomDataOffset == room.NumDataWords); + Debug.Assert(offset == rawData.Length); - return RoomData; + return roomData; } private void ReadSoundEffects(TRLevelReader reader) diff --git a/TRLevelControl/Control/TR2LevelControl.cs b/TRLevelControl/Control/TR2LevelControl.cs index ef55158b5..bfee5a725 100644 --- a/TRLevelControl/Control/TR2LevelControl.cs +++ b/TRLevelControl/Control/TR2LevelControl.cs @@ -60,55 +60,46 @@ protected override void Read(TRLevelReader reader) YBottom = reader.ReadInt32(), YTop = reader.ReadInt32() }, - - //Grab data - NumDataWords = reader.ReadUInt32() }; _level.Rooms.Add(room); - room.Data = new ushort[room.NumDataWords]; - for (int j = 0; j < room.NumDataWords; j++) - { - room.Data[j] = reader.ReadUInt16(); - } - - //Store what we just read - room.RoomData = ConvertToRoomData(room); + uint numWords = reader.ReadUInt32(); + room.RoomData = ConvertToRoomData(reader.ReadUInt16s(numWords)); //Portals - room.NumPortals = reader.ReadUInt16(); - room.Portals = new TRRoomPortal[room.NumPortals]; - for (int j = 0; j < room.NumPortals; j++) + ushort numPortals = reader.ReadUInt16(); + room.Portals = new(); + for (int j = 0; j < numPortals; j++) { - room.Portals[j] = TR2FileReadUtilities.ReadRoomPortal(reader); + room.Portals.Add(TR2FileReadUtilities.ReadRoomPortal(reader)); } //Sectors room.NumZSectors = reader.ReadUInt16(); room.NumXSectors = reader.ReadUInt16(); - room.SectorList = new TRRoomSector[room.NumXSectors * room.NumZSectors]; + room.Sectors = new(); for (int j = 0; j < (room.NumXSectors * room.NumZSectors); j++) { - room.SectorList[j] = TR2FileReadUtilities.ReadRoomSector(reader); + room.Sectors.Add(TR2FileReadUtilities.ReadRoomSector(reader)); } //Lighting room.AmbientIntensity = reader.ReadInt16(); room.AmbientIntensity2 = reader.ReadInt16(); room.LightMode = reader.ReadInt16(); - room.NumLights = reader.ReadUInt16(); - room.Lights = new TR2RoomLight[room.NumLights]; - for (int j = 0; j < room.NumLights; j++) + ushort numLights = reader.ReadUInt16(); + room.Lights = new(); + for (int j = 0; j < numLights; j++) { - room.Lights[j] = TR2FileReadUtilities.ReadRoomLight(reader); + room.Lights.Add(TR2FileReadUtilities.ReadRoomLight(reader)); } //Static meshes - room.NumStaticMeshes = reader.ReadUInt16(); - room.StaticMeshes = new TR2RoomStaticMesh[room.NumStaticMeshes]; - for (int j = 0; j < room.NumStaticMeshes; j++) + ushort numStaticMeshes = reader.ReadUInt16(); + room.StaticMeshes = new(); + for (int j = 0; j < numStaticMeshes; j++) { - room.StaticMeshes[j] = TR2FileReadUtilities.ReadRoomStaticMesh(reader); + room.StaticMeshes.Add(TR2FileReadUtilities.ReadRoomStaticMesh(reader)); } room.AlternateRoom = reader.ReadInt16(); @@ -293,115 +284,80 @@ private void WriteSprites(TRLevelWriter writer) _spriteBuilder.WriteSprites(writer, _level.Sprites); } - private static TR2RoomData ConvertToRoomData(TR2Room room) + private static TR2RoomData ConvertToRoomData(ushort[] rawData) { - int RoomDataOffset = 0; + // This approach is temporarily retained - //Grab detailed room data - TR2RoomData RoomData = new() + TR2RoomData roomData = new() { - //Room vertices - NumVertices = UnsafeConversions.UShortToShort(room.Data[RoomDataOffset]) + Vertices = new() }; - RoomData.Vertices = new TR2RoomVertex[RoomData.NumVertices]; - RoomDataOffset++; - - for (int j = 0; j < RoomData.NumVertices; j++) + int offset = 0; + ushort count = rawData[offset++]; + for (int j = 0; j < count; j++) { - TR2RoomVertex vertex = new() + roomData.Vertices.Add(new() { - Vertex = new TRVertex() - }; - - vertex.Vertex.X = UnsafeConversions.UShortToShort(room.Data[RoomDataOffset]); - RoomDataOffset++; - vertex.Vertex.Y = UnsafeConversions.UShortToShort(room.Data[RoomDataOffset]); - RoomDataOffset++; - vertex.Vertex.Z = UnsafeConversions.UShortToShort(room.Data[RoomDataOffset]); - RoomDataOffset++; - vertex.Lighting = UnsafeConversions.UShortToShort(room.Data[RoomDataOffset]); - RoomDataOffset++; - vertex.Attributes = room.Data[RoomDataOffset]; - RoomDataOffset++; - vertex.Lighting2 = UnsafeConversions.UShortToShort(room.Data[RoomDataOffset]); - RoomDataOffset++; - - RoomData.Vertices[j] = vertex; + Vertex = new() + { + X = UnsafeConversions.UShortToShort(rawData[offset++]), + Y = UnsafeConversions.UShortToShort(rawData[offset++]), + Z = UnsafeConversions.UShortToShort(rawData[offset++]), + }, + Lighting = UnsafeConversions.UShortToShort(rawData[offset++]), + Attributes = rawData[offset++], + Lighting2 = UnsafeConversions.UShortToShort(rawData[offset++]), + }); } - //Room rectangles - RoomData.NumRectangles = UnsafeConversions.UShortToShort(room.Data[RoomDataOffset]); - RoomData.Rectangles = new TRFace4[RoomData.NumRectangles]; - - RoomDataOffset++; - - for (int j = 0; j < RoomData.NumRectangles; j++) + count = rawData[offset++]; + roomData.Rectangles = new(); + for (int j = 0; j < count; j++) { - TRFace4 face = new() + roomData.Rectangles.Add(new() { - Vertices = new ushort[4] - }; - face.Vertices[0] = room.Data[RoomDataOffset]; - RoomDataOffset++; - face.Vertices[1] = room.Data[RoomDataOffset]; - RoomDataOffset++; - face.Vertices[2] = room.Data[RoomDataOffset]; - RoomDataOffset++; - face.Vertices[3] = room.Data[RoomDataOffset]; - RoomDataOffset++; - face.Texture = room.Data[RoomDataOffset]; - RoomDataOffset++; - - RoomData.Rectangles[j] = face; + Vertices = new ushort[] + { + rawData[offset++], + rawData[offset++], + rawData[offset++], + rawData[offset++], + }, + Texture = rawData[offset++], + }); } - //Room triangles - RoomData.NumTriangles = UnsafeConversions.UShortToShort(room.Data[RoomDataOffset]); - RoomData.Triangles = new TRFace3[RoomData.NumTriangles]; - - RoomDataOffset++; - - for (int j = 0; j < RoomData.NumTriangles; j++) + count = rawData[offset++]; + roomData.Triangles = new(); + for (int j = 0; j < count; j++) { - TRFace3 face = new() + roomData.Triangles.Add(new() { - Vertices = new ushort[3] - }; - face.Vertices[0] = room.Data[RoomDataOffset]; - RoomDataOffset++; - face.Vertices[1] = room.Data[RoomDataOffset]; - RoomDataOffset++; - face.Vertices[2] = room.Data[RoomDataOffset]; - RoomDataOffset++; - face.Texture = room.Data[RoomDataOffset]; - RoomDataOffset++; - - RoomData.Triangles[j] = face; + Vertices = new ushort[] + { + rawData[offset++], + rawData[offset++], + rawData[offset++], + }, + Texture = rawData[offset++], + }); } - //Room sprites - RoomData.NumSprites = UnsafeConversions.UShortToShort(room.Data[RoomDataOffset]); - RoomData.Sprites = new TRRoomSprite[RoomData.NumSprites]; - - RoomDataOffset++; - - for (int j = 0; j < RoomData.NumSprites; j++) + count = rawData[offset++]; + roomData.Sprites = new(); + for (int j = 0; j < count; j++) { - TRRoomSprite face = new() + roomData.Sprites.Add(new() { - Vertex = UnsafeConversions.UShortToShort(room.Data[RoomDataOffset]) - }; - RoomDataOffset++; - face.Texture = UnsafeConversions.UShortToShort(room.Data[RoomDataOffset]); - RoomDataOffset++; - - RoomData.Sprites[j] = face; + Vertex = UnsafeConversions.UShortToShort(rawData[offset++]), + Texture = UnsafeConversions.UShortToShort(rawData[offset++]), + }); } - Debug.Assert(RoomDataOffset == room.NumDataWords); + Debug.Assert(offset == rawData.Length); - return RoomData; + return roomData; } private void ReadSoundEffects(TRLevelReader reader) diff --git a/TRLevelControl/Control/TR3LevelControl.cs b/TRLevelControl/Control/TR3LevelControl.cs index a9cd64052..fbe0350b0 100644 --- a/TRLevelControl/Control/TR3LevelControl.cs +++ b/TRLevelControl/Control/TR3LevelControl.cs @@ -60,54 +60,45 @@ protected override void Read(TRLevelReader reader) YBottom = reader.ReadInt32(), YTop = reader.ReadInt32() }, - - //Grab data - NumDataWords = reader.ReadUInt32() }; _level.Rooms.Add(room); - room.Data = new ushort[room.NumDataWords]; - for (int j = 0; j < room.NumDataWords; j++) - { - room.Data[j] = reader.ReadUInt16(); - } - - //Store what we just read - room.RoomData = ConvertToRoomData(room); + uint numWords = reader.ReadUInt32(); + room.RoomData = TR3FileReadUtilities.ConvertToRoomData(reader.ReadUInt16s(numWords)); //Portals - room.NumPortals = reader.ReadUInt16(); - room.Portals = new TRRoomPortal[room.NumPortals]; - for (int j = 0; j < room.NumPortals; j++) + ushort numPortals = reader.ReadUInt16(); + room.Portals = new(); + for (int j = 0; j < numPortals; j++) { - room.Portals[j] = TR2FileReadUtilities.ReadRoomPortal(reader); + room.Portals.Add(TR2FileReadUtilities.ReadRoomPortal(reader)); } //Sectors room.NumZSectors = reader.ReadUInt16(); room.NumXSectors = reader.ReadUInt16(); - room.Sectors = new TRRoomSector[room.NumXSectors * room.NumZSectors]; + room.Sectors = new(); for (int j = 0; j < (room.NumXSectors * room.NumZSectors); j++) { - room.Sectors[j] = TR2FileReadUtilities.ReadRoomSector(reader); + room.Sectors.Add(TR2FileReadUtilities.ReadRoomSector(reader)); } //Lighting room.AmbientIntensity = reader.ReadInt16(); room.LightMode = reader.ReadInt16(); - room.NumLights = reader.ReadUInt16(); - room.Lights = new TR3RoomLight[room.NumLights]; - for (int j = 0; j < room.NumLights; j++) + ushort numLights = reader.ReadUInt16(); + room.Lights = new(); + for (int j = 0; j < numLights; j++) { - room.Lights[j] = TR3FileReadUtilities.ReadRoomLight(reader); + room.Lights.Add(TR3FileReadUtilities.ReadRoomLight(reader)); } //Static meshes - room.NumStaticMeshes = reader.ReadUInt16(); - room.StaticMeshes = new TR3RoomStaticMesh[room.NumStaticMeshes]; - for (int j = 0; j < room.NumStaticMeshes; j++) + ushort numStaticMeshes = reader.ReadUInt16(); + room.StaticMeshes = new(); + for (int j = 0; j < numStaticMeshes; j++) { - room.StaticMeshes[j] = TR3FileReadUtilities.ReadRoomStaticMesh(reader); + room.StaticMeshes.Add(TR3FileReadUtilities.ReadRoomStaticMesh(reader)); } room.AlternateRoom = reader.ReadInt16(); @@ -299,117 +290,6 @@ private void WriteSprites(TRLevelWriter writer) _spriteBuilder.WriteSprites(writer, _level.Sprites); } - private static TR3RoomData ConvertToRoomData(TR3Room room) - { - int RoomDataOffset = 0; - - //Grab detailed room data - TR3RoomData RoomData = new() - { - //Room vertices - NumVertices = UnsafeConversions.UShortToShort(room.Data[RoomDataOffset]) - }; - RoomData.Vertices = new TR3RoomVertex[RoomData.NumVertices]; - - RoomDataOffset++; - - for (int j = 0; j < RoomData.NumVertices; j++) - { - TR3RoomVertex vertex = new() - { - Vertex = new TRVertex() - }; - - vertex.Vertex.X = UnsafeConversions.UShortToShort(room.Data[RoomDataOffset]); - RoomDataOffset++; - vertex.Vertex.Y = UnsafeConversions.UShortToShort(room.Data[RoomDataOffset]); - RoomDataOffset++; - vertex.Vertex.Z = UnsafeConversions.UShortToShort(room.Data[RoomDataOffset]); - RoomDataOffset++; - vertex.Lighting = UnsafeConversions.UShortToShort(room.Data[RoomDataOffset]); - RoomDataOffset++; - vertex.Attributes = room.Data[RoomDataOffset]; - RoomDataOffset++; - vertex.Colour = room.Data[RoomDataOffset]; - RoomDataOffset++; - - RoomData.Vertices[j] = vertex; - } - - //Room rectangles - RoomData.NumRectangles = UnsafeConversions.UShortToShort(room.Data[RoomDataOffset]); - RoomData.Rectangles = new TRFace4[RoomData.NumRectangles]; - - RoomDataOffset++; - - for (int j = 0; j < RoomData.NumRectangles; j++) - { - TRFace4 face = new() - { - Vertices = new ushort[4] - }; - face.Vertices[0] = room.Data[RoomDataOffset]; - RoomDataOffset++; - face.Vertices[1] = room.Data[RoomDataOffset]; - RoomDataOffset++; - face.Vertices[2] = room.Data[RoomDataOffset]; - RoomDataOffset++; - face.Vertices[3] = room.Data[RoomDataOffset]; - RoomDataOffset++; - face.Texture = room.Data[RoomDataOffset]; - RoomDataOffset++; - - RoomData.Rectangles[j] = face; - } - - //Room triangles - RoomData.NumTriangles = UnsafeConversions.UShortToShort(room.Data[RoomDataOffset]); - RoomData.Triangles = new TRFace3[RoomData.NumTriangles]; - - RoomDataOffset++; - - for (int j = 0; j < RoomData.NumTriangles; j++) - { - TRFace3 face = new() - { - Vertices = new ushort[3] - }; - face.Vertices[0] = room.Data[RoomDataOffset]; - RoomDataOffset++; - face.Vertices[1] = room.Data[RoomDataOffset]; - RoomDataOffset++; - face.Vertices[2] = room.Data[RoomDataOffset]; - RoomDataOffset++; - face.Texture = room.Data[RoomDataOffset]; - RoomDataOffset++; - - RoomData.Triangles[j] = face; - } - - //Room sprites - RoomData.NumSprites = UnsafeConversions.UShortToShort(room.Data[RoomDataOffset]); - RoomData.Sprites = new TRRoomSprite[RoomData.NumSprites]; - - RoomDataOffset++; - - for (int j = 0; j < RoomData.NumSprites; j++) - { - TRRoomSprite face = new() - { - Vertex = UnsafeConversions.UShortToShort(room.Data[RoomDataOffset]) - }; - RoomDataOffset++; - face.Texture = UnsafeConversions.UShortToShort(room.Data[RoomDataOffset]); - RoomDataOffset++; - - RoomData.Sprites[j] = face; - } - - Debug.Assert(RoomDataOffset == room.NumDataWords); - - return RoomData; - } - private void ReadSoundEffects(TRLevelReader reader) { _level.SoundEffects = new(); diff --git a/TRLevelControl/Helpers/Pathing/Room.cs b/TRLevelControl/Helpers/Pathing/Room.cs index e175b086d..c3396b955 100644 --- a/TRLevelControl/Helpers/Pathing/Room.cs +++ b/TRLevelControl/Helpers/Pathing/Room.cs @@ -35,7 +35,7 @@ public static Room Create(TR2Room room) Ceiling = (sbyte)(room.Info.YTop / TRConsts.Step1), NumXSectors = room.NumXSectors, NumZSectors = room.NumZSectors, - Sectors = room.SectorList.ToList(), + Sectors = room.Sectors.ToList(), FloorPlan = new List(), Boxes = new List() }; diff --git a/TRLevelControl/Helpers/TR2BoxUtilities.cs b/TRLevelControl/Helpers/TR2BoxUtilities.cs index 7f8f1dfcb..ae7ad79d4 100644 --- a/TRLevelControl/Helpers/TR2BoxUtilities.cs +++ b/TRLevelControl/Helpers/TR2BoxUtilities.cs @@ -105,7 +105,7 @@ public static int GetSectorCount(TR2Level level, int boxIndex) int count = 0; foreach (TR2Room room in level.Rooms) { - foreach (TRRoomSector sector in room.SectorList) + foreach (TRRoomSector sector in room.Sectors) { if (sector.BoxIndex == boxIndex) { diff --git a/TRLevelControl/Model/TR1/TR1Room.cs b/TRLevelControl/Model/TR1/TR1Room.cs index b65a2209a..0e69b2fba 100644 --- a/TRLevelControl/Model/TR1/TR1Room.cs +++ b/TRLevelControl/Model/TR1/TR1Room.cs @@ -5,100 +5,45 @@ namespace TRLevelControl.Model; public class TR1Room : ISerializableCompact { public TRRoomInfo Info { get; set; } - - public uint NumDataWords { get; set; } - - public ushort[] Data { get; set; } - public TR1RoomData RoomData { get; set; } - - public ushort NumPortals { get; set; } - - public TRRoomPortal[] Portals { get; set; } - + public List Portals { get; set; } public ushort NumZSectors { get; set; } - public ushort NumXSectors { get; set; } - - public TRRoomSector[] Sectors { get; set; } - + public List Sectors { get; set; } public short AmbientIntensity { get; set; } - - public ushort NumLights { get; set; } - - public TR1RoomLight[] Lights { get; set; } - - public ushort NumStaticMeshes { get; set; } - - public TR1RoomStaticMesh[] StaticMeshes { get; set; } - + public List Lights { get; set; } + public List StaticMeshes { get; set; } public short AlternateRoom { get; set; } - public short Flags { get; set; } public bool ContainsWater { - get - { - return (Flags & 0x01) > 0; - } - } - - public void Fill() - { - Flags |= 0x01; - } - - public void Drain() - { - Flags &= ~0x01; - } - - //Ambient Intensity = 0 (bright) - 0x1FFF (dark) - //Vertex Light = 0 (bright) - 0x1FFF (dark) - //RoomStaticMesh intensity = 0 (bright) - 0x1FFF (dark) - //but... - //Light intensity = 0 (dark) - 0x1FFF (bright)!!! - public void SetLights(ushort val) - { - foreach (TR1RoomLight light in Lights) - { - light.Intensity = val; - } - } - - public void SetStaticMeshLights(ushort val) - { - foreach (TR1RoomStaticMesh mesh in StaticMeshes) + get => (Flags & 0x01) > 0; + set { - mesh.Intensity = val; - } - } - - public void SetVertexLight(short val) - { - foreach (TR1RoomVertex vert in RoomData.Vertices) - { - vert.Lighting = val; + if (value) + { + Flags |= 0x01; + } + else + { + Flags &= ~0x01; + } } } - public void SetAmbient(short val) - { - AmbientIntensity = val; - } - public byte[] Serialize() { using MemoryStream stream = new(); using (BinaryWriter writer = new(stream)) { writer.Write(Info.Serialize()); - writer.Write(NumDataWords); - writer.Write(RoomData.Serialize()); - writer.Write(NumPortals); + byte[] meshData = RoomData.Serialize(); + writer.Write((uint)meshData.Length / sizeof(short)); + writer.Write(meshData); + writer.Write((ushort)Portals.Count); foreach (TRRoomPortal portal in Portals) { writer.Write(portal.Serialize()); @@ -106,22 +51,20 @@ public byte[] Serialize() writer.Write(NumZSectors); writer.Write(NumXSectors); - foreach (TRRoomSector sector in Sectors) { writer.Write(sector.Serialize()); } writer.Write(AmbientIntensity); - writer.Write(NumLights); - + + writer.Write((ushort)Lights.Count); foreach (TR1RoomLight light in Lights) { writer.Write(light.Serialize()); } - writer.Write(NumStaticMeshes); - + writer.Write((ushort)StaticMeshes.Count); foreach (TR1RoomStaticMesh mesh in StaticMeshes) { writer.Write(mesh.Serialize()); diff --git a/TRLevelControl/Model/TR1/TR1RoomData.cs b/TRLevelControl/Model/TR1/TR1RoomData.cs index c4cbb38f7..c0274f836 100644 --- a/TRLevelControl/Model/TR1/TR1RoomData.cs +++ b/TRLevelControl/Model/TR1/TR1RoomData.cs @@ -4,50 +4,35 @@ namespace TRLevelControl.Model; public class TR1RoomData : ISerializableCompact { - public short NumVertices { get; set; } - - public TR1RoomVertex[] Vertices { get; set; } - - public short NumRectangles { get; set; } - - public TRFace4[] Rectangles { get; set; } - - public short NumTriangles { get; set; } - - public TRFace3[] Triangles { get; set; } - - public short NumSprites { get; set; } - - public TRRoomSprite[] Sprites { get; set; } + public List Vertices { get; set; } + public List Rectangles { get; set; } + public List Triangles { get; set; } + public List Sprites { get; set; } public byte[] Serialize() { using MemoryStream stream = new(); using (BinaryWriter writer = new(stream)) { - writer.Write(NumVertices); - + writer.Write((short)Vertices.Count); foreach (TR1RoomVertex vert in Vertices) { writer.Write(vert.Serialize()); } - writer.Write(NumRectangles); - + writer.Write((short)Rectangles.Count); foreach (TRFace4 face in Rectangles) { writer.Write(face.Serialize()); } - writer.Write(NumTriangles); - + writer.Write((short)Triangles.Count); foreach (TRFace3 face in Triangles) { writer.Write(face.Serialize()); } - writer.Write(NumSprites); - + writer.Write((short)Sprites.Count); foreach (TRRoomSprite sprite in Sprites) { writer.Write(sprite.Serialize()); diff --git a/TRLevelControl/Model/TR2/TR2Room.cs b/TRLevelControl/Model/TR2/TR2Room.cs index 1cd72dcc8..9acce52a6 100644 --- a/TRLevelControl/Model/TR2/TR2Room.cs +++ b/TRLevelControl/Model/TR2/TR2Room.cs @@ -1,85 +1,39 @@ -using System.Text; -using TRLevelControl.Serialization; +using TRLevelControl.Serialization; namespace TRLevelControl.Model; public class TR2Room : ISerializableCompact { - public static readonly short DarknessIntensity1 = 8000; - public static readonly ushort DarknessIntensity2 = 1000; - - //16 bytes public TRRoomInfo Info { get; set; } - - //4 bytes - public uint NumDataWords { get; set; } - - //2 * NumDataWords bytes - public ushort[] Data { get; set; } - - //Variable public TR2RoomData RoomData { get; set; } - - //2 bytes - public ushort NumPortals { get; set; } - - //32 * NumPortals bytes - public TRRoomPortal[] Portals { get; set; } - - //2 bytes + public List Portals { get; set; } public ushort NumZSectors { get; set; } - - //2 bytes public ushort NumXSectors { get; set; } - - //(Xs * Zs) * 8 bytes - public TRRoomSector[] SectorList { get; set; } - - //2 bytes + public List Sectors { get; set; } public short AmbientIntensity { get; set; } - - //2 bytes public short AmbientIntensity2 { get; set; } - - //2 bytes public short LightMode { get; set; } - - //2 bytes - public ushort NumLights { get; set; } - - //24 * NumLights bytes - public TR2RoomLight[] Lights { get; set; } - - //2 bytes - public ushort NumStaticMeshes { get; set; } - - //20 * NumStaticMeshes bytes - public TR2RoomStaticMesh[] StaticMeshes { get; set; } - - //2 bytes + public List Lights { get; set; } + public List StaticMeshes { get; set; } public short AlternateRoom { get; set; } - - //2 bytes public short Flags { get; set; } - public bool ContainsWater + public bool ContainsWater { - get + get => (Flags & 0x01) > 0; + set { - return ((Flags & 0x01) > 0); + if (value) + { + Flags |= 0x01; + } + else + { + Flags &= ~0x01; + } } } - public void Fill() - { - Flags |= 0x01; - } - - public void Drain() - { - Flags &= ~(0x01); - } - public bool IsSkyboxVisible { get => (Flags & 0x08) > 0; @@ -112,63 +66,18 @@ public bool IsWindy } } - //Ambient Intensity = 0 (bright) - 0x1FFF (dark) - //Vertex Light = 0 (bright) - 0x1FFF (dark) - //RoomStaticMesh intensity = 0 (bright) - 0x1FFF (dark) - //but... - //Light intensity = 0 (dark) - 0x1FFF (bright)!!! - public void SetLights(ushort val) - { - foreach (TR2RoomLight light in Lights) - { - light.Intensity1 = val; - light.Intensity2 = val; - } - } - - public void SetStaticMeshLights(ushort val) - { - foreach (TR2RoomStaticMesh mesh in StaticMeshes) - { - mesh.Intensity1 = val; - mesh.Intensity2 = val; - } - } - - public void SetVertexLight(short val) - { - foreach (TR2RoomVertex vert in RoomData.Vertices) - { - vert.Lighting = val; - vert.Lighting2 = val; - } - } - - public void SetAmbient(short val) - { - AmbientIntensity = val; - AmbientIntensity2 = val; - } - - public void Darken() - { - SetAmbient(DarknessIntensity1); - SetLights(DarknessIntensity2); - SetStaticMeshLights((ushort)DarknessIntensity1); - SetVertexLight(DarknessIntensity1); - } - public byte[] Serialize() { using MemoryStream stream = new(); using (BinaryWriter writer = new(stream)) { writer.Write(Info.Serialize()); - writer.Write(NumDataWords); - writer.Write(RoomData.Serialize()); - writer.Write(NumPortals); + byte[] meshData = RoomData.Serialize(); + writer.Write((uint)meshData.Length / sizeof(short)); + writer.Write(meshData); + writer.Write((ushort)Portals.Count); foreach (TRRoomPortal portal in Portals) { writer.Write(portal.Serialize()); @@ -176,8 +85,7 @@ public byte[] Serialize() writer.Write(NumZSectors); writer.Write(NumXSectors); - - foreach (TRRoomSector sector in SectorList) + foreach (TRRoomSector sector in Sectors) { writer.Write(sector.Serialize()); } @@ -185,15 +93,14 @@ public byte[] Serialize() writer.Write(AmbientIntensity); writer.Write(AmbientIntensity2); writer.Write(LightMode); - writer.Write(NumLights); + writer.Write((ushort)Lights.Count); foreach (TR2RoomLight light in Lights) { writer.Write(light.Serialize()); } - writer.Write(NumStaticMeshes); - + writer.Write((ushort)StaticMeshes.Count); foreach (TR2RoomStaticMesh mesh in StaticMeshes) { writer.Write(mesh.Serialize()); @@ -205,13 +112,4 @@ public byte[] Serialize() return stream.ToArray(); } - - public override string ToString() - { - StringBuilder sb = new(base.ToString()); - - sb.Append(" RoomInfo: { " + Info.ToString() + "}"); - - return sb.ToString(); - } } diff --git a/TRLevelControl/Model/TR2/TR2RoomData.cs b/TRLevelControl/Model/TR2/TR2RoomData.cs index 7e46f787e..7acd5a51e 100644 --- a/TRLevelControl/Model/TR2/TR2RoomData.cs +++ b/TRLevelControl/Model/TR2/TR2RoomData.cs @@ -4,58 +4,35 @@ namespace TRLevelControl.Model; public class TR2RoomData : ISerializableCompact { - // 2 bytes - public short NumVertices { get; set; } - - // NumVertices * 12 bytes - public TR2RoomVertex[] Vertices { get; set; } - - // 2 bytes - public short NumRectangles { get; set; } - - // NumRectangles * 10 bytes - public TRFace4[] Rectangles { get; set; } - - // 2 bytes - public short NumTriangles { get; set; } - - // NumTriangles * 8 bytes - public TRFace3[] Triangles { get; set; } - - // 2 bytes - public short NumSprites { get; set; } - - // NumSprites * 4 bytes bytes - public TRRoomSprite[] Sprites { get; set; } + public List Vertices { get; set; } + public List Rectangles { get; set; } + public List Triangles { get; set; } + public List Sprites { get; set; } public byte[] Serialize() { using MemoryStream stream = new(); using (BinaryWriter writer = new(stream)) { - writer.Write(NumVertices); - + writer.Write((short)Vertices.Count); foreach (TR2RoomVertex vert in Vertices) { writer.Write(vert.Serialize()); } - writer.Write(NumRectangles); - + writer.Write((short)Rectangles.Count); foreach (TRFace4 face in Rectangles) { writer.Write(face.Serialize()); } - writer.Write(NumTriangles); - + writer.Write((short)Triangles.Count); foreach (TRFace3 face in Triangles) { writer.Write(face.Serialize()); } - writer.Write(NumSprites); - + writer.Write((short)Sprites.Count); foreach (TRRoomSprite sprite in Sprites) { writer.Write(sprite.Serialize()); diff --git a/TRLevelControl/Model/TR3/TR3Room.cs b/TRLevelControl/Model/TR3/TR3Room.cs index d08860690..9589efdfe 100644 --- a/TRLevelControl/Model/TR3/TR3Room.cs +++ b/TRLevelControl/Model/TR3/TR3Room.cs @@ -1,53 +1,23 @@ -using System.Diagnostics; -using System.Drawing; - -using TRLevelControl.Serialization; +using TRLevelControl.Serialization; namespace TRLevelControl.Model; public class TR3Room : ISerializableCompact { - private readonly byte SPOT_LIGHT_TYPE = 0; - private readonly byte SUN_LIGHT_TYPE = 1; - public TRRoomInfo Info { get; set; } - - public uint NumDataWords { get; set; } - - public ushort[] Data { get; set; } - public TR3RoomData RoomData { get; set; } - - public ushort NumPortals { get; set; } - - public TRRoomPortal[] Portals { get; set; } - + public List Portals { get; set; } public ushort NumZSectors { get; set; } - public ushort NumXSectors { get; set; } - - public TRRoomSector[] Sectors { get; set; } - + public List Sectors { get; set; } public short AmbientIntensity { get; set; } - public short LightMode { get; set; } - - public ushort NumLights { get; set; } - - public TR3RoomLight[] Lights { get; set; } - - public ushort NumStaticMeshes { get; set; } - - public TR3RoomStaticMesh[] StaticMeshes { get; set; } - + public List Lights { get; set; } + public List StaticMeshes { get; set; } public short AlternateRoom { get; set; } - public short Flags { get; set; } - public byte WaterScheme { get; set; } - public byte ReverbInfo { get; set; } - public byte Filler { get; set; } public bool ContainsWater @@ -117,125 +87,18 @@ public bool IsSwamp } } - public void SetAmbient(short val) - { - AmbientIntensity = val; - } - - public void SetLights(ushort val) - { - foreach (TR3RoomLight light in Lights) - { - Debug.Assert(light.LightProperties.Length == 4); - - if (light.LightType == SUN_LIGHT_TYPE) - { - light.LightProperties[0] = 0; - light.LightProperties[1] = 0; - light.LightProperties[2] = 0; - light.LightProperties[3] = 0; - } - else if (light.LightType == SPOT_LIGHT_TYPE) - { - TR3RoomSpotlight spotLight = new() - { - Intensity = ((light.LightProperties[0] << 16) | ((light.LightProperties[1]) & 0xffff)), - Fade = ((light.LightProperties[2] << 16) | ((light.LightProperties[3]) & 0xffff)) - }; - - spotLight.Intensity = val; - - light.LightProperties[0] = (short)(spotLight.Intensity >> 16); - light.LightProperties[1] = (short)(spotLight.Intensity & 0xFFFF); - light.LightProperties[2] = (short)(spotLight.Fade >> 16); - light.LightProperties[3] = (short)(spotLight.Fade & 0xFFFF); - } - } - } - - public void SetVertexLight(short val) - { - foreach (TR3RoomVertex vert in RoomData.Vertices) - { - vert.Lighting = val; - - byte red = (byte)((vert.Colour & 0x7C00) >> 10); - byte green = (byte)((vert.Colour & 0x03E0) >> 5); - byte blue = (byte)(vert.Colour & 0x001F); - - red -= (byte)(red * val / 100); - green -= (byte)(green * val / 100); - blue -= (byte)(blue * val / 100); - - vert.Colour = (ushort)((red << 10) | (green << 5) | (blue)); - } - } - - #region Vertex Effects & Filters - public void SetColourFilter(Color col, bool replace, bool enableCaustics, bool enableWave) - { - foreach (TR3RoomVertex vert in RoomData.Vertices) - { - byte curRed = (byte)((vert.Colour & 0x7C00) >> 10); - byte curGreen = (byte)((vert.Colour & 0x03E0) >> 5); - byte curBlue = (byte)(vert.Colour & 0x001F); - - byte newRed = ConvertColorChannelToRGB555(col.R); - byte newGreen = ConvertColorChannelToRGB555(col.G); - byte newBlue = ConvertColorChannelToRGB555(col.B); - - if (replace) - { - byte applyR = curRed; - byte applyG = curGreen; - byte applyB = curBlue; - - if (newRed > 0) - applyR = newRed; - - if (newGreen > 0) - applyG = newGreen; - - if (newBlue > 0) - applyB = newBlue; - - vert.Colour = (ushort)((applyR << 10) | (applyG << 5) | (applyB)); - } - else - { - vert.Colour = (ushort)((Blend(curRed, newRed) << 10) | (Blend(curGreen, newGreen) << 5) | (Blend(curBlue, newBlue))); - } - - // #296 Retain original caustics and waves for water/swamp rooms - if (!vert.UseCaustics) - vert.UseCaustics = enableCaustics; - if (!vert.UseWaveMovement) - vert.UseWaveMovement = enableWave; - } - } - - private static byte ConvertColorChannelToRGB555(byte col) - { - return (byte)(((col - byte.MinValue) * (31 - 0)) / (byte.MaxValue - byte.MinValue) + 0); - } - - private static byte Blend(byte curChannel, byte newChannel) - { - return Math.Min((byte)((newChannel * 0.1) + curChannel * (1 - 0.1)), (byte)31); - } - #endregion - public byte[] Serialize() { using MemoryStream stream = new(); using (BinaryWriter writer = new(stream)) { writer.Write(Info.Serialize()); - writer.Write(NumDataWords); - writer.Write(RoomData.Serialize()); - writer.Write(NumPortals); + byte[] meshData = RoomData.Serialize(); + writer.Write((uint)meshData.Length / sizeof(short)); + writer.Write(meshData); + writer.Write((ushort)Portals.Count); foreach (TRRoomPortal portal in Portals) { writer.Write(portal.Serialize()); @@ -243,7 +106,6 @@ public byte[] Serialize() writer.Write(NumZSectors); writer.Write(NumXSectors); - foreach (TRRoomSector sector in Sectors) { writer.Write(sector.Serialize()); @@ -251,15 +113,14 @@ public byte[] Serialize() writer.Write(AmbientIntensity); writer.Write(LightMode); - writer.Write(NumLights); + writer.Write((ushort)Lights.Count); foreach (TR3RoomLight light in Lights) { writer.Write(light.Serialize()); } - writer.Write(NumStaticMeshes); - + writer.Write((ushort)StaticMeshes.Count); foreach (TR3RoomStaticMesh mesh in StaticMeshes) { writer.Write(mesh.Serialize()); diff --git a/TRLevelControl/Model/TR3/TR3RoomData.cs b/TRLevelControl/Model/TR3/TR3RoomData.cs index efb3ab755..4053ee6ee 100644 --- a/TRLevelControl/Model/TR3/TR3RoomData.cs +++ b/TRLevelControl/Model/TR3/TR3RoomData.cs @@ -4,58 +4,35 @@ namespace TRLevelControl.Model; public class TR3RoomData : ISerializableCompact { - // 2 bytes - public short NumVertices { get; set; } - - // NumVertices * 12 bytes - public TR3RoomVertex[] Vertices { get; set; } - - // 2 bytes - public short NumRectangles { get; set; } - - // NumRectangles * 10 bytes - public TRFace4[] Rectangles { get; set; } - - // 2 bytes - public short NumTriangles { get; set; } - - // NumTriangles * 8 bytes - public TRFace3[] Triangles { get; set; } - - // 2 bytes - public short NumSprites { get; set; } - - // NumSprites * 4 bytes bytes - public TRRoomSprite[] Sprites { get; set; } + public List Vertices { get; set; } + public List Rectangles { get; set; } + public List Triangles { get; set; } + public List Sprites { get; set; } public byte[] Serialize() { using MemoryStream stream = new(); using (BinaryWriter writer = new(stream)) { - writer.Write(NumVertices); - + writer.Write((short)Vertices.Count); foreach (TR3RoomVertex vert in Vertices) { writer.Write(vert.Serialize()); } - writer.Write(NumRectangles); - + writer.Write((short)Rectangles.Count); foreach (TRFace4 face in Rectangles) { writer.Write(face.Serialize()); } - writer.Write(NumTriangles); - + writer.Write((short)Triangles.Count); foreach (TRFace3 face in Triangles) { writer.Write(face.Serialize()); } - writer.Write(NumSprites); - + writer.Write((short)Sprites.Count); foreach (TRRoomSprite sprite in Sprites) { writer.Write(sprite.Serialize()); diff --git a/TRLevelControl/Model/TR4/TR4Room.cs b/TRLevelControl/Model/TR4/TR4Room.cs index 207a8b1b7..337d794da 100644 --- a/TRLevelControl/Model/TR4/TR4Room.cs +++ b/TRLevelControl/Model/TR4/TR4Room.cs @@ -5,43 +5,19 @@ namespace TRLevelControl.Model; public class TR4Room : ISerializableCompact { public TRRoomInfo Info { get; set; } - - public uint NumDataWords { get; set; } - - public ushort[] Data { get; set; } - public TR3RoomData RoomData { get; set; } - - public ushort NumPortals { get; set; } - - public TRRoomPortal[] Portals { get; set; } - + public List Portals { get; set; } public ushort NumZSectors { get; set; } - public ushort NumXSectors { get; set; } - - public TRRoomSector[] Sectors { get; set; } - + public List Sectors { get; set; } public short AmbientIntensity { get; set; } - public short LightMode { get; set; } - - public ushort NumLights { get; set; } - - public TR4RoomLight[] Lights { get; set; } - - public ushort NumStaticMeshes { get; set; } - - public TR3RoomStaticMesh[] StaticMeshes { get; set; } - + public List Lights { get; set; } + public List StaticMeshes { get; set; } public short AlternateRoom { get; set; } - public short Flags { get; set; } - public byte WaterScheme { get; set; } - public byte ReverbInfo { get; set; } - public byte Filler { get; set; } public byte[] Serialize() @@ -50,11 +26,12 @@ public byte[] Serialize() using (BinaryWriter writer = new(stream)) { writer.Write(Info.Serialize()); - writer.Write(NumDataWords); - writer.Write(RoomData.Serialize()); - writer.Write(NumPortals); + byte[] meshData = RoomData.Serialize(); + writer.Write((uint)meshData.Length / sizeof(short)); + writer.Write(meshData); + writer.Write((ushort)Portals.Count); foreach (TRRoomPortal portal in Portals) { writer.Write(portal.Serialize()); @@ -62,7 +39,6 @@ public byte[] Serialize() writer.Write(NumZSectors); writer.Write(NumXSectors); - foreach (TRRoomSector sector in Sectors) { writer.Write(sector.Serialize()); @@ -70,15 +46,14 @@ public byte[] Serialize() writer.Write(AmbientIntensity); writer.Write(LightMode); - writer.Write(NumLights); + writer.Write((ushort)Lights.Count); foreach (TR4RoomLight light in Lights) { writer.Write(light.Serialize()); } - writer.Write(NumStaticMeshes); - + writer.Write((ushort)StaticMeshes.Count); foreach (TR3RoomStaticMesh mesh in StaticMeshes) { writer.Write(mesh.Serialize()); diff --git a/TRLevelControl/TR3FileReadUtilities.cs b/TRLevelControl/TR3FileReadUtilities.cs index 68063bed5..d9bd15e46 100644 --- a/TRLevelControl/TR3FileReadUtilities.cs +++ b/TRLevelControl/TR3FileReadUtilities.cs @@ -1,9 +1,86 @@ -using TRLevelControl.Model; +using System.Diagnostics; +using TRLevelControl.Model; namespace TRLevelControl; internal static class TR3FileReadUtilities { + public static TR3RoomData ConvertToRoomData(ushort[] rawData) + { + // This approach is temporarily retained + + TR3RoomData roomData = new() + { + Vertices = new() + }; + + int offset = 0; + ushort count = rawData[offset++]; + for (int j = 0; j < count; j++) + { + roomData.Vertices.Add(new() + { + Vertex = new() + { + X = UnsafeConversions.UShortToShort(rawData[offset++]), + Y = UnsafeConversions.UShortToShort(rawData[offset++]), + Z = UnsafeConversions.UShortToShort(rawData[offset++]), + }, + Lighting = UnsafeConversions.UShortToShort(rawData[offset++]), + Attributes = rawData[offset++], + Colour = rawData[offset++], + }); + } + + count = rawData[offset++]; + roomData.Rectangles = new(); + for (int j = 0; j < count; j++) + { + roomData.Rectangles.Add(new() + { + Vertices = new ushort[] + { + rawData[offset++], + rawData[offset++], + rawData[offset++], + rawData[offset++], + }, + Texture = rawData[offset++], + }); + } + + count = rawData[offset++]; + roomData.Triangles = new(); + for (int j = 0; j < count; j++) + { + roomData.Triangles.Add(new() + { + Vertices = new ushort[] + { + rawData[offset++], + rawData[offset++], + rawData[offset++], + }, + Texture = rawData[offset++], + }); + } + + count = rawData[offset++]; + roomData.Sprites = new(); + for (int j = 0; j < count; j++) + { + roomData.Sprites.Add(new() + { + Vertex = UnsafeConversions.UShortToShort(rawData[offset++]), + Texture = UnsafeConversions.UShortToShort(rawData[offset++]), + }); + } + + Debug.Assert(offset == rawData.Length); + + return roomData; + } + public static TR3RoomLight ReadRoomLight(BinaryReader reader) { return new TR3RoomLight diff --git a/TRLevelControl/TR4FileReadUtilities.cs b/TRLevelControl/TR4FileReadUtilities.cs index 0b7824208..32e00f566 100644 --- a/TRLevelControl/TR4FileReadUtilities.cs +++ b/TRLevelControl/TR4FileReadUtilities.cs @@ -6,10 +6,9 @@ namespace TRLevelControl; internal static class TR4FileReadUtilities { - public static readonly string SPRMarker = "SPR"; public static readonly string TEXMarker = "TEX"; - public static void PopulateRooms(BinaryReader reader, TR4Level lvl) + public static void PopulateRooms(TRLevelReader reader, TR4Level lvl) { ushort numRooms = reader.ReadUInt16(); lvl.Rooms = new(); @@ -26,54 +25,45 @@ public static void PopulateRooms(BinaryReader reader, TR4Level lvl) YBottom = reader.ReadInt32(), YTop = reader.ReadInt32() }, - - //Grab data - NumDataWords = reader.ReadUInt32() }; lvl.Rooms.Add(room); - room.Data = new ushort[room.NumDataWords]; - for (int j = 0; j < room.NumDataWords; j++) - { - room.Data[j] = reader.ReadUInt16(); - } - - //Store what we just read - room.RoomData = ConvertToRoomData(room); + uint numWords = reader.ReadUInt32(); + room.RoomData = TR3FileReadUtilities.ConvertToRoomData(reader.ReadUInt16s(numWords)); //Portals - room.NumPortals = reader.ReadUInt16(); - room.Portals = new TRRoomPortal[room.NumPortals]; - for (int j = 0; j < room.NumPortals; j++) + ushort numPortals = reader.ReadUInt16(); + room.Portals = new(); + for (int j = 0; j < numPortals; j++) { - room.Portals[j] = TR2FileReadUtilities.ReadRoomPortal(reader); + room.Portals.Add(TR2FileReadUtilities.ReadRoomPortal(reader)); } //Sectors room.NumZSectors = reader.ReadUInt16(); room.NumXSectors = reader.ReadUInt16(); - room.Sectors = new TRRoomSector[room.NumXSectors * room.NumZSectors]; + room.Sectors = new(); for (int j = 0; j < (room.NumXSectors * room.NumZSectors); j++) { - room.Sectors[j] = TR2FileReadUtilities.ReadRoomSector(reader); + room.Sectors.Add(TR2FileReadUtilities.ReadRoomSector(reader)); } //Lighting room.AmbientIntensity = reader.ReadInt16(); room.LightMode = reader.ReadInt16(); - room.NumLights = reader.ReadUInt16(); - room.Lights = new TR4RoomLight[room.NumLights]; - for (int j = 0; j < room.NumLights; j++) + ushort numLights = reader.ReadUInt16(); + room.Lights = new(); + for (int j = 0; j < numLights; j++) { - room.Lights[j] = ReadRoomLight(reader); + room.Lights.Add(ReadRoomLight(reader)); } //Static meshes - room.NumStaticMeshes = reader.ReadUInt16(); - room.StaticMeshes = new TR3RoomStaticMesh[room.NumStaticMeshes]; - for (int j = 0; j < room.NumStaticMeshes; j++) + ushort numStaticMeshes = reader.ReadUInt16(); + room.StaticMeshes = new(); + for (int j = 0; j < numStaticMeshes; j++) { - room.StaticMeshes[j] = TR3FileReadUtilities.ReadRoomStaticMesh(reader); + room.StaticMeshes.Add(TR3FileReadUtilities.ReadRoomStaticMesh(reader)); } room.AlternateRoom = reader.ReadInt16(); @@ -195,117 +185,6 @@ public static void PopulateEntitiesAndAI(TRLevelReader reader, TR4Level lvl) lvl.AIEntities = reader.ReadTR4AIEntities(numEntities); } - private static TR3RoomData ConvertToRoomData(TR4Room room) - { - int RoomDataOffset = 0; - - //Grab detailed room data - TR3RoomData RoomData = new() - { - //Room vertices - NumVertices = UnsafeConversions.UShortToShort(room.Data[RoomDataOffset]) - }; - RoomData.Vertices = new TR3RoomVertex[RoomData.NumVertices]; - - RoomDataOffset++; - - for (int j = 0; j < RoomData.NumVertices; j++) - { - TR3RoomVertex vertex = new() - { - Vertex = new TRVertex() - }; - - vertex.Vertex.X = UnsafeConversions.UShortToShort(room.Data[RoomDataOffset]); - RoomDataOffset++; - vertex.Vertex.Y = UnsafeConversions.UShortToShort(room.Data[RoomDataOffset]); - RoomDataOffset++; - vertex.Vertex.Z = UnsafeConversions.UShortToShort(room.Data[RoomDataOffset]); - RoomDataOffset++; - vertex.Lighting = UnsafeConversions.UShortToShort(room.Data[RoomDataOffset]); - RoomDataOffset++; - vertex.Attributes = room.Data[RoomDataOffset]; - RoomDataOffset++; - vertex.Colour = room.Data[RoomDataOffset]; - RoomDataOffset++; - - RoomData.Vertices[j] = vertex; - } - - //Room rectangles - RoomData.NumRectangles = UnsafeConversions.UShortToShort(room.Data[RoomDataOffset]); - RoomData.Rectangles = new TRFace4[RoomData.NumRectangles]; - - RoomDataOffset++; - - for (int j = 0; j < RoomData.NumRectangles; j++) - { - TRFace4 face = new() - { - Vertices = new ushort[4] - }; - face.Vertices[0] = room.Data[RoomDataOffset]; - RoomDataOffset++; - face.Vertices[1] = room.Data[RoomDataOffset]; - RoomDataOffset++; - face.Vertices[2] = room.Data[RoomDataOffset]; - RoomDataOffset++; - face.Vertices[3] = room.Data[RoomDataOffset]; - RoomDataOffset++; - face.Texture = room.Data[RoomDataOffset]; - RoomDataOffset++; - - RoomData.Rectangles[j] = face; - } - - //Room triangles - RoomData.NumTriangles = UnsafeConversions.UShortToShort(room.Data[RoomDataOffset]); - RoomData.Triangles = new TRFace3[RoomData.NumTriangles]; - - RoomDataOffset++; - - for (int j = 0; j < RoomData.NumTriangles; j++) - { - TRFace3 face = new() - { - Vertices = new ushort[3] - }; - face.Vertices[0] = room.Data[RoomDataOffset]; - RoomDataOffset++; - face.Vertices[1] = room.Data[RoomDataOffset]; - RoomDataOffset++; - face.Vertices[2] = room.Data[RoomDataOffset]; - RoomDataOffset++; - face.Texture = room.Data[RoomDataOffset]; - RoomDataOffset++; - - RoomData.Triangles[j] = face; - } - - //Room sprites - RoomData.NumSprites = UnsafeConversions.UShortToShort(room.Data[RoomDataOffset]); - RoomData.Sprites = new TRRoomSprite[RoomData.NumSprites]; - - RoomDataOffset++; - - for (int j = 0; j < RoomData.NumSprites; j++) - { - TRRoomSprite face = new() - { - Vertex = UnsafeConversions.UShortToShort(room.Data[RoomDataOffset]) - }; - RoomDataOffset++; - face.Texture = UnsafeConversions.UShortToShort(room.Data[RoomDataOffset]); - RoomDataOffset++; - - RoomData.Sprites[j] = face; - } - - Debug.Assert(RoomDataOffset == room.NumDataWords); - - return RoomData; - } - private static TR4RoomLight ReadRoomLight(BinaryReader reader) { return new TR4RoomLight diff --git a/TRLevelControlTests/TR2/IOTests.cs b/TRLevelControlTests/TR2/IOTests.cs index 6573d189c..fa6107e13 100644 --- a/TRLevelControlTests/TR2/IOTests.cs +++ b/TRLevelControlTests/TR2/IOTests.cs @@ -170,7 +170,7 @@ public void FloorData_InsertFDTest() int room, roomSector = -1; for (room = 0; room < lvl.Rooms.Count; room++) { - roomSector = lvl.Rooms[room].SectorList.ToList().FindIndex(s => s.FDIndex == 0); + roomSector = lvl.Rooms[room].Sectors.ToList().FindIndex(s => s.FDIndex == 0); if (roomSector != -1) { break; @@ -182,7 +182,7 @@ public void FloorData_InsertFDTest() Assert.Fail("Could not locate a Room Sector that does not have floor data associated with it."); } - TRRoomSector sector = lvl.Rooms[room].SectorList[roomSector]; + TRRoomSector sector = lvl.Rooms[room].Sectors[roomSector]; // Create a slot in the FD for this sector fdataReader.CreateFloorData(sector); @@ -209,7 +209,7 @@ public void FloorData_InsertFDTest() lvl = WriteReadTempLevel(lvl); //Reassign the sector - sector = lvl.Rooms[room].SectorList[roomSector]; + sector = lvl.Rooms[room].Sectors[roomSector]; fdataReader = new FDControl(); fdataReader.ParseFromLevel(lvl); @@ -245,7 +245,7 @@ public void FloorData_RemoveFDTest() int room, roomSector = -1; for (room = 0; room < lvl.Rooms.Count; room++) { - roomSector = lvl.Rooms[room].SectorList.ToList().FindIndex(s => s.FDIndex > 0); + roomSector = lvl.Rooms[room].Sectors.ToList().FindIndex(s => s.FDIndex > 0); if (roomSector != -1) { break; @@ -257,7 +257,7 @@ public void FloorData_RemoveFDTest() Assert.Fail("Could not locate a Room Sector that has floor data associated with it."); } - TRRoomSector sector = lvl.Rooms[room].SectorList[roomSector]; + TRRoomSector sector = lvl.Rooms[room].Sectors[roomSector]; // Remove the FD for this sector fdataReader.RemoveFloorData(sector); @@ -270,7 +270,7 @@ public void FloorData_RemoveFDTest() lvl = WriteReadTempLevel(lvl); //Reassign the sector - sector = lvl.Rooms[room].SectorList[roomSector]; + sector = lvl.Rooms[room].Sectors[roomSector]; fdataReader = new FDControl(); fdataReader.ParseFromLevel(lvl); diff --git a/TRRandomizerCore/Levels/TR2CombinedLevel.cs b/TRRandomizerCore/Levels/TR2CombinedLevel.cs index 4a7d27f47..0d0c41fe2 100644 --- a/TRRandomizerCore/Levels/TR2CombinedLevel.cs +++ b/TRRandomizerCore/Levels/TR2CombinedLevel.cs @@ -1,5 +1,4 @@ -using TRRandomizerCore.Utilities; -using TRGE.Core; +using TRGE.Core; using TRLevelControl.Helpers; using TRLevelControl.Model; @@ -75,37 +74,6 @@ public class TR2CombinedLevel /// public bool IsAssault => Is(TR2LevelNames.ASSAULT); - public bool CanPerformDraining(short room) - { - foreach (List area in RoomWaterUtilities.RoomRemovalWaterMap[Name]) - { - if (area.Contains(room)) - { - return true; - } - } - - return false; - } - - public bool PerformDraining(short room) - { - foreach (List area in RoomWaterUtilities.RoomRemovalWaterMap[Name]) - { - if (area.Contains(room)) - { - foreach (int filledRoom in area) - { - Data.Rooms[filledRoom].Drain(); - } - - return true; - } - } - - return false; - } - public List GetEnemyEntities() { List allEnemies = TR2TypeUtilities.GetFullListOfEnemies(); diff --git a/TRRandomizerCore/Randomizers/Shared/AudioRandomizer.cs b/TRRandomizerCore/Randomizers/Shared/AudioRandomizer.cs index 6352f2bec..8b84fceed 100644 --- a/TRRandomizerCore/Randomizers/Shared/AudioRandomizer.cs +++ b/TRRandomizerCore/Randomizers/Shared/AudioRandomizer.cs @@ -25,9 +25,9 @@ public void ResetFloorMap() _trackMap.Clear(); } - public void RandomizeFloorTracks(TRRoomSector[] sectors, FDControl floorData, Random generator, Func positionAction) + public void RandomizeFloorTracks(List sectors, FDControl floorData, Random generator, Func positionAction) { - for (int i = 0; i < sectors.Length; i++) + for (int i = 0; i < sectors.Count; i++) { TRRoomSector sector = sectors[i]; FDActionListItem trackItem = null; diff --git a/TRRandomizerCore/Randomizers/Shared/RandoConsts.cs b/TRRandomizerCore/Randomizers/Shared/RandoConsts.cs new file mode 100644 index 000000000..83065dd51 --- /dev/null +++ b/TRRandomizerCore/Randomizers/Shared/RandoConsts.cs @@ -0,0 +1,8 @@ +namespace TRRandomizerCore.Randomizers; + +public static class RandoConsts +{ + public const uint DarknessRange = 10; // 0 = Dusk, 10 = Night + public const short DarknessIntensity1 = 8000; + public const ushort DarknessIntensity2 = 1000; +} diff --git a/TRRandomizerCore/Randomizers/TR1/TR1NightModeRandomizer.cs b/TRRandomizerCore/Randomizers/TR1/TR1NightModeRandomizer.cs index 3df199475..3e1390b55 100644 --- a/TRRandomizerCore/Randomizers/TR1/TR1NightModeRandomizer.cs +++ b/TRRandomizerCore/Randomizers/TR1/TR1NightModeRandomizer.cs @@ -9,8 +9,6 @@ namespace TRRandomizerCore.Randomizers; public class TR1NightModeRandomizer : BaseTR1Randomizer { - public const uint DarknessRange = 10; // 0 = Dusk, 10 = Night - private static readonly Dictionary> _excludedRooms = new() { [TR1LevelNames.ATLANTIS] @@ -25,7 +23,7 @@ public override void Randomize(int seed) { _generator = new Random(seed); - Settings.NightModeDarkness = Math.Min(Settings.NightModeDarkness, DarknessRange); + Settings.NightModeDarkness = Math.Min(Settings.NightModeDarkness, RandoConsts.DarknessRange); ChooseNightLevels(); @@ -74,10 +72,10 @@ private void SetNightMode(TR1CombinedLevel level) private void DarkenRooms(TR1CombinedLevel level) { - double scale = (100 - DarknessRange + Settings.NightModeDarkness) / 100d; + double scale = (100 - RandoConsts.DarknessRange + Settings.NightModeDarkness) / 100d; - short intensity1 = (short)(TR2Room.DarknessIntensity1 * scale); - ushort intensity2 = (ushort)(TR2Room.DarknessIntensity2 * (2 - scale)); + short intensity1 = (short)(RandoConsts.DarknessIntensity1 * scale); + ushort intensity2 = (ushort)(RandoConsts.DarknessIntensity2 * (2 - scale)); for (int i = 0; i < level.Data.Rooms.Count; i++) { @@ -87,10 +85,11 @@ private void DarkenRooms(TR1CombinedLevel level) } TR1Room room = level.Data.Rooms[i]; - room.SetAmbient(intensity1); - room.SetLights(intensity2); - room.SetStaticMeshLights((ushort)intensity1); - room.SetVertexLight(intensity1); + + room.AmbientIntensity = intensity1; + room.Lights.ForEach(l => l.Intensity = intensity2); + room.StaticMeshes.ForEach(s => s.Intensity = (ushort)intensity1); + room.RoomData.Vertices.ForEach(v => v.Lighting = intensity1); } } } diff --git a/TRRandomizerCore/Randomizers/TR2/TR2AudioRandomizer.cs b/TRRandomizerCore/Randomizers/TR2/TR2AudioRandomizer.cs index 58de46a35..d34c4f08f 100644 --- a/TRRandomizerCore/Randomizers/TR2/TR2AudioRandomizer.cs +++ b/TRRandomizerCore/Randomizers/TR2/TR2AudioRandomizer.cs @@ -87,7 +87,7 @@ private void RandomizeFloorTracks(TR2Level level, FDControl floorData) _audioRandomizer.ResetFloorMap(); foreach (TR2Room room in level.Rooms) { - _audioRandomizer.RandomizeFloorTracks(room.SectorList, floorData, _generator, sectorIndex => + _audioRandomizer.RandomizeFloorTracks(room.Sectors, floorData, _generator, sectorIndex => { // Get the midpoint of the tile in world coordinates return new Vector2 diff --git a/TRRandomizerCore/Randomizers/TR2/TR2EnemyRandomizer.cs b/TRRandomizerCore/Randomizers/TR2/TR2EnemyRandomizer.cs index 14354b6ce..3a4895752 100644 --- a/TRRandomizerCore/Randomizers/TR2/TR2EnemyRandomizer.cs +++ b/TRRandomizerCore/Randomizers/TR2/TR2EnemyRandomizer.cs @@ -642,7 +642,7 @@ private void RandomizeEnemies(TR2CombinedLevel level, EnemyRandomizationCollecti roomDrainIndex = room.AlternateRoom; } - if (roomDrainIndex != -1 && !level.PerformDraining(roomDrainIndex)) + if (roomDrainIndex != -1) { // Draining cannot be performed so make the entity a water creature. // The list of provided water creatures will either be those native diff --git a/TRRandomizerCore/Randomizers/TR2/TR2NightModeRandomizer.cs b/TRRandomizerCore/Randomizers/TR2/TR2NightModeRandomizer.cs index 36d3faf1e..ba58ccdaa 100644 --- a/TRRandomizerCore/Randomizers/TR2/TR2NightModeRandomizer.cs +++ b/TRRandomizerCore/Randomizers/TR2/TR2NightModeRandomizer.cs @@ -9,8 +9,6 @@ namespace TRRandomizerCore.Randomizers; public class TR2NightModeRandomizer : BaseTR2Randomizer { - public const uint DarknessRange = 10; // 0 = Dusk, 10 = Night - internal TR2TextureMonitorBroker TextureMonitor { get; set; } private List _nightLevels; @@ -19,7 +17,7 @@ public override void Randomize(int seed) { _generator = new Random(seed); - Settings.NightModeDarkness = Math.Min(Settings.NightModeDarkness, DarknessRange); + Settings.NightModeDarkness = Math.Min(Settings.NightModeDarkness, RandoConsts.DarknessRange); ChooseNightLevels(); @@ -74,17 +72,50 @@ private void SetNightMode(TR2CombinedLevel level) private void DarkenRooms(TR2Level level) { - double scale = (100 - DarknessRange + Settings.NightModeDarkness) / 100d; + double scale = (100 - RandoConsts.DarknessRange + Settings.NightModeDarkness) / 100d; - short intensity1 = (short)(TR2Room.DarknessIntensity1 * scale); - ushort intensity2 = (ushort)(TR2Room.DarknessIntensity2 * (2 - scale)); + short intensity1 = (short)(RandoConsts.DarknessIntensity1 * scale); + ushort intensity2 = (ushort)(RandoConsts.DarknessIntensity2 * (2 - scale)); foreach (TR2Room room in level.Rooms) { - room.SetAmbient(intensity1); - room.SetLights(intensity2); - room.SetStaticMeshLights((ushort)intensity1); - room.SetVertexLight(intensity1); + SetAmbient(room, intensity1); + SetLights(room, intensity2); + SetStaticMeshLights(room, (ushort)intensity1); + SetVertexLight(room, intensity1); + } + } + + private static void SetAmbient(TR2Room room, short val) + { + room.AmbientIntensity = val; + room.AmbientIntensity2 = val; + } + + private static void SetLights(TR2Room room, ushort val) + { + foreach (TR2RoomLight light in room.Lights) + { + light.Intensity1 = val; + light.Intensity2 = val; + } + } + + private static void SetStaticMeshLights(TR2Room room, ushort val) + { + foreach (TR2RoomStaticMesh mesh in room.StaticMeshes) + { + mesh.Intensity1 = val; + mesh.Intensity2 = val; + } + } + + private static void SetVertexLight(TR2Room room, short val) + { + foreach (TR2RoomVertex vert in room.RoomData.Vertices) + { + vert.Lighting = val; + vert.Lighting2 = val; } } diff --git a/TRRandomizerCore/Randomizers/TR2R/TR2RAudioRandomizer.cs b/TRRandomizerCore/Randomizers/TR2R/TR2RAudioRandomizer.cs index 64354a04d..286c1058d 100644 --- a/TRRandomizerCore/Randomizers/TR2R/TR2RAudioRandomizer.cs +++ b/TRRandomizerCore/Randomizers/TR2R/TR2RAudioRandomizer.cs @@ -84,7 +84,7 @@ private void RandomizeFloorTracks(TR2Level level, FDControl floorData) _audioRandomizer.ResetFloorMap(); foreach (TR2Room room in level.Rooms) { - _audioRandomizer.RandomizeFloorTracks(room.SectorList, floorData, _generator, sectorIndex => + _audioRandomizer.RandomizeFloorTracks(room.Sectors, floorData, _generator, sectorIndex => { return new Vector2 ( diff --git a/TRRandomizerCore/Randomizers/TR3/TR3NightModeRandomizer.cs b/TRRandomizerCore/Randomizers/TR3/TR3NightModeRandomizer.cs index d47cbb67a..348bfd6aa 100644 --- a/TRRandomizerCore/Randomizers/TR3/TR3NightModeRandomizer.cs +++ b/TRRandomizerCore/Randomizers/TR3/TR3NightModeRandomizer.cs @@ -70,7 +70,25 @@ private void DarkenRooms(TR3Level level) { foreach (TR3Room room in level.Rooms) { - room.SetVertexLight((short)(Settings.NightModeDarkness * 10)); + SetVertexLight(room, (short)(Settings.NightModeDarkness * 10)); + } + } + + private static void SetVertexLight(TR3Room room, short val) + { + foreach (TR3RoomVertex vert in room.RoomData.Vertices) + { + vert.Lighting = val; + + byte red = (byte)((vert.Colour & 0x7C00) >> 10); + byte green = (byte)((vert.Colour & 0x03E0) >> 5); + byte blue = (byte)(vert.Colour & 0x001F); + + red -= (byte)(red * val / 100); + green -= (byte)(green * val / 100); + blue -= (byte)(blue * val / 100); + + vert.Colour = (ushort)((red << 10) | (green << 5) | (blue)); } } } diff --git a/TRRandomizerCore/Randomizers/TR3/TR3VfxRandomizer.cs b/TRRandomizerCore/Randomizers/TR3/TR3VfxRandomizer.cs index 564354d4c..a386cdf0a 100644 --- a/TRRandomizerCore/Randomizers/TR3/TR3VfxRandomizer.cs +++ b/TRRandomizerCore/Randomizers/TR3/TR3VfxRandomizer.cs @@ -79,7 +79,7 @@ private void FilterVertices(TR3Level level) { foreach (TR3Room room in level.Rooms) { - room.SetColourFilter(Settings.VfxFilterColor, Settings.VfxVivid, Settings.VfxCaustics, Settings.VfxWave); + SetColourFilter(room, Settings.VfxFilterColor, Settings.VfxVivid, Settings.VfxCaustics, Settings.VfxWave); } } @@ -87,7 +87,7 @@ private void FilterVerticesRandomLevel(TR3Level level, Color col) { foreach (TR3Room room in level.Rooms) { - room.SetColourFilter(col, Settings.VfxVivid, Settings.VfxCaustics, Settings.VfxWave); + SetColourFilter(room, col, Settings.VfxVivid, Settings.VfxCaustics, Settings.VfxWave); } } @@ -97,7 +97,59 @@ private void FilterVerticesRandomRoom(TR3Level level) { Color col = _colors[_generator.Next(0, _colors.Length - 1)]; - room.SetColourFilter(col, Settings.VfxVivid, Settings.VfxCaustics, Settings.VfxWave); + SetColourFilter(room, col, Settings.VfxVivid, Settings.VfxCaustics, Settings.VfxWave); } } + + private static void SetColourFilter(TR3Room room, Color col, bool replace, bool enableCaustics, bool enableWave) + { + foreach (TR3RoomVertex vert in room.RoomData.Vertices) + { + byte curRed = (byte)((vert.Colour & 0x7C00) >> 10); + byte curGreen = (byte)((vert.Colour & 0x03E0) >> 5); + byte curBlue = (byte)(vert.Colour & 0x001F); + + byte newRed = ConvertColorChannelToRGB555(col.R); + byte newGreen = ConvertColorChannelToRGB555(col.G); + byte newBlue = ConvertColorChannelToRGB555(col.B); + + if (replace) + { + byte applyR = curRed; + byte applyG = curGreen; + byte applyB = curBlue; + + if (newRed > 0) + applyR = newRed; + + if (newGreen > 0) + applyG = newGreen; + + if (newBlue > 0) + applyB = newBlue; + + vert.Colour = (ushort)((applyR << 10) | (applyG << 5) | (applyB)); + } + else + { + vert.Colour = (ushort)((Blend(curRed, newRed) << 10) | (Blend(curGreen, newGreen) << 5) | (Blend(curBlue, newBlue))); + } + + // #296 Retain original caustics and waves for water/swamp rooms + if (!vert.UseCaustics) + vert.UseCaustics = enableCaustics; + if (!vert.UseWaveMovement) + vert.UseWaveMovement = enableWave; + } + } + + private static byte ConvertColorChannelToRGB555(byte col) + { + return (byte)(((col - byte.MinValue) * (31 - 0)) / (byte.MaxValue - byte.MinValue) + 0); + } + + private static byte Blend(byte curChannel, byte newChannel) + { + return Math.Min((byte)((newChannel * 0.1) + curChannel * (1 - 0.1)), (byte)31); + } } diff --git a/TRRandomizerCore/TRRandomizerController.cs b/TRRandomizerCore/TRRandomizerController.cs index e6bb2b567..db6a3660a 100644 --- a/TRRandomizerCore/TRRandomizerController.cs +++ b/TRRandomizerCore/TRRandomizerController.cs @@ -1428,7 +1428,7 @@ public uint NightModeDarkness set => LevelRandomizer.NightModeDarkness = value; } - public static uint NightModeDarknessRange => TR2NightModeRandomizer.DarknessRange; + public static uint NightModeDarknessRange => RandoConsts.DarknessRange; public bool NightModeAssaultCourse { diff --git a/TRRandomizerCore/Textures/Landmarks/TR2LandmarkImporter.cs b/TRRandomizerCore/Textures/Landmarks/TR2LandmarkImporter.cs index b801930ea..c28066a84 100644 --- a/TRRandomizerCore/Textures/Landmarks/TR2LandmarkImporter.cs +++ b/TRRandomizerCore/Textures/Landmarks/TR2LandmarkImporter.cs @@ -31,7 +31,7 @@ protected override void SetRoomTexture(TR2Level level, int roomIndex, int rectan TR2Room room = level.Rooms[portalSector.Room]; int x = isLevelMirrored ? (room.NumXSectors - portalSector.X - 1) : portalSector.X; - TRRoomSector sector = room.SectorList[x * room.NumZSectors + portalSector.Z]; + TRRoomSector sector = room.Sectors[x * room.NumZSectors + portalSector.Z]; return GetSectorPortalRoom(sector, floorData, portalSector.Direction); } diff --git a/TRRandomizerCore/Utilities/FaceUtilities.cs b/TRRandomizerCore/Utilities/FaceUtilities.cs index c9e828522..6844902f4 100644 --- a/TRRandomizerCore/Utilities/FaceUtilities.cs +++ b/TRRandomizerCore/Utilities/FaceUtilities.cs @@ -33,7 +33,7 @@ public static List GetTriggerFaces(TR2Level level, List tri List faces = new(); foreach (TR2Room room in level.Rooms) { - faces.AddRange(ScanTriggerFaces(floorData, triggerTypes, includeDeathTiles, room.SectorList, room.NumZSectors, room.RoomData.Rectangles, v => + faces.AddRange(ScanTriggerFaces(floorData, triggerTypes, includeDeathTiles, room.Sectors, room.NumZSectors, room.RoomData.Rectangles, v => { return room.RoomData.Vertices[v].Vertex; })); @@ -67,7 +67,7 @@ public static Dictionary> GetClimbableFaces(TR2Level lev Dictionary> faces = new(); foreach (TR2Room room in level.Rooms) { - foreach (TRRoomSector sector in room.SectorList) + foreach (TRRoomSector sector in room.Sectors) { ScanTR2SectorLadderFaces(faces, level, floorData, room, sector); } @@ -95,10 +95,10 @@ public static Dictionary> GetClimbableFaces(TR3Level lev } private static List ScanTriggerFaces - (FDControl floorData, List triggerMatches, bool includeDeathTiles, TRRoomSector[] sectors, ushort roomDepth, TRFace4[] roomFaces, Func vertexAction) + (FDControl floorData, List triggerMatches, bool includeDeathTiles, List sectors, ushort roomDepth, List roomFaces, Func vertexAction) { List faces = new(); - for (int i = 0; i < sectors.Length; i++) + for (int i = 0; i < sectors.Count; i++) { TRRoomSector sector = sectors[i]; if (sector.FDIndex == 0) @@ -146,7 +146,7 @@ private static void ScanTR2SectorLadderFaces(Dictionary> if (entry is FDClimbEntry climbEntry) { - int sectorIndex = room.SectorList.ToList().IndexOf(sector); + int sectorIndex = room.Sectors.ToList().IndexOf(sector); short x = (short)(sectorIndex / room.NumZSectors * TRConsts.Step4); short z = (short)(sectorIndex % room.NumZSectors * TRConsts.Step4); diff --git a/TRRandomizerCore/Utilities/Locations/TR2LocationGenerator.cs b/TRRandomizerCore/Utilities/Locations/TR2LocationGenerator.cs index 14371858d..fc3bc248e 100644 --- a/TRRandomizerCore/Utilities/Locations/TR2LocationGenerator.cs +++ b/TRRandomizerCore/Utilities/Locations/TR2LocationGenerator.cs @@ -23,12 +23,12 @@ protected override TRRoomSector GetSector(Location location, TR2Level level) protected override TRRoomSector GetSector(int x, int z, int roomIndex, TR2Level level) { TR2Room room = level.Rooms[roomIndex]; - return FDUtilities.GetRoomSector(x, z, room.SectorList, room.Info, room.NumZSectors); + return FDUtilities.GetRoomSector(x, z, room.Sectors, room.Info, room.NumZSectors); } protected override List GetRoomSectors(TR2Level level, int room) { - return level.Rooms[room].SectorList.ToList(); + return level.Rooms[room].Sectors.ToList(); } protected override TRDictionary GetStaticMeshes(TR2Level level) diff --git a/TRRandomizerCore/Utilities/RoomWaterUtilities.cs b/TRRandomizerCore/Utilities/RoomWaterUtilities.cs index 5e81c4f41..75e446fe7 100644 --- a/TRRandomizerCore/Utilities/RoomWaterUtilities.cs +++ b/TRRandomizerCore/Utilities/RoomWaterUtilities.cs @@ -8,100 +8,6 @@ namespace TRRandomizerCore.Utilities; public static class RoomWaterUtilities { - public static readonly Dictionary>> RoomRemovalWaterMap = new() - { - { TR2LevelNames.GW, new List> - { - //No drain areas defined for now - } - }, - { TR2LevelNames.VENICE, new List> - { - //No drain areas defined for now - } - }, - { TR2LevelNames.BARTOLI, new List> - { - //No drain areas defined for now - } - }, - { TR2LevelNames.OPERA, new List> - { - //No drain areas defined for now - } - }, - { TR2LevelNames.RIG, new List> - { - //No drain areas defined for now - } - }, - { TR2LevelNames.DA, new List> - { - //No drain areas defined for now - } - }, - { TR2LevelNames.FATHOMS, new List> - { - //No drain areas defined for now - } - }, - { TR2LevelNames.DORIA, new List> - { - //No drain areas defined for now - } - }, - { TR2LevelNames.LQ, new List> - { - //No drain areas defined for now - } - }, - { TR2LevelNames.DECK, new List> - { - //No drain areas defined for now - } - }, - { TR2LevelNames.TIBET, new List> - { - //No drain areas defined for now - } - }, - { TR2LevelNames.MONASTERY, new List> - { - //No drain areas defined for now - } - }, - { TR2LevelNames.COT, new List> - { - //No drain areas defined for now - } - }, - { TR2LevelNames.CHICKEN, new List> - { - //No drain areas defined for now - } - }, - { TR2LevelNames.XIAN, new List> - { - //No drain areas defined for now - } - }, - { TR2LevelNames.FLOATER, new List> - { - //No drain areas defined for now - } - }, - { TR2LevelNames.LAIR, new List> - { - //No drain areas defined for now - } - }, - { TR2LevelNames.HOME, new List> - { - //No drain areas defined for now - } - } - }; - public static readonly Dictionary DefaultRoomCountDictionary = new() { { TR1LevelNames.CAVES, 38 }, diff --git a/TRRandomizerCore/Utilities/TR2EnemyUtilities.cs b/TRRandomizerCore/Utilities/TR2EnemyUtilities.cs index 82cb5f79a..acf652e31 100644 --- a/TRRandomizerCore/Utilities/TR2EnemyUtilities.cs +++ b/TRRandomizerCore/Utilities/TR2EnemyUtilities.cs @@ -37,19 +37,7 @@ public static int GetTargetEnemyAdjustmentCount(string lvlName, TR2Type enemy) public static bool IsWaterEnemyRequired(TR2CombinedLevel level) { - foreach (TR2Entity entityInstance in level.Data.Entities) - { - TR2Type entity = entityInstance.TypeID; - if (TR2TypeUtilities.IsWaterCreature(entity)) - { - if (!level.CanPerformDraining(entityInstance.Room)) - { - // Draining cannot be performed so we need to ensure we get at least one water enemy - return true; - } - } - } - return false; + return level.Data.Entities.Any(e => TR2TypeUtilities.IsWaterCreature(e.TypeID)); } public static bool IsDroppableEnemyRequired(TR2CombinedLevel level) diff --git a/TextureExport/Types/FaceMapper.cs b/TextureExport/Types/FaceMapper.cs index 406b00b17..e9fcd7366 100644 --- a/TextureExport/Types/FaceMapper.cs +++ b/TextureExport/Types/FaceMapper.cs @@ -31,11 +31,11 @@ public static void DrawFaces(TR1Level level, string lvl, int[] roomNumbers) newRectFaces[roomNumber] = new Dictionary(); newTriFaces[roomNumber] = new Dictionary(); - for (int i = 0; i < level.Rooms[roomNumber].RoomData.NumRectangles; i++) + for (int i = 0; i < level.Rooms[roomNumber].RoomData.Rectangles.Count; i++) { rectFaces[roomNumber][i] = GetFaceSegment(level.Rooms[roomNumber].RoomData.Rectangles[i].Texture, packer.Tiles); } - for (int i = 0; i < level.Rooms[roomNumber].RoomData.NumTriangles; i++) + for (int i = 0; i < level.Rooms[roomNumber].RoomData.Triangles.Count; i++) { triFaces[roomNumber][i] = GetFaceSegment(level.Rooms[roomNumber].RoomData.Triangles[i].Texture, packer.Tiles); } @@ -103,11 +103,11 @@ public static void DrawFaces(TR2Level level, string lvl, int[] roomNumbers) newRectFaces[roomNumber] = new Dictionary(); newTriFaces[roomNumber] = new Dictionary(); - for (int i = 0; i < level.Rooms[roomNumber].RoomData.NumRectangles; i++) + for (int i = 0; i < level.Rooms[roomNumber].RoomData.Rectangles.Count; i++) { rectFaces[roomNumber][i] = GetFaceSegment(level.Rooms[roomNumber].RoomData.Rectangles[i].Texture, packer.Tiles); } - for (int i = 0; i < level.Rooms[roomNumber].RoomData.NumTriangles; i++) + for (int i = 0; i < level.Rooms[roomNumber].RoomData.Triangles.Count; i++) { triFaces[roomNumber][i] = GetFaceSegment(level.Rooms[roomNumber].RoomData.Triangles[i].Texture, packer.Tiles); } @@ -175,11 +175,11 @@ public static void DrawFaces(TR3Level level, string lvl, int[] roomNumbers) newRectFaces[roomNumber] = new Dictionary(); newTriFaces[roomNumber] = new Dictionary(); - for (int i = 0; i < level.Rooms[roomNumber].RoomData.NumRectangles; i++) + for (int i = 0; i < level.Rooms[roomNumber].RoomData.Rectangles.Count; i++) { rectFaces[roomNumber][i] = GetFaceSegment(level.Rooms[roomNumber].RoomData.Rectangles[i].Texture, packer.Tiles); } - for (int i = 0; i < level.Rooms[roomNumber].RoomData.NumTriangles; i++) + for (int i = 0; i < level.Rooms[roomNumber].RoomData.Triangles.Count; i++) { triFaces[roomNumber][i] = GetFaceSegment(level.Rooms[roomNumber].RoomData.Triangles[i].Texture, packer.Tiles); } @@ -245,7 +245,7 @@ public static void DrawBoxes(TR2Level level, string lvl, int[] roomNumbers) rectFaces[roomNumber] = new Dictionary(); newRectFaces[roomNumber] = new Dictionary(); - for (int i = 0; i < level.Rooms[roomNumber].RoomData.NumRectangles; i++) + for (int i = 0; i < level.Rooms[roomNumber].RoomData.Rectangles.Count; i++) { TexturedTileSegment seg = GetBoxFaceSegment(level.Rooms[roomNumber], i, packer.Tiles); if (seg != null)