Пример #1
0
 def AddTrigger(self, trigger):
     with self.lock:
         telemetry.APPEND_TO_ZONE(trigger.guid)
         self.LogInfo('\tFxSequencer::AddTrigger: Entering')
         shipBall = None
         targetBall = None
         if trigger.shipID is not None:
             shipBall = self.GetBall(trigger.shipID)
         if trigger.targetID is not None:
             targetBall = self.GetBall(trigger.targetID)
         if shipBall is None:
             self.LogWarn(
                 '\tFxSequencer::AddTrigger: ship not in ballpark. Trigger ignored'
             )
             return
         if getattr(shipBall, '__guid__',
                    '') == 'spaceObject.PlayerOwnedStructure' and getattr(
                        trigger, 'moduleID', None) is not None:
             trigger.shipID = trigger.moduleID
         if trigger.targetID is not None and targetBall is None:
             self.LogWarn(
                 '\tFxSequencer::AddTrigger: target not in ballpark. Trigger ignored'
             )
             return
         if getattr(shipBall, 'model', None) is None:
             self.LogWarn(
                 '\tFxSequencer::AddTrigger: ship model not loaded. Trigger delayed',
                 trigger.shipID)
             if trigger.shipID in self.delayedtriggers:
                 self.delayedtriggers[trigger.shipID].append(trigger)
             else:
                 self.delayedtriggers[trigger.shipID] = [trigger]
             return
         if trigger.targetID is not None and getattr(
                 targetBall, 'model', None) is None:
             self.LogWarn(
                 '\tFxSequencer::AddTrigger: target ship model not loaded. Trigger delayed',
                 trigger.targetID)
             if trigger.targetID in self.delayedtriggers:
                 self.delayedtriggers[trigger.targetID].append(trigger)
             else:
                 self.delayedtriggers[trigger.targetID] = [trigger]
             return
         key = self.GetKey(trigger)
         if trigger.duration is None or trigger.duration <= 0.0:
             trigger.duration = effects.GetClassification(trigger.guid)[5]
         if trigger.repeat is None or trigger.repeat == 0:
             trigger.repeat = 1
         trigger.__dict__['stamp'] = blue.os.GetSimTime() + long(
             trigger.duration * trigger.repeat / 1000.0 * SECOND)
         if key in self.activations and trigger.guid not in (
                 'effects.Cloak', 'effects.Uncloak'):
             activation = self.activations[key]
             activation.AddTrigger(trigger)
             self.AddActivationToBallRegister(activation)
         else:
             self.AddActivation(trigger, key)
     self.LogInfo('\tFxSequencer::AddTrigger: Done')
Пример #2
0
def ReadYamlFile(path):
    telemetry.APPEND_TO_ZONE(path)
    data = None
    rf = blue.ResFile()
    if rf.FileExists(path):
        rf.Open(path)
        yamlStr = rf.read()
        rf.close()
        data = yaml.load(yamlStr, Loader=yaml.CLoader)
    return data
Пример #3
0
 def AddTrigger(self, trigger):
     with self.lock:
         telemetry.APPEND_TO_ZONE(trigger.guid)
         self.LogInfo('\tFxSequencer::AddTrigger: Entering')
         shipBall = None
         targetBall = None
         if trigger.shipID is not None:
             shipBall = self.GetBall(trigger.shipID)
         if trigger.targetID is not None:
             targetBall = self.GetBall(trigger.targetID)
         classification = GetClassification(trigger.guid)
         if shipBall is None:
             self.LogWarn('\tFxSequencer::AddTrigger: ship not in ballpark. Trigger ignored')
             return
         if classification and classification[0] is ShipRenderEffect:
             if hasattr(shipBall, 'model') and not hasattr(shipBall.model, 'overlayEffects'):
                 self.LogInfo('This ball', shipBall.id, 'of type', self.GetItem(trigger.shipID).typeID, 'does not support the ship effect', trigger.guid)
                 return
         if isinstance(shipBall, PlayerOwnedStructure) and getattr(trigger, 'moduleID', None):
             trigger.shipID = trigger.moduleID
         if trigger.targetID is not None and targetBall is None:
             self.LogWarn('\tFxSequencer::AddTrigger: target not in ballpark. Trigger ignored')
             return
         if getattr(shipBall, 'model', None) is None:
             if trigger.shipID in self.delayedtriggers:
                 self.delayedtriggers[trigger.shipID].append(trigger)
             else:
                 self.delayedtriggers[trigger.shipID] = [trigger]
             return
         if trigger.targetID is not None and getattr(targetBall, 'model', None) is None:
             self.LogWarn('\tFxSequencer::AddTrigger: target ship model not loaded. Trigger delayed', trigger.targetID)
             if trigger.targetID in self.delayedtriggers:
                 self.delayedtriggers[trigger.targetID].append(trigger)
             else:
                 self.delayedtriggers[trigger.targetID] = [trigger]
             return
         key = self.GetKey(trigger)
         if trigger.duration is None or trigger.duration <= 0.0:
             classification = GetClassification(trigger.guid)
             if classification is not None:
                 trigger.duration = classification[5]
         if trigger.repeat is None or trigger.repeat == 0:
             trigger.repeat = 1
         trigger.__dict__['stamp'] = blue.os.GetSimTime() + long(trigger.duration * trigger.repeat / 1000.0 * SECOND)
         if key in self.activations and trigger.guid not in ('effects.Cloak', 'effects.Uncloak'):
             activation = self.activations[key]
             activation.AddTrigger(trigger)
             self.AddActivationToBallRegister(activation)
         else:
             self.AddActivation(trigger, key)
     self.LogInfo('\tFxSequencer::AddTrigger: Done')
