- build silhouette now uses team colour and you see all team players building placement

- improve performance when rending cell markers
This commit is contained in:
Mark Vejvoda 2012-06-22 13:30:15 +00:00
parent e94d7b2fef
commit 0f5cb29919
6 changed files with 53 additions and 34 deletions

View File

@ -394,7 +394,7 @@ void Renderer::initGame(const Game *game, GameCamera *gameCamera) {
SurfaceData::nextUniqueId = 1; SurfaceData::nextUniqueId = 1;
mapSurfaceData.clear(); mapSurfaceData.clear();
this->game= game; this->game= game;
//worldToScreenPosCache.clear(); worldToScreenPosCache.clear();
//vars //vars
shadowMapFrame= 0; shadowMapFrame= 0;
@ -637,7 +637,7 @@ void Renderer::endScenario() {
// list3dValid=false; // list3dValid=false;
//} //}
//worldToScreenPosCache.clear(); worldToScreenPosCache.clear();
ReleaseSurfaceVBOs(); ReleaseSurfaceVBOs();
mapSurfaceData.clear(); mapSurfaceData.clear();
} }
@ -680,7 +680,7 @@ void Renderer::endGame(bool isFinalEnd) {
// list3dValid=false; // list3dValid=false;
//} //}
//worldToScreenPosCache.clear(); worldToScreenPosCache.clear();
ReleaseSurfaceVBOs(); ReleaseSurfaceVBOs();
mapSurfaceData.clear(); mapSurfaceData.clear();
} }
@ -1755,7 +1755,9 @@ void Renderer::renderMouse3d() {
modelRenderer->begin(true, true, false); modelRenderer->begin(true, true, false);
const UnitType *building= gui->getBuilding(); const UnitType *building= gui->getBuilding();
renderGhostModel(building, pos); const Gui *gui= game->getGui();
renderGhostModel(building, pos, gui->getSelectedFacing());
modelRenderer->end(); modelRenderer->end();
@ -4593,7 +4595,7 @@ void Renderer::renderTeamColorPlane(){
} }
} }
void Renderer::renderGhostModel(const UnitType *building, const Vec2i pos,Vec4f *forceColor) { void Renderer::renderGhostModel(const UnitType *building, const Vec2i pos,CardinalDir facing, Vec4f *forceColor) {
//const UnitType *building= gui->getBuilding(); //const UnitType *building= gui->getBuilding();
//const Vec2i &pos= gui->getPosObjWorld(); //const Vec2i &pos= gui->getPosObjWorld();
@ -4631,8 +4633,8 @@ void Renderer::renderGhostModel(const UnitType *building, const Vec2i pos,Vec4f
glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, color.ptr()); glMaterialfv(GL_FRONT_AND_BACK, GL_AMBIENT, color.ptr());
Model *buildingModel= building->getFirstStOfClass(scStop)->getAnimation(); Model *buildingModel= building->getFirstStOfClass(scStop)->getAnimation();
if(gui->getSelectedFacing() != CardinalDir::NORTH) { if(facing != CardinalDir::NORTH) {
float rotateAmount = gui->getSelectedFacing() * 90.f; float rotateAmount = facing * 90.f;
if(rotateAmount > 0) { if(rotateAmount > 0) {
glRotatef(rotateAmount, 0.f, 1.f, 0.f); glRotatef(rotateAmount, 0.f, 1.f, 0.f);
} }
@ -4772,7 +4774,6 @@ void Renderer::renderUnitsToBuild(const int renderFps) {
VisibleQuadContainerCache &qCache = getQuadCache(); VisibleQuadContainerCache &qCache = getQuadCache();
if(qCache.visibleQuadUnitBuildList.empty() == false) { if(qCache.visibleQuadUnitBuildList.empty() == false) {
Vec4f modelColor= Vec4f(0.f, 1.f, 0.f, 0.5f);
glMatrixMode(GL_MODELVIEW); glMatrixMode(GL_MODELVIEW);
glPushAttrib(GL_CURRENT_BIT | GL_LIGHTING_BIT | GL_ENABLE_BIT | GL_DEPTH_BUFFER_BIT); glPushAttrib(GL_CURRENT_BIT | GL_LIGHTING_BIT | GL_ENABLE_BIT | GL_DEPTH_BUFFER_BIT);
@ -4786,8 +4787,11 @@ void Renderer::renderUnitsToBuild(const int renderFps) {
for(int visibleUnitIndex = 0; for(int visibleUnitIndex = 0;
visibleUnitIndex < qCache.visibleQuadUnitBuildList.size(); ++visibleUnitIndex) { visibleUnitIndex < qCache.visibleQuadUnitBuildList.size(); ++visibleUnitIndex) {
std::pair<Vec2i, const UnitType *> &buildUnit = qCache.visibleQuadUnitBuildList[visibleUnitIndex]; const UnitBuildInfo &buildUnit = qCache.visibleQuadUnitBuildList[visibleUnitIndex];
renderGhostModel(buildUnit.second, buildUnit.first,&modelColor); //Vec4f modelColor= Vec4f(0.f, 1.f, 0.f, 0.5f);
const Vec3f teamColor = buildUnit.unit->getFaction()->getTexture()->getPixmapConst()->getPixel3f(0,0);
Vec4f modelColor= Vec4f(teamColor.x,teamColor.y,teamColor.z,0.5f);
renderGhostModel(buildUnit.buildUnit, buildUnit.pos, buildUnit.facing, &modelColor);
//printf("Rendering to build unit index = %d\n",visibleUnitIndex); //printf("Rendering to build unit index = %d\n",visibleUnitIndex);
} }
@ -6105,9 +6109,9 @@ bool Renderer::computePosition(const Vec2i &screenPos, Vec2i &worldPos, bool exa
// This method takes world co-ordinates and translates them to screen co-ords // This method takes world co-ordinates and translates them to screen co-ords
Vec3f Renderer::computeScreenPosition(const Vec3f &worldPos) { Vec3f Renderer::computeScreenPosition(const Vec3f &worldPos) {
//if(worldToScreenPosCache.find(worldPos) != worldToScreenPosCache.end()) { if(worldToScreenPosCache.find(worldPos) != worldToScreenPosCache.end()) {
// return worldToScreenPosCache[worldPos]; return worldToScreenPosCache[worldPos];
//} }
assertGl(); assertGl();
const Metrics &metrics= Metrics::getInstance(); const Metrics &metrics= Metrics::getInstance();
@ -6135,7 +6139,7 @@ Vec3f Renderer::computeScreenPosition(const Vec3f &worldPos) {
&screenX, &screenY, &screenZ); &screenX, &screenY, &screenZ);
Vec3f screenPos(screenX,screenY,screenZ); Vec3f screenPos(screenX,screenY,screenZ);
//worldToScreenPosCache[worldPos]=screenPos; worldToScreenPosCache[worldPos]=screenPos;
return screenPos; return screenPos;
} }
@ -8055,6 +8059,7 @@ VisibleQuadContainerCache & Renderer::getQuadCache( bool updateOnDirtyFrame,
//} //}
//else { //else {
quadCache.clearVolatileCacheData(); quadCache.clearVolatileCacheData();
worldToScreenPosCache.clear();
//} //}
// Unit calculations // Unit calculations
@ -8097,8 +8102,8 @@ VisibleQuadContainerCache & Renderer::getQuadCache( bool updateOnDirtyFrame,
bool unitBuildPending = unit->isBuildCommandPending(); bool unitBuildPending = unit->isBuildCommandPending();
if(unitBuildPending == true) { if(unitBuildPending == true) {
std::pair<Vec2i, const UnitType *> pendingUnit = unit->getBuildCommandPendingInfo(); const UnitBuildInfo &pendingUnit = unit->getBuildCommandPendingInfo();
const Vec2i &pos = pendingUnit.first; const Vec2i &pos = pendingUnit.pos;
const Map *map= world->getMap(); const Map *map= world->getMap();
bool unitBuildCheckedForRender = false; bool unitBuildCheckedForRender = false;
@ -8108,8 +8113,8 @@ VisibleQuadContainerCache & Renderer::getQuadCache( bool updateOnDirtyFrame,
if(VisibleQuadContainerCache::enableFrustumCalcs == true) { if(VisibleQuadContainerCache::enableFrustumCalcs == true) {
Vec3f pos3f= Vec3f(pos.x, map->getCell(pos)->getHeight(), pos.y); Vec3f pos3f= Vec3f(pos.x, map->getCell(pos)->getHeight(), pos.y);
//bool insideQuad = PointInFrustum(quadCache.frustumData, unit->getCurrVector().x, unit->getCurrVector().y, unit->getCurrVector().z ); //bool insideQuad = PointInFrustum(quadCache.frustumData, unit->getCurrVector().x, unit->getCurrVector().y, unit->getCurrVector().z );
bool insideQuad = CubeInFrustum(quadCache.frustumData, pos3f.x, pos3f.y, pos3f.z, pendingUnit.second->getSize()); bool insideQuad = CubeInFrustum(quadCache.frustumData, pos3f.x, pos3f.y, pos3f.z, pendingUnit.buildUnit->getSize());
bool renderInMap = world->toRenderUnit(unit,pendingUnit); bool renderInMap = world->toRenderUnit(pendingUnit);
if(insideQuad == false || renderInMap == false) { if(insideQuad == false || renderInMap == false) {
if(renderInMap == true) { if(renderInMap == true) {
quadCache.visibleQuadUnitBuildList.push_back(pendingUnit); quadCache.visibleQuadUnitBuildList.push_back(pendingUnit);
@ -8124,7 +8129,7 @@ VisibleQuadContainerCache & Renderer::getQuadCache( bool updateOnDirtyFrame,
if(unitBuildCheckedForRender == false) { if(unitBuildCheckedForRender == false) {
bool insideQuad = visibleQuad.isInside(pos); bool insideQuad = visibleQuad.isInside(pos);
bool renderInMap = world->toRenderUnit(unit,pendingUnit); bool renderInMap = world->toRenderUnit(pendingUnit);
if(insideQuad == true && renderInMap == true) { if(insideQuad == true && renderInMap == true) {
quadCache.visibleQuadUnitBuildList.push_back(pendingUnit); quadCache.visibleQuadUnitBuildList.push_back(pendingUnit);
} }

View File

@ -159,7 +159,7 @@ public:
Quad2i lastVisibleQuad; Quad2i lastVisibleQuad;
std::vector<Object *> visibleObjectList; std::vector<Object *> visibleObjectList;
std::vector<Unit *> visibleQuadUnitList; std::vector<Unit *> visibleQuadUnitList;
std::vector<std::pair<Vec2i, const UnitType *> > visibleQuadUnitBuildList; std::vector<UnitBuildInfo> visibleQuadUnitBuildList;
std::vector<Unit *> visibleUnitList; std::vector<Unit *> visibleUnitList;
std::vector<Vec2i> visibleScaledCellList; std::vector<Vec2i> visibleScaledCellList;
std::map<Vec2i,Vec3f> visibleScaledCellToScreenPosList; std::map<Vec2i,Vec3f> visibleScaledCellToScreenPosList;
@ -321,7 +321,7 @@ private:
Mutex saveScreenShotThreadAccessor; Mutex saveScreenShotThreadAccessor;
std::list<std::pair<string,Pixmap2D *> > saveScreenQueue; std::list<std::pair<string,Pixmap2D *> > saveScreenQueue;
//std::map<Vec3f,Vec3f> worldToScreenPosCache; std::map<Vec3f,Vec3f> worldToScreenPosCache;
//bool masterserverMode; //bool masterserverMode;
@ -468,7 +468,7 @@ public:
void renderMouse2d(int mouseX, int mouseY, int anim, float fade= 0.f); void renderMouse2d(int mouseX, int mouseY, int anim, float fade= 0.f);
void renderMouse3d(); void renderMouse3d();
void renderGhostModel(const UnitType *building, const Vec2i pos,Vec4f *forceColor=NULL); void renderGhostModel(const UnitType *building, const Vec2i pos,CardinalDir facing,Vec4f *forceColor=NULL);
void renderBackground(const Texture2D *texture); void renderBackground(const Texture2D *texture);
void renderTextureQuad(int x, int y, int w, int h, const Texture2D *texture, float alpha=1.f,const Vec3f *color=NULL); void renderTextureQuad(int x, int y, int w, int h, const Texture2D *texture, float alpha=1.f,const Vec3f *color=NULL);

View File

@ -875,16 +875,17 @@ bool Unit::isBuildCommandPending() const {
return result; return result;
} }
std::pair<Vec2i, const UnitType *> Unit::getBuildCommandPendingInfo() const { UnitBuildInfo Unit::getBuildCommandPendingInfo() const {
std::pair<Vec2i, const UnitType *> result; UnitBuildInfo result;
result.second = NULL;
Command *command= this->getCurrCommand(); Command *command= this->getCurrCommand();
if(command != NULL) { if(command != NULL) {
const BuildCommandType *bct= dynamic_cast<const BuildCommandType*>(command->getCommandType()); const BuildCommandType *bct= dynamic_cast<const BuildCommandType*>(command->getCommandType());
if(bct != NULL) { if(bct != NULL) {
result.first = command->getOriginalPos(); result.pos = command->getOriginalPos();
result.second = command->getUnitType(); result.facing = command->getFacing();
result.buildUnit = command->getUnitType();
result.unit = this;
} }
} }

View File

@ -83,6 +83,19 @@ enum CauseOfDeathType {
ucodStarvedRegeneration ucodStarvedRegeneration
}; };
class UnitBuildInfo {
public:
UnitBuildInfo() {
unit = NULL;
//pos;
buildUnit = NULL;
}
const Unit *unit;
CardinalDir facing;
Vec2i pos;
const UnitType *buildUnit;
};
// ===================================================== // =====================================================
// class UnitObserver // class UnitObserver
// ===================================================== // =====================================================
@ -535,7 +548,7 @@ public:
bool isBeingBuilt() const; bool isBeingBuilt() const;
bool isBuilt() const; bool isBuilt() const;
bool isBuildCommandPending() const; bool isBuildCommandPending() const;
std::pair<Vec2i, const UnitType *> getBuildCommandPendingInfo() const; UnitBuildInfo getBuildCommandPendingInfo() const;
bool isAnimProgressBound() const; bool isAnimProgressBound() const;
bool isPutrefacting() const { bool isPutrefacting() const {

View File

@ -827,21 +827,21 @@ bool World::toRenderUnit(const Unit *unit) const {
map.getSurfaceCell(Map::toSurfCoords(unit->getTargetPos()))->isExplored(thisTeamIndex)); map.getSurfaceCell(Map::toSurfCoords(unit->getTargetPos()))->isExplored(thisTeamIndex));
} }
bool World::toRenderUnit(const Unit *unit, std::pair<Vec2i, const UnitType *> pendingUnit) const { bool World::toRenderUnit(const UnitBuildInfo &pendingUnit) const {
if(unit == NULL) { if(pendingUnit.unit == NULL) {
throw megaglest_runtime_error("unit == NULL"); throw megaglest_runtime_error("unit == NULL");
} }
if(showWorldForPlayer(thisFactionIndex) == true) { if(showWorldForPlayer(thisFactionIndex) == true) {
return true; return true;
} }
if(unit->getTeam() != thisTeamIndex) { if(pendingUnit.unit->getTeam() != thisTeamIndex) {
return false; return false;
} }
return return
(map.getSurfaceCell(Map::toSurfCoords(pendingUnit.first))->isVisible(thisTeamIndex) && (map.getSurfaceCell(Map::toSurfCoords(pendingUnit.pos))->isVisible(thisTeamIndex) &&
map.getSurfaceCell(Map::toSurfCoords(pendingUnit.first))->isExplored(thisTeamIndex) ); map.getSurfaceCell(Map::toSurfCoords(pendingUnit.pos))->isExplored(thisTeamIndex) );
} }
void World::morphToUnit(int unitId,const string &morphName,bool ignoreRequirements) { void World::morphToUnit(int unitId,const string &morphName,bool ignoreRequirements) {

View File

@ -219,7 +219,7 @@ public:
bool toRenderUnit(const Unit *unit, const Quad2i &visibleQuad) const; bool toRenderUnit(const Unit *unit, const Quad2i &visibleQuad) const;
bool toRenderUnit(const Unit *unit) const; bool toRenderUnit(const Unit *unit) const;
bool toRenderUnit(const Unit *unit, std::pair<Vec2i, const UnitType *> pendingUnit) const; bool toRenderUnit(const UnitBuildInfo &pendingUnit) const;
Unit *nearestStore(const Vec2i &pos, int factionIndex, const ResourceType *rt); Unit *nearestStore(const Vec2i &pos, int factionIndex, const ResourceType *rt);