#include #include "common.h" #include "snapshot.h" int dp_snapshot_put_player(struct snapshot *s, uint32_t id, const struct player *p) { if (!s || !p) return -1; if (id >= LENGTH(s->players)) return -1; s->players[id] = *p; s->players[id].state = STATE_ACTIVE; return 0; } struct player *dp_snapshot_get_player(struct snapshot *s, uint32_t id) { struct player *p; if (!s) return NULL; if (id >= LENGTH(s->players)) return NULL; p = &s->players[id]; if (p->state == STATE_INACTIVE) return NULL; return p; } int dp_snapshot_remove_player(struct snapshot *s, uint32_t id) { struct player *p; if (!s) return -1; if (id >= LENGTH(s->players)) return -1; p = dp_snapshot_get_player(s, id); memset(p, 0, sizeof(*p)); p->state = STATE_REMOVED; return 0; } int dp_snapshot_set_player_input(struct snapshot *s, uint32_t id, uint8_t input) { struct player *p; if (!(p = dp_snapshot_get_player(s, id))) return -1; p->input = input; return 0; } int dp_snapshot_put_ball(struct snapshot *s, uint32_t id, const struct ball *b) { if (!s || !b) return -1; if (id >= LENGTH(s->balls)) return -1; s->balls[id] = *b; s->balls[id].state = STATE_ACTIVE; return 0; } struct ball *dp_snapshot_get_ball(struct snapshot *s, uint32_t id) { struct ball *b; if (!s) return NULL; if (id >= LENGTH(s->balls)) return NULL; b = &s->balls[id]; if (b->state == STATE_INACTIVE) return NULL; return b; } int dp_snapshot_remove_ball(struct snapshot *s, uint32_t id) { struct ball *b; if (!s) return -1; if (id >= LENGTH(s->balls)) return -1; b = dp_snapshot_get_ball(s, id); memset(b, 0, sizeof(*b)); b->state = STATE_REMOVED; return 0; }