[nexuiz-commits] r6500 - in trunk/data/qcsrc: client server
DONOTREPLY at icculus.org
DONOTREPLY at icculus.org
Thu Apr 16 05:09:36 EDT 2009
Author: div0
Date: 2009-04-16 05:09:35 -0400 (Thu, 16 Apr 2009)
New Revision: 6500
Modified:
trunk/data/qcsrc/client/particles.qc
trunk/data/qcsrc/server/g_triggers.qc
Log:
func_pointparticles: reduce bandwidth
Modified: trunk/data/qcsrc/client/particles.qc
===================================================================
--- trunk/data/qcsrc/client/particles.qc 2009-04-16 08:11:41 UTC (rev 6499)
+++ trunk/data/qcsrc/client/particles.qc 2009-04-16 09:09:35 UTC (rev 6500)
@@ -79,6 +79,7 @@
.float scriptstate;
.float scriptvelocity;
.float scripttime;
+.float switchedon;
void PointparticlesScript_InitEntity(entity e)
{
if(e.bgmscript != "")
@@ -115,7 +116,7 @@
if(cvar("bgmvolume") <= 0)
return 0.5;
- e.scriptstate = !!e.scriptstate; // turns 0 to 0 and 2 to 1
+ e.switchedon = FALSE;
t = gettime(GETTIME_CDTRACK);
@@ -135,7 +136,8 @@
{
// time code reached!
e.scriptvelocity = stof(argv(2));
- e.scriptstate = (e.scriptvelocity > 0) ? 2 : 0;
+ if(e.scriptvelocity > 0)
+ e.switchedon = TRUE;
e.scripttime = stof(argv(1));
e.scriptline += 1;
}
@@ -153,7 +155,7 @@
void Draw_PointParticles()
{
- float n, i, fail, force;
+ float n, i, fail;
vector p;
vector sz;
vector o;
@@ -164,8 +166,7 @@
if(n == 0)
return;
fail = 0;
- force = (self.scriptstate == 2);
- for(i = random(); (force || i <= n) && fail <= 64*n; ++i)
+ for(i = random(); (self.switchedon || i <= n) && fail <= 64*n; ++i)
{
p = o + self.mins;
p_x += random() * sz_x;
@@ -186,7 +187,7 @@
self.origin = p;
sound(self, CHAN_AUTO, self.noise, VOL_BASE * self.volume, self.atten);
}
- force = 0;
+ self.switchedon = 0;
}
else if(self.absolute)
{
@@ -209,12 +210,15 @@
void Ent_PointParticles()
{
- float f;
+ float f, i;
vector v;
f = ReadByte();
if(f & 2)
{
- self.impulse = ReadCoord(); // density (<0: point, >0: volume)
+ i = ReadCoord(); // density (<0: point, >0: volume)
+ if(i && !self.impulse)
+ self.switchedon = 1;
+ self.impulse = i;
}
if(f & 4)
{
@@ -225,44 +229,72 @@
if(f & 1)
{
self.modelindex = ReadShort();
- if(self.modelindex)
+ if(f & 0x80)
{
- self.mins_x = ReadCoord();
- self.mins_y = ReadCoord();
- self.mins_z = ReadCoord();
- self.maxs_x = ReadCoord();
- self.maxs_y = ReadCoord();
- self.maxs_z = ReadCoord();
+ if(self.modelindex)
+ {
+ self.mins_x = ReadCoord();
+ self.mins_y = ReadCoord();
+ self.mins_z = ReadCoord();
+ self.maxs_x = ReadCoord();
+ self.maxs_y = ReadCoord();
+ self.maxs_z = ReadCoord();
+ }
+ else
+ {
+ self.mins = '0 0 0';
+ self.maxs_x = ReadCoord();
+ self.maxs_y = ReadCoord();
+ self.maxs_z = ReadCoord();
+ }
}
else
{
- self.mins = '0 0 0';
- self.maxs_x = ReadCoord();
- self.maxs_y = ReadCoord();
- self.maxs_z = ReadCoord();
+ self.mins = self.maxs = '0 0 0';
}
self.cnt = ReadShort(); // effect number
- self.velocity = decompressShortVector(ReadShort());
- self.movedir = decompressShortVector(ReadShort());
- self.waterlevel = ReadCoord();
- self.count = ReadCoord();
- self.glow_color = ReadByte();
+ if(f & 0x20)
+ {
+ self.velocity = decompressShortVector(ReadShort());
+ self.movedir = decompressShortVector(ReadShort());
+ }
+ else
+ {
+ self.velocity = self.movedir = '0 0 0';
+ }
+ if(f & 0x40)
+ {
+ self.waterlevel = ReadShort() / 16.0;
+ self.count = ReadByte() / 16.0;
+ self.glow_color = ReadByte();
+ }
+ else
+ {
+ self.waterlevel = self.count = self.glow_color = 0;
+ }
if(self.noise)
strunzone(self.noise);
- self.noise = strzone(ReadString());
- if(self.noise != "")
+ if(self.bgmscript)
+ strunzone(self.bgmscript);
+ if(f & 0x10)
{
- self.atten = ReadByte() / 64.0;
- self.volume = ReadByte() / 255.0;
+ self.noise = strzone(ReadString());
+ if(self.noise != "")
+ {
+ self.atten = ReadByte() / 64.0;
+ self.volume = ReadByte() / 255.0;
+ }
+ self.bgmscript = strzone(ReadString());
+ if(self.bgmscript != "")
+ self.bgmscriptdecay = ReadByte() / 255.0;
+ PointparticlesScript_InitEntity(self);
}
- if(self.bgmscript)
- strunzone(self.bgmscript);
- self.bgmscript = strzone(ReadString());
- if(self.bgmscript != "")
- self.bgmscriptdecay = ReadByte() / 255.0;
- PointparticlesScript_InitEntity(self);
+ else
+ {
+ self.noise = self.bgmscript = string_null;
+ }
}
if(f & 2)
Modified: trunk/data/qcsrc/server/g_triggers.qc
===================================================================
--- trunk/data/qcsrc/server/g_triggers.qc 2009-04-16 08:11:41 UTC (rev 6499)
+++ trunk/data/qcsrc/server/g_triggers.qc 2009-04-16 09:09:35 UTC (rev 6500)
@@ -559,6 +559,18 @@
float pointparticles_SendEntity(entity to, float fl)
{
WriteByte(MSG_ENTITY, ENT_CLIENT_POINTPARTICLES);
+
+ // optional features to save space
+ fl = fl & 0x0F;
+ if(self.noise || self.bgmscript)
+ fl |= 0x10; // 2 bytes
+ if(self.movedir != '0 0 0' || self.velocity != '0 0 0')
+ fl |= 0x20; // 4 bytes - saves CPU
+ if(self.glow_color || self.waterlevel || self.glow_color)
+ fl |= 0x40; // 4 bytes - obscure features almost never used
+ if(self.mins != '0 0 0' || self.maxs != '0 0 0')
+ fl |= 0x80; // 14 bytes - saves lots of space
+
WriteByte(MSG_ENTITY, fl);
if(fl & 2)
{
@@ -578,35 +590,50 @@
if(self.model != "null")
{
WriteShort(MSG_ENTITY, self.modelindex);
- WriteCoord(MSG_ENTITY, self.mins_x);
- WriteCoord(MSG_ENTITY, self.mins_y);
- WriteCoord(MSG_ENTITY, self.mins_z);
- WriteCoord(MSG_ENTITY, self.maxs_x);
- WriteCoord(MSG_ENTITY, self.maxs_y);
- WriteCoord(MSG_ENTITY, self.maxs_z);
+ if(fl & 0x80)
+ {
+ WriteCoord(MSG_ENTITY, self.mins_x);
+ WriteCoord(MSG_ENTITY, self.mins_y);
+ WriteCoord(MSG_ENTITY, self.mins_z);
+ WriteCoord(MSG_ENTITY, self.maxs_x);
+ WriteCoord(MSG_ENTITY, self.maxs_y);
+ WriteCoord(MSG_ENTITY, self.maxs_z);
+ }
}
else
{
WriteShort(MSG_ENTITY, 0);
- WriteCoord(MSG_ENTITY, self.maxs_x);
- WriteCoord(MSG_ENTITY, self.maxs_y);
- WriteCoord(MSG_ENTITY, self.maxs_z);
+ if(fl & 0x80)
+ {
+ WriteCoord(MSG_ENTITY, self.maxs_x);
+ WriteCoord(MSG_ENTITY, self.maxs_y);
+ WriteCoord(MSG_ENTITY, self.maxs_z);
+ }
}
WriteShort(MSG_ENTITY, self.cnt);
- WriteShort(MSG_ENTITY, compressShortVector(self.velocity));
- WriteShort(MSG_ENTITY, compressShortVector(self.movedir));
- WriteCoord(MSG_ENTITY, self.waterlevel);
- WriteCoord(MSG_ENTITY, self.count);
- WriteByte(MSG_ENTITY, self.glow_color);
- WriteString(MSG_ENTITY, self.noise);
- if(self.noise != "")
+ if(fl & 0x20)
{
- WriteByte(MSG_ENTITY, floor(self.atten * 64));
- WriteByte(MSG_ENTITY, floor(self.volume * 255));
+ WriteShort(MSG_ENTITY, compressShortVector(self.velocity));
+ WriteShort(MSG_ENTITY, compressShortVector(self.movedir));
}
- WriteString(MSG_ENTITY, self.bgmscript);
- if(self.bgmscript != "")
- WriteByte(MSG_ENTITY, floor(self.bgmscriptdecay * 255));
+ if(fl & 0x40)
+ {
+ WriteShort(MSG_ENTITY, self.waterlevel * 16.0);
+ WriteByte(MSG_ENTITY, self.count * 16.0);
+ WriteByte(MSG_ENTITY, self.glow_color);
+ }
+ if(fl & 0x10)
+ {
+ WriteString(MSG_ENTITY, self.noise);
+ if(self.noise != "")
+ {
+ WriteByte(MSG_ENTITY, floor(self.atten * 64));
+ WriteByte(MSG_ENTITY, floor(self.volume * 255));
+ }
+ WriteString(MSG_ENTITY, self.bgmscript);
+ if(self.bgmscript != "")
+ WriteByte(MSG_ENTITY, floor(self.bgmscriptdecay * 255));
+ }
}
return 1;
}
More information about the nexuiz-commits
mailing list