Stage loader checks for errors now. New file format defined.
[cantaveria.git] / kernel.c
blob59aaccda29c3c63e4ef0545a0e10d997e8a183c9
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 <util.h>
28 #include <root.h>
29 #include <boot.h>
31 #include <video.h>
32 #include <input.h>
34 #include <console.h>
35 #include <graphics.h> // ?
37 #include <gameover.h>
38 #include <transfer.h>
39 #include <kernel.h>
41 int dt = QUANTUM; /* this is a global variable */
43 static struct {
44 void (*update)();
45 void (*draw)();
46 void (*press)(input in);
47 void (*release)(input in);
48 } handler;
51 static void terminate(){
52 loader_quit();
53 audio_quit();
54 video_quit();
57 static void press(input in){ handler.press(in); }
58 static void release(input in){ handler.release(in); }
60 void dispatch_error(const char* msg){
61 error_msg("kernel.c dispatch_input: %s\n", msg);
64 static void dispatch_input(){
65 input in = get_input();
66 while(in.type != NO_INPUT){
67 switch(in.type){
68 case BUTTON_PRESS: press(in); break;
69 case BUTTON_RELEASE: release(in); break;
70 case END_OF_PROGRAM: game_is_over(); break;
71 case SKIP_INPUT: dispatch_error("SKIP_INPUT is not supposed to come from generator"); break;
72 case INVALID_INPUT: dispatch_error("INVALID_INPUT produced in generator"); break;
73 case NO_INPUT: dispatch_error("NO_INPUT is impossible here"); break;
75 in = get_input();
79 void initialize(int argc, char* argv[]){
80 video_init(argc, argv);
81 seq_init();
82 synth_init();
83 audio_init();
84 input_init("FIXME");
85 loader_init();
86 graphics_init();
87 text_init();
88 stage_init();
89 rand_reset(RANDOM_SEED);
91 atexit(terminate);
93 setup_splash();
96 void update(){
97 dispatch_input();
98 fps_update();
99 // console_clear();
100 animate_sprites();
101 handler.update();
104 void draw(){
105 handler.draw();
106 console_draw();
107 draw_final();
110 void set_handler(
111 void (*update)(),
112 void (*draw)(),
113 void (*press)(input in),
114 void (*release)(input in)
116 handler.update = update;
117 handler.draw = draw;
118 handler.press = press;
119 handler.release = release;