--- a/rts/Game/WebbarBrowser.h +++ b/rts/Game/WebbarBrowser.h @@ -99,6 +99,7 @@ #include "WebbarReports.h" #include "WebbarPlacement.h" #include "WebbarWorld.h" +#include "WebbarGeoSmoke.h" #include "WebbarTerrain.h" #include "WebbarTerrainFixture.h" #include "WebbarPoses.h" @@ -715,6 +716,7 @@ static const bool browser = std::getenv("WEBBAR_BROWSER") != nullptr; static const bool playableBrowser = browser && std::getenv("WEBBAR_PLAYABLE") != nullptr; if (playableBrowser && gs->frameNum >= 0) { SCOPED_TIMER("Webbar::Publish::Effects"); GetWebbarEffects().Publish(); } + if (playableBrowser && gs->frameNum >= 0) { SCOPED_TIMER("Webbar::Publish::GeoSmoke"); PublishWebbarGeoSmoke(); } if (playableBrowser) { PublishWebbarAutomationReports(); PublishWebbarBomberTargets(); PublishWebbarOrderEvents(); } // A recorded automation policy adds exact10-frame ferry observations. Old // streams without that registry keep the original publication cadence. --- /dev/null +++ b/rts/Game/WebbarGeoSmoke.h @@ -0,0 +1,42 @@ +/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */ +#pragma once +#include +#include +#include +#include "Rendering/Env/Particles/Classes/GeoThermSmokeProjectile.h" +#include "Rendering/Env/Particles/ProjectileDrawer.h" +#include "Sim/Projectiles/ProjectileHandler.h" + +// Only original ownerless, always-visible geothermal smoke. Native code owns +// emission, collisions/cover, wind, lifetime, colour and texture selection. +// This optional stream adds nothing to WBG1, WBF2 or the bridge9 contract. +static void PublishWebbarGeoSmoke() +{ + static const bool enabled = MAIN_THREAD_EM_ASM_INT({ return typeof Module['webbarGeoSmoke'] === 'function' ? 1 : 0; }); + if (!enabled) return; + struct Record { + float previous[3], current[3]; + float size, expansion, radius; + uint32_t rgba, texture, flags; + }; + static_assert(sizeof(Record) == 48); + static std::vector records; + records.clear(); + uint32_t dropped = 0; + for (const CProjectile* projectile: projectileHandler.GetActiveProjectiles(false)) { + const auto* smoke = dynamic_cast(projectile); + // Match the original delayed renderer admission. These puffs are public + // because CSmokeProjectile(nullptr,...) explicitly makes them visible. + if (smoke == nullptr || smoke->createMe || !smoke->alwaysVisible) continue; + if (records.size() >= 8192) { ++dropped; continue; } + const float3& previous = smoke->preFrameTra.t; + const float3& current = smoke->pos; + records.push_back({{previous.x, previous.y, previous.z}, {current.x, current.y, current.z}, smoke->size, smoke->GetWebbarSmokeExpansion(), smoke->GetDrawRadius(), smoke->GetWebbarSmokeColor(), smoke->GetWebbarSmokeTexture(), uint32_t(smoke->castShadow) | (uint32_t(smoke->alwaysVisible) << 1)}); + } + const uint32_t header[] = {0x31534757, uint32_t(gs->frameNum), uint32_t(records.size()), uint32_t(projectileDrawer->NumSmokeTextures()), dropped}; + static std::vector packet; + packet.resize(sizeof(header) + records.size() * sizeof(Record)); + std::memcpy(packet.data(), header, sizeof(header)); + if (!records.empty()) std::memcpy(packet.data() + sizeof(header), records.data(), records.size() * sizeof(Record)); + MAIN_THREAD_EM_ASM({ if (Module['webbarGeoSmoke']) Module['webbarGeoSmoke'](HEAPU8.slice($0, $0 + $1).buffer); }, packet.data(), packet.size()); +} --- a/rts/Rendering/Env/Particles/Classes/SmokeProjectile.h +++ b/rts/Rendering/Env/Particles/Classes/SmokeProjectile.h @@ -38,6 +38,16 @@ float ageSpeed; public: float size; +#if defined(__EMSCRIPTEN__) + // Read-only browser presentation. No layout, lifetime or simulation change. + unsigned GetWebbarSmokeColor() const { + const unsigned char alpha = static_cast((1.0f - age) * 255.0f); + const unsigned char shade = static_cast(color * alpha); + return unsigned(shade) | (unsigned(shade) << 8) | (unsigned(shade) << 16) | (unsigned(alpha) << 24); + } + float GetWebbarSmokeExpansion() const { return sizeExpansion; } + unsigned GetWebbarSmokeTexture() const { return textureNum; } +#endif private: float startSize; float sizeExpansion;