void Start()
    {
        // init utymap library
        _compositionRoot = InitTask.Run((container, config) =>
        {
            container
            .Register(Component.For <Stylesheet>().Use <Stylesheet>(@"mapcss/ground/ground.mapcss"))
            .Register(Component.For <MaterialProvider>().Use <MaterialProvider>())
            .Register(Component.For <GameObjectBuilder>().Use <GameObjectBuilder>())
            .Register(Component.For <IGeocoder>().Use <UtyMapGeocoder>())
            .Register(Component.For <IElementBuilder>().Use <PlaceElementBuilder>().Named("place"));
        });

        // initial geo position and quad key of character
        var coordinate = new GeoCoordinate(StartLatitude, StartLongitude);
        var quadKey    = GeoUtils.CreateQuadKey(coordinate, LevelOfDetail);

        // init address controller which is responsible for searching address
        _addressController = new AddressController(
            _compositionRoot.GetService <IGeocoder>(),
            Text.GetComponent <Text>());

        // init tile controller which is responsible for tile processing
        _tileController = new TileController(
            _compositionRoot.GetService <IMapDataStore>(),
            _compositionRoot.GetService <Stylesheet>(),
            ElevationType,
            coordinate,
            LevelOfDetail);

        // freeze target till initial tile is loaded
        var rigidbody = CharacterTarget.transform.GetComponent <Rigidbody>();

        rigidbody.isKinematic = true;
        // TODO unsubscribe listener
        _compositionRoot
        .GetService <IMapDataStore>()
        .ObserveOn <Tile>(Scheduler.MainThread)
        .Subscribe(tile =>
        {
            if (!quadKey.Equals(tile.QuadKey))
            {
                return;
            }

            // get elevation at current position
            var elevation = _compositionRoot
                            .GetService <IMapDataLibrary>()
                            .GetElevation(ElevationType, quadKey, coordinate);
            // move character accordingly
            CharacterTarget.transform.localPosition = new Vector3(
                CharacterTarget.transform.localPosition.x,
                (float)elevation + 5f,
                CharacterTarget.transform.localPosition.z);
            rigidbody.isKinematic = false;
        });
    }
Exemple #2
0
        void Start()
        {
            // init utymap library
            _compositionRoot = InitTask.Run((container, config) =>
            {
                container
                .Register(Component.For <Stylesheet>().Use <Stylesheet>(@"mapcss/default/index.mapcss"))
                .Register(Component.For <MaterialProvider>().Use <MaterialProvider>())
                .Register(Component.For <GameObjectBuilder>().Use <GameObjectBuilder>())
                .RegisterInstance <IEnumerable <IElementBuilder> >(new List <IElementBuilder>());
            });
            // store map data store reference to member variable
            _mapDataStore = _compositionRoot.GetService <IMapDataStore>();

            // for demo purpose, disable mesh caching to force import data into memory for every run
            _compositionRoot.GetService <IMapDataLibrary>().DisableCache();

            // get reference for active stylesheet.
            var stylesheet = _compositionRoot.GetService <Stylesheet>();
            // get reference to trace.
            var trace = _compositionRoot.GetService <ITrace>();
            // create tile which represents target region to load.
            var tile = new Tile(
                // create quadkey using coordinate and choose proper LOD
                GeoUtils.CreateQuadKey(_coordinate, Scene == SceneType.Bird ? 14 : 16),
                // provide stylesheet (used to be the same as for import)
                stylesheet,
                // use cartesian projection as we want to build flat world
                new CartesianProjection(_coordinate),
                // use flat elevation (all vertices have zero meters elevation)
                ElevationDataType.Flat,
                // parent for built game objects
                gameObject);

            // import data into memory
            _mapDataStore.AddTo(
                // define where geoindex is created (in memory, not persistent)
                MapDataStorages.TransientStorageKey,
                // path to map data
                String.Format(MapDataPathFormat, Scene == SceneType.Bird ? "json" : "xml"),
                // stylesheet is used to import only used data and skip unused
                stylesheet,
                // level of detail (zoom) for which map data should be imported
                new Range <int>(16, 16),
                new CancellationToken())
            // start import and listen for events.
            .Subscribe(
                // NOTE progress callback is ignored
                (progress) => { },
                // exception is reported
                (exception) => trace.Error("import", exception, "Cannot import map data"),
                // once completed, load the corresponding tile
                () => _mapDataStore.OnNext(tile));
        }
        void Start()
        {
            // init utymap library
            _compositionRoot = InitTask.Run((container, config) =>
            {
                container
                .Register(Component.For <Stylesheet>().Use <Stylesheet>(@"mapcss/default/index.mapcss"))
                .Register(Component.For <MaterialProvider>().Use <MaterialProvider>())
                .Register(Component.For <GameObjectBuilder>().Use <GameObjectBuilder>())
                .RegisterInstance <IEnumerable <IElementBuilder> >(new List <IElementBuilder>());
            });

            // store map data store reference to member variable
            _mapDataStore = _compositionRoot.GetService <IMapDataStore>();

            // get reference for active stylesheet
            var stylesheet = _compositionRoot.GetService <Stylesheet>();
            // define level of detail
            const int levelOfDetail = 14;
            // create center coordinate;
            var coordinate = (new GeoCoordinate(Latitude, Longitude));
            // create "center" tile
            var center = GeoUtils.CreateQuadKey(coordinate, levelOfDetail);

            // load multiply tiles at once
            for (var tileX = center.TileX - 1; tileX <= center.TileX + 1; ++tileX)
            {
                for (var tileY = center.TileY - 1; tileY <= center.TileY + 1; ++tileY)
                {
                    var quadKey = new QuadKey(tileX, tileY, levelOfDetail);
                    var parent  = new GameObject(quadKey.ToString());
                    parent.transform.SetParent(gameObject.transform);
                    _mapDataStore.OnNext(new Tile(
                                             // quadkey to load.
                                             quadKey,
                                             // provide stylesheet
                                             stylesheet,
                                             // use cartesian projection as we want to build flat world
                                             new CartesianProjection(coordinate),
                                             // use grid elevation: uses mapzen servers by default,
                                             // stores elevation in simple NxN grid format.
                                             ElevationDataType.Grid,
                                             // parent for built game objects
                                             parent));
                }
            }
        }
