~ubuntu-branches/debian/sid/ember/sid

« back to all changes in this revision

Viewing changes to src/components/ogre/SceneManagers/EmberPagingSceneManager/include/OgrePagingLandScapePageManager.h

  • Committer: Bazaar Package Importer
  • Author(s): Michael Koch
  • Date: 2009-07-23 07:46:40 UTC
  • Revision ID: james.westby@ubuntu.com-20090723074640-wh0ukzis0kda36qv
Tags: upstream-0.5.6
ImportĀ upstreamĀ versionĀ 0.5.6

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/***************************************************************************
 
2
        OgrePagingLandScapePageManager.h  -  description
 
3
        -------------------
 
4
        begin                : Sat May 01 2004
 
5
        copyright            : (C) 2003-2006 by Jose A. Milan and Tuan Kuranes
 
6
        email                : spoke2@supercable.es && tuan.kuranes@free.fr
 
7
***************************************************************************/
 
8
 
 
9
/***************************************************************************
 
10
*                                                                         *
 
11
*   This program is free software; you can redistribute it and/or modify  *
 
12
*   it under the terms of the GNU Lesser General Public License as        *
 
13
*   published by the Free Software Foundation; either version 2 of the    *
 
14
*   License, or (at your option) any later version.                       *
 
15
*                                                                         *
 
16
***************************************************************************/
 
17
 
 
18
#ifndef PAGINGLandScapePAGEMANAGER_H
 
19
#define PAGINGLandScapePAGEMANAGER_H
 
20
 
 
21
#include "OgrePagingLandScapePrerequisites.h"
 
22
#include "OgreSingleton.h"
 
23
#include "OgreFrameListener.h"
 
24
#include "OgrePagingLandScapeQueue.h"
 
25
 
 
26
#include "OgrePagingLandScapePage.h"
 
27
 
 
28
namespace Ogre
 
