rev |
line source |
nuclear@0
|
1 #ifndef RESOURCE_MANAGER_H_
|
nuclear@0
|
2 #define RESOURCE_MANAGER_H_
|
nuclear@0
|
3
|
nuclear@0
|
4 /* TODO API */
|
nuclear@0
|
5
|
nuclear@0
|
6 /* usage example:
|
nuclear@0
|
7 int texload(const char *fname, void *cls)
|
nuclear@0
|
8 {
|
nuclear@0
|
9 // open image, parse data ...
|
nuclear@0
|
10 }
|
nuclear@0
|
11
|
nuclear@0
|
12 struct resman rman;
|
nuclear@0
|
13
|
nuclear@0
|
14 resman_init(&rman);
|
nuclear@0
|
15 resman_set_load_func(&rman, texload, 0);
|
nuclear@0
|
16 resman_set_done_func(&rman, texload_done, 0);
|
nuclear@0
|
17 ...
|
nuclear@0
|
18
|
nuclear@0
|
19 struct texture *tex;
|
nuclear@0
|
20 struct resman_job *rjob;
|
nuclear@0
|
21
|
nuclear@0
|
22 rjob = resman_get(&rman, "tex.png", 0);
|
nuclear@0
|
23 ...
|
nuclear@0
|
24 resman_wait_job(&rman, rjob);
|
nuclear@0
|
25 tex = resman_get_job_data(rjob);
|
nuclear@0
|
26 resman_free_job(&rman, rjob);
|
nuclear@0
|
27
|
nuclear@0
|
28 ...
|
nuclear@0
|
29 resman_destroy(&rman);
|
nuclear@0
|
30 */
|
nuclear@0
|
31
|
nuclear@0
|
32 struct resman;
|
nuclear@0
|
33
|
nuclear@0
|
34 typedef int (*resman_load_func_t)(const char *fname, void *cls);
|
nuclear@0
|
35 typedef void (*resman_done_func_t)(int status, void *cls);
|
nuclear@0
|
36
|
nuclear@0
|
37
|
nuclear@0
|
38 int resman_init(struct resman *rman);
|
nuclear@0
|
39 void resman_destroy(struct resman *rman);
|
nuclear@0
|
40
|
nuclear@0
|
41 /* The load callback will be called to load a data file. It may be called in the
|
nuclear@0
|
42 * context of a different loading thread.
|
nuclear@0
|
43 */
|
nuclear@0
|
44 void resman_set_load_func(struct resman *rman, resman_load_func_t func, void *cls);
|
nuclear@0
|
45
|
nuclear@0
|
46 /* The "done" callback will be called in the context of the main thread, whenever a
|
nuclear@0
|
47 * file was sucessfully loaded, or an error occured.
|
nuclear@0
|
48 * It's first argument (status) is set to whatever the load function returned, and its
|
nuclear@0
|
49 * closure pointer is the closure
|
nuclear@0
|
50 */
|
nuclear@0
|
51 void resman_set_done_func(struct resman *rman, resman_done_func_t func);
|
nuclear@0
|
52
|
nuclear@0
|
53 #endif /* RESOURCE_MANAGER_H_ */
|