Author Topic: Making a SHMUP (shoot-em-up) in Axe  (Read 10733 times)

0 Members and 2 Guests are viewing this topic.

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Making a SHMUP (shoot-em-up) in Axe
« Reply #15 on: March 01, 2011, 05:13:50 pm »
Why is post-check more optimized than a Repeat loop, though?

I think I remember mentioning why this is in a previous post somewhere... ah yes, here it is:

Speaking of optimizing control structures, any chance for Do...While loops?

I'd like Switch cases more than Do...While loops, but I don't really know how the second works.


Do...While loops are a lot like While...End loops, except that the check to advance to another iteration of the loop is at the end instead of the beginning. This turns out to be more optimized. Whereas a While...End loop has two jumps, one to exit the loop if the condition is false and one to jump back to the beginning, a Do...While combines the two into one jump that jumps back to the beginning if the condition is true.

I don't know how good that explanation was, but perhaps this pseudocode will help clarify it. Numbers in brackets indicate the number of bytes the real code takes:

While...End loop                                                                          Do...While loop                                                                              
Code: [Select]
;While
[x] Loop condition
[2] Check if loop condition is true or false
[3] Exit the loop if false

;Loop contents

;End
[3] Jump back to the beginning of the loop


       
Code: [Select]
;Do
;[0] Start of the loop, takes no actual code



;Loop contents

;While
[x] Loop condition
[2] Check if loop condition is true or false
[3] Jump back to the beginning of the loop if true




I like leaving the last Return in because it helps code readability, and it makes it easier to add new subroutines after it. It doesn't actually affect the compiled code, right?

I agree that it improves readability, but because Axe automatically adds a return to the end of programs it's redundant and a waste of 1 byte. You can always improve readability while maintaining optimization by keeping the final Return, but commenting it out.
« Last Edit: March 01, 2011, 05:14:13 pm by Runer112 »

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Making a SHMUP (shoot-em-up) in Axe
« Reply #16 on: March 01, 2011, 05:55:56 pm »
Looks great!  Are you going to keep the ship on the screen?

What do you mean?
Are you going to make it so the player's sprite cannot go off the screen?

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Making a SHMUP (shoot-em-up) in Axe
« Reply #17 on: March 01, 2011, 06:17:18 pm »
Why is post-check more optimized than a Repeat loop, though?

I think I remember mentioning why this is in a previous post somewhere... ah yes, here it is:

Oh, right, I keep thinking Repeat is the same as in BASIC (post-checking).

I like leaving the last Return in because it helps code readability, and it makes it easier to add new subroutines after it. It doesn't actually affect the compiled code, right?

I agree that it improves readability, but because Axe automatically adds a return to the end of programs it's redundant and a waste of 1 byte. You can always improve readability while maintaining optimization by keeping the final Return, but commenting it out.

Axe actually checks if there's already a Return at the end. If there is, it isn't added.

Looks great!  Are you going to keep the ship on the screen?

What do you mean?
Are you going to make it so the player's sprite cannot go off the screen?

Yeah, definitely. Runer112's code takes care of that, and I think I'll use it for ASHMUPK. That part of it should be fairly easy to understand.
« Last Edit: March 01, 2011, 06:17:34 pm by Deep Thought »




Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Making a SHMUP (shoot-em-up) in Axe
« Reply #18 on: March 01, 2011, 06:21:01 pm »
Axe actually checks if there's already a Return at the end. If there is, it isn't added.

I was pretty sure it didn't check if the code already ends in a Return. Upon quickly double-checking this, it appears that Axe will always add a final Return whether or not your code ends in one. Do you get different results?
« Last Edit: March 01, 2011, 06:22:54 pm by Runer112 »

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Making a SHMUP (shoot-em-up) in Axe
« Reply #19 on: March 01, 2011, 06:25:21 pm »
I swear Quigibo mentioned he optimized the Return...

Maybe it was just a feature request. I'll check.




Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55943
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Making a SHMUP (shoot-em-up) in Axe
« Reply #20 on: March 02, 2011, 04:38:25 am »
Wow nice tutorial Deep Thought. It should really be useful. It's so well detailed too :D

Offline Quigibo

  • The Executioner
  • CoT Emeritus
  • LV11 Super Veteran (Next: 3000)
  • *
  • Posts: 2031
  • Rating: +1075/-24
  • I wish real life had a "Save" and "Load" button...
    • View Profile
Re: Making a SHMUP (shoot-em-up) in Axe
« Reply #21 on: March 03, 2011, 03:49:29 am »
I swear Quigibo mentioned he optimized the Return...

Maybe it was just a feature request. I'll check.

It was available at one time, but I removed this feature for some reason because there was a case where this behavior was not desired.  I can't seem to remember what it was though... if I can't think of anything, I'll add it back in.
___Axe_Parser___
Today the calculator, tomorrow the world!

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Making a SHMUP (shoot-em-up) in Axe
« Reply #22 on: April 06, 2011, 07:54:53 pm »
Finished combining the bullet display routine into ASHMUPM and cleaned up a couple other things. You'll probably have to refresh the page to see the changes (due to page caching).

Also starting to work on the enemies section. It's a lot easier now that I have a link cable :D

EDIT: Whoa ... it does run a lot faster O.O
« Last Edit: April 06, 2011, 07:55:41 pm by Deep Thought »




Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Making a SHMUP (shoot-em-up) in Axe
« Reply #23 on: April 06, 2011, 08:34:22 pm »
I believe it was removed because of something to do with subprograms and memory leaks o.O

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Making a SHMUP (shoot-em-up) in Axe
« Reply #24 on: April 06, 2011, 08:41:10 pm »
Found it:

  • Return optimization in no longer automatic due to possible program leaks.

When would it cause a memory leak?