- Added ability to render text titles for each unit (currently used to debug)
This commit is contained in:
parent
50fe71a651
commit
7753435b3a
|
@ -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
|
||||
|
|
|
@ -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 *,Vec3f>(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<Unit *,Vec3f> &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
|
||||
|
|
|
@ -257,6 +257,9 @@ private:
|
|||
|
||||
bool allowRotateUnits;
|
||||
|
||||
//std::vector<Unit *> renderUnitTitleList;
|
||||
std::vector<std::pair<Unit *,Vec3f> > 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
|
||||
|
|
|
@ -179,7 +179,7 @@ public:
|
|||
void switchToNextDisplayColor();
|
||||
void onSelectionChanged();
|
||||
|
||||
bool getShowDebugUI() { return showDebugUI; }
|
||||
bool getShowDebugUI() const { return showDebugUI; }
|
||||
|
||||
private:
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue