Mirai's Miscellaneous Misadventures

M43 / include / mimimi.h

1/* license: AGPLv3 or later */
2/* copyright 2023 zamfofex */
3
4#ifndef MIMIMI_H
5#define MIMIMI_H
6
7struct mimimi_position
8{
9	int x, y;
10};
11
12struct mimimi_size
13{
14	int width, height;
15};
16
17struct mimimi_image
18{
19	int width, height;
20	unsigned char *colors;
21};
22
23struct mimimi_engine
24{
25	void *data;
26	void *(*texture)(void *data, struct mimimi_image *image);
27	void (*invalidate)(void *data, void *texture);
28	void (*stamp)(void *data, int x, int y, void *texture);
29	struct mimimi_size size;
30};
31
32struct mimimi_physics
33{
34	int dx, dy;
35	unsigned char airborne;
36	int width, height;
37	int gravity;
38};
39
40struct mimimi_collision
41{
42	int count;
43	struct mimimi_position **positions;
44	int strength;
45	int proximity;
46	int height;
47	int tolerance;
48};
49
50struct mimimi_life
51{
52	int knocked_time;
53	int immunity_time;
54	int pristinity;
55	int max_pristinity;
56	int recovery_time;
57};
58
59struct mimimi_fall
60{
61	int max_speed;
62	int knocked_time;
63};
64
65struct mimimi_walk
66{
67	int ground_speed;
68	int airborne_speed;
69	int direction;
70};
71
72struct mimimi_ground
73{
74	int width, height;
75	unsigned char *tiles;
76};
77
78struct mimimi_sprite
79{
80	struct mimimi_position position;
81	struct mimimi_physics physics;
82	struct mimimi_life life;
83	struct mimimi_fall fall;
84	struct mimimi_walk walk;
85	struct mimimi_ground *ground;
86};
87
88struct mimimi_conveyor
89{
90	struct mimimi_sprite *sprite;
91	struct mimimi_ground *ground;
92	unsigned char was_airborne;
93	int speed;
94};
95
96struct mimimi_positioned_physics
97{
98	struct mimimi_physics *physics;
99	struct mimimi_physics other;
100	struct mimimi_position transform;
101	struct mimimi_position *position;
102	struct mimimi_position previous;
103	struct mimimi_position other_position;
104	unsigned char was_airborne;
105};
106
107struct mimimi_trampoline
108{
109	struct mimimi_sprite *sprite;
110	struct mimimi_ground *ground;
111	int restitution;
112	int dy;
113};
114
115struct mimimi_video
116{
117	int count;
118	struct mimimi_image *images;
119	void **textures;
120};
121
122struct mimimi_video_set
123{
124	int standing_video_count;
125	int jumping_video_count;
126	struct mimimi_video *standing;
127	struct mimimi_video *knocked;
128	struct mimimi_video *falling;
129	struct mimimi_video *jumping;
130};
131
132struct mimimi_appearance
133{
134	struct mimimi_video_set left, right;
135};
136
137struct mimimi_font
138{
139	unsigned char glyphs[0x60][0x10];
140};
141
142struct mimimi_pose_layer
143{
144	int slant;
145	int y_angle;
146	int z_angle;
147};
148
149struct mimimi_pose
150{
151	int x;
152	int y;
153	int count;
154	struct mimimi_pose_layer layers[0x100];
155};
156
157struct mimimi_movement
158{
159	int count;
160	struct mimimi_pose *poses;
161};
162
163struct mimimi_background
164{
165	void *texture;
166	struct mimimi_position *camera;
167	int x, y, z;
168};
169
170struct mimimi_display
171{
172	struct mimimi_position *camera;
173	struct mimimi_sprite *sprite;
174	struct mimimi_appearance *appearance;
175	unsigned char animation_time;
176	int direction;
177	int width, height;
178};
179
180struct mimimi_row
181{
182	int width;
183	int height;
184	int count;
185	unsigned char colors[0x80];
186};
187
188struct mimimi_layer
189{
190	int x, y, z;
191	int width;
192	int amplifier;
193	int count;
194	struct mimimi_row rows[0x80];
195};
196
197struct mimimi_model_layer
198{
199	int parent_index;
200	struct mimimi_layer *layer;
201};
202
203struct mimimi_model
204{
205	int count;
206	struct mimimi_model_layer layers[0x80];
207};
208
209struct mimimi_history
210{
211	unsigned int left, right;
212};
213
214struct mimimi_clamped_camera_threshold
215{
216	int x;
217	int top;
218	int bottom;
219};
220
221struct mimimi_clamped_camera
222{
223	struct mimimi_position *origin;
224	struct mimimi_position *position;
225	struct mimimi_position *input;
226	struct mimimi_position output;
227	struct mimimi_clamped_camera_threshold *thresholds;
228	int count;
229};
230
231struct mimimi_dialogue_paragraph
232{
233	struct mimimi_model *model;
234	char *name;
235	char *text;
236};
237
238struct mimimi_dialogue
239{
240	struct mimimi_dialogue_paragraph *paragraphs;
241	int count;
242};
243
244struct mimimi_strip_dialogue
245{
246	struct mimimi_engine *engine;
247	int count;
248	void *texture;
249	int notches[0x80];
250	unsigned char held;
251	int i;
252	int x, y;
253	struct mimimi_image image;
254	unsigned char colors[128 * 2048];
255};
256
257struct mimimi_toast_dialogue
258{
259	struct mimimi_engine *engine;
260	int count;
261	void *textures[0x80];
262	int delays[0x80];
263	int heights[0x80];
264	unsigned char colors[128 * 2048];
265	int i, j, k;
266};
267
268extern struct mimimi_font *mimimi_font;
269
270extern struct mimimi_model *mimimi_mango;
271extern struct mimimi_model *mimimi_pepper;
272
273void mimimi_collision_tick(struct mimimi_collision *collision);
274
275void mimimi_camera_tick(struct mimimi_position *camera, struct mimimi_position *position, int ox, int oy);
276void mimimi_camera_stamp(struct mimimi_engine *engine, struct mimimi_position *camera, int x, int y, int z, void *texture);
277void mimimi_clamped_camera_tick(struct mimimi_clamped_camera *camera);
278
279void mimimi_collision_physics_tick(struct mimimi_physics *physics, struct mimimi_position *position, struct mimimi_ground *ground);
280void mimimi_dynamics_tick(struct mimimi_physics *physics, struct mimimi_position *position);
281void mimimi_physics_tick(struct mimimi_physics *physics, struct mimimi_position *position, struct mimimi_ground *ground);
282
283void mimimi_life_tick(struct mimimi_life *life);
284void mimimi_fall_tick(struct mimimi_fall *fall, struct mimimi_physics *physics, struct mimimi_life *life);
285void mimimi_walk_tick(struct mimimi_walk *walk, struct mimimi_physics *physics);
286
287void mimimi_sprite(struct mimimi_sprite *sprite, struct mimimi_ground *ground, int x, int y, int width, int height);
288void mimimi_sprite_tick(struct mimimi_sprite *sprite);
289
290void mimimi_conveyor_tick(struct mimimi_conveyor *conveyor);
291void mimimi_positioned_physics_tick(struct mimimi_positioned_physics *physics, struct mimimi_ground *ground);
292void mimimi_positioned_physics(struct mimimi_positioned_physics *physics, struct mimimi_physics *other, struct mimimi_position *position, struct mimimi_ground *ground, struct mimimi_position *transform);
293void mimimi_trampoline_tick(struct mimimi_trampoline *trampoline);
294
295void mimimi_appearance(struct mimimi_appearance *appearance, struct mimimi_model *model, int x, int y);
296void mimimi_video(struct mimimi_video *video, struct mimimi_engine *engine);
297void mimimi_invalidate_video(struct mimimi_video *video, struct mimimi_engine *engine);
298void mimimi_prepare_appearance(struct mimimi_appearance *appearance, struct mimimi_engine *engine);
299void mimimi_invalidate_appearance(struct mimimi_appearance *appearance, struct mimimi_engine *engine);
300
301int mimimi_measure_character(struct mimimi_font *font, char ch);
302int mimimi_draw_character(struct mimimi_font *font, char ch, struct mimimi_image *target, int x, int y, unsigned char color);
303
304int mimimi_measure_segment(struct mimimi_font *font, char *text, int count);
305int mimimi_draw_segment(struct mimimi_font *font, char *text, int count, struct mimimi_image *target, int x, int y, unsigned char color);
306
307char *mimimi_skip_word(char *text);
308int mimimi_count_word(char *text);
309int mimimi_measure_word(struct mimimi_font *font, char *text);
310int mimimi_draw_word(struct mimimi_font *font, char *text, struct mimimi_image *target, int x, int y, unsigned char color);
311
312char *mimimi_skip_paragraph(char *text);
313int mimimi_count_paragraph(char *text);
314int mimimi_measure_paragraph(struct mimimi_font *font, char *text);
315int mimimi_draw_paragraph(struct mimimi_font *font, char *text, struct mimimi_image *target, int x, int y, unsigned char color);
316
317char *mimimi_skip_line(struct mimimi_font *font, char *text, int width);
318int mimimi_count_line(struct mimimi_font *font, char *text, int width);
319int mimimi_measure_line(struct mimimi_font *font, char *text, int width);
320int mimimi_draw_line(struct mimimi_font *font, char *text, int width, struct mimimi_image *target, int x, int y, unsigned char color);
321
322int mimimi_measure_text(struct mimimi_font *font, char *text, int width, int line_height);
323int mimimi_draw_text(struct mimimi_font *font, char *text, int width, int line_height, struct mimimi_image *target, int x, int y, unsigned char color);
324
325void mimimi_movement(struct mimimi_video *video, struct mimimi_model *model, struct mimimi_movement *movement);
326void mimimi_pose(struct mimimi_image *image, struct mimimi_model *model, struct mimimi_pose *pose);
327
328void mimimi_background_tick(struct mimimi_background *background, struct mimimi_engine *engine);
329void mimimi_display_tick(struct mimimi_display *display, struct mimimi_engine *engine);
330
331unsigned char mimimi_ground_tile(struct mimimi_ground *ground, int x, int y);
332
333void mimimi_history_tick(struct mimimi_history *history, unsigned char left, unsigned char right);
334void mimimi_controls_tick(struct mimimi_walk *walk, struct mimimi_history *history, void (*jump)(void *data), void *data);
335void mimimi_jump(void *data);
336
337void mimimi_strip_dialogue(struct mimimi_strip_dialogue *strip_dialogue, struct mimimi_dialogue *dialogue, struct mimimi_engine *engine);
338unsigned char mimimi_strip_dialogue_tick(struct mimimi_strip_dialogue *dialogue, unsigned char held);
339
340void mimimi_toast_dialogue(struct mimimi_toast_dialogue *toast_dialogue, struct mimimi_dialogue *dialogue, struct mimimi_engine *engine);
341unsigned char mimimi_toast_dialogue_top_tick(struct mimimi_toast_dialogue *dialogue);
342unsigned char mimimi_toast_dialogue_bottom_tick(struct mimimi_toast_dialogue *dialogue);
343
344int mimimi_wasm(void (*start)(void *chapter, struct mimimi_engine *engine), void (*tick)(void *chapter, unsigned char left, unsigned char right), unsigned long int size);
345int mimimi_fbdev(void (*start)(void *chapter, struct mimimi_engine *engine), void (*tick)(void *chapter, unsigned char left, unsigned char right), unsigned long int size);
346
347#endif