Copy link to clipboard
Copied
I thought I understood [Inline] but my app says otherwise.
I've been using [Inline] with great success for a few months now; however, this quick snippet of code won't [Inline] properly. I know this because I've ran numerous tests with the function looped 100,000 times and I'll get around 400ms with [Inline] and 400ms without [Inline].
I could just be really sleepy and frustrated, but I thought I'd try and learn so that I wouldn't make the same mistake again. So here are the guts of the function in question:
var shared:int = 0;
var length:int = goodRegions[index].length;
for ( var i:int = 0; i < length; ++i ) {
rect = goodRegions[index];
mRect.x = rect.x + masterX;
mRect.width = rect.width;
if ( mRect.x + mRect.width > sRect.x ) {
shared = i;
break;
}
}
for ( var i:int = shared; i < length; ++i ) {
rect = goodRegions[index];
mRect.x = rect.x + masterX;
mRect.y = rect.y + masterY;
mRect.width = rect.width;
mRect.height = rect.height;
if ( sRect.x + sRect.width < mRect.x ) { break; }
}
There are outside variables I didn't include because they are passed through the function parameters.
I would greatly any help I can get understanding what I'm doing wrong.
Yea it turns out I was really tired and didn't realize that I was using [Inline] incorrectly. For future reference, inline functions don't work properly when they contain function calls. >,>
Copy link to clipboard
Copied
what are you trying to do?
Copy link to clipboard
Copied
Ah you know what, I left out a line:
...
for ( var i:int = shared; i < length; ++i ) {
rect = goodRegions[index];
mRect.x = rect.x + masterX;
mRect.y = rect.y + masterY;
mRect.width = rect.width;
mRect.height = rect.height;
if ( CheckForCollisions( mRect, sRect ) ) { <--------------------------- missing from original post
if ( sRect.x + sRect.width < mRect.x ) { break; }
}
}
Since posting I've actually played around with the removal of the extra function and it started to work properly. I don't understand why my Collision check was making the function ineligible for [Inline]...
But maybe this would help:
[Inline]
private final function CheckForCollisions( rectA:Rectangle, rectB:Rectangle ):Boolean {
return (( rectA.x < rectB.x + rectB.width - 2 && rectA.x + rectA.width > rectB.x + 2 ) &&
( rectA.y < rectB.y + rectB.height - 2 && rectA.y + rectA.height > rectB.y + 2 ));
}
Is it inappropriate to use an inline function within another inline function? Oh and I'm multi-threading my physics code, so this is being ran on a separate thread/worker.
Copy link to clipboard
Copied
Yea it turns out I was really tired and didn't realize that I was using [Inline] incorrectly. For future reference, inline functions don't work properly when they contain function calls. >,>
Find more inspiration, events, and resources on the new Adobe Community
Explore Now