Пример #1
0
        protected override void OnUpdate()
        {
            var mouseMode = GetSingleton <CurrentMouseMode>();

            if (mouseMode.Mode != MouseMode.Mining)
            {
                return;
            }

            var mapSettings = GetSingleton <MapSettings>();
            var ores        = GetComponentDataFromEntity <ResourceOre>(true);

            Entities
            .WithoutBurst()
            .WithStructuralChanges()
            .WithAll <MouseMiningTag>()
            .ForEach((ref MouseButtons mouseButtons, ref MouseWorldPosition mouseWorldPosition) =>
            {
                if (mouseButtons.IsClick(MouseButton.Left))
                {
                    var clickedEntity = mapSettings.Tiles[IndexUtils.WorldIndex1D(mouseWorldPosition.Position, mapSettings.Tiles.Length)];
                    var clickedOre    = ores[clickedEntity];

                    if (clickedOre.IsValid)
                    {
                        if (EntityManager.HasComponent <WorkProgress>(clickedEntity))
                        {
                            EntityManager.SetComponentData(clickedEntity, new WorkProgress()
                            {
                                Progress = clickedOre.Type.Value.WorkRequired
                            });
                        }
                        else
                        {
                            EntityManager.AddComponentData(clickedEntity, new WorkProgress()
                            {
                                Progress = clickedOre.Type.Value.WorkRequired
                            });
                        }

                        if (EntityManager.HasComponent <MiningWork>(clickedEntity) == false)
                        {
                            EntityManager.AddComponentData(clickedEntity, new MiningWork()
                            {
                                ProgressPerSecond = 0
                            });
                        }
                    }
                }
                if (mouseButtons.IsClick(MouseButton.Right))
                {
                    var clickedEntity = mapSettings.Tiles[IndexUtils.WorldIndex1D(mouseWorldPosition.Position, mapSettings.Tiles.Length)];
                    var clickedOre    = ores[clickedEntity];

                    if (clickedOre.IsValid)
                    {
                        if (EntityManager.HasComponent <WorkProgress>(clickedEntity) == false)
                        {
                            EntityManager.AddComponentData(clickedEntity, new WorkProgress()
                            {
                                Progress = 0
                            });
                        }

                        if (EntityManager.HasComponent <MiningWork>(clickedEntity) == false)
                        {
                            EntityManager.AddComponentData(clickedEntity, new MiningWork()
                            {
                                ProgressPerSecond = clickedOre.Type.Value.WorkRequired
                            });
                        }
                        else
                        {
                            EntityManager.SetComponentData(clickedEntity, new MiningWork()
                            {
                                ProgressPerSecond = clickedOre.Type.Value.WorkRequired
                            });
                        }
                    }
                }
            }).Run();
        }
Пример #2
0
        private void InitializeBufferData(List <T> vertices)
        {
            List <int> indices = IndexUtils.GenerateIndices(vertices.Count);

            InitializeBufferData(vertices, indices);
        }
Пример #3
0
        public void ZeroCount()
        {
            var indices = IndexUtils.GenerateIndices(0);

            Assert.AreEqual(0, indices.Count);
        }
        protected async Task <IIndexInterface <TKey, TValue>[]> GetAndWaitForIndexes <TKey, TValue>(params string[] propertyNames) where TValue : IIndexableGrain
        {
            var indexes = propertyNames.Select(name => this.IndexFactory.GetIndex <TKey, TValue>(IndexUtils.PropertyNameToIndexName(name))).ToArray();

            const int MaxRetries = 100;
            int       retries    = 0;

            foreach (var index in indexes)
            {
                while (!await index.IsAvailable())
                {
                    ++retries;
                    Assert.True(retries < MaxRetries, "Maximum number of GetAndWaitForIndexes retries was exceeded");
                    await Task.Delay(50);
                }
            }
            return(indexes);
        }
