Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

I can't get inline to work for this simple function.

Community Beginner ,
Jan 06, 2015 Jan 06, 2015

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.

TOPICS
ActionScript
224
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Beginner , Jan 06, 2015 Jan 06, 2015

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. >,>

Translate
Community Expert ,
Jan 06, 2015 Jan 06, 2015

what are you trying to do?

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 06, 2015 Jan 06, 2015

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.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Beginner ,
Jan 06, 2015 Jan 06, 2015
LATEST

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. >,>

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines