def test_step_max_dt(self): from bGrease 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)
def test_step_components(self): from bGrease 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)
def test_activate(self): from bGrease import World world = World(master_clock=TestClock()) sys1 = world.systems.one = TestSystem() sys2 = world.systems.two = TestSystem() manager = TestModeManager() self.assertFalse(world.active) world.activate(manager) self.assertTrue(world.manager is manager, world.manager) self.assertTrue(world.active) self.assertTrue((world.tick, None) in world.master_clock.scheduled) self.assertTrue(sys1 in manager.handlers) self.assertTrue(sys2 in manager.handlers) return world, manager
def test_tick_increments_world_time(self): from bGrease import World world = World(clock_factory=TestClock) self.assertEqual(world.time, 0) self.assertEqual(world.clock.ticks, 0) self.assertEqual(world.clock.time_func(), world.time) dt = 1.0/30.0 world.tick(dt) self.assertAlmostEqual(world.time, dt) self.assertEqual(world.clock.time_func(), world.time) self.assertEqual(world.clock.ticks, 1) world.tick(dt) self.assertAlmostEqual(world.time, dt*2) self.assertEqual(world.clock.time_func(), world.time) self.assertEqual(world.clock.ticks, 2)
def test_system_step_order(self): from bGrease 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)
def test_on_draw(self): from bGrease import World world = World() renderer1 = world.renderers.one = TestRenderer() renderer2 = world.renderers.two = TestRenderer() gl = TestGL() self.assertFalse(gl.cleared) self.assertFalse(gl.matrix_reset) self.assertFalse(renderer1.drawn) self.assertFalse(renderer2.drawn) world.on_draw(gl=gl) self.assertTrue(gl.cleared) self.assertTrue(gl.matrix_reset) self.assertTrue(renderer1.drawn) self.assertTrue(renderer2.drawn) start = renderer1.order self.assertEqual(renderer2.order, start + 1)
def test_running(self): from bGrease import World world = World() self.assertTrue(world.running) self.assertEqual(world.time, 0) dt = 1.0/30.0 world.tick(dt) self.assertAlmostEqual(world.time, dt) world.running = False world.tick(dt) world.tick(dt) self.assertAlmostEqual(world.time, dt) world.running = True world.tick(dt) self.assertAlmostEqual(world.time, dt*2)
def test_add_system_during_run(self): from bGrease 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)