]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/lib/net.qh
Merge branch 'master' into TimePath/unified_weapons
[xonotic/xonotic-data.pk3dir.git] / qcsrc / lib / net.qh
1 #ifndef NET_H
2 #define NET_H
3
4 #ifdef SVQC
5 .int SendFlags;
6 .bool(entity to, int sendflags) SendEntity;
7
8 void Net_LinkEntity(entity e, bool docull, float dt, bool(entity to, int sendflags) sendfunc)
9 {
10     if (!e.classname) e.classname = "net_linked";
11
12     if (!e.model || !self.modelindex) {
13         vector mi = e.mins;
14         vector ma = e.maxs;
15         _setmodel(e, "null");
16         setsize(e, mi, ma);
17     }
18
19     e.SendEntity = sendfunc;
20     e.SendFlags = 0xFFFFFF;
21
22     if (!docull) e.effects |= EF_NODEPTHTEST;
23
24     if (dt) {
25         e.nextthink = time + dt;
26         e.think = SUB_Remove;
27     }
28 }
29
30 .void() uncustomizeentityforclient;
31 .float uncustomizeentityforclient_set;
32
33 void SetCustomizer(entity e, float(void) customizer, void(void) uncustomizer)
34 {
35     e.customizeentityforclient = customizer;
36     e.uncustomizeentityforclient = uncustomizer;
37     e.uncustomizeentityforclient_set = !!uncustomizer;
38 }
39
40 void UncustomizeEntitiesRun()
41 {
42     for (entity e = NULL; (e = findfloat(e, uncustomizeentityforclient_set, 1)); ) {
43         WITH(entity, self, e, e.uncustomizeentityforclient());
44     }
45 }
46
47 #endif
48
49 #include "registry.qh"
50 #include "sort.qh"
51
52 REGISTRY(Linked, 24)
53
54 .string netname;
55 .int m_id;
56 .void(entity this, bool isNew) m_read;
57
58 #ifdef CSQC
59     #define REGISTER_LINKED(id, param) \
60         void Ent_Read##id(entity this, param) { this = self; } \
61         REGISTER(RegisterLinked, Linked, Linked, Linked_COUNT, id, m_id, spawn()) { \
62             this.netname = #id; \
63             this.m_read = Ent_Read##id; \
64         } \
65         [[accumulate]] void Ent_Read##id(entity this, param)
66 #else
67     #define REGISTER_LINKED(id, param) \
68         REGISTER(RegisterLinked, Linked, Linked, Linked_COUNT, id, m_id, spawn()) { \
69             this.netname = #id; \
70         }
71 #endif
72
73 REGISTER_REGISTRY(RegisterLinked)
74 REGISTRY_SORT(Linked, netname, 0)
75 STATIC_INIT(RegisterLinked_renumber) {
76     for (int i = 0; i < Linked_COUNT; ++i) {
77         Linked[i].m_id = 100 + i;
78     }
79 }
80
81 #endif