libtcod / python-tcod

A high-performance Python port of libtcod. Includes the libtcodpy module for backwards compatibility with older projects.
BSD 2-Clause "Simplified" License
409 stars 36 forks source link

Feature/image blit #28

Closed will8211 closed 7 years ago

will8211 commented 7 years ago

Hi! I'm working on "Roguelike Tutorial, using python3+tdl" on roguebasin. It's based on Jotaf's "Complete Roguelike Tutorial, using python+libtcod".

http://www.roguebasin.com/index.php?title=Roguelike_Tutorial,_using_python3%2Btdl

For part 10, there's a call to tcod's image_blit_2x.

In this fork, I've added an image_blit method to _BaseConsole. It takes the name of an image as a string and x/y coordinates for the placement of the upper left corner. It converts the image to a TCOD image and passes the variables to TCOD_image_blit_2x or TCOD_image_blit_rect depending on a flag called "subcell_res". In the future, it could also be used to allow image scaling and through TCOD_image_blit.

It would be great if you would be willing to add this the master branch. I can provide the project I used for testing on request.

Thanks! Will

coveralls commented 7 years ago

Coverage Status

Coverage decreased (-0.3%) to 72.823% when pulling 6404363088b2d5f2d05af913577ae2077e49df00 on will8211:feature/image_blit into f81e12796e737a218b62d5b6f0ee4ff6bb028eae on HexDecimal:master.

coveralls commented 7 years ago

Coverage Status

Coverage decreased (-0.3%) to 72.823% when pulling 6404363088b2d5f2d05af913577ae2077e49df00 on will8211:feature/image_blit into f81e12796e737a218b62d5b6f0ee4ff6bb028eae on HexDecimal:master.

coveralls commented 7 years ago

Coverage Status

Coverage decreased (-0.3%) to 72.823% when pulling 6404363088b2d5f2d05af913577ae2077e49df00 on will8211:feature/image_blit into f81e12796e737a218b62d5b6f0ee4ff6bb028eae on HexDecimal:master.

HexDecimal commented 7 years ago

The tdl_image variable points to C data not managed by the Python garbage collector. Not manually freeing it will cause a memory leak.

I expect a method like this to be called rather frequently, but the way it's set up is I/O bound, this could cause a lot of lag per call.

The tcod_console attribute is exclusive to the tdl.Console class. This method will break when called on a Window instance. It's easy to fix but I'm not sure that I'll keep supporting the Window class in the future.

I'm going to work on porting libtcod-cffi's tcod.image.Image class to work with the tdl.Console class. It will be easy for me to setup, but it won't be able to blit to Window objects. Will that be okay?

will8211 commented 7 years ago

Thanks for the detailed reply!

I suspected there might be some challenges involved that I hadn't foreseen. The function seemed too easy to implement, considering that you hadn't done it already.

My main goal is to use image_blit_2x to blit a single image into the root console to create a title screen. Would that feature be doable in the near future? I think it's the only thing missing to fully recreate Jotaf's libtcod tutorial.

Also, I'd just like to say that I really like tdl, and I'm very happy to see that you've continued developing it. Based on the interest I've seen in the tutorial, I'd say a lot of people are enjoying using it. Thanks a lot for all the work you're putting into it!

Cheers, Will

On May 29, 2017 6:56 AM, "Kyle Stewart" notifications@github.com wrote:

The tdl_image variable points to C data not managed by the Python garbage collector. Not manually freeing it will cause a memory leak.

I expect a method like this to be called rather frequently, but the way it's set up is I/O bound, this could cause a lot of lag per call.

The tcod_console attribute is exclusive to the tdl.Console class. This method will break when called on a Window instance. It's easy to fix but I'm not sure that I'll keep supporting the Window class in the future.

I'm going to work on porting libtcod-cffi's tcod.image.Image https://libtcod-cffi.readthedocs.io/en/latest/tcod_ref.html#tcod.image.Image class to work with the tdl.Console class. It will be easy for me to setup, but it won't be able to blit to Window objects. Will that be okay?

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/HexDecimal/python-tdl/pull/28#issuecomment-304545677, or mute the thread https://github.com/notifications/unsubscribe-auth/ALlgPTHVtU5r6Bt-RUJ8TU9iSIWL6DoXks5r-fumgaJpZM4NonBM .

HexDecimal commented 7 years ago

I've released a new version of tdl. I haven't tested this specific code yet. The feature you asked for will look something like this:

tcod.image_load(filename).blit_2x(tdl_console, dest_x, dest_y)
will8211 commented 7 years ago

Fantastic! Very pythonic. I'll test it out this evening.

On May 29, 2017 1:55 PM, "Kyle Stewart" notifications@github.com wrote:

I've released a new version of tdl. I haven't tested this specific code yet. The feature you asked for will look something like this:

tcod.image_load(filename).blit_2x(tdl_console, dest_x, dest_y)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/HexDecimal/python-tdl/pull/28#issuecomment-304578327, or mute the thread https://github.com/notifications/unsubscribe-auth/ALlgPTBMSPMfDU4JVaqL4uhYRuw1wYC0ks5r-l3HgaJpZM4NonBM .