X-Git-Url: http://de.git.xonotic.org/?a=blobdiff_plain;f=qcsrc%2Fcommon%2Ftriggers%2Ffunc%2Fconveyor.qc;h=4214a73239628f1a06a405cda73f7d094a18e4cd;hb=375c41912c7afebd2f25e37920efef219489761f;hp=5cd17e7bfc3e1544cdeca427a884d09b5b542828;hpb=42e255d014f2c6a1871177ea511f630624cdfb57;p=xonotic%2Fxonotic-data.pk3dir.git diff --git a/qcsrc/common/triggers/func/conveyor.qc b/qcsrc/common/triggers/func/conveyor.qc index 5cd17e7bf..4214a7323 100644 --- a/qcsrc/common/triggers/func/conveyor.qc +++ b/qcsrc/common/triggers/func/conveyor.qc @@ -1,201 +1,177 @@ +#include "conveyor.qh" REGISTER_NET_LINKED(ENT_CLIENT_CONVEYOR) -void conveyor_think() -{SELFPARAM(); +void conveyor_think(entity this) +{ #ifdef CSQC // TODO: check if this is what is causing the glitchiness when switching between them - float dt = time - self.move_time; - self.move_time = time; + float dt = time - this.move_time; + this.move_time = time; if(dt <= 0) { return; } #endif - entity e; // set myself as current conveyor where possible - for(e = world; (e = findentity(e, conveyor, self)); ) - e.conveyor = world; + IL_EACH(g_conveyed, it.conveyor == this, + { + it.conveyor = NULL; + IL_REMOVE(g_conveyed, it); + }); - if(self.state) + if(this.active == ACTIVE_ACTIVE) { - for(e = findradius((self.absmin + self.absmax) * 0.5, vlen(self.absmax - self.absmin) * 0.5 + 1); e; e = e.chain) - if(!e.conveyor.state) - if(isPushable(e)) + FOREACH_ENTITY_RADIUS((this.absmin + this.absmax) * 0.5, vlen(this.absmax - this.absmin) * 0.5 + 1, !it.conveyor.active && isPushable(it), + { + vector emin = it.absmin; + vector emax = it.absmax; + if(this.solid == SOLID_BSP) + { + emin -= '1 1 1'; + emax += '1 1 1'; + } + if(boxesoverlap(emin, emax, this.absmin, this.absmax)) // quick + if(WarpZoneLib_BoxTouchesBrush(emin, emax, this, it)) // accurate { - vector emin = e.absmin; - vector emax = e.absmax; - if(self.solid == SOLID_BSP) - { - emin -= '1 1 1'; - emax += '1 1 1'; - } - if(boxesoverlap(emin, emax, self.absmin, self.absmax)) // quick - if(WarpZoneLib_BoxTouchesBrush(emin, emax, self, e)) // accurate - e.conveyor = self; + if(!it.conveyor) + IL_PUSH(g_conveyed, it); + it.conveyor = this; } + }); - for(e = world; (e = findentity(e, conveyor, self)); ) + IL_EACH(g_conveyed, it.conveyor == this, { - if(IS_CLIENT(e)) // doing it via velocity has quite some advantages + if(IS_CLIENT(it)) // doing it via velocity has quite some advantages continue; // done in SV_PlayerPhysics continue; - setorigin(e, e.origin + self.movedir * PHYS_INPUT_FRAMETIME); - move_out_of_solid(e); + setorigin(it, it.origin + this.movedir * PHYS_INPUT_FRAMETIME); + move_out_of_solid(it); #ifdef SVQC - UpdateCSQCProjectile(e); + UpdateCSQCProjectile(it); #endif /* // stupid conveyor code - tracebox(e.origin, e.mins, e.maxs, e.origin + self.movedir * sys_frametime, MOVE_NORMAL, e); + tracebox(it.origin, it.mins, it.maxs, it.origin + this.movedir * sys_frametime, MOVE_NORMAL, it); if(trace_fraction > 0) - setorigin(e, trace_endpos); + setorigin(it, trace_endpos); */ - } + }); } #ifdef SVQC - self.nextthink = time; + this.nextthink = time; #endif } #ifdef SVQC -void conveyor_use(entity this, entity actor, entity trigger) +bool conveyor_send(entity this, entity to, int sendflags) { - this.state = !this.state; + WriteHeader(MSG_ENTITY, ENT_CLIENT_CONVEYOR); + WriteByte(MSG_ENTITY, sendflags); - this.SendFlags |= 2; -} + if(sendflags & SF_TRIGGER_INIT) + { + WriteByte(MSG_ENTITY, this.warpzone_isboxy); + WriteVector(MSG_ENTITY, this.origin); -void conveyor_reset(entity this) -{ - this.state = (this.spawnflags & 1); + WriteVector(MSG_ENTITY, this.mins); + WriteVector(MSG_ENTITY, this.maxs); - this.SendFlags |= 2; -} + WriteVector(MSG_ENTITY, this.movedir); -bool conveyor_send(entity this, entity to, int sf) -{ - WriteHeader(MSG_ENTITY, ENT_CLIENT_CONVEYOR); - WriteByte(MSG_ENTITY, sf); + WriteByte(MSG_ENTITY, this.speed); + WriteByte(MSG_ENTITY, this.active); - if(sf & 1) - { - WriteByte(MSG_ENTITY, self.warpzone_isboxy); - WriteCoord(MSG_ENTITY, self.origin_x); - WriteCoord(MSG_ENTITY, self.origin_y); - WriteCoord(MSG_ENTITY, self.origin_z); - - 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); - - WriteCoord(MSG_ENTITY, self.movedir_x); - WriteCoord(MSG_ENTITY, self.movedir_y); - WriteCoord(MSG_ENTITY, self.movedir_z); - - WriteByte(MSG_ENTITY, self.speed); - WriteByte(MSG_ENTITY, self.state); - - WriteString(MSG_ENTITY, self.targetname); - WriteString(MSG_ENTITY, self.target); + WriteString(MSG_ENTITY, this.targetname); + WriteString(MSG_ENTITY, this.target); } - if(sf & 2) - WriteByte(MSG_ENTITY, self.state); + if(sendflags & SF_TRIGGER_UPDATE) + WriteByte(MSG_ENTITY, this.active); return true; } -void conveyor_init() -{SELFPARAM(); +void conveyor_init(entity this) +{ if (!this.speed) this.speed = 200; this.movedir *= this.speed; - this.think = conveyor_think; + setthink(this, conveyor_think); this.nextthink = time; + this.setactive = generic_netlinked_setactive; IFTARGETED { - this.use = conveyor_use; - this.reset = conveyor_reset; - this.reset(this); + // backwards compatibility + this.use = generic_netlinked_legacy_use; } - else - this.state = 1; + this.reset = generic_netlinked_reset; + this.reset(this); FixSize(this); Net_LinkEntity(this, 0, false, conveyor_send); - this.SendFlags |= 1; + this.SendFlags |= SF_TRIGGER_INIT; } spawnfunc(trigger_conveyor) { - SetMovedir(self); + SetMovedir(this); EXACTTRIGGER_INIT; - conveyor_init(); + conveyor_init(this); } spawnfunc(func_conveyor) { - SetMovedir(self); - InitMovingBrushTrigger(); - self.movetype = MOVETYPE_NONE; - conveyor_init(); + SetMovedir(this); + InitMovingBrushTrigger(this); + set_movetype(this, MOVETYPE_NONE); + conveyor_init(this); } #elif defined(CSQC) -void conveyor_draw(entity this) { WITHSELF(this, conveyor_think()); } +void conveyor_draw(entity this) { conveyor_think(this); } -void conveyor_init() -{SELFPARAM(); - self.draw = conveyor_draw; - self.drawmask = MASK_NORMAL; - - self.movetype = MOVETYPE_NONE; - self.model = ""; - self.solid = SOLID_TRIGGER; - self.move_origin = self.origin; - self.move_time = time; +void conveyor_init(entity this, bool isnew) +{ + if(isnew) + IL_PUSH(g_drawables, this); + this.draw = conveyor_draw; + this.drawmask = MASK_NORMAL; + + set_movetype(this, MOVETYPE_NONE); + this.model = ""; + this.solid = SOLID_TRIGGER; + this.move_time = time; } NET_HANDLE(ENT_CLIENT_CONVEYOR, bool isnew) { - float sf = ReadByte(); + int sendflags = ReadByte(); - if(sf & 1) + if(sendflags & SF_TRIGGER_INIT) { - self.warpzone_isboxy = ReadByte(); - self.origin_x = ReadCoord(); - self.origin_y = ReadCoord(); - self.origin_z = ReadCoord(); - setorigin(self, self.origin); - - self.mins_x = ReadCoord(); - self.mins_y = ReadCoord(); - self.mins_z = ReadCoord(); - self.maxs_x = ReadCoord(); - self.maxs_y = ReadCoord(); - self.maxs_z = ReadCoord(); - setsize(self, self.mins, self.maxs); - - self.movedir_x = ReadCoord(); - self.movedir_y = ReadCoord(); - self.movedir_z = ReadCoord(); - - self.speed = ReadByte(); - self.state = ReadByte(); - - self.targetname = strzone(ReadString()); - self.target = strzone(ReadString()); - - conveyor_init(); + this.warpzone_isboxy = ReadByte(); + this.origin = ReadVector(); + setorigin(this, this.origin); + + this.mins = ReadVector(); + this.maxs = ReadVector(); + setsize(this, this.mins, this.maxs); + + this.movedir = ReadVector(); + + this.speed = ReadByte(); + this.active = ReadByte(); + + this.targetname = strzone(ReadString()); + this.target = strzone(ReadString()); + + conveyor_init(this, isnew); } - if(sf & 2) - self.state = ReadByte(); + if(sendflags & SF_TRIGGER_UPDATE) + this.active = ReadByte(); return true; }