mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-04 04:23:55 -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
43
cockatrice/src/game/arrow_registry.h
Normal file
43
cockatrice/src/game/arrow_registry.h
Normal file
|
|
@ -0,0 +1,43 @@
|
|||
#ifndef COCKATRICE_ARROW_REGISTRY_H
|
||||
#define COCKATRICE_ARROW_REGISTRY_H
|
||||
|
||||
#include "board/arrow_data.h"
|
||||
|
||||
#include <QMap>
|
||||
#include <QSet>
|
||||
#include <QSharedPointer>
|
||||
|
||||
class ArrowItem;
|
||||
|
||||
struct ArrowKey
|
||||
{
|
||||
int creatorId;
|
||||
int arrowId;
|
||||
|
||||
bool operator<(const ArrowKey &other) const
|
||||
{
|
||||
if (creatorId != other.creatorId) {
|
||||
return creatorId < other.creatorId;
|
||||
}
|
||||
return arrowId < other.arrowId;
|
||||
}
|
||||
};
|
||||
|
||||
class ArrowRegistry
|
||||
{
|
||||
public:
|
||||
void insert(QSharedPointer<ArrowData> data, ArrowItem *arrow);
|
||||
ArrowItem *take(int creatorId, int arrowId);
|
||||
|
||||
[[nodiscard]] ArrowItem *get(int creatorId, int arrowId) const;
|
||||
[[nodiscard]] bool contains(int creatorId, int arrowId) const;
|
||||
[[nodiscard]] QSet<int> idsForPlayer(int playerId) const;
|
||||
[[nodiscard]] QList<ArrowItem *> all() const;
|
||||
|
||||
private:
|
||||
QMap<ArrowKey, QSharedPointer<ArrowData>> dataStore;
|
||||
QMap<ArrowKey, ArrowItem *> items;
|
||||
QMap<int, QSet<int>> byPlayer;
|
||||
};
|
||||
|
||||
#endif
|
||||
Loading…
Add table
Add a link
Reference in a new issue