예제 #1
0
        public void TestCreateEntity_PassNullArg_ReturnsEntityWithDefaultName()
        {
            Assert.NotNull(mEntityManager);

            var newEntity = mEntityManager.CreateEntity(null);

            Assert.NotNull(newEntity);
            Assert.AreEqual(newEntity.Name, "Entity0");
            Assert.AreEqual(newEntity.Id, (EntityId)0);
        }
예제 #2
0
        public static SingleGameObject Create(IEntityManager manager, BoundingBox box, Vector4 color)
        {
            var tag = new ElementTag("Physics Object" + Guid.NewGuid());

            //var box = new BoundingBox(new Vector3(-5,10,-5), new Vector3(5,20,5));

            box = box.Transform(Matrix4x4.CreateTranslation(new Vector3(64, 100, 32) - box.GetCenter()));

            var geobox = GeometryBuilder.BuildGeoBox(box);

            manager.CreateEntity(tag)
            .AddComponents(new IGraphicComponent[] {
                new SimpleGeometryComponent {
                    Positions = geobox.Positions.ToImmutableArray(),
                    Indices   = geobox.Indices.ToImmutableArray(),
                    Normals   = geobox.Positions.CalculateNormals(geobox.Indices).ToImmutableArray(),
                    Color     = color
                },
                new D3DTriangleColoredVertexRenderComponent(),
                TransformComponent.Create(Matrix4x4.Identity),
                PhysicalComponentFactory.CreateAABB(),
                // PhysicalComponentFactory.CreateMesh(),
            });

            return(new PhysicsObjectTest(tag));
        }
예제 #3
0
        public static PolylineGameObject Create(IEntityManager manager, ElementTag tag,
                                                IEnumerable <Vector3> points, Vector4[] color)
        {
            var indeces = new List <int>();

            for (var i = 0; i < points.Count(); i++)
            {
                indeces.AddRange(new[] { i, i });
            }
            var geo = new SimpleGeometryComponent()
            {
                Positions = points.ToImmutableArray(),
                Indices   = indeces.ToImmutableArray(),
                Colors    = color.ToImmutableArray(),
            };
            var tag1 = manager
                       .CreateEntity(tag)
                       .AddComponent(geo)
                       .AddComponent(SDX.Engine.Components.D3DLineVertexRenderComponent.AsLineList())
                       .AddComponent(new TransformComponent())
                       //.AddComponent(new PositionColorsComponent { Colors = color })
                       .Tag;

            return(new PolylineGameObject(tag1));
        }
예제 #4
0
        void CreateEntity()
        {
            if (entity != null)
            {
                RecycleEntity();
            }

            entity = entityManager.CreateEntity(groups, enabled);

            for (int i = 0; i < children.Length; i++)
            {
                entity.AddChild(children[i].Entity);
            }

            entity.AddAll(components);
            entity.AddAll(componentBehaviours);

            // Activate components
            for (int i = 0; i < componentBehaviours.Length; i++)
            {
                var component = componentBehaviours[i];

                if (component.Active && component.Entity != null)
                {
                    component.OnActivated();
                }
            }
        }
예제 #5
0
        /// <summary>
        /// The method creates a new entity with the only component that's already attached to it.
        /// The component is TDisposableComponent. All entities that have that component are destroyed
        /// at an end of a frame with a special system.
        /// </summary>
        /// <param name="entityManager">A reference to IEntityManager implementation</param>
        /// <param name="name">A name of an entity (optional)</param>
        /// <returns>The method returns an identifier of created entity</returns>

        public static EntityId CreateDisposableEntity(this IEntityManager entityManager, string name = null)
        {
            IEntity entity = entityManager.CreateEntity(name);

            entity.AddComponent <TDisposableComponent>();

            return(entity.Id);
        }
예제 #6
0
        public void CreateEntityShouldReturnUserGridEntity()
        {
            var entity = new object();

            _entityManager.CreateEntity("collection", entity).ReturnsForAnyArgs(entity);

            var returnedEntity = _client.CreateEntity("collection", entity);

            Assert.AreEqual(entity, returnedEntity);
        }
예제 #7
0
        public static GraphicEntity Build(IEntityManager context, IAppWindow window)
        {
            var view = context.CreateEntity(new ElementTag("EngineInfo"));

            view//.AddComponent(new WindowHeaderUpdaterComponent(window))
            .AddComponent(new InputInfoComponent())
            .AddComponent(PerfomanceComponent.Create(0, 0));

            return(view);
        }
예제 #8
0
        public void AddEntity()
        {
            var entity = _componentManager.CreateEntity();

            A.CallTo(() => _eventSystem.Send(A <object> ._, A <EntityAdded> ._))
            .MustHaveHappenedOnceExactly();

            Assert.That(_componentManager.GetEntity(entity.Id), Is.EqualTo(entity));
        }
예제 #9
0
        public static ElementTag BuildArrow(IEntityManager manager, ArrowData data)
        {
            var geo = GeometryBuilder.BuildArrow(data);

            return(manager
                   .CreateEntity(data.tag)
                   .AddComponent(geo)
                   .AddComponent(D3DTriangleColoredVertexRenderComponent.AsStrip())
                   .AddComponent(new TransformComponent())
                   .Tag);
        }
예제 #10
0
        public static LightGameObject CreateAmbientLight(IEntityManager manager)
        {
            var tag = new ElementTag("AmbientLight_" + Interlocked.Increment(ref lights));

            manager.CreateEntity(tag)
            .AddComponents(
                LightComponent.CreateAmbient(0.4f, 0),
                ColorComponent.CreateDiffuse(V4Colors.White)
                );

            return(new LightGameObject(tag, "AmbientLight"));
        }
예제 #11
0
        public static OrbitsRotationGameObject Create(IEntityManager manager)
        {
            var geo = GeometryBuilder.BuildRotationOrbits(100, Vector3.Zero);
            var tag = manager
                      .CreateEntity(new ElementTag("OrbitsRotationGameObject"))
                      .AddComponent(geo)
                      .AddComponent(D3DLineVertexRenderComponent.AsLineStrip())
                      .AddComponent(new TransformComponent())
                      .Tag;

            return(new OrbitsRotationGameObject());
        }
예제 #12
0
        public static LightGameObject CreatePointLight(IEntityManager manager, Vector3 position)  //
        {
            var tag = new ElementTag("PointLight_" + Interlocked.Increment(ref lights));

            manager.CreateEntity(tag)
            .AddComponents(
                LightComponent.CreatePoint(0.4f, 1, position),
                ColorComponent.CreateDiffuse(new Vector4(1, 1, 1, 1))
                );

            return(new LightGameObject(tag, "PointLight"));
        }
예제 #13
0
        public static LightGameObject CreateDirectionLight(IEntityManager manager, Vector3 direction)  // ,
        {
            var tag = new ElementTag("DirectionLight_" + Interlocked.Increment(ref lights));

            manager.CreateEntity(tag)
            .AddComponents(
                LightComponent.CreateDirectional(0.2f, 2, direction),
                ColorComponent.CreateDiffuse(new Vector4(1, 1, 1, 1))
                );

            return(new LightGameObject(tag, "DirectionLight"));
        }
예제 #14
0
        public void CreatedEntitiesExists()
        {
            var a = entityManager.CreateEntity(empty);
            var b = entityManager.CreateEntity(empty);

            Assert.AreNotEqual(a, b);
            Assert.IsTrue(entityManager.Exist(a));
            Assert.IsTrue(entityManager.Exist(b));
        }
예제 #15
0
        public static ElementTag BuildLineEntity(this IEntityManager manager, Vector3[] points)
        {
            var geo = new SimpleGeometryComponent()
            {
                Positions = points.ToImmutableArray(),
                Indices   = ImmutableArray.Create <int>(),
                Color     = new Vector4(0, 1, 0, 1)
            };

            return(manager
                   .CreateEntity(new ElementTag("Points" + Guid.NewGuid()))
                   .AddComponent(geo)
                   .AddComponent(new SDX.Engine.Components.D3DLineVertexRenderComponent())
                   .Tag);
        }
