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

Add a tmx loader to map_utils #149

Merged
merged 6 commits into from Jul 13, 2016

Conversation

Projects
None yet
2 participants
@udiboy1209
Member

udiboy1209 commented Jun 28, 2016

Capable of loading and displaying single layer tmx maps with animated tiles.

Depends on python-tmx module version 1.6

@Kovak I had recently submitted a patch to that module for loading animated tile frames, hence it might not have been updated on pypi. The maintainer said it would be up as version 1.6 so you should wait for that to be distributed before testing the example.

@udiboy1209 udiboy1209 referenced this pull request Jun 28, 2016

Closed

tiled_gsoc #148

@udiboy1209

This comment has been minimized.

Member

udiboy1209 commented Jul 7, 2016

@Kovak I've pushed the code and example for loading a layered map. But the example only gives me a black screen. Can you check the system init code to see if something's missing.

Fix layer array generation bug in map_data
and also fix example to use correct system_names
@udiboy1209

This comment has been minimized.

Member

udiboy1209 commented Jul 10, 2016

@Kovak I fixed the previous error, can you tell me the cause of this error. The log isn't helping much.

[INFO              ] [Logger      ] Record log in /home/udiboy/.kivy/logs/kivy_16-07-11_60.txt
[INFO              ] [Kivy        ] v1.9.1
[INFO              ] [Python      ] v3.5.1+ (default, Mar 30 2016, 22:46:26) 
[GCC 5.3.1 20160330]
[INFO              ] [Factory     ] 179 symbols loaded
[INFO              ] [Image       ] Providers: img_tex, img_dds, img_gif, img_sdl2 (img_pil, img_ffpyplayer ignored)
[INFO              ] [OSC         ] using <multiprocessing> for socket
[INFO              ] [Window      ] Provider: sdl2(['window_egl_rpi'] ignored)
[INFO              ] [GL          ] OpenGL version <b'3.0 Mesa 11.2.0'>
[INFO              ] [GL          ] OpenGL vendor <b'Intel Open Source Technology Center'>
[INFO              ] [GL          ] OpenGL renderer <b'Mesa DRI Intel(R) HD Graphics 520 (Skylake GT2) '>
[INFO              ] [GL          ] OpenGL parsed version: 3, 0
[INFO              ] [GL          ] Shading version <b'1.30'>
[INFO              ] [GL          ] Texture max size <8192>
[INFO              ] [GL          ] Texture max units <32>
[INFO              ] [Window      ] auto add sdl2 input provider
[INFO              ] [Window      ] virtual keyboard not allowed, single mode, not docked
[INFO              ] [Audio       ] Providers: audio_sdl2 (audio_ffpyplayer ignored)
[INFO              ] [Shader      ] Read </home/udiboy/Projects/kivy/kivent/examples/assets/glsl/positionshader.glsl>
[INFO              ] [Shader      ] Read </home/udiboy/Projects/kivy/kivent/examples/assets/glsl/positionshader.glsl>
[INFO              ] [Shader      ] Read </home/udiboy/Projects/kivy/kivent/examples/assets/glsl/positionshader.glsl>
[INFO              ] [Shader      ] Read </home/udiboy/Projects/kivy/kivent/examples/assets/glsl/positionshader.glsl>
[ERROR             ] [GameSystem  ] System_id: position not attached retrying in 1 sec. If you see this error once or twice, we are probably just waiting on the KV file to load. If you see it a whole bunch something is probably wrong. Make sure all systems are setup properly.
[INFO              ] [ProbeSysfs  ] device match: /dev/input/event5
[INFO              ] [MTD         ] Read event from </dev/input/event5>
[INFO              ] [Base        ] Start application main loop
 Exception in thread Thread-1:
 Traceback (most recent call last):
   File "/usr/lib/python3.5/threading.py", line 914, in _bootstrap_inner
     self.run()
   File "/usr/lib/python3.5/threading.py", line 862, in run
     self._target(*self._args, **self._kwargs)
   File "/home/udiboy/.apps/venvs/kivy3/lib/python3.5/site-packages/kivy/input/providers/mtdev.py", line 219, in _thread_run
     _device = Device(_fn)
   File "/home/udiboy/.apps/venvs/kivy3/lib/python3.5/site-packages/kivy/lib/mtdev.py", line 131, in __init__
     self._fd = os.open(filename, os.O_NONBLOCK | os.O_RDONLY)
 PermissionError: [Errno 13] Permission denied: '/dev/input/event5'

