From: Mario Date: Fri, 29 Jul 2016 10:48:06 +0000 (+1000) Subject: Clean up auxiliary crosshair code a little X-Git-Tag: xonotic-v0.8.2~700^2~8 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=be8c83a637d1f1061c97ac1f581d5ad3a1a86729;p=xonotic%2Fxonotic-data.pk3dir.git Clean up auxiliary crosshair code a little --- diff --git a/qcsrc/common/vehicles/cl_vehicles.qc b/qcsrc/common/vehicles/cl_vehicles.qc index 5382a6f7a..f7e7ca025 100644 --- a/qcsrc/common/vehicles/cl_vehicles.qc +++ b/qcsrc/common/vehicles/cl_vehicles.qc @@ -48,12 +48,14 @@ void AuxiliaryXhair_Draw2D(entity this) NET_HANDLE(ENT_CLIENT_AUXILIARYXHAIR, bool isnew) { + int sf = ReadByte(); + int axh_id = bound(0, ReadByte(), MAX_AXH); - entity axh = AuxiliaryXhair[axh_id]; + entity axh = AuxiliaryXhair[axh_id]; - if(axh == NULL || wasfreed(axh)) // MADNESS? THIS IS QQQQCCCCCCCCC (wasfreed, why do you exsist?) + if(axh == NULL || wasfreed(axh)) { - axh = spawn(); + axh = new(auxiliary_crosshair); axh.draw2d = func_null; axh.drawmask = MASK_NORMAL; axh.axh_drawflag = DRAWFLAG_ADDITIVE; @@ -63,12 +65,20 @@ NET_HANDLE(ENT_CLIENT_AUXILIARYXHAIR, bool isnew) AuxiliaryXhair[axh_id] = axh; } - axh.origin_x = ReadCoord(); - axh.origin_y = ReadCoord(); - axh.origin_z = ReadCoord(); - axh.colormod_x = ReadByte() / 255; - axh.colormod_y = ReadByte() / 255; - axh.colormod_z = ReadByte() / 255; + if(sf & 2) + { + axh.origin_x = ReadCoord(); + axh.origin_y = ReadCoord(); + axh.origin_z = ReadCoord(); + } + + if(sf & 4) + { + axh.colormod_x = ReadByte() / 255; + axh.colormod_y = ReadByte() / 255; + axh.colormod_z = ReadByte() / 255; + } + axh.cnt = time; axh.draw2d = AuxiliaryXhair_Draw2D; if (isnew) IL_PUSH(g_drawables_2d, axh); @@ -81,10 +91,22 @@ NET_HANDLE(TE_CSQC_VEHICLESETUP, bool isnew) return = true; // hud_id == 0 means we exited a vehicle, so stop alarm sound/s - if(hud_id == 0) + // note: HUD_NORMAL is set to 0 currently too, but we'll check both just in case + if(hud_id == 0 || hud_id == HUD_NORMAL) { sound(this, CH_TRIGGER_SINGLE, SND_Null, VOL_BASEVOICE, ATTEN_NONE); sound(this, CH_PAIN_SINGLE, SND_Null, VOL_BASEVOICE, ATTEN_NONE); + + for(int i = 0; i < MAX_AXH; ++i) + { + entity axh = AuxiliaryXhair[i]; + + if(axh != NULL && !wasfreed(axh)) + { + AuxiliaryXhair[i] = NULL; + remove(axh); + } + } return; } diff --git a/qcsrc/common/vehicles/sv_vehicles.qc b/qcsrc/common/vehicles/sv_vehicles.qc index 82b20a6bc..4fd9a0d52 100644 --- a/qcsrc/common/vehicles/sv_vehicles.qc +++ b/qcsrc/common/vehicles/sv_vehicles.qc @@ -3,20 +3,30 @@ bool SendAuxiliaryXhair(entity this, entity to, int sf) { WriteHeader(MSG_ENTITY, ENT_CLIENT_AUXILIARYXHAIR); + WriteByte(MSG_ENTITY, sf); WriteByte(MSG_ENTITY, this.cnt); - WriteCoord(MSG_ENTITY, this.origin_x); - WriteCoord(MSG_ENTITY, this.origin_y); - WriteCoord(MSG_ENTITY, this.origin_z); + if(sf & 2) + { + WriteCoord(MSG_ENTITY, this.origin_x); + WriteCoord(MSG_ENTITY, this.origin_y); + WriteCoord(MSG_ENTITY, this.origin_z); + } - WriteByte(MSG_ENTITY, rint(this.colormod_x * 255)); - WriteByte(MSG_ENTITY, rint(this.colormod_y * 255)); - WriteByte(MSG_ENTITY, rint(this.colormod_z * 255)); + if(sf & 4) + { + WriteByte(MSG_ENTITY, rint(this.colormod_x * 255)); + WriteByte(MSG_ENTITY, rint(this.colormod_y * 255)); + WriteByte(MSG_ENTITY, rint(this.colormod_z * 255)); + } return true; } +.vector axh_prevorigin; +.vector axh_prevcolors; + void UpdateAuxiliaryXhair(entity own, vector loc, vector clr, int axh_id) { if(!IS_REAL_CLIENT(own)) @@ -27,17 +37,26 @@ void UpdateAuxiliaryXhair(entity own, vector loc, vector clr, int axh_id) if(axh == NULL || wasfreed(axh)) // MADNESS? THIS IS QQQQCCCCCCCCC (wasfreed, why do you exsist? Mario: because of sloppy code like this) { - axh = spawn(); - axh.cnt = axh_id; - axh.drawonlytoclient = own; - axh.owner = own; + axh = new(auxiliary_xhair); + axh.cnt = axh_id; + axh.drawonlytoclient = own; + axh.owner = own; Net_LinkEntity(axh, false, 0, SendAuxiliaryXhair); } - setorigin(axh, loc); - axh.colormod = clr; - axh.SendFlags = 0x01; - own.(AuxiliaryXhair[axh_id]) = axh; + if(loc != axh.axh_prevorigin) + { + setorigin(axh, loc); + axh.SendFlags |= 2; + } + + if(clr != axh.axh_prevcolors) + { + axh.colormod = clr; + axh.SendFlags |= 4; + } + + own.(AuxiliaryXhair[axh_id]) = axh; // set it anyway...? } void CSQCVehicleSetup(entity own, int vehicle_id)