--- a/rts/Game/WebbarPoses.h +++ b/rts/Game/WebbarPoses.h @@ -20,7 +20,9 @@ // only when its own animation state changed; the page composes the hierarchy from the parent table // (sent with the unit's structure item). The unit record carries rotation only (the snapshot has the // position). -// Unsynced and read-only: nothing here changes simulation state or the engine's own model caches. +// Legacy mode is read-only. Optional native TRS mode steps only the unsynced +// visual cache using the original draw lifecycle; active-feature checks are required. +#include "Game/WebbarCloakEvents.h" #include #include #include @@ -57,8 +59,8 @@ static_assert(offsetof(Header, extensionMagic) == 232); static_assert(sizeof(Header) == 352); constexpr uint32_t HEADER_BYTES = 384, SLOT_HEADER_BYTES = 32; -constexpr uint32_t EXTENSION_MAGIC = 0x31584257, FEATURE_BOUNDS = 1, FEATURE_REFLECTION = 2; -constexpr uint8_t FLAG_ROTATION = 1, FLAG_CULLED = 2, FLAG_LOD = 4, FLAG_RESET = 8, FLAG_STRUCTURE = 16, FLAG_NATIVE_BOUNDS = 32; +constexpr uint32_t EXTENSION_MAGIC = 0x31584257, FEATURE_BOUNDS = 1, FEATURE_REFLECTION = 2, FEATURE_NATIVE_TRS = 4, FEATURE_NATIVE_DRAW_TIMING = 8, FEATURE_NATIVE_PROPERTIES = 16, FEATURE_NATIVE_COUPLED = 32, FEATURE_NATIVE_CLOAK_TIMING = 64; +constexpr uint8_t FLAG_ROTATION = 1, FLAG_CULLED = 2, FLAG_LOD = 4, FLAG_RESET = 8, FLAG_STRUCTURE = 16, FLAG_NATIVE_BOUNDS = 32, FLAG_NATIVE_TRS = 64, FLAG_NATIVE_PROPERTIES = 128; struct PieceState { float raw[7]; uint32_t visible; float m[12]; int32_t first; bool dirty; }; struct UnitState { @@ -102,7 +104,7 @@ std::memset(memory, 0, HEADER_BYTES + 3 * size_t(next)); Header* h = reinterpret_cast(memory); h->magic = 0x314d5057; h->version = 1; h->middle = 1; h->slotCapacity = next; - h->extensionMagic = EXTENSION_MAGIC; h->supportedFeatures = FEATURE_BOUNDS | FEATURE_REFLECTION; + h->extensionMagic = EXTENSION_MAGIC; h->supportedFeatures = FEATURE_BOUNDS | FEATURE_REFLECTION | FEATURE_NATIVE_TRS | FEATURE_NATIVE_DRAW_TIMING | FEATURE_NATIVE_PROPERTIES | FEATURE_NATIVE_COUPLED | FEATURE_NATIVE_CLOAK_TIMING; for (int i = 0; i < 3; ++i) h->slotOffset[i] = HEADER_BYTES + i * next; if (header != nullptr) { // Keep the page's acknowledgement, camera and statistics across the switch. @@ -114,6 +116,7 @@ std::memcpy(h->stats, header->stats, sizeof(h->stats)); h->stats[7] += 1; } + if (std::getenv("WEBBAR_NATIVE_POSES_TEST") != nullptr) h->requestedFeatures |= FEATURE_NATIVE_TRS | FEATURE_BOUNDS; block = memory; header = h; capacity = next; back = 2; MAIN_THREAD_EM_ASM({ if (Module['webbarPoseMailbox']) Module['webbarPoseMailbox']($0, $1); }, block, HEADER_BYTES + 3 * next); } @@ -124,9 +127,12 @@ void Bytes(const void* data, size_t size) { if (at + size > limit) { overflow = true; return; } std::memcpy(base + at, data, size); at += size; } }; +#include "WebbarNativePoses.h" + // Returns false when the slot overflowed (the caller grows the mailbox and publishes again). static bool Write(const std::vector& units, int32_t slotSeq) { + if (NativeRequested()) return WriteNative(units, slotSeq); const int32_t acknowledged = __atomic_load_n(&header->consumed, __ATOMIC_ACQUIRE); float view[32]; std::memcpy(view, header->view, sizeof(view)); @@ -282,7 +288,8 @@ if (Write(units, slotSeq)) return; // Units are pending again (chains reset); a larger block gets a fresh triple buffer. const size_t pieces = std::accumulate(units.begin(), units.end(), size_t(0), [](size_t n, const CUnit* u) { return n + u->localModel.pieces.size(); }); - Allocate(uint32_t(SLOT_HEADER_BYTES + units.size() * 68 + pieces * 54 + 4096)); + const bool native = NativeRequested(); + Allocate(uint32_t(SLOT_HEADER_BYTES + (native ? sizeof(NativeFrameTiming) + sizeof(NativeDrawStamp) : 0) + units.size() * (native ? 92 + sizeof(NativeProperties) : 68) + pieces * (native ? 68 : 54) + 4096)); } } @@ -290,7 +297,7 @@ // current frame when the camera changed, so units panned into view get their real pose (not a stale one). static void Refresh(const std::vector& (*units)()) { - if (!Enabled() || block == nullptr || (!gs->paused && !(webbarReplay::Enabled() && (webbarReplay::paused.load() || gs->frameNum >= webbarReplay::total.load()))) || gs->frameNum < 0) return; + if (!Enabled() || block == nullptr || NativeCoupledRequested() || (!gs->paused && !(webbarReplay::Enabled() && (webbarReplay::paused.load() || gs->frameNum >= webbarReplay::total.load()))) || gs->frameNum < 0) return; if (__atomic_load_n(&header->cameraSeq, __ATOMIC_ACQUIRE) == publishedCameraSeq) return; Publish(units()); } --- a/rts/Game/WebbarBrowser.h +++ b/rts/Game/WebbarBrowser.h @@ -103,6 +103,7 @@ #include "WebbarTerrain.h" #include "WebbarTerrainFixture.h" #include "WebbarPoses.h" +static void PublishWebbarPoses(); #include "WebbarNativeBeams.h" #include "WebbarQueueActions.h" #include "WebbarQuotaOwnership.h" @@ -574,7 +575,8 @@ } // Separate, versioned pose stream used only by the playable client. Compose -// matrices from copied animation state, without updating the engine's caches. +// matrices from animation state. Legacy mode is read-only; native TRS mode +// follows the original unsynced cache/reset lifecycle. static void PublishWebbarPoses() { const auto& units = WebbarUnits(); @@ -722,6 +724,10 @@ if (playableBrowser && gs->frameNum >= 0) UpdateWebbarNativeBeams(); if (playableBrowser && gs->frameNum >= 0) { SCOPED_TIMER("Webbar::Publish::GeoSmoke"); PublishWebbarGeoSmoke(); } if (playableBrowser) { PublishWebbarAutomationReports(); PublishWebbarBomberTargets(); PublishWebbarOrderEvents(); } + // Optional native transforms use actual simulation-frame endpoints. Legacy + // clients retain the established three-frame publication and slot layout. + const bool nativePosesPublished = playableBrowser && gs->frameNum >= 0 && WebbarPoseMailbox::NativeRequested(); + if (nativePosesPublished && (!WebbarPoseMailbox::NativeCoupledRequested() || !WebbarPoseMailbox::NativeDrawStarted())) { SCOPED_TIMER("Webbar::Publish::NativePoses"); PublishWebbarPoses(); } // A recorded automation policy adds exact10-frame ferry observations. Old // streams without that registry keep the original publication cadence. const bool automationTick = playableBrowser && unitHandler.webbarAutomation.active && gs->frameNum % 10 == 0; @@ -780,7 +786,7 @@ { SCOPED_TIMER("Webbar::Publish::Nano"); WebbarNano::Publish(); } { SCOPED_TIMER("Webbar::Publish::Terrain"); PublishWebbarTerrain(); } { SCOPED_TIMER("Webbar::Publish::State"); PublishWebbarPlayState(); } - { SCOPED_TIMER("Webbar::Publish::Poses"); PublishWebbarPoses(); } + { SCOPED_TIMER("Webbar::Publish::Poses"); if (!nativePosesPublished) PublishWebbarPoses(); } } MAIN_THREAD_EM_ASM({ if (Module['webbarSnapshot']) Module['webbarSnapshot'](HEAPU8.slice($0, $0 + $1).buffer); --- a/rts/Game/WebbarNativeDistortion.h +++ b/rts/Game/WebbarNativeDistortion.h @@ -84,7 +84,7 @@ float uniforms[12]={float(gs->frameNum),spring_tomsecs(globalRendering->grTime)*.001f,(gs->GetLuaSimFrame()+next.fraction)/GAME_SPEED,next.fraction}; if(bins){lua_getglobal(L,"webbarDistortionUniforms");valid=Uniform("windXZ",uniforms+4,2)&&Uniform("radiusMultiplier",uniforms+6,1)&&Uniform("intensityMultiplier",uniforms+7,1)&&Uniform("distortionOverallStrength",uniforms+8,1);lua_pop(L,1);} if(!valid){ready=false;Report();return;} - const uint32_t header[]={0x31544457,1,uint32_t(gs->frameNum),bins,180,epoch,uint32_t(sequence),total};std::vector packet;packet.reserve(sizeof(header)+sizeof(uniforms)+payload.size());Append(packet,header,sizeof(header));Append(packet,uniforms,sizeof(uniforms));Append(packet,payload.data(),payload.size()); + const uint32_t header[]={0x31544457,(next.flags&1u)?2u:1u,uint32_t(gs->frameNum),bins,180,epoch,uint32_t(sequence),total};std::vector packet;packet.reserve(sizeof(header)+sizeof(uniforms)+payload.size());Append(packet,header,sizeof(header));Append(packet,uniforms,sizeof(uniforms));Append(packet,payload.data(),payload.size()); MAIN_THREAD_EM_ASM({if(Module['webbarNativeDistortionVBO'])Module['webbarNativeDistortionVBO'](HEAPU8.slice($0,$0+$1).buffer);},packet.data(),packet.size()); } private: @@ -95,7 +95,7 @@ bool Pose(int id,int piece,float* matrix,float* identity,float* speed){ const CUnit* unit=id>=0&&size_t(id)spectatingFullView&&(gu->myAllyTeam<0||!(unit->losStatus[gu->myAllyTeam]&LOS_INLOS))))return true; auto it=poses.find(id);if(it==poses.end()){UnitPose p;p.world=Interpolate(unit->preFrameTra,Transform::FromMatrix(unit->GetTransformMatrix(true)),request.fraction);const auto& parts=unit->localModel.pieces;p.current.reserve(parts.size());for(const auto& part:parts){const Transform local=part.CalcPieceSpaceTransform(part.GetPosition(),part.GetRotation(),part.GetScaling());if(part.parent&&part.parent->GetLModelPieceIndex()>=p.current.size()){failureDetail="parent piece order";return false;}p.current.push_back(part.parent?p.current[part.parent->GetLModelPieceIndex()]*local:local);}it=poses.emplace(id,std::move(p)).first;} - auto& pose=it->second;Transform result=pose.world;if(piece){if(size_t(piece)>pose.current.size()){failureDetail="piece outside attached model";failurePieces=int(pose.current.size());return false;}const auto& part=unit->localModel.pieces[piece-1];if(!part.GetScriptVisible())return true;result=result*Interpolate(part.GetEffectivePrevModelSpaceTransformFor(pose.current[piece-1]),pose.current[piece-1],request.fraction);} + auto& pose=it->second;Transform result=pose.world;if(piece){if(size_t(piece)>pose.current.size()){failureDetail="piece outside attached model";failurePieces=int(pose.current.size());return false;}const auto& part=unit->localModel.pieces[piece-1];if(!part.GetScriptVisible())return true;Transform previous=part.GetEffectivePrevModelSpaceTransformFor(pose.current[piece-1]),current=pose.current[piece-1];WebbarPoseMailbox::NativePiecePair(unit,piece-1,previous,current);result=result*Interpolate(previous,current,request.fraction);} const CMatrix44f m=result.ToMatrix();for(int i=0;i<16;i++){matrix[i]=m[i];if(!std::isfinite(matrix[i])){failureDetail="nonfinite attachment matrix";return false;}}*identity=float(id);for(int i=0;i<4;i++)speed[i]=unit->speed[i];return true; } static void Append(std::vector& out,const void* data,size_t size){if(!size)return;const auto* p=static_cast(data);out.insert(out.end(),p,p+size);} --- a/rts/Game/WebbarNativePoses.h +++ b/rts/Game/WebbarNativePoses.h @@ -0,0 +1,163 @@ +/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */ +#pragma once +// Included inside WebbarPoseMailbox after Header/Writer. Optional WBX1 bit4; +// no new layout is sent until the reader explicitly requests native transforms. +// This private path steps the original unsynced model cache just as +// CModelDrawerDataBase::UpdateObjectTrasform does. Active-feature determinism, +// draw/reset lifecycle, visibility and moving-image qualification are required. +struct NativeFrameTiming { + uint32_t magic; uint32_t bytes; + double atEpochMs, frameStartEpochMs, lastDrawStartEpochMs; + float simFPS, averageDrawMs, previousOffset; + int32_t lastDrawSimFrame, smoothMode; + uint32_t flags; // paused1, lagging2, preSim4, capture8 + float captureOffset, uncertaintyMs; +}; +static_assert(sizeof(NativeFrameTiming) == 64); +struct NativeDrawStamp { + uint32_t magic = 0x31444e57, sequence = 0; // WND1, request sequence + float offset = 0; uint32_t reserved = 0; double atEpochMs = 0; +}; +static_assert(sizeof(NativeDrawStamp) == 24); +struct NativeProperties { + uint32_t creation, kind; + float health, progress, radius, x, y, z, heading, vx, vz; +}; +static_assert(sizeof(NativeProperties) == 44); +static NativeDrawStamp nativeDrawStamp; +static bool NativeRequested(); +static bool NativeCoupledRequested() {return NativeRequested() && (__atomic_load_n(&header->requestedFeatures,__ATOMIC_ACQUIRE) & FEATURE_NATIVE_COUPLED) != 0;} +static bool NativeDrawStarted() {return nativeDrawStamp.sequence != 0;} +static double NativeEpochNow() {return EM_ASM_DOUBLE({return performance.timeOrigin + performance.now();});} +static void SetNativeDrawStamp(uint32_t sequence,float offset,double at) {nativeDrawStamp.sequence=sequence;nativeDrawStamp.offset=offset;nativeDrawStamp.atEpochMs=at;} + +struct NativePieceState { + float values[16] = {}; // effective previous then current:quat.xyzw,xyz,scale + uint16_t visible = 0; + bool initialized = false, dirty = true; + int32_t first = -1; +}; +struct NativeUnitState { + int32_t def = -1, creation = INT32_MIN, computedFrame = INT32_MIN, lastActive = -1; + float world[16] = {}; + std::vector pieces; +}; +static std::vector nativeStates; +static bool NativeRequested() { + return Enabled() && header != nullptr && (__atomic_load_n(&header->requestedFeatures, __ATOMIC_ACQUIRE) & FEATURE_NATIVE_TRS) != 0; +} +static void NativeTransformValues(const Transform& v, float* out) { + const float values[] = {v.r.x,v.r.y,v.r.z,v.r.r,v.t.x,v.t.y,v.t.z,v.s}; + std::memcpy(out, values, sizeof(values)); +} +static Transform NativeTransformValue(const float* v) { + return Transform{CQuaternion{v[0],v[1],v[2],v[3]},float3{v[4],v[5],v[6]},v[7]}; +} +// Share the same pre-reset effective pairs with original attached effects. +static bool NativePiecePair(const CUnit* unit, size_t piece, Transform& previous, Transform& current) { + if (!NativeRequested() || size_t(unit->id) >= nativeStates.size()) return false; + const auto& state = nativeStates[unit->id]; + if (state.def != unit->unitDef->id || state.creation != unit->creationFrame || state.computedFrame != gs->frameNum || piece >= state.pieces.size()) return false; + const auto& row = state.pieces[piece]; if (!row.initialized || !row.visible) return false; + previous = NativeTransformValue(row.values); current = NativeTransformValue(row.values + 8); return true; +} +static NativeFrameTiming NativeTiming() { + // Bracket the native clock with monotonic HR-time origins. Preserve measured + // uncertainty; do not substitute message receipt time or Date.now(). + const double before = EM_ASM_DOUBLE({ return performance.timeOrigin + performance.now(); }); + const spring_time now = spring_gettime(); + const double after = EM_ASM_DOUBLE({ return performance.timeOrigin + performance.now(); }); + const double epoch = (before + after) * .5; + NativeFrameTiming result{}; result.magic = 0x31544e57; result.bytes = sizeof(result); // WNT1 + result.atEpochMs = epoch; + result.frameStartEpochMs = epoch - double((now - game->lastFrameTime).toMilliSecsf()); + result.lastDrawStartEpochMs = epoch - double((now - globalRendering->lastFrameStart).toMilliSecsf()); + result.simFPS = gu->simFPS; result.averageDrawMs = gu->avgFrameTime; result.previousOffset = globalRendering->timeOffset; + result.lastDrawSimFrame = game->lastSimFrame; result.smoothMode = configHandler->GetInt("SmoothTimeOffset"); + result.flags = (gs->paused ? 1u : 0u) | (game->IsSimLagging() ? 2u : 0u) | (gs->PreSimFrame() ? 4u : 0u) | (videoCapturing->AllowRecord() ? 8u : 0u); + result.captureOffset = videoCapturing->GetTimeOffset(); result.uncertaintyMs = float((after - before) * .5); + return result; +} +static void NativeStep(CUnit* unit, NativeUnitState& state) { + if (state.computedFrame == gs->frameNum) return; + NativeTransformValues(unit->preFrameTra, state.world); + NativeTransformValues(Transform::FromMatrix(unit->GetTransformMatrix(true)), state.world + 8); + for (size_t i = 0; i < unit->localModel.pieces.size(); ++i) { + const auto& piece = unit->localModel.pieces[i]; auto& row = state.pieces[i]; + const auto& current = piece.GetModelSpaceTransform(); // original lazy update + if (!row.initialized || piece.GetWasUpdated()) { + const bool visible = piece.GetScriptVisible(); float values[16]; + NativeTransformValues(visible ? piece.GetEffectivePrevModelSpaceTransform() : Transform::Zero(), values); + NativeTransformValues(visible ? current : Transform::Zero(), values + 8); + if (!row.initialized || row.visible != visible || std::memcmp(row.values, values, sizeof(values)) != 0) { + std::memcpy(row.values, values, sizeof(values)); row.visible = uint16_t(visible); row.dirty = true; row.first = -1; + } + row.initialized = true; + if (piece.GetWasUpdated()) piece.ResetWasUpdated(); // original visual lifecycle + } + } + state.computedFrame = gs->frameNum; +} +static bool WriteNative(const std::vector& units, int32_t slotSeq) { + static int previousFrame=INT32_MIN,previousTeam=INT32_MIN,previousAlly=INT32_MIN;static bool previousFull=false; + if(gs->frameNummyTeam!=previousTeam || gu->myAllyTeam!=previousAlly || gu->spectatingFullView!=previousFull)nativeStates.clear(); + previousFrame=gs->frameNum;previousTeam=gu->myTeam;previousAlly=gu->myAllyTeam;previousFull=gu->spectatingFullView; + const int32_t acknowledged = __atomic_load_n(&header->consumed, __ATOMIC_ACQUIRE); + const int32_t cameraSeq = __atomic_load_n(&header->cameraSeq, __ATOMIC_ACQUIRE); + const uint32_t features = __atomic_load_n(&header->requestedFeatures, __ATOMIC_ACQUIRE) & header->supportedFeatures; + const bool propertiesKnown = (features & FEATURE_NATIVE_PROPERTIES) != 0, coupled = NativeCoupledRequested() && NativeDrawStarted(); + const bool cloakTimingKnown = propertiesKnown && (features & FEATURE_NATIVE_CLOAK_TIMING) != 0; + const bool boundsKnown = (features & FEATURE_BOUNDS) != 0, viewKnown = cameraSeq > 0, reflectionKnown = viewKnown && (features & FEATURE_REFLECTION) != 0; + float view[32], reflection[28]; std::memcpy(view, header->view, sizeof(view)); + if (reflectionKnown) std::memcpy(reflection, header->reflectionView, sizeof(reflection)); + Writer out{block + header->slotOffset[back], SLOT_HEADER_BYTES, capacity}; + const auto timing = NativeTiming(); out.Put(timing);if(coupled)out.Put(nativeDrawStamp); + double withData = 0, records = 0, culled = 0, legacy = 16; uint32_t count = 0; + for (CUnit* unit: units) { + const auto& pieces = unit->localModel.pieces; const uint32_t id = uint32_t(unit->id); const int32_t def = unit->unitDef->id; + legacy += 80 + 72.0 * pieces.size(); + if (id >= nativeStates.size()) nativeStates.resize(std::max(id + 1, unitHandler.MaxUnits())); + auto& state = nativeStates[id]; + if (state.def != def || state.creation != unit->creationFrame || state.pieces.size() != pieces.size()) { + state = NativeUnitState{}; state.def = def; state.creation = unit->creationFrame; state.pieces.resize(pieces.size()); + } + float bounds[4] = {}; uint8_t flags = 0; + const uint32_t kind = unit->unitDef->canfly ? 1u : (unit->unitDef->IsImmobileUnit() ? 2u : 0u); + const uint32_t material = WebbarVisible(unit) && unit->IsCloaked() ? 256u : 0u; + const NativeProperties properties{uint32_t(unit->creationFrame),kind|material,unit->health/std::max(1.f,unit->maxHealth),unit->buildProgress,unit->radius,unit->pos.x,unit->pos.y,unit->pos.z,float(unit->heading)*(3.14159265358979323846f/32768.f),unit->speed.x,unit->speed.z}; + // WBC history stays owner-only. Never expose other teams' transition times. + const int32_t cloakTransition = unit->team == gu->myTeam ? webbarCloakEvents::Frame(unit->id) : 0; + if(propertiesKnown)flags |= FLAG_NATIVE_PROPERTIES; + if (boundsKnown) { + const float3 rel = unit->localModel.GetRelMidPos(), offset = unit->GetObjectSpaceVec(float3(-rel.x, rel.y, rel.z)); + bounds[0]=offset.x;bounds[1]=offset.y;bounds[2]=offset.z;bounds[3]=unit->GetDrawRadius();flags |= FLAG_NATIVE_BOUNDS; + } + bool active = true; + if (viewKnown) { + const float3 center = boundsKnown ? unit->pos + float3(bounds[0],bounds[1],bounds[2]) : float3(unit->midPos); + const float radius = (boundsKnown ? bounds[3] : unit->radius * 1.5f) + std::max(0.0f, view[30]); + for (int k=0;k<24 && active;k+=4) if (view[k]*center.x+view[k+1]*center.y+view[k+2]*center.z+view[k+3] < -radius) active=false; + if (!active && reflectionKnown) { active=true;for(int k=0;k<24 && active;k+=4)if(reflection[k]*center.x+reflection[k+1]*center.y+reflection[k+2]*center.z+reflection[k+3] < -radius)active=false; } + const float dx=center.x-view[24],dy=center.y-view[25],dz=center.z-view[26]; + if (active && view[27]>0 && dx*dx+dy*dy+dz*dz > (view[27]+radius)*(view[27]+radius)) active=false; + } + if (!active) { + flags |= FLAG_CULLED;culled++;for(auto& piece:state.pieces)piece.first=-1; + out.Put(id);out.Put(uint16_t(def));out.Put(uint8_t(unit->team));out.Put(flags);out.Put(uint16_t(pieces.size()));out.Put(uint16_t(0)); + if(propertiesKnown)out.Put(properties);if(cloakTimingKnown)out.Put(cloakTransition);if(boundsKnown)out.Bytes(bounds,sizeof(bounds));count++;continue; + } + if (state.lastActive != slotSeq-1) {flags |= FLAG_RESET;for(auto& piece:state.pieces){piece.dirty=true;piece.first=-1;}} + NativeStep(unit,state);state.lastActive=slotSeq; + uint16_t included=0; + for(auto& piece:state.pieces){if(!piece.dirty)continue;if(piece.first>=0 && acknowledged>=piece.first){piece.dirty=false;continue;}if(piece.first<0)piece.first=slotSeq;included++;} + flags |= FLAG_NATIVE_TRS; + out.Put(id);out.Put(uint16_t(def));out.Put(uint8_t(unit->team));out.Put(flags);out.Put(uint16_t(pieces.size()));out.Put(included); + if(propertiesKnown)out.Put(properties);if(cloakTimingKnown)out.Put(cloakTransition);if(boundsKnown)out.Bytes(bounds,sizeof(bounds));out.Bytes(state.world,sizeof(state.world)); + for(size_t i=0;iframeNum),count,uint32_t(out.at),uint32_t(viewKnown),uint32_t(std::min(legacy,4294967295.0)),FEATURE_NATIVE_TRS|(propertiesKnown?FEATURE_NATIVE_PROPERTIES:0u)|(coupled?FEATURE_NATIVE_COUPLED:0u)|(cloakTimingKnown?FEATURE_NATIVE_CLOAK_TIMING:0u)}; + std::memcpy(out.base,info,sizeof(info));header->stats[0]++;header->stats[1]+=out.at;header->stats[2]+=legacy;header->stats[3]+=withData;header->stats[4]+=records;header->stats[5]+=culled; + publishedCameraSeq=cameraSeq;back=__atomic_exchange_n(&header->middle,back|4,__ATOMIC_ACQ_REL)&3;return true; +} --- a/rts/Game/WebbarNativeBeams.h +++ b/rts/Game/WebbarNativeBeams.h @@ -37,7 +37,8 @@ // WBR2 appends actual projection/FPS/rotation. WBR1 reserves stay zero. float flameCamera[8]={}; float distortionViewport[2]={}; - uint32_t extensionPadding[54]={}; + double nativeAtEpochMs=0;float nativeSimFPS=0;uint32_t nativeReserved=0; + uint32_t extensionPadding[50]={}; }; static_assert(sizeof(WebbarBeamDrawMailbox)==512); static_assert(offsetof(WebbarBeamDrawMailbox,flameCamera)==256); @@ -50,6 +51,7 @@ float planes[24]={},eye[3]={},direction[3]={}; float flameCamera[8]={}; float distortionViewport[2]={}; + double nativeAtEpochMs=0;float nativeSimFPS=0;uint32_t nativeReserved=0; bool flames=false,distortions=false; }; static_assert(offsetof(WebbarBeamDrawRequest,flameCamera)==144); @@ -69,7 +71,13 @@ if(c[0]<=1 || c[0]>=179 || c[1]<=0 || c[1]>100 || c[2]<=0 || c[3]<=c[2] || c[3]>1e9f || c[4]<0 || c[4]>1000) return false; } if(request.distortions) for(float v:request.distortionViewport) if(!std::isfinite(v)||v<1||v>16384||v!=std::floor(v)) return false; - if(request.flags || !std::isfinite(request.fraction) || request.fraction<0 || request.fraction>1) return false; + // Flag1 is an explicit native-clock request, advertised by WBX1 bit8. + // Native CGame offsets can exceed1 (or be negative); original GPU TRS + // interpolation clamps independently, while effects use the raw time. + const bool nativeTiming = (request.flags == 1 || request.flags == 3) && WebbarPoseMailbox::NativeRequested(); + if(request.flags == 3 && !WebbarPoseMailbox::NativeCoupledRequested())return false; + if(nativeTiming){request.nativeAtEpochMs=box.nativeAtEpochMs;request.nativeSimFPS=box.nativeSimFPS;request.nativeReserved=box.nativeReserved;if(!std::isfinite(request.nativeAtEpochMs)||request.nativeAtEpochMs<=0||!std::isfinite(request.nativeSimFPS)||request.nativeSimFPS<0||request.nativeReserved)return false;} + if ((request.flags != 0 && !nativeTiming) || !std::isfinite(request.fraction) || (!nativeTiming && (request.fraction < 0 || request.fraction > 1))) return false; for(float value:request.reserved) if(value!=0) return false; for(float value:request.planes) if(!std::isfinite(value)) return false; for(float value:request.eye) if(!std::isfinite(value)) return false; @@ -355,6 +363,20 @@ if(!webbarNativeBeams) return; WebbarBeamDrawRequest request;int32_t sequence; if(!ReadWebbarBeamDrawRequest(request,sequence)) return; + if(request.flags & 1u){ + const double now=WebbarPoseMailbox::NativeEpochNow(); + // Same interpolation gate as CGame::UpdateUnsynced. Transport delay + // must not advance a paused/lagging/preSim/capture draw. + double offset=videoCapturing->GetTimeOffset(); + if(!gs->paused && !game->IsSimLagging() && !gs->PreSimFrame() && !videoCapturing->AllowRecord()) + offset=double(request.fraction)+(now-request.nativeAtEpochMs)*double(request.nativeSimFPS)*.001+double(int64_t(request.frame)-int64_t(gs->frameNum)); + if(!std::isfinite(offset)||!std::isfinite(float(offset)))return; + request.fraction=float(offset);request.frame=uint32_t(gs->frameNum); + if(request.flags & 2u){ + WebbarPoseMailbox::SetNativeDrawStamp(uint32_t(sequence),request.fraction,now); + PublishWebbarPoses(); // same original visual endpoints as the attached effects below + } + } webbarNativeBeams->Publish(request,sequence); if(request.distortions) PublishWebbarNativeDistortion(request,sequence); __atomic_store_n(&webbarBeamDrawMailbox.acknowledged,sequence,__ATOMIC_RELEASE);