From: TimePath Date: Sat, 21 Nov 2015 10:23:34 +0000 (+1100) Subject: csqcmodel: optimize server2csqc X-Git-Tag: xonotic-v0.8.2~1645 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=f972b5a8899b4d3793be9644265b2ced1aaec6d9;p=xonotic%2Fxonotic-data.pk3dir.git csqcmodel: optimize server2csqc --- diff --git a/qcsrc/lib/csqcmodel/cl_model.qc b/qcsrc/lib/csqcmodel/cl_model.qc index a656fb790..2057c881e 100644 --- a/qcsrc/lib/csqcmodel/cl_model.qc +++ b/qcsrc/lib/csqcmodel/cl_model.qc @@ -209,19 +209,32 @@ void CSQCModel_Draw() self.csqcmodel_teleported = 0; } +entity CSQCModel_players[255]; // 255 is engine limit on maxclients + +void CSQCModel_remove() +{ + SELFPARAM(); + CSQCModel_players[this.entnum - 1] = NULL; +} + NET_HANDLE(ENT_CLIENT_MODEL, bool isnew) { int sf = ReadInt24_t(); // some nice flags for CSQCMODEL_IF and the hooks - bool isplayer = (self.entnum >= 1 && self.entnum <= maxclients); - bool islocalplayer = (self.entnum == player_localnum + 1); - noref bool isnolocalplayer = (isplayer && (self.entnum != player_localnum + 1)); + bool isplayer = (this.entnum >= 1 && this.entnum <= maxclients); + if (isnew && isplayer) + { + CSQCModel_players[this.entnum - 1] = this; + this.entremove = CSQCModel_remove; + } + bool islocalplayer = (this.entnum == player_localnum + 1); + noref bool isnolocalplayer = (isplayer && (this.entnum != player_localnum + 1)); - self.classname = "csqcmodel"; - self.iflags |= IFLAG_ORIGIN; // interpolate origin too - self.iflags |= IFLAG_ANGLES; // interpolate angles too - self.iflags |= IFLAG_VELOCITY | IFLAG_AUTOVELOCITY; // let's calculate velocity automatically + this.classname = "csqcmodel"; + this.iflags |= IFLAG_ORIGIN; // interpolate origin too + this.iflags |= IFLAG_ANGLES; // interpolate angles too + this.iflags |= IFLAG_VELOCITY | IFLAG_AUTOVELOCITY; // let's calculate velocity automatically { CSQCMODEL_HOOK_PREUPDATE } @@ -233,10 +246,10 @@ NET_HANDLE(ENT_CLIENT_MODEL, bool isnew) #define CSQCMODEL_ENDIF } #define CSQCMODEL_PROPERTY(flag,t,r,w,f) \ if(sf & flag) \ - self.f = r(); + this.f = r(); #define CSQCMODEL_PROPERTY_SCALED(flag,t,r,w,f,s,mi,ma) \ if(sf & flag) \ - self.f = (r() + mi) / s; + this.f = (r() + mi) / s; ALLPROPERTIES #undef CSQCMODEL_PROPERTY_SCALED #undef CSQCMODEL_PROPERTY @@ -245,15 +258,15 @@ NET_HANDLE(ENT_CLIENT_MODEL, bool isnew) if(sf & CSQCMODEL_PROPERTY_MODELINDEX) { - vector pmin = self.mins, pmax = self.maxs; - setmodelindex(self, self.modelindex); // this retrieves the .model key and sets mins/maxs/absmin/absmax - setsize(self, pmin, pmax); + vector pmin = this.mins, pmax = this.maxs; + setmodelindex(this, this.modelindex); // this retrieves the .model key and sets mins/maxs/absmin/absmax + setsize(this, pmin, pmax); } if(sf & CSQCMODEL_PROPERTY_TELEPORTED) { - self.iflags |= IFLAG_TELEPORTED; - self.csqcmodel_teleported = 1; + this.iflags |= IFLAG_TELEPORTED; + this.csqcmodel_teleported = 1; } CSQCModel_InterpolateAnimation_Note(sf); @@ -268,21 +281,23 @@ NET_HANDLE(ENT_CLIENT_MODEL, bool isnew) #endif // relink - setorigin(self, self.origin); + setorigin(this, this.origin); // set obvious render flags - if(self.entnum == player_localentnum) - self.renderflags |= RF_EXTERNALMODEL; + if(this.entnum == player_localentnum) + this.renderflags |= RF_EXTERNALMODEL; else - self.renderflags &= ~RF_EXTERNALMODEL; + this.renderflags &= ~RF_EXTERNALMODEL; // draw it - self.drawmask = MASK_NORMAL; - self.predraw = CSQCModel_Draw; + this.drawmask = MASK_NORMAL; + this.predraw = CSQCModel_Draw; return true; } -entity CSQCModel_server2csqc(float pl) +entity CSQCModel_server2csqc(int pl) { - return findfloat(world, entnum, pl); // FIXME optimize this using an array + if (pl <= maxclients) return CSQCModel_players[pl - 1]; + LOG_WARNINGF("player out of bounds: %d\n", pl); + return findfloat(NULL, entnum, pl); }