1 /* Copyright (C) 2020 SovietPony
3 * This program is free software: you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License as published by
5 * the Free Software Foundation, version 3 of the License ONLY.
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 # include <emscripten.h>
22 #include <stdlib.h> // srand exit
28 #include "player.h" // pl1 pl2
29 #include "menu.h" // G_keyf
30 #include "error.h" // logo
31 #include "monster.h" // nomon
33 #include "files.h" // F_startup F_addwad F_initwads F_allocres
34 #include "config.h" // CFG_args CFG_load CFG_save
35 #include "args.h" // ARG_parse
36 #include "memory.h" // M_startup
37 #include "game.h" // G_init G_act
38 #include "sound.h" // S_init S_done
39 #include "music.h" // S_initmusic S_updatemusic S_donemusic
40 #include "render.h" // R_init R_draw R_done
44 #define MODE_SOFTWARE 2
48 static int mode
= MODE_NONE
;
49 static int text_input
= 0;
51 static int height
= 0;
52 static int fullscreen
= 0;
53 static void *softbuffer
= NULL
;
54 static videomode_size_t vsize
= { 320, 200, 0 };
55 static videomode_t vlist
= { 1, &vsize
};
57 static const cfg_t arg
[] = {
58 {"file", NULL
, Y_FILES
},
59 {"cheat", &cheat
, Y_SW_ON
},
60 // {"vga", &shot_vga, Y_SW_ON},
61 // {"musvol", &mus_vol, Y_WORD},
62 {"mon", &nomon
, Y_SW_OFF
},
63 {"warp", &_warp
, Y_BYTE
},
64 // {"config", NULL, cfg_file, Y_STRING},
65 {NULL
, NULL
, 0} // end
68 static const cfg_t cfg
[] = {
69 // {"screenshot", &shot_vga, Y_SW_ON},
70 // {"music_volume", &mus_vol, Y_WORD},
71 // {"music_random", &music_random, Y_SW_ON},
72 // {"music_time", &music_time, Y_DWORD},
73 // {"music_fade", &music_fade, Y_DWORD},
74 {"pl1_left", &pl1
.kl
, Y_KEY
},
75 {"pl1_right",&pl1
.kr
, Y_KEY
},
76 {"pl1_up", &pl1
.ku
, Y_KEY
},
77 {"pl1_down", &pl1
.kd
, Y_KEY
},
78 {"pl1_jump", &pl1
.kj
, Y_KEY
},
79 {"pl1_fire", &pl1
.kf
, Y_KEY
},
80 {"pl1_next", &pl1
.kwr
, Y_KEY
},
81 {"pl1_prev", &pl1
.kwl
, Y_KEY
},
82 {"pl1_use", &pl1
.kp
, Y_KEY
},
83 {"pl2_left", &pl2
.kl
, Y_KEY
},
84 {"pl2_right", &pl2
.kr
, Y_KEY
},
85 {"pl2_up", &pl2
.ku
, Y_KEY
},
86 {"pl2_down", &pl2
.kd
, Y_KEY
},
87 {"pl2_jump", &pl2
.kj
, Y_KEY
},
88 {"pl2_fire", &pl2
.kf
, Y_KEY
},
89 {"pl2_next", &pl2
.kwr
, Y_KEY
},
90 {"pl2_prev", &pl2
.kwl
, Y_KEY
},
91 {"pl2_use", &pl2
.kp
, Y_KEY
},
92 {NULL
, NULL
, 0} // end
95 static void CFG_args (int argc
, char **argv
) {
100 list
[3] = MUS_args();
101 ARG_parse(argc
, argv
, 4, list
);
104 static void CFG_load (void) {
105 const cfg_t
*list
[4];
109 list
[3] = MUS_conf();
110 CFG_read_config("default.cfg", 4, list
);
111 CFG_read_config("doom2d.cfg", 4, list
);
114 static void CFG_save (void) {
115 const cfg_t
*list
[4];
119 list
[3] = MUS_conf();
120 CFG_update_config("doom2d.cfg", "doom2d.cfg", 4, list
, "generated by doom2d, do not modify");
123 /* --- error.h --- */
125 void logo (const char *s
, ...) {
133 void logo_gas (int cur
, int all
) {
137 void ERR_failinit (char *s
, ...) {
146 void ERR_fatal (char *s
, ...) {
151 puts("\nCRITICAL ERROR:");
159 void ERR_quit (void) {
163 /* --- system.h --- */
165 int Y_set_videomode_opengl (int w
, int h
, int fullscreen
) {
174 int Y_set_videomode_software (int w
, int h
, int fullscreen
) {
178 buf
= softbuffer
? realloc(softbuffer
, w
* h
) : malloc(w
* h
);
180 mode
= MODE_SOFTWARE
;
188 const videomode_t
*Y_get_videomode_list_opengl (int fullscreen
) {
192 const videomode_t
*Y_get_videomode_list_software (int fullscreen
) {
196 void Y_get_videomode (int *w
, int *h
) {
197 if (mode
!= MODE_NONE
) {
206 int Y_videomode_setted (void) {
207 return mode
!= MODE_NONE
;
210 void Y_unset_videomode (void) {
216 void Y_set_fullscreen (int yes
) {
220 int Y_get_fullscreen (void) {
221 return (mode
!= MODE_NONE
) && fullscreen
;
224 void Y_swap_buffers (void) {
225 assert(mode
== MODE_OPENGL
);
228 void Y_get_buffer (byte
**buf
, int *w
, int *h
, int *pitch
) {
229 assert(mode
== MODE_SOFTWARE
);
236 void Y_set_vga_palette (byte
*vgapal
) {
239 assert(vgapal
!= NULL
);
240 assert(mode
== MODE_SOFTWARE
);
243 void Y_repaint_rect (int x
, int y
, int w
, int h
) {
244 assert(mode
== MODE_SOFTWARE
);
247 void Y_repaint (void) {
248 assert(mode
== MODE_SOFTWARE
);
251 void Y_enable_text_input (void) {
255 void Y_disable_text_input (void) {
261 static void poll_events (void) {
265 static void step (void) {
270 if ((t
- ticks
) * 1000 / CLOCKS_PER_SEC
> DELAY
) {
277 int main (int argc
, char *argv
[]) {
278 logo("main: initialize\n");
284 pl1
.kf
= KEY_PAGEDOWN
;
299 //srand(SDL_GetTicks());
300 F_addwad("doom2d.wad");
301 CFG_args(argc
, argv
);
309 #ifdef __EMSCRIPTEN__
310 emscripten_set_main_loop(step
, 0, 1);