Revision | beb9f2c3c8688193ba1823c342ceec30f5542e1a (tree) |
---|---|
Time | 2024-07-08 03:08:23 |
Author | sebastian_bugiu |
Commiter | sebastian_bugiu |
WIP adding NodeMemoryManager and ObjectMemoryManager per zone.
@@ -218,6 +218,8 @@ | ||
218 | 218 | /// Called by SceneManager when it is telling we're a static MovableObject being dirty |
219 | 219 | /// Don't call this directly. @see SceneManager::notifyStaticDirty |
220 | 220 | virtual void _notifyStaticDirty(void) const {} |
221 | + | |
222 | + void migrateTo( ObjectMemoryManager *objMemManager ); | |
221 | 223 | |
222 | 224 | /** Internal method by which the movable object must add Renderable subclass instances to the rendering queue. |
223 | 225 | @remarks |
@@ -1976,8 +1976,9 @@ | ||
1976 | 1976 | virtual void updateSceneGraph(); |
1977 | 1977 | |
1978 | 1978 | typedef FastArray<MovableObject*> MovableObjectArray; |
1979 | - virtual void _findVisibleObjects ( Camera * cam, Camera * lodCamera, | |
1980 | - const size_t numNodes, ObjectData t, MovableObjectArray &outCulledObjects, bool onlyShadowCasters ) {} | |
1979 | + virtual void _findVisibleObjects( NodeMemoryManagerVec &nodeMemoryManagers, | |
1980 | + ObjectMemoryManagerVec &entitiesMemoryManagerCulledList, | |
1981 | + bool onlyShadowCasters ) {} | |
1981 | 1982 | |
1982 | 1983 | /** Internal method for applying animations to scene nodes. |
1983 | 1984 | @remarks |
@@ -52,9 +52,9 @@ | ||
52 | 52 | const uint32 VisibilityFlags::LAYER_SHADOW_CASTER = 1 << 31; |
53 | 53 | const uint32 VisibilityFlags::LAYER_VISIBILITY = 1 << 30; |
54 | 54 | const uint32 VisibilityFlags::LAYER_PCZ_VISIBILITY = 1 << 29; |
55 | - const uint32 VisibilityFlags::RESERVED_VISIBILITY_FLAGS = ~(LAYER_SHADOW_CASTER|LAYER_VISIBILITY|LAYER_PCZ_VISIBILITY); | |
55 | + const uint32 VisibilityFlags::RESERVED_VISIBILITY_FLAGS = ~(LAYER_SHADOW_CASTER|LAYER_VISIBILITY); | |
56 | 56 | uint32 MovableObject::msDefaultQueryFlags = 0xFFFFFFFF; |
57 | - uint32 MovableObject::msDefaultVisibilityFlags = 0xFFFFFFFF & (~(LAYER_VISIBILITY|LAYER_PCZ_VISIBILITY)); | |
57 | + uint32 MovableObject::msDefaultVisibilityFlags = 0xFFFFFFFF & (~(LAYER_VISIBILITY)); | |
58 | 58 | //----------------------------------------------------------------------- |
59 | 59 | MovableObject::MovableObject( IdType id, ObjectMemoryManager *objectMemoryManager, |
60 | 60 | SceneManager *manager, uint8 renderQueueId ) |
@@ -191,6 +191,17 @@ | ||
191 | 191 | return retVal; |
192 | 192 | } |
193 | 193 | //----------------------------------------------------------------------- |
194 | + void MovableObject::migrateTo( ObjectMemoryManager *objMemManager ) | |
195 | + { | |
196 | + mObjectMemoryManager->migrateTo( mObjectData, mRenderQueueID, | |
197 | + objMemManager ); | |
198 | + mObjectMemoryManager = objMemManager; | |
199 | + if( mParentNode ) | |
200 | + { | |
201 | + | |
202 | + } | |
203 | + } | |
204 | + //----------------------------------------------------------------------- | |
194 | 205 | bool MovableObject::isVisible(void) const |
195 | 206 | { |
196 | 207 | if( !getVisible() ) |
@@ -560,10 +571,18 @@ | ||
560 | 571 | //Decompose the result for analyzing each MovableObject's |
561 | 572 | //There's no need to check objData.mOwner[j] is null because |
562 | 573 | //we set mVisibilityFlags to 0 on slot removals |
574 | + int vis = 0; | |
563 | 575 | if( IS_BIT_SET( j, scalarMask ) ) |
564 | 576 | { |
565 | 577 | culledObjects.push_back( objData.mOwner[j] ); |
578 | + vis = 1; | |
566 | 579 | } |
580 | +// if ( vis == 1 ) | |
581 | +// { | |
582 | + std::stringstream str; | |
583 | + str << "visibility for object: " << objData.mOwner[j]->getName() << " final visibility: " << vis; | |
584 | + LogManager::getSingleton().logMessage( LML_NORMAL, str.str() ); | |
585 | +// } | |
567 | 586 | } |
568 | 587 | |
569 | 588 | objData.advanceFrustumPack(); |
@@ -1087,10 +1087,10 @@ | ||
1087 | 1087 | |
1088 | 1088 | camera->_setRenderedRqs( realFirstRq, realLastRq ); |
1089 | 1089 | #ifdef USE_PCZ |
1090 | - PCZCullFrustumRequest cullRequest( realFirstRq, realLastRq, | |
1090 | + CullFrustumRequest cullRequest( realFirstRq, realLastRq, | |
1091 | 1091 | mIlluminationStage == IRS_RENDER_TO_TEXTURE, true, false, |
1092 | 1092 | &mEntitiesMemoryManagerCulledList, camera, lodCamera ); |
1093 | - firePCZCullFrustumThreads( cullRequest ); | |
1093 | + fireCullFrustumThreads( cullRequest ); | |
1094 | 1094 | #else |
1095 | 1095 | CullFrustumRequest cullRequest( realFirstRq, realLastRq, |
1096 | 1096 | mIlluminationStage == IRS_RENDER_TO_TEXTURE, true, false, |
@@ -2489,9 +2489,6 @@ | ||
2489 | 2489 | //when there are less entities than ARRAY_PACKED_REALS |
2490 | 2490 | numObjs = std::min( numObjs, totalObjs - toAdvance ); |
2491 | 2491 | objData.advancePack( toAdvance / ARRAY_PACKED_REALS ); |
2492 | - | |
2493 | - // First go through the portals to remove everything that isn't visible. | |
2494 | - _findVisibleObjects( const_cast<Camera*>(camera), const_cast<Camera*>(lodCamera), numObjs, objData, outVisibleObjects, false ); | |
2495 | 2492 | |
2496 | 2493 | MovableObject::pczCullFrustum( numObjs, objData, camera, visibilityMask, |
2497 | 2494 | outVisibleObjects, lodCamera ); |
@@ -2895,7 +2892,7 @@ | ||
2895 | 2892 | _applySceneAnimations(); |
2896 | 2893 | updateAllTransforms(); |
2897 | 2894 | #ifdef USE_PCZ |
2898 | - resetAllUpdateFlags(); | |
2895 | +// resetAllUpdateFlags(); | |
2899 | 2896 | #endif |
2900 | 2897 | updateAllAnimations(); |
2901 | 2898 | updateAllTagPoints(); |
@@ -97,16 +97,12 @@ | ||
97 | 97 | Starts with objects in the zone and proceeds through visible portals |
98 | 98 | This is a recursive call (the main call should be to _findVisibleObjects) |
99 | 99 | */ |
100 | - void findVisibleNodes(PCZCamera * cam, PCZCamera * lodCamera, | |
101 | - const size_t numNodes, | |
102 | - ObjectData objData, | |
103 | - MovableObject::MovableObjectArray &outCulledObjects, | |
104 | -// NodeList & visibleNodeList, | |
105 | -// RenderQueue * queue, | |
106 | -// VisibleObjectsBoundsInfo* visibleBounds, | |
107 | - bool onlyShadowCasters, | |
108 | - bool displayNodes, | |
109 | - bool showBoundingBoxes); | |
100 | + void findVisibleNodes( PCZCamera *camera, | |
101 | + NodeMemoryManagerVec &nodeMemoryManagers, | |
102 | + ObjectMemoryManagerVec &entitiesMemoryManagerCulledList, | |
103 | + bool onlyShadowCasters, | |
104 | + bool displayNodes, | |
105 | + bool showBoundingBoxes ); | |
110 | 106 | |
111 | 107 | /* Functions for finding Nodes that intersect various shapes */ |
112 | 108 | void _findNodes( const AxisAlignedBox &t, |
@@ -141,10 +141,13 @@ | ||
141 | 141 | |
142 | 142 | /** Update Scene Graph (does several things now) */ |
143 | 143 | void updateSceneGraph( /*Camera * cam*/ ); |
144 | + | |
145 | + virtual void highLevelCull(); | |
144 | 146 | |
145 | 147 | /** Recurses through the PCZTree determining which nodes are visible. */ |
146 | - virtual void _findVisibleObjects ( Camera * cam, Camera * lodCamera, | |
147 | - const size_t numNodes, ObjectData objData, MovableObject::MovableObjectArray &outCulledObjects, bool onlyShadowCasters ); | |
148 | + virtual void _findVisibleObjects( NodeMemoryManagerVec &nodeMemoryManagers, | |
149 | + ObjectMemoryManagerVec &entitiesMemoryManagerCulledList, | |
150 | + bool onlyShadowCasters ); | |
148 | 151 | |
149 | 152 | /** Alerts each unculled object, notifying it that it will be drawn. |
150 | 153 | * Useful for doing calculations only on nodes that will be drawn, prior |
@@ -328,6 +331,9 @@ | ||
328 | 331 | |
329 | 332 | /// @see SceneManager::prepareShadowTextures. |
330 | 333 | // virtual void prepareShadowTextures(Camera* cam, Viewport* vp, const LightList* lightList = 0); |
334 | + | |
335 | + void setCurrentCamera( Camera *camera ) { mCurrentCamera = camera; } | |
336 | + Camera *getCurrentCamera() { return mCurrentCamera; } | |
331 | 337 | |
332 | 338 | protected: |
333 | 339 | /// Type of default zone to be used |
@@ -367,21 +373,11 @@ | ||
367 | 373 | /// The zone of the active camera (for shadow texture casting use); |
368 | 374 | PCZone* mActiveCameraZone; |
369 | 375 | |
370 | -// NodeMemoryManager mNodeMemoryManager[NUM_SCENE_MEMORY_MANAGER_TYPES]; | |
371 | -// ObjectMemoryManager mEntityMemoryManager[NUM_SCENE_MEMORY_MANAGER_TYPES]; | |
372 | -// ObjectMemoryManager mLightMemoryManager; | |
376 | + Camera *mCurrentCamera; | |
377 | + | |
373 | 378 | ObjectMemoryManager mPortalMemoryManager; |
374 | 379 | ObjectMemoryManager mAntiPortalMemoryManager; |
375 | 380 | ObjectMemoryManager mZoneMemoryManager; |
376 | -// SkeletonAnimManager mSkeletonAnimationManager; | |
377 | -// NodeMemoryManager mTagPointNodeMemoryManager; | |
378 | - /// Filled and cleared every frame in HighLevelCull() | |
379 | - NodeMemoryManagerVec mNodeMemoryManagerUpdateList; | |
380 | -// NodeMemoryManagerVec mTagPointNodeMemoryManagerUpdateList; | |
381 | - ObjectMemoryManagerVec mEntitiesMemoryManagerCulledList; | |
382 | - ObjectMemoryManagerVec mEntitiesMemoryManagerUpdateList; | |
383 | - ObjectMemoryManagerVec mLightsMemoryManagerCulledList; | |
384 | -// SkeletonAnimManagerVec mSkeletonAnimManagerCulledList; | |
385 | 381 | |
386 | 382 | /** Internal method for locating a list of lights which could be affecting the frustum. |
387 | 383 | @remarks |
@@ -53,6 +53,8 @@ | ||
53 | 53 | |
54 | 54 | #include "OgrePCZPrerequisites.h" |
55 | 55 | #include "OgrePortalBase.h" |
56 | +#include "Math/Array/OgreNodeMemoryManager.h" | |
57 | +#include "Math/Array/OgreObjectMemoryManager.h" | |
56 | 58 | |
57 | 59 | namespace Ogre |
58 | 60 | { |
@@ -192,16 +194,14 @@ | ||
192 | 194 | Starts with objects in the zone and proceeds through visible portals |
193 | 195 | This is a recursive call (the main call should be to _findVisibleObjects) |
194 | 196 | */ |
195 | - virtual void findVisibleNodes(PCZCamera * cam, PCZCamera * lodCamera, | |
196 | - const size_t numNodes, | |
197 | - ObjectData objData, | |
198 | - MovableObject::MovableObjectArray &outCulledObjects, | |
199 | -// NodeList & visibleNodeList, | |
200 | - // RenderQueue * queue, | |
201 | - // VisibleObjectsBoundsInfo* visibleBounds, | |
202 | - bool onlyShadowCasters, | |
203 | - bool displayNodes = false, | |
204 | - bool showBoundingBoxes = false) = 0; | |
197 | + typedef vector<NodeMemoryManager*>::type NodeMemoryManagerVec; | |
198 | + typedef vector<ObjectMemoryManager*>::type ObjectMemoryManagerVec; | |
199 | + virtual void findVisibleNodes( PCZCamera *camera, | |
200 | + NodeMemoryManagerVec &nodeMemoryManagers, | |
201 | + ObjectMemoryManagerVec &ntitiesMemoryManagerCulledList, | |
202 | + bool onlyShadowCasters, | |
203 | + bool displayNodes = false, | |
204 | + bool showBoundingBoxes = false) = 0; | |
205 | 205 | |
206 | 206 | /* Functions for finding Nodes that intersect various shapes */ |
207 | 207 | virtual void _findNodes( const AxisAlignedBox &t, |
@@ -254,6 +254,9 @@ | ||
254 | 254 | AntiPortalList mAntiPortals; |
255 | 255 | /// Pointer to the pcz scene manager that created this zone |
256 | 256 | PCZSceneManager * mPCZSM; |
257 | + | |
258 | + NodeMemoryManager mNodeMemoryManager; | |
259 | + ObjectMemoryManager mEntitiesMemoryManager; | |
257 | 260 | |
258 | 261 | protected: |
259 | 262 | /** Binary predicate for portal <-> camera distance sorting. */ |
@@ -45,6 +45,7 @@ | ||
45 | 45 | #include "OgrePCZCamera.h" |
46 | 46 | #include "OgreMovableObject.h" |
47 | 47 | #include "OgreLogManager.h" |
48 | +#include "Math/Array/OgreNodeMemoryManager.h" | |
48 | 49 | |
49 | 50 | namespace Ogre |
50 | 51 | { |
@@ -78,6 +79,11 @@ | ||
78 | 79 | { |
79 | 80 | // add a reference to this node in the "nodes at home in this zone" list |
80 | 81 | mHomeNodeList.insert( n ); |
82 | +// n->migrateTo( &mNodeMemoryManager ); | |
83 | + for( size_t i = 0; i < n->numAttachedObjects(); ++i ) | |
84 | + { | |
85 | + n->getAttachedObject( i )->migrateTo( &mEntitiesMemoryManager ); | |
86 | + } | |
81 | 87 | } |
82 | 88 | else |
83 | 89 | { |
@@ -516,17 +522,12 @@ | ||
516 | 522 | /* |
517 | 523 | // Recursively walk the zones, adding all visible SceneNodes to the list of visible nodes. |
518 | 524 | */ |
519 | - void DefaultZone::findVisibleNodes(PCZCamera * camera, | |
520 | - PCZCamera * lodCamera, | |
521 | - const size_t numNodes, | |
522 | - ObjectData objData, | |
523 | - MovableObject::MovableObjectArray &outCulledObjects, | |
524 | - // NodeList & visibleNodeList, | |
525 | - // RenderQueue * queue, | |
526 | - // VisibleObjectsBoundsInfo* visibleBounds, | |
525 | + void DefaultZone::findVisibleNodes( PCZCamera *camera, | |
526 | + NodeMemoryManagerVec &nodeMemoryManagers, | |
527 | + ObjectMemoryManagerVec &entitiesMemoryManagerCulledList, | |
527 | 528 | bool onlyShadowCasters, |
528 | 529 | bool displayNodes, |
529 | - bool showBoundingBoxes) | |
530 | + bool showBoundingBoxes ) | |
530 | 531 | { |
531 | 532 | |
532 | 533 | //return immediately if nothing is in the zone. |
@@ -546,9 +547,12 @@ | ||
546 | 547 | // TODO use modern way to render sky. |
547 | 548 | //mPCZSM->enableSky(true); |
548 | 549 | } |
550 | + | |
551 | + nodeMemoryManagers.push_back( &mNodeMemoryManager ); | |
552 | + entitiesMemoryManagerCulledList.push_back( &mEntitiesMemoryManager ); | |
549 | 553 | |
550 | 554 | // find visible nodes at home in the zone |
551 | - bool vis; | |
555 | + /*bool vis; | |
552 | 556 | PCZSceneNodeList::iterator it = mHomeNodeList.begin(); |
553 | 557 | while ( it != mHomeNodeList.end() ) |
554 | 558 | { |
@@ -686,7 +690,7 @@ | ||
686 | 690 | } |
687 | 691 | } |
688 | 692 | ++it; |
689 | - } | |
693 | + }*/ | |
690 | 694 | |
691 | 695 | // Here we merge both portal and antiportal visible to the camera into one list. |
692 | 696 | // Then we sort them in the order from nearest to furthest from camera. |
@@ -737,16 +741,12 @@ | ||
737 | 741 | portal->getTargetZone()->setLastVisibleFrame(mLastVisibleFrame); |
738 | 742 | portal->getTargetZone()->setLastVisibleFromCamera(camera); |
739 | 743 | // recurse into the connected zone |
740 | - portal->getTargetZone()->findVisibleNodes(camera, lodCamera, | |
741 | - numNodes, | |
742 | - objData, | |
743 | - outCulledObjects, | |
744 | - // visibleNodeList, | |
745 | - // RenderQueue * queue, | |
746 | - // VisibleObjectsBoundsInfo* visibleBounds, | |
747 | - onlyShadowCasters, | |
748 | - displayNodes, | |
749 | - showBoundingBoxes); | |
744 | + portal->getTargetZone()->findVisibleNodes( camera, | |
745 | + nodeMemoryManagers, | |
746 | + entitiesMemoryManagerCulledList, | |
747 | + onlyShadowCasters, | |
748 | + displayNodes, | |
749 | + showBoundingBoxes ); | |
750 | 750 | if (planes_added > 0) |
751 | 751 | { |
752 | 752 | // Then remove the extra culling planes added before going to the next portal in the list. |
@@ -55,7 +55,8 @@ | ||
55 | 55 | mDefaultZone(0), |
56 | 56 | mShowPortals(false), |
57 | 57 | mZoneFactoryManager(0), |
58 | - mActiveCameraZone(0) | |
58 | + mActiveCameraZone(0), | |
59 | + mCurrentCamera( 0 ) | |
59 | 60 | { } |
60 | 61 | |
61 | 62 | PCZSceneManager::~PCZSceneManager() |
@@ -369,15 +370,6 @@ | ||
369 | 370 | return retVal; |
370 | 371 | } |
371 | 372 | |
372 | - /*SceneNode* PCZSceneManager::createSceneNodeImpl(const String& name) | |
373 | - { | |
374 | - SceneNode *retVal = OGRE_NEW PCZSceneNode( Id::generateNewId<Node>(), this, | |
375 | - nodeMemoryManager, parent ); | |
376 | - if( nodeMemoryManager->getMemoryManagerType() == SCENE_STATIC ) | |
377 | - notifyStaticDirty( retVal ); | |
378 | - return retVal; | |
379 | - }*/ | |
380 | - | |
381 | 373 | SceneNode * PCZSceneManager::createSceneNode( SceneMemoryMgrTypes sceneType ) |
382 | 374 | { |
383 | 375 | SceneNode * sn = SceneManager::createSceneNode(sceneType); |
@@ -421,6 +413,9 @@ | ||
421 | 413 | zone->notifyCameraCreated( c ); |
422 | 414 | } |
423 | 415 | |
416 | + // TODO HACK for setting current camera for findVisibleNodes(). This should be an explicit call from game. | |
417 | + setCurrentCamera( c ); | |
418 | + | |
424 | 419 | return c; |
425 | 420 | } |
426 | 421 |
@@ -1279,12 +1274,9 @@ | ||
1279 | 1274 | // main visibility determination & render queue filling routine |
1280 | 1275 | // over-ridden from base/default scene manager. This is *the* |
1281 | 1276 | // main call. |
1282 | - void PCZSceneManager::_findVisibleObjects( Camera * camera, | |
1283 | - Camera * lodCamera, | |
1284 | - const size_t numNodes, | |
1285 | - ObjectData objData, | |
1286 | - MovableObject::MovableObjectArray &outCulledObjects, | |
1287 | - bool onlyShadowCasters ) | |
1277 | + void PCZSceneManager::_findVisibleObjects( NodeMemoryManagerVec &nodeMemoryManagers, | |
1278 | + ObjectMemoryManagerVec &entitiesMemoryManagerCulledList, | |
1279 | + bool onlyShadowCasters ) | |
1288 | 1280 | { |
1289 | 1281 | // clear the render queue |
1290 | 1282 | // getRenderQueue()->clear(); |
@@ -1303,10 +1295,12 @@ | ||
1303 | 1295 | } |
1304 | 1296 | return; |
1305 | 1297 | }*/ |
1298 | + | |
1299 | + PCZCamera *camera = (PCZCamera*) getCurrentCamera(); | |
1306 | 1300 | |
1307 | 1301 | // increment the visibility frame counter |
1308 | 1302 | mFrameCount = frameCount; |
1309 | - mLastActiveCamera = camera; | |
1303 | +// mLastActiveCamera = camera; | |
1310 | 1304 | |
1311 | 1305 | // clear the list of visible nodes |
1312 | 1306 | mVisible.clear(); |
@@ -1316,27 +1310,33 @@ | ||
1316 | 1310 | //enableSky(false); |
1317 | 1311 | |
1318 | 1312 | // remove all extra culling planes |
1319 | - ((PCZCamera*)camera)->removeAllExtraCullingPlanes(); | |
1313 | + camera->removeAllExtraCullingPlanes(); | |
1320 | 1314 | |
1321 | 1315 | // update the camera |
1322 | - ((PCZCamera*)camera)->update(); | |
1316 | + camera->update(); | |
1323 | 1317 | |
1324 | 1318 | // get the home zone of the camera |
1325 | 1319 | PCZone* cameraHomeZone = ((PCZSceneNode*)(camera->getParentSceneNode()))->getHomeZone(); |
1326 | - | |
1327 | - // walk the zones, starting from the camera home zone, | |
1328 | - // adding all visible scene nodes to the mVisibles list | |
1329 | - cameraHomeZone->setLastVisibleFrame(mFrameCount); | |
1330 | - cameraHomeZone->findVisibleNodes( (PCZCamera*)camera, (PCZCamera*)lodCamera, | |
1331 | - numNodes, | |
1332 | - objData, | |
1333 | - outCulledObjects, | |
1334 | - // visibleNodeList, | |
1335 | - // RenderQueue * queue, | |
1336 | - // VisibleObjectsBoundsInfo* visibleBounds, | |
1337 | - onlyShadowCasters, | |
1338 | - false, | |
1339 | - false); | |
1320 | + | |
1321 | + if( cameraHomeZone ) | |
1322 | + { | |
1323 | + // walk the zones, starting from the camera home zone, | |
1324 | + // adding all visible scene nodes to the mVisibles list | |
1325 | + cameraHomeZone->setLastVisibleFrame(mFrameCount); | |
1326 | + cameraHomeZone->findVisibleNodes( camera, | |
1327 | + nodeMemoryManagers, | |
1328 | + entitiesMemoryManagerCulledList, | |
1329 | + onlyShadowCasters, | |
1330 | + false, | |
1331 | + false); | |
1332 | + } | |
1333 | + } | |
1334 | + | |
1335 | + void PCZSceneManager::highLevelCull() | |
1336 | + { | |
1337 | + SceneManager::highLevelCull(); | |
1338 | + | |
1339 | + _findVisibleObjects( mNodeMemoryManagerUpdateList, mEntitiesMemoryManagerCulledList, false ); | |
1340 | 1340 | } |
1341 | 1341 | |
1342 | 1342 | void PCZSceneManager::findNodesIn( const AxisAlignedBox &box, |