chronicleroflegends
Member
As I continue adding more custom code to my project, there is one area I am wanting to understand better.
Macros and Subroutines have similar function with some key differences, and I want to know better what I am working with.
What my understanding is so far:
Subroutine: A block of code that you can call from anywhere, as long as that subroutine's label is defined within the bank you currently have active.
Only 1 copy of this code exists, you can call it as many times as you like without bloating the code.
It saves the current code location to the stack, runs the subroutine, and then returns to where it left off.
you -must- return from a subroutine, or you will have undefined and usually game breaking behavior, as the code execution order gets screwed up.
Macro: This code can be called from -anywhere- it doesn't matter which bank you are in. This is because it is not actually calling this code, but inserting the
contents of the macro into the place where you called it. Every time you call a macro, it adds the entire contents of its code to that location. This makes it difficult to
use macros inside of branching statements, because they normally push your labels out of range unless the macro is very short.
So, in my experience. I would think that it would usually be better and faster to create and use subroutines. However there seems to be an efficiency cost that I am not understanding.
I am trying to make my collision code more efficient in this manner:
Make different subroutines for 1 point, 4 point, and 6 point collision.
Only call those subroutines for appropriate objects, such that only the minimum necessary number of collision points is checked every frame.
These subroutines work, however I am noticing much more slowdown, not less. Is it actually more taxing to the CPU to use subroutines rather than direct code?
Macros and Subroutines have similar function with some key differences, and I want to know better what I am working with.
What my understanding is so far:
Subroutine: A block of code that you can call from anywhere, as long as that subroutine's label is defined within the bank you currently have active.
Only 1 copy of this code exists, you can call it as many times as you like without bloating the code.
It saves the current code location to the stack, runs the subroutine, and then returns to where it left off.
you -must- return from a subroutine, or you will have undefined and usually game breaking behavior, as the code execution order gets screwed up.
Macro: This code can be called from -anywhere- it doesn't matter which bank you are in. This is because it is not actually calling this code, but inserting the
contents of the macro into the place where you called it. Every time you call a macro, it adds the entire contents of its code to that location. This makes it difficult to
use macros inside of branching statements, because they normally push your labels out of range unless the macro is very short.
So, in my experience. I would think that it would usually be better and faster to create and use subroutines. However there seems to be an efficiency cost that I am not understanding.
I am trying to make my collision code more efficient in this manner:
Make different subroutines for 1 point, 4 point, and 6 point collision.
Only call those subroutines for appropriate objects, such that only the minimum necessary number of collision points is checked every frame.
These subroutines work, however I am noticing much more slowdown, not less. Is it actually more taxing to the CPU to use subroutines rather than direct code?