From c76590105800204b9122938be16cae9cbc4b453b Mon Sep 17 00:00:00 2001 From: Freddy Date: Fri, 9 Mar 2018 02:52:49 +0100 Subject: [PATCH] func_rain and func_snow: fix density, remove magic numbers and use colormap instead of cnt for color --- qcsrc/common/triggers/func/rainsnow.qc | 54 ++++++++++++++++++-------- qcsrc/common/triggers/func/rainsnow.qh | 4 ++ qcsrc/lib/net.qh | 1 - 3 files changed, 42 insertions(+), 17 deletions(-) diff --git a/qcsrc/common/triggers/func/rainsnow.qc b/qcsrc/common/triggers/func/rainsnow.qc index 1817a9ce9..1c1a39bb0 100644 --- a/qcsrc/common/triggers/func/rainsnow.qc +++ b/qcsrc/common/triggers/func/rainsnow.qc @@ -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; diff --git a/qcsrc/common/triggers/func/rainsnow.qh b/qcsrc/common/triggers/func/rainsnow.qh index 6f70f09be..d60eb4f48 100644 --- a/qcsrc/common/triggers/func/rainsnow.qh +++ b/qcsrc/common/triggers/func/rainsnow.qh @@ -1 +1,5 @@ #pragma once + + +const int RAINSNOW_SNOW = 0; +const int RAINSNOW_RAIN = 1; diff --git a/qcsrc/lib/net.qh b/qcsrc/lib/net.qh index fe2952e2c..a9c28dab3 100644 --- a/qcsrc/lib/net.qh +++ b/qcsrc/lib/net.qh @@ -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; -- 2.39.2