Jump to content
• Advertisement
• entries
455
• comments
639
• views
426703

# TLM Optimisation...

163 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 loopsfor(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...

## Recommended Comments

sometimes you can't see the algorithms for the code. Or something else Zen. I dunno [wink].

## 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
• Advertisement
• ### Blog Entries

• Advertisement
×

## Important Information

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

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!