diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index b7abf956..8eb9189d 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -1016,6 +1016,8 @@ void Game::render2d(){ if(config.getBool("DebugMode") && gui.getShowDebugUI() == true) { renderer.renderText(str, coreData.getMenuFontNormal(), Vec3f(1.0f), 10, 500, false); + + renderer.renderUnitTitles(coreData.getMenuFontNormal(),Vec3f(1.0f)); } //network status diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index 8076ed52..8e24ccf9 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -1632,6 +1632,8 @@ void Renderer::renderUnit(RenderEntity &entity,MeshCallbackTeamColor *meshCallba glPopMatrix(); unit->setVisible(true); + // Add to the pending render unit title list + renderUnitTitleList.push_back(std::pair(unit,computeScreenPosition(unit->getCurrVectorFlat())) ); entity.setState(resRendered); } @@ -2196,6 +2198,38 @@ bool Renderer::computePosition(const Vec2i &screenPos, Vec2i &worldPos){ return map->isInside(worldPos); } +// This method takes world co-ordinates and translates them to screen co-ords +Vec3f Renderer::computeScreenPosition(const Vec3f &worldPos) { + assertGl(); + + const Metrics &metrics= Metrics::getInstance(); + GLint viewport[]= {0, 0, metrics.getVirtualW(), metrics.getVirtualH()}; + GLdouble worldX = worldPos.x; + GLdouble worldY = worldPos.y; + GLdouble worldZ = worldPos.z; + + //load matrices + loadProjectionMatrix(); + loadGameCameraMatrix(); + + //get matrices + GLdouble modelviewMatrix[16]; + glGetDoublev(GL_MODELVIEW_MATRIX, modelviewMatrix); + GLdouble projectionMatrix[16]; + glGetDoublev(GL_PROJECTION_MATRIX, projectionMatrix); + + //get the screen coordinates + GLdouble screenX; + GLdouble screenY; + GLdouble screenZ; + gluProject(worldX, worldY, worldZ, + modelviewMatrix, projectionMatrix, viewport, + &screenX, &screenY, &screenZ); + + Vec3f screenPos(screenX,screenY,screenZ); + return screenPos; +} + void Renderer::computeSelected(Selection::UnitContainer &units, const Vec2i &posDown, const Vec2i &posUp){ //declarations @@ -3312,4 +3346,22 @@ Texture2D::Filter Renderer::strToTextureFilter(const string &s){ throw runtime_error("Error converting from string to FilterType, found: "+s); } +// This method renders titles for units +void Renderer::renderUnitTitles(Font2D *font, Vec3f color) { + if(renderUnitTitleList.size() > 0) { + for(int idx = 0; idx < renderUnitTitleList.size(); idx++) { + std::pair &unitInfo = renderUnitTitleList[idx]; + Unit *unit = unitInfo.first; + if(unit != NULL) { + string str = unit->getFullName() + " - " + intToStr(unit->getId()); + //get the screen coordinates + Vec3f &screenPos = unitInfo.second; + renderText(str, font, color, fabs(screenPos.x) + 5, fabs(screenPos.y) + 5, false); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] screenPos.x = %f, screenPos.y = %f, screenPos.z = %f\n",__FILE__,__FUNCTION__,__LINE__,screenPos.x,screenPos.y,screenPos.z); + } + } + renderUnitTitleList.clear(); + } +} + }}//end namespace diff --git a/source/glest_game/graphics/renderer.h b/source/glest_game/graphics/renderer.h index 5edff80f..897d6674 100644 --- a/source/glest_game/graphics/renderer.h +++ b/source/glest_game/graphics/renderer.h @@ -257,6 +257,9 @@ private: bool allowRotateUnits; + //std::vector renderUnitTitleList; + std::vector > renderUnitTitleList; + private: Renderer(); ~Renderer(); @@ -371,6 +374,8 @@ public: static string shadowsToStr(Shadows shadows); const Game * getGame() { return game; } + void renderUnitTitles(Font2D *font, Vec3f color); + Vec3f computeScreenPosition(const Vec3f &worldPos); private: //private misc diff --git a/source/glest_game/gui/gui.h b/source/glest_game/gui/gui.h index f21de80c..0b892803 100644 --- a/source/glest_game/gui/gui.h +++ b/source/glest_game/gui/gui.h @@ -179,7 +179,7 @@ public: void switchToNextDisplayColor(); void onSelectionChanged(); - bool getShowDebugUI() { return showDebugUI; } + bool getShowDebugUI() const { return showDebugUI; } private: diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index 4d4dc6ad..17a72788 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -1267,15 +1267,15 @@ void Unit::logSynchData(string source) { std::string Unit::toString() const { std::string result = ""; -/* - result += "id = " + intToStr(this->id); - result += " name [" + this->getFullName() + "]"; - result += " desc: " + this->getDesc(); -*/ + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + result += "id = " + intToStr(this->id); if(this->type != NULL) { result += " name [" + this->type->getName() + "]"; } + + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + result += " hp = " + intToStr(this->hp); result += " ep = " + intToStr(this->ep); result += " loadCount = " + intToStr(this->loadCount); @@ -1287,9 +1287,14 @@ std::string Unit::toString() const { result += " progress2 = " + intToStr(this->progress2); result += " kills = " + intToStr(this->kills); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(this->targetRef.getUnit() != NULL) { result += " targetRef = " + this->targetRef.getUnit()->toString(); } + + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + result += " currField = " + intToStr(this->currField); result += " targetField = " + intToStr(this->targetField); if(level != NULL) { @@ -1306,6 +1311,8 @@ std::string Unit::toString() const { result += " targetRotation = " + floatToStr(this->targetRotation); result += " rotation = " + floatToStr(this->rotation); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + if(loadType != NULL) { result += " loadType = " + loadType->getName(); } @@ -1318,12 +1325,18 @@ std::string Unit::toString() const { result += " alive = " + intToStr(this->alive); result += " showUnitParticles = " + intToStr(this->showUnitParticles); + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + result += " totalUpgrade = " + totalUpgrade.toString(); result += " " + unitPath.toString() + "\n"; + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + result += "Command count = " + intToStr(commands.size()) + "\n"; + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + int cmdIdx = 0; for(Commands::const_iterator iterList = commands.begin(); iterList != commands.end(); ++iterList) { result += " index = " + intToStr(cmdIdx) + " "; @@ -1334,9 +1347,16 @@ std::string Unit::toString() const { cmdIdx++; } + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + result += "allowRotateUnits = " + intToStr(allowRotateUnits) + "\n"; + + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + result += "modelFacing = " + intToStr(modelFacing.asInt()) + "\n"; + //SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); + return result; } diff --git a/source/shared_lib/sources/util/util.cpp b/source/shared_lib/sources/util/util.cpp index 6eb69ea2..15ef4760 100644 --- a/source/shared_lib/sources/util/util.cpp +++ b/source/shared_lib/sources/util/util.cpp @@ -195,7 +195,7 @@ void SystemFlags::handleDebug(DebugType type, const char *fmt, ...) { va_list argList; va_start(argList, fmt); - char szBuf[1024]=""; + char szBuf[4096]=""; vsprintf(szBuf,fmt, argList); // Either output to a logfile or