Author Topic: Axe Q&A  (Read 590549 times)

0 Members and 6 Guests are viewing this topic.

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Axe Q&A
« Reply #345 on: May 20, 2011, 11:51:36 am »
I have some little code, but it runs slow like hell, I'd like to know your opinions on why:

Code: [Select]
.C
512→Y
12288→X
0→A→B
Repeat getKey(15)
  ClrDraw
  Rect(0,0,96,64)
  RectI(3,3,90,58)
  Line(0,30,40,30)
  Rect(X/256,Y/256,8,8)

  If getKey(2)
    A-16→A
  End

  If getKey(3)
    A+16→A
  End
 
  X+A→X
  Y+B→Y

  If (pxl-Test(X/256+8,Y/256))
    0→A
  End

  If (pxl-Test(X/256-1,Y/256))
    0→A
  End
 
  If (pxl-Test(X/256,Y/256+8))
    0→B
  End

  !If (pxl-Test(X/256,Y/256+8))
    B+4→B
  End
 
  If getKey(4)
    B-16→B
  End
 
  DispGraph
End

I know it can be optimized like having 'or's in the first two pixel tests, but would that enchance its speed that much?

I have a theory, dividing variables by 256 is what's making it slow. Am I right?

I just tried this and it was much faster, I'm wondering why:

Code: [Select]
.C
512→Y
12288→X
0→A→B
Repeat getKey(15)
  ClrDraw
  Rect(0,0,96,64)
  RectI(3,3,90,58)
  Line(0,30,40,30)
  Rect(X/256,Y/256,8,8)

  If getKey(2)
    A-16→A
  End

  If getKey(3)
    A+16→A
  End
 
  X+A→X
  Y+B→Y

  If (pxl-Test(X/256+8,Y/256)) or (pxl-Test(X/256-1,Y/256))
    0→A
  End
 
  If (pxl-Test(X/256,Y/256+8))
    0→B
  End

  !If (pxl-Test(X/256,Y/256+8))
    B+4→B
  End
 
  If getKey(4)
    B-16→B
  End
 
  DispGraph
End
« Last Edit: May 20, 2011, 11:54:16 am by Scout »

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Axe Q&A
« Reply #346 on: May 20, 2011, 11:55:31 am »
You can divide by 256 about 500,000 times a second, which is one of the reasons why inflating variables by 256 is the preferred method of increasing accuracy. My guess would be that drawing 2 massive rectangles every frame can't help.


EDIT: The second block of code you posted should run at virtually the exact same speed as the original block of code. Are you sure it actually sped up? And if so, did you make any other changes to the code?

EDIT 2: I think the program appearing to run slowly is just an illusion caused by your object moving at slow speeds. It gets about 40 frames per second, the object is just in the same position in many frames because it is moving slowly.
« Last Edit: May 20, 2011, 12:05:45 pm by Runer112 »

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Axe Q&A
« Reply #347 on: May 20, 2011, 12:24:46 pm »
I have a huge problem in Axe, I can't avoid that my sprites go through walls or even the floor when they are in fast speeds. Is there any way to avoid this?
« Last Edit: May 21, 2011, 10:52:20 am by Scout »

Offline yunhua98

  • You won't this read sentence right.
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2718
  • Rating: +214/-12
  • Go take a dive in the River Lethe.
    • View Profile
Re: Axe Q&A
« Reply #348 on: May 21, 2011, 10:03:05 am »
Yes, the velocity sometimes is over 256, so it goes more than 1 pixel at a time.  Add a terminal velocity, that is, stop accelerating when it's over 256

Spoiler For =====My Projects=====:
Minor setback due to code messing up.  On hold for Contest.
<hr>
On hold for Contest.


Spoiler For ===Staff Memberships===:






Have you seen any good news-worthy programs/events?  If so, PM me with an article to be included in the next issue of CGPN!
The Game is only a demo, the code that allows one to win hasn't been done.
To paraphrase Oedipus, Hamlet, Lear, and all those guys, "I wish I had known this some time ago."
Signature Last Updated: 12/26/11
<hr>

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: Axe Q&A
« Reply #349 on: May 21, 2011, 10:50:13 am »
I have a huge problem in Axe, I can't avoid that my sprites go through walls or even the floor when they are in fast speeds. Is there any way to avoid this?

