annotate src/mbaf/mbapp.c @ 1111:fa5f71d4aa04

console backend
author Thinker K.F. Li <thinker@codemud.net>
date Wed, 08 Dec 2010 18:59:44 +0800
parents 84006acab6af
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
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
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
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
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
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
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
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
17
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
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
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
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
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
29 rdman_attach_backend(app->rdman, rt);
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
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
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
32 return app;
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
33 }
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
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
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
36 {
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
37 app->private = (void *) data;
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
38 }
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
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
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
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
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
43 }
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
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
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
46 {
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
47 /*
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
48 * Start handle connections, includes one to X server.
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
49 * User start to interact with the application.
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
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
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
52
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
53 /*
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
54 * Clean
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
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
2ca0773cd48d * Add MBAF files
wycc
parents:
diff changeset
58 }