Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
rainsnow.qc
Go to the documentation of this file.
1#include "rainsnow.qh"
2REGISTER_NET_LINKED(ENT_CLIENT_RAINSNOW)
3
4#ifdef SVQC
5bool rainsnow_SendEntity(entity this, entity to, float sf)
6{
7 vector myorg = this.origin + this.mins;
8 vector mysize = this.maxs - this.mins;
9 WriteHeader(MSG_ENTITY, ENT_CLIENT_RAINSNOW);
11 WriteVector(MSG_ENTITY, myorg);
12 WriteVector(MSG_ENTITY, mysize);
16 WriteShort(MSG_ENTITY, bound(0, this.fade_end, 32767));
17 return true;
18}
19
20/*QUAKED spawnfunc_func_rain (0 .5 .8) ?
21This is an invisible area like a trigger, which rain falls inside of.
22
23Keys:
24"velocity"
25 falling direction (should be something like '0 0 -700', use the X and Y velocity for wind)
26"cnt"
27 sets color of rain (default 12 - white)
28"count"
29 adjusts density, this many particles fall every second for a 1024x1024 area, default is 2000
30*/
31spawnfunc(func_rain)
32{
33 this.dest = this.velocity;
34 this.velocity = '0 0 0';
35 if (!this.dest)
36 this.dest = '0 0 -700';
37 this.angles = '0 0 0';
39 this.solid = SOLID_NOT;
40 SetBrushEntityModel(this, true);
41 if (!this.cnt)
42 {
43 this.cnt = 12;
44 }
45 if (!this.count)
46 this.count = 2000;
47 // relative to absolute particle count
48 //this.count = 0.1 * this.count * (this.size_x / 1024) * (this.size_y / 1024);
49 if (this.count < 1)
50 this.count = 1;
51 if(this.count > 65535)
52 this.count = 65535;
53
54 this.state = RAINSNOW_RAIN;
55
56 Net_LinkEntity(this, false, 0, rainsnow_SendEntity);
57}
58
59
60/*QUAKED spawnfunc_func_snow (0 .5 .8) ?
61This is an invisible area like a trigger, which snow falls inside of.
62
63Keys:
64"velocity"
65 falling direction (should be something like '0 0 -300', use the X and Y velocity for wind)
66"cnt"
67 sets color of rain (default 12 - white)
68"count"
69 adjusts density, this many particles fall every second for a 1024x1024 area, default is 2000
70*/
71spawnfunc(func_snow)
72{
73 this.dest = this.velocity;
74 this.velocity = '0 0 0';
75 if (!this.dest)
76 this.dest = '0 0 -300';
77 this.angles = '0 0 0';
79 this.solid = SOLID_NOT;
80 SetBrushEntityModel(this, true);
81 if (!this.cnt)
82 {
83 this.cnt = 12;
84 }
85 if (!this.count)
86 this.count = 2000;
87 // relative to absolute particle count
88 //this.count = 0.1 * this.count * (this.size_x / 1024) * (this.size_y / 1024);
89 if (this.count < 1)
90 this.count = 1;
91 if(this.count > 65535)
92 this.count = 65535;
93
94 this.state = RAINSNOW_SNOW;
95
96 Net_LinkEntity(this, false, 0, rainsnow_SendEntity);
97}
98#elif defined(CSQC)
99float autocvar_cl_rainsnow_maxdrawdist = 1000;
100
101void Draw_RainSnow(entity this)
102{
103 float drawdist = ((this.fade_end) ? this.fade_end : autocvar_cl_rainsnow_maxdrawdist);
104 vector maxdist = '1 1 1' * drawdist;
105
106 vector effbox_min = vec_to_max(view_origin - maxdist, this.origin + this.mins);
107 vector effbox_max = vec_to_min(view_origin + maxdist, this.origin + this.maxs);
108
109 vector mysize = effbox_max - effbox_min;
110 float mycount = bound(1, 0.1 * this.count * (mysize.x / 1024) * (mysize.y / 1024), 65535);
111
112 if(boxesoverlap(view_origin - maxdist, view_origin + maxdist, this.absmin, this.absmax)) // optimisation: don't render any rain if the player is outside the view distance
113 {
114 if(this.state == RAINSNOW_RAIN)
115 te_particlerain(effbox_min, effbox_max, this.velocity, floor(mycount * drawframetime + random()), this.glow_color);
116 else
117 te_particlesnow(effbox_min, effbox_max, this.velocity, floor(mycount * drawframetime + random()), this.glow_color);
118 }
119}
120
121NET_HANDLE(ENT_CLIENT_RAINSNOW, bool isnew)
122{
123 this.state = ReadByte(); // Rain, Snow, or Whatever
124 this.origin = ReadVector();
125 this.maxs = ReadVector();
126 this.velocity = decompressShortVector(ReadShort());
127 this.count = ReadShort();
128 this.glow_color = ReadByte(); // color
129 this.fade_end = ReadShort();
130
131 return = true;
132
133 this.mins = -0.5 * this.maxs;
134 this.maxs = 0.5 * this.maxs;
135 this.origin = this.origin - this.mins;
136
137 this.solid = SOLID_NOT; // before setorigin/setsize to prevent area grid linking
138 setorigin(this, this.origin);
139 setsize(this, this.mins, this.maxs);
140 if (isnew) IL_PUSH(g_drawables, this);
141 this.draw = Draw_RainSnow;
142}
143#endif
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
float cnt
Definition powerups.qc:24
float count
Definition powerups.qc:22
IntrusiveList g_drawables
Definition main.qh:91
vector view_origin
Definition main.qh:109
float drawframetime
Definition main.qh:108
float fade_end
Definition item.qh:87
float compressShortVector(vector vec)
Definition util.qc:519
vector decompressShortVector(int data)
Definition util.qc:484
vector mins
vector velocity
const float SOLID_NOT
vector maxs
vector absmax
vector origin
float solid
vector absmin
int state
float glow_color
ent angles
Definition ent_cs.qc:146
WriteByte(chan, ent.angles.y/DEC_FACTOR)
ERASEABLE entity IL_PUSH(IntrusiveList this, entity it)
Push to tail.
vector dest
Definition jumppads.qh:54
#define NET_HANDLE(id, param)
Definition net.qh:15
const int MSG_ENTITY
Definition net.qh:156
#define ReadVector()
Definition net.qh:349
#define WriteHeader(to, id)
Definition net.qh:265
#define REGISTER_NET_LINKED(id)
Definition net.qh:91
void Net_LinkEntity(entity e, bool docull, float dt, bool(entity this, entity to, int sendflags) sendfunc)
Definition net.qh:167
int ReadByte()
float bound(float min, float value, float max)
float random(void)
void WriteShort(float data, float dest, float desto)
float floor(float f)
void set_movetype(entity this, int mt)
Definition movetypes.qc:4
const int MOVETYPE_NONE
Definition movetypes.qh:129
ERASEABLE vector vec_to_min(vector a, vector b)
Definition p2mathlib.qc:30
ERASEABLE vector vec_to_max(vector a, vector b)
Definition p2mathlib.qc:40
bool rainsnow_SendEntity(entity this, entity to, float sf)
Definition rainsnow.qc:5
const int RAINSNOW_SNOW
Definition rainsnow.qh:4
const int RAINSNOW_RAIN
Definition rainsnow.qh:5
vector
Definition self.qh:96
#define spawnfunc(id)
Definition spawnfunc.qh:107
void SetBrushEntityModel(entity this, bool with_lod)
Definition subs.qc:419
ERASEABLE float boxesoverlap(vector m1, vector m2, vector m3, vector m4)
Requires that m2>m1 in all coordinates, and that m4>m3.
Definition vector.qh:72