Xonotic QuakeC
The free, fast arena FPS with crisp movement and a wide array of weapons
all.qc
Go to the documentation of this file.
1#include "all.qh"
2
3const int EFF_NET_VELOCITY = BIT(0);
4const int EFF_NET_COLOR_MIN = BIT(1);
5const int EFF_NET_COLOR_MAX = BIT(2);
6const int EFF_NET_COLOR_SAME = BIT(3); // optimisation bit for sending only one color
7
8REGISTER_NET_TEMP(net_effect)
9#ifdef CSQC
10NET_HANDLE(net_effect, bool isNew)
11{
12 entity eff = ReadRegistered(Effects);
13
14 vector vel = '0 0 0';
15 int eff_cnt = 1;
16 int eff_flags = 0;
17 bool eff_trail = eff.eent_eff_trail;
18 vector v = ReadVector();
19 int extraflags = ReadByte();
20
22
23 if(extraflags & EFF_NET_VELOCITY)
24 vel = ReadVector();
25
26 if(extraflags & EFF_NET_COLOR_MIN)
27 {
31 eff_flags |= PARTICLES_USECOLOR;
32 }
33
34 if(extraflags & EFF_NET_COLOR_MAX)
35 {
39 eff_flags |= PARTICLES_USECOLOR;
40 }
41 else if(extraflags & EFF_NET_COLOR_SAME)
43
44 if(!eff_trail)
45 eff_cnt = ReadByte();
46
47 if(eff_trail)
49 else
50 boxparticles(particleeffectnum(eff), NULL, v, v, vel, vel, 1, eff_flags);
51 return true;
52}
53#endif
54
55#ifdef SVQC
56bool Net_Write_Effect(entity this, entity client, int sf)
57{
58 int channel = MSG_ONE;
59 msg_entity = client;
60 WriteHeader(channel, net_effect);
61 WriteRegistered(Effects, channel, this);
62 WriteVector(channel, this.eent_net_location);
63
64 int extraflags = 0;
65 if(this.eent_net_velocity != '0 0 0')
66 extraflags |= EFF_NET_VELOCITY;
67 if(this.eent_net_color_min != '0 0 0')
68 extraflags |= EFF_NET_COLOR_MIN;
69 // optimisation: only send one color if the min and max match
70 if(this.eent_net_color_min != '0 0 0' && this.eent_net_color_min == this.eent_net_color_max)
71 extraflags |= EFF_NET_COLOR_SAME;
72 else if(this.eent_net_color_max != '0 0 0')
73 extraflags |= EFF_NET_COLOR_MAX;
74
75 WriteByte(channel, extraflags);
76
77 // attempt to save a tiny bit more bandwidth by not sending velocity if it isn't set
78 if(extraflags & EFF_NET_VELOCITY)
79 WriteVector(channel, this.eent_net_velocity);
80
81 if(extraflags & EFF_NET_COLOR_MIN)
82 {
83 vector col = this.eent_net_color_min;
84 WriteByte(channel, rint(bound(0, 16 * col.x, 255)));
85 WriteByte(channel, rint(bound(0, 16 * col.y, 255)));
86 WriteByte(channel, rint(bound(0, 16 * col.z, 255)));
87 }
88
89 if(extraflags & EFF_NET_COLOR_MAX)
90 {
91 vector col = this.eent_net_color_max;
92 WriteByte(channel, rint(bound(0, 16 * col.x, 255)));
93 WriteByte(channel, rint(bound(0, 16 * col.y, 255)));
94 WriteByte(channel, rint(bound(0, 16 * col.z, 255)));
95 }
96
97 if(!this.eent_eff_trail) { WriteByte(channel, this.eent_net_count); }
98 return true;
99}
100
101void Send_Effect_Except(entity eff, vector eff_loc, vector eff_vel, int eff_cnt, vector eff_col_min, vector eff_col_max, entity ignore)
102{
103 if(!eff) { return; }
104 if(!eff.eent_eff_trail && !eff_cnt) { return; } // effect has no count!
105 entity net_eff = new_pure(net_effect);
106 net_eff.owner = eff;
107 //net_eff.eent_broadcast = broadcast;
108 net_eff.m_id = eff.m_id;
109 net_eff.eent_net_velocity = eff_vel;
110 net_eff.eent_net_location = eff_loc;
111 net_eff.eent_net_count = eff_cnt;
112 net_eff.eent_eff_trail = eff.eent_eff_trail;
113 net_eff.eent_net_color_min = eff_col_min;
114 net_eff.eent_net_color_max = eff_col_max;
115
116 FOREACH_CLIENT(IS_REAL_CLIENT(it) && it != ignore && !(IS_SPEC(it) && it.enemy && it.enemy == ignore), Net_Write_Effect(net_eff, it, 0));
117 delete(net_eff);
118}
119
120void Send_Effect(entity eff, vector eff_loc, vector eff_vel, int eff_cnt)
121{
122 Send_Effect_Except(eff, eff_loc, eff_vel, eff_cnt, '0 0 0', '0 0 0', NULL);
123}
124
125void Send_Effect_(string eff_name, vector eff_loc, vector eff_vel, int eff_cnt)
126{
127 // problem with this is, we might not have all the available effects for it
128 FOREACH(Effects, it.eent_eff_name == eff_name, {
129 Send_Effect(it, eff_loc, eff_vel, eff_cnt);
130 return;
131 });
132 // revert to engine handling TODO: send the effect name and draw it on the client side? not as light on networking, but resolves the use of server side effects
133 __pointparticles(_particleeffectnum(eff_name), eff_loc, eff_vel, eff_cnt);
134}
135#endif
136
137#if ENABLE_EFFECTINFO
138 #include "effectinfo.qc"
139#endif
#define BIT(n)
Only ever assign into the first 24 bits in QC (so max is BIT(23)).
Definition bits.qh:8
var entity(vector mins, vector maxs,.entity tofield) findbox_tofield_OrFallback
vector particles_colormin
vector particles_colormax
float PARTICLES_USECOLOR
vector eent_net_color_max
Definition effect.qh:26
vector eent_net_location
Definition effect.qh:23
int eent_eff_trail
Definition effect.qh:21
vector eent_net_color_min
Definition effect.qh:25
vector eent_net_velocity
Definition effect.qh:24
#define particleeffectnum(e)
Definition effect.qh:3
int eent_net_count
Definition effect.qh:27
const int EFF_NET_COLOR_MIN
Definition all.qc:4
const int EFF_NET_COLOR_SAME
Definition all.qc:6
const int EFF_NET_VELOCITY
Definition all.qc:3
void Send_Effect_(string eff_name, vector eff_loc, vector eff_vel, int eff_cnt)
Definition all.qc:125
void Send_Effect(entity eff, vector eff_loc, vector eff_vel, int eff_cnt)
Definition all.qc:120
bool Net_Write_Effect(entity this, entity client, int sf)
Definition all.qc:56
void Send_Effect_Except(entity eff, vector eff_loc, vector eff_vel, int eff_cnt, vector eff_col_min, vector eff_col_max, entity ignore)
Definition all.qc:101
const int EFF_NET_COLOR_MAX
Definition all.qc:5
#define FOREACH(list, cond, body)
Definition iter.qh:19
#define NET_HANDLE(id, param)
Definition net.qh:15
#define ReadVector()
Definition net.qh:350
#define ReadRegistered(r)
Definition net.qh:291
#define WriteHeader(to, id)
Definition net.qh:265
int ReadByte()
#define WriteRegistered(r, to, it)
Definition net.qh:293
#define REGISTER_NET_TEMP(id)
Definition net.qh:31
void WarpZone_TrailParticles_WithMultiplier(entity own, float eff, vector org, vector end, float f, int boxflags)
Definition common.qc:489
float MSG_ONE
Definition menudefs.qc:56
float bound(float min, float value, float max)
float rint(float f)
void WriteByte(float data, float dest, float desto)
#define new_pure(class)
purely logical entities (not linked to the area grid)
Definition oo.qh:67
#define NULL
Definition post.qh:14
entity msg_entity
Definition progsdefs.qc:63
vector
Definition self.qh:92
#define IS_SPEC(v)
Definition utils.qh:10
#define IS_REAL_CLIENT(v)
Definition utils.qh:17
#define FOREACH_CLIENT(cond, body)
Definition utils.qh:52