Exemplo n.º 1
0
        public void CenterPosition()
        {
            var tc = new TestCore();

            tc.Init();

            var texture = Texture2D.Load(@"TestData/IO/AltseedPink.png");

            Assert.NotNull(texture);

            var node = new SpriteNode();

            node.Texture        = texture;
            node.CenterPosition = texture.Size / 2;
            node.Position       = Engine.WindowSize / 2;
            Engine.AddNode(node);

            var child = new SpriteNode();

            child.Texture        = texture;
            child.CenterPosition = texture.Size / 2;
            //child.Position = texture.Size / 2;
            node.AddChildNode(child);

            var child2 = new SpriteNode();

            child2.Texture        = texture;
            child2.CenterPosition = texture.Size / 2;
            child2.Position       = texture.Size / 2;
            node.AddChildNode(child2);

            tc.LoopBody(c =>
            {
                node.Angle   += 1.0f;
                child.Angle  += 1.0f;
                child2.Angle += 1.0f;
            }
                        , null);

            tc.End();
        }
Exemplo n.º 2
0
        public void TreeAdd()
        {
            var tc = new TestCore();

            tc.Init();

            var t1 = Texture2D.Load(@"TestData/IO/AltseedPink.png");

            Assert.NotNull(t1);

            var s = new SpriteNode();

            s.Src      = new RectF(new Vector2F(100, 100), new Vector2F(100, 100));
            s.Texture  = t1;
            s.Position = new Vector2F(100, 100);

            var s2 = new SpriteNode();

            s2.Src      = new RectF(new Vector2F(200, 200), new Vector2F(100, 100));
            s2.Texture  = t1;
            s2.Position = new Vector2F(200, 200);

            var s3 = new SpriteNode();

            s3.Src      = new RectF(new Vector2F(200, 200), new Vector2F(100, 100));
            s3.Texture  = t1;
            s3.Position = new Vector2F(200, 200);

            s.AddChildNode(s2);
            s2.AddChildNode(s3);

            tc.LoopBody(c =>
            {
                if (c == 100)
                {
                    Engine.AddNode(s);
                }
            }, null);

            tc.End();
        }
Exemplo n.º 3
0
        public void StaticFileCache()
        {
            var tc = new TestCore();

            tc.Init();

            var path = System.IO.Path.GetFullPath("TestData/IO/AltseedPink.png");

            Assert.True(Engine.File.Exists(path));
            StaticFile test = null;

            Assert.AreNotEqual(test = StaticFile.Create(path), null);

            StaticFile test3 = null;

            Assert.AreNotEqual(test3 = StaticFile.Create(path), null);

            Engine.Log.Info(LogCategory.Engine, $"{test.selfPtr}/{test3.selfPtr}");
            Engine.Log.Info(LogCategory.Engine, Engine.Resources.GetResourcesCount(ResourceType.StaticFile).ToString());
            tc.End();
        }
Exemplo n.º 4
0
        public void Basic()
        {
            var tc = new TestCore();

            tc.Init();

            Engine.Profiler.StartCapture();

            {
                using var block1 = new ProfilerBlock("Block1", new Color(255, 0, 0));
                System.Threading.Thread.Sleep(500);
                {
                    using var block2 = new ProfilerBlock("Block2", new Color(0, 255, 0));
                    System.Threading.Thread.Sleep(500);
                }
            }

            Engine.Profiler.DumpToFileAndStopCapture("Profiler.prof");

            tc.End();
        }
Exemplo n.º 5
0
        public void Play()
        {
            var tc = new TestCore();

            tc.Init();

            var bgm = Altseed2.Sound.Load(@"TestData/Sound/bgm1.ogg", false);
            var se  = Altseed2.Sound.Load(@"TestData/Sound/se1.wav", true);

            Assert.NotNull(bgm);
            Assert.NotNull(se);

            var bgm_id = Engine.Sound.Play(bgm);
            var se_id  = Engine.Sound.Play(se);

            tc.LoopBody(null, null);

            Engine.Sound.StopAll();

            tc.End();
        }
Exemplo n.º 6
0
        public void Loop()
        {
            var tc = new TestCore();

            tc.Init();

            var bgm = Altseed2.Sound.Load(@"TestData/Sound/bgm1.ogg", false);

            Assert.NotNull(bgm);

            bgm.IsLoopingMode     = true;
            bgm.LoopStartingPoint = 1f;
            bgm.LoopEndPoint      = 2.5f;

            var bgm_id = Engine.Sound.Play(bgm);

            tc.LoopBody(null, null);

            Engine.Sound.StopAll();

            tc.End();
        }
Exemplo n.º 7
0
        public void EnuemrateAncestors()
        {
            var tc = new TestCore();

            tc.Init();

            var t1 = Texture2D.Load(@"TestData/IO/AltseedPink.png");

            Assert.NotNull(t1);

            var s = new SpriteNode();

            s.Src      = new RectF(new Vector2F(100, 100), new Vector2F(100, 100));
            s.Texture  = t1;
            s.Position = new Vector2F(100, 100);

            var s2 = new SpriteNode();

            s2.Src      = new RectF(new Vector2F(200, 200), new Vector2F(100, 100));
            s2.Texture  = t1;
            s2.Position = new Vector2F(200, 0);

            s.AddChildNode(s2);

            Engine.AddNode(s);

            tc.LoopBody(c =>
            {
                if (c == 2)
                {
                    var e = s2.EnumerateAncestors().ToArray();
                    Assert.AreEqual(1, e.Length);
                    Assert.AreSame(e[0], s);
                }
                s.Angle++;
            }, null);

            tc.End();
        }
