示例#1
0
 public EnemyArrayTable(int enemies, int groups)
 {
     this.enemylist = new ByteStack(enemies);
     this.grouplist = new ByteStack(groups);
     for (byte i = 0; i < enemies; i++)
     {
         enemylist.push(i);
     }
     for (byte i = 0; i < groups; i++)
     {
         grouplist.push(i);
     }
 }
示例#2
0
        public static void TestStackable <T>(int count = 1)
            where T : IStackable, new()
        {
            var byteStack = new ByteStack();

            for (int i = 0; i < count; i++)
            {
                byteStack.Add(new T());
            }
            var stack = byteStack.Stack();

            Assert.AreEqual(ByteStack.Unstack(stack).Stackables[0].GetType(), typeof(T));
            Console.WriteLine();
            Assert.Pass();
        }
示例#3
0
        //public static NbtDocument ParseValue(ref NbtReader reader)
        //{
        //
        //}
        //
        //public static bool TryParseValue(ref NbtReader reader, out NbtDocument document)
        //{
        //}

        private static void Parse(
            ref NbtReader reader,
            ref MetadataDb database,
            ref ByteStack <ContainerFrame> stack)
        {
            int rowCount = 0;

            while (reader.Read())
            {
                int      location = reader.TagLocation;
                NbtType  type     = reader.TagType;
                NbtFlags flags    = reader.TagFlags;

PeekStack:
                ref ContainerFrame frame = ref stack.TryPeek();
                if (!Unsafe.IsNullRef(ref frame))
                {
                    if (frame.ListEntriesRemaining == 0)
                    {
                        stack.TryPop();

                        int totalRowCount = rowCount - frame.InitialRowCount;
                        database.SetRowCount(frame.ContainerRow, totalRowCount);
                        goto PeekStack;
                    }
                    else if (frame.ListEntriesRemaining != -1)
                    {
                        frame.ListEntriesRemaining--;
                    }
                    else
                    {
                        frame.CompoundEntryCounter++;
                    }
                }

                switch (type)
                {
                case NbtType.End:
                {
                    // Documents with a single End tag (no Compound root) are valid.
                    if (stack.TryPop(out var compoundFrame))
                    {
                        int totalRowCount  = rowCount - compoundFrame.InitialRowCount;
                        int compoundLength = compoundFrame.CompoundEntryCounter - 1;     // -1 to exclude End

                        database.SetRowCount(compoundFrame.ContainerRow, totalRowCount);
                        database.SetLength(compoundFrame.ContainerRow, compoundLength);
                    }
                    continue;     // Continue to not increment row count
                }

                case NbtType.Compound:
                {
                    int containerRow = database.Append(
                        location, collectionLength: 0, rowCount: 1, type, flags);

                    stack.Push(new ContainerFrame(containerRow, rowCount)
                        {
                            ListEntriesRemaining = -1
                        });
                    break;
                }

                case NbtType.List:
                {
                    int listLength   = reader.TagCollectionLength;
                    int containerRow = database.Append(
                        location, listLength, rowCount: 1, type, flags);

                    stack.Push(new ContainerFrame(containerRow, rowCount)
                        {
                            ListEntriesRemaining = listLength
                        });
                    break;
                }

                default:
                    database.Append(location, reader.TagCollectionLength, rowCount: 1, type, flags);
                    break;
                }

                rowCount++;
            }

            database.TrimExcess();
        }
示例#4
0
        public NbtReaderState(ByteStack <ContainerFrame> stack, NbtOptions?options = null) : this()
        {
            Options = options ?? NbtOptions.JavaDefault;

            _containerInfoStack = stack;
        }
        public NbtReaderState(NbtOptions?options = null) : this()
        {
            Options = options ?? NbtOptions.JavaDefault;

            _containerInfoStack = new ByteStack <ContainerFrame>(NbtOptions.DefaultMaxDepth, clearOnReturn: false);
        }