29
{
 
30
    class _OgrePagingLandScapeExport PagingLandScapePageManager : public FrameListener
 
31
    {
 
32
        public:
 
33
                
 
34
                        ///ctor
 
35
                        PagingLandScapePageManager(PagingLandScapeSceneManager * scnMgr);
 
36
                        ///dtor
 
37
                ~PagingLandScapePageManager(void);
 
38
 
 
39
                        /// upon new landscape
 
40
                        void load(void);
 
41
                        /// empty before loading a landscape or final deletion
 
42
            void clear(void);
 
43
                        /// reset paging but keep page pool in memory
 
44
            void reset(void);
 
45
 
 
46
                        /// used to load first page earlier than first updatePaging() call
 
47
                        /// say like just after scene manager setWorldGeom()
 
48
            void LoadFirstPage(PagingLandScapeCamera* cam);
 
49
                        /// Make sure page under camera is loaded, 
 
50
                        /// that neighbor pages are preLoaded, preLoading
 
51
                        /// and process queues accordingly
 
52
                void updatePaging(PagingLandScapeCamera* cam);
 
53
 
 
54
                        // recursively call LOD update on all page and tiles
 
55
                        void _updateLod(void);
 
56
                        
 
57
                        // load everything around camera just now.
 
58
            void loadNow(PagingLandScapeCamera *cam);
 
59
            // Make sure page gets into loaded page list when loaded from outside 
 
60
            // ie "LoadNow" getOption
 
61
            void addLoadedPage(PagingLandScapePage *p);
 
62
 
 
63
                        /// if page is already instantiated get page at this pos,
 
64
                        /// otherwise allocate one, if alwaysReturn is set true.
 
65
                        PagingLandScapePage* getPage(const unsigned int i , const unsigned int j,
 
66
                                const bool alwaysReturn = true);
 
67
                        /// Instantiate a new page from pool.
 
68
                        PagingLandScapePage* getNewPage(const unsigned int i , const unsigned int j);
 
69
                        /// Return a page to the pool.
 
70
                        void releasePage (PagingLandScapePage*p );
 
71
 
 
72
                        /// get Tile at absolute position in space, return answer even when position is outside landscape
 
73
                        /// when alwaysAnswer is true
 
74
                        PagingLandScapeTile* getTile(const Real posx, const Real posz, bool alwaysAnswer);
 
75
                        /// get Tile at absolute position but unscaled by landscape scale in space, 
 
76
                        /// return answer even when position is outside landscape
 
77
                        /// when alwaysAnswer is true
 
78
                        PagingLandScapeTile* getTileUnscaled(const Real posx, const Real posz, bool alwaysAnswer);
 
79
                        // get Tile at relative position (in the page containing the tile page coordinate system) in space, 
 
80
                        /// return answer even when position is outside landscape
 
81
                        /// when alwaysAnswer is true
 
82
                        PagingLandScapeTile* getTile(const Real posx, const Real posz, 
 
83
                                                                                 const unsigned int pagex, const unsigned int pagez, 
 
84
                                                                                 bool alwaysAnswer);
 
85
                        // get Tile at relative position but unscaled by landscape scale (in the page containing the tile page coordinate system) in space, 
 
86
                        /// return answer even when position is outside landscape
 
87
                        /// when alwaysAnswer is true
 
88
                        PagingLandScapeTile* getTileUnscaled(const Real posx, const Real posz, 
 
89
                                                                                                 const unsigned int pagex, const unsigned int pagez, 
 
90
                                                                                                 bool alwaysAnswer);
 
91
                        // get Tile at relative position but unscaled by landscape scale (in the page containing the tile page coordinate system) in space, 
 
92
                        /// return answer even when position is outside landscape
 
93
                        /// when alwaysAnswer is true
 
94
                        PagingLandScapeTile* getTilePage (unsigned int &posx, unsigned int &posz, const unsigned int pagex, const unsigned int pagez);
 
95
 
 
96
                        void getGlobalToPage(Real& x, Real& z) const;
 
97
                        /** Get the Page indices from a position
 
98
                        @param posx the world position vector.
 
99
                        @param posz the world position vector. 
 
100
                        @param x        result placed in reference to the x index of the page
 
101
                        @param z        result placed in reference to the z index of the page
 
102
                        */
 
103
            inline bool getPageIndices(const Real posx, const Real posz, unsigned int& x, unsigned int& z, bool alwaysAnswer) const
 
104
            {
 
105
                if (alwaysAnswer)
 
106
                {
 
107
                    getNearestPageIndicesUnscaled(posx * mOptions->invScale.x, posz* mOptions->invScale.z, x, z);
 
108
                    return true;
 
109
                }
 
110
                else
 
111
                {
 
112
                    return getRealPageIndicesUnscaled(posx * mOptions->invScale.x, posz* mOptions->invScale.z, x, z);
 
113
                }
 
114
            }
 
115
                        /** Get the Page indices from a position, returning page only if position is in.
 
116
                        @param posx the world position vector but unscaled. 
 
117
                        @param posz the world position vector but unscaled.  
 
118
                        @param x        result placed in reference to the x index of the page
 
119
                        @param z        result placed in reference to the z index of the page
 
120
                        */
 
121
                    inline bool getRealPageIndicesUnscaled(const Real posx, const Real posz, 
 
122
                                                    unsigned int& x, unsigned int& z) 
 
123
                                                    const
 
124
           {      
 
125
                const Real lx = ((posx + mOptions->maxUnScaledX) * mOptions->invPageSizeMinusOne);
 
126
                const Real lz = ((posz + mOptions->maxUnScaledZ) * mOptions->invPageSizeMinusOne);
 
127
 
 
128
                // make sure indices are not negative or outside range of number of pages
 
129
                if (lx >= mOptions->world_width || lx < static_cast <Real> (0.0) || 
 
130
                    lz >= mOptions->world_height || lz < static_cast <Real> (0.0) )
 
131
                {
 
132
                    return false;
 
133
                }
 
134
                else 
 
135
                {
 
136
                    x = static_cast< unsigned int > (lx);
 
137
                    z = static_cast< unsigned int > (lz);
 
138
                    return true;
 
139
                }
 
140
            }
 
141
                        /** Get the Page indices from a position, always returning a page.
 
142
                        @param posx the world position vector but unscaled. 
 
143
                        @param posz the world position vector but unscaled.  
 
144
                        @param x        result placed in reference to the x index of the page
 
145
                        @param z        result placed in reference to the z index of the page
 
146
                        */
 
147
                        void getNearestPageIndicesUnscaled(const Real posx, const Real posz, unsigned int& x, unsigned int& z) const; 
 
148
 
 
149
                        /** Get the Tile indices from a position
 
150
                        @param posx the world position vector. 
 
151
                        @param posz the world position vector.
 
152
                        @param pagex the world position page number. 
 
153
                        @param pagez the world position page number. 
 
154
                        @param x        result placed in reference to the x index of the page
 
155
                        @param z        result placed in reference to the z index of the page
 
156
                        */
 
157
                        bool getTileIndices(const Real posx, const Real posz, const unsigned int pagex, const unsigned int pagez, unsigned int& x, unsigned int& z, bool alwaysAnswer) const;
 
158
 
 
159
                        /** Get the Tile indices from a position, returning tile only if position is in.
 
160
                        @param posx the world position vector but unscaled. 
 
161
                        @param posz the world position vector but unscaled.  
 
162
                        @param x        result placed in reference to the x index of the page
 
163
                        @param z        result placed in reference to the z index of the page
 
164
                        */
 
165
                        inline bool getRealTileIndicesUnscaled(const Real posx, const Real posz, 
 
166
                                                    const unsigned int pagex, const unsigned int pagez, 
 
167
                                                    unsigned int& x, unsigned int& z) const
 
168
            {
 
169
                // adjust x and z to be local to page
 
170
                const int pSize = mOptions->PageSize - 1;
 
171
                const int tilex = static_cast< int >((posx - ((pagex * pSize) - mOptions->maxUnScaledX)) * mOptions->invTileSizeMinusOne); 
 
172
                const int tilez = static_cast< int >((posz - ((pagez * pSize) - mOptions->maxUnScaledZ)) * mOptions->invTileSizeMinusOne);
 
173
 
 
174
            
 
175
                const int tilesPerPage = static_cast< int >(mOptions->NumTiles);
 
176
                //const int tilesPerPage = static_cast< int >(mOptions->NumTiles(pSize * inv_tSize) - 1);
 
177
 
 
178
                if (tilex > tilesPerPage || tilex < 0 || 
 
179
                    tilez > tilesPerPage || tilez < 0)
 
180
                {
 
181
                    return false;
 
182
                }
 
183
                else
 
184
                {
 
185
                    x = static_cast< unsigned int >(tilex);
 
186
                    z = static_cast< unsigned int >(tilez);
 
187
                    return true;
 
188
                }
 
189
            }
 
190
 
 
191
                        /** Get the Tile indices from a position, returning tile only if position is in.
 
192
                        @param posx the world position vector but unscaled. 
 
193
                        @param posz the world position vector but unscaled.  
 
194
                        @param x        result placed in reference to the x index of the page
 
195
                        @param z        result placed in reference to the z index of the page
 
196
                        */
 
197
                        void getNearestTileIndicesUnscaled(const Real posx, const Real posz, const unsigned int pagex, const unsigned int pagez, unsigned int& x, unsigned int& z) const;
 
198
 
 
199
                        void setTerrainReady(bool isready)
 
200
                        {
 
201
                                mTerrainReady = isready;
 
202
                        };
 
203
 
 
204
 
 
205
                        void removeFromQueues(PagingLandScapePage* p);
 
206
 
 
207
                        bool frameStarted(const FrameEvent& evt);
 
208
                        bool frameEnded(const FrameEvent& evt);
 
209
 
 
210
                        void setWorldGeometryRenderQueue(uint8 qid);
 
211
                        RenderQueueGroupID getRenderQueueGroupID(void)
 
212
                        {
 
213
                                return mRenderQueueGroupID;
 
214
                        };
 
215
 
 
216
                        void setMapMaterial(void);
 
217
                        void WorldDimensionChange(void);
 
218
 
 
219
 
 
220
 
 
221
                        /// getter
 
222
                        unsigned int getCurrentCameraPageX(void) const;
 
223
                        /// getter
 
224
                        unsigned int getCurrentCameraPageZ(void) const;
 
225
                        /// getter
 
226
                        unsigned int getCurrentCameraTileX(void) const;
 
227
                        /// getter
 
228
            unsigned int getCurrentCameraTileZ(void) const;
 
229
                        /// getter
 
230
                        int getPagePreloadQueueSize(void) const;
 
231
                        /// getter
 
232
                        int getPageLoadQueueSize(void) const;
 
233
                        /// getter
 
234
            int getPageTextureloadQueueSize(void) const;
 
235
                        /// getter
 
236
                        int getLoadedPageSize(void) const;
 
237
                        /// getter
 
238
                        int getPreLoadedPageSize(void) const;
 
239
                        /// getter
 
240
                        int getTextureLoadedPageSize(void) const;
 
241
                        /// getter
 
242
                        int getUnloadedPagesSize(void) const;
 
243
 
 
244
            RenderQueueGroupID getPageRenderQueue(){return mRenderQueueGroupID;};
 
245
 
 
246
            PagingLandScapeOptions*             getOptions(){return mOptions;}
 
247
            PagingLandScapeSceneManager* getSceneManager(){return mSceneManager;}
 
248
 
 
249
            bool isEnabled ()const {return mEnabled;}
 
250
            void setEnabled (const bool enabled){mEnabled = enabled;}
 
251
 
 
252
        protected:
 
253
 
 
254
            PagingLandScapeOptions*             mOptions;
 
255
            PagingLandScapeSceneManager *mSceneManager;
 
256
 
 
257
 
 
258
 
 
259
                        void processUnloadQueues();
 
260
                        void processLoadQueues();
 
261
                        void updateLoadedPages();
 
262
                        void queuePageNeighbors ();
 
263
 
 
264
                        void makePageLoadedNow(PagingLandScapePage* p);
 
265
            PagingLandScapePage* find_nearest(const Vector3& pos, const unsigned int x, const unsigned int z, PagingLandScapePageList& mQueue) const;
 
266
 
 
267
            PagingLandScapeData2DManager*     mData2d;
 
268
            PagingLandScapeTextureManager*    mTexture;
 
269
            PagingLandScapeRenderableManager* mRenderablesMgr;
 
270
 
 
271
                /** LandScape pages for the terrain.
 
272
                */
 
273
                //PagingLandScapePages mPages;
 
274
 
 
275
            PagingLandScapeQueue <PagingLandScapePage> mPageLoadQueue;
 
276
            PagingLandScapeQueue <PagingLandScapePage> mPagePreloadQueue;
 
277
            PagingLandScapeQueue <PagingLandScapePage> mPageTextureloadQueue;
 
278
 
 
279
            PagingLandScapePageList mLoadedPages;
 
280
            PagingLandScapePageList mPreLoadedPages;
 
281
            PagingLandScapePageList mTextureLoadedPages;
 
282
 
 
283
                        PagingLandScapePageList mActivePages;
 
284
                        PagingLandScapePageList mFreePages;
 
285
                        PagingLandScapePageArray mPagePool;
 
286
 
 
287
            unsigned int mWidth;
 
288
            unsigned int mHeight;
 
289
 
 
290
            int mNextQueueFrameCount;
 
291
            int mTimePreLoaded;
 
292
 
 
293
                        int mPause;
 
294
 
 
295
            PagingLandScapeCamera* mCurrentcam;
 
296
            bool mTerrainReady;
 
297
            bool mOnFrame;
 
298
 
 
299
                        unsigned int mRenderableLoadInterval;
 
300
                        unsigned int mPageLoadInterval;
 
301
 
 
302
            RenderQueueGroupID mRenderQueueGroupID;
 
303
 
 
304
            //if not queued to be removed from frame listener
 
305
            //or SM is in paused State
 
306
            bool mEnabled;
 
307
        };
 
308
 
 
309
}
 
310
 
 
311
#endif