Skip to content
This repository has been archived by the owner on Jun 7, 2021. It is now read-only.

Commit

Permalink
Known flags values implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
HanabishiRecca committed Jan 22, 2020
1 parent 403f521 commit 4477df2
Show file tree
Hide file tree
Showing 11 changed files with 170 additions and 31 deletions.
22 changes: 13 additions & 9 deletions FastMDX/src/Objects/CollisionShape.cs
Original file line number Diff line number Diff line change
@@ -1,39 +1,43 @@
namespace FastMDX {
public struct CollisionShape : IDataRW {
public Node Node;
public uint Type;
public ShapeType Type;
public Vec3 Vertices1, Vertices2;
public float Radius;

void IDataRW.ReadFrom(DataStream ds) {
ds.ReadData(ref Node);
ds.ReadStruct(ref Type);

if(Type > 3)
if((uint)Type > 3)
throw new ParsingException();

ds.ReadStruct(ref Vertices1);

if(Type != 2)
if(Type != ShapeType.Sphere)
ds.ReadStruct(ref Vertices2);

if(Type > 1)
if((Type == ShapeType.Sphere) || (Type == ShapeType.Cylinder))
ds.ReadStruct(ref Radius);
}

void IDataRW.WriteTo(DataStream ds) {
if(Type > 3)
throw new ParsingException();

ds.WriteData(ref Node);
ds.WriteStruct(Type);
ds.WriteStruct(ref Vertices1);

if(Type != 2)
if(Type != ShapeType.Sphere)
ds.WriteStruct(ref Vertices2);

if(Type > 1)
if((Type == ShapeType.Sphere) || (Type == ShapeType.Cylinder))
ds.WriteStruct(Radius);
}

public enum ShapeType : uint {
Box,
Plane,
Sphere,
Cylinder,
}
}
}
26 changes: 23 additions & 3 deletions FastMDX/src/Objects/Geoset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ namespace FastMDX {

public struct Geoset : IDataRW {
public Vec3[] VertexPositions, VertexNormals;
public uint[] FaceTypeGroups, FaceGroups, MatrixGroups, MatrixIndices;
public FaceTypeGroup[] FaceTypeGroups;
public uint[] FaceGroups, MatrixGroups, MatrixIndices;
public ushort[] Faces;
public byte[] VertexGroups;
public LocalProperties Properties;
Expand All @@ -22,7 +23,7 @@ void IDataRW.ReadFrom(DataStream ds) {
VertexNormals = ds.ReadStructArray<Vec3>();

ds.CheckTag(PTYP);
FaceTypeGroups = ds.ReadStructArray<uint>();
FaceTypeGroups = ds.ReadStructArray<FaceTypeGroup>();

ds.CheckTag(PCNT);
FaceGroups = ds.ReadStructArray<uint>();
Expand Down Expand Up @@ -88,8 +89,27 @@ void IDataRW.WriteTo(DataStream ds) {
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct LocalProperties {
public int MaterialId;
public uint SelectionGroup, SelectionFlags;
public uint SelectionGroup;
public SelectionType SelectionType;
public Extent Extent;
}

public enum FaceTypeGroup : uint {
Points,
Lines,
LineLoop,
LineStrip,
Triangles,
TriangleStrip,
TriangleFan,
Quads,
QuadStrip,
Polygons,
}

public enum SelectionType : uint {
None,
Unselectable = 4,
}
}
}
12 changes: 10 additions & 2 deletions FastMDX/src/Objects/GeosetAnimation.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Runtime.InteropServices;
using System;
using System.Runtime.InteropServices;

namespace FastMDX {
using static OptionalBlocks;
Expand Down Expand Up @@ -31,9 +32,16 @@ void IDataRW.WriteTo(DataStream ds) {
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct LocalProperties {
public float Alpha;
public uint Flags;
public Flags Flags;
public Color Color;
public int GeosetId;
}

[Flags]
public enum Flags : uint {
None = 0x0,
DropShadow = 0x1,
Color = 0x2,
}
}
}
26 changes: 24 additions & 2 deletions FastMDX/src/Objects/Layer.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Runtime.InteropServices;
using System;
using System.Runtime.InteropServices;

namespace FastMDX {
using static OptionalBlocks;
Expand Down Expand Up @@ -30,9 +31,30 @@ void IDataRW.WriteTo(DataStream ds) {

[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct LocalProperties {
public uint FilterMode, ShadingFlags;
public FilterMode FilterMode;
public ShadingFlags ShadingFlags;
public int TextureId, TextureAnimationId, CoordId;
public float Alpha;
}

public enum FilterMode : uint {
None,
Transparent,
Blend,
Additive,
AddAlpha,
Modulate,
Modulate2x,
}

[Flags]
public enum ShadingFlags : uint {
Unshaded = 0x1,
SphereEnvironmentMap = 0x2,
TwoSided = 0x10,
Unfogged = 0x20,
NoDepthTest = 0x40,
NoDepthSet = 0x80,
}
}
}
8 changes: 7 additions & 1 deletion FastMDX/src/Objects/Light.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,18 @@ void IDataRW.WriteTo(DataStream ds) {

[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct LocalProperties {
public uint Type;
public Type Type;
public float AttenuationStart, AttenuationEnd;
public Color Color;
public float Intensity;
public Color AmbientColor;
public float AmbientIntensity;
}

public enum Type : uint {
Omni,
Directional,
Ambient,
}
}
}
14 changes: 12 additions & 2 deletions FastMDX/src/Objects/Material.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Runtime.InteropServices;
using System;
using System.Runtime.InteropServices;

namespace FastMDX {
using static InnerBlocks;
Expand Down Expand Up @@ -26,7 +27,16 @@ void IDataRW.WriteTo(DataStream ds) {

[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct LocalProperties {
public uint PriorityPlane, Flags;
public uint PriorityPlane;
public Flags Flags;
}

[Flags]
public enum Flags : uint {
None = 0x0,
ConstantColor = 0x1,
SortPrimitivesFarZ = 0x10,
FullResolution = 0x20,
}
}
}
31 changes: 29 additions & 2 deletions FastMDX/src/Objects/Node.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Runtime.InteropServices;
using System;
using System.Runtime.InteropServices;

namespace FastMDX {
using static OptionalBlocks;
Expand Down Expand Up @@ -35,7 +36,7 @@ public struct LocalProperties {

fixed byte name[(int)NAME_LEN];
public int ObjectId, ParentId;
public uint Flags;
public Flags Flags;

public string Name {
get {
Expand All @@ -48,5 +49,31 @@ public string Name {
}
}
}

[Flags]
public enum Flags : uint {
Helper = 0x0,
DontInheritTranslation = 0x1,
DontInheritRotation = 0x2,
DontInheritScaling = 0x4,
Billboarded = 0x8,
BillboardedLockX = 0x10,
BillboardedLockY = 0x20,
BillboardedLockZ = 0x40,
CameraAnchored = 0x80,
Bone = 0x100,
Light = 0x200,
EventObject = 0x400,
Attachment = 0x800,
ParticleEmitter = 0x1000,
CollisionShape = 0x2000,
RibbonEmitter = 0x4000,
PEUsesMdlPE2Unshaded = 0x8000,
PEUsesTgaPE2SortPrimitivesFarZ = 0x10000,
LineEmitter = 0x20000,
Unfogged = 0x40000,
ModelSpace = 0x80000,
XYQuad = 0x100000,
}
}
}
26 changes: 24 additions & 2 deletions FastMDX/src/Objects/ParticleEmitter2.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,17 @@ void IDataRW.WriteTo(DataStream ds) {
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct LocalProperties {
public float Speed, Variation, Latitude, Gravity, Lifespan, EmissionRate, Length, Width;
public uint FilterMode, Rows, Columns, Flag;
public FilterMode FilterMode;
public uint Rows, Columns;
public HeadTailType HeadTailType;
public float TailLength, Time;
public SegmentColor SegmentColor;
public SegmentAlpha SegmentAlpha;
public Vec3 SegmentScaling;
public Interval HeadInterval, HeadDecayInterval, TailInterval, TailDecayInterval;
public int TextureId;
public uint Squirt, PriorityPlane;
public Squirt Squirt;
public uint PriorityPlane;
public int ReplaceableId;
}

Expand All @@ -64,5 +67,24 @@ public struct SegmentAlpha {
public struct Interval {
public uint Start, End, Repeat;
}

public enum FilterMode : uint {
Blend,
Additive,
Modulate,
Modulate2x,
AddAlpha,
}

public enum HeadTailType : uint {
Head,
Tail,
Both,
}

public enum Squirt : uint {
NoSquirt,
Squirt,
}
}
}
7 changes: 6 additions & 1 deletion FastMDX/src/Objects/Sequence.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public unsafe struct Sequence {
fixed byte name[(int)NAME_LEN];
public uint IntervalStart, IntervalEnd;
public float MoveSpeed;
public uint Flags;
public LoopType Type;
public float Rarity;
public uint SyncPoint;
public Extent Extent;
Expand All @@ -23,5 +23,10 @@ public string Name {
BinaryString.Encode(value, n, NAME_LEN);
}
}

public enum LoopType : uint {
Looping,
NonLooping,
}
}
}
12 changes: 10 additions & 2 deletions FastMDX/src/Objects/Texture.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Runtime.InteropServices;
using System;
using System.Runtime.InteropServices;

namespace FastMDX {
[StructLayout(LayoutKind.Sequential, Pack = 1)]
Expand All @@ -7,7 +8,7 @@ public unsafe struct Texture {

public int ReplaceableId;
fixed byte name[(int)NAME_LEN];
public uint Flags;
public WrapFlags Flags;

public string Name {
get {
Expand All @@ -19,5 +20,12 @@ public string Name {
BinaryString.Encode(value, n, NAME_LEN);
}
}

[Flags]
public enum WrapFlags : uint {
None = 0x0,
WrapWidth = 0x1,
WrapHeight = 0x2,
}
}
}
17 changes: 12 additions & 5 deletions FastMDX/src/Objects/Transform.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,39 @@ void IDataRW.ReadFrom(DataStream ds) {
var tracksCount = ds.ReadStruct<uint>();
ds.ReadStruct(ref Properties);

if(Properties.InterpolationType > 1)
if((uint)Properties.InterpolationType > 1)
TracksInter = ds.ReadStructArray<TrackInter<T>>(tracksCount);
else
Tracks = ds.ReadStructArray<Track<T>>(tracksCount);
}

void IDataRW.WriteTo(DataStream ds) {
if(Properties.InterpolationType > 1)
if((uint)Properties.InterpolationType > 1)
ds.WriteStruct((uint)TracksInter.Length);
else
ds.WriteStruct((uint)Tracks.Length);

ds.WriteStruct(ref Properties);

if(Properties.InterpolationType > 1)
if((uint)Properties.InterpolationType > 1)
ds.WriteStructArray(TracksInter, false);
else
ds.WriteStructArray(Tracks, false);
}

bool IOptionalBlock.HasData => (Properties.InterpolationType > 1) ? (TracksInter?.Length > 0) : (Tracks?.Length > 0);
bool IOptionalBlock.HasData => ((uint)Properties.InterpolationType > 1) ? (TracksInter?.Length > 0) : (Tracks?.Length > 0);

[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct LocalProperties {
public uint InterpolationType;
public InterpolationType InterpolationType;
public int GlobalSequenceId;
}

public enum InterpolationType : uint {
None,
Linear,
Hermite,
Bezier,
}
}
}

0 comments on commit 4477df2

Please sign in to comment.