mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-10 08:14:47 -07:00
[Game] [Arrows] Use arrowData/registry and generate unique server-side ids (#6973)
* [Game] [Arrows] Track creatorId, use arrowData in arrowItem, use registry, generate unique arrow id's on server side and delete-on-exist inserts. Took 2 minutes Took 1 minute * Fix emitting slot instead of signal. Took 15 minutes * Clear arrows locally in special circumstances i.e. teardown. Took 28 minutes --------- Co-authored-by: Lukas Brübach <Bruebach.Lukas@bdosecurity.de>
This commit is contained in:
parent
c14a008080
commit
23da49ee5b
19 changed files with 225 additions and 148 deletions
48
cockatrice/src/game/arrow_registry.cpp
Normal file
48
cockatrice/src/game/arrow_registry.cpp
Normal file
|
|
@ -0,0 +1,48 @@
|
|||
#include "arrow_registry.h"
|
||||
|
||||
#include "board/arrow_item.h"
|
||||
|
||||
void ArrowRegistry::insert(QSharedPointer<ArrowData> data, ArrowItem *arrow)
|
||||
{
|
||||
const ArrowKey key{data->creatorId, data->id};
|
||||
|
||||
if (auto *existing = take(data->creatorId, data->id)) {
|
||||
existing->delArrow();
|
||||
}
|
||||
|
||||
dataStore.insert(key, data);
|
||||
items.insert(key, arrow);
|
||||
byPlayer[data->creatorId].insert(data->id);
|
||||
}
|
||||
|
||||
ArrowItem *ArrowRegistry::take(int creatorId, int arrowId)
|
||||
{
|
||||
const ArrowKey key{creatorId, arrowId};
|
||||
dataStore.remove(key);
|
||||
auto &playerSet = byPlayer[creatorId];
|
||||
playerSet.remove(arrowId);
|
||||
if (playerSet.isEmpty()) {
|
||||
byPlayer.remove(creatorId);
|
||||
}
|
||||
return items.take(key);
|
||||
}
|
||||
|
||||
ArrowItem *ArrowRegistry::get(int creatorId, int arrowId) const
|
||||
{
|
||||
return items.value(ArrowKey{creatorId, arrowId}, nullptr);
|
||||
}
|
||||
|
||||
bool ArrowRegistry::contains(int creatorId, int arrowId) const
|
||||
{
|
||||
return items.contains(ArrowKey{creatorId, arrowId});
|
||||
}
|
||||
|
||||
QSet<int> ArrowRegistry::idsForPlayer(int playerId) const
|
||||
{
|
||||
return byPlayer.value(playerId);
|
||||
}
|
||||
|
||||
QList<ArrowItem *> ArrowRegistry::all() const
|
||||
{
|
||||
return items.values();
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue