Game Development Community

Projectile code assistance

by Ronald J Nelson · in Torque Game Engine · 08/03/2007 (12:14 am) · 10 replies

Hi all I have been modifing my projectile code to make the previous version I had done to make bullets recognize materials work better and be more flexible. However, I have run into a problem where it doesn't get the container anymore in this portion of processTick:

if (getContainer()->castRay(oldPosition, newPosition, csmDynamicCollisionMask | csmStaticCollisionMask, &rInfo) == true)

I would really appreciate it if someone could look at my files and point out my mistakes.

File links removed.

Fell free to use what I have if you find it useful, I would really just like to figure out why I broke the code, it all looks fine to me.

I plan to take down this code as soon as I can get it fixed.

#1
08/03/2007 (2:27 am)
ProcessTick looks fine to me, Ron.

What's happening? castRay returns 0? getContainer returns NULL or garbage?
#2
08/03/2007 (4:49 am)
Looks as if getContainer is returning NULL or garbage. If you run this in a DEBUG executable you will get a Fatal: (c:\torque\sdk\engine\sim\sceneobject.cc @ 286) Bad minCoord.

I am guessing that it has something to do with how I am loading up decals and explosionDT.
#3
08/03/2007 (7:05 am)
Extra info: I have tried adding consolelogentry statements to the portions pertaining to decals and explosionDT in pack and unpack. They said the check for loading the info for these two are good there.

In void ProjectileData::unpackData(BitStream* stream) I added this:

for (U32 i = 0; i < NumFX; i++)
      if (stream->readFlag())
	  {
         decalId[i] = stream->readRangedU32(DataBlockObjectIdFirst, DataBlockObjectIdLast);
		 explosionIdDT[i] = stream->readRangedU32(DataBlockObjectIdFirst, DataBlockObjectIdLast);
		 Con::errorf( ConsoleLogEntry::General, "explosionIdDT : %d", explosionIdDT[i]);
	  }

And this is what I get:
explosionIdDT : 276
explosionIdDT : 272
explosionIdDT : 282
explosionIdDT : 274
explosionIdDT : 276
explosionIdDT : 272
explosionIdDT : 282
explosionIdDT : 274
explosionIdDT : 276
explosionIdDT : 272
explosionIdDT : 282
explosionIdDT : 274
explosionIdDT : 276
explosionIdDT : 272
explosionIdDT : 282
explosionIdDT : 274
explosionIdDT : 276
explosionIdDT : 272
explosionIdDT : 274
explosionIdDT : 274
explosionIdDT : 276
explosionIdDT : 272
explosionIdDT : 282
explosionIdDT : 274

Which to me says it knows the datablocks are there, but something is happening that it won't use them.
#4
08/03/2007 (7:34 am)
But why would that make getContainer () return NULL? Can you try this with a stock Projectile class, and see if the same problem appears?
#5
08/03/2007 (11:31 am)
Totally hypothetical guess: any chance you commented out/deleted any code related to the object moving itself through the binning system? SceneObject provides access to the Container class, but each object is responsible for making sure it manages bin movement, and if you don't participate in that process with your class, it would effectively never be in a container.

Another possible issue: did you add your projectile to the scene itself with a call to ::addToScene()?
#6
08/03/2007 (5:07 pm)
Stefan - I stripped it down massively and most is original TGE code now. Still crashes and for the life of me, I can't tell why.

Stephen- Nope nothing commented out. As a matter of fact it never even gets to the point where I did anything other than some minor datablock coding.

I have reloaded those and I am including the script files for one of my weapons.
#7
08/03/2007 (10:17 pm)
I have double checked with WinMerge the backed up copies of my game and source code compared to the script and source I have put up here. There are no new changes that I might have messed up on other than how I am doing my explosions.

The fact is, that the projectile does not appear to even fire when I do this in the non-Debug compilation. Its as if it is not recognizing the projectile datablock as being valid. I also know this because my reload script also indicates it cannot find the ammo for the weapon for reloads which means the datablock is not working.

As far as I can tell something with loading the different explosions in an array like was done with the decals is causing problems.
#8
08/04/2007 (1:46 am)
I still don't understand why an invalid datablock would affect the container.

Quote:
The fact is, that the projectile does not appear to even fire when I do this in the non-Debug compilation.

What happens in Debug that's different?

Quote:
Its as if it is not recognizing the projectile datablock as being valid. I also know this because my reload script also indicates it cannot find the ammo for the weapon for reloads which means the datablock is not working.

Wouldn't that mean the ShapeImageData rather than ProjectileData?
Your explosion ID loading, packing, unpacking and whatnot looks OK.
#9
08/04/2007 (12:30 pm)
Stefan - When I am using the debug version I get the Fatal: (c:\torque\sdk\engine\sim\sceneobject.cc @ 286) Bad minCoord error when I fire the weapon at anything.

When I am using the regular executable it just fires and eventually crashes after firing a few rounds.
#10
08/07/2007 (7:15 pm)
Figured this one out on my own. I needed to perfrom the pack and unpack updates seperately for the decals and explosions. Same varaibles, just done individually. Works perfect and I actually see an improved performance rate.

Thanks for everyone's help.