Exemple #4
0
 public static void Reload()
 {
     if (ReloadTask == null || ReloadTask.IsCompleted)
     {
         ReloadTask = Task.Run(() =>
         {
             if (!InitTask.IsCompleted)
             {
                 InitTask.Wait();
             }
             ReadLevelDifferences(true);
             ReadRecipeRotations(true);
             ReadCraftingActionData();
             Reloaded();
         });
     }
 }
Exemple #5
0
 private static void GameDataReloaded()
 {
     if (ReloadTask == null || ReloadTask.IsCompleted)
     {
         ReloadTask = Task.Run(() =>
         {
             if (!InitTask.IsCompleted)
             {
                 InitTask.Wait();
             }
             ReadItems(true);
             ReadRecipes(true);
             ReadActions(true);
             Reloaded();
         });
     }
 }
Exemple #6
0
        void Start()
        {
            // init utymap library
            _compositionRoot = InitTask.Run((container, config) =>
            {
                container
                // NOTE use another mapcss style
                .Register(Component.For <Stylesheet>().Use <Stylesheet>(@"mapcss/customization/customization.mapcss"))
                .Register(Component.For <MaterialProvider>().Use <MaterialProvider>())
                .Register(Component.For <GameObjectBuilder>().Use <GameObjectBuilder>())
                // NOTE for use case 1: put cubes for POI
                .Register(Component.For <IElementBuilder>().Use <PlaceElementBuilder>().Named("place"))
                // NOTE for use case 2: search for capsule object in scene which replaces specific tree
                .Register(Component.For <IElementBuilder>().Use <ImportElementBuilder>().Named("import"));
            });

            // store map data store reference to member variable
            _mapDataStore = _compositionRoot.GetService <IMapDataStore>();

            // disable mesh caching to force import data into memory for every run
            _compositionRoot.GetService <IMapDataLibrary>().DisableCache();

            // import data into memory
            _mapDataStore.AddTo(
                // define where geoindex is created (in memory, not persistent)
                MapDataStorages.TransientStorageKey,
                // path to map data
                MapDataPath,
                // stylesheet is used to import only used data and skip unused
                _compositionRoot.GetService <Stylesheet>(),
                // level of detail (zoom) for which map data should be imported
                new Range <int>(16, 16),
                new CancellationToken())
            // start import and listen for events.
            .Subscribe(
                // NOTE progress callback is ignored
                (progress) => { },
                // exception is reported
                (exception) => _compositionRoot.GetService <ITrace>().Error("import", exception, "Cannot import map data"),
                // once completed, load the corresponding tile
                OnDataImported);
        }
