mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2025-01-26 02:07:26 +00:00
fix waving for tiles with EFX_WAVY set; minor optimizations
This commit is contained in:
parent
063c270e6a
commit
8c467517fd
2 changed files with 22 additions and 14 deletions
|
@ -413,28 +413,27 @@ void TileEffectData::Wavy::update(float dt)
|
||||||
|
|
||||||
wavySave = wavy;
|
wavySave = wavy;
|
||||||
lerpIn = 0;
|
lerpIn = 0;
|
||||||
|
waving = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (waving)
|
if (waving)
|
||||||
{
|
{
|
||||||
// TODO: set waving=false if magnitude==0 ?
|
const float spd = PI*1.1f;
|
||||||
float spd = PI*1.1f;
|
const float magRedSpd = 48;
|
||||||
float magRedSpd = 48;
|
const float lerpSpd = 5.0;
|
||||||
float lerpSpd = 5.0;
|
const float wavySzInv = 1.0f / float(wavy.size());
|
||||||
float wavySz = float(wavy.size());
|
|
||||||
for (size_t i = 0; i < wavy.size(); i++)
|
for (size_t i = 0; i < wavy.size(); i++)
|
||||||
{
|
{
|
||||||
float weight = float(i)/wavySz;
|
const float m = float(i)*wavySzInv;
|
||||||
|
float weight = m;
|
||||||
if (flip)
|
if (flip)
|
||||||
weight = 1.0f-weight;
|
weight = 1.0f-weight;
|
||||||
if (weight < 0.125f)
|
if (weight < 0.125f)
|
||||||
weight *= 0.5f;
|
weight *= 0.5f;
|
||||||
wavy[i] = sinf(angleOffset + (float(i)/wavySz)*PI)*(magnitude*effectMult)*weight;
|
float val = sinf(angleOffset + m*PI)*(magnitude*effectMult)*weight;
|
||||||
if (!wavySave.empty())
|
if (!wavySave.empty())
|
||||||
{
|
val = val * lerpIn + (wavySave[i] * (1.0f-lerpIn));
|
||||||
if (lerpIn < 1)
|
wavy[i] = val;
|
||||||
wavy[i] = wavy[i] * lerpIn + (wavySave[i] * (1.0f-lerpIn));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (lerpIn < 1)
|
if (lerpIn < 1)
|
||||||
|
@ -448,26 +447,34 @@ void TileEffectData::Wavy::update(float dt)
|
||||||
{
|
{
|
||||||
magnitude -= magRedSpd*dt;
|
magnitude -= magRedSpd*dt;
|
||||||
if (magnitude < 0)
|
if (magnitude < 0)
|
||||||
magnitude = 0;
|
stop();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
magnitude += magRedSpd*dt;
|
magnitude += magRedSpd*dt;
|
||||||
if (magnitude > 0)
|
if (magnitude > 0)
|
||||||
magnitude = 0;
|
stop();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void TileEffectData::Wavy::stop()
|
||||||
|
{
|
||||||
|
magnitude = 0;
|
||||||
|
waving = false;
|
||||||
|
}
|
||||||
|
|
||||||
void TileEffectData::update(float dt, const TileData *t)
|
void TileEffectData::update(float dt, const TileData *t)
|
||||||
{
|
{
|
||||||
switch(efxtype)
|
switch(efxtype)
|
||||||
{
|
{
|
||||||
case EFX_WAVY:
|
case EFX_WAVY:
|
||||||
|
if(!(wavy.waving || wavy.touching))
|
||||||
|
break;
|
||||||
wavy.update(dt);
|
wavy.update(dt);
|
||||||
if(const size_t N = wavy.wavy.size())
|
if(const size_t N = wavy.wavy.size())
|
||||||
grid->setFromWavy(&wavy.wavy[0], N, t->et->w);
|
grid->setFromWavy(&wavy.wavy[0], N, t->et->w);
|
||||||
break;
|
// fall through
|
||||||
|
|
||||||
case EFX_SEGS:
|
case EFX_SEGS:
|
||||||
grid->update(dt);
|
grid->update(dt);
|
||||||
|
|
|
@ -137,6 +137,7 @@ struct TileEffectData
|
||||||
float hitPerc, effectMult;
|
float hitPerc, effectMult;
|
||||||
bool waving, flip, touching;
|
bool waving, flip, touching;
|
||||||
void update(float dt);
|
void update(float dt);
|
||||||
|
void stop();
|
||||||
};
|
};
|
||||||
Wavy wavy;
|
Wavy wavy;
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue