Mercurial > MadButterfly
annotate src/mbaf/mbapp.c @ 1022:84006acab6af refine_backend_if
Use macros to hide the default backend
author | Thinker K.F. Li <thinker@codemud.net> |
---|---|
date | Mon, 22 Nov 2010 15:20:11 +0800 |
parents | 8c556e0839eb |
children |
rev | line source |
---|---|
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
462
diff
changeset
|
1 // -*- indent-tabs-mode: t; tab-width: 8; c-basic-offset: 4; -*- |
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
462
diff
changeset
|
2 // vim: sw=4:ts=8:sts=4 |
294 | 3 #include <mb.h> |
456
26c302b47de1
Change name of header files.
Thinker K.F. Li <thinker@branda.to>
parents:
454
diff
changeset
|
4 #include <mb_af.h> |
993
5b58e74988bc
Use mb_backend_t::new instead of mb_backend_t::init
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
5 #include <mb_backend.h> |
454
9b8dda201ccb
Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
453
diff
changeset
|
6 |
9b8dda201ccb
Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
453
diff
changeset
|
7 mbaf_t *mbaf_init(const char *module, const char *module_dir) |
294 | 8 { |
454
9b8dda201ccb
Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
453
diff
changeset
|
9 mbaf_t *app = (mbaf_t *) malloc(sizeof(mbaf_t)); |
993
5b58e74988bc
Use mb_backend_t::new instead of mb_backend_t::init
Thinker K.F. Li <thinker@codemud.net>
parents:
822
diff
changeset
|
10 mb_rt_t *rt; |
294 | 11 |
1022
84006acab6af
Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents:
995
diff
changeset
|
12 rt = mb_runtime_new(":0.0", 800, 600); |
453
84ce2d4a8c3f
Change interface of sprite loader.
Thinker K.F. Li <thinker@branda.to>
parents:
296
diff
changeset
|
13 if(rt == NULL) |
84ce2d4a8c3f
Change interface of sprite loader.
Thinker K.F. Li <thinker@branda.to>
parents:
296
diff
changeset
|
14 return NULL; |
84ce2d4a8c3f
Change interface of sprite loader.
Thinker K.F. Li <thinker@branda.to>
parents:
296
diff
changeset
|
15 |
84ce2d4a8c3f
Change interface of sprite loader.
Thinker K.F. Li <thinker@branda.to>
parents:
296
diff
changeset
|
16 sprite_set_search_path(module_dir); |
294 | 17 |
18 app->rt = rt; | |
1022
84006acab6af
Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents:
995
diff
changeset
|
19 app->rdman = mb_runtime_rdman(rt); |
84006acab6af
Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents:
995
diff
changeset
|
20 app->kbevents = mb_runtime_kbevents(rt); |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
462
diff
changeset
|
21 |
294 | 22 app->rootsprite= sprite_load(module,app->rdman, app->rdman->root_coord); |
453
84ce2d4a8c3f
Change interface of sprite loader.
Thinker K.F. Li <thinker@branda.to>
parents:
296
diff
changeset
|
23 if(app->rootsprite == NULL) { |
1022
84006acab6af
Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents:
995
diff
changeset
|
24 mb_runtime_free(rt); |
453
84ce2d4a8c3f
Change interface of sprite loader.
Thinker K.F. Li <thinker@branda.to>
parents:
296
diff
changeset
|
25 free(app); |
84ce2d4a8c3f
Change interface of sprite loader.
Thinker K.F. Li <thinker@branda.to>
parents:
296
diff
changeset
|
26 return NULL; |
84ce2d4a8c3f
Change interface of sprite loader.
Thinker K.F. Li <thinker@branda.to>
parents:
296
diff
changeset
|
27 } |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
462
diff
changeset
|
28 |
294 | 29 rdman_attach_backend(app->rdman, rt); |
30 MB_SPRITE_GOTO_SCENE(app->rootsprite, 1); | |
822
586e50f82c1f
Unify coding style tag for emacs and vim.
Shih-Yuan Lee (FourDollars) <fourdollars@gmail.com>
parents:
462
diff
changeset
|
31 |
294 | 32 return app; |
33 } | |
34 | |
454
9b8dda201ccb
Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
453
diff
changeset
|
35 void mbaf_set_data(mbaf_t *app,void *data) |
294 | 36 { |
37 app->private = (void *) data; | |
38 } | |
39 | |
994
5d9def42df12
Rename mb_backend_t::tman() to mb_backend_t::timer_man()
Thinker K.F. Li <thinker@codemud.net>
parents:
993
diff
changeset
|
40 mb_timer_man_t *mbaf_get_timer(mbaf_t *app) |
294 | 41 { |
1022
84006acab6af
Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents:
995
diff
changeset
|
42 return mb_runtime_timer_man(app->rt); |
294 | 43 } |
44 | |
454
9b8dda201ccb
Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
453
diff
changeset
|
45 void mbaf_loop(mbaf_t *app) |
294 | 46 { |
47 /* | |
48 * Start handle connections, includes one to X server. | |
49 * User start to interact with the application. | |
50 */ | |
1022
84006acab6af
Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents:
995
diff
changeset
|
51 mb_runtime_event_loop(app->rt); |
294 | 52 |
53 /* | |
54 * Clean | |
55 */ | |
1022
84006acab6af
Use macros to hide the default backend
Thinker K.F. Li <thinker@codemud.net>
parents:
995
diff
changeset
|
56 mb_runtime_free(app->rt); |
454
9b8dda201ccb
Make naming convention consistent with MadButterfly.
Thinker K.F. Li <thinker@branda.to>
parents:
453
diff
changeset
|
57 free(app); |
294 | 58 } |