Changeset View
Standalone View
source/gui/ObjectTypes/CMiniMap.cpp
/* Copyright (C) 2019 Wildfire Games. | /* Copyright (C) 2020 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
▲ Show 20 Lines • Show All 119 Lines • ▼ Show 20 Lines | CMiniMap::CMiniMap(CGUI& pGUI) : | ||||
// Tests won't have config initialised | // Tests won't have config initialised | ||||
if (CConfigDB::IsInitialised()) | if (CConfigDB::IsInitialised()) | ||||
{ | { | ||||
CFG_GET_VAL("gui.session.minimap.pingduration", m_PingDuration); | CFG_GET_VAL("gui.session.minimap.pingduration", m_PingDuration); | ||||
CFG_GET_VAL("gui.session.minimap.blinkduration", blinkDuration); | CFG_GET_VAL("gui.session.minimap.blinkduration", blinkDuration); | ||||
} | } | ||||
m_HalfBlinkDuration = blinkDuration/2; | m_HalfBlinkDuration = blinkDuration/2; | ||||
CTextureProperties textureProps(L"art/textures/ui/session/minimap-flare-circle.png"); | |||||
m_FlareTexture = g_Renderer.GetTextureManager().CreateTexture(textureProps); | |||||
} | } | ||||
vladislavbelov: So, you're not going to use DDS? | |||||
Done Inline ActionsHmm, good point. Other parts of our code used png, so I didn't thought about that. Imarok: Hmm, good point. Other parts of our code used png, so I didn't thought about that.
Isn't the… | |||||
Done Inline ActionsIf you use .png directly, then there shouldn't be any automatic DDS usage AFAIK. Also CStr should be CStrW I suppose. Since you always use L and CStr might be CStrW for Unicode. vladislavbelov: If you use `.png` directly, then there shouldn't be any automatic DDS usage AFAIK.
Also `CStr`… | |||||
Done Inline ActionsWhat else should I use?
That's what FromUTF8() does. Imarok: What else should I use?
If I use `.dds` it errors out.
> Also `CStr` should be `CStrW` I… | |||||
Done Inline ActionsYou can just use CStrW().FromInt wraitii: You can just use CStrW().FromInt | |||||
Done Inline ActionsI don't think so as I need the 0 at the front. Imarok: I don't think so as I need the 0 at the front. | |||||
CMiniMap::~CMiniMap() | CMiniMap::~CMiniMap() | ||||
{ | { | ||||
Destroy(); | Destroy(); | ||||
} | } | ||||
void CMiniMap::HandleMessage(SGUIMessage& Message) | void CMiniMap::HandleMessage(SGUIMessage& Message) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 44 Lines • ▼ Show 20 Lines | void CMiniMap::HandleMessage(SGUIMessage& Message) | ||||
default: | default: | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
bool CMiniMap::IsMouseOver() const | bool CMiniMap::IsMouseOver() const | ||||
{ | { | ||||
// Get the mouse position. | // Get the mouse position. | ||||
Done Inline Actionsdebug? wraitii: debug? | |||||
Done Inline ActionsAh, yeah. Imarok: Ah, yeah.
I uploaded in a hurry >< | |||||
const CPos& mousePos = m_pGUI.GetMousePos(); | const CPos& mousePos = m_pGUI.GetMousePos(); | ||||
Not Done Inline ActionsCould do m_FlareTextures.reserve(m_FlareTextureCount);. vladislavbelov: Could do `m_FlareTextures.reserve(m_FlareTextureCount);`. | |||||
Done Inline ActionsTrue. I thought about that but was too lazy ;) Imarok: True. I thought about that but was too lazy ;) | |||||
// Get the position of the center of the minimap. | // Get the position of the center of the minimap. | ||||
CPos minimapCenter = CPos(m_CachedActualSize.left + m_CachedActualSize.GetWidth() / 2.0, m_CachedActualSize.bottom - m_CachedActualSize.GetHeight() / 2.0); | CPos minimapCenter = CPos(m_CachedActualSize.left + m_CachedActualSize.GetWidth() / 2.0, m_CachedActualSize.bottom - m_CachedActualSize.GetHeight() / 2.0); | ||||
Done Inline ActionsWrong format type. Also it's hardcoded for 2 digits. At least it should be a named format constant. vladislavbelov: Wrong format type. Also it's hardcoded for 2 digits. At least it should be a named format… | |||||
// Take the magnitude of the difference of the mouse position and minimap center. | // Take the magnitude of the difference of the mouse position and minimap center. | ||||
double distFromCenter = sqrt(pow((mousePos.x - minimapCenter.x), 2) + pow((mousePos.y - minimapCenter.y), 2)); | double distFromCenter = sqrt(pow((mousePos.x - minimapCenter.x), 2) + pow((mousePos.y - minimapCenter.y), 2)); | ||||
Done Inline Actionsemplace_back. vladislavbelov: `emplace_back`. | |||||
// If the distance is less then the radius of the minimap (half the width) the mouse is over the minimap. | // If the distance is less then the radius of the minimap (half the width) the mouse is over the minimap. | ||||
if (distFromCenter < m_CachedActualSize.GetWidth() / 2.0) | if (distFromCenter < m_CachedActualSize.GetWidth() / 2.0) | ||||
return true; | return true; | ||||
else | else | ||||
return false; | return false; | ||||
} | } | ||||
void CMiniMap::GetMouseWorldCoordinates(float& x, float& z) const | void CMiniMap::GetMouseWorldCoordinates(float& x, float& z) const | ||||
{ | { | ||||
// Determine X and Z according to proportion of mouse position and minimap | // Determine X and Z according to proportion of mouse position and minimap | ||||
const CPos& mousePos = m_pGUI.GetMousePos(); | const CPos& mousePos = m_pGUI.GetMousePos(); | ||||
float px = (mousePos.x - m_CachedActualSize.left) / m_CachedActualSize.GetWidth(); | float px = (mousePos.x - m_CachedActualSize.left) / m_CachedActualSize.GetWidth(); | ||||
float py = (m_CachedActualSize.bottom - mousePos.y) / m_CachedActualSize.GetHeight(); | float py = (m_CachedActualSize.bottom - mousePos.y) / m_CachedActualSize.GetHeight(); | ||||
float angle = GetAngle(); | float angle = GetAngle(); | ||||
// Scale world coordinates for shrunken square map | // Scale world coordinates for shrunken square map | ||||
x = TERRAIN_TILE_SIZE * m_MapSize * (m_MapScale * (cos(angle)*(px-0.5) - sin(angle)*(py-0.5)) + 0.5); | x = TERRAIN_TILE_SIZE * m_MapSize * (m_MapScale * (cos(angle)*(px-0.5) - sin(angle)*(py-0.5)) + 0.5); | ||||
z = TERRAIN_TILE_SIZE * m_MapSize * (m_MapScale * (cos(angle)*(py-0.5) + sin(angle)*(px-0.5)) + 0.5); | z = TERRAIN_TILE_SIZE * m_MapSize * (m_MapScale * (cos(angle)*(py-0.5) + sin(angle)*(px-0.5)) + 0.5); | ||||
} | } | ||||
CPos CMiniMap::GetMapCoordinates(float x, float z) const | |||||
{ | |||||
const float width = m_CachedActualSize.GetWidth(); | |||||
const float height = m_CachedActualSize.GetHeight(); | |||||
const float invTileMapSize = 1.0f / (TERRAIN_TILE_SIZE * m_MapSize); | |||||
return CPos(width * x * invTileMapSize, height * z * invTileMapSize); | |||||
} | |||||
void CMiniMap::SetCameraPos() | void CMiniMap::SetCameraPos() | ||||
{ | { | ||||
CTerrain* terrain = g_Game->GetWorld()->GetTerrain(); | CTerrain* terrain = g_Game->GetWorld()->GetTerrain(); | ||||
CVector3D target; | CVector3D target; | ||||
GetMouseWorldCoordinates(target.X, target.Z); | GetMouseWorldCoordinates(target.X, target.Z); | ||||
target.Y = terrain->GetExactGroundLevel(target.X, target.Z); | target.Y = terrain->GetExactGroundLevel(target.X, target.Z); | ||||
g_Game->GetView()->MoveCameraTarget(target); | g_Game->GetView()->MoveCameraTarget(target); | ||||
Show All 23 Lines | bool CMiniMap::FireWorldClickEvent(int button, int UNUSED(clicks)) | ||||
paramData.append(coords); | paramData.append(coords); | ||||
paramData.append(buttonJs); | paramData.append(buttonJs); | ||||
return ScriptEventWithReturn(EventNameWorldClick, paramData); | return ScriptEventWithReturn(EventNameWorldClick, paramData); | ||||
} | } | ||||
// This sets up and draws the rectangle on the minimap | // This sets up and draws the rectangle on the minimap | ||||
// which represents the view of the camera in the world. | // which represents the view of the camera in the world. | ||||
void CMiniMap::DrawViewRect(CMatrix3D transform) const | void CMiniMap::DrawViewRect(const CMatrix3D& transform) const | ||||
{ | { | ||||
// Compute the camera frustum intersected with a fixed-height plane. | // Compute the camera frustum intersected with a fixed-height plane. | ||||
// Use the water height as a fixed base height, which should be the lowest we can go | // Use the water height as a fixed base height, which should be the lowest we can go | ||||
float h = g_Renderer.GetWaterManager()->m_WaterHeight; | float h = g_Renderer.GetWaterManager()->m_WaterHeight; | ||||
const float width = m_CachedActualSize.GetWidth(); | const float width = m_CachedActualSize.GetWidth(); | ||||
const float height = m_CachedActualSize.GetHeight(); | const float height = m_CachedActualSize.GetHeight(); | ||||
const float invTileMapSize = 1.0f / float(TERRAIN_TILE_SIZE * m_MapSize); | |||||
CVector3D hitPt[4]; | CVector3D hitPt[4]; | ||||
hitPt[0] = m_Camera->GetWorldCoordinates(0, g_Renderer.GetHeight(), h); | hitPt[0] = m_Camera->GetWorldCoordinates(0, g_Renderer.GetHeight(), h); | ||||
hitPt[1] = m_Camera->GetWorldCoordinates(g_Renderer.GetWidth(), g_Renderer.GetHeight(), h); | hitPt[1] = m_Camera->GetWorldCoordinates(g_Renderer.GetWidth(), g_Renderer.GetHeight(), h); | ||||
hitPt[2] = m_Camera->GetWorldCoordinates(g_Renderer.GetWidth(), 0, h); | hitPt[2] = m_Camera->GetWorldCoordinates(g_Renderer.GetWidth(), 0, h); | ||||
hitPt[3] = m_Camera->GetWorldCoordinates(0, 0, h); | hitPt[3] = m_Camera->GetWorldCoordinates(0, 0, h); | ||||
float ViewRect[4][2]; | CPos ViewRect[4]; | ||||
for (int i = 0; i < 4; ++i) | for (int i = 0; i < 4; ++i) | ||||
{ | |||||
// convert to minimap space | // convert to minimap space | ||||
ViewRect[i][0] = (width * hitPt[i].X * invTileMapSize); | ViewRect[i] = GetMapCoordinates(hitPt[i].X, hitPt[i].Z); | ||||
ViewRect[i][1] = (height * hitPt[i].Z * invTileMapSize); | |||||
} | |||||
float viewVerts[] = { | float viewVerts[] = { | ||||
ViewRect[0][0], -ViewRect[0][1], | ViewRect[0].x, -ViewRect[0].y, | ||||
ViewRect[1][0], -ViewRect[1][1], | ViewRect[1].x, -ViewRect[1].y, | ||||
ViewRect[2][0], -ViewRect[2][1], | ViewRect[2].x, -ViewRect[2].y, | ||||
ViewRect[3][0], -ViewRect[3][1] | ViewRect[3].x, -ViewRect[3].y | ||||
}; | }; | ||||
// Enable Scissoring to restrict the rectangle to only the minimap. | // Enable Scissoring to restrict the rectangle to only the minimap. | ||||
glScissor( | glScissor( | ||||
m_CachedActualSize.left * g_GuiScale, | m_CachedActualSize.left * g_GuiScale, | ||||
g_Renderer.GetHeight() - m_CachedActualSize.bottom * g_GuiScale, | g_Renderer.GetHeight() - m_CachedActualSize.bottom * g_GuiScale, | ||||
width * g_GuiScale, | width * g_GuiScale, | ||||
height * g_GuiScale); | height * g_GuiScale); | ||||
Show All 15 Lines | if (!g_Renderer.m_SkipSubmit) | ||||
glDrawArrays(GL_LINE_LOOP, 0, 4); | glDrawArrays(GL_LINE_LOOP, 0, 4); | ||||
tech->EndPass(); | tech->EndPass(); | ||||
glLineWidth(1.0f); | glLineWidth(1.0f); | ||||
glDisable(GL_SCISSOR_TEST); | glDisable(GL_SCISSOR_TEST); | ||||
} | } | ||||
void CMiniMap::DrawFlare(CShaderProgramPtr shader, const MapFlareObj& flare, double cur_time) const | |||||
Done Inline ActionscurrentTime. vladislavbelov: `currentTime`. | |||||
{ | |||||
float step = std::fmod((cur_time - flare.time) * 15, 35); | |||||
Done Inline Actions. vladislavbelov: . | |||||
Done Inline ActionsStill some commented code. vladislavbelov: Still some commented code. | |||||
float x = flare.pos.x + step; | |||||
float y = -flare.pos.y-step; | |||||
float x2 = flare.pos.x - step; | |||||
float y2 = -flare.pos.y+step; | |||||
Done Inline Actionsstatic_cast. vladislavbelov: `static_cast`. | |||||
float z = 0; | |||||
float quadTex[] = { | |||||
0, 1, | |||||
1, 1, | |||||
1, 0, | |||||
1, 0, | |||||
0, 0, | |||||
0, 1 | |||||
}; | |||||
float quadVerts[] = { | |||||
x, y, z, | |||||
x2, y, z, | |||||
x2, y2, z, | |||||
x2, y2, z, | |||||
x, y2, z, | |||||
x, y, z | |||||
}; | |||||
shader->Uniform(str_color, flare.color); | |||||
shader->TexCoordPointer(GL_TEXTURE0, 2, GL_FLOAT, 0, quadTex); | |||||
shader->VertexPointer(3, GL_FLOAT, 0, quadVerts); | |||||
Done Inline Actionsconst. vladislavbelov: `const`. | |||||
shader->AssertPointersBound(); | |||||
if (!g_Renderer.m_SkipSubmit) | |||||
glDrawArrays(GL_TRIANGLES, 0, 6); | |||||
} | |||||
struct MinimapUnitVertex | struct MinimapUnitVertex | ||||
Done Inline ActionsFor the skip we need to skip the only glDraw* calls but leave all bindings. vladislavbelov: For the skip we need to skip the only `glDraw*` calls but leave all bindings. | |||||
{ | { | ||||
// This struct is copyable for convenience and because to move is to copy for primitives. | // This struct is copyable for convenience and because to move is to copy for primitives. | ||||
u8 r, g, b, a; | u8 r, g, b, a; | ||||
float x, y; | float x, y; | ||||
}; | }; | ||||
Done Inline ActionsThis actually seems like it should use a magic number & could use a comment wraitii: This actually seems like it should use a magic number & could use a comment | |||||
// Adds a vertex to the passed VertexArray | // Adds a vertex to the passed VertexArray | ||||
static void inline addVertex(const MinimapUnitVertex& v, | static void inline addVertex(const MinimapUnitVertex& v, | ||||
Done Inline ActionsMissed constants for 8 and 16. vladislavbelov: Missed constants for 8 and 16. | |||||
VertexArrayIterator<u8[4]>& attrColor, | VertexArrayIterator<u8[4]>& attrColor, | ||||
VertexArrayIterator<float[2]>& attrPos) | VertexArrayIterator<float[2]>& attrPos) | ||||
{ | { | ||||
(*attrColor)[0] = v.r; | (*attrColor)[0] = v.r; | ||||
(*attrColor)[1] = v.g; | (*attrColor)[1] = v.g; | ||||
(*attrColor)[2] = v.b; | (*attrColor)[2] = v.b; | ||||
(*attrColor)[3] = v.a; | (*attrColor)[3] = v.a; | ||||
++attrColor; | ++attrColor; | ||||
(*attrPos)[0] = v.x; | (*attrPos)[0] = v.x; | ||||
(*attrPos)[1] = v.y; | (*attrPos)[1] = v.y; | ||||
++attrPos; | ++attrPos; | ||||
} | } | ||||
void CMiniMap::DrawTexture(CShaderProgramPtr shader, float coordMax, float angle, float x, float y, float x2, float y2, float z) const | void CMiniMap::DrawTexture(CShaderProgramPtr shader, float coordMax, float angle, float x, float y, float x2, float y2, float z) const | ||||
{ | { | ||||
// Rotate the texture coordinates (0,0)-(coordMax,coordMax) around their center point (m,m) | // Rotate the texture coordinates (0,0)-(coordMax,coordMax) around their center point (m,m) | ||||
// Scale square maps to fit in circular minimap area | // Scale square maps to fit in circular minimap area | ||||
const float s = sin(angle) * m_MapScale; | const float s = sin(angle) * m_MapScale; | ||||
const float c = cos(angle) * m_MapScale; | const float c = cos(angle) * m_MapScale; | ||||
const float m = coordMax / 2.f; | const float m = coordMax / 2.f; | ||||
▲ Show 20 Lines • Show All 81 Lines • ▼ Show 20 Lines | void CMiniMap::Draw() | ||||
CShaderProgramPtr shader; | CShaderProgramPtr shader; | ||||
CShaderTechniquePtr tech; | CShaderTechniquePtr tech; | ||||
CShaderDefines baseDefines; | CShaderDefines baseDefines; | ||||
baseDefines.Add(str_MINIMAP_BASE, str_1); | baseDefines.Add(str_MINIMAP_BASE, str_1); | ||||
tech = g_Renderer.GetShaderManager().LoadEffect(str_minimap, g_Renderer.GetSystemShaderDefines(), baseDefines); | tech = g_Renderer.GetShaderManager().LoadEffect(str_minimap, g_Renderer.GetSystemShaderDefines(), baseDefines); | ||||
tech->BeginPass(); | tech->BeginPass(); | ||||
shader = tech->GetShader(); | shader = tech->GetShader(); | ||||
Done Inline ActionsThis loads up the minimap shader with MINIMAP_BASE define. wraitii: This loads up the minimap shader with `MINIMAP_BASE` define. | |||||
// Draw the main textured quad | // Draw the main textured quad | ||||
shader->BindTexture(str_baseTex, m_TerrainTexture); | shader->BindTexture(str_baseTex, m_TerrainTexture); | ||||
const CMatrix3D baseTransform = GetDefaultGuiMatrix(); | const CMatrix3D baseTransform = GetDefaultGuiMatrix(); | ||||
CMatrix3D baseTextureTransform; | CMatrix3D baseTextureTransform; | ||||
baseTextureTransform.SetIdentity(); | baseTextureTransform.SetIdentity(); | ||||
shader->Uniform(str_transform, baseTransform); | shader->Uniform(str_transform, baseTransform); | ||||
shader->Uniform(str_textureTransform, baseTextureTransform); | shader->Uniform(str_textureTransform, baseTextureTransform); | ||||
DrawTexture(shader, texCoordMax, angle, x, y, x2, y2, z); | DrawTexture(shader, texCoordMax, angle, x, y, x2, y2, z); | ||||
Done Inline ActionsHere it binds the transform and the texture, and then uses the helper DrawTexture to render two triangles at the appropriate coordinates. You should be able to do exactly the same thing, but call DrawTexture with different x,y,x2,y2 and your Flare texture. wraitii: Here it binds the transform and the texture, and then uses the helper DrawTexture to render two… | |||||
// Draw territory boundaries | // Draw territory boundaries | ||||
glEnable(GL_BLEND); | glEnable(GL_BLEND); | ||||
CTerritoryTexture& territoryTexture = g_Game->GetView()->GetTerritoryTexture(); | CTerritoryTexture& territoryTexture = g_Game->GetView()->GetTerritoryTexture(); | ||||
shader->BindTexture(str_baseTex, territoryTexture.GetTexture()); | shader->BindTexture(str_baseTex, territoryTexture.GetTexture()); | ||||
const CMatrix3D* territoryTransform = territoryTexture.GetMinimapTextureMatrix(); | const CMatrix3D* territoryTransform = territoryTexture.GetMinimapTextureMatrix(); | ||||
shader->Uniform(str_transform, baseTransform); | shader->Uniform(str_transform, baseTransform); | ||||
shader->Uniform(str_textureTransform, *territoryTransform); | shader->Uniform(str_textureTransform, *territoryTransform); | ||||
DrawTexture(shader, 1.0f, angle, x, y, x2, y2, z); | DrawTexture(shader, 1.0f, angle, x, y, x2, y2, z); | ||||
tech->EndPass(); | tech->EndPass(); | ||||
Done Inline ActionsSee here it's doing the same for territory -> you can pretty much reuse this wraitii: See here it's doing the same for territory -> you can pretty much reuse this | |||||
// Draw the LOS quad in black, using alpha values from the LOS texture | // Draw the LOS quad in black, using alpha values from the LOS texture | ||||
CLOSTexture& losTexture = g_Game->GetView()->GetLOSTexture(); | CLOSTexture& losTexture = g_Game->GetView()->GetLOSTexture(); | ||||
CShaderDefines losDefines; | CShaderDefines losDefines; | ||||
losDefines.Add(str_MINIMAP_LOS, str_1); | losDefines.Add(str_MINIMAP_LOS, str_1); | ||||
tech = g_Renderer.GetShaderManager().LoadEffect(str_minimap, g_Renderer.GetSystemShaderDefines(), losDefines); | tech = g_Renderer.GetShaderManager().LoadEffect(str_minimap, g_Renderer.GetSystemShaderDefines(), losDefines); | ||||
tech->BeginPass(); | tech->BeginPass(); | ||||
shader = tech->GetShader(); | shader = tech->GetShader(); | ||||
shader->BindTexture(str_baseTex, losTexture.GetTexture()); | shader->BindTexture(str_baseTex, losTexture.GetTexture()); | ||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA); | ||||
const CMatrix3D* losTransform = losTexture.GetMinimapTextureMatrix(); | const CMatrix3D* losTransform = losTexture.GetMinimapTextureMatrix(); | ||||
shader->Uniform(str_transform, baseTransform); | shader->Uniform(str_transform, baseTransform); | ||||
shader->Uniform(str_textureTransform, *losTransform); | shader->Uniform(str_textureTransform, *losTransform); | ||||
DrawTexture(shader, 1.0f, angle, x, y, x2, y2, z); | DrawTexture(shader, 1.0f, angle, x, y, x2, y2, z); | ||||
tech->EndPass(); | tech->EndPass(); | ||||
glDisable(GL_BLEND); | glDisable(GL_BLEND); | ||||
PROFILE_START("minimap units"); | PROFILE_START("minimap units and flares"); | ||||
CShaderDefines pointDefines; | CShaderDefines pointDefines; | ||||
pointDefines.Add(str_MINIMAP_POINT, str_1); | pointDefines.Add(str_MINIMAP_POINT, str_1); | ||||
tech = g_Renderer.GetShaderManager().LoadEffect(str_minimap, g_Renderer.GetSystemShaderDefines(), pointDefines); | tech = g_Renderer.GetShaderManager().LoadEffect(str_minimap, g_Renderer.GetSystemShaderDefines(), pointDefines); | ||||
Done Inline ActionsHere it reloads the shader with MINIMAP_POINT but I think you can just keep MINIMAP_BASE wraitii: Here it reloads the shader with MINIMAP_POINT but I think you can just keep MINIMAP_BASE | |||||
tech->BeginPass(); | tech->BeginPass(); | ||||
shader = tech->GetShader(); | shader = tech->GetShader(); | ||||
shader->Uniform(str_transform, baseTransform); | shader->Uniform(str_transform, baseTransform); | ||||
shader->Uniform(str_pointSize, 3.f); | shader->Uniform(str_pointSize, 3.f); | ||||
CMatrix3D unitMatrix; | CMatrix3D unitMatrix; | ||||
unitMatrix.SetIdentity(); | unitMatrix.SetIdentity(); | ||||
// Center the minimap on the origin of the axis of rotation. | // Center the minimap on the origin of the axis of rotation. | ||||
▲ Show 20 Lines • Show All 101 Lines • ▼ Show 20 Lines | if (g_RenderingOptions.GetRenderPath() == RenderPath::SHADER) | ||||
glDisable(GL_VERTEX_PROGRAM_POINT_SIZE); | glDisable(GL_VERTEX_PROGRAM_POINT_SIZE); | ||||
#endif | #endif | ||||
} | } | ||||
tech->EndPass(); | tech->EndPass(); | ||||
DrawViewRect(unitMatrix); | DrawViewRect(unitMatrix); | ||||
PROFILE_END("minimap units"); | while (!m_MapFlares.empty() && 6 + m_MapFlares.front().time < cur_time) | ||||
m_MapFlares.pop_front(); | |||||
glEnable(GL_BLEND); | |||||
const float width = m_CachedActualSize.GetWidth(); | |||||
const float height = m_CachedActualSize.GetHeight(); | |||||
glScissor( | |||||
m_CachedActualSize.left * g_GuiScale, | |||||
g_Renderer.GetHeight() - m_CachedActualSize.bottom * g_GuiScale, | |||||
width * g_GuiScale, | |||||
height * g_GuiScale); | |||||
ImarokAuthorUnsubmitted Done Inline ActionsI needto enable scissoring here to get it. ^^ Imarok: I needto enable scissoring here to get it. ^^
| |||||
vladislavbelovUnsubmitted Done Inline ActionsWhy do you need that? vladislavbelov: Why do you need that? | |||||
ImarokAuthorUnsubmitted Done Inline ActionsElse parts of the circles may be drawn outside the minimap. Imarok: Else parts of the circles may be drawn outside the minimap. | |||||
vladislavbelovUnsubmitted Done Inline ActionsIs that bad? You will have circles over/under interface anyway. But anyway you have a mask that you might use to hide the circular area. vladislavbelov: Is that bad? You will have circles over/under interface anyway. But anyway you have a mask that… | |||||
CShaderDefines flareDefines; | |||||
flareDefines.Add(str_MINIMAP_FLARE, str_1); | |||||
tech = g_Renderer.GetShaderManager().LoadEffect(str_minimap, g_Renderer.GetSystemShaderDefines(), flareDefines); | |||||
tech->BeginPass(); | |||||
shader = tech->GetShader(); | |||||
shader->BindTexture(str_baseTex, m_FlareTexture); | |||||
shader->Uniform(str_transform, unitMatrix); | |||||
shader->Uniform(str_textureTransform, baseTextureTransform); | |||||
for (const MapFlareObj& flare : m_MapFlares) | |||||
DrawFlare(shader, flare, cur_time); | |||||
tech->EndPass(); | |||||
glDisable(GL_SCISSOR_TEST); | |||||
glDisable(GL_BLEND); | |||||
PROFILE_END("minimap units and flares"); | |||||
Not Done Inline ActionsIt's not good to modify a state during drawing. vladislavbelov: It's not good to modify a state during drawing. | |||||
Done Inline ActionsDon't see a good alternative. Do you have one? Imarok: Don't see a good alternative. Do you have one?
| |||||
Not Done Inline ActionsYou might check void Tick(). vladislavbelov: You might check `void Tick()`. | |||||
Done Inline Actionswhere? Imarok: where?
| |||||
// Reset depth mask | // Reset depth mask | ||||
glDepthMask(1); | glDepthMask(1); | ||||
} | } | ||||
void CMiniMap::CreateTextures() | void CMiniMap::CreateTextures() | ||||
{ | { | ||||
Destroy(); | Destroy(); | ||||
▲ Show 20 Lines • Show All 78 Lines • ▼ Show 20 Lines | for (u32 j = 0; j < h; ++j) | ||||
} | } | ||||
} | } | ||||
// Upload the texture | // Upload the texture | ||||
g_Renderer.BindTexture(0, m_TerrainTexture); | g_Renderer.BindTexture(0, m_TerrainTexture); | ||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_MapSize - 1, m_MapSize - 1, GL_RGBA, GL_UNSIGNED_BYTE, m_TerrainData); | glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, m_MapSize - 1, m_MapSize - 1, GL_RGBA, GL_UNSIGNED_BYTE, m_TerrainData); | ||||
} | } | ||||
JSFunctionSpec CMiniMap::JSI_methods[] = | |||||
{ | |||||
JS_FN("flare", CMiniMap::FlareProxy, 2, 0), | |||||
Done Inline Actions. vladislavbelov: . | |||||
Done Inline ActionsWhat do you mean? Imarok: What do you mean? | |||||
Done Inline Actionsemplace_back. vladislavbelov: `emplace_back`. | |||||
JS_FS_END | |||||
Done Inline ActionsMight use emplace. vladislavbelov: Might use `emplace`. | |||||
Done Inline ActionsDoesn't work. Maybe because color is a const ref and the rest not. Imarok: Doesn't work. Maybe because `color` is a const ref and the rest not. | |||||
}; | |||||
void CMiniMap::RegisterScriptFunctions() | |||||
{ | |||||
JSContext* cx = m_pGUI.GetScriptInterface()->GetContext(); | |||||
Done Inline Actionsspaces after { and before } wraitii: spaces after { and before } | |||||
JSAutoRequest rq(cx); | |||||
JS_DefineFunctions(cx, m_JSObject, JSI_methods); | |||||
} | |||||
bool CMiniMap::FlareProxy(JSContext* cx, uint argc, JS::Value* vp) | |||||
{ | |||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp); | |||||
CMiniMap* thisObj = ScriptInterface::GetPrivate<CMiniMap>(cx, args, &JSI_IGUIObject::JSI_class); | |||||
if (!thisObj) | |||||
{ | |||||
JSAutoRequest rq(cx); | |||||
JS_ReportError(cx, "This is not a CMiniMap object!"); | |||||
Done Inline Actionsdelete wraitii: delete | |||||
Done Inline Actionsnot the scope of the diff I'd say. Imarok: not the scope of the diff I'd say. | |||||
return false; | |||||
} | |||||
bool ret = thisObj->Flare(cx, argc, vp); | |||||
args.rval().set(JS::BooleanValue(ret)); | |||||
return true; | |||||
} | |||||
bool CMiniMap::Flare(JSContext* cx, uint argc, JS::Value* vp) | |||||
{ | |||||
JS::CallArgs args = JS::CallArgsFromVp(argc, vp); | |||||
bool ret = false; | |||||
if (args.length() != 2) | |||||
LOGERROR("CMiniMap::Flare: Got %d arguments, but expected 2.", args.length()); | |||||
else | |||||
{ | |||||
JSAutoRequest rq(cx); | |||||
CVector2D pos; | |||||
CStr colorStr; | |||||
CColor color; | |||||
if (ScriptInterface::FromJSVal(cx, args.get(0), pos) && | |||||
ScriptInterface::FromJSVal(cx, args.get(1), colorStr) && | |||||
color.ParseString(colorStr)) | |||||
{ | |||||
m_MapFlares.push_back({GetMapCoordinates(pos.X, pos.Y), color, timer_Time()}); | |||||
ret = true; | |||||
} | |||||
} | |||||
return ret; | |||||
} | |||||
void CMiniMap::Destroy() | void CMiniMap::Destroy() | ||||
{ | { | ||||
if (m_TerrainTexture) | if (m_TerrainTexture) | ||||
{ | { | ||||
glDeleteTextures(1, &m_TerrainTexture); | glDeleteTextures(1, &m_TerrainTexture); | ||||
m_TerrainTexture = 0; | m_TerrainTexture = 0; | ||||
} | } | ||||
SAFE_ARRAY_DELETE(m_TerrainData); | SAFE_ARRAY_DELETE(m_TerrainData); | ||||
} | } |
So, you're not going to use DDS?