flow
Posted: Fri Jan 18, 2008 10:28 pm
I've realised some flow improvements. Well ... it's my opinion.
First of all you should separate the ISceneManager::drawAll() function in two:
1) ISceneManager::update( float fDeltaTime );
2) ISceneManager::drawAll();
as below:
and
I'll give you some considerations: pausing!
if you make a a functionand then in constructor:and in update function (at beginning):
will just freeze but the scene will still render! This is good for opening in game menus and pause the game ... let say that we have a game and want to change our weapon from an inventory ... we should pause the game but stii render the 3D scene behind 2d stuff(inventory).
About fDeltaTime ... it is the difference between 2 frames. It will also help with lerp motion. For example if I want to move a scene node from point a to point b but using smooth motion, I can use the function
And then assuming we have a the "object" will move smoothly from point a to point b using the function like this:Then the render function will render the "object: to the specific position.
That's all for now
If you think that my ideeas are good I will continue.
First of all you should separate the ISceneManager::drawAll() function in two:
1) ISceneManager::update( float fDeltaTime );
2) ISceneManager::drawAll();
as below:
Code: Select all
void CSceneManager::update()
{
// reset attributes
Parameters.setAttribute ( "culled", 0 );
Parameters.setAttribute ( "calls", 0 );
Parameters.setAttribute ( "drawn", 0 );
// reset all transforms
video::IVideoDriver* driver = getVideoDriver();
if ( driver )
{
core::matrix4 identity;
driver->setTransform ( video::ETS_PROJECTION, identity );
driver->setTransform ( video::ETS_VIEW, identity );
driver->setTransform ( video::ETS_WORLD, identity );
driver->setTransform ( video::ETS_TEXTURE_0, identity );
driver->setTransform ( video::ETS_TEXTURE_1, identity );
driver->setTransform ( video::ETS_TEXTURE_2, identity );
driver->setTransform ( video::ETS_TEXTURE_3, identity );
}
u32 currentTime = os::Timer::getTime();
/*
char string[1024];
sprintf( string, "current time: %d\n", currentTime );
appendToDebugLog( DS_IRRLICHT_DEBUG_CHANNEL, string );
//*/
// do animations and other stuff.
OnAnimate( currentTime );
/*!
First Scene Node for prerendering should be the active camera
consistent Camera is needed for culling
*/
camWorldPos.set(0,0,0);
if ( ActiveCamera )
{
ActiveCamera->OnRegisterSceneNode();
camWorldPos = ActiveCamera->getAbsolutePosition();
}
// let all nodes register themselves
OnRegisterSceneNode();
u32 i; // new ISO for scoping problem in some compilers
//render camera scenes
{
CurrentRendertime = ESNRP_CAMERA;
for (i=0; i<CameraList.size(); ++i)
CameraList[i]->render();
CameraList.set_used(0);
}
}
Code: Select all
void CSceneManager::drawAll()
{
if (!Driver)
return;
u32 i; // new ISO for scoping problem in some compilers
//render lights scenes
{
CurrentRendertime = ESNRP_LIGHT;
Driver->deleteAllDynamicLights();
Driver->setAmbientLight(AmbientLight);
LightList.sort (); // on distance to camera
u32 maxLights = core::min_ ( Driver->getMaximalDynamicLightAmount (), LightList.size () );
for (i=0; i< maxLights; ++i)
LightList[i].node->render();
LightList.set_used(0);
}
// render skyboxes
{
CurrentRendertime = ESNRP_SKY_BOX;
for (i=0; i<SkyBoxList.size(); ++i)
SkyBoxList[i]->render();
SkyBoxList.set_used(0);
}
// render default objects
{
CurrentRendertime = ESNRP_SOLID;
SolidNodeList.sort(); // sort by textures
for (i=0; i<SolidNodeList.size(); ++i)
SolidNodeList[i].node->render();
Parameters.setAttribute ( "drawn", (s32) SolidNodeList.size () );
SolidNodeList.set_used(0);
}
// render shadows
{
CurrentRendertime = ESNRP_SHADOW;
for (i=0; i<ShadowNodeList.size(); ++i)
ShadowNodeList[i]->render();
if (!ShadowNodeList.empty())
Driver->drawStencilShadow(true,ShadowColor, ShadowColor,
ShadowColor, ShadowColor);
ShadowNodeList.set_used(0);
}
// render transparent objects.
{
CurrentRendertime = ESNRP_TRANSPARENT;
TransparentNodeList.sort(); // sort by distance from camera
for (i=0; i<TransparentNodeList.size(); ++i)
TransparentNodeList[i].node->render();
TransparentNodeList.set_used(0);
}
// render shader objects.
{
for ( u32 g = 0; g!= ESNRP_SHADER_10 - ESNRP_SHADER_0 + 1; ++g )
{
CurrentRendertime = (scene::E_SCENE_NODE_RENDER_PASS) (ESNRP_SHADER_0 + g);
const u32 size = ShaderNodeList[g].size ();
if ( 0 == size )
continue;
ShaderNodeList[g].sort(); // sort by textures
for (i=0; i< size; ++i)
ShaderNodeList[g][i].node->render();
ShaderNodeList[g].set_used(0);
}
}
clearDeletionList();
CurrentRendertime = ESNRP_COUNT;
}
if you make a
Code: Select all
bool m_bPaused;
Code: Select all
inline void setPause( bool bPause ){ m_bPaused = bPause; }
Code: Select all
m_bPaused = false;
Code: Select all
if( m_bPaused ) return;
About fDeltaTime ... it is the difference between 2 frames. It will also help with lerp motion. For example if I want to move a scene node from point a to point b but using smooth motion, I can use the function
Code: Select all
vector3df LerpValue( vector3df& current_point, vector3df& target_point, float fFactor )
{
if( factor >= 1.0f )
return target_point;
return current_point * ( 1.0f - fFactor ) + target_point * fFactor );
}
Code: Select all
void move( vector3df to_pos ){ m_targetPos = to_pos;}
Code: Select all
m_pos = LerpValue( m_pos, m_targetPos, fDeltaTime * fSpeed );
SetPosition( m_pos );/* m_pos is the current position*/
That's all for now
![Smile :)](./images/smilies/icon_smile.gif)