Exemplo n.º 8
0
        public void PauseAndResume()
        {
            var tc = new TestCore();

            tc.Init();

            var texture = Texture2D.Load(@"TestData/IO/AltseedPink.png");

            Assert.NotNull(texture);

            var node = new RotateSpriteNode();

            node.Texture        = texture;
            node.CenterPosition = texture.Size / 2;
            node.Position       = new Vector2F(200, 200);
            Engine.AddNode(node);

            var node2 = new RotateSpriteNode();

            node2.Texture        = texture;
            node2.CenterPosition = texture.Size / 2;
            node2.Position       = new Vector2F(600, 200);
            Engine.AddNode(node2);

            tc.LoopBody(c =>
            {
                if (c == 50)
                {
                    Engine.Pause(node);
                }
                if (c == 150)
                {
                    Engine.Resume();
                }
            }
                        , null);

            tc.End();
        }
Exemplo n.º 9
0
        public void RemovingNodeCauseCrash()
        {
            var tc = new TestCore(new Configuration()
            {
                WaitVSync = false
            });

            tc.Init();
            Engine.TargetFPS = 10000;
            SpriteNode node = null;

#if !CI
            tc.Duration = 100000;
#endif
            tc.LoopBody(c =>
            {
                if (node != null)
                {
                    Engine.RemoveNode(node);
                }

                node                = new SpriteNode();
                node.Texture        = Texture2D.Load(@"TestData/IO/AltseedPink.png");
                node.CenterPosition = node.Texture.Size / 2;
                node.Position       = new Vector2F(200, 200);
                Engine.AddNode(node);

                if (c % 100 == 0)
                {
                    GC.Collect();
                    GC.WaitForFullGCComplete();
                }
            }
                        , null);

            tc.End();
        }
Exemplo n.º 10
0
        public void RectangleNode()
        {
            var tc = new TestCore(new Configuration());

            tc.Init();

            var rectangle1 = new RectangleNode()
            {
                Color          = new Color(255, 0, 0),
                Position       = new Vector2F(100f, 100f),
                CenterPosition = new Vector2F(25f, 25f),
                RectangleSize  = new Vector2F(50f, 50f),
            };
            var rectangle2 = new RectangleNode()
            {
                Color         = new Color(0, 255, 0),
                Position      = new Vector2F(400f, 200f),
                RectangleSize = new Vector2F(200f, 100f),
            };
            var rectangle3 = new RectangleNode()
            {
                Color         = new Color(0, 0, 255),
                Position      = new Vector2F(200f, 300f),
                RectangleSize = new Vector2F(100f, 150f),
            };

            Engine.AddNode(rectangle1);
            Engine.AddNode(rectangle2);
            Engine.AddNode(rectangle3);

            tc.LoopBody((c) =>
            {
                rectangle1.RectangleSize += new Vector2F(1, 1);
            }, null);

            tc.End();
        }
Exemplo n.º 11
0
        public void Shader()
        {
            var tc = new TestCore();

            tc.Init();

            var shader1 = Altseed2.Shader.Create("ShaderTest", Engine.Graphics.BuiltinShader.DownsampleShader, ShaderStage.Pixel);

            Assert.NotNull(shader1);

            const string path = "Serialization/Shader.bin";

            Serialize(path, shader1);

            var shader2 = Deserialize <Shader>(path);

            Assert.NotNull(shader2);

            Assert.AreEqual(shader1.Code, shader2.Code);
            Assert.AreEqual(shader1.Name, shader2.Name);
            Assert.AreEqual(shader1.StageType, shader2.StageType);

            tc.End();
        }
Exemplo n.º 12
0
        public void LineNode()
        {
            var tc = new TestCore(new Configuration());

            tc.Init();

            var line1 = new LineNode()
            {
                Color     = new Color(255, 0, 0),
                Point1    = new Vector2F(100f, 100f),
                Point2    = new Vector2F(200f, 200f),
                Thickness = 10f,
            };
            var line2 = new LineNode()
            {
                Color     = new Color(0, 255, 0),
                Point1    = new Vector2F(50f, 450f),
                Point2    = new Vector2F(600f, 50f),
                Thickness = 5.0f,
            };
            var line3 = new LineNode()
            {
                Color     = new Color(0, 0, 255),
                Point1    = new Vector2F(100f, 150f),
                Point2    = new Vector2F(100f, 350f),
                Thickness = 15.0f,
            };

            Engine.AddNode(line1);
            Engine.AddNode(line2);
            Engine.AddNode(line3);

            tc.LoopBody(null, null);

            tc.End();
        }
Exemplo n.º 13
0
        public void TriangleNode()
        {
            var tc = new TestCore(new Configuration());

            tc.Init();

            var triangle = new TriangleNode()
            {
                Color    = new Color(255, 0, 0),
                Point1   = new Vector2F(100f, 100f),
                Point2   = new Vector2F(200f, 200f),
                Point3   = new Vector2F(100f, 200f),
                Position = new Vector2F(100, 100),
            };

            Engine.AddNode(triangle);

            tc.LoopBody((c) =>
            {
                triangle.Point2 += new Vector2F(1, 1);
            }, null);

            tc.End();
        }
Exemplo n.º 14
0
        public void CircleNode()
        {
            var tc = new TestCore(new Configuration());

            tc.Init();

            var circle1 = new CircleNode()
            {
                Color    = new Color(255, 0, 0),
                Position = new Vector2F(100, 100),
                Radius   = 50f,
                VertNum  = 30,
            };
            var circle2 = new CircleNode()
            {
                Color    = new Color(0, 255, 0),
                Position = new Vector2F(400, 200),
                Radius   = 30f,
                VertNum  = 8,
            };
            var circle3 = new CircleNode()
            {
                Color    = new Color(0, 0, 255),
                Position = new Vector2F(50, 400),
                Radius   = 40f,
                VertNum  = 5,
            };

            Engine.AddNode(circle1);
            Engine.AddNode(circle2);
            Engine.AddNode(circle3);

            tc.LoopBody(null, null);

            tc.End();
        }
