Fix collision not refreshing on expired predictions and slight placement issue

This commit is contained in:
Kae 2023-08-19 22:49:05 +10:00
parent 3805db7722
commit 572b492b93
2 changed files with 11 additions and 3 deletions

View File

@ -1072,13 +1072,18 @@ void WorldClient::update(float dt) {
float expireTime = min((float)m_latency + 100, 2000.f); float expireTime = min((float)m_latency + 100, 2000.f);
auto now = Time::monotonicMilliseconds(); auto now = Time::monotonicMilliseconds();
eraseWhere(m_predictedTiles, [now, expireTime](auto& pair) { eraseWhere(m_predictedTiles, [&](auto& pair) {
float expiry = (float)(now - pair.second.time) / expireTime; float expiry = (float)(now - pair.second.time) / expireTime;
auto center = Vec2F(pair.first) + Vec2F::filled(0.5f); auto center = Vec2F(pair.first) + Vec2F::filled(0.5f);
auto size = Vec2F::filled(0.875f - expiry * 0.875f); auto size = Vec2F::filled(0.875f - expiry * 0.875f);
auto poly = PolyF(RectF::withCenter(center, size)); auto poly = PolyF(RectF::withCenter(center, size));
SpatialLogger::logPoly("world", poly, Color::Cyan.mix(Color::Red, expiry).toRgba()); 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. // Secret broadcasts are transmitted through DamageNotifications for vanilla server compatibility.

View File

@ -119,7 +119,7 @@ List<Drawable> MaterialItem::nonRotatedDrawables() const {
} }
void MaterialItem::fire(FireMode mode, bool shifting, bool edgeTriggered) { void MaterialItem::fire(FireMode mode, bool shifting, bool edgeTriggered) {
if (!initialized() || !ready() || !owner()->inToolRange()) if (!initialized() || !ready())
return; return;
auto layer = (mode == FireMode::Primary || !twoHanded() ? TileLayer::Foreground : TileLayer::Background); 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; size_t total = 0;
for (int i = 0; i != steps; ++i) { for (int i = 0; i != steps; ++i) {
auto placementOrigin = aimPosition + diff * (1.0f - ((float)i / steps)); auto placementOrigin = aimPosition + diff * (1.0f - ((float)i / steps));
if (!owner()->inToolRange(placementOrigin))
continue;
for (Vec2I& pos : tileArea(radius, placementOrigin)) for (Vec2I& pos : tileArea(radius, placementOrigin))
modifications.emplaceAppend(pos, PlaceMaterial{layer, materialId(), placementHueShift(pos), m_collisionOverride}); modifications.emplaceAppend(pos, PlaceMaterial{layer, materialId(), placementHueShift(pos), m_collisionOverride});