Skip to content

Commit b90ec46

Browse files
committed
changed over bone control
breaking down bone driver working on more swapping over changed over more code more work on jobification moved server provider to its own package improved the error reporting
1 parent 4d4406f commit b90ec46

38 files changed

Lines changed: 5588 additions & 865 deletions

Basis/Packages/com.basis.common/BasisLocks.cs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
using System.Collections.Generic;
55
using System.Linq;
66
using System.Text;
7+
using System.Threading;
78

89
namespace Basis.Scripts.Common
910
{
@@ -25,6 +26,8 @@ private sealed class ContextState
2526
{
2627
public readonly object Sync = new object();
2728
public readonly HashSet<string> Owners = new HashSet<string>();
29+
// Mirrors Owners.Count; written under Sync, read lock-free via Volatile.
30+
public int LiveCount;
2831
}
2932

3033
public static LockContext GetContext(string context)
@@ -81,7 +84,10 @@ public void Add(string key)
8184
var state = GetState();
8285

8386
lock (state.Sync)
84-
state.Owners.Add(key);
87+
{
88+
if (state.Owners.Add(key))
89+
Volatile.Write(ref state.LiveCount, state.Owners.Count);
90+
}
8591
}
8692

8793
public bool Remove(string key)
@@ -101,7 +107,10 @@ public bool Remove(string key)
101107
lock (state.Sync)
102108
{
103109
BasisDebug.Log($"removing lock for {key}");
104-
return state.Owners.Remove(key);
110+
bool removed = state.Owners.Remove(key);
111+
if (removed)
112+
Volatile.Write(ref state.LiveCount, state.Owners.Count);
113+
return removed;
105114
}
106115
}
107116

@@ -115,6 +124,7 @@ public void Clear()
115124
lock (state.Sync)
116125
{
117126
state.Owners.Clear();
127+
Volatile.Write(ref state.LiveCount, 0);
118128
}
119129
}
120130

@@ -163,10 +173,7 @@ public int Count
163173
return 0;
164174
}
165175

166-
lock (state.Sync)
167-
{
168-
return state.Owners.Count;
169-
}
176+
return Volatile.Read(ref state.LiveCount);
170177
}
171178
}
172179

Basis/Packages/com.basis.framework/Avatar/TransformBinders/BoneControl/BasisLocalBoneControl.cs

Lines changed: 172 additions & 140 deletions
Large diffs are not rendered by default.

Basis/Packages/com.basis.framework/BasisUI/Menus/BasisMenuBase.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public abstract class BasisMenuBase<TMenu> where TMenu : BasisMenuBase<TMenu>
1717

1818
public static List<BasisMenuActionProvider<TMenu>> Providers = new();
1919

20+
private static readonly HashSet<Type> SuppressedProviderTypes = new();
21+
2022
/// <summary>
2123
/// Parent component used containing Action Provider buttons.
2224
/// </summary>
@@ -32,6 +34,7 @@ public abstract class BasisMenuBase<TMenu> where TMenu : BasisMenuBase<TMenu>
3234
/// </summary>
3335
public static void AddProvider(BasisMenuActionProvider<TMenu> provider)
3436
{
37+
if (provider == null || SuppressedProviderTypes.Contains(provider.GetType())) return;
3538
Providers.Add(provider);
3639
Providers.Sort();
3740
if (Instance) Instance.BindProvidersToButtons();
@@ -47,6 +50,41 @@ public static void RemoveProvider(BasisMenuActionProvider<TMenu> provider)
4750
if (Instance) Instance.BindProvidersToButtons();
4851
}
4952

