server has to assign free table space for a new card so that there is no race condition

This commit is contained in:
Max-Wilhelm Bruker 2010-06-18 19:57:06 +02:00
parent 9f79bd2c8e
commit 62a9003d3e
7 changed files with 69 additions and 62 deletions

View file

@ -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()) {