Author Topic: Way to optimize Line( drawings? (SOLVED)  (Read 4361 times)

0 Members and 1 Guest are viewing this topic.

Offline Derf321

  • LV3 Member (Next: 100)
  • ***
  • Posts: 59
  • Rating: +0/-0
    • View Profile
Way to optimize Line( drawings? (SOLVED)
« on: November 27, 2012, 11:36:00 pm »
I have a map drawn out on my game which does not move or change during it. Is there a more efficient way to do Line( drawings? I've seen people use those bracket hex code things like [23423492056] but I'm not sure how to use them or where to get info on them. My program's just getting up there in size and I'd like to condense it before I hit the Axe compiler limit.

Basically I just want to optimize this code that runs once at the start:
Spoiler For Spoiler:
Line(1,9,25,9):Line(25,1,25,9):Line(3,4,4,4):Line(4,3,6,3):Line(6,3,6,4):Line(6,4,7,4):Line(7,4,7,6):Line(6,6,6,7):Line(6,7,4,7):Line(4,6,3,6):Line(3,6,3,5):Line(94,1,94,62):Line(94,48,1,48):Line(1,62,1,1):Line(1,1,94,1):Line(1,62,94,62):Line(16,48,16,62):Line(31,48,31,62):Line(46,48,46,62):Line(61,48,61,62)
Line(1,29,25,29):Line(35,29,55,29):Line(55,29,55,36):Line(55,43,55,48)
Line(3,42,9,42):Line(3,42,3,34):Line(3,34,9,34):Line(9,34,9,42):Line(19,56,19,52):Line(20,54,20,50):Line(20,50,28,50):Line(28,51,24,51):Line(21,52,22,51):Line(37,54,38,53):Line(40,53,41,54):Line(34,52,44,52):Line(44,52,44,51):Line(41,51,34,51):Line(34,53,35,53):Line(38,50,39,50):Line(48,52,59,52):Line(48,53,50,53):Line(50,51,53,51):Line(52,53,52,55):Line(53,53,53,55):Line(54,53,54,53):Line(57,51,58,50):Line(57,52,58,54)
Line(4,55,4,52):Line(5,55,5,52):Line(4,52,11,52):Line(4,51,12,51):Line(6,53,6,53)

I appreciate any help!
« Last Edit: December 05, 2012, 02:56:17 pm by Derf321 »

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4659
  • Rating: +718/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Way to optimize Line( drawings?
« Reply #1 on: November 28, 2012, 07:57:08 am »
Warning: I'm not an Axe programmer :P
Basically what you can do is store all of the coordinates in order as data. Brackets are one way to do it, but then you have to convert all your coordinates to hex. Instead, use Data(. For example:
Code: [Select]
Data(1,9,25,9,25,1,25,9,3,4,4,4,...→A
Now you can run a For( loop to draw all your lines. I am not sure if this will work, but I think you will get the idea:
Code: [Select]
Data(1,9,25,9,25,1,25,9,3,4,4,4,...)-1→A
For(53      ;number of lines you have, I think
Line({A++},{A++},{A++},{A++})
End
EDIT: If Jacobly doesn't get around to it, this is the even more optimised version he gave on IRC:
Code: [Select]
Data(1,9,25,9,25,1,25,9,3,4,4,4,...)-2→A
For(53      ;number of lines you have, I think
Line({A+2→A}r,/256,{A+2}r,/256
End

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: Way to optimize Line( drawings?
« Reply #2 on: November 28, 2012, 01:11:06 pm »
Or do that, using hex code:
Code: [Select]
[0000000000000000000000007FFFFFFFFFFFFFFFFFFFFFFE4000004000000000000000024E00004000000000000000025B00004000000000000000025100004000000000000000025B00004000000000000000024E00004000000000000000024000004000000000000000027FFFFFC000000000000000024000000000000000000000024000000000000000000000024000000000000000000000024000000000000000000000024000000000000000000000024000000000000000000000024000000000000000000000024000000000000000000000024000000000000000000000024000000000000000000000024000000000000000000000024000000000000000000000024000000000000000000000024000000000000000000000024000000000000000000000024000000000000000000000024000000000000000000000024000000000000000000000024000000000000000000000027FFFFFC01FFFFF00000000024000000000000100000000024000000000000100000000024000000000000100000000024000000000000100000000025FC0000000000100000000025040000000000100000000025040000000000100000000025040000000000000000000025040000000000000000000025040000000000000000000025040000000000000000000025040000000000000000000025FC0000000000000000000024000000000000100000000024000000000000100000000024000000000000100000000024000000000000100000000024000000000000100000000027FFFFFFFFFFFFFFFFFFFFFFE40008001000200040000000240008FF903020024000000024FF88AF93FCA3C44000000024FF09C013FFAFFF4000000024E0098013282EE44000000024C00980104420C24000000024C00900100020C04000000024000900100020004000000024000800100020004000000024000800100020004000000024000800100020004000000024000800100020004000000024000800100020004000000027FFFFFFFFFFFFFFFFFFFFFFE000000000000000000000000]->GDB1
Copy(GDB1,L6)
Now, I won't let you with that solution without explaining how it works, that won't help you in the long term ;)

First of all, notice that your screen has a width that is a multiple of 8 (96=8*12). This is because it is not only composed of pixels, but is (behind the scenes) composed of bytes. Those bytes are pointed by L6.

Now, try to do that (where "pi" is the pi token, not pi in lowercase):
   ClrDraw
   pi11111111→{L6}
   DispGraph
You'll see a line of 8 pixels on the top left corner of the screen.
This is because you set the first 8 bits of "the screen" as black.

Now, try this:
   ClrDraw
   pi11000011→{L6}
   DispGraph
You'll see 2 black pixels followed by 4 white ones followed by 2 black ones, still in the top left corner, according to the bits you set to black.

Now, try this:
   ClrDraw
   pi11000011→{L6+1}
   DispGraph
You'll see the same pattern as the previous one, but not on the top left corner, there will first be 8 white pixels. This is because you did not set the first byte of "the screen" but the second byte, so the first byte is white, untouched, and the second one has the pattern.

Now, try this
   ClrDraw
   pi11000011→{L6+12}
   DispGraph
Still the same pattern but not in the first line: in the second line of bytes, because as I said, 96=8*12, so the 12th byte of "the screen" is the first one of the second line.


I guess you understood all so now how does my code work ?
Well I put in the hex code the values of each byte of "the screen" and I copy them to the screen. To easily get those values, you can draw the image on Paint and convert it to hex code using SourceCoder :)


By the way, since there is a lot of white space in your image, I guess that you could in fact only use hex code for the bottom and use another way to draw the top part of it (using lines or rectangles or anything else).
« Last Edit: November 28, 2012, 01:12:34 pm by Hayleia »
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s

Offline Derf321

  • LV3 Member (Next: 100)
  • ***
  • Posts: 59
  • Rating: +0/-0
    • View Profile
Re: Way to optimize Line( drawings?
« Reply #3 on: November 28, 2012, 02:59:06 pm »
Oh thanks for the idea Xeda, I probably will do that. It would save SO much program space!
Thank you too Hayleia! But it looks like that's a lot more bytes to type in in the long run. But now I know how the hex works, so thank you! =D

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: Way to optimize Line( drawings?
« Reply #4 on: November 29, 2012, 12:42:23 pm »
But it looks like that's a lot more bytes to type in in the long run.
Of course you won't type them by hand :P
There are some image to hex converters lying around, including SourceCoder on Cemetech (that is the one I use because it doesn't need any installation since it is online and since I don't convert that much images) :)
« Last Edit: November 29, 2012, 12:42:29 pm by Hayleia »
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s

Offline Derf321

  • LV3 Member (Next: 100)
  • ***
  • Posts: 59
  • Rating: +0/-0
    • View Profile
Re: Way to optimize Line( drawings?
« Reply #5 on: November 30, 2012, 01:03:06 pm »
There are some image to hex converters lying around, including SourceCoder on Cemetech
How do I use it to convert it to hex? Will it read Axe sources well?

Offline Hayleia

  • Programming Absol
  • Coder Of Tomorrow
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3367
  • Rating: +393/-7
    • View Profile
Re: Way to optimize Line( drawings?
« Reply #6 on: November 30, 2012, 01:54:49 pm »
There are some image to hex converters lying around, including SourceCoder on Cemetech
How do I use it to convert it to hex? Will it read Axe sources well?
Have it parse a png file. Note that this png should only have shades of grey (no pink, etc) if you don't want random results.
As for it reading Axe sources, I never tried, I only use it for converting images :P
I guess that it will manage to open it, but custom Axe tokens won't be displayed well (like Data being ΔList, etc).
I own: 83+ ; 84+SE ; 76.fr ; CX CAS ; Prizm ; 84+CSE
Sorry if I answer with something that seems unrelated, English is not my primary language and I might not have understood well. Sorry if I make English mistakes too.

click here to know where you got your last +1s

Offline Derf321

  • LV3 Member (Next: 100)
  • ***
  • Posts: 59
  • Rating: +0/-0
    • View Profile
Re: Way to optimize Line( drawings?
« Reply #7 on: December 05, 2012, 11:41:05 am »
Warning: I'm not an Axe programmer :P
Basically what you can do is store all of the coordinates in order as data. Brackets are one way to do it, but then you have to convert all your coordinates to hex. Instead, use Data(. For example:
Code: [Select]
Data(1,9,25,9,25,1,25,9,3,4,4,4,...→A
Now you can run a For( loop to draw all your lines. I am not sure if this will work, but I think you will get the idea:
Code: [Select]
Data(1,9,25,9,25,1,25,9,3,4,4,4,...)-1→A
For(53      ;number of lines you have, I think
Line({A++},{A++},{A++},{A++})
End
EDIT: If Jacobly doesn't get around to it, this is the even more optimised version he gave on IRC:
Code: [Select]
Data(1,9,25,9,25,1,25,9,3,4,4,4,...)-2→A
For(53      ;number of lines you have, I think
Line({A+2→A}r,/256,{A+2}r,/256
End


I tried this and just using Data(12,31...)-4→A, Line({A+4→A},{A+1},{A+2},{A+3}), but either one slightly affects the display (one line out of place or something) like the attached picture.
Any clue?
« Last Edit: December 05, 2012, 11:41:33 am by Derf321 »

Offline jacobly

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 205
  • Rating: +161/-1
    • View Profile
Re: Way to optimize Line( drawings?
« Reply #8 on: December 05, 2012, 11:59:18 am »
It's supposed to be
Code: [Select]
Data(1,9,25,9,25,1,25,9,3,4,4,4,...)-2→A
For(53      .number of lines you have
Line({A+2→A}ʳ,/256,{A+2→A}ʳ,/256
End

Extra lines suggest that you are looping too many times.

Offline Derf321

  • LV3 Member (Next: 100)
  • ***
  • Posts: 59
  • Rating: +0/-0
    • View Profile
Re: Way to optimize Line( drawings?
« Reply #9 on: December 05, 2012, 02:55:29 pm »
Extra lines suggest that you are looping too many times.
Worked like a charm! Thank you! It reduced the size of the compiled program by over 1000 bytes, with the cost of about 80 more bytes uncompiled (which definitely helps!). Thanks a lot guys!