Exemplo n.º 1
0
def create_object(definition_or_id, obj_id=0, init=None, post_add=None, loc_type=None, **kwargs):
    from objects.components.inventory_item import ItemLocation
    from objects.base_object import BaseObject
    added_to_object_manager = False
    obj = None
    if loc_type is None:
        loc_type = ItemLocation.ON_LOT
    try:
        obj = create_script_object(definition_or_id, **kwargs)
        if obj is None:
            return
        if not isinstance(obj, BaseObject):
            logger.error('Type {0} is not a valid managed object.  It is not a subclass of BaseObject.', type(obj))
            return
        if init is not None:
            init(obj)
        if loc_type == ItemLocation.FROM_WORLD_FILE:
            obj.persistence_group = PersistenceGroups.IN_OPEN_STREET
        obj.item_location = ItemLocation(loc_type) if loc_type is not None else ItemLocation.INVALID_LOCATION
        obj.id = obj_id
        if loc_type == ItemLocation.ON_LOT or loc_type == ItemLocation.FROM_WORLD_FILE or loc_type == ItemLocation.FROM_OPEN_STREET:
            obj.object_manager_for_create.add(obj)
        elif loc_type == ItemLocation.SIM_INVENTORY or loc_type == ItemLocation.OBJECT_INVENTORY:
            services.current_zone().inventory_manager.add(obj)
        else:
            logger.error('Unsupported loc_type passed to create_script_object.  We likely need to update this code path.', owner='mduke')
        added_to_object_manager = True
        if post_add is not None:
            post_add(obj)
        return obj
    finally:
        if not added_to_object_manager and obj is not None:
            import _weakrefutils
            _weakrefutils.clear_weak_refs(obj)
Exemplo n.º 2
0
def create_object(definition_or_id,
                  obj_id=0,
                  init=None,
                  post_add=None,
                  loc_type=None,
                  **kwargs):
    from objects.components.inventory_item import ItemLocation
    from objects.base_object import BaseObject
    added_to_object_manager = False
    obj = None
    if loc_type is None:
        loc_type = ItemLocation.ON_LOT
    try:
        obj = create_script_object(definition_or_id, **kwargs)
        if obj is None:
            return
        if not isinstance(obj, BaseObject):
            logger.error(
                'Type {0} is not a valid managed object.  It is not a subclass of BaseObject.',
                type(obj))
            return
        if init is not None:
            init(obj)
        if loc_type == ItemLocation.FROM_WORLD_FILE:
            obj.persistence_group = PersistenceGroups.IN_OPEN_STREET
        obj.item_location = ItemLocation(
            loc_type
        ) if loc_type is not None else ItemLocation.INVALID_LOCATION
        obj.id = obj_id
        if loc_type == ItemLocation.ON_LOT or loc_type == ItemLocation.FROM_WORLD_FILE or loc_type == ItemLocation.FROM_OPEN_STREET:
            obj.object_manager_for_create.add(obj)
        elif loc_type == ItemLocation.SIM_INVENTORY or loc_type == ItemLocation.OBJECT_INVENTORY:
            services.current_zone().inventory_manager.add(obj)
        else:
            logger.error(
                'Unsupported loc_type passed to create_script_object.  We likely need to update this code path.',
                owner='mduke')
        added_to_object_manager = True
        if post_add is not None:
            post_add(obj)
        return obj
    finally:
        if not added_to_object_manager and obj is not None:
            import _weakrefutils
            _weakrefutils.clear_weak_refs(obj)
Exemplo n.º 3
0
 def remove(self, obj):
     if obj.id not in self._objects:
         logger.error('Attempting to remove an object that is not in this manager')
         return
     if obj.id in self._objects_to_be_removed:
         logger.error('Attempting to remove an object {} that is already in the process of being removed.'.format(obj), owner='tastle')
         return
     try:
         self._objects_to_be_removed.append(obj.id)
         self.call_on_remove(obj)
         _weakrefutils.clear_weak_refs(obj)
         del self._objects[obj.id]
         self._objects_to_be_removed.remove(obj.id)
         old_obj_id = obj.id
         obj.id = 0
         self.call_post_remove(obj)
         _weakrefutils.clear_weak_refs(obj)
         object_leak_tracker = services.get_object_leak_tracker()
         if object_leak_tracker is not None:
             object_leak_tracker.track_object(obj, self, old_obj_id)
     except Exception:
         logger.exception('Exception thrown while calling remove on {0}', obj)