Exemplo n.º 15
0
        public void LoadTexture()
        {
            if (System.IO.Directory.Exists("tmp"))
            {
                System.IO.Directory.Delete("tmp", true);
            }

            System.IO.Directory.CreateDirectory("tmp");
            foreach (var i in Enumerable.Range(0, 100))
            {
                System.IO.File.Copy("TestData/IO/AltseedPink.png", "tmp/test" + i + ".png");
            }
            var tc = new TestCore();

            tc.Init();

            var font = Font.LoadDynamicFont("TestData/Font/mplus-1m-regular.ttf", 64);

            Assert.NotNull(font);

            var node = new TextNode()
            {
                Font = font, FontSize = 80, Text = "", CameraGroup = 1 << 0
            };

            Engine.AddNode(node);

            var camera = new CameraNode();

            camera.Group = 0;
            Engine.AddNode(camera);

            var tasks = new List <Task <Texture2D> >();

            foreach (var i in Enumerable.Range(0, 100))
            {
                tasks.Add(Texture2D.LoadAsync("tmp/test" + i + ".png"));
            }

            while (Engine.DoEvents())
            {
                node.Text = $"Loading Texture: {tasks.Count(obj => obj.IsCompleted)}/{tasks.Count()}";
                Assert.True(Engine.Update());

                if (tasks.All(obj => obj.IsCompleted))
                {
                    break;
                }
            }

            foreach (var i in Enumerable.Range(0, 100))
            {
                Assert.AreNotEqual(tasks[0].Result, null);
            }

            int count = 0;

            var sprite = new SpriteNode();

            sprite.Position       = new Vector2F(300, 300);
            sprite.Texture        = tasks[0].Result;
            sprite.Src            = new RectF(new Vector2F(), tasks[0].Result.Size);
            sprite.CenterPosition = sprite.Texture.Size / 2;
            sprite.CameraGroup    = 1 << 0;
            Engine.AddNode(sprite);

            while (Engine.DoEvents() && count < 100)
            {
                node.Text      = $"Shown Texture: {count}/{tasks.Count()}";
                sprite.Texture = tasks[count].Result;
                Assert.True(Engine.Update());
                count++;
            }

            tc.End();
        }
Exemplo n.º 16
0
        public void CreateStaticFile()
        {
            if (System.IO.Directory.Exists("tmp"))
            {
                System.IO.Directory.Delete("tmp", true);
            }

            System.IO.Directory.CreateDirectory("tmp");
            foreach (var i in Enumerable.Range(0, 1000))
            {
                System.IO.File.Copy("TestData/IO/test.txt", "tmp/test" + i + ".txt");
            }
            var tc = new TestCore();

            tc.Init();

            var font = Font.LoadDynamicFont("TestData/Font/mplus-1m-regular.ttf", 64);

            Assert.NotNull(font);

            var node = new TextNode()
            {
                Font = font, FontSize = 80, Text = ""
            };

            Engine.AddNode(node);

            // TODO : improve performance
            int  itemnum = 100;
            bool dogc    = true;

            var tasks = new List <Task <StaticFile> >();

            foreach (var i in Enumerable.Range(0, itemnum))
            {
                if (i % 10 == 0 && dogc)
                {
                    Thread.Sleep(10);
                    Assert.True(Engine.Update());
                }

                tasks.Add(StaticFile.CreateAsync("tmp/test" + i + ".txt"));
            }

            while (Engine.DoEvents())
            {
                node.Text = $"Static File: {tasks.Count(obj => obj.IsCompleted)}/{tasks.Count()}";
                Assert.True(Engine.Update());

                if (tasks.All(obj => obj.IsCompleted))
                {
                    break;
                }
            }

            foreach (var i in Enumerable.Range(0, itemnum))
            {
                Assert.AreEqual(tasks[0].Result.Size, tasks[i].Result.Size);
            }

            tc.End();
        }