53+
/// <summary>
54+
/// Prevent a provider type from appearing on this menu, regardless of when its
55+
/// registrar runs. Order-independent: removes the provider if already present and
56+
/// blocks any later registration, rebinding the menu if it is open.
57+
/// </summary>
58+
public static void SuppressProvider<T>() where T : BasisMenuActionProvider<TMenu>
59+
=> SuppressProvider(typeof(T));
60+
61+
public static void SuppressProvider(Type providerType)
62+
{
63+
if (providerType == null)
64+
{
65+
BasisDebug.LogError("SuppressProvider was called with a null providerType; nothing suppressed.");
66+
return;
67+
}
68+
69+
SuppressedProviderTypes.Add(providerType);
70+
71+
if (Providers.RemoveAll(p => providerType.IsInstanceOfType(p)) > 0)
72+
{
73+
Providers.Sort();
74+
if (Instance) Instance.BindProvidersToButtons();
75+
BasisDebug.Log($"SuppressProvider removed and blocked provider '{providerType.Name}'.");
76+
}
77+
else
78+
{
79+
BasisDebug.LogWarning($"SuppressProvider could not find a registered provider of type '{providerType.Name}' to remove; it is now blocked from registering later.");
80+
}
81+
}
82+
83+
public static void AllowProvider(Type providerType)
84+
{
85+
if (providerType != null) SuppressedProviderTypes.Remove(providerType);
86+
}
87+
5088

5189
public void BindProvidersToButtons()
5290
{

Basis/Packages/com.basis.framework/BasisUI/Tweening/BasisTweenManager.cs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
using Basis.BasisUI;
12
using System;
23
using System.Collections.Generic;
34

@@ -25,10 +26,13 @@ internal static void RegisterGroup(Action<double> processor)
2526

2627
public static void Simulate(double realtimeSinceStartupAsDouble)
2728
{
28-
List<Action<double>> processors = _tweenProcessors;
29-
foreach (Action<double> tween in processors)
29+
if (BasisMainMenu.Instance != null)
3030
{
31-
tween(realtimeSinceStartupAsDouble);
31+
List<Action<double>> processors = _tweenProcessors;
32+
foreach (Action<double> tween in processors)
33+
{
34+
tween(realtimeSinceStartupAsDouble);
35+
}
3236
}
3337
}
3438
}

Basis/Packages/com.basis.framework/BasisUI/Tweening/TweenTypes/BaseTween.cs

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,21 @@ namespace Basis.BTween
1111
public static implicit operator bool(BaseTween<T> tween) => tween != null;
1212

1313

14-
public bool Active;
14+
private bool _active;
15+
public bool Active
16+
{
17+
get => _active;
18+
set
19+
{
20+
if (_active == value) return;
21+
_active = value;
22+
if (value) ActiveCount++;
23+
else ActiveCount--;
24+
}
25+
}
26+
// Live count of active tweens of this type; lets ProcessGroup skip the pool when idle.
27+
private static int ActiveCount;
28+
1529
public Easing Ease = Easing.OutSine;
1630
public float StartTime;
1731
public float EndTime;
@@ -28,6 +42,7 @@ static BaseTween()
2842

