From de05b18ef2a99168b0a1a8a921a4b18ec7023833 Mon Sep 17 00:00:00 2001 From: DeaDDooMER Date: Sat, 21 Mar 2020 18:31:19 +0300 Subject: [PATCH] system: game itself do not depends on sdl --- src/CMakeLists.txt | 8 +- src/config.c | 30 +--- src/default.cfg | 44 +++--- src/error.c | 19 +-- src/game.c | 17 ++- src/input.c | 233 +++++++++++++++++++++++++++++++ src/input.h | 118 ++++++++++++++++ src/keyb.c | 61 --------- src/keyb.h | 38 ------ src/main.c | 108 --------------- src/menu.c | 334 ++++++++++++++++++++++++++------------------- src/menu.h | 1 + src/my.c | 5 - src/my.h | 2 - src/player.c | 36 ++--- src/sdl/main.c | 245 +++++++++++++++++++++++++++++++++ src/sound.c | 1 + 17 files changed, 860 insertions(+), 440 deletions(-) create mode 100644 src/input.c create mode 100644 src/input.h delete mode 100644 src/keyb.c delete mode 100644 src/keyb.h delete mode 100644 src/main.c create mode 100644 src/sdl/main.c diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index b01523e..1a511c6 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,12 +1,13 @@ cmake_minimum_required(VERSION 3.6) project(doom2d C) -option(WITH_OPENGL "Build with OpenGL render" OFF) +option(WITH_OPENGL "Build with OpenGL render" ON) option(WITH_SOFTWARE "Build with Software render" ON) set(D2D_GAME_ROOT .) set(D2D_OPENGL_ROOT ${D2D_GAME_ROOT}/gl) set(D2D_SOFTWARE_ROOT ${D2D_GAME_ROOT}/soft) +set(D2D_SDL_ROOT ${D2D_GAME_ROOT}/sdl) find_package(SDL REQUIRED) find_package(SDL_mixer REQUIRED) @@ -17,6 +18,7 @@ endif (WITH_OPENGL) aux_source_directory(${D2D_GAME_ROOT} D2D_GAME_SRC) aux_source_directory(${D2D_OPENGL_ROOT} D2D_OPENGL_SRC) aux_source_directory(${D2D_SOFTWARE_ROOT} D2D_SOFTWARE_SRC) +aux_source_directory(${D2D_SDL_ROOT} D2D_SDL_SRC) if (NOT CMAKE_BUILD_TYPE) set(CMAKE_BUILD_TYPE Release) @@ -37,13 +39,13 @@ message(STATUS "SOFTWARE: " ${WITH_SOFTWARE}) message(STATUS "OPENGL: " ${WITH_OPENGL}) if (WITH_OPENGL) - add_executable(doom2d-gl ${D2D_GAME_SRC} ${D2D_OPENGL_SRC}) + add_executable(doom2d-gl ${D2D_GAME_SRC} ${D2D_SDL_SRC} ${D2D_OPENGL_SRC}) target_include_directories(doom2d-gl PRIVATE "${D2D_GAME_ROOT}" "${SDL_INCLUDE_DIR}" "${SDLMIXER_INCLUDE_DIR}" "${OPENGL_INCLUDE_DIR}") target_link_libraries(doom2d-gl "${SDL_LIBRARY}" "${SDLMIXER_LIBRARY}" "${OPENGL_LIBRARY}") endif (WITH_OPENGL) if (WITH_SOFTWARE) - add_executable(doom2d-soft ${D2D_GAME_SRC} ${D2D_SOFTWARE_SRC}) + add_executable(doom2d-soft ${D2D_GAME_SRC} ${D2D_SDL_SRC} ${D2D_SOFTWARE_SRC}) target_include_directories(doom2d-soft PRIVATE "${D2D_GAME_ROOT}" "${SDL_INCLUDE_DIR}" "${SDLMIXER_INCLUDE_DIR}") target_link_libraries(doom2d-soft "${SDL_LIBRARY}" "${SDLMIXER_LIBRARY}") endif (WITH_SOFTWARE) diff --git a/src/config.c b/src/config.c index 0c5bc21..c51e9ee 100644 --- a/src/config.c +++ b/src/config.c @@ -24,7 +24,6 @@ #include #include #include -#include #include "map.h" #include "sound.h" #include "music.h" @@ -35,6 +34,7 @@ #include "files.h" #include "render.h" #include "error.h" +#include "input.h" #include "my.h" enum{NONE,BYTE,WORD,DWORD,STRING,SW_ON,SW_OFF,FILES,KEY}; @@ -154,18 +154,6 @@ next: } } -static int get_key (char *name) { - int i; - for(i=1; i #include #include -#include "keyb.h" #include "sound.h" #include "render.h" #include "memory.h" @@ -35,7 +34,6 @@ void logo (const char *s, ...) { va_list ap; - int x, y; va_start(ap, s); vprintf(s, ap); va_end(ap); @@ -49,14 +47,13 @@ void logo_gas (int cur, int all) { static void close_all (void) { S_done(); S_donemusic(); - K_done(); - R_done(); M_shutdown(); + R_done(); } void ERR_failinit (char *s, ...) { va_list ap; - close_all(); + //close_all(); va_start(ap, s); vprintf(s, ap); va_end(ap); @@ -64,7 +61,7 @@ void ERR_failinit (char *s, ...) { exit(1); } -void ERR_fatal(char *s,...) { +void ERR_fatal (char *s,...) { va_list ap; close_all(); puts("\nКРИТИЧЕСКАЯ ОШИБКА:"); @@ -76,14 +73,8 @@ void ERR_fatal(char *s,...) { } void ERR_quit (void) { - void *p; - //V_done(); - //if(!(p=malloc(4000))) - puts("Спасибо за то, что вы играли в Операцию \"Смятка\"!"); - //else { -// F_loadres(F_getresid("ENDOOM"),p,0,4000); - // memcpy((void*)0xB8000,p,4000);free(p);gotoxy(1,24); - //} + puts("Спасибо за то, что вы играли в Операцию \"Смятка\"!"); + //F_loadres(F_getresid("ENDOOM"),p,0,4000); close_all(); CFG_save(); exit(0); diff --git a/src/game.c b/src/game.c index 8d14674..b540223 100644 --- a/src/game.c +++ b/src/game.c @@ -26,7 +26,6 @@ #include #include "files.h" #include "memory.h" -#include "keyb.h" #include "sound.h" #include "view.h" #include "bmap.h" @@ -47,8 +46,8 @@ #include "music.h" #include "a8.h" #include "error.h" +#include "input.h" -#include #define LT_DELAY 8 #define LT_HITTIME 6 @@ -273,8 +272,8 @@ void G_act (void) { if(g_st==GS_BVIDEO || g_st==GS_EVIDEO) { - if(!A8_nextframe() || lastkey==SDLK_ESCAPE) { - if(lastkey==SDLK_ESCAPE) lastkey=0; + if (!A8_nextframe() || lastkey == KEY_ESCAPE) { + if (lastkey == KEY_ESCAPE) lastkey = KEY_UNKNOWN; A8_close(); if(g_st==GS_BVIDEO) G_start(); else goto inter; @@ -311,10 +310,14 @@ void G_act (void) { set_trans(GS_TITLE); } #else - if(keys[SDLK_SPACE] || keys[SDLK_RETURN] || keys[SDLK_KP_ENTER])//if(keys[0x39] || keys[0x1C] || keys[0x9C]) - if(!G_beg_video()) G_start(); else { - g_st=GS_BVIDEO;F_freemus(); + if (I_pressed(KEY_SPACE) || I_pressed(KEY_RETURN) || I_pressed(KEY_KP_ENTER)) { + if (!G_beg_video()) { + G_start(); + } else { + g_st = GS_BVIDEO; + F_freemus(); } + } #endif return; } diff --git a/src/input.c b/src/input.c new file mode 100644 index 0000000..825e5d2 --- /dev/null +++ b/src/input.c @@ -0,0 +1,233 @@ +#include "input.h" +#include +#include + +static char keystate[KEY__LAST + 1]; + +const char *I_key_to_string (int key) { + switch (key) { + case KEY_0: return "0"; + case KEY_1: return "1"; + case KEY_2: return "2"; + case KEY_3: return "3"; + case KEY_4: return "4"; + case KEY_5: return "5"; + case KEY_6: return "6"; + case KEY_7: return "7"; + case KEY_8: return "8"; + case KEY_9: return "9"; + case KEY_A: return "A"; + case KEY_B: return "B"; + case KEY_C: return "C"; + case KEY_D: return "D"; + case KEY_E: return "E"; + case KEY_F: return "F"; + case KEY_G: return "G"; + case KEY_H: return "H"; + case KEY_I: return "I"; + case KEY_J: return "J"; + case KEY_K: return "K"; + case KEY_L: return "L"; + case KEY_M: return "M"; + case KEY_N: return "N"; + case KEY_O: return "O"; + case KEY_P: return "P"; + case KEY_Q: return "Q"; + case KEY_R: return "R"; + case KEY_S: return "S"; + case KEY_T: return "T"; + case KEY_U: return "U"; + case KEY_V: return "V"; + case KEY_W: return "W"; + case KEY_X: return "X"; + case KEY_Y: return "Y"; + case KEY_Z: return "Z"; + case KEY_RETURN: return "RETURN"; + case KEY_ESCAPE: return "ESCAPE"; + case KEY_BACKSPACE: return "BACKSPACE"; + case KEY_TAB: return "TAB"; + case KEY_SPACE: return "SPACE"; + case KEY_MINUS: return "MINUS"; + case KEY_EQUALS: return "EQUALS"; + case KEY_LEFTBRACKET: return "LEFTBRACKET"; + case KEY_RIGHTBRACKET: return "RIGHTBRACKET"; + case KEY_BACKSLASH: return "BACKSLASH"; + case KEY_SEMICOLON: return "SEMICOLON"; + case KEY_APOSTROPHE: return "APOSTROPHE"; + case KEY_GRAVE: return "GRAVE"; + case KEY_COMMA: return "COMMA"; + case KEY_PERIOD: return "PERIOD"; + case KEY_SLASH: return "SLASH"; + case KEY_CAPSLOCK: return "CAPSLOCK"; + case KEY_F1: return "F1"; + case KEY_F2: return "F2"; + case KEY_F3: return "F3"; + case KEY_F4: return "F4"; + case KEY_F5: return "F5"; + case KEY_F6: return "F6"; + case KEY_F7: return "F7"; + case KEY_F8: return "F8"; + case KEY_F9: return "F9"; + case KEY_F10: return "F10"; + case KEY_F11: return "F11"; + case KEY_F12: return "F12"; + case KEY_PRINTSCREEN: return "PRINTSCREEN"; + case KEY_SCROLLLOCK: return "SCROLLLOCK"; + case KEY_PAUSE: return "PAUSE"; + case KEY_INSERT: return "INSERT"; + case KEY_HOME: return "HOME"; + case KEY_PAGEUP: return "PAGEUP"; + case KEY_DELETE: return "DELETE"; + case KEY_END: return "END"; + case KEY_PAGEDOWN: return "PAGEDOWN"; + case KEY_RIGHT: return "RIGHT"; + case KEY_LEFT: return "LEFT"; + case KEY_DOWN: return "DOWN"; + case KEY_UP: return "UP"; + case KEY_NUMLOCK: return "NUMLOCK"; + case KEY_KP_DIVIDE: return "KP_DIVIDE"; + case KEY_KP_MULTIPLY: return "KP_MULTIPLY"; + case KEY_KP_MINUS: return "KP_MINUS"; + case KEY_KP_PLUS: return "KP_PLUS"; + case KEY_KP_ENTER: return "KP_ENTER"; + case KEY_KP_0: return "KP_0"; + case KEY_KP_1: return "KP_1"; + case KEY_KP_2: return "KP_2"; + case KEY_KP_3: return "KP_3"; + case KEY_KP_4: return "KP_4"; + case KEY_KP_5: return "KP_5"; + case KEY_KP_6: return "KP_6"; + case KEY_KP_7: return "KP_7"; + case KEY_KP_8: return "KP_8"; + case KEY_KP_9: return "KP_9"; + case KEY_KP_PERIOD: return "KP_PERIOD"; + case KEY_SYSREQ: return "SYSREQ"; + case KEY_LCTRL: return "LCTRL"; + case KEY_LSHIFT: return "LSHIFT"; + case KEY_LALT: return "LALT"; + case KEY_LSUPER: return "LSUPER"; + case KEY_RCTRL: return "RCTRL"; + case KEY_RSHIFT: return "RSHIFT"; + case KEY_RALT: return "RALT"; + case KEY_RSUPER: return "RSUPER"; + default: return "UNKNOWN"; + } +} + +int I_string_to_key (const char *str) { + if (strcasecmp(str, "0") == 0) return KEY_0; + else if (strcasecmp(str, "1") == 0) return KEY_1; + else if (strcasecmp(str, "2") == 0) return KEY_2; + else if (strcasecmp(str, "3") == 0) return KEY_3; + else if (strcasecmp(str, "4") == 0) return KEY_4; + else if (strcasecmp(str, "5") == 0) return KEY_5; + else if (strcasecmp(str, "6") == 0) return KEY_6; + else if (strcasecmp(str, "7") == 0) return KEY_7; + else if (strcasecmp(str, "8") == 0) return KEY_8; + else if (strcasecmp(str, "9") == 0) return KEY_9; + else if (strcasecmp(str, "A") == 0) return KEY_A; + else if (strcasecmp(str, "B") == 0) return KEY_B; + else if (strcasecmp(str, "C") == 0) return KEY_C; + else if (strcasecmp(str, "D") == 0) return KEY_D; + else if (strcasecmp(str, "E") == 0) return KEY_E; + else if (strcasecmp(str, "F") == 0) return KEY_F; + else if (strcasecmp(str, "G") == 0) return KEY_G; + else if (strcasecmp(str, "H") == 0) return KEY_H; + else if (strcasecmp(str, "I") == 0) return KEY_I; + else if (strcasecmp(str, "J") == 0) return KEY_J; + else if (strcasecmp(str, "K") == 0) return KEY_K; + else if (strcasecmp(str, "L") == 0) return KEY_L; + else if (strcasecmp(str, "M") == 0) return KEY_M; + else if (strcasecmp(str, "N") == 0) return KEY_N; + else if (strcasecmp(str, "O") == 0) return KEY_O; + else if (strcasecmp(str, "P") == 0) return KEY_P; + else if (strcasecmp(str, "Q") == 0) return KEY_Q; + else if (strcasecmp(str, "R") == 0) return KEY_R; + else if (strcasecmp(str, "S") == 0) return KEY_S; + else if (strcasecmp(str, "T") == 0) return KEY_T; + else if (strcasecmp(str, "U") == 0) return KEY_U; + else if (strcasecmp(str, "V") == 0) return KEY_V; + else if (strcasecmp(str, "W") == 0) return KEY_W; + else if (strcasecmp(str, "X") == 0) return KEY_X; + else if (strcasecmp(str, "Y") == 0) return KEY_Y; + else if (strcasecmp(str, "Z") == 0) return KEY_Z; + else if (strcasecmp(str, "RETURN") == 0) return KEY_RETURN; + else if (strcasecmp(str, "ESCAPE") == 0) return KEY_ESCAPE; + else if (strcasecmp(str, "BACKSPACE") == 0) return KEY_BACKSPACE; + else if (strcasecmp(str, "TAB") == 0) return KEY_TAB; + else if (strcasecmp(str, "SPACE") == 0) return KEY_SPACE; + else if (strcasecmp(str, "MINUS") == 0) return KEY_MINUS; + else if (strcasecmp(str, "EQUALS") == 0) return KEY_EQUALS; + else if (strcasecmp(str, "LEFTBRACKET") == 0) return KEY_LEFTBRACKET; + else if (strcasecmp(str, "RIGHTBRACKET") == 0) return KEY_RIGHTBRACKET; + else if (strcasecmp(str, "BACKSLASH") == 0) return KEY_BACKSLASH; + else if (strcasecmp(str, "SEMICOLON") == 0) return KEY_SEMICOLON; + else if (strcasecmp(str, "APOSTROPHE") == 0) return KEY_APOSTROPHE; + else if (strcasecmp(str, "GRAVE") == 0) return KEY_GRAVE; + else if (strcasecmp(str, "COMMA") == 0) return KEY_COMMA; + else if (strcasecmp(str, "PERIOD") == 0) return KEY_PERIOD; + else if (strcasecmp(str, "SLASH") == 0) return KEY_SLASH; + else if (strcasecmp(str, "CAPSLOCK") == 0) return KEY_CAPSLOCK; + else if (strcasecmp(str, "F1") == 0) return KEY_F1; + else if (strcasecmp(str, "F2") == 0) return KEY_F2; + else if (strcasecmp(str, "F3") == 0) return KEY_F3; + else if (strcasecmp(str, "F4") == 0) return KEY_F4; + else if (strcasecmp(str, "F5") == 0) return KEY_F5; + else if (strcasecmp(str, "F6") == 0) return KEY_F6; + else if (strcasecmp(str, "F7") == 0) return KEY_F7; + else if (strcasecmp(str, "F8") == 0) return KEY_F8; + else if (strcasecmp(str, "F9") == 0) return KEY_F9; + else if (strcasecmp(str, "F10") == 0) return KEY_F10; + else if (strcasecmp(str, "F11") == 0) return KEY_F11; + else if (strcasecmp(str, "F12") == 0) return KEY_F12; + else if (strcasecmp(str, "PRINTSCREEN") == 0) return KEY_PRINTSCREEN; + else if (strcasecmp(str, "SCROLLLOCK") == 0) return KEY_SCROLLLOCK; + else if (strcasecmp(str, "PAUSE") == 0) return KEY_PAUSE; + else if (strcasecmp(str, "INSERT") == 0) return KEY_INSERT; + else if (strcasecmp(str, "HOME") == 0) return KEY_HOME; + else if (strcasecmp(str, "PAGEUP") == 0) return KEY_PAGEUP; + else if (strcasecmp(str, "DELETE") == 0) return KEY_DELETE; + else if (strcasecmp(str, "END") == 0) return KEY_END; + else if (strcasecmp(str, "PAGEDOWN") == 0) return KEY_PAGEDOWN; + else if (strcasecmp(str, "RIGHT") == 0) return KEY_RIGHT; + else if (strcasecmp(str, "LEFT") == 0) return KEY_LEFT; + else if (strcasecmp(str, "DOWN") == 0) return KEY_DOWN; + else if (strcasecmp(str, "UP") == 0) return KEY_UP; + else if (strcasecmp(str, "NUMLOCK") == 0) return KEY_NUMLOCK; + else if (strcasecmp(str, "KP_DIVIDE") == 0) return KEY_KP_DIVIDE; + else if (strcasecmp(str, "KP_MULTIPLY") == 0) return KEY_KP_MULTIPLY; + else if (strcasecmp(str, "KP_MINUS") == 0) return KEY_KP_MINUS; + else if (strcasecmp(str, "KP_PLUS") == 0) return KEY_KP_PLUS; + else if (strcasecmp(str, "KP_ENTER") == 0) return KEY_KP_ENTER; + else if (strcasecmp(str, "KP_0") == 0) return KEY_KP_0; + else if (strcasecmp(str, "KP_1") == 0) return KEY_KP_1; + else if (strcasecmp(str, "KP_2") == 0) return KEY_KP_2; + else if (strcasecmp(str, "KP_3") == 0) return KEY_KP_3; + else if (strcasecmp(str, "KP_4") == 0) return KEY_KP_4; + else if (strcasecmp(str, "KP_5") == 0) return KEY_KP_5; + else if (strcasecmp(str, "KP_6") == 0) return KEY_KP_6; + else if (strcasecmp(str, "KP_7") == 0) return KEY_KP_7; + else if (strcasecmp(str, "KP_8") == 0) return KEY_KP_8; + else if (strcasecmp(str, "KP_9") == 0) return KEY_KP_9; + else if (strcasecmp(str, "KP_PERIOD") == 0) return KEY_KP_PERIOD; + else if (strcasecmp(str, "SYSREQ") == 0) return KEY_SYSREQ; + else if (strcasecmp(str, "LCTRL") == 0) return KEY_LCTRL; + else if (strcasecmp(str, "LSHIFT") == 0) return KEY_LSHIFT; + else if (strcasecmp(str, "LALT") == 0) return KEY_LALT; + else if (strcasecmp(str, "LSUPER") == 0) return KEY_LSUPER; + else if (strcasecmp(str, "RCTRL") == 0) return KEY_RCTRL; + else if (strcasecmp(str, "RSHIFT") == 0) return KEY_RSHIFT; + else if (strcasecmp(str, "RALT") == 0) return KEY_RALT; + else if (strcasecmp(str, "RSUPER") == 0) return KEY_RSUPER; + else return KEY_UNKNOWN; +} + +int I_pressed (int key) { + assert(key >= 0 && key <= KEY__LAST); + return keystate[key]; +} + +void I_press (int key, int down) { + assert(key >= 0 && key <= KEY__LAST); + keystate[key] = down != 0; +} diff --git a/src/input.h b/src/input.h new file mode 100644 index 0000000..ad86145 --- /dev/null +++ b/src/input.h @@ -0,0 +1,118 @@ +#ifndef INPUT_H_INCLUDED +#define INPUT_H_INCLUDED + +enum { + KEY_UNKNOWN, + KEY_0, + KEY_1, + KEY_2, + KEY_3, + KEY_4, + KEY_5, + KEY_6, + KEY_7, + KEY_8, + KEY_9, + KEY_A, + KEY_B, + KEY_C, + KEY_D, + KEY_E, + KEY_F, + KEY_G, + KEY_H, + KEY_I, + KEY_J, + KEY_K, + KEY_L, + KEY_M, + KEY_N, + KEY_O, + KEY_P, + KEY_Q, + KEY_R, + KEY_S, + KEY_T, + KEY_U, + KEY_V, + KEY_W, + KEY_X, + KEY_Y, + KEY_Z, + KEY_RETURN, + KEY_ESCAPE, + KEY_BACKSPACE, + KEY_TAB, + KEY_SPACE, + KEY_MINUS, + KEY_EQUALS, + KEY_LEFTBRACKET, + KEY_RIGHTBRACKET, + KEY_BACKSLASH, + KEY_SEMICOLON, + KEY_APOSTROPHE, + KEY_GRAVE, + KEY_COMMA, + KEY_PERIOD, + KEY_SLASH, + KEY_CAPSLOCK, + KEY_F1, + KEY_F2, + KEY_F3, + KEY_F4, + KEY_F5, + KEY_F6, + KEY_F7, + KEY_F8, + KEY_F9, + KEY_F10, + KEY_F11, + KEY_F12, + KEY_PRINTSCREEN, + KEY_SCROLLLOCK, + KEY_PAUSE, + KEY_INSERT, + KEY_HOME, + KEY_PAGEUP, + KEY_DELETE, + KEY_END, + KEY_PAGEDOWN, + KEY_RIGHT, + KEY_LEFT, + KEY_DOWN, + KEY_UP, + KEY_NUMLOCK, + KEY_KP_DIVIDE, + KEY_KP_MULTIPLY, + KEY_KP_MINUS, + KEY_KP_PLUS, + KEY_KP_ENTER, + KEY_KP_0, + KEY_KP_1, + KEY_KP_2, + KEY_KP_3, + KEY_KP_4, + KEY_KP_5, + KEY_KP_6, + KEY_KP_7, + KEY_KP_8, + KEY_KP_9, + KEY_KP_PERIOD, + KEY_SYSREQ, + KEY_LCTRL, + KEY_LSHIFT, + KEY_LALT, + KEY_LSUPER, + KEY_RCTRL, + KEY_RSHIFT, + KEY_RALT, + KEY_RSUPER, + KEY__LAST = KEY_RSUPER +}; + +const char *I_key_to_string (int key); +int I_string_to_key (const char *str); +int I_pressed (int key); +void I_press (int key, int down); + +#endif /* INPUT_H_INCLUDED */ diff --git a/src/keyb.c b/src/keyb.c deleted file mode 100644 index 7110996..0000000 --- a/src/keyb.c +++ /dev/null @@ -1,61 +0,0 @@ -/* - Copyright (C) Prikol Software 1996-1997 - Copyright (C) Aleksey Volynskov 1996-1997 - Copyright (C) 2011 - - This file is part of the Doom2D:Rembo project. - - Doom2D:Rembo is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License version 2 as - published by the Free Software Foundation. - - Doom2D:Rembo is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, see or - write to the Free Software Foundation, Inc., - 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include "keyb.h" -#include "error.h" -#include - -// массив клавиш: 0 - отпущена, иначе - нажата -unsigned char *keys = NULL; - -static key_f *key_proc = NULL; - -void K_init (void) { - keys = SDL_GetKeyState(NULL); -} - -void K_done (void) { - // not needed for sdl -} - -// установить функцию обработки клавиш -void K_setkeyproc (key_f *k) { - key_proc = k; -} - -void updatee_keys (void) { - SDL_Event event; - while (SDL_PollEvent (&event)) { - /* - if (event.type == SDL_KEYDOWN && event.key.keysym.sym == SDLK_RETURN && event.key.keysym.mod & KMOD_LALT) { - V_toggle(); - } - else */ - if (event.type == SDL_KEYDOWN || event.type == SDL_KEYUP) { - if (event.type == SDL_KEYDOWN && key_proc!=NULL) - key_proc(event.key.keysym.sym, event.type == SDL_KEYDOWN); - } - else if (event.type == SDL_QUIT) { - ERR_quit(); - } - } -} diff --git a/src/keyb.h b/src/keyb.h deleted file mode 100644 index d52559a..0000000 --- a/src/keyb.h +++ /dev/null @@ -1,38 +0,0 @@ -/* - Драйвер клавиатуры V1.1 для DOS4GW (а также DirectX 3) - Copyright (C) Алексей Волынсков, 1996 - - Copyright (C) Prikol Software 1996-1997 - Copyright (C) Aleksey Volynskov 1996-1997 - Copyright (C) 2011 - - This file is part of the Doom2D:Rembo project. - - Doom2D:Rembo is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License version 2 as - published by the Free Software Foundation. - - Doom2D:Rembo is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, see or - write to the Free Software Foundation, Inc., - 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#ifndef KEYB_H_INCLUDED -#define KEYB_H_INCLUDED - -typedef void key_f (int k, int pressed); - -extern unsigned char *keys; - -void K_init (void); -void K_done (void); -void K_setkeyproc (key_f *k); -void updatee_keys (void); - -#endif /* KEYB_H_INCLUDED */ diff --git a/src/main.c b/src/main.c deleted file mode 100644 index edf7156..0000000 --- a/src/main.c +++ /dev/null @@ -1,108 +0,0 @@ -/* - Copyright (C) Prikol Software 1996-1997 - Copyright (C) Aleksey Volynskov 1996-1997 - Copyright (C) 2011 - - This file is part of the Doom2D:Rembo project. - - Doom2D:Rembo is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License version 2 as - published by the Free Software Foundation. - - Doom2D:Rembo is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, see or - write to the Free Software Foundation, Inc., - 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA -*/ - -#include "glob.h" -#include -#include -#include -#include -#include "error.h" -#include "config.h" -#include "memory.h" -#include "keyb.h" -#include "sound.h" -#include "files.h" -#include "view.h" -#include "menu.h" -#include "player.h" -#include "my.h" -#include "render.h" -#include "game.h" -#include "music.h" - -#include - -int main(int argc, char *argv[]) { - if (SDL_Init(SDL_INIT_VIDEO)<0) ERR_failinit("Unable to init SDL: %s\n", SDL_GetError()); - SDL_WM_SetCaption("Doom 2D v1.351", "Doom 2D"); - int i; - - pl1.ku=SDLK_KP8; - pl1.kd=SDLK_KP5; - pl1.kl=SDLK_KP4; - pl1.kr=SDLK_KP6; - pl1.kf=SDLK_PAGEDOWN; - pl1.kj=SDLK_DELETE; - pl1.kwl=SDLK_HOME; - pl1.kwr=SDLK_END; - pl1.kp=SDLK_KP8; - pl1.id=-1; - pl2.ku=SDLK_e; - pl2.kd=SDLK_d; - pl2.kl=SDLK_s; - pl2.kr=SDLK_f; - pl2.kf=SDLK_a; - pl2.kj=SDLK_q; - pl2.kwl=SDLK_1; - pl2.kwr=SDLK_2; - pl2.kp=SDLK_e; - pl2.id=-2; - myrandomize(); - F_startup(); - char *pw; -#ifndef WIN32 - pw = "/usr/share/doom2d-rembo/doom2d.wad"; -#else - pw = "doom2d.wad"; -#endif - if (fexists(pw)) - F_addwad(pw); - else - F_addwad("doom2d.wad"); - CFG_args(argc, argv); - CFG_load(); - F_initwads(); - M_startup(); - F_allocres(); - G_init(); - K_init(); - logo("S_init: настройка звука\n"); - S_init(); - S_initmusic(); - R_init(); - GM_init(); - F_loadmus("MENU"); - S_startmusic(0); - - Uint32 ticks = SDL_GetTicks(); - for (;;) { - updatee_keys(); - S_updatemusic(); - Uint32 t = SDL_GetTicks(); - if (t - ticks > DELAY) { - ticks = t; - G_act(); - } - R_draw(); - //SDL_Delay(1); - } -} diff --git a/src/menu.c b/src/menu.c index bd225a4..3d797fc 100644 --- a/src/menu.c +++ b/src/menu.c @@ -27,7 +27,6 @@ #include "files.h" #include "memory.h" #include "error.h" -#include "keyb.h" #include "sound.h" #include "view.h" #include "player.h" @@ -40,8 +39,8 @@ #include "player.h" #include "sound.h" #include "music.h" +#include "input.h" -#include #include #define QSND_NUM 14 @@ -336,45 +335,45 @@ struct { int keysym; byte ch; } keychar[] = { - {SDLK_SPACE, ' '}, - {SDLK_0, '0'}, - {SDLK_1, '1'}, - {SDLK_2, '2'}, - {SDLK_3, '3'}, - {SDLK_4, '4'}, - {SDLK_5, '5'}, - {SDLK_6, '6'}, - {SDLK_7, '7'}, - {SDLK_8, '8'}, - {SDLK_9, '9'}, - {SDLK_UNDERSCORE, '_'}, - {SDLK_a, 'A'}, - {SDLK_b, 'B'}, - {SDLK_c, 'C'}, - {SDLK_d, 'D'}, - {SDLK_e, 'E'}, - {SDLK_f, 'F'}, - {SDLK_g, 'G'}, - {SDLK_h, 'H'}, - {SDLK_i, 'I'}, - {SDLK_j, 'J'}, - {SDLK_k, 'K'}, - {SDLK_l, 'L'}, - {SDLK_m, 'M'}, - {SDLK_n, 'N'}, - {SDLK_o, 'O'}, - {SDLK_p, 'P'}, - {SDLK_q, 'Q'}, - {SDLK_r, 'R'}, - {SDLK_s, 'S'}, - {SDLK_t, 'T'}, - {SDLK_u, 'U'}, - {SDLK_v, 'V'}, - {SDLK_w, 'W'}, - {SDLK_x, 'X'}, - {SDLK_y, 'Y'}, - {SDLK_z, 'Z'}, - {SDLK_COMMA,','}, + {KEY_SPACE, ' '}, + {KEY_0, '0'}, + {KEY_1, '1'}, + {KEY_2, '2'}, + {KEY_3, '3'}, + {KEY_4, '4'}, + {KEY_5, '5'}, + {KEY_6, '6'}, + {KEY_7, '7'}, + {KEY_8, '8'}, + {KEY_9, '9'}, + //{KEY_UNDERSCORE, '_'}, + {KEY_A, 'A'}, + {KEY_B, 'B'}, + {KEY_C, 'C'}, + {KEY_D, 'D'}, + {KEY_E, 'E'}, + {KEY_F, 'F'}, + {KEY_G, 'G'}, + {KEY_H, 'H'}, + {KEY_I, 'I'}, + {KEY_J, 'J'}, + {KEY_K, 'K'}, + {KEY_L, 'L'}, + {KEY_M, 'M'}, + {KEY_N, 'N'}, + {KEY_O, 'O'}, + {KEY_P, 'P'}, + {KEY_Q, 'Q'}, + {KEY_R, 'R'}, + {KEY_S, 'S'}, + {KEY_T, 'T'}, + {KEY_U, 'U'}, + {KEY_V, 'V'}, + {KEY_W, 'W'}, + {KEY_X, 'X'}, + {KEY_Y, 'Y'}, + {KEY_Z, 'Z'}, + {KEY_COMMA,','}, {0} }; @@ -418,107 +417,165 @@ int GM_act (void) { lastkey=0; return 1; } - if(input) switch(lastkey) { - case SDLK_RETURN: case SDLK_KP_ENTER://case 0x1C: case 0x9C: - F_savegame(save_mnu.cur,ibuf); - input=0;GM_set(NULL);break; - case 1: input=0;GM_set(mnu);break; - case SDLK_BACKSPACE://case 0x0E: - if(icur) {ibuf[--icur]=0;GM_set(mnu);} break; - default: - if(icur>=23) break; - c=get_keychar(lastkey);//c=keychar[(keys[0x2A] || keys[0x36])?1:0][lastkey]; - if(!c) break; - ibuf[icur]=c;ibuf[++icur]=0;GM_set(mnu); - }else { - switch(lastkey) { - case SDLK_ESCAPE://case 1: - if(!mnu) {GM_set(&main_mnu);Z_sound(msnd3,128);} - else {GM_set(NULL);Z_sound(msnd4,128);} - break; - case SDLK_F5: - if(mnu) break; - Z_sound(msnd3,128); - GMV_say("_GAMMA"); - GM_set(&gamma_mnu);break; - case SDLK_F4://case 0x3E: - if(mnu) break; - Z_sound(msnd3,128); - GMV_say("_VOLUME"); - GM_set(&vol_mnu);break; - case SDLK_F2://case 0x3C: - if(mnu) break; - if(g_st!=GS_GAME) break; - Z_sound(msnd3,128); - F_getsavnames();GM_set(&save_mnu);break; - case SDLK_F3://case 0x3D: - if(mnu) break; - Z_sound(msnd3,128); - F_getsavnames();GM_set(&load_mnu);break; - case SDLK_F10://case 0x44: - if(mnu) break; - Z_sound(msnd3,128); - GM_command(QUITGAME);break; - case SDLK_UP: case SDLK_KP8://case 0x48: case 0xC8: - if(!mnu) break; - if(mnu->type!=MENU) break; - if(--mnu->cur<0) mnu->cur=mnu->n-1; - GM_set(mnu); - Z_sound(msnd1,128);break; - case SDLK_DOWN: case SDLK_KP5: case SDLK_KP2://case 0x50: case 0xD0: case 0x4C: - if(!mnu) break; - if(mnu->type!=MENU) break; - if(++mnu->cur>=mnu->n) mnu->cur=0; - GM_set(mnu); - Z_sound(msnd1,128);break; - case SDLK_LEFT: case SDLK_RIGHT: case SDLK_KP4: case SDLK_KP6://case 0x4B: case 0x4D: case 0xCB: case 0xCD: - if(!mnu) break; - if(mnu->type!=MENU) break; - if(mnu->t[mnu->cur]t[mnu->cur]+((lastkey==SDLK_LEFT || lastkey==SDLK_KP4)?0:1));//GM_command(mnu->t[mnu->cur]+((lastkey==0x4B || lastkey==0xCB)?0:1)); - GM_set(mnu); - if(!movsndt) movsndt=Z_sound((lastkey==SDLK_LEFT || lastkey==SDLK_KP4)?msnd5:msnd6,255);//if(!movsndt) movsndt=Z_sound((lastkey==0x4B || lastkey==0xCB)?msnd5:msnd6,255); - break; - case SDLK_RETURN: case SDLK_SPACE: case SDLK_KP_ENTER://case 0x1C: case 0x39: case 0x9C: - if(!mnu) break; - if(mnu->type!=MENU) break; - if(mnu->t[mnu->cur]>=PL1CM) { - Z_sound(msnd2,128); - GM_command(PLCEND); - break; - } - if(mnu->t[mnu->cur]>=SVOLM) break; - Z_sound(msnd2,128); - GM_command(mnu->t[mnu->cur]); - break; - case SDLK_y://case 0x15: - if(!mnu) break; - if(mnu->type!=MSG) break; - Z_sound(msnd3,128); - GM_command(mnu->t[0]); - break; - case SDLK_n://case 0x31: - if(!mnu) break; - if(mnu->type!=MSG) break; - Z_sound(msnd4,128); - GM_command(mnu->t[1]); - break; - case SDLK_F1://case 0x3B: - if(shot_vga) {shot();Z_sound(msnd4,128);} - break; - } + if (input) { + switch (lastkey) { + case KEY_RETURN: + case KEY_KP_ENTER: + F_savegame(save_mnu.cur, ibuf); + input = 0; + GM_set(NULL); + break; + case KEY_ESCAPE: + input = 0; + GM_set(mnu); + break; + case KEY_BACKSPACE: + if (icur) { + icur -= 1; + ibuf[icur] = 0; + GM_set(mnu); + } + break; + default: + if (icur < 23) { + c = get_keychar(lastkey); + if (c != 0) { + ibuf[icur] = c; + icur += 1; + ibuf[icur] = 0; + GM_set(mnu); + } + } + break; + } + } else { + switch (lastkey) { + case KEY_ESCAPE: + if (mnu == NULL) { + GM_set(&main_mnu); + Z_sound(msnd3, 128); + } else { + GM_set(NULL); + Z_sound(msnd4, 128); + } + break; + case KEY_F5: + if (mnu == NULL) { + Z_sound(msnd3, 128); + GMV_say("_GAMMA"); + GM_set(&gamma_mnu); + } + break; + case KEY_F4: + if (mnu == NULL) { + Z_sound(msnd3, 128); + GMV_say("_VOLUME"); + GM_set(&vol_mnu); + } + break; + case KEY_F2: + if (mnu == NULL && g_st == GS_GAME) { + Z_sound(msnd3, 128); + F_getsavnames(); + GM_set(&save_mnu); + } + break; + case KEY_F3: + if (mnu == NULL) { + Z_sound(msnd3, 128); + F_getsavnames(); + GM_set(&load_mnu); + } + break; + case KEY_F10: + if (mnu == NULL) { + Z_sound(msnd3, 128); + GM_command(QUITGAME); + } + break; + case KEY_UP: + case KEY_KP_8: + if (mnu != NULL && mnu->type == MENU) { + mnu->cur -= 1; + if (mnu->cur < 0) { + mnu->cur = mnu->n - 1; + } + GM_set(mnu); + Z_sound(msnd1, 128); + } + break; + case KEY_DOWN: + case KEY_KP_5: + case KEY_KP_2: + if (mnu != NULL && mnu->type == MENU) { + mnu->cur += 1; + if (mnu->cur >= mnu->n) { + mnu->cur = 0; + } + GM_set(mnu); + Z_sound(msnd1, 128); + } + break; + case KEY_LEFT: + case KEY_RIGHT: + case KEY_KP_4: + case KEY_KP_6: + if (mnu != NULL && mnu->type == MENU && mnu->t[mnu->cur] >= SVOLM) { + GM_command(mnu->t[mnu->cur] + (lastkey == KEY_LEFT || lastkey == KEY_KP_4)); + GM_set(mnu); + if (!movsndt) { + movsndt = Z_sound(lastkey == KEY_LEFT || lastkey == KEY_KP_4 ? msnd5 : msnd6, 255); + } + } + break; + case KEY_RETURN: + case KEY_SPACE: + case KEY_KP_ENTER: + if (mnu != NULL && mnu->type == MENU) { + if (mnu->t[mnu->cur] >= PL1CM) { + Z_sound(msnd2, 128); + GM_command(PLCEND); + break; + } else if (mnu->t[mnu->cur] < SVOLM) { + Z_sound(msnd2,128); + GM_command(mnu->t[mnu->cur]); + } + } + break; + case KEY_Y: + if (mnu != NULL && mnu->type == MSG) { + Z_sound(msnd3, 128); + GM_command(mnu->t[0]); + } + break; + case KEY_N: + if (mnu != NULL && mnu->type == MSG) { + Z_sound(msnd4, 128); + GM_command(mnu->t[1]); + } + break; + case KEY_F1: + if (shot_vga) { + shot(); + Z_sound(msnd4, 128); + } + break; + } } - lastkey=0; - return((mnu)?1:0); + lastkey = KEY_UNKNOWN; + return mnu ? 1 : 0; } -static void G_keyf (int k, int press) { +void G_keyf (int key, int down) { int i; - - lastkey=k; - if(!_2pl || cheat) { - for(i=0;i<31;++i) cbuf[i]=cbuf[i+1]; - cbuf[31]=get_keychar(k); + if (down) { + lastkey = key; + if (!_2pl || cheat) { + for (i = 0; i < 31; ++i) { + cbuf[i] = cbuf[i + 1]; + } + cbuf[31] = get_keychar(key); + } } } @@ -545,5 +602,4 @@ void GM_init (void) { msnd4=Z_getsnd("SWTCHX"); msnd5=Z_getsnd("SUDI"); msnd6=Z_getsnd("TUDI"); - K_setkeyproc(G_keyf); } diff --git a/src/menu.h b/src/menu.h index 3e6c65e..fedd702 100644 --- a/src/menu.h +++ b/src/menu.h @@ -49,6 +49,7 @@ extern byte gm_redraw; extern short lastkey; void GMV_say (char *nm); +void G_keyf (int key, int down); void G_code (void); int GM_act (void); void GM_init (void); diff --git a/src/my.c b/src/my.c index a966eb8..28dba3d 100644 --- a/src/my.c +++ b/src/my.c @@ -20,7 +20,6 @@ 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ -#include #include "glob.h" #include "error.h" #include "misc.h" @@ -126,10 +125,6 @@ void myfwrite32 (int32_t x, FILE *f) { myfwrite(&x, 4, 1, f); } -void myrandomize (void) { - srand(SDL_GetTicks()); -} - int fexists (char *filename) { FILE *f; if ((f = fopen(filename, "r"))) diff --git a/src/my.h b/src/my.h index 15792f1..a278cc2 100644 --- a/src/my.h +++ b/src/my.h @@ -39,8 +39,6 @@ void myfwrite8 (int8_t x, FILE *f); void myfwrite16 (int16_t x, FILE *f); void myfwrite32 (int32_t x, FILE *f); -void myrandomize (void); - int fexists (char *filename); #endif /* MY_H_INCLUDED */ diff --git a/src/player.c b/src/player.c index f593f30..4ade170 100644 --- a/src/player.c +++ b/src/player.c @@ -23,7 +23,6 @@ #include "glob.h" #include #include -#include "keyb.h" #include "view.h" #include "dots.h" #include "smoke.h" @@ -36,6 +35,7 @@ #include "misc.h" #include "my.h" #include "game.h" +#include "input.h" #define PL_RAD 8 #define PL_HT 26 @@ -202,22 +202,22 @@ static void fire(player_t *p) { if(p->cwpn) return; if(p->wpn==8) { if(!p->fire) - if(keys[p->kf] && p->cell>=40) + if(I_pressed(p->kf) && p->cell>=40) {Z_sound(snd[5],128);p->fire=21;p->cell-=40;p->drawst|=PL_DRAWWPN;return;} else return; if(p->fire==1) p->cwpn=12; else return; }else if(p->wpn==1) { if(!p->csnd) { - if(!keys[p->kf]) {Z_sound(snd[7],128);p->csnd=13;return;} + if(!I_pressed(p->kf)) {Z_sound(snd[7],128);p->csnd=13;return;} } - if(keys[p->kf] && !p->fire) { + if(I_pressed(p->kf) && !p->fire) { p->fire=2; WP_chainsaw(p->o.x+((p->d)?4:-4),p->o.y,(g_dm)?9:3,p->id); if(!p->csnd) {Z_sound(snd[8],128);p->csnd=29;} }return; }else if(p->fire) return; - if(keys[p->kf] || p->wpn==8) { + if(I_pressed(p->kf) || p->wpn==8) { switch(p->wpn) { case 2: case 5: if(!p->ammo) return; @@ -252,10 +252,10 @@ static void fire(player_t *p) { static void chgwpn(player_t *p) { if(p->cwpn) return; if(p->fire && p->wpn!=1) return; - if(keys[p->kwl]) { + if(I_pressed(p->kwl)) { do{ if(--p->wpn<0) p->wpn=10; }while(!(p->wpns&(1<wpn))); p->cwpn=3; - }else if(keys[p->kwr]) { + }else if(I_pressed(p->kwr)) { do{ if(++p->wpn>10) p->wpn=0; }while(!(p->wpns&(1<wpn))); p->cwpn=3; } @@ -277,7 +277,7 @@ static void jump(player_t *p,int st) { } p->drawst|=PL_DRAWAIR; } - if(keys[p->kj]) { + if(I_pressed(p->kj)) { if(p_fly) { p->o.yv=-PL_FLYUP; }else{ @@ -577,14 +577,14 @@ void PL_act (player_t *p) { }else st=0; if(st&Z_HITWATER) Z_splash(&p->o,PL_RAD+PL_HT); if(p->f&PLF_FIRE) if(p->fire!=2) p->f-=PLF_FIRE; - if(keys[p->ku]) {p->f|=PLF_UP;p->looky-=5;} + if(I_pressed(p->ku)) {p->f|=PLF_UP;p->looky-=5;} else{ p->f&=0xFFFF-PLF_UP; - if(keys[p->kd]) + if(I_pressed(p->kd)) {p->f|=PLF_DOWN;p->looky+=5;} else {p->f&=0xFFFF-PLF_DOWN;p->looky=Z_dec(p->looky,5);} } - if(keys[p->kp]) SW_press(p->o.x,p->o.y,p->o.r,p->o.h,1|p->keys,p->id); + if(I_pressed(p->kp)) SW_press(p->o.x,p->o.y,p->o.r,p->o.h,1|p->keys,p->id); if(p->fire) --p->fire; if(p->cwpn) --p->cwpn; if(p->csnd) --p->csnd; @@ -606,15 +606,15 @@ void PL_act (player_t *p) { if(p_fly) SMK_gas(p->o.x,p->o.y-2,2,3,p->o.xv+p->o.vx,p->o.yv+p->o.vy,128); if((p->s+=abs(p->o.xv)/2) >= 24) p->s%=24; - if(!keys[p->kl] && !keys[p->kr]) { + if(!I_pressed(p->kl) && !I_pressed(p->kr)) { if(p->o.xv) p->o.xv=Z_dec(p->o.xv,1); else p->st=STAND; break; } - if(p->o.xvkr]) {p->o.xv+=PL_RUN>>3;p->d=1;} + if(p->o.xvkr)) {p->o.xv+=PL_RUN>>3;p->d=1;} else if(PL_RUN>8) SMK_gas(p->o.x,p->o.y-2,2,3,p->o.xv+p->o.vx,p->o.yv+p->o.vy,32); - if(p->o.xv>-PL_RUN && keys[p->kl]) {p->o.xv-=PL_RUN>>3;p->d=0;} + if(p->o.xv>-PL_RUN && I_pressed(p->kl)) {p->o.xv-=PL_RUN>>3;p->d=0;} else if(PL_RUN>8) SMK_gas(p->o.x,p->o.y-2,2,3,p->o.xv+p->o.vx,p->o.yv+p->o.vy,32); break; @@ -622,15 +622,15 @@ void PL_act (player_t *p) { chgwpn(p);fire(p);jump(p,st); if(p_fly) SMK_gas(p->o.x,p->o.y-2,2,3,p->o.xv+p->o.vx,p->o.yv+p->o.vy,128); - if(keys[p->kl]) {p->st=GO;p->s=0;p->d=0;} - else if(keys[p->kr]) {p->st=GO;p->s=0;p->d=1;} + if(I_pressed(p->kl)) {p->st=GO;p->s=0;p->d=0;} + else if(I_pressed(p->kr)) {p->st=GO;p->s=0;p->d=1;} break; case DEAD: case MESS: case OUT: p->o.xv=Z_dec(p->o.xv,1); - if(keys[p->ku] || keys[p->kd] || keys[p->kl] || keys[p->kr] || - keys[p->kf] || keys[p->kj] || keys[p->kp] || keys[p->kwl] || keys[p->kwr]) { + if(I_pressed(p->ku) || I_pressed(p->kd) || I_pressed(p->kl) || I_pressed(p->kr) || + I_pressed(p->kf) || I_pressed(p->kj) || I_pressed(p->kp) || I_pressed(p->kwl) || I_pressed(p->kwr)) { if(p->st!=OUT) MN_spawn_deadpl(&p->o,p->color,(p->st==MESS)?1:0); PL_restore(p); if(g_dm) {G_respawn_player(p);break;} diff --git a/src/sdl/main.c b/src/sdl/main.c new file mode 100644 index 0000000..3aaad80 --- /dev/null +++ b/src/sdl/main.c @@ -0,0 +1,245 @@ +/* + Copyright (C) Prikol Software 1996-1997 + Copyright (C) Aleksey Volynskov 1996-1997 + Copyright (C) 2011 + + This file is part of the Doom2D:Rembo project. + + Doom2D:Rembo is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License version 2 as + published by the Free Software Foundation. + + Doom2D:Rembo is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, see or + write to the Free Software Foundation, Inc., + 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#include +#include // srand +#include // strcasecmp +#include "input.h" + +#include "my.h" // fexists +#include "player.h" // pl1 pl2 +#include "menu.h" // GM_init G_keyf +#include "error.h" // logo + +#include "files.h" // F_startup F_addwad F_initwads F_allocres +#include "config.h" // CFG_args CFG_load +#include "memory.h" // M_startup +#include "game.h" // G_Init G_act +#include "sound.h" // S_init S_done +#include "music.h" // S_initmusic S_updatemusic S_donemusic +#include "render.h" // R_init R_draw R_done + +static int quit = 0; + +static int sdl_to_key (int code) { + switch (code) { + case SDLK_0: return KEY_0; + case SDLK_1: return KEY_1; + case SDLK_2: return KEY_2; + case SDLK_3: return KEY_3; + case SDLK_4: return KEY_4; + case SDLK_5: return KEY_5; + case SDLK_6: return KEY_6; + case SDLK_7: return KEY_7; + case SDLK_8: return KEY_8; + case SDLK_9: return KEY_9; + case SDLK_a: return KEY_A; + case SDLK_b: return KEY_B; + case SDLK_c: return KEY_C; + case SDLK_d: return KEY_D; + case SDLK_e: return KEY_E; + case SDLK_f: return KEY_F; + case SDLK_g: return KEY_G; + case SDLK_h: return KEY_H; + case SDLK_i: return KEY_I; + case SDLK_j: return KEY_J; + case SDLK_k: return KEY_K; + case SDLK_l: return KEY_L; + case SDLK_m: return KEY_M; + case SDLK_n: return KEY_N; + case SDLK_o: return KEY_O; + case SDLK_p: return KEY_P; + case SDLK_q: return KEY_Q; + case SDLK_r: return KEY_R; + case SDLK_s: return KEY_S; + case SDLK_t: return KEY_T; + case SDLK_u: return KEY_U; + case SDLK_v: return KEY_V; + case SDLK_w: return KEY_W; + case SDLK_x: return KEY_X; + case SDLK_y: return KEY_Y; + case SDLK_z: return KEY_Z; + case SDLK_RETURN: return KEY_RETURN; + case SDLK_ESCAPE: return KEY_ESCAPE; + case SDLK_BACKSPACE: return KEY_BACKSPACE; + case SDLK_TAB: return KEY_TAB; + case SDLK_SPACE: return KEY_SPACE; + case SDLK_MINUS: return KEY_MINUS; + case SDLK_EQUALS: return KEY_EQUALS; + case SDLK_LEFTBRACKET: return KEY_LEFTBRACKET; + case SDLK_RIGHTBRACKET: return KEY_RIGHTBRACKET; + case SDLK_BACKSLASH: return KEY_BACKSLASH; + case SDLK_SEMICOLON: return KEY_SEMICOLON; + case SDLK_QUOTE: return KEY_APOSTROPHE; + case SDLK_BACKQUOTE: return KEY_GRAVE; + case SDLK_COMMA: return KEY_COMMA; + case SDLK_PERIOD: return KEY_PERIOD; + case SDLK_SLASH: return KEY_SLASH; + case SDLK_CAPSLOCK: return KEY_CAPSLOCK; + case SDLK_F1: return KEY_F1; + case SDLK_F2: return KEY_F2; + case SDLK_F3: return KEY_F3; + case SDLK_F4: return KEY_F4; + case SDLK_F5: return KEY_F5; + case SDLK_F6: return KEY_F6; + case SDLK_F7: return KEY_F7; + case SDLK_F8: return KEY_F8; + case SDLK_F9: return KEY_F9; + case SDLK_F10: return KEY_F10; + case SDLK_F11: return KEY_F11; + case SDLK_F12: return KEY_F12; + case SDLK_PRINT: return KEY_PRINTSCREEN; + case SDLK_SCROLLOCK: return KEY_SCROLLLOCK; + case SDLK_PAUSE: return KEY_PAUSE; + case SDLK_INSERT: return KEY_INSERT; + case SDLK_HOME: return KEY_HOME; + case SDLK_PAGEUP: return KEY_PAGEUP; + case SDLK_DELETE: return KEY_DELETE; + case SDLK_END: return KEY_END; + case SDLK_PAGEDOWN: return KEY_PAGEDOWN; + case SDLK_RIGHT: return KEY_RIGHT; + case SDLK_LEFT: return KEY_LEFT; + case SDLK_DOWN: return KEY_DOWN; + case SDLK_UP: return KEY_UP; + case SDLK_NUMLOCK: return KEY_NUMLOCK; + case SDLK_KP_DIVIDE: return KEY_KP_DIVIDE; + case SDLK_KP_MULTIPLY: return KEY_KP_MULTIPLY; + case SDLK_KP_MINUS: return KEY_KP_MINUS; + case SDLK_KP_PLUS: return KEY_KP_PLUS; + case SDLK_KP_ENTER: return KEY_KP_ENTER; + case SDLK_KP0: return KEY_KP_0; + case SDLK_KP1: return KEY_KP_1; + case SDLK_KP2: return KEY_KP_2; + case SDLK_KP3: return KEY_KP_3; + case SDLK_KP4: return KEY_KP_4; + case SDLK_KP5: return KEY_KP_5; + case SDLK_KP6: return KEY_KP_6; + case SDLK_KP7: return KEY_KP_7; + case SDLK_KP8: return KEY_KP_8; + case SDLK_KP9: return KEY_KP_9; + case SDLK_KP_PERIOD: return KEY_KP_PERIOD; + case SDLK_SYSREQ: return KEY_SYSREQ; + case SDLK_LCTRL: return KEY_LCTRL; + case SDLK_LSHIFT: return KEY_LSHIFT; + case SDLK_LALT: return KEY_LALT; + case SDLK_LSUPER: return KEY_LSUPER; + case SDLK_RCTRL: return KEY_RCTRL; + case SDLK_RSHIFT: return KEY_RSHIFT; + case SDLK_RALT: return KEY_RALT; + case SDLK_RSUPER: return KEY_RSUPER; + default: return KEY_UNKNOWN; + } +} + +static void poll_events (void (*h)(int key, int down)) { + int key; + SDL_Event ev; + while (SDL_PollEvent(&ev)) { + switch (ev.type) { + case SDL_QUIT: + ERR_quit(); + break; + case SDL_KEYDOWN: + case SDL_KEYUP: + key = sdl_to_key(ev.key.keysym.sym); + I_press(key, ev.type == SDL_KEYDOWN); + if (h != NULL) { + (*h)(key, ev.type == SDL_KEYDOWN); + } + break; + } + } +} + +int SDL_main (int argc, char *argv[]) { + char *pw; + Uint32 t, ticks; + logo("main: initialize SDL\n"); + if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER) == -1) { + logo("main: failed to init SDL: %s\n", SDL_GetError()); + return 1; + } + SDL_WM_SetCaption("Doom 2D v1.351", "Doom 2D"); + pl1.id = -1; // TODO move to generic code + pl2.id = -2; // TODO move to generic code + // Player 1 defaults + pl1.ku = KEY_KP_8; + pl1.kd = KEY_KP_5; + pl1.kl = KEY_KP_4; + pl1.kr = KEY_KP_6; + pl1.kf = KEY_PAGEDOWN; + pl1.kj = KEY_DELETE; + pl1.kwl = KEY_HOME; + pl1.kwr = KEY_END; + pl1.kp = KEY_KP_8; + // Player 2 defaults + pl2.ku = KEY_E; + pl2.kd = KEY_D; + pl2.kl = KEY_S; + pl2.kr = KEY_F; + pl2.kf = KEY_A; + pl2.kj = KEY_Q; + pl2.kwl = KEY_1; + pl2.kwr = KEY_2; + pl2.kp = KEY_E; + srand(SDL_GetTicks()); + F_startup(); +#ifndef WIN32 + pw = "/usr/share/doom2d-rembo/doom2d.wad"; +#else + pw = "doom2d.wad"; +#endif + if (fexists(pw)) { + F_addwad(pw); + } else { + F_addwad("doom2d.wad"); + } + CFG_args(argc, argv); + CFG_load(); + F_initwads(); + M_startup(); + F_allocres(); + G_init(); + S_init(); + S_initmusic(); + R_init(); + GM_init(); // TODO move to game + F_loadmus("MENU"); // TODO move to menu + S_startmusic(0); // TODO move to menu + ticks = SDL_GetTicks(); + while (!quit) { + poll_events(&G_keyf); + S_updatemusic(); + t = SDL_GetTicks(); + if (t - ticks > DELAY) { + ticks = t; + G_act(); + } + R_draw(); + } + R_done(); + S_donemusic(); + S_done(); + M_shutdown(); + SDL_Quit(); + return 0; +} diff --git a/src/sound.c b/src/sound.c index 2fe510b..4a4077d 100644 --- a/src/sound.c +++ b/src/sound.c @@ -38,6 +38,7 @@ static struct { } chunks[NUM_CHUNKS]; void S_init (void) { + logo("S_init: настройка звука\n"); if (!SDL_WasInit(SDL_INIT_AUDIO)) { if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) { fprintf(stderr, "\nUnable to initialize audio: %s\n", SDL_GetError()); -- 2.29.2