overlays: fix indentation

This commit is contained in:
Megamouse 2023-01-16 18:52:23 +01:00
parent 24445123fc
commit 709305df0e
2 changed files with 174 additions and 174 deletions

View File

@ -5,143 +5,143 @@
namespace rsx
{
namespace overlays
{
void animation_base::begin_animation(u64 frame)
{
frame_start = frame;
frame_end = u64(frame + duration * g_cfg.video.vblank_rate);
}
namespace overlays
{
void animation_base::begin_animation(u64 frame)
{
frame_start = frame;
frame_end = u64(frame + duration * g_cfg.video.vblank_rate);
}
f32 animation_base::get_progress_ratio(u64 frame) const
{
if (!frame_start)
{
return 0.f;
}
f32 animation_base::get_progress_ratio(u64 frame) const
{
if (!frame_start)
{
return 0.f;
}
f32 t = f32(frame - frame_start) / (frame_end - frame_start);
f32 t = f32(frame - frame_start) / (frame_end - frame_start);
switch (type) {
case animation_type::linear:
break;
case animation_type::ease_in_quad:
t = t * t;
break;
case animation_type::ease_out_quad:
t = t * (2.0f - t);
break;
case animation_type::ease_in_out_cubic:
t = t > 0.5f ? 4.0f * std::pow((t - 1.0f), 3.0f) + 1.0f : 4.0f * std::pow(t, 3.0f);
break;
}
switch (type) {
case animation_type::linear:
break;
case animation_type::ease_in_quad:
t = t * t;
break;
case animation_type::ease_out_quad:
t = t * (2.0f - t);
break;
case animation_type::ease_in_out_cubic:
t = t > 0.5f ? 4.0f * std::pow((t - 1.0f), 3.0f) + 1.0f : 4.0f * std::pow(t, 3.0f);
break;
}
return t;
}
return t;
}
void animation_translate::apply(compiled_resource& resource)
{
if (!active)
{
return;
}
void animation_translate::apply(compiled_resource& resource)
{
if (!active)
{
return;
}
const vertex delta = { current.x, current.y, current.z, 0.f };
for (auto& cmd : resource.draw_commands)
{
for (auto& v : cmd.verts)
{
v += delta;
}
}
}
const vertex delta = { current.x, current.y, current.z, 0.f };
for (auto& cmd : resource.draw_commands)
{
for (auto& v : cmd.verts)
{
v += delta;
}
}
}
void animation_translate::update(u64 frame)
{
if (!active)
{
return;
}
void animation_translate::update(u64 frame)
{
if (!active)
{
return;
}
if (frame_start == 0)
{
start = current;
begin_animation(frame);
return;
}
if (frame_start == 0)
{
start = current;
begin_animation(frame);
return;
}
if (frame >= frame_end)
{
// Exit condition
finish();
return;
}
if (frame >= frame_end)
{
// Exit condition
finish();
return;
}
f32 t = get_progress_ratio(frame);
current = lerp(start, end, t);
}
f32 t = get_progress_ratio(frame);
current = lerp(start, end, t);
}
void animation_translate::finish()
{
active = false;
frame_start = 0;
frame_end = 0;
current = end; // Snap current to limit in case we went over
void animation_translate::finish()
{
active = false;
frame_start = 0;
frame_end = 0;
current = end; // Snap current to limit in case we went over
if (on_finish)
{
on_finish();
}
}
if (on_finish)
{
on_finish();
}
}
void animation_color_interpolate::apply(compiled_resource& data)
{
if (!active)
{
return;
}
void animation_color_interpolate::apply(compiled_resource& data)
{
if (!active)
{
return;
}
for (auto& cmd : data.draw_commands)
{
cmd.config.color *= current;
}
}
for (auto& cmd : data.draw_commands)
{
cmd.config.color *= current;
}
}
void animation_color_interpolate::update(u64 frame)
{
if (!active)
{
return;
}
void animation_color_interpolate::update(u64 frame)
{
if (!active)
{
return;
}
if (frame_start == 0)
{
start = current;
begin_animation(frame);
return;
}
if (frame_start == 0)
{
start = current;
begin_animation(frame);
return;
}
if (frame >= frame_end)
{
finish();
return;
}
if (frame >= frame_end)
{
finish();
return;
}
f32 t = get_progress_ratio(frame);
current = lerp(start, end, t);
}
f32 t = get_progress_ratio(frame);
current = lerp(start, end, t);
}
void animation_color_interpolate::finish()
{
active = false;
frame_start = 0;
frame_end = 0;
current = end;
void animation_color_interpolate::finish()
{
active = false;
frame_start = 0;
frame_end = 0;
current = end;
if (on_finish)
{
on_finish();
}
}
};
if (on_finish)
{
on_finish();
}
}
};
}

View File

@ -8,71 +8,71 @@
namespace rsx
{
namespace overlays
{
struct compiled_resource;
namespace overlays
{
struct compiled_resource;
enum class animation_type
{
linear,
ease_in_quad,
ease_out_quad,
ease_in_out_cubic,
};
enum class animation_type
{
linear,
ease_in_quad,
ease_out_quad,
ease_in_out_cubic,
};
struct animation_base
{
protected:
u64 frame_start = 0;
u64 frame_end = 0;
struct animation_base
{
protected:
u64 frame_start = 0;
u64 frame_end = 0;
void begin_animation(u64 frame);
f32 get_progress_ratio(u64 frame) const;
void begin_animation(u64 frame);
f32 get_progress_ratio(u64 frame) const;
template<typename T>
static T lerp(const T& a, const T& b, f32 t)
{
return (a * (1.f - t)) + (b * t);
}
template<typename T>
static T lerp(const T& a, const T& b, f32 t)
{
return (a * (1.f - t)) + (b * t);
}
public:
bool active = false;
animation_type type { animation_type::linear };
f32 duration = 1.f; // in seconds
public:
bool active = false;
animation_type type { animation_type::linear };
f32 duration = 1.f; // in seconds
std::function<void()> on_finish;
std::function<void()> on_finish;
virtual void apply(compiled_resource&) = 0;
virtual void update(u64 frame) = 0;
};
virtual void apply(compiled_resource&) = 0;
virtual void update(u64 frame) = 0;
};
struct animation_translate : animation_base
{
private:
vector3f start{}; // Set `current` instead of this
// NOTE: Necessary because update() is called after rendering,
// resulting in one frame of incorrect translation
public:
vector3f current{};
vector3f end{};
struct animation_translate : animation_base
{
private:
vector3f start{}; // Set `current` instead of this
// NOTE: Necessary because update() is called after rendering,
// resulting in one frame of incorrect translation
public:
vector3f current{};
vector3f end{};
void apply(compiled_resource& data) override;
void update(u64 frame) override;
void finish();
};
void apply(compiled_resource& data) override;
void update(u64 frame) override;
void finish();
};
struct animation_color_interpolate : animation_translate
{
private:
color4f start{};
struct animation_color_interpolate : animation_translate
{
private:
color4f start{};
public:
color4f current{};
color4f end{};
public:
color4f current{};
color4f end{};
void apply(compiled_resource& data) override;
void update(u64 frame) override;
void finish();
};
}
void apply(compiled_resource& data) override;
void update(u64 frame) override;
void finish();
};
}
}