From: DeaDDooMER Date: Mon, 13 Apr 2020 09:47:57 +0000 (+0400) Subject: engine: use lib cp866 where needed X-Git-Url: http://deadsoftware.ru/gitweb?a=commitdiff_plain;h=02f89a09888d2aab62c7bd92b8d3ac33fcd0c0ab;p=flatwaifu.git engine: use lib cp866 where needed --- diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 83cd7f2..9028b81 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -31,6 +31,7 @@ set(D2D_SDL_ROOT ${D2D_GAME_ROOT}/sdl) set(D2D_SDLMIXER_ROOT ${D2D_GAME_ROOT}/sdlmixer) set(D2D_OPENAL_ROOT ${D2D_GAME_ROOT}/openal) set(D2D_STUBSOUND_ROOT ${D2D_GAME_ROOT}/stubsnd) +set(D2D_LIBCP866_ROOT ${D2D_GAME_ROOT}/libs/cp866) aux_source_directory(${D2D_GAME_ROOT} D2D_GAME_SRC) aux_source_directory(${D2D_SDL_ROOT} D2D_SDL_SRC) @@ -42,6 +43,7 @@ aux_source_directory(${D2D_SDL_ROOT} D2D_SDL_SRC) aux_source_directory(${D2D_SDLMIXER_ROOT} D2D_SDLMIXER_SRC) aux_source_directory(${D2D_OPENAL_ROOT} D2D_OPENAL_SRC) aux_source_directory(${D2D_STUBSOUND_ROOT} D2D_STUBSOUND_SRC) +aux_source_directory(${D2D_LIBCP866_ROOT} D2D_LIBCP866_SRC) if(WITH_SDL) if(D2D_FOR_EMSCRIPTEN) @@ -139,15 +141,22 @@ message(STATUS "SYSTEM: " "${SYSTEM_DRIVER}") message(STATUS "RENDER: " "${RENDER_DRIVER}") message(STATUS "SOUND: " "${SOUND_DRIVER}") -add_executable(doom2d ${D2D_GAME_SRC} ${D2D_SYSTEM_SRC} ${D2D_RENDER_SRC} ${D2D_SOUND_SRC}) -target_include_directories(doom2d PRIVATE "${D2D_GAME_ROOT}" "${D2D_SYSTEM_INCLUDE_DIR}" "${D2D_RENDER_INCLUDE_DIR}" "${D2D_SOUND_INCLUDE_DIR}") +set(D2D_USED_SRC ${D2D_GAME_SRC} ${D2D_SYSTEM_SRC} ${D2D_RENDER_SRC} ${D2D_SOUND_SRC} ${D2D_LIBCP866_SRC}) +set(D2D_USED_INCLUDE_DIR "${D2D_GAME_ROOT}" "${D2D_SYSTEM_INCLUDE_DIR}" "${D2D_RENDER_INCLUDE_DIR}" "${D2D_SOUND_INCLUDE_DIR}" "${D2D_LIBCP866_ROOT}") +set(D2D_USED_LIBRARY "${D2D_SYSTEM_LIBRARY}" "${D2D_RENDER_LIBRARY}" "${D2D_SOUND_LIBRARY}") +#message(STATUS "USED SRC: ${D2D_USED_SRC}") +#message(STATUS "USED INC: ${D2D_USED_INCLUDE_DIR}") +#message(STATUS "USED LIB: ${D2D_USED_LIBRARY}") +add_executable(doom2d ${D2D_USED_SRC}) +target_include_directories(doom2d PRIVATE ${D2D_USED_INCLUDE_DIR}) if(D2D_FOR_EMSCRIPTEN) set(CMAKE_EXECUTABLE_SUFFIX ".html") configure_file(${D2D_GAME_ROOT}/doom2d.wad doom2d.wad COPYONLY) set(D2D_DOOM2D_WAD doom2d.wad) configure_file(${D2D_GAME_ROOT}/default.cfg default.cfg COPYONLY) set(D2D_DEFAULT_CFG default.cfg) - set_target_properties(doom2d PROPERTIES LINK_FLAGS "-s WASM=0 -s DISABLE_EXCEPTION_CATCHING=1 -s SAFE_HEAP=1 -s ASSERTIONS=1 -s GL_ASSERTIONS=1 ${D2D_SYSTEM_LINKFLAGS} ${D2D_RENDER_LINKFLAGS} ${D2D_SOUND_LINKFLAGS} --preload-file ${D2D_DOOM2D_WAD} --preload-file ${D2D_DEFAULT_CFG}") + set(D2D_USED_LINKFLAGS ${D2D_SYSTEM_LINKFLAGS} ${D2D_RENDER_LINKFLAGS} ${D2D_SOUND_LINKFLAGS}) + set_target_properties(doom2d PROPERTIES LINK_FLAGS "-s WASM=0 -s DISABLE_EXCEPTION_CATCHING=1 -s SAFE_HEAP=1 -s ASSERTIONS=1 -s GL_ASSERTIONS=1 ${D2D_USED_LINKFLAGS} --preload-file ${D2D_DOOM2D_WAD} --preload-file ${D2D_DEFAULT_CFG}") else() - target_link_libraries(doom2d "${D2D_SYSTEM_LIBRARY}" "${D2D_RENDER_LIBRARY}" "${D2D_SOUND_LIBRARY}") + target_link_libraries(doom2d ${D2D_USED_LIBRARY}) endif() diff --git a/src/files.c b/src/files.c index f7037cf..1b47091 100644 --- a/src/files.c +++ b/src/files.c @@ -39,6 +39,7 @@ #include "switch.h" #include "weapons.h" #include "error.h" +#include "cp866.h" typedef struct { byte n, i, v, d; @@ -223,9 +224,9 @@ void F_initwads (void) { ERR_failinit("Не могу открыть файл2: %s", wads[i]); } mysplitpath(wads[i], f_drive, f_dir, f_name, f_ext); - if (strcasecmp(f_ext, ".lmp") == 0) { + if (cp866_strcasecmp(f_ext, ".lmp") == 0) { for (k = 0; k < MAX_WAD; ++k) { - if (strncasecmp(wad[k].n, f_name, 8) == 0) { + if (cp866_strncasecmp(wad[k].n, f_name, 8) == 0) { wad[k].o = 0; wad[k].l = myfilelength(h); wad[k].f = i; @@ -257,7 +258,7 @@ void F_initwads (void) { w.o = myfread32(h); // len myfread(w.n, 1, 8, h); // name for (k = 0; k < MAX_WAD; ++k) { - if (strncasecmp(wad[k].n, w.n, 8) == 0) { + if (cp866_strncasecmp(wad[k].n, w.n, 8) == 0) { wad[k].o = w.o; wad[k].l = w.l; wad[k].f = i; @@ -329,7 +330,7 @@ void F_saveres(int r, void *p, dword o, dword l) { int F_findres (const char n[8]) { int i; for (i = 0; i < wad_num; i++) { - if (strncasecmp(wad[i].n, n, 8) == 0) { + if (cp866_strncasecmp(wad[i].n, n, 8) == 0) { return i; } } @@ -356,7 +357,7 @@ int F_getsprid (const char n[4], int s, int d) { s+='A';d+='0'; for(i=s_start+1;i=m_end) i=m_start+1; - if (strcasecmp(wad[i].n,"MENU") == 0 || - strcasecmp(wad[i].n,"INTERMUS") == 0 || - strcasecmp(wad[i].n,"\x8a\x8e\x8d\x85\x96\x0") == 0) + if (cp866_strcasecmp(wad[i].n,"MENU") == 0 || + cp866_strcasecmp(wad[i].n,"INTERMUS") == 0 || + cp866_strcasecmp(wad[i].n,"\x8a\x8e\x8d\x85\x96\x0") == 0) continue; - if(strncasecmp(wad[i].n,"DMI",3)!=0) break; + if(cp866_strncasecmp(wad[i].n,"DMI",3)!=0) break; } memcpy(s,wad[i].n,8); } diff --git a/src/gl/render.c b/src/gl/render.c index c057b90..f7180f9 100644 --- a/src/gl/render.c +++ b/src/gl/render.c @@ -22,6 +22,8 @@ #include "view.h" #include "switch.h" // sw_secrets +#include "cp866.h" + #ifdef __APPLE__ # include #else @@ -30,7 +32,6 @@ #include #include #include -#include #include #define VGA_TRANSPARENT_COLOR 0 @@ -629,11 +630,9 @@ static image Z_getspr (const char n[4], int s, int d, char *dir) { static image *Z_get_char_image (image *img, int ch) { image *p = NULL; + ch = cp866_toupper(ch); if (ch > 32 && ch < 160) { p = &img[ch - '!']; - if (p->n == NULL) { - p = &img[toupper(ch) - '!']; - } } return p; } diff --git a/src/libs/cp866/cp866.c b/src/libs/cp866/cp866.c index 90d1bbd..3494b61 100644 --- a/src/libs/cp866/cp866.c +++ b/src/libs/cp866/cp866.c @@ -1,22 +1,18 @@ #include "cp866.h" -int cp866_isalpha (char c) { - unsigned char ch = c; +int cp866_isalpha (int ch) { return (ch >= 0x41 && ch <= 0x5A) || (ch >= 0x61 && ch <= 0x7A) || (ch >= 0x80 && ch <= 0xAF) || (ch >= 0xE0 && ch <= 0xF7); } -int cp866_isupper (char c) { - unsigned char ch = c; +int cp866_isupper (int ch) { return (ch >= 0x41 && ch <= 0x5A) || (ch >= 0x80 && ch <= 0x9F) || ch == 0xF0 || ch == 0xF2 || ch == 0xF4 || ch == 0xF6; } -int cp866_islower (char c) { - unsigned char ch = c; +int cp866_islower (int ch) { return (ch >= 0x61 && ch <= 0x7A) || (ch >= 0xA0 && ch <= 0xAF) || (ch >= 0xE0 && ch <= 0xEF) || ch == 0xF1 || ch == 0xF3 || ch == 0xF5 || ch == 0xF7; } -char cp866_toupper (char c) { - unsigned char ch = c; +int cp866_toupper (int ch) { if (ch >= 0x61 && ch <= 0x7A) { return ch - 0x61 + 0x41; } else if (ch >= 0xA0 && ch <= 0xAF) { @@ -36,8 +32,7 @@ char cp866_toupper (char c) { } } -char cp866_tolower (char c) { - unsigned char ch = c; +int cp866_tolower (int ch) { if (ch >= 0x41 && ch <= 0x5A) { return ch - 0x41 + 0x61; } else if (ch >= 0x80 && ch <= 0x8F) { @@ -79,8 +74,7 @@ int cp866_strncasecmp (const char *a, const char *b, unsigned int n) { return i == 0 ? 0 : *(const unsigned char *)aa - *(const unsigned char *)bb; } -int cp866_ctou (char c) { - unsigned char ch = c; +int cp866_ctou (int ch) { switch (ch) { case 0xB0: return 0x2591; case 0xB1: return 0x2592; @@ -159,8 +153,7 @@ int cp866_ctou (char c) { } } -int cp866_ctoug (char c) { - unsigned char ch = c; +int cp866_ctoug (int ch) { switch (ch) { case 0x00: return 0x0000; case 0x01: return 0x263A; diff --git a/src/libs/cp866/cp866.h b/src/libs/cp866/cp866.h index 57c3ee7..7a8d697 100644 --- a/src/libs/cp866/cp866.h +++ b/src/libs/cp866/cp866.h @@ -1,16 +1,16 @@ #ifndef CP866_H_INCLUDED #define CP866_H_INCLUDED -int cp866_isalpha (char ch); -int cp866_isupper (char ch); -int cp866_islower (char ch); -char cp866_toupper (char ch); -char cp866_tolower (char ch); +int cp866_isalpha (int ch); +int cp866_isupper (int ch); +int cp866_islower (int ch); +int cp866_toupper (int ch); +int cp866_tolower (int ch); int cp866_strcasecmp (const char *a, const char *b); int cp866_strncasecmp (const char *a, const char *b, unsigned int n); -int cp866_ctou (char ch); -int cp866_ctoug (char ch); +int cp866_ctou (int ch); +int cp866_ctoug (int ch); int cp866_utoc (int ch); #endif /* CP866_H_INCLUDED */ diff --git a/src/sdl/main.c b/src/sdl/main.c index 9227725..4f529db 100644 --- a/src/sdl/main.c +++ b/src/sdl/main.c @@ -28,8 +28,6 @@ #include #include #include // srand exit -#include // strcasecmp -#include #include #include "system.h" #include "input.h" diff --git a/src/sdl2/main.c b/src/sdl2/main.c index 1a25886..5b111de 100644 --- a/src/sdl2/main.c +++ b/src/sdl2/main.c @@ -11,6 +11,8 @@ #include "system.h" #include "input.h" +#include "cp866.h" + #include "my.h" // fexists #include "player.h" // pl1 pl2 #include "menu.h" // G_keyf @@ -505,8 +507,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; } }