Пример #4
0
    def StartService(self, serviceName, ms=None, reason='StartService'):
        telemetry.APPEND_TO_ZONE(serviceName)
        srv = self.services.get(serviceName, None)
        if srv and srv.state == service.SERVICE_RUNNING:
            return srv
        if serviceName in self.services:
            srv = self.services[serviceName]
        else:
            if serviceName in self.blockedServices:
                raise RuntimeError(
                    '%s has been blocked from running on this system' %
                    serviceName)
            srv = self.CreateServiceInstance(serviceName)
            self.services[serviceName] = srv
        if srv.state in (service.SERVICE_START_PENDING, ):
            return srv
        if srv.state == service.SERVICE_STARTING_DEPENDENCIES:
            desiredStates = (service.SERVICE_START_PENDING,
                             service.SERVICE_RUNNING)
            errorStates = (service.SERVICE_FAILED, service.SERVICE_STOPPED)
            self.WaitForServiceObjectState(srv, desiredStates, errorStates)
            return srv
        if self.state in (service.SERVICE_STOP_PENDING,
                          service.SERVICE_STOPPED):
            raise RuntimeError, "Can't start service " + serviceName + ' when service manager is shutting down'
        if srv.state == service.SERVICE_FAILED:
            return srv
        try:
            r = reason
            if reason in ('GetService', 'StartService'):
                up = 4
                if reason == 'StartService':
                    up = 2
                r = '%s - called from %s' % (reason, log.WhoCalledMe(up))
            self.LogInfo('Starting', serviceName, '. Reason:', r)
        except:
            pass

        srv.state = service.SERVICE_STARTING_DEPENDENCIES
        srv.__error__ = None
        try:
            self.dependants[serviceName] = []
            if srv.__startupdependencies__:
                self.LogInfo(
                    'starting startup dependencies for %s, which are: %s' %
                    (serviceName, str(srv.__startupdependencies__)))
                for each in srv.__startupdependencies__:
                    if each == srv.__guid__.split('.')[1]:
                        self.LogError(
                            'Found a service with a dependancy on it self:',
                            each,
                            '. The service reference will not be assigned, things will probaly blow up'
                        )
                        continue
                    if type(each) is str:
                        each = (each, each)
                    depname, asname = each
                    if not self.IsServiceRunning(depname):
                        self.LogInfo(serviceName, 'is waiting while', depname,
                                     'is started')
                    depService = self.StartServiceAndWaitForRunningState(
                        depname,
                        reason='startup dependency for %s' % serviceName)
                    self.dependants[depname].append(serviceName)
                    if getattr(boot, 'replaceDependencyServiceWrappers',
                               'false').lower(
                               ) != 'true' or not depService.IsRunning():
                        setattr(srv, asname,
                                srv.session.ConnectToService(depname))
                    else:
                        setattr(srv, asname, depService)

            srv.state = service.SERVICE_START_PENDING
            if srv.__dependencies__:
                uthread.new(
                    self._LoadServiceDependenciesAsych, srv, serviceName
                ).context = serviceName + ' _LoadServiceDependenciesAsych'
            for notify in srv.__notifyevents__:
                if not hasattr(srv, notify):
                    raise RuntimeError('MissingSvcExportAttribute',
                                       serviceName, 'notify', notify)
                if not self.notify.has_key(notify):
                    self.notify[notify] = []
                self.notify[notify].append(srv)

        except Exception as e:
            srv.state = service.SERVICE_FAILED
            srv.__error__ = sys.exc_info()
            raise

        if ms:
            ms.Seek(0)
        args = (ms, )
        if serviceName in self.startInline:
            self.StartServiceRun(srv, args, serviceName)
        else:
            uthread.pool(serviceName + ' StartServiceRun',
                         self.StartServiceRun, srv, args, serviceName)
        return srv