Skip to content

Commit 76f8ca5

Browse files
authored
Int3 refactor (SubnauticaNitrox#1265)
* Int3 refactor & cleanup * DataExtensions cleanup * review changes
1 parent 0444495 commit 76f8ca5

26 files changed

Lines changed: 243 additions & 251 deletions

NitroxClient/GameLogic/Spawning/CellRootSpawner.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
using NitroxClient.MonoBehaviours;
2+
using NitroxModel.DataStructures;
23
using NitroxModel.DataStructures.GameLogic;
34
using NitroxModel.DataStructures.Util;
45
using UnityEngine;
5-
using NitroxInt3 = NitroxModel.DataStructures.Int3;
66

77
namespace NitroxClient.GameLogic.Spawning
88
{

NitroxClient/GameLogic/Terrain.cs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
using NitroxModel.Packets;
77
using NitroxClient.Communication.Abstract;
88
using UnityEngine;
9-
using NitroxModel_Subnautica.Helper.Int3;
9+
using NitroxModel_Subnautica.DataStructures;
1010

1111
namespace NitroxClient.GameLogic
1212
{
@@ -15,20 +15,18 @@ public class Terrain
1515
private readonly IMultiplayerSession multiplayerSession;
1616
private readonly IPacketSender packetSender;
1717
private readonly VisibleCells visibleCells;
18-
private readonly PacketReceiver packetReceiver;
1918

2019
private bool cellsPendingSync;
2120
private float timeWhenCellsBecameOutOfSync;
2221

2322
private List<AbsoluteEntityCell> added = new List<AbsoluteEntityCell>();
2423
private List<AbsoluteEntityCell> removed = new List<AbsoluteEntityCell>();
2524

26-
public Terrain(IMultiplayerSession multiplayerSession, IPacketSender packetSender, VisibleCells visibleCells, PacketReceiver packetReceiver)
25+
public Terrain(IMultiplayerSession multiplayerSession, IPacketSender packetSender, VisibleCells visibleCells)
2726
{
2827
this.multiplayerSession = multiplayerSession;
2928
this.packetSender = packetSender;
3029
this.visibleCells = visibleCells;
31-
this.packetReceiver = packetReceiver;
3230
}
3331

3432
public void CellLoaded(Int3 batchId, Int3 cellId, int level)
@@ -41,7 +39,7 @@ private IEnumerator WaitAndAddCell(Int3 batchId, Int3 cellId, int level)
4139
{
4240
yield return new WaitForSeconds(0.5f);
4341

44-
AbsoluteEntityCell cell = new AbsoluteEntityCell(batchId.Model(), cellId.Model(), level);
42+
AbsoluteEntityCell cell = new AbsoluteEntityCell(batchId.ToDto(), cellId.ToDto(), level);
4543

4644
if (!visibleCells.Contains(cell))
4745
{
@@ -52,7 +50,7 @@ private IEnumerator WaitAndAddCell(Int3 batchId, Int3 cellId, int level)
5250

5351
public void CellUnloaded(Int3 batchId, Int3 cellId, int level)
5452
{
55-
AbsoluteEntityCell cell = new AbsoluteEntityCell(batchId.Model(), cellId.Model(), level);
53+
AbsoluteEntityCell cell = new AbsoluteEntityCell(batchId.ToDto(), cellId.ToDto(), level);
5654

5755
if (visibleCells.Contains(cell))
5856
{

NitroxClient/MonoBehaviours/Overrides/MultiplayerBuilder.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
using UWE;
1010
using NitroxModel.DataStructures.GameLogic.Buildings.Rotation;
1111
using NitroxModel_Subnautica.DataStructures.GameLogic.Buildings.Rotation;
12-
using NitroxModel_Subnautica.Helper.Int3;
1312
using NitroxModel_Subnautica.DataStructures.GameLogic.Buildings.Rotation.Metadata;
13+
using NitroxModel_Subnautica.DataStructures;
1414

1515
namespace NitroxClient.MonoBehaviours.Overrides
1616
{
@@ -255,7 +255,7 @@ private static void ApplyRotationMetadata(GameObject ghostModel, RotationMetadat
255255
BaseModuleRotationMetadata baseModuleRotationMetadata = (rotationMetadata as BaseModuleRotationMetadata);
256256
BaseAddModuleGhost module = (component as BaseAddModuleGhost);
257257

258-
module.anchoredFace = new Base.Face(baseModuleRotationMetadata.Cell.Global(), (Base.Direction)baseModuleRotationMetadata.Direction);
258+
module.anchoredFace = new Base.Face(baseModuleRotationMetadata.Cell.ToUnity(), (Base.Direction)baseModuleRotationMetadata.Direction);
259259
module.ReflectionCall("RebuildGhostGeometry");
260260
}
261261
else if (component is BaseAddFaceGhost)
@@ -265,7 +265,7 @@ private static void ApplyRotationMetadata(GameObject ghostModel, RotationMetadat
265265
Log.Info("Applying BaseAddFaceGhost " + baseModuleRotationMetadata);
266266

267267

268-
Base.Face face = new Base.Face(baseModuleRotationMetadata.Cell.Global(), (Base.Direction)baseModuleRotationMetadata.Direction);
268+
Base.Face face = new Base.Face(baseModuleRotationMetadata.Cell.ToUnity(), (Base.Direction)baseModuleRotationMetadata.Direction);
269269
faceGhost.anchoredFace = face;
270270

271271
Base ghostBase = (Base)faceGhost.ReflectionGet("ghostBase");

NitroxModel-Subnautica/DataStructures/DataExtensions.cs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,20 @@
11
using System;
2+
using NitroxModel.DataStructures;
23
using NitroxModel.DataStructures.GameLogic;
34
using UnityEngine;
45

56
namespace NitroxModel_Subnautica.DataStructures
67
{
78
public static class DataExtensions
89
{
9-
public static Int3 ToUnity(this NitroxModel.DataStructures.Int3 v)
10+
public static Int3 ToUnity(this NitroxInt3 v)
1011
{
1112
return new Int3(v.X, v.Y, v.Z);
1213
}
1314

14-
public static NitroxModel.DataStructures.Int3 ToDto(this Int3 v)
15+
public static NitroxInt3 ToDto(this Int3 v)
1516
{
16-
return new NitroxModel.DataStructures.Int3(v.x, v.y, v.z);
17+
return new NitroxInt3(v.x, v.y, v.z);
1718
}
1819

1920
public static NitroxVector3 ToDto(this Vector3 v)
@@ -26,11 +27,6 @@ public static Vector3 ToUnity(this NitroxVector3 v)
2627
return new Vector3(v.X, v.Y, v.Z);
2728
}
2829

29-
public static Vector3 AsVector3(this NitroxModel.DataStructures.Int3 v)
30-
{
31-
return new Vector3(v.X, v.Y, v.Z);
32-
}
33-
3430
public static NitroxTechType ToDto(this TechType v)
3531
{
3632
return new NitroxTechType(v.ToString());

NitroxModel-Subnautica/DataStructures/GameLogic/Buildings/Rotation/Metadata/AnchoredFaceRotationMetadata.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using System;
2+
using NitroxModel.DataStructures;
23
using NitroxModel.DataStructures.GameLogic.Buildings.Rotation;
3-
using NitroxModel_Subnautica.Helper.Int3;
44
using ProtoBufNet;
55

66
namespace NitroxModel_Subnautica.DataStructures.GameLogic.Buildings.Rotation.Metadata
@@ -10,7 +10,7 @@ namespace NitroxModel_Subnautica.DataStructures.GameLogic.Buildings.Rotation.Met
1010
public class AnchoredFaceRotationMetadata : RotationMetadata
1111
{
1212
[ProtoMember(1)]
13-
public NitroxModel.DataStructures.Int3 Cell { get; set; }
13+
public NitroxInt3 Cell { get; set; }
1414

1515
[ProtoMember(2)]
1616
public int Direction { get; set; }
@@ -25,14 +25,14 @@ protected AnchoredFaceRotationMetadata() : base(typeof(BaseAddFaceGhost))
2525

2626
public AnchoredFaceRotationMetadata(Int3 cell, int facedirection, int facetype) : base(typeof(BaseAddFaceGhost))
2727
{
28-
Cell = cell.Model();
28+
Cell = cell.ToDto();
2929
Direction = facedirection;
3030
FaceType = facetype;
3131
}
3232

3333
public override string ToString()
3434
{
35-
return "[AnchoredFaceRotationMetadata Cell: " + Cell + " Direction: " + Direction + " FaceType: " + FaceType + "]";
35+
return $"[AnchoredFaceRotationMetadata - Cell: {Cell}, Direction: {Direction}, FaceType: {FaceType}]";
3636
}
3737
}
3838
}

NitroxModel-Subnautica/DataStructures/GameLogic/Buildings/Rotation/Metadata/BaseModuleRotationMetadata.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
using ProtoBufNet;
22
using System;
33
using NitroxModel.DataStructures.GameLogic.Buildings.Rotation;
4-
using NitroxModel_Subnautica.Helper.Int3;
4+
using NitroxModel.DataStructures;
55

66
namespace NitroxModel_Subnautica.DataStructures.GameLogic.Buildings.Rotation
77
{
@@ -11,7 +11,7 @@ public class BaseModuleRotationMetadata : RotationMetadata
1111
{
1212
// Base modules anchor based on a face. This can be constructed via these two attributes.
1313
[ProtoMember(1)]
14-
public NitroxModel.DataStructures.Int3 Cell { get; set; }
14+
public NitroxInt3 Cell { get; set; }
1515

1616
[ProtoMember(2)]
1717
public int Direction { get; set; }
@@ -23,13 +23,13 @@ protected BaseModuleRotationMetadata() : base(typeof(BaseAddModuleGhost))
2323

2424
public BaseModuleRotationMetadata(Int3 cell, int direction) : base(typeof(BaseAddModuleGhost))
2525
{
26-
Cell = cell.Model();
26+
Cell = cell.ToDto();
2727
Direction = direction;
2828
}
2929

3030
public override string ToString()
3131
{
32-
return "[BaseModuleRotationMetadata cell: " + Cell + " direction: " + Direction + " ]";
32+
return $"[BaseModuleRotationMetadata - Cell: {Cell}, Direction: {Direction}]";
3333
}
3434
}
3535
}

NitroxModel-Subnautica/DataStructures/GameLogic/Buildings/Rotation/Metadata/CorridorRotationMetadata.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public CorridorRotationMetadata(int rotation) : base(typeof(BaseAddCorridorGhost
2525

2626
public override string ToString()
2727
{
28-
return "[CorridorRotationMetadata Rotation: " + Rotation + " ]";
28+
return $"[CorridorRotationMetadata - Rotation: {Rotation} ]";
2929
}
3030
}
3131
}

NitroxModel-Subnautica/DataStructures/GameLogic/Buildings/Rotation/Metadata/MapRoomRotationMetadata.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public MapRoomRotationMetadata(byte cellType, int connectionMask) : base(typeof(
2929

3030
public override string ToString()
3131
{
32-
return "[MapRoomRotationMetadata CellType: " + CellType + " ConnectionMask: " + ConnectionMask + " ]";
32+
return $"[MapRoomRotationMetadata - CellType: {CellType}, ConnectionMask: {ConnectionMask}]";
3333
}
3434
}
3535
}

NitroxModel-Subnautica/DataStructures/GameLogic/Entities/SubnauticaUweWorldEntityFactory.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System.Collections.Generic;
22
using NitroxModel.DataStructures.GameLogic.Entities;
33
using NitroxModel.DataStructures.Util;
4-
using NitroxModel_Subnautica.Helper;
54
using UWE;
65

76
namespace NitroxModel_Subnautica.DataStructures.GameLogic.Entities
@@ -17,9 +16,8 @@ public SubnauticaUweWorldEntityFactory(Dictionary<string, WorldEntityInfo> world
1716

1817
public override Optional<UweWorldEntity> From(string classId)
1918
{
20-
WorldEntityInfo worldEntityInfo;
2119

22-
if (worldEntitiesByClassId.TryGetValue(classId, out worldEntityInfo))
20+
if (worldEntitiesByClassId.TryGetValue(classId, out WorldEntityInfo worldEntityInfo))
2321
{
2422
UweWorldEntity uweWorldEntity = new UweWorldEntity(worldEntityInfo.techType.ToDto(),
2523
worldEntityInfo.localScale.ToDto(),

NitroxModel-Subnautica/Helper/Int3Converter.cs

Lines changed: 0 additions & 15 deletions
This file was deleted.

0 commit comments

Comments
 (0)