示例#1
0
def gamemodel():
    model = core.GameModel()
    model.res['testworld'] = WorldHandle()
    w = model.res['testworld'].get()
    w.add_processor(core.AbstractProcessor())
    model.switch(model.res['testworld'], immediate=True)
    return model
示例#2
0
def test_abstract_processor(world):
    range_update = 50

    entity1 = world.create_entity(ComponentC())
    entity2 = world.create_entity(ComponentD())

    world.add_processor(core.AbstractProcessor())

    for i in range(range_update):
        world.process()

    assert world.try_component(entity1, ComponentC).val == range_update
    assert world.try_component(
        entity2, ComponentD).val == (ComponentD.INIT_VAL + range_update)
示例#3
0
def test_gamemodel_switch(gamemodel):
    gamemodel.res['testworld'].get().create_entity(ModelComponent())
    gamemodel.res['testworld2'] = WorldHandle()
    testworld = gamemodel.current_world
    testworld2 = gamemodel.res['testworld2'].get()

    component = ModelComponent()
    testworld2.create_entity(component)
    testworld2.add_processor(core.AbstractProcessor())

    assert gamemodel.res['testworld'].get() == testworld
    assert gamemodel.current_world_handle == gamemodel.res['testworld']
    assert gamemodel.current_world == gamemodel.res['testworld'].get()
    gamemodel.loop()

    assert component.var == 0
    gamemodel.switch(gamemodel.res['testworld2'],
                     cur_reset=True,
                     immediate=True)
    assert gamemodel.res['testworld'].get() != testworld

    assert gamemodel.current_world_handle == gamemodel.res['testworld2']
    assert gamemodel.current_world == gamemodel.res['testworld2'].get()
    gamemodel.loop()

    gamemodel.switch(gamemodel.res['testworld'])
    gamemodel.res['testworld'].get().add_processor(core.AbstractProcessor())
    gamemodel.res['testworld'].get().create_entity(ModelComponent())
    assert gamemodel.current_world_handle == gamemodel.res['testworld2']
    assert gamemodel.current_world == gamemodel.res['testworld2'].get()
    gamemodel.loop()

    assert gamemodel.current_world_handle == gamemodel.res['testworld']
    assert gamemodel.current_world == gamemodel.res['testworld'].get()

    assert component.var == 11
示例#4
0
def test_gamemodel_switch(gamemodel):
    testworld = gamemodel.current_world
    testworld.create_entity(ModelComponent())
    testworld2_hand = WorldHandle()
    testworld2 = testworld2_hand.get()
    testworld2.create_entity(ModelComponent())
    testworld2.add_processor(core.AbstractProcessor())

    batch1 = gamemodel.get_batch(testworld)
    batch2 = gamemodel.get_batch(testworld2)

    gamemodel.switch(testworld2_hand, immediate=True, cur_reset=True)

    assert batch2 is gamemodel.get_batch()
    assert batch1 is not gamemodel.get_batch(testworld)

    gamemodel.switch(testworld2_hand, immediate=True, dest_reset=True)

    assert batch2 is not gamemodel.get_batch()

    gamemodel.loop()