Пример #1
0
def main():
    """ Main function of the simulator """

    # input and output FIFOs
    fifoIn = deque([], IN_FIFO_LEN)
    fifoOut = deque([], OUT_FIFO_LEN)

    # input wave file
    wf = wave.open('440Hz.wav', 'rb')

    # output wave file
    wof = wave.open('output.wav', 'wb')
    wof.setnchannels(1)
    wof.setsampwidth(2)
    wof.setframerate(16000)

    # for i in range(5):
    #     packet = createPacket(array('L', [x*i for x in range(4)]))
    #     fifoIn.append(packet)

    # set the simulation duration in seconds
    scheduler.setSimDuration(10.1)

    # producer adds packet to the input FIFO
    event = scheduler.Event(0, CODEC_INTERVAL, producerCallback, [fifoIn, wf])
    scheduler.addEvent(event)

    # the transport sends packets on the medium and store them in a (finte)
    # output FIFO
    event = scheduler.Event(0, FRAME_INTERVAL, aclTransportCallback,
                            [fifoIn, fifoOut])
    scheduler.addEvent(event)

    # consumer takes packets from the output FIFO and writes them to a wave file
    # RSL10: 16129/16000 or 15957/16000
    event = scheduler.Event(FRAME_INTERVAL, FRAME_INTERVAL, consumerCallback,
                            [fifoOut, wof])
    scheduler.addEvent(event)

    # START the simulation
    scheduler.runEvents()

    # end of the simulation
    scheduler.simDone()

    print("Consumer underflow:", underflowCnt)
    print("Consumer overflow:", overflowCnt)
    print("Radio overflow:", radioOverflow)

    wof.close()
    vcd.close()
    vcdFile.close()
Пример #2
0
    def __init__(self, obj, config):
        super().__init__(config)
        self.log.info(self.M("ship_create"))
        utils.parent_groups(obj)

        self.obj = obj
        self.hull = [o for o in self.obj.childrenRecursive if 'HULL' in o][0]
        self.vert_center = [
            o for o in self.hull.childrenRecursive if 'VERT_CENTER' in o
        ][0]

        self._event = scheduler.Event(self.update)
        scheduler.add_event(self._event)

        self.miniguns = GunStorage(
            minigun.MiniGun(o, self.config["MINIGUN_CONFIG"])
            for o in self.obj.childrenRecursive if 'MINIGUN' in o)
        self.railguns = GunStorage(
            railgun.RailGun(o, self.config["RAILGUN_CONFIG"])
            for o in self.obj.childrenRecursive if 'RAILGUN' in o)
        self.thrusters = GunStorage(
            Thruster(self.hull, o, self.config['THRUSTER_CONFIG'])
            for o in self.obj.childrenRecursive if 'THRUSTER' in o)

        self.hull.removeParent()

        self.navigation_target = self.hull.worldPosition
Пример #3
0
 def __init__(self, conf):
     super().__init__(conf)
     self._event = scheduler.Event(self.update)
     scheduler.add_event(self._event)
     
     self.alive_bullets = set()
     self.dead_bullets = set()
     
     for _i in range(self.config['BULLET_LIMIT']):
         self.dead_bullets.add(_Bullet())
Пример #4
0
    def __init__(self, scene):
        super().__init__({})
        self.scene = scene
        self.unused_trails = [
            _GpuTrail(t) for t in self.scene.objectsInactive
            if '__TRAIL_INSTANCE__' in t
        ]
        self.used_trails = []

        self._event = scheduler.Event(self.update)
        scheduler.add_event(self._event)
        self.scene.pre_draw.append(self._draw)
Пример #5
0
 def __init__(self, scene, conf, mouse):
     super().__init__(conf)
     self.log.info(self.M("create_hud"))
     self._event = scheduler.Event(self.update)
     scheduler.add_event(self._event)
     
     self.scene = scene
     self.ship = None
     self.mouse = mouse
     
     self.weapon_selector = WeaponSelector(
         [o for o in scene.objects if 'WEAPON_SELECTOR' in o][0],
         self.config['WEAPON_UI_CONFIG'],
         self.mouse
     )
