def test_collision_handler_gravity_pickle():
    from panda3d.core import CollisionHandlerGravity

    collider1 = NodePath(CollisionNode("collider1"))
    collider2 = NodePath(CollisionNode("collider2"))
    target1 = NodePath("target1")
    target2 = NodePath("target2")

    handler = CollisionHandlerGravity()
    handler.add_out_pattern("out pattern")
    handler.add_collider(collider1, target1)
    handler.add_collider(collider2, target2)
    handler.offset = 1.0
    handler.reach = 2.0
    handler.max_velocity = 3.0
    handler.gravity = -4.0

    handler = loads(dumps(handler, -1))

    assert tuple(handler.in_patterns) == ()
    assert tuple(handler.again_patterns) == ()
    assert tuple(handler.out_patterns) == ("out pattern", )
    assert handler.center == None
    assert handler.offset == 1.0
    assert handler.reach == 2.0
    assert handler.max_velocity == 3.0
    assert handler.gravity == -4.0
Ejemplo n.º 2
0
def test_collision_traverser_pickle():
    from direct.stdpy.pickle import dumps, loads

    handler = CollisionHandlerQueue()

    collider1 = NodePath(CollisionNode("collider1"))
    collider2 = NodePath(CollisionNode("collider2"))

    trav = CollisionTraverser("test123")
    trav.respect_prev_transform = True
    trav.add_collider(collider1, handler)
    trav.add_collider(collider2, handler)

    trav = loads(dumps(trav, -1))
    assert trav.respect_prev_transform is True

    assert trav.name == "test123"
    assert trav.get_num_colliders() == 2
    collider1 = trav.get_collider(0)
    collider2 = trav.get_collider(1)
    assert collider1.name == "collider1"
    assert collider2.name == "collider2"

    # Two colliders must still be the same object; this only works with our own
    # version of the pickle module, in direct.stdpy.pickle.
    assert trav.get_handler(collider1) == trav.get_handler(collider2)
Ejemplo n.º 3
0
def test_reduce_persist():
    from panda3d.core import NodePath

    parent = NodePath("parent")
    child = parent.attach_new_node("child")

    parent2, child2 = loads(dumps([parent, child]))
    assert tuple(parent2.children) == (child2, )
Ejemplo n.º 4
0
def test_pickle_copy():
    from panda3d.core import PandaNode, NodePath

    # Make two Python wrappers pointing to the same node
    node1 = PandaNode("node")
    node2 = NodePath(node1).node()
    assert node1.this == node2.this
    assert id(node1) != id(node2)

    # Test that pickling and loading still results in the same node object.
    node1, node2 = loads(dumps([node1, node2]))
    assert node1 == node2
Ejemplo n.º 5
0
    def loadMemory(self, dumped):
        try:
            loaded = pickle.loads(dumped)
        except Exception as exp:
            safeprint(exp)
            return

        self.storyManager.destroy()
        self.audioPlayer.stopAll(0.5)
        restoreRuntimeData(loaded)
        self.audioPlayer.reload()
        self.storyManager = StoryManager()
Ejemplo n.º 6
0
 def loadMemory(self,dumped):
     try:
         loaded = pickle.loads(dumped)
     except Exception as exp: 
         safeprint(exp)
         return
     
     self.storyManager.destroy()
     self.audioPlayer.stopAll(0.5)
     restoreRuntimeData(loaded)
     self.audioPlayer.reload()
     self.storyManager = StoryManager()   
Ejemplo n.º 7
0
def test_cpta_float_pickle():
    from panda3d.core import PTA_float, CPTA_float
    from direct.stdpy.pickle import dumps, loads, HIGHEST_PROTOCOL

    null_pta = CPTA_float(PTA_float())

    empty_pta = CPTA_float([])

    data_pta = CPTA_float([1.0, 2.0, 3.0])
    data = data_pta.get_data()

    for proto in range(1, HIGHEST_PROTOCOL + 1):
        null_pta2 = loads(dumps(null_pta, proto))
        assert null_pta2.is_null()
        assert len(null_pta2) == 0

        empty_pta2 = loads(dumps(empty_pta, proto))
        assert not empty_pta2.is_null()
        assert len(empty_pta2) == 0

        data_pta2 = loads(dumps(data_pta, proto))
        assert tuple(data_pta2) == (1.0, 2.0, 3.0)
        assert data_pta2.get_data() == data_pta.get_data()
def test_collision_handler_event_pickle():
    from panda3d.core import CollisionHandlerEvent

    handler = CollisionHandlerEvent()
    handler.add_in_pattern("abcdefg")
    handler.add_in_pattern("test")
    handler.add_again_pattern("again pattern")
    handler.add_again_pattern("another again pattern")
    handler.add_out_pattern("out pattern")

    handler = loads(dumps(handler, -1))

    assert tuple(handler.in_patterns) == ("abcdefg", "test")
    assert tuple(handler.again_patterns) == ("again pattern",
                                             "another again pattern")
    assert tuple(handler.out_patterns) == ("out pattern", )
def test_collision_handler_pusher_pickle():
    from panda3d.core import CollisionHandlerPusher

    collider1 = NodePath(CollisionNode("collider1"))
    collider2 = NodePath(CollisionNode("collider2"))
    target1 = NodePath("target1")
    target2 = NodePath("target2")

    handler = CollisionHandlerPusher()
    handler.add_again_pattern("again pattern")
    handler.add_collider(collider1, target1)
    handler.add_collider(collider2, target2)
    handler.horizontal = True

    handler = loads(dumps(handler, -1))

    assert tuple(handler.in_patterns) == ()
    assert tuple(handler.again_patterns) == ("again pattern", )
    assert tuple(handler.out_patterns) == ()
    assert not handler.has_center()
    assert handler.horizontal
def test_collision_handler_queue_pickle():
    from panda3d.core import CollisionHandlerQueue

    handler = CollisionHandlerQueue()
    handler = loads(dumps(handler, -1))
    assert type(handler) == CollisionHandlerQueue
Ejemplo n.º 11
0
def test_loader_file_type_registry_pickle():
    from direct.stdpy.pickle import dumps, loads

    registry = LoaderFileTypeRegistry.get_global_ptr()
    assert loads(dumps(registry, -1)) == registry