Author Topic: My terrible "tilemapper" that I need help optimizing  (Read 5357 times)

0 Members and 2 Guests are viewing this topic.

Offline BrownyTCat

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 420
  • Rating: +37/-8
    • View Profile
My terrible "tilemapper" that I need help optimizing
« on: December 16, 2012, 06:49:26 pm »
I wrote this for a platform game and it currently uses a pic to store data. All of the files are attached, but I've hit a problem with run speed due to my horrible coding skills. If anyone could convert it to load data like "real" tilemaps, I'd appreciate it, but try to keep it understandable/commented as I cannot do polar math or anything at all. Also try to make it suitable for a sidescroller as that's what I was initially aiming for. Thank you.

TMAPDATA - Program/subroutine to define the GDB(s)
TMAPSRC - Main source for the mapper
Pic2 - Single PicVar used to store all the data for up to 8 tile varieties in 8-pixel-tall rows. The engine scrolls smoothly across all 64 horizontal pixels/tiles.

The source has some small labels/comments that should at least tell you what something is.

Offline squidgetx

  • Food.
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1881
  • Rating: +503/-17
  • rawr.
    • View Profile
Re: My terrible "tilemapper" that I need help optimizing
« Reply #1 on: December 16, 2012, 07:50:01 pm »
Your code looks decent, just changing the tilemapper from pixel to whole-byte would speed everything up quite nicely. Basically the idea is that instead of using a pic and using pxl-test, you use a series of bytes to define your data.

So if your tilemap was a big box say, 8x8 in size the data might look like this:
Code: [Select]
0101010101010101
0100000000000001
0100000000000001
0100000000000001
0100000000000001
0100000000000001
0100000000000001
0101010101010101
where 1 is a wall and 0 is empty space. Then to draw it, you use something similar to what you had, only simplified for full byte tiles (and unoptimized for readability)
Code: [Select]
for(a,0,11)
for(b,0,7)
pt-on(a*8+s,v*8,{b+y*w+x+b+gdb1}*8+Pic0
end
end
where gdb1 points to your tilemap data, pic0 are your tiles, and w is your tilemap width. What you're doing, in essence, is modeling a 2d matrix.
« Last Edit: December 16, 2012, 07:55:39 pm by squidgetx »

Offline BrownyTCat

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 420
  • Rating: +37/-8
    • View Profile
Re: My terrible "tilemapper" that I need help optimizing
« Reply #2 on: December 16, 2012, 08:50:19 pm »
Thanks for helping me at least attempt GDBs, I tried implementing this with a map with a width of 16 but got very messed up results, and it looks like the scroller is advancing vertically once the smoother is done... It's hard to explain, but this happened. Also, how the heck do you find your position in a GDB for checking things like collisions?

The new source is attached, now all one program.

Offline squidgetx

  • Food.
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1881
  • Rating: +503/-17
  • rawr.
    • View Profile
Re: My terrible "tilemapper" that I need help optimizing
« Reply #3 on: December 16, 2012, 09:55:56 pm »
Sorry, I made a typo in my code;

It should be b+y*w+x+a+gdb1, not b+y*w+x+b+gdb1.

The B+Y part is the y coord as you draw, and the X+A is the X coordinate. The code starts at X,Y, and loops through the 12x8 section of data in front of it.

You can use the same kind of method to find your own position in a data structure: {y*width+x+pointer}

Also here's a good set of tips for general optimization:
http://ourl.ca/8520

Offline BrownyTCat

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 420
  • Rating: +37/-8
    • View Profile
Re: My terrible "tilemapper" that I need help optimizing
« Reply #4 on: December 16, 2012, 11:04:54 pm »
That seems to have resolved everything, thanks for the help!

Offline BrownyTCat

  • LV6 Super Member (Next: 500)
  • ******
  • Posts: 420
  • Rating: +37/-8
    • View Profile
Re: My terrible "tilemapper" that I need help optimizing
« Reply #5 on: December 17, 2012, 07:06:32 pm »
I've been having issues with collisions, I messed with them until I forgot my own name and now realize that I cannot fix it.
Source is attached, could not find the source of numerous bugs with falling through things.