Jump to content
IGNORED

Mord's Blog - Saving cycles.


RSS Bot

Recommended Posts

Of course, this means saving compared to how I use to do it. To maintain player movement while they're trying to push along a wall as they move in the collision tests I have to take into account wasted frames and on successive direction tests jump further to make up for lost time.

 

Since horizontal tests are done first, to test movement in the horizontal direction I double the speed prior to moving. Originally I just went through the full 16-bit addition sequence twice. On average that would take up about 80 odd cycles due to the generalized functions I used in it. Those functions are still in the rom but I'm not using them for player movement/collision anymore. I can use those for moving less frequent movement. (monsters/items notably. For the rare couple of items that the player will actually be able to move around with I'll have the item refresh it's X/Y with an offset from the player's X/Y instead of calculating it's movement separately. That should be faster...)

 

Anyway this is what I did for the Move-Right test. I tested it in the rom and it seems to work reliably. IE: Far more efficient than what I was doing. :ponder:

 

The subtraction routine (moving left) however is still a bit icky. Right now I just skipped out with putting the subtraction in a tiny 2-pass loop. Still more efficient than before but I'm hoping to think up something similar like the below.

 

CODE

; Horizontal Move Test ( Moving Right )

; This forces a double-step in the right direction.

 

clc ; 1, 2 ; This part handles double-addition of whole part.

lda SpeedX ; 2, 3 ; Realistically "SpeedX" will never be very high, normally 0-4 at most.)

asl ; 1, 2 ; so there's not going to be any carry flag to worry about.

adc PlayerX ; 2, 3 ;

sta PlayerX ; 2, 3 ;

 

; we can assume the carry is still cleared.

 

lda SpeedXf ; 2, 3 ;

asl ; 1, 2 ;

bcc .MovePlayerHorizontal_Skip1; 2, 2/3;

inc PlayerX ; 2, 5 ;

clc ; 1, 2 ;

.MovePlayerHorizontal_Skip1

 

adc PlayerXf ; 2, 3 ;

sta PlayerXf ; 2, 3 ;

lda #0 ; 2, 2 ;

adc PlayerX ; 2, 3 ; adds any carry left over to PlayerX.

sta PlayerX ; 2, 3 ;

; 35-41 cycles.

 

 

 

 

http://www.atariage.com/forums/index.php?a...;showentry=2491

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...