2943
private static void ProcessGroup(double currentTime)
3044
{
45+
if (ActiveCount <= 0) return;
3146
List<T> list = Tweens;
3247
int count = list.Count;
3348
for (int i = 0; i < count; i++)

Basis/Packages/com.basis.framework/Device Management/BasisDeviceManagement.cs

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ public static string StaticCurrentMode
160160
/// <summary>
161161
/// Registered device SDK managers capable of booting into given modes (Desktop/XR/etc.).
162162
/// </summary>
163-
[SerializeField] public List<BasisBaseTypeManagement> BaseTypes = new();
163+
[SerializeField] public BasisBaseTypeManagement[] BaseTypes;
164164

165165
/// <summary>
166166
/// Helpers that constrain transforms to input devices.
@@ -264,14 +264,11 @@ private async void OnDestroy()
264264
public void Simulate()
265265
{
266266
OnDeviceManagementLoop?.Invoke();
267-
int Count = BaseTypes.Count;
267+
int Count = BaseTypes.Length;
268268
for (int Index = 0; Index < Count; Index++)
269269
{
270-
BasisBaseTypeManagement Sim = BaseTypes[Index];
271-
if (Sim != null)
272-
{
273-
Sim.Simulate();
274-
}
270+
BaseTypes[Index].Simulate();
271+
//if a null happens here thats a failure of how you added / removed something
275272
}
276273
}
277274

@@ -450,7 +447,8 @@ public async Task StartDevices(string mode)
450447
/// </summary>
451448
public void StopAllDevices()
452449
{
453-
for (int i = 0; i < BaseTypes.Count; i++)
450+
var length = BaseTypes.Length;
451+
for (int i = 0; i < length; i++)
454452
{
455453
BaseTypes[i]?.AttemptStopSDK();
456454
}
@@ -477,7 +475,8 @@ public void ShutDownXR()
477475
/// </summary>
478476
public void StartAllStartIfPermanentlyExists()
479477
{
480-
for (int i = 0; i < BaseTypes.Count; i++)
478+
var length = BaseTypes.Length;
479+
for (int i = 0; i < length; i++)
481480
{
482481
BaseTypes[i]?.StartIfPermanentlyExists();
483482
}
@@ -507,9 +506,13 @@ public static void UnassignFBTrackers()
507506
public bool TryFindBasisBaseTypeManagement(string name, out List<BasisBaseTypeManagement> match, bool OnlyFinding = false)
508507
{
509508
match = new List<BasisBaseTypeManagement>();
510-
if (string.IsNullOrEmpty(name) || BaseTypes == null) return false;
509+
if (string.IsNullOrEmpty(name) || BaseTypes == null)
510+
{
511+
return false;
512+
}
511513

512-
for (int i = 0; i < BaseTypes.Count; i++)
514+
var length = BaseTypes.Length;
515+
for (int i = 0; i < length; i++)
513516
{
514517
var type = BaseTypes[i];
515518
if (type != null && type.AttemptIsDeviceBootable(name, OnlyFinding))
@@ -588,7 +591,7 @@ private IEnumerator RestoreInversetOffsets(BasisInput input, BasisStoredPrevious
588591
}
589592
if (prev.hasRoleAssigned)
590593
{
591-
input.Control.InverseOffsetFromBone = prev.InverseOffsetFromBone;
594+
input.Control.SetInverseOffset(prev.InverseOffsetFromBone);
592595
}
593596
if (input.HasControl)
594597
{
@@ -888,8 +891,9 @@ public async Task SoftSwitchToDesktop()
888891

889892
BasisDebug.Log($"Soft-switching from {AutoSwapPreviousVRMode} to Desktop (keeping runtime alive)", BasisDebug.LogTag.Device);
890893

894+
var length = BaseTypes.Length;
891895
// Soft-stop VR input devices — runtime stays alive
892-
for (int i = 0; i < BaseTypes.Count; i++)
896+
for (int i = 0; i < length; i++)
893897
{
894898
var bt = BaseTypes[i];
895899
if (bt != null && bt.IsDeviceBooted && bt.IsDeviceBootable(AutoSwapPreviousVRMode))
@@ -925,8 +929,9 @@ public async Task SoftSwitchToVR()
925929

926930
BasisDebug.Log($"Soft-switching from Desktop back to {vrMode}", BasisDebug.LogTag.Device);
927931

932+
var length = BaseTypes.Length;
928933
// Stop desktop devices normally
929-
for (int i = 0; i < BaseTypes.Count; i++)
934+
for (int i = 0; i < length; i++)
930935
{
931936
var bt = BaseTypes[i];
932937
if (bt != null && bt.IsDeviceBooted && bt.IsDeviceBootable(BasisConstants.Desktop))
@@ -941,7 +946,7 @@ public async Task SoftSwitchToVR()
941946
BasisCursorManagement.OnReset();
942947

943948
// Soft-start VR input devices — runtime is already alive
944-
for (int i = 0; i < BaseTypes.Count; i++)
949+
for (int i = 0; i < length; i++)
945950
{
946951
var bt = BaseTypes[i];
947952
if (bt != null && bt.IsDeviceBooted && bt.IsDeviceBootable(vrMode))

Basis/Packages/com.basis.framework/Device Management/Devices/Base/BasisInput.cs

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -311,8 +311,9 @@ public void CalculateOffset()
311311
BasisInverseOffsetData.InitialControlRotation = Control.OutgoingWorldData.rotation;
312312

313313
Vector3 Offset = Control.OutgoingWorldData.position - BasisInverseOffsetData.TrackerPosition;
314-
Control.InverseOffsetFromBone.position = BasisInverseOffsetData.InitialInverseTrackRotation * (Offset);
315-
Control.InverseOffsetFromBone.rotation = BasisInverseOffsetData.InitialInverseTrackRotation * BasisInverseOffsetData.InitialControlRotation;
314+
Control.SetInverseOffset(
315+
BasisInverseOffsetData.InitialInverseTrackRotation * (Offset),
316+
BasisInverseOffsetData.InitialInverseTrackRotation * BasisInverseOffsetData.InitialControlRotation);
316317
Control.UseInverseOffset = true;
317318
}
318319

@@ -323,8 +324,7 @@ public void UnAssignRoleAndTracker()
323324
{
324325
if (Control != null)
325326
{
326-
Control.IncomingData.position = Vector3.zero;
327-
Control.IncomingData.rotation = Quaternion.identity;
327+
Control.SetIncoming(Vector3.zero, Quaternion.identity);
328328
SetRealTrackers(BasisHasTracked.HasNoTracker, BasisHasRigLayer.HasNoRigLayer, UniqueDeviceIdentifier);
329329
}
330330
if (DeviceMatchSettings == null || DeviceMatchSettings.HasTrackedRole == false)
@@ -392,8 +392,7 @@ public void UnAssignTracker()
392392
if (HasControl)
393393
{
394394
BasisDebug.Log($"UnAssigning Tracker {Control.name}", BasisDebug.LogTag.Input);
395-
Control.InverseOffsetFromBone.position = Vector3.zero;
396-
Control.InverseOffsetFromBone.rotation = Quaternion.identity;
395+
Control.SetInverseOffset(Vector3.zero, Quaternion.identity);
397396
Control.UseInverseOffset = false;
398397
}
399398
UnAssignRoleAndTracker();
@@ -736,11 +735,7 @@ public void ControlOnlyAsDevice()
736735
{
737736
if (hasRoleAssigned && Control.HasTracked != BasisHasTracked.HasNoTracker)
738737
{
739-
// Apply position offset using math.mul for quaternion-vector multiplication
740-
Control.IncomingData.position = ScaledDeviceCoord.position;
741-
742-
// Apply rotation offset using math.mul for quaternion multiplication
743-
Control.IncomingData.rotation = ScaledDeviceCoord.rotation;
738+
Control.SetIncoming(ScaledDeviceCoord.position, ScaledDeviceCoord.rotation);
744739
}
745740

746741
}

Basis/Packages/com.basis.framework/Device Management/Devices/Base/BasisInputController.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,7 @@ public void ControlOnlyAsHand(Vector3 Position,Quaternion Rotation)
8383
{
8484
if (hasRoleAssigned && Control.HasTracked != BasisHasTracked.HasNoTracker)
8585
{
86-
Control.IncomingData.position = Position;
87-
Control.IncomingData.rotation = Rotation;
86+
Control.SetIncoming(Position, Rotation);
8887
}
8988
}
9089
public Vector3 ChangeHandYHeight(Vector3 position)

Basis/Packages/com.basis.framework/Device Management/Devices/Simulation/BasisInputXRSimulate.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,8 +99,7 @@ public override void LateDoPollData()
9999

100100
if (hasRoleAssigned && Control.HasTracked != BasisHasTracked.HasNoTracker)
101101
{
102-
Control.IncomingData.position = ScaledDeviceCoord.position;
103-
Control.IncomingData.rotation = ScaledDeviceCoord.rotation;
102+
Control.SetIncoming(ScaledDeviceCoord.position, ScaledDeviceCoord.rotation);
104103
this.transform.name = Control.name;
105104
this.FollowMovement.name = $"{Control.name} Moveable transform";
106105
}

Basis/Packages/com.basis.framework/Drivers/Common/BasisHeightDriver.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -136,8 +136,7 @@ public static void ApplyAvatarScale(float ScaleFactor)
136136
{
137137
BasisLocalBoneControl c = boneDriver.Controls[Index];
138138

139-
c.TposeLocalScaled.position = c.TposeLocal.position * ScaleFactor;
140-
c.TposeLocalScaled.rotation = c.TposeLocal.rotation;
139+
c.SetTposeScaled(c.TposeLocal.position * ScaleFactor, c.TposeLocal.rotation);
141140
c.ScaledOffset = c.Offset * ScaleFactor;
142141
}
143142
}

0 commit comments

Comments
 (0)