diff options
author | Paul Duncan <pabs@pablotron.org> | 2019-01-07 22:05:19 -0500 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2019-01-07 22:05:19 -0500 |
commit | c31caa18f969199a3fb91995ae08b29368cf010d (patch) | |
tree | ce48c67b8394db3e9d5c6077ea06f5244785940f /src/sok.h | |
parent | ad4c3bf0154aae2adedd4ecf7239e30e2d5f9e1c (diff) | |
download | sok-c31caa18f969199a3fb91995ae08b29368cf010d.tar.bz2 sok-c31caa18f969199a3fb91995ae08b29368cf010d.zip |
reorganize src/, add support for RLE
Diffstat (limited to 'src/sok.h')
-rw-r--r-- | src/sok.h | 181 |
1 files changed, 0 insertions, 181 deletions
diff --git a/src/sok.h b/src/sok.h deleted file mode 100644 index 7635ead..0000000 --- a/src/sok.h +++ /dev/null @@ -1,181 +0,0 @@ -#ifndef SOK_H -#define SOK_H - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#include <stdint.h> // uint16_t - -/*********/ -/* types */ -/*********/ - -typedef struct { - uint16_t x, y; -} sok_pos_t; - -typedef enum { - SOK_DIR_RIGHT, - SOK_DIR_UP, - SOK_DIR_LEFT, - SOK_DIR_DOWN, - SOK_DIR_LAST, -} sok_dir_t; - -typedef struct { - sok_pos_t pos; - sok_dir_t dir; - _Bool is_push; -} sok_move_t; - -/****************/ -/* level parser */ -/****************/ - -typedef struct sok_level_parser_t_ sok_level_parser_t; - -typedef bool (*sok_level_parser_pos_cb_t)( - const sok_level_parser_t * const, - const sok_pos_t -); - -typedef bool (*sok_level_parser_junk_cb_t)( - const sok_level_parser_t * const, - const size_t, - const char -); - -typedef struct { - sok_level_parser_pos_cb_t on_size, - on_home, - on_wall, - on_goal, - on_box; - sok_level_parser_junk_cb_t on_junk; -} sok_level_parser_cbs_t; - -struct sok_level_parser_t_ { - const sok_level_parser_cbs_t *cbs; - void *user_data; -}; - -void sok_level_parser_init( - sok_level_parser_t * const parser, - const sok_level_parser_cbs_t * const cbs, - void * const user_data -); - -bool sok_level_parser_parse( - sok_level_parser_t * const parser, - const char * const buf, - const size_t buf_len -); - -/*********/ -/* level */ -/*********/ - -#define SOK_LEVEL_MAX_WIDTH (1 << 8) -#define SOK_LEVEL_MAX_HEIGHT (1 << 8) -#define SOK_LEVEL_MAX_BOXES 64 -#define SOK_LEVEL_MAX_GOALS 64 - -typedef struct { - sok_pos_t size; - _Bool walls[SOK_LEVEL_MAX_WIDTH * SOK_LEVEL_MAX_HEIGHT]; - - // player home position - sok_pos_t home; - - // boxes - sok_pos_t boxes[SOK_LEVEL_MAX_BOXES]; - size_t num_boxes; - - // goals - sok_pos_t goals[SOK_LEVEL_MAX_GOALS]; - size_t num_goals; -} sok_level_t; - -/***********/ -/* context */ -/***********/ - -#define SOK_CTX_MAX_MOVES 1024 - -typedef struct { - sok_level_t level; - - sok_move_t moves[SOK_CTX_MAX_MOVES]; - size_t num_moves; - - // player position - sok_pos_t home; - - // box positions - sok_pos_t boxes[SOK_LEVEL_MAX_BOXES]; - - // user data - void *user_data; -} sok_ctx_t; - -void sok_ctx_init(sok_ctx_t * const ctx, void *user_data); - -_Bool sok_ctx_set_level(sok_ctx_t * const ctx, const char * const level); - -_Bool sok_ctx_is_done(sok_ctx_t * const); - -_Bool sok_ctx_move(sok_ctx_t * const, const sok_dir_t); -_Bool sok_ctx_undo(sok_ctx_t * const); - -/******************/ -/* context walker */ -/******************/ - -typedef _Bool (*sok_ctx_walk_pos_cb_t)( - const sok_ctx_t * const, - const sok_pos_t, - void * const -); - -typedef _Bool (*sok_ctx_walk_tile_cb_t)( - const sok_ctx_t * const, - const sok_pos_t, - const _Bool, - void * const -); - -typedef _Bool (*sok_ctx_walk_goal_cb_t)( - const sok_ctx_t * const, - const sok_pos_t, - const _Bool has_player, - const _Bool has_box, - void * const -); - -typedef _Bool (*sok_ctx_walk_move_cb_t)( - const sok_ctx_t * const, - const sok_move_t, - void * const -); - -typedef struct { - sok_ctx_walk_pos_cb_t on_size, - on_wall; - sok_ctx_walk_tile_cb_t on_home, - on_box; - sok_ctx_walk_goal_cb_t on_goal; - sok_ctx_walk_move_cb_t on_move; -} sok_ctx_walk_cbs_t; - -_Bool sok_ctx_walk( - const sok_ctx_t * const, - const sok_ctx_walk_cbs_t * const, - void * const -); - -#ifdef __cplusplus -}; -#endif /* __cplusplus */ - -#endif /* SOK_H */ |