Skip to content
This repository was archived by the owner on Nov 16, 2024. It is now read-only.

Commit 27bc8af

Browse files
WLT quiet mode (#209)
* First pass making all WLT logging mutable. * Move to taking advantage of ConditionalAttribute. * Fix SpongyAnchorARF to return spongy pose when not applying adjustment. * Update packaging to v1.5.1. * Disable space pin binder file logging by default.
1 parent 08343b0 commit 27bc8af

30 files changed

+318
-235
lines changed

Assets/WorldLocking.ASA.Examples/Scripts/PlatformMenuSelector.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ namespace Microsoft.MixedReality.WorldLocking.ASA.Examples
1313
public class PlatformMenuSelector : MonoBehaviour
1414
{
1515
[SerializeField]
16-
private GameObject HoloLensMenu;
16+
private GameObject HoloLensMenu = null;
1717

1818
[SerializeField]
19-
private GameObject AndroidMenu;
19+
private GameObject AndroidMenu = null;
2020

2121
[SerializeField]
22-
private GameObject iOSMenu;
22+
private GameObject iOSMenu = null;
2323

2424
private void Awake()
2525
{

Assets/WorldLocking.ASA/Scripts/PublisherASA.cs

Lines changed: 54 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22
// Licensed under the MIT License. See LICENSE in the project root for license information.
33

44
//#define WLT_EXTRA_LOGGING
5+
#define WLT_LOG_ASA_SETUP
6+
7+
#if WLT_DISABLE_LOGGING
8+
#undef WLT_EXTRA_LOGGING
9+
#undef WLT_LOG_ASA_SETUP
10+
#endif // WLT_DISABLE_LOGGING
511

612
using System;
713
using System.Collections;
@@ -35,7 +41,7 @@ namespace Microsoft.MixedReality.WorldLocking.ASA
3541
/// </remarks>
3642
public class PublisherASA : MonoBehaviour, IPublisher
3743
{
38-
#region Inspector fields
44+
#region Inspector fields
3945

4046
[Tooltip("Enable coarse relocation")]
4147
[SerializeField]
@@ -144,10 +150,10 @@ public class PublisherASA : MonoBehaviour, IPublisher
144150
/// </summary>
145151
public float MinRecommendedForCreateProgress { get { return minRecommendedForCreateProgress; } set { minRecommendedForCreateProgress = value; } }
146152

147-
#endregion // Inspector fields
153+
#endregion // Inspector fields
148154

149155
#if WLT_ASA_INCLUDED
150-
#region Internal members
156+
#region Internal members
151157
/// <summary>
152158
/// The ASA manager
153159
/// </summary>
@@ -198,9 +204,9 @@ public class PublisherASA : MonoBehaviour, IPublisher
198204

199205
private bool IsBusy { get { return busy != null; } }
200206

201-
#endregion // Internal members
207+
#endregion // Internal members
202208

203-
#region Internal types
209+
#region Internal types
204210

205211
/// <summary>
206212
/// All of the information we know about a cloud anchor.
@@ -259,16 +265,15 @@ public static string DebugString(AnchorRecord record, string msg)
259265
/// </summary>
260266
/// <param name="record">The record to dump.</param>
261267
/// <param name="msg">A prefacing message.</param>
268+
[System.Diagnostics.Conditional("WLT_EXTRA_LOGGING")]
262269
public static void DebugLog(AnchorRecord record, string msg)
263270
{
264-
#if WLT_EXTRA_LOGGING
265271
SimpleConsole.AddLine(ConsoleLow, DebugString(record, msg));
266-
#endif // WLT_EXTRA_LOGGING
267272
}
268273
};
269274

270275
/// <summary>
271-
/// Concreate internal implementation of ILocalPeg.
276+
/// Concrete internal implementation of ILocalPeg.
272277
/// </summary>
273278
private class LocalPeg : ILocalPeg
274279
{
@@ -311,10 +316,10 @@ public Pose GlobalPose
311316

312317
}
313318

314-
#endregion // Internal types
319+
#endregion // Internal types
315320
#endif // WLT_ASA_INCLUDED
316321

317-
#region Public API
322+
#region Public API
318323

319324
/// <summary>
320325
/// Initialization.
@@ -338,7 +343,7 @@ public async void Setup()
338343
}
339344
#endif // UNITY_ANDROID
340345

341-
Debug.Log($"Setting up publisher.");
346+
LogASASetup($"Setting up publisher.");
342347
asaManager = GameObject.FindObjectOfType<SpatialAnchorManager>();
343348
if (asaManager == null)
344349
{
@@ -351,19 +356,19 @@ public async void Setup()
351356
int delayBeforeCreateMS = 1000;
352357
await Task.Delay(delayBeforeCreateMS);
353358

354-
Debug.Log($"To create session");
359+
LogASASetup($"To create session");
355360
await asaManager.CreateSessionAsync();
356361

357362
int delayBeforeStartMS = 2000;
358363
await Task.Delay(delayBeforeStartMS);
359364

360-
Debug.Log($"To start session");
365+
LogASASetup($"To start session");
361366
await asaManager.StartSessionAsync();
362367

363368
asaManager.Session.OnLogDebug += OnASALog;
364369
asaManager.Session.Error += OnASAError;
365370

366-
Debug.Log($"To create criteria");
371+
LogASASetup($"To create criteria");
367372
anchorLocateCriteria = new AnchorLocateCriteria();
368373

369374
locationProvider = CreateLocationProvider();
@@ -380,7 +385,7 @@ public async void Setup()
380385
#endif // WLT_ASA_INCLUDED
381386
}
382387

383-
#region Implementation of IPublisher
388+
#region Implementation of IPublisher
384389
/// <inheritdocs />
385390
public ReadinessStatus Status
386391
{
@@ -463,7 +468,7 @@ public async Task<CloudAnchorId> Create(LocalPegAndProperties pegAndProps)
463468

464469
AnchorRecord.DebugLog(record, "Past ToCloud");
465470

466-
Debug.Log($"asaMgr:{(asaManager != null ? "valid" : "null")}, session:{(asaManager != null && asaManager.Session != null ? "valid" : "null")}");
471+
LogASASetup($"asaMgr:{(asaManager != null ? "valid" : "null")}, session:{(asaManager != null && asaManager.Session != null ? "valid" : "null")}");
467472

468473
await asaManager.Session.CreateAnchorAsync(record.cloudAnchor);
469474

@@ -505,10 +510,10 @@ public async Task<LocalPegAndProperties> Read(CloudAnchorId cloudAnchorId)
505510
SimpleConsole.AddLine(ConsoleMid, $"Read CID={cloudAnchorId}");
506511
// mafinc - do we want an option here to force downloading, even if we already have it cached locally?
507512
AnchorRecord record = GetRecord(cloudAnchorId);
508-
Debug.Log($"GetRecord ca={cloudAnchorId}, record={(record == null ? "null" : record.localPeg.Name)}");
513+
LogASASetup($"GetRecord ca={cloudAnchorId}, record={(record == null ? "null" : record.localPeg.Name)}");
509514
if (record == null)
510515
{
511-
Debug.Log($"Downloading record ca={cloudAnchorId}");
516+
LogASASetup($"Downloading record ca={cloudAnchorId}");
512517
record = await DownloadRecord(cloudAnchorId);
513518
if (record == null)
514519
{
@@ -680,13 +685,21 @@ public async Task PurgeArea(float radius)
680685
throw new NotSupportedException("Trying to use PublisherASA without Azure Spatial Anchors installed.");
681686
#endif // WLT_ASA_INCLUDED
682687
}
683-
#endregion // Implementation of IPublisher
688+
#endregion // Implementation of IPublisher
684689

685-
#endregion // Public API
690+
#endregion // Public API
686691

687692
#if WLT_ASA_INCLUDED
688693

689-
#region Internal implementations
694+
#region Internal implementations
695+
696+
private static void LogASASetup(string message)
697+
{
698+
#if WLT_LOG_ASA_SETUP
699+
Debug.Log(message);
700+
#endif // WLT_LOG_ASA_SETUP
701+
}
702+
690703

691704
/// <summary>
692705
/// Implementation of downloading a cloud anchor by its cloud anchor id.
@@ -695,7 +708,7 @@ public async Task PurgeArea(float radius)
695708
/// <returns>Awaitable internal <see cref="AnchorRecord"/> created from cloud anchor.</returns>
696709
private async Task<AnchorRecord> DownloadRecord(CloudAnchorId cloudAnchorId)
697710
{
698-
Debug.Log($"Criteria.Identifiers to [{cloudAnchorId}]");
711+
LogASASetup($"Criteria.Identifiers to [{cloudAnchorId}]");
699712
var cachedRecord = GetRecord(cloudAnchorId);
700713
if (cachedRecord != null)
701714
{
@@ -710,7 +723,7 @@ private async Task<AnchorRecord> DownloadRecord(CloudAnchorId cloudAnchorId)
710723

711724
var watcher = asaManager.Session.CreateWatcher(anchorLocateCriteria);
712725

713-
Debug.Log($"Got watcher, start waiting");
726+
LogASASetup($"Got watcher, start waiting");
714727

715728
AnchorRecord record = null;
716729
bool waiting = true;
@@ -727,11 +740,11 @@ private async Task<AnchorRecord> DownloadRecord(CloudAnchorId cloudAnchorId)
727740
}
728741
if (locatedCopy != null && locatedCopy.Count > 0)
729742
{
730-
Debug.Log($"Got {locatedCopy.Count} located anchors");
743+
LogASASetup($"Got {locatedCopy.Count} located anchors");
731744
int idx = locatedCopy.FindIndex(x => x.Identifier == cloudAnchorId);
732745
if (idx >= 0)
733746
{
734-
Debug.Log($"Found located anchor {cloudAnchorId}, status={locatedCopy[idx].Status}");
747+
LogASASetup($"Found located anchor {cloudAnchorId}, status={locatedCopy[idx].Status}");
735748
if (locatedCopy[idx].Status == LocateAnchorStatus.Located)
736749
{
737750
record = new AnchorRecord();
@@ -861,7 +874,7 @@ private async Task<List<AnchorRecord>> SearchForRecords(float radius)
861874

862875
var watcher = asaManager.Session.CreateWatcher(anchorLocateCriteria);
863876

864-
Debug.Log($"Got watcher, start waiting");
877+
LogASASetup($"Got watcher, start waiting");
865878

866879
double startTime = Time.timeAsDouble;
867880
List<AnchorRecord> locatedRecords = new List<AnchorRecord>();
@@ -880,7 +893,7 @@ private async Task<List<AnchorRecord>> SearchForRecords(float radius)
880893
}
881894
if (locatedCopy != null && locatedCopy.Count > 0)
882895
{
883-
Debug.Log($"Got {locatedCopy.Count} located anchors");
896+
LogASASetup($"Got {locatedCopy.Count} located anchors");
884897
foreach (var located in locatedCopy)
885898
{
886899
SimpleConsole.AddLine(ConsoleMid, $"Found located anchor {located.Identifier}, status={located.Status}");
@@ -944,7 +957,7 @@ private async Task<List<AnchorRecord>> DownloadRecordList(IReadOnlyCollection<Cl
944957

945958
var watcher = asaManager.Session.CreateWatcher(anchorLocateCriteria);
946959

947-
Debug.Log($"Got watcher, start waiting");
960+
LogASASetup($"Got watcher, start waiting");
948961

949962
double startTime = Time.timeAsDouble;
950963
List<AnchorRecord> locatedRecords = new List<AnchorRecord>();
@@ -963,7 +976,7 @@ private async Task<List<AnchorRecord>> DownloadRecordList(IReadOnlyCollection<Cl
963976
}
964977
if (locatedCopy != null && locatedCopy.Count > 0)
965978
{
966-
Debug.Log($"Got {locatedCopy.Count} located anchors");
979+
LogASASetup($"Got {locatedCopy.Count} located anchors");
967980
foreach (var located in locatedCopy)
968981
{
969982
SimpleConsole.AddLine(ConsoleMid, $"Found located anchor {located.Identifier}, status={located.Status}");
@@ -1041,9 +1054,9 @@ record = await DownloadRecord(cloudAnchorId);
10411054
}
10421055

10431056

1044-
#endregion // Internal implementations
1057+
#endregion // Internal implementations
10451058

1046-
#region Internal helpers
1059+
#region Internal helpers
10471060

10481061
/// <summary>
10491062
/// Convert the collection of ids to an array.
@@ -1211,7 +1224,7 @@ private async Task<LocalPeg> InternalCreateLocalPeg(string id, Pose lockedPose)
12111224
return peg;
12121225
}
12131226

1214-
#region TRASH
1227+
#region TRASH
12151228

12161229
#if WLT_EXTRA_LOGGING
12171230
private static void PrintScene()
@@ -1255,7 +1268,7 @@ private static void PrintSubtree(int consolePriority, Transform subroot, int ind
12551268
}
12561269
#endif // WLT_EXTRA_LOGGING
12571270

1258-
#endregion // TRASH
1271+
#endregion // TRASH
12591272

12601273
/// <summary>
12611274
/// If cloud anchor id is unknown, add the record, else update the record.
@@ -1344,9 +1357,9 @@ private async Task<AnchorRecord> RecordFromCloud(AnchorRecord record)
13441357
return record;
13451358
}
13461359

1347-
#endregion // Internal helpers
1360+
#endregion // Internal helpers
13481361

1349-
#region ASA events
1362+
#region ASA events
13501363

13511364
/// <summary>
13521365
/// Put incoming cloud anchors (from ASA thread) into a list for processing on main thread.
@@ -1409,17 +1422,17 @@ private void OnASAError(object sender, SessionErrorEventArgs args)
14091422
);
14101423
}
14111424

1412-
#endregion // ASA events
1425+
#endregion // ASA events
14131426

1414-
#region Setup helpers
1427+
#region Setup helpers
14151428

14161429
/// <summary>
14171430
/// Create a location provider if coarse relocation is enabled.
14181431
/// </summary>
14191432
/// <returns>Location provider or null.</returns>
14201433
private PlatformLocationProvider CreateLocationProvider()
14211434
{
1422-
Debug.Log($"To create location provider");
1435+
LogASASetup($"To create location provider");
14231436

14241437
if (!CoarseRelocationEnabled)
14251438
{
@@ -1511,9 +1524,9 @@ private void ReleaseBusy()
15111524
Debug.Assert(busy != null);
15121525
busy = null;
15131526
}
1514-
#endregion // Setup helpers
1527+
#endregion // Setup helpers
15151528

1516-
#region Awful stuff
1529+
#region Awful stuff
15171530

15181531
#if UNITY_ANDROID
15191532
private static readonly string[] androidPermissions = new string[]
@@ -1605,7 +1618,7 @@ private void PermissionCallback_Denied(string permission)
16051618
waitingState = PermissionWaiting.Denied;
16061619
}
16071620
#endif
1608-
#endregion // Awful stuff
1621+
#endregion // Awful stuff
16091622

16101623
#endif // WLT_ASA_INCLUDED
16111624
}

0 commit comments

Comments
 (0)