+#include "bgmscript.qh"
+#include "_.qh"
+
+#include "../common/util.qh"
+
#define CONSTANT_SPEED_DECAY
float bgmscriptbuf;
float bgmscriptbufsize;
float bgmscriptbufloaded;
-.float bgmscriptline;
-.float bgmscriptline0;
-.float bgmscriptvolume;
-.float bgmscripttime;
-.float bgmscriptstate;
-.float bgmscriptstatetime;
+class(BGMScript) .float bgmscriptline;
+class(BGMScript) .float bgmscriptline0;
+class(BGMScript) .float bgmscriptvolume;
+class(BGMScript) .float bgmscripttime;
+class(BGMScript) .float bgmscriptstate;
+class(BGMScript) .float bgmscriptstatetime;
float GetAttackDecaySustainAmplitude(float a, float d, float s, float t)
{
// attack: from 0 to 1, in time a for a full length
// decay: from 1 to s, in time d
// sustain: s
-
+
if(t < 0)
return 0;
-
+
if(a)
if(t <= a)
return t / a;
if(!r)
return 0;
-
+
if(t > r)
return 0;
-
+
releaseval = s * (1 - t / r);
if(t < -d)
if(!s)
return 0;
-
+
// if amp > s, we may be in the attack or in the prolonged decay curve
releasetime = (1 - amp / s) * r;
e.bgmscriptline = e.bgmscriptline0 = i;
if(i >= bgmscriptbufsize)
{
- print("ERROR: bgmscript does not define ", e.bgmscript, "\n");
- e.bgmscript = "";
+ printf("ERROR: bgmscript does not define %s\n", e.bgmscript);
+ strunzone(e.bgmscript);
+ e.bgmscript = string_null;
}
}
}
if(e.bgmscript == "")
return 1;
-
+
if(autocvar_bgmvolume <= 0)
return -1;
- e.just_toggled = FALSE;
+ e.just_toggled = false;
if(bgmtime < 0)
return -1;
if(bgmtime < e.bgmscripttime)
{
- //print("reset ", e.bgmscript, "\n");
amp = GetCurrentAmplitude(e, e.bgmscripttime - e.bgmscriptstatetime + drawframetime);
e.bgmscriptline = e.bgmscriptline0;
e.bgmscripttime = bgmtime;
// treat this as a stop event for all notes, to prevent sticking keys
- e.bgmscriptstate = FALSE;
+ e.bgmscriptstate = false;
e.bgmscriptvolume = 1;
e.bgmscriptstatetime = bgmtime - GetTimeForAmplitude(e, amp);
}
// find the CURRENT line
- for(;;)
+ for (;;)
{
tokenize_console(bufstr_get(bgmscriptbuf, e.bgmscriptline));
if(stof(argv(1)) >= bgmtime || argv(0) != e.bgmscript)
vel = stof(argv(2));
if(vel > 0)
{
- e.just_toggled = e.bgmscriptstate = TRUE;
+ e.just_toggled = e.bgmscriptstate = true;
e.bgmscriptvolume = vel;
}
else
- e.just_toggled = e.bgmscriptstate = FALSE;
+ e.just_toggled = e.bgmscriptstate = false;
e.bgmscriptstatetime = e.bgmscripttime - GetTimeForAmplitude(e, amp);
}