DModel.py 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. from direct.distributed.DistributedNode import DistributedNode
  2. class DModel(DistributedNode):
  3. def __init__(self, cr):
  4. DistributedNode.__init__(self, cr)
  5. # Load up the visible representation of this avatar.
  6. self.model = loader.loadModel('smiley.egg')
  7. self.model.reparentTo(self)
  8. def announceGenerate(self):
  9. """ This method is called after generate(), after all of the
  10. required fields have been filled in. At the time of this call,
  11. the distributed object is ready for use. """
  12. DistributedNode.announceGenerate(self)
  13. # Now that the object has been fully manifested, we can parent
  14. # it into the scene.
  15. self.reparentTo(render)
  16. def disable(self):
  17. """ This method is called when the object is removed from the
  18. scene, for instance because it left the zone. It is balanced
  19. against generate(): for each generate(), there will be a
  20. corresponding disable(). Everything that was done in
  21. generate() or announceGenerate() should be undone in disable().
  22. After a disable(), the object might be cached in memory in case
  23. it will eventually reappear. The DistributedObject should be
  24. prepared to receive another generate() for an object that has
  25. already received disable().
  26. Note that the above is only strictly true for *cacheable*
  27. objects. Most objects are, by default, non-cacheable; you
  28. have to call obj.setCacheable(True) (usually in the
  29. constructor) to make it cacheable. Until you do this, your
  30. non-cacheable object will always receive a delete() whenever
  31. it receives a disable(), and it will never be stored in a
  32. cache.
  33. """
  34. # Take it out of the scene graph.
  35. self.detachNode()
  36. DistributedNode.disable(self)
  37. def delete(self):
  38. """ This method is called after disable() when the object is to
  39. be completely removed, for instance because the other user
  40. logged off. We will not expect to see this object again; it
  41. will not be cached. This is stronger than disable(), and the
  42. object may remove any structures it needs to in order to allow
  43. it to be completely deleted from memory. This balances against
  44. __init__(): every DistributedObject that is created will
  45. eventually get delete() called for it exactly once. """
  46. # Clean out self.model, so we don't have a circular reference.
  47. self.model = None
  48. DistributedNode.delete(self)