Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

initial pyscroll rendering #280

Merged
merged 5 commits into from Apr 10, 2017
Merged

Conversation

bitcraft
Copy link
Collaborator

@bitcraft bitcraft commented Apr 4, 2017

Using pyscroll for map rendering. Improvements include much faster map loading (still room for improvement...), and more synchronized map animations (water tiles). There is one bug in the pyscroll library affecting Tuxemon that we may wait to be fixed, or just wait. Map animations that cover sprites will not be animated. For example, the moving "M" sign will not animate if the player is behind it.

Also, there is some linting done for pep8 and docstrings added. Some sections of code have been commented out to hold them as a reference for a while until any/all visual bugs are worked out.

@ShadowApex
Copy link
Contributor

Looks great, but when I try testing it out, I get a traceback as soon as it tries to switch to the world state:

Traceback (most recent call last):
  File "./tuxemon.py", line 60, in <module>
    main()
  File "/tmp/Tuxemon/tuxemon/core/main.py", line 109, in main
    control.main()
  File "/tmp/Tuxemon/tuxemon/core/control.py", line 542, in main
    self.main_loop()
  File "/tmp/Tuxemon/tuxemon/core/control.py", line 592, in main_loop
    self.key_events = list(events)
  File "/tmp/Tuxemon/tuxemon/core/control.py", line 303, in process_events
    game_event = self._send_event(game_event)
  File "/tmp/Tuxemon/tuxemon/core/control.py", line 323, in _send_event
    game_event = state.process_event(game_event)
  File "/tmp/Tuxemon/tuxemon/core/components/menu/menu.py", line 411, in process_event
    self.on_menu_selection(self.get_selected_item())
  File "/tmp/Tuxemon/tuxemon/core/states/persistance/load_menu.py", line 44, in on_menu_selection
    self.game.push_state("WorldState")
  File "/tmp/Tuxemon/tuxemon/core/state.py", line 405, in push_state
    instance.startup(**kwargs)
  File "/tmp/Tuxemon/tuxemon/core/states/world/worldstate.py", line 104, in startup
    self.change_map(map_name)
  File "/tmp/Tuxemon/tuxemon/core/states/world/worldstate.py", line 669, in change_map
    map_data = self.load_map(map_name)
  File "/tmp/Tuxemon/tuxemon/core/states/world/worldstate.py", line 704, in load_map
    map_data["data"] = map.Map(map_name)
  File "/tmp/Tuxemon/tuxemon/core/components/map.py", line 88, in __init__
    self.load(filename)
  File "/tmp/Tuxemon/tuxemon/core/components/map.py", line 168, in load
    self.initialize_renderer()
  File "/tmp/Tuxemon/tuxemon/core/components/map.py", line 202, in initialize_renderer
    visual_data.convert_surfaces(self.renderer._buffer, True)
AttributeError: 'TiledMapData' object has no attribute 'convert_surfaces'

@bitcraft
Copy link
Collaborator Author

bitcraft commented Apr 9, 2017

Pyscroll needs to be up-to-date. Should be version 2.16.12

@ShadowApex
Copy link
Contributor

Thanks bitcraft, didn't realize I had an outdated pyscroll. Thanks also for including the new dependency in requirements.txt. I can also update the README and install instructions when we merge this.

After updating pyscroll, the initial crash I got was fixed, but I found a few other interesting bugs aside from animations not playing over the player:

  • In small maps, menus will not clear in regions of the screen that have no tile data:

An easy fix for this could be to just expand the map and add black tiles in the smaller TMX maps or squeeze in a blit of a black square at the start of every frame.

  • When your character is parallel to a collision wall, and not facing it, when you try to face the wall, the player sprite does not change.

  • When getting into combat, right after the starting sprite animations complete (when the monster and trainer sprites move into position), it crashes with this tb:

Traceback (most recent call last):
  File "./tuxemon.py", line 60, in <module>
    main()
  File "/tmp/Tuxemon/tuxemon/core/main.py", line 109, in main
    control.main()
  File "/tmp/Tuxemon/tuxemon/core/control.py", line 542, in main
    self.main_loop()
  File "/tmp/Tuxemon/tuxemon/core/control.py", line 603, in main_loop
    self.update(time_delta)
  File "/tmp/Tuxemon/tuxemon/core/control.py", line 206, in update
    state.update(dt)
  File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 154, in update
    self.transition_phase(new_phase)
  File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 247, in transition_phase
    self.fill_battlefield_positions(ask=self._round > 1)
  File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 393, in fill_battlefield_positions
    self.add_monster_into_play(player, next(available))
  File "/tmp/Tuxemon/tuxemon/core/states/combat/combat.py", line 408, in add_monster_into_play
    self.animate_monster_release_bottom(feet, monster)
  File "/tmp/Tuxemon/tuxemon/core/states/combat/combat_animations.py", line 119, in animate_monster_release_bottom
    scale_sprite(capdev, .4)
  File "/tmp/Tuxemon/tuxemon/core/tools.py", line 221, in scale_sprite
    sprite._original_image = pygame.transform.scale(sprite._original_image, sprite.rect.get_size())
AttributeError: 'pygame.Rect' object has no attribute 'get_size'

@bitcraft
Copy link
Collaborator Author

bitcraft commented Apr 9, 2017

Thanks for the detailed reports!

Fixed screen clearing by modifying pyscroll. I implemented a couple features just for Tuxemon, so I don't see a problem with a workaround in pyscroll to accommodate Tuxemon. Technically, it is an issue what should be solved in Tuxemon, in the future sometime.

@bitcraft
Copy link
Collaborator Author

bitcraft commented Apr 9, 2017

Pyscroll will need to be updated to fix the screen clearing bug. Its on pip.

@ShadowApex
Copy link
Contributor

Did some testing and everything else looks good! We'll need to open another GitHub issue to make sure we later address the animations playing over the player. Other than that, I don't see any other regressions switching over to Pyscroll.

Thanks @bitcraft !

@ShadowApex ShadowApex merged commit d7e8ae9 into Tuxemon:development Apr 10, 2017
@bitcraft
Copy link
Collaborator Author

Just a minor note, the bug that causes the "M" sign to stop moving when the player moves under it has been fixed in pyscroll. Needs version 2.16.14

@MirceaKitsune
Copy link
Contributor

@bitcraft That's great to hear! Although I'm afraid the fix only introduces a crash for me; I updated my clone of Pyscroll Git, and now when I exit the house and go outside Tuxemon closes down upon map load. Here is the console crash log:

