public void AttributesTestsMethod()
        {
            EntityWorld world = new EntityWorld();
            world.PoolCleanupDelay = 1;
            world.InitializeAll();

            Debug.Assert(world.SystemManager.Systems.Size == 2);

            Entity et = world.CreateEntity();
            var power = et.AddComponentFromPool<Power2>();
            power.POWER = 100;
            et.Refresh();

            Entity et1 = world.CreateEntityFromTemplate("teste");
            Debug.Assert(et1 != null);

            {
                world.Update(0, ExecutionType.UpdateSynchronous);
            }

            et.RemoveComponent<Power2>();
            et.Refresh();

            {
                world.Update(0, ExecutionType.UpdateSynchronous);
            }

            et.AddComponentFromPool<Power2>();
            et.GetComponent<Power2>().POWER = 100;
            et.Refresh();

            world.Update(0, ExecutionType.UpdateSynchronous);
        }
 public Entity BuildEntity(Entity et1, EntityWorld world , params object[] args)
 {
     et1.AddComponent(new Power());
     et1.GetComponent<Power>().POWER = 100;
     et1.Refresh();
     return et1;
 }
Esempio n. 3
0
        protected override void Initialize()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            Type[] types = new Type[] {typeof(Enemy),typeof(Expires),typeof(Health),typeof(SpatialForm),typeof(Transform),typeof(Velocity),typeof(Weapon)};
            pool = new GamePool(100,types);
            pool.Initialize();

            spriteBatch = new SpriteBatch(GraphicsDevice);
            world = new EntityWorld();
            world.GetEntityManager().RemovedComponentEvent += new RemovedComponentHandler(RemovedComponent);
            world.SetPool(pool);

            font = Content.Load<SpriteFont>("Arial");
            SystemManager systemManager = world.GetSystemManager();
            renderSystem = systemManager.SetSystem(new RenderSystem(GraphicsDevice,spriteBatch,Content),ExecutionType.Draw);
            hudRenderSystem = systemManager.SetSystem(new HudRenderSystem(spriteBatch, font), ExecutionType.Draw);
            controlSystem = systemManager.SetSystem(new MovementSystem(spriteBatch), ExecutionType.Update,1);
            movementSystem = systemManager.SetSystem(new PlayerShipControlSystem(spriteBatch),ExecutionType.Update);
            enemyShooterSystem = systemManager.SetSystem(new EnemyShipMovementSystem(spriteBatch), ExecutionType.Update,1);
            enemyShipMovementSystem = systemManager.SetSystem(new EnemyShooterSystem(), ExecutionType.Update);
            collisionSystem = systemManager.SetSystem(new CollisionSystem(), ExecutionType.Update,1);
            healthBarRenderSystem = systemManager.SetSystem(new HealthBarRenderSystem(spriteBatch, font), ExecutionType.Draw);
            enemySpawnSystem = systemManager.SetSystem(new EnemySpawnSystem(500, spriteBatch), ExecutionType.Update);
            expirationSystem = systemManager.SetSystem(new ExpirationSystem(), ExecutionType.Update);

            systemManager.InitializeAll();

            InitPlayerShip();
            InitEnemyShips();

            base.Initialize();
        }
Esempio n. 4
0
        /// <summary>
        /// Allows the game to perform any initialization it needs to before starting to run.
        /// This is where it can query for any required services and load any non-graphic
        /// related content.  Calling base.Initialize will enumerate through any components
        /// and initialize them as well.
        /// </summary>
        protected override void Initialize()
        {
            // Create a new SpriteBatch, which can be used to draw textures.
            this.spriteBatch = new SpriteBatch(GraphicsDevice);

            // TODO: Add your initialization logic here
            this.world = new EntityWorld();

            this.world.SystemManager.SetSystem(new PlayerShipControlSystem(), ExecutionType.Update);
            this.world.SystemManager.SetSystem(new MovementSystem(this.GraphicsDevice), ExecutionType.Update);
            this.world.SystemManager.SetSystem(new RenderSystem(GraphicsDevice, this.spriteBatch), ExecutionType.Draw);

            this.world.SystemManager.InitializeAll();

            // initialize player
            Entity entity = this.world.CreateEntity();
            entity.AddComponent(new Placement(
                new Vector2(this.GraphicsDevice.Viewport.Width / 2, this.GraphicsDevice.Viewport.Height / 2),
                270.0f
            ));
            entity.AddComponent(new Acceleration());
            entity.AddComponent(new Velocity());
            entity.AddComponent(new SpatialForm(SpatialForms.Player));
            entity.Refresh();

            entity.Tag = "PLAYER";

            base.Initialize();
        }
Esempio n. 5
0
            public void Start()
            {
                GameWindow.Window = new RenderWindow(new VideoMode(1280, 720), "Subject2Change");
                GameWindow.Window.SetFramerateLimit(120);
                GameWindow.Window.SetVisible(true);

                GameWindow.Window.Closed += OnClosed;
                GameWindow.Window.KeyPressed += GameEventHandler.OnKeyPressed;
                GameWindow.Window.Resized += GameEventHandler.OnResized;
                GameWindow.Window.KeyReleased += GameEventHandler.OnKeyReleased;

                _world = new EntityWorld(false, true, true);

                //Entity camera = _world.CreateEntityFromTemplate("camera");
                EntityFactory.CreatePlayer(_world);

                Sprite testSprite = SFMLwrap.LoadSprite("test.png", SFMLwrap.DefaultScale);

                while (GameWindow.Window.IsOpen())
                {
                    GameWindow.Window.DispatchEvents();
                    GameWindow.Window.Clear(Color.Blue);
                    testSprite.Position = EntityFactory.Player.GetComponent<TransformC>().Position;
                    _world.Update();
                    //SpriteBatch batch = new SpriteBatch(GameWindow.Window);

                    GameWindow.Window.Draw(testSprite);
                    GameWindow.Window.Display();
                }
            }
Esempio n. 6
0
        public BattleWorld(IHeroesService heroesService, GraphicResources graphicResources)
        {
            _heroesService = heroesService;
            _content = graphicResources.Content;
            _entityWorld = new EntityWorld();
            var systemManager = _entityWorld.SystemManager;
            EntityCreator entityCreator = new EntityCreator(_entityWorld);
            BattleEngine.EntityCreator = entityCreator;
            _fighterManager = new FighterManager(_entityWorld);
            EntitySystem.BlackBoard.SetEntry("Resources", graphicResources);

            systemManager.SetSystem(new CharacterPlacingSystem(graphicResources), GameLoopType.Update, 0);
            systemManager.SetSystem(new EffectManagerSystem(), GameLoopType.Update, 0);
            systemManager.SetSystem(new MovingSystem(), GameLoopType.Update, 1);
            systemManager.SetSystem(new ActingSystem(), GameLoopType.Update, 3);
            systemManager.SetSystem(new AISkillSelectionSystem(_fighterManager), GameLoopType.Update, 4);
            systemManager.SetSystem(new ExpirationSystem(), GameLoopType.Update, 5);
            systemManager.SetSystem(new InputSkillSelectionSystem(_fighterManager, graphicResources), GameLoopType.Update, 5);
            systemManager.SetSystem(new AnimationSystem(entityCreator), GameLoopType.Update, 5);
            systemManager.SetSystem(new ParticleGeneratorSystem(), GameLoopType.Update, 5);

            systemManager.SetSystem(new ImageRenderingSystem(graphicResources), GameLoopType.Draw, 0);
            systemManager.SetSystem(new CharacterInfoRenderingSystem(graphicResources), GameLoopType.Draw, 1);
            systemManager.SetSystem(new ParticleRenderingSystem(graphicResources), GameLoopType.Draw, 1);
            systemManager.SetSystem(new ColoredTextRenderingSystem(graphicResources), GameLoopType.Draw, 2);
            systemManager.SetSystem(new InputSkillSelectionRenderingSystem(graphicResources), GameLoopType.Draw, 2);
        }
 /// <summary>Creates the test health entity with ID.</summary>
 /// <param name="entityWorld">The entity world.</param>
 /// <param name="id">The id.</param>
 /// <returns>The Entity.</returns>
 public static Entity CreateTestHealthEntityWithId(EntityWorld entityWorld, long id)
 {
     Entity entity = entityWorld.CreateEntity(id);
     entity.AddComponent(new TestHealthComponent());
     entity.GetComponent<TestHealthComponent>().Points = 100;            
     return entity;
 }
