mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-04-27 07:48:01 -07:00
server has to assign free table space for a new card so that there is no race condition
This commit is contained in:
parent
9f79bd2c8e
commit
62a9003d3e
7 changed files with 69 additions and 62 deletions
|
|
@ -73,6 +73,26 @@ Server_Card *Server_CardZone::getCard(int id, bool remove, int *position)
|
|||
}
|
||||
}
|
||||
|
||||
int Server_CardZone::getFreeGridColumn(int y) const
|
||||
{
|
||||
int x = 0;
|
||||
|
||||
// Stupid algorithm. For large numbers of cards, it would be more
|
||||
// efficient to sort the cards by their x value and only need to iterate once.
|
||||
bool occupied;
|
||||
do {
|
||||
occupied = false;
|
||||
for (int i = 0; i < cards.size(); ++i)
|
||||
if ((cards[i]->getY() == y) && (cards[i]->getX() == x)) {
|
||||
occupied = true;
|
||||
++x;
|
||||
break;
|
||||
}
|
||||
} while (occupied);
|
||||
|
||||
return x;
|
||||
}
|
||||
|
||||
void Server_CardZone::insertCard(Server_Card *card, int x, int y)
|
||||
{
|
||||
if (hasCoords()) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue