--- a/rts/Game/WebbarWeapons.h +++ b/rts/Game/WebbarWeapons.h @@ -1,6 +1,8 @@ /* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */ #pragma once #include "Sim/Projectiles/WeaponProjectiles/WeaponProjectile.h" +#include "Sim/Projectiles/WeaponProjectiles/FlameProjectile.h" +#include "Sim/Projectiles/WeaponProjectiles/WeaponProjectileTypes.h" #include "Sim/Weapons/PlasmaRepulser.h" #include "Sim/Features/Feature.h" #include "Sim/Units/Unit.h" @@ -41,6 +43,9 @@ // Optional WPN4 suffix. Read only fully constructed, admitted projectiles in // Publish, never their base-constructor ProjectileCreated notification. struct ShotBounds { float radius; uint32_t hasModel; }; + // Optional WPN5 appends original fully constructed flame radius/curTime. + // Non-flame records carry -1/-1. Existing WPN3/4 and bridge9 stay supported. + struct ShotFlame { float radius, time, drawX, drawY, drawZ; }; // 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); } @@ -126,6 +131,8 @@ std::vector shots; static const bool publishBounds = std::getenv("WEBBAR_NATIVE_VISUAL_BOUNDS") != nullptr; std::vector bounds; + static const bool publishFlame = publishBounds && std::getenv("WEBBAR_NATIVE_FLAME_VBO") != nullptr; + std::vector flames; uint32_t omitted=0; for (const auto* p: projectileHandler.GetActiveProjectiles(true)) { if (!p->weapon || p->deleteMe || !WebbarProjectileVisible(p)) continue; @@ -136,6 +143,10 @@ 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}); + if (publishFlame) { + const auto* flame = p->GetProjectileType() == WEAPON_FLAME_PROJECTILE ? static_cast(w) : nullptr; + flames.push_back(flame != nullptr ? ShotFlame{flame->radius, flame->GetVisualTime(), flame->preFrameTra.t.x, flame->preFrameTra.t.y, flame->preFrameTra.t.z} : ShotFlame{-1.0f, -1.0f, 0.0f, 0.0f, 0.0f}); + } } for (const auto* d: pending) { const auto& v=d->visuals; @@ -148,7 +159,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 && sizeof(ShotBounds)==8); + static_assert(sizeof(Record)==88 && sizeof(Shot)==56 && sizeof(ShotBounds)==8 && sizeof(ShotFlame)==20); 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)); @@ -156,14 +167,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[]={publishBounds ? 0x34574257u : 0x33574257u,uint32_t(gs->frameNum),uint32_t(shots.size()),omitted}; - const size_t stride = sizeof(Shot) + (publishBounds ? sizeof(ShotBounds) : 0); + const uint32_t header[]={publishFlame ? 0x35574257u : publishBounds ? 0x34574257u : 0x33574257u,uint32_t(gs->frameNum),uint32_t(shots.size()),omitted}; + const size_t stride = sizeof(Shot) + (publishBounds ? sizeof(ShotBounds) : 0) + (publishFlame ? sizeof(ShotFlame) : 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)); + if (publishFlame) std::memcpy(packet.data()+sizeof(header)+i*stride+sizeof(Shot)+sizeof(ShotBounds),&flames[i],sizeof(ShotFlame)); } MAIN_THREAD_EM_ASM({if(Module['webbarWeapons'])Module['webbarWeapons'](HEAPU8.slice($0,$0+$1).buffer);},packet.data(),packet.size()); } --- a/rts/Sim/Projectiles/WeaponProjectiles/FlameProjectile.h +++ b/rts/Sim/Projectiles/WeaponProjectiles/FlameProjectile.h @@ -19,6 +19,8 @@ void Collision() override; int GetProjectilesCount() const override; + // Read-only original visual phase; never advance it from presentation code. + float GetVisualTime() const { return curTime; } int ShieldRepulse(const float3& shieldPos, float shieldForce, float shieldMaxSpeed) override;