Esempio n. 8
0
        private IEnumerable Intro(Story story, EntityWorld world)
        {
            var bgGenerator = ServiceLocator.Instance.GetService<SpaceBackgroundGeneratorService>();
            bgGenerator.GenerateBackground(world, 12345);

            var entity = world.CreateStoryOverlay(Properties.Resources.String_ActOne_Intro01);

            yield return Coroutine.WaitFor(TimeSpan.FromSeconds(2));
            entity.FadeGuiElement(TimeSpan.FromSeconds(1.5), 0)
                .OnDone = () => entity.Delete();
            yield return Coroutine.WaitFor(TimeSpan.FromSeconds(2));

            var variant = new ShipVariant
            {
                HullId = "Jormugand",
                TrimDecalColor = Color.Cyan,
                BaseDecalColor = new Color(212, 113, 108),
            };
            _playerEntity = world.CreateShip(variant, new Vector2(500,0),0, physics:true);
            _playerEntity.Tag = "PlayerShip";
            _playerEntity.Refresh();
            var cameraControl = world.SystemManager.GetSystem<Systems.CameraControlSystem>();
            cameraControl.Mode = Systems.CameraMode.FollowEntity;
            cameraControl.FollowedEntity = _playerEntity;

            var test = world.CreateShip("mobius", new Vector2(0, 0), MathHelper.Pi * 1.5f, physics:true);
            test.GetComponent<ShipModelComponent>().BaseDecalColor = Color.Khaki;

            story.State.Fire(Story.Triggers.NextScene);
            yield return null;
        }
Esempio n. 9
0
 public SpriteSystem(EntityWorld world)
     : base(Aspect.All(
         typeof(Sprite),
         typeof(Renderable),
         typeof(Position)))
 {
     _world = world;
 }
Esempio n. 10
0
        public void Initialize(EntityWorld entityWorld, IEntityFactory entityFactory)
        {
            _entityWorld = entityWorld;
            EntityFactory = entityFactory;

            _entityWorld.EntityManager.AddedEntityEvent += OnEntityAdded;
            _entityWorld.EntityManager.RemovedEntityEvent += OnEntityRemoved;
        }
Esempio n. 11
0
 public HeartbeatSystem(IScriptManager scriptManager,
     EntityWorld world)
     : base(Aspect.All(typeof(Heartbeat),
         typeof(Script)))
 {
     _scriptManager = scriptManager;
     _world = world;
 }
Esempio n. 12
0
        public Entity BuildEntity(Entity e, EntityWorld world, params object[] args)
        {
            e.AddComponent(new Position());

            e.Refresh();

            return e;
        }
 public Entity BuildEntity(Entity entity, EntityWorld entityWorld, params object[] args)
 {
     var shipDef = Game.WorldConfiguration.Ships[args[0] as string];
     entity.AddComponent(new ModelComponent(shipDef.Model));
     entity.AddComponent(new SceneGraphNode());
     entity.AddComponent(shipDef);
     return entity;
 }
Esempio n. 14
0
 void Start()
 {
     world = new EntityWorld (false, true, true);
     world.InitializeAll (true);
     Entity e = world.CreateEntityFromTemplate ("Ship");
     GameObject obj = new GameObject("Ship");
     PhysicsRelay relay = obj.AddComponent<PhysicsRelay>();
     relay.SetEntity (e);
 }
Esempio n. 15
0
 public UnitController(InputManager inputManager, InputState inputState, EntityWorld entityWorld, DisFieldMixer disFieldMixer, Lord lord)
 {
     this.inputManager = inputManager;
     this.inputState = inputState;
     this.entityWorld = entityWorld;
     this.disFieldMixer = disFieldMixer;
     this.lord = lord;
     pathGoal = null;
 }
        /// <summary>The build entity.</summary>
        /// <param name="entity">The entity.</param>
        /// <param name="entityWorld">The entity world.</param>
        /// <param name="args">The args.</param>
        /// <returns>The built <see cref="Entity" />.</returns>
        public Entity BuildEntity(Entity entity, EntityWorld entityWorld, params object[] args)
        {
            entity.AddComponent(new TestPowerComponent());
            entity.GetComponent<TestPowerComponent>().Power = 100;

            entity.Refresh();

            return entity;
        }
