Пример #1
0
 def update_title(self):
     title = self.base_title
     title += " [HIGH MAP 0x9C00-0x9FFF]" if self.tilemap.map_offset == constants.HIGH_TILEMAP else \
         " [LOW MAP 0x9800-0x9BFF]"
     title += " [HIGH DATA (SIGNED) 0x8800-0x97FF]" if self.tilemap.signed_tile_data else \
         " [LOW DATA (UNSIGNED) 0x8000-0x8FFF]"
     if self.tilemap._select == "WINDOW":
         title += " [Window]"
     if self.tilemap._select == "BACKGROUND":
         title += " [Background]"
     sdl2.SDL_SetWindowTitle(self._window, title.encode("utf8"))
Пример #2
0
def run():
    out_blocks = ""
    out_images = ""
    all_blocks = []

    sdl2.SDL_Init(sdl2.SDL_INIT_VIDEO | sdl2.SDL_INIT_EVERYTHING)
    sdl_image.IMG_Init(sdl_image.IMG_INIT_PNG)

    window = sdl2.ext.Window("BAConv", size=(1024, 384))
    window.show()
    ren = sdl2.ext.Renderer(window, flags=sdl2.SDL_RENDERER_ACCELERATED)
    # makes zoomed graphics blocky (for retro effect)
    sdl2.SDL_SetHint(sdl2.SDL_HINT_RENDER_SCALE_QUALITY, b"nearest")
    # makes the graphics look and act like the desired screen size, even though they may be rendered at a different one
    sdl2.SDL_RenderSetLogicalSize(ren.sdlrenderer, 256, 96)

    frames = []
    count = 0
    limit = 8000  # only deal with this many frames

    pass1 = True  # True means calculate blocks, False means load from pre-calculated file

    if pass1:
        # pass 1 - gather all the blocks
        for i in range(0, int(6565 / 4)):
            # for i in range(43, int(600 / 4)):
            count += 1
            if count > limit:  # stop early
                break
            events = sdl2.ext.get_events()  # otherwise window doesn't update
            for event in events:
                if event.type == sdl2.SDL_QUIT:
                    exit(0)
            ren.clear()
            file = f"image-{i*4+1:03}.png"
            sdl2.SDL_SetWindowTitle(window.window, file.encode('utf-8'))
            frame = processImage(
                file, ren)  # also draws left hand side pre-processed
            frames.append(frame)

            renderImage(frame, ren)  # right hand side post-process
            sdl2.SDL_RenderPresent(ren.sdlrenderer)
            window.refresh()

        print(f"Processed {count} frames.")

        values = 0
        size = 0
        for frame in frames:
            values += len(frame)
            size += frame[1] * (len(frame) - 2) + 1
            print(frame)

        print(f"Raw values: {values}")
        print(f"Average values per frame: {values/len(frames)}")
        print(f"Theoretical size: {size/8}")

        exit(0)

        # store blocks in file
        file_lines = []
        for block in all_blocks:
            file_lines.append(block.serialize())

        with open("data_file.txt", "w") as write_file:
            write_file.writelines("\n".join(file_lines))
    else:
        # read in blocks from file (quicker)
        with open("data_file.txt", "r") as read_file:
            file_lines = read_file.readlines()
            all_blocks = []
            for line in file_lines:
                all_blocks.append(Block.fromData(line.split(",")))

    # sort and choose top blocks
    all_blocks.sort(reverse=True)

    # 1024 is currently all you're planning to store
    # todo: choose final number of blocks to use
    # all_blocks=all_blocks[0:1024]
    for i, b in enumerate(all_blocks):
        print(f"Block {i}: {b.count}")

    # pass 2 - build new images with top blocks
    all_images = []
    count = 0
    # for i in range(43, int(6509 / 4)):
    for i in range(0, int(6565 / 4)):
        # for i in range(43, int(600 / 4)):
        count += 1
        if count > limit:  # stop early
            break
        ren.clear()
        file = f"image-{i*4+1:03}.png"
        sdl2.SDL_SetWindowTitle(window.window, file.encode('utf-8'))
        image = reprocessImage(
            file, ren, all_blocks)  # also draws left hand side pre-processed
        all_images.append(image)
        renderImage(image, all_blocks, ren)  # right hand side post-process
        events = sdl2.ext.get_events()  # otherwise window doesn't update
        sdl2.SDL_RenderPresent(ren.sdlrenderer)
        window.refresh()

    # play back final frames in loop
    fr = 0
    while True:
        fr = (fr + 1) % len(all_images)
        events = sdl2.ext.get_events()  # otherwise window doesn't update
        for event in events:
            if event.type == sdl2.SDL_QUIT:
                exit(0)
        ren.clear()
        file = f"image-{i*2+1:03}.png"
        sdl2.SDL_SetWindowTitle(window.window, file.encode('utf-8'))
        renderImage(all_images[fr], all_blocks, ren)
        sdl2.SDL_RenderPresent(ren.sdlrenderer)
        window.refresh()
