Game Development Community

Creating sprites causes hiccups

by Vern Jensen · in Torque Game Builder · 06/08/2009 (7:55 pm) · 58 replies

I've found that creating a sprite and adding it to the sceneGraph is really slow. Enough to cause the creation of even 10 or so to generate a noticeable hiccup on slightly older systems. (i.e. 1 GHz processors) I did some tests with this method:

function doStarFieldTest()
{
	$gMyTestStartTime = getRealTime();
	
	%newSprite = new t2dStaticSprite() 
	{ 
		scenegraph = gameSceneGraph; 	// NOTE: This name must be set in Torque's GUI editor!
//		class = Asteroid; 
		imageMap = "star2ImageMap";
		layer = $gAsteroidLayer;
		size = "0.3 0.3";
	}; 

	for (%n = 1; %n < 500; %n++)
	{
		
	/*	
		%newSprite = new t2dStaticSprite() 
		{ 
			scenegraph = gameSceneGraph; 	// NOTE: This name must be set in Torque's GUI editor!
			imageMap = "star2ImageMap";
			layer = $gAsteroidLayer;
			size = "0.3 0.3";
		}; 
	*/	
		
		%newSprite.setLinearVelocity( 0, 15 );
	
		
						// Set a random location
		%xLoc = GetRandomFloat(-70, 70);
		%yLoc = GetRandomFloat(-70p, 70);
		%newSprite.setPosition( %xLoc, %yLoc );
	}
	
	
	echo("  Time to create 50 stars: " @ (getRealTime() - $gMyTestStartTime));
}

I added key bindings to call this any time a key was pressed. In one version, I left it as-is, where only *one* sprite is created, but then the code above is called on it 500 times. This was a test to see if executing these lines of script 500 times was what was creating the noticeable slowdown.

In the second version, uncomment the "new t2dStaticSprite" code inside the loop, and change it to loop only *50* times, not 500. This version is *significantly* slower than the other. It creates noticeable lurches in the animation every time I push the key that invokes this function. This is on a 2 GHz dual-core Intel Mac. Only 50 sprites. Even far fewer sprites can create a noticeable lurch in the animation if created at once on a somewhat older computer. (As I mentioned before, even 10 is enough to see the delay.) That's just 5 bullets with glows attached to them. In a shooter, this is a common occurrence. You *need* to be able to create (and delete -- also slow) lots of sprites in a single frame of animation in some instances.

The problem is not script. The problem is "new t2dStaticSprite" -- something internal to the engine is quite slow for this. I have the engine source, and can make mods, but I don't even know where to start. What files should I be looking at to consider trying possible engine-level speed-ups?

Page«First 1 2 3 Next»
#41
06/15/2009 (7:18 am)
As I said in my previous post, I need some way of sending it to you!
#42
06/15/2009 (4:52 pm)
JohnnyC@virtual-prophecy.com
#43
06/16/2009 (12:38 am)
Email sent.
#44
06/16/2009 (1:23 pm)
sorry, here's mine: smithmj5@gmail.com - I thought you could get my email address from my profile, my bad!
#45
06/16/2009 (1:46 pm)
No, your email is blank in your profile.

Email sent.
#46
07/01/2009 (4:55 pm)
hey there, melv.

i recompiled TGB with the memory fix, and now, it takes half of what it used to before, thats a nice touch, BUT, there seems to be a glith (bug?) now.

whenever i load an image, that needs to be loaded with the KEY method, the TGB editor wont accept it, and aoutput basically garbage.

let me put it this way:
with the old (stock) version of TGB, i creted some files that used a set of images that used the key format, and they worked pretty darn good, now, with the recompiled version, the whole (unmodified) level loads as usual (but faster T_T), BUT wherever was a frame of certain images loaded with the KEY method, i see error glitches, and found out by looking at the art assets thru the editor, that the program is not accepting the images the way it used to (somewhat, the alpha channel is gone or somethin like that!)...

i'll send you some pics of the problem, with an attached image to your email, for you to check.
#47
07/04/2009 (9:39 am)
I've just got back from holiday a few hours ago so sorry for the delay in replying, I'll deal with your email when I get through them all.

So do you have problems with a recompiled stock TGB? Only when you recompile with the new files I sent you?
#48
07/06/2009 (1:30 pm)
if i compile the Stock (unmodified) TGB, everything goes as expected. if i replace the original files with the ones you sent me, then the bug pops up... i think the bug was introduced in the T2DImageMapDatablock.cc ... but im not sure where to look to try and fix it myself.
#49
07/06/2009 (1:58 pm)
Hmm, that's very odd. I've seen this used now in many projects that use the key response without problem. I've tried this again and I don't get any issue.

Could you post me the image-map setup for the artwork you sent me? I presume those are static-sprites (you may have said in your email).
#50
07/06/2009 (4:02 pm)
just sent you another email with more explicit images, logs and stuff... maybe you can see whats goin on with that info.
#51
12/14/2009 (3:07 am)
Could Someone send me the code too. I got TGB Pro too. My 40MB game is taking 500MB ram. Thanks in advance.

\
#52
12/14/2009 (4:44 am)
sent.

It should be noted that this code stops the original bitmap from staying in memory co-resident with the texture that's on the GPU. This is not a generalized memory optimization pass or anything like that and there are many reasons why your code could be leaking memory.

The code replaces the stock v1.7.4 and should not be used if you've made modifications to the source-code yourself unless you are sure you know what you are doing.

Sorry for the disclaimer but I've been drowned (in the past) by supporting this update and I'm seriously busy right now and may be forced to ignore such requests which isn't something I like doing at all!

#53
12/14/2009 (1:30 pm)
Hey Melv, if you're reading this, would you happen to know of any other released games or demos (Mac/Windows cross-platform) that use your memory modification code?

My game isn't launching on some setups, whereas TGB 1.1.3-based games Phantasia and Larva Mortus are. I'm about to start working on narrowing down what's causing this, and if I have any 1.7.4 games (esp. ones that use your memory mod) to point these users to, for testing purposes, that would be quite helpful in the narrowing-down process. :-)
#54
12/14/2009 (2:44 pm)
I don't know them off the top of my head although I do know this code has been used and has been confirmed to have passed some rigorous QA. I'd need to go back on my emails to find some of those threads.

To be completely honestly, if you look at the code changes, they are trivial and should have no relation to not launching or any serious consequences at all. Indeed, even if all image-maps fail then the game will launch, it's just that anything using the image-maps won't render.

If you're saying it's crashing then where is it crashing?
#55
12/14/2009 (6:16 pm)
It's actually hanging, on startup. Two reports so far of this on a Mac. Nothing outputted to the console.log file -- it's there, but is empty. The icon bounces in the dock, but nothing ever happens, and if you bring up the task manager, you see the process as "not responding."

It's obviously either a change to the engine since 1.1.3, or something I've changed to the engine myself. I will be sending various tests to these guys, who are willing to help me, out, to try to narrow it down. However, it would be helpful if I could point them to another published TGB 1.7.4 game, esp. one that uses your memory changes, to verify that neither 1.7.4, nor your changes, are the problem. You are likely right that your changes couldn't affect startup, but I just want to be sure.
#56
12/15/2009 (4:44 am)
I see now Vern. I'll ask around but I'm not sure of the specific versions for any one game. You'd probably find that most are the latests. A quick way to find out would be to download some of the demos (Show Off) and check the version in the resultant log. :)

I'll ask around though.
#57
12/15/2009 (5:24 am)
Yeah, I've tried a number on TorquePowered, and most are 1.1.3 or some other older version. Let me know if you find any that are 1.7.4.
#58
02/15/2010 (5:19 am)
If someone could, please send the files to eric.paik@gmail.com
Page«First 1 2 3 Next»