Changeset 1202


Ignore:
Timestamp:
08/13/06 01:44:15 (18 years ago)
Author:
szydlowski
Message:

improvements on demo mode, added command line parsing for easy benchmark scripting scripting,
so far only load/store demo from/to file

Files:
7 edited

Legend:

Unmodified
Added
Removed
  • GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/include/TestKdTree.h

    r1200 r1202  
    2727public: 
    2828 
    29         KdTreeApp()     { mFrameListener = 0; } 
     29        KdTreeApp()      
     30        {  
     31                mFrameListener = 0;  
     32                mRenderTargerListener = 0; 
     33        } 
     34 
     35        KdTreeApp(const String& infile, const String& outfile)   
     36        {  
     37                mFrameListener = 0;  
     38                mRenderTargerListener = 0; 
     39                mDemoInfileName = infile; 
     40                mDemoOutfileName = outfile; 
     41        } 
    3042 
    3143        ~KdTreeApp() 
     
    5668        int             mSelectEntities; 
    5769 
     70        String mDemoInfileName; 
     71        String mDemoOutfileName; 
     72 
    5873        virtual void setupResources(void); 
    5974 
     
    7186    virtual bool configure(void); 
    7287 
     88        /** load scene from file **/ 
    7389        bool loadScene(const String& filename); 
    7490        bool loadSceneIV(const String &filename, SceneNode *root, const int index); 
     91 
     92        void createMaterials(void); 
    7593private: 
    76         void createMaterials(void); 
    7794        std::string cat(std::string name, int x, int z) 
    7895        { 
  • GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/include/TestKdTreeAppListener.h

    r1200 r1202  
    4646using namespace Ogre; 
    4747 
     48struct FrameInfo 
     49{ 
     50        FrameInfo(Vector3 pos, Quaternion or, Real time): 
     51        mPosition(pos), mOrientation(or), mElapsedTime(time) 
     52        { } 
     53 
     54        Vector3 mPosition; 
     55        Quaternion mOrientation; 
     56        Real    mElapsedTime; 
     57}; 
     58 
     59typedef std::list<FrameInfo> FrameList; 
     60 
    4861class KdTreeAppListener: public FrameListener, public KeyListener 
    4962{ 
     
    110123 
    111124        // stuff for walkthrough recording/playback 
    112         struct FrameInfo 
    113         { 
    114                 FrameInfo(Vector3 pos, Quaternion or, Real time): 
    115                 mPosition(pos), mOrientation(or), mElapsedTime(time) 
    116                 { } 
    117  
    118                 Vector3 mPosition; 
    119                 Quaternion mOrientation; 
    120                 Real    mElapsedTime; 
    121         }; 
    122  
    123         typedef std::list<FrameInfo> FrameList; 
     125        String mDemoInfileName; 
     126        String mDemoOutfileName; 
    124127 
    125128        enum AppState 
     
    139142        OverlayElement * mDemoStatus; 
    140143 
     144        void setDemoOverlay(); 
     145 
    141146        void toggleRecord(); 
    142147        void togglePlayback(); 
    143 //      void resetPlayback(); 
    144148 
    145149        void saveFrameInfo(Real elapsedTime); 
    146  
    147         void setDemoOverlay(); 
    148  
    149         void saveFramesBinary(const String& filename); 
    150         void loadFramesBinary(const String& filename); 
     150         
     151        /** save demo frame data to file **/ 
     152        static void saveFrames(const String& filename, FrameList& framelist); 
     153        static void saveFramesAscii(const String& filename, FrameList& framelist); 
     154        static void saveFramesBinary(const String& filename, FrameList& framelist); 
     155 
     156        /** load demo frame data from file **/ 
     157        static void loadFrames(const String& filename, FrameList& framelist); 
     158        static void loadFramesAscii(const String& filename, FrameList& framelist); 
     159        static void loadFramesBinary(const String& filename, FrameList& framelist); 
     160 
    151161public: 
    152         void loadFrames(const String& filename); 
    153         void saveFrames(const String& filename); 
    154  
    155162        // visualization modes for scene nodes 
    156163        enum  
     
    163170 
    164171    // Constructor takes a RenderWindow because it uses that to determine input context 
    165     KdTreeAppListener(RenderWindow* win, SceneManager* sm, Real rs, Real ms, Real rp, 
     172    KdTreeAppListener(RenderWindow* win, SceneManager* sm, Real rs, Real ms, Real rp,  
     173                const String& infile, const String& outfile,  
    166174                bool useBufferedInputKeys = false, bool useBufferedInputMouse = false); 
    167175 
  • GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/scripts/TestKdTree.vcproj

    r1187 r1202  
    2222                                ImproveFloatingPointConsistency="TRUE" 
    2323                                AdditionalIncludeDirectories="..\include;&quot;$(OGRE_PATH)\Samples\Common\include&quot;;&quot;$(OGRE_PATH)\OgreMain\include&quot;;..\..\..\..\..\..\Lib\Vis\OnlineCullingCHC\IVReader\include" 
    24                                 PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;GTP_VISIBILITY_MODIFIED_OGRE;KDTREE_FASTSTART" 
     24                                PreprocessorDefinitions="WIN32;_DEBUG;_WINDOWS;GTP_VISIBILITY_MODIFIED_OGRE" 
    2525                                MinimalRebuild="TRUE" 
    2626                                BasicRuntimeChecks="3" 
     
    8585                                OptimizeForWindowsApplication="TRUE" 
    8686                                AdditionalIncludeDirectories="..\include;&quot;$(OGRE_PATH)\Samples\Common\include&quot;;&quot;$(OGRE_PATH)\OgreMain\include&quot;;..\..\..\..\..\..\Lib\Vis\OnlineCullingCHC\IVReader\include" 
    87                                 PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;GTP_VISIBILITY_MODIFIED_OGRE;KDTREE_FASTSTART" 
     87                                PreprocessorDefinitions="WIN32;NDEBUG;_WINDOWS;GTP_VISIBILITY_MODIFIED_OGRE" 
    8888                                StringPooling="TRUE" 
    8989                                MinimalRebuild="TRUE" 
  • GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/src/TestKdTree.cpp

    r1200 r1202  
    99extern "C" { 
    1010#endif 
     11 
     12void splitStrCmdLine(const char *strCmdLine, std::vector<std::string>& argv); 
     13bool getopt(const std::string& option, const std::vector<std::string>& argv, const std::string& optstring, std::string& optarg); 
    1114 
    1215#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 
     
    1619#endif 
    1720        { 
     21#if OGRE_PLATFORM == OGRE_PLATFORM_WIN32 
     22                // parse windows-style command line 
     23                std::string optarg = "i:o:", infile, outfile; 
     24                std::vector<std::string> argv; 
     25 
     26                splitStrCmdLine(strCmdLine, argv); 
     27 
     28                getopt("i", argv, optarg, infile); 
     29                getopt("o", argv, optarg, outfile); 
     30 
     31                // Create application object 
     32                KdTreeApp app(infile, outfile); 
     33#else 
     34                // TODO: unix-style getopt 
    1835                // Create application object 
    1936                KdTreeApp app; 
     37#endif 
    2038 
    2139                SET_TERM_HANDLER; 
     
    4260#endif 
    4361 
     62// split a space-separated string argument in an array of strings 
     63// sensitive to " 
     64void splitStrCmdLine(const char *strCmdLine, std::vector<std::string>& argv) 
     65{ 
     66        std::string cmdline(strCmdLine); 
     67        argv.clear(); 
     68 
     69        std::string tmp; 
     70        unsigned int strpos = 0; 
     71        bool skipspace = false; 
     72 
     73        while (strpos < cmdline.length()) 
     74        { 
     75                while (strpos < cmdline.length() && cmdline[strpos] == ' ') 
     76                        strpos++; 
     77                tmp.clear(); 
     78                while (strpos < cmdline.length() && (cmdline[strpos] != ' ' || skipspace)) 
     79                { 
     80                        if (cmdline[strpos] == '"') 
     81                        { 
     82                                ++ strpos; 
     83                                skipspace = !skipspace; 
     84                                if (!skipspace) 
     85                                        continue; 
     86                        } 
     87 
     88                        tmp += cmdline[strpos ++]; 
     89                } 
     90                argv.push_back(tmp); 
     91        } 
     92 
     93        //std::ofstream testout("test.txt"); 
     94 
     95        //testout << cmdline << "\n\n"; 
     96 
     97        //std::vector<std::string>::iterator it = argv.begin(); 
     98        //while (it != argv.end()) 
     99        //{ 
     100        //      testout << *it << "\n"; 
     101        //      ++ it; 
     102        //} 
     103 
     104        //testout.close(); 
     105} 
     106 
     107// simplified std::-based getopt (no long options) 
     108// does not provide options consecutively like POSIX getopt, it rather gives you the value of the option you ask for 
     109// or returns false if option not present or anything else went wrong 
     110bool getopt(const std::string& option, const std::vector<std::string>& argv, const std::string& optstring, std::string& optarg) 
     111{ 
     112        static enum argtypes 
     113        { 
     114                no_argument, 
     115                required_argument, 
     116                optional_argument 
     117        }; 
     118 
     119        // early terminate 
     120        if (option.empty() || argv.empty() || optstring.empty()) 
     121                return false; 
     122 
     123        // verify presence of option 
     124        size_t iopt = optstring.find(option); 
     125        if (iopt == std::string::npos) 
     126                return false; 
     127 
     128        // check if mandatory or optional argument 
     129        int arg = no_argument; 
     130        if (++ iopt < optstring.size() && optstring[iopt] == ':') 
     131                arg = required_argument; 
     132        if (++ iopt < optstring.size() && optstring[iopt] == ':') 
     133                arg = optional_argument; 
     134 
     135 
     136        // find the arguments value 
     137        size_t item = 0; 
     138        std::string optstr = "-" + option; 
     139 
     140        while (item < argv.size()) 
     141        { 
     142                if (argv[item] == optstr) 
     143                { 
     144                        switch (arg) 
     145                        { 
     146                        case no_argument: 
     147                                optarg.clear(); 
     148                                return true; 
     149                                break; 
     150                        case required_argument: 
     151                                if (++ item < argv.size() && argv[item][0] != '-') 
     152                                { 
     153                                        optarg = argv[item]; 
     154                                        return true; 
     155                                } 
     156                                else 
     157                                { 
     158                                        optarg.clear(); 
     159                                        return false; 
     160                                } 
     161                                break; 
     162                        case optional_argument: 
     163                                if (++ item < argv.size() && argv[item][0] != '-') 
     164                                { 
     165                                        optarg = argv[item]; 
     166                                        return true; 
     167                                } 
     168                                else 
     169                                { 
     170                                        optarg.clear(); 
     171                                        return true; 
     172                                } 
     173                                break; 
     174                        default: 
     175                                return false; 
     176                        } 
     177                } 
     178                ++ item; 
     179        } 
     180 
     181        return false; 
     182} 
     183 
    44184#define ENT_GRID        0x01 
    45185#define ENT_RND         0x02 
     
    94234        tmp = cfDeath.getSetting("rotatespeed"); 
    95235        mRotateSpeed = static_cast<Real>(strtod(tmp.c_str(), &errptr)); 
     236 
     237        // command line has preference over config file 
     238        if (mDemoInfileName.empty()) 
     239                mDemoInfileName = cfDeath.getSetting("demoinfile"); 
     240 
     241        if (mDemoOutfileName.empty()) 
     242                mDemoOutfileName = cfDeath.getSetting("demooutfile"); 
    96243 
    97244        ExampleApplication::setupResources(); 
     
    275422void KdTreeApp::createFrameListener(void) 
    276423{ 
    277         mFrameListener = new KdTreeAppListener(mWindow, mSceneMgr, mRotateSpeed, mMoveSpeed, mRotationPeriod); 
     424        mFrameListener = new KdTreeAppListener(mWindow, mSceneMgr, mRotateSpeed, mMoveSpeed, mRotationPeriod, mDemoInfileName, mDemoOutfileName); 
    278425        mFrameListener->showDebugOverlay( true ); 
    279426        mRoot->addFrameListener(mFrameListener); 
  • GTP/trunk/App/Demos/Vis/KdTreeDemo/OGRE/src/TestKdTreeAppListener.cpp

    r1200 r1202  
    7171// Constructor takes a RenderWindow because it uses that to determine input context 
    7272KdTreeAppListener::KdTreeAppListener(RenderWindow* win, SceneManager* sm, Real rs, Real ms, Real rp, 
    73         bool useBufferedInputKeys, bool useBufferedInputMouse) 
     73                                                                         const String& infile, const String& outfile, 
     74                                                                         bool useBufferedInputKeys, bool useBufferedInputMouse) 
    7475{ 
    7576        mDebugOverlay = OverlayManager::getSingleton().getByName("Core/DebugOverlay"); 
     
    102103        mVizCamTransVect = Vector3::ZERO; 
    103104        mSeqNum = 0; 
     105 
     106        mDemoInfileName = infile; 
     107        mDemoOutfileName = outfile; 
    104108 
    105109        mAppState = AS_NORMAL; 
     
    140144        setDemoOverlay(); 
    141145 
    142         //loadFrames("demo-in.txt"); 
    143         loadFramesBinary("demo-in.bin"); 
     146        if (!mDemoInfileName.empty()) 
     147                loadFrames(mDemoInfileName, mFrameList); 
    144148} 
    145149//----------------------------------------------------------------------- 
     
    153157        { 
    154158                PlatformManager::getSingleton().destroyInputReader( mInputDevice ); 
    155         } 
    156  
    157         // save demo 
    158         if (!mFrameList.empty()) 
    159         { 
    160                 //saveFrames("demo-out.txt"); 
    161                 saveFramesBinary("demo-out.bin"); 
    162159        } 
    163160} 
     
    346343        { 
    347344                toggleRecord(); 
     345                mTimeUntilNextToggle = 0.5; 
     346        } 
     347 
     348        if (mInputDevice->isKeyDown(KC_F6) && mTimeUntilNextToggle <= 0) 
     349        { 
     350                if (!mDemoOutfileName.empty() && !mFrameList.empty()) 
     351                        saveFrames(mDemoOutfileName, mFrameList); 
    348352                mTimeUntilNextToggle = 0.5; 
    349353        } 
     
    11461150} 
    11471151 
     1152 
    11481153//----------------------------------------------------------------------------- 
    1149 //void KdTreeAppListener::resetPlayback() 
    1150 //{ 
    1151 //      if (!mFrameList.empty()) 
    1152 //      { 
    1153 //              mCurrFrame = mFrameList.begin(); 
    1154 //              mTimeRemaining = mCurrFrame->mElapsedTime; 
    1155 //      } 
    1156 //} 
     1154void KdTreeAppListener::saveFrames(const String& filename, FrameList& framelist) 
     1155{ 
     1156        size_t dot = filename.find_last_of("."); 
     1157        String ext = filename.substr(dot + 1, filename.length()); 
     1158        if (ext == "txt") 
     1159                saveFramesAscii(filename, framelist); 
     1160        else if (ext == "bin") 
     1161                saveFramesBinary(filename, framelist); 
     1162        else 
     1163                OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Invalid extension for demo file: " + ext, "KdTreeApp::loadFrames"); 
     1164} 
    11571165 
    11581166//----------------------------------------------------------------------------- 
    1159 void KdTreeAppListener::saveFrameInfo(Real elapsedTime) 
    1160 { 
    1161         mFrameList.push_back(FrameInfo(mCamNode->getPosition(), mCamNode->getOrientation(), elapsedTime)); 
    1162 } 
    1163  
    1164 //----------------------------------------------------------------------------- 
    1165 void KdTreeAppListener::saveFrames(const String& filename) 
     1167void KdTreeAppListener::saveFramesAscii(const String& filename, FrameList& framelist) 
    11661168{ 
    11671169        // open file 
     
    11731175        } 
    11741176 
    1175         FrameList::iterator it = mFrameList.begin(); 
    1176         FrameList::iterator end = mFrameList.end(); 
     1177        FrameList::iterator it = framelist.begin(); 
     1178        FrameList::iterator end = framelist.end(); 
    11771179 
    11781180        // dump values 
     
    11901192 
    11911193//----------------------------------------------------------------------------- 
    1192 void KdTreeAppListener::saveFramesBinary(const String& filename) 
     1194void KdTreeAppListener::saveFramesBinary(const String& filename, FrameList& framelist) 
    11931195{ 
    11941196        std::ofstream dest(filename.c_str(), std::ios_base::out | std::ios_base::binary); 
     
    12001202        } 
    12011203 
    1202         FrameList::iterator it = mFrameList.begin(); 
    1203         FrameList::iterator end = mFrameList.end(); 
    1204  
    1205         size_t size = sizeof(Real); 
     1204        FrameList::iterator it = framelist.begin(); 
     1205        FrameList::iterator end = framelist.end(); 
     1206 
     1207        int size = sizeof(Real); 
    12061208 
    12071209        // dump values 
     
    12231225 
    12241226//----------------------------------------------------------------------------- 
    1225 void KdTreeAppListener::loadFrames(const String& filename) 
     1227void KdTreeAppListener::loadFrames(const String& filename, FrameList& framelist) 
     1228{ 
     1229        size_t dot = filename.find_last_of("."); 
     1230        String ext = filename.substr(dot + 1, filename.length()); 
     1231        if (ext == "txt") 
     1232                loadFramesAscii(filename, framelist); 
     1233        else if (ext == "bin") 
     1234                loadFramesBinary(filename, framelist); 
     1235        else 
     1236                OGRE_EXCEPT(Exception::ERR_INVALIDPARAMS, "Invalid extension for demo file: " + ext, "KdTreeApp::loadFrames"); 
     1237} 
     1238 
     1239//----------------------------------------------------------------------------- 
     1240void KdTreeAppListener::loadFramesAscii(const String& filename, FrameList& framelist) 
    12261241{ 
    12271242        // open file 
     
    12341249 
    12351250        // clear the list 
    1236         mFrameList.clear(); 
     1251        framelist.clear(); 
    12371252 
    12381253        Vector3 pos; 
     
    12531268                src >> time; 
    12541269 
    1255                 mFrameList.push_back(FrameInfo(pos, or, time)); 
     1270                framelist.push_back(FrameInfo(pos, or, time)); 
    12561271        } 
    12571272 
    12581273        // HACK pop last frame, was doubled while reading 
    1259         mFrameList.pop_back(); 
     1274        framelist.pop_back(); 
    12601275 
    12611276        src.close(); 
     
    12631278 
    12641279//----------------------------------------------------------------------------- 
    1265 void KdTreeAppListener::loadFramesBinary(const String& filename) 
     1280void KdTreeAppListener::loadFramesBinary(const String& filename, FrameList& framelist) 
    12661281{ 
    12671282        // open file 
     
    12741289 
    12751290        // clear the list 
    1276         mFrameList.clear(); 
    1277  
    1278         size_t size = sizeof(Real); 
     1291        framelist.clear(); 
     1292 
     1293        int size = sizeof(Real); 
    12791294 
    12801295        Vector3 pos; 
     
    12931308                src.read((char *)&time, size); 
    12941309 
    1295                 mFrameList.push_back(FrameInfo(pos, or, time)); 
     1310                framelist.push_back(FrameInfo(pos, or, time)); 
    12961311        } 
    12971312 
    12981313        // HACK pop last frame, was doubled while reading 
    1299         mFrameList.pop_back(); 
     1314        framelist.pop_back(); 
    13001315 
    13011316        src.close(); 
    13021317} 
     1318 
     1319//----------------------------------------------------------------------------- 
     1320void KdTreeAppListener::saveFrameInfo(Real elapsedTime) 
     1321{ 
     1322        mFrameList.push_back(FrameInfo(mCamNode->getPosition(), mCamNode->getOrientation(), elapsedTime)); 
     1323} 
     1324 
    13031325//----------------------------------------------------------------------------- 
    13041326void KdTreeAppListener::setDemoOverlay() 
Note: See TracChangeset for help on using the changeset viewer.