def __init_display(self, sf, fps): if is_pi() and config.blank_console: call_and_log("setterm -blank force", shell=True) bgcolor = (0.0, 0.0, 0.0, 0.0) # fix dispmanx alpha layer https://github.com/tipam/pi3d/issues/197 monkey_patch() self.width = 1920 if sf == 0: #adapt to screen size self.DISPLAY = pi3d.Display.create(background=bgcolor, layer=1) sf = self.width / self.DISPLAY.width self.height = self.DISPLAY.height * sf else: logger.debug("Forcing size") self.height = 1080 self.DISPLAY = pi3d.Display.create(x=0, y=0, w=int(self.width / sf), h=int(self.height / sf), background=bgcolor, layer=1) self.DISPLAY.frames_per_second = fps logger.info("Display %dx%d@%d", self.DISPLAY.width, self.DISPLAY.height, self.DISPLAY.frames_per_second) self.CAMERA = pi3d.Camera(is_3d=False, scale=1 / sf) opengles.glBlendFuncSeparate(pi3d.constants.GL_SRC_ALPHA, pi3d.constants.GL_ONE_MINUS_SRC_ALPHA, 1, pi3d.constants.GL_ONE_MINUS_SRC_ALPHA) self.sf = sf
def __init_display(self, sf, fps): if is_pi() and config.blank_console: call_and_log("video/blank_console.sh blank", shell=True) bgcolor = (0.0, 0.0, 0.0, 0.0) self.width = 1920 if sf == 0: #adapt to screen size self.DISPLAY = pi3d.Display.create(background=bgcolor, layer=1, use_pygame=True) sf = self.width / self.DISPLAY.width self.height = self.DISPLAY.height * sf else: logger.debug("Forcing size") self.height = 1080 self.DISPLAY = pi3d.Display.create(x=0, y=0, w=int(self.width / sf), h=int(self.height / sf), background=bgcolor, layer=1, use_pygame=True) self.DISPLAY.frames_per_second = fps logger.info("Display %dx%d@%d", self.DISPLAY.width, self.DISPLAY.height, self.DISPLAY.frames_per_second) self.CAMERA = pi3d.Camera(is_3d=False, scale=1 / sf) opengles.glBlendFuncSeparate(pi3d.constants.GL_SRC_ALPHA, pi3d.constants.GL_ONE_MINUS_SRC_ALPHA, 1, pi3d.constants.GL_ONE_MINUS_SRC_ALPHA) self.sf = sf
def _handle_replay(self, start): self.overlay_mode = start self.__move_sprites() if start: self.feedback.setIcon(None) else: if is_pi(): self.bgr.encourageChange()
def replay(self, replay_type, trigger, extra={}): extra['type'] = trigger call_and_log(["video/generate-replay.sh", config.replay_path, str(config.ignore_recent_chunks), str(config.long_chunks), str(config.short_chunks)]) self.bus.notify('replay_start', extra) if is_pi(): call_and_log(["video/replay.sh", os.path.join(config.replay_path, "replay_{}.h264".format(replay_type)), str(config.replay_fps)]) else: time.sleep(3) self.bus.notify('replay_end')
def replay(self, replay_type, trigger, extra={}): extra['type'] = trigger call_and_log(["video/generate-replay.sh", config.replay_path, str(config.ignore_recent_chunks), str(config.long_chunks), str(config.short_chunks)]) # If we want to keep replays, make a copy of the files with a timestamp. if config.save_replays == True: copyfile(os.path.join(config.replay_save_path, "replay_short.h264"), os.path.join(config.replay_save_path, "{}_replay_short.h264".format(int(time.time())))) copyfile(os.path.join(config.replay_save_path, "replay_long.h264"), os.path.join(config.replay_save_path, "{}_replay_long.h264".format(int(time.time())))) self.bus.notify('replay_start', extra) if is_pi(): call_and_log(["video/replay.sh", os.path.join(config.replay_path, "replay_{}.h264".format(replay_type)), str(config.replay_fps)]) else: time.sleep(3) self.bus.notify('replay_end')
def replay(self, replay_type, trigger, extra={}): extra['type'] = trigger call_and_log([ "video/generate-replay.sh", config.replay_path, str(config.ignore_recent_chunks), str(config.long_chunks), str(config.short_chunks) ]) self.bus.notify('replay_start', extra) if is_pi(): call_and_log([ "video/replay.sh", os.path.join(config.replay_path, "replay_{}.h264".format(replay_type)), str(config.replay_fps) ]) else: time.sleep(3) self.bus.notify('replay_end')
def run(self): try: while self.DISPLAY.loop_running(): self.checkSchedules() if not self.overlay_mode: if self.bg_img: self.bg_img.draw() self.bg.draw() self.instructions.draw() self.goal_time.quick_change( self.__get_time_since_last_goal()) self.goal_time.draw() self.feedback.draw() self.logo.draw() self.people.draw() self.yCounter.draw() self.bCounter.draw() if not self.overlay_mode: self.winner.draw() self.game_mode_ui.quick_change(self.__get_mode_string()) self.game_mode_ui.draw() self.yPlayers.draw() self.bPlayers.draw() if self.draw_menu: self.menu.draw() if self.show_leds: self.__draw_leds() except: traceback.print_exc() if is_pi() and config.blank_console: call_and_log("setterm -blank poke", shell=True)
def run(self): try: while self.DISPLAY.loop_running(): self.checkSchedules() if not self.overlay_mode: if self.bg_img: self.bg_img.draw() self.bg.draw() self.instructions.draw() self.goal_time.quick_change(self.__get_time_since_last_goal()) self.goal_time.draw() self.feedback.draw() self.logo.draw() self.people.draw() self.yCounter.draw() self.bCounter.draw() if not self.overlay_mode: self.winner.draw() self.game_mode_ui.quick_change(self.__get_mode_string()) self.game_mode_ui.draw() self.yPlayers.draw() self.bPlayers.draw() if self.draw_menu: self.menu.draw() if self.show_leds: self.__draw_leds() except: traceback.print_exc() if is_pi() and config.blank_console: call_and_log("setterm -blank poke", shell=True)
def __setup_sprites(self): flat = Shader("uv_flat") matflat = Shader("mat_flat") if is_x11(): # load an image as bg self.bg_img = pi3d.ImageSprite(load_texture( self.__choose_random_bg()), flat, w=int(self.height * bg_w / bg_h), h=self.height, z=101) else: self.bg_img = None if is_pi(): self.bgr = BGRotater(bg_w, bg_h, -1, img("bg"), self.bg_change_interval) self.bgr.change() bg = pi3d.Sprite(w=self.width, h=self.height, z=100) bg.set_shader(matflat) bg.set_alpha(0) self.bg = Flashing(bg) logger.debug("Loading other images") logo_d = (80, 80) self.logo = pi3d.ImageSprite(load_icon( "icons/logo.png", fallback="icons/logo_fallback.png"), flat, w=logo_d[0], h=logo_d[1], x=self._fright(logo_d[0] / 2 + 40), y=self._fbottom(logo_d[1] / 2 + 40), z=50) self.people = Disappear(pi3d.ImageSprite( load_icon("icons/people.png"), flat, w=logo_d[0], h=logo_d[1], x=self._fright(logo_d[0] * 3 / 2 + 40 + 20), y=self._fbottom(logo_d[1] / 2 + 40), z=50), duration=config.md_ev_interval + 1, fade=0.5) in_d = (512 * 0.75, 185 * 0.75) self.instructions = pi3d.ImageSprite( load_icon("icons/instructions.png"), flat, w=in_d[0], h=in_d[1], x=self._fleft(in_d[0] / 2 + 40), y=self._fbottom(in_d[1] / 2 + 40), z=50) self.instructions = LazyTrigger( Disappear(self.instructions, duration=5)) logger.debug("Loading font") printable_cps = list( itertools.chain( range(ord(' '), ord('~')), range(161, 255), [ord("○"), ord("●"), ord("◌"), ord("◉"), ord('Ω')])) fontfile = img("UbuntuMono-B_circle.ttf") font = OutlineFont(fontfile, font_size=80, image_size=1024, outline_size=2, codepoints=printable_cps, mipmap=False, filter=GL_LINEAR) self.goal_time = ChangingText(flat, font=font, string=self.__get_time_since_last_goal(), is_3d=False, justify='C', x=0, y=self._fbottom(90), z=50) self.game_mode_ui = ChangingText(flat, font=font, string=self.__get_mode_string(None), is_3d=False, justify='R', x=self._fright(40), y=self._ftop(60), z=50) self.feedback = KeysFeedback(flat) s = 512 self.yCounter = Move( Counter(0, flat, config.team_colors['yellow'], w=s, h=s, z=50)) self.bCounter = Move( Counter(0, flat, config.team_colors['black'], w=s, h=s, z=50)) playerfont = OutlineFont(fontfile, font_size=50, image_size=768, outline_size=2, codepoints=printable_cps, mipmap=False, filter=GL_LINEAR) self.yPlayers = Multiline(flat, font=playerfont, string=self.getPlayers(left=True), x=-380, y=-250, z=50, justify='C') self.bPlayers = Multiline(flat, font=playerfont, string=self.getPlayers(left=False), x=380, y=-250, z=50, justify='C') menufont = OutlineFont(fontfile, (255, 255, 255, 255), font_size=50, image_size=768, codepoints=printable_cps, mipmap=False, filter=GL_LINEAR) arrow = load_icon("icons/arrow.png") menu = Menu(menufont, arrow, wchar=60, n=12, z=10) self.menu = MenuTree(self.main_menu, menu, rootTitle="Game mode") self.ledShapes = { "YD": FlatDisk(radius=20, sides=12, x=-100, y=-430, z=0, rx=90), "YI": FlatDisk(radius=20, sides=12, x=-100, y=-370, z=0, rx=90), "OK": FlatDisk(radius=50, sides=12, x=0, y=-400, z=0, rx=90), "BD": FlatDisk(radius=20, sides=12, x=100, y=-430, z=0, rx=90), "BI": FlatDisk(radius=20, sides=12, x=100, y=-370, z=0, rx=90), } red = (1, 0, 0, 0) green = (0, 1, 0, 0) self.blackColor = (0, 0, 0, 0) self.ledColors = { "YD": red, "YI": green, "OK": green, "BD": red, "BI": green } self.leds = [] self.winner = WinnerString(flat) # move immediately to position self.__move_sprites()
def __setup_sprites(self): flat = Shader("uv_flat") matflat = Shader("mat_flat") if is_x11(): # load an image as bg self.bg_img = pi3d.ImageSprite(load_texture(self.__choose_random_bg()), flat, w=int(self.height * bg_w / bg_h), h=self.height, z=101) else: self.bg_img = None if is_pi(): self.bgr = BGRotater(bg_w, bg_h, -1, img("bg"), self.bg_change_interval) self.bgr.change() bg = pi3d.Sprite(w=self.width, h=self.height, z=100) bg.set_shader(matflat) bg.set_alpha(0) self.bg = Flashing(bg) logger.debug("Loading other images") logo_d = (80, 80) self.logo = pi3d.ImageSprite(load_icon("icons/logo.png", fallback="icons/logo_fallback.png"), flat, w=logo_d[0], h=logo_d[1], x=self._fright(logo_d[0] / 2 + 40), y=self._fbottom(logo_d[1] / 2 + 40), z=50) self.people = Disappear(pi3d.ImageSprite(load_icon("icons/people.png"), flat, w=logo_d[0], h=logo_d[1], x=self._fright(logo_d[0] * 3 / 2 + 40 + 20), y=self._fbottom(logo_d[1] / 2 + 40), z=50), duration=config.md_ev_interval + 1, fade=0.5) in_d = (512 * 0.75, 185 * 0.75) self.instructions = pi3d.ImageSprite(load_icon("icons/instructions.png"), flat, w=in_d[0], h=in_d[1], x=self._fleft(in_d[0] / 2 + 40), y=self._fbottom(in_d[1] / 2 + 40), z=50) self.instructions = LazyTrigger(Disappear(self.instructions, duration=5)) logger.debug("Loading font") printable_cps = list(itertools.chain(range(ord(' '), ord('~')), range(161, 255), [ord("○"), ord("●"), ord("◌"), ord("◉"), ord('Ω')])) fontfile = img("UbuntuMono-B_circle.ttf") font = OutlineFont(fontfile, font_size=80, image_size=1024, outline_size=2, codepoints=printable_cps, mipmap=False, filter=GL_LINEAR) self.goal_time = ChangingText(flat, font=font, string=self.__get_time_since_last_goal(), is_3d=False, justify='C', x=0, y=self._fbottom(90), z=50) self.game_mode_ui = ChangingText(flat, font=font, string=self.__get_mode_string(None), is_3d=False, justify='R', x=self._fright(40), y=self._ftop(60), z=50) self.feedback = KeysFeedback(flat) s = 512 self.yCounter = Move(Counter(0, flat, config.team_colors['yellow'], w=s, h=s, z=50)) self.bCounter = Move(Counter(0, flat, config.team_colors['black'], w=s, h=s, z=50)) playerfont = OutlineFont(fontfile, font_size=50, image_size=768, outline_size=2, codepoints=printable_cps, mipmap=False, filter=GL_LINEAR) self.yPlayers = Multiline(flat, font=playerfont, string=self.getPlayers(left=True), x=-380, y=-250, z=50, justify='C') self.bPlayers = Multiline(flat, font=playerfont, string=self.getPlayers(left=False), x=380, y=-250, z=50, justify='C') menufont = OutlineFont(fontfile, (255, 255, 255, 255), font_size=50, image_size=768, codepoints=printable_cps, mipmap=False, filter=GL_LINEAR) arrow = load_icon("icons/arrow.png") menu = Menu(menufont, arrow, wchar=60, n=12, z=10) self.menu = MenuTree(self.main_menu, menu, rootTitle="Game mode") self.ledShapes = { "YD": FlatDisk(radius=20, sides=12, x=-100, y=-430, z=0, rx=90), "YI": FlatDisk(radius=20, sides=12, x=-100, y=-370, z=0, rx=90), "OK": FlatDisk(radius=50, sides=12, x=0, y=-400, z=0, rx=90), "BD": FlatDisk(radius=20, sides=12, x=100, y=-430, z=0, rx=90), "BI": FlatDisk(radius=20, sides=12, x=100, y=-370, z=0, rx=90), } red = (1, 0, 0, 0) green = (0, 1, 0, 0) self.blackColor = (0, 0, 0, 0) self.ledColors = {"YD": red, "YI": green, "OK": green, "BD": red, "BI": green} self.leds = [] self.winner = WinnerString(flat) # move immediately to position self.__move_sprites()