Skip to content

Commit

Permalink
WLT quiet mode (microsoft#209)
Browse files Browse the repository at this point in the history
* 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.
  • Loading branch information
fast-slow-still authored Sep 27, 2021
1 parent 08343b0 commit 27bc8af
Show file tree
Hide file tree
Showing 30 changed files with 318 additions and 235 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ namespace Microsoft.MixedReality.WorldLocking.ASA.Examples
public class PlatformMenuSelector : MonoBehaviour
{
[SerializeField]
private GameObject HoloLensMenu;
private GameObject HoloLensMenu = null;

[SerializeField]
private GameObject AndroidMenu;
private GameObject AndroidMenu = null;

[SerializeField]
private GameObject iOSMenu;
private GameObject iOSMenu = null;

private void Awake()
{
Expand Down
95 changes: 54 additions & 41 deletions Assets/WorldLocking.ASA/Scripts/PublisherASA.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,12 @@
// Licensed under the MIT License. See LICENSE in the project root for license information.

//#define WLT_EXTRA_LOGGING
#define WLT_LOG_ASA_SETUP

#if WLT_DISABLE_LOGGING
#undef WLT_EXTRA_LOGGING
#undef WLT_LOG_ASA_SETUP
#endif // WLT_DISABLE_LOGGING

using System;
using System.Collections;
Expand Down Expand Up @@ -35,7 +41,7 @@ namespace Microsoft.MixedReality.WorldLocking.ASA
/// </remarks>
public class PublisherASA : MonoBehaviour, IPublisher
{
#region Inspector fields
#region Inspector fields

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

#endregion // Inspector fields
#endregion // Inspector fields

#if WLT_ASA_INCLUDED
#region Internal members
#region Internal members
/// <summary>
/// The ASA manager
/// </summary>
Expand Down Expand Up @@ -198,9 +204,9 @@ public class PublisherASA : MonoBehaviour, IPublisher

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

#endregion // Internal members
#endregion // Internal members

#region Internal types
#region Internal types

/// <summary>
/// All of the information we know about a cloud anchor.
Expand Down Expand Up @@ -259,16 +265,15 @@ public static string DebugString(AnchorRecord record, string msg)
/// </summary>
/// <param name="record">The record to dump.</param>
/// <param name="msg">A prefacing message.</param>
[System.Diagnostics.Conditional("WLT_EXTRA_LOGGING")]
public static void DebugLog(AnchorRecord record, string msg)
{
#if WLT_EXTRA_LOGGING
SimpleConsole.AddLine(ConsoleLow, DebugString(record, msg));
#endif // WLT_EXTRA_LOGGING
}
};

/// <summary>
/// Concreate internal implementation of ILocalPeg.
/// Concrete internal implementation of ILocalPeg.
/// </summary>
private class LocalPeg : ILocalPeg
{
Expand Down Expand Up @@ -311,10 +316,10 @@ public Pose GlobalPose

}

#endregion // Internal types
#endregion // Internal types
#endif // WLT_ASA_INCLUDED

#region Public API
#region Public API

/// <summary>
/// Initialization.
Expand All @@ -338,7 +343,7 @@ public async void Setup()
}
#endif // UNITY_ANDROID

Debug.Log($"Setting up publisher.");
LogASASetup($"Setting up publisher.");
asaManager = GameObject.FindObjectOfType<SpatialAnchorManager>();
if (asaManager == null)
{
Expand All @@ -351,19 +356,19 @@ public async void Setup()
int delayBeforeCreateMS = 1000;
await Task.Delay(delayBeforeCreateMS);

Debug.Log($"To create session");
LogASASetup($"To create session");
await asaManager.CreateSessionAsync();

int delayBeforeStartMS = 2000;
await Task.Delay(delayBeforeStartMS);

Debug.Log($"To start session");
LogASASetup($"To start session");
await asaManager.StartSessionAsync();

asaManager.Session.OnLogDebug += OnASALog;
asaManager.Session.Error += OnASAError;

Debug.Log($"To create criteria");
LogASASetup($"To create criteria");
anchorLocateCriteria = new AnchorLocateCriteria();

locationProvider = CreateLocationProvider();
Expand All @@ -380,7 +385,7 @@ public async void Setup()
#endif // WLT_ASA_INCLUDED
}

#region Implementation of IPublisher
#region Implementation of IPublisher
/// <inheritdocs />
public ReadinessStatus Status
{
Expand Down Expand Up @@ -463,7 +468,7 @@ public async Task<CloudAnchorId> Create(LocalPegAndProperties pegAndProps)

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

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

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

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

#endregion // Public API
#endregion // Public API

#if WLT_ASA_INCLUDED

#region Internal implementations
#region Internal implementations

private static void LogASASetup(string message)
{
#if WLT_LOG_ASA_SETUP
Debug.Log(message);
#endif // WLT_LOG_ASA_SETUP
}


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

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

Debug.Log($"Got watcher, start waiting");
LogASASetup($"Got watcher, start waiting");

AnchorRecord record = null;
bool waiting = true;
Expand All @@ -727,11 +740,11 @@ private async Task<AnchorRecord> DownloadRecord(CloudAnchorId cloudAnchorId)
}
if (locatedCopy != null && locatedCopy.Count > 0)
{
Debug.Log($"Got {locatedCopy.Count} located anchors");
LogASASetup($"Got {locatedCopy.Count} located anchors");
int idx = locatedCopy.FindIndex(x => x.Identifier == cloudAnchorId);
if (idx >= 0)
{
Debug.Log($"Found located anchor {cloudAnchorId}, status={locatedCopy[idx].Status}");
LogASASetup($"Found located anchor {cloudAnchorId}, status={locatedCopy[idx].Status}");
if (locatedCopy[idx].Status == LocateAnchorStatus.Located)
{
record = new AnchorRecord();
Expand Down Expand Up @@ -861,7 +874,7 @@ private async Task<List<AnchorRecord>> SearchForRecords(float radius)

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

Debug.Log($"Got watcher, start waiting");
LogASASetup($"Got watcher, start waiting");

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

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

Debug.Log($"Got watcher, start waiting");
LogASASetup($"Got watcher, start waiting");

double startTime = Time.timeAsDouble;
List<AnchorRecord> locatedRecords = new List<AnchorRecord>();
Expand All @@ -963,7 +976,7 @@ private async Task<List<AnchorRecord>> DownloadRecordList(IReadOnlyCollection<Cl
}
if (locatedCopy != null && locatedCopy.Count > 0)
{
Debug.Log($"Got {locatedCopy.Count} located anchors");
LogASASetup($"Got {locatedCopy.Count} located anchors");
foreach (var located in locatedCopy)
{
SimpleConsole.AddLine(ConsoleMid, $"Found located anchor {located.Identifier}, status={located.Status}");
Expand Down Expand Up @@ -1041,9 +1054,9 @@ record = await DownloadRecord(cloudAnchorId);
}


#endregion // Internal implementations
#endregion // Internal implementations

#region Internal helpers
#region Internal helpers

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

#region TRASH
#region TRASH

#if WLT_EXTRA_LOGGING
private static void PrintScene()
Expand Down Expand Up @@ -1255,7 +1268,7 @@ private static void PrintSubtree(int consolePriority, Transform subroot, int ind
}
#endif // WLT_EXTRA_LOGGING

#endregion // TRASH
#endregion // TRASH

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

#endregion // Internal helpers
#endregion // Internal helpers

#region ASA events
#region ASA events

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

#endregion // ASA events
#endregion // ASA events

#region Setup helpers
#region Setup helpers

/// <summary>
/// Create a location provider if coarse relocation is enabled.
/// </summary>
/// <returns>Location provider or null.</returns>
private PlatformLocationProvider CreateLocationProvider()
{
Debug.Log($"To create location provider");
LogASASetup($"To create location provider");

if (!CoarseRelocationEnabled)
{
Expand Down Expand Up @@ -1511,9 +1524,9 @@ private void ReleaseBusy()
Debug.Assert(busy != null);
busy = null;
}
#endregion // Setup helpers
#endregion // Setup helpers

#region Awful stuff
#region Awful stuff

#if UNITY_ANDROID
private static readonly string[] androidPermissions = new string[]
Expand Down Expand Up @@ -1605,7 +1618,7 @@ private void PermissionCallback_Denied(string permission)
waitingState = PermissionWaiting.Denied;
}
#endif
#endregion // Awful stuff
#endregion // Awful stuff

#endif // WLT_ASA_INCLUDED
}
Expand Down
Loading

0 comments on commit 27bc8af

Please sign in to comment.