Mario Kart 64
code_80004740.h
Go to the documentation of this file.
1 #ifndef CODE_80004740_H
2 #define CODE_80004740_H
3 
4 #include "common_structs.h"
5 
6 /*
7 What I know about animation stuff so far
8 
9 Its not clear to me exactly what animations even are in MK64, my speculation is that their some form of matrix manipulation sequence.
10 Presumably the "models" of the objects that are getting animated are a bunch of matrices and the animations somehow change them.
11 code_80004740 appears to be responsible for the handling of animations.
12 Animation seem to be reserved for objects, namely: seagulls in KTB, flags in YV, chain chomps in RR, and penguins in SL.
13 
14 Each object has 2 pointers of interest, at offsets 0x70 and 0x74 (unk_070 and unk_074).
15 These are passed to func_80004DFC, along with what appears to be an index and a timer.
16 func_80004DFC(unk70, unk74, index, timer)
17 
18 unk_070 points to what I will call a "Type 1" array.
19 I call it an array, but I don't think that's entirely accurate.
20 There are 4 potential "types" of "type 1" arrays: 0, 1, 2, and 3
21 Only type 0 has anything below the "size" entry.
22 The rest only have the type and size.
23 The contents look like this struct
24 struct {
25  s32 type;
26  s32 size;
27  s32 always_zero_never_used;
28  s32 maybe_a_dl_pointer_maybe_null;
29  s32 thing1;
30  s32 thing2;
31  s32 thing3;
32 }
33 Again, note that types 1, 2, and 3 only have the "type" and "size" elements.
34 
35 They are handled in func_80004C30.
36 Each "type" indicates a different action to take while iterating over the array.
37 Type 1: Only used to modify Type 0's behaviour
38 Type 2: Pop a matrix
39 Type 3: End of array, stop processing
40 Type 0: Always handles some part of the animation. If preceded by a Type 1 entry it will pop a matrix prior to the animation handling.
41 
42 The "size" entry is used in a weird way. If you have a set of entries like:
43 
44  0x00000001, <- Our unk_070 pointer starts here
45  0x00000002,
46 
47  0x00000000,
48  0x00000007,
49  0x00000000,
50  0x00000000,
51  0x00000000,
52  0x00000000,
53  0x00000000,
54 
55  0x00000001,
56  0x00000002,
57 
58 Then the size of 2 in the first entry is used to move the pointer 2 words forward
59 
60  0x00000001,
61  0x00000002,
62 
63  0x00000000, <- Goes here
64  0x00000007,
65  0x00000000,
66  0x00000000,
67  0x00000000,
68  0xfffffffb, (this is really -5)
69  0x00000005,
70 
71  0x00000001,
72  0x00000002,
73 
74 Then, the 7 does the same thing
75 
76  0x00000001,
77  0x00000002,
78 
79  0x00000000,
80  0x00000007,
81  0x00000000,
82  0x00000000,
83  0x00000000,
84  0x00000000,
85  0x00000000,
86 
87  0x00000001, <- Now we're here
88  0x00000002,
89 
90 This is why I don't think referring to this as an "array" is really correct.
91 Iterating over this data not like iterating over a proper array at all.
92 
93 I don't really understand the "thing" entries yet.
94 They seem to be used in func_80004A1C to set some values in Vec3f which is then used to set some values in a Mat4.
95 This, I assume, is related to the matrix maniplation stuff that's used to actually accomplish the animation.
96 
97 The unk_074 pointer points to a list of other pointers.
98 As best as I can tell only the penguins actually have multiple entries in this list, all the other animated objects have just 1 entry.
99 The pointers in this list have entires that look like this struct:
100 
101 struct {
102  s32 always_set_to_something_but_never_used;
103  s32 always_zero_never_used;
104  s/u16 animation_length;
105  s/u16 has_value_but_never_used;
106  s32 type_2_array_pointer;
107  s32 type_3_array_pointer;
108 }
109 
110 I will refer to these structs as Struct 2's.
111 
112 Type 2 arrays appear to be just s/u16 arrays.
113 Their use will be discussed later
114 
115 Type 3 arrays appear to be arrays of pairs of s/u16 numbers that look like this struct:
116 
117 struct {
118  s/u16 some_limiter;
119  s/u16 some_offset;
120 };
121 
122 Type 3 entires are interesting.
123 They're used in func_80004C30 and func_80004A1C, and they're always used in triples
124 The `timer` argument to func_80004DFC is compared to the `some_limiter` entry.
125 If it less than the limiter then its value it used elsewhere, otherwise 0 is used (more details below).
126 The `some_offset` value is always used.
127 
128 Then, the 2 chosen values are used to select a value from the Type 2 array.
129 So, for example, if you have a Struct 2 like:
130 
131 
132  0x00010000,
133  0x00000000,
134  0x0037, <- animation lenght
135  0x000a,
136  d_course_koopa_troopa_beach_unk_data2,
137  d_course_koopa_troopa_beach_unk_data3,
138 
139 d_course_koopa_troopa_beach_unk_data2 should be a Type 2 array while d_course_koopa_troopa_beach_unk_data3 is a Type 3 array.
140 
141 d_course_koopa_troopa_beach_unk_data3 has entries that look like:
142  //limiter //offset
143  0x0001, 0x0000,
144  0x0037, 0x0001,
145  0x0001, 0x0000,
146 
147 In practice the limiter value is always 1 or the animation length, meaning that you either choose 0 or the current animation timer.
148 There's never a situation where you will choose the animation timer until it hits X and then swap to 0.
149 Its always one or the other, never swapping.
150 
151 The first triplet is used in func_80004C30 to access the Type 2 array and the values accessed is placed into D_80162D70.
152 D_80162D70 is a Vec3s is then used to set the values of some Vec3f in func_80004A1C.
153 All further triplets are used in func_80004A1C to collect Type 2 values to another Vec3s local to the function.
154 Both the local Vec3s and Vec3f are used to create a Mat4, which is then converted to a Mtx, which is then pushed into the matrix pool.
155 
156 The chosen values are then used to access the Type 2 array and the value accessed is placed into D_80162D70.
157 D_80162D70 is a Vec3s that is used to set values in the some Vec3f that goes on to be used to modify the same Mat4 that the `thing` values are placed into.
158 
159 */
160 
161 typedef struct {
162  /* 0x00 */ s32 type;
163  /* 0x04 */ s32 size;
166  /* 0x10 */ s32 thing[3];
168 
169 typedef struct {
170  /* 0x00 */ u16 some_limiter;
171  /* 0x02 */ u16 some_offset;
173 
175 
176 typedef struct {
179  /* 0x08 */ s16 animation_length;
184 
189 };
190 
191 /* Function Prototypes */
192 
193 void func_80004740(Mtx *dest, Mat4 src);
194 void mtxf_translate_rotate2(Mat4 dest, Vec3f b, Vec3s c);
195 s16 func_80004EAC(void*, s16);
199 
200 #endif
void func_80004A1C(animation_type_1 *, s16 *, animation_type_3_triplet, s32)
Definition: code_80004740.c:68
void func_80004C30(u32 *, animation_type_2 *, s16)
Definition: code_80004740.c:106
animation_type_3 animation_type_3_triplet[3]
Definition: code_80004740.h:174
s16 func_80004DFC(animation_type_1 *, animation_type_2 **, s16, s16)
Definition: code_80004740.c:154
void mtxf_translate_rotate2(Mat4 dest, Vec3f b, Vec3s c)
Definition: code_80004740.c:37
void func_80004740(Mtx *dest, Mat4 src)
Definition: code_80004740.c:17
s16 func_80004EAC(void *, s16)
Definition: code_80004740.c:173
f32 Vec3f[3]
Definition: common_structs.h:6
s16 Vec3s[3]
Definition: common_structs.h:8
f32 Mat4[4][4]
Definition: common_structs.h:13
Definition: code_80004740.h:161
s32 size
Definition: code_80004740.h:163
s32 type
Definition: code_80004740.h:162
Gfx * optional_segmented_dl_address
Definition: code_80004740.h:165
s32 always_zero_never_used
Definition: code_80004740.h:164
Definition: code_80004740.h:176
u16 has_value_but_never_used
Definition: code_80004740.h:180
s16 animation_length
Definition: code_80004740.h:179
s16 * type_2_array_pointer
Definition: code_80004740.h:181
s32 always_zero_never_used
Definition: code_80004740.h:178
s32 always_set_to_something_but_never_used
Definition: code_80004740.h:177
animation_type_3_triplet * type_3_array_pointer
Definition: code_80004740.h:182
Definition: code_80004740.h:169
u16 some_offset
Definition: code_80004740.h:171
u16 some_limiter
Definition: code_80004740.h:170
Definition: code_80004740.h:185
s16 unk8
Definition: code_80004740.h:188
s32 unk0
Definition: code_80004740.h:186
s32 unk4
Definition: code_80004740.h:187
signed int s32
Definition: ultratypes.h:15
unsigned int u32
Definition: ultratypes.h:16
signed short int s16
Definition: ultratypes.h:13
unsigned short int u16
Definition: ultratypes.h:14