@@ -490,9 +490,9 @@ void MinimapGenerator::setupCameraData() {
490490 m_currentScene->setMandatoryADTs (adtVec);
491491 }
492492
493- std::cout << " (Debug) m_x = " << m_x << " m_y = " << m_y <<
494- " , x = " << (max.x + min.x ) * 0 .5f <<
495- " , y = " << (max.y + min.y ) * 0 .5f << std::endl;
493+ // std::cout << "(Debug) m_x = " << m_x << " m_y = " << m_y <<
494+ // ", x = " << (max.x + min.x) * 0.5f <<
495+ // ", y = " << (max.y + min.y) * 0.5f << std::endl;
496496
497497 setLookAtPoint (
498498 (max.x + min.x ) * 0.5 ,
@@ -505,15 +505,12 @@ void MinimapGenerator::setZoom(float zoom) {
505505}
506506
507507void MinimapGenerator::setLookAtPoint (float x, float y) {
508- mathfu::vec3 lookAtPoint = mathfu::vec3 (x, y, 0 );
509-
510- lookAtPoint = lookAtPoint;
511- // std::cout << "lookAtPoint = (" << lookAtPoint.x << ", " << lookAtPoint.y << ", " << lookAtPoint.z << ") " << std::endl;
508+ mathfu::vec3 lookAtPoint2D = mathfu::vec3 (x, y, 0 );
512509
513510 mathfu::vec3 lookAtVec3 = getLookAtVec3 ();
514- lookAtPoint -= ( 7000 . 0f * lookAtVec3);
511+ mathfu::vec3 lookAtPoint = lookAtPoint2D - ((m_minZ - 10 ) * lookAtVec3);
515512
516- mathfu::vec3 cameraPos = lookAtPoint-( 3000 . 0f *lookAtVec3);
513+ mathfu::vec3 cameraPos = lookAtPoint2D - ((m_maxZ + 10 ) *lookAtVec3);
517514// std::cout << "cameraPos = (" << cameraPos.x << ", " << cameraPos.y << ", " << cameraPos.z << ") " << std::endl;
518515
519516 m_apiContainer->camera ->setCameraPos (
@@ -525,120 +522,160 @@ void MinimapGenerator::setLookAtPoint(float x, float y) {
525522 m_apiContainer->camera ->tick (0 );
526523}
527524
525+ void MinimapGenerator::resetCandidate () {
526+ prepearCandidate = false ;
527+ m_candidateDS = nullptr ;
528+ m_candidateCS = nullptr ;
529+ m_candidateUS = nullptr ;
530+ framesReady = 0 ;
531+ }
532+
533+ void MinimapGenerator::calcBB (const HCullStage &cullStage, mathfu::vec3 &minCoord,
534+ mathfu::vec3 &maxCoord,
535+ const CAaBox &adtBox2d,
536+ int adt_x, int adt_y, bool applyAdtChecks) {
537+ minCoord = mathfu::vec3 (20000 , 20000 , 20000 );
538+ maxCoord = mathfu::vec3 (-20000 , -20000 , -20000 );
539+
540+ for (auto &m2Object: cullStage->m2Array .getDrawn ()) {
541+ auto objBB = m2Object->getAABB ();
542+
543+ if (applyAdtChecks && !MathHelper::isAabbIntersect2d (objBB, adtBox2d)) continue ;
544+
545+ minCoord = mathfu::vec3 (
546+ std::min<float >(minCoord.x , objBB.min .x ),
547+ std::min<float >(minCoord.y , objBB.min .y ),
548+ std::min<float >(minCoord.z , objBB.min .z )
549+ );
550+ maxCoord = mathfu::vec3 (
551+ std::max<float >(maxCoord.x , objBB.max .x ),
552+ std::max<float >(maxCoord.y , objBB.max .y ),
553+ std::max<float >(maxCoord.z , objBB.max .z )
554+ );
555+ }
556+
557+ for (auto &wmoObject: cullStage->wmoGroupArray .getToDraw ()) {
558+ auto objBB = wmoObject->getWorldAABB ();
559+
560+ if (applyAdtChecks && !MathHelper::isAabbIntersect2d (objBB, adtBox2d)) continue ;
561+
562+ minCoord = mathfu::vec3 (
563+ std::min<float >(minCoord.x , objBB.min .x ),
564+ std::min<float >(minCoord.y , objBB.min .y ),
565+ std::min<float >(minCoord.z , objBB.min .z )
566+ );
567+ maxCoord = mathfu::vec3 (
568+ std::max<float >(maxCoord.x , objBB.max .x ),
569+ std::max<float >(maxCoord.y , objBB.max .y ),
570+ std::max<float >(maxCoord.z , objBB.max .z )
571+ );
572+ }
573+
574+
575+ for (auto &adtObjectRes: cullStage->adtArray ) {
576+ auto adtObj = adtObjectRes->adtObject ;
577+
578+ if (applyAdtChecks && (adtObj->getAdtX () != adt_x || adtObj->getAdtY () != adt_y)) {
579+ // std::cout << "skipping adtObj( " <<
580+ // adtObj->getAdtX() << "," << adtObj->getAdtY() << " "
581+ // ") for adt(" << adt_x << ", " << adt_y << ")" << std::endl;
582+
583+ continue ;
584+ }
528585
529- const int waitQueueLen = 5 ;
586+ auto objBB = adtObj->calcAABB ();
587+
588+ minCoord = mathfu::vec3 (
589+ std::min<float >(minCoord.x , objBB.min .x ),
590+ std::min<float >(minCoord.y , objBB.min .y ),
591+ std::min<float >(minCoord.z , objBB.min .z )
592+ );
593+ maxCoord = mathfu::vec3 (
594+ std::max<float >(maxCoord.x , objBB.max .x ),
595+ std::max<float >(maxCoord.y , objBB.max .y ),
596+ std::max<float >(maxCoord.z , objBB.max .z )
597+ );
598+ }
599+ }
600+
601+ const int waitQueueLen = 3 ;
530602void MinimapGenerator::process () {
531- if (m_processor->completedAllJobs () && !m_apiContainer-> hDevice -> wasTexturesUploaded () ) {
603+ if (m_processor->completedAllJobs ()) {
532604 framesReady++;
533605 } else {
534- framesReady = 0 ;
535- prepearCandidate = false ;
536- m_candidateDS = nullptr ;
537- m_candidateCS = nullptr ;
606+ resetCandidate ();
538607 return ;
539608 }
540609
541610 if (framesReady < waitQueueLen) {
542611 return ;
543612 }
544613
545- if (!prepearCandidate) {
546- prepearCandidate = true ;
547- m_candidateDS = nullptr ;
548- m_candidateCS = nullptr ;
549- framesReady = 0 ;
614+ if (
615+ (m_candidateCS != nullptr && (
616+ (m_candidateCS->m2Array .getToLoadGeom ().size () != 0 ) ||
617+ (m_candidateCS->m2Array .getToLoadMain ().size () != 0 ) ||
618+ (m_candidateCS->wmoGroupArray .getToLoad ().size () != 0 )
619+ )
620+ ) ||
621+ (m_candidateUS != nullptr && m_candidateUS->texturesForUpload .size () > 0 )
622+ ) {
623+ resetCandidate ();
550624 return ;
551625 }
552626
627+ if (m_candidateDS == nullptr ) {
628+ prepearCandidate = true ;
629+ return ;
630+ }
553631
554632 auto lastFrameIt = m_candidateDS;
555633 auto lastFrameCull = m_candidateCS;
556- m_candidateDS = nullptr ;
557- m_candidateCS = nullptr ;
558- prepearCandidate = false ;
559- framesReady = 0 ;
560-
561- if (m_mgMode == EMGMode::eBoundingBoxCalculation) {
562- int adt_x = m_x;
563- int adt_y = m_y;
634+ resetCandidate ();
635+
636+ // Check the BB and adjust minZ-maxZ
637+ int adt_x = m_x;
638+ int adt_y = m_y;
639+
640+ vec2 minAdt = {
641+ AdtIndexToWorldCoordinate (adt_y + 1 ),
642+ AdtIndexToWorldCoordinate (adt_x + 1 )
643+ };
644+ vec2 maxAdt = {
645+ AdtIndexToWorldCoordinate (adt_y),
646+ AdtIndexToWorldCoordinate (adt_x),
647+ };
648+ mathfu::vec3 minCoord = mathfu::vec3 (20000 , 20000 , 20000 );
649+ mathfu::vec3 maxCoord = mathfu::vec3 (-20000 , -20000 , -20000 );
650+ {
564651
565- vec2 minAdt ={
566- AdtIndexToWorldCoordinate (adt_y+1 ),
567- AdtIndexToWorldCoordinate (adt_x+1 )
568- };
569- vec2 maxAdt = {
570- AdtIndexToWorldCoordinate (adt_y),
571- AdtIndexToWorldCoordinate (adt_x),
572- };
573652 CAaBox adtBox2d = {
574653 mathfu::vec3_packed (mathfu::vec3 (minAdt.x , minAdt.y , 0 )),
575654 mathfu::vec3_packed (mathfu::vec3 (maxAdt.x , maxAdt.y , 0 ))
576655 };
577656
578- mathfu::vec3 minCoord = mathfu::vec3 (20000 , 20000 , 20000 );
579- mathfu::vec3 maxCoord = mathfu::vec3 (-20000 , -20000 , -20000 );
580-
581- for (auto &m2Object: lastFrameCull->m2Array .getCandidates ()) {
582- auto objBB = m2Object->getAABB ();
583-
584- if (!MathHelper::isAabbIntersect2d (objBB, adtBox2d)) continue ;
585-
586- minCoord = mathfu::vec3 (
587- std::min<float >(minCoord.x , objBB.min .x ),
588- std::min<float >(minCoord.y , objBB.min .y ),
589- std::min<float >(minCoord.z , objBB.min .z )
590- );
591- maxCoord = mathfu::vec3 (
592- std::max<float >(maxCoord.x , objBB.max .x ),
593- std::max<float >(maxCoord.y , objBB.max .y ),
594- std::max<float >(maxCoord.z , objBB.max .z )
595- );
596- }
597-
598- for (auto &wmoObject: lastFrameCull->wmoArray .getCandidates ()) {
599- auto objBB = wmoObject->getAABB ();
600- if (!MathHelper::isAabbIntersect2d (objBB, adtBox2d)) continue ;
601-
602- minCoord = mathfu::vec3 (
603- std::min<float >(minCoord.x , objBB.min .x ),
604- std::min<float >(minCoord.y , objBB.min .y ),
605- std::min<float >(minCoord.z , objBB.min .z )
606- );
607- maxCoord = mathfu::vec3 (
608- std::max<float >(maxCoord.x , objBB.max .x ),
609- std::max<float >(maxCoord.y , objBB.max .y ),
610- std::max<float >(maxCoord.z , objBB.max .z )
611- );
612- }
613-
614-
615- for (auto &adtObjectRes: lastFrameCull->adtArray ) {
616- auto adtObj = adtObjectRes->adtObject ;
617- if (adtObj->getAdtX () != adt_x || adtObj->getAdtY () != adt_y) {
618- std::cout << " skipping adtObj( " <<
619- adtObj->getAdtX () << " ," << adtObj->getAdtY () << " "
620- " ) for adt(" << adt_x << " , " << adt_y << " )" << std::endl;
621-
622- continue ;
657+ this ->calcBB (lastFrameCull, minCoord, maxCoord, adtBox2d, adt_x, adt_y, m_mgMode == EMGMode::eBoundingBoxCalculation);
658+ float zFar = (minCoord - maxCoord).Length ();
659+ float maxZ = maxCoord.z ;
660+ float minZ = minCoord.z ;
661+
662+ if (!lastFrameCull->m2Array .getDrawn ().empty () || !lastFrameCull->adtArray .empty () ||
663+ !lastFrameCull->wmoGroupArray .getToDraw ().empty ()) {
664+ if (minCoord.x < 20000 && maxCoord.x > -20000 ) {
665+ if (zFar > m_zFar || maxZ > m_maxZ || minZ < m_minZ) {
666+ m_zFar = std::max<float >(zFar, m_zFar);
667+ m_maxZ = std::max<float >(maxZ, m_maxZ);
668+ m_minZ = std::min<float >(minZ, m_minZ);
669+ resetCandidate ();
670+ setupCameraData ();
671+ return ;
672+ }
623673 }
624-
625- auto objBB = adtObj->calcAABB ();
626- minCoord = mathfu::vec3 (
627- std::min<float >(minCoord.x , objBB.min .x ),
628- std::min<float >(minCoord.y , objBB.min .y ),
629- std::min<float >(minCoord.z , objBB.min .z )
630- );
631- maxCoord = mathfu::vec3 (
632- std::max<float >(maxCoord.x , objBB.max .x ),
633- std::max<float >(maxCoord.y , objBB.max .y ),
634- std::max<float >(maxCoord.z , objBB.max .z )
635- );
636674 }
675+ }
637676
638- std::cout << " minCoord = (" << minCoord.x << " , " << minCoord.y << " , " << minCoord.z << " )" << std::endl;
639- std::cout << " maxCoord = (" << maxCoord.x << " , " << maxCoord.y << " , " << maxCoord.z << " )" << std::endl;
640-
641- // Set x-y limits according to current adt index, since bounding box counting process is done per ADT
677+ // Conditional mode stuff
678+ if (m_mgMode == EMGMode::eBoundingBoxCalculation) {
642679 minCoord = mathfu::vec3 (
643680 minAdt.x ,
644681 minAdt.y ,
@@ -662,17 +699,24 @@ void MinimapGenerator::process() {
662699 saveDrawStageToFile (currentScenario.folderToSave , lastFrameIt);
663700 }
664701
665- m_y--;
666- if (m_y < 0 ) {
667- m_x++;
668- m_y = m_chunkHeight - 1 ;
669- }
702+ // Apply this logic only if it's not a preview mode
703+ if (m_mgMode != EMGMode::ePreview) {
704+ m_y--;
705+ if (m_y < 0 ) {
706+ m_x++;
707+ m_y = m_chunkHeight - 1 ;
708+ }
670709// std::cout << "m_x = " << m_x << " out of (" << m_chunkStartX+m_chunkWidth << ") m_y = " << m_y << " out of (" << m_chunkStartY+m_chunkHeight << ")" << std::endl;
671710
672- if (m_x >= m_chunkWidth) {
673- startNextScenario ();
674- } else {
675- setupCameraData ();
711+ if (m_x >= m_chunkWidth) {
712+ startNextScenario ();
713+ } else {
714+ // reset
715+ m_zFar = 10000 .0f ;
716+ m_maxZ = 1000 .0f ;
717+ m_minZ = -1000 .0f ;
718+ setupCameraData ();
719+ }
676720 }
677721}
678722
@@ -751,9 +795,10 @@ HDrawStage MinimapGenerator::createSceneDrawStage(HFrameScenario sceneScenario)
751795
752796 m_lastDraw = sceneDrawStage;
753797 // We dont need stack in preview mode
754- if (m_mgMode != EMGMode::ePreview && prepearCandidate && m_candidateDS == nullptr ) {
798+ if (prepearCandidate && m_candidateDS == nullptr ) {
755799 m_candidateDS = sceneDrawStage;
756800 m_candidateCS = cullStage;
801+ m_candidateUS = updateStage;
757802 }
758803 stackOfCullStages[m_apiContainer->hDevice ->getDrawFrameNumber ()] = cullStage;
759804
@@ -770,10 +815,11 @@ float MinimapGenerator::GetOrthoDimension() {
770815}
771816
772817mathfu::mat4 MinimapGenerator::getOrthoMatrix () {
773- return mathfu::mat4::Ortho (
818+ return
819+ mathfu::mat4::Ortho (
774820 -GetOrthoDimension () / 2 .0f ,GetOrthoDimension () / 2 .0f ,
775821 -GetOrthoDimension () / 2 .0f ,GetOrthoDimension () / 2 .0f ,
776- 1 ,10000
822+ 1 ,m_zFar + 10 , 1
777823 );
778824}
779825
0 commit comments