mirror of
https://gitea.wildfiregames.com/0ad/0ad
synced 2026-06-16 05:13:58 -07:00
Slightly improves minimap flares, makes animation more smooth via alpha fade in/out.
Tested By: Langbart Differential Revision: https://code.wildfiregames.com/D4351 This was SVN commit r26001.
This commit is contained in:
parent
0c4f59d0a7
commit
9b3dcd2610
11 changed files with 69 additions and 27 deletions
|
|
@ -242,7 +242,7 @@
|
|||
</optional>
|
||||
<optional>
|
||||
<attribute name="flare_animation_speed">
|
||||
<data type="nonNegativeInteger"/>
|
||||
<data type="decimal"/>
|
||||
</attribute>
|
||||
</optional>
|
||||
<optional>
|
||||
|
|
@ -252,7 +252,17 @@
|
|||
</optional>
|
||||
<optional>
|
||||
<attribute name="flare_lifetime_seconds">
|
||||
<data type="nonNegativeInteger"/>
|
||||
<data type="decimal"/>
|
||||
</attribute>
|
||||
</optional>
|
||||
<optional>
|
||||
<attribute name="flare_start_fade_seconds">
|
||||
<data type="decimal"/>
|
||||
</attribute>
|
||||
</optional>
|
||||
<optional>
|
||||
<attribute name="flare_stop_fade_seconds">
|
||||
<data type="decimal"/>
|
||||
</attribute>
|
||||
</optional>
|
||||
<optional>
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:3bdab823affff3e81eebe9408ccec951ffc2eb734d65c4aa5cc6b0146372e40d
|
||||
size 746
|
||||
oid sha256:5bd0c9341fe3b40a1906f9b496f1cfc55463a98f2027bbc0110c45fa0a05991a
|
||||
size 780
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:f425e40fab04c1caefa52412632604195af9418836b2b81b5a2bda11f33e651b
|
||||
size 1160
|
||||
oid sha256:2df79388517ac094f2559a055d60b7fa870a03a49bc01798693465907e34fa3a
|
||||
size 1284
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:51b3afa3258954260b2e71ff7ad813b21673049395622a8aa847511882ecfd13
|
||||
size 1460
|
||||
oid sha256:afbde1b6296f3f771bc267ff065694320112bccbf1ed8675d0014e1fde8451f1
|
||||
size 1838
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:0629361330fa2b2947739cf736b4a885c4f7c03bbd0e39d7b24aed83041ec9cf
|
||||
size 5173
|
||||
oid sha256:77ecf96497ba21adc35c88a43cc34f72f9b061f48b4be2776d8fbf0f409833b8
|
||||
size 6562
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:3d7a46316d198688643d1097b1de8445faae326e879d3e9235f1e71362f20150
|
||||
size 5420
|
||||
oid sha256:f3353f97157cf20debf5843a9ee842c03c047c2194a059f2c384a7db32150eba
|
||||
size 6616
|
||||
|
|
|
|||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:982819ff2a63ad94667aad3d2e1b0bbf1b8f7d95e23f4b1b24ccf908a6073598
|
||||
size 5725
|
||||
oid sha256:dd06bc808c25a912bfa74bc3b973633306152cc70a1e5c61153cab3b1ac7bb8d
|
||||
size 6800
|
||||
|
|
|
|||
|
|
@ -63,8 +63,10 @@
|
|||
mask="true"
|
||||
flare_texture_count="16"
|
||||
flare_render_size="32"
|
||||
flare_animation_speed="11"
|
||||
flare_animation_speed="10.67"
|
||||
flare_interleave="true"
|
||||
flare_lifetime_seconds="6"
|
||||
flare_start_fade_seconds="0.25"
|
||||
flare_stop_fade_seconds="0.5"
|
||||
/>
|
||||
</object>
|
||||
|
|
|
|||
|
|
@ -36,6 +36,7 @@
|
|||
#include "lib/external_libraries/libsdl.h"
|
||||
#include "lib/ogl.h"
|
||||
#include "lib/timer.h"
|
||||
#include "maths/MathUtil.h"
|
||||
#include "ps/CLogger.h"
|
||||
#include "ps/ConfigDB.h"
|
||||
#include "ps/CStrInternStatic.h"
|
||||
|
|
@ -136,7 +137,9 @@ CMiniMap::CMiniMap(CGUI& pGUI) :
|
|||
m_MapSize(0), m_MapScale(1.f), m_Mask(this, "mask", false),
|
||||
m_FlareTextureCount(this, "flare_texture_count", 0), m_FlareRenderSize(this, "flare_render_size", 0),
|
||||
m_FlareInterleave(this, "flare_interleave", false), m_FlareAnimationSpeed(this, "flare_animation_speed", 0.0f),
|
||||
m_FlareLifetimeSeconds(this, "flare_lifetime_seconds", 0.0f)
|
||||
m_FlareLifetimeSeconds(this, "flare_lifetime_seconds", 0.0f),
|
||||
m_FlareStartFadeSeconds(this, "flare_start_fade_seconds", 0.0f),
|
||||
m_FlareStopFadeSeconds(this, "flare_stop_fade_seconds", 0.0f)
|
||||
{
|
||||
m_Clicking = false;
|
||||
m_MouseHovering = false;
|
||||
|
|
@ -341,21 +344,38 @@ void CMiniMap::DrawFlare(CCanvas2D& canvas, const MapFlare& flare, double curren
|
|||
flareCenter.X - m_FlareRenderSize, flareCenter.Y - m_FlareRenderSize,
|
||||
flareCenter.X + m_FlareRenderSize, flareCenter.Y + m_FlareRenderSize);
|
||||
|
||||
const u32 flooredStep = floor((currentTime - flare.time) * m_FlareAnimationSpeed);
|
||||
const double deltaTime = currentTime - flare.time;
|
||||
const double remainingTime = m_FlareLifetimeSeconds - deltaTime;
|
||||
const u32 flooredStep = floor(deltaTime * m_FlareAnimationSpeed);
|
||||
|
||||
CTexturePtr texture = m_FlareTextures[flooredStep % m_FlareTextures.size()];
|
||||
// TODO: Only draw inside the minimap circle.
|
||||
canvas.DrawTexture(texture, destination, CRect(0, 0, texture->GetWidth(), texture->GetHeight()), flare.color, CColor(0.0f, 0.0f, 0.0f, 0.0f), 0.0f);
|
||||
const float startFadeAlpha = m_FlareStartFadeSeconds > 0.0f ? deltaTime / m_FlareStartFadeSeconds : 1.0f;
|
||||
const float stopFadeAlpha = m_FlareStopFadeSeconds > 0.0f ? remainingTime / m_FlareStopFadeSeconds : 1.0f;
|
||||
const float alpha = Clamp(std::min(
|
||||
SmoothStep(0.0f, 1.0f, startFadeAlpha), SmoothStep(0.0f, 1.0f, stopFadeAlpha)),
|
||||
0.0f, 1.0f);
|
||||
|
||||
// Draw a second circle if the first has reached half of the animation
|
||||
DrawFlareFrame(canvas, flooredStep % m_FlareTextures.size(), destination, flare.color, alpha);
|
||||
|
||||
// Draw a second circle if the first has reached half of the animation.
|
||||
if (m_FlareInterleave && flooredStep >= m_FlareTextures.size() / 2)
|
||||
{
|
||||
texture = m_FlareTextures[(flooredStep - m_FlareTextures.size() / 2) % m_FlareTextures.size()];
|
||||
// TODO: Only draw inside the minimap circle.
|
||||
canvas.DrawTexture(texture, destination, CRect(0, 0, texture->GetWidth(), texture->GetHeight()), flare.color, CColor(0.0f, 0.0f, 0.0f, 0.0f), 0.0f);
|
||||
DrawFlareFrame(canvas, (flooredStep - m_FlareTextures.size() / 2) % m_FlareTextures.size(),
|
||||
destination, flare.color, alpha);
|
||||
}
|
||||
}
|
||||
|
||||
void CMiniMap::DrawFlareFrame(CCanvas2D& canvas, const u32 frameIndex,
|
||||
const CRect& destination, const CColor& color, float alpha) const
|
||||
{
|
||||
// TODO: Only draw inside the minimap circle.
|
||||
CTexturePtr texture = m_FlareTextures[frameIndex % m_FlareTextures.size()];
|
||||
CColor finalColor = color;
|
||||
finalColor.a *= alpha;
|
||||
canvas.DrawTexture(texture, destination,
|
||||
CRect(0, 0, texture->GetWidth(), texture->GetHeight()), finalColor,
|
||||
CColor(0.0f, 0.0f, 0.0f, 0.0f), 0.0f);
|
||||
}
|
||||
|
||||
void CMiniMap::Draw(CCanvas2D& canvas)
|
||||
{
|
||||
PROFILE3("render minimap");
|
||||
|
|
|
|||
|
|
@ -80,6 +80,8 @@ private:
|
|||
CGUISimpleSetting<bool> m_FlareInterleave;
|
||||
CGUISimpleSetting<float> m_FlareAnimationSpeed;
|
||||
CGUISimpleSetting<float> m_FlareLifetimeSeconds;
|
||||
CGUISimpleSetting<float> m_FlareStartFadeSeconds;
|
||||
CGUISimpleSetting<float> m_FlareStopFadeSeconds;
|
||||
|
||||
// Whether to draw a black square around and under the minimap.
|
||||
CGUISimpleSetting<bool> m_Mask;
|
||||
|
|
@ -94,7 +96,8 @@ private:
|
|||
|
||||
void DrawViewRect(CCanvas2D& canvas) const;
|
||||
|
||||
void DrawFlare(CCanvas2D& canvas, const MapFlare& flare, double curentTime) const;
|
||||
void DrawFlare(CCanvas2D& canvas, const MapFlare& flare, double currentTime) const;
|
||||
void DrawFlareFrame(CCanvas2D& canvas, const u32 frameIndex, const CRect& destination, const CColor& color, float alpha) const;
|
||||
|
||||
void GetMouseWorldCoordinates(float& x, float& z) const;
|
||||
|
||||
|
|
|
|||
|
|
@ -22,13 +22,13 @@
|
|||
#define RADTODEG(a) ((a) * (180.0f/(float)M_PI))
|
||||
#define SQR(x) ((x) * (x))
|
||||
|
||||
template <typename T>
|
||||
template<typename T>
|
||||
inline T Interpolate(const T& a, const T& b, float t)
|
||||
{
|
||||
return a + (b - a) * t;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
template<typename T>
|
||||
inline T Clamp(T value, T min, T max)
|
||||
{
|
||||
if (value <= min)
|
||||
|
|
@ -38,6 +38,13 @@ inline T Clamp(T value, T min, T max)
|
|||
return value;
|
||||
}
|
||||
|
||||
template<typename T>
|
||||
inline T SmoothStep(T edge0, T edge1, T value)
|
||||
{
|
||||
value = Clamp<T>((value - edge0) / (edge1 - edge0), 0, 1);
|
||||
return value * value * (3 - 2 * value);
|
||||
}
|
||||
|
||||
inline float sgn(float a)
|
||||
{
|
||||
if (a > 0.0f)
|
||||
|
|
|
|||
Loading…
Reference in a new issue