[INFO              ] [KivEnt      ] Vertex Format: vertex_format_4f registered. Size per vertex is: 16. Format is [(b'pos', 2, b'float', 0, False), (b'uvs', 2, b'float', 8, False)].
[INFO              ] [KivEnt      ] Vertex Format: vertex_format_7f registered. Size per vertex is: 28. Format is [(b'pos', 2, b'float', 0, False), (b'uvs', 2, b'float', 8, False), (b'rot', 1, b'float', 16, False), (b'center', 2, b'float', 20, False)].
[INFO              ] [KivEnt      ] Vertex Format: vertex_format_2f4ub registered. Size per vertex is: 12. Format is [(b'pos', 2, b'float', 0, False), (b'v_color', 4, b'ubyte', 8, True)].
[INFO              ] [KivEnt      ] Vertex Format: vertex_format_7f4ub registered. Size per vertex is: 32. Format is [(b'pos', 2, b'float', 0, False), (b'uvs', 2, b'float', 8, False), (b'rot', 1, b'float', 16, False), (b'center', 2, b'float', 20, False), (b'v_color', 4, b'ubyte', 28, True)].
[INFO              ] [KivEnt      ] Vertex Format: vertex_format_4f4ub registered. Size per vertex is: 20. Format is [(b'pos', 2, b'float', 0, False), (b'uvs', 2, b'float', 8, False), (b'v_color', 4, b'ubyte', 16, True)].
[INFO              ] [KivEnt      ] Model Manager reserved space for vertex format: vertex_format_4f. 75 KiB was reserved for vertices, fitting a total of 4800. 25 KiB was reserved for indices fitting a total of 12800.
[INFO              ] [KivEnt      ] Model Manager reserved space for vertex format: vertex_format_7f. 75 KiB was reserved for vertices, fitting a total of 2742. 25 KiB was reserved for indices fitting a total of 12800.
[INFO              ] [KivEnt      ] Model Manager reserved space for vertex format: vertex_format_4f4ub. 75 KiB was reserved for vertices, fitting a total of 3840. 25 KiB was reserved for indices fitting a total of 12800.
[INFO              ] [KivEnt      ] Model Manager reserved space for vertex format: vertex_format_7f4ub. 75 KiB was reserved for vertices, fitting a total of 2400. 25 KiB was reserved for indices fitting a total of 12800.
[INFO              ] [KivEnt      ] Model Manager reserved space for vertex format: vertex_format_2f4ub. 75 KiB was reserved for vertices, fitting a total of 6400. 25 KiB was reserved for indices fitting a total of 12800.
[INFO              ] [KivEnt      ] Batches for canvas: <kivy.graphics.instructions.RenderContext object at 0x7f23c3433b10> will have 16384 verts and 131072 indices.VBO will be 256 in KiB per frame with 40 total vbos, an estimated 4096 enities fit in each batch with 4 verts per entity
[INFO              ] [KivEnt      ] map_layer1 allocated 26488 KiB
[INFO              ] [KivEnt      ] position allocated 1176 KiB
[INFO              ] [KivEnt      ] Batches for canvas: <kivy.graphics.instructions.RenderContext object at 0x7f23c3433d38> will have 16384 verts and 131072 indices.VBO will be 256 in KiB per frame with 40 total vbos, an estimated 4096 enities fit in each batch with 4 verts per entity
[INFO              ] [KivEnt      ] map_layer2 allocated 26488 KiB
[INFO              ] [KivEnt      ] Batches for canvas: <kivy.graphics.instructions.RenderContext object at 0x7f23c3433f60> will have 16384 verts and 131072 indices.VBO will be 256 in KiB per frame with 40 total vbos, an estimated 4096 enities fit in each batch with 4 verts per entity
[INFO              ] [KivEnt      ] map_layer3 allocated 26488 KiB
[INFO              ] [KivEnt      ] tile_map allocated 6262 KiB
[INFO              ] [KivEnt      ] Batches for canvas: <kivy.graphics.instructions.RenderContext object at 0x7f23c34338e8> will have 16384 verts and 131072 indices.VBO will be 256 in KiB per frame with 40 total vbos, an estimated 4096 enities fit in each batch with 4 verts per entity
[INFO              ] [KivEnt      ] map_layer0 allocated 26488 KiB
[INFO              ] [KivEnt      ] animation allocated 7034 KiB
[INFO              ] [KivEnt      ] We will need 124954 KiB for game, we have 204800 KiB
[INFO              ] [GL          ] NPOT texture support is available
[INFO              ] [Base        ] Leaving application in progress...
Yay
init game
Setting up tilemap
 Traceback (most recent call last):
   File "main.py", line 62, in <module>
     YourAppNameApp().run()
   File "/home/udiboy/.apps/venvs/kivy3/lib/python3.5/site-packages/kivy/app.py", line 828, in run
     runTouchApp()
   File "/home/udiboy/.apps/venvs/kivy3/lib/python3.5/site-packages/kivy/base.py", line 487, in runTouchApp
     EventLoop.window.mainloop()
   File "/home/udiboy/.apps/venvs/kivy3/lib/python3.5/site-packages/kivy/core/window/window_sdl2.py", line 619, in mainloop
     self._mainloop()
   File "/home/udiboy/.apps/venvs/kivy3/lib/python3.5/site-packages/kivy/core/window/window_sdl2.py", line 362, in _mainloop
     EventLoop.idle()
   File "/home/udiboy/.apps/venvs/kivy3/lib/python3.5/site-packages/kivy/base.py", line 327, in idle
     Clock.tick()
   File "/home/udiboy/.apps/venvs/kivy3/lib/python3.5/site-packages/kivy/clock.py", line 515, in tick
     self._process_events()
   File "/home/udiboy/.apps/venvs/kivy3/lib/python3.5/site-packages/kivy/clock.py", line 647, in _process_events
     event.tick(self._last_tick, remove)
   File "/home/udiboy/.apps/venvs/kivy3/lib/python3.5/site-packages/kivy/clock.py", line 406, in tick
     ret = callback(self._dt)
   File "kivent_core/gameworld.pyx", line 281, in kivent_core.gameworld.GameWorld.init_gameworld.lambda (kivent_core/gameworld.c:5894)
   File "kivent_core/gameworld.pyx", line 278, in kivent_core.gameworld.GameWorld.init_gameworld (kivent_core/gameworld.c:6104)
   File "main.py", line 36, in init_game
     self.setup_tile_map()
   File "main.py", line 46, in setup_tile_map
     self.gameworld.init_entity)
   File "/home/udiboy/.apps/venvs/kivy3/lib/python3.5/site-packages/kivent_maps/map_utils.py", line 50, in init_entities_from_map
     init_entity(comp_data, systems)
   File "kivent_core/gameworld.pyx", line 440, in kivent_core.gameworld.GameWorld.init_entity (kivent_core/gameworld.c:8211)
   File "kivent_core/systems/gamesystem.pyx", line 260, in kivent_core.systems.gamesystem.GameSystem.create_component (kivent_core/systems/gamesystem.c:3723)
   File "kivent_core/systems/animation.pyx", line 122, in kivent_core.systems.animation.AnimationSystem.init_component (kivent_core/systems/animation.c:4627)
   File "kivent_core/systems/staticmemgamesystem.pyx", line 410, in kivent_core.systems.staticmemgamesystem.ZonedAggregator.add_entity (kivent_core/systems/staticmemgamesystem.c:4363)
   File "kivent_core/memory_handlers/zone.pyx", line 298, in kivent_core.memory_handlers.zone.MemoryZone.get_pointer (kivent_core/memory_handlers/zone.c:2779)
   File "kivent_core/memory_handlers/pool.pyx", line 153, in kivent_core.memory_handlers.pool.MemoryPool.get_pointer (kivent_core/memory_handlers/pool.c:1548)
   File "kivent_core/memory_handlers/pool.pyx", line 131, in kivent_core.memory_handlers.pool.MemoryPool.get_memory_block_from_index (kivent_core/memory_handlers/pool.c:1458)
 IndexError: list index out of range
