Dawn/src/card/poker/action/action.c

50 lines
1.3 KiB
C

/**
* Copyright (c) 2021 Dominic Masters
*
* This software is released under the MIT License.
* https://opensource.org/licenses/MIT
*/
#include "action.h"
void holdemActionInit() {
// Free up all actions
memset(HOLDEM_GAME_STATE.actionQueue, (int32_t)NULL,
sizeof(holdemaction_t) * HOLDEM_GAME_ACTION_QUEUE_SIZE
);
// Free up all data
memset(HOLDEM_GAME_STATE.actionData, (int32_t)NULL, sizeof(void *) *
HOLDEM_GAME_ACTION_DATA_SIZE * HOLDEM_GAME_ACTION_QUEUE_SIZE
);
}
void holdemActionAdd(holdemaction_t action) {
int32_t i = -1;
int32_t j = -1;
for(i = 0; i < HOLDEM_GAME_ACTION_QUEUE_SIZE; i++) {
if(HOLDEM_GAME_STATE.actionQueue[i].init != NULL) continue;
j = i;
break;
}
HOLDEM_GAME_STATE.actionQueue[j] = action;
action.init(j, HOLDEM_GAME_STATE.actionData + j);
}
void holdemActionUpdate() {
int32_t i;
for(i = 0; i < HOLDEM_GAME_ACTION_QUEUE_SIZE; i++) {
if(HOLDEM_GAME_STATE.actionQueue[i].update == NULL) continue;
HOLDEM_GAME_STATE.actionQueue[i].update(i, HOLDEM_GAME_STATE.actionData+i);
}
}
void holdemActionDispose() {
int32_t i;
for(i = 0; i < HOLDEM_GAME_ACTION_QUEUE_SIZE; i++) {
if(HOLDEM_GAME_STATE.actionQueue[i].dispose == NULL) continue;
HOLDEM_GAME_STATE.actionQueue[i].dispose(i, HOLDEM_GAME_STATE.actionData+i);
}
}