Пример #3
0
 def set_title(self, title):
     sdl2.SDL_SetWindowTitle(self._window, title.encode())
Пример #4
0
 def update_title(self):
     title = self.base_title
     title += " " if self.mb.lcd.LCDC.sprite_enable else " [Disabled]"
     sdl2.SDL_SetWindowTitle(self._window, title.encode("utf8"))
Пример #5
0
 def update_title(self):
     title = self.base_title
     title += " [8x16]" if self.mb.lcd.LCDC.sprite_height else " [8x8]"
     sdl2.SDL_SetWindowTitle(self._window, title.encode("utf8"))
Пример #6
0
 def title(self, value: str):
     data = c_char_p(value.encode())
     sdl2.SDL_SetWindowTitle(self._window, data)
     self._title = value
Пример #7
0
 def set_caption_message(self, msg):
     """Add a message to the window caption."""
     title = self.caption + (' - ' + msg if msg else '')
     sdl2.SDL_SetWindowTitle(self.display, title)
Пример #8
0
 def _vispy_set_title(self, title):
     if self._id is None:
         return
     # Set the window title. Has no effect for widgets
     sdl2.SDL_SetWindowTitle(self._id.window, title.encode('UTF-8'))
Пример #9
0
def run():
    out_blocks = ""
    out_images = ""
    all_blocks = []

    sdl2.SDL_Init(sdl2.SDL_INIT_VIDEO | sdl2.SDL_INIT_EVERYTHING)
    sdl_image.IMG_Init(sdl_image.IMG_INIT_PNG)

    window = sdl2.ext.Window("BAConv", size=(1024, 384))
    window.show()
    ren = sdl2.ext.Renderer(window, flags=sdl2.SDL_RENDERER_ACCELERATED)
    # makes zoomed graphics blocky (for retro effect)
    sdl2.SDL_SetHint(sdl2.SDL_HINT_RENDER_SCALE_QUALITY, b"nearest")
    # makes the graphics look and act like the desired screen size, even though they may be rendered at a different one
    sdl2.SDL_RenderSetLogicalSize(ren.sdlrenderer, 256, 96)
    max_blocks = 0
    total_blocks = 0
    count = 0
    limit = 100

    # pass 1 - gather all the blocks
    for i in range(0, int(6565 / 4)):
        count += 1
        if count > limit:  # stop early
            break
        events = sdl2.ext.get_events()  # otherwise window doesn't update
        ren.clear()
        file = f"image-{i*4+1:03}.png"
        sdl2.SDL_SetWindowTitle(window.window, file.encode('utf-8'))
        image, blocks = processImage(
            file, ren)  # also draws left hand side pre-processed

        # add blocks to master list
        for i, block in enumerate(blocks):
            found = False
            for j, b in enumerate(all_blocks):
                if block == b:  # better match found update existing record
                    all_blocks[j].count += blocks[i].count
                    found = True  # found a match of some sort
            if not found:  # totally new block
                all_blocks.append(block)

        num_blocks = len(blocks)
        total_blocks += num_blocks
        if max_blocks < num_blocks:
            max_blocks = num_blocks
        renderImage(image, blocks, ren)  # right hand side post-process
        sdl2.SDL_RenderPresent(ren.sdlrenderer)
        window.refresh()

    print(f"Max blocks: {max_blocks}")
    print(f"Total blocks: {total_blocks}")
    print(f"Average blocks: {total_blocks/count}")
    print(f"Processed {count} frames.")

    # sort and choose top blocks
    all_blocks.sort(reverse=True)

    # 1024 is currently all you're planning to store
    # todo: choose final number of blocks to use
    # all_blocks=all_blocks[0:1024]
    for i, b in enumerate(all_blocks):
        print(f"Block {i}: {b.count}")

    # pass 2 - build new images with top blocks
    all_images = []
    count = 0
    for i in range(43, int(6509 / 2)):
        count += 1
        if count > limit:  # stop early
            break
        ren.clear()
        file = f"image-{i*2+1:03}.png"
        sdl2.SDL_SetWindowTitle(window.window, file.encode('utf-8'))
        image = reprocessImage(
            file, ren, all_blocks)  # also draws left hand side pre-processed
        all_images.append(image)
        renderImage(image, all_blocks, ren)  # right hand side post-process
        events = sdl2.ext.get_events()  # otherwise window doesn't update
        sdl2.SDL_RenderPresent(ren.sdlrenderer)
        window.refresh()

    fr = 0
    while True:
        fr = (fr + 1) % len(all_images)
        events = sdl2.ext.get_events()  # otherwise window doesn't update
        ren.clear()
        file = f"image-{i*2+1:03}.png"
        sdl2.SDL_SetWindowTitle(window.window, file.encode('utf-8'))
        renderImage(all_images[fr], all_blocks, ren)
        sdl2.SDL_RenderPresent(ren.sdlrenderer)
        window.refresh()
        sdl2.SDL_Delay(10)
Пример #10
0
def start_system() -> None:
    sdl(sdl2.SDL_Init(sdl2.SDL_INIT_EVERYTHING))
    window = sdl(
        sdl2.SDL_CreateWindow(b"Overwritten by game loop",
                              sdl2.SDL_WINDOWPOS_UNDEFINED,
                              sdl2.SDL_WINDOWPOS_UNDEFINED, SCREEN_WIDTH,
                              SCREEN_HEIGHT, sdl2.SDL_WINDOW_OPENGL))
    renderer = sdl(
        sdl2.SDL_CreateRenderer(window, -1, sdl2.SDL_RENDERER_ACCELERATED))

    entities.initialize_bullet_pool(renderer)
    entities.Entities.append(entities.create_player(renderer))

    for i in range(5):
        for j in range(3):
            x = (i / 5) * SCREEN_WIDTH + (entities.ENEMY_SIZE / 2)
            y = j * entities.ENEMY_SIZE + \
                (entities.ENEMY_SIZE / 2)
            entities.Entities.append(
                entities.create_enemy(renderer, Vec2f(x, y)))

    event = sdl2.SDL_Event()
    running = True
    while running:
        frame_start_time = sdl2.SDL_GetTicks()
        while sdl(sdl2.SDL_PollEvent(ctypes.byref(event))) != 0:
            if event.type == sdl2.SDL_QUIT:
                running = False
                break

        sdl(sdl2.SDL_SetRenderDrawColor(renderer, 255, 255, 255, 255))
        sdl(sdl2.SDL_RenderClear(renderer))

        # Start draw and update subsystem. In a naïve ECS implementation every
        # system iterates through the complete list of entities. Below we
        # operate on only the active subset of entities.
        for entity in entities.Entities:
            if entity.active:
                entity.draw(renderer)
                entity.update()

        # Start collision subsystem
        check_collisions()
        sdl(sdl2.SDL_RenderPresent(renderer))

        # Add artificial wait to simulate running game on slow computer
        # sdl2.SDL_Delay(100)

        # If we're running at half TARGET_TICKS_PER_SECOND, delta is 2. If we're
        # running at double TARGET_TICKS_PER_SECOND, delta becomes 0.5.
        frame_render_time = sdl2.SDL_GetTicks() - frame_start_time

        # Alternatively, we could store just frame_render_time in delta_time and
        # defer calculation below to each component.
        config.delta_time = (frame_render_time / 1000) * \
            TARGET_TICKS_PER_SECOND

        sdl2.SDL_SetWindowTitle(
            window,
            f"""Space Invaders - Delta: {config.delta_time:.2f}, Render: {frame_render_time} ms"""
            .encode())

    sdl(sdl2.SDL_DestroyRenderer(renderer))
    sdl(sdl2.SDL_DestroyWindow(window))
