Skip to content

Commit

Permalink
Replace float arrays with Vector3D record struct
Browse files Browse the repository at this point in the history
  • Loading branch information
sliekens committed Sep 16, 2023
1 parent 264f989 commit 831f327
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 19 deletions.
24 changes: 9 additions & 15 deletions GW2SDK/Features/Mumble/GameTick.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,34 +8,28 @@ namespace GuildWars2.Mumble;
[PublicAPI]
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct GameTick

{
public readonly uint UiVersion;

public readonly uint UiTick;

/// <summary>Avatar position is the position of the player in the coordinate system of the map. While the game uses inches
/// as unit, mumble uses meters.</summary>
[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
public readonly float[] AvatarPosition;
/// <summary>Avatar position is the position of the player in the coordinate system of the map. X is measured along the
/// east-west axis, Y measures elevation, Z is measured along the north-south axis.</summary>
/// <remarks>While the game uses inches as unit, mumble uses meters.</remarks>
public readonly Vector3D AvatarPosition;

[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
public readonly float[] AvatarFront;
public readonly Vector3D AvatarFront;

[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
public readonly float[] AvatarTop;
public readonly Vector3D AvatarTop;

[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public readonly string Name;

[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
public readonly float[] CameraPosition;
public readonly Vector3D CameraPosition;

[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
public readonly float[] CameraFront;
public readonly Vector3D CameraFront;

[MarshalAs(UnmanagedType.ByValArray, SizeConst = 3)]
public readonly float[] CameraTop;
public readonly Vector3D CameraTop;

[MarshalAs(UnmanagedType.ByValTStr, SizeConst = 256)]
public readonly string Identity;
Expand Down
13 changes: 13 additions & 0 deletions GW2SDK/Features/Mumble/Vector3D.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
using System.Runtime.InteropServices;

namespace GuildWars2.Mumble;

[StructLayout(LayoutKind.Sequential)]
public record struct Vector3D
{
public readonly float X;

public readonly float Y;

public readonly float Z;
}
8 changes: 4 additions & 4 deletions samples/Mumble/GameReporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,16 +119,16 @@ protected override async Task ExecuteAsync(CancellationToken stoppingToken)
}

logger.LogInformation(
"[{UiTick}] {Name}, {Title} ({Specialization}) is on {Transport} in {Map}, Position: {{ Right = {Pos0}, Up = {Pos1}, Front = {Pos2} }}",
"[{UiTick}] {Name}, {Title} ({Specialization}) is on {Transport} in {Map}, Position: {{ Latitude = {X}, Longitude = {Z}, Elevation = {Y} }}",
snapshot.UiTick,
identity.Name,
title,
specialization,
transport,
map.Name,
snapshot.AvatarPosition[0],
snapshot.AvatarPosition[1],
snapshot.AvatarPosition[2]
snapshot.AvatarPosition.X,
snapshot.AvatarPosition.Z,
snapshot.AvatarPosition.Y
);
}
},
Expand Down

0 comments on commit 831f327

Please sign in to comment.