dsekai
World engine for retrocomputers.
Loading...
Searching...
No Matches
engines.h
Go to the documentation of this file.
1
2#ifndef ENGINES_H
3#define ENGINES_H
4
16#define MINIMAP_X (SCREEN_W - TILEMAP_TW - 10)
17#define MINIMAP_Y (10)
18
32#define DSEKAI_TRANSITION_MASK_FRAME 0x0f
33
41#define DSEKAI_TRANSITION_MASK_TYPE 0x70
42
47#define DSEKAI_TRANSITION_DIR_OPEN 0x80
48
49#define DSEKAI_TRANSITION_TYPE_CURTAIN 0x00
50#define DSEKAI_TRANSITION_TYPE_ZOOM 0x10
51 /* dsekai_engines_transitions */
53
54#if defined( DEPTH_VGA )
55# define DSEKAI_TITLE_TEXT_COLOR GRAPHICS_COLOR_DARKRED
56#elif defined( DEPTH_CGA )
57# define DSEKAI_TITLE_TEXT_COLOR GRAPHICS_COLOR_MAGENTA
58#else
59# define DSEKAI_TITLE_TEXT_COLOR GRAPHICS_COLOR_WHITE
60#endif /* DEPTH_VGA || DEPTH_CGA */
61
62#ifndef ENGINES_TOKENS_ONLY
63
75typedef void (*title_option_cb)( struct DSEKAI_STATE* state );
76
81 RES_CONST char** option_tokens;
82 title_option_cb* option_callbacks;
84 uint8_t option_idx;
85 uint8_t option_min;
86 uint8_t option_max;
87};
88
106};
107
108#ifndef NO_ENGINE_POV
109
114struct POV_STATE {
115 uint8_t dirty;
116 uint8_t minimap[TILEMAP_TH * TILEMAP_TW];
117 uint16_t inc;
118};
119
120#endif /* !NO_ENGINE_POV */
121
122#ifndef NO_ENGINE_EDITOR
123
133#define EDITOR_FLAG_ACTIVE 0x01
134
142#define EDITOR_FLAG_FORCE_FRAME 0x02
143
152 uint8_t flags;
153};
154 /* dsekai_engines_specific_struct */
156
157#endif /* !NO_ENGINE_EDITOR */
158
163#define DSEKAI_FLAG_INPUT_BLOCKED 0x01
164
165#define DSEKAI_FLAG_MENU_BLOCKED 0x02
166
172#define DSEKAI_FLAG_BLANK_FRAME 0x04
173
174#define DSEKAI_FLAG_UNLOCKED 0x08
175
181#define ENGINE_STATE_OPENING 1
182
187#define ENGINE_STATE_RUNNING 2
188
197 uint8_t version;
198
210
214 struct ITEM* items;
215
216 int16_t items_sz;
217
222
230
234 uint8_t engine_type;
235
242
256
261
262 uint16_t mobiles_sz;
263
270
275
282
289 uint16_t ani_sprite_x;
290
302 uint8_t warp_to_x;
308 uint8_t warp_to_y;
309
311 uint16_t engine_state;
312
314 uint8_t flags;
315
325 uint8_t transition;
326
333 RESOURCE_NAME player_sprite_name;
334
342
347
348 int16_t crops_sz;
349
350#ifndef NO_ENGINE_EDITOR
351
352 struct EDITOR_STATE editor;
353
354#endif /* !NO_ENGINE_EDITOR */
355
356 struct MENU_STATE menu;
357};
358
363
368int16_t engines_warp_loop( MEMORY_HANDLE state_handle );
369
374void engines_animate_mobiles( struct DSEKAI_STATE* state );
375
381#ifdef PLATFORM_WASM
382void engines_loop_iter( void* state_handle );
383#else
384int16_t engines_loop_iter( MEMORY_HANDLE state_handle );
385#endif /* PLATFORM_WASM */
386
394 struct MOBILE* mover, int8_t dir_move, struct DSEKAI_STATE* state );
395
396#ifndef NO_TITLE
397
398void engines_exit_to_title( struct DSEKAI_STATE* state );
399
400#endif /* !NO_TITLE */
401
402void engines_set_transition(
403 struct DSEKAI_STATE* state, uint8_t trans_type, uint8_t trans_open );
404
405void engines_draw_transition( struct DSEKAI_STATE* state );
406
412uint8_t engines_state_lock( struct DSEKAI_STATE* state );
413
414uint8_t engines_state_unlock( struct DSEKAI_STATE* state );
415
418#endif /* !ENGINES_TOKENS_ONLY */
419
426#ifndef NO_ENGINE_POV
427
428#define ENGINE_TABLE( f ) f( 0, NONE, title ) f( 1, TOPDOWN, topdown ) f( 2, POV, pov )
429
430#else
431
435#define ENGINE_TABLE( f ) f( 0, NONE, title ) f( 1, TOPDOWN, topdown )
436
437#endif /* ENGINE_POV */
438
439#ifndef ENGINES_TOKENS_ONLY
440
441/* \brief Pause scripts if modal window is pending, screen is scrolling, menu
442 * is open, etc.
443 */
444#define engines_active( state ) (0 == window_modal() && DSEKAI_FLAG_INPUT_BLOCKED != (DSEKAI_FLAG_INPUT_BLOCKED & (state)->flags) && 0 > (state)->menu.menu_id)
445
451typedef int16_t (*ENGINES_SETUP)( struct DSEKAI_STATE* state );
452
459typedef int16_t (*ENGINES_INPUT)(
460 INPUT_VAL in_char, int16_t click_x, int16_t click_y,
461 struct DSEKAI_STATE* state );
462
467typedef void (*ENGINES_ANIMATE)( struct DSEKAI_STATE* state );
468
473typedef void (*ENGINES_DRAW)( struct DSEKAI_STATE* state );
474
475#define ENGINES_SETUP_PROTOTYPES( idx, eng, prefix ) int16_t prefix ## _setup( struct DSEKAI_STATE* state ) SECTION_SETUP;
476
477ENGINE_TABLE( ENGINES_SETUP_PROTOTYPES )
478
479#define ENGINES_INPUT_PROTOTYPES( idx, eng, prefix ) int16_t prefix ## _input( INPUT_VAL in_char, int16_t click_x, int16_t click_y, struct DSEKAI_STATE* state );
480
481ENGINE_TABLE( ENGINES_INPUT_PROTOTYPES )
482
483#define ENGINES_ANIMATE_PROTOTYPES( idx, eng, prefix ) void prefix ## _animate( struct DSEKAI_STATE* state );
484
485ENGINE_TABLE( ENGINES_ANIMATE_PROTOTYPES )
486
487#define ENGINES_DRAW_PROTOTYPES( idx, eng, prefix ) void prefix ## _draw( struct DSEKAI_STATE* state );
488
489ENGINE_TABLE( ENGINES_DRAW_PROTOTYPES )
490
491#define ENGINES_SHUTDOWN_PROTOTYPES( idx, eng, prefix ) void prefix ## _shutdown( struct DSEKAI_STATE* state ) SECTION_SETUP;
492
493ENGINE_TABLE( ENGINES_SHUTDOWN_PROTOTYPES )
494
495#endif /* !ENGINES_TOKENS_ONLY */
496
497#ifdef ENGINES_C
498
499#define ENGINES_LIST_TOKENS( idx, eng, prefix ) #prefix,
500
501RES_CONST char* gc_engines_tokens[] = {
502 ENGINE_TABLE( ENGINES_LIST_TOKENS )
503 NULL
504};
505
506#ifndef ENGINES_TOKENS_ONLY
507
508#define ENGINES_LIST_SETUP( idx, eng, prefix ) prefix ## _setup,
509
510RES_CONST ENGINES_SETUP gc_engines_setup[] = {
511 ENGINE_TABLE( ENGINES_LIST_SETUP )
512};
513
514#define ENGINES_LIST_INPUT( idx, eng, prefix ) prefix ## _input,
515
516RES_CONST ENGINES_INPUT gc_engines_input[] = {
517 ENGINE_TABLE( ENGINES_LIST_INPUT )
518};
519
520#define ENGINES_LIST_ANIMATE( idx, eng, prefix ) prefix ## _animate,
521
522RES_CONST ENGINES_ANIMATE gc_engines_animate[] = {
523 ENGINE_TABLE( ENGINES_LIST_ANIMATE )
524};
525
526#define ENGINES_LIST_DRAW( idx, eng, prefix ) prefix ## _draw,
527
528RES_CONST ENGINES_DRAW gc_engines_draw[] = {
529 ENGINE_TABLE( ENGINES_LIST_DRAW )
530};
531
532#define ENGINES_LIST_SHUTDOWN( idx, eng, prefix ) prefix ## _shutdown,
533
534RES_CONST ENGINES_DRAW gc_engines_shutdown[] = {
535 ENGINE_TABLE( ENGINES_LIST_SHUTDOWN )
536};
537
538#endif /* !ENGINES_TOKENS_ONLY */
539
540#else
541
542extern RES_CONST char* gc_engines_tokens[];
543
544#ifndef ENGINES_TOKENS_ONLY
545
546extern RES_CONST ENGINES_SETUP gc_engines_setup[];
547extern RES_CONST ENGINES_INPUT gc_engines_input[];
548extern RES_CONST ENGINES_ANIMATE gc_engines_animate[];
549extern RES_CONST ENGINES_DRAW gc_engines_draw[];
550
551#endif /* !ENGINES_TOKENS_ONLY */
552
553#endif /* ENGINES_C */
554 /* dsekai_engines_types_sect */
556
559#endif /* ENGINES_H */
560
void(* ENGINES_ANIMATE)(struct DSEKAI_STATE *state)
Cycles animations and executes scripts relevant to the current engine.
Definition: engines.h:467
int16_t(* ENGINES_INPUT)(INPUT_VAL in_char, int16_t click_x, int16_t click_y, struct DSEKAI_STATE *state)
Handles polled input according to the rules of the current engine.
Definition: engines.h:459
int16_t(* ENGINES_SETUP)(struct DSEKAI_STATE *state)
Sets up the current engine (allocates specific state, etc).
Definition: engines.h:451
void(* ENGINES_DRAW)(struct DSEKAI_STATE *state)
Draws the engine sceen on-screen according to current state.
Definition: engines.h:473
void engines_animate_mobiles(struct DSEKAI_STATE *state)
Do generic mobile animation and execute their scripts.
Definition: engines.c:194
int16_t engines_warp_loop(MEMORY_HANDLE state_handle)
Handle transition to a new TILEMAP.
Definition: engines.c:23
int16_t engines_loop_iter(MEMORY_HANDLE state_handle)
Central loop iteration handler. Calls engine-specific callbacks.
Definition: engines.c:269
int8_t engines_input_movement(struct MOBILE *mover, int8_t dir_move, struct DSEKAI_STATE *state)
Handle generic player movement commmand.
Definition: engines.c:229
void engines_draw_loading_screen()
Draw a simple loading screen.
Definition: engines.c:11
#define TILEMAP_NAME_MAX
Maximum size of TILEMAP::name.
Definition: src/config.h:254
#define TILEMAP_TH
Maximum TILEMAP height in tiles.
Definition: tmstruct.h:22
#define TILEMAP_TW
Maximum TILEMAP width in tiles.
Definition: tmstruct.h:20
Definition: crop.h:58
General/shared state of the running engine in memory.
Definition: engines.h:196
uint16_t ani_sprite_x
The horizontal offset of all on-screen MOBILE sprites on their spritesheets in pixels.
Definition: engines.h:289
MEMORY_HANDLE map_handle
Currently loaded TILEMAP.
Definition: engines.h:221
struct ITEM * items
Temporary pointer for use during Engine Locking.
Definition: engines.h:214
char warp_to[TILEMAP_NAME_MAX]
When holding a valid string, triggers the map change process.
Definition: engines.h:296
MEMORY_HANDLE items_handle
Array consisting of all items in the current game world.
Definition: engines.h:209
MEMORY_HANDLE engine_state_handle
Contains the currently loaded Engine-Specific Struct.
Definition: engines.h:274
MEMORY_HANDLE mobiles_handle
Array of currently loaded MOBILE objects on this map.
Definition: engines.h:255
struct TILEMAP * tilemap
Temporary pointer for use during Engine Locking.
Definition: engines.h:229
uint8_t warp_to_x
Sets the player MOBILE::coords horizontal on map change.
Definition: engines.h:302
RESOURCE_NAME player_sprite_name
Resource ID for the player sprite.
Definition: engines.h:333
struct MOBILE * mobiles
Temporary pointer for use during Engine Locking.
Definition: engines.h:260
uint8_t engine_type
Engine type tilemap is supposed to be used with.
Definition: engines.h:234
uint8_t engine_type_change
Engine type set to be changed to with engines_warp_loop().
Definition: engines.h:241
uint16_t engine_state
Current engine state (see below in struct reference).
Definition: engines.h:311
struct CROP_PLOT * crops
Temporary pointer for use during Engine Locking.
Definition: engines.h:346
uint8_t flags
Global boolean values dictating engine state and behavior.
Definition: engines.h:314
uint8_t warp_to_y
Sets the player MOBILE::coords vertical on map change.
Definition: engines.h:308
struct MOBILE player
Currently active player MOBILE. Stays between maps.
Definition: engines.h:269
uint8_t ani_sprite_countdown
The number of loops until DSEKAI_STATE::ani_sprite_countdown changes.
Definition: engines.h:281
MEMORY_HANDLE crops_handle
Array of all crops growing on all maps.
Definition: engines.h:341
uint8_t transition
The current frame of the playing Engine Transitions.
Definition: engines.h:325
Definition: engines.h:144
uint8_t selected_tile
Definition: engines.h:150
uint8_t current_tile
Definition: engines.h:148
struct TILEMAP_COORDS coords
Tile coordinates currently being edited.
Definition: engines.h:146
uint8_t flags
Bitfield controlling behavior and flow of editor.
Definition: engines.h:152
An emulated memory handle for modern systems. Overridden on most platforms.
Definition: memory.h:20
An instance of an item in the world.
Definition: itstruct.h:91
Definition: menu.h:73
A moving/interactive object in the world.
Definition: mobile.h:248
State for ::ENGINE_TYPE_POV. Displays a first-person 3D view of the world using raycasting.
Definition: engines.h:114
X/Y coordinates of a tile on the current map.
Definition: tmstruct.h:33
Information pertaining to in-game world currently loaded.
Definition: tmstruct.h:87
State for ::ENGINE_TYPE_NONE. A simple title screen engine.
Definition: engines.h:80
uint8_t option_idx
Index of the currently highlighted option.
Definition: engines.h:84
State for ::ENGINE_TYPE_TOPDOWN. Displays a top-down 2-dimensional view of the world.
Definition: engines.h:93
int16_t screen_scroll_y
Top vertical offset of the current viewport in pixels.
Definition: engines.h:97
int16_t screen_scroll_x_tgt
Horizontal offset the viewport is scrolling to in pixels.
Definition: engines.h:103
int16_t screen_scroll_y_tgt
Vertical offset the viewport is scrolling to in pixels.
Definition: engines.h:105
int16_t screen_scroll_x
Left horizontal offset of the current viewport in pixels.
Definition: engines.h:95
int16_t screen_scroll_tx
Left horizontal offset of the current viewport in tiles.
Definition: engines.h:99
int16_t screen_scroll_ty
Top vertical offset of the current viewport in tiles.
Definition: engines.h:101