Mirai's Miscellaneous Misadventures
M50 / include / mimimi.h
1
2
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_life
41{
42 int knocked_time;
43 int immunity_time;
44 int pristinity;
45 int max_pristinity;
46 int recovery_time;
47};
48
49struct mimimi_fall
50{
51 int max_speed;
52 int knocked_time;
53};
54
55struct mimimi_walk
56{
57 int ground_speed;
58 int airborne_speed;
59 int direction;
60};
61
62struct mimimi_ground
63{
64 int width, height;
65 unsigned char tiles[0x2000];
66};
67
68struct mimimi_sprite
69{
70 struct mimimi_position position;
71 struct mimimi_physics physics;
72 struct mimimi_life life;
73 struct mimimi_fall fall;
74 struct mimimi_walk walk;
75 struct mimimi_ground *ground;
76 struct mimimi_position offset;
77};
78
79struct mimimi_conveyor
80{
81 struct mimimi_sprite *sprite;
82 struct mimimi_ground *ground;
83 unsigned char was_airborne;
84 int speed;
85};
86
87struct mimimi_positioned_physics
88{
89 struct mimimi_physics *physics;
90 struct mimimi_physics other;
91 struct mimimi_position transform;
92 struct mimimi_position *position;
93 struct mimimi_position previous;
94 unsigned char was_airborne;
95};
96
97struct mimimi_trampoline
98{
99 struct mimimi_sprite *sprite;
100 struct mimimi_ground *ground;
101 int restitution;
102 int dy;
103};
104
105struct mimimi_video
106{
107 int count;
108 struct mimimi_image *images;
109 void **textures;
110};
111
112struct mimimi_video_set
113{
114 int standing_video_count;
115 int jumping_video_count;
116 struct mimimi_video *standing;
117 struct mimimi_video *knocked;
118 struct mimimi_video *falling;
119 struct mimimi_video *jumping;
120};
121
122struct mimimi_appearance
123{
124 struct mimimi_video_set left, right;
125};
126
127struct mimimi_font
128{
129 unsigned char glyphs[0x60][0x10];
130};
131
132struct mimimi_pose_layer
133{
134 int slant;
135 int y_angle;
136 int z_angle;
137};
138
139struct mimimi_pose
140{
141 int x;
142 int y;
143 int count;
144 struct mimimi_pose_layer layers[0x100];
145};
146
147struct mimimi_movement
148{
149 int count;
150 struct mimimi_pose *poses;
151};
152
153struct mimimi_background
154{
155 void *texture;
156 int x, y, z;
157};
158
159struct mimimi_display
160{
161 struct mimimi_position *camera;
162 struct mimimi_appearance appearance;
163 unsigned char animation_time;
164 int direction;
165 int width, height;
166};
167
168struct mimimi_row
169{
170 int width;
171 int height;
172 int count;
173 unsigned char colors[0x80];
174};
175
176struct mimimi_layer
177{
178 int x, y, z;
179 int width;
180 int amplifier;
181 int count;
182 struct mimimi_row rows[0x80];
183};
184
185struct mimimi_model_layer
186{
187 int parent_index;
188 struct mimimi_layer *layer;
189};
190
191struct mimimi_model
192{
193 int count;
194 struct mimimi_model_layer layers[0x80];
195};
196
197struct mimimi_history
198{
199 unsigned int left, right;
200};
201
202struct mimimi_clamped_camera
203{
204 struct mimimi_position *input;
205 struct mimimi_position output;
206 struct mimimi_position offset;
207 struct mimimi_size size;
208};
209
210struct mimimi_dialogue_paragraph
211{
212 struct mimimi_model *model;
213 char *name;
214 char *text;
215};
216
217struct mimimi_dialogue
218{
219 struct mimimi_dialogue_paragraph *paragraphs;
220 int count;
221};
222
223struct mimimi_strip_dialogue
224{
225 struct mimimi_engine *engine;
226 int count;
227 void *texture;
228 int notches[0x80];
229 unsigned char held;
230 int i;
231 int x, y;
232 struct mimimi_image image;
233 unsigned char colors[128 * 2048];
234};
235
236struct mimimi_toast_dialogue
237{
238 struct mimimi_engine *engine;
239 int count;
240 void *textures[0x80];
241 int delays[0x80];
242 int heights[0x80];
243 unsigned char colors[128 * 2048];
244 struct mimimi_image images[128];
245 int i, j, k;
246};
247
248struct mimimi_momentum
249{
250 int x;
251 int dx;
252};
253
254struct mimimi_platform
255{
256 struct mimimi_positioned_physics physics;
257 struct mimimi_ground *ground;
258 void *texture;
259};
260
261struct mimimi_linear_motion
262{
263 int *value;
264 int origin;
265 int scale;
266};
267
268struct mimimi_angular_motion
269{
270 struct mimimi_position *value;
271 struct mimimi_position origin;
272 int angle;
273 int scale;
274 int height;
275};
276
277struct mimimi_logo_line
278{
279 unsigned char *packed;
280 struct mimimi_size size;
281 struct mimimi_position position;
282};
283
284struct mimimi_logo
285{
286 struct mimimi_logo_line *lines;
287 unsigned char colors[8][16384];
288 struct mimimi_image images[8];
289 void *textures[8];
290 int y_offsets[8];
291 int count;
292};
293
294struct mimimi_platform_set
295{
296 struct mimimi_momentum momentum;
297 int balance;
298 int strength;
299 int linear_weight;
300 int angular_weight;
301 int min, max;
302
303 int linear_platform_count;
304 struct mimimi_platform *linear_platforms;
305 struct mimimi_linear_motion *linear_motions;
306
307 int angular_platform_count;
308 struct mimimi_platform *angular_platforms;
309 struct mimimi_angular_motion *angular_motions;
310};
311
312struct mimimi_area
313{
314 struct mimimi_ground *ground;
315 struct mimimi_position offset;
316 struct mimimi_background *backgrounds;
317 int background_count;
318 struct mimimi_background *foregrounds;
319 int foreground_count;
320};
321
322struct mimimi_stage
323{
324 struct mimimi_display **displays;
325 struct mimimi_sprite *sprites;
326 int sprite_count;
327 struct mimimi_position camera;
328 struct mimimi_clamped_camera clamped_camera;
329 struct mimimi_area *areas;
330 int area_count;
331 struct mimimi_platform_set *platform_sets;
332 int platform_set_count;
333};
334
335extern struct mimimi_font *mimimi_font;
336
337extern struct mimimi_model *mimimi_mango;
338extern struct mimimi_model *mimimi_pepper;
339
340extern struct mimimi_model *mimimi_homura_flash;
341extern struct mimimi_model *mimimi_mirai_flash;
342extern struct mimimi_model *mimimi_mirai_yang;
343extern struct mimimi_model *mimimi_haruka_flash;
344
345extern struct mimimi_model *mimimi_ryoubi_flash;
346extern struct mimimi_model *mimimi_ryouna_flash;
347
348extern signed char *mimimi_sine;
349extern signed char *mimimi_cosine;
350
351extern struct mimimi_logo_line *mimimi_logo_lines;
352extern int mimimi_logo_line_count;
353
354int mimimi_div(int n, int q);
355int mimimi_div_up(int n, int q);
356int mimimi_div_down(int n, int q);
357int mimimi_mod(int n, int q);
358int mimimi_angle(int x, int y);
359
360void mimimi_camera_tick(struct mimimi_position *camera, struct mimimi_position *position, int ox, int oy);
361void mimimi_camera_stamp(struct mimimi_engine *engine, struct mimimi_position *camera, int x, int y, int z, void *texture);
362void mimimi_clamped_camera_tick(struct mimimi_clamped_camera *camera, int width, int height);
363
364void mimimi_collision_physics_tick(struct mimimi_physics *physics, struct mimimi_position *position, struct mimimi_ground *ground);
365void mimimi_dynamics_tick(struct mimimi_physics *physics, struct mimimi_position *position);
366void mimimi_physics_tick(struct mimimi_physics *physics, struct mimimi_position *position, struct mimimi_ground *ground);
367void mimimi_physics(struct mimimi_physics *physics, int width, int height);
368
369void mimimi_life_malloctick(struct mimimi_life *life);
370void mimimi_fall_tick(struct mimimi_fall *fall, struct mimimi_physics *physics, struct mimimi_life *life);
371void mimimi_walk_tick(struct mimimi_walk *walk, struct mimimi_physics *physics);
372
373void mimimi_sprite(struct mimimi_sprite *sprite, struct mimimi_ground *ground, int x, int y, int width, int height);
374void mimimi_sprite_tick(struct mimimi_sprite *sprite);
375
376void mimimi_conveyor_tick(struct mimimi_conveyor *conveyor);
377void mimimi_positioned_physics_tick(struct mimimi_positioned_physics *physics, struct mimimi_ground *ground);
378void mimimi_positioned_physics(struct mimimi_positioned_physics *physics, struct mimimi_physics *other, struct mimimi_position *position);
379void mimimi_trampoline_tick(struct mimimi_trampoline *trampoline);
380
381void mimimi_appearance(struct mimimi_appearance *appearance, struct mimimi_model *model, int x, int y);
382void mimimi_video(struct mimimi_video *video, struct mimimi_engine *engine);
383void mimimi_invalidate_video(struct mimimi_video *video, struct mimimi_engine *engine);
384void mimimi_prepare_appearance(struct mimimi_appearance *appearance, struct mimimi_engine *engine);
385void mimimi_invalidate_appearance(struct mimimi_appearance *appearance, struct mimimi_engine *engine);
386
387int mimimi_measure_character(struct mimimi_font *font, char ch);
388int mimimi_draw_character(struct mimimi_font *font, char ch, struct mimimi_image *target, int x, int y, unsigned char color);
389
390int mimimi_measure_segment(struct mimimi_font *font, char *text, int count);
391int mimimi_draw_segment(struct mimimi_font *font, char *text, int count, struct mimimi_image *target, int x, int y, unsigned char color);
392
393char *mimimi_skip_word(char *text);
394int mimimi_count_word(char *text);
395int mimimi_measure_word(struct mimimi_font *font, char *text);
396int mimimi_draw_word(struct mimimi_font *font, char *text, struct mimimi_image *target, int x, int y, unsigned char color);
397
398char *mimimi_skip_paragraph(char *text);
399int mimimi_count_paragraph(char *text);
400int mimimi_measure_paragraph(struct mimimi_font *font, char *text);
401int mimimi_draw_paragraph(struct mimimi_font *font, char *text, struct mimimi_image *target, int x, int y, unsigned char color);
402
403char *mimimi_skip_line(struct mimimi_font *font, char *text, int width);
404int mimimi_count_line(struct mimimi_font *font, char *text, int width);
405int mimimi_measure_line(struct mimimi_font *font, char *text, int width);
406int mimimi_draw_line(struct mimimi_font *font, char *text, int width, struct mimimi_image *target, int x, int y, unsigned char color);
407
408int mimimi_measure_text(struct mimimi_font *font, char *text, int width, int line_height);
409int 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);
410
411void mimimi_movement(struct mimimi_video *video, struct mimimi_model *model, struct mimimi_movement *movement);
412void mimimi_pose(struct mimimi_image *image, struct mimimi_model *model, struct mimimi_pose *pose);
413
414void mimimi_background_tick(struct mimimi_background *background, struct mimimi_engine *engine, struct mimimi_position *camera, struct mimimi_position *offset);
415void mimimi_display_tick(struct mimimi_display *display, struct mimimi_engine *engine, struct mimimi_sprite *sprite);
416
417unsigned char mimimi_ground_tile(struct mimimi_ground *ground, int x, int y);
418
419void mimimi_history_tick(struct mimimi_history *history, unsigned char left, unsigned char right);
420void mimimi_controls_tick(struct mimimi_walk *walk, struct mimimi_history *history, void (*jump)(void *data), void *data);
421void mimimi_jump(void *data);
422
423void mimimi_strip_dialogue(struct mimimi_strip_dialogue *strip_dialogue, struct mimimi_dialogue *dialogue, struct mimimi_engine *engine);
424unsigned char mimimi_strip_dialogue_tick(struct mimimi_strip_dialogue *dialogue, unsigned char held);
425
426void mimimi_toast_dialogue(struct mimimi_toast_dialogue *toast_dialogue, struct mimimi_dialogue *dialogue, struct mimimi_engine *engine);
427unsigned char mimimi_toast_dialogue_top_tick(struct mimimi_toast_dialogue *dialogue);
428unsigned char mimimi_toast_dialogue_bottom_tick(struct mimimi_toast_dialogue *dialogue);
429
430void mimimi_stage(struct mimimi_stage *stage, struct mimimi_ground **grounds, int count);
431void mimimi_stage_tick(struct mimimi_stage *stage, struct mimimi_engine *engine);
432struct mimimi_sprite *mimimi_spawn(struct mimimi_stage *stage, struct mimimi_display *display, int x, int y, int width, int height);
433
434void mimimi_linear_propagate(struct mimimi_momentum *momentum, int value, int x0, int scale);
435void mimimi_linear_apply(struct mimimi_momentum *momentum, int *value, int x0, int scale);
436
437void mimimi_angular_propagate(struct mimimi_momentum *momentum, struct mimimi_position *position, int x0, int y0, int a0, int scale);
438void mimimi_angular_apply(struct mimimi_momentum *momentum, struct mimimi_position *position, int x0, int y0, int a0, int scale, int length);
439
440void mimimi_linear_motion_propagate(struct mimimi_linear_motion *motion, struct mimimi_momentum *momentum);
441void mimimi_linear_motion_apply(struct mimimi_linear_motion *motion, struct mimimi_momentum *momentum);
442
443void mimimi_angular_motion_propagate(struct mimimi_angular_motion *motion, struct mimimi_momentum *momentum);
444void mimimi_angular_motion_apply(struct mimimi_angular_motion *motion, struct mimimi_momentum *momentum);
445
446void mimimi_platform_display_tick(struct mimimi_platform *platform, struct mimimi_position *camera, int x, int y, struct mimimi_engine *engine);
447struct mimimi_platform_set *mimimi_add_platform_set(struct mimimi_stage *stage);
448void mimimi_spawn_linear_platform(struct mimimi_stage *stage, struct mimimi_platform_set *platforms, struct mimimi_ground *ground, void *texture, int x, int y, int scale);
449void mimimi_spawn_angular_platform(struct mimimi_stage *stage, struct mimimi_platform_set *platforms, struct mimimi_ground *ground, void *texture, int x, int y, int a, int scale, int height);
450
451void mimimi_platform_set_tick(struct mimimi_platform_set *platform_set);
452void mimimi_platform_set_display_tick(struct mimimi_platform_set *platforms, struct mimimi_engine *engine, struct mimimi_position *camera);
453
454void mimimi_logo(struct mimimi_engine *engine, struct mimimi_logo *logo, struct mimimi_logo_line *lines, int count);
455unsigned char mimimi_logo_tick(struct mimimi_engine *engine, struct mimimi_logo *logo, int x, int y);
456
457void mimimi_unpack_bits(int size, unsigned char *unpacked, unsigned char *packed);
458
459void mimimi_linear_motion(struct mimimi_linear_motion *motion, int *value, int origin, int scale);
460void mimimi_angular_motion(struct mimimi_angular_motion *motion, struct mimimi_position *value, int x0, int y0, int a0, int scale, int height);
461
462void mimimi_display(struct mimimi_display *display, struct mimimi_model *model, struct mimimi_engine *engine);
463
464void mimimi_background_image(struct mimimi_image *image, struct mimimi_ground *ground, unsigned char *colors);
465void *mimimi_background(struct mimimi_engine *engine, struct mimimi_ground *ground, unsigned char *colors);
466
467int mimimi_wasm(void *(*start)(struct mimimi_engine *engine), void (*tick)(void *chapter, unsigned char left, unsigned char right));
468int mimimi_fbdev(void *(*start)(struct mimimi_engine *engine), void (*tick)(void *chapter, unsigned char left, unsigned char right));
469int mimimi_minifb(void *(*start)(struct mimimi_engine *engine), void (*tick)(void *chapter, unsigned char left, unsigned char right));
470int mimimi_sdl2(void *(*start)(struct mimimi_engine *engine), void (*tick)(void *chapter, unsigned char left, unsigned char right));
471
472#endif