LCOV - code coverage report
Current view: top level - eq/server - observer.cpp (source / functions) Hit Total Coverage
Test: lcov2.info Lines: 44 56 78.6 %
Date: 2014-06-18 Functions: 12 14 85.7 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2009-2013, Stefan Eilemann <eile@equalizergraphics.com>
       3             :  *                    2010, Cedric Stalder <cedric.stalder@gmail.com>
       4             :  *
       5             :  * This library is free software; you can redistribute it and/or modify it under
       6             :  * the terms of the GNU Lesser General Public License version 2.1 as published
       7             :  * by the Free Software Foundation.
       8             :  *
       9             :  * This library is distributed in the hope that it will be useful, but WITHOUT
      10             :  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
      11             :  * FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
      12             :  * details.
      13             :  *
      14             :  * You should have received a copy of the GNU Lesser General Public License
      15             :  * along with this library; if not, write to the Free Software Foundation, Inc.,
      16             :  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
      17             :  */
      18             : 
      19             : #include "observer.h"
      20             : 
      21             : #include "config.h"
      22             : #include "global.h"
      23             : #include "view.h"
      24             : 
      25             : #include <co/dataIStream.h>
      26             : #include <co/dataOStream.h>
      27             : 
      28             : namespace eq
      29             : {
      30             : namespace server
      31             : {
      32             : 
      33             : typedef fabric::Observer< Config, Observer > Super;
      34             : 
      35         217 : Observer::Observer( Config* parent )
      36             :         : Super( parent )
      37             :         , _inverseHeadMatrix( Matrix4f::IDENTITY )
      38         217 :         , _state( STATE_ACTIVE )
      39             : {
      40         217 :     _updateEyes();
      41         217 : }
      42             : 
      43         432 : Observer::~Observer()
      44             : {
      45         432 : }
      46             : 
      47          18 : void Observer::setDirty( const uint64_t bits )
      48             : {
      49          18 :     Super::setDirty( bits );
      50          77 :     for( ViewsCIter i = _views.begin(); i != _views.end(); ++i )
      51          59 :         (*i)->setDirty( View::DIRTY_OBSERVER );
      52          18 : }
      53             : 
      54           8 : void Observer::deserialize( co::DataIStream& is, const uint64_t dirtyBits )
      55             : {
      56           8 :     Super::deserialize( is, dirtyBits );
      57             : 
      58           8 :     if( dirtyBits & ( DIRTY_EYE_POSITION | DIRTY_HEAD ))
      59           8 :         _updateEyes();
      60          16 :     if( dirtyBits & DIRTY_FOCUS ||
      61           8 :         ( (dirtyBits & DIRTY_HEAD) && getFocusMode() != FOCUSMODE_FIXED ))
      62             :     {
      63           0 :         _updateViews();
      64             :     }
      65           8 :     if( dirtyBits & DIRTY_HEAD )
      66           0 :         getHeadMatrix().inverse( _inverseHeadMatrix );
      67           8 : }
      68             : 
      69          10 : ServerPtr Observer::getServer()
      70             : {
      71          10 :     Config* config = getConfig();
      72          10 :     LBASSERT( config );
      73          10 :     return ( config ? config->getServer() : 0 );
      74             : }
      75             : 
      76         402 : void Observer::addView( View* view )
      77             : {
      78         402 :     LBASSERT( lunchbox::find( _views, view ) == _views.end( ));
      79         402 :     _views.push_back( view );
      80         402 : }
      81             : 
      82           0 : void Observer::removeView( View* view )
      83             : {
      84           0 :     ViewsIter i = lunchbox::find( _views, view );
      85           0 :     LBASSERT( i != _views.end( ));
      86           0 :     if( i != _views.end( ))
      87           0 :         _views.erase( i );
      88           0 : }
      89             : 
      90           8 : void Observer::init()
      91             : {
      92           8 :     _updateEyes();
      93           8 :     _updateViews();
      94           8 :     getHeadMatrix().inverse( _inverseHeadMatrix );
      95           8 : }
      96             : 
      97         233 : void Observer::_updateEyes()
      98             : {
      99         233 :     const Matrix4f& head = getHeadMatrix();
     100         932 :     for( size_t i = 0; i < NUM_EYES; ++i )
     101         699 :         _eyeWorld[ i ] = head * getEyePosition( Eye( 1 << i ));
     102             : 
     103         233 :     LBVERB << "Eye position: " << _eyeWorld[ fabric::EYE_CYCLOP_BIT ]
     104         233 :            << std::endl;
     105         233 : }
     106             : 
     107           8 : void Observer::_updateViews()
     108             : {
     109          63 :     for( ViewsIter i = _views.begin(); i != _views.end(); ++i )
     110          55 :         (*i)->updateFrusta();
     111           8 : }
     112             : 
     113           0 : void Observer::postDelete()
     114             : {
     115           0 :     _state = STATE_DELETE;
     116           0 :     getConfig()->postNeedsFinish();
     117           0 : }
     118             : 
     119             : }
     120             : }
     121             : #include "../fabric/observer.ipp"
     122             : template class eq::fabric::Observer< eq::server::Config, eq::server::Observer >;
     123             : /** @cond IGNORE */
     124             : template std::ostream& eq::fabric::operator << ( std::ostream&,
     125          27 :       const eq::fabric::Observer< eq::server::Config, eq::server::Observer >& );
     126             : /** @endcond */

Generated by: LCOV version 1.10