From 6f0e3c0c089ecf99af003913a69e780a2a3861f8 Mon Sep 17 00:00:00 2001 From: Marianne Gagnon Date: Fri, 11 Jul 2014 20:50:42 -0400 Subject: [PATCH] Remove useless RTT and simplify rendering of icons on the minimap --- src/karts/kart_properties.cpp | 6 ++ src/states_screens/race_gui.cpp | 39 +++++----- src/states_screens/race_gui.hpp | 4 +- src/states_screens/race_gui_base.cpp | 90 +---------------------- src/states_screens/race_gui_base.hpp | 6 +- src/states_screens/race_gui_overworld.cpp | 27 +++---- src/states_screens/race_gui_overworld.hpp | 4 +- 7 files changed, 46 insertions(+), 130 deletions(-) diff --git a/src/karts/kart_properties.cpp b/src/karts/kart_properties.cpp index 68706516e..c9fb3cb4f 100644 --- a/src/karts/kart_properties.cpp +++ b/src/karts/kart_properties.cpp @@ -21,6 +21,7 @@ #include "addons/addon.hpp" #include "config/stk_config.hpp" #include "config/player_manager.hpp" +#include "graphics/glwrap.hpp" #include "graphics/irr_driver.hpp" #include "graphics/material_manager.hpp" #include "io/file_manager.hpp" @@ -243,6 +244,11 @@ void KartProperties::load(const std::string &filename, const std::string &node) else m_minimap_icon = NULL; + if (m_minimap_icon == NULL) + { + m_minimap_icon = getUnicolorTexture(m_color); + } + // Only load the model if the .kart file has the appropriate version, // otherwise warnings are printed. if (m_version >= 1) diff --git a/src/states_screens/race_gui.cpp b/src/states_screens/race_gui.cpp index 38b43a193..2b1c492e1 100644 --- a/src/states_screens/race_gui.cpp +++ b/src/states_screens/race_gui.cpp @@ -63,9 +63,9 @@ RaceGUI::RaceGUI() // Originally m_map_height was 100, and we take 480 as minimum res const float scaling = irr_driver->getFrameSize().Height / 480.0f; // Marker texture has to be power-of-two for (old) OpenGL compliance - m_marker_rendered_size = 2 << ((int) ceil(1.0 + log(32.0 * scaling))); - m_marker_ai_size = (int)( 14.0f * scaling); - m_marker_player_size = (int)( 16.0f * scaling); + //m_marker_rendered_size = 2 << ((int) ceil(1.0 + log(32.0 * scaling))); + m_minimap_ai_size = (int)( 14.0f * scaling); + m_minimap_player_size = (int)( 16.0f * scaling); m_map_width = (int)(100.0f * scaling); m_map_height = (int)(100.0f * scaling); m_map_left = (int)( 10.0f * scaling); @@ -87,7 +87,7 @@ RaceGUI::RaceGUI() m_speed_meter_icon = material_manager->getMaterial("speedback.png"); m_speed_bar_icon = material_manager->getMaterial("speedfore.png"); - createMarkerTexture(); + //createMarkerTexture(); // Determine maximum length of the rank/lap text, in order to // align those texts properly on the right side of the viewport. @@ -238,15 +238,17 @@ void RaceGUI::drawScores() irr::video::ITexture *team_icon; int numLeader = 1; - for(unsigned int i=0; igetNumKarts(); i++){ + for(unsigned int i=0; igetNumKarts(); i++) + { int j = soccerWorld->getTeamLeader(i); if(j < 0) break; - core::rect source(j*m_marker_rendered_size, 0, - (j+1)*m_marker_rendered_size,m_marker_rendered_size); + AbstractKart* kart = soccerWorld->getKart(i); + video::ITexture* icon = kart->getKartProperties()->getMinimapIcon(); + core::rect source(core::position2di(0, 0), icon->getSize()); core::recti position(offsetX, offsetY, - offsetX + 2*m_marker_player_size, offsetY + 2*m_marker_player_size); - draw2DImage(m_marker, position, source, + offsetX + 2*m_minimap_player_size, offsetY + 2*m_minimap_player_size); + draw2DImage(icon, position, source, NULL, NULL, true); core::stringw score = StringUtils::toWString(soccerWorld->getScore(i)); int string_height = @@ -265,8 +267,8 @@ void RaceGUI::drawScores() default: break; } core::rect indicatorPos(offsetX, offsetY, - offsetX + (int)(m_marker_player_size/1.25f), - offsetY + (int)(m_marker_player_size/1.25f)); + offsetX + (int)(m_minimap_player_size/1.25f), + offsetY + (int)(m_minimap_player_size/1.25f)); core::rect sourceRect(core::position2d(0,0), team_icon->getOriginalSize()); draw2DImage(team_icon,indicatorPos,sourceRect, @@ -373,20 +375,19 @@ void RaceGUI::drawGlobalMiniMap() const Vec3& xyz = kart->getXYZ(); Vec3 draw_at; world->getTrack()->mapPoint2MiniMap(xyz, &draw_at); + + video::ITexture* icon = kart->getKartProperties()->getMinimapIcon(); + // int marker_height = m_marker->getOriginalSize().Height; - core::rect source(i *m_marker_rendered_size, - 0, - (i+1)*m_marker_rendered_size, - m_marker_rendered_size); + core::rect source(core::position2di(0, 0), icon->getSize()); int marker_half_size = (kart->getController()->isPlayerController() - ? m_marker_player_size - : m_marker_ai_size )>>1; + ? m_minimap_player_size + : m_minimap_ai_size )>>1; core::rect position(m_map_left+(int)(draw_at.getX()-marker_half_size), lower_y -(int)(draw_at.getY()+marker_half_size), m_map_left+(int)(draw_at.getX()+marker_half_size), lower_y -(int)(draw_at.getY()-marker_half_size)); - draw2DImage(m_marker, position, source, - NULL, NULL, true); + draw2DImage(icon, position, source, NULL, NULL, true); } // for iremoveTexture(m_marker); + //irr_driver->removeTexture(m_marker); // If the referee is currently being shown, // remove it from the scene graph. delete m_referee; } // ~RaceGUIBase -//----------------------------------------------------------------------------- -/** Creates a texture with the markers for all karts in the current race - * on it. This assumes that nothing is attached to the scene node at - * this stage. - */ -void RaceGUIBase::createMarkerTexture() -{ - unsigned int num_karts = race_manager->getNumberOfKarts(); - unsigned int npower2 = 1; - // Textures must be power of 2, so - while(npower2>1)-1; - IrrDriver::RTTProvider rttProvider(core::dimension2du(m_marker_rendered_size - *npower2, - m_marker_rendered_size), - "RaceGUI::markers", true); - scene::ICameraSceneNode *camera = irr_driver->addCameraSceneNode(); - core::matrix4 projection; - projection.buildProjectionMatrixOrthoLH((float)(m_marker_rendered_size*npower2), - (float)(m_marker_rendered_size), - -1.0f, 1.0f); - camera->setProjectionMatrix(projection, true); - core::vector3df center( (float)(m_marker_rendered_size*npower2>>1), - (float)(m_marker_rendered_size>>1), 0.0f); - camera->setPosition(center); - camera->setUpVector(core::vector3df(0,1,0)); - camera->setTarget(center + core::vector3df(0,0,4)); - // The call to render sets the projection matrix etc. So we have to call - // this now before doing the direct OpenGL calls. - // FIXME: perhaps we should use three calls to irr_driver: begin(), - // render(), end() - so we could do the rendering by calling to - // draw2DPolygon() between render() and end(), avoiding the - // call to camera->render() - camera->render(); - // We have to reset the material here, since otherwise the last - // set material (i.e from the kart selection screen) will be used - // when rednering to the texture. - video::SMaterial m; - m.setTexture(0, NULL); - irr_driver->getVideoDriver()->setMaterial(m); - for(unsigned int i=0; igetKartIdent(i); - assert(kart_ident.size() > 0); - - const KartProperties *kp=kart_properties_manager->getKart(kart_ident); - assert(kp != NULL); - - core::vector2df center((float)((m_marker_rendered_size>>1) - +i*m_marker_rendered_size), - (float)(m_marker_rendered_size>>1) ); - int count = kp->getShape(); - video::ITexture *t = kp->getMinimapIcon(); - if(t) - { - video::ITexture *t = kp->getIconMaterial()->getTexture(); - core::recti dest_rect(i*m_marker_rendered_size, - 0, - (i+1)*m_marker_rendered_size, - m_marker_rendered_size); - core::recti source_rect(core::vector2di(0,0), t->getSize()); - draw2DImage(t, dest_rect, - source_rect, - /*clipRect*/0, - /*color*/ 0, - /*useAlpha*/true); - } - else // no special minimap icon defined - { - video::S3DVertex *vertices = new video::S3DVertex[count+1]; - unsigned short int *index = new unsigned short int[count+1]; - video::SColor color = kp->getColor(); - createRegularPolygon(count, (float)radius, center, color, - vertices, index); - irr_driver->getVideoDriver()->draw2DVertexPrimitiveList(vertices, - count, index, count-2, - video::EVT_STANDARD, - scene::EPT_TRIANGLE_FAN); - delete [] vertices; - delete [] index; - } // if special minimap icon defined - } - - m_marker = rttProvider.renderToTexture(-1, /*is_2d_render*/true); - irr_driver->removeCameraSceneNode(camera); -} // createMarkerTexture - //----------------------------------------------------------------------------- /** Creates the 2D vertices for a regular polygon. Adopted from Irrlicht. * \param n Number of vertices to use. diff --git a/src/states_screens/race_gui_base.hpp b/src/states_screens/race_gui_base.hpp index 55bce3039..05a20beb7 100644 --- a/src/states_screens/race_gui_base.hpp +++ b/src/states_screens/race_gui_base.hpp @@ -170,10 +170,10 @@ protected: core::vector2df m_plunger_speed; /** The size of a single marker in pixels, must be a power of 2. */ - int m_marker_rendered_size; + //int m_marker_rendered_size; /** A texture with all mini dots to be displayed in the minimap for all karts. */ - video::ITexture *m_marker; + //video::ITexture *m_marker; video::ITexture *m_gauge_empty; /** Default texture for nitro gauge. */ video::ITexture *m_gauge_full; @@ -186,7 +186,7 @@ protected: Material *m_icons_frame; void cleanupMessages(const float dt); - void createMarkerTexture(); + //void createMarkerTexture(); void createRegularPolygon(unsigned int n, float radius, const core::vector2df ¢er, const video::SColor &color, diff --git a/src/states_screens/race_gui_overworld.cpp b/src/states_screens/race_gui_overworld.cpp index a2a7299f8..f7cd19e05 100644 --- a/src/states_screens/race_gui_overworld.cpp +++ b/src/states_screens/race_gui_overworld.cpp @@ -77,11 +77,11 @@ RaceGUIOverworld::RaceGUIOverworld() const float scaling = irr_driver->getFrameSize().Height / 420.0f; // Marker texture has to be power-of-two for (old) OpenGL compliance - m_marker_rendered_size = 2 << ((int) ceil(1.0 + log(32.0 * scaling))); - m_marker_challenge_size = (int)( 12.0f * scaling); - m_marker_player_size = (int)( 24.0f * scaling); - m_map_width = (int)(250.0f * scaling); - m_map_height = (int)(250.0f * scaling); + //m_marker_rendered_size = 2 << ((int) ceil(1.0 + log(32.0 * scaling))); + m_minimap_challenge_size = (int)( 12.0f * scaling); + m_minimap_player_size = (int)( 24.0f * scaling); + m_map_width = (int)(250.0f * scaling); + m_map_height = (int)(250.0f * scaling); m_map_left = 20; m_map_bottom = UserConfigParams::m_height-10; @@ -100,7 +100,7 @@ RaceGUIOverworld::RaceGUIOverworld() m_speed_meter_icon = material_manager->getMaterial("speedback.png"); m_speed_bar_icon = material_manager->getMaterial("speedfore.png"); - createMarkerTexture(); + //createMarkerTexture(); // Translate strings only one in constructor to avoid calling // gettext in each frame. @@ -363,13 +363,11 @@ void RaceGUIOverworld::drawGlobalMiniMap() Vec3 draw_at; track->mapPoint2MiniMap(kart_xyz, &draw_at); - core::rect source(i *m_marker_rendered_size, - 0, - (i+1)*m_marker_rendered_size, - m_marker_rendered_size); + video::ITexture* icon = kart->getKartProperties()->getMinimapIcon(); + core::rect source(core::position2di(0, 0), icon->getSize()); int marker_half_size = (kart->getController()->isPlayerController() - ? m_marker_player_size - : m_marker_challenge_size )>>1; + ? m_minimap_player_size + : m_minimap_challenge_size )>>1; core::rect position(m_map_left+(int)(draw_at.getX()-marker_half_size), lower_y -(int)(draw_at.getY()+marker_half_size), m_map_left+(int)(draw_at.getX()+marker_half_size), @@ -390,8 +388,7 @@ void RaceGUIOverworld::drawGlobalMiniMap() rect, NULL, colors, true); } // if isPlayerController - draw2DImage(m_marker, position, source, - NULL, NULL, true); + draw2DImage(icon, position, source, NULL, NULL, true); } // for i source(core::position2d(0,0), m_icons[state]->getOriginalSize()); - int marker_size = m_marker_challenge_size; + int marker_size = m_minimap_challenge_size; core::position2di mouse = irr_driver->getMouseLocation(); core::rect dest(m_map_left+(int)(draw_at.getX()-marker_size/2), lower_y -(int)(draw_at.getY()+marker_size/2), diff --git a/src/states_screens/race_gui_overworld.hpp b/src/states_screens/race_gui_overworld.hpp index beed1b9c2..950c2d9bd 100644 --- a/src/states_screens/race_gui_overworld.hpp +++ b/src/states_screens/race_gui_overworld.hpp @@ -75,11 +75,11 @@ private: /** The size of a single marker on the screen for AI karts, * need not be a power of 2. */ - int m_marker_challenge_size; + int m_minimap_challenge_size; /** The size of a single marker on the screen or player karts, * need not be a power of 2. */ - int m_marker_player_size; + int m_minimap_player_size; /** The width of the rendered mini map in pixels, must be a power of 2. */ int m_map_rendered_width;