Esempio n. 17
0
 public Entity BuildEntity(Entity entity, EntityWorld entityWorld, params object[] args)
 {
     PhysicsBody body = entity.AddComponentFromPool<SPShared.ECS.Components.PhysicsBody>();
     body.Body.Shape = shipShape;
     PhysicsSystem physicsSystem = entityWorld.SystemManager.GetSystem<PhysicsSystem>();
     physicsSystem.AddBody(body);
     physicsSystem.AddConstraint(new Constraint2D(body.Body));
     return entity;
 }
        // BuildEntity(entity, entityWorld)
        public static void LoadTiledMap(EntityWorld entityWorld, string mapFile, string tilesetLocation)
        {
            // Actual map entity. Contains map data. Rendering system draws map from this entity
            Entity tiledMapEntity = entityWorld.CreateEntity();
            tiledMapEntity.Tag = "map";
            tiledMapEntity.AddComponent(new TransformComponent());
            tiledMapEntity.AddComponent(new TiledMapComponent(mapFile, tilesetLocation));
            TmxMap tmxMap = tiledMapEntity.GetComponent<TiledMapComponent>().Map;
            List<Texture2D> textures = tiledMapEntity.GetComponent<TiledMapComponent>().Textures;

            // Farseer world associated with map
            Entity farseerWorldEntity = entityWorld.CreateEntity();
            farseerWorldEntity.AddComponent(new FarseerWorldComponent(9.81f));
            World world = farseerWorldEntity.GetComponent<FarseerWorldComponent>().world;
            
            foreach (var objLayer in tmxMap.ObjectGroups)
            {
                // Create entities for static objects in map
                // TODO: If there are performance issues, can optimize all static objects into single entity
                if (objLayer.Name == "collision")
                {
                    foreach (var tmxObj in objLayer.Objects)
                    {
                        Entity fixtureEntity = entityWorld.CreateEntity();
                        fixtureEntity.AddComponent(new FarseerFixtureComponent(tmxObj, world));
                    }
                }

                // Create dynamic objects
                // In particular starting location of player is in here
                if (objLayer.Name == "dynamic")
                {
                    foreach (var tmxObj in objLayer.Objects)
                    {
                        tmxObj.Properties.Add("BodyType", "Dynamic");
                        Entity dynamicEntity = entityWorld.CreateEntity();

                        if (tmxObj.Tile != null)
                        {
                            dynamicEntity.AddComponent(new TransformComponent());

                            Texture2D texture = GetTexture(tmxMap, textures, tmxObj.Tile.Gid);
                            dynamicEntity.AddComponent(new TextureComponent(texture));
                        }

                        dynamicEntity.AddComponent(new FarseerFixtureComponent(tmxObj, world));

                        if (tmxObj.Name == "player")
                        {
                            dynamicEntity.Tag = "player";
                        }
                    }
                }
            }

        }
Esempio n. 19
0
        public Entity CreateStandAloneEntity(EntityWorld world)
        {
            var entity = world.CreateEntity();
            entity.AddComponentFromPool<Transform>();
            entity.AddComponent(new SceneGraphComponent());
            entity.AddComponent(new SceneGraphRenderRoot<StandardShipModelRenderer>());
            CreateChildEntities(world, entity);

            return entity;
        }
