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
) {
96 const cfg_t
*list
[] = { arg
, R_args(), S_args(), MUS_args() };
97 ARG_parse(argc
, argv
, 4, list
);
100 static void CFG_load (void) {
101 const cfg_t
*list
[] = { cfg
, R_conf(), S_conf(), MUS_conf() };
102 CFG_read_config("default.cfg", 4, list
);
103 CFG_read_config("doom2d.cfg", 4, list
);
106 static void CFG_save (void) {
107 const cfg_t
*list
[] = { cfg
, R_conf(), S_conf(), MUS_conf() };
108 CFG_update_config("doom2d.cfg", "doom2d.cfg", 4, list
, "generated by doom2d, do not modify");
111 /* --- error.h --- */
113 void logo (const char *s
, ...) {
121 void logo_gas (int cur
, int all
) {
125 void ERR_failinit (char *s
, ...) {
134 void ERR_fatal (char *s
, ...) {
139 puts("\nCRITICAL ERROR:");
147 void ERR_quit (void) {
151 /* --- system.h --- */
153 int Y_set_videomode_opengl (int w
, int h
, int fullscreen
) {
162 int Y_set_videomode_software (int w
, int h
, int fullscreen
) {
165 void *buf
= softbuffer
? realloc(softbuffer
, w
* h
) : malloc(w
* h
);
167 mode
= MODE_SOFTWARE
;
175 const videomode_t
*Y_get_videomode_list_opengl (int fullscreen
) {
179 const videomode_t
*Y_get_videomode_list_software (int fullscreen
) {
183 void Y_get_videomode (int *w
, int *h
) {
184 if (mode
!= MODE_NONE
) {
193 int Y_videomode_setted (void) {
194 return mode
!= MODE_NONE
;
197 void Y_unset_videomode (void) {
203 void Y_set_fullscreen (int yes
) {
207 int Y_get_fullscreen (void) {
208 return (mode
!= MODE_NONE
) && fullscreen
;
211 void Y_swap_buffers (void) {
212 assert(mode
== MODE_OPENGL
);
215 void Y_get_buffer (byte
**buf
, int *w
, int *h
, int *pitch
) {
216 assert(mode
== MODE_SOFTWARE
);
217 // *buf = surf->pixels;
218 *buf
= NULL
; // fix this
224 void Y_set_vga_palette (byte
*vgapal
) {
227 assert(vgapal
!= NULL
);
228 assert(mode
== MODE_SOFTWARE
);
231 void Y_repaint_rect (int x
, int y
, int w
, int h
) {
232 assert(mode
== MODE_SOFTWARE
);
235 void Y_repaint (void) {
236 assert(mode
== MODE_SOFTWARE
);
239 void Y_enable_text_input (void) {
243 void Y_disable_text_input (void) {
249 static void poll_events (void) {
253 static void step (void) {
257 if ((t
- ticks
) * 1000 / CLOCKS_PER_SEC
> DELAY
) {
264 int main (int argc
, char *argv
[]) {
265 logo("main: initialize\n");
271 pl1
.kf
= KEY_PAGEDOWN
;
286 //srand(SDL_GetTicks());
287 F_addwad("doom2d.wad");
288 CFG_args(argc
, argv
);
296 #ifdef __EMSCRIPTEN__
297 emscripten_set_main_loop(step
, 0, 1);