mirror of
https://github.com/glest/glest-source.git
synced 2025-02-24 19:52:25 +01:00
Highlighting rendering without cycling through all units each frame ...
This commit is contained in:
parent
c1f617481e
commit
4aae520da6
@ -4912,29 +4912,47 @@ void Renderer::renderSelectionEffects() {
|
||||
}
|
||||
|
||||
//render selection hightlights
|
||||
for(int i=0; i < world->getFactionCount(); ++i) {
|
||||
for(int j=0; j < world->getFaction(i)->getUnitCount(); ++j) {
|
||||
const Unit *unit= world->getFaction(i)->getUnit(j);
|
||||
if(game->getGui()->getHighlightedUnit()!=NULL)
|
||||
{
|
||||
const Unit *unit=game->getGui()->getHighlightedUnit() ;
|
||||
|
||||
if(unit->isHighlighted()) {
|
||||
float highlight= unit->getHightlight();
|
||||
if(game->getWorld()->getThisFactionIndex() == unit->getFactionIndex()) {
|
||||
glColor4f(0.f, 1.f, 0.f, highlight);
|
||||
}
|
||||
else{
|
||||
glColor4f(1.f, 0.f, 0.f, highlight);
|
||||
}
|
||||
|
||||
Vec3f v= unit->getCurrVectorFlat();
|
||||
v.y+= 0.3f;
|
||||
renderSelectionCircle(v, unit->getType()->getSize(), 0.5f+0.4f*highlight );
|
||||
if(unit->isHighlighted()) {
|
||||
float highlight= unit->getHightlight();
|
||||
if(game->getWorld()->getThisFactionIndex() == unit->getFactionIndex()) {
|
||||
glColor4f(0.f, 1.f, 0.f, highlight);
|
||||
}
|
||||
else{
|
||||
glColor4f(1.f, 0.f, 0.f, highlight);
|
||||
}
|
||||
|
||||
Vec3f v= unit->getCurrVectorFlat();
|
||||
v.y+= 0.3f;
|
||||
renderSelectionCircle(v, unit->getType()->getSize(), 0.5f+0.4f*highlight );
|
||||
}
|
||||
}
|
||||
// old inefficient way to render highlights
|
||||
// for(int i=0; i < world->getFactionCount(); ++i) {
|
||||
// for(int j=0; j < world->getFaction(i)->getUnitCount(); ++j) {
|
||||
// const Unit *unit= world->getFaction(i)->getUnit(j);
|
||||
//
|
||||
// if(unit->isHighlighted()) {
|
||||
// float highlight= unit->getHightlight();
|
||||
// if(game->getWorld()->getThisFactionIndex() == unit->getFactionIndex()) {
|
||||
// glColor4f(0.f, 1.f, 0.f, highlight);
|
||||
// }
|
||||
// else{
|
||||
// glColor4f(1.f, 0.f, 0.f, highlight);
|
||||
// }
|
||||
//
|
||||
// Vec3f v= unit->getCurrVectorFlat();
|
||||
// v.y+= 0.3f;
|
||||
// renderSelectionCircle(v, unit->getType()->getSize(), 0.5f+0.4f*highlight );
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
//render resource selection highlight
|
||||
if(game->getGui()->getHighlightedResourceObject()!=NULL)
|
||||
{
|
||||
|
||||
const Object* object=game->getGui()->getHighlightedResourceObject();
|
||||
if(object->isHighlighted())
|
||||
{
|
||||
|
@ -112,6 +112,7 @@ Gui::Gui(){
|
||||
minQuadSize=20;
|
||||
selectedResourceObjectPos=Vec2i(-1,-1);
|
||||
highlightedResourceObjectPos=Vec2i(-1,-1);
|
||||
highlightedUnitId=-1;
|
||||
hudTexture=NULL;
|
||||
commander=NULL;
|
||||
world=NULL;
|
||||
@ -163,6 +164,15 @@ Object *Gui::getHighlightedResourceObject() const{
|
||||
}
|
||||
}
|
||||
|
||||
Unit* Gui::getHighlightedUnit() const{
|
||||
if(highlightedUnitId==-1){
|
||||
return NULL;
|
||||
}
|
||||
else {
|
||||
return world->findUnitById(highlightedUnitId);
|
||||
}
|
||||
}
|
||||
|
||||
// ==================== is ====================
|
||||
|
||||
bool Gui::isPlacingBuilding() const{
|
||||
@ -1067,6 +1077,8 @@ bool Gui::computeTarget(const Vec2i &screenPos, Vec2i &targetPos, const Unit *&t
|
||||
if(uc.empty() == false){
|
||||
targetUnit= getRelevantObjectFromSelection(&uc);
|
||||
targetPos= targetUnit->getPos();
|
||||
highlightedUnitId=targetUnit->getId();
|
||||
getHighlightedUnit()->resetHighlight();
|
||||
return true;
|
||||
}
|
||||
else if(obj != NULL){
|
||||
|
@ -145,6 +145,7 @@ private:
|
||||
CardinalDir selectedBuildingFacing;
|
||||
Vec2i selectedResourceObjectPos;
|
||||
Vec2i highlightedResourceObjectPos;
|
||||
int highlightedUnitId;
|
||||
|
||||
Texture2D* hudTexture;
|
||||
|
||||
@ -165,6 +166,7 @@ public:
|
||||
const Selection *getSelection() const {return &selection;}
|
||||
const Object *getSelectedResourceObject() const;
|
||||
Object *getHighlightedResourceObject() const;
|
||||
Unit *getHighlightedUnit() const;
|
||||
|
||||
const SelectionQuad *getSelectionQuad() const {return &selectionQuad;}
|
||||
CardinalDir getSelectedFacing() const {return selectedBuildingFacing;}
|
||||
|
@ -55,7 +55,7 @@ Command::Command(const CommandType *ct, Unit* unit) {
|
||||
this->unitRef= unit;
|
||||
unitType= NULL;
|
||||
if(unit!=NULL) {
|
||||
unit->resetHighlight();
|
||||
//unit->resetHighlight(); is in gui now
|
||||
pos= unit->getCellPos();
|
||||
}
|
||||
stateType = cst_None;
|
||||
|
Loading…
x
Reference in New Issue
Block a user