-
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #63 from BigBang1112/dev
GBX.NET 1.1.1
- Loading branch information
Showing
37 changed files
with
870 additions
and
399 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
namespace GBX.NET; | ||
|
||
public class BitReader | ||
{ | ||
private readonly byte[] data; | ||
|
||
public int Position { get; private set; } | ||
public int Length { get; } | ||
|
||
public BitReader(byte[] data) | ||
{ | ||
this.data = data; | ||
|
||
Length = data.Length * 8; | ||
} | ||
|
||
private bool ReadBit(ReadOnlySpan<byte> data) | ||
{ | ||
var result = (data[Position / 8] & (1 << (Position % 8))) != 0; | ||
Position++; | ||
return result; | ||
} | ||
|
||
public bool ReadBit() | ||
{ | ||
return ReadBit(data); | ||
} | ||
|
||
public ulong ReadNumber(int bits) | ||
{ | ||
ulong result = 0; | ||
|
||
ReadOnlySpan<byte> dataSpan = data; | ||
|
||
for (var i = 0; i < bits; i++) | ||
{ | ||
result |= (ulong)(ReadBit(dataSpan) ? 1 : 0) << i; | ||
} | ||
|
||
return result; | ||
} | ||
|
||
public byte Read2Bit() | ||
{ | ||
return (byte)ReadNumber(bits: 2); | ||
} | ||
|
||
public byte ReadByte() | ||
{ | ||
return (byte)ReadNumber(bits: 8); | ||
} | ||
|
||
public sbyte ReadSByte() | ||
{ | ||
return (sbyte)ReadNumber(bits: 8); | ||
} | ||
|
||
public short ReadInt16() | ||
{ | ||
return (short)ReadNumber(bits: 16); | ||
} | ||
|
||
public ushort ReadUInt16() | ||
{ | ||
return (ushort)ReadNumber(bits: 16); | ||
} | ||
|
||
public int ReadInt32() | ||
{ | ||
return (int)ReadNumber(bits: 32); | ||
} | ||
|
||
// ReadToEnd through bits | ||
|
||
public byte[] ReadToEnd() | ||
{ | ||
var remaining = Length - Position; | ||
var result = new byte[(remaining + 7) / 8]; | ||
for (var i = 0; i < remaining; i++) | ||
result[i / 8] |= (byte)((ReadBit() ? 1 : 0) << (i % 8)); | ||
return result; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
Src/GBX.NET/Builders/Engines/Game/CGameCtnMediaBlockTriangles3DBuilder.TMUF.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
namespace GBX.NET.Builders.Engines.Game; | ||
|
||
public partial class CGameCtnMediaBlockTriangles3DBuilder | ||
{ | ||
public class TMUF : GameBuilder<CGameCtnMediaBlockTriangles3DBuilder, CGameCtnMediaBlockTriangles3D> | ||
{ | ||
public IList<CGameCtnMediaBlockTriangles.Key>? Keys { get; set; } | ||
|
||
public TMUF(CGameCtnMediaBlockTriangles3DBuilder baseBuilder, CGameCtnMediaBlockTriangles3D node) : base(baseBuilder, node) { } | ||
|
||
public TMUF WithKeys(Func<CGameCtnMediaBlockTriangles3D, IList<CGameCtnMediaBlockTriangles.Key>> keys) | ||
{ | ||
Keys = keys(Node); | ||
return this; | ||
} | ||
|
||
public override CGameCtnMediaBlockTriangles3D Build() | ||
{ | ||
Node.Keys = Keys ?? new List<CGameCtnMediaBlockTriangles.Key>(); | ||
return Node; | ||
} | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
Src/GBX.NET/Builders/Engines/Game/CGameCtnMediaBlockTriangles3DBuilder.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
namespace GBX.NET.Builders.Engines.Game; | ||
|
||
public partial class CGameCtnMediaBlockTriangles3DBuilder : Builder | ||
{ | ||
public Vec4[] Vertices { get; } | ||
public Int3[]? Triangles { get; set; } | ||
|
||
/// <param name="vertices">Array of vertex colors.</param> | ||
public CGameCtnMediaBlockTriangles3DBuilder(Vec4[] vertices) | ||
{ | ||
Vertices = vertices; | ||
} | ||
|
||
public CGameCtnMediaBlockTriangles3DBuilder WithTriangles(Int3[] triangles) | ||
{ | ||
Triangles = triangles; | ||
return this; | ||
} | ||
|
||
public TMUF ForTMUF() => new(this, NewNode()); | ||
|
||
internal CGameCtnMediaBlockTriangles3D NewNode() | ||
{ | ||
var node = new CGameCtnMediaBlockTriangles3D | ||
{ | ||
Vertices = Vertices, | ||
Triangles = Triangles ?? Array.Empty<Int3>() | ||
}; | ||
|
||
node.CreateChunk<CGameCtnMediaBlockTriangles.Chunk03029001>(); | ||
|
||
return node; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.