void ILocationManager.Start() { m_logger.Debug("Start"); m_running = true; m_didStartLocationServices = false; }
void ProcessValuables(IEnumerable <LocationValuablesCollectionItemContainer> locationValuables) { m_perf = new PerfCounters(); m_perf.Start("v"); // Group items by the sets of locations they reference. // The goal here is to reduce the number of locations we visit, ideally as close to 1 // visit per location as possible. SetDictionary <IEnumerable <Location>, LocationValuablesCollectionItemContainer> fixedSets = new SetDictionary <IEnumerable <Location>, LocationValuablesCollectionItemContainer>(); // Location sets per story tag Dictionary <string, IEnumerable <Location> > tagSets = new Dictionary <string, IEnumerable <Location> >(); // Location sets per location type Dictionary <string, IEnumerable <Location> > typeSets = new Dictionary <string, IEnumerable <Location> >(); SetDictionary <string, LocationValuablesCollectionItemContainer> tagLvcs = new SetDictionary <string, LocationValuablesCollectionItemContainer>(); SetDictionary <string, LocationValuablesCollectionItemContainer> typeLvcs = new SetDictionary <string, LocationValuablesCollectionItemContainer>(); foreach (var lvc in locationValuables) { if (lvc.SpawnItem.Locations != null) { fixedSets.Add(lvc.SpawnItem.Locations, lvc); } if (lvc.SpawnItem.LocationTypes != null) { foreach (var type in lvc.SpawnItem.LocationTypes) { if (!typeSets.ContainsKey(type)) { typeSets[type] = LocationCache.Instance.GetLocationsWithType(type); } typeLvcs.Add(type, lvc); } } if (lvc.SpawnItem.StoryTags != null) { foreach (var tag in lvc.SpawnItem.StoryTags) { if (!tagSets.ContainsKey(tag)) { tagSets[tag] = LocationCache.Instance.GetLocationsWithStoryTag(tag); } tagLvcs.Add(tag, lvc); } } } Dictionary <string, Location> processedLocations = new Dictionary <string, Location>(); // Processes the set of locations, optionally creating a union with an existing set Action <IEnumerable <Location>, IEnumerable <LocationValuablesCollectionItemContainer> > processLocations = (locs, lvcsIn) => { m_perf.Start("l"); m_perf.Start("u"); HashSet <LocationValuablesCollectionItemContainer> lvcs = new HashSet <LocationValuablesCollectionItemContainer>(); if (lvcsIn != null) { lvcs.UnionWith(lvcsIn); } m_perf.Stop("u"); m_perf.Start("locs"); if (locs != null) { foreach (var location in locs) { if (!processedLocations.ContainsKey(location.Id)) { processedLocations.Add(location.Id, location); if (location.LocationTypes != null) { foreach (var type in location.LocationTypes) { var tl = typeLvcs[type]; if (tl != null) { lvcs.UnionWith(tl); } } } if (location.StoryTags != null) { foreach (var tag in location.StoryTags) { var tl = tagLvcs[tag]; if (tl != null) { lvcs.UnionWith(tl); } } } m_perf.Start("c"); // Can be smarter here: if LVCs haven't changed, only locations, then // any location that's been checked can be skipped foreach (var lvc in lvcs) { // Have we processed this lvc/location combo recently?? // Note: this currently persists until the resource is deactivated. LocationSpawnItemResults <LocationValuablesCollection> results = null; lock (m_locationComputedItems) { results = GetResults(lvc.ActivationContext.InstanceId, location); if (results != null) { continue; } results = new LocationSpawnItemResults <LocationValuablesCollection>(lvc.ActivationContext.InstanceId, location, lvc.SpawnItem); var prob = lvc.SpawnItem.Probability.GetValueOrDefault(1); var rnd = Tools.RandomDouble(0, 1); if (rnd < prob) { // Tada! results.DidSpawn = true; } AddComputedResult(location, lvc.InstanceId, results); } if (results.DidSpawn) { OnItemsSpawned(lvc.InstanceId, results); } } m_perf.Stop("c"); } else { // TODO: locations re-used } } } m_perf.Stop("locs"); m_perf.Stop("l"); }; foreach (var set in fixedSets.Keys) { processLocations(set, fixedSets[set]); } foreach (var set in tagSets.Values) { processLocations(set, null); } foreach (var set in typeSets.Values) { processLocations(set, null); } /* * m_activationContexts.Add(e.ActivationContext.InstanceId, e.ActivationContext); */ //if (IsRunning) { //AddSpawnItems(e.LocationValuables, null/*e.ActivationContext.GetStorageAgent()*/); } m_perf.Stop("v"); m_logger.Debug("ProcessValuables perf={0}", m_perf.ToShortString()); }
public void Initialize() { m_liveSessionListeners = new HashSet <object>(); IStepTracker stepTracker = null; #if IOS_NATIVE if (Application.isMobilePlatform) { m_logger.Debug("Initializing iOS Native"); m_categoryOptions = IOSAudioSessionCategoryOptions.None; if (MixWithOthers) { m_categoryOptions = IOSAudioSessionCategoryOptions.MixWithOthers; } m_currentCategory = DefaultAudioCategory; if (EnableBackgroundAudio) { IOSAudioSession.Instance.SetCategory(m_currentCategory, m_categoryOptions); IOSAudioSession.Instance.RemoteCommandReceived += (sender, args) => { if (args.Command == IOSAudioRemoteCommand.Pause) { SuspendLiveSession(); } }; } if (UseNativeDownloader) { FileDownloader.SetFactory(new IOSFileDownloaderFactory()); } AppDataPath = IOSFileDownloader.AppDataPath; Accelerometer = IOSMotionManager.Instance.GetAccelerometer(); LocationManager = IOSLocationManager.Instance; SystemCompass = new IOSCompass(); if (EnableBeacons) { BeaconManager = IOSBeaconManager.Instance; } if (EnableNotifications) { LocalNotificationManager = new IOSLocalNotificationManager(IOSLocalNotificationTypes.Badge | IOSLocalNotificationTypes.Sound); } } #endif #if ANDROID_NATIVE if (Application.isMobilePlatform) { m_logger.Debug("Initializing Android Native"); JavaClass activityClass = new JavaClass("com.unity3d.player.UnityPlayer"); JavaObject mainActivity = activityClass.GetStaticFieldValue <JavaObject>("currentActivity", "android.app.Activity"); AndroidApplicationManager.Instance.Initialize(mainActivity); LocationManager = new AndroidLocationManager(); if (EnableBeacons) { BeaconManager = new AndroidBeaconManager(); } if (EnableNotifications) { LocalNotificationManager = new AndroidLocalNotificationManager(StorageManager.GetFilePath("platform", "androidNotificationManager.json")); } } #endif if (BeaconManager == null && EnableBeacons) { BeaconManager = UnityBeaconManager.Instance; } if (Accelerometer == null) { Accelerometer = gameObject.AddComponent <UnityAccelerometer>(); } if (LocationManager == null) { LocationManager = gameObject.AddComponent <UnityLocationManager>(); } LocationManager.EnableBackgroundUpdates = EnableBackgroundLocation; if (SystemCompass == null) { SystemCompass = gameObject.AddComponent <UnityCompass>(); } if (LocalNotificationManager == null) { LocalNotificationManager = new DummyLocalNotificationManager(); } if (EnableNotifications && EnableBackgroundNotifications) { BackgroundNotifier.Instance.Initialize(); } var nrCompass = new NoiseDampeningCompass(SystemCompass); #if UNITY_ANDROID // Android compass tends to be much more jittery--apply a higher dampening // factor nrCompass.DampeningFactor = 0.25; #endif NoiseReducedCompass = nrCompass; if (Application.isMobilePlatform) { var accTracker = new AccelerometerStepTracker(Accelerometer); stepTracker = accTracker; Accelerometer.Start(); accTracker.Start(); } else { stepTracker = gameObject.AddComponent <DebugStepTracker>(); } Pedometer = new Pedometer(stepTracker); m_logger.Debug("Setting compass type={0}", CompassType); switch (CompassType) { case CompassType.System: Compass = SystemCompass; break; case CompassType.NoiseReduced: Compass = NoiseReducedCompass; break; case CompassType.LocationTracker: LocationTrackerCompass = new Motive.AR.LocationServices.LocationTrackerCompass(); Compass = LocationTrackerCompass; break; case CompassType.Hybrid: default: var hybrid = new HybridCompass(NoiseReducedCompass); LocationTrackerCompass = hybrid.TrackerCompass; Compass = hybrid; break; } AudioChannel = CreateAudioPlayerChannel(); ForegroundAudioChannel = gameObject.AddComponent <UnityAudioPlayerChannel>(); Pedometer.Stepped += (sender, args) => { if (ScriptEngine.Instance.UserInteractionEventManager != null) { ScriptEngine.Instance.UserInteractionEventManager.AddEvent("step"); } }; if (ScreenSleepBehavior == ScreenSleepBehavior.AlwaysOn) { Screen.sleepTimeout = SleepTimeout.NeverSleep; } }