From 991e6fe683ae0ff8b90e583388ea6709baeb587c Mon Sep 17 00:00:00 2001 From: rt Date: Mon, 28 May 2018 20:12:50 +0200 Subject: [PATCH] fix #5247 --- rts/Game/Game.cpp | 23 ++++------ rts/Game/UI/MiniMap.cpp | 98 +++++++++++++++++++++++------------------ rts/Game/UI/MiniMap.h | 2 +- rts/Lua/LuaOpenGL.cpp | 14 +++--- 4 files changed, 70 insertions(+), 67 deletions(-) diff --git a/rts/Game/Game.cpp b/rts/Game/Game.cpp index 009296b42f7..5375eda3273 100644 --- a/rts/Game/Game.cpp +++ b/rts/Game/Game.cpp @@ -1145,7 +1145,6 @@ bool CGame::UpdateUnsynced(const spring_time currentTime) } - const bool doDrawWorld = hideInterface || !minimap->GetMaximized() || minimap->GetMinimized(); const bool newSimFrame = (lastSimFrame != gs->frameNum); const bool forceUpdate = (unsyncedUpdateDeltaTime >= (1.0f / GAME_SPEED)); @@ -1161,12 +1160,13 @@ bool CGame::UpdateUnsynced(const spring_time currentTime) lineDrawer.UpdateLineStipple(); - if (doDrawWorld) { + { worldDrawer.Update(newSimFrame); CNamedTextures::Update(); CFontTexture::Update(); } + // always update InfoTexture and SoundListener at <= 30Hz (even when paused) if (newSimFrame || forceUpdate) { lastUnsyncedUpdateTime = currentTime; @@ -1225,9 +1225,6 @@ bool CGame::Draw() { const spring_time currentTimePreDraw = spring_gettime(); - const bool fullMiniMap = minimap->GetMaximized() && !minimap->GetMinimized(); - const bool doDrawWorld = hideInterface || !fullMiniMap; - SCOPED_SPECIAL_TIMER("Draw"); globalRendering->SetGLTimeStamp(0); @@ -1286,22 +1283,21 @@ bool CGame::Draw() { { minimap->Update(); - if (doDrawWorld) - worldDrawer.GenerateIBLTextures(); + // note: neither this call nor DrawWorld can be made conditional on minimap->GetMaximized() + // minimap never covers entire screen when maximized unless map aspect-ratio matches screen + // (unlikely); the minimap update also depends on GenerateIBLTextures for unbinding its FBO + worldDrawer.GenerateIBLTextures(); camera->Update(); - if (doDrawWorld) - worldDrawer.Draw(); - + worldDrawer.Draw(); worldDrawer.ResetMVPMatrices(); } { SCOPED_TIMER("Draw::Screen"); - if (doDrawWorld) - eventHandler.DrawScreenEffects(); + eventHandler.DrawScreenEffects(); hudDrawer->Draw((gu->GetMyPlayer())->fpsController.GetControllee()); debugDrawerAI->Draw(); @@ -1311,8 +1307,7 @@ bool CGame::Draw() { DrawInterfaceWidgets(); mouse->DrawCursor(); - if (doDrawWorld) - eventHandler.DrawScreenPost(); + eventHandler.DrawScreenPost(); } glEnable(GL_DEPTH_TEST); diff --git a/rts/Game/UI/MiniMap.cpp b/rts/Game/UI/MiniMap.cpp index a2aaf1bdaa1..38b47745c18 100644 --- a/rts/Game/UI/MiniMap.cpp +++ b/rts/Game/UI/MiniMap.cpp @@ -203,21 +203,18 @@ void CMiniMap::ParseGeometry(const string& geostr) void CMiniMap::ToggleMaximized(bool _maxspect) { - if (maximized) { - curPos.x = oldPos.x; - curPos.y = oldPos.y; - curDim.x = oldDim.x; - curDim.y = oldDim.y; - } else { - oldPos.x = curPos.x; - oldPos.y = curPos.y; - oldDim.x = curDim.x; - oldDim.y = curDim.y; + if ((maximized = !maximized)) { + // stash current geometry + oldPos = curPos; + oldDim = curDim; maxspect = _maxspect; - SetMaximizedGeometry(); + } else { + // restore previous geometry + curPos = oldPos; + curDim = oldDim; } - maximized = !maximized; + // needed for SetMaximizedGeometry UpdateGeometry(); } @@ -232,7 +229,7 @@ void CMiniMap::SetMaximizedGeometry() return; } - const float mapRatio = (float)mapDims.mapx / (float)mapDims.mapy; + const float mapRatio = (float)mapDims.mapx / (float)mapDims.mapy; const float viewRatio = globalRendering->aspectRatio; if (mapRatio > viewRatio) { @@ -348,10 +345,10 @@ void CMiniMap::ConfigCommand(const std::string& line) if (globalRendering->dualScreenMode) return; - const bool isMaximized = maximized; - maximized = (words.size() >= 2) ? !!atoi(words[1].c_str()) : !maximized; + const bool isMaximized = maximized; + const bool wantMaximized = (words.size() >= 2) ? !!atoi(words[1].c_str()) : !isMaximized; - if (isMaximized != maximized) + if (isMaximized != wantMaximized) ToggleMaximized(command == "maxspect"); } break; @@ -364,10 +361,8 @@ void CMiniMap::ConfigCommand(const std::string& line) void CMiniMap::SetGeometry(int px, int py, int sx, int sy) { - curPos.x = px; - curPos.y = py; - curDim.x = sx; - curDim.y = sy; + curPos = {px, py}; + curDim = {sx, sy}; UpdateGeometry(); } @@ -421,7 +416,7 @@ void CMiniMap::UpdateGeometry() const float h = float(curDim.y); const float mapx = float(mapDims.mapx * SQUARE_SIZE); const float mapy = float(mapDims.mapy * SQUARE_SIZE); - const float ref = unitBaseSize / math::pow((200.f * 200.0f), unitExponent); + const float ref = unitBaseSize / math::pow((200.0f * 200.0f), unitExponent); const float dpr = ref * math::pow((w * h), unitExponent); unitSizeX = dpr * (mapx / w); @@ -434,37 +429,49 @@ void CMiniMap::UpdateGeometry() mapBox.ymin = globalRendering->viewSizeY - (curPos.y + curDim.y); mapBox.ymax = mapBox.ymin + curDim.y - 1; - if (!maximized) { - // right to left + // FIXME: + // also need to make sure we can leave maximized-mode when !maxspect (in + // which case the buttons should be drawn on top of map, not outside it) + if (!maximized || maxspect) { + // work right (resizeBox) to left (minimizeBox) resizeBox.xmax = mapBox.xmax; resizeBox.xmin = resizeBox.xmax - (buttonSize - 1); + moveBox.xmax = resizeBox.xmax - buttonSize; moveBox.xmin = resizeBox.xmin - buttonSize; + maximizeBox.xmax = moveBox.xmax - buttonSize; maximizeBox.xmin = moveBox.xmin - buttonSize; + minimizeBox.xmax = maximizeBox.xmax - buttonSize; minimizeBox.xmin = maximizeBox.xmin - buttonSize; + const int ymin = (mapBox.ymax + 1) + 3; // 3 for the white|black|white const int ymax = ymin + (buttonSize - 1); resizeBox.ymin = moveBox.ymin = maximizeBox.ymin = minimizeBox.ymin = ymin; resizeBox.ymax = moveBox.ymax = maximizeBox.ymax = minimizeBox.ymax = ymax; + buttonBox.xmin = minimizeBox.xmin; buttonBox.xmax = mapBox.xmax; buttonBox.ymin = ymin - 3; buttonBox.ymax = ymax; } else { - // left to right + // work left to right minimizeBox.xmin = mapBox.xmin; minimizeBox.xmax = minimizeBox.xmin + (buttonSize - 1); + maximizeBox.xmin = minimizeBox.xmin + buttonSize; maximizeBox.xmax = minimizeBox.xmax + buttonSize; + // dead buttons - resizeBox.xmin = resizeBox.ymin = moveBox.xmin = moveBox.ymin = 0; + resizeBox.xmin = resizeBox.ymin = moveBox.xmin = moveBox.ymin = 0; resizeBox.xmax = resizeBox.ymax = moveBox.xmax = moveBox.ymax = -1; + const int ymin = mapBox.ymin; const int ymax = ymin + (buttonSize - 1); maximizeBox.ymin = minimizeBox.ymin = ymin; maximizeBox.ymax = minimizeBox.ymax = ymax; + buttonBox.xmin = minimizeBox.xmin; buttonBox.xmax = maximizeBox.xmax; buttonBox.ymin = ymin - 3; @@ -497,13 +504,13 @@ void CMiniMap::SelectUnits(int x, int y) if (fullProxy && (bp.movement > 4)) { // use a selection box - const float3 newPos = GetMapPosition(x, y); - const float3 oldPos = GetMapPosition(bp.x, bp.y); + const float3 newMapPos = GetMapPosition(x, y); + const float3 oldMapPos = GetMapPosition(bp.x, bp.y); - const float xmin = std::min(oldPos.x, newPos.x); - const float xmax = std::max(oldPos.x, newPos.x); - const float zmin = std::min(oldPos.z, newPos.z); - const float zmax = std::max(oldPos.z, newPos.z); + const float xmin = std::min(oldMapPos.x, newMapPos.x); + const float xmax = std::max(oldMapPos.x, newMapPos.x); + const float zmin = std::min(oldMapPos.z, newMapPos.z); + const float zmax = std::max(oldMapPos.z, newMapPos.z); const float4 planeRight(-RgtVector, xmin); const float4 planeLeft( RgtVector, -xmax); @@ -919,7 +926,7 @@ void CMiniMap::Update() fbo.Bind(); UpdateTextureCache(); - // no need, gets done in CGame + // gets done in CGame // fbo.Unbind(); } @@ -993,7 +1000,7 @@ void CMiniMap::UpdateTextureCache() glClearColor(0.0f, 0.0f, 0.0f, 1.0f); glClear(GL_COLOR_BUFFER_BIT); - DrawForReal(false, true); + DrawForReal(false, true, false); curPos = tmpPos; } @@ -1043,7 +1050,7 @@ void CMiniMap::Draw() } // draw the frameborder - if (!maximized && !globalRendering->dualScreenMode) { + if (!globalRendering->dualScreenMode) { DrawFrame(rdBufferC); DrawButtons(rdBufferC, rdBufferTC); } @@ -1051,20 +1058,23 @@ void CMiniMap::Draw() glPopAttrib(); } - // Draw Minimap itself - DrawForReal(true); + // draw minimap itself + DrawForReal(true, false, false); } -void CMiniMap::DrawForReal(bool useNormalizedCoors, bool updateTex) + +void CMiniMap::DrawForReal(bool useNormalizedCoors, bool updateTex, bool luaCall) { if (minimized) return; glActiveTexture(GL_TEXTURE0); - if ((!updateTex) && RenderCachedTexture(useNormalizedCoors)) + if (!updateTex) { + RenderCachedTexture(useNormalizedCoors); return; + } glPushAttrib(GL_DEPTH_BUFFER_BIT); glEnable(GL_BLEND); @@ -1183,8 +1193,8 @@ void CMiniMap::DrawCameraFrustumAndMouseSelection() glColor4f(1.0f, 1.0f, 1.0f, 1.0f); CMouseHandler::ButtonPressEvt& bp = mouse->buttons[SDL_BUTTON_LEFT]; if (selecting && fullProxy && (bp.movement > 4)) { - const float3 oldPos = GetMapPosition(bp.x, bp.y); - const float3 newPos = GetMapPosition(mouse->lastx, mouse->lasty); + const float3 oldMapPos = GetMapPosition(bp.x, bp.y); + const float3 newMapPos = GetMapPosition(mouse->lastx, mouse->lasty); glColor4fv(cmdColors.mouseBox); //glBlendFunc((GLenum)cmdColors.MouseBoxBlendSrc(), // (GLenum)cmdColors.MouseBoxBlendDst()); @@ -1193,10 +1203,10 @@ void CMiniMap::DrawCameraFrustumAndMouseSelection() CVertexArray* va = GetVertexArray(); va->Initialize(); va->EnlargeArrays(4, 0, VA_SIZE_2D0); - va->AddVertexQ2d0(oldPos.x, oldPos.z); - va->AddVertexQ2d0(newPos.x, oldPos.z); - va->AddVertexQ2d0(newPos.x, newPos.z); - va->AddVertexQ2d0(oldPos.x, newPos.z); + va->AddVertexQ2d0(oldMapPos.x, oldMapPos.z); + va->AddVertexQ2d0(newMapPos.x, oldMapPos.z); + va->AddVertexQ2d0(newMapPos.x, newMapPos.z); + va->AddVertexQ2d0(oldMapPos.x, newMapPos.z); va->DrawArray2d0(GL_LINE_LOOP); glLineWidth(1.0f); diff --git a/rts/Game/UI/MiniMap.h b/rts/Game/UI/MiniMap.h index 09427372f0a..c208000d094 100644 --- a/rts/Game/UI/MiniMap.h +++ b/rts/Game/UI/MiniMap.h @@ -34,7 +34,7 @@ class CMiniMap : public CInputReceiver { bool IsAbove(int x, int y); std::string GetTooltip(int x, int y); void Draw(); - void DrawForReal(bool useNormalizedCoors = true, bool updateTex = false); + void DrawForReal(bool useNormalizedCoors = true, bool updateTex = false, bool luaCall = false); void Update(); void ConfigCommand(const std::string& command); diff --git a/rts/Lua/LuaOpenGL.cpp b/rts/Lua/LuaOpenGL.cpp index 70b504c92bb..646f4985072 100644 --- a/rts/Lua/LuaOpenGL.cpp +++ b/rts/Lua/LuaOpenGL.cpp @@ -989,11 +989,11 @@ int LuaOpenGL::DrawMiniMap(lua_State* L) GL::PushMatrix(); GL::Scale(globalRendering->viewSizeX, globalRendering->viewSizeY, 1.0f); - minimap->DrawForReal(true); + minimap->DrawForReal(true, false, true); GL::PopMatrix(); } else { - minimap->DrawForReal(false); + minimap->DrawForReal(false, false, true); } return 0; @@ -1542,8 +1542,7 @@ int LuaOpenGL::DrawGroundQuad(lua_State* L) tu1 = luaL_checknumber(L, 8); tv1 = luaL_checknumber(L, 9); useTxcd = true; - } - else { + } else { if (lua_isboolean(L, 6)) { useTxcd = lua_toboolean(L, 6); if (useTxcd) { @@ -1566,9 +1565,8 @@ int LuaOpenGL::DrawGroundQuad(lua_State* L) const int xie = std::max(0, std::min(mapxi, int((xe + 0.5f) / SQUARE_SIZE))); const int zis = std::max(0, std::min(mapzi, int((zs + 0.5f) / SQUARE_SIZE))); const int zie = std::max(0, std::min(mapzi, int((ze + 0.5f) / SQUARE_SIZE))); - if ((xis >= xie) || (zis >= zie)) { + if ((xis >= xie) || (zis >= zie)) return 0; - } if (!useTxcd) { for (int xib = xis; xib < xie; xib++) { @@ -1586,12 +1584,12 @@ int LuaOpenGL::DrawGroundQuad(lua_State* L) } glEnd(); } - } - else { + } else { const float tuStep = (tu1 - tu0) / float(xie - xis); const float tvStep = (tv1 - tv0) / float(zie - zis); float tub = tu0; + for (int xib = xis; xib < xie; xib++) { const int xit = xib + 1; const float xb = xib * SQUARE_SIZE;