Exemplo n.º 17
0
        public void AcnhorAndShapeNode()
        {
            var tc = new TestCore(new Configuration()
            {
                VisibleTransformInfo = true
            });

            tc.Init();

            var font = Font.LoadDynamicFont("TestData/Font/mplus-1m-regular.ttf", 64);

            Assert.NotNull(font);

            var texture = Texture2D.Load(@"TestData/IO/AltseedPink.png");

            Assert.NotNull(texture);

            var sprite = new SpriteNode();

            sprite.Texture = texture;
            sprite.ZOrder  = 5;

            Vector2F rectSize = texture.Size;
            var      parent   = new AnchorTransformerNode();

            parent.Position   = Engine.WindowSize / 2;
            parent.Size       = rectSize;
            parent.AnchorMode = AnchorMode.Fill;
            Engine.AddNode(sprite);
            sprite.AddChildNode(parent);

            var circle2 = new CircleNode()
            {
                Color    = new Color(0, 255, 0),
                Position = new Vector2F(400, 200),
                Radius   = 100f,
                VertNum  = 80,
                ZOrder   = 10,
            };

            var circle2Anchor = new AnchorTransformerNode();

            circle2Anchor.AnchorMin  = new Vector2F(0.0f, 0.0f);
            circle2Anchor.AnchorMax  = new Vector2F(0.5f, 1f);
            circle2Anchor.AnchorMode = AnchorMode.Fill;
            sprite.AddChildNode(circle2);
            circle2.AddChildNode(circle2Anchor);

            var circle3 = new CircleNode()
            {
                Color    = new Color(0, 0, 255),
                Position = new Vector2F(50, 400),
                Radius   = 100f,
                VertNum  = 50,
                ZOrder   = 15,
            };

            var circle3Anchor = new AnchorTransformerNode();

            circle3Anchor.AnchorMin  = new Vector2F(0.5f, 0.5f);
            circle3Anchor.AnchorMax  = new Vector2F(1f, 1f);
            circle3Anchor.AnchorMode = AnchorMode.Fill;
            circle2.AddChildNode(circle3);
            circle3.AddChildNode(circle3Anchor);

            var text2 = new TextNode()
            {
                Font     = font,
                FontSize = 20,
                Text     = "",
                ZOrder   = 10,
                Scale    = new Vector2F(0.8f, 0.8f),
                Color    = new Color(255, 128, 0)
            };

            Engine.AddNode(text2);

            tc.Duration = 10000;

            string infoText(AnchorTransformerNode n) =>
            $"Scale:{n.Scale}\n" +
            $"Position:{n.Position}\n" +
            $"Pivot:{n.Pivot}\n" +
            $"Size:{n.Size}\n" +
            $"Margin: LT:{n.LeftTop} RB:{n.RightBottom}\n" +
            $"Anchor: {n.AnchorMin} {n.AnchorMax}\n";

            tc.LoopBody(c =>
            {
                circle2Anchor.RightBottom = new Vector2F();
                circle3Anchor.RightBottom = new Vector2F();

                if (Engine.Keyboard.GetKeyState(Key.Right) == ButtonState.Hold)
                {
                    rectSize.X += 1.5f;
                }
                if (Engine.Keyboard.GetKeyState(Key.Left) == ButtonState.Hold)
                {
                    rectSize.X -= 1.5f;
                }
                if (Engine.Keyboard.GetKeyState(Key.Down) == ButtonState.Hold)
                {
                    rectSize.Y += 1.5f;
                }
                if (Engine.Keyboard.GetKeyState(Key.Up) == ButtonState.Hold)
                {
                    rectSize.Y -= 1.5f;
                }

                if (Engine.Keyboard.GetKeyState(Key.D) == ButtonState.Hold)
                {
                    parent.Position += new Vector2F(1.5f, 0);
                }
                if (Engine.Keyboard.GetKeyState(Key.A) == ButtonState.Hold)
                {
                    parent.Position += new Vector2F(-1.5f, 0);
                }
                if (Engine.Keyboard.GetKeyState(Key.S) == ButtonState.Hold)
                {
                    parent.Position += new Vector2F(0, 1.5f);
                }
                if (Engine.Keyboard.GetKeyState(Key.W) == ButtonState.Hold)
                {
                    parent.Position += new Vector2F(0, -1.5f);
                }

                if (Engine.Keyboard.GetKeyState(Key.Q) == ButtonState.Hold)
                {
                    circle2Anchor.Angle += 1.5f;
                }
                if (Engine.Keyboard.GetKeyState(Key.E) == ButtonState.Hold)
                {
                    circle2Anchor.Angle -= 1.5f;
                }

                if (Engine.Keyboard.GetKeyState(Key.Z) == ButtonState.Hold)
                {
                    parent.Scale += new Vector2F(0.1f, 0);
                }
                if (Engine.Keyboard.GetKeyState(Key.C) == ButtonState.Hold)
                {
                    parent.Scale -= new Vector2F(0.1f, 0);
                }

                parent.Size = rectSize;

                text2.Text = infoText(parent) + '\n' + infoText(circle2Anchor) + '\n' + infoText(circle3Anchor);
            }, null);

            tc.End();
        }
Exemplo n.º 18
0
        public void DrawText()
        {
            var tc = new TestCore();

            tc.Init();

            var font  = Font.LoadDynamicFont("TestData/Font/mplus-1m-regular.ttf", 100);
            var font2 = Font.LoadDynamicFont("TestData/Font/GenYoMinJP-Bold.ttf", 100);

            Assert.NotNull(font);
            Assert.NotNull(font2);
            var imageFont = Font.CreateImageFont(font);

            imageFont.AddImageGlyph('〇', Texture2D.Load(@"TestData/IO/AltseedPink.png"));

            List <RenderedText> texts = new List <RenderedText>();

            {
                var t = RenderedText.Create();
                t.Font      = font;
                t.Text      = "Hello, world! こんにちは";
                t.Transform = MathHelper.CalcTransform(new Vector2F(), 0, new Vector2F(1, 1));
                texts.Add(t);
            }

            {
                var t = RenderedText.Create();
                t.Font      = font;
                t.Text      = "色を指定する。";
                t.Color     = new Color(0, 0, 255, 255);
                t.Transform = MathHelper.CalcTransform(new Vector2F(0, 100), 0, new Vector2F(1, 1));
                texts.Add(t);
            }

            {
                var t = RenderedText.Create();
                t.Font      = font2;
                t.Text      = "𠀋 𡈽 𡌛 𡑮 𡢽 𠮟 𡚴 𡸴 𣇄 𣗄 𣜿 𣝣 𣳾 𤟱 𥒎 𥔎 𥝱 𥧄 𥶡 𦫿 𦹀 𧃴 𧚄 𨉷";
                t.Transform = MathHelper.CalcTransform(new Vector2F(0, 200), 0, new Vector2F(1, 1));
                texts.Add(t);
            }

            var rotatedText = RenderedText.Create();
            {
                rotatedText.Font = font;
                rotatedText.Text = "くるくるまわる";
                texts.Add(rotatedText);
            }

            {
                var imageFontText = RenderedText.Create();
                imageFontText.Font      = imageFont;
                imageFontText.Text      = "Altseed〇Altseed";
                imageFontText.Transform = MathHelper.CalcTransform(new Vector2F(0, 300), 0, new Vector2F(1, 1));
                texts.Add(imageFontText);
            }

            int count = 0;

            while (Engine.DoEvents() && count++ < 300)
            {
                Assert.True(Engine.Graphics.BeginFrame(new RenderPassParameter(Engine.ClearColor, true, true)));
                rotatedText.Transform = MathHelper.CalcTransform(new Vector2F(0, 300), count, new Vector2F(1, 1));

                foreach (var item in texts)
                {
                    Engine.Renderer.DrawText(item);
                }

                Engine.Renderer.Render();
                Assert.True(Engine.Graphics.EndFrame());
            }

            tc.End();
        }