Пример #5
0
        public void LoadChunk(ChunkIndex chunkIndex)
        {
            if (m_createdChunks.ContainsKey(chunkIndex))
            {
                return;
            }

            Entity chunkEntity = CreateChunk(chunkIndex, false);

            var voxels = m_voxelWorld.EntityManager.GetBuffer <Voxel>(chunkEntity);

            float cX = (float)(chunkIndex.X * ChunkWidth);
            float cY = (float)(chunkIndex.Y * ChunkHeight);
            float cZ = (float)(chunkIndex.Z * ChunkDepth);

            Perlin perlin     = new Perlin();
            Perlin dirtPerlin = new Perlin();

            perlin.Frequency = 0.01;

            dirtPerlin.Frequency = 0.001;
            dirtPerlin.Seed      = 5;

            for (int x = 0; x < ChunkWidth; x++)
            {
                for (int z = 0; z < ChunkDepth; z++)
                {
                    //    Position used for data generation
                    float3 voxelPos = new float3(
                        cX + x + 0.01f,
                        1.01f,
                        cZ + z + 0.01f
                        );


                    int stone = (int)(perlin.GetValue((double)voxelPos.x, 0.1, (double)voxelPos.z) * 6) + 6;
                    int dirt  = (int)(dirtPerlin.GetValue((double)voxelPos.x, 0.1, (double)voxelPos.z) * 6) + 6;

                    bool lastDirt = true;

                    for (int y = 0; y < ChunkHeight; y++)
                    {
                        int flatIndex = IndexUtils.ToFlatIndex(x, y, z, ChunkWidth, ChunkDepth);

                        if (y <= stone)
                        {
                            lastDirt = false;
                            m_emptyChunk[flatIndex] = new Voxel()
                            {
                                DatabaseIndex = 3
                            };
                        }
                        else if (y <= dirt)
                        {
                            lastDirt = true;
                            m_emptyChunk[flatIndex] = new Voxel()
                            {
                                DatabaseIndex = 1
                            };
                        }
                        else
                        {
                            if (lastDirt)
                            {
                                m_emptyChunk[flatIndex] = new Voxel()
                                {
                                    DatabaseIndex = 2
                                };
                            }
                            m_emptyChunk[flatIndex] = new Voxel()
                            {
                                DatabaseIndex = 0
                            };
                            lastDirt = false;
                        }
                    }
                }
            }

            voxels.AddRange(m_emptyChunk);
            if (!m_voxelWorld.EntityManager.HasComponent <TriangulateChunk>(chunkEntity))
            {
                m_voxelWorld.EntityManager.AddComponentData(chunkEntity, new TriangulateChunk());
            }
        }
Пример #6
0
 public void TestTranslateStartEndIndex(int start, int end, int total, int expectedStart, int expectedEnd)
 {
     var(actualStart, actualEnd) = IndexUtils.TranslateStartEndIndex(start, end, total);
     Assert.Equal(expectedStart, actualStart);
     Assert.Equal(expectedEnd, actualEnd);
 }
Пример #7
0
        protected override void OnUpdate()
        {
            var mapSettings = GetSingleton <MapSettings>();
            var edgeSize    = mapSettings.MapEdgeSize;

            var ores = GetComponentDataFromEntity <ResourceOre>(true);

            var tiles          = mapSettings.Tiles;
            var neighborsLocal = _neighbors;

            var setTargetCMDBuffer = _cmdBufferSystem.CreateCommandBuffer().ToConcurrent();

            // TODO: Enable burst (native queue allocation problem)
            Entities
            .WithReadOnly(ores)
            .WithReadOnly(neighborsLocal)
            .WithReadOnly(tiles)
            .WithNativeDisableContainerSafetyRestriction(tiles)
            .WithoutBurst()
            .WithAll <UnitTag, SeekingOresTag>()
            .WithNone <Waypoint, PathRequest>()
            .ForEach((Entity e, int entityInQueryIndex, in MapIndex mapIndex) =>
            {
                #region Found ores
                int2 oreIndex = new int2();

                bool founded  = false;
                var tilesSize = tiles.Length;

                NativeQueue <int> toSearch     = new NativeQueue <int>(Allocator.Temp);
                NativeArray <Boolean> searched = new NativeArray <Boolean>(tiles.Length, Allocator.Temp, NativeArrayOptions.ClearMemory);
                toSearch.Enqueue(mapIndex.Index1D);

                while (founded == false && toSearch.Count > 0)
                {
                    var currentIndex = toSearch.Dequeue();
                    for (int i = 0; i < neighborsLocal.Length; i++)
                    {
                        var neighborIndex = neighborsLocal[i].Of(currentIndex, tilesSize);
                        if (neighborIndex != -1 && searched[neighborIndex] == false)
                        {
                            toSearch.Enqueue(neighborIndex);
                        }
                    }

                    var currentEntity      = tiles[currentIndex];
                    searched[currentIndex] = true;

                    if (ores.HasComponent(currentEntity) && ores[currentEntity].IsValid)
                    {
                        oreIndex = IndexUtils.Index2D(currentIndex, tilesSize);
                        founded  = true;
                    }
                }

                toSearch.Dispose();
                searched.Dispose();
                #endregion Found ores

                setTargetCMDBuffer.AddComponent <PathRequest>(entityInQueryIndex, e, new PathRequest(mapIndex.Index2D, oreIndex));
            }).ScheduleParallel();

            _cmdBufferSystem.AddJobHandleForProducer(Dependency);
        }
