Fixed another bug in output level.
[cantaveria.git] / kernel.c
blob376cb716c469a9c41dfab890532c66a69d17e43f
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>
36 #include <util.h>
38 #include <kernel.h>
39 #include <transfer.h>
41 int game_over = false;
42 int dt = QUANTUM;
44 static struct {
45 void (*update)();
46 void (*draw)();
47 void (*press)(input in);
48 void (*release)(input in);
49 } handler;
52 static void terminate(){
53 loader_quit();
54 audio_quit();
55 video_quit();
58 static void press(input in){ handler.press(in); }
59 static void release(input in){ handler.release(in); }
61 void dispatch_error(const char* msg){
62 error_msg("kernel.c dispatch_input: %s\n", msg);
65 static void dispatch_input(){
66 input in = get_input();
67 while(in.type != NO_INPUT){
68 switch(in.type){
69 case BUTTON_PRESS: press(in); break;
70 case BUTTON_RELEASE: release(in); break;
71 case END_OF_PROGRAM: game_is_over(); break;
72 case SKIP_INPUT: dispatch_error("SKIP_INPUT is not supposed to come from generator"); break;
73 case INVALID_INPUT: dispatch_error("INVALID_INPUT produced in generator"); break;
74 case NO_INPUT: dispatch_error("NO_INPUT is impossible here"); break;
76 in = get_input();
80 void initialize(int argc, char* argv[]){
81 video_init(argc, argv);
82 audio_init();
83 input_init("FIXME");
84 loader_init();
85 graphics_init();
86 text_init();
87 rand_reset(RANDOM_SEED);
88 atexit(terminate);
90 setup_splash();
93 void update(){
94 dispatch_input();
95 fps_update();
96 // console_clear();
97 animate_sprites();
98 handler.update();
101 void draw(){
102 handler.draw();
103 draw_final();
106 void game_is_over(){
107 game_over = true;
110 int is_game_over(){
111 return game_over;
114 void set_handler(
115 void (*update)(),
116 void (*draw)(),
117 void (*press)(input in),
118 void (*release)(input in)
120 handler.update = update;
121 handler.draw = draw;
122 handler.press = press;
123 handler.release = release;