That's because when a bullet moves, say, 8 pixels at once, it only tests if that 8th pixel is a wall or a floor, so all the pixels in between (which might include a wall) don't get tested. The easy (but slow) fix is to test each bullet with a For( loop before moving.




Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Axe Q&A
« Reply #350 on: May 21, 2011, 10:53:33 am »
I will probably loop all positions :/

Offline Binder News

  • LV8 Addict (Next: 1000)
  • ********
  • Posts: 785
  • Rating: +46/-3
  • Zombie of Tomorrow
    • View Profile
Re: Axe Q&A
« Reply #351 on: May 21, 2011, 11:31:06 am »
Another thing to do is only redraw the screen every other frame. Just put
Code: [Select]
Main Loop
For({<insert pointer here>},0,1)
...
End
DispGraph
End
Spoiler For userbars:







Hacker-in-training!   Z80 Assembly Programmer     Axe Programmer
C++ H4X0R             Java Coder                           I <3 Python!

Perdidisti ludum     Cerebrum non habes

"We are humans first, no matter what."
"Fame is a vapor, popularity an accident, and riches take wings. Only one thing endures, and that is character."
Spoiler For Test Results:





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: Axe Q&A
« Reply #352 on: May 21, 2011, 11:38:48 am »
Another thing to do is only redraw the screen every other frame.

What's that for?




Offline Happybobjr

  • James Oldiges
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2325
  • Rating: +128/-20
  • Howdy :)
    • View Profile
Re: Axe Q&A
« Reply #353 on: May 21, 2011, 12:34:28 pm »
Or you could do...

Code: [Select]
!If A+1^2->A
DispGraph
End
School: East Central High School
 
Axe: 1.0.0
TI-84 +SE  ||| OS: 2.53 MP (patched) ||| Version: "M"
TI-Nspire    |||  Lent out, and never returned
____________________________________________________________

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: Axe Q&A
« Reply #354 on: May 21, 2011, 01:39:13 pm »
Hey, the problem with looping is that if I only allow the sprite to move if pxl-Tests=0 8pixels to the right/left, it will not be able to even be close to walls.

This is not a good alternative and I do n't get Yeong's nor Happybojr's.

Offline Happybobjr

  • James Oldiges
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2325
  • Rating: +128/-20
  • Howdy :)
    • View Profile
Re: Axe Q&A
« Reply #355 on: May 21, 2011, 01:46:38 pm »
Displaying the graph is the slowest thing you can do on a calculator.
If you display the graph every other frame, you are just about guaranteed to have a 33% speed increase.
School: East Central High School
 
Axe: 1.0.0
TI-84 +SE  ||| OS: 2.53 MP (patched) ||| Version: "M"
TI-Nspire    |||  Lent out, and never returned
____________________________________________________________

Offline Runer112

  • Project Author
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2289
  • Rating: +639/-31
    • View Profile
Re: Axe Q&A
« Reply #356 on: May 21, 2011, 01:49:54 pm »
Actually, the slowest Axe command (that won't freeze the calculator altogether) is Pause 0, which would take about 220 million cycles. That's a bit over half a minute at 6MHz. ;)

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: Axe Q&A
« Reply #357 on: May 21, 2011, 05:04:59 pm »
Actually, the slowest Axe command (that won't freeze the calculator altogether) is Pause 0, which would take about 220 million cycles. That's a bit over half a minute at 6MHz. ;)

Slowest useful command, I guess. Pause pauses, so it should pause.




Offline Freyaday

  • The One And Only Serial Time Killing Catboy-Capoeirista-Ballerino
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1970
  • Rating: +128/-15
  • I put on my robe and pixel hat...
    • View Profile
Re: Axe Q&A
« Reply #358 on: May 22, 2011, 12:28:19 am »
I think Pause 0 should pause for 0 time, but it doesn't.
How long is Pause 1, anyway?
In other news, Frey continues kicking unprecedented levels of ass.
Proud member of LF#N--Lolis For #9678B6 Names


I'm a performer at heart; I stole it last week.
My Artwork!

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: Axe Q&A
« Reply #359 on: May 22, 2011, 12:34:33 am »
It's like a For( loop with 0 frames -- it actually does the Pause routine 65,536 times, or half a minute.

Each Pause is about 1/1800 of a second.