mircea@linux-qz0r:~/Games/Small/Python/Tuxemon/Tuxemon_GIT/tuxemon> python ./tuxemon.py No handlers could be found for logger "core.components.rumble" libpng warning: iCCP: known incorrect sRGB profile State was not able to be GC'd <core.states.transition.fade.FadeInTransition object at 0x7f9fc75738d0> State was not able to be GC'd <core.states.splash.SplashState object at 0x7f9fc7573590> State was not able to be GC'd <core.states.transition.fade.FadeOutTransition object at 0x7f9fc7573790> Map was not preloaded. Loading from disk. State was not able to be GC'd <core.states.start.StartState object at 0x7f9fc7573150> State was not able to be GC'd <core.states.transition.fade.FadeInTransition object at 0x7f9fc7573650> State was not able to be GC'd <core.components.menu.input.InputMenu object at 0x7f9feee9ba50> Map was not preloaded. Loading from disk. Map was not preloaded. Loading from disk. libpng warning: iCCP: known incorrect sRGB profile libpng warning: iCCP: known incorrect sRGB profile Traceback (most recent call last): File "./tuxemon.py", line 60, in <module> main() File "/home/mircea/Games/Small/Python/Tuxemon/Tuxemon_GIT/tuxemon/core/main.py", line 98, in main control.main() File "/home/mircea/Games/Small/Python/Tuxemon/Tuxemon_GIT/tuxemon/core/control.py", line 542, in main self.main_loop() File "/home/mircea/Games/Small/Python/Tuxemon/Tuxemon_GIT/tuxemon/core/control.py", line 603, in main_loop self.update(time_delta) File "/home/mircea/Games/Small/Python/Tuxemon/Tuxemon_GIT/tuxemon/core/control.py", line 206, in update state.update(dt) File "/home/mircea/Games/Small/Python/Tuxemon/Tuxemon_GIT/tuxemon/core/states/world/worldstate.py", line 275, in update super(WorldState, self).update(time_delta) File "/home/mircea/Games/Small/Python/Tuxemon/Tuxemon_GIT/tuxemon/core/state.py", line 142, in update self.animations.update(time_delta) File "/usr/lib64/python2.7/site-packages/pygame/sprite.py", line 399, in update for s in self.sprites(): s.update(*args) File "/home/mircea/Games/Small/Python/Tuxemon/Tuxemon_GIT/tuxemon/core/components/animation.py", line 210, in update self.finish() File "/home/mircea/Games/Small/Python/Tuxemon/Tuxemon_GIT/tuxemon/core/components/animation.py", line 221, in finish self._execute_callbacks("on interval") File "/home/mircea/Games/Small/Python/Tuxemon/Tuxemon_GIT/tuxemon/core/components/animation.py", line 89, in _execute_callbacks [cb() for cb in callbacks] File "/home/mircea/Games/Small/Python/Tuxemon/Tuxemon_GIT/tuxemon/core/states/world/worldstate.py", line 234, in handle_delayed_teleport self.change_map(map_name) File "/home/mircea/Games/Small/Python/Tuxemon/Tuxemon_GIT/tuxemon/core/states/world/worldstate.py", line 646, in change_map map_data = self.load_map(map_name) File "/home/mircea/Games/Small/Python/Tuxemon/Tuxemon_GIT/tuxemon/core/states/world/worldstate.py", line 681, in load_map map_data["data"] = map.Map(map_name) File "/home/mircea/Games/Small/Python/Tuxemon/Tuxemon_GIT/tuxemon/core/components/map.py", line 129, in __init__ self.load(filename) File "/home/mircea/Games/Small/Python/Tuxemon/Tuxemon_GIT/tuxemon/core/components/map.py", line 213, in load self.renderer = self.initialize_renderer() File "/home/mircea/Games/Small/Python/Tuxemon/Tuxemon_GIT/tuxemon/core/components/map.py", line 243, in initialize_renderer visual_data = pyscroll.data.TiledMapData(self.data) File "/home/mircea/Games/Small/Python/Tuxemon/Tuxemon_GIT/tuxemon/pyscroll/data.py", line 230, in __init__ self.reload_animations() File "/home/mircea/Games/Small/Python/Tuxemon/Tuxemon_GIT/tuxemon/pyscroll/data.py", line 254, in reload_animations positions = tuple(self.tmx.get_tile_locations_by_gid(gid)) File "/home/mircea/Games/Small/Python/Tuxemon/Tuxemon_GIT/tuxemon/core/components/pytmx/pytmx.py", line 548, in <genexpr> self.layers[l].data[y][x] == gid) File "/home/mircea/Games/Small/Python/Tuxemon/Tuxemon_GIT/tuxemon/core/components/pytmx/pytmx.py", line 216, in __getattr__ raise AttributeError AttributeError

@bitcraft
Copy link
Collaborator Author

you will need to update pytmx as well. i used a rarely-tested pytmx feature, which is buggy. new pytmx will fix it.

@MirceaKitsune
Copy link
Contributor

Oh... my bad. That fixed the crash, and I can confirm the scrolling sign works perfectly when standing behind it now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants