From 9ef8c82441e696ddf59c12a8a08078f1ebb7d611 Mon Sep 17 00:00:00 2001 From: Titus Tscharntke Date: Wed, 6 Jul 2011 22:02:38 +0000 Subject: [PATCH] extra team color markers ( by default use * to toggle/switch on ) --- mk/linux/glestkeys.ini | 1 + source/glest_game/game/game.cpp | 21 +++++++ source/glest_game/game/game.h | 6 ++ source/glest_game/global/core_data.cpp | 5 ++ source/glest_game/global/core_data.h | 2 + source/glest_game/graphics/renderer.cpp | 81 +++++++++++++++++++++++-- source/glest_game/graphics/renderer.h | 5 +- 7 files changed, 116 insertions(+), 5 deletions(-) diff --git a/mk/linux/glestkeys.ini b/mk/linux/glestkeys.ini index 7872069b..47d62072 100644 --- a/mk/linux/glestkeys.ini +++ b/mk/linux/glestkeys.ini @@ -14,6 +14,7 @@ ChangeFontColor=C GameSpeedIncrease='+' GameSpeedDecrease='-' ExitKey=escape +ExtraTeamColorMarker='*' GroupUnitsKey1='0' GroupUnitsKey2='1' GroupUnitsKey3='2' diff --git a/source/glest_game/game/game.cpp b/source/glest_game/game/game.cpp index 45c2d130..41b4c507 100644 --- a/source/glest_game/game/game.cpp +++ b/source/glest_game/game/game.cpp @@ -66,6 +66,7 @@ Game::Game(Program *program, const GameSettings *gameSettings): lastRenderLog2d = 0; totalRenderFps = 0; lastMaxUnitCalcTime = 0; + renderExtraTeamColor = 0; mouseMoved= false; quitTriggeredIndicator = false; @@ -1598,6 +1599,10 @@ void Game::keyDown(SDL_KeyboardEvent key) { //printf("Toggle pause paused = %d\n",paused); setPaused(!paused); } + else if(isKeyPressed(configKeys.getSDLKey("ExtraTeamColorMarker"),key, false) == true) { + //printf("Toggle ExtraTeamColorMarker\n"); + toggleTeamColorMarker(); + } //switch display color //else if(key == configKeys.getCharKey("ChangeFontColor")) { else if(isKeyPressed(configKeys.getSDLKey("ChangeFontColor"),key, false) == true) { @@ -1895,11 +1900,23 @@ void Game::render3d(){ if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] renderFps = %d took msecs: %lld [renderSelectionEffects]\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start(); + // renderTeamColorCircle + if((renderExtraTeamColor&renderTeamColorCircleBit)>0){ + renderer.renderTeamColorCircle(); + if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] renderFps = %d took msecs: %lld [renderObjects]\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start(); + } //units renderer.renderUnits(avgRenderFps); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] renderFps = %d took msecs: %lld [renderUnits]\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start(); + // renderTeamColorPlane + if((renderExtraTeamColor&renderTeamColorPlaneBit)>0){ + renderer.renderTeamColorPlane(); + if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] renderFps = %d took msecs: %lld [renderObjects]\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); + if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) chrono.start(); + } //objects renderer.renderObjects(avgRenderFps); if(SystemFlags::getSystemSettingType(SystemFlags::debugPerformance).enabled && chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s Line: %d] renderFps = %d took msecs: %lld [renderObjects]\n",__FILE__,__FUNCTION__,__LINE__,renderFps,chrono.getMillis()); @@ -2475,5 +2492,9 @@ Vec2i Game::getPerformanceTimerResults() { void Game::consoleAddLine(string line) { console.addLine(line); } +void Game::toggleTeamColorMarker() { + renderExtraTeamColor++; + renderExtraTeamColor=renderExtraTeamColor%4; +} }}//end namespace diff --git a/source/glest_game/game/game.h b/source/glest_game/game/game.h index 0824701a..5fa0b5fb 100644 --- a/source/glest_game/game/game.h +++ b/source/glest_game/game/game.h @@ -114,6 +114,10 @@ private: int updateFpsAvgTest; int renderFpsAvgTest; + int renderExtraTeamColor; + static const int renderTeamColorCircleBit=1; + static const int renderTeamColorPlaneBit=2; + bool photoModeEnabled; bool visibleHUD; bool withRainEffect; @@ -146,6 +150,8 @@ public: bool getPaused() const { return paused;} void setPaused(bool value); const int getTotalRenderFps() const {return totalRenderFps;} + + void toggleTeamColorMarker(); //init virtual void load(LoadGameItem loadTypes); virtual void load(); diff --git a/source/glest_game/global/core_data.cpp b/source/glest_game/global/core_data.cpp index 57b65fec..86058d19 100644 --- a/source/glest_game/global/core_data.cpp +++ b/source/glest_game/global/core_data.cpp @@ -64,6 +64,11 @@ void CoreData::load() { fireTexture->getPixmap()->init(1); fireTexture->getPixmap()->load(dir+"/misc_textures/fire_particle.tga"); + teamColorTexture= renderer.newTexture2D(rsGlobal); + teamColorTexture->setFormat(Texture::fAlpha); + teamColorTexture->getPixmap()->init(1); + teamColorTexture->getPixmap()->load(dir+"/misc_textures/team_color_texture.tga"); + snowTexture= renderer.newTexture2D(rsGlobal); snowTexture->setMipmap(false); snowTexture->setFormat(Texture::fAlpha); diff --git a/source/glest_game/global/core_data.h b/source/glest_game/global/core_data.h index 51875bd5..c4bfa9f3 100644 --- a/source/glest_game/global/core_data.h +++ b/source/glest_game/global/core_data.h @@ -50,6 +50,7 @@ private: std::vector logoTextureList; Texture2D *backgroundTexture; Texture2D *fireTexture; + Texture2D *teamColorTexture; Texture2D *snowTexture; Texture2D *waterSplashTexture; Texture2D *customTexture; @@ -83,6 +84,7 @@ public: Texture2D *getBackgroundTexture() const {return backgroundTexture;} Texture2D *getFireTexture() const {return fireTexture;} + Texture2D *getTeamColorTexture() const {return teamColorTexture;} Texture2D *getSnowTexture() const {return snowTexture;} Texture2D *getLogoTexture() const {return logoTexture;} Texture2D *getWaterSplashTexture() const {return waterSplashTexture;} diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index fef0d395..f0a237b9 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -2946,6 +2946,54 @@ void Renderer::renderWater() { assertGl(); } +void Renderer::renderTeamColorCircle(){ + VisibleQuadContainerCache &qCache = getQuadCache(); + if(qCache.visibleQuadUnitList.size() > 0) { + + glPushAttrib(GL_ENABLE_BIT | GL_CURRENT_BIT | GL_DEPTH_BUFFER_BIT); + glDisable(GL_LIGHTING); + glDisable(GL_TEXTURE_2D); + glDepthFunc(GL_ALWAYS); + glDisable(GL_STENCIL_TEST); + glDisable(GL_CULL_FACE); + glEnable(GL_BLEND); + glLineWidth(2.f); + + for(int visibleUnitIndex = 0; + visibleUnitIndex < qCache.visibleQuadUnitList.size(); ++visibleUnitIndex) { + Unit *unit = qCache.visibleQuadUnitList[visibleUnitIndex]; + Vec3f currVec= unit->getCurrVectorFlat(); + Vec3f color=unit->getFaction()->getTexture()->getPixmapConst()->getPixel3f(0,0); + glColor4f(color.x, color.y, color.z, 0.7f); + renderSelectionCircle(currVec, unit->getType()->getSize(), 0.8f, 0.05f); + } + glPopAttrib(); + } +} + +void Renderer::renderTeamColorPlane(){ + VisibleQuadContainerCache &qCache = getQuadCache(); + if(qCache.visibleQuadUnitList.size() > 0){ + glPushAttrib(GL_ENABLE_BIT); + glDisable(GL_LIGHTING); + glEnable(GL_TEXTURE_2D); + glEnable(GL_BLEND); + glEnable(GL_COLOR_MATERIAL); + const Texture2D *texture=CoreData::getInstance().getTeamColorTexture(); + for(int visibleUnitIndex = 0; + visibleUnitIndex < qCache.visibleQuadUnitList.size(); ++visibleUnitIndex){ + Unit *unit = qCache.visibleQuadUnitList[visibleUnitIndex]; + Vec3f currVec= unit->getCurrVectorFlat(); + renderTeamColorEffect(currVec,visibleUnitIndex,unit->getType()->getSize(), + unit->getFaction()->getTexture()->getPixmapConst()->getPixel3f(0,0),texture); + } + glDisable(GL_COLOR_MATERIAL); + glPopAttrib(); + } +} + + + void Renderer::renderUnits(const int renderFps) { Unit *unit=NULL; const World *world= game->getWorld(); @@ -3055,8 +3103,34 @@ void Renderer::renderUnits(const int renderFps) { glAlphaFunc(GL_GREATER, 0.0f); //assert assertGl(); + } +void Renderer::renderTeamColorEffect(Vec3f &v, int heigth, int size, Vec3f color, const Texture2D *texture) { + GLUquadricObj *disc; + float halfSize=size; + halfSize=halfSize; + float heigthoffset=0.5+heigth%25*0.004; + glPushMatrix(); + glBindTexture(GL_TEXTURE_2D, static_cast(texture)->getHandle()); + glColor4f(color.x, color.y, color.z, 1.0f); + glBegin(GL_TRIANGLE_STRIP); + glTexCoord2i(0, 1); + glVertex3f(v.x-halfSize,v.y+heigthoffset,v.z+halfSize); + glTexCoord2i(0, 0); + glVertex3f(v.x-halfSize,v.y+heigthoffset, v.z-halfSize); + glTexCoord2i(1, 1); + + glVertex3f(v.x+halfSize,v.y+heigthoffset, v.z+halfSize); + glTexCoord2i(1, 0); + glVertex3f(v.x+halfSize,v.y+heigthoffset, v.z-halfSize); + glEnd(); + glPopMatrix(); + +} + + + void Renderer::renderSelectionEffects() { const World *world= game->getWorld(); @@ -3336,10 +3410,9 @@ void Renderer::renderWaterEffects(){ } void Renderer::renderHud(){ - const Metrics &metrics= Metrics::getInstance(); - const World *world= game->getWorld(); Texture2D *hudTexture=game->getGui()->getHudTexture(); if(hudTexture!=NULL){ + const Metrics &metrics= Metrics::getInstance(); renderTextureQuad(0, 0, metrics.getVirtualW(), metrics.getVirtualH(),hudTexture,1.0f); } } @@ -5056,7 +5129,7 @@ void Renderer::enableProjectiveTexturing() { // ==================== private aux drawing ==================== -void Renderer::renderSelectionCircle(Vec3f v, int size, float radius) { +void Renderer::renderSelectionCircle(Vec3f v, int size, float radius, float thickness) { GLUquadricObj *disc; glMatrixMode(GL_MODELVIEW); @@ -5066,7 +5139,7 @@ void Renderer::renderSelectionCircle(Vec3f v, int size, float radius) { glRotatef(90.f, 1.f, 0.f, 0.f); disc= gluNewQuadric(); gluQuadricDrawStyle(disc, GLU_FILL); - gluCylinder(disc, radius*(size-0.2f), radius*size, 0.2f, 30, 1); + gluCylinder(disc, radius*(size-thickness), radius*size, thickness, 30, 1); gluDeleteQuadric(disc); glPopMatrix(); diff --git a/source/glest_game/graphics/renderer.h b/source/glest_game/graphics/renderer.h index 0057c61d..533b4bb0 100644 --- a/source/glest_game/graphics/renderer.h +++ b/source/glest_game/graphics/renderer.h @@ -424,6 +424,8 @@ public: void loadConfig(); void saveScreen(const string &path); Quad2i getVisibleQuad() const {return visibleQuad;} + void renderTeamColorPlane(); + void renderTeamColorCircle(); //static static Shadows strToShadows(const string &s); @@ -495,7 +497,8 @@ private: void enableProjectiveTexturing(); //private aux drawing - void renderSelectionCircle(Vec3f v, int size, float radius); + void renderSelectionCircle(Vec3f v, int size, float radius, float thickness=0.2f); + void renderTeamColorEffect(Vec3f &v, int heigth, int size, Vec3f color, const Texture2D *texture); void renderArrow(const Vec3f &pos1, const Vec3f &pos2, const Vec3f &color, float width); void renderTile(const Vec2i &pos); void renderQuad(int x, int y, int w, int h, const Texture2D *texture);