]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/client/bgmscript.qc
Merge branch 'master' into TimePath/issue-1170
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / bgmscript.qc
index 587a2e96cf8ac289bf287905ce5560c7eb17ab65..9d024941e6bf00d4b8c7f53133deca7535edbde4 100644 (file)
@@ -17,10 +17,10 @@ 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;
@@ -38,10 +38,10 @@ float GetReleaseAmplitude(float d, float s, float r, float t)
 
        if(!r)
                return 0;
-       
+
        if(t > r)
                return 0;
-       
+
        releaseval = s * (1 - t / r);
 
        if(t < -d)
@@ -70,7 +70,7 @@ float GetReleaseTime(float d, float s, float r, float amp)
 
        if(!s)
                return 0;
-       
+
        // if amp > s, we may be in the attack or in the prolonged decay curve
        releasetime = (1 - amp / s) * r;
 
@@ -131,8 +131,9 @@ void BGMScript_InitEntity(entity e)
                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;
                }
        }
 }
@@ -167,45 +168,42 @@ float GetTimeForAmplitude(entity e, float amp)
 
 float BGMScript(entity e)
 {
-       float t;
        float amp, vel;
 
        if(e.bgmscript == "")
                return 1;
-       
-       if(cvar("bgmvolume") <= 0)
+
+       if(autocvar_bgmvolume <= 0)
                return -1;
 
        e.just_toggled = FALSE;
 
-       t = gettime(GETTIME_CDTRACK);
-       if(t < 0)
+       if(bgmtime < 0)
                return -1;
 
-       if(t < e.bgmscripttime)
+       if(bgmtime < e.bgmscripttime)
        {
-               //print("reset ", e.bgmscript, "\n");
                amp = GetCurrentAmplitude(e, e.bgmscripttime - e.bgmscriptstatetime + drawframetime);
 
                e.bgmscriptline = e.bgmscriptline0;
-               e.bgmscripttime = t;
+               e.bgmscripttime = bgmtime;
 
                // treat this as a stop event for all notes, to prevent sticking keys
                e.bgmscriptstate = FALSE;
                e.bgmscriptvolume = 1;
-               e.bgmscriptstatetime = t - GetTimeForAmplitude(e, amp);
+               e.bgmscriptstatetime = bgmtime - GetTimeForAmplitude(e, amp);
        }
 
        // find the CURRENT line
        for(;;)
        {
                tokenize_console(bufstr_get(bgmscriptbuf, e.bgmscriptline));
-               if(stof(argv(1)) >= t || argv(0) != e.bgmscript)
+               if(stof(argv(1)) >= bgmtime || argv(0) != e.bgmscript)
                {
-                       e.bgmscripttime = t;
-                       return GetCurrentAmplitude(e, t - e.bgmscriptstatetime);
+                       e.bgmscripttime = bgmtime;
+                       return GetCurrentAmplitude(e, bgmtime - e.bgmscriptstatetime);
                }
-               else if(t >= stof(argv(1)))
+               else if(bgmtime >= stof(argv(1)))
                {
                        e.bgmscriptline += 1;
                        e.bgmscripttime = stof(argv(1));