def _get_prop(self, asm, prop_name, definition_id): props = self._props prop = props.get(prop_name) (from_actor, states_to_override) = asm.get_prop_state_override(prop_name) if not definition_id: self._override_prop_states(from_actor, prop, states_to_override) return prop if prop is not None: if prop.definition.id != definition_id: asm.set_actor(prop_name, None) prop.destroy(source=self, cause='Replacing prop.') del props[prop_name] prop = None if prop is None: share_key = asm.get_prop_share_key(prop_name) if share_key is None: prop = create_prop(definition_id) else: prop_manager = services.prop_manager() prop = prop_manager.create_shared_prop(share_key, definition_id) if prop is not None: props[prop_name] = prop else: logger.error( "{}: Failed to create prop '{}' with definition id {:#x}", asm.name, prop_name, definition_id) if prop is not None: asm.set_prop_state_values(prop_name, prop) self._override_prop_states(from_actor, prop, states_to_override) asm.set_prop_as_asm_actor(prop_name, prop) return prop
def destroy_all_objects(_connection=None): with supress_posture_graph_build(): all_objects = list( itertools.chain(services.object_manager().objects, services.prop_manager().objects)) for obj in all_objects: while obj.persistence_group != objects.persistence_groups.PersistenceGroups.SIM: obj.destroy(source=obj, cause='destroy_all_objects command') return True
def on_throw_destroy(self, event_data): prop_id = event_data.event_data.get('event_actor_id') if prop_id is not None: if self.throw_impact_data.impact_effect is not None: thrown_obj = services.prop_manager().get(prop_id) if thrown_obj is not None: fade_out_vfx = self.throw_impact_data.impact_effect(thrown_obj) fade_out_vfx.start_one_shot() self.animation_context.destroy_prop_from_actor_id(prop_id)
def destroy_all_props(self, held_only=False): names = [] for name in self._all_props_gen(held_only): names.append(name) for name in names: prop_manager = services.prop_manager() prop_manager.destroy_prop(self._props.pop(name), source=self, cause='Animation destroying all props.')
def destroy_prop_from_actor_id(self, prop_id): props = self._props for (prop_name, prop) in props.items(): if prop.id == prop_id: prop_manager = services.prop_manager() prop_manager.destroy_prop(prop, source=self, cause='Discarding props.') del props[prop_name] return
def destroy_random_objects(count: int = 1, _connection=None): output = sims4.commands.CheatOutput(_connection) with supress_posture_graph_build(): all_objects = list( itertools.chain(services.object_manager().objects, services.prop_manager().objects)) non_sim_objects = list( obj for obj in all_objects if obj.persistence_group != objects.persistence_groups.PersistenceGroups.SIM) count = min(count, len(non_sim_objects)) to_kill = random.sample(non_sim_objects, count) for obj in to_kill: obj.destroy(source=obj, cause='destroy_random_objects command') output('{}/{} objects destroyed!'.format(len(to_kill), len(non_sim_objects))) return True
def destroy_all_objects_with_less_area_than(max_area=0.25, _connection=None): with supress_posture_graph_build(): all_objects = list( itertools.chain(services.object_manager().objects, services.prop_manager().objects)) for obj in all_objects: if isinstance(obj, PropObject): obj.destroy( source=obj, cause= 'Prop in destroy_all_objects_with_less_area_than command') else: while obj.persistence_group != objects.persistence_groups.PersistenceGroups.SIM: poly = obj.footprint_polygon if poly: if poly.area() < max_area: obj.destroy( source=obj, cause= 'Too small in destroy_all_objects_with_less_area_than command' ) return True
def object_manager_for_create(self): return services.prop_manager()
def generate_statistics(): now_ticks = services.server_clock_service().now().absolute_ticks() ticks_elapsed = now_ticks - previous_log_time_ticks now_time = time.time() time_elapsed = now_time - previous_log_time_stamp ticks_per_sec = 0 if time_elapsed != 0: ticks_per_sec = ticks_elapsed / time_elapsed else: ticks_per_sec = 'Zero time elapsed. ticks elapsed = {}'.format( ticks_elapsed) num_sim_infos = 0 num_sims = 0 for sim_info in services.sim_info_manager().objects: num_sim_infos += 1 if sim_info.is_instanced(allow_hidden_flags=ALL_HIDDEN_REASONS): num_sims += 1 all_props = [] if services.prop_manager(): all_props = list(services.prop_manager().objects) all_objects = list(services.object_manager().objects) all_inventory_objects = list( services.current_zone().inventory_manager.objects) objects_active_lot_interactive = [] objects_active_lot_decorative = [] objects_open_street_interactive = [] objects_open_street_decorative = [] for obj in all_objects: if obj.is_on_active_lot(): if obj.definition.has_build_buy_tag( *PerformanceHandlerTuning.DECORATIVE_OBJECT_TAGS_ACTIVE_LOT ): objects_active_lot_decorative.append(obj) else: objects_active_lot_interactive.append(obj) elif obj.definition.has_build_buy_tag( *PerformanceHandlerTuning.DECORATIVE_OBJECT_TAGS_OPEN_STREET): objects_open_street_decorative.append(obj) else: objects_open_street_interactive.append(obj) objects_active_lot_autonomous = [] objects_open_street_autonomous = [] objects_active_lot_user_directed = [] objects_open_street_user_directed = [] autonomous_counter = Counter() user_directed_counter = Counter() def process_interactive_objects(objects, autonomous_list, user_directed_list, autonomous_counter, user_directed_counter, location='undefined'): for obj in objects: in_autonomous_list = False in_user_directed_list = False in_user_directed_counter = (obj.definition.name, location) in user_directed_counter for sa in obj.super_affordances(): if sa.allow_autonomous: autonomous_counter.update({(sa, location): 1}) if not in_autonomous_list: in_autonomous_list = True autonomous_list.append(obj) if not in_user_directed_counter: user_directed_counter.update({ (obj.definition.name, location): 1 }) if not (sa.allow_user_directed and in_user_directed_list): in_user_directed_list = True user_directed_list.append(obj) process_interactive_objects(objects_active_lot_interactive, objects_active_lot_autonomous, objects_active_lot_user_directed, autonomous_counter, user_directed_counter, location='active_lot') process_interactive_objects(objects_open_street_interactive, objects_open_street_autonomous, objects_open_street_user_directed, autonomous_counter, user_directed_counter, location='open_street') performance_metrics.clear() set_gsi_performance_metric('num_sims', num_sims) set_gsi_performance_metric('num_sim_infos', num_sim_infos) set_gsi_performance_metric( 'num_objects_active_lot', len(objects_active_lot_interactive) + len(objects_active_lot_decorative)) set_gsi_performance_metric( 'num_objects_open_street', len(objects_open_street_interactive) + len(objects_open_street_decorative)) set_gsi_performance_metric('num_props', len(all_props)) set_gsi_performance_metric('total_objects_props', len(all_props) + len(all_objects)) set_gsi_performance_metric(consts.TICKS_PER_SECOND, ticks_per_sec) metrics = [ (consts.OBJS_ACTIVE_LOT_INTERACTIVE, lambda: len(objects_active_lot_interactive)), (consts.OBJS_ACTIVE_LOT_DECORATIVE, lambda: len(objects_active_lot_decorative)), (consts.OBJS_OPEN_STREET_INTERACTIVE, lambda: len(objects_open_street_interactive)), (consts.OBJS_OPEN_STREET_DECORATIVE, lambda: len(objects_open_street_decorative)), (consts.OBJS_TOTAL, lambda: len(all_objects)), (consts.PROPS_TOTAL, lambda: len(all_props)), (consts.OBJS_INVENTORY_TOTAL, lambda: len(all_inventory_objects)), (consts.OBJS_GRAND_TOTAL, lambda: len(all_props) + len(all_objects) + len(all_inventory_objects) ), (consts.OBJS_ACTIVE_LOT_AUTONOMOUS_AFFORDANCE, lambda: len(objects_active_lot_autonomous)), (consts.OBJS_OPEN_STREET_AUTONOMOUS_AFFORDANCE, lambda: len(objects_open_street_autonomous)), (consts.OBJS_AUTONOMOUS_AFFORDANCE, lambda: sum(autonomous_counter.values())) ] details = list() for (name, func) in metrics: entry = {'metric': name, 'count': func()} details.append(entry) set_gsi_performance_metric('AdditionalMetrics', details) def generate_histogram(name, objects, fill_gsi_func, histogram_counter=None, object_name_func=None): if histogram_counter is None: histogram_counter = Counter(objects) histogram = list() for (obj, freq) in histogram_counter.most_common(): entry = fill_gsi_func(obj, freq, object_name_func=object_name_func) histogram.append(entry) set_gsi_performance_metric(name, histogram) def fill_gsi_object_location_histogram_entry(object_location_pair, frequency, object_name_func=None): obj_name = object_name_func( object_location_pair[0] ) if object_name_func is not None else object_location_pair[0] return { 'name': obj_name, 'location': object_location_pair[1], 'frequency': frequency } def combine_object_location_lists(active_lot_list, open_street_list): all_objects = [(active_lot_obj.definition.name, 'active_lot') for active_lot_obj in active_lot_list] all_objects.extend([(open_street_obj.definition.name, 'open_street') for open_street_obj in open_street_list]) return all_objects all_objects_locations_interactive = combine_object_location_lists( objects_active_lot_interactive, objects_open_street_interactive) all_objects_locations_decorative = combine_object_location_lists( objects_active_lot_decorative, objects_open_street_decorative) all_objects_locations_autonomous = combine_object_location_lists( objects_active_lot_autonomous, objects_open_street_autonomous) sa_name_func = lambda x: x.__name__ generate_histogram(consts.OBJECT_CLASSIFICATIONS[0], all_objects_locations_interactive, fill_gsi_object_location_histogram_entry) generate_histogram(consts.OBJECT_CLASSIFICATIONS[1], all_objects_locations_decorative, fill_gsi_object_location_histogram_entry) generate_histogram(consts.OBJECT_CLASSIFICATIONS[2], all_objects_locations_autonomous, fill_gsi_object_location_histogram_entry) generate_histogram(consts.OBJECT_CLASSIFICATIONS[3], [], fill_gsi_object_location_histogram_entry, autonomous_counter, sa_name_func) generate_histogram(consts.OBJECT_CLASSIFICATIONS[4], [], fill_gsi_object_location_histogram_entry, user_directed_counter) return performance_metrics
def generate_statistics(): now_ticks = services.server_clock_service().now().absolute_ticks() ticks_elapsed = now_ticks - previous_log_time_ticks now_time = time.time() time_elapsed = now_time - previous_log_time_stamp ticks_per_sec = 0 if time_elapsed != 0: ticks_per_sec = ticks_elapsed / time_elapsed else: ticks_per_sec = 'Zero time elapsed. ticks elapsed = {}'.format( ticks_elapsed) num_sim_infos = 0 num_sims = 0 for sim_info in services.sim_info_manager().objects: num_sim_infos += 1 while sim_info.is_instanced(allow_hidden_flags=ALL_HIDDEN_REASONS): num_sims += 1 all_props = [] if services.prop_manager(): all_props = list(services.prop_manager().objects) all_objects = list(services.object_manager().objects) all_inventory_objects = list( services.current_zone().inventory_manager.objects) objects_active_lot_interactive = [] objects_active_lot_decorative = [] objects_open_street_interactive = [] objects_open_street_decorative = [] for obj in all_objects: tags = obj.definition.build_buy_tags if obj.is_on_active_lot(): if PerformanceHandlerTuning.DECORATIVE_OBJECT_TAGS_ACTIVE_LOT & tags: objects_active_lot_decorative.append(obj) else: objects_active_lot_interactive.append(obj) if PerformanceHandlerTuning.DECORATIVE_OBJECT_TAGS_OPEN_STREET & tags: objects_open_street_decorative.append(obj) else: objects_open_street_interactive.append(obj) elif PerformanceHandlerTuning.DECORATIVE_OBJECT_TAGS_OPEN_STREET & tags: objects_open_street_decorative.append(obj) else: objects_open_street_interactive.append(obj) performance_metrics.clear() set_gsi_performance_metric('num_sims', num_sims) set_gsi_performance_metric('num_sim_infos', num_sim_infos) set_gsi_performance_metric( 'num_objects_active_lot', len(objects_active_lot_interactive) + len(objects_active_lot_decorative)) set_gsi_performance_metric( 'num_objects_open_street', len(objects_open_street_interactive) + len(objects_open_street_decorative)) set_gsi_performance_metric('num_props', len(all_props)) set_gsi_performance_metric('total_objects_props', len(all_props) + len(all_objects)) set_gsi_performance_metric('ticks_per_sec', ticks_per_sec) metrics = [ ('#Objects (Active Lot) Interactive', lambda: len(objects_active_lot_interactive)), ('#Objects (Active Lot) Decorative', lambda: len(objects_active_lot_decorative)), ('#Objects (OpenStreet) Interactive', lambda: len(objects_open_street_interactive)), ('#Objects (OpenStreet) Decorative', lambda: len(objects_open_street_decorative)), ('Total Objects', lambda: len(all_objects)), ('Total Props', lambda: len(all_props)), ('Total Inventory Objects', lambda: len(all_inventory_objects)), ('Grand Total (Objs,Props,InventoryObjs)', lambda: len(all_props) + len(all_objects) + len(all_inventory_objects) ) ] details = list() for (name, func) in metrics: entry = {'metric': name, 'count': func()} details.append(entry) set_gsi_performance_metric('AdditionalMetrics', details) def generate_histogram(name, objects): histogram_counter = Counter([obj.definition.name for obj in objects]) histogram = list() for (obj_name, freq) in histogram_counter.most_common(): entry = {'object_name': obj_name, 'frequency': freq} histogram.append(entry) set_gsi_performance_metric(name, histogram) generate_histogram(OBJECT_CLASSIFICATIONS[0], objects_active_lot_interactive) generate_histogram(OBJECT_CLASSIFICATIONS[1], objects_active_lot_decorative) generate_histogram(OBJECT_CLASSIFICATIONS[2], objects_open_street_interactive) generate_histogram(OBJECT_CLASSIFICATIONS[3], objects_open_street_decorative) return performance_metrics