-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlibsm64.c
720 lines (571 loc) · 22.7 KB
/
libsm64.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
#ifndef SM64_LIB_EXPORT
#define SM64_LIB_EXPORT
#endif
#include "libsm64.h"
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <string.h>
#include <math.h>
#include "decomp/audio/external.h"
#include "decomp/include/PR/os_cont.h"
#include "decomp/engine/math_util.h"
#include "decomp/include/sm64.h"
#include "decomp/include/seq_ids.h"
#include "decomp/shim.h"
#include "decomp/memory.h"
#include "decomp/global_state.h"
#include "decomp/game/mario.h"
#include "decomp/game/object_stuff.h"
#include "decomp/engine/surface_collision.h"
#include "decomp/engine/graph_node.h"
#include "decomp/engine/geo_layout.h"
#include "decomp/game/rendering_graph_node.h"
#include "decomp/mario/geo.inc.h"
#include "decomp/game/platform_displacement.h"
#include "decomp/game/sound_init.h"
#include "debug_print.h"
#include "load_surfaces.h"
#include "gfx_adapter.h"
#include "load_anim_data.h"
#include "load_audio_data.h"
#include "load_tex_data.h"
#include "obj_pool.h"
#include "fake_interaction.h"
static struct AllocOnlyPool *s_mario_geo_pool = NULL;
static struct GraphNode *s_mario_graph_node = NULL;
static bool s_init_global = false;
static bool s_init_one_mario = false;
struct MarioInstance
{
struct GlobalState *globalState;
};
struct ObjPool s_mario_instance_pool = { 0, 0 };
static void update_button( bool on, u16 button )
{
gController.buttonPressed &= ~button;
if( on )
{
if(( gController.buttonDown & button ) == 0 )
gController.buttonPressed |= button;
gController.buttonDown |= button;
}
else
{
gController.buttonDown &= ~button;
}
}
static struct Area *allocate_area( void )
{
struct Area *result = malloc( sizeof( struct Area ));
memset( result, 0, sizeof( struct Area ));
result->flags = 1;
result->camera = malloc( sizeof( struct Camera ));
memset( result->camera, 0, sizeof( struct Camera ));
return result;
}
static void free_area( struct Area *area )
{
free( area->camera );
free( area );
}
typedef void (*SM64DebugPrintFunctionPtr)( const char * );
SM64_LIB_FN void sm64_register_debug_print_function( SM64DebugPrintFunctionPtr debugPrintFunction )
{
g_debug_print_func = debugPrintFunction;
}
typedef void (*SM64PlaySoundFunctionPtr)( uint32_t soundBits, float *pos );
SM64_LIB_FN void sm64_register_play_sound_function( SM64PlaySoundFunctionPtr playSoundFunction )
{
g_play_sound_func = playSoundFunction;
}
SM64_LIB_FN void sm64_global_init( const uint8_t *rom, uint8_t *outTexture )
{
if( s_init_global )
sm64_global_terminate();
s_init_global = true;
load_mario_textures_from_rom( rom, outTexture );
load_mario_anims_from_rom( rom );
memory_init();
}
SM64_LIB_FN void sm64_global_terminate( void )
{
if( !s_init_global ) return;
global_state_bind( NULL );
if( s_init_one_mario )
{
for( int i = 0; i < s_mario_instance_pool.size; ++i )
if( s_mario_instance_pool.objects[i] != NULL )
sm64_mario_delete( i );
obj_pool_free_all( &s_mario_instance_pool );
}
s_init_global = false;
s_init_one_mario = false;
if( s_mario_geo_pool )
{
alloc_only_pool_free( s_mario_geo_pool );
s_mario_geo_pool = NULL;
}
surfaces_unload_all();
unload_mario_anims();
memory_terminate();
}
SM64_LIB_FN void sm64_audio_init( const uint8_t *rom ) {
load_audio_banks( rom );
}
#define SAMPLES_HIGH 544
#define SAMPLES_LOW 528
SM64_LIB_FN uint32_t sm64_audio_tick( uint32_t numQueuedSamples, uint32_t numDesiredSamples, int16_t *audio_buffer ) {
if ( !g_is_audio_initialized ) {
DEBUG_PRINT("Attempted to tick audio, but sm64_audio_init() has not been called yet.");
return 0;
}
update_game_sound();
u32 num_audio_samples = numQueuedSamples < numDesiredSamples ? SAMPLES_HIGH : SAMPLES_LOW;
for (int i = 0; i < 2; i++)
{
create_next_audio_buffer( audio_buffer + i * ( 2 * num_audio_samples ), num_audio_samples );
}
return num_audio_samples;
}
SM64_LIB_FN void sm64_static_surfaces_load( const struct SM64Surface *surfaceArray, uint32_t numSurfaces )
{
surfaces_load_static( surfaceArray, numSurfaces );
}
SM64_LIB_FN int32_t sm64_mario_create( float x, float y, float z )
{
int32_t marioIndex = obj_pool_alloc_index( &s_mario_instance_pool, sizeof( struct MarioInstance ));
struct MarioInstance *newInstance = s_mario_instance_pool.objects[marioIndex];
newInstance->globalState = global_state_create();
global_state_bind( newInstance->globalState );
if( !s_init_one_mario )
{
s_init_one_mario = true;
s_mario_geo_pool = alloc_only_pool_init();
s_mario_graph_node = process_geo_layout( s_mario_geo_pool, mario_geo_ptr );
}
gCurrSaveFileNum = 1;
gMarioObject = hack_allocate_mario();
gCurrentArea = allocate_area();
gCurrentObject = gMarioObject;
gMarioSpawnInfoVal.startPos[0] = x;
gMarioSpawnInfoVal.startPos[1] = y;
gMarioSpawnInfoVal.startPos[2] = z;
gMarioSpawnInfoVal.startAngle[0] = 0;
gMarioSpawnInfoVal.startAngle[1] = 0;
gMarioSpawnInfoVal.startAngle[2] = 0;
gMarioSpawnInfoVal.areaIndex = 0;
gMarioSpawnInfoVal.activeAreaIndex = 0;
gMarioSpawnInfoVal.behaviorArg = 0;
gMarioSpawnInfoVal.behaviorScript = NULL;
gMarioSpawnInfoVal.unk18 = NULL;
gMarioSpawnInfoVal.next = NULL;
init_mario_from_save_file();
if( init_mario() < 0 )
{
sm64_mario_delete( marioIndex );
return -1;
}
set_mario_action( gMarioState, ACT_SPAWN_SPIN_AIRBORNE, 0);
find_floor( x, y, z, &gMarioState->floor );
return marioIndex;
}
SM64_LIB_FN void sm64_mario_tick( int32_t marioId, const struct SM64MarioInputs *inputs, struct SM64MarioState *outState, struct SM64MarioGeometryBuffers *outBuffers )
{
if( marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL )
{
DEBUG_PRINT("Tried to tick non-existant Mario with ID: %u", marioId);
return;
}
global_state_bind( ((struct MarioInstance *)s_mario_instance_pool.objects[ marioId ])->globalState );
update_button( inputs->buttonA, A_BUTTON );
update_button( inputs->buttonB, B_BUTTON );
update_button( inputs->buttonZ, Z_TRIG );
gMarioState->marioObj->header.gfx.cameraToObject[0] = 0;
gMarioState->marioObj->header.gfx.cameraToObject[1] = 0;
gMarioState->marioObj->header.gfx.cameraToObject[2] = 0;
gMarioState->area->camera->yaw = atan2s( inputs->camLookZ, inputs->camLookX );
gController.stickX = -64.0f * inputs->stickX;
gController.stickY = 64.0f * inputs->stickY;
gController.stickMag = sqrtf( gController.stickX*gController.stickX + gController.stickY*gController.stickY );
apply_mario_platform_displacement();
bhv_mario_update();
update_mario_platform(); // TODO platform grabbed here and used next tick could be a use-after-free
gfx_adapter_bind_output_buffers( outBuffers );
geo_process_root_hack_single_node( s_mario_graph_node );
gAreaUpdateCounter++;
outState->health = gMarioState->health;
vec3f_copy( outState->position, gMarioState->pos );
vec3f_copy( outState->velocity, gMarioState->vel );
outState->faceAngle = (float)gMarioState->faceAngle[1] / 32768.0f * 3.14159f;
outState->action = gMarioState->action;
outState->flags = gMarioState->flags;
outState->particleFlags = gMarioState->particleFlags;
outState->invincTimer = gMarioState->invincTimer;
}
SM64_LIB_FN void sm64_mario_delete( int32_t marioId )
{
if( marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL )
{
DEBUG_PRINT("Tried to delete non-existant Mario with ID: %u", marioId);
return;
}
struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[ marioId ])->globalState;
global_state_bind( globalState );
if ( g_is_audio_initialized ) {
stop_sound(SOUND_MARIO_SNORING3, gMarioState->marioObj->header.gfx.cameraToObject);
}
free( gMarioObject );
free_area( gCurrentArea );
global_state_delete( globalState );
obj_pool_free_index( &s_mario_instance_pool, marioId );
}
SM64_LIB_FN void sm64_set_mario_action(int32_t marioId, uint32_t action)
{
if( marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL )
{
DEBUG_PRINT("Tried to use non-existant Mario with ID: %d", marioId);
return;
}
struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[ marioId ])->globalState;
global_state_bind( globalState );
set_mario_action(gMarioState, action, 0);
}
SM64_LIB_FN void sm64_set_mario_action_arg(int32_t marioId, uint32_t action, uint32_t actionArg)
{
if( marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL )
{
DEBUG_PRINT("Tried to use non-existant Mario with ID: %d", marioId);
return;
}
struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[ marioId ])->globalState;
global_state_bind( globalState );
set_mario_action(gMarioState, action, actionArg);
}
SM64_LIB_FN void sm64_set_mario_animation(int32_t marioId, int32_t animID)
{
if( marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL )
{
DEBUG_PRINT("Tried to use non-existant Mario with ID: %d", marioId);
return;
}
struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[ marioId ])->globalState;
global_state_bind( globalState );
set_mario_animation(gMarioState, animID);
}
SM64_LIB_FN void sm64_set_mario_anim_frame(int32_t marioId, int16_t animFrame)
{
if( marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL )
{
DEBUG_PRINT("Tried to use non-existant Mario with ID: %d", marioId);
return;
}
struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[ marioId ])->globalState;
global_state_bind( globalState );
gMarioState->marioObj->header.gfx.animInfo.animFrame = animFrame;
}
SM64_LIB_FN void sm64_set_mario_state(int32_t marioId, uint32_t flags)
{
if( marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL )
{
DEBUG_PRINT("Tried to use non-existant Mario with ID: %d", marioId);
return;
}
struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[ marioId ])->globalState;
global_state_bind( globalState );
gMarioState->flags = flags;
}
SM64_LIB_FN void sm64_set_mario_position(int32_t marioId, float x, float y, float z)
{
if( marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL )
{
DEBUG_PRINT("Tried to use non-existant Mario with ID: %d", marioId);
return;
}
struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[ marioId ])->globalState;
global_state_bind( globalState );
gMarioState->pos[0] = x;
gMarioState->pos[1] = y;
gMarioState->pos[2] = z;
vec3f_copy(gMarioState->marioObj->header.gfx.pos, gMarioState->pos);
}
SM64_LIB_FN void sm64_set_mario_angle(int32_t marioId, float x, float y, float z)
{
if( marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL )
{
DEBUG_PRINT("Tried to use non-existant Mario with ID: %d", marioId);
return;
}
struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[ marioId ])->globalState;
global_state_bind( globalState );
vec3s_set(gMarioState->faceAngle, (int16_t)(x / 3.14159f * 32768.f), (int16_t)(y / 3.14159f * 32768.f), (int16_t)(z / 3.14159f * 32768.f));
vec3s_copy(gMarioState->marioObj->header.gfx.angle, gMarioState->faceAngle);
}
SM64_LIB_FN void sm64_set_mario_faceangle(int32_t marioId, float y)
{
if( marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL )
{
DEBUG_PRINT("Tried to use non-existant Mario with ID: %d", marioId);
return;
}
struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[ marioId ])->globalState;
global_state_bind( globalState );
gMarioState->faceAngle[1] = (int16_t)(y / 3.14159f * 32768.f);
vec3s_set(gMarioState->marioObj->header.gfx.angle, 0, gMarioState->faceAngle[1], 0);
}
SM64_LIB_FN void sm64_set_mario_velocity(int32_t marioId, float x, float y, float z)
{
if( marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL )
{
DEBUG_PRINT("Tried to use non-existant Mario with ID: %d", marioId);
return;
}
struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[ marioId ])->globalState;
global_state_bind( globalState );
gMarioState->vel[0] = x;
gMarioState->vel[1] = y;
gMarioState->vel[2] = z;
}
SM64_LIB_FN void sm64_set_mario_forward_velocity(int32_t marioId, float vel)
{
if( marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL )
{
DEBUG_PRINT("Tried to use non-existant Mario with ID: %d", marioId);
return;
}
struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[ marioId ])->globalState;
global_state_bind( globalState );
gMarioState->forwardVel = vel;
}
SM64_LIB_FN void sm64_set_mario_invincibility(int32_t marioId, int16_t timer)
{
if( marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL )
{
DEBUG_PRINT("Tried to use non-existant Mario with ID: %d", marioId);
return;
}
struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[ marioId ])->globalState;
global_state_bind( globalState );
gMarioState->invincTimer = timer;
}
SM64_LIB_FN void sm64_set_mario_water_level(int32_t marioId, signed int level)
{
if( marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL )
{
DEBUG_PRINT("Tried to use non-existant Mario with ID: %d", marioId);
return;
}
struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[ marioId ])->globalState;
global_state_bind( globalState );
gMarioState->waterLevel = level;
}
SM64_LIB_FN void sm64_set_mario_gas_level(int32_t marioId, signed int level)
{
if( marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL )
{
DEBUG_PRINT("Tried to use non-existant Mario with ID: %d", marioId);
return;
}
struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[ marioId ])->globalState;
global_state_bind( globalState );
gMarioState->gasLevel = level;
}
SM64_LIB_FN void sm64_set_mario_health(int32_t marioId, uint16_t health)
{
if( marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL )
{
DEBUG_PRINT("Tried to use non-existant Mario with ID: %d", marioId);
return;
}
struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[ marioId ])->globalState;
global_state_bind( globalState );
gMarioState->health = health;
gMarioState->hurtCounter = 0;
gMarioState->healCounter = 0;
}
SM64_LIB_FN void sm64_mario_take_damage(int32_t marioId, uint32_t damage, uint32_t subtype, float x, float y, float z)
{
if( marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL )
{
DEBUG_PRINT("Tried to use non-existant Mario with ID: %d", marioId);
return;
}
struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[ marioId ])->globalState;
global_state_bind( globalState );
fake_damage_knock_back(gMarioState, damage, subtype, x, y, z);
}
SM64_LIB_FN void sm64_mario_heal(int32_t marioId, uint8_t healCounter)
{
if( marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL )
{
DEBUG_PRINT("Tried to use non-existant Mario with ID: %d", marioId);
return;
}
struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[ marioId ])->globalState;
global_state_bind( globalState );
gMarioState->healCounter += healCounter;
}
SM64_LIB_FN void sm64_mario_kill(int32_t marioId)
{
if( marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL )
{
DEBUG_PRINT("Tried to use non-existant Mario with ID: %d", marioId);
return;
}
struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[ marioId ])->globalState;
global_state_bind( globalState );
gMarioState->health = 0xff;
}
SM64_LIB_FN void sm64_mario_interact_cap(int32_t marioId, uint32_t capFlag, uint16_t capTime, uint8_t playMusic)
{
if( marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL )
{
DEBUG_PRINT("Tried to use non-existant Mario with ID: %d", marioId);
return;
}
struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[ marioId ])->globalState;
global_state_bind( globalState );
uint16_t capMusic = 0;
if(gMarioState->action != ACT_GETTING_BLOWN && capFlag != 0)
{
gMarioState->flags &= ~MARIO_CAP_ON_HEAD & ~MARIO_CAP_IN_HAND;
gMarioState->flags |= capFlag;
switch(capFlag)
{
case MARIO_VANISH_CAP:
if(capTime == 0) capTime = 600;
capMusic = SEQUENCE_ARGS(4, SEQ_EVENT_POWERUP);
break;
case MARIO_METAL_CAP:
if(capTime == 0) capTime = 600;
capMusic = SEQUENCE_ARGS(4, SEQ_EVENT_METAL_CAP);
break;
case MARIO_WING_CAP:
if(capTime == 0) capTime = 1800;
capMusic = SEQUENCE_ARGS(4, SEQ_EVENT_POWERUP);
break;
}
if (capTime > gMarioState->capTimer) {
gMarioState->capTimer = capTime;
}
if ((gMarioState->action & ACT_FLAG_IDLE) || gMarioState->action == ACT_WALKING) {
gMarioState->flags |= MARIO_CAP_IN_HAND;
set_mario_action(gMarioState, ACT_PUTTING_ON_CAP, 0);
} else {
gMarioState->flags |= MARIO_CAP_ON_HEAD;
}
play_sound(SOUND_MENU_STAR_SOUND, gMarioState->marioObj->header.gfx.cameraToObject);
play_sound(SOUND_MARIO_HERE_WE_GO, gMarioState->marioObj->header.gfx.cameraToObject);
if (playMusic != 0 && capMusic != 0) {
play_cap_music(capMusic);
}
}
}
SM64_LIB_FN void sm64_mario_extend_cap(int32_t marioId, uint16_t capTime)
{
if( marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL )
{
DEBUG_PRINT("Tried to use non-existant Mario with ID: %d", marioId);
return;
}
struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[ marioId ])->globalState;
global_state_bind( globalState );
gMarioState->capTimer += capTime;
}
SM64_LIB_FN bool sm64_mario_attack(int32_t marioId, float x, float y, float z, float hitboxHeight)
{
if( marioId >= s_mario_instance_pool.size || s_mario_instance_pool.objects[marioId] == NULL )
{
DEBUG_PRINT("Tried to use non-existant Mario with ID: %d", marioId);
return false;
}
struct GlobalState *globalState = ((struct MarioInstance *)s_mario_instance_pool.objects[ marioId ])->globalState;
global_state_bind( globalState );
return fake_interact_bounce_top(gMarioState, x, y, z, hitboxHeight);
}
SM64_LIB_FN uint32_t sm64_surface_object_create( const struct SM64SurfaceObject *surfaceObject )
{
uint32_t id = surfaces_load_object( surfaceObject );
return id;
}
SM64_LIB_FN void sm64_surface_object_move( uint32_t objectId, const struct SM64ObjectTransform *transform )
{
surface_object_update_transform( objectId, transform );
}
SM64_LIB_FN void sm64_surface_object_delete( uint32_t objectId )
{
// A mario standing on the platform that is being destroyed will have a pointer to freed memory if we don't clear it.
for( int i = 0; i < s_mario_instance_pool.size; ++i )
{
if( s_mario_instance_pool.objects[i] == NULL )
continue;
struct GlobalState *state = ((struct MarioInstance *)s_mario_instance_pool.objects[ i ])->globalState;
if( state->mgMarioObject->platform == surfaces_object_get_transform_ptr( objectId ))
state->mgMarioObject->platform = NULL;
}
surfaces_unload_object( objectId );
}
SM64_LIB_FN int32_t sm64_surface_find_wall_collision( float *xPtr, float *yPtr, float *zPtr, float offsetY, float radius )
{
return f32_find_wall_collision( xPtr, yPtr, zPtr, offsetY, radius );
}
SM64_LIB_FN int32_t sm64_surface_find_wall_collisions( struct SM64WallCollisionData *colData )
{
return find_wall_collisions( colData );
}
SM64_LIB_FN float sm64_surface_find_ceil( float posX, float posY, float posZ, struct SM64SurfaceCollisionData **pceil )
{
return find_ceil( posX, posY, posZ, pceil );
}
SM64_LIB_FN float sm64_surface_find_floor_height_and_data( float xPos, float yPos, float zPos, struct SM64FloorCollisionData **floorGeo )
{
return find_floor_height_and_data( xPos, yPos, zPos, floorGeo );
}
SM64_LIB_FN float sm64_surface_find_floor_height( float x, float y, float z )
{
return find_floor_height( x, y, z );
}
SM64_LIB_FN float sm64_surface_find_floor( float xPos, float yPos, float zPos, struct SM64SurfaceCollisionData **pfloor )
{
return find_floor( xPos, yPos, zPos, pfloor );
}
SM64_LIB_FN float sm64_surface_find_water_level( float x, float z )
{
return find_water_level( x, z );
}
SM64_LIB_FN float sm64_surface_find_poison_gas_level( float x, float z )
{
return find_poison_gas_level( x, z );
}
SM64_LIB_FN void sm64_seq_player_play_sequence(uint8_t player, uint8_t seqId, uint16_t arg2)
{
seq_player_play_sequence(player,seqId,arg2);
}
SM64_LIB_FN void sm64_play_music(uint8_t player, uint16_t seqArgs, uint16_t fadeTimer)
{
play_music(player,seqArgs,fadeTimer);
}
SM64_LIB_FN void sm64_stop_background_music(uint16_t seqId)
{
stop_background_music(seqId);
}
SM64_LIB_FN void sm64_fadeout_background_music(uint16_t arg0, uint16_t fadeOut)
{
fadeout_background_music(arg0,fadeOut);
}
SM64_LIB_FN uint16_t sm64_get_current_background_music()
{
return get_current_background_music();
}
SM64_LIB_FN void sm64_play_sound(int32_t soundBits, float *pos)
{
play_sound(soundBits,pos);
}
SM64_LIB_FN void sm64_play_sound_global(int32_t soundBits)
{
play_sound(soundBits,gGlobalSoundSource);
}
SM64_LIB_FN void sm64_set_sound_volume(float vol)
{
gAudioVolume = vol;
}