Main Page   Class Hierarchy   Alphabetical List   Compound List   File List   Compound Members   File Members  

panda/src/chancfg/chansetup.cxx

Go to the documentation of this file.
00001 // Filename: chansetup.cxx
00002 // Created by:  cary (05Feb99)
00003 //
00004 ////////////////////////////////////////////////////////////////////
00005 //
00006 // PANDA 3D SOFTWARE
00007 // Copyright (c) 2001, Disney Enterprises, Inc.  All rights reserved
00008 //
00009 // All use of this software is subject to the terms of the Panda 3d
00010 // Software license.  You should have received a copy of this license
00011 // along with this source code; you will also find a current copy of
00012 // the license at http://www.panda3d.org/license.txt .
00013 //
00014 // To contact the maintainers of this program write to
00015 // panda3d@yahoogroups.com .
00016 //
00017 ////////////////////////////////////////////////////////////////////
00018 
00019 #include "chansetup.h"
00020 #include "chanparse.h"
00021 #include "chanshare.h"
00022 #include <notify.h>
00023 
00024 SetupType* SetupDB = (SetupType*)0;
00025 
00026 class SetupParseFunctor : public ChanParseFunctor {
00027 public:
00028   INLINE SetupParseFunctor(void) : ChanParseFunctor() {}
00029   virtual ~SetupParseFunctor(void);
00030 
00031   virtual void operator()(std::string);
00032 };
00033 
00034 SetupParseFunctor::~SetupParseFunctor(void) {
00035   return;
00036 }
00037 
00038 void SetupParseFunctor::operator()(std::string S) {
00039   std::string sym;
00040 
00041   ChanEatFrontWhite(S);
00042   sym = ChanReadNextWord(S);
00043   ChanCheckScoping(S);
00044   ChanDescope(S);
00045 
00046   SetupItem s;
00047 
00048   bool stereo = ChanReadNextBool(S);
00049   //KEH
00050   //bool hw_chan = ChanReadNextBool(S);
00051   //int chan_num = ChanReadNextIntB(S);
00052 
00053   ChanCheckScoping(S);
00054   int i = S.find_first_of(")");
00055   std::string stmp = S.substr(1, i-2);
00056   S.erase(0, i+1);
00057   ChanEatFrontWhite(S);
00058   ChanViewport v(ChanReadNextFloat(stmp), ChanReadNextFloat(stmp),
00059          ChanReadNextFloat(stmp), ChanReadNextFloat(stmp));
00060   if (!stmp.empty()) {
00061     // error, there shouldn't be anything left after eating the viewport
00062     nout << "error, tailing text in viewport spec '" << stmp << "'" << endl;
00063     stmp.erase(0, std::string::npos);
00064   }
00065   SetupFOV fov;
00066   if (S[0] == '#') {
00067     bool b = ChanReadNextBool(S);
00068     if (b) {
00069         // error, #t is not allowed here
00070         nout << "error, cannot have #t for FOV spec" << endl;
00071         b = false;
00072     }
00073     fov.setFOV();
00074   } else if (S[0] == '(') {
00075     i = S.find_first_of(")");
00076     stmp = S.substr(1, i-2);
00077     S.erase(0, i+1);
00078     ChanEatFrontWhite(S);
00079     fov.setFOV(ChanReadNextFloat(stmp), ChanReadNextFloat(stmp));
00080     if (!stmp.empty()) {
00081         // error, there shouldn't be anything left after eating the fov
00082         nout << "error, trailing text after fov spec '" << stmp << "'" << endl;
00083         stmp.erase(0, std::string::npos);
00084     }
00085   } else {
00086     fov.setFOV(ChanReadNextFloat(S));
00087   }
00088   SetupItem::Orientation orie = SetupItem::Up;
00089   if (!S.empty()) {
00090     stmp = ChanReadNextWord(S);
00091     if (stmp == "up") {
00092       // nothing really to do
00093       orie = SetupItem::Up;
00094     } else if (stmp == "down") {
00095       orie = SetupItem::Down;
00096     } else if (stmp == "left") {
00097       orie = SetupItem::Left;
00098     } else if (stmp == "right") {
00099       orie = SetupItem::Right;
00100     } else {
00101       // error, not a recognized orientation
00102       nout << "error, invalid orientation '" << stmp << "'" << endl;
00103       stmp.erase(0, std::string::npos);
00104     }
00105   }
00106   if (!S.empty()) {
00107     // error, we should have consumed all the data by now
00108     nout << "error, trailing text on setup spec '" << S << "'" << endl;
00109     S.erase(0, std::string::npos);
00110   }
00111   //KEH
00112   //s.setState(stereo, hw_chan, chan_num, v, fov, orie);
00113   s.setState(stereo, false, -1, v, fov, orie);
00114 
00115   if (chancfg_cat.is_debug()) {
00116     chancfg_cat->debug() << "parsed a setup called '" << sym << "':" << endl;
00117     chancfg_cat->debug() << "  is" << (s.getStereo()?" ":" not ")
00118              << "a stereo setup" << endl;
00119     chancfg_cat->debug() <<"   is" << (s.getHWChan()?" ":" not ")
00120              << "a HW channel setup" << endl;
00121     chancfg_cat->debug() << "  prefered HW channel number: " << s.getChan()
00122              << endl;
00123     ChanViewport qv(s.getViewport());
00124     chancfg_cat->debug() << "  sub viewport: (" << qv.left() << ", "
00125              << qv.right() << ", " << qv.bottom() << ", "
00126              << qv.top() << ")" << endl;
00127     SetupFOV qf(s.getFOV());
00128     switch (qf.getType()) {
00129       case SetupFOV::Invalid:
00130         chancfg_cat->debug() << "  FOV is invalid" << endl;
00131         break;
00132       case SetupFOV::Default:
00133         chancfg_cat->debug() << "  FOV takes defaults" << endl;
00134         break;
00135       case SetupFOV::Horizontal:
00136         chancfg_cat->debug() << "  FOV specifies only horizontal: "
00137                      << qf.getHoriz() << endl;
00138         break;
00139       case SetupFOV::Both:
00140         chancfg_cat->debug() << "  FOV: " << qf.getHoriz() << " x "
00141                      << qf.getVert() << endl;
00142         break;
00143       default:
00144         chancfg_cat->debug() << "  FOV is of an unknown type (" << (int)qf.getType()
00145                  << ")" << endl;
00146     }
00147     switch (s.getOrientation()) {
00148       case SetupItem::Up:
00149         chancfg_cat->debug() << "  setup is oriented Up" << endl;
00150         break;
00151       case SetupItem::Down:
00152         chancfg_cat->debug() << "  setup is oriented Down" << endl;
00153         break;
00154       case SetupItem::Left:
00155         chancfg_cat->debug() << "  setup is oriented Left" << endl;
00156         break;
00157       case SetupItem::Right:
00158         chancfg_cat->debug() << "  setup is oriented Right" << endl;
00159         break;
00160       default:
00161         chancfg_cat->debug() << "  setup has an unknown orientation ("
00162                     << (int)s.getOrientation() << ")" << endl;
00163     }
00164   }
00165   (*SetupDB)[sym] = s;
00166 }
00167 
00168 
00169 void ResetSetup() {
00170   if (SetupDB != (SetupType *)NULL) {
00171     delete SetupDB;
00172   }
00173   SetupDB = new SetupType;
00174 }
00175 
00176 void ParseSetup(istream& is) {
00177   SetupParseFunctor s;
00178   ChanParse(is, &s);
00179 }

Generated on Fri May 2 00:35:19 2003 for Panda by doxygen1.3