From f4c60b122158c7deaeabcb56602f4f5105778484 Mon Sep 17 00:00:00 2001 From: Freddy Date: Wed, 7 Mar 2018 21:52:54 +0100 Subject: [PATCH] func_pointparticles: use relays, replace magic numbers --- qcsrc/common/triggers/func/conveyor.qc | 54 +----------- qcsrc/common/triggers/func/pointparticles.qc | 88 +++++++++----------- qcsrc/common/triggers/spawnflags.qh | 21 +++-- qcsrc/common/triggers/triggers.qc | 52 ++++++++++++ qcsrc/common/triggers/triggers.qh | 6 ++ 5 files changed, 115 insertions(+), 106 deletions(-) diff --git a/qcsrc/common/triggers/func/conveyor.qc b/qcsrc/common/triggers/func/conveyor.qc index acb6529ff..f1b0ad52c 100644 --- a/qcsrc/common/triggers/func/conveyor.qc +++ b/qcsrc/common/triggers/func/conveyor.qc @@ -63,54 +63,6 @@ void conveyor_think(entity this) #ifdef SVQC -void conveyor_setactive(entity this, int act) -{ - int old_status = this.active; - if(act == ACTIVE_TOGGLE) - { - if(this.active == ACTIVE_ACTIVE) - { - this.active = ACTIVE_NOT; - } - else - { - this.active = ACTIVE_ACTIVE; - } - } - else - { - this.active = act; - } - - if (this.active != old_status) - { - this.SendFlags |= SF_TRIGGER_UPDATE; - } -} - -// Compatibility with old maps -void conveyor_use(entity this, entity actor, entity trigger) -{ - conveyor_setactive(this, ACTIVE_TOGGLE); -} - -void conveyor_reset(entity this) -{ - IFTARGETED - { - if(this.spawnflags & CONVEYOR_START_ENABLED) - { - this.active = ACTIVE_ACTIVE; - } - } - else - { - this.active = ACTIVE_ACTIVE; - } - - this.SendFlags |= SF_TRIGGER_UPDATE; -} - bool conveyor_send(entity this, entity to, int sendflags) { WriteHeader(MSG_ENTITY, ENT_CLIENT_CONVEYOR); @@ -145,13 +97,13 @@ void conveyor_init(entity this) this.movedir *= this.speed; setthink(this, conveyor_think); this.nextthink = time; - this.setactive = conveyor_setactive; + this.setactive = generic_netlinked_setactive; IFTARGETED { // backwards compatibility - this.use = conveyor_use; + this.use = generic_netlinked_legacy_use; } - this.reset = conveyor_reset; + this.reset = generic_netlinked_reset; this.reset(this); FixSize(this); diff --git a/qcsrc/common/triggers/func/pointparticles.qc b/qcsrc/common/triggers/func/pointparticles.qc index 54fe212ae..1aaa05e8d 100644 --- a/qcsrc/common/triggers/func/pointparticles.qc +++ b/qcsrc/common/triggers/func/pointparticles.qc @@ -4,39 +4,39 @@ REGISTER_NET_LINKED(ENT_CLIENT_POINTPARTICLES) #ifdef SVQC // NOTE: also contains func_sparks -bool pointparticles_SendEntity(entity this, entity to, float fl) +bool pointparticles_SendEntity(entity this, entity to, float sendflags) { WriteHeader(MSG_ENTITY, ENT_CLIENT_POINTPARTICLES); // optional features to save space - fl = fl & 0x0F; - if(this.spawnflags & 2) - fl |= 0x10; // absolute count on toggle-on + sendflags = sendflags & 0x0F; + if(this.spawnflags & PARTICLES_IMPULSE) + sendflags |= SF_POINTPARTICLES_IMPULSE; // absolute count on toggle-on if(this.movedir != '0 0 0' || this.velocity != '0 0 0') - fl |= 0x20; // 4 bytes - saves CPU + sendflags |= SF_POINTPARTICLES_MOVING; // 4 bytes - saves CPU if(this.waterlevel || this.count != 1) - fl |= 0x40; // 4 bytes - obscure features almost never used + sendflags |= SF_POINTPARTICLES_JITTER_AND_COUNT; // 4 bytes - obscure features almost never used if(this.mins != '0 0 0' || this.maxs != '0 0 0') - fl |= 0x80; // 14 bytes - saves lots of space + sendflags |= SF_POINTPARTICLES_BOUNDS; // 14 bytes - saves lots of space - WriteByte(MSG_ENTITY, fl); - if(fl & 2) + WriteByte(MSG_ENTITY, sendflags); + if(sendflags & SF_TRIGGER_UPDATE) { - if(this.state) + if(this.active == ACTIVE_ACTIVE) WriteCoord(MSG_ENTITY, this.impulse); else WriteCoord(MSG_ENTITY, 0); // off } - if(fl & 4) + if(sendflags & SF_TRIGGER_RESET) { WriteVector(MSG_ENTITY, this.origin); } - if(fl & 1) + if(sendflags & SF_TRIGGER_INIT) { if(this.model != "null") { WriteShort(MSG_ENTITY, this.modelindex); - if(fl & 0x80) + if(sendflags & SF_POINTPARTICLES_BOUNDS) { WriteVector(MSG_ENTITY, this.mins); WriteVector(MSG_ENTITY, this.maxs); @@ -45,19 +45,19 @@ bool pointparticles_SendEntity(entity this, entity to, float fl) else { WriteShort(MSG_ENTITY, 0); - if(fl & 0x80) + if(sendflags & SF_POINTPARTICLES_BOUNDS) { WriteVector(MSG_ENTITY, this.maxs); } } WriteShort(MSG_ENTITY, this.cnt); WriteString(MSG_ENTITY, this.mdl); - if(fl & 0x20) + if(sendflags & SF_POINTPARTICLES_MOVING) { WriteShort(MSG_ENTITY, compressShortVector(this.velocity)); WriteShort(MSG_ENTITY, compressShortVector(this.movedir)); } - if(fl & 0x40) + if(sendflags & SF_POINTPARTICLES_JITTER_AND_COUNT) { WriteShort(MSG_ENTITY, this.waterlevel * 16.0); WriteByte(MSG_ENTITY, this.count * 16.0); @@ -80,30 +80,16 @@ bool pointparticles_SendEntity(entity this, entity to, float fl) return 1; } -void pointparticles_use(entity this, entity actor, entity trigger) -{ - this.state = !this.state; - this.SendFlags |= 2; -} - void pointparticles_think(entity this) { if(this.origin != this.oldorigin) { - this.SendFlags |= 4; + this.SendFlags |= SF_TRIGGER_RESET; this.oldorigin = this.origin; } this.nextthink = time; } -void pointparticles_reset(entity this) -{ - if(this.spawnflags & 1) - this.state = 1; - else - this.state = 0; -} - spawnfunc(func_pointparticles) { if(this.model != "") { precache_model(this.model); _setmodel(this, this.model); } @@ -125,17 +111,17 @@ spawnfunc(func_pointparticles) setsize(this, '0 0 0', this.maxs - this.mins); } //if(!this.cnt) this.cnt = _particleeffectnum(this.mdl); + this.setactive = generic_netlinked_setactive; - Net_LinkEntity(this, (this.spawnflags & 4), 0, pointparticles_SendEntity); + Net_LinkEntity(this, (this.spawnflags & PARTICLES_VISCULLING), 0, pointparticles_SendEntity); IFTARGETED { - this.use = pointparticles_use; - this.reset = pointparticles_reset; - this.reset(this); + // backwards compatibility + this.use = generic_netlinked_legacy_use; } - else - this.state = 1; + this.reset = generic_netlinked_reset; + this.reset(this); setthink(this, pointparticles_think); this.nextthink = time; } @@ -177,10 +163,12 @@ class(PointParticles) .int impulse; // density class(PointParticles) .string noise; // sound class(PointParticles) .float atten; class(PointParticles) .float volume; -class(PointParticles) .float absolute; // 1 = count per second is absolute, 2 = only spawn at toggle +class(PointParticles) .int absolute; // 1 = count per second is absolute, ABSOLUTE_ONLY_SPAWN_AT_TOGGLE = only spawn at toggle class(PointParticles) .vector movedir; // trace direction class(PointParticles) .float glow_color; // palette index +const int ABSOLUTE_ONLY_SPAWN_AT_TOGGLE = 2; + void Draw_PointParticles(entity this) { float n, i, fail; @@ -190,7 +178,7 @@ void Draw_PointParticles(entity this) o = this.origin; sz = this.maxs - this.mins; n = doBGMScript(this); - if(this.absolute == 2) + if(this.absolute == ABSOLUTE_ONLY_SPAWN_AT_TOGGLE) { if(n >= 0) n = this.just_toggled ? this.impulse : 0; @@ -268,22 +256,22 @@ NET_HANDLE(ENT_CLIENT_POINTPARTICLES, bool isnew) { float i; vector v; - int f = ReadByte(); - if(f & 2) + int sendflags = ReadByte(); + if(sendflags & SF_TRIGGER_UPDATE) { i = ReadCoord(); // density (<0: point, >0: volume) if(i && !this.impulse && (this.cnt || this.mdl)) // this.cnt check is so it only happens if the ent already existed this.just_toggled = 1; this.impulse = i; } - if(f & 4) + if(sendflags & SF_TRIGGER_RESET) { this.origin = ReadVector(); } - if(f & 1) + if(sendflags & SF_TRIGGER_INIT) { this.modelindex = ReadShort(); - if(f & 0x80) + if(sendflags & SF_POINTPARTICLES_BOUNDS) { if(this.modelindex) { @@ -304,7 +292,7 @@ NET_HANDLE(ENT_CLIENT_POINTPARTICLES, bool isnew) this.cnt = ReadShort(); // effect number this.mdl = strzone(ReadString()); // effect string - if(f & 0x20) + if(sendflags & SF_POINTPARTICLES_MOVING) { this.velocity = decompressShortVector(ReadShort()); this.movedir = decompressShortVector(ReadShort()); @@ -313,7 +301,7 @@ NET_HANDLE(ENT_CLIENT_POINTPARTICLES, bool isnew) { this.velocity = this.movedir = '0 0 0'; } - if(f & 0x40) + if(sendflags & SF_POINTPARTICLES_JITTER_AND_COUNT) { this.waterlevel = ReadShort() / 16.0; this.count = ReadByte() / 16.0; @@ -346,18 +334,18 @@ NET_HANDLE(ENT_CLIENT_POINTPARTICLES, bool isnew) return = true; - if(f & 2) + if(sendflags & SF_TRIGGER_UPDATE) { this.absolute = (this.impulse >= 0); if(!this.absolute) { v = this.maxs - this.mins; - this.impulse *= -v.x * v.y * v.z / 262144; // relative: particles per 64^3 cube + this.impulse *= -v.x * v.y * v.z / (64**3); // relative: particles per 64^3 cube } } - if(f & 0x10) - this.absolute = 2; + if(sendflags & SF_POINTPARTICLES_IMPULSE) + this.absolute = ABSOLUTE_ONLY_SPAWN_AT_TOGGLE; setorigin(this, this.origin); setsize(this, this.mins, this.maxs); diff --git a/qcsrc/common/triggers/spawnflags.qh b/qcsrc/common/triggers/spawnflags.qh index b2e397d1b..69962e54d 100644 --- a/qcsrc/common/triggers/spawnflags.qh +++ b/qcsrc/common/triggers/spawnflags.qh @@ -2,6 +2,7 @@ // generic usage const int NOSPLASH = BIT(8); // generic anti-splashdamage spawnflag +const int START_ENABLED = BIT(0); // bobbing const int BOBBING_XAXIS = BIT(0); @@ -15,9 +16,6 @@ const int BREAKABLE_NODAMAGE = BIT(2); // button const int BUTTON_DONTACCUMULATEDMG = BIT(7); -// conveyor -const int CONVEYOR_START_ENABLED = BIT(0); - // door, door_rotating and door_secret const int DOOR_START_OPEN = BIT(0); const int DOOR_DONT_LINK = BIT(2); @@ -40,6 +38,10 @@ const int DOOR_SECRET_1ST_DOWN = BIT(2); // 1st move is down from arrow const int DOOR_SECRET_NO_SHOOT = BIT(3); // only opened by trigger const int DOOR_SECRET_YES_SHOOT = BIT(4); // shootable even if targeted +// particles +const int PARTICLES_IMPULSE = BIT(1); +const int PARTICLES_VISCULLING = BIT(2); + // jumppads const int PUSH_ONCE = BIT(0); const int PUSH_SILENT = BIT(1); // not used? @@ -60,9 +62,18 @@ const int TELEPORT_FLAG_TDEATH = BIT(2); const int TELEPORT_FLAG_FORCE_TDEATH = BIT(3); // triggers +const int SPAWNFLAG_NOMESSAGE = BIT(0); +const int SPAWNFLAG_NOTOUCH = BIT(0); // why are these the same? + +//---------- +// SENDFLAGS +//---------- const int SF_TRIGGER_INIT = BIT(0); const int SF_TRIGGER_UPDATE = BIT(1); const int SF_TRIGGER_RESET = BIT(2); -const int SPAWNFLAG_NOMESSAGE = BIT(0); -const int SPAWNFLAG_NOTOUCH = BIT(0); // why are these the same? +// pointparticles +const int SF_POINTPARTICLES_IMPULSE = BIT(4); +const int SF_POINTPARTICLES_MOVING = BIT(5); // Send velocity and movedir +const int SF_POINTPARTICLES_JITTER_AND_COUNT = BIT(6); // Send waterlevel (=jitter) and count +const int SF_POINTPARTICLES_BOUNDS = BIT(7); // Send min and max of the brush diff --git a/qcsrc/common/triggers/triggers.qc b/qcsrc/common/triggers/triggers.qc index f7287212a..034f66e1a 100644 --- a/qcsrc/common/triggers/triggers.qc +++ b/qcsrc/common/triggers/triggers.qc @@ -21,6 +21,58 @@ void FixSize(entity e) } #ifdef SVQC +void generic_netlinked_setactive(entity this, int act) +{ + int old_status = this.active; + if(act == ACTIVE_TOGGLE) + { + if(this.active == ACTIVE_ACTIVE) + { + this.active = ACTIVE_NOT; + } + else + { + this.active = ACTIVE_ACTIVE; + } + } + else + { + this.active = act; + } + + if (this.active != old_status) + { + this.SendFlags |= SF_TRIGGER_UPDATE; + } +} + +void generic_netlinked_reset(entity this) +{ + IFTARGETED + { + if(this.spawnflags & START_ENABLED) + { + this.active = ACTIVE_ACTIVE; + } + else + { + this.active = ACTIVE_NOT; + } + } + else + { + this.active = ACTIVE_ACTIVE; + } + + this.SendFlags |= SF_TRIGGER_UPDATE; +} + +// Compatibility with old maps +void generic_netlinked_legacy_use(entity this, entity actor, entity trigger) +{ + LOG_WARNF("Entity %s was (de)activated by a trigger, please update map to use relays", this.targetname); + this.setactive(this, ACTIVE_TOGGLE); +} bool autocvar_g_triggers_debug = true; diff --git a/qcsrc/common/triggers/triggers.qh b/qcsrc/common/triggers/triggers.qh index 588972002..681bb898b 100644 --- a/qcsrc/common/triggers/triggers.qh +++ b/qcsrc/common/triggers/triggers.qh @@ -22,6 +22,12 @@ void target_voicescript_next(entity pl); void target_voicescript_clear(entity pl); void SUB_UseTargets_PreventReuse(entity this, entity actor, entity trigger); + +// generic methods for netlinked entities +void generic_netlinked_reset(entity this); +void generic_netlinked_setactive(entity this, int act); +// WARNING: DON'T USE, ONLY TO KEEP COMPATIBILITY BECAUSE OF SWITCH FROM .state TO .alive!!!! +void generic_netlinked_legacy_use(entity this, entity actor, entity trigger); #endif .float sub_target_used; -- 2.39.2