Skip to content

Commit

Permalink
Implement model hierarchy (LostArtefacts#628)
Browse files Browse the repository at this point in the history
  • Loading branch information
lahm86 authored Apr 27, 2024
1 parent 7ea3396 commit 6081cca
Show file tree
Hide file tree
Showing 44 changed files with 795 additions and 292 deletions.
389 changes: 349 additions & 40 deletions TRLevelControl/Build/TRModelBuilder.cs

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions TRLevelControl/ITRLevelObserver.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ public interface ITRLevelObserver
short? GetAnimCommandPadding();
void OnUnusedStateChangeRead(Tuple<ushort, ushort> padding);
Tuple<ushort, ushort> GetUnusedStateChange();
void OnEmptyAnimFramesRead(int animIndex, byte frameSize);
byte? GetEmptyAnimFrameSize(int animIndex);
void OnFramePaddingRead(int animIndex, int frameIndex, List<short> values);
List<short> GetFramePadding(int animIndex, int frameIndex);
void OnSampleIndicesRead(uint[] sampleIndices);
IEnumerable<uint> GetSampleIndices();
}
22 changes: 22 additions & 0 deletions TRLevelControl/Model/Base/Enums/TR1FX.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
namespace TRLevelControl.Model;

public enum TR1FX : short
{
Turn180 = 0,
FloorShake = 1,
LaraNormal = 2,
LaraBubbles = 3,
EndLevel = 4,
Earthquake = 5,
Flood = 6,
RaisingBlock = 7,
StairsToSlope = 8,
Sand = 9,
PowerUp = 10,
Explosion = 11,
LaraHandsFree = 12,
FlipMap = 13,
DrawRightGun = 14,
Chainblock = 15,
Flicker = 16,
}
14 changes: 3 additions & 11 deletions TRLevelControl/Model/Base/TRAnimCommand.cs
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
namespace TRLevelControl.Model;

