From: <kla...@us...> - 2016-07-03 07:29:36
|
Revision: 13715 http://sourceforge.net/p/vegastrike/code/13715 Author: klaussfreire Date: 2016-07-03 07:29:34 +0000 (Sun, 03 Jul 2016) Log Message: ----------- Optimize handling of subunit-less units by skipping some unneeded work Modified Paths: -------------- trunk/vegastrike/src/cmd/unit.cpp trunk/vegastrike/src/cmd/unit_generic.h Modified: trunk/vegastrike/src/cmd/unit.cpp =================================================================== --- trunk/vegastrike/src/cmd/unit.cpp 2016-07-03 07:24:55 UTC (rev 13714) +++ trunk/vegastrike/src/cmd/unit.cpp 2016-07-03 07:29:34 UTC (rev 13715) @@ -255,12 +255,14 @@ this->meshdata[i]->Draw( lod, mat, d, cloak ); } Unit *un; - for (un_iter iter = this->getSubUnits(); (un = *iter); ++iter) { - Matrix temp; - un->curr_physical_state.to_matrix( temp ); - Matrix submat; - MultMatrix( submat, mat, temp ); - (un)->DrawNow( submat, lod ); + if (this->hasSubUnits()) { + for (un_iter iter = this->getSubUnits(); (un = *iter); ++iter) { + Matrix temp; + un->curr_physical_state.to_matrix( temp ); + Matrix submat; + MultMatrix( submat, mat, temp ); + (un)->DrawNow( submat, lod ); + } } float cmas = this->computer.max_ab_speed()*this->computer.max_ab_speed(); if (cmas == 0) @@ -356,7 +358,7 @@ AUDAdjustSound( sound.engine, cumulative_transformation.position, GetVelocity() ); #endif - unsigned int i; + unsigned int i, n; if ( (this->hull < 0) && (!cam_setup_phase) ) Explode( true, GetElapsedTime() ); @@ -367,6 +369,7 @@ float avgscale = 1.0f; bool On_Screen = false; + bool Unit_On_Screen = false; float Apparent_Size = 0.0f; int cloak = this->cloaking; Matrix wmat; @@ -394,11 +397,11 @@ ( camera->GetVelocity().Magnitude()+this->Velocity.Magnitude() )*SIMULATION_ATOM; unsigned int numKeyFrames = this->graphicOptions.NumAnimationPoints; - for (i = 0; i <= this->nummesh(); i++) { + for (i = 0, n = this->nummesh(); i <= n; i++) { //NOTE LESS THAN OR EQUALS...to cover shield mesh if (this->meshdata[i] == NULL) continue; - if ( i == this->nummesh() && (this->meshdata[i]->numFX() == 0 || this->hull < 0) ) + if ( i == n && (this->meshdata[i]->numFX() == 0 || this->hull < 0) ) continue; if (this->meshdata[i]->getBlendDst() == ONE) { if ( (this->invisible & UnitType::INVISGLOW) != 0 ) @@ -453,8 +456,12 @@ } } } - } - { + + Unit_On_Screen = On_Screen || !!GFXSphereInFrustum( + ct->position, + minmeshradius+this->rSize() ); + } else Unit_On_Screen = true; + if (Unit_On_Screen && this->hasSubUnits()) { Unit *un; double backup = interpolation_blend_factor; int cur_sim_frame = _Universe->activeStarSystem()->getCurrentSimFrame(); Modified: trunk/vegastrike/src/cmd/unit_generic.h =================================================================== --- trunk/vegastrike/src/cmd/unit_generic.h 2016-07-03 07:24:55 UTC (rev 13714) +++ trunk/vegastrike/src/cmd/unit_generic.h 2016-07-03 07:29:34 UTC (rev 13715) @@ -341,6 +341,7 @@ * The ammo and the weapon type. As well as the possible weapons it may fit * Warning: type has a string inside... cannot be memcpy'd */ + bool hasSubUnits() const { return !SubUnits.empty(); }; un_iter getSubUnits(); un_kiter viewSubUnits() const; #define NO_MOUNT_STAR |