Пример #6
0
    def __init__(self, scene, conf):
        super().__init__(conf)

        logging.basicConfig(level=config.get('SYS/LOG_LEVEL'),
                            format='%(message)s')
        if config.get('SYS/EXIT_ON_ERROR'):
            self.log.info("exit_with_error_enabled")
            sys.excepthook = err
        else:
            sys.excepthook = sys.__excepthook__

        for cb in gc.callbacks.copy():
            gc.callbacks.remove(cb)
        gc.callbacks.append(gc_notify)

        exit_key = config.get('KEYS/EMERGENCY_ABORT_KEY')
        if exit_key:
            bge.logic.setExitKey(bge.events.__dict__[exit_key])

        self.log.info(self.M("init_game"))
        self._event = scheduler.Event(self.update)
        scheduler.add_event(self._event)

        bge.logic.addScene('HUD')
        self.scene = scene
        self.hud = None
        self.hud_scene = None

        self.hero = ship.Ship(self.scene.objects['HeroShipMain'],
                              self.config['HERO_CONFIG'])
        self.camera = camera.Camera(self.scene.objects['MainCamera'],
                                    self.config['CAMERA_CONFIG'])
        self.mouse = mouse.Mouse(self.config['MOUSE_CONFIG'])

        self.environment = environment.Environment(
            self.scene.objects['LightRig'],
            self.scene.objects['TerrainTiles'],
            self.scene.objects['SkySphere'],
        )

        self.scene.objects['MainCamera'].setParent(self.hero.vert_center)
        self.camera.set_view(0.5, -0.5, 0.2)

        self.navigation_waypoints = []

        self.scene.active_camera = self.camera.camera
        bge.render.showMouse(True)
Пример #7
0
    def __init__(self, obj, config):
        super().__init__(obj, config)
        self.log.debug(self.M("create_minigun", game_object=obj.name))
        utils.parent_groups(obj)
        objs = obj.childrenRecursive

        self.obj = obj
        self.yaw = [o for o in objs if 'YAW' in o][0]
        self.pitch = [o for o in objs if 'PITCH' in o][0]
        self.barrel = [o for o in objs if 'BARREL' in o][0]
        self.spawner = [o for o in objs if 'SPAWNER' in o][0]

        self._target = None
        self.barrel_angle = 0.0
        self.barrel_velocity = 0.0
        self.time_since_last_shot = 0.0

        self._event = scheduler.Event(self.update)
        scheduler.add_event(self._event)
Пример #8
0
def aclTransportCallback(fifoIn, fifoOut):
    """ Simulate an ACL tranport between a master and a slave. Packets are 
    retransmitted untile they are successfully acknowledged. """

    global fifoRadio, radioOverflow

    # get the packet scheduled for this event
    schedPacket = fifoIn.popleft()
    schedPacket.txAttemps = packet.FLUSH_TIMEOUT_INF

    if fifoRadio.maxlen == len(fifoRadio):
        radioOverflow += 1

    fifoRadio.append(schedPacket)

    # schedule tx slots within a connection event
    for i in range(min(len(fifoRadio), MAX_TX_CONN_EVENT)):
        event = scheduler.Event(
            scheduler.Scheduler.clockTime + i * PACKET_DURATION, 0,
            txCallaback, [fifoRadio, fifoOut])
        scheduler.addEvent(event)
Пример #9
0
    def __init__(self, obj, conf):
        super().__init__(obj, conf)
        self.log.debug(self.M("create_railgun", game_object=obj.name))
        utils.parent_groups(obj)
        objs = obj.childrenRecursive

        self.obj = obj
        self.yaw = [o for o in objs if 'MAIN_YAW' in o][0]

        self.pitch = [o for o in objs if 'PITCH' in o][0]
        self.barrels = [
            Barrel(o, self.config['BARREL_CONFIG']) for o in objs
            if 'SPAWNER' in o
        ]

        self._target = None

        self._event = scheduler.Event(self.update)
        scheduler.add_event(self._event)

        self.salvo_number = 0
        self.time_since_last_shot = self.config['RELOAD_TIME']
Пример #10
0
 def __init__(self, ship_obj, obj, conf):
     super().__init__(conf)
     self.obj = obj
     self.ship_obj = ship_obj
     self._event = scheduler.Event(self.update)
     scheduler.add_event(self._event)