Draw: purge SELFPARAM
[xonotic/xonotic-data.pk3dir.git] / qcsrc / client / modeleffects.qc
1 #include "modeleffects.qh"
2 #include "_all.qh"
3
4 .float cnt;
5 .float scale;
6 .float alpha;
7
8 void ModelEffect_Draw(entity this)
9 {
10         self.angles = self.angles + frametime * self.avelocity;
11         setorigin(self, self.origin + frametime * self.velocity);
12         self.scale = self.scale1 + (self.scale2 - self.scale1) * (time - self.teleport_time) / (self.lifetime + self.fadetime - self.teleport_time);
13         self.alpha = self.cnt * bound(0, 1 - (time - self.lifetime) / self.fadetime, 1);
14         if(self.alpha < ALPHA_MIN_VISIBLE)
15         {
16                 remove(self);
17                 return;
18         }
19         self.drawmask = MASK_NORMAL;
20         if(self.scale <= 0)
21         {
22                 self.drawmask = 0;
23                 return;
24         }
25 }
26
27 void Ent_ModelEffect(bool isNew)
28 {SELFPARAM();
29         self.classname = "modeleffect_spawner";
30
31         int f = ReadByte();
32
33         entity e = spawn();
34         e.classname = "modeleffect";
35         e.model = "from network";
36         e.modelindex = ReadShort();
37         e.skin = ReadByte();
38         e.frame = ReadByte();
39         e.frame1time = time;
40         e.origin_x = ReadCoord();
41         e.origin_y = ReadCoord();
42         e.origin_z = ReadCoord();
43         setorigin(e, e.origin);
44         if(f & 1)
45         {
46                 e.velocity_x = ReadCoord();
47                 e.velocity_y = ReadCoord();
48                 e.velocity_z = ReadCoord();
49         }
50         if(f & 2)
51         {
52                 e.angles_x = ReadAngle();
53                 e.angles_y = ReadAngle();
54                 e.angles_z = ReadAngle();
55         }
56         if(f & 4)
57         {
58                 e.avelocity_x = ReadAngle();
59                 e.avelocity_y = ReadAngle();
60                 e.avelocity_z = ReadAngle();
61         }
62         e.scale1 = ReadShort() / 256.0;
63         e.scale2 = ReadShort() / 256.0;
64         e.lifetime = time + ReadByte() * 0.01;
65         e.fadetime = ReadByte() * 0.01;
66         e.teleport_time = time;
67         e.cnt = ReadByte() / 255.0; // actually alpha
68
69         e.draw = ModelEffect_Draw;
70
71         if(!isNew)
72                 remove(e); // yes, this IS stupid, but I don't need to duplicate all the read* stuff then
73 }