Tile Prediction: make refunds silent
This commit is contained in:
parent
caf7abebfe
commit
3534067801
@ -1153,20 +1153,23 @@ uint64_t Player::itemsCanHold(ItemPtr const& items) const {
|
|||||||
return m_inventory->itemsCanFit(items);
|
return m_inventory->itemsCanFit(items);
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemPtr Player::pickupItems(ItemPtr const& items) {
|
ItemPtr Player::pickupItems(ItemPtr const& items, bool silent) {
|
||||||
if (isDead() || !items || m_inventory->itemsCanFit(items) == 0)
|
if (isDead() || !items || m_inventory->itemsCanFit(items) == 0)
|
||||||
return items;
|
return items;
|
||||||
|
|
||||||
triggerPickupEvents(items);
|
triggerPickupEvents(items);
|
||||||
|
|
||||||
if (items->pickupSound().size()) {
|
if (!silent) {
|
||||||
m_effectsAnimator->setSoundPool("pickup", {items->pickupSound()});
|
if (items->pickupSound().size()) {
|
||||||
float pitch = 1.f - ((float)items->count() / (float)items->maxStack()) * 0.5f;
|
m_effectsAnimator->setSoundPool("pickup", {items->pickupSound()});
|
||||||
m_effectsAnimator->setSoundPitchMultiplier("pickup", clamp(pitch * Random::randf(0.8f, 1.2f), 0.f, 2.f));
|
float pitch = 1.f - ((float)items->count() / (float)items->maxStack()) * 0.5f;
|
||||||
m_effectsAnimator->playSound("pickup");
|
m_effectsAnimator->setSoundPitchMultiplier("pickup", clamp(pitch * Random::randf(0.8f, 1.2f), 0.f, 2.f));
|
||||||
|
m_effectsAnimator->playSound("pickup");
|
||||||
|
}
|
||||||
|
auto itemDb = Root::singleton().itemDatabase();
|
||||||
|
queueItemPickupMessage(itemDb->itemShared(items->descriptor()));
|
||||||
}
|
}
|
||||||
auto itemDb = Root::singleton().itemDatabase();
|
|
||||||
queueItemPickupMessage(itemDb->itemShared(items->descriptor()));
|
|
||||||
return m_inventory->addItems(items);
|
return m_inventory->addItems(items);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -200,7 +200,7 @@ public:
|
|||||||
uint64_t itemsCanHold(ItemPtr const& items) const;
|
uint64_t itemsCanHold(ItemPtr const& items) const;
|
||||||
// Adds items to the inventory, returning the overflow.
|
// Adds items to the inventory, returning the overflow.
|
||||||
// The items parameter is invalid after use.
|
// The items parameter is invalid after use.
|
||||||
ItemPtr pickupItems(ItemPtr const& items);
|
ItemPtr pickupItems(ItemPtr const& items, bool silent = false);
|
||||||
// Pick up all of the given items as possible, dropping the overflow.
|
// Pick up all of the given items as possible, dropping the overflow.
|
||||||
// The item parameter is invalid after use.
|
// The item parameter is invalid after use.
|
||||||
void giveItem(ItemPtr const& item);
|
void giveItem(ItemPtr const& item);
|
||||||
|
@ -214,6 +214,14 @@ ItemPtr PlayerInventory::addItems(ItemPtr items) {
|
|||||||
if (is<BackArmor>(items) && !backArmor())
|
if (is<BackArmor>(items) && !backArmor())
|
||||||
m_equipment[EquipmentSlot::Back] = items->take(1);
|
m_equipment[EquipmentSlot::Back] = items->take(1);
|
||||||
|
|
||||||
|
if (is<MaterialItem>(items)) {
|
||||||
|
if (auto primary = primaryHeldItem()) {
|
||||||
|
primary->stackWith(items);
|
||||||
|
if (items->empty())
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Then, finally the bags
|
// Then, finally the bags
|
||||||
return addToBags(std::move(items));
|
return addToBags(std::move(items));
|
||||||
}
|
}
|
||||||
|
@ -573,23 +573,28 @@ void WorldClient::render(WorldRenderData& renderData, unsigned bufferTiles) {
|
|||||||
|
|
||||||
renderTile.liquidId = clientTile.liquid.liquid;
|
renderTile.liquidId = clientTile.liquid.liquid;
|
||||||
renderTile.liquidLevel = floatToByte(clientTile.liquid.level);
|
renderTile.liquidLevel = floatToByte(clientTile.liquid.level);
|
||||||
|
});
|
||||||
|
|
||||||
if (!m_predictedTiles.empty()) {
|
for (auto& pair : m_predictedTiles) {
|
||||||
if (auto p = m_predictedTiles.ptr(position)) {
|
Vec2I tileArrayPos = m_geometry.diff(pair.first, renderData.tileMinPosition);
|
||||||
if (p->liquid) {
|
if (tileArrayPos[0] >= 0 && tileArrayPos[0] < (int)renderData.tiles.size(0) && tileArrayPos[1] >= 0 && tileArrayPos[1] < (int)renderData.tiles.size(1)) {
|
||||||
auto& liquid = *p->liquid;
|
RenderTile& renderTile = renderData.tiles(tileArrayPos[0], tileArrayPos[1]);
|
||||||
if (liquid.liquid == renderTile.liquidId)
|
PredictedTile& p = pair.second;
|
||||||
renderTile.liquidLevel = floatToByte(clientTile.liquid.level + liquid.level, true);
|
if (p.liquid) {
|
||||||
else {
|
auto& liquid = *p.liquid;
|
||||||
renderTile.liquidId = liquid.liquid;
|
if (liquid.liquid == renderTile.liquidId) {
|
||||||
renderTile.liquidLevel = floatToByte(liquid.level, true);
|
uint8_t added = floatToByte(liquid.level, true);
|
||||||
}
|
renderTile.liquidLevel = (renderTile.liquidLevel > 255 - added) ? 255 : renderTile.liquidLevel + added;
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
p->apply(renderTile);
|
renderTile.liquidId = liquid.liquid;
|
||||||
|
renderTile.liquidLevel = floatToByte(liquid.level, true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
pair.second.apply(renderTile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for (auto const& previewTile : previewTiles) {
|
for (auto const& previewTile : previewTiles) {
|
||||||
Vec2I tileArrayPos = m_geometry.diff(previewTile.position, renderData.tileMinPosition);
|
Vec2I tileArrayPos = m_geometry.diff(previewTile.position, renderData.tileMinPosition);
|
||||||
@ -896,10 +901,10 @@ void WorldClient::handleIncomingPackets(List<PacketPtr> const& packets) {
|
|||||||
|
|
||||||
if (auto placeMaterial = modification.second.ptr<PlaceMaterial>()) {
|
if (auto placeMaterial = modification.second.ptr<PlaceMaterial>()) {
|
||||||
auto stack = materialDatabase->materialItemDrop(placeMaterial->material);
|
auto stack = materialDatabase->materialItemDrop(placeMaterial->material);
|
||||||
tryGiveMainPlayerItem(itemDatabase->item(stack));
|
tryGiveMainPlayerItem(itemDatabase->item(stack), true);
|
||||||
} else if (auto placeMod = modification.second.ptr<PlaceMod>()) {
|
} else if (auto placeMod = modification.second.ptr<PlaceMod>()) {
|
||||||
auto stack = materialDatabase->modItemDrop(placeMod->mod);
|
auto stack = materialDatabase->modItemDrop(placeMod->mod);
|
||||||
tryGiveMainPlayerItem(itemDatabase->item(stack));
|
tryGiveMainPlayerItem(itemDatabase->item(stack), true);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1799,8 +1804,8 @@ void WorldClient::clearWorld() {
|
|||||||
m_forceRegions.clear();
|
m_forceRegions.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
void WorldClient::tryGiveMainPlayerItem(ItemPtr item) {
|
void WorldClient::tryGiveMainPlayerItem(ItemPtr item, bool silent) {
|
||||||
if (auto spill = m_mainPlayer->pickupItems(item))
|
if (auto spill = m_mainPlayer->pickupItems(item, silent))
|
||||||
addEntity(ItemDrop::createRandomizedDrop(spill->descriptor(), m_mainPlayer->position()));
|
addEntity(ItemDrop::createRandomizedDrop(spill->descriptor(), m_mainPlayer->position()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -213,7 +213,7 @@ private:
|
|||||||
|
|
||||||
void initWorld(WorldStartPacket const& packet);
|
void initWorld(WorldStartPacket const& packet);
|
||||||
void clearWorld();
|
void clearWorld();
|
||||||
void tryGiveMainPlayerItem(ItemPtr item);
|
void tryGiveMainPlayerItem(ItemPtr item, bool silent = false);
|
||||||
|
|
||||||
void notifyEntityCreate(EntityPtr const& entity);
|
void notifyEntityCreate(EntityPtr const& entity);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user