summaryrefslogtreecommitdiff
path: root/src/libs/grid/grid.h
diff options
context:
space:
mode:
authorVito Caputo <vcaputo@pengaru.com>2018-12-30 16:31:35 -0800
committerVito Caputo <vcaputo@pengaru.com>2018-12-30 16:31:35 -0800
commit2436fde1cfe091db740f15665822e18295a7f8de (patch)
tree88a982ed101fa30015a752f6a51f2907706ece46 /src/libs/grid/grid.h
parent7146b9c2a253c5c51d7935bae8725232ef276cdf (diff)
libs/grid: add grid cellular automata component
Prep for adding a new module displaying a cellular automata based on the grid component from a multiplayer game I'm working on.
Diffstat (limited to 'src/libs/grid/grid.h')
-rw-r--r--src/libs/grid/grid.h55
1 files changed, 55 insertions, 0 deletions
diff --git a/src/libs/grid/grid.h b/src/libs/grid/grid.h
new file mode 100644
index 0000000..e17989f
--- /dev/null
+++ b/src/libs/grid/grid.h
@@ -0,0 +1,55 @@
+/*
+ * Copyright (C) 2018 - Vito Caputo - <vcaputo@pengaru.com>
+ *
+ * This program is free software: you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 3 as published
+ * by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef _GRID_H
+#define _GRID_H
+
+#include <stdint.h>
+
+typedef enum grid_ops_move_result_t {
+ GRID_OPS_MOVE_RESULT_FAIL,
+ GRID_OPS_MOVE_RESULT_SUCCESS,
+ GRID_OPS_MOVE_RESULT_NOOP,
+} grid_ops_move_result_t;
+
+/* hooks to integrate from back-end to front-end */
+typedef struct grid_ops_t {
+ void (*setup)(void *ctx, uint32_t player); /* the specified player number has been assigned to this context */
+ void (*shutdown)(void *ctx); /* the grid has shutdown */
+ void (*joined)(void *ctx, uint32_t player); /* the specified player joined */
+ void (*parted)(void *ctx, uint32_t player); /* the specified player parted */
+ void (*said)(void *ctx, uint32_t player, const char *text); /* the specified player says text */
+ void (*planned)(void *ctx, uint32_t move); /* the specified move has been planned */
+ void (*executed)(void *ctx, uint32_t move, grid_ops_move_result_t result);/* the specified move has been executed, removed from plan */
+ void (*canceled)(void *ctx, uint32_t move); /* the specified move has been canceled, removed from plan */
+ void (*taken)(void *ctx, uint32_t x, uint32_t y, unsigned player); /* the specified cell has been taken by the specified player */
+ void (*won)(void *ctx, uint32_t player); /* the game has been won by the specified player */
+} grid_ops_t;
+
+typedef struct grid_t grid_t;
+typedef struct grid_player_t grid_player_t;
+
+grid_t * grid_new(uint32_t players, uint32_t width, uint32_t height);
+void grid_free(grid_t *grid);
+void grid_tick(grid_t *grid);
+
+grid_player_t * grid_player_new(grid_t *grid, const grid_ops_t *ops, void *ops_ctx);
+void grid_player_free(grid_player_t *player);
+void grid_player_plan(grid_player_t *player, uint32_t move, uint32_t x, uint32_t y);
+void grid_player_cancel(grid_player_t *player, uint32_t move);
+void grid_player_say(grid_player_t *player, const char *text);
+
+#endif
© All Rights Reserved