Skip to content

Commit

Permalink
Merge branch 'kira-kira'
Browse files Browse the repository at this point in the history
  • Loading branch information
KimihikoAkayasaki committed Nov 16, 2024
2 parents 223b646 + c6de6fe commit 0f0a375
Show file tree
Hide file tree
Showing 107 changed files with 2,646 additions and 808 deletions.
130 changes: 130 additions & 0 deletions Amethyst.Plugins.Contract/Actions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
using System;
using System.Diagnostics.CodeAnalysis;

namespace Amethyst.Plugins.Contract;

// Input action declaration for key events
public interface IKeyInputAction : IComparable<IKeyInputAction>, IEquatable<IKeyInputAction>
{
/// <summary>
/// Identifies the action
/// </summary>
public string Guid { get; init; }

/// <summary>
/// Friendly name of the action
/// </summary>
public string Name { get; set; }

/// <summary>
/// Action description for binding UI
/// </summary>
public string Description { get; set; }

/// <summary>
/// Action image for binding UI to be shown in info
/// MUST BE OF TYPE Microsoft.UI.Xaml.Controls.Image
/// </summary>
/// <remarks>
/// Make this a getter and return an Image constructed
/// during OnLoad, expect COM-related crashes otherwise
/// </remarks>
public object? Image { get; set; }

/// <summary>
/// Invoke the action (shortcut)
/// </summary>
public Action<object?> Invoke => _ => { };

/// <summary>
/// Checks whether the action is used for anything
/// </summary>
public bool IsUsed => false;

/// <summary>
/// Action data type (shortcut)
/// </summary>
public Type DataType => typeof(object);
}

// Input action declaration for key events
public class KeyInputAction<T> : IKeyInputAction
{
/// <summary>
/// Identifies the action
/// </summary>
public string Guid { get; init; } = System.Guid.NewGuid().ToString();

/// <summary>
/// Friendly name of the action
/// </summary>
public string Name { get; set; } = "INVALID";

/// <summary>
/// Action description for binding UI
/// </summary>
public string Description { get; set; } = string.Empty;

/// <summary>
/// Action image for binding UI to be shown in info
/// MUST BE OF TYPE Microsoft.UI.Xaml.Controls.Image
/// </summary>
/// <remarks>
/// Make this a getter and return an Image constructed
/// during OnLoad, expect COM-related crashes otherwise
/// </remarks>
public object? Image { get; set; }

/// <summary>
/// Implement comparator with other actions (by Guid)
/// </summary>
public int CompareTo(IKeyInputAction? other)
{
return string.Compare(Guid, other?.Guid, StringComparison.Ordinal);
}

/// <summary>
/// Implement comparator with other actions (by Guid)
/// </summary>
public bool Equals(IKeyInputAction? other)
{
return Guid.Equals(other?.Guid);
}

/// <summary>
/// Implement comparator with other objects
/// </summary>
public override bool Equals(object? obj)
{
return Equals(obj as IKeyInputAction);
}

/// <summary>
/// Implement hashes for the comparator
/// </summary>
public override int GetHashCode()
{
return Guid.GetHashCode();
}

/// <summary>
/// Host import for Invoke() calls and stuff
/// Func so you can use it in static context
/// </summary>
public Func<IAmethystHost?> GetHost { get; set; } = () => null;

/// <summary>
/// Invoke the action (shortcut)
/// </summary>
public Action<T?> Invoke => data => GetHost()?.ReceiveKeyInput(this, data);

/// <summary>
/// Checks whether the action is used for anything
/// </summary>
public bool IsUsed => GetHost()?.CheckInputActionIsUsed(this) ?? false;

/// <summary>
/// Action data type (shortcut)
/// </summary>
public Type DataType => typeof(T);
}
63 changes: 31 additions & 32 deletions Amethyst.Plugins.Contract/Amethyst.Plugins.Contract.csproj
Original file line number Diff line number Diff line change
@@ -1,37 +1,36 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Title>Amethyst Device Plugin API (Contract)</Title>
<FileVersion></FileVersion>
<Version>0.2.13</Version>
<Platforms>x64</Platforms>
</PropertyGroup>
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Title>Amethyst Device Plugin API (Contract)</Title>
<FileVersion></FileVersion>
<Version>0.3.33</Version>
<Platforms>x64</Platforms>
</PropertyGroup>

