def start(self):
     self._alarm_handle = alarms.add_alarm_real_time(
         self,
         clock.interval_in_real_seconds(1.0),
         self._process,
         repeating=True,
         use_sleep_time=False)
Exemple #2
0
def enable_performance_logging(*args, enableLog=False, **kwargs):
    global previous_log_time_stamp, previous_log_time_ticks, performance_log_alarm
    if enableLog:

        def alarm_callback(_):
            global previous_log_time_stamp, previous_log_time_ticks
            generate_statistics()
            _log_performance_metrics()
            previous_log_time_stamp = time.time()
            previous_log_time_ticks = services.server_clock_service().now(
            ).absolute_ticks()

        previous_log_time_stamp = time.time()
        previous_log_time_ticks = services.server_clock_service().now(
        ).absolute_ticks()
        set_gsi_performance_metric('ticks_per_sec', 'N/A')
        _log_performance_metrics()
        current_zone = services.current_zone()
        if performance_log_alarm is not None:
            alarms.cancel_alarm(performance_log_alarm)
        performance_log_alarm = alarms.add_alarm_real_time(
            current_zone,
            clock.interval_in_real_seconds(SECONDS_BETWEEN_LOGGING),
            alarm_callback,
            repeating=True,
            use_sleep_time=False)
    elif performance_log_alarm is not None:
        alarms.cancel_alarm(performance_log_alarm)
        performance_log_alarm = None
        previous_log_time_stamp = 0
        set_gsi_performance_metric('ticks_per_sec', 'N/A')
Exemple #3
0
 def _initial_update_callback(self, alarm_handle):
     self._pulse()
     time_span = clock.interval_in_real_seconds(self.update_frequency)
     self._alarm = alarms.add_alarm_real_time(self.owner,
                                              time_span,
                                              self._update_callback,
                                              repeating=True,
                                              use_sleep_time=False)
Exemple #4
0
 def _start(self):
     if self._alarm is None:
         time_span = clock.interval_in_real_seconds(self.update_frequency)
         time_span *= random.random()
         self._alarm = alarms.add_alarm_real_time(
             self.owner,
             time_span,
             self._initial_update_callback,
             repeating=False,
             use_sleep_time=False)
Exemple #5
0
 def set_build_buy_lockout_state(self, lockout_state, lockout_timer=None):
     if self._build_buy_lockout_alarm_handler is not None:
         alarms.cancel_alarm(self._build_buy_lockout_alarm_handler)
         self._build_buy_lockout_alarm_handler = None
     elif self._build_buy_lockout and lockout_state:
         return
     if lockout_state and lockout_timer is not None:
         time_span_real_time = clock.interval_in_real_seconds(lockout_timer)
         self._build_buy_lockout_alarm_handler = alarms.add_alarm_real_time(self, time_span_real_time, lambda *_: self.set_build_buy_lockout_state(False))
     if lockout_state and not self.build_buy_lockout:
         self.reset(ResetReason.RESET_EXPECTED)
     self._build_buy_lockout = lockout_state
     self.resend_interactable()
     self.resend_tint()
Exemple #6
0
 def start(self):
     self._alarm_handle = add_alarm_real_time(self,
                                              interval_in_real_seconds(
                                                  self.INTERVAL),
                                              self._on_update,
                                              repeating=True,
                                              use_sleep_time=False)
     object_manager = services.object_manager()
     object_manager.register_callback(
         CallbackTypes.ON_OBJECT_LOCATION_CHANGED,
         self._update_object_cache)
     object_manager.register_callback(CallbackTypes.ON_OBJECT_ADD,
                                      self._update_object_cache)
     services.current_zone().wall_contour_update_callbacks.append(
         self._update_object_cache)
def autonomy_distance_estimates_perform_timed_run(time_to_run_in_seconds:int=180, _connection=None):
    global g_distance_estimate_alarm_handle
    if g_distance_estimate_alarm_handle is not None:
        autonomy_distance_estimates_disable(_connection=_connection)
        alarms.cancel_alarm(g_distance_estimate_alarm_handle)
        g_distance_estimate_alarm_handle = None
    autonomy_distance_estimates_enable(_connection=_connection)

    def _finish_test_and_write_file(_):
        global g_distance_estimate_alarm_handle
        autonomy_distance_estimates_log_file(_connection=_connection)
        autonomy_distance_estimates_disable(_connection=_connection)
        g_distance_estimate_alarm_handle = None

    time_span = date_and_time.create_time_span(minutes=time_to_run_in_seconds)
    g_distance_estimate_alarm_handle = alarms.add_alarm_real_time(services.autonomy_service(), time_span, _finish_test_and_write_file)
Exemple #8
0
def autonomy_distance_estimates_perform_timed_run(
        time_to_run_in_seconds: int = 180, _connection=None):
    global g_distance_estimate_alarm_handle
    if g_distance_estimate_alarm_handle is not None:
        autonomy_distance_estimates_disable(_connection=_connection)
        alarms.cancel_alarm(g_distance_estimate_alarm_handle)
        g_distance_estimate_alarm_handle = None
    autonomy_distance_estimates_enable(_connection=_connection)

    def _finish_test_and_write_file(_):
        global g_distance_estimate_alarm_handle
        autonomy_distance_estimates_log_file(_connection=_connection)
        autonomy_distance_estimates_disable(_connection=_connection)
        g_distance_estimate_alarm_handle = None

    time_span = date_and_time.create_time_span(minutes=time_to_run_in_seconds)
    g_distance_estimate_alarm_handle = alarms.add_alarm_real_time(
        services.autonomy_service(), time_span, _finish_test_and_write_file)
 def _register_alarm() -> None:
     has_setup_alarm_before = False
     if _AutosaveHandler._AUTOSAVE_ALARM_HANDLE is not None:
         has_setup_alarm_before = True
         from alarms import _lookup_alarm_handle
         alarm_handle = _lookup_alarm_handle(_AutosaveHandler._AUTOSAVE_ALARM_HANDLE._element_handle)
         if alarm_handle is not None:
             return
         CommonBasicNotification(
             'S4ASM Autosaving Setup Again',
             'S4ASM will autosave every {} minutes real time. Look for the notification!'.format(_AutosaveHandler._AUTOSAVE_INTERVAL_MINUTES)
         ).show()
     from alarms import add_alarm_real_time
     from sims4communitylib.utils.sims.common_sim_utils import CommonSimUtils
     _AutosaveHandler._AUTOSAVE_ALARM_HANDLE = add_alarm_real_time(CommonSimUtils.get_active_sim_info(), _AutosaveHandler._get_autosave_interval(), _AutosaveHandler._time_to_save, repeating=True, cross_zone=True)
     if not has_setup_alarm_before:
         CommonBasicNotification(
             'S4ASM Autosaving Setup',
             'S4ASM will autosave every {} minutes real time. Look for the notification!'.format(_AutosaveHandler._AUTOSAVE_INTERVAL_MINUTES)
         ).show()
Exemple #10
0
def gc_sample_log(rate: int = 30, real_time: bool = False, _connection=None):
    global gc_alarm_handle
    if gc_alarm_handle is None:
        gc_output('Enabled sample logging.')
        if real_time:
            ticks = rate * TICKS_PER_REAL_WORLD_SECOND
            gc_alarm_handle = alarms.add_alarm_real_time(
                services.current_zone(),
                TimeSpan(ticks),
                garbage_sample_handle,
                repeating=True,
                use_sleep_time=False)
        else:
            gc_alarm_handle = alarms.add_alarm(services.current_zone(),
                                               create_time_span(minutes=rate),
                                               garbage_sample_handle,
                                               repeating=True)
    else:
        gc_output('Disabling sample logging.')
        gc_alarm_handle.cancel()
        gc_alarm_handle = None
 def _initial_update_callback(self, alarm_handle):
     self._pulse()
     time_span = clock.interval_in_real_seconds(self.update_frequency)
     self._alarm = alarms.add_alarm_real_time(self.owner, time_span, self._update_callback, repeating=True, use_sleep_time=False)
 def _start(self):
     if self._alarm is None:
         time_span = clock.interval_in_real_seconds(self.update_frequency)
         time_span *= random.random()
         self._alarm = alarms.add_alarm_real_time(self.owner, time_span, self._initial_update_callback, repeating=False, use_sleep_time=False)
 def start(self):
     self._alarm_handle = alarms.add_alarm_real_time(self, clock.interval_in_real_seconds(1.0), self._process, repeating=True, use_sleep_time=False)
 def start(self):
     self._alarm_handle = add_alarm_real_time(self, interval_in_real_seconds(self.INTERVAL), self._on_update, repeating=True, use_sleep_time=False)
     object_manager = services.object_manager()
     object_manager.register_callback(CallbackTypes.ON_OBJECT_LOCATION_CHANGED, self._update_object_cache)
     object_manager.register_callback(CallbackTypes.ON_OBJECT_ADD, self._update_object_cache)
     services.current_zone().wall_contour_update_callbacks.append(self._update_object_cache)
