Account for latency predicting item drop pickup
This commit is contained in:
parent
b51e174bdc
commit
cd36a269fd
@ -300,10 +300,10 @@ bool ItemDrop::canTake() const {
|
|||||||
return m_mode.get() == Mode::Available && m_owningEntity.get() == NullEntityId && !m_item->empty();
|
return m_mode.get() == Mode::Available && m_owningEntity.get() == NullEntityId && !m_item->empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemPtr ItemDrop::takeBy(EntityId entityId) {
|
ItemPtr ItemDrop::takeBy(EntityId entityId, float timeOffset) {
|
||||||
if (canTake()) {
|
if (canTake()) {
|
||||||
m_owningEntity.set(entityId);
|
m_owningEntity.set(entityId);
|
||||||
m_dropAge.setElapsedTime(0.0);
|
m_dropAge.setElapsedTime(timeOffset);
|
||||||
m_mode.set(Mode::Taken);
|
m_mode.set(Mode::Taken);
|
||||||
setPersistent(false);
|
setPersistent(false);
|
||||||
|
|
||||||
|
@ -70,7 +70,7 @@ public:
|
|||||||
|
|
||||||
// Mark this drop as taken by the given entity. The drop will animate
|
// Mark this drop as taken by the given entity. The drop will animate
|
||||||
// towards them for a while and then disappear.
|
// towards them for a while and then disappear.
|
||||||
ItemPtr takeBy(EntityId entityId);
|
ItemPtr takeBy(EntityId entityId, float timeOffset = 0.0f);
|
||||||
|
|
||||||
// Mark this drop as taken, but do not animate it towards a player simply
|
// Mark this drop as taken, but do not animate it towards a player simply
|
||||||
// disappear next step.
|
// disappear next step.
|
||||||
|
@ -1126,7 +1126,7 @@ void WorldClient::update(float dt) {
|
|||||||
if (itemDrop->canTake() && !m_requestedDrops.contains(itemDrop->entityId()) && distSquared < square(DropDist)) {
|
if (itemDrop->canTake() && !m_requestedDrops.contains(itemDrop->entityId()) && distSquared < square(DropDist)) {
|
||||||
m_requestedDrops.add(itemDrop->entityId());
|
m_requestedDrops.add(itemDrop->entityId());
|
||||||
if (m_mainPlayer->itemsCanHold(itemDrop->item()) != 0) {
|
if (m_mainPlayer->itemsCanHold(itemDrop->item()) != 0) {
|
||||||
itemDrop->takeBy(m_mainPlayer->entityId());
|
itemDrop->takeBy(m_mainPlayer->entityId(), (float)m_latency / 1000);
|
||||||
m_outgoingPackets.append(make_shared<RequestDropPacket>(itemDrop->entityId()));
|
m_outgoingPackets.append(make_shared<RequestDropPacket>(itemDrop->entityId()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user