<PropertyGroup>
<PackageId>Amethyst.Plugins.Contract</PackageId>
<Version>0.2.25</Version>
<Authors>K2VR</Authors>
<Company>K2VR</Company>
<PackageTags>Amethyst;K2VR;KinectToVR;VR;OpenVR;Fullbody Tracking</PackageTags>
<Description>
This client class library lets you export your plugin library for Amethyst with MEF.
Compatible with C# (with XAML via WinUI/WinRT), C++/CLI, and custom WinRT projections.
Contains additional functions and helper classes to make plugin developmnet easier.
</Description>
<PackageIcon>ktvr.png</PackageIcon>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RequireLicenseAcceptance>true</RequireLicenseAcceptance>
<SupportedOSPlatformVersion>10.0.19041.0</SupportedOSPlatformVersion>
<PlatformTarget>AnyCPU</PlatformTarget>
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
</PropertyGroup>
<PropertyGroup>
<PackageId>Amethyst.Plugins.Contract</PackageId>
<Authors>K2VR</Authors>
<Company>K2VR</Company>
<PackageTags>Amethyst;K2VR;KinectToVR;VR;OpenVR;Fullbody Tracking</PackageTags>
<Description>
This client class library lets you export your plugin library for Amethyst with MEF.
Compatible with C# (with XAML via WinUI/WinRT), C++/CLI, and custom WinRT projections.
Contains additional functions and helper classes to make plugin developmnet easier.
</Description>
<PackageIcon>ktvr.png</PackageIcon>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
<RequireLicenseAcceptance>true</RequireLicenseAcceptance>
<SupportedOSPlatformVersion>10.0.19041.0</SupportedOSPlatformVersion>
<PlatformTarget>AnyCPU</PlatformTarget>
<AllowUnsafeBlocks>False</AllowUnsafeBlocks>
</PropertyGroup>

<ItemGroup>
<None Include="Assets\ktvr.png" Pack="true" PackagePath="\" />
</ItemGroup>
<ItemGroup>
<None Include="Assets\ktvr.png" Pack="true" PackagePath="\" />
</ItemGroup>

</Project>
</Project>
9 changes: 9 additions & 0 deletions Amethyst.Plugins.Contract/Classes.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
using System.Data;
using System.Diagnostics.CodeAnalysis;
using System.Numerics;
using System.Runtime.Serialization;
using System.Text.Json.Serialization;

namespace Amethyst.Plugins.Contract;

Expand Down Expand Up @@ -103,6 +105,13 @@ public Quaternion Orientation
/// Auto-computed on each pose [position] change
/// </summary>
public long PreviousPoseTimestamp { get; private set; }

/// <summary>
/// Supported key input actions that can be used by Amethyst
/// </summary>
[JsonIgnore]
[IgnoreDataMember]
public SortedSet<IKeyInputAction> SupportedInputActions { get; init; } = new();
}

[DataContract]
Expand Down
44 changes: 42 additions & 2 deletions Amethyst.Plugins.Contract/Contract.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,13 @@ public interface IServiceEndpoint
[DefaultValue(null)]
public Uri ErrorDocsUri { get; }

/// <summary>
/// Keeps all supported input actions that may be received from ProcessKeyInput
/// You will not be able to receive actions from unsupported TrackerType either
/// </summary>
[DefaultValue(null)]
public Dictionary<TrackerType, SortedSet<IKeyInputAction>> SupportedInputActions { get; }

/// <summary>
/// Get the absolute pose of the HMD, calibrated against the play space
/// Return null if unknown to the service or unavailable
Expand Down Expand Up @@ -341,6 +348,12 @@ public interface IServiceEndpoint
/// Check connection: status, serialized status, combined ping time
/// </summary>
public Task<(int Status, string StatusMessage, long PingTime)> TestConnection();

/// <summary>
/// Process a key input event sent by a device, that was assigned and found
/// </summary>
public Task ProcessKeyInput(IKeyInputAction action, object? data,
TrackerType? receiver, CancellationToken? token = null);
}

