Delay in adding new items
by J.C. Smith · in Torque Game Engine · 04/26/2005 (6:23 am) · 9 replies
Hey there guys and gals. I have been thumping my head on the wall today trying to figure this out, and finally I decided to just break down and ask. Someone has probably run into this same problem before, and any help or explanation would be much appreciated.
In quick summary I was writing something similar to Popcap's Dynomite. Basically I have a map populated with a bunch of multi-colored balls, which are "Items". I modified the collision to detect them as such, and rigged it up to check to see if your Projectile ball is the proper color to destroy the item and add to your score. If your projectile is of the improper color I have it do spawn a new ball Item between the previous one and the player. Everything is working fine, but there is a very annoying delay in spawning the new balls. The projectile and balls collide, if I have the console echos turned on it echos the collision to me, but then I have maybe a half second to a second delay before the new ball is spawned. The new ball is supposed to actually be the projectile (which is being destroyed at the same time I spawn the new ball) so the delay is killing the effect. Here's a simplified version of my code:
function Ball::damage(%this, %obj, %sourceObject, %position, %damage, %damageType)
{
if ($ballcolor == 0)
{
echo ("HIT!");
$score = $score +10;
%obj.schedule(10, "delete");
}
else
{
echo ("Wrong Color");
createBall (%position);
}
}
function createBall(%pos)
{
%ball= new Item() { datablock = Ball; };
%ball.position = %pos;
// Removed all of the position and ball color routines, for brevity
MissionCleanup.add(%ball);
}
Everything is creating and working just fine, but I'm getting that half second or so delay. My best guess is that it has something to do with Items timeslice but I've been wading through the source and I can't figure out where. Any help would be much appreciated.
- J.C.
In quick summary I was writing something similar to Popcap's Dynomite. Basically I have a map populated with a bunch of multi-colored balls, which are "Items". I modified the collision to detect them as such, and rigged it up to check to see if your Projectile ball is the proper color to destroy the item and add to your score. If your projectile is of the improper color I have it do spawn a new ball Item between the previous one and the player. Everything is working fine, but there is a very annoying delay in spawning the new balls. The projectile and balls collide, if I have the console echos turned on it echos the collision to me, but then I have maybe a half second to a second delay before the new ball is spawned. The new ball is supposed to actually be the projectile (which is being destroyed at the same time I spawn the new ball) so the delay is killing the effect. Here's a simplified version of my code:
function Ball::damage(%this, %obj, %sourceObject, %position, %damage, %damageType)
{
if ($ballcolor == 0)
{
echo ("HIT!");
$score = $score +10;
%obj.schedule(10, "delete");
}
else
{
echo ("Wrong Color");
createBall (%position);
}
}
function createBall(%pos)
{
%ball= new Item() { datablock = Ball; };
%ball.position = %pos;
// Removed all of the position and ball color routines, for brevity
MissionCleanup.add(%ball);
}
Everything is creating and working just fine, but I'm getting that half second or so delay. My best guess is that it has something to do with Items timeslice but I've been wading through the source and I can't figure out where. Any help would be much appreciated.
- J.C.
#2
04/26/2005 (10:04 am)
It's the networking. I don't know what command Dreamer is talking about. If you're doing a single player game I'd suggest turning up the packet size and update rates, or even consider doing away with the networking completely (that would be a much bigger change of course ;). Doing the former gave the GDC Warzone demo a big apparent performance boost.
#3
04/26/2005 (10:31 am)
Ahhhh sorry for the bad info there, I could have swore I remember reading about a function somewhere in code that forces an action to happen now rather than waiting on the next tick... Then again I used alot of different engines before coming to Torque, and some of that junk is still floating around upstairs if ya know what I mean.
#4
I'm using staticShapeData for something similar and there is no visible delay.
04/26/2005 (10:55 am)
Just curious... why are you using Items? For the lighting data fields? I'm using staticShapeData for something similar and there is no visible delay.
#5
To Sam, I'm really just doing this trying to get the feel of Torque. I've owned a license from the beginning but work has kept me busy and I'll admit it took me a while to come aroud to accepting scripting languages. I spent my first 7 years programming exclusively in assembly, before moving to C/C++. I originally licensed the source, looked aroud, and just sort of moved on. Recently I have had a lot more free time, and decided to give torque some time. So basically I'm just figuring out the engine.
The original system used static shapes, but I was having a problem with the collision (I was waiting for an OnCollision which never was being called in the staticshape data, but the collision worked through projectiles, I should have been waiting for Damage instead I'd guess now). So I was scanning resources trying to find the reason for it and one tutorial I read (or possibly misread) said that staticshapes wouldn't be collided against. Assuming that was the problem I started messing around with items and have the system implemented based on them, which had worked fine until now. I should probably rewrite it using shapes but was mostly curious as to why the delay was happening and if there was any way around it. Probably before I implement it back as shapes I'll first mess aroudn with the source and try to get the items displaying quickly for educatoinal purposes.
Thank you all for your responses.
04/26/2005 (10:23 pm)
Okies, thanks a bunch.To Sam, I'm really just doing this trying to get the feel of Torque. I've owned a license from the beginning but work has kept me busy and I'll admit it took me a while to come aroud to accepting scripting languages. I spent my first 7 years programming exclusively in assembly, before moving to C/C++. I originally licensed the source, looked aroud, and just sort of moved on. Recently I have had a lot more free time, and decided to give torque some time. So basically I'm just figuring out the engine.
The original system used static shapes, but I was having a problem with the collision (I was waiting for an OnCollision which never was being called in the staticshape data, but the collision worked through projectiles, I should have been waiting for Damage instead I'd guess now). So I was scanning resources trying to find the reason for it and one tutorial I read (or possibly misread) said that staticshapes wouldn't be collided against. Assuming that was the problem I started messing around with items and have the system implemented based on them, which had worked fine until now. I should probably rewrite it using shapes but was mostly curious as to why the delay was happening and if there was any way around it. Probably before I implement it back as shapes I'll first mess aroudn with the source and try to get the items displaying quickly for educatoinal purposes.
Thank you all for your responses.
#6
05/05/2005 (2:05 am)
Figured I'd give a quick update here. Since writing these messages I've gone over a variety of differnet approaches to try to handle this. I've tried doing it with staticshapes and with items, and I've fiddled quite a bit with the packet rates. In the end nothing has been able to do away with the visible delay.
#7
datablock StaticShapeData(RedBall)
{
category = "Balls";
shapeFile = "~/data/shapes/balls/redball.dts";
};
datablock StaticShapeData(BlueBall)
{
category = "Balls";
shapeFile = "~/data/shapes/balls/blueball.dts";
};
datablock StaticShapeData(YellowBall)
{
category = "Balls";
shapeFile = "~/data/shapes/balls/yellowball.dts";
};
datablock StaticShapeData(PurpleBall)
{
category = "Balls";
shapeFile = "~/data/shapes/balls/purpleball.dts";
};
function GenerateMap(%numx,%numy,%maxblocks)
{
$maxcolors = %maxblocks;
%xsize = 4; //This determines how much to step for each tile. This allows us to have
%ysize = 4; //sized blocks for different maps.
%initialx = 0 - ((%numx * %xsize) /2); // Initial X, Y and Z positions, the entire map will be based on these start locations
%initialy = 25; // Meaning this is where the map in the world.
%initialz = 52;
%directoryname = "~/starter.fps/data/shapes/balls/"; // name of directory where shape files are located
echo ("Generating Map");
%blockname[0] = "RedBall";
%blockname[1] = "BlueBall";
%blockname[2] = "YellowBall";
%blockname[3] = "PurpleBall";
for (%i = 0; %i< %numy; %i++) // do generation for each amount in y size
{
for (%j = 0; %j < %numx; %j++) // calculate this row
{
%t = getRandom (%maxblocks -1);
$mapdata[%j,%i] = %t;
%posx = %initialx + (%xsize * %j);
%posy = %initialy + (%ysize * %i);
%position = %posx SPC %posy SPC %initialz;
%tempblocknum = $mapdata[%j, %i];
%shapefile = %blockname[%tempblocknum];
$obj[%j, %i] = new StaticShape()
{
datablock = %shapefile;
position = %initialx + (%xsize * %j) SPC %initialy + (%ysize * %i) SPC %initialz;
rotation = "0 0 0";
scale = "1 1 1";
};
MissionCleanup.add($obj[%j,%i]);
}
}
echo ("Finished Generation Loop - Waiting on Shapes to Render");
}
05/05/2005 (7:04 pm)
One more follow-up for those wondering what I mean by the delay. Here's a snippet of code which illustrates it well... Call this with a setting similar to GenerateMap(12, 6, 3) or whatever (x, y, # of colors) and it will generate a grid of balls. You'll have to have a ball object, I just created a simple one with 3ds max... When the script is done executing (quickly) it echos that it is now waiting for the items to be added, that loop has been exited. It then takes over 4 seconds for the balls to get through drawing on an XP 2800+. datablock StaticShapeData(RedBall)
{
category = "Balls";
shapeFile = "~/data/shapes/balls/redball.dts";
};
datablock StaticShapeData(BlueBall)
{
category = "Balls";
shapeFile = "~/data/shapes/balls/blueball.dts";
};
datablock StaticShapeData(YellowBall)
{
category = "Balls";
shapeFile = "~/data/shapes/balls/yellowball.dts";
};
datablock StaticShapeData(PurpleBall)
{
category = "Balls";
shapeFile = "~/data/shapes/balls/purpleball.dts";
};
function GenerateMap(%numx,%numy,%maxblocks)
{
$maxcolors = %maxblocks;
%xsize = 4; //This determines how much to step for each tile. This allows us to have
%ysize = 4; //sized blocks for different maps.
%initialx = 0 - ((%numx * %xsize) /2); // Initial X, Y and Z positions, the entire map will be based on these start locations
%initialy = 25; // Meaning this is where the map in the world.
%initialz = 52;
%directoryname = "~/starter.fps/data/shapes/balls/"; // name of directory where shape files are located
echo ("Generating Map");
%blockname[0] = "RedBall";
%blockname[1] = "BlueBall";
%blockname[2] = "YellowBall";
%blockname[3] = "PurpleBall";
for (%i = 0; %i< %numy; %i++) // do generation for each amount in y size
{
for (%j = 0; %j < %numx; %j++) // calculate this row
{
%t = getRandom (%maxblocks -1);
$mapdata[%j,%i] = %t;
%posx = %initialx + (%xsize * %j);
%posy = %initialy + (%ysize * %i);
%position = %posx SPC %posy SPC %initialz;
%tempblocknum = $mapdata[%j, %i];
%shapefile = %blockname[%tempblocknum];
$obj[%j, %i] = new StaticShape()
{
datablock = %shapefile;
position = %initialx + (%xsize * %j) SPC %initialy + (%ysize * %i) SPC %initialz;
rotation = "0 0 0";
scale = "1 1 1";
};
MissionCleanup.add($obj[%j,%i]);
}
}
echo ("Finished Generation Loop - Waiting on Shapes to Render");
}
#8
maybe a small delay if I have 10+ objects, but not 4 secs, - on a P3 1400 XP.
I guess $mapdata is an array? %tempblocknum = $mapdata[%j, %i];
Why are you using an array (?) for $obj here... $obj[%j, %i] = new StaticShape() ?
05/05/2005 (8:12 pm)
Hmmm... I done similair things, laying out fairly complicated things objects in a grid and it is almost instant, maybe a small delay if I have 10+ objects, but not 4 secs, - on a P3 1400 XP.
I guess $mapdata is an array? %tempblocknum = $mapdata[%j, %i];
Why are you using an array (?) for $obj here... $obj[%j, %i] = new StaticShape() ?
#9
In the case of $mapdata though this is an array. Basically the idea here was to break the world up into basically the equivalent of 2d tiles rendered in 3d. In the original incarnation of the code I used colision detection and a quick algorithm to place a ball at an offset between the player and the collision object. The problem though was that after a while the balls became laid out in a big mess. So this time around my plan was to use a gridded approach, and to use a simple collision object, when it was hit I was going to draw the ball in an offset that aligned with the the grid and kept everything in order. For the purpose of the example above you don't need global mapdata or objects at all, but it didn't cut it out of the code.
05/06/2005 (3:53 am)
The problem is there regardless of the array or not, I just did a cut and paste of the generate code without cleaning it up at all. The $obj was just a hold over from an experiment I was doing last night, it should be changed back to a %, but I handn't cleaned it up. So it's not completely optimized code, some of it was after experimenting for couple of days with different things. In the case of $mapdata though this is an array. Basically the idea here was to break the world up into basically the equivalent of 2d tiles rendered in 3d. In the original incarnation of the code I used colision detection and a quick algorithm to place a ball at an offset between the player and the collision object. The problem though was that after a while the balls became laid out in a big mess. So this time around my plan was to use a gridded approach, and to use a simple collision object, when it was hit I was going to draw the ball in an offset that aligned with the the grid and kept everything in order. For the purpose of the example above you don't need global mapdata or objects at all, but it didn't cut it out of the code.
Torque Owner Dreamer
Default Studio Name