Page MenuHome

BGE: Code Cleanup: LOD hysteresis calculation
ClosedPublic

Authored by Thomas Szepe (hg1) on May 10 2015, 9:37 PM.

Diff Detail

Event Timeline

Thomas Szepe (hg1) retitled this revision from to BGE: Code Cleanup: LOD hysteresis calculation.
Thomas Szepe (hg1) updated this object.

Other than inline comment it seems ok to me.

I add to kupoman as reviewer too.

source/gameengine/Ketsji/KX_GameObject.cpp
844

I would move LoD hysteresis calculation to a new static calcHysteresis function, calling it from both if "level" statements.
This way, we would avoid unnecessary calculations

source/gameengine/Ketsji/KX_GameObject.cpp
844

Calling the LoD hysteresis calculation in the if "level" statements does not avoid unnecessary calculations, Because one of the statements is always true.

Daniel Stokes (kupoman) edited edge metadata.

As long as the logic has been tested and works, this looks good to me.

This revision is now accepted and ready to land.May 12 2015, 4:02 AM

LOD example

source/gameengine/Ketsji/KX_GameObject.cpp
844

Not always. If you pass throught several LoDs (more than 2) in same direction you will be out of level value.

you can test it putting the following before if statements: printf("level = %i, m_previousLodLevel - 1 = %i, m_previousLodLevel = %i, m_previousLodLevel + 1 = %i\n", level, (m_previousLodLevel -1), m_previousLodLevel, (m_previousLodLevel + 1));

Moreover, I just realize that the hysteresis precalculation that you propose is out of "for" loop and therefore hysteresis variance calculation will be always based on first lod level.

Not always. If you pass throught several LoDs (more than 2) in same direction you will be out of level value.

No what you are claim is not correct. One of the If statements will be run minimum one time per frame. If the load level higher then 0 and in view range, then the else if and then the if will be called one time each frame. So we have two calculations for every frame instead of one. That was the reason why I moved it out of the loop.

you can test it putting the following before if statements: printf("level = %i, m_previousLodLevel - 1 = %i, m_previousLodLevel = %i, m_previousLodLevel + 1 = %i\n", level, (m_previousLodLevel -1), m_previousLodLevel, (m_previousLodLevel + 1));

I have already done a printout like this. But to get sure I have done it a second time. I also added a printout of the hysteresis one printout in each if (else if) statement.
This is the result for LOD 1.

Frame Start
hysteresis = 5
level = 0, m_previousLodLevel - 1 = 0, m_previousLodLevel = 1, m_previousLodLevel + 1 = 2
IF 2
level = 1, m_previousLodLevel - 1 = 0, m_previousLodLevel = 1, m_previousLodLevel + 1 = 2
IF 1
............................

Printout if hysteresis calculation in loop.

Frame Start
level = 0, m_previousLodLevel - 1 = 0, m_previousLodLevel = 1, m_previousLodLevel + 1 = 2
hysteresis = 5
IF 2
level = 1, m_previousLodLevel - 1 = 0, m_previousLodLevel = 1, m_previousLodLevel + 1 = 2
IF 1
hysteresis = 10
............................

Moreover, I just realize that the hysteresis precalculation that you propose is out of "for" loop and therefore hysteresis variance calculation will be always based on first lod level.

Yes you are right. I didn't tested this case. I will move the hysteresis calculation back in to the loop.

Thomas Szepe (hg1) updated this object.
Thomas Szepe (hg1) edited edge metadata.

Added static calcHysteresis function. Moved hysteresis calculation back in for loop.

Jorge Bernal (lordloki) edited edge metadata.

Looks ok to me

This revision was automatically updated to reflect the committed changes.