Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
task.c
Go to the documentation of this file.
1#include "engine/game.h"
2#include <libgs.h>
3#include <libetc.h>
4#include <libsnd.h>
5
6/* Task method: goes to state `state`, from substate 0 */
7void taskSetState(Task *task, s32 state) {
8 task->state = state;
9 task->substate = 0;
10 task->step = 0;
11 task->counter = 0;
12}
13
14/* Task method: goes to substate `substate`, from step 0 */
15void taskSetSubstate(Task *task, s32 substate) {
16 task->substate = substate;
17 task->step = 0;
18 task->counter = 0;
19}
20
21/* Task method: goes to step `step`, with its counter at 0 */
22void taskSetStep(Task *task, s32 step) {
23 task->step = step;
24 task->counter = 0;
25}
26
27/* Task method: sets the counter */
28void taskSetCounter(Task *task, s32 counter) {
29 task->counter = counter;
30}
31
32/* Task method: goes to the next state, from substate 0 */
33void taskNextState(Task *task) {
34 task->substate = 0;
35 task->step = 0;
36 task->counter = 0;
37 task->state++;
38}
39
40/* Task method: goes to the next substate, from step 0 */
42 task->step = 0;
43 task->counter = 0;
44 task->substate++;
45}
46
47/* Task method: goes to the next step, with its counter at 0 */
48void taskNextStep(Task *task) {
49 task->counter = 0;
50 task->step++;
51}
52
53/* Task method: counts one more */
54void taskTickCounter(Task *task) {
55 task->counter++;
56}
57
58/* Default destructor: kills the children, then frees the task */
59void destroyTask(Task *task) {
60 s32 i;
61 Task **children;
62
63 if (task->childCount != 0) {
64 children = task->children;
65 for (i = 0; i < task->childCount; i++) {
66 if (children[i] != NULL) {
67 TASK_REGISTRY.funcs.kill(children[i]);
68 }
69 }
70 HEAP.free(task->children);
71 }
73 HEAP.free(task);
74}
75
76/*
77 * Allocates a zeroed task of `size` bytes (header included) with room for
78 * childrenSize / 4 child tasks. A nonzero id also registers it (findTask).
79 */
80void *createTaskWithId(void (*update)(), s32 size, s32 childrenSize, s32 id) {
81 Task *task = HEAP.allocZeroed(size, MEM_MODE);
82
83 if (childrenSize != 0) {
84 task->children = HEAP.allocZeroed(childrenSize, MEM_MODE);
85 task->childCount = childrenSize / 4;
86 }
87 task->setState = taskSetState;
89 task->setStep = taskSetStep;
93 task->nextStep = taskNextStep;
95 task->update = update;
96 task->destroy = destroyTask;
97 if (id != 0) {
98 task->id = id;
100 }
101 return task;
102}
103
104/* createTaskWithId for a task nothing needs to find */
105void *createTask(void (*update)(), s32 size, s32 childrenSize) {
106 return createTaskWithId(update, size, childrenSize, 0);
107}
#define NULL
Definition common.h:17
signed int s32
Definition common.h:11
Heap HEAP
The functions that return what a call left in v0 (allocMemHigh, findTask) and the ones that take othe...
Definition heap.c:184
#define MEM_MODE
the current mode's: freed by main whenever the mode task ends
Definition heap.h:17
TaskRegistry TASK_REGISTRY
Definition registry.c:122
void *(* allocZeroed)(s32 size, s32 tag)
Definition heap.h:31
void(* free)(void *ptr)
Definition heap.h:27
void(* remove)(struct Task *task)
Definition task.h:17
void(* kill)(struct Task *task)
Definition task.h:22
void(* add)(struct Task *task)
Definition task.h:16
TaskFuncs funcs
Definition task.h:76
Any task, seen through its header.
Definition task.h:62
void(* setCounter)(struct Task *task, s32 counter)
Definition task.h:63
void(* setSubstate)(struct Task *task, s32 substate)
Definition task.h:63
void(* destroy)(struct Task *task)
Definition task.h:63
void(* setState)(struct Task *task, s32 state)
Definition task.h:63
s32 id
Definition task.h:63
s32 counter
Definition task.h:63
s32 childCount
Definition task.h:63
void(* nextSubstate)(struct Task *task)
Definition task.h:63
void(* update)()
Definition task.h:63
s32 substate
Definition task.h:63
void(* nextState)(struct Task *task)
Definition task.h:63
void(* nextStep)(struct Task *task)
Definition task.h:63
s32 state
Definition task.h:63
void * children
Definition task.h:63
void(* setStep)(struct Task *task, s32 step)
Definition task.h:63
s32 step
Definition task.h:63
void(* tickCounter)(struct Task *task)
Definition task.h:63
void taskNextStep(Task *task)
Task method: goes to the next step, with its counter at 0.
Definition task.c:48
void * createTask(void(*update)(), s32 size, s32 childrenSize)
createTaskWithId for a task nothing needs to find
Definition task.c:105
void taskTickCounter(Task *task)
Task method: counts one more.
Definition task.c:54
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
void destroyTask(Task *task)
Default destructor: kills the children, then frees the task.
Definition task.c:59
void taskSetCounter(Task *task, s32 counter)
Task method: sets the counter.
Definition task.c:28
void taskSetState(Task *task, s32 state)
Task method: goes to state state, from substate 0.
Definition task.c:7
void taskSetStep(Task *task, s32 step)
Task method: goes to step step, with its counter at 0.
Definition task.c:22
void taskSetSubstate(Task *task, s32 substate)
Task method: goes to substate substate, from step 0.
Definition task.c:15
void taskNextState(Task *task)
Task method: goes to the next state, from substate 0.
Definition task.c:33
void taskNextSubstate(Task *task)
Task method: goes to the next substate, from step 0.
Definition task.c:41