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); }
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); }
public void Initialize() { _networkAgent = new NetworkAgent(AgentRole.Server, "Umbra"); _networkAgent.OnPlayerConnect += OnPlayerConnect; _networkAgent.OnPlayerDisconnect += OnPlayerDisconnect; EntitySystem.BlackBoard.SetEntry("NetworkAgent", _networkAgent); _entityWorld = new EntityWorld(); _entityWorld.InitializeAll(new[] { GetType().Assembly }); CrawEntityManager.Instance.Initialize(_entityWorld, new ServerEntityFactory(_entityWorld)); }
protected override void Initialize() { ConvertUnits.SetDisplayUnitToSimUnitRatio(16f); spriteBatch = new SpriteBatch(GraphicsDevice); entityWorld = new EntityWorld(); EntitySystem.BlackBoard.SetEntry("ContentManager", this.Content); EntitySystem.BlackBoard.SetEntry("GraphicsDevice", this.GraphicsDevice); EntitySystem.BlackBoard.SetEntry("SpriteBatch", this.spriteBatch); entityWorld.InitializeAll(true); base.Initialize(); }
public void DummyTests() { EntityWorld world = new EntityWorld(); SystemManager systemManager = world.SystemManager; DummyCommunicationSystem DummyCommunicationSystem = new DummyCommunicationSystem(); systemManager.SetSystem(DummyCommunicationSystem, ExecutionType.UpdateSynchronous); world.InitializeAll(false); for (int i = 0; i < 100; i++) { Entity et = world.CreateEntity(); et.AddComponent(new Health()); et.GetComponent<Health>().HP += 100; et.Group = "teste"; et.Refresh(); } { Entity et = world.CreateEntity(); et.Tag = "tag"; et.AddComponent(new Health()); et.GetComponent<Health>().HP += 100; et.Refresh(); } { DateTime dt = DateTime.Now; world.Update(0); Console.WriteLine((DateTime.Now - dt).TotalMilliseconds); } Debug.Assert(world.TagManager.GetEntity("tag") != null); Debug.Assert(world.GroupManager.GetEntities("teste").Size == 100); Debug.Assert(world.EntityManager.ActiveEntitiesCount == 101); Debug.Assert(world.SystemManager.Systems.Size == 1); }
protected override void Initialize() { spriteBatch = new SpriteBatch(GraphicsDevice); _netAgent = new NetworkAgent(AgentRole.Client, "Umbra"); EntitySystem.BlackBoard.SetEntry("Game", this); EntitySystem.BlackBoard.SetEntry("ContentManager", Content); EntitySystem.BlackBoard.SetEntry("SpriteBatch", spriteBatch); EntitySystem.BlackBoard.SetEntry("GraphicsDevice", GraphicsDevice); EntitySystem.BlackBoard.SetEntry("ContentManager", Content); EntitySystem.BlackBoard.SetEntry("NetworkAgent", _netAgent); _entityWorld = new EntityWorld(); // create camera Vector3 camPosition = new Vector3(0, 10, 5); Matrix camRotation = Matrix.CreateFromAxisAngle(new Vector3(1, 0, 0), MathHelper.ToRadians(-65.0f)); float aspectRatio = (float)GraphicsDevice.Viewport.Width / GraphicsDevice.Viewport.Height; CameraComponent cameraComponent = new CameraComponent(camPosition, camRotation, aspectRatio); Entity cameraEntity = _entityWorld.CreateEntity(); cameraEntity.AddComponent(cameraComponent); EntitySystem.BlackBoard.SetEntry("Camera", cameraComponent); //// TEMP //// Map map = new Map(100, 100); Entity mapEntity = _entityWorld.CreateEntity(); mapEntity.AddComponent(new TileMapComponent(map)); EntitySystem.BlackBoard.SetEntry("Map", map); //// TEMP //// _entityWorld.InitializeAll(new[] { GetType().Assembly }); CrawEntityManager.Instance.Initialize(_entityWorld, new ClientEntityFactory(_entityWorld)); _netAgent.Connect("127.0.0.1"); base.Initialize(); }
public void TestAttributes() { Debug.WriteLine("Initialize EntityWorld: "); EntityWorld entityWorld = new EntityWorld { PoolCleanupDelay = 1 }; #if (!FULLDOTNET && !METRO) || CLIENTPROFILE entityWorld.InitializeAll(global::System.Reflection.Assembly.GetExecutingAssembly()); #else entityWorld.InitializeAll(true); #endif Debug.WriteLine("OK"); const int ExpectedNumberOfSystems = 2; int actualNumberOfSystems = entityWorld.SystemManager.Systems.Count; Assert.AreEqual(ExpectedNumberOfSystems, actualNumberOfSystems, "Number of initial systems does not fit."); Debug.WriteLine("Number of Systems: {0} OK", actualNumberOfSystems); Debug.WriteLine("Build up entity with component from pool manually: "); Entity entityWithPooledComponent = TestEntityFactory.CreateTestPowerEntityWithPooledComponent(entityWorld); Debug.WriteLine("OK"); Debug.WriteLine("Build up entity from template: "); Entity entityFromTemplate = entityWorld.CreateEntityFromTemplate("test"); Assert.IsNotNull(entityFromTemplate, "Entity from test template is null."); Debug.WriteLine("OK"); entityWorld.Update(); entityWorld.Draw(); Debug.WriteLine("Remove component from entity: "); entityWithPooledComponent.RemoveComponent<TestPowerComponentPoolable>(); entityWorld.Update(); entityWorld.Draw(); Assert.IsFalse(entityWithPooledComponent.HasComponent<TestPowerComponentPoolable>(), "Entity has still deleted component."); Debug.WriteLine("OK"); Debug.WriteLine("Add component to entity: "); entityWithPooledComponent.AddComponentFromPool<TestPowerComponentPoolable>(); entityWithPooledComponent.GetComponent<TestPowerComponentPoolable>().Power = 100; entityWorld.Update(); entityWorld.Draw(); Assert.IsTrue(entityWithPooledComponent.HasComponent<TestPowerComponentPoolable>(), "Could not add component to entity."); Debug.WriteLine("OK"); }
internal void Initialize(D3D11Host host) { Services = new GameServiceContainer(); ServiceLocator.Initialize(Services); Artemis.System.EntitySystem.BlackBoard.SetEntry("GraphicsDevice", host.GraphicsDevice); Artemis.System.EntitySystem.BlackBoard.SetEntry("ServiceProvider", Services); Services.AddService<IGraphicsDeviceService>(host); Services.AddService(host.GraphicsDevice); _mouse = new MouseService(host); Services.AddService<IMouseService>(_mouse); _mouse.ButtonDown += OnMouseButtonDown; _keyboard = new KeyboardService(host); Services.AddService<IKeyboardService>(_keyboard); _timer = new TimerService(); Services.AddService<ITimerService>(_timer); Services.AddService(new FastSpriteBatch(host.GraphicsDevice)); _timer.LastFrameUpdateTime = _gameTime; _timer.LastFrameRenderTime = _gameTime; SpriteBatch = new SpriteBatch(host.GraphicsDevice); Services.AddService(SpriteBatch); Content = new ContentManager(Services); Content.RootDirectory = Environment.CurrentDirectory; SpriteManager = new SpriteManagerService(Content); Services.AddService<ISpriteManagerService>(SpriteManager); SpriteManager.LoadSpriteSheet("Textures/Hulls.json"); Host = host; World = new EntityWorld(false, false, false); int drawDepth = 0; World.CreateComponentPool<Transform>(200, 200); World.SystemManager.SetSystem(new GridRendererSystem(), Artemis.Manager.GameLoopType.Draw, drawDepth++); World.InitializeAll(); World.CreateCamera(Constants.ActiveCameraTag, Host.GraphicsDevice); Emitter = new ParticleEmitterComponent(); }
protected override void Initialize() { // make root world and build to it RootWorld = new EntityWorld(); RootWorld.InitializeAll(true); TTFactory.BuildTo(RootWorld); // make root screen and build to it RootScreen = new ScreenComp(false, 0, 0); TTFactory.BuildTo(RootScreen); // make the MainChannel and build to it MainChannel = TTFactory.CreateChannel(Color.CornflowerBlue); MainChannelScreen = MainChannel.GetComponent<WorldComp>().Screen; TTFactory.BuildTo(MainChannel); // the TTMusicEngine if (IsAudio) { AudioEngine = MusicEngine.GetInstance(); AudioEngine.AudioPath = "Content"; if (!AudioEngine.Initialize()) throw new Exception(AudioEngine.StatusMsg); } base.Initialize(); }
public void TestSimpleSystem() { Debug.WriteLine("Initialize EntityWorld: "); EntityWorld entityWorld = new EntityWorld(); entityWorld.SystemManager.SetSystem(new TestNormalEntityProcessingSystem1(), GameLoopType.Update); entityWorld.InitializeAll(); Debug.WriteLine("OK"); Entity entity1 = TestEntityFactory.CreateTestHealthEntity(entityWorld); Assert.IsNotNull(entity1); Entity entity2 = TestEntityFactory.CreateTestPowerEntity(entityWorld); Assert.IsNotNull(entity2); Stopwatch stopwatch = Stopwatch.StartNew(); entityWorld.Update(); entityWorld.Draw(); stopwatch.Stop(); #if DEBUG Debug.WriteLine("Processed update and draw with duration {0} for {1} elements", FastDateTime.ToString(stopwatch.Elapsed), entityWorld.EntityManager.EntitiesRequestedCount); #else Debug.WriteLine("Processed update and draw with duration {0} for {1} elements", FastDateTime.ToString(stopwatch.Elapsed), entityWorld.EntityManager.ActiveEntities.Count); #endif const float Expected1 = 90.0f; Assert.AreEqual(Expected1, entity1.GetComponent<TestHealthComponent>().Points); const float Expected2 = 100.0f; Assert.AreEqual(Expected2, entity2.GetComponent<TestHealthComponent>().Points); Assert.AreEqual(Expected2, entity2.GetComponent<TestPowerComponent>().Power); }
public void TestSystemCommunication() { Debug.WriteLine("Initialize EntityWorld: "); EntitySystem.BlackBoard.SetEntry("Damage", 5); EntityWorld entityWorld = new EntityWorld(); entityWorld.SystemManager.SetSystem(new TestCommunicationSystem(), GameLoopType.Update); entityWorld.InitializeAll(); Debug.WriteLine("OK"); Debug.WriteLine("Fill EntityWorld with " + Load + " entities: "); List<Entity> entities = new List<Entity>(); for (int index = Load; index >= 0; --index) { Entity entity = TestEntityFactory.CreateTestHealthEntity(entityWorld); entities.Add(entity); } Debug.WriteLine("OK"); Stopwatch stopwatch = Stopwatch.StartNew(); entityWorld.Update(); entityWorld.Draw(); stopwatch.Stop(); Debug.WriteLine("Update 1 duration: {0}", FastDateTime.ToString(stopwatch.Elapsed)); EntitySystem.BlackBoard.SetEntry("Damage", 10); stopwatch.Restart(); entityWorld.Update(); entityWorld.Draw(); stopwatch.Stop(); Debug.WriteLine("Update 2 duration: {0}", FastDateTime.ToString(stopwatch.Elapsed)); Debug.WriteLine("Test entities: "); const float Expected = 85.0f; foreach (Entity item in entities) { Assert.AreEqual(Expected, item.GetComponent<TestHealthComponent>().Points); } Debug.WriteLine("OK"); EntitySystem.BlackBoard.RemoveEntry("Damage"); }
public void SecondMostSimpleSystemEverTest() { EntityWorld world = new EntityWorld(); world.InitializeAll(true); Entity et = world.CreateEntity(); et.AddComponent(new Health()); et.GetComponent<Health>().HP = 100; et.Refresh(); Entity et1 = world.CreateEntity(); et1.AddComponent(new Power()); et1.GetComponent<Power>().POWER = 100; et1.Refresh(); { world.Update(0); } ///two systems runnning ///each remove 10 HP Debug.Assert(et.GetComponent<Health>().HP == 80); Debug.Assert(et1.GetComponent<Power>().POWER == 90); }
public void TestMultipleSystems() { Debug.WriteLine("Initialize EntityWorld: "); HealthBag.Clear(); ComponentPool.Clear(); HealthBag.Add(new TestHealthComponent()); HealthBag.Add(new TestHealthComponent()); ComponentPool.Add(typeof(TestHealthComponent), HealthBag); EntityWorld entityWorld = new EntityWorld(); entityWorld.EntityManager.RemovedComponentEvent += RemovedComponent; entityWorld.EntityManager.RemovedEntityEvent += RemovedEntity; entityWorld.SystemManager.SetSystem(new TestRenderHealthBarSingleSystem(), GameLoopType.Update); entityWorld.SystemManager.SetSystem(new TestEntityProcessingSystem1(), GameLoopType.Update); entityWorld.SystemManager.SetSystem(new TestEntityProcessingSystem2(), GameLoopType.Update); entityWorld.SystemManager.SetSystem(new TestEntityProcessingSystem3(), GameLoopType.Update); entityWorld.InitializeAll(); Debug.WriteLine("OK"); Debug.WriteLine("Fill EntityWorld with " + Load + " entities: "); List<Entity> entities = new List<Entity>(); for (int index = Load - 1; index >= 0; --index) { Entity entity = TestEntityFactory.CreateTestHealthEntity(entityWorld); entities.Add(entity); } Debug.WriteLine("OK"); const int Passes = 3; Stopwatch stopwatch = Stopwatch.StartNew(); for (int index = 0; index < Passes; ++index) { entityWorld.Update(); entityWorld.Draw(); } stopwatch.Stop(); Debug.WriteLine("Update (" + Passes + " passes) duration: {0}", FastDateTime.ToString(stopwatch.Elapsed)); /* int df = 0; foreach (Entity entity in entities) { if (Math.Abs(entity.GetComponent<TestHealthComponent>().Points - 90) < float.Epsilon) { df++; } else { Debug.WriteLine("Error " + df); } } */ }
/// <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. spriteBatch = new SpriteBatch(GraphicsDevice); font = Content.Load<SpriteFont>("myFont"); world = new EntityWorld(); EntitySystem.BlackBoard.SetEntry<ContentManager>("ContentManager", Content); EntitySystem.BlackBoard.SetEntry<GraphicsDevice>("GraphicsDevice", GraphicsDevice); EntitySystem.BlackBoard.SetEntry<SpriteBatch>("SpriteBatch", spriteBatch); EntitySystem.BlackBoard.SetEntry<SpriteFont>("SpriteFont", font); EntitySystem.BlackBoard.SetEntry<int>("EnemyInterval", 500); world.InitializeAll(); InitPlayerShip(); InitEnemyShips(); base.Initialize(); }
public void QueueSystemTeste() { EntityWorld world = new EntityWorld(); SystemManager systemManager = world.SystemManager; QueueSystemTest QueueSystemTest = new ArtemisTest.QueueSystemTest(); QueueSystemTest QueueSystemTest2 = new ArtemisTest.QueueSystemTest(); systemManager.SetSystem(QueueSystemTest, ExecutionType.UpdateAsynchronous); systemManager.SetSystem(QueueSystemTest2, ExecutionType.UpdateAsynchronous); QueueSystemTest2 QueueSystemTestteste = new ArtemisTest.QueueSystemTest2(); systemManager.SetSystem(QueueSystemTestteste, ExecutionType.UpdateAsynchronous); world.InitializeAll(false); QueueSystemTest.SetQueueProcessingLimit(20, QueueSystemTest.Id); Debug.Assert(QueueSystemTest.GetQueueProcessingLimit(QueueSystemTest.Id) == QueueSystemTest.GetQueueProcessingLimit(QueueSystemTest2.Id)); Debug.Assert(QueueSystemTest.GetQueueProcessingLimit(QueueSystemTestteste.Id) != QueueSystemTest.GetQueueProcessingLimit(QueueSystemTest2.Id)); QueueSystemTest.SetQueueProcessingLimit(1000, QueueSystemTest.Id); QueueSystemTest.SetQueueProcessingLimit(2000, QueueSystemTestteste.Id); List<Entity> l = new List<Entity>(); for (int i = 0; i < 1000000; i++) { Entity et = world.CreateEntity(); et.AddComponent(new Health()); et.GetComponent<Health>().HP = 100; QueueSystemTest.AddToQueue(et, QueueSystemTest.Id); l.Add(et); } List<Entity> l2 = new List<Entity>(); for (int i = 0; i < 1000000; i++) { Entity et = world.CreateEntity(); et.AddComponent(new Health()); et.GetComponent<Health>().HP = 100; QueueSystemTest.AddToQueue(et, QueueSystemTestteste.Id); l2.Add(et); } Console.WriteLine("Start"); while (QueueSystemTest.QueueCount(QueueSystemTest.Id) > 0 || QueueSystemTest.QueueCount(QueueSystemTestteste.Id) > 0) { DateTime dt = DateTime.Now; world.Update(0, ExecutionType.UpdateAsynchronous); Console.WriteLine("Count: " + QueueSystemTest.QueueCount(QueueSystemTest.Id)); Console.WriteLine("Time: " + (DateTime.Now - dt).TotalMilliseconds); } Console.WriteLine("End"); foreach (var item in l) { Debug.Assert(item.GetComponent<Health>().HP == 90); } foreach (var item in l2) { Debug.Assert(item.GetComponent<Health>().HP == 80); } }
public void multsystem() { healthBag.Clear(); componentPool.Clear(); healthBag.Add(new Health()); healthBag.Add(new Health()); componentPool.Add(typeof(Health), healthBag); EntityWorld world = new EntityWorld(); SystemManager systemManager = world.SystemManager; world.EntityManager.RemovedComponentEvent += new RemovedComponentHandler(RemovedComponent); world.EntityManager.RemovedEntityEvent += new RemovedEntityHandler(RemovedEntity); EntitySystem hs = systemManager.SetSystem(new SingleHealthBarRenderSystem(),ExecutionType.UpdateAsynchronous); hs = systemManager.SetSystem(new DummySystem(),ExecutionType.UpdateAsynchronous); hs = systemManager.SetSystem(new DummySystem2(), ExecutionType.UpdateAsynchronous); hs = systemManager.SetSystem(new DummySystem3(), ExecutionType.UpdateAsynchronous); world.InitializeAll(false); List<Entity> l = new List<Entity>(); for (int i = 0; i < 100000; i++) { Entity et = world.CreateEntity(); et.AddComponent(new Health()); et.GetComponent<Health>().HP += 100; et.Refresh(); l.Add(et); } for (int i = 0; i < 100; i++) { DateTime dt = DateTime.Now; world.Update(0,ExecutionType.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"); // } //} }
public void multi() { healthBag.Add(new Health()); healthBag.Add(new Health()); componentPool.Add(typeof(Health), healthBag); EntityWorld world = new EntityWorld(); SystemManager systemManager = world.SystemManager; world.EntityManager.RemovedComponentEvent += new RemovedComponentHandler(RemovedComponent); world.EntityManager.RemovedEntityEvent += new RemovedEntityHandler(RemovedEntity); EntitySystem hs = systemManager.SetSystem(new MultHealthBarRenderSystem(), ExecutionType.UpdateSynchronous); world.InitializeAll(false); List<Entity> l = new List<Entity>(); for (int i = 0; i < 1000; i++) { Entity et = world.CreateEntity(); et.AddComponent(new Health()); et.GetComponent<Health>().HP += 100; et.Refresh(); l.Add(et); } for (int i = 0; i < 100; i++) { DateTime dt = DateTime.Now; world.Update(0); Console.WriteLine((DateTime.Now - dt).TotalMilliseconds); } int df = 0; foreach (var item in l) { if (item.GetComponent<Health>().HP == 90) { df++; } } }
public void MostSimpleSystemEverTest() { EntityWorld world = new EntityWorld(); SystemManager systemManager = world.SystemManager; MostSimpleSystemEver DummyCommunicationSystem = new MostSimpleSystemEver(); systemManager.SetSystem(DummyCommunicationSystem, ExecutionType.UpdateSynchronous); world.InitializeAll(false); Entity et = world.CreateEntity(); et.AddComponent(new Health()); et.GetComponent<Health>().HP = 100; et.Refresh(); Entity et1 = world.CreateEntity(); et1.AddComponent(new Health()); et1.AddComponent(new Power()); et1.GetComponent<Health>().HP = 100; et1.GetComponent<Power>().POWER = 100; et1.Refresh(); { DateTime dt = DateTime.Now; world.Update(0); Console.WriteLine((DateTime.Now - dt).TotalMilliseconds); } Debug.Assert(et.GetComponent<Health>().HP == 90); Debug.Assert(et1.GetComponent<Health>().HP == 100); Debug.Assert(et1.GetComponent<Power>().POWER == 100); }
public void TestDummies() { Debug.WriteLine("Initialize EntityWorld: "); EntityWorld entityWorld = new EntityWorld(); entityWorld.SystemManager.SetSystem(new TestCommunicationSystem(), GameLoopType.Update); entityWorld.InitializeAll(); Debug.WriteLine("OK"); Debug.WriteLine("Fill EntityWorld with " + Load + " grouped entities: "); for (int index = Load - 1; index >= 0; --index) { TestEntityFactory.CreateTestHealthEntity(entityWorld, "test"); } Debug.WriteLine("OK"); Debug.WriteLine("Add a tagged entity to EntityWorld: "); TestEntityFactory.CreateTestHealthEntity(entityWorld, null, "tag"); Debug.WriteLine("OK"); Debug.WriteLine("Update EntityWorld: "); Stopwatch stopwatch = Stopwatch.StartNew(); entityWorld.Update(); entityWorld.Draw(); stopwatch.Stop(); Debug.WriteLine("duration " + FastDateTime.ToString(stopwatch.Elapsed) + " "); Debug.WriteLine("OK"); int actualNumberOfSystems = entityWorld.SystemManager.Systems.Count; const int ExpectedNumberOfSystems = 1; Debug.WriteLine("Number of Systems: {0} ", actualNumberOfSystems); Assert.AreEqual(ExpectedNumberOfSystems, actualNumberOfSystems); Debug.WriteLine("OK"); Entity actualTaggedEntity = entityWorld.TagManager.GetEntity("tag"); Debug.WriteLine("Is tagged entity present: {0} ", actualTaggedEntity != null); Assert.IsNotNull(actualTaggedEntity); Debug.WriteLine("OK"); int actualNumberOfGroupedEntities = entityWorld.GroupManager.GetEntities("test").Count; const int ExpectedNumberOfGroupedEntities = Load; Debug.WriteLine("Number of grouped entities: {0} ", actualNumberOfGroupedEntities); Assert.AreEqual(ExpectedNumberOfGroupedEntities, actualNumberOfGroupedEntities); Debug.WriteLine("OK"); #if DEBUG int actualNumberOfActiveEntities = entityWorld.EntityManager.EntitiesRequestedCount; const int ExpectedNumberOfActiveEntities = ExpectedNumberOfGroupedEntities + ExpectedNumberOfSystems; Debug.WriteLine("Number of active entities: {0} ", actualNumberOfActiveEntities); Assert.AreEqual(ExpectedNumberOfActiveEntities, actualNumberOfActiveEntities); Debug.WriteLine("OK"); #endif }
public void SystemComunicationTeste() { EntitySystem.BlackBoard.SetEntry<int>("Damage", 5); EntityWorld world = new EntityWorld(); SystemManager systemManager = world.SystemManager; DummyCommunicationSystem DummyCommunicationSystem = new DummyCommunicationSystem(); systemManager.SetSystem(DummyCommunicationSystem, ExecutionType.UpdateSynchronous); world.InitializeAll(false); List<Entity> l = new List<Entity>(); for (int i = 0; i < 100; i++) { Entity et = world.CreateEntity(); et.AddComponent(new Health()); et.GetComponent<Health>().HP += 100; et.Refresh(); l.Add(et); } { DateTime dt = DateTime.Now; world.Update(0); Console.WriteLine((DateTime.Now - dt).TotalMilliseconds); } EntitySystem.BlackBoard.SetEntry<int>("Damage", 10); { DateTime dt = DateTime.Now; world.Update(0); Console.WriteLine((DateTime.Now - dt).TotalMilliseconds); } foreach (var item in l) { Debug.Assert(item.GetComponent<Health>().HP == 85); } }
public void TestHybridQueueSystem() { Debug.WriteLine("Initialize EntityWorld: "); EntityWorld entityWorld = new EntityWorld(); TestQueueHybridSystem testQueueHybridSystem = entityWorld.SystemManager.SetSystem(new TestQueueHybridSystem(), GameLoopType.Update); entityWorld.InitializeAll(); Debug.WriteLine("OK"); const int Chunk = 500; Debug.WriteLine("Fill EntityWorld with first chunk of " + Chunk + " entities: "); List<Entity> entities = new List<Entity>(); for (int index = Chunk; index > 0; --index) { entities.Add(TestEntityFactory.CreateTestHealthEntity(entityWorld)); } Debug.WriteLine("OK"); Debug.WriteLine("Fill EntityWorld with second chunk of " + Chunk + " entities: "); for (int index = Chunk; index > 0; --index) { Entity entity = TestEntityFactory.CreateTestHealthEntity(entityWorld); testQueueHybridSystem.AddToQueue(entity); entities.Add(entity); } Debug.WriteLine("OK"); Stopwatch stopwatch = Stopwatch.StartNew(); int numberOfQueues = 0; while (testQueueHybridSystem.QueueCount > 0) { ++numberOfQueues; entityWorld.Update(); entityWorld.Draw(); } stopwatch.Stop(); Debug.WriteLine("Processed {0} hybrid queues with duration {1}", numberOfQueues, FastDateTime.ToString(stopwatch.Elapsed)); Debug.WriteLine("Test first chunk: "); float expectedPointsFirstChunk = 100.0f - (10 * numberOfQueues); if (expectedPointsFirstChunk < 0.0f) { Debug.WriteLine("Results may be inaccurate. Please lower chunk size. "); expectedPointsFirstChunk = 0.0f; } for (int index = Chunk - 1; index >= 0; --index) { Assert.AreEqual(expectedPointsFirstChunk, entities[index].GetComponent<TestHealthComponent>().Points, "Index:<" + index + ">."); } Debug.WriteLine("OK"); Debug.WriteLine("Test second chunk: "); float expectedPointsSecondChunk = 90.0f - (10 * numberOfQueues); if (expectedPointsSecondChunk < 0.0f) { Debug.WriteLine("Results may be inaccurate. Please lower chunk size. "); expectedPointsSecondChunk = 0.0f; } for (int index = (Chunk * 2) - 1; index >= Chunk; --index) { Assert.AreEqual(expectedPointsSecondChunk, entities[index].GetComponent<TestHealthComponent>().Points, "Index:<" + index + ">."); } Debug.WriteLine("OK"); }
public void TestRenderMultiHealthBarSystem() { Debug.WriteLine("Initialize EntityWorld: "); HealthBag.Clear(); ComponentPool.Clear(); HealthBag.Add(new TestHealthComponent()); HealthBag.Add(new TestHealthComponent()); ComponentPool.Add(typeof(TestHealthComponent), HealthBag); EntityWorld entityWorld = new EntityWorld(); entityWorld.EntityManager.RemovedComponentEvent += RemovedComponent; entityWorld.EntityManager.RemovedEntityEvent += RemovedEntity; entityWorld.SystemManager.SetSystem(new TestRenderHealthBarMultiSystem(), GameLoopType.Update); entityWorld.InitializeAll(); Debug.WriteLine("OK"); Debug.WriteLine("Fill EntityWorld with " + Load + " entities: "); List<Entity> entities = new List<Entity>(); for (int index = Load - 1; index >= 0; --index) { Entity entity = TestEntityFactory.CreateTestHealthEntity(entityWorld); entities.Add(entity); } Debug.WriteLine("OK"); const int Passes = 9; Stopwatch stopwatch = Stopwatch.StartNew(); for (int index = 0; index < Passes; ++index) { entityWorld.Update(); entityWorld.Draw(); } stopwatch.Stop(); Debug.WriteLine("Update (" + Passes + " passes) duration: {0}", FastDateTime.ToString(stopwatch.Elapsed)); int expectedPoints = 100 - (Passes * 10); if (expectedPoints < 0) { expectedPoints = 0; } int df = entities.Count(item => Math.Abs((int)(item.GetComponent<TestHealthComponent>().Points - expectedPoints)) < float.Epsilon); Assert.AreEqual(Load, df); Debug.WriteLine("Found {0} entities with health of {1}.", df, expectedPoints); }
public void TestQueueSystems() { Debug.WriteLine("Initialize EntityWorld: "); EntityWorld entityWorld = new EntityWorld(); #if !PORTABLE TestQueueSystem testQueueSystem1 = entityWorld.SystemManager.SetSystem(new TestQueueSystem(10), GameLoopType.Update, 0, ExecutionType.Asynchronous); TestQueueSystem testQueueSystem2 = entityWorld.SystemManager.SetSystem(new TestQueueSystem(10), GameLoopType.Update, 0, ExecutionType.Asynchronous); TestQueueSystemCopy testQueueSystem3 = entityWorld.SystemManager.SetSystem(new TestQueueSystemCopy(20), GameLoopType.Update, 0, ExecutionType.Asynchronous); #else TestQueueSystem testQueueSystem1 = entityWorld.SystemManager.SetSystem(new TestQueueSystem(10), GameLoopType.Update); TestQueueSystem testQueueSystem2 = entityWorld.SystemManager.SetSystem(new TestQueueSystem(10), GameLoopType.Update); TestQueueSystemCopy testQueueSystem3 = entityWorld.SystemManager.SetSystem(new TestQueueSystemCopy(20), GameLoopType.Update); #endif entityWorld.InitializeAll(); Debug.WriteLine("OK"); QueueSystemProcessingThreadSafe.SetQueueProcessingLimit(20, testQueueSystem2.Id); int expectedLimit = QueueSystemProcessingThreadSafe.GetQueueProcessingLimit(testQueueSystem2.Id); Assert.AreEqual(expectedLimit, QueueSystemProcessingThreadSafe.GetQueueProcessingLimit(testQueueSystem1.Id)); Assert.AreNotEqual(expectedLimit, QueueSystemProcessingThreadSafe.GetQueueProcessingLimit(testQueueSystem3.Id)); QueueSystemProcessingThreadSafe.SetQueueProcessingLimit(1024, testQueueSystem1.Id); QueueSystemProcessingThreadSafe.SetQueueProcessingLimit(4096, testQueueSystem3.Id); Debug.WriteLine("Fill EntityWorld with first chunk of " + Load + " entities: "); List<Entity> entities1 = new List<Entity>(); for (int index = Load; index >= 0; --index) { Entity entity = TestEntityFactory.CreateTestHealthEntity(entityWorld); QueueSystemProcessingThreadSafe.AddToQueue(entity, testQueueSystem1.Id); entities1.Add(entity); } Debug.WriteLine("OK"); Debug.WriteLine("Fill EntityWorld with second chunk of " + Load + " entities: "); List<Entity> entities2 = new List<Entity>(); for (int index = Load; index >= 0; --index) { Entity entity = TestEntityFactory.CreateTestHealthEntity(entityWorld); QueueSystemProcessingThreadSafe.AddToQueue(entity, testQueueSystem3.Id); entities2.Add(entity); } Debug.WriteLine("OK"); Debug.WriteLine("Begin down tearing of queues..."); Stopwatch stopwatch = Stopwatch.StartNew(); int loopCount = 0; while (QueueSystemProcessingThreadSafe.QueueCount(testQueueSystem1.Id) > 0 || QueueSystemProcessingThreadSafe.QueueCount(testQueueSystem3.Id) > 0) { entityWorld.Update(); entityWorld.Draw(); ++loopCount; #if DEBUG Debug.WriteLine("Queue size thread A: {0} B: {1}", QueueSystemProcessingThreadSafe.QueueCount(testQueueSystem1.Id), QueueSystemProcessingThreadSafe.QueueCount(testQueueSystem3.Id)); #endif } stopwatch.Stop(); Debug.WriteLine("End OK. Loops: {0} Time: {1}", loopCount, FastDateTime.ToString(stopwatch.Elapsed)); Debug.WriteLine("Test entities 1: "); const float Expected1 = 90.0f; foreach (Entity entity in entities1) { Assert.AreEqual(Expected1, entity.GetComponent<TestHealthComponent>().Points); } Debug.WriteLine("OK"); Debug.WriteLine("Test entities 2: "); const float Expected2 = 80.0f; foreach (Entity entity in entities2) { Assert.AreEqual(Expected2, entity.GetComponent<TestHealthComponent>().Points); } Debug.WriteLine("OK"); }
internal void Initialize(D3D11Host host) { if (IsInitialized) return; IsInitialized = true; Services = new GameServiceContainer(); ServiceLocator.Initialize(Services); _host = host; Artemis.System.EntitySystem.BlackBoard.SetEntry("GraphicsDevice", _host.GraphicsDevice); Artemis.System.EntitySystem.BlackBoard.SetEntry("ServiceProvider", Services); Services.AddService<IGraphicsDeviceService>(host); Services.AddService(host.GraphicsDevice); _mouse = new MouseService(host); Services.AddService<IMouseService>(_mouse); _mouse.ButtonDown += OnMouseButtonDown; _keyboard = new KeyboardService(host); Services.AddService<IKeyboardService>(_keyboard); _timer = new TimerService(); Services.AddService<ITimerService>(_timer); Services.AddService(new FastSpriteBatch(host.GraphicsDevice)); _timer.LastFrameUpdateTime = _gameTime; _timer.LastFrameRenderTime = _gameTime; SpriteBatch = new SpriteBatch(host.GraphicsDevice); Services.AddService(SpriteBatch); Content = new ContentManager(Services); Content.RootDirectory = Environment.CurrentDirectory; SpriteManager = new SpriteManagerService(Content); Services.AddService<ISpriteManagerService>(SpriteManager); //LoadHullSprites("textures/hulls.json"); Artemis.System.EntitySystem.BlackBoard.SetEntry("ContentManager", Content); World = new EntityWorld(false, false, false); World.CreateComponentPool<Transform>(200, 200); _gridSystem = new GridRendererSystem(); _gridSystem.IsEnabled = false; World.SystemManager.SetSystem(_gridSystem, Artemis.Manager.GameLoopType.Draw, 1); //World.SystemManager.SetSystem(new ShipRendererSystem(), Artemis.Manager.GameLoopType.Draw, 2); World.SystemManager.SetSystem(new SceneGraphRendererSystem<StandardShipModelRenderer>(new StandardShipModelRenderer()), Artemis.Manager.GameLoopType.Draw, 3); World.SystemManager.SetSystem(new BoundingBoxRendererSystem(), Artemis.Manager.GameLoopType.Draw, 4); World.SystemManager.SetSystem(new GenericDrawableRendererSystem(), Artemis.Manager.GameLoopType.Draw, 5); _hardpointRendererSystem = new HardpointRendererSystem(); _hardpointRendererSystem.IsEnabled = false; World.SystemManager.SetSystem(_hardpointRendererSystem, Artemis.Manager.GameLoopType.Draw, 6); World.SystemManager.SetSystem(new CameraControlSystem(), Artemis.Manager.GameLoopType.Update, 1); _transformSystem = new MouseControlledTransformSystem(); World.SystemManager.SetSystem(_transformSystem, Artemis.Manager.GameLoopType.Update, 2); World.SystemManager.SetSystem(new ShipUpdateSystem(), Artemis.Manager.GameLoopType.Update, 3); World.SystemManager.SetSystem(new BoundingBoxSelectionSystem(), Artemis.Manager.GameLoopType.Update, 4); World.SystemManager.SetSystem(new ShowThrusterTrailsOverrideSystem(), Artemis.Manager.GameLoopType.Update, 5); World.InitializeAll(); CameraEntity = World.CreateCamera(Constants.ActiveCameraTag, _host.GraphicsDevice); CameraEntity.Tag = Constants.ActiveCameraTag; Camera = CameraEntity.GetComponent<Camera>(); GridEntity = World.CreateGrid(new Vector2(50, 50), GridColor); World.CreateCircle(Vector2.Zero, 10, 8, XnaColor.Red * 0.4f); host.PreviewKeyDown += HandleKeyboardInput; EditorService = new ShipEditorService(_mouse, World); CreateNewShipModelCommand.Execute(null); EditorService.SelectedPartEntities.CollectionChanged += (o, e) => { if (e.NewItems != null && e.NewItems.Count > 0) { var color = e.NewItems.Cast<Entity>().First().GetComponent<IShipPartComponent>().Part.Color; _selectedColor = System.Windows.Media.Color.FromArgb(color.A, color.R, color.G, color.B); PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(nameof(SelectedColor))); } }; _mouse.WheelChanged += OnWheelChanged; IsHardpointsVisible = false; LoadHullSprites("textures/hulls.json"); IsGridVisible = true; }
public void TestSimpleSystem2() { Debug.WriteLine("Initialize EntityWorld: "); EntityWorld entityWorld = new EntityWorld(); TestEntityProcessingSystem testEntityProcessingSystem = entityWorld.SystemManager.SetSystem(new TestEntityProcessingSystem(), GameLoopType.Update); entityWorld.InitializeAll(); Debug.WriteLine("OK"); const float Expected = 0; Assert.AreEqual(Expected, testEntityProcessingSystem.Counter); Stopwatch stopwatch = Stopwatch.StartNew(); entityWorld.Update(); entityWorld.Draw(); stopwatch.Stop(); #if DEBUG Debug.WriteLine("Processed update and draw with duration {0} for {1} elements", FastDateTime.ToString(stopwatch.Elapsed), entityWorld.EntityManager.EntitiesRequestedCount); #else Debug.WriteLine("Processed update and draw with duration {0} for {1} elements", FastDateTime.ToString(stopwatch.Elapsed), entityWorld.EntityManager.ActiveEntities.Count); #endif const float Expected1 = 1; Assert.AreEqual(Expected1, testEntityProcessingSystem.Counter); Debug.WriteLine("OK"); }
public void TestAttributes() { Debug.WriteLine("Initialize EntityWorld: "); EntityWorld entityWorld = new EntityWorld(false,true,true) { PoolCleanupDelay = 1 }; #if (!FULLDOTNET && !METRO) || CLIENTPROFILE entityWorld.InitializeAll(global::System.Reflection.Assembly.GetExecutingAssembly()); #endif Debug.WriteLine("OK"); const int ExpectedNumberOfSystems = 2; int actualNumberOfSystems = entityWorld.SystemManager.Systems.Count; Assert.AreEqual(ExpectedNumberOfSystems, actualNumberOfSystems, "Number of initial systems does not fit."); Debug.WriteLine("Number of Systems: {0} OK", actualNumberOfSystems); Debug.WriteLine("Build up entity with component from pool manually: "); Entity entityWithPooledComponent = TestEntityFactory.CreateTestPowerEntityWithPooledComponent(entityWorld); Debug.WriteLine("OK"); Debug.WriteLine("Build up entity from template: "); Entity entityFromTemplate = entityWorld.CreateEntityFromTemplate("test"); Assert.IsNotNull(entityFromTemplate, "Entity from test template is null."); Debug.WriteLine("OK"); entityWorld.Update(); entityWorld.Draw(); Debug.WriteLine("Remove component from entity: "); entityWithPooledComponent.RemoveComponent<TestPowerComponentPoolable>(); entityWorld.Update(); entityWorld.Draw(); Assert.IsFalse(entityWithPooledComponent.HasComponent<TestPowerComponentPoolable>(), "Entity has still deleted component."); Debug.WriteLine("OK"); Debug.WriteLine("Add component to entity: "); entityWithPooledComponent.AddComponentFromPool<TestPowerComponentPoolable>(); entityWithPooledComponent.GetComponent<TestPowerComponentPoolable>().Power = 100; entityWorld.Update(); entityWorld.Draw(); Assert.IsTrue(entityWithPooledComponent.HasComponent<TestPowerComponentPoolable>(), "Could not add component to entity."); Debug.WriteLine("OK"); // TestNormalEntityProcessingSystem2 and TestNormalEntityProcessingSystem3 are autoloaded (marked with ArtemisEntitySystem attribute) List<TestNormalEntityProcessingSystem2> listOfTestNormalEntityProcessingSystem2 = entityWorld.SystemManager.GetSystems<TestNormalEntityProcessingSystem2>(); Assert.IsNotNull(listOfTestNormalEntityProcessingSystem2, "Failed to retrieve autoloaded TestNormalEntityProcessingSystem2 system."); Assert.AreEqual(1, listOfTestNormalEntityProcessingSystem2.Count, "Invalid count of TestNormalEntityProcessingSystem2 systems"); Debug.WriteLine("OK"); List<TestNormalEntityProcessingSystem3> listOfTestNormalEntityProcessingSystem3 = entityWorld.SystemManager.GetSystems<TestNormalEntityProcessingSystem3>(); Assert.IsNotNull(listOfTestNormalEntityProcessingSystem3, "Failed to retrieve autoloaded TestNormalEntityProcessingSystem3 system."); Assert.AreEqual(1, listOfTestNormalEntityProcessingSystem3.Count, "Invalid count of TestNormalEntityProcessingSystem3 systems"); Debug.WriteLine("OK"); }
public void TestUniqueId() { Debug.WriteLine("Initialize EntityWorld: "); EntityWorld entityWorld = new EntityWorld(); entityWorld.SystemManager.SetSystem(new TestCommunicationSystem(), GameLoopType.Update); entityWorld.InitializeAll(); Debug.WriteLine("OK"); Entity ent1 = TestEntityFactory.CreateTestHealthEntityWithId(entityWorld, -5); Debug.WriteLine("ID1 " + ent1.UniqueId); Debug.Assert(ent1.UniqueId == -5, "Ids dont match"); Entity ent2 = TestEntityFactory.CreateTestHealthEntity(entityWorld); Debug.WriteLine("ID2 " + ent2.UniqueId); Debug.Assert(ent2.UniqueId != -5 && ent2.UniqueId > 0, "Ids cant match"); Entity entrec = entityWorld.EntityManager.GetEntityByUniqueId(-5); Debug.Assert(ent1 == entrec, "Entities must match"); entrec = entityWorld.EntityManager.GetEntity(ent1.Id); Debug.Assert(ent1 == entrec, "Entities must match"); entityWorld.DeleteEntity(ent1); entityWorld.Update(); entrec = entityWorld.EntityManager.GetEntityByUniqueId(-5); Debug.Assert(entrec == null, "Entity must be null"); entrec = entityWorld.EntityManager.GetEntity(ent1.Id); Debug.Assert(entrec == null, "Entity must be null"); Debug.WriteLine("OK"); }
public void TestUniqId() { global::System.Diagnostics.Debug.WriteLine("Initialize EntityWorld: "); EntityWorld entityWorld = new EntityWorld(); entityWorld.SystemManager.SetSystem(new TestCommunicationSystem(), GameLoopType.Update); #if !FULLDOTNET && !METRO entityWorld.InitializeAll(); #else entityWorld.InitializeAll(false); #endif global::System.Diagnostics.Debug.WriteLine("OK"); var ent1 = TestEntityFactory.CreateTestHealthEntityWithID(entityWorld, -5); global::System.Diagnostics.Debug.WriteLine("ID1 " + ent1.UniqueId ); Debug.Assert(ent1.UniqueId == -5, "Ids dont match"); var ent2 = TestEntityFactory.CreateTestHealthEntity(entityWorld); global::System.Diagnostics.Debug.WriteLine("ID2 " + ent2.UniqueId); Debug.Assert(ent2.UniqueId != -5 && ent2.UniqueId > 0, "Ids cant match"); var entrec = entityWorld.EntityManager.GetEntityByUniqueID(-5); Debug.Assert(ent1 == entrec, "Entities must match"); entrec = entityWorld.EntityManager.GetEntity(ent1.Id); Debug.Assert(ent1 == entrec, "Entities must match"); entityWorld.DeleteEntity(ent1); entityWorld.Update(); entrec = entityWorld.EntityManager.GetEntityByUniqueID(-5); Debug.Assert(entrec==null, "Entity must be null"); entrec = entityWorld.EntityManager.GetEntity(ent1.Id); Debug.Assert(entrec == null, "Entity must be null"); global::System.Diagnostics.Debug.WriteLine("OK"); }
public void FTestQueueSystems() { Debug.WriteLine("Initialize EntityWorld: "); EntityWorld entityWorld = new EntityWorld(); #if !PORTABLE TestQueueSystemCopy2 testQueueSystem1 = entityWorld.SystemManager.SetSystem(new TestQueueSystemCopy2(10), GameLoopType.Update, 0, ExecutionType.Asynchronous); #else TestQueueSystemCopy2 testQueueSystem1 = entityWorld.SystemManager.SetSystem(new TestQueueSystemCopy2(10), GameLoopType.Update); #endif entityWorld.InitializeAll(); Debug.WriteLine("OK"); QueueSystemProcessingThreadSafe<DummyPlaceHolder>.SetQueueProcessingLimit(20, testQueueSystem1.Id); Debug.WriteLine("Fill EntityWorld with first chunk of " + Load + " entities: "); List<DummyPlaceHolder> entities1 = new List<DummyPlaceHolder>(); for (int index = Load; index >= 0; --index) { DummyPlaceHolder dph = new DummyPlaceHolder { Component = new TestHealthComponent(100) }; QueueSystemProcessingThreadSafe<DummyPlaceHolder>.AddToQueue(dph, testQueueSystem1.Id); entities1.Add(dph); } Debug.WriteLine("OK"); Debug.WriteLine("Begin down tearing of queues..."); Stopwatch stopwatch = Stopwatch.StartNew(); int loopCount = 0; while (QueueSystemProcessingThreadSafe<DummyPlaceHolder>.QueueCount(testQueueSystem1.Id) > 0 || QueueSystemProcessingThreadSafe<DummyPlaceHolder>.QueueCount(testQueueSystem1.Id) > 0) { entityWorld.Update(); entityWorld.Draw(); ++loopCount; #if DEBUG Debug.WriteLine("Queue size thread A: {0} ", QueueSystemProcessingThreadSafe<DummyPlaceHolder>.QueueCount(testQueueSystem1.Id)); #endif } stopwatch.Stop(); Debug.WriteLine("End OK. Loops: {0} Time: {1}", loopCount, FastDateTime.ToString(stopwatch.Elapsed)); Debug.WriteLine("Test entities 1: "); const float Expected1 = 90.0f; foreach (DummyPlaceHolder entity in entities1) { TestHealthComponent testHealthComponent = entity.Component as TestHealthComponent; if (testHealthComponent != null) { Assert.AreEqual(Expected1, testHealthComponent.Points); } } Debug.WriteLine("OK"); }
public void HybridQueueSystemTeste() { EntityWorld world = new EntityWorld(); SystemManager systemManager = world.SystemManager; HybridQueueSystemTest HybridQueueSystemTest = new ArtemisTest.HybridQueueSystemTest(); EntitySystem hs = systemManager.SetSystem(HybridQueueSystemTest, ExecutionType.UpdateSynchronous); world.InitializeAll(false); List<Entity> l = new List<Entity>(); for (int i = 0; i < 100; i++) { Entity et = world.CreateEntity(); et.AddComponent(new Health()); et.GetComponent<Health>().HP += 100; et.Refresh(); l.Add(et); } for (int i = 0; i < 100; i++) { Entity et = world.CreateEntity(); et.AddComponent(new Health()); et.GetComponent<Health>().HP += 100; HybridQueueSystemTest. AddToQueue(et); l.Add(et); } int j = 0; while (HybridQueueSystemTest.QueueCount > 0) { j++; DateTime dt = DateTime.Now; world.Update(0); Console.WriteLine((DateTime.Now - dt).TotalMilliseconds); } for (int i = 0; i < 100; i++) { Debug.Assert(l[i].GetComponent<Health>().HP == 100 - (10 * j)); } for (int i = 100; i < 200; i++) { Debug.Assert(l[i].GetComponent<Health>().HP == 90); } }