Пример #11
0
 def _set_window_title(self, name):
     window_name = f'{name} - CASINT: CASIO Basic Interpreter'.encode()
     sdl2.SDL_SetWindowTitle(self.window, window_name)
Пример #12
0
def run():
    out_blocks = ""
    out_images = ""

    sdl2.SDL_Init(sdl2.SDL_INIT_VIDEO | sdl2.SDL_INIT_EVERYTHING)
    sdl_image.IMG_Init(sdl_image.IMG_INIT_PNG)

    window = sdl2.ext.Window("BAConv", size=(1024, 384))
    window.show()
    ren = sdl2.ext.Renderer(window, flags=sdl2.SDL_RENDERER_ACCELERATED)
    # makes zoomed graphics blocky (for retro effect)
    sdl2.SDL_SetHint(sdl2.SDL_HINT_RENDER_SCALE_QUALITY, b"nearest")
    # makes the graphics look and act like the desired screen size, even though they may be rendered at a different one
    sdl2.SDL_RenderSetLogicalSize(ren.sdlrenderer, 256, 96)
    max_blocks = 0
    total_blocks = 0
    count = 0
    cart = 1

    for i in range(0, int(6565 / 2)):
        count += 1
        # for i in range(254, 355):
        # while True:
        # 	i=304
        events = sdl2.ext.get_events()
        ren.clear()
        file = f"image-{i*2+1:03}.png"
        sdl2.SDL_SetWindowTitle(window.window, file.encode('utf-8'))
        image, blocks = processImage(
            file, ren)  # also draws left hand side pre-processed
        num_blocks = len(blocks)
        total_blocks += num_blocks
        if max_blocks < num_blocks:
            max_blocks = num_blocks
            # print(f"New max:{num_blocks}")
        renderImage(image, blocks, ren)  # right hand side post-process
        sdl2.SDL_RenderPresent(ren.sdlrenderer)
        window.refresh()

        # output encoded image
        out_images += '"'
        for i in range(0, 192):
            if image[i] + 35 == 92:
                out_images += '\\\\'
            else:
                out_images += f"{chr(image[i]+35)}"
        out_images += '",\n'

        # output encoded blocks
        out_blocks += "{"
        for block in blocks[2:]:
            out_blocks += '"'
            for y in range(0, 8):
                val = 0
                for x in range(0, 8):
                    if block[y * 8 + x] == 1:
                        val += 2**x
                out_blocks += f"{val:02x}"
            out_blocks += '",'
        out_blocks += "},\n"

        if count % 40 == 0:

            output = header.replace(
                '$$',
                f"{(cart+1):02}") + out_images + middle + out_blocks + footer
            outfile = open(f"badbadapple{cart:02}.p8", 'w')
            outfile.write(output)
            outfile.close()

            out_images = ''
            out_blocks = ''
            cart += 1

    print(out_images)

    print(f"Max blocks: {max_blocks}")
    print(f"Total blocks: {total_blocks}")
    print(f"Average blocks: {total_blocks/count}")
    print(f"Processed {count} frames.")