Paper Mario DX
Paper Mario (N64) modding
 
Loading...
Searching...
No Matches
worker.c
Go to the documentation of this file.
1#include "common.h"
2
6
9
11 s32 i;
12
15 } else {
17 }
18
19 for (i = 0; i < MAX_WORKERS; i++) {
20 (*gCurrentWorkerListPtr)[i] = NULL;
21 }
22}
23
31
32s32 create_worker_world(void (*updateFunc)(void), void (*drawFunc)(void)) {
33 Worker* worker;
34 s32 i;
35
36 for (i = 0; i < MAX_WORKERS; i++) {
37 Worker* lastWorker = (*gCurrentWorkerListPtr)[i];
38 if (lastWorker == NULL) {
39 break;
40 }
41 }
43
44 (*gCurrentWorkerListPtr)[i] = worker = heap_malloc(sizeof(*worker));
45 ASSERT(worker != NULL);
46
48 worker->update = updateFunc;
49 if (updateFunc == NULL) {
51 }
52 worker->draw = drawFunc;
53 if (drawFunc == NULL) {
55 }
56
59 }
60 return i;
61}
62
63s32 create_worker_frontUI(void (*updateFunc)(void), void (*drawFunc)(void)) {
64 Worker* worker;
65 s32 i;
66
67 for (i = 0; i < MAX_WORKERS; i++) {
68 Worker* lastWorker = (*gCurrentWorkerListPtr)[i];
69 if (lastWorker == NULL) {
70 break;
71 }
72 }
74
75 (*gCurrentWorkerListPtr)[i] = worker = heap_malloc(sizeof(*worker));
76 ASSERT(worker != NULL);
77
79 worker->update = updateFunc;
80 if (updateFunc == NULL) {
82 }
83 worker->draw = drawFunc;
84 if (drawFunc == NULL) {
86 }
87
90 }
91 return i;
92}
93
94s32 create_worker_backUI(void (*updateFunc)(void), void (*drawFunc)(void)) {
95 Worker* worker;
96 s32 i;
97
98 for (i = 0; i < MAX_WORKERS; i++) {
99 Worker* lastWorker = (*gCurrentWorkerListPtr)[i];
100 if (lastWorker == NULL) {
101 break;
102 }
103 }
104 ASSERT(i < MAX_WORKERS);
105
106 (*gCurrentWorkerListPtr)[i] = worker = heap_malloc(sizeof(*worker));
107 ASSERT(worker != NULL);
108
110 worker->update = updateFunc;
111 if (updateFunc == NULL) {
113 }
114 worker->draw = drawFunc;
115 if (drawFunc == NULL) {
117 }
118
121 }
122 return i;
123}
124
125void update_workers(void) {
126 s32 i;
127
128 for (i = 0; i < MAX_WORKERS; i++) {
129 Worker* worker = (*gCurrentWorkerListPtr)[i];
130 if (worker != NULL) {
131 worker->flags &= ~WORKER_FLAG_SKIP_DRAW_UNTIL_UPDATE;
132 worker->update();
133 }
134 }
135}
136
138 s32 i;
139
140 for (i = 0; i < MAX_WORKERS; i++) {
141 Worker* worker = (*gCurrentWorkerListPtr)[i];
142 if (worker != NULL && !(worker->flags & WORKER_FLAG_SKIP_DRAW_UNTIL_UPDATE)) {
143 if (!(worker->flags & WORKER_FLAG_FRONT_UI)) {
144 worker->draw();
145 }
146 }
147 }
148}
149
151 s32 i;
152
153 for (i = 0; i < MAX_WORKERS; i++) {
154 Worker* worker = (*gCurrentWorkerListPtr)[i];
155 if (worker != NULL && !(worker->flags & WORKER_FLAG_SKIP_DRAW_UNTIL_UPDATE)) {
156 if (worker->flags & WORKER_FLAG_FRONT_UI) {
157 worker->draw();
158 }
159 }
160 }
161}
162
164 s32 i;
165
166 for (i = 0; i < MAX_WORKERS; i++) {
167 Worker* worker = (*gCurrentWorkerListPtr)[i];
168 if (worker != NULL && !(worker->flags & WORKER_FLAG_SKIP_DRAW_UNTIL_UPDATE)) {
169 if (worker->flags & WORKER_FLAG_BACK_UI) {
170 worker->draw();
171 }
172 }
173 }
174}
175
176void free_worker(s32 idx) {
178 idx &= ~BATTLE_ENTITY_ID_BIT;
179 if ((*gCurrentWorkerListPtr)[idx] != NULL) {
181 (*gCurrentWorkerListPtr)[idx] = NULL;
182 }
183 }
184}
185
187 return (*gCurrentWorkerListPtr)[idx & ~BATTLE_ENTITY_ID_BIT];
188}
Worker * WorkerList[16]
#define ASSERT(condition)
@ WORKER_FLAG_FRONT_UI
Definition enums.h:2772
@ WORKER_FLAG_BACK_UI
Definition enums.h:2773
@ WORKER_FLAG_1
Definition enums.h:2770
@ WORKER_FLAG_SKIP_DRAW_UNTIL_UPDATE
Definition enums.h:2771
@ CONTEXT_WORLD
Definition enums.h:3529
s32 heap_free(void *ptr)
Definition heap.c:42
void * heap_malloc(s32 size)
Definition heap.c:34
#define BSS
Definition macros.h:7
#define BATTLE_ENTITY_ID_BIT
Definition macros.h:146
#define MAX_WORKERS
Definition macros.h:95
void(* draw)(void)
void(* update)(void)
GameStatus * gGameStatusPtr
Definition main_loop.c:32
Worker * get_worker(s32 idx)
Definition worker.c:186
void render_workers_frontUI(void)
Definition worker.c:150
s32 create_worker_backUI(void(*updateFunc)(void), void(*drawFunc)(void))
Definition worker.c:94
void worker_delegate_do_nothing(void)
Definition worker.c:7
void render_workers_backUI(void)
Definition worker.c:163
void render_workers_world(void)
Definition worker.c:137
void clear_worker_list(void)
Definition worker.c:10
BSS WorkerList gWorldWorkerList
Definition worker.c:3
s32 create_worker_world(void(*updateFunc)(void), void(*drawFunc)(void))
Definition worker.c:32
BSS WorkerList * gCurrentWorkerListPtr
Definition worker.c:5
void free_worker(s32 idx)
Definition worker.c:176
s32 create_worker_frontUI(void(*updateFunc)(void), void(*drawFunc)(void))
Definition worker.c:63
void update_workers(void)
Definition worker.c:125
void init_worker_list(void)
Definition worker.c:24
BSS WorkerList gBattleWorkerList
Definition worker.c:4