LCOV - code coverage report
Current view: top level - eq/server - observer.cpp (source / functions) Hit Total Coverage
Test: Equalizer Lines: 44 56 78.6 %
Date: 2017-12-16 05:07:20 Functions: 12 14 85.7 %

          Line data    Source code
       1             : 
       2             : /* Copyright (c) 2009-2016, Stefan Eilemann <eile@equalizergraphics.com>
       3             :  *                          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             : typedef fabric::Observer<Config, Observer> Super;
      33             : 
      34         408 : Observer::Observer(Config* parent)
      35             :     : Super(parent)
      36         408 :     , _state(STATE_ACTIVE)
      37             : {
      38         408 :     _updateEyes();
      39         408 : }
      40             : 
      41         812 : Observer::~Observer()
      42             : {
      43         812 : }
      44             : 
      45          14 : void Observer::setDirty(const uint64_t bits)
      46             : {
      47          14 :     Super::setDirty(bits);
      48          28 :     for (ViewsCIter i = _views.begin(); i != _views.end(); ++i)
      49          14 :         (*i)->setDirty(View::DIRTY_OBSERVER);
      50          14 : }
      51             : 
      52           2 : void Observer::deserialize(co::DataIStream& is, const uint64_t dirtyBits)
      53             : {
      54           2 :     Super::deserialize(is, dirtyBits);
      55             : 
      56           2 :     if (dirtyBits & (DIRTY_EYE_POSITION | DIRTY_HEAD))
      57           2 :         _updateEyes();
      58           4 :     if (dirtyBits & DIRTY_FOCUS ||
      59           2 :         ((dirtyBits & DIRTY_HEAD) && getFocusMode() != FOCUSMODE_FIXED))
      60             :     {
      61           0 :         _updateViews();
      62             :     }
      63           2 :     if (dirtyBits & DIRTY_HEAD)
      64           0 :         _inverseHeadMatrix = getHeadMatrix().inverse();
      65           2 : }
      66             : 
      67           2 : ServerPtr Observer::getServer()
      68             : {
      69           2 :     Config* config = getConfig();
      70           2 :     LBASSERT(config);
      71           2 :     return (config ? config->getServer() : 0);
      72             : }
      73             : 
      74         688 : void Observer::addView(View* view)
      75             : {
      76         688 :     LBASSERT(lunchbox::find(_views, view) == _views.end());
      77         688 :     _views.push_back(view);
      78         688 : }
      79             : 
      80           0 : void Observer::removeView(View* view)
      81             : {
      82           0 :     ViewsIter i = lunchbox::find(_views, view);
      83           0 :     LBASSERT(i != _views.end());
      84           0 :     if (i != _views.end())
      85           0 :         _views.erase(i);
      86           0 : }
      87             : 
      88           2 : void Observer::init()
      89             : {
      90           2 :     _updateEyes();
      91           2 :     _updateViews();
      92           2 :     _inverseHeadMatrix = getHeadMatrix().inverse();
      93           2 : }
      94             : 
      95         412 : void Observer::_updateEyes()
      96             : {
      97         412 :     const Matrix4f& head = getHeadMatrix();
      98        1648 :     for (size_t i = 0; i < NUM_EYES; ++i)
      99        1236 :         _eyeWorld[i] = head * getEyePosition(Eye(1 << i));
     100             : 
     101         412 :     LBVERB << "Eye position: " << _eyeWorld[fabric::EYE_CYCLOP_BIT]
     102         412 :            << std::endl;
     103         412 : }
     104             : 
     105           2 : void Observer::_updateViews()
     106             : {
     107          16 :     for (ViewsIter i = _views.begin(); i != _views.end(); ++i)
     108          14 :         (*i)->updateFrusta();
     109           2 : }
     110             : 
     111           0 : void Observer::postDelete()
     112             : {
     113           0 :     _state = STATE_DELETE;
     114           0 :     getConfig()->postNeedsFinish();
     115           0 : }
     116             : }
     117             : }
     118             : #include "../fabric/observer.ipp"
     119             : template class eq::fabric::Observer<eq::server::Config, eq::server::Observer>;
     120             : /** @cond IGNORE */
     121             : template std::ostream& eq::fabric::operator<<(
     122             :     std::ostream&,
     123          60 :     const eq::fabric::Observer<eq::server::Config, eq::server::Observer>&);
     124             : /** @endcond */

Generated by: LCOV version 1.11