예제 #16
0
        public static ArrowGameObject Build(IEntityManager manager, ArrowData data)
        {
            var geo = GeometryBuilder.BuildArrow(data);

            geo.Color = data.color;
            var en = manager
                     .CreateEntity(data.tag)
                     .AddComponents(
                geo,
                D3DTriangleColoredVertexRenderComponent.AsStrip(),
                new TransformComponent()
                );

            return(new ArrowGameObject(en.Tag));
        }
예제 #17
0
        public static LightObject CreatePointLight(IEntityManager manager, Vector3 position)  //
        {
            var index = 1;

            if (!occupiedIndex.Add(index))
            {
                throw new LightIndexOccupiedException(index);
            }
            var tag = new ElementTag("PointLight_" + Interlocked.Increment(ref lights));

            manager.CreateEntity(tag)
            .AddComponent(LightComponent.CreatePoint(0.4f, index, position))
            .AddComponent(ColorComponent.CreateDiffuse(new Vector4(1, 1, 1, 1)));

            return(new LightObject(tag, "PointLight"));
        }
예제 #18
0
        public static TerrainGameObject Create(IEntityManager manager)
        {
            var tag = new ElementTag("Terrain");

            var resources = Path.Combine(@"Resources\terrain\");
            //"../../../../D3DLab.Wpf.Engine.App/Resources/terrain/"
            var grass    = Path.Combine(resources, "1.jpg");
            var slope    = Path.Combine(resources, "slope.bmp");
            var rock     = Path.Combine(resources, "rock-lambertian.jpg");
            var seafloor = Path.Combine(resources, "seafloor.bmp");
            var sand     = Path.Combine(resources, "sand-lambertian.png");
            var shore    = Path.Combine(resources, "shore.jpg");
            var dirt     = Path.Combine(resources, "dirt.bmp");
            var snow     = Path.Combine(resources, "snow01n.bmp");


            var heigtmap = Path.Combine(resources, "test.bmp");

            manager.CreateEntity(tag)
            .AddComponents(new IGraphicComponent[] {
                new D3DTerrainRenderComponent()
                {
                    CanRender = false
                },
                new Systems.TerrainConfigurationComponent {
                    Width  = 256,
                    Height = 256,
                },
                new D3DTexturedMaterialSamplerComponent(
                    new System.IO.FileInfo(seafloor),
                    new System.IO.FileInfo(shore),
                    new System.IO.FileInfo(sand),
                    new System.IO.FileInfo(grass),
                    new System.IO.FileInfo(dirt),
                    new System.IO.FileInfo(rock),
                    new System.IO.FileInfo(slope),

                    new System.IO.FileInfo(Path.Combine(resources, "rock01n.bmp")),
                    new System.IO.FileInfo(snow),
                    new System.IO.FileInfo(Path.Combine(resources, "distance01n.bmp"))
                    ),
                TransformComponent.Identity(),
                PhysicalComponentFactory.CreateStaticMesh()
            });

            return(new TerrainGameObject(tag));
        }
예제 #19
0
        public static LightObject CreateDirectionLight(IEntityManager manager, Vector3 direction, float intensity)  // ,
        {
            var index = 2;

            if (!occupiedIndex.Add(index))
            {
                throw new LightIndexOccupiedException(index);
            }

            var tag = new ElementTag("DirectionLight_" + Interlocked.Increment(ref lights));

            manager.CreateEntity(tag)
            .AddComponent(LightComponent.CreateDirectional(intensity, index, direction))
            .AddComponent(ColorComponent.CreateDiffuse(new Vector4(1, 1, 1, 1)));

            return(new LightObject(tag, "DirectionLight"));
        }
예제 #20
0
        public static ElementTag Build(IEntityManager manager, List <Vector3> pos, List <int> indexes, List <Vector4> colors)
        {
            var geo = new SimpleGeometryComponent()
            {
                Positions = pos.ToImmutableArray(),
                Indices   = indexes.ToImmutableArray(),
                Colors    = colors.ToImmutableArray(),
                Normals   = pos.CalculateNormals(indexes).ToImmutableArray()
            };

            return(manager
                   .CreateEntity(new ElementTag("Geometry" + Guid.NewGuid()))
                   .AddComponent(geo)
                   .AddComponent(TransformComponent.Identity())
                   .AddComponent(GetObjGroupsRender())
                   .Tag);
        }
예제 #21
0
        public static SphereGameObject Create(IEntityManager manager, Data data)
        {
            var tag = manager
                      .CreateEntity(new ElementTag("Sphere_" + DateTime.Now.Ticks))
                      .AddComponent(new SimpleGeometryComponent()
            {
                Indices   = new[] { 0 }.ToImmutableArray(),
                Positions = new Vector3[] { data.Center }.ToImmutableArray(),
                Color     = data.Color,
            })
                      .AddComponent(new D3DSpherePointRenderComponent())
                      .AddComponent(TransformComponent.Identity())
                      .Tag;


            return(new SphereGameObject(tag));
        }
예제 #22
0
        public static LightObject CreateAmbientLight(IEntityManager manager, float intensity = 0.4f)
        {
            var index = 0;

            if (!occupiedIndex.Add(index))
            {
                throw new LightIndexOccupiedException(index);
            }

            var tag = new ElementTag("AmbientLight_" + Interlocked.Increment(ref lights));
            var sv4 = SharpDX.Color.White.ToVector4();

            manager.CreateEntity(tag)
            .AddComponent(LightComponent.CreateAmbient(intensity, index))
            .AddComponent(ColorComponent.CreateDiffuse(new Vector4(sv4.X, sv4.Y, sv4.Z, sv4.W)));

            return(new LightObject(tag, "AmbientLight"));
        }
예제 #23
0
        public static ElementTag BuildGroupMeshElement(this IEntityManager manager, IEnumerable <AbstractGeometry3D> objs)
        {
            var group = new Std.Engine.Core.Components.CompositeGeometryComponent();

            objs.ForEach(x => group.Add(new SimpleGeometryComponent {
                Positions = x.Positions.ToImmutableArray(),
                Indices   = x.Indices.ToImmutableArray(),
                Normals   = x.Normals.ToImmutableArray(),
                Color     = x.Color
            }));
            group.Combine();
            return(manager
                   .CreateEntity(new ElementTag("GroupGeometry" + Guid.NewGuid()))
                   .AddComponent(group)
                   .AddComponent(new D3DTriangleColoredVertexRenderComponent())
                   .AddComponent(TransformComponent.Create(Matrix4x4.CreateTranslation(Vector3.UnitY * 30)))
                   .Tag);
        }
예제 #24
0
        public static CameraGameObject Create(IContextState context)
        {
            IEntityManager manager   = context.GetEntityManager();
            var            cameraTag = new ElementTag("CameraEntity_" + Interlocked.Increment(ref cameras));

            var obj = new CameraGameObject(cameraTag, "PerspectiveCamera");

            manager.CreateEntity(cameraTag)
            //.AddComponent(new OrthographicCameraComponent(Window.Width, Window.Height));
            .AddComponent(new PerspectiveCameraComponent());

            {//entities ordering
                context.EntityOrder
                .RegisterOrder <RenderSystem>(cameraTag, 0)
                .RegisterOrder <DefaultInputSystem>(cameraTag, 0);
            }

            return(obj);
        }
예제 #25
0
        public static SingleGameObject Create(IEntityManager manager)
        {
            var tag = new ElementTag("Anim CMO file");

            var fileName = Path.Combine($"{Directory.GetCurrentDirectory()}", $"Resources", $"animation", $"Chick.cmo");
            //var fileName = @"C:\Storage\projects\sv\3d\d3dlab\D3DLab.Wpf.Engine.App\Resources\animation\Chick.cmo";
            var meshes = CMOAnimationLoader.LoadFromFile(fileName);

            var mesh = meshes.First();

            var animesh = new MeshAnimationComponent("Armature|ArmatureAction.002");
            var render  = new D3DAnimRenderComponent();
            var texture = new D3DTexturedMaterialSamplerComponent(new SamplerStateDescription()
            {
                AddressU           = TextureAddressMode.Clamp,
                AddressV           = TextureAddressMode.Clamp,
                AddressW           = TextureAddressMode.Clamp,
                BorderColor        = new SharpDX.Color4(0, 0, 0, 0),
                ComparisonFunction = Comparison.Never,
                Filter             = Filter.MinMagMipLinear,
                MaximumAnisotropy  = 16,
                MaximumLod         = float.MaxValue,
                MinimumLod         = 0,
                MipLodBias         = 0.0f
            });

            var moveToZ   = Matrix4x4.CreateTranslation(Vector3.UnitY * 20);
            var rotateToY = Matrix4x4.CreateRotationX(-90f.ToRad());

            manager.CreateEntity(tag)
            .AddComponents(new IGraphicComponent[] {
                mesh,
                render,
                animesh,
                texture,
                TransformComponent.Create(rotateToY * moveToZ),
                // PhysicalComponentFactory.CreateAABB(),
            });

            // new SingleGameObject( EntityBuilders.BuildMeshElement(manager, pos, indx, V4Colors.Red),"test");

            return(new AnimCMOObject(tag));
        }
예제 #26
0
        public void AddMember(IEntityManager gem, IHexCoord position, string entityId)
        {
            var ent = gem.CreateEntity(entityId, e => {
                e.AddModule(new SquadMember(this, _number));
            });

            ent.GetComponent <HexMovementComp>().SetPosition(position);
            ent.GetComponent <ModelColorizer>().Colorize(Config.Color);

            //var map = ServiceLocator.Instance.GetService<IHexMap>();
            //var center = map.GetTile(map.Columns / 2, map.Rows / 2);
            //var dir = center.GetTop() - ent.transform.position;
            //dir.y = 0;
            //ent.transform.rotation = Quaternion.LookRotation(dir);
            ent.transform.rotation = Quaternion.Euler(0, Random.value * 360f, 0);

            Members.Add(ent);
            AliveMembers.Add(ent);
            _number++;
        }
예제 #27
0
        public static SingleGameObject CreateStaticAABB(IEntityManager manager, BoundingBox box)
        {
            var tag = new ElementTag("Physics Static " + Guid.NewGuid());

            var geobox = GeometryBuilder.BuildGeoBox(box);

            manager.CreateEntity(tag)
            .AddComponents(new IGraphicComponent[] {
                new SimpleGeometryComponent {
                    Positions = geobox.Positions.ToImmutableArray(),
                    Indices   = geobox.Indices.ToImmutableArray(),
                    Normals   = geobox.Positions.CalculateNormals(geobox.Indices).ToImmutableArray(),
                    Color     = new Vector4(1, 0, 0, 1)
                },
                new D3DTriangleColoredVertexRenderComponent(),
                TransformComponent.Identity(),
                PhysicalComponentFactory.CreateStaticAABB(),
            });

            return(new PhysicsObjectTest(tag));
        }
예제 #28
0
        public static TerrainGameObject CreateClipmaps(IEntityManager manager)
        {
            var tag = new ElementTag("Terrain");

            manager.CreateEntity(tag)
            .AddComponents(new IGraphicComponent[] {
                new D3DTerrainRenderComponent()
                {
                    CanRender = false
                },
                new Systems.TerrainConfigurationComponent {
                    Width  = 256,
                    Height = 256,
                },
                new TransformComponent(),
                new D3DTexturedMaterialSamplerComponent(),
                new ClipmapsTerrainComponent {
                },
            });

            return(new TerrainGameObject(tag));
        }
예제 #29
0
파일: Context.cs 프로젝트: Hengle/ECSLight
 /// <summary>
 /// Make a new entity, or recycle an unused entity.
 /// </summary>
 /// <returns>new empty entity</returns>
 public IEntity CreateEntity(string name = "")
 {
     return(_entityManager.CreateEntity(name));
 }
예제 #30
0
        /// <summary>
        /// The method creates a new entity within the context
        /// </summary>
        /// <param name="name">An optional parameter that specifies a name of the entity</param>
        /// <returns>An integer index that is an entity's identifier</returns>

        public EntityId CreateEntity(string name = null)
        {
            IEntity newEntity = mEntityManager.CreateEntity(name);

            return(newEntity.Id);
        }