/// <summary>
Expand All @@ -352,7 +365,7 @@ public interface IAmethystHost
/// Helper to get all joints' positions from the app, which are added in Amethyst.
/// Note: if joint's off, its trackingState will be ITrackedJointState::State_NotTracked
/// Note: [AppJointPoses] will always be returned raw and w/o tweaks/offsets
/// / if need the final ones, please consider writing an IServiceEndpoint
/// / if you need the final ones, please consider writing an IServiceEndpoint
/// </summary>
List<TrackedJoint> AppJointPoses { get; }

Expand Down Expand Up @@ -412,6 +425,11 @@ public interface IAmethystHost
/// </summary>
bool IsTrackedJointValid(TrackedJointType jointType);

/// <summary>
/// Check if a tracker with the specified role is enabled and active
/// </summary>
bool IsTrackerEnabled(TrackerType trackerType);

/// <summary>
/// Lock the main update loop while in scope with [lock (UpdateThreadLock) { }]
/// This will block AME from updating while locked, and also wait for when the/
Expand Down Expand Up @@ -465,14 +483,36 @@ void Log(object message, LogSeverity severity = LogSeverity.Info, [CallerLineNum
/// Mark fatal as true to show the crash handler with your message
/// </summary>
void RequestExit(string message, bool fatal = false);

/// <summary>
/// Process a key input action called from a single joint
/// The handler will check whether the action is used anywhere,
/// and trigger the linked output action if applicable
/// </summary>
/// <param name="action">
/// Definition of the input action called
/// </param>
/// <param name="data">
/// Data to be sent, involved with the action
/// </param>
void ReceiveKeyInput(IKeyInputAction action, object? data);

/// <summary>
/// Check whether a KeyInputAction is used for anything
/// Devices may use this to skip updating unused actions
/// </summary>
/// <param name="action">
/// Definition of the input action to validate
/// </param>
bool CheckInputActionIsUsed(IKeyInputAction action);
}

/// <summary>
/// Implement this interface and put its type inside your plugin metadata
/// under "DependencyInstaller" for dependency installation functionality
/// Note: you should only use basic/local functionality, as it is unknown
/// whether the load context will contain any external libraries you may
/// be relying on - like framework or device proprietary SDKs and such, etc
/// be relying on - like framework or device proprietary SDKs and such, etc.
/// </summary>
public interface IDependencyInstaller
{
Expand Down
5 changes: 4 additions & 1 deletion Amethyst.Plugins.Contract/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,10 @@ public enum TrackerType
TrackerWaist,
TrackerChest,
TrackerCamera,
TrackerKeyboard
TrackerKeyboard,
TrackerHead,
TrackerLeftHand,
TrackerRightHand
}

// Global joint states
Expand Down
14 changes: 12 additions & 2 deletions Amethyst/Amethyst.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@
<Description>Amethyst (Desktop) App</Description>
<PackageProjectUrl>k2vr.tech</PackageProjectUrl>
<!--AZ_BUILD_DATA<Version>AZ_BUILD_NUMBER</Version>AZ_BUILD_DATA-->
<FileVersion>1.2.16.0</FileVersion>
<AssemblyVersion>1.2.16.0</AssemblyVersion>
<FileVersion>1.3.0.0</FileVersion>
<AssemblyVersion>1.3.0.0</AssemblyVersion>
<RepositoryUrl>https://github.com/KinectToVR/Amethyst</RepositoryUrl>
<EnablePreviewMsixTooling>true</EnablePreviewMsixTooling>
</PropertyGroup>
Expand Down Expand Up @@ -235,6 +235,16 @@
<Generator>MSBuild:Compile</Generator>
</Page>
</ItemGroup>
<ItemGroup>
<Page Remove="$(ProjectDir)\Plugins\**\*.xaml" />
<Compile Remove="$(ProjectDir)\Plugins\**\*.xaml" />
<None Include="$(ProjectDir)\Plugins\**\*.xaml" />
</ItemGroup>
<ItemGroup>
<Page Remove="$(ProjectDir)\Plugins\**\*.pri" />
<Compile Remove="$(ProjectDir)\Plugins\**\*.pri" />
<None Include="$(ProjectDir)\Plugins\**\*.pri" />
</ItemGroup>
<ProjectExtensions>
<VisualStudio>
<UserProperties assets_4strings_4it_1json__JsonSchema="https://api.airplane.dev/v0/schemas/task.json" />
Expand Down
Loading

0 comments on commit 0f0a375

Please sign in to comment.