Ejemplo n.º 1
0
 static void AsyncWritting()
 {
     stopwatch.Restart();
     while (requests.Count > 0)
     {
         Write((RenderRequest)requests.Dequeue());
     }
     AgeTimedTextRequests((int)stopwatch.ElapsedMilliseconds);
     Thread.Sleep(Arit.Clamp(asyncFrameLenght - (int)stopwatch.ElapsedMilliseconds, 0, asyncFrameLenght));
 }
Ejemplo n.º 2
0
        static void AsyncWrittingDebug()
        {
            int sleepTime, elapsedTime, queleLen = 0, charCount = 0;

            stopwatch.Restart();
            RenderRequest tRequest;

            while (requests.Count > 0)
            {
                queleLen++;
                tRequest = (RenderRequest)requests.Dequeue();
                {
                    charCount += tRequest.Text.Length;
                    Write(tRequest);

                    tRequest = null;
                }
            }
            requests.Clear();
            stopwatch.Stop();
            elapsedTime = (int)stopwatch.ElapsedMilliseconds;
            sleepTime   = asyncFrameLenght - elapsedTime - Arit.Clamp(lastSleepTime, int.MinValue, 0);

            if (queleLen > 0)
            {
                string debugString = "";
                debugString += $"Frame len: {$"{asyncFrameLenght}".PadLeft(5)}, ";
                debugString += $"Elapsed: {$"{elapsedTime}".PadLeft(5)}, ";
                debugString += $"Sleep: {$"{sleepTime}".PadLeft(5)}, ";
                debugString += $"Queue len: {$"{queleLen}".PadLeft(5)}, ";
                debugString += $"Chars: {$"{charCount}".PadLeft(8)}, ";
                debugString += $"Requests: {$"{requestCount}".PadLeft(8)}, ";
                debugString += $"Hist ID: {$"{requestPointer}".PadLeft(4)}, ";
                debugString += $"Dropped: {$"{droppedRequests}".PadLeft(2)}";

                AsyncWrite(debugString.PadRight(windowSize.x).Pastel(Color.DarkBlue).PastelBg(Color.LightGray), 0, 0);
            }
            AsyncWrite($"Frame: {$"{frame}".PadLeft(8)}".Pastel(Color.DarkViolet).PastelBg(Color.LightGray), windowSize.x - 16, 0);
            lastSleepTime = sleepTime;
            AgeTimedTextRequests(elapsedTime + sleepTime);

            Thread.Sleep(Arit.Clamp(sleepTime, 0, asyncFrameLenght));
        }
Ejemplo n.º 3
0
        public static bool SetupGame(MenuEvent e)
        {
            e.Menu.Erase();
            GameSetup GS = new GameSetup();

            Menu gameMenu = new Menu(new Int2(1, 1), new Int2(32, 45), "Game Setup", Boxes.BoxType.doubled)
            {
                VerticalTextWrapping = Menu.Wrapping.wrapping
            };

            gameMenu.AddControll(new LineSeparatorControll("sep0", "sep0"));
            gameMenu.AddControll(new LabelControll("- Game options -", "game_label"));
            gameMenu.AddControll(new IntSwitcherControll("Turn timer", "timer")
            {
                Max            = 600,
                Min            = 0,
                Step           = 1,
                Value          = 0,
                MinSpecialText = "∞",
                FastStepTime   = 200
            });
            gameMenu.AddControll(new IntSwitcherControll("Total lenght limit", "len_lim")
            {
                Max            = 1152,
                Min            = 0,
                Step           = 1,
                Value          = 0,
                MinSpecialText = "∞",
                FastStepTime   = 200
            });
            gameMenu.AddControll(new IntSwitcherControll("Collision distance", "col_dist")
            {
                Value        = 1,
                Min          = 0,
                Max          = 32,
                Step         = 1,
                FastStepTime = 200
            }, CollisionDistanceChanges);
            gameMenu.AddControll(new CheckBoxControll("Corner collisions", "cor_coll", true)
            {
                TrueValue  = "■",
                FalseValue = " "
            }, CollisionChanges);

            gameMenu.AddControll(new LineSeparatorControll("sep1", "sep1"));
            gameMenu.AddControll(new LabelControll("- Board -", "board_label"));

            gameMenu.AddControll(new IntSwitcherControll("Board width", "width", 10, 4, 50, 1), MapSwitcherChanged);
            gameMenu.AddControll(new IntSwitcherControll("Board height", "height", 10, 4, 40, 1), MapSwitcherChanged);

            gameMenu.AddControll(new LineSeparatorControll("sep2", "sep2"));
            gameMenu.AddControll(new LabelControll("- Ships -", "ships_label"));

            for (int i = 0; i < 8; i++)
            {
                gameMenu.AddControll(new IntSwitcherControll($"Lenght {i+1}", $"{i+1}len", Arit.Clamp(4 - i, 0, 8), 0, 32, 1), ShipCountChanged);
                ships[i]        = Arit.Clamp(4 - i, 0, 8);
                shipsOnBoard[i] = 0;
            }

            gameMenu.AddControll(new LineSeparatorControll("sep3", "sep3"));
            gameMenu.AddControll(new MenuControll("◊ START THE GAME ◊", "start"), ShipSetup);

            gameMenu.AddControll(new LineSeparatorControll("sep4", "sep4"));
            gameMenu.AddControll(new MenuControll("Go back", "exit"), gameMenu.Exit);

            gameMenu.AddControll(new LineSeparatorControll("sep_fin", "sep_fin"));

            prepareMap = new Map(new Int2(10, 10), new Int2(34, 1));
            prepareMap.Draw();

            DrawShips();
            gameMenu.WaitForInput();

            EraseShips();
            prepareMap.Erase();
            e.Menu.Draw();
            return(true);
        }