Пример #8
0
        static int Main(string[] args)
        {
            var defaultsConfig = ConfigurationsUtils.LoadConfigFile <DefaultsConfigSection>(DEFAULTS_CONFIG_FILE_NAME);

            var serviceProvider = new ServiceCollection()
                                  .AddScoped <IIndexer, ImportIndexer>()
                                  .AddScoped <IDbAdapter, SqliteAdapter>()
                                  .AddScoped <IRankedResults, RankedResults>()
                                  .AddScoped <ISearch, Search>()
                                  .AddScoped <IDisplayResults, TerminalDisplayResults>()
                                  .AddSingleton(ConfigurationsUtils.LoadConfigFile <DbConfigSection>(DB_CONFIG_FILE_NAME))
                                  .AddSingleton(defaultsConfig)
                                  .BuildServiceProvider();

            var app = new CommandLineApplication();

            app.Command("find", (command) =>
            {
                command.Description        = "search a file";
                var valuesOption           = command.Option("--v", "search for the exact value", CommandOptionType.SingleValue);
                var maxResultsOption       = command.Option("--m", "Max result count", CommandOptionType.SingleValue);
                var displayInTermialOption = command.Option("--t", "Dont open the result in file explorer, display in terminal", CommandOptionType.SingleValue);
                var explicitValueOption    = command.Option("--e", "Show only results with exact match", CommandOptionType.SingleValue);

                var t = command.Arguments;
                command.OnExecute(async() =>
                {
                    int resultsCount = defaultsConfig.DefaultResultCount;
                    if (maxResultsOption.HasValue())
                    {
                        if (maxResultsOption.Value() == "*")
                        {
                            resultsCount = -1;
                        }
                        else
                        {
                            resultsCount = int.Parse(maxResultsOption.Value());
                        }
                    }
                    var cmd = new Command
                    {
                        Type  = CommandType.Find,
                        Value = valuesOption.Value()
                    };

                    var findOptions = new FindOptions(explicitValueOption.Value(), resultsCount, displayInTermialOption.Value());

                    await Find(serviceProvider, cmd, findOptions);
                    return(0);
                });
            });

            app.Command("map", (command) =>
            {
                command.Description = "map a folder";
                var updateOption    = command.Option("--u", "update mapping info of a file", CommandOptionType.SingleValue);
                var newPathOption   = command.Option("--n", "map a new value to a folder or a file", CommandOptionType.SingleValue);
                var pathOption      = command.Option("--v", "map a file or folder and all of its sub folders", CommandOptionType.SingleValue);
                var mapAllOption    = command.Option("--a", "Map all the sub folders starting from the root path from the configuration", CommandOptionType.SingleValue);
                var overrideOption  = command.Option("--o", "override all mappings", CommandOptionType.SingleValue);
                var clearAllOption  = command.Option("--c", "clear all mappings", CommandOptionType.SingleValue);


                command.OnExecute(async() =>
                {
                    var dbAdapter = serviceProvider.GetService <IDbAdapter>();

                    if (clearAllOption.HasValue())
                    {
                        await dbAdapter.ClearMappings();
                    }
                    else if (!updateOption.HasValue())
                    {
                        string updatePath = pathOption.Value();
                        if (mapAllOption.HasValue() && bool.Parse(mapAllOption.Value()))
                        {
                            updatePath = serviceProvider.GetService <DefaultsConfigSection>().RootFolder;
                        }

                        bool overrideAll = overrideOption.HasValue() ? bool.Parse(overrideOption.Value()) : false;
                        System.Console.WriteLine($"mapping {updatePath}");

                        var toMap = new List <Index>();
                        if (File.GetAttributes(updatePath).HasFlag(FileAttributes.Directory))
                        {
                            IndexUtils.Map(toMap, updatePath);
                            System.Console.WriteLine(string.Join(",", toMap.Select(m => m.SearchKey)));
                            dbAdapter.SetIndexes(toMap, overrideAll);
                        }
                        else
                        {
                            toMap.Add(IndexUtils.CreateUpdateIndex(pathOption.Value().ToLower()));
                            dbAdapter.SetIndexes(toMap, overrideAll);
                        }
                        System.Console.WriteLine($"{toMap.Count} files mapped");
                    }
                    else
                    {
                        await dbAdapter.UpdateIndexes(IndexUtils.CreateUpdateIndex(pathOption.Value().ToLower(), newPathOption.Value().ToLower()));
                    }
                    return(0);
                });
            });

            return(app.Execute(args));
        }