diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index d9dc6c7a..52d65f0b 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -394,7 +394,7 @@ void Renderer::initGame(const Game *game, GameCamera *gameCamera) { SurfaceData::nextUniqueId = 1; mapSurfaceData.clear(); this->game= game; - //worldToScreenPosCache.clear(); + worldToScreenPosCache.clear(); //vars shadowMapFrame= 0; @@ -637,7 +637,7 @@ void Renderer::endScenario() { // list3dValid=false; //} - //worldToScreenPosCache.clear(); + worldToScreenPosCache.clear(); ReleaseSurfaceVBOs(); mapSurfaceData.clear(); } @@ -680,7 +680,7 @@ void Renderer::endGame(bool isFinalEnd) { // list3dValid=false; //} - //worldToScreenPosCache.clear(); + worldToScreenPosCache.clear(); ReleaseSurfaceVBOs(); mapSurfaceData.clear(); } @@ -1755,7 +1755,9 @@ void Renderer::renderMouse3d() { modelRenderer->begin(true, true, false); const UnitType *building= gui->getBuilding(); - renderGhostModel(building, pos); + const Gui *gui= game->getGui(); + + renderGhostModel(building, pos, gui->getSelectedFacing()); 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 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()); Model *buildingModel= building->getFirstStOfClass(scStop)->getAnimation(); - if(gui->getSelectedFacing() != CardinalDir::NORTH) { - float rotateAmount = gui->getSelectedFacing() * 90.f; + if(facing != CardinalDir::NORTH) { + float rotateAmount = facing * 90.f; if(rotateAmount > 0) { glRotatef(rotateAmount, 0.f, 1.f, 0.f); } @@ -4772,7 +4774,6 @@ void Renderer::renderUnitsToBuild(const int renderFps) { VisibleQuadContainerCache &qCache = getQuadCache(); if(qCache.visibleQuadUnitBuildList.empty() == false) { - Vec4f modelColor= Vec4f(0.f, 1.f, 0.f, 0.5f); glMatrixMode(GL_MODELVIEW); 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; visibleUnitIndex < qCache.visibleQuadUnitBuildList.size(); ++visibleUnitIndex) { - std::pair &buildUnit = qCache.visibleQuadUnitBuildList[visibleUnitIndex]; - renderGhostModel(buildUnit.second, buildUnit.first,&modelColor); + const UnitBuildInfo &buildUnit = qCache.visibleQuadUnitBuildList[visibleUnitIndex]; + //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); } @@ -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 Vec3f Renderer::computeScreenPosition(const Vec3f &worldPos) { - //if(worldToScreenPosCache.find(worldPos) != worldToScreenPosCache.end()) { - // return worldToScreenPosCache[worldPos]; - //} + if(worldToScreenPosCache.find(worldPos) != worldToScreenPosCache.end()) { + return worldToScreenPosCache[worldPos]; + } assertGl(); const Metrics &metrics= Metrics::getInstance(); @@ -6135,7 +6139,7 @@ Vec3f Renderer::computeScreenPosition(const Vec3f &worldPos) { &screenX, &screenY, &screenZ); Vec3f screenPos(screenX,screenY,screenZ); - //worldToScreenPosCache[worldPos]=screenPos; + worldToScreenPosCache[worldPos]=screenPos; return screenPos; } @@ -8055,6 +8059,7 @@ VisibleQuadContainerCache & Renderer::getQuadCache( bool updateOnDirtyFrame, //} //else { quadCache.clearVolatileCacheData(); + worldToScreenPosCache.clear(); //} // Unit calculations @@ -8097,8 +8102,8 @@ VisibleQuadContainerCache & Renderer::getQuadCache( bool updateOnDirtyFrame, bool unitBuildPending = unit->isBuildCommandPending(); if(unitBuildPending == true) { - std::pair pendingUnit = unit->getBuildCommandPendingInfo(); - const Vec2i &pos = pendingUnit.first; + const UnitBuildInfo &pendingUnit = unit->getBuildCommandPendingInfo(); + const Vec2i &pos = pendingUnit.pos; const Map *map= world->getMap(); bool unitBuildCheckedForRender = false; @@ -8108,8 +8113,8 @@ VisibleQuadContainerCache & Renderer::getQuadCache( bool updateOnDirtyFrame, if(VisibleQuadContainerCache::enableFrustumCalcs == true) { 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 = CubeInFrustum(quadCache.frustumData, pos3f.x, pos3f.y, pos3f.z, pendingUnit.second->getSize()); - bool renderInMap = world->toRenderUnit(unit,pendingUnit); + bool insideQuad = CubeInFrustum(quadCache.frustumData, pos3f.x, pos3f.y, pos3f.z, pendingUnit.buildUnit->getSize()); + bool renderInMap = world->toRenderUnit(pendingUnit); if(insideQuad == false || renderInMap == false) { if(renderInMap == true) { quadCache.visibleQuadUnitBuildList.push_back(pendingUnit); @@ -8124,7 +8129,7 @@ VisibleQuadContainerCache & Renderer::getQuadCache( bool updateOnDirtyFrame, if(unitBuildCheckedForRender == false) { bool insideQuad = visibleQuad.isInside(pos); - bool renderInMap = world->toRenderUnit(unit,pendingUnit); + bool renderInMap = world->toRenderUnit(pendingUnit); if(insideQuad == true && renderInMap == true) { quadCache.visibleQuadUnitBuildList.push_back(pendingUnit); } diff --git a/source/glest_game/graphics/renderer.h b/source/glest_game/graphics/renderer.h index e21b78f7..7f9797d0 100644 --- a/source/glest_game/graphics/renderer.h +++ b/source/glest_game/graphics/renderer.h @@ -159,7 +159,7 @@ public: Quad2i lastVisibleQuad; std::vector visibleObjectList; std::vector visibleQuadUnitList; - std::vector > visibleQuadUnitBuildList; + std::vector visibleQuadUnitBuildList; std::vector visibleUnitList; std::vector visibleScaledCellList; std::map visibleScaledCellToScreenPosList; @@ -321,7 +321,7 @@ private: Mutex saveScreenShotThreadAccessor; std::list > saveScreenQueue; - //std::map worldToScreenPosCache; + std::map worldToScreenPosCache; //bool masterserverMode; @@ -468,7 +468,7 @@ public: void renderMouse2d(int mouseX, int mouseY, int anim, float fade= 0.f); 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 renderTextureQuad(int x, int y, int w, int h, const Texture2D *texture, float alpha=1.f,const Vec3f *color=NULL); diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index e0e2d7e0..cbfd1363 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -875,16 +875,17 @@ bool Unit::isBuildCommandPending() const { return result; } -std::pair Unit::getBuildCommandPendingInfo() const { - std::pair result; - result.second = NULL; +UnitBuildInfo Unit::getBuildCommandPendingInfo() const { + UnitBuildInfo result; Command *command= this->getCurrCommand(); if(command != NULL) { const BuildCommandType *bct= dynamic_cast(command->getCommandType()); if(bct != NULL) { - result.first = command->getOriginalPos(); - result.second = command->getUnitType(); + result.pos = command->getOriginalPos(); + result.facing = command->getFacing(); + result.buildUnit = command->getUnitType(); + result.unit = this; } } diff --git a/source/glest_game/type_instances/unit.h b/source/glest_game/type_instances/unit.h index 69bec62a..82595929 100644 --- a/source/glest_game/type_instances/unit.h +++ b/source/glest_game/type_instances/unit.h @@ -83,6 +83,19 @@ enum CauseOfDeathType { ucodStarvedRegeneration }; +class UnitBuildInfo { +public: + UnitBuildInfo() { + unit = NULL; + //pos; + buildUnit = NULL; + } + const Unit *unit; + CardinalDir facing; + Vec2i pos; + const UnitType *buildUnit; +}; + // ===================================================== // class UnitObserver // ===================================================== @@ -535,7 +548,7 @@ public: bool isBeingBuilt() const; bool isBuilt() const; bool isBuildCommandPending() const; - std::pair getBuildCommandPendingInfo() const; + UnitBuildInfo getBuildCommandPendingInfo() const; bool isAnimProgressBound() const; bool isPutrefacting() const { diff --git a/source/glest_game/world/world.cpp b/source/glest_game/world/world.cpp index c2826951..83a9763d 100644 --- a/source/glest_game/world/world.cpp +++ b/source/glest_game/world/world.cpp @@ -827,21 +827,21 @@ bool World::toRenderUnit(const Unit *unit) const { map.getSurfaceCell(Map::toSurfCoords(unit->getTargetPos()))->isExplored(thisTeamIndex)); } -bool World::toRenderUnit(const Unit *unit, std::pair pendingUnit) const { - if(unit == NULL) { +bool World::toRenderUnit(const UnitBuildInfo &pendingUnit) const { + if(pendingUnit.unit == NULL) { throw megaglest_runtime_error("unit == NULL"); } if(showWorldForPlayer(thisFactionIndex) == true) { return true; } - if(unit->getTeam() != thisTeamIndex) { + if(pendingUnit.unit->getTeam() != thisTeamIndex) { return false; } return - (map.getSurfaceCell(Map::toSurfCoords(pendingUnit.first))->isVisible(thisTeamIndex) && - map.getSurfaceCell(Map::toSurfCoords(pendingUnit.first))->isExplored(thisTeamIndex) ); + (map.getSurfaceCell(Map::toSurfCoords(pendingUnit.pos))->isVisible(thisTeamIndex) && + map.getSurfaceCell(Map::toSurfCoords(pendingUnit.pos))->isExplored(thisTeamIndex) ); } void World::morphToUnit(int unitId,const string &morphName,bool ignoreRequirements) { diff --git a/source/glest_game/world/world.h b/source/glest_game/world/world.h index b36b70da..1e72e228 100644 --- a/source/glest_game/world/world.h +++ b/source/glest_game/world/world.h @@ -219,7 +219,7 @@ public: bool toRenderUnit(const Unit *unit, const Quad2i &visibleQuad) const; bool toRenderUnit(const Unit *unit) const; - bool toRenderUnit(const Unit *unit, std::pair pendingUnit) const; + bool toRenderUnit(const UnitBuildInfo &pendingUnit) const; Unit *nearestStore(const Vec2i &pos, int factionIndex, const ResourceType *rt);