示例#6
0
        public static void RunAutomated()
        {
            Console.Title = "Dreary Program test";
            Console.WriteLine("Stack trace\n" + Environment.StackTrace);
            Console.WriteLine("DREARY PROGTEST");

            try
            {
                ByteStack stack = new ByteStack(16);
                stack.Push((byte)0xff);
                PrintByteArray(stack.DumpStack());
                Console.WriteLine(stack.PopByte() + " should be " + 0xff);
                stack.Push((ushort)0xffff);
                PrintByteArray(stack.DumpStack());
                ushort outputs = 0; stack.PopShort(ref outputs);
                Console.WriteLine(outputs + " should be " + 0xffff);
                stack.Push(0xffffffff);
                PrintByteArray(stack.DumpStack());
                int outputi = 0; stack.PopInt(ref outputi);
                Console.WriteLine(outputi + " should be " + 0xffffffff);
            }
            catch (Exception e)
            {
                Console.WriteLine("test failed: " + e);
                Environment.Exit(1);
            }

            Console.Write(Directory.GetCurrentDirectory() + "\\");
            string audiotoplay = "GameSounds/rwd.mp3";

            Console.WriteLine("Playing " + audiotoplay);
            try
            {
                AudioSystem.PlayAudio(audiotoplay);
            }
            catch (Exception e)
            {
                Console.WriteLine("Error playing sound: " + e);
                Environment.Exit(2);
            }

            Console.WriteLine("Testing form");
            try
            {
                Form1 form = new Form1();
                form.Show();
                Console.WriteLine("Sleeping for 5s");
                Thread.Sleep(5000);
                form.Close();
                form.Dispose();
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                Environment.Exit(3);
            }
            Console.WriteLine("Test done");

            Console.WriteLine("TEST DONE");
            Environment.Exit(0);
        }
示例#7
0
        public static void Run()
        {
            Console.Title = "Dreary Program test";
            Console.WriteLine("Stack trace\n" + Environment.StackTrace);
            Console.WriteLine("DREARY PROGTEST");
            Console.WriteLine("Select mode");
            Console.WriteLine("1 test stack, 2 continue program, 3 net test, 4 audio test, 5 form test, 6 auto test, 0 exit dreary");

            bool continueprog = false;
            bool testing      = true;

            while (testing)
            {
                Console.Write('.');
                switch (Console.ReadLine())
                {
                case "0":
                    testing = false;
                    break;

                case "1":
                    try
                    {
                        ByteStack stack = new ByteStack(16);
                        stack.Push((byte)0xff);
                        PrintByteArray(stack.DumpStack());
                        Console.WriteLine(stack.PopByte() + " should be " + 0xff);
                        stack.Push((ushort)0xffff);
                        PrintByteArray(stack.DumpStack());
                        ushort outputs = 0; stack.PopShort(ref outputs);
                        Console.WriteLine(outputs + " should be " + 0xffff);
                        stack.Push(0xffffffff);
                        PrintByteArray(stack.DumpStack());
                        int outputi = 0; stack.PopInt(ref outputi);
                        Console.WriteLine(outputi + " should be " + 0xffffffff);
                    } catch (Exception e)
                    {
                        Console.WriteLine("test failed: " + e);
                    }
                    break;

                case "2":
                    continueprog = true;
                    testing      = false;
                    break;

                case "3":
                    try
                    {
                        Console.WriteLine("Starting server");
                        Task serverformthread = new Task(() =>
                        {
                            try
                            {
                                Form1 serverform = new Form1();
                                serverform.Show();
                                serverform.server = new Net.Server(21212, serverform);
                                serverform.server.Start();
                            } catch (Exception e)
                            {
                                Console.WriteLine("Server failed " + e);
                            }
                        });
                        Console.WriteLine("Starting client");
                        Task clientformthread = new Task(() => {
                            try
                            {
                                Form1 clientform = new Form1();
                                clientform.Show();
                                clientform.client = new Net.Client(clientform);
                                clientform.client.Connect("127.0.0.1", 21212);
                            } catch (Exception e)
                            {
                                Console.WriteLine("Client failed " + e);
                            }
                        });
                        serverformthread.Start();
                        clientformthread.Start();
                    } catch (Exception e)
                    {
                        Console.WriteLine("test failed: " + e);
                    }
                    break;

                case "4":
                    Console.Write(Directory.GetCurrentDirectory() + "\\");
                    string audiotoplay = Console.ReadLine();
                    Console.WriteLine("Playing " + audiotoplay);
                    try
                    {
                        AudioSystem.PlayAudio(audiotoplay);
                    } catch (Exception e)
                    {
                        Console.WriteLine("Error playing sound: " + e);
                    }
                    break;

                case "5":
                    Console.WriteLine("Testing form");
                    try
                    {
                        Form1 form = new Form1();
                        form.Show();
                        Console.WriteLine("Sleeping for 5s");
                        Thread.Sleep(5000);
                        form.Close();
                        form.Dispose();
                    } catch (Exception e)
                    {
                        Console.WriteLine(e);
                    }
                    Console.WriteLine("Test done");
                    break;

                case "6":
                    Console.WriteLine("Autotesting (will exit upon finish)");
                    try
                    {
                        RunAutomated();
                    } catch (Exception e)
                    {
                        Console.WriteLine(e);
                    }
                    break;

                default:
                    Console.WriteLine("?");
                    break;
                }
            }
            Console.WriteLine("TEST DONE");
            if (!continueprog)
            {
                Environment.Exit(0);
            }
        }