Equalizer 1.0

eVolve.cpp

00001 
00002 /* Copyright (c) 2005-2010, Stefan Eilemann <eile@equalizergraphics.com> 
00003  *
00004  * Redistribution and use in source and binary forms, with or without
00005  * modification, are permitted provided that the following conditions are met:
00006  *
00007  * - Redistributions of source code must retain the above copyright notice, this
00008  *   list of conditions and the following disclaimer.
00009  * - Redistributions in binary form must reproduce the above copyright notice,
00010  *   this list of conditions and the following disclaimer in the documentation
00011  *   and/or other materials provided with the distribution.
00012  * - Neither the name of Eyescale Software GmbH nor the names of its
00013  *   contributors may be used to endorse or promote products derived from this
00014  *   software without specific prior written permission.
00015  *
00016  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00017  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00018  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00019  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
00020  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
00021  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
00022  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
00023  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
00024  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
00025  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
00026  * POSSIBILITY OF SUCH DAMAGE.
00027  */
00028 
00029 #include "eVolve.h"
00030 
00031 #include "config.h"
00032 #include "localInitData.h"
00033 
00034 #include <stdlib.h>
00035 
00036 namespace eVolve
00037 {
00038 
00039 static const std::string _help(
00040     std::string( "eVolve - Equalizer volume rendering example\n" ) +
00041     std::string( "\tRun-time commands:\n" ) +
00042     std::string( "\t\tLeft Mouse Button:         Rotate model\n" ) +
00043     std::string( "\t\tMiddle Mouse Button:       Move model in X, Y\n" ) +
00044     std::string( "\t\tRight Mouse Button:        Move model in Z\n" ) +
00045     std::string( "\t\t<Esc>, All Mouse Buttons:  Exit program\n" ) +
00046     std::string( "\t\t<Space>, r:                Reset camera\n" ) +
00047     std::string( "\t\to:                         Toggle " ) +
00048     std::string( "perspective/orthographic\n" ) +
00049     std::string( "\t\ts:                         Toggle statistics " ) +
00050     std::string( "overlay\n" ) +
00051     std::string( "\t\tl:                         Switch layout for active canvas\n")+
00052     std::string( "\t\tF1, h:                     Toggle help overlay\n" )
00053  );
00054 
00055 const std::string& EVolve::getHelp()
00056 {
00057     return _help;
00058 }
00059 
00060 EVolve::EVolve( const LocalInitData& initData )
00061         : _initData( initData )
00062 {}
00063 
00064 int EVolve::run()
00065 {
00066     // 1. connect to server
00067     eq::ServerPtr server = new eq::Server;
00068     if( !connectServer( server ))
00069     {
00070         EQERROR << "Can't open server" << std::endl;
00071         return EXIT_FAILURE;
00072     }
00073 
00074     // 2. choose config
00075     eq::ConfigParams configParams;
00076     Config* config = static_cast<Config*>(server->chooseConfig( configParams ));
00077 
00078     if( !config )
00079     {
00080         EQERROR << "No matching config on server" << std::endl;
00081         disconnectServer( server );
00082         return EXIT_FAILURE;
00083     }
00084 
00085     // 3. init config
00086     co::base::Clock clock;
00087 
00088     config->setInitData( _initData );
00089     if( !config->init( ))
00090     {
00091         server->releaseConfig( config );
00092         disconnectServer( server );
00093         return EXIT_FAILURE;
00094     }
00095     else if( config->getError( ))
00096         EQWARN << "Error during initialization: " << config->getError()
00097                << std::endl;
00098 
00099     EQLOG( LOG_STATS ) << "Config init took " << clock.getTimef() << " ms"
00100                        << std::endl;
00101 
00102     // 4. run main loop
00103     uint32_t maxFrames = _initData.getMaxFrames();
00104     
00105     clock.reset();
00106     while( config->isRunning( ) && maxFrames-- )
00107     {
00108         config->startFrame();
00109         if( config->getError( ))
00110             EQWARN << "Error during frame start: " << config->getError()
00111                    << std::endl;
00112         config->finishFrame();
00113     }
00114     const uint32_t frame = config->finishAllFrames();
00115     const float    time  = clock.getTimef();
00116     EQLOG( LOG_STATS ) << "Rendering took " << time << " ms (" << frame
00117                        << " frames @ " << ( frame / time * 1000.f) << " FPS)"
00118                        << std::endl;
00119 
00120     // 5. exit config
00121     clock.reset();
00122     config->exit();
00123     EQLOG( LOG_STATS ) << "Exit took " << clock.getTimef() << " ms" <<std::endl;
00124 
00125     // 6. cleanup and exit
00126     server->releaseConfig( config );
00127     if( !disconnectServer( server ))
00128         EQERROR << "Client::disconnectServer failed" << std::endl;
00129     server = 0;
00130 
00131     return EXIT_SUCCESS;
00132 }
00133 
00134 void EVolve::clientLoop()
00135 {
00136     do
00137     {
00138          eq::Client::clientLoop();
00139          EQINFO << "Configuration run successfully executed" << std::endl;
00140     }
00141     while( _initData.isResident( )); // execute at lease one config run
00142 }
00143 }
Generated on Sun May 8 2011 19:11:05 for Equalizer 1.0 by  doxygen 1.7.3