Exemplo n.º 4
0
 def _gc_callback(self, phase, info):
     generation = info['generation']
     if phase != 'stop' or generation < 1:
         return
     if self.gc_callback_disable_reasons:
         return
     new_list = []
     caches.clear_all_caches(force=True)
     for indexed_object in self._remove_indexed_object_tracker:
         obj = None
         if indexed_object.ref:
             obj = indexed_object.ref()
         if obj is None:
             pass
         if generation == 1:
             self._should_trigger_full = True
             new_list.append(indexed_object)
         if indexed_object.gc_gen_two_iteration > 0:
             self._print_leaked_object(obj)
             _weakrefutils.clear_weak_refs(obj)
         else:
             indexed_object.gc_gen_two_iteration = 1
             new_list.append(indexed_object)
     self._remove_indexed_object_tracker = new_list
Exemplo n.º 5
0
 def remove(self, obj):
     if obj.id not in self._objects:
         logger.error(
             'Attempting to remove an object that is not in this manager')
         return
     if obj.id in self._objects_to_be_removed:
         logger.error(
             'Attempting to remove an object {} that is already in the process of being removed.'.format(
                 obj),
             owner='tastle')
         return
     try:
         self._objects_to_be_removed.append(obj.id)
         self.call_on_remove(obj)
         _weakrefutils.clear_weak_refs(obj)
         del self._objects[obj.id]
         self._objects_to_be_removed.remove(obj.id)
         obj.id = 0
         self.call_post_remove(obj)
         _weakrefutils.clear_weak_refs(obj)
         IndexedManager._indexed_object_tracker.add_object(obj)
     except Exception:
         logger.exception('Exception thrown while calling remove on {0}',
                          obj)
Exemplo n.º 6
0
 def on_proxied_object_removed(self, proxied_obj_ref):
     _weakrefutils.clear_weak_refs(self)
Exemplo n.º 7
0
def create_object(definition_or_id,
                  obj_id=0,
                  init=None,
                  post_add=None,
                  loc_type=None,
                  disable_object_commodity_callbacks=False,
                  content_source=ContentSource.DEFAULT,
                  **kwargs):
    from objects.base_object import BaseObject
    from objects.object_enums import ItemLocation
    added_to_object_manager = False
    obj = None
    if loc_type is None:
        loc_type = ItemLocation.ON_LOT
    try:
        from objects.definition import Definition
        if isinstance(definition_or_id, Definition):
            fallback_definition_id = build_buy.get_vetted_object_defn_guid(
                obj_id, definition_or_id.id)
            if fallback_definition_id != definition_or_id.id:
                definition_or_id = fallback_definition_id
        else:
            definition_or_id = build_buy.get_vetted_object_defn_guid(
                obj_id, definition_or_id)
        if definition_or_id is None:
            return
        obj = create_script_object(definition_or_id, **kwargs)
        if obj is None:
            return
        if not isinstance(obj, BaseObject):
            logger.error(
                'Type {0} is not a valid managed object.  It is not a subclass of BaseObject.',
                type(obj))
            return
        if init is not None:
            init(obj)
        if loc_type == ItemLocation.FROM_WORLD_FILE or loc_type == ItemLocation.FROM_CONDITIONAL_LAYER:
            obj.persistence_group = PersistenceGroups.IN_OPEN_STREET
        obj.item_location = ItemLocation(
            loc_type
        ) if loc_type is not None else ItemLocation.INVALID_LOCATION
        obj.id = obj_id
        obj.content_source = content_source
        if (disable_object_commodity_callbacks
                or services.current_zone().suppress_object_commodity_callbacks
            ) and not obj.is_sim:
            commodity_tracker = obj.commodity_tracker
            if commodity_tracker is not None:
                commodity_tracker.set_callback_alarm_calculation_supression(
                    True)
        if loc_type == ItemLocation.ON_LOT or (
                loc_type == ItemLocation.FROM_WORLD_FILE or
            (loc_type == ItemLocation.FROM_OPEN_STREET
             or loc_type == ItemLocation.HOUSEHOLD_INVENTORY)
        ) or loc_type == ItemLocation.FROM_CONDITIONAL_LAYER:
            obj.object_manager_for_create.add(obj)
        elif loc_type == ItemLocation.SIM_INVENTORY or loc_type == ItemLocation.OBJECT_INVENTORY:
            services.current_zone().inventory_manager.add(obj)
        else:
            logger.error(
                'Unsupported loc_type passed to create_script_object.  We likely need to update this code path.',
                owner='mduke')
        added_to_object_manager = True
        if post_add is not None:
            post_add(obj)
        return obj
    finally:
        if not added_to_object_manager and obj is not None:
            import _weakrefutils
            _weakrefutils.clear_weak_refs(obj)
Exemplo n.º 8
0
 def on_proxied_object_removed(self, proxied_obj_ref):
     _weakrefutils.clear_weak_refs(self)
Exemplo n.º 9
0
 def on_proxied_object_removed(self):
     _weakrefutils.clear_weak_refs(self)
     self._proxied_obj = None