Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
models.c
Go to the documentation of this file.
1/* FIGHTSTG's models task (FIGHTSTG_createModels): the fighters' models and
2 their controls. */
3
5
6/* The fighters' models' task: nothing to do but start */
8 switch (task->state) {
9 case TASK_INIT:
10 default:
11 task->nextState(task);
12 break;
13 case TASK_RUN:
14 case TASK_DONE:
15 case TASK_KILL:
16 break;
17 }
18}
19
20/* The slot of the fighter model registered as ID, or -1 */
22 s32 i;
23
24 for (i = 0; i < 4; i++) {
25 if (task->controls[i].active && task->controls[i].id == id) {
26 return i;
27 }
28 }
29 return -1;
30}
31
32/* A free fighter model slot, or -1 */
34 s32 i;
35
36 for (i = 0; i < 4; i++) {
37 if (!task->controls[i].active) {
38 return i;
39 }
40 }
41 return -1;
42}
43
44/* Models.remove: kills the model registered as ID and frees its slot */
46 ModelsChildren *children = task->children;
47 s32 i = FIGHTSTG_findModelSlot(task, id);
48
49 if (i != -1) {
50 children->dying[i] = children->models[i];
51 children->models[i] = NULL;
52 children->dying[i]->setState(children->dying[i], TASK_KILL);
53 task->controls[i].active = 0;
54 }
55}
56
57/* the fighters' models' texture places */
59 { 832, 0 }, { 896, 0 }, { 960, 0 }, { 960, 256 },
60};
61
62/* Models.add: replaces the model registered as ID with FIGHTER's, in a free
63 slot with that slot's textures, drawn on layer BATTLE_LAYER_MODELS when VISIBLE */
64void FIGHTSTG_addFighterModel(Models *task, s32 id, s32 fighter, s32 visible) {
65 ModelsChildren *children = task->children;
66 FighterInfo *info;
67 ModelControl *control;
68 s32 i;
69
72 if (i != -1) {
73 info = FIGHTSTG_fighterCache.funcs.getInfo(fighter);
74 control = &task->controls[i];
75 children->models[i] = FIGHTSTG_createIdlingModel(info->model, info->motions, FIGHTSTG_fighterTexPos[i], control);
76 HEAP.zero(control, sizeof(ModelControl));
77 task->controls[i].active = 1;
78 task->controls[i].motion = 1;
79 task->controls[i].fighter = fighter;
80 task->controls[i].id = id;
81 task->controls[i].layers[0].enabled = visible;
82 task->controls[i].layers[0].wireframe = 0;
84 }
85}
86
87/* Models.get: the control of the model registered as ID, or NULL */
89 s32 i = FIGHTSTG_findModelSlot(task, id);
90
91 if (i != -1) {
92 return &task->controls[i];
93 }
94 return NULL;
95}
96
97/* Models.setId: registers the model ID as NEWID instead, removing the one
98 that had it */
99void FIGHTSTG_setModelId(Models *task, s32 id, s32 newId) {
100 FIGHTSTG_removeFighterModel(task, newId);
101 task->controls[FIGHTSTG_findModelSlot(task, id)].id = newId;
102}
103
104/* Models.getFighter: the fighter of the model registered as ID, or 0 */
106 s32 i = FIGHTSTG_findModelSlot(task, id);
107
108 if (i != -1) {
109 return task->controls[i].fighter;
110 }
111 return 0;
112}
113
114/* Models.face: puts the model registered as ID at its side's place, facing
115 the other side, as its home */
117 ModelControl *control = FIGHTSTG_getModelControl(task, id);
118 FighterInfo *info;
119 s16 z;
120
121 if (control != NULL) {
123 if (id < 0x10) {
124 control->pos.x = 0;
125 control->pos.y = -info->height;
126 z = -0x1400 - info->distance;
127 control->rot.y = 0x800;
128 control->rot.x = 0;
129 control->rot.z = 0;
130 } else {
131 control->pos.x = 0;
132 control->pos.y = -info->height;
133 z = info->distance + 0x1400;
134 control->rot.x = 0;
135 control->rot.y = 0;
136 control->rot.z = 0;
137 }
138 control->pos.z = z;
139 control->homePos = control->pos;
140 control->homeRot = control->rot;
141 }
142}
143
144/* Models.setIdleMotion */
145void FIGHTSTG_setModelIdleMotion(Models *task, s32 id, s32 motion) {
146 ModelControl *control = FIGHTSTG_getModelControl(task, id);
147
148 if (control != NULL) {
149 control->idleMotion = motion;
150 }
151}
152
153/* Creates the fighters' models (Models), with no fighters yet */
156 s32 i;
157
158 for (i = 0; i < 4; i++) {
159 task->controls[i].active = 0;
160 }
166 task->face = FIGHTSTG_faceModel;
168 return task;
169}
FighterCache FIGHTSTG_fighterCache
the fighters' data, loaded one at a time
Definition battle.c:21
#define BATTLE_TASK_MODELS
the fighters'
Definition types.h:23
#define BATTLE_LAYER_MODELS
Definition types.h:30
FIGHTSTG.PRO: the battle.
#define NULL
Definition common.h:17
signed int s32
Definition common.h:11
signed short s16
Definition common.h:9
#define TASK_RUN
Definition task.h:35
#define TASK_KILL
Definition task.h:37
#define TASK_INIT
Tasks: every game object is a task, a heap block that starts with this header and is updated once per...
Definition task.h:34
#define TASK_DONE
Definition task.h:36
Heap HEAP
The functions that return what a call left in v0 (allocMemHigh, findTask) and the ones that take othe...
Definition heap.c:184
Model * FIGHTSTG_createIdlingModel(s32 file, s32 motionFile, Vec2 texPos, ModelControl *control)
A model whose motions go back to its idle motion (FIGHTSTG_createModel): the fighters'.
Definition model_mesh.c:497
Vec2 FIGHTSTG_fighterTexPos[]
the fighters' models' texture places
Definition models.c:58
void FIGHTSTG_faceModel(Models *task, s32 id)
Models.face: puts the model registered as ID at its side's place, facing the other side,...
Definition models.c:116
ModelControl * FIGHTSTG_getModelControl(Models *task, s32 id)
Models.get: the control of the model registered as ID, or NULL.
Definition models.c:88
s32 FIGHTSTG_getModelFighter(Models *task, s32 id)
Models.getFighter: the fighter of the model registered as ID, or 0.
Definition models.c:105
Models * FIGHTSTG_createModels(void)
Creates the fighters' models (Models), with no fighters yet.
Definition models.c:154
void FIGHTSTG_addFighterModel(Models *task, s32 id, s32 fighter, s32 visible)
Models.add: replaces the model registered as ID with FIGHTER's, in a free slot with that slot's textu...
Definition models.c:64
s32 FIGHTSTG_findFreeModelSlot(Models *task)
A free fighter model slot, or -1.
Definition models.c:33
void FIGHTSTG_updateModels(Models *task)
The fighters' models' task: nothing to do but start.
Definition models.c:7
s32 FIGHTSTG_findModelSlot(Models *task, s32 id)
The slot of the fighter model registered as ID, or -1.
Definition models.c:21
void FIGHTSTG_setModelId(Models *task, s32 id, s32 newId)
Models.setId: registers the model ID as NEWID instead, removing the one that had it.
Definition models.c:99
void FIGHTSTG_removeFighterModel(Models *task, s32 id)
Models.remove: kills the model registered as ID and frees its slot.
Definition models.c:45
void FIGHTSTG_setModelIdleMotion(Models *task, s32 id, s32 motion)
Models.setIdleMotion.
Definition models.c:145
FighterInfoFuncs funcs
Definition model.h:272
FighterInfo *(* getInfo)(s32 id)
Definition model.h:258
A fighter's entry in its file, from FIGHTSTG_fighterCache.funcs.getInfo.
Definition model.h:225
s32 model
Definition model.h:226
s16 height
Definition model.h:232
s32 motions
Definition model.h:227
s16 distance
how far past 0x1400 from the middle it stands
Definition model.h:230
void(* zero)(void *ptr, s32 size)
Definition heap.h:32
What drives a Model, owned by whoever created it.
Definition model.h:99
ShortVec3 rot
Definition model.h:108
s32 active
in the Models task's list
Definition model.h:100
s32 wireframe
they are drawn as wireframe (Mesh.drawWireframe)
Definition model.h:114
s32 enabled
Definition model.h:112
ShortVec3 pos
Definition model.h:107
s32 layerId
the layer its meshes are drawn in
Definition model.h:113
s32 id
the Models task's
Definition model.h:101
ShortVec3 homeRot
Definition model.h:110
struct ModelControl::@3 layers[2]
the model is drawn once for each one enabled
ShortVec3 homePos
Definition model.h:109
s32 motion
the motion to play
Definition model.h:102
s32 fighter
the Models task's
Definition model.h:105
s32 idleMotion
Definition model.h:106
void(* setState)(struct Model *task, s32 state)
Definition model.h:133
The Models task's children: a removed model stays until it is gone.
Definition model.h:277
Model * dying[4]
Definition model.h:279
Model * models[4]
Definition model.h:278
The fighters' models (FIGHTSTG_createModels), registered as BATTLE_TASK_MODELS: up to four,...
Definition model.h:284
void(* remove)(struct Models *task, s32 id)
Definition model.h:287
void(* setId)(struct Models *task, s32 id, s32 newId)
Definition model.h:290
void(* setIdleMotion)(struct Models *task, s32 id, s32 motion)
Definition model.h:293
void(* face)(struct Models *task, s32 id)
ids under 0x10 are one side
Definition model.h:292
void * children
Definition model.h:285
ModelControl controls[4]
Definition model.h:286
void(* add)(struct Models *task, s32 id, s32 fighter, s32 visible)
Definition model.h:288
void(* nextState)(struct Models *task)
Definition model.h:285
s32 state
Definition model.h:285
s32(* getFighter)(struct Models *task, s32 id)
Definition model.h:291
ModelControl *(* get)(struct Models *task, s32 id)
Definition model.h:289
s16 x
Definition model.h:15
s16 z
Definition model.h:17
s16 y
Definition model.h:16
Definition gfx.h:352
void * createTaskWithId(void(*update)(), s32 size, s32 childrenSize, s32 id)
Allocates a zeroed task of size bytes (header included) with room for childrenSize / 4 child tasks.
Definition task.c:80