Equalizer  1.6.1
eVolve.cpp
1 
2 /* Copyright (c) 2005-2010, Stefan Eilemann <eile@equalizergraphics.com>
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, are permitted provided that the following conditions are met:
6  *
7  * - Redistributions of source code must retain the above copyright notice, this
8  * list of conditions and the following disclaimer.
9  * - Redistributions in binary form must reproduce the above copyright notice,
10  * this list of conditions and the following disclaimer in the documentation
11  * and/or other materials provided with the distribution.
12  * - Neither the name of Eyescale Software GmbH nor the names of its
13  * contributors may be used to endorse or promote products derived from this
14  * software without specific prior written permission.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
17  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
20  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26  * POSSIBILITY OF SUCH DAMAGE.
27  */
28 
29 #include "eVolve.h"
30 
31 #include "config.h"
32 #include "localInitData.h"
33 
34 #include <stdlib.h>
35 
36 namespace eVolve
37 {
38 
39 static const std::string _help(
40  std::string( "eVolve - Equalizer volume rendering example\n" ) +
41  std::string( "\tRun-time commands:\n" ) +
42  std::string( "\t\tLeft Mouse Button: Rotate model\n" ) +
43  std::string( "\t\tMiddle Mouse Button: Move model in X, Y\n" ) +
44  std::string( "\t\tRight Mouse Button: Move model in Z\n" ) +
45  std::string( "\t\t<Esc>, All Mouse Buttons: Exit program\n" ) +
46  std::string( "\t\t<Space>, r: Reset camera\n" ) +
47  std::string( "\t\td: Toggle demo color mode\n" ) +
48  std::string( "\t\tb: Toggle background color\n" ) +
49  std::string( "\t\tn: Toggle normals Quality mode (raw data only)\n" ) +
50  std::string( "\t\to: Toggle " ) +
51  std::string( "perspective/orthographic\n" ) +
52  std::string( "\t\ts: Toggle statistics " ) +
53  std::string( "overlay\n" ) +
54  std::string( "\t\tl: Switch layout for active canvas\n")+
55  std::string( "\t\tF1, h: Toggle help overlay\n" )
56  );
57 
58 const std::string& EVolve::getHelp()
59 {
60  return _help;
61 }
62 
63 EVolve::EVolve( const LocalInitData& initData )
64  : _initData( initData )
65 {}
66 
67 int EVolve::run()
68 {
69  // 1. connect to server
70  eq::ServerPtr server = new eq::Server;
71  if( !connectServer( server ))
72  {
73  LBERROR << "Can't open server" << std::endl;
74  return EXIT_FAILURE;
75  }
76 
77  // 2. choose config
78  eq::fabric::ConfigParams configParams;
79  Config* config = static_cast<Config*>(server->chooseConfig( configParams ));
80 
81  if( !config )
82  {
83  LBERROR << "No matching config on server" << std::endl;
84  disconnectServer( server );
85  return EXIT_FAILURE;
86  }
87 
88  // 3. init config
89  lunchbox::Clock clock;
90 
91  config->setInitData( _initData );
92  if( !config->init( ))
93  {
94  server->releaseConfig( config );
95  disconnectServer( server );
96  return EXIT_FAILURE;
97  }
98  else if( config->getError( ))
99  LBWARN << "Error during initialization: " << config->getError()
100  << std::endl;
101 
102  LBLOG( LOG_STATS ) << "Config init took " << clock.getTimef() << " ms"
103  << std::endl;
104 
105  // 4. run main loop
106  uint32_t maxFrames = _initData.getMaxFrames();
107 
108  clock.reset();
109  while( config->isRunning( ) && maxFrames-- )
110  {
111  config->startFrame();
112  if( config->getError( ))
113  LBWARN << "Error during frame start: " << config->getError()
114  << std::endl;
115  config->finishFrame();
116  }
117  const uint32_t frame = config->finishAllFrames();
118  const float time = clock.getTimef();
119  LBLOG( LOG_STATS ) << "Rendering took " << time << " ms (" << frame
120  << " frames @ " << ( frame / time * 1000.f) << " FPS)"
121  << std::endl;
122 
123  // 5. exit config
124  clock.reset();
125  config->exit();
126  LBLOG( LOG_STATS ) << "Exit took " << clock.getTimef() << " ms" <<std::endl;
127 
128  // 6. cleanup and exit
129  server->releaseConfig( config );
130  if( !disconnectServer( server ))
131  LBERROR << "Client::disconnectServer failed" << std::endl;
132  server = 0;
133 
134  return EXIT_SUCCESS;
135 }
136 
137 void EVolve::clientLoop()
138 {
139  do
140  {
142  LBINFO << "Configuration run successfully executed" << std::endl;
143  }
144  while( _initData.isResident( )); // execute at lease one config run
145 }
146 }
virtual uint32_t finishAllFrames()
Finish rendering all pending frames.
eq::fabric::Error getError() const
Definition: object.h:82
virtual bool init()
virtual bool exit()
Proxy object for the connection to an Equalizer server.
Definition: client/server.h:38
lunchbox::RefPtr< Server > ServerPtr
A reference-counted pointer to an eq::Server.
virtual uint32_t startFrame()
Statistic events (4096)
Definition: client/log.h:33
virtual uint32_t finishFrame()
Finish the rendering of a frame.
virtual void clientLoop()
Implements the processing loop for render clients.
Parameters for running a configuration.
bool isRunning() const