Jump to content

  • Log In with Google      Sign In   
  • Create Account

Banner advertising on our site currently available from just $5!

1. Learn about the promo. 2. Sign up for GDNet+. 3. Set up your advert!


Member Since 26 Mar 2002
Offline Last Active Oct 30 2014 02:29 PM

Topics I've Started

Creating fast stroke around sprite

02 February 2011 - 01:42 PM

I am creating a stroke around 2D sprites of a specified width. I do this in an offline process, so this is not a shader/DX question. But it's still de same principle.

For each pixel that has no alpha, I am making 2 for loops from -width to +width. Then if one of the pixel has alpha, I check the squared distance if it's smaller than my width and apply the new color.

I am wondering if there is not a faster way to do it. For 744 pngs, 512x512 each with a stroke of 8 pixels, it takes me 30 mins for my process. I split the work on my 4 cores (I have a Xeon machine, which is not crazy fast to start with...)

Here is the code (Language is C++):

	virtual void PixelShader(int TexCoord[2], unsigned char Out[4])
		unsigned char colorAt[4];
		int texCoordAt[2];
		float pos[2];
		float posAt[2];
		float fWidth = (float)m_width;
		fWidth *= fWidth;
		bool borderIt;
		float d;

		tex2D(TexCoord, Out);
		if (Out[3] <= 32) // No alpha (32 epsilon)
			pos[0] = (float)TexCoord[0];
			pos[1] = (float)TexCoord[1];

			// Check around with our width to see if we should fill with border
			borderIt = false;
			for (int j = TexCoord[1] - m_width; j <= TexCoord[1] + m_width; ++j)
				for (int i = TexCoord[0] - m_width; i <= TexCoord[0] + m_width; ++i)
					texCoordAt[0] = i;
					texCoordAt[1] = j;
					posAt[0] = (float)texCoordAt[0];
					posAt[1] = (float)texCoordAt[1];
					tex2D(texCoordAt, colorAt);
					if (colorAt[3] > 32)
						// Calculate the distance between the 2 points
						d = disSquared(pos, posAt);
						if (d <= fWidth)
							borderIt = true;
				if (borderIt)

			if (borderIt)
				Out[0] = m_color[0];
				Out[1] = m_color[1];
				Out[2] = m_color[2];
				Out[3] = 255;
tex2D and disSquared and inline small functions.

Can it be optimized? I would like to gain not just twice the speed, but even more if possible.


EDIT: A note, if I remove the breaks, I do not lose performance, but neither gain any. So the time lost by breaking the code is the same as to just continue the loop.

Mac OS X - Texture keep increasing the more I advance in the Level

13 April 2010 - 07:01 AM

Hi, This is an odd bug that we have on the Mac version of our game. Using the OpenGL Driver Monitor available on Mac, we see the number of textures and VRam used increasing the more we advance in the Level. If we go back, the number stop increasing. They only increase when we go to part of the level we didn't see before. Those area reuse the same meshes and there are no "new" textures. This is a very odd bug. I've been told that on iPhone, you need to render all your textures once at start of the your game, on an offscreen rectangle, to pre-cache them because iPhone has the same issue (Or "feature" ?) than on the Mac OS X. But doing so in our game doesn't fix the problem. And this is not a leak, because we are regaining all that memory at the end of the level. It's something done internally in the drivers, and on some Mac (Mac book pro) it creates big lags. And I would like also to specify this is not an engine bug. I did all the necessary debugging and no new textures are created. And it's a direct port from the DX version. Thanks for any help. I can't find any info about this on Google. My search skills are bad tho, if yours are better, please share! :)

Physic over networking

24 March 2010 - 07:37 AM

Hi guys, So I have that little test game I am making. You are pushing boxes (Using Box2D for the physic). This is a co-op multiplayer game. I already know a lot about interpolation, prediction, etc. As I already published action multiplayer games before. But this one introduces a new variable to the equation: Physic. How can I sync the physic between peers, without destroying the gameplay at all. I would like this to be p2p, with a ref peer. I was thinking that if you are the one awaking a box when pushing it first, you become the "owner" of this box until it goes back to sleep. Meaning you are the one sending it's update to the other peer. Or, I was thinking of always keeping them with a sync simulation (Like an RTS game for say). But that would create delays and it's not very a solution I would like for that kind of scenario. Thanks. (Sorry for my English)

RTS Algo to detect serounding units

02 March 2010 - 06:58 AM

In an RTS game, how to efficiently gather units in the range of another one? Three things I would like to use that for: - Detecting an enemy unit is in attack range - Switching resources if the one gathering is empty or being gathered by another unit. - Flocking. Move around other units. Unless this one can be part of the path finding, but other problems comes: moving units will recreate the nodes, and will invalidate all current paths using the touching nodes. This one is probably the most important and most CPU consuming. My game have a max of 1000 units. It's not that many, but It is out of question to loop through all of them O(N^2) for every actions requiring it. I was thinking of using a quad tree, and processing only a certain amount of units per update frame. Like 100. So would take up to 10 frames for a unit to react. Is there a known "better" efficient way to deal with that problem? Thanks you

Homework questions, why are they taboo?

08 February 2010 - 04:30 AM

Hi, I've read a couple posts from students asking homework questions. I am wondering why the general trend here is to not answer those questions. The point of an homework is to do research. I consider that asking a question on a game development forum, *is* research. And they will get an explication for the answer too. And maybe useful links :) I mean, most of my research have been done by asking questions on gamedev, and I got provide links and such that helped me a lot learning everything I know today. It wasn't part of my school, but I consider this similar. Just wondering, cheers. [Edited by - Ravuya on February 8, 2010 11:17:23 AM]