Code: Select all
//! Simulation of videosignal lost. Call this fun. inside main loop.
//! Returns true if videosignal from camera is 'lost'.
//! NOTE: MUST NOT use if() before itself
//! or after 'if(smth) emulCamDamage()' use:
//! '..else device->getSceneManager()->getRootSceneNode()->setVisible(true);'
bool emulCamDamage(u8 damage //! Damage level [0..255] 0-is no damage.
,ICameraSceneNode* camera
,IrrlichtDevice* device
,wchar_t* mess=L"V I D E O S I G N A L I S L O S T"
,IGUIFont* font=0)
{
if(!device) return true;
ISceneManager* smgr=device->getSceneManager();
ISceneNode* rsn=smgr->getRootSceneNode();
if(camera!=smgr->getActiveCamera())
{
rsn->setVisible(true);
return true;
}
static s32 comatoz;
if(--comatoz<0) comatoz=0;
IVideoDriver* driver=device->getVideoDriver();
if(!comatoz&&rand()%255<damage)
{
u32 coma=driver->getFPS();
comatoz=1+rand()%++coma; //! (0..1] in seconds.
}
smgr->getRootSceneNode()->setVisible(!comatoz);
if(!comatoz) return false;
rect<s32> view=driver->getViewPort();
u32 x=view.getSize().Width;
u32 y=view.getSize().Height;
s32 sfc=x*y/100; //! Let's get enough green snowflakes ;)
for(s32 j=0; j<sfc; j++)
driver->drawPixel(rand()%(x+1),rand()%(y+1)
,SColor(255,0,255,0));
if(mess) //! Tells that a signal from camera is lost.
{
IGUIEnvironment* env=device->getGUIEnvironment();
if(!font) font=env->getSkin()->getFont();
font->draw(mess
,view
,SColor(255,255,255,0)
,true,true);
}
device->sleep(10); //! Some rest when show just a noise.
return true;
}