@Kovak

This comment has been minimized.

Contributor

Kovak commented Jul 10, 2016

This typically means we have run out of some statically allocated memory, are we trying to allocate more components than there are space for in the zone?

@udiboy1209

This comment has been minimized.

Member

udiboy1209 commented Jul 10, 2016

@Kovak I increased the zone and gameworld size to 10 times, but I still get the same error. I traced it to a component_index being -1(when cast to unsigned it gives a pretty huge no.) in staticmemgamesystem's add_entity.

@udiboy1209

This comment has been minimized.

Member

udiboy1209 commented Jul 11, 2016

@Kovak I figured out the problem. If a tile in the second layer is animated it will have components corresponding to 'position','map_layer2','animation' but the animation system is init to depend on components of renderers of all map layers, and that tile entity only has the component for 'map_layer2' init and no other renderer. One solution is using a different animation system for each layer's renderer. I'll implement this, but if you know a better way please suggest.

@udiboy1209

This comment has been minimized.

Member

udiboy1209 commented Jul 11, 2016

The issue is fixed! Map layers render correctly now 😀. I'll finally start with hexagonal/isometric tiles.

udiboy1209 added some commits Jul 11, 2016

Fix memory allocation issue for map_manager
Add memroy_required attribute to map_system to
control the memory needed for TileMap

@Kovak Kovak merged commit effdba9 into kivy:tiled_gsoc_2016 Jul 13, 2016

@Kovak

This comment has been minimized.

Contributor

Kovak commented Jul 13, 2016

this is looking great udiboy1209!

@udiboy1209 udiboy1209 deleted the udiboy1209:tmx_parser branch Jul 13, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment