Game Development Community

TSShapeInstance::setCurrentDetail Bug?

by Duncan Gray · in Torque Game Engine · 10/31/2004 (7:14 pm) · 9 replies

In TSShapeInstance::setCurrentDetail

In this code section

S32 cutoff = getMin(smNumSkipRenderDetails,mShape->mSmallestVisibleDL);
if (mCurrentDetailLevel>=0 && mCurrentDetailLevel {
mCurrentDetailLevel = cutoff;
mCurrentIntraDetailLevel = 1.0f;
}

Is it not missing the smallest detail level, i.e. should it read

if (mCurrentDetailLevel>=0 && mCurrentDetailLevel <= cutoff)

#1
10/31/2004 (8:54 pm)
Hmm... Depends on the cutoff. I wonder if Clark knows the answer to this one. Can you test it by using some highly visible LODs and playing with the values?
#2
10/31/2004 (9:15 pm)
Ben, I have tested it with the default player and he seems to be visible from further away but it requires a model with more highly visible LODs to be sure.

At least it did not crash so it seems there is a detail level equal to cutoff.
#3
10/31/2004 (10:52 pm)
Hmm. Interesting. Well, if you can show that this is making it NOT select a LOD, then I think it would be worth putting it into HEAD.
#4
11/04/2004 (2:36 pm)
Um, your change wouldn't make any difference except possibily insuring that mCurrentIntraDetailLevel=1 (which is a subtle change and not actually what you want here). Note that the only difference your change makes is in the cast that mCurrentDetailLevel==cutoff, in which case it enters the if clause and sets mCurrentDetailLevel = cutoff.

Note: the smNumSkipRenderDetails will be 0 unless you specifically change it, so none of the above code normally matters. What it does, if you enable it, is to not render the highest detail levels of tsshapes. So if you set smNumSkipRenderDetails=2, you would never render detail level 0 or 1 (note that hte smallest visible dl line makes sure that some visible detail level gets rendered). There is a similar variable for skipping the load of the highest detail levels. These variables are in there for performance reasons.
#5
11/04/2004 (3:49 pm)
Lo, Clark has spoken. ;)
#6
12/06/2007 (8:30 am)
I think there is a bug here: mCurrentDetailLevel < cutoff

This code should read: mCurrentDetailLevel > cutoff

Looking for confirmation.
#7
12/06/2007 (9:55 am)
No, it's correct as is (had to stare at it for a while to remember why, though). As mentioned above, the cutoff value is for the skip render detail code. If the skip value is 0 (as it normally is) then the cutoff will do nothing. If the cutoff is positive, then the mSmallestVisibleDL part will make sure something gets rendered (so if you are skipping 5 detail levels but only have 1 visible one, you'll get the visible one). So the < means if the dl is less, use the cutoff value (which we know to be a visible dl based on the line above).
#8
12/06/2007 (10:10 am)
Ok, well for our characters, we have 5 detail levels, and the smNumSkipRenderDetails is zero.. so this code always uses detail level zero. I've removed the check for smNumSkipRenderDetails and check to see if mCurrentDetailLevel > cutoff to limit it to the smallest detail level, and it works like we want now. We wanted shape object specific forced detail level, and these changes give us that.

void TSShapeInstance::setCurrentDetail(S32 dl, F32 intraDL)
{
   mCurrentDetailLevel = dl;
   mCurrentIntraDetailLevel = intraDL>1.0f ? 1.0f : (intraDL<0.0f ? 0.0f : intraDL);

   // restrict chosen detail level by cutoff value
   S32 cutoff = mShape->mSmallestVisibleDL;	// getMin(smNumSkipRenderDetails,mShape->mSmallestVisibleDL);	kwh, smNumSkipRenderDetails is unused
   if (mCurrentDetailLevel >= 0 && mCurrentDetailLevel > cutoff)	// kwh, changed from (mCurrentDetailLevel < cutoff)
   {
      mCurrentDetailLevel = cutoff;
      mCurrentIntraDetailLevel = 1.0f;
   }
}
#9
12/06/2007 (10:28 am)
Kirk, the code before had no effect since smNumSkipRenderDetails was 0 (i.e. mCurrentDetail<0 was always false). You've changed it to do something completely different, which is to always make sure you have a visible detail level, even if you explicitly specified one that isn't visible. That's not generally what one wants (if you explicitly set the collision detail, e.g., then your code will ignore that and set the smallest visible dl instead). But if it's what you want then you're good to go.