• entries
455
639
• views
424894

# TLM Optimisation...

132 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...

## 1 Comment

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

• ### What is your GameDev Story?

In 2019 we are celebrating 20 years of GameDev.net! Share your GameDev Story with us.

(You must login to your GameDev.net account.)

×