--- a/rts/Game/WebbarWeapons.h +++ b/rts/Game/WebbarWeapons.h @@ -6,6 +6,7 @@ #include "Sim/Units/Unit.h" #include "Game/WebbarEffectQueue.h" #include +#include // Same discriminator as Spring.GetProjectileTarget, read only after the existing // projectile admission. Do not publish its target ID or look up another object. @@ -37,6 +38,9 @@ // WPN3: existing WPN2 fields, then original Lua target kind (g/u/f/p or 0). // The projectile is already admitted; target IDs are never exported here. struct Shot { uint32_t id, definition, team; float x,y,z,vx,vy,vz,ex,ey,ez,ttl; uint32_t targetKind; }; + // Optional WPN4 suffix. Read only fully constructed, admitted projectiles in + // Publish, never their base-constructor ProjectileCreated notification. + struct ShotBounds { float radius; uint32_t hasModel; }; // WBC1 naval CEG record (wakes, bow splashes, Lua splashes, torpedo trails). struct Ceg { uint32_t id, frame, generator, owner, flags, pad; float pos[3], dir[3], damage, radius, gfxMod, pad2; }; WebbarEffects(): CEventClient("Webbar browser effects", -100000, false) { eventHandler.AddClient(this); } @@ -120,6 +124,8 @@ void Publish() { DrainQueues(); std::vector shots; + static const bool publishBounds = std::getenv("WEBBAR_NATIVE_VISUAL_BOUNDS") != nullptr; + std::vector bounds; uint32_t omitted=0; for (const auto* p: projectileHandler.GetActiveProjectiles(true)) { if (!p->weapon || p->deleteMe || !WebbarProjectileVisible(p)) continue; @@ -129,6 +135,7 @@ const float3& pos=d->IsHitScanWeapon()?w->GetStartPos():p->pos; const auto& end=w->GetTargetPos(); shots.push_back({uint32_t(p->id),definition,p->GetTeamID()>=0?uint32_t(p->GetTeamID()):0xffffffff,pos.x,pos.y,pos.z,p->speed.x,p->speed.y,p->speed.z,end.x,end.y,end.z,float(w->GetTimeToLive()),WebbarProjectileTargetKind(w)}); + if (publishBounds) bounds.push_back({p->GetDrawRadius(), p->model != nullptr ? 1u : 0u}); } for (const auto* d: pending) { const auto& v=d->visuals; @@ -141,7 +148,7 @@ },d->id,d->name.c_str(),d->type.c_str(),v.impactExpGenTag.c_str(),v.ptrailExpGenTag.c_str(),v.modelName.c_str(),values,(d->customParams.contains("beam_thickness_orig")||d->customParams.contains("plasma_size_orig"))); } pending.clear(); - static_assert(sizeof(Record)==88 && sizeof(Shot)==56); + static_assert(sizeof(Record)==88 && sizeof(Shot)==56 && sizeof(ShotBounds)==8); if (!records.empty() || dropped) { const uint32_t header[]={0x33454257,uint32_t(gs->frameNum),uint32_t(records.size()),dropped}; std::vector packet(sizeof(header)+records.size()*sizeof(Record)); @@ -149,9 +156,15 @@ MAIN_THREAD_EM_ASM({if(Module['webbarEffects'])Module['webbarEffects'](HEAPU8.slice($0,$0+$1).buffer);},packet.data(),packet.size()); records.clear();dropped=0; } - const uint32_t header[]={0x33574257,uint32_t(gs->frameNum),uint32_t(shots.size()),omitted}; - std::vector packet(sizeof(header)+shots.size()*sizeof(Shot)); - std::memcpy(packet.data(),header,sizeof(header));std::memcpy(packet.data()+sizeof(header),shots.data(),shots.size()*sizeof(Shot)); + const uint32_t header[]={publishBounds ? 0x34574257u : 0x33574257u,uint32_t(gs->frameNum),uint32_t(shots.size()),omitted}; + const size_t stride = sizeof(Shot) + (publishBounds ? sizeof(ShotBounds) : 0); + std::vector packet(sizeof(header)+shots.size()*stride); + std::memcpy(packet.data(),header,sizeof(header)); + if (!publishBounds) std::memcpy(packet.data()+sizeof(header),shots.data(),shots.size()*sizeof(Shot)); + else for (size_t i = 0; i < shots.size(); ++i) { + std::memcpy(packet.data()+sizeof(header)+i*stride,&shots[i],sizeof(Shot)); + std::memcpy(packet.data()+sizeof(header)+i*stride+sizeof(Shot),&bounds[i],sizeof(ShotBounds)); + } MAIN_THREAD_EM_ASM({if(Module['webbarWeapons'])Module['webbarWeapons'](HEAPU8.slice($0,$0+$1).buffer);},packet.data(),packet.size()); } std::vector records;