performance improvements in culling

This commit is contained in:
Ricardo Quesada 2014-02-23 02:02:28 -08:00
parent 04460750b8
commit f77b92f1d7
1 changed files with 11 additions and 6 deletions

View File

@ -617,25 +617,30 @@ void Sprite::draw(void)
// Culling function from cocos2d-iphone CCSprite.m file // Culling function from cocos2d-iphone CCSprite.m file
bool Sprite::culling() const bool Sprite::culling() const
{ {
Size s = Director::getInstance()->getWinSize(); // half size of the screen
float hcsx = _contentSize.width * 0.5f; Size screen_half = Director::getInstance()->getWinSize();
float hcsy = _contentSize.height * 0.5f; screen_half.width /= 2;
screen_half.height /= 2;
float hcsx = _contentSize.width / 2;
float hcsy = _contentSize.height / 2;
// convert to world coordinates // convert to world coordinates
float x = hcsx * _modelViewTransform.mat[0] + hcsy * _modelViewTransform.mat[4] + _modelViewTransform.mat[12]; float x = hcsx * _modelViewTransform.mat[0] + hcsy * _modelViewTransform.mat[4] + _modelViewTransform.mat[12];
float y = hcsx * _modelViewTransform.mat[1] + hcsy * _modelViewTransform.mat[5] + _modelViewTransform.mat[13]; float y = hcsx * _modelViewTransform.mat[1] + hcsy * _modelViewTransform.mat[5] + _modelViewTransform.mat[13];
// center of screen is (0,0) // center of screen is (0,0)
x -= s.width/2; x -= screen_half.width;
y -= s.height/2; y -= screen_half.height;
// convert content size to world coordinates // convert content size to world coordinates
float wchw = hcsx * fmaxf(fabsf(_modelViewTransform.mat[0] + _modelViewTransform.mat[4]), fabsf(_modelViewTransform.mat[0] - _modelViewTransform.mat[4])); float wchw = hcsx * fmaxf(fabsf(_modelViewTransform.mat[0] + _modelViewTransform.mat[4]), fabsf(_modelViewTransform.mat[0] - _modelViewTransform.mat[4]));
float wchh = hcsy * fmaxf(fabsf(_modelViewTransform.mat[1] + _modelViewTransform.mat[5]), fabsf(_modelViewTransform.mat[1] - _modelViewTransform.mat[5])); float wchh = hcsy * fmaxf(fabsf(_modelViewTransform.mat[1] + _modelViewTransform.mat[5]), fabsf(_modelViewTransform.mat[1] - _modelViewTransform.mat[5]));
// compare if it in the positive quarter of the screen
float tmpx = (fabsf(x)-wchw); float tmpx = (fabsf(x)-wchw);
float tmpy = (fabsf(y)-wchh); float tmpy = (fabsf(y)-wchh);
return (tmpx < s.width/2 && tmpy < s.height/2); return (tmpx < screen_half.width && tmpy < screen_half.height);
} }
// Node overrides // Node overrides