Exemplo n.º 19
0
        public void Anchor()
        {
            var tc = new TestCore(new Configuration()
            {
                VisibleTransformInfo = true
            });

            tc.Init();

            var font = Font.LoadDynamicFont("TestData/Font/mplus-1m-regular.ttf", 30);

            Assert.NotNull(font);

            var texture = Texture2D.Load(@"TestData/IO/AltseedPink.png");

            Assert.NotNull(texture);

            var sprite = new SpriteNode();

            sprite.Texture = texture;
            sprite.ZOrder  = 5;

            Vector2F rectSize = texture.Size;
            var      parent   = new AnchorTransformerNode();

            parent.Position   = Engine.WindowSize / 2;
            parent.Size       = rectSize;
            parent.AnchorMode = AnchorMode.Fill;
            Engine.AddNode(sprite);
            sprite.AddChildNode(parent);

            var sprite2 = new SpriteNode();

            sprite2.Texture = texture;
            sprite2.Color   = new Color(255, 0, 0, 200);
            sprite2.ZOrder  = 10;

            var child = new AnchorTransformerNode();

            child.Position            = rectSize / 2;
            child.Pivot               = new Vector2F(0.5f, 0.5f);
            child.AnchorMin           = new Vector2F(0.0f, 0.0f);
            child.AnchorMax           = new Vector2F(1f, 1f);
            child.HorizontalAlignment = HorizontalAlignment.Left;
            child.VerticalAlignment   = VerticalAlignment.Center;
            child.Size       = sprite2.ContentSize;
            child.AnchorMode = AnchorMode.KeepAspect;
            sprite.AddChildNode(sprite2);
            sprite2.AddChildNode(child);

            var text = new TextNode();

            text.Font   = font;
            text.Color  = new Color(0, 0, 0);
            text.Text   = "あいうえお";
            text.ZOrder = 15;

            var childText = new AnchorTransformerNode();

            childText.Pivot     = new Vector2F(0.5f, 0.5f);
            childText.AnchorMin = new Vector2F(0.5f, 0.5f);
            childText.AnchorMax = new Vector2F(0.5f, 0.5f);
            childText.Size      = text.ContentSize;
            //childText.HorizontalAlignment = HorizontalAlignment.Center;
            //childText.VerticalAlignment = VerticalAlignment.Center;
            childText.AnchorMode = AnchorMode.ContentSize;
            sprite2.AddChildNode(text);
            text.AddChildNode(childText);

            var text2 = new TextNode()
            {
                Font   = font,
                Text   = "",
                ZOrder = 10,
                Scale  = new Vector2F(0.8f, 0.8f),
                Color  = new Color(255, 128, 0)
            };

            Engine.AddNode(text2);

            tc.Duration = 10000;

            string infoText(AnchorTransformerNode n) =>
            $"Scale:{n.Scale}\n" +
            $"Position:{n.Position}\n" +
            $"Pivot:{n.Pivot}\n" +
            $"Size:{n.Size}\n" +
            $"Margin: LT:{n.LeftTop} RB:{n.RightBottom}\n" +
            $"Anchor: {n.AnchorMin} {n.AnchorMax}\n";

            tc.LoopBody(c =>
            {
                if (Engine.Keyboard.GetKeyState(Key.Right) == ButtonState.Hold)
                {
                    rectSize.X += 1.5f;
                }
                if (Engine.Keyboard.GetKeyState(Key.Left) == ButtonState.Hold)
                {
                    rectSize.X -= 1.5f;
                }
                if (Engine.Keyboard.GetKeyState(Key.Down) == ButtonState.Hold)
                {
                    rectSize.Y += 1.5f;
                }
                if (Engine.Keyboard.GetKeyState(Key.Up) == ButtonState.Hold)
                {
                    rectSize.Y -= 1.5f;
                }

                if (Engine.Keyboard.GetKeyState(Key.D) == ButtonState.Hold)
                {
                    parent.Position += new Vector2F(1.5f, 0);
                }
                if (Engine.Keyboard.GetKeyState(Key.A) == ButtonState.Hold)
                {
                    parent.Position += new Vector2F(-1.5f, 0);
                }
                if (Engine.Keyboard.GetKeyState(Key.S) == ButtonState.Hold)
                {
                    parent.Position += new Vector2F(0, 1.5f);
                }
                if (Engine.Keyboard.GetKeyState(Key.W) == ButtonState.Hold)
                {
                    parent.Position += new Vector2F(0, -1.5f);
                }

                if (Engine.Keyboard.GetKeyState(Key.Q) == ButtonState.Hold)
                {
                    child.Angle += 1.5f;
                }
                if (Engine.Keyboard.GetKeyState(Key.E) == ButtonState.Hold)
                {
                    child.Angle -= 1.5f;
                }

                if (Engine.Keyboard.GetKeyState(Key.Z) == ButtonState.Hold)
                {
                    parent.Scale += new Vector2F(0.1f, 0);
                }
                if (Engine.Keyboard.GetKeyState(Key.C) == ButtonState.Hold)
                {
                    parent.Scale -= new Vector2F(0.1f, 0);
                }

                parent.Size = rectSize;

                text2.Text = infoText(parent) + '\n' + infoText(child) + '\n' + infoText(childText);
            }, null);

            tc.End();
        }
Exemplo n.º 20
0
        public void SpriteNode()
        {
            var tc = new TestCore();

            tc.Init();

            var texture = Texture2D.Load(@"TestData/IO/AltseedPink.png");

            Assert.NotNull(texture);

            var node = new SpriteNode();

            node.Texture = texture;
            //node.Src = new RectF(new Vector2F(100, 100), new Vector2F(200, 200));
            //node.Pivot = new Vector2F(0.5f, 0.5f);
            //node.AdjustSize();
            Engine.AddNode(node);

            tc.LoopBody(c =>
            {
                if (Engine.Keyboard.GetKeyState(Key.Right) == ButtonState.Hold)
                {
                    node.Position += new Vector2F(1.5f, 0);
                }
                if (Engine.Keyboard.GetKeyState(Key.Left) == ButtonState.Hold)
                {
                    node.Position -= new Vector2F(1.5f, 0);
                }
                if (Engine.Keyboard.GetKeyState(Key.Down) == ButtonState.Hold)
                {
                    node.Position += new Vector2F(0, 1.5f);
                }
                if (Engine.Keyboard.GetKeyState(Key.Up) == ButtonState.Hold)
                {
                    node.Position -= new Vector2F(0, 1.5f);
                }
                if (Engine.Keyboard.GetKeyState(Key.B) == ButtonState.Hold)
                {
                    node.Scale += new Vector2F(0.01f, 0.01f);
                }
                if (Engine.Keyboard.GetKeyState(Key.S) == ButtonState.Hold)
                {
                    node.Scale -= new Vector2F(0.01f, 0.01f);
                }
                if (Engine.Keyboard.GetKeyState(Key.R) == ButtonState.Hold)
                {
                    node.Angle += 3;
                }
                if (Engine.Keyboard.GetKeyState(Key.L) == ButtonState.Hold)
                {
                    node.Angle -= 3;
                }
                if (Engine.Keyboard.GetKeyState(Key.X) == ButtonState.Hold)
                {
                    node.Src = new RectF(node.Src.X, node.Src.Y, node.Src.Width - 2.0f, node.Src.Height - 2.0f);
                }
                if (Engine.Keyboard.GetKeyState(Key.Z) == ButtonState.Hold)
                {
                    node.Src = new RectF(node.Src.X, node.Src.Y, node.Src.Width + 2.0f, node.Src.Height + 2.0f);
                }
                if (Engine.Keyboard.GetKeyState(Key.C) == ButtonState.Hold)
                {
                    node.Src = new RectF(node.Src.X - 2.0f, node.Src.Y - 2.0f, node.Src.Width, node.Src.Height);
                }
                if (Engine.Keyboard.GetKeyState(Key.V) == ButtonState.Hold)
                {
                    node.Src = new RectF(node.Src.X + 2.0f, node.Src.Y + 2.0f, node.Src.Width, node.Src.Height);
                }
            }
                        , null);

            tc.End();
        }
Exemplo n.º 21
0
        public void IsUpdated()
        {
            var tc = new TestCore();

            tc.Init();

            var node1 = new IsUpdatedTestNode("node1")
            {
                Position = new Vector2F(0f, 0f)
            };
            var node2 = new IsUpdatedTestNode("node2")
            {
                Position = new Vector2F(0f, 100f)
            };
            var node3 = new IsUpdatedTestNode("node3")
            {
                Position = new Vector2F(0f, 200f)
            };

            Engine.AddNode(node1);
            node1.AddChildNode(node2);
            node2.AddChildNode(node3);

            tc.LoopBody(c =>
            {
                node1.UpdateText();
                node2.UpdateText();
                node3.UpdateText();

                if (c == 10)
                {
                    node1.IsUpdated = false;
                    Assert.False(node1.IsUpdated);
                    Assert.True(node2.IsUpdated);
                    Assert.True(node3.IsUpdated);
                    Assert.False(node1.IsUpdatedActually);
                    Assert.False(node2.IsUpdatedActually);
                    Assert.False(node3.IsUpdatedActually);
                }
                else if (c == 40)
                {
                    node1.IsUpdated = true;
                    Assert.True(node1.IsUpdated);
                    Assert.True(node2.IsUpdated);
                    Assert.True(node3.IsUpdated);
                    Assert.True(node1.IsUpdatedActually);
                    Assert.True(node2.IsUpdatedActually);
                    Assert.True(node3.IsUpdatedActually);
                }
                else if (c == 70)
                {
                    node3.IsUpdated = false;
                    Assert.True(node1.IsUpdated);
                    Assert.True(node2.IsUpdated);
                    Assert.False(node3.IsUpdated);
                    Assert.True(node1.IsUpdatedActually);
                    Assert.True(node2.IsUpdatedActually);
                    Assert.False(node3.IsUpdatedActually);
                }
                else if (c == 100)
                {
                    node2.IsUpdated = false;
                    Assert.True(node1.IsUpdated);
                    Assert.False(node2.IsUpdated);
                    Assert.False(node3.IsUpdated);
                    Assert.True(node1.IsUpdatedActually);
                    Assert.False(node2.IsUpdatedActually);
                    Assert.False(node3.IsUpdatedActually);
                }
                else if (c == 130)
                {
                    node2.IsUpdated = true;
                    Assert.True(node1.IsUpdated);
                    Assert.True(node2.IsUpdated);
                    Assert.False(node3.IsUpdated);
                    Assert.True(node1.IsUpdatedActually);
                    Assert.True(node2.IsUpdatedActually);
                    Assert.False(node3.IsUpdatedActually);
                }
            }, null);

            tc.End();
        }
Exemplo n.º 22
0
        public void TreeDelete()
        {
            var tc = new TestCore();

            tc.Init();

            var t1 = Texture2D.Load(@"TestData/IO/AltseedPink.png");

            Assert.NotNull(t1);

            var s = new Altseed2.Node();
            //s.Texture = t1;
            //s.Position = new Vector2F(100, 100);

            var s2 = new SpriteNode();

            s2.Texture  = t1;
            s2.Position = new Vector2F(100, 100);

            var s3 = new SpriteNode();

            s3.Texture  = t1;
            s3.Position = new Vector2F(100, 100);

            var s4 = new SpriteNode();

            s4.Texture  = t1;
            s4.Position = new Vector2F(100, 100);

            s.AddChildNode(s2);
            s2.AddChildNode(s3);
            s3.AddChildNode(s4);

            Engine.AddNode(s);

            tc.LoopBody(c =>
            {
                if (c == 100)
                {
                    Engine.RemoveNode(s);
                }
                if (c == 101)
                {
                    Assert.IsFalse(s.IsRegistered);
                    Assert.IsFalse(s2.IsRegistered);
                    Assert.IsFalse(s3.IsRegistered);
                    Assert.IsFalse(s4.IsRegistered);

                    var dc     = typeof(Engine).GetField("_DrawnCollection", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null) as DrawnCollection;
                    var drawns = typeof(DrawnCollection).GetField("_Drawns", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(dc) as SortedDictionary <int, HashSet <IDrawn> >;
                    Assert.IsTrue(drawns.All(kv => kv.Value.Count == 0));
                }
                if (c == 110)
                {
                    Engine.AddNode(s);
                }
                if (c == 111)
                {
                    Assert.IsTrue(s.IsRegistered);
                    Assert.IsTrue(s2.IsRegistered);
                    Assert.IsTrue(s3.IsRegistered);
                    Assert.IsTrue(s4.IsRegistered);

                    var dc     = typeof(Engine).GetField("_DrawnCollection", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null) as DrawnCollection;
                    var drawns = typeof(DrawnCollection).GetField("_Drawns", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(dc) as SortedDictionary <int, HashSet <IDrawn> >;
                    Assert.AreEqual(3, drawns.Sum(kv => kv.Value.Count));
                }
                if (c == 120)
                {
                    s2.RemoveChildNode(s3);
                    s2.FlushQueue();

                    Assert.AreEqual(RegisteredStatus.Free, s3.Status);

                    Assert.IsTrue(s.IsRegistered);
                    Assert.IsTrue(s2.IsRegistered);
                    Assert.IsFalse(s3.IsRegistered);
                    Assert.IsFalse(s4.IsRegistered);

                    var dc     = typeof(Engine).GetField("_DrawnCollection", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null) as DrawnCollection;
                    var drawns = typeof(DrawnCollection).GetField("_Drawns", BindingFlags.Instance | BindingFlags.NonPublic).GetValue(dc) as SortedDictionary <int, HashSet <IDrawn> >;
                    Assert.AreEqual(1, drawns.Sum(kv => kv.Value.Count));
                }
            }, null);

            tc.End();
        }
Exemplo n.º 23
0
        public void Reusable()
        {
            var tc = new TestCore();

            tc.Init();

            var t1 = Texture2D.Load(@"TestData/IO/AltseedPink.png");

            Assert.NotNull(t1);

            var s = new SpriteNode();

            s.Texture  = t1;
            s.Position = new Vector2F(100, 100);

            var s2 = new SpriteNode();

            s2.Texture  = t1;
            s2.Position = new Vector2F(200, 200);
            s.AddChildNode(s2);
            Engine.AddNode(s);

            var n = new Node();

            tc.Duration = 5;
            tc.LoopBody(c =>
            {
                switch (c)
                {
                case 0:
                    break;

                case 1:
                    break;

                case 2:
                    Assert.True(s2.Parent == s);
                    break;

                case 3:
                    Engine.RemoveNode(s);
                    break;

                case 4:
                    Assert.Null(s.Parent);
                    Assert.True(s.Status == RegisteredStatus.Free);
                    break;

                case 5:
                    s.RemoveChildNode(s2);
                    Assert.True(s2.Status == RegisteredStatus.WaitingRemoved);
                    s.FlushQueue();
                    Assert.Null(s2.Parent);
                    Assert.True(s2.Status == RegisteredStatus.Free);
                    Assert.AreEqual(s.Children.Count, 0);
                    break;
                }
            }, null);

            tc.End();
        }
Exemplo n.º 24
0
        public void IsDrawn()
        {
            var tc = new TestCore();

            tc.Init();

            var texture = Texture2D.Load(@"TestData/IO/AltseedPink.png");

            Assert.NotNull(texture);

            var node = new SpriteNode();

            node.Texture        = texture;
            node.CenterPosition = texture.Size / 2;
            node.Position       = new Vector2F(100, 100);
            Engine.AddNode(node);

            var node2 = new SpriteNode();

            node2.Texture        = texture;
            node2.CenterPosition = texture.Size / 2;
            node2.Position       = new Vector2F(200, 200);

            var node3 = new SpriteNode();

            node3.Texture        = texture;
            node3.CenterPosition = texture.Size / 2;
            node3.Position       = new Vector2F(300, 300);

            tc.LoopBody(c =>
            {
                if (c == 2)
                {
                    node.AddChildNode(node2);
                }

                if (c == 4)
                {
                    node.IsDrawn = false;
                    Assert.IsFalse(node.IsDrawnActually);
                    Assert.IsFalse(node2.IsDrawnActually);
                }

                if (c == 6)
                {
                    node2.AddChildNode(node3);
                }

                if (c == 8)
                {
                    node.IsDrawn = true;

                    Assert.IsTrue(node.IsDrawnActually);
                    Assert.IsTrue(node2.IsDrawnActually);
                    Assert.IsTrue(node3.IsDrawnActually);
                }

                if (c == 10)
                {
                    node2.IsDrawn = false;

                    Assert.IsTrue(node.IsDrawnActually);
                    Assert.IsFalse(node2.IsDrawnActually);
                    Assert.IsFalse(node3.IsDrawnActually);
                }
            }, null);

            tc.End();
        }
Exemplo n.º 25
0
        public void Node()
        {
            var tc = new TestCore()
            {
                Duration = 5
            };

            tc.Init();

            //
            // RootNode
            // --node0
            //   |-node1
            //   --node2
            //
            // node3 is isolated from other nodes
            //

            var node0 = new NumericNode(0);
            var node1 = new NumericNode(1);
            var node2 = new NumericNode(2);
            var node3 = new NumericNode(3);

            NumericNode deserialized_node0 = null;
            NumericNode deserialized_node3 = null;

            node0.AddChildNode(node1);
            node0.AddChildNode(node2);
            Engine.AddNode(node0);

            int[] comparisonArray = null;

            const string path = "Serialization/Node.bin";

            tc.LoopBody(null, x =>
            {
                switch (x)
                {
                case 1:
                    var set = new SortedSet <int>();
                    foreach (var node in EnumerateEngineNodes())
                    {
                        if (node is NumericNode n)
                        {
                            set.Add(n.Index);
                        }
                    }
                    comparisonArray = set.ToArray();

                    Serialize(path, (node0, node3));

                    Assert.AreEqual(node0.Children.Count, 2);
                    Assert.AreEqual(EnumerateEngineNodes().Count(), 3);
                    break;

                case 2:
                    Engine.RemoveNode(node0);
                    break;

                case 3:
                    var tuple          = Deserialize <(NumericNode, NumericNode)>(path);
                    deserialized_node0 = tuple.Item1;
                    deserialized_node3 = tuple.Item2;

                    Assert.AreEqual(node0.Index, deserialized_node0.Index);
                    Assert.AreEqual(node3.Index, deserialized_node3.Index);
                    Assert.AreEqual(EnumerateEngineNodes().Count(), 0);
                    break;

                case 4:
                    Assert.NotNull(comparisonArray);
                    Assert.NotNull(deserialized_node0);
                    Assert.NotNull(deserialized_node3);

                    set = new SortedSet <int>();
                    foreach (var node in EnumerateEngineNodes())
                    {
                        if (node is NumericNode n)
                        {
                            set.Add(n.Index);
                        }
                    }

                    Assert.True(Enumerable.SequenceEqual(comparisonArray, set.ToArray()));
                    Assert.AreEqual(deserialized_node0.Children.Count, 2);
                    Assert.AreEqual(EnumerateEngineNodes().Count(), 3);
                    break;
                }
            });

            tc.End();
Exemplo n.º 26
0
        public void StreamFileBase()
        {
            var tc = new TestCore();

            tc.Init();

            // pack files
            Assert.True(Engine.File.Pack("TestData/IO/", "pack.pack"));
            Assert.True(Engine.File.PackWithPassword("TestData/IO/pack/", "password.pack", "altseed"));

            // add package
            Assert.True(Engine.File.AddRootPackage("pack.pack"));

            // create static file, and compare no-package and package without password
            StreamFile test = null;

            Assert.AreNotEqual(test = StreamFile.Create("TestData/IO/test.txt"), null);
            Assert.False(test.IsInPackage);
            StreamFile testPack = null;

            Assert.AreNotEqual(testPack = StreamFile.Create("test.txt"), null);
            Assert.True(testPack.IsInPackage);
            Assert.AreEqual(test.Size, testPack.Size);
            Assert.AreEqual(test.TempBufferSize, 0);
            Assert.AreEqual(testPack.TempBufferSize, 0);
            for (int i = 0; i < test.Size; i++)
            {
                Assert.AreEqual(test.Read(1), 1);
                Assert.AreEqual(testPack.Read(1), 1);
                Assert.AreEqual(test.TempBufferSize, i + 1);
                Assert.AreEqual(testPack.TempBufferSize, i + 1);
                Assert.AreEqual(test.TempBuffer, test.TempBuffer);
            }

            // add package
            Assert.True(Engine.File.AddRootPackageWithPassword("password.pack", "altseed"));

            // clear cache
            Engine.Resources.Clear();

            StreamFile testPack2 = null;

            Assert.AreNotEqual(testPack2 = StreamFile.Create("test.txt"), null);
            Assert.True(testPack2.IsInPackage);
            Assert.AreNotEqual(testPack, testPack2);
            Assert.AreNotEqual(testPack.Size, testPack2.Size);

            // create static file, and compare no-package and package with password
            StreamFile test3 = null;

            Assert.AreNotEqual(test3 = StreamFile.Create("TestData/IO/pack/test.txt"), null);
            Assert.AreEqual(test3.Size, testPack2.Size);
            Assert.AreEqual(test3.Size, testPack2.Size);
            Assert.AreEqual(test3.TempBufferSize, 0);
            Assert.AreEqual(testPack2.TempBufferSize, 0);
            for (int i = 0; i < test3.Size; i++)
            {
                Assert.AreEqual(test3.Read(1), 1);
                Assert.AreEqual(testPack2.Read(1), 1);
                Assert.AreEqual(test3.TempBufferSize, i + 1);
                Assert.AreEqual(testPack2.TempBufferSize, i + 1);
            }

            tc.End();
        }
Exemplo n.º 27
0
        public void StaticFileAsync()
        {
            var tc = new TestCore();

            tc.Init();

            // pack files
            Assert.True(Engine.File.Pack("TestData/IO/", "pack.pack"));

            // add package
            Assert.True(Engine.File.AddRootPackage("pack.pack"));

            // create static file, and compare no-package and package without password
            StaticFile test1 = null;
            StaticFile test2 = null;

#if !CI
            StaticFile test3 = null;
            StaticFile test4 = null;
#endif
            StaticFile testCache = null;
            StaticFile testPack1 = null;
            StaticFile testPack2 = null;
#if !CI
            StaticFile testPack3 = null;
            StaticFile testPack4 = null;
#endif
            StaticFile testPackCache = null;

            var task1 = Task.Run(() =>
            {
                test1 = StaticFile.Create("TestData/IO/test.txt");
#if !CI
                test3 = StaticFile.Create("TestData/IO/全角 テスト.txt");
#endif
                testPack1 = StaticFile.Create("test.txt");
#if !CI
                testPack3 = StaticFile.Create("全角 テスト.txt");
#endif
                testCache = StaticFile.Create("TestData/IO/test.txt");
            });

            var task2 = Task.Run(() =>
            {
                test2 = StaticFile.Create("TestData/IO/space test.txt");
#if !CI
                test4 = StaticFile.Create("TestData/IO/全角 テスト.txt");
#endif
                testPack2 = StaticFile.Create("space test.txt");
#if !CI
                testPack4 = StaticFile.Create("全角 テスト.txt");
#endif
                testPackCache = StaticFile.Create("space test.txt");
            });

            task1.Wait();
            task2.Wait();

            Assert.AreNotEqual(test1, null);
            Assert.AreNotEqual(test2, null);
#if !CI
            Assert.AreNotEqual(test3, null);
            Assert.AreNotEqual(test4, null);
#endif
            Assert.AreNotEqual(testCache, null);
            Assert.AreNotEqual(testPack1, null);
            Assert.AreNotEqual(testPack2, null);
#if !CI
            Assert.AreNotEqual(testPack3, null);
            Assert.AreNotEqual(testPack4, null);
#endif
            Assert.AreNotEqual(testPackCache, null);

            Assert.AreEqual(test1.Size, testPack1.Size);
            Assert.AreEqual(test2.Size, testPack2.Size);
#if !CI
            Assert.AreEqual(test3.Size, testPack3.Size);
            Assert.AreEqual(test4.Size, testPack4.Size);
#endif
            tc.End();
        }