From 572b492b938f52a0bbc7ef7306c9250bf902727c Mon Sep 17 00:00:00 2001 From: Kae <80987908+Novaenia@users.noreply.github.com> Date: Sat, 19 Aug 2023 22:49:05 +1000 Subject: [PATCH] Fix collision not refreshing on expired predictions and slight placement issue --- source/game/StarWorldClient.cpp | 9 +++++++-- source/game/items/StarMaterialItem.cpp | 5 ++++- 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/source/game/StarWorldClient.cpp b/source/game/StarWorldClient.cpp index 6359a12..b07e488 100644 --- a/source/game/StarWorldClient.cpp +++ b/source/game/StarWorldClient.cpp @@ -1072,13 +1072,18 @@ void WorldClient::update(float dt) { float expireTime = min((float)m_latency + 100, 2000.f); auto now = Time::monotonicMilliseconds(); - eraseWhere(m_predictedTiles, [now, expireTime](auto& pair) { + eraseWhere(m_predictedTiles, [&](auto& pair) { float expiry = (float)(now - pair.second.time) / expireTime; auto center = Vec2F(pair.first) + Vec2F::filled(0.5f); auto size = Vec2F::filled(0.875f - expiry * 0.875f); auto poly = PolyF(RectF::withCenter(center, size)); SpatialLogger::logPoly("world", poly, Color::Cyan.mix(Color::Red, expiry).toRgba()); - return expiry >= 1.0f; + if (expiry >= 1.0f) { + dirtyCollision(RectI::withSize(pair.first, { 1, 1 })); + return true; + } else { + return false; + } }); // Secret broadcasts are transmitted through DamageNotifications for vanilla server compatibility. diff --git a/source/game/items/StarMaterialItem.cpp b/source/game/items/StarMaterialItem.cpp index 183b160..210fcaa 100644 --- a/source/game/items/StarMaterialItem.cpp +++ b/source/game/items/StarMaterialItem.cpp @@ -119,7 +119,7 @@ List MaterialItem::nonRotatedDrawables() const { } void MaterialItem::fire(FireMode mode, bool shifting, bool edgeTriggered) { - if (!initialized() || !ready() || !owner()->inToolRange()) + if (!initialized() || !ready()) return; auto layer = (mode == FireMode::Primary || !twoHanded() ? TileLayer::Foreground : TileLayer::Background); @@ -150,6 +150,9 @@ void MaterialItem::fire(FireMode mode, bool shifting, bool edgeTriggered) { size_t total = 0; for (int i = 0; i != steps; ++i) { auto placementOrigin = aimPosition + diff * (1.0f - ((float)i / steps)); + if (!owner()->inToolRange(placementOrigin)) + continue; + for (Vec2I& pos : tileArea(radius, placementOrigin)) modifications.emplaceAppend(pos, PlaceMaterial{layer, materialId(), placementHueShift(pos), m_collisionOverride});