source: GTP/trunk/App/Demos/Vis/HillyTerrain/OGRE/TerrainFrameListener.h @ 723

Revision 723, 12.0 KB checked in by mattausch, 18 years ago (diff)

found slowdown

RevLine 
[133]1#ifndef _TerrainFrameListener_H__
2#define _TerrainFrameListener_H__
[115]3
4#include "CEGUIForwardRefs.h"
5#include <Ogre.h>
6#include <OgreKeyEvent.h>
7#include <OgreEventListeners.h>
8#include <OgreStringConverter.h>
9#include <OgreException.h>
10#include "VisibilityEnvironment.h"
[130]11#include "VisibilityManager.h"
[115]12#include "OgreTerrainContentGenerator.h"
[151]13#include "OgrePlatformQueryManager.h"
[115]14
[173]15
[160]16class TestCullingTerrainApplication;
17
18
[115]19using namespace Ogre;
20
[259]21/** Struct storing walktrough statistics
22*/
23struct WalkthroughStats
24{
25public:
[115]26
[259]27        unsigned long mAccFps;
28        unsigned long mBestFps;
29        unsigned long mWorstFps;
30        unsigned long mAccTris;
31        unsigned long mAccQueryCulledNodes;
32        unsigned long mAccFrustumCulledNodes;
33        unsigned long mFrameCount;
34        unsigned long mAccRenderedNodes;
35       
36        WalkthroughStats():
37        mAccFps(0), mBestFps(0), mWorstFps(0), mAccTris(0),
38        mAccQueryCulledNodes(0), mAccFrustumCulledNodes(0),
39        mFrameCount(0), mAccRenderedNodes(0)
40        {}
[254]41
[259]42        void Reset()
43        {
44                mAccFps = mBestFps = mWorstFps = mAccTris = mAccQueryCulledNodes = mAccFrustumCulledNodes = mFrameCount = mAccRenderedNodes = 0;
45        }
46
47        void UpdateFrame(int currentFps, int bestFps, int worstFps, int renderedTris, int renderedNodes, int queryCulledNodes, int frustumCulledNodes)
48        {
49                mAccFps += currentFps;
50                mBestFps = bestFps;
51                mWorstFps = worstFps;
52
53                // accumulated #triangles (M)
54                mAccTris += renderedTris / 1000;
55                mAccRenderedNodes += renderedNodes;
56                mAccQueryCulledNodes += queryCulledNodes;
57                mAccFrustumCulledNodes += frustumCulledNodes;
58       
59                ++ mFrameCount;
60        }
61
62        void Print(std::ostream &d, const std::string &algorithmName) const
63        {
64                // compuate average fps and triangle count
65                float avgFps = (float)mAccFps / (float)mFrameCount;
66                float avgTris = (float)mAccTris / (float)mFrameCount;
67                float avgFrustumCulledNodes = 0;
68                float avgRenderedNodes = 0;
69                float avgQueryCulledNodes = 0;
70               
71                if (mFrameCount != 0)
72                {
73                        avgFrustumCulledNodes = (float)mAccFrustumCulledNodes / (float)mFrameCount;
74                        avgQueryCulledNodes  = (float)mAccQueryCulledNodes / (float)mFrameCount;
75                        avgRenderedNodes = (float)mAccRenderedNodes / (float) mFrameCount;
76                }
77
78                //-- write out stats for recorded walkthrough
79                d << "Algorithm: " << algorithmName << "\n"
80                        << "avg. FPS: " << avgFps << "\n"
81                        << "best FPS: " << mBestFps << "\n"
82                        << "worst FPS: " << mWorstFps << "\n"
[723]83                        << "#frames: " << mFrameCount << "\n"
[259]84                        << "avg. #triangles: " << avgTris << " M\n"
85                        << "avg. #query culled nodes: " << avgFrustumCulledNodes << "\n"
86                        << "avg. #frustum culled nodes: " << avgQueryCulledNodes << "\n"
87                        << "avg. #rendered nodes: " << avgRenderedNodes << "\n";
88        }
89
90};
91
[161]92/** Frame listener specialised for terrains.
[115]93*/
[161]94class TerrainFrameListener: public FrameListener, public MouseListener,
95                                                        public MouseMotionListener, public KeyListener
[115]96{
97public:
98       
[160]99   TerrainFrameListener(RenderWindow* win,
100                                                Camera* cam,
101                                                SceneManager *sceneManager,
102                                                CEGUI::Renderer *renderer,
103                                                TerrainContentGenerator *contentGenerator,
104                                                Camera *vizCamera,
105                                                SceneNode *camNode,
106                                                Light *sunLight,
107                                                TestCullingTerrainApplication *app);
[115]108
[133]109   ~TerrainFrameListener();
[115]110
111   bool frameStarted(const FrameEvent& evt);
112   bool frameEnded(const FrameEvent& evt);
[417]113     
[115]114
115   /* MouseListener callbacks. */
116   virtual void mouseClicked(MouseEvent* e) { }
117   virtual void mouseEntered(MouseEvent* e) { }
118   virtual void mouseExited(MouseEvent* e)  { }
119
120   // This is when the mouse button goes DOWN.
[161]121   void mousePressed(MouseEvent* e);
[115]122
123   // This is when the mouse button is let UP.
[161]124   void mouseReleased(MouseEvent* e);
[115]125
126   /* MouseMotionListener callbacks */
[161]127   void mouseMoved(MouseEvent *e);
[115]128   
129   // This is when the mouse is clicked, held and dragged.
[161]130   void mouseDragged(MouseEvent *e);
[115]131
[161]132   void mouseDragDropped(MouseEvent *e);
[115]133   void keyPressed(KeyEvent* e);
134
135   void keyReleased(KeyEvent* e);
136   void keyClicked(KeyEvent* e);
137 
[161]138   /** The information about camera position and orienation per frame.
139   */
[115]140   typedef struct
141   {
142           Vector3 position;
143           Quaternion orientation;
144           Real timeElapsed;
[254]145           Real fps;
[115]146   } frame_info;
147
[254]148   typedef std::vector<frame_info> FrameInfoContainer;
149
[115]150   enum  {WALKTHROUGH, REPLAY, STATE_NUM};
151
152   // visualization modes for scene nodes
[723]153   enum {
154                 NODEVIZ_NONE,
155                 NODEVIZ_RENDER_NODES,
156                 NODEVIZ_RENDER_NODES_AND_CONTENT,
157                 NODEVIZ_MODES_NUM};
158
[115]159   //enum {NODEVIZ_NONE, NODEVIZ_RENDER_GEOMETRY, NODEVIZ_MODES_NUM};
160
[173]161   void zoomVizCamera(int zoom);
[115]162       
[254]163   void addFrameInfo(FrameInfoContainer &frameInfos, SceneNode *camNode, Real timeElapsed);
[115]164   void setCurrentFrameInfo(Real timeElapsed);
165
166   void setAlgorithm(int algorithm);
167
168   void moveCamera();
169
[723]170   void writeFrames(const std::string filename, const FrameInfoContainer &frameInfo) const;
171   void loadFrames(const std::string filename, FrameInfoContainer &frameInfo);
[115]172
173    bool processUnbufferedKeyInput(const FrameEvent& evt);
174    bool processUnbufferedMouseInput(const FrameEvent& evt);
175
[723]176        void switchMouseMode();
177       
[254]178        /** Shows the frame / algorithm statistics.
179        */
[120]180    void showStats(bool show);
[115]181
[254]182        /** Updates frame statistics and the frame statistics display.
183        */
[120]184        void updateStats();
185
[254]186        /** Toggles wether help screen is shown or not.
187        */
[120]188        void toggleShowHelp();
[254]189       
190        /** Toggles wether shadows are shown or not.
191        */
[139]192        void toggleShowShadows();
[120]193        void toggleDisplayCameraDetails();
[254]194        /** Takes screenshot of the current scene.
195        */
[164]196        void takeScreenshot();
[254]197        /** Takes one video frame.
198        */
199        void takeVideoFrame(std::ofstream &ofstr);
200
[120]201        void nextSceneDetailLevel();
202        void nextFilter();
203        void nextAlgorithm();
204        void nextNodeVizMode();
205        void nextAppState();
206    void changeThreshold(int incr);
[146]207        void changeAssumedVisibility(int incr);
[723]208        void changeVizScale(const int incr);
[187]209        void setTestGeometryForVisibleLeaves(bool testGeometryForVisibleLeaves);
[254]210        /** Shows octree hierarchy of the scene.
211        */
[120]212        void toggleShowOctree();
[254]213        /** Toggles wether we use the initial depth pass.
214        */
[120]215        void toggleUseDepthPass();
[343]216        /** Toggles wether we use ARB or NV queries.
217        */
218        void toggleUseArbQueries();
[254]219        /** Toggles wether the visualization is shown.
220        */
[120]221        void toggleShowViz();
[254]222        /** Toggles wether the frames are recorded.
223        */
[120]224        void toggleRecord();
225
[133]226        /** Applies visibility query. Collects the visible objects
227                and their visibility information.
[154]228                @param fromPoint if query should be from point or from camera
229                @param relativeVisibility if query should return number of visible pixels or
230                the ratio visible / projected pixels.
231                @param useItemBuffer if item buffer should be used or occlusion queries
[133]232        */
[160]233        void applyVisibilityQuery(bool fromPoint, bool relativeVisibility, bool useItemBuffer);
[130]234
[254]235        /** Shows result from visibility queries.
236        */
[135]237        void toggleShowQueryStats();
238
[160]239        /** Sets the type of the objects generated in the scene.
240        */
241        void setObjectType(int objectType);
242
[173]243        static String msAlgorithmCaptions[];
[723]244        static String msApprevAlgorithmCaptions[];
[173]245        static String msQueryTypeCaptions[];
246        static String msQueryRelativeVisCaptions[];
247        static String msQueryMethodCaptions[];
248        static Real msObjectTerrainOffsets[];
249        static Real msObjectScales[];
250        static String msObjectCaptions[];
251
[115]252protected:
253
[160]254        void initHelpOverlayElement(String name, int top);
[173]255        void initOverlayElement(OverlayElement **elInfo, String ext, String name,
256                                                        int top, String caption);
[160]257
258        //-- initialise overlays
259        void initHelpOverlay();
260        void initVisStatsOverlay();
261        void initQueryOverlay();
[115]262       
[120]263        SceneManager *mSceneMgr;           // A pointer to the scene manager
[115]264   
265        CEGUI::Renderer *mGUIRenderer;     // cegui renderer
266       
267        int mCurrentAlgorithm;
268        int mVisibilityThreshold;
[146]269        int mAssumedVisibility;
[254]270        /// the current frame number
[120]271        int mCurrentFrame;
[254]272        /// the current application state
[120]273        int mAppState;
[254]274        /// The number of objects on the screen
[120]275        int mObjectCount;           
[254]276        /// visualization mode
[120]277        int mNodeVizMode;
[254]278        /// number of video frames
279        int mNumVideoFrames;
280        /// the newly created object
281        SceneNode *mCurrentObject;   
[259]282
283        WalkthroughStats mWalkthroughStats;
284
[723]285        /// visualization scale
286        float mVizScale;
[259]287
[723]288        ////////////////////////////////////////////////////////////////////////
289
290        /** HACK for recording demo:
291                1) the walkthrough must be recorded.
292                2) the walktrough must be replayed using the different options, e.g., CHC
293                   with the mSavePrecomputedFps option. This saves the frame rates
294                   for the different methods.
295            3) the walkthrough must then be replayed with the mRecordDemo options turned on.
296                   for the video recording we are using FRAPS.
297        */
298
299        /// the currently interpolated FPS
300        float mPrecomputedFps;
301        /// saves the precomputed fps for the different methods.
302        bool mSavePrecomputedFps;
303        /// displayes the precomputed fps
304        bool mRecordDemo;
305       
306        ////////////////////////////////////////////////////////////////////////////
307
308
[115]309        OverlayElement *mAlgorithmInfo;
310        OverlayElement *mThresholdInfo;
[146]311        OverlayElement *mAssumedVisibilityInfo;
[115]312        OverlayElement *mFrustumCulledNodesInfo;
313        OverlayElement *mQueryCulledNodesInfo;
314    OverlayElement *mTraversedNodesInfo;
315        OverlayElement *mHierarchyNodesInfo;
[155]316        OverlayElement *mTestGeometryForVisibleLeavesInfo;
[115]317        OverlayElement *mUseDepthPassInfo;
[343]318        OverlayElement *mUseArbQueriesInfo;
[115]319        OverlayElement *mRenderedNodesInfo;
[160]320        OverlayElement *mObjectsCountInfo;
[115]321        OverlayElement *mQueriesIssuedInfo;
[155]322        OverlayElement *mDelayedQueriesIssuedInfo;
323        OverlayElement *mDelayedTraversedNodesInfo;
[160]324        OverlayElement *mCurrentObjectTypeInfo;
[115]325
[723]326        OverlayElement *mMyStatsAlgorithmInfo;
327        OverlayElement *mMyStatsFpsInfo;
328
[135]329        OverlayElement *mQueryTypeInfo;
330        OverlayElement *mQueryVisibleNodesInfo;
[159]331        OverlayElement *mQueryVisibleGeometryInfo;
332        OverlayElement *mQueryVisiblePatchInfo;
333
[135]334        OverlayElement *mQueryVisiblityInfo;
335        OverlayElement *mQueryNodeVisibilityInfo;
336        OverlayElement *mQueryGeometryVisibilityInfo;
[159]337        OverlayElement *mQueryPatchVisibilityInfo;
[161]338        //OverlayElement *mHelpInfo;
[135]339
[115]340        RayQueryExecutor *mRayQueryExecutor;
341        TerrainContentGenerator *mTerrainContentGenerator;
342
[155]343        bool mTestGeometryForVisibleLeaves;
[115]344        bool mShowOctree;
345        bool mUseDepthPass;
[343]346        bool mUseArbQueries;
[115]347        bool mShowVisualization;
348        bool mCullCamera;
[254]349        bool mRecordFrames;
[139]350        bool mShowShadows;
[120]351        bool mVisualizeCulledNodes;
352        bool mShowHelp;
353        bool mStatsOn;
[723]354        bool mLMouseDown;
355        bool mRMouseDown;     // True if the mouse buttons are down
[120]356        bool mShutdownRequested;
357        bool mDisplayCameraDetails;
[159]358        bool mUseItemBuffer;
[161]359        bool mUseAnimation;
[174]360       
361        int mItemBufferMode;
[159]362
[115]363        Real mVizCameraHeight;
364
365        Camera *mVizCamera;
366        SceneNode *mCamNode;
367       
[254]368        /// Per frame data stored for a walkthrough
369        FrameInfoContainer mFrameInfo;
[723]370        /// HACK for demo
371        FrameInfoContainer mPrecomputedFpsFrameInfo;
[254]372       
[160]373        Real mReplayTimeElapsed;
[115]374        //EventProcessor* mEventProcessor;
375    InputReader* mInputDevice;
376    Camera* mCamera;
377
378    Vector3 mTranslateVector;
379    RenderWindow* mWindow;
[120]380   
[115]381        unsigned int mNumScreenShots;
[120]382    int mSceneDetailIndex;
383        int mAniso;
384
385        float mMoveScale;
[115]386    Degree mRotScale;
[164]387
[115]388    // just to stop toggles flipping too fast
[120]389    Real mTimeDelay;
[115]390    Radian mRotX, mRotY;
391    TextureFilterOptions mFiltering;
[120]392 
393        Real mMoveSpeed;
[115]394    Degree mRotateSpeed;
[120]395   
396        Overlay* mDebugOverlay;
397        Overlay* mHelpOverlay;
398        Overlay* mCullStatsOverlay;
[135]399        Overlay* mQueryOverlay;
[723]400        Overlay* mMyStatsOverlay;
[121]401
402        Light *mSunLight;
[130]403        GtpVisibility::VisibilityManager *mVisibilityManager;
404        EventProcessor* mEventProcessor;
405       
[133]406        bool mShiftPressed;
[135]407        bool mShowQueryStats;
[259]408       
[133]409        //bool mUseBufferedInputKeys, mUseBufferedInputMouse, mInputTypeSwitchingOn;
[151]410        PlatformQueryManager *mQueryManager;
[155]411
412        float mDelayedQueriesIssued;
413        float mDelayedTraversedNodes;
[159]414
[160]415        int mCurrentObjectType;
416
[164]417        bool mDeleteObjects;
[254]418        bool mRecordVideo;
[164]419
[254]420        Timer *mTimer;
421        long mTimeFrameEnded;
422        long mTimeFrameStarted;
423        float mPureRenderTimeFps;
[160]424        TestCullingTerrainApplication *mApplication;
[417]425
426        bool mUseBufferedInputMouse;
[421]427        Matrix4 rotMatrix;
[115]428};
429
430
[133]431#endif //_TerrainFrameListener_H__
Note: See TracBrowser for help on using the repository browser.