Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
168 changes: 168 additions & 0 deletions src/SB/Core/x/xHudMeter.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,171 @@
#include "xHudMeter.h"

#include <types.h>

#include "xString.h"
#include "xMathInlines.h"

namespace xhud
{
namespace
{
static void add_global_tweaks()
{
}
} // namespace

meter_widget::meter_widget(const meter_asset& asset)
: widget((xhud::asset&)asset), res((xhud::meter_asset&)asset), value(asset.start_value),
min_value(asset.min_value), max_value(asset.max_value), end_value(asset.start_value),
value_vel(0.0f), ping_delay(10.0f)
{
add_global_tweaks();
}
} // namespace xhud

void xhud::meter_widget::set_value(F32 v)
{
F32 dvalue;
F32 sign;

dvalue = v - value;
if (dvalue < -0.01f)
{
if (res.sound.start_decrement != 0)
{
xSndPlay(res.sound.start_decrement, 1.0f, 0.0f, 0x80, 0x0, NULL, SND_CAT_GAME, 0.0f);
}

if (res.decrement_time < 0.01f)
{
set_value_immediate(v);
return;
}

dvalue = -1.0f;
}
else if (dvalue > 0.01f)
{
if (res.sound.start_increment != 0)
{
xSndPlay(res.sound.start_increment, 1.0f, 0.0f, 0x80, 0x0, NULL, SND_CAT_GAME, 0.0f);
}

if (res.increment_time < 0.01f)
{
set_value_immediate(v);
return;
}

dvalue = 1.0f;
}
else
{
set_value_immediate(v);
return;
}

end_value = dvalue;

if (res.decrement_time == 0.0f)
{
printf("decrement time = 0 -- ass saved!\n");
}

dvalue = res.decrement_time > 1e-5f ? 1e-5f : dvalue / res.decrement_time;
value_vel = dvalue;
value_accel = 50.0f * res.decrement_time;

if (xsqrt(2.0f * (v - value) / res.decrement_time) > 2.0f)
{
value_accel = 25.0f * res.decrement_time;
}
}

void xhud::meter_widget::set_value_immediate(F32 v)
{
value = v;
end_value = v;
value_vel = 0.0f;
}

void xhud::meter_widget::destruct()
{
xhud::widget::destruct();
}

U32 xhud::meter_widget::type() const
{
static U32 myid = xStrHash(res.type_name());

return myid;
}

bool xhud::meter_widget::is(U32 id) const
{
bool isTheWidget = false;

if (id == xhud::meter_widget::type() || xhud::widget::is(id))
{
isTheWidget = true;
}

return isTheWidget;
}

void xhud::meter_widget::updater(F32 dt)
{
F32 old_value;
F32 pitch; // This was Heavy Iron, idk why they chose a name that causes name collisions :(
F32 min_ping_time;

xhud::widget::updater(dt);

ping_delay += dt;
this->pitch += dt;

if (value_vel != 0.0f)
{
old_value = value;

value = value + dt * (0.5f * value_accel * dt);
value_vel += value_accel * dt;

if (value_vel < 0.0f)
{
if (value <= end_value)
{
value = end_value;
end_value = 0.0f;
}

pitch = range_limit<F32>(-4.0f * this->pitch, -10.0f, 6.5f);
min_ping_time = 0.05f * xpow(0.5f, 0.083333336f * pitch);

if ((S32)value != (S32)old_value && res.sound.decrement != 0 &&
ping_delay > min_ping_time)
{
ping_delay = 0.0f;
pings.play(res.sound.decrement, 1.0f, pitch, 0x80, 0, 0, SND_CAT_GAME);
}
}
else
{
if (value >= end_value)
{
value = end_value;
value_vel = 0.0f;
}

pitch = range_limit<F32>(2.0f * this->pitch, -10.0f, 6.5f);
min_ping_time = 0.05f * xpow(0.5f, 0.083333336f * pitch);

if ((S32)value != (S32)old_value && res.sound.increment != 0 &&
ping_delay > min_ping_time)
{
ping_delay = 0.0f;
pings.play(res.sound.increment, 1.0f, pitch, 0x80, 0, 0, SND_CAT_GAME);
}
}
}
}
19 changes: 19 additions & 0 deletions src/SB/Core/x/xHudMeter.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ namespace xhud
U32 start_decrement;
U32 decrement;
} sound;

static const char* type_name()
{
return "hud:meter";
}
};

struct meter_widget : widget
Expand All @@ -34,6 +39,20 @@ namespace xhud
F32 ping_delay;
F32 pitch;
sound_queue<4> pings;

meter_widget(const meter_asset& asset);

void set_value(F32 v);
void set_value_immediate(F32 v);
void destruct();
U32 type() const;
bool is(U32 id) const;
void updater(F32 dt);

void update(F32 dt)
{
updater(dt);
}
};
} // namespace xhud

Expand Down
10 changes: 10 additions & 0 deletions src/SB/Core/x/xSnd.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,16 @@ template <S32 N> struct sound_queue
U32 _playing[N + 1];
S32 head;
S32 tail;

sound_queue()
{
head = 0;
tail = 0;
}

void play(U32 id, F32 vol, F32 pitch, U32 priority, U32 flags, U32 parentID,
sound_category snd_category);
void push(U32 id);
};

enum sound_effect
Expand Down