]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blobdiff - qcsrc/common/triggers/func/rainsnow.qc
Merge branch 'master' into Lyberta/StandaloneOverkillWeapons
[xonotic/xonotic-data.pk3dir.git] / qcsrc / common / triggers / func / rainsnow.qc
index dc569f69a1a738a1f8dbecefa82d6d69ee12fbc9..ff49eca2c0176c899cdaf1ccd02d9669e0fd851b 100644 (file)
@@ -1,16 +1,15 @@
+#include "rainsnow.qh"
 REGISTER_NET_LINKED(ENT_CLIENT_RAINSNOW)
 
 #ifdef SVQC
 bool rainsnow_SendEntity(entity this, entity to, float sf)
 {
+       vector myorg = this.origin + this.mins;
+       vector mysize = this.maxs - this.mins;
        WriteHeader(MSG_ENTITY, ENT_CLIENT_RAINSNOW);
        WriteByte(MSG_ENTITY, this.state);
-       WriteCoord(MSG_ENTITY, this.origin_x + this.mins_x);
-       WriteCoord(MSG_ENTITY, this.origin_y + this.mins_y);
-       WriteCoord(MSG_ENTITY, this.origin_z + this.mins_z);
-       WriteCoord(MSG_ENTITY, this.maxs_x - this.mins_x);
-       WriteCoord(MSG_ENTITY, this.maxs_y - this.mins_y);
-       WriteCoord(MSG_ENTITY, this.maxs_z - this.mins_z);
+       WriteVector(MSG_ENTITY, myorg);
+       WriteVector(MSG_ENTITY, mysize);
        WriteShort(MSG_ENTITY, compressShortVector(this.dest));
        WriteShort(MSG_ENTITY, this.count);
        WriteByte(MSG_ENTITY, this.cnt);
@@ -35,21 +34,23 @@ spawnfunc(func_rain)
        if (!this.dest)
                this.dest = '0 0 -700';
        this.angles = '0 0 0';
-       this.movetype = MOVETYPE_NONE;
+       set_movetype(this, MOVETYPE_NONE);
        this.solid = SOLID_NOT;
        SetBrushEntityModel(this);
        if (!this.cnt)
+       {
                this.cnt = 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);
 }
@@ -73,46 +74,54 @@ spawnfunc(func_snow)
        if (!this.dest)
                this.dest = '0 0 -300';
        this.angles = '0 0 0';
-       this.movetype = MOVETYPE_NONE;
+       set_movetype(this, MOVETYPE_NONE);
        this.solid = SOLID_NOT;
        SetBrushEntityModel(this);
        if (!this.cnt)
+       {
                this.cnt = 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);
 }
 #elif defined(CSQC)
+float autocvar_cl_rainsnow_maxdrawdist = 2048;
+
 void Draw_Rain(entity this)
 {
-    te_particlerain(this.origin + this.mins, this.origin + this.maxs, this.velocity, floor(this.count * drawframetime + random()), this.glow_color);
+       vector maxdist = '1 1 0' * autocvar_cl_rainsnow_maxdrawdist;
+       maxdist.z = 5;
+       if(boxesoverlap(vec2(view_origin) - maxdist, vec2(view_origin) + maxdist, vec2(this.absmin) - '0 0 5', vec2(this.absmax) + '0 0 5'))
+       //if(autocvar_cl_rainsnow_maxdrawdist <= 0 || vdist(vec2(this.origin) - vec2(this.absmin + this.absmax * 0.5), <=, autocvar_cl_rainsnow_maxdrawdist))
+       te_particlerain(this.origin + this.mins, this.origin + this.maxs, this.velocity, floor(this.count * drawframetime + random()), this.glow_color);
 }
 
 void Draw_Snow(entity this)
 {
-    te_particlesnow(this.origin + this.mins, this.origin + this.maxs, this.velocity, floor(this.count * drawframetime + random()), this.glow_color);
+       vector maxdist = '1 1 0' * autocvar_cl_rainsnow_maxdrawdist;
+       maxdist.z = 5;
+       if(boxesoverlap(vec2(view_origin) - maxdist, vec2(view_origin) + maxdist, vec2(this.absmin) - '0 0 5', vec2(this.absmax) + '0 0 5'))
+       //if(autocvar_cl_rainsnow_maxdrawdist <= 0 || vdist(vec2(this.origin) - vec2(this.absmin + this.absmax * 0.5), <=, autocvar_cl_rainsnow_maxdrawdist))
+       te_particlesnow(this.origin + this.mins, this.origin + this.maxs, this.velocity, floor(this.count * drawframetime + random()), this.glow_color);
 }
 
 NET_HANDLE(ENT_CLIENT_RAINSNOW, bool isnew)
 {
-       this.impulse = ReadByte(); // Rain, Snow, or Whatever
-       this.origin_x = ReadCoord();
-       this.origin_y = ReadCoord();
-       this.origin_z = ReadCoord();
-       this.maxs_x = ReadCoord();
-       this.maxs_y = ReadCoord();
-       this.maxs_z = ReadCoord();
+       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;
@@ -124,7 +133,8 @@ NET_HANDLE(ENT_CLIENT_RAINSNOW, bool isnew)
        setorigin(this, this.origin);
        setsize(this, this.mins, this.maxs);
        this.solid = SOLID_NOT;
-       if(this.impulse)
+       if (isnew) IL_PUSH(g_drawables, this);
+       if(this.state == RAINSNOW_RAIN)
                this.draw = Draw_Rain;
        else
                this.draw = Draw_Snow;