Esempio n. 20
0
 public void CreateChildEntities(EntityWorld world, Entity parentEntity)
 {
     var modelComponent = new ShipModelComponent { Model = this };
     parentEntity.AddComponent(modelComponent);
     foreach (var part in Parts)
     {
         part.CreateEntity(world, parentEntity);
     }
     modelComponent.BoundingBox = CalculateBoundingBox(0);
 }
 public Entity BuildEntity(Entity e, EntityWorld world, params object[] args)
 {
     e.Group = "EFFECTS";
     e.AddComponentFromPool<Transform>();
     e.AddComponent(new SpatialForm());
     e.AddComponent(new Expires());
     e.GetComponent<SpatialForm>().SpatialFormFile = "ShipExplosion";
     e.GetComponent<Expires>().LifeTime = 1000;
     return e;
 }
        /// <summary>The build entity.</summary>
        /// <param name="entity">The entity.</param>
        /// <param name="entityWorld">The entityWorld.</param>
        /// <param name="args">The args.</param>
        /// <returns>The <see cref="Entity" />.</returns>
        public Entity BuildEntity(Entity entity, EntityWorld entityWorld, params object[] args)
        {
            entity.Group = "EFFECTS";

            entity.AddComponentFromPool<TransformComponent>();
            entity.AddComponent(new SpatialFormComponent("BulletExplosion"));
            entity.AddComponent(new ExpiresComponent(1000));

            return entity;
        }
Esempio n. 23
0
 public PlayerMovementSystem(IInputManager inputManager,
     EntityWorld world)
     : base(Aspect.All(typeof(Velocity),
         typeof(Position),
         typeof(PlayerAction),
         typeof(Sprite)))
 {
     _inputManager = inputManager;
     _world = world;
 }
Esempio n. 24
0
        public override Entity CreateEntity(EntityWorld world)
        {
            var entity = base.CreateEntity(world);
            var xform = entity.GetComponent<Transform>();
            xform.Scale *= (float)Math.Log(Radius) * 1e-1f;
            var pos = GetPositionAtTime(DateTime.Today);

            xform.Position = pos * 500;
            return entity;
        }
Esempio n. 25
0
 public FighterManager(EntityWorld world)
 {
     _world = world;
     _fighters = new Dictionary<bool,Dictionary<bool,List<Entity>>>();
     _fighters.Add(true, new Dictionary<bool,List<Entity>>());
     _fighters.Add(false, new Dictionary<bool,List<Entity>>());
     _fighters[true].Add(true, new List<Entity>());
     _fighters[true].Add(false, new List<Entity>());
     _fighters[false].Add(true, new List<Entity>());
     _fighters[false].Add(false, new List<Entity>());
 }
        /// <summary>The build entity.</summary>
        /// <param name="entity">The entity.</param>
        /// <param name="entityWorld">The entityWorld.</param>
        /// <param name="args">The args.</param>
        /// <returns>The <see cref="Entity" />.</returns>
        public Entity BuildEntity(Entity entity, EntityWorld entityWorld, params object[] args)
        {
            entity.Group = "BULLETS";

            entity.AddComponentFromPool<TransformComponent>();
            entity.AddComponent(new SpatialFormComponent("Missile"));
            entity.AddComponent(new VelocityComponent());
            entity.AddComponent(new ExpiresComponent(2000));

            return entity;
        }
Esempio n. 27
0
        public EntityIdSystem(EntityWorld entityWorld)
            : base()
        {
            entityWorld.EntityManager.AddedEntityEvent += (Entity entity) =>
            {
                Debug.Log("setting new entity id");
                setId(entity);
                Debug.Log("New id:"+ entity.entityId);

            };
        }
        public Entity BuildEntity(Entity e, EntityWorld world, params object[] args)
        {
            e.Group = "BULLETS";

            e.AddComponentFromPool<Transform>();
            e.AddComponent(new SpatialForm());
            e.AddComponent(new Velocity());
            e.AddComponent(new Expires());
            e.GetComponent<SpatialForm>().SpatialFormFile = "Missile";
            e.GetComponent<Expires>().LifeTime = 2000;
            return e;
        }
Esempio n. 29
0
 public override Entity CreateEntity(EntityWorld world, Entity ship, Entity parent, int? index = default(int?))
 {
     var entity = world.CreateEntity();
     parent.AddChild(entity);
     var xform = entity.AddComponentFromPool<Transform>();
     xform.CopyValuesFrom(Transform);
     var component = new DummyPartComponent(this, ship);
     entity.AddComponent(component);
     entity.AddComponent<IShipPartComponent>(component);
     entity.AddComponent(new BoundingBoxComponent(new FloatRect(-10, -10, 20, 20)));
     return entity;
 }
