12 #include "arenaFile.h"
14 #include "shareFunction.h"
17 #include "interface.h"
20 #include "configFile.h"
21 #endif /* PUBLIC_SERVER */
23 static export_fce_t export_fce
= {
25 .fce_addLayer
= addLayer
,
26 .fce_image_get
= image_get
,
27 #endif /* PUBLIC_SERVER */
28 .fce_module_load_dep
= module_load_dep
,
29 .fce_share_function_add
= share_function_add
,
30 .fce_share_function_get
= share_function_get
,
32 .fce_getValue
= arena_file_get_value
,
33 .fce_net_multiplayer_get_game_type
= net_multiplayer_get_game_type
,
34 .fce_tux_get_proportion
= tux_get_proportion
,
35 .fce_tux_set_proportion
= tux_set_proportion
,
36 .fce_tux_action
= tux_action
,
38 .fce_timer_get_current_time
= timer_get_current_time
,
40 .fce_arena_get_current
= arena_get_current
,
41 .fce_arena_conflict_space
= arena_conflict_space
,
42 .fce_arena_is_free_space
= arena_is_free_space
,
43 .fce_arena_find_free_space
= arena_find_free_space
,
45 .fce_proto_send_module_server
= proto_send_module_server
,
46 .fce_proto_send_del_server
= proto_send_del_server
,
48 .fce_proto_send_module_client
= proto_send_module_client
,
49 #endif /* PUBLIC_SERVER */
50 .fce_shot_destroy
= shot_destroy
,
51 .fce_shot_bound_bombBall
= shot_bound_bombBall
,
52 .fce_shot_transform_lasser
= shot_transform_lasser
55 static list_t
*listModule
;
56 static mod_reg_t mod_reglist
;
58 /* register module as valid */
59 static mod_reg_t
*mod_register(char *name
, mod_sym_t
*sym
)
61 /* alloc and init context */
62 mod_reg_t
*mod
= (mod_reg_t
*) malloc(sizeof(mod_reg_t
));
68 mod
->name
= strdup(name
);
71 /* add entry into list */
72 mod
->next
= &mod_reglist
;
73 mod
->prev
= mod_reglist
.prev
;
74 mod
->prev
->next
= mod
;
75 mod
->next
->prev
= mod
;
80 /* free all unnecessary memory blocks from module's reglist */
81 static void mod_destroy()
88 for (mod
= mod_reglist
.next
; mod
!= &mod_reglist
; mod
= mod
->next
) {
89 /* delete entry from context */
90 mod
->next
->prev
= mod
->prev
;
91 mod
->prev
->next
= mod
->next
;
107 static mod_reg_t
*mod_find(char *name
)
110 for (mod
= mod_reglist
.next
; mod
!= &mod_reglist
; mod
= mod
->next
) {
111 if (!strcmp(mod
->name
, name
)) {
119 static module_t
*newModule(char *name
)
121 assert(name
!= NULL
);
123 mod_reg_t
*mod
= mod_find(name
);
126 error("Module [%s] is unavailable", name
);
130 module_t
*ret
= malloc(sizeof(module_t
));
136 ret
->name
= strdup(name
);
143 ret
->fce_init
= mod
->sym
->init
;
144 #ifndef PUBLIC_SERVER
145 ret
->fce_draw
= mod
->sym
->draw
;
146 #endif /* PUBLIC_SERVER */
147 ret
->fce_event
= mod
->sym
->event
;
148 ret
->fce_destroy
= mod
->sym
->destroy
;
149 ret
->fce_isConflict
= mod
->sym
->isConflict
;
150 ret
->fce_cmd
= mod
->sym
->cmdArena
;
151 ret
->fce_recvMsg
= mod
->sym
->recvMsg
;
153 debug("Loading module [%s]", name
);
155 if (ret
->fce_init(&export_fce
) != 0) {
156 error("Unable to load module [%s]", name
);
165 static int destroyModule(module_t
*p
)
169 debug("Unloading module [%s]", p
->name
);
181 listModule
= list_new();
182 share_function_init();
184 mod_reglist
.next
= &mod_reglist
;
185 mod_reglist
.prev
= &mod_reglist
;
187 mod_register("libmodAI", &modai_sym
);
188 mod_register("libmodWall", &modwall_sym
);
189 mod_register("libmodPipe", &modpipe_sym
);
190 mod_register("libmodMove", &modmove_sym
);
191 mod_register("libmodBasic", &modbasic_sym
);
192 mod_register("libmodTeleport", &modteleport_sym
);
195 int isModuleLoaded(char *name
)
199 for (i
= 0; i
< listModule
->count
; i
++) {
202 this = (module_t
*) listModule
->list
[i
];
204 if (strcmp(this->name
, name
) == 0) {
212 int module_load(char *name
)
216 if (isModuleLoaded(name
)) {
217 error("Unable to load already loaded module [%s]", name
);
221 module
= newModule(name
);
223 if (module
== NULL
) {
224 error("Unable to load module [%s]", name
);
228 list_add(listModule
, module
);
233 int module_load_dep(char *name
)
235 if (isModuleLoaded(name
)) {
239 return module_load(name
);
242 void module_cmd(char *s
)
246 for (i
= 0; i
< listModule
->count
; i
++) {
249 this = (module_t
*) listModule
->list
[i
];
254 #ifndef PUBLIC_SERVER
255 void module_draw(int x
, int y
, int w
, int h
)
259 for (i
= 0; i
< listModule
->count
; i
++) {
262 this = (module_t
*) listModule
->list
[i
];
263 this->fce_draw(x
, y
, w
, h
);
266 #endif /* PUBLIC_SERVER */
272 for (i
= 0; i
< listModule
->count
; i
++) {
275 this = (module_t
*) listModule
->list
[i
];
280 int module_is_conflict(int x
, int y
, int w
, int h
)
284 for (i
= 0; i
< listModule
->count
; i
++) {
287 this = (module_t
*) listModule
->list
[i
];
289 if (this->fce_isConflict(x
, y
, w
, h
) == 1) {
297 int module_recv_msg(char *msg
)
301 for (i
= 0; i
< listModule
->count
; i
++) {
304 this = (module_t
*) listModule
->list
[i
];
305 this->fce_recvMsg(msg
);
313 list_destroy_item(listModule
, destroyModule
);
314 share_function_quit();