public PointI MakeFirstLaunch()
        {
            MakeShift(PointI.Zero, PointI.CreateXZ(world.Size / 2, world.Size / 2).Add(world.Offset));
            manager.Start();
            while (manager.IsEmpty)
            {
            }

            var answer = manager.Pop();

            world[answer.Position] = answer;
            AddNotifyAll(answer);
            return(answer.Position);
        }
        public static void Main1(string[] args)
        {
            TextureInfo.Order = new[]
            {
                TextureSide.Left, TextureSide.Back, TextureSide.Right,
                TextureSide.Top, TextureSide.Front, TextureSide.Bottom
            };
            var threads = Environment.ProcessorCount;

            ThreadPool.SetMaxThreads(threads, threads);
            ThreadPool.SetMinThreads(threads, threads);
            var startOffset = PointI.CreateXZ(1, 1);
            var worldSize   = 15;
            var gg          = new WorldGenerator(
                new LandGenerator(UsageGenerators.CoreGenerator),
                new IGenerator <ChunkB, ChunkB>[]
            {
                new OreGenerator(UsageGenerators.OreCoreGenerator),
                new SimpleTreeSpawner(),
                new BedrockGenerator(UsageGenerators.BedrockCoreGenerator)
            }
                );
            //var gg=new WorldGenerator(new PerlinChunkGenerator(UsageGenerators.CoreGenerator), new SimpleTreeSpawner());
            //var manager = new WorldManager2(new PerlinChunkGenerator(UsageGenerators.CoreGenerator));
            //var gg = new FlatGenerator();
            var world   = new GameWorld(startOffset, worldSize);
            var manager = new WorldManager(world, gg);
            var game    = new Game(world, manager, new CowSpawner());


            var visualWorld   = new VisualWorld(startOffset, worldSize);
            var visualManager = new VisualManager(new Visualizer(game.World), visualWorld);

            manager.AddAlert    += visualManager.HandlerForAdd;
            manager.UpdateAlert += visualManager.HandlerForUpdate;

            Console.Beep();
            GC.Collect();
            GC.WaitForPendingFinalizers();
            var memory = GC.GetTotalMemory(true);

            Console.WriteLine("World size: " + memory / (1024 * 1024) + " Mb");
            Console.Beep();


            using var painter = new Window(game,
                                           visualManager);
            painter.Run(200, 200);
        }
Beispiel #3
0
        public IReadOnlyList <PointI> GetPointOfGaps()
        {
            var result = new List <PointI>();

            for (var i = 0; i < Size; i++)
            {
                for (var j = 0; j < Size; j++)
                {
                    var point = Offset.Add(PointI.CreateXZ(i, j));
                    if (!chunks.ContainsKey(point))
                    {
                        result.Add(point);
                    }
                }
            }

            return(result);
        }
        public Chunk <Block> Generate(Chunk <Block> source)
        {
            var rnd    = new Random();
            var chance = rnd.Next(3);

            if (chance != 0)
            {
                return(source);
            }
            var treePosition = PointI.CreateXZ(rnd.Next(2, 13), rnd.Next(2, 13)).AsPointB();
            var treeRoot     = PointI.Zero;

            for (byte y = 255 - 7; y > 0; y--)
            {
                var point = treePosition.Add(new PointB(0, y, 0));
                if (source[point] != null)
                {
                    treeRoot = point.Add(new PointB(0, 1, 0)).AsPointI();
                    break;
                }
            }

            if (treeRoot.Equals(PointI.Zero))
            {
                return(source);
            }

            treeRoot = treeRoot.Add(WorldStructures.Tree.ShiftToCenter);
            foreach (var coord in WorldStructures.Tree.TrunkCoordinates)
            {
                var point = treeRoot.Add(coord).AsPointB();
                source[point] ??= new Block(WorldStructures.Tree.TrunkMaterial, point);
            }

            foreach (var coord in WorldStructures.Tree.TreeCrownCoordinates)
            {
                var point = treeRoot.Add(coord).AsPointB();
                source[point] ??= new Block(WorldStructures.Tree.CrownMaterial, point);
            }

            return(source);
        }
        public override void Load()
        {
            Bind <int>().ToConstant(10);
            Bind <PointI>().ToConstant(PointI.CreateXZ(1, 1));
            Bind <BlockWorld>().To <GameWorld>().InSingletonScope();

            Bind <LandGenerator>().ToSelf()
            .WithConstructorArgument((typeof(IGenerator <PointF, float>)), UsageGenerators.CoreGenerator);
            Bind <IGenerator <ChunkB, ChunkB> >().To <OreGenerator>()
            .WithConstructorArgument((typeof(IGenerator <PointF, float>)), UsageGenerators.OreCoreGenerator);
            Bind <IGenerator <ChunkB, ChunkB> >().To <SimpleTreeSpawner>();
            Bind <IGenerator <ChunkB, ChunkB> >().To <BedrockGenerator>()
            .WithConstructorArgument((typeof(IGenerator <PointF, float>)), UsageGenerators.BedrockCoreGenerator);
            Bind <IGenerator <PointI, ChunkB> >().To <WorldGenerator>()
            .WhenInjectedInto <IWorldManager>()
            .WithConstructorArgument(typeof(IGenerator <PointI, ChunkB>),
                                     c => c.Kernel.Get <LandGenerator>());

            Bind <IWorldManager>().To <WorldManager>().InSingletonScope()
            .WithConstructorArgument(c => c.Kernel.Get <World <ChunkB, Block> >());
            Bind <IGenerator <ChunkB, List <PointB> > >().To <CowSpawner>();
            Bind <Game>().ToSelf().InSingletonScope();
        }