Mirai's Miscellaneous Misadventures

M45 / 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	struct mimimi_position offset;
87};
88
89struct mimimi_conveyor
90{
91	struct mimimi_sprite *sprite;
92	struct mimimi_ground *ground;
93	unsigned char was_airborne;
94	int speed;
95};
96
97struct mimimi_positioned_physics
98{
99	struct mimimi_physics *physics;
100	struct mimimi_physics other;
101	struct mimimi_position transform;
102	struct mimimi_position *position;
103	struct mimimi_position previous;
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 *position;
224	struct mimimi_position *input;
225	struct mimimi_position output;
226	struct mimimi_clamped_camera_threshold *thresholds;
227	int count;
228};
229
230struct mimimi_dialogue_paragraph
231{
232	struct mimimi_model *model;
233	char *name;
234	char *text;
235};
236
237struct mimimi_dialogue
238{
239	struct mimimi_dialogue_paragraph *paragraphs;
240	int count;
241};
242
243struct mimimi_strip_dialogue
244{
245	struct mimimi_engine *engine;
246	int count;
247	void *texture;
248	int notches[0x80];
249	unsigned char held;
250	int i;
251	int x, y;
252	struct mimimi_image image;
253	unsigned char colors[128 * 2048];
254};
255
256struct mimimi_toast_dialogue
257{
258	struct mimimi_engine *engine;
259	int count;
260	void *textures[0x80];
261	int delays[0x80];
262	int heights[0x80];
263	unsigned char colors[128 * 2048];
264	int i, j, k;
265};
266
267struct mimimi_offset_threshold
268{
269	int x;
270	struct mimimi_position offset;
271};
272
273struct mimimi_offset
274{
275	struct mimimi_sprite *sprite;
276	struct mimimi_offset_threshold *thresholds;
277	int count;
278};
279
280struct mimimi_momentum
281{
282	int x;
283	int dx;
284};
285
286struct mimimi_platform
287{
288	struct mimimi_positioned_physics physics;
289	struct mimimi_ground ground;
290	void *texture;
291};
292
293extern struct mimimi_font *mimimi_font;
294
295extern struct mimimi_model *mimimi_mango;
296extern struct mimimi_model *mimimi_pepper;
297
298extern signed char *mimimi_sine;
299extern signed char *mimimi_cosine;
300extern int mimimi_angle(int x, int y);
301
302int mimimi_div(int n, int q);
303int mimimi_div_up(int n, int q);
304int mimimi_div_down(int n, int q);
305int mimimi_mod(int n, int q);
306
307void mimimi_collision_tick(struct mimimi_collision *collision);
308
309void mimimi_camera_tick(struct mimimi_position *camera, struct mimimi_position *position, int ox, int oy);
310void mimimi_camera_stamp(struct mimimi_engine *engine, struct mimimi_position *camera, int x, int y, int z, void *texture);
311void mimimi_clamped_camera_tick(struct mimimi_clamped_camera *camera);
312
313void mimimi_collision_physics_tick(struct mimimi_physics *physics, struct mimimi_position *position, struct mimimi_ground *ground);
314void mimimi_dynamics_tick(struct mimimi_physics *physics, struct mimimi_position *position);
315void mimimi_physics_tick(struct mimimi_physics *physics, struct mimimi_position *position, struct mimimi_ground *ground);
316void mimimi_physics(struct mimimi_physics *physics, int width, int height);
317
318void mimimi_life_tick(struct mimimi_life *life);
319void mimimi_fall_tick(struct mimimi_fall *fall, struct mimimi_physics *physics, struct mimimi_life *life);
320void mimimi_walk_tick(struct mimimi_walk *walk, struct mimimi_physics *physics);
321
322void mimimi_sprite(struct mimimi_sprite *sprite, struct mimimi_ground *ground, int x, int y, int width, int height);
323void mimimi_sprite_tick(struct mimimi_sprite *sprite);
324
325void mimimi_conveyor_tick(struct mimimi_conveyor *conveyor);
326void mimimi_positioned_physics_tick(struct mimimi_positioned_physics *physics, struct mimimi_ground *ground);
327void mimimi_positioned_physics(struct mimimi_positioned_physics *physics, struct mimimi_physics *other, struct mimimi_position *position);
328void mimimi_trampoline_tick(struct mimimi_trampoline *trampoline);
329
330void mimimi_appearance(struct mimimi_appearance *appearance, struct mimimi_model *model, int x, int y);
331void mimimi_video(struct mimimi_video *video, struct mimimi_engine *engine);
332void mimimi_invalidate_video(struct mimimi_video *video, struct mimimi_engine *engine);
333void mimimi_prepare_appearance(struct mimimi_appearance *appearance, struct mimimi_engine *engine);
334void mimimi_invalidate_appearance(struct mimimi_appearance *appearance, struct mimimi_engine *engine);
335
336int mimimi_measure_character(struct mimimi_font *font, char ch);
337int mimimi_draw_character(struct mimimi_font *font, char ch, struct mimimi_image *target, int x, int y, unsigned char color);
338
339int mimimi_measure_segment(struct mimimi_font *font, char *text, int count);
340int mimimi_draw_segment(struct mimimi_font *font, char *text, int count, struct mimimi_image *target, int x, int y, unsigned char color);
341
342char *mimimi_skip_word(char *text);
343int mimimi_count_word(char *text);
344int mimimi_measure_word(struct mimimi_font *font, char *text);
345int mimimi_draw_word(struct mimimi_font *font, char *text, struct mimimi_image *target, int x, int y, unsigned char color);
346
347char *mimimi_skip_paragraph(char *text);
348int mimimi_count_paragraph(char *text);
349int mimimi_measure_paragraph(struct mimimi_font *font, char *text);
350int mimimi_draw_paragraph(struct mimimi_font *font, char *text, struct mimimi_image *target, int x, int y, unsigned char color);
351
352char *mimimi_skip_line(struct mimimi_font *font, char *text, int width);
353int mimimi_count_line(struct mimimi_font *font, char *text, int width);
354int mimimi_measure_line(struct mimimi_font *font, char *text, int width);
355int mimimi_draw_line(struct mimimi_font *font, char *text, int width, struct mimimi_image *target, int x, int y, unsigned char color);
356
357int mimimi_measure_text(struct mimimi_font *font, char *text, int width, int line_height);
358int 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);
359
360void mimimi_movement(struct mimimi_video *video, struct mimimi_model *model, struct mimimi_movement *movement);
361void mimimi_pose(struct mimimi_image *image, struct mimimi_model *model, struct mimimi_pose *pose);
362
363void mimimi_background_tick(struct mimimi_background *background, struct mimimi_engine *engine);
364void mimimi_display_tick(struct mimimi_display *display, struct mimimi_engine *engine);
365
366unsigned char mimimi_ground_tile(struct mimimi_ground *ground, int x, int y);
367
368void mimimi_history_tick(struct mimimi_history *history, unsigned char left, unsigned char right);
369void mimimi_controls_tick(struct mimimi_walk *walk, struct mimimi_history *history, void (*jump)(void *data), void *data);
370void mimimi_jump(void *data);
371
372void mimimi_strip_dialogue(struct mimimi_strip_dialogue *strip_dialogue, struct mimimi_dialogue *dialogue, struct mimimi_engine *engine);
373unsigned char mimimi_strip_dialogue_tick(struct mimimi_strip_dialogue *dialogue, unsigned char held);
374
375void mimimi_toast_dialogue(struct mimimi_toast_dialogue *toast_dialogue, struct mimimi_dialogue *dialogue, struct mimimi_engine *engine);
376unsigned char mimimi_toast_dialogue_top_tick(struct mimimi_toast_dialogue *dialogue);
377unsigned char mimimi_toast_dialogue_bottom_tick(struct mimimi_toast_dialogue *dialogue);
378
379void mimimi_offset_tick(struct mimimi_offset *offset, int x, int y);
380
381void mimimi_linear_propagate(struct mimimi_momentum *momentum, int value, int x0, int scale, int weight);
382void mimimi_linear_apply(struct mimimi_momentum *momentum, int *value, int x0, int scale);
383
384void mimimi_angular_propagate(struct mimimi_momentum *momentum, struct mimimi_position *position, int x0, int y0, int a0, int scale, int weight);
385void mimimi_angular_apply(struct mimimi_momentum *momentum, struct mimimi_position *position, int x0, int y0, int a0, int scale, int length);
386
387int mimimi_wasm(void (*start)(void *chapter, struct mimimi_engine *engine), void (*tick)(void *chapter, unsigned char left, unsigned char right), unsigned long int size);
388int mimimi_fbdev(void (*start)(void *chapter, struct mimimi_engine *engine), void (*tick)(void *chapter, unsigned char left, unsigned char right), unsigned long int size);
389
390void mimimi_platform_display_tick(struct mimimi_platform *platform, struct mimimi_position *camera, int x, int y, struct mimimi_engine *engine);
391
392#endif