Esempio n. 30
0
        static void multsystem()
        {
            healthBag.Add(new Health());
            healthBag.Add(new Health());
            componentPool.Add(typeof(Health), healthBag);

            Bag<Component> tempBag;
            EntityWorld world = new EntityWorld();
            SystemManager systemManager = world.GetSystemManager();
            world.GetEntityManager().RemovedComponentEvent += new RemovedComponentHandler(RemovedComponent);
            world.GetEntityManager().RemovedEntityEvent += new RemovedEntityHandler(RemovedEntity);            
            EntitySystem hs = systemManager.SetSystem(new SingleHealthBarRenderSystem(),ExecutionType.Update);
            hs = systemManager.SetSystem(new DummySystem(),ExecutionType.Update);
            hs = systemManager.SetSystem(new DummySystem2(),ExecutionType.Update);
            hs = systemManager.SetSystem(new DummySystem3(),ExecutionType.Update);
            systemManager.InitializeAll();           
            

            List<Entity> l = new List<Entity>();
            for (int i = 0; i < 100000; i++)
            {
                Entity et = world.CreateEntity();
                et.AddComponent(new Health());
                et.GetComponent<Health>().AddHealth(100);
                et.Refresh();
                l.Add(et);
            }

            for (int i = 0; i < 100; i++)
            {
                DateTime dt = DateTime.Now;
                world.LoopStart();
                //manager.UpdateAsynchronous();
                systemManager.UpdateSynchronous(ExecutionType.Update);
                Console.WriteLine((DateTime.Now - dt).TotalMilliseconds);
            }

            //int df = 0;
            //foreach (var item in l)
            //{
            //    if (item.GetComponent<Health>().GetHealth() == 90)
            //    {
            //        df++;
            //    }
            //    else
            //    {
            //        Console.WriteLine("errro");
            //    }
            //}

            Console.ReadLine();
        }
 public SystemManager(EntityWorld world)
 {
     this.world = world;
 }
Esempio n. 32
0
 /// <summary>Gets the component mapper for.</summary>
 /// <typeparam name="TK">The <see langword="Type" /> TK.</typeparam>
 /// <param name="type">The type.</param>
 /// <param name="entityWorld">The entity world.</param>
 /// <returns>The ComponentMapper.</returns>
 public static ComponentMapper <TK> GetComponentMapperFor <TK>(TK type, EntityWorld entityWorld) where TK : IComponent
 {
     return(new ComponentMapper <TK>(entityWorld));
 }
Esempio n. 33
0
        private Bag <Component> entityComponents = new Bag <Component>();       // Added for debug support.

        public EntityManager(EntityWorld world)
        {
            System.Diagnostics.Debug.Assert(world != null);
            this.world = world;
        }
Esempio n. 34
0
 internal TagManager(EntityWorld world)
 {
     this.world = world;
 }
Esempio n. 35
0
 internal GroupManager(EntityWorld world)
 {
     this.world = world;
 }
Esempio n. 36
0
 public Entity(EntityWorld world, int id)
 {
     this.world         = world;
     this.entityManager = world.GetEntityManager();
     this.id            = id;
 }
 public void SetWorld(EntityWorld world)
 {
     this.world = world;
 }
 public GroupManager(EntityWorld world)
 {
     this.world = world;
 }
Esempio n. 39
0
 /// <summary>
 /// Creates a component mapper within the given Entity World
 /// </summary>
 /// <param name="world">EntityWorld</param>
 public ComponentMapper(EntityWorld world)
 {
     System.Diagnostics.Debug.Assert(world != null);
     em   = world.EntityManager;
     type = ComponentTypeManager.GetTypeFor <T>();
 }
Esempio n. 40
0
 internal Entity(EntityWorld world, int id)
 {
     this.world         = world;
     this.entityManager = world.EntityManager;
     this.id            = id;
 }
Esempio n. 41
0
 internal SystemManager(EntityWorld world)
 {
     this.world = world;
 }
        private Bag <Component> entityComponents = new Bag <Component>();       // Added for debug support.

        public EntityManager(EntityWorld world)
        {
            this.world = world;
        }
Esempio n. 43
0
 public ComponentMapper(EntityWorld world)
 {
     this.em   = world.GetEntityManager();
     this.type = ComponentTypeManager.GetTypeFor <T>();
 }