public void RunGame() { _logger.Start(); var config = ConfigBuilder.GetDefault() .Build(); var componentRoot = TestHelper.GetGameRunner(_container, config); _messageBus = _container.Resolve <IMessageBus>(); _trace = _container.Resolve <ITrace>(); _tileListener = new DemoTileListener(_messageBus, _logger); // start game on default position componentRoot.RunGame(StartGeoCoordinate); _geoPositionObserver = _container.Resolve <ITileController>(); _mapPositionObserver = _container.Resolve <ITileController>(); _messageBus.AsObservable <GeoPosition>().Do(position => { _trace.Debug(LogTag, "GeoPosition: {0}", position.ToString()); _geoPositionObserver.OnNext(position.Coordinate); }).Subscribe(); _messageBus.AsObservable <Vector2d>().Do(position => { _trace.Debug(LogTag, "MapPosition: {0}", position.ToString()); _mapPositionObserver.OnNext(position); }).Subscribe(); }
// Update is called once per frame private void Update() { if (_isInitialized && _position != transform.position) { _position = transform.position; Scheduler.ThreadPool.Schedule(() => _positionObserver.OnNext(new MapPoint(_position.x, _position.z, _position.y))); } }
private void DoContinuosMovements() { _geoPositionObserver.OnNext(StartGeoCoordinate); float speed = 30; // meters per second float distance = 1000; // meters float angle = 30; // grads MoveTo(angle, speed, distance); MoveTo(360 - angle, speed, distance); _trace.Debug(LogTag, "DoContinuosMovements: end"); }
/// <summary> Runs game. </summary> /// <remarks> Do not call this method on UI thread to prevent its blocking. </remarks> /// <param name="coordinate">GeoCoordinate for (0,0) map point. </param> public void RunGame(GeoCoordinate coordinate) { var messageBus = _container.Resolve <IMessageBus>(); // resolve actual position observers var tilePositionObserver = _container.Resolve <ITileController>(); _mapPositionObserver = tilePositionObserver; _geoPositionObserver = tilePositionObserver; // notify about geo coordinate change _geoPositionObserver.OnNext(coordinate); }
void Awake() { var appManager = ApplicationManager.Instance; _geoPositionObserver = appManager.GetService<ITileController>(); _messageBus = appManager.GetService<IMessageBus>(); _trace = appManager.GetService<ITrace>(); var elevationProvider = appManager.GetService<IElevationProvider>(); _messageBus.AsObservable<GeoPosition>() .SubscribeOn(Scheduler.ThreadPool) .Do(position => { _trace.Info(CategoryName, "GeoPosition: {0}", position.ToString()); // notify ASM about position change to process tiles _geoPositionObserver.OnNext(position.Coordinate); // calculate new world position var mapPoint = GeoProjection.ToMapCoordinate(appManager.Coordinate, position.Coordinate); var elevation = elevationProvider.GetElevation(position.Coordinate); var worldPosition = new Vector3((float)mapPoint.X, elevation, (float)mapPoint.Y); // set transform on UI thread Observable.Start(() => transform.position = worldPosition, Scheduler.MainThread); }).Subscribe(); _messageBus.AsObservable<TileLoadFinishMessage>() .Take(1) .ObserveOnMainThread() .Subscribe(_ => { Observable.Start(() => { // read nmea file with gps data using (Stream stream = new FileStream(GpsTrackFile, FileMode.Open)) { _trace.Info(CategoryName, "start to read geopositions from {0}", GpsTrackFile); _mocker = new NmeaPositionMocker(stream, _messageBus); _mocker.OnDone += (s, e) => _trace.Info(CategoryName, "trace is finished"); _mocker.Start(Thread.Sleep); } }, Scheduler.ThreadPool); }); }
void Awake() { var appManager = ApplicationManager.Instance; _geoPositionObserver = appManager.GetService <ITileController>(); _messageBus = appManager.GetService <IMessageBus>(); _trace = appManager.GetService <ITrace>(); var elevationProvider = appManager.GetService <IElevationProvider>(); _messageBus.AsObservable <GeoPosition>() .SubscribeOn(Scheduler.ThreadPool) .Do(position => { _trace.Info(CategoryName, "GeoPosition: {0}", position.ToString()); // notify ASM about position change to process tiles _geoPositionObserver.OnNext(position.Coordinate); // calculate new world position var mapPoint = GeoProjection.ToMapCoordinate(appManager.Coordinate, position.Coordinate); var elevation = elevationProvider.GetElevation(position.Coordinate); var worldPosition = new Vector3((float)mapPoint.X, elevation, (float)mapPoint.Y); // set transform on UI thread Observable.Start(() => transform.position = worldPosition, Scheduler.MainThread); }).Subscribe(); _messageBus.AsObservable <TileLoadFinishMessage>() .Take(1) .ObserveOnMainThread() .Subscribe(_ => { Observable.Start(() => { // read nmea file with gps data using (Stream stream = new FileStream(GpsTrackFile, FileMode.Open)) { _trace.Info(CategoryName, "start to read geopositions from {0}", GpsTrackFile); _mocker = new NmeaPositionMocker(stream, _messageBus); _mocker.OnDone += (s, e) => _trace.Info(CategoryName, "trace is finished"); _mocker.Start(Thread.Sleep); } }, Scheduler.ThreadPool); }); }
void IObserver <Vector2d> .OnNext(Vector2d value) { _mapPositionObserver.OnNext(value); }
void IObserver <GeoCoordinate> .OnNext(GeoCoordinate value) { _geoPositionObserver.OnNext(value); }