Jump to content
  • Advertisement
Sign in to follow this  
  • entries
    455
  • comments
    639
  • views
    424575

TLM Optimisation...

Sign in to follow this  
_the_phantom_

122 views

I was walking to the pub last night, letting my mind wander over the code I'm going to have to do when a thought struck me; What I'd planned todo in 3 passes I could do in one and with only two render targets.

The code, as mentioned before, peforms a sum of all the energy from different directions into the current point, then in a seperate loop works out how much energy a given cell has based on what is being sent into it from surrounding cells, it then calculates the position.


// Inner loops
for(int x = 0; x < width; ++x)
{
for(int y = 0; y < height; ++y)
{
Sn[x][y] = 0.5 * (-In[x][y] + Is[x][y] + Ie[x][y] + Iw[x][y]);
Sw[x][y] = 0.5 * ( In[x][y] - Is[x][y] + Ie[x][y] + Iw[x][y]);
Se[x][y] = 0.5 * ( In[x][y] + Is[x][y] - Ie[x][y] + Iw[x][y]);
Sw[x][y] = 0.5 * ( In[x][y] + Is[x][y] + Ie[x][y] - Iw[x][y]);
}
}
for(int x = 0; x < width; ++x)
{
for(int y = 0; y < height; ++y)
{
Ie[x][y] = Sw[x+1][y];
Iw[x][y] = Se[x-1][y];
In[x][y] = Sw[x][y-1];
Is[x][y] = Se[x][y+1];

nodevalue[x][y] = (/* maths involving the above sink array elements*/);
}
}





It occured to me that the first two steps could be combined into one and the final value worked out from that. Ping-ponging two render buffers means I can read from one and write to another with no problems. This effectly turns an O(n^2) op into an O(n) operation...

I'm half wondering how such a simple optimisation was missed? That said, the text describes API as 'advanced programming interface', which makes me cry...
Sign in to follow this  


1 Comment


Recommended Comments

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!