Software Design Specification for Suika2
Author | ktabata |
Modified By | |
Organization | |
Updated | 10th October 2023 |
Created | 29th October 2022 |
Revision | 14.6.0 |
Table of Contents
This document outlines the software design specification (SDS) for Suika2 in English. It is intended to help programmers understand Suika2's high-level design and get started quickly.
Suika2 consists of the following components:
+---------------+ | cmd_*.c (PIL) | +---------------+ | main.c (PIL) | +---------------+ | event.c (PIL) | +---------------+ | HAL | +---------------+ | OS API | +---------------+
We don't use C++ classes to wrap OS API because:
A HAL is a component implemented on a per-platform basis.
Currently, the project has six HALs.
The HALs consist of the following modules:
A HAL must provide the following functionalities:
The PIL provides the following functionalities:
A HAL runs a main loop. In a main loop, a HAL dispatches UI events to the functions implemented in "event.c". The following functions are for event handling and are implemented in "event.c"
bool on_event_init(void); void on_event_cleanup(void); bool on_event_frame(int *x, int *y, int *w, int *h); void on_event_key_press(int key); void on_event_key_release(int key); void on_event_mouse_press(int button, int x, int y); void on_event_mouse_release(int button, int x, int y); void on_event_mouse_move(int x, int y); void on_event_mouse_scroll(int n);
"on_event_frame()" function is called every frame. In this function, the program calls "game_loop_iter()" function that is implemented in "main.c".
"game_loop_iter()" calls "dispatch_command()". In "dispatch_command()", each command implementation such as "message_command()" is called.
The command implementation functions are implemented in "cmd_*.c" files.
A command implementation function is called every frames while the command is executed. A function, "is_in_command_repetition()", is provided to distinguish between the first frame and the frames that will be executed repeatedly after that.
When a command quits, the command implementation function just calls "move_to_next_command()".