From: TimePath Date: Tue, 6 Oct 2015 23:38:30 +0000 (+1100) Subject: Net: tempentity support X-Git-Tag: xonotic-v0.8.2~1861 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=784ed7e054583264723e7638b3f6817a87cf3de7;p=xonotic%2Fxonotic-data.pk3dir.git Net: tempentity support --- diff --git a/qcsrc/client/main.qc b/qcsrc/client/main.qc index e3f07b275..d494050f0 100644 --- a/qcsrc/client/main.qc +++ b/qcsrc/client/main.qc @@ -835,7 +835,7 @@ void CSQC_Ent_Update(float bIsNewEntity) #endif self.enttype = t; bool done = false; - FOREACH(Linked, it.m_id == t, LAMBDA( + FOREACH(LinkedEntities, it.m_id == t, LAMBDA( it.m_read(self, bIsNewEntity); done = true; break; @@ -1266,7 +1266,7 @@ void Net_WeaponComplain() // CSQC_Parse_TempEntity : Handles all temporary entity network data in the CSQC layer. // You must ALWAYS first acquire the temporary ID, which is sent as a byte. // Return value should be 1 if CSQC handled the temporary entity, otherwise return 0 to have the engine process the event. -float CSQC_Parse_TempEntity() +bool CSQC_Parse_TempEntity() { // Acquire TE ID int nTEID = ReadByte(); @@ -1274,6 +1274,10 @@ float CSQC_Parse_TempEntity() if (autocvar_developer_csqcentities) LOG_INFOF("CSQC_Parse_TempEntity() with nTEID=%d\n", nTEID); + FOREACH(TempEntities, it.m_id == nTEID, LAMBDA( + it.m_read(NULL, true); + return true; + )); switch (nTEID) { case TE_CSQC_MUTATOR: diff --git a/qcsrc/common/nades/all.qc b/qcsrc/common/nades/all.qc index 86e6d278b..33c1a7e18 100644 --- a/qcsrc/common/nades/all.qc +++ b/qcsrc/common/nades/all.qc @@ -51,9 +51,10 @@ void healer_setup(entity e) } #endif // CSQC -REGISTER_LINKED(Nade_Heal, bool isNew) +REGISTER_NET_LINKED(Nade_Heal, bool isNew) #ifdef CSQC { + Net_Accept(); int sf = ReadByte(); if (sf & 1) { this.origin_x = ReadCoord(); @@ -70,21 +71,22 @@ REGISTER_LINKED(Nade_Heal, bool isNew) #endif #ifdef SVQC -float healer_send(entity to, int sf) +bool healer_send(entity to, int sf) { SELFPARAM(); - WriteByte(MSG_ENTITY, Linked_Nade_Heal.m_id); - WriteByte(MSG_ENTITY, sf); + int channel = MSG_ENTITY; + WriteHeader(channel, Nade_Heal); + WriteByte(channel, sf); if (sf & 1) { - WriteCoord(MSG_ENTITY, this.origin.x); - WriteCoord(MSG_ENTITY, this.origin.y); - WriteCoord(MSG_ENTITY, this.origin.z); + WriteCoord(channel, this.origin.x); + WriteCoord(channel, this.origin.y); + WriteCoord(channel, this.origin.z); - WriteByte(MSG_ENTITY, this.healer_lifetime); + WriteByte(channel, this.healer_lifetime); //WriteByte(MSG_ENTITY, this.ltime - time + 1); - WriteShort(MSG_ENTITY, this.healer_radius); + WriteShort(channel, this.healer_radius); // round time delta to a 1/10th of a second - WriteByte(MSG_ENTITY, (this.ltime - time)*10.0+0.5); + WriteByte(channel, (this.ltime - time)*10.0+0.5); } return true; } diff --git a/qcsrc/lib/net.qh b/qcsrc/lib/net.qh index a41fae144..ff18f0eaf 100644 --- a/qcsrc/lib/net.qh +++ b/qcsrc/lib/net.qh @@ -49,32 +49,67 @@ void UncustomizeEntitiesRun() #include "registry.qh" #include "sort.qh" -REGISTRY(Linked, 24) - .string netname; .int m_id; .void(entity this, bool isNew) m_read; #ifdef CSQC - #define REGISTER_LINKED(id, param) \ + #define Net_Accept() do { if (!this) this = spawn(); } while (0) + #define Net_Reject() do { if (this) remove(this); } while (0) +#else + #define WriteHeader(to, id) do { \ + if (NET_##id##_istemp) WriteByte(to, SVC_TEMPENTITY); \ + WriteByte(to, NET_##id.m_id); \ + } while (0) +#endif + +#ifdef CSQC + #define REGISTER_NET_LINKED(id, param) \ void Ent_Read##id(entity this, param) { this = self; } \ - REGISTER(RegisterLinked, Linked, Linked, Linked_COUNT, id, m_id, spawn()) { \ + REGISTER(RegisterLinkedEntities, NET, LinkedEntities, LinkedEntities_COUNT, id, m_id, spawn()) { \ this.netname = #id; \ this.m_read = Ent_Read##id; \ } \ [[accumulate]] void Ent_Read##id(entity this, param) #else - #define REGISTER_LINKED(id, param) \ - REGISTER(RegisterLinked, Linked, Linked, Linked_COUNT, id, m_id, spawn()) { \ + #define REGISTER_NET_LINKED(id, param) \ + const bool NET_##id##_istemp = false; \ + REGISTER(RegisterLinkedEntities, NET, LinkedEntities, LinkedEntities_COUNT, id, m_id, spawn()) { \ + this.netname = #id; \ + } +#endif + +REGISTRY(LinkedEntities, 24) +REGISTER_REGISTRY(RegisterLinkedEntities) +REGISTRY_SORT(LinkedEntities, netname, 0) +STATIC_INIT(RegisterLinkedEntities_renumber) { + for (int i = 0; i < LinkedEntities_COUNT; ++i) { + LinkedEntities[i].m_id = 100 + i; + } +} + +#ifdef CSQC + #define REGISTER_NET_TEMP(id, param) \ + void Net_Read##id(entity this, param); \ + REGISTER(RegisterTempEntities, NET, TempEntities, TempEntities_COUNT, id, m_id, spawn()) { \ + this.netname = #id; \ + this.m_read = Net_Read##id; \ + } \ + void Net_Read##id(entity this, param) +#else + #define REGISTER_NET_TEMP(id, param) \ + const bool NET_##id##_istemp = true; \ + REGISTER(RegisterTempEntities, NET, TempEntities, TempEntities_COUNT, id, m_id, spawn()) { \ this.netname = #id; \ } #endif -REGISTER_REGISTRY(RegisterLinked) -REGISTRY_SORT(Linked, netname, 0) -STATIC_INIT(RegisterLinked_renumber) { - for (int i = 0; i < Linked_COUNT; ++i) { - Linked[i].m_id = 100 + i; +REGISTRY(TempEntities, 24) +REGISTER_REGISTRY(RegisterTempEntities) +REGISTRY_SORT(TempEntities, netname, 0) +STATIC_INIT(RegisterTempEntities_renumber) { + for (int i = 0; i < TempEntities_COUNT; ++i) { + TempEntities[i].m_id = 115 + i; } }