forked from 0ad/0ad
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
@ -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>
|
||||
|
BIN
binaries/data/mods/public/art/textures/animated/minimap-flare/frame00.png
(Stored with Git LFS)
BIN
binaries/data/mods/public/art/textures/animated/minimap-flare/frame00.png
(Stored with Git LFS)
Binary file not shown.
BIN
binaries/data/mods/public/art/textures/animated/minimap-flare/frame01.png
(Stored with Git LFS)
BIN
binaries/data/mods/public/art/textures/animated/minimap-flare/frame01.png
(Stored with Git LFS)
Binary file not shown.
BIN
binaries/data/mods/public/art/textures/animated/minimap-flare/frame02.png
(Stored with Git LFS)
BIN
binaries/data/mods/public/art/textures/animated/minimap-flare/frame02.png
(Stored with Git LFS)
Binary file not shown.
BIN
binaries/data/mods/public/art/textures/animated/minimap-flare/frame13.png
(Stored with Git LFS)
BIN
binaries/data/mods/public/art/textures/animated/minimap-flare/frame13.png
(Stored with Git LFS)
Binary file not shown.
BIN
binaries/data/mods/public/art/textures/animated/minimap-flare/frame14.png
(Stored with Git LFS)
BIN
binaries/data/mods/public/art/textures/animated/minimap-flare/frame14.png
(Stored with Git LFS)
Binary file not shown.
BIN
binaries/data/mods/public/art/textures/animated/minimap-flare/frame15.png
(Stored with Git LFS)
BIN
binaries/data/mods/public/art/textures/animated/minimap-flare/frame15.png
(Stored with Git LFS)
Binary file not shown.
@ -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 New Issue
Block a user