From 80bfc72e7389b49fd9e2ddc42573f1f9acff8157 Mon Sep 17 00:00:00 2001 From: Sean Heber Date: Thu, 23 Jan 2014 21:14:39 -0600 Subject: [PATCH] Performance enhancement Improved tile performance by using reserve() to alloc the size of the arrays internally all at once instead of on-demand since this is way faster. In my test case this made a significant impact. Also attempting to get the compiler to avoid some other more hidden copying. --- project/src/common/Hardware.cpp | 71 ++++++++++++++++++--------------- 1 file changed, 38 insertions(+), 33 deletions(-) diff --git a/project/src/common/Hardware.cpp b/project/src/common/Hardware.cpp index a467e9677..56aa46f95 100644 --- a/project/src/common/Hardware.cpp +++ b/project/src/common/Hardware.cpp @@ -333,9 +333,14 @@ public: { Vertices &vertices = mArrays->mVertices; Vertices &tex = mArrays->mTexCoords; - UserPoint *point = (UserPoint *)inData; + Colours &colours = mArrays->mColours; + const UserPoint *point = (const UserPoint *)inData; mElement.mFirst = vertices.size(); + vertices.reserve(vertices.size() + (6 * inCount)); + tex.reserve(tex.size() + (6 * inCount)); + colours.reserve(colours.size() + (6 * inCount)); + for(int i=0;iPixelToTex(tex_pos); + const UserPoint tp2 = mTexture->PixelToTex(UserPoint(tex_pos.x+size.x,tex_pos.y+size.y)); - pos = tex_pos; - tex.push_back( mTexture->PixelToTex(pos) ); - tex.push_back( mTexture->PixelToTex(UserPoint(pos.x+size.x,pos.y)) ); - tex.push_back( mTexture->PixelToTex(UserPoint(pos.x+size.x,pos.y+size.y)) ); - tex.push_back( mTexture->PixelToTex(pos) ); - tex.push_back( mTexture->PixelToTex(UserPoint(pos.x+size.x,pos.y+size.y)) ); - tex.push_back( mTexture->PixelToTex(UserPoint(pos.x,pos.y+size.y)) ); + tex.push_back( tp1 ); + tex.push_back( mTexture->PixelToTex(UserPoint(tex_pos.x+size.x,tex_pos.y)) ); + tex.push_back( tp2 ); + tex.push_back( tp1 ); + tex.push_back( tp2 ); + tex.push_back( mTexture->PixelToTex(UserPoint(tex_pos.x,tex_pos.y+size.y)) ); if (inCommands[i]&pcTile_Col_Bit) { - UserPoint rg = *point++; - UserPoint ba = *point++; - Colours &colours = mArrays->mColours; + const UserPoint &rg = *point++; + const UserPoint &ba = *point++; #ifdef BLACKBERRY - uint32 col = ((int)(rg.x*255)) | - (((int)(rg.y*255))<<8) | - (((int)(ba.x*255))<<16) | - (((int)(ba.y*255))<<24); + const uint32 col = ((int)(rg.x*255)) | + (((int)(rg.y*255))<<8) | + (((int)(ba.x*255))<<16) | + (((int)(ba.y*255))<<24); #else - uint32 col = ((rg.x<0 ? 0 : rg.x>1?255 : (int)(rg.x*255))) | - ((rg.y<0 ? 0 : rg.y>1?255 : (int)(rg.y*255))<<8) | - ((ba.x<0 ? 0 : ba.x>1?255 : (int)(ba.x*255))<<16) | - ((ba.y<0 ? 0 : ba.y>1?255 : (int)(ba.y*255))<<24); + const uint32 col = ((rg.x<0 ? 0 : rg.x>1?255 : (int)(rg.x*255))) | + ((rg.y<0 ? 0 : rg.y>1?255 : (int)(rg.y*255))<<8) | + ((ba.x<0 ? 0 : ba.x>1?255 : (int)(ba.x*255))<<16) | + ((ba.y<0 ? 0 : ba.y>1?255 : (int)(ba.y*255))<<24); #endif colours.push_back( col ); colours.push_back( col );