]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
func_rain and func_snow: fix density, remove magic numbers and use colormap instead...
authorFreddy <schro.sb@gmail.com>
Fri, 9 Mar 2018 01:52:49 +0000 (02:52 +0100)
committerFreddy <schro.sb@gmail.com>
Fri, 9 Mar 2018 01:52:49 +0000 (02:52 +0100)
qcsrc/common/triggers/func/rainsnow.qc
qcsrc/common/triggers/func/rainsnow.qh
qcsrc/lib/net.qh

index 1817a9ce9a1e4d658b0b1f8411bc790734e62721..1c1a39bb0152049c284da648a76c44b8b8aa72ee 100644 (file)
@@ -12,7 +12,7 @@ bool rainsnow_SendEntity(entity this, entity to, float sf)
        WriteVector(MSG_ENTITY, mysize);
        WriteShort(MSG_ENTITY, compressShortVector(this.dest));
        WriteShort(MSG_ENTITY, this.count);
-       WriteByte(MSG_ENTITY, this.cnt);
+       WriteByte(MSG_ENTITY, this.colormap);
        return true;
 }
 
@@ -22,7 +22,7 @@ This is an invisible area like a trigger, which rain falls inside of.
 Keys:
 "velocity"
  falling direction (should be something like '0 0 -700', use the X and Y velocity for wind)
-"cnt"
+"colormap"
  sets color of rain (default 12 - white)
 "count"
  adjusts density, this many particles fall every second for a 1024x1024 area, default is 2000
@@ -37,18 +37,29 @@ spawnfunc(func_rain)
        set_movetype(this, MOVETYPE_NONE);
        this.solid = SOLID_NOT;
        SetBrushEntityModel(this);
-       if (!this.cnt)
-               this.cnt = 12;
+       if (!this.colormap)
+       {
+               // backwards compatibility
+               if (this.cnt)
+               {
+                       LOG_WARN("func_rain uses deprecated field cnt, please use colormap instead");
+                       this.colormap = this.cnt;
+               }
+               else
+               {
+                       this.colormap = 12;
+               }
+       }
        if (!this.count)
                this.count = 2000;
-       this.count = 0.01 * this.count * (this.size_x / 1024) * (this.size_y / 1024);
+       // relative to absolute particle count
+       this.count = this.count * (this.size_x / 1024) * (this.size_y / 1024);
        if (this.count < 1)
                this.count = 1;
        if(this.count > 65535)
                this.count = 65535;
 
-       this.state = 1; // 1 is rain, 0 is snow
-       this.Version = 1;
+       this.state = RAINSNOW_RAIN;
 
        Net_LinkEntity(this, false, 0, rainsnow_SendEntity);
 }
@@ -60,7 +71,7 @@ This is an invisible area like a trigger, which snow falls inside of.
 Keys:
 "velocity"
  falling direction (should be something like '0 0 -300', use the X and Y velocity for wind)
-"cnt"
+"colormap"
  sets color of rain (default 12 - white)
 "count"
  adjusts density, this many particles fall every second for a 1024x1024 area, default is 2000
@@ -75,18 +86,29 @@ spawnfunc(func_snow)
        set_movetype(this, MOVETYPE_NONE);
        this.solid = SOLID_NOT;
        SetBrushEntityModel(this);
-       if (!this.cnt)
-               this.cnt = 12;
+       if (!this.colormap)
+       {
+               // backwards compatibility
+               if (this.cnt)
+               {
+                       LOG_WARN("func_snow uses deprecated field cnt, please use colormap instead");
+                       this.colormap = this.cnt;
+               }
+               else
+               {
+                       this.colormap = 12;
+               }
+       }
        if (!this.count)
                this.count = 2000;
-       this.count = 0.01 * this.count * (this.size_x / 1024) * (this.size_y / 1024);
+       // relative to absolute particle count
+       this.count = this.count * (this.size_x / 1024) * (this.size_y / 1024);
        if (this.count < 1)
                this.count = 1;
        if(this.count > 65535)
                this.count = 65535;
 
-       this.state = 0; // 1 is rain, 0 is snow
-       this.Version = 1;
+       this.state = RAINSNOW_SNOW;
 
        Net_LinkEntity(this, false, 0, rainsnow_SendEntity);
 }
@@ -113,11 +135,11 @@ void Draw_Snow(entity this)
 
 NET_HANDLE(ENT_CLIENT_RAINSNOW, bool isnew)
 {
-       this.impulse = ReadByte(); // Rain, Snow, or Whatever
+       this.state = ReadByte(); // Rain, Snow, or Whatever
        this.origin = ReadVector();
        this.maxs = ReadVector();
        this.velocity = decompressShortVector(ReadShort());
-       this.count = ReadShort() * 10;
+       this.count = ReadShort();
        this.glow_color = ReadByte(); // color
 
        return = true;
@@ -130,7 +152,7 @@ NET_HANDLE(ENT_CLIENT_RAINSNOW, bool isnew)
        setsize(this, this.mins, this.maxs);
        this.solid = SOLID_NOT;
        if (isnew) IL_PUSH(g_drawables, this);
-       if(this.impulse)
+       if(this.state == RAINSNOW_RAIN)
                this.draw = Draw_Rain;
        else
                this.draw = Draw_Snow;
index 6f70f09beec2219624baeca92e2cd7deaa104fb4..d60eb4f481ea3bd764aa87325b9a2a125e2cb959 100644 (file)
@@ -1 +1,5 @@
 #pragma once
+
+
+const int RAINSNOW_SNOW = 0;
+const int RAINSNOW_RAIN = 1;
index fe2952e2c4025c3d5f84854627824cc3f4ab3d6f..a9c28dab3ecbc0b44b9a868a0ebab34bcf1a6410 100644 (file)
@@ -107,7 +107,6 @@ STATIC_INIT(C2S_Protocol_renumber) { FOREACH(C2S_Protocol, true, it.m_id = i); }
 #ifdef SVQC
        const int MSG_ENTITY = 5;
 
-       .int Version;  // deprecated, use SendFlags
        .int SendFlags;
 
        IntrusiveList g_uncustomizables;