Exemple #15
0
 def start_services(self, gameplay_zone_data, save_slot_data):
     _distributor = distributor.system.Distributor.instance()
     self.sim_quadtree = placement.get_sim_quadtree_for_zone(self.id)
     self.single_part_condition_list = weakref.WeakKeyDictionary()
     self.multi_part_condition_list = weakref.WeakKeyDictionary()
     from objects.object_manager import ObjectManager, PropManager, PartyManager, InventoryManager, SocialGroupManager
     from sims.sim_info_manager import SimInfoManager
     from server.clientmanager import ClientManager
     from sims.household_manager import HouseholdManager
     from autonomy.autonomy_service import AutonomyService
     from ui.ui_dialog_service import UiDialogService
     from server.config_service import ConfigService
     from event_testing.test_events import EventManager
     from situations.situation_manager import SituationManager
     from filters.sim_filter_service import SimFilterService
     from socials.clustering import ObjectClusterService, SocialGroupClusterService
     from postures.posture_graph import PostureGraphService
     from animation.arb_accumulator import ArbAccumulatorService
     from world.travel_service import TravelService
     from situations.service_npcs.service_npc_manager import ServiceNpcService
     from story_progression.story_progression_service import StoryProgressionService
     from sims.master_controller import MasterController
     from filters.neighborhood_population_service import NeighborhoodPopulationService
     from services.lot_spawner_service import LotSpawnerService
     from zone_spin_up_service import ZoneSpinUpService
     from interactions.privacy import PrivacyService
     from services.age_service import AgeService
     from situations.ambient.ambient_service import AmbientService
     from broadcasters.broadcaster_service import BroadcasterService
     from services.super_speed_three_service import SuperSpeedThreeService
     from services.fire_service import FireService
     from services.cleanup_service import CleanupService
     from time_service import TimeService
     from sims4.sim_irq_service import SimIrqService
     from venues.venue_service import VenueService
     from services.reset_and_delete_service import ResetAndDeleteService
     services = [
         GameClock(), TimeService(), ConfigService(), SimIrqService(),
         EventManager(), ClientManager(manager_id=MGR_CLIENT),
         HouseholdManager(manager_id=MGR_HOUSEHOLD),
         ResetAndDeleteService(), ObjectManager(manager_id=MGR_OBJECT),
         InventoryManager(manager_id=MGR_OBJECT), AgeService(),
         SimInfoManager(manager_id=MGR_SIM_INFO),
         PropManager(manager_id=MGR_OBJECT), PostureGraphService(),
         ArbAccumulatorService(None, None), AutonomyService(),
         SituationManager(manager_id=MGR_SITUATION), SimFilterService(),
         PartyManager(manager_id=MGR_PARTY),
         SocialGroupManager(manager_id=MGR_SOCIAL_GROUP), UiDialogService(),
         ObjectClusterService(), SocialGroupClusterService(),
         TravelService(), NeighborhoodPopulationService(),
         ServiceNpcService(), LotSpawnerService(), VenueService(),
         AmbientService(), StoryProgressionService(), ZoneSpinUpService(),
         PrivacyService(), FireService(), BroadcasterService(),
         CleanupService(), SuperSpeedThreeService(), CareerService(),
         MasterController()
     ]
     from sims4.service_manager import ServiceManager
     self.service_manager = ServiceManager()
     for service in services:
         self.service_manager.register_service(service)
     self.client_object_managers = set()
     self.service_manager.start_services(
         zone=self,
         gameplay_zone_data=gameplay_zone_data,
         save_slot_data=save_slot_data)
     self.navmesh_alarm_handle = alarms.add_alarm_real_time(
         self,
         clock.interval_in_real_seconds(1),
         self._check_navmesh_updated_alarm_callback,
         repeating=True,
         use_sleep_time=False)
     self._royalty_alarm_manager.start_schedule()
 def create_update_alarm(self):
     self._alarm_handle = add_alarm_real_time(self, interval_in_real_seconds(self.INTERVAL), self._on_update, repeating=True, use_sleep_time=False)
 def _log(self, level, message, frame=sims4.log.DEFAULT):
     if not self._logqueue and self._auto_flush_time is not None:
         alarms.add_alarm_real_time(
             self, clock.interval_in_real_seconds(self._auto_flush_time),
             self.flush)
     self._logqueue.append((level, message, frame))