X-Git-Url: https://deadsoftware.ru/gitweb?a=blobdiff_plain;f=src%2Fsdl2%2Fmain.c;h=f9eb159fe7b7342c1ab28cd2fd9a9a9a5ed783c7;hb=9f3ca6bf02300e3dc72e3c2085a8e35aa9242678;hp=1a25886799791e976727ca56a7a36e381f97ef7f;hpb=4a0a2f1f4922d5346c4aee584e7d4a13803bffab;p=flatwaifu.git diff --git a/src/sdl2/main.c b/src/sdl2/main.c index 1a25886..f9eb159 100644 --- a/src/sdl2/main.c +++ b/src/sdl2/main.c @@ -11,13 +11,17 @@ #include "system.h" #include "input.h" +#include "cp866.h" + #include "my.h" // fexists #include "player.h" // pl1 pl2 #include "menu.h" // G_keyf #include "error.h" // logo +#include "monster.h" // nomon #include "files.h" // F_startup F_addwad F_initwads F_allocres #include "config.h" // CFG_args CFG_load CFG_save +#include "args.h" // ARG_parse #include "memory.h" // M_startup #include "game.h" // G_init G_act #include "sound.h" // S_init S_done @@ -33,6 +37,62 @@ static SDL_GLContext context; static SDL_Surface *surf; static videomode_t vlist; +static const cfg_t arg[] = { + {"file", NULL, Y_FILES}, + {"cheat", &cheat, Y_SW_ON}, +// {"vga", &shot_vga, Y_SW_ON}, + {"sndvol", &snd_vol, Y_WORD}, + {"musvol", &mus_vol, Y_WORD}, + {"mon", &nomon, Y_SW_OFF}, + {"warp", &_warp, Y_BYTE}, +// {"config", NULL, cfg_file, Y_STRING}, + {NULL, NULL, 0} // end +}; + +static const cfg_t cfg[] = { +// {"screenshot", &shot_vga, Y_SW_ON}, + {"sound_volume", &snd_vol, Y_WORD}, + {"music_volume", &mus_vol, Y_WORD}, + {"music_random", &music_random, Y_SW_ON}, + {"music_time", &music_time, Y_DWORD}, + {"music_fade", &music_fade, Y_DWORD}, + {"pl1_left", &pl1.kl, Y_KEY}, + {"pl1_right",&pl1.kr, Y_KEY}, + {"pl1_up", &pl1.ku, Y_KEY}, + {"pl1_down", &pl1.kd, Y_KEY}, + {"pl1_jump", &pl1.kj, Y_KEY}, + {"pl1_fire", &pl1.kf, Y_KEY}, + {"pl1_next", &pl1.kwr, Y_KEY}, + {"pl1_prev", &pl1.kwl, Y_KEY}, + {"pl1_use", &pl1.kp, Y_KEY}, + {"pl2_left", &pl2.kl, Y_KEY}, + {"pl2_right", &pl2.kr, Y_KEY}, + {"pl2_up", &pl2.ku, Y_KEY}, + {"pl2_down", &pl2.kd, Y_KEY}, + {"pl2_jump", &pl2.kj, Y_KEY}, + {"pl2_fire", &pl2.kf, Y_KEY}, + {"pl2_next", &pl2.kwr, Y_KEY}, + {"pl2_prev", &pl2.kwl, Y_KEY}, + {"pl2_use", &pl2.kp, Y_KEY}, + {NULL, NULL, 0} // end +}; + +static void CFG_args (int argc, char **argv) { + const cfg_t *list[] = { arg, R_args() }; + ARG_parse(argc, argv, 2, list); +} + +static void CFG_load (void) { + const cfg_t *list[] = { cfg, R_conf() }; + CFG_read_config("default.cfg", 2, list); + CFG_read_config("doom2d.cfg", 2, list); +} + +static void CFG_save (void) { + const cfg_t *list[] = { cfg, R_conf() }; + CFG_update_config("doom2d.cfg", "doom2d.cfg", 2, list, "generated by doom2d, do not modify"); +} + /* --- error.h --- */ void logo (const char *s, ...) { @@ -452,37 +512,6 @@ static int utf8_to_wchar (char *x) { return i; } -static int wchar_to_cp866 (int uch) { - if (uch <= 0x7f) { - return uch; - } else if (uch >= 0x410 && uch <= 0x43f) { - return uch - 0x410 + 0x80; - } else if (uch >= 0x440 && uch <= 0x44f) { - return uch - 0x440 + 0xe0; - } else { - switch (uch) { - // TODO graphics from 0xb0..0xdf - case 0x401: return 0xf0; - case 0x451: return 0xf1; - case 0x404: return 0xf2; - case 0x454: return 0xf3; - case 0x407: return 0xf4; - case 0x457: return 0xf5; - case 0x40e: return 0xf6; - case 0x45e: return 0xf7; - case 0xb0: return 0xf8; - case 0x2219: return 0xf9; - case 0xb7: return 0xfa; - case 0x221a: return 0xfb; - case 0x2116: return 0xfc; - case 0xa4: return 0xfd; - case 0x25a0: return 0xfe; - case 0xa0: return 0xff; - default: return 0; // unknown - } - } -} - static void poll_events (void) { int key, down, uch, ch; SDL_Event ev; @@ -505,8 +534,10 @@ static void poll_events (void) { break; case SDL_TEXTINPUT: uch = utf8_to_wchar(ev.text.text); - ch = wchar_to_cp866(uch); - GM_input(ch); + ch = cp866_utoc(uch); + if (ch >= 0) { + GM_input(ch); + } break; } } @@ -525,6 +556,7 @@ static void step (void) { int main (int argc, char **argv) { char *pw; + CFG_args(argc, argv); logo("system: initialize SDL2\n"); if (SDL_Init(SDL_INIT_TIMER | SDL_INIT_VIDEO | SDL_INIT_EVENTS) == -1) { logo("system: failed to init SDL2: %s\n", SDL_GetError()); @@ -552,6 +584,7 @@ int main (int argc, char **argv) { pl2.kp = KEY_E; srand(SDL_GetTicks()); F_startup(); + CFG_load(); #ifndef WIN32 pw = "/usr/share/doom2d-rembo/doom2d.wad"; #else @@ -562,8 +595,6 @@ int main (int argc, char **argv) { } else { F_addwad("doom2d.wad"); } - CFG_args(argc, argv); - CFG_load(); F_initwads(); M_startup(); F_allocres();