Rearranged root headers somewhat.
[cantaveria.git] / kernel.c
blob3f114a875eb7a96909eb0eb7241f8731edaf5f12
1 /*
2 Cantaveria - action adventure platform game
3 Copyright (C) 2009 2010 Evan Rinehart
5 This program is free software; you can redistribute it and/or
6 modify it under the terms of the GNU General Public License
7 as published by the Free Software Foundation; either version 2
8 of the License, or (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to
18 The Free Software Foundation, Inc.
19 51 Franklin Street, Fifth Floor
20 Boston, MA 02110-1301, USA
22 evanrinehart@gmail.com
24 #include <stdlib.h>
26 #include <list.h>
27 #include <root.h>
28 #include <video.h>
29 #include <audio.h>
30 #include <input.h>
32 #include <loader.h>
33 #include <graphics.h>
34 #include <text.h>
35 #include <stage.h>
37 #include <util.h>
39 #include <kernel.h>
40 #include <transfer.h>
41 #include <gameover.h>
43 int dt = QUANTUM;
45 static struct {
46 void (*update)();
47 void (*draw)();
48 void (*press)(input in);
49 void (*release)(input in);
50 } handler;
53 static void terminate(){
54 loader_quit();
55 audio_quit();
56 video_quit();
59 static void press(input in){ handler.press(in); }
60 static void release(input in){ handler.release(in); }
62 void dispatch_error(const char* msg){
63 error_msg("kernel.c dispatch_input: %s\n", msg);
66 static void dispatch_input(){
67 input in = get_input();
68 while(in.type != NO_INPUT){
69 switch(in.type){
70 case BUTTON_PRESS: press(in); break;
71 case BUTTON_RELEASE: release(in); break;
72 case END_OF_PROGRAM: game_is_over(); break;
73 case SKIP_INPUT: dispatch_error("SKIP_INPUT is not supposed to come from generator"); break;
74 case INVALID_INPUT: dispatch_error("INVALID_INPUT produced in generator"); break;
75 case NO_INPUT: dispatch_error("NO_INPUT is impossible here"); break;
77 in = get_input();
81 void initialize(int argc, char* argv[]){
82 video_init(argc, argv);
83 audio_init();
84 input_init("FIXME");
85 loader_init();
86 graphics_init();
87 text_init();
88 stage_init();
89 rand_reset(RANDOM_SEED);
90 atexit(terminate);
92 setup_splash();
95 void update(){
96 dispatch_input();
97 fps_update();
98 // console_clear();
99 animate_sprites();
100 handler.update();
103 void draw(){
104 handler.draw();
105 draw_final();
108 void set_handler(
109 void (*update)(),
110 void (*draw)(),
111 void (*press)(input in),
112 void (*release)(input in)
114 handler.update = update;
115 handler.draw = draw;
116 handler.press = press;
117 handler.release = release;