public class TRAnimCommand : ICloneable
public abstract class TRAnimCommand : ICloneable
{
public TRAnimCommandType Type { get; set; }
public List<short> Params { get; set; } = new();
public abstract TRAnimCommandType Type { get; }

public TRAnimCommand Clone()
{
return new()
{
Type = Type,
Params = new(Params),
};
}
public abstract TRAnimCommand Clone();

object ICloneable.Clone()
=> Clone();
Expand Down
43 changes: 15 additions & 28 deletions TRLevelControl/Model/Base/TRAnimFrame.cs
Original file line number Diff line number Diff line change
@@ -1,38 +1,25 @@
using TRLevelControl.Serialization;
namespace TRLevelControl.Model;

namespace TRLevelControl.Model;

public class TRAnimFrame : ISerializableCompact
public class TRAnimFrame : ICloneable
{
public TRBoundingBox Box { get; set; }

public TRBoundingBox Bounds { get; set; }
public short OffsetX { get; set; }

public short OffsetY { get; set; }

public short OffsetZ { get; set; }
public List<TRAnimFrameRotation> Rotations { get; set; }

public short NumValues { get; set; }

public ushort[] AngleSets { get; set; }

public byte[] Serialize()
public TRAnimFrame Clone()
{
using MemoryStream stream = new();
using (BinaryWriter writer = new(stream))
return new()
{
writer.Write(Box.Serialize());
writer.Write(OffsetX);
writer.Write(OffsetY);
writer.Write(OffsetZ);
writer.Write(NumValues);

foreach (ushort val in AngleSets)
{
writer.Write(val);
}
}

return stream.ToArray();
Bounds = Bounds.Clone(),
OffsetX = OffsetX,
OffsetY = OffsetY,
OffsetZ = OffsetZ,
Rotations = new(Rotations.Select(r => r.Clone()))
};
}

object ICloneable.Clone()
=> Clone();
}
6 changes: 2 additions & 4 deletions TRLevelControl/Model/Base/TRAnimation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
public class TRAnimation : ICloneable
{
public byte FrameRate { get; set; }
public byte FrameSize { get; set; }
public ushort StateID { get; set; }
public FixedFloat32 Speed { get; set; }
public FixedFloat32 Accel { get; set; }
Expand All @@ -15,7 +14,7 @@ public class TRAnimation : ICloneable
public ushort NextFrame { get; set; }
public List<TRStateChange> Changes { get; set; } = new();
public List<TRAnimCommand> Commands { get; set; } = new();
public List<short> Frames { get; set; } = new();
public List<TRAnimFrame> Frames { get; set; } = new();

public TRAnimation Clone()
{
Expand All @@ -25,14 +24,13 @@ public TRAnimation Clone()
FrameRate = FrameRate,
FrameStart = FrameStart,
FrameEnd = FrameEnd,
FrameSize = FrameSize,
Speed = Speed,
Accel = Accel,
SpeedLateral = SpeedLateral,
AccelLateral = AccelLateral,
NextAnimation = NextAnimation,
NextFrame = NextFrame,
Frames = new(Frames),
Frames = new(Frames.Select(f => f.Clone())),
Changes = new(Changes.Select(c => c.Clone())),
Commands = new(Commands.Select(c => c.Clone()))
};
Expand Down
35 changes: 14 additions & 21 deletions TRLevelControl/Model/Base/TRModel.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
using System.Text;
namespace TRLevelControl.Model;

namespace TRLevelControl.Model;

public class TRModel
public class TRModel : ICloneable
{
public List<TRAnimation> Animations { get; set; } = new();
public List<TRMeshTreeNode> MeshTrees { get; set; } = new();
Expand All @@ -12,23 +10,18 @@ public class TRModel

public ushort StartingMesh { get; set; }

public uint MeshTree { get; set; }

public uint FrameOffset { get; set; }

public ushort Animation { get; set; }

public override string ToString()
public TRModel Clone()
{
StringBuilder sb = new(base.ToString());

sb.Append(" ID: " + ID);
sb.Append(" NumMeshes: " + NumMeshes);
sb.Append(" StartingMesh: " + StartingMesh);
sb.Append(" MeshTree: " + MeshTree);
sb.Append(" FrameOffset: " + FrameOffset);
sb.Append(" Animation: " + Animation);

return sb.ToString();
return new()
{
Animations = new(Animations.Select(a => a.Clone())),
MeshTrees = new(MeshTrees.Select(m => m.Clone())),
ID = ID,
NumMeshes = NumMeshes,
StartingMesh = StartingMesh,
};
}

object ICloneable.Clone()
=> Clone();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace TRLevelControl.Model;

public class TREmptyHandsCommand : TRAnimCommand
{
public override TRAnimCommandType Type => TRAnimCommandType.EmptyHands;

public override TRAnimCommand Clone()
=> (TREmptyHandsCommand)MemberwiseClone();
}
11 changes: 11 additions & 0 deletions TRLevelControl/Model/Common/AnimCommands/TRFXCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace TRLevelControl.Model;

public class TRFXCommand : TRAnimCommand
{
public override TRAnimCommandType Type => TRAnimCommandType.FlipEffect;
public short FrameNumber { get; set; }
public short EffectID { get; set; }

public override TRAnimCommand Clone()
=> (TRFXCommand)MemberwiseClone();
}
11 changes: 11 additions & 0 deletions TRLevelControl/Model/Common/AnimCommands/TRFootprintCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace TRLevelControl.Model;

public class TRFootprintCommand : TRAnimCommand
{
public override TRAnimCommandType Type => TRAnimCommandType.FlipEffect;
public short FrameNumber { get; set; }
public TRFootprint Foot { get; set; }

public override TRAnimCommand Clone()
=> (TRFootprintCommand)MemberwiseClone();
}
11 changes: 11 additions & 0 deletions TRLevelControl/Model/Common/AnimCommands/TRJumpDistanceCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
namespace TRLevelControl.Model;

public class TRJumpDistanceCommand : TRAnimCommand
{
public override TRAnimCommandType Type => TRAnimCommandType.JumpDistance;
public short VerticalSpeed { get; set; }
public short HorizontalSpeed { get; set; }

public override TRAnimCommand Clone()
=> (TRJumpDistanceCommand)MemberwiseClone();
}
9 changes: 9 additions & 0 deletions TRLevelControl/Model/Common/AnimCommands/TRKillCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace TRLevelControl.Model;

public class TRKillCommand : TRAnimCommand
{
public override TRAnimCommandType Type => TRAnimCommandType.Kill;

public override TRAnimCommand Clone()
=> (TRKillCommand)MemberwiseClone();
}
10 changes: 10 additions & 0 deletions TRLevelControl/Model/Common/AnimCommands/TRNullCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
namespace TRLevelControl.Model;

public class TRNullCommand : TRAnimCommand
{
public override TRAnimCommandType Type => TRAnimCommandType.Null;
public short Value { get; set; }

public override TRAnimCommand Clone()
=> (TRNullCommand)MemberwiseClone();
}
12 changes: 12 additions & 0 deletions TRLevelControl/Model/Common/AnimCommands/TRSFXCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace TRLevelControl.Model;

public class TRSFXCommand : TRAnimCommand
{
public override TRAnimCommandType Type => TRAnimCommandType.PlaySound;
public TRSFXEnvironment Environment { get; set; }
public short FrameNumber { get; set; }
public short SoundID { get; set; }

public override TRAnimCommand Clone()
=> (TRSFXCommand)MemberwiseClone();
}
12 changes: 12 additions & 0 deletions TRLevelControl/Model/Common/AnimCommands/TRSetPositionCommand.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
namespace TRLevelControl.Model;

public class TRSetPositionCommand : TRAnimCommand
{
public override TRAnimCommandType Type => TRAnimCommandType.SetPosition;
public short X { get; set; }
public short Y { get; set; }
public short Z { get; set; }

public override TRAnimCommand Clone()
=> (TRSetPositionCommand)MemberwiseClone();
}
9 changes: 9 additions & 0 deletions TRLevelControl/Model/Common/Enums/TRAngleMode.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace TRLevelControl.Model;

public enum TRAngleMode
{
All = 0,
X = 0x4000,
Y = 0x8000,
Z = 0xC000,
}
7 changes: 7 additions & 0 deletions TRLevelControl/Model/Common/Enums/TRFootprint.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace TRLevelControl.Model;

public enum TRFootprint
{
Left = 0x4000,
Right = 0x8000,
}
8 changes: 8 additions & 0 deletions TRLevelControl/Model/Common/Enums/TRSFXEnvironment.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace TRLevelControl.Model;

public enum TRSFXEnvironment
{
Any = 0,
Land = 0x4000,
Water = 0x8000,
}
14 changes: 14 additions & 0 deletions TRLevelControl/Model/Common/TRAnimFrameRotation.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
namespace TRLevelControl.Model;

public class TRAnimFrameRotation : ICloneable
{
public short X { get; set; }
public short Y { get; set; }
public short Z { get; set; }

public TRAnimFrameRotation Clone()
=> (TRAnimFrameRotation)MemberwiseClone();

object ICloneable.Clone()
=> Clone();
}
35 changes: 35 additions & 0 deletions TRLevelControl/Model/TR2/Enums/TR2FX.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
namespace TRLevelControl.Model;

public enum TR2FX : short
{
Turn180 = 0,
FloorShake = 1,
LaraNormal = 2,
LaraBubbles = 3,
EndLevel = 4,
Flood = 5,
Chandelier = 6,
Rumble = 7,
Pistons = 8,
Curtains = 9,
SetChange = 10,
Explosion = 11,
LaraHandsFree = 12,
FlipMap = 13,
DrawRightGun = 14,
DrawLeftGun = 15,
MeshSwap1 = 18,
MeshSwap2 = 19,
MeshSwap3 = 20,
HideItem = 21,
ShowItem = 22,
DynamicLightsOn = 23,
DynamicLightsOff = 24,
Statue = 25,
ResetHair = 26,
Boiler = 27,
AssaultReset = 28,
AssaultStop = 29,
AssaultStart = 30,
AssaultEnd = 31,
}
Loading

0 comments on commit 6081cca

Please sign in to comment.