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 int net_name = (REGISTRY_COUNT(Effects) >= 255) ? ReadShort() : ReadByte();
13
14 entity eff = REGISTRY_GET(Effects, net_name);
15
16 vector vel = '0 0 0';
17 int eff_cnt = 1;
18 int eff_flags = 0;
19 bool eff_trail = eff.eent_eff_trail;
20 vector v = ReadVector();
21 int extraflags = ReadByte();
22
24
25 if(extraflags & EFF_NET_VELOCITY)
26 vel = ReadVector();
27
28 if(extraflags & EFF_NET_COLOR_MIN)
29 {
33 eff_flags |= PARTICLES_USECOLOR;
34 }
35
36 if(extraflags & EFF_NET_COLOR_MAX)
37 {
41 eff_flags |= PARTICLES_USECOLOR;
42 }
43 else if(extraflags & EFF_NET_COLOR_SAME)
45
46 if(!eff_trail)
47 eff_cnt = ReadByte();
48
49 if(eff_trail)
51 else
52 boxparticles(particleeffectnum(eff), NULL, v, v, vel, vel, 1, eff_flags);
53 return true;
54}
55#endif
56
57#ifdef SVQC
58bool Net_Write_Effect(entity this, entity client, int sf)
59{
60 int channel = MSG_ONE;
61 msg_entity = client;
62 WriteHeader(channel, net_effect);
63 (REGISTRY_COUNT(Effects) >= 255)
64 ? WriteShort(channel, this.m_id)
65 : WriteByte(channel, this.m_id);
66 WriteVector(channel, this.eent_net_location);
67
68 int extraflags = 0;
69 if(this.eent_net_velocity != '0 0 0')
70 extraflags |= EFF_NET_VELOCITY;
71 if(this.eent_net_color_min != '0 0 0')
72 extraflags |= EFF_NET_COLOR_MIN;
73 // optimisation: only send one color if the min and max match
74 if(this.eent_net_color_min != '0 0 0' && this.eent_net_color_min == this.eent_net_color_max)
75 extraflags |= EFF_NET_COLOR_SAME;
76 else if(this.eent_net_color_max != '0 0 0')
77 extraflags |= EFF_NET_COLOR_MAX;
78
79 WriteByte(channel, extraflags);
80
81 // attempt to save a tiny bit more bandwidth by not sending velocity if it isn't set
82 if(extraflags & EFF_NET_VELOCITY)
83 WriteVector(channel, this.eent_net_velocity);
84
85 if(extraflags & EFF_NET_COLOR_MIN)
86 {
87 vector col = this.eent_net_color_min;
88 WriteByte(channel, rint(bound(0, 16 * col.x, 255)));
89 WriteByte(channel, rint(bound(0, 16 * col.y, 255)));
90 WriteByte(channel, rint(bound(0, 16 * col.z, 255)));
91 }
92
93 if(extraflags & EFF_NET_COLOR_MAX)
94 {
95 vector col = this.eent_net_color_max;
96 WriteByte(channel, rint(bound(0, 16 * col.x, 255)));
97 WriteByte(channel, rint(bound(0, 16 * col.y, 255)));
98 WriteByte(channel, rint(bound(0, 16 * col.z, 255)));
99 }
100
101 if(!this.eent_eff_trail) { WriteByte(channel, this.eent_net_count); }
102 return true;
103}
104
105void Send_Effect_Except(entity eff, vector eff_loc, vector eff_vel, int eff_cnt, vector eff_col_min, vector eff_col_max, entity ignore)
106{
107 if(!eff) { return; }
108 if(!eff.eent_eff_trail && !eff_cnt) { return; } // effect has no count!
109 entity net_eff = new_pure(net_effect);
110 net_eff.owner = eff;
111 //net_eff.eent_broadcast = broadcast;
112 net_eff.m_id = eff.m_id;
113 net_eff.eent_net_velocity = eff_vel;
114 net_eff.eent_net_location = eff_loc;
115 net_eff.eent_net_count = eff_cnt;
116 net_eff.eent_eff_trail = eff.eent_eff_trail;
117 net_eff.eent_net_color_min = eff_col_min;
118 net_eff.eent_net_color_max = eff_col_max;
119
120 FOREACH_CLIENT(IS_REAL_CLIENT(it) && it != ignore && !(IS_SPEC(it) && it.enemy && it.enemy == ignore), Net_Write_Effect(net_eff, it, 0));
121 delete(net_eff);
122}
123
124void Send_Effect(entity eff, vector eff_loc, vector eff_vel, int eff_cnt)
125{
126 Send_Effect_Except(eff, eff_loc, eff_vel, eff_cnt, '0 0 0', '0 0 0', NULL);
127}
128
129void Send_Effect_(string eff_name, vector eff_loc, vector eff_vel, int eff_cnt)
130{
131 // problem with this is, we might not have all the available effects for it
132 FOREACH(Effects, it.eent_eff_name == eff_name, {
133 Send_Effect(it, eff_loc, eff_vel, eff_cnt);
134 return;
135 });
136 // 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
137 __pointparticles(_particleeffectnum(eff_name), eff_loc, eff_vel, eff_cnt);
138}
139#endif
140
141#if ENABLE_EFFECTINFO
142 #include "effectinfo.qc"
143#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 m_id
Definition effect.qh:19
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:129
void Send_Effect(entity eff, vector eff_loc, vector eff_vel, int eff_cnt)
Definition all.qc:124
bool Net_Write_Effect(entity this, entity client, int sf)
Definition all.qc:58
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:105
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:367
#define WriteHeader(to, id)
Definition net.qh:221
int ReadByte()
#define REGISTER_NET_TEMP(id)
Definition net.qh:28
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)
void WriteShort(float data, float dest, float desto)
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
#define REGISTRY_COUNT(id)
Definition registry.qh:18
#define REGISTRY_GET(id, i)
Definition registry.qh:43
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:50