Exemple #7
0
        void Start()
        {
            _compositionRoot = InitTask.Run((container, config) =>
            {
                container
                .Register(Component.For <Stylesheet>().Use <Stylesheet>(@"mapcss/default/index.mapcss"))
                .Register(Component.For <MaterialProvider>().Use <MaterialProvider>())
                .Register(Component.For <GameObjectBuilder>().Use <GameObjectBuilder>())
                .Register(Component.For <IElementBuilder>().Use <LabelElementBuilder>().Named("label"));
            });

            var mapDataStore     = _compositionRoot.GetService <IMapDataStore>();
            var stylesheet       = _compositionRoot.GetService <Stylesheet>();
            var materialProvider = _compositionRoot.GetService <MaterialProvider>();
            var startCoord       = new GeoCoordinate(StartLatitude, StartLongitude);

            // scaled radius of Earth in meters, approx. 1:1000
            const float planetRadius = 6371f;
            const float surfaceScale = 0.01f;
            const float detailScale  = 1f;

            _lods = new List <Range <int> > {
                new Range <int>(1, 8), new Range <int>(9, 15), new Range <int>(16, 16)
            };

            var sphereController  = new SphereTileController(mapDataStore, stylesheet, ElevationDataType.Flat, Pivot, _lods[0], planetRadius);
            var surfaceController = new SurfaceTileController(mapDataStore, stylesheet, ElevationDataType.Flat, Pivot, _lods[1], startCoord, surfaceScale, 1000);
            var detailController  = new SurfaceTileController(mapDataStore, stylesheet, ElevationDataType.Flat, Pivot, _lods[2], startCoord, detailScale, 500);

            var sphereGestures  = new SphereGestureStrategy(sphereController, TwoFingerMoveGesture, ManipulationGesture, planetRadius);
            var surfaceGestures = new SurfaceGestureStrategy(surfaceController, TwoFingerMoveGesture, ManipulationGesture);
            var detailGestures  = new SurfaceGestureStrategy(detailController, TwoFingerMoveGesture, ManipulationGesture);

            _spaces = new List <Space>
            {
                new SphereSpace(sphereController, sphereGestures, Planet, materialProvider),
                new SurfaceSpace(surfaceController, surfaceGestures, Surface, materialProvider),
                new SurfaceSpace(detailController, detailGestures, Surface, materialProvider)
            };

            DoTransition(startCoord, StartZoom);
        }
Exemple #8
0
        void Start()
        {
            // init utymap library
            _compositionRoot = InitTask.Run((container, config) =>
            {
                container
                // NOTE use another mapcss style
                .Register(Component.For <Stylesheet>().Use <Stylesheet>(@"mapcss/default/index.mapcss"))
                .Register(Component.For <MaterialProvider>().Use <MaterialProvider>())
                .Register(Component.For <GameObjectBuilder>().Use <GameObjectBuilder>())
                .RegisterInstance <IEnumerable <IElementBuilder> >(new List <IElementBuilder>());
            });

            // get trace for logging.
            _trace = _compositionRoot.GetService <ITrace>();

            // store map data store reference to member variable
            _mapDataStore = _compositionRoot.GetService <IMapDataStore>();

            // disable mesh caching to force import data into memory for every run
            _compositionRoot.GetService <IMapDataLibrary>().DisableCache();

            // import data into memory
            _mapDataStore.AddTo(
                // define where geoindex is created (in memory, not persistent)
                MapDataStorages.TransientStorageKey,
                // path to map data
                MapDataPath,
                // stylesheet is used to import only used data and skip unused
                _compositionRoot.GetService <Stylesheet>(),
                // level of detail (zoom) for which map data should be imported
                _range,
                new CancellationToken())
            // start import and listen for events.
            .Subscribe(
                // NOTE progress callback is ignored
                (progress) => { },
                // exception is reported
                (exception) => _trace.Error("search", exception, "Cannot import map data"),
                // once completed, load the corresponding tile
                OnDataImported);
        }
