What would be faster

Hey,

I’m creating an RTS, see my signature. And it’s going pretty well, obviously there is always the problem of lag. Now I wonder what to do. Should I see if a unit is on-screen and only render it when it is on-screen or should I just always render it.

Rendering would be copypixeling a 70x70 pixel picture to a bitmapdata that the user can’t always see. Obviously this is useless and uses precious cpu time. But maybe checking if a unit is on screen takes more cpu then the rendering part. Obviously the time spend on calculating if it’s on-screen is wasted when it appears that it is on-screen.

The user sees a screen of 500x500 pixels with the left top being the coordinate: (offSetX, offSetY). So the code would look something like this:


if (_x > offSetX && 
    _x < offSetX + 500 &&
    _y > offSetY &&
    _y < offSetY + 500)
    {
    render();
    }

What do you guys think? I think I’ll write a short program to see which one takes up the most cpu if you guys don’t know this exactly though :slight_smile: .

Thanks,

ArmoredSandwich AKA ImWithNoob.

Edit:


Testing copy pixels, we're gonna copy pixel a picture of: 70x70 100000 times
It took: 204 ms.
Testing the calculation too see if a unit should be rendered or not, 100000 times, unit is off-screen
It took: 155 ms.
Testing the calculation too see if a unit should be rendered or not, 100000 time, unit is on-screen.
It took: 241 ms.

Even if it was faster the unit would still have to render itself. So nope, it’s not faster. :stuck_out_tongue: