Exemplo n.º 1
0
 def test_step_max_dt(self):
     from grease import World
     world = World()
     sys1 = world.systems.sys = TestSystem()
     comp1 = world.components.foo = TestComponent()
     world.step(10000)
     self.assertEqual(comp1.runtime, 10.0 / world.step_rate)
     self.assertEqual(sys1.runtime, 10.0 / world.step_rate)
Exemplo n.º 2
0
 def test_step_max_dt(self):
     from grease import World
     world = World()
     sys1 = world.systems.sys = TestSystem()
     comp1 = world.components.foo = TestComponent()
     world.step(10000)
     self.assertEqual(comp1.runtime, 10.0 / world.step_rate)
     self.assertEqual(sys1.runtime, 10.0 / world.step_rate)
Exemplo n.º 3
0
 def test_step_components(self):
     from grease import World, Entity
     world = World()
     comp1 = world.components.one = TestComponent()
     comp2 = world.components.two = TestComponent()
     entity = Entity(world)
     self.assertTrue(comp1.runtime == comp2.runtime == 0, comp1.runtime)
     world.step(0.05)
     self.assertEqual(comp1.runtime, 0.05)
     self.assertEqual(comp2.runtime, 0.05)
     world.step(0.06)
     self.assertEqual(comp1.runtime, 0.11)
     self.assertEqual(comp2.runtime, 0.11)
Exemplo n.º 4
0
 def test_step_components(self):
     from grease import World, Entity
     world = World()
     comp1 = world.components.one = TestComponent()
     comp2 = world.components.two = TestComponent()
     entity = Entity(world)
     self.assertTrue(comp1.runtime == comp2.runtime == 0, comp1.runtime)
     world.step(0.05)
     self.assertEqual(comp1.runtime, 0.05)
     self.assertEqual(comp2.runtime, 0.05)
     world.step(0.06)
     self.assertEqual(comp1.runtime, 0.11)
     self.assertEqual(comp2.runtime, 0.11)
Exemplo n.º 5
0
 def test_system_step_order(self):
     from grease import World
     world = World()
     sys1 = world.systems.one = TestSystem()
     sys3 = world.systems.three = TestSystem()
     sys2 = TestSystem()
     world.systems.insert('two', sys2, index=1)
     self.assertEqual(len(world.systems), 3)
     self.assertTrue(sys1.runtime == sys2.runtime == sys3.runtime == 0)
     self.assertTrue(sys1.order == sys2.order == sys3.order == TestSystem.order)
     world.step(0.13)
     self.assertTrue(sys1.runtime == sys2.runtime == sys3.runtime == 0.13)
     start = sys1.order
     self.assertEqual(sys2.order, start + 1)
     self.assertEqual(sys3.order, start + 2)
Exemplo n.º 6
0
 def test_system_step_order(self):
     from grease import World
     world = World()
     sys1 = world.systems.one = TestSystem()
     sys3 = world.systems.three = TestSystem()
     sys2 = TestSystem()
     world.systems.insert('two', sys2, index=1)
     self.assertEqual(len(world.systems), 3)
     self.assertTrue(sys1.runtime == sys2.runtime == sys3.runtime == 0)
     self.assertTrue(
         sys1.order == sys2.order == sys3.order == TestSystem.order)
     world.step(0.13)
     self.assertTrue(sys1.runtime == sys2.runtime == sys3.runtime == 0.13)
     start = sys1.order
     self.assertEqual(sys2.order, start + 1)
     self.assertEqual(sys3.order, start + 2)
Exemplo n.º 7
0
 def test_add_system_during_run(self):
     from grease import World
     world = World()
     sys1 = world.systems.sys1 = TestSystem()
     to_inject = TestSystem()
     injector = world.systems.injector = TestSystemInjector('injected', to_inject)
     self.assertEqual(len(world.systems), 2)
     self.assertTrue(sys1.runtime == to_inject.runtime == injector.runtime == 0)
     self.assertFalse(injector.injected)
     world.step(0.1)
     self.assertEqual(len(world.systems), 3)
     self.assertEqual(sys1.runtime, 0.1)
     self.assertEqual(injector.runtime, 0.1)
     self.assertEqual(to_inject.runtime, 0)
     self.assertTrue(injector.injected)
     world.step(0.1)
     self.assertEqual(len(world.systems), 3)
     self.assertEqual(sys1.runtime, 0.2)
     self.assertEqual(injector.runtime, 0.2)
     self.assertEqual(to_inject.runtime, 0.1)
Exemplo n.º 8
0
 def test_add_system_during_run(self):
     from grease import World
     world = World()
     sys1 = world.systems.sys1 = TestSystem()
     to_inject = TestSystem()
     injector = world.systems.injector = TestSystemInjector(
         'injected', to_inject)
     self.assertEqual(len(world.systems), 2)
     self.assertTrue(
         sys1.runtime == to_inject.runtime == injector.runtime == 0)
     self.assertFalse(injector.injected)
     world.step(0.1)
     self.assertEqual(len(world.systems), 3)
     self.assertEqual(sys1.runtime, 0.1)
     self.assertEqual(injector.runtime, 0.1)
     self.assertEqual(to_inject.runtime, 0)
     self.assertTrue(injector.injected)
     world.step(0.1)
     self.assertEqual(len(world.systems), 3)
     self.assertEqual(sys1.runtime, 0.2)
     self.assertEqual(injector.runtime, 0.2)
     self.assertEqual(to_inject.runtime, 0.1)