Exemple #9
0
        /// <summary>
        /// User changed state in voice lobbies (joined/left)
        /// </summary>
        /// <param name="e"></param>
        /// <returns></returns>
        public async Task VoiceStateUpdated(VoiceStateUpdateEventArgs e)
        {
            InitTask?.Wait();
            //DebugLogWriteLine("VoiceStateUpdated: ");

            if (e.After?.Channel != e.Before?.Channel)               //Channel changed
            {
                var beforeInLobbies     = DateVoiceLobbies.Contains(e.Before?.Channel);
                var afterInLobbies      = DateVoiceLobbies.Contains(e.After?.Channel);
                var beforeInSecretRooms = SecretRooms.Contains(e.Before?.Channel);
                var afterInSecretRooms  = SecretRooms.Contains(e.After?.Channel);

                if (!beforeInLobbies && !beforeInSecretRooms && afterInLobbies)
                {
                    //User connected to lobbies
                    DebugLogWriteLine($"User {e.User} connected to {e.Channel} ");
                    UserConnected_AddToActivity(e.User);
                    //Start matching session
                    TryStartMatchingTask();
                }
                else if ((beforeInLobbies || beforeInSecretRooms) && !afterInLobbies && !afterInSecretRooms)
                {
                    //User left activity
                    DebugLogWriteLine($"User {e.User} left activity ");
                    if (beforeInLobbies)
                    {
                        UsersInLobbies.Remove(e.User);
                        RemoveStateFor(e.User);
                    }
                    //remove disband secret room if one left TODO check logic
                    if (beforeInSecretRooms)
                    {
                        RemoveStateFor(e.User);
                        //DebugLogWrite($"trying to disbnad {e.Before.Channel}... ");
                        await disbandRemoveSecretRoom(e.Before.Channel).ConfigureAwait(false);

                        //DebugLogWrite($"{e.Before.Channel} removed/disbanded");
                    }
                }
                else if (beforeInLobbies && afterInLobbies)
                {
                    DebugLogWriteLine($"User {e.User} switched lobbies ");
                    //User switched Lobbies
                }
                else if (beforeInLobbies && afterInSecretRooms)
                {
                    DebugLogWriteLine($"User {e.User} moved to {e.After.Channel} ");
                    //Moved to secret room
                    UsersInLobbies.Remove(e.User);
                }
                else if (beforeInSecretRooms && afterInLobbies)
                {
                    //Returned from secret room
                    RemoveStateFor(e.User);
                    DebugLogWriteLine($"User {e.User} returned to lobby, trying to disbnad {e.Before.Channel}... ");
                    UserConnected_AddToActivity(e.User);
                    await disbandRemoveSecretRoom(e.Before.Channel).ConfigureAwait(false);

                    //DebugLogWrite($"{e.Before.Channel} removed/disbanded. Starting MatchingTask");
                    //Start matching session
                    TryStartMatchingTask();
                }

                TryCombLobbies();
            }

            async Task disbandRemoveSecretRoom(DiscordChannel channel)
            {
                //Remove empty room, if 1 user left, move him into lobby 0, later room will be removed
                if (channel.Users.Count() == 0)
                {
                    try {                     //usually shouldn't throw, but in debug
                        await channel.DeleteAsync().ConfigureAwait(false);
                    } catch {
                        //DebugLogWrite($"Exception while deleting ");
                    }
                }
                else if (channel.Users.Count() == 1)
                {
                    try {
                        var moveMember = await Guild.GetMemberAsync(channel.Users.First().Id);

                        await DateVoiceLobbies[0].PlaceMemberAsync(moveMember);
                    } catch {
                        //DebugLogWrite($"Exception while moving member ");
                    }
                }
            }
        }
 private ListViewItem CreateTaskItem(InitTask task, int weight)
 {
     ListViewItem item = new ListViewItem();
     item.Text = TypeDescriptor.GetConverter(typeof(InitTask)).ConvertToString(task);
     item.StateImageIndex = weight;
     item.Tag = task;
     return item;
 }
 private ListViewItem CreateTaskItem(InitTask task)
 {
     return this.CreateTaskItem(task, 1);
 }