From 318cd69318f1281280d9abf4722d074a641807c6 Mon Sep 17 00:00:00 2001 From: Denis Pauk Date: Sun, 13 Aug 2023 15:07:44 +0300 Subject: [PATCH] Add nolerp filtering by * --- CMakeLists.txt | 5 ++ Makefile | 5 ++ src/client/input/sdl.c | 114 +----------------------- src/client/refresh/gl1/gl1_image.c | 4 +- src/client/refresh/gl1/gl1_main.c | 2 +- src/client/refresh/gl3/gl3_image.c | 4 +- src/client/refresh/gl3/gl3_main.c | 2 +- src/client/refresh/ref_shared.h | 2 +- src/common/header/shared.h | 3 + src/common/shared/utils.c | 137 +++++++++++++++++++++++++++++ 10 files changed, 159 insertions(+), 119 deletions(-) create mode 100644 src/common/shared/utils.c diff --git a/CMakeLists.txt b/CMakeLists.txt index 86b5df74..841cf708 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -460,6 +460,7 @@ set(Client-Source ${COMMON_SRC_DIR}/shared/flash.c ${COMMON_SRC_DIR}/shared/rand.c ${COMMON_SRC_DIR}/shared/shared.c + ${COMMON_SRC_DIR}/shared/utils.c ${COMMON_SRC_DIR}/unzip/ioapi.c ${COMMON_SRC_DIR}/unzip/miniz.c ${COMMON_SRC_DIR}/unzip/unzip.c @@ -523,6 +524,7 @@ set(Server-Source ${COMMON_SRC_DIR}/zone.c ${COMMON_SRC_DIR}/shared/rand.c ${COMMON_SRC_DIR}/shared/shared.c + ${COMMON_SRC_DIR}/shared/utils.c ${COMMON_SRC_DIR}/unzip/ioapi.c ${COMMON_SRC_DIR}/unzip/miniz.c ${COMMON_SRC_DIR}/unzip/unzip.c @@ -573,6 +575,7 @@ set(GL1-Source ${REF_SRC_DIR}/files/wal.c ${REF_SRC_DIR}/files/pvs.c ${COMMON_SRC_DIR}/shared/shared.c + ${COMMON_SRC_DIR}/shared/utils.c ${COMMON_SRC_DIR}/md4.c ) @@ -609,6 +612,7 @@ set(GL3-Source ${REF_SRC_DIR}/files/wal.c ${REF_SRC_DIR}/files/pvs.c ${COMMON_SRC_DIR}/shared/shared.c + ${COMMON_SRC_DIR}/shared/utils.c ${COMMON_SRC_DIR}/md4.c ) @@ -663,6 +667,7 @@ set(SOFT-Source ${REF_SRC_DIR}/files/wal.c ${REF_SRC_DIR}/files/pvs.c ${COMMON_SRC_DIR}/shared/shared.c + ${COMMON_SRC_DIR}/shared/utils.c ${COMMON_SRC_DIR}/md4.c ) diff --git a/Makefile b/Makefile index 98643500..faca5449 100644 --- a/Makefile +++ b/Makefile @@ -882,6 +882,7 @@ CLIENT_OBJS_ := \ src/common/shared/flash.o \ src/common/shared/rand.o \ src/common/shared/shared.o \ + src/common/shared/utils.o \ src/common/unzip/ioapi.o \ src/common/unzip/miniz.o \ src/common/unzip/unzip.o \ @@ -934,6 +935,7 @@ REFGL1_OBJS_ := \ src/client/refresh/files/wal.o \ src/client/refresh/files/pvs.o \ src/common/shared/shared.o \ + src/common/shared/utils.o \ src/common/md4.o ifeq ($(YQ2_OSTYPE), Windows) @@ -966,6 +968,7 @@ REFGL3_OBJS_ := \ src/client/refresh/files/wal.o \ src/client/refresh/files/pvs.o \ src/common/shared/shared.o \ + src/common/shared/utils.o \ src/common/md4.o REFGL3_OBJS_GLADE_ := \ @@ -1009,6 +1012,7 @@ REFSOFT_OBJS_ := \ src/client/refresh/files/wal.o \ src/client/refresh/files/pvs.o \ src/common/shared/shared.o \ + src/common/shared/utils.o \ src/common/md4.o ifeq ($(YQ2_OSTYPE), Windows) @@ -1041,6 +1045,7 @@ SERVER_OBJS_ := \ src/common/zone.o \ src/common/shared/rand.o \ src/common/shared/shared.o \ + src/common/shared/utils.o \ src/common/unzip/ioapi.o \ src/common/unzip/miniz.o \ src/common/unzip/unzip.o \ diff --git a/src/client/input/sdl.c b/src/client/input/sdl.c index b121eca8..3e26762f 100644 --- a/src/client/input/sdl.c +++ b/src/client/input/sdl.c @@ -688,7 +688,7 @@ IN_Update(void) event.window.event == SDL_WINDOWEVENT_FOCUS_GAINED) { Key_MarkAllUp(); - + if (event.window.event == SDL_WINDOWEVENT_FOCUS_LOST) { S_Activate(false); @@ -1688,116 +1688,6 @@ static char *default_haptic_filter = ( "world/*train2 " ); -/* - * name: sound name - * filter: sound name rule with '*' - * return false for empty filter - */ -static qboolean -Haptic_Feedback_Filtered_Line(const char *name, const char *filter) -{ - const char *current_filter = filter; - - // skip empty filter - if (!*current_filter) - { - return false; - } - - while (*current_filter) - { - char part_filter[MAX_QPATH]; - const char *name_part; - const char *str_end; - - str_end = strchr(current_filter, '*'); - if (!str_end) - { - if (!strstr(name, current_filter)) - { - // no such part in string - return false; - } - // have such part - break; - } - // copy filter line - if ((str_end - current_filter) >= MAX_QPATH) - { - return false; - } - memcpy(part_filter, current_filter, str_end - current_filter); - part_filter[str_end - current_filter] = 0; - // place part in name - name_part = strstr(name, part_filter); - if (!name_part) - { - // no such part in string - return false; - } - // have such part - name = name_part + strlen(part_filter); - // move to next filter - current_filter = str_end + 1; - } - - return true; -} - -/* - * name: sound name - * filter: sound names separated by space, and '!' for skip file - */ -static qboolean -Haptic_Feedback_Filtered(const char *name, const char *filter) -{ - const char *current_filter = filter; - - while (*current_filter) - { - char line_filter[MAX_QPATH]; - const char *str_end; - - str_end = strchr(current_filter, ' '); - // its end of filter - if (!str_end) - { - // check rules inside line - if (Haptic_Feedback_Filtered_Line(name, current_filter)) - { - return true; - } - return false; - } - // copy filter line - if ((str_end - current_filter) >= MAX_QPATH) - { - return false; - } - memcpy(line_filter, current_filter, str_end - current_filter); - line_filter[str_end - current_filter] = 0; - // check rules inside line - if (*line_filter == '!') - { - // has invert rule - if (Haptic_Feedback_Filtered_Line(name, line_filter + 1)) - { - return false; - } - } - else - { - if (Haptic_Feedback_Filtered_Line(name, line_filter)) - { - return true; - } - } - // move to next filter - current_filter = str_end + 1; - } - return false; -} - /* * Haptic Feedback: * effect_volume=0..SHRT_MAX @@ -1833,7 +1723,7 @@ Haptic_Feedback(const char *name, int effect_volume, int effect_duration, last_haptic_volume = joy_haptic_magnitude->value * 16; - if (Haptic_Feedback_Filtered(name, haptic_feedback_filter->string)) + if (Utils_FilenameFiltered(name, haptic_feedback_filter->string, ' ')) { int effect_id; diff --git a/src/client/refresh/gl1/gl1_image.c b/src/client/refresh/gl1/gl1_image.c index 863af2a0..74903770 100644 --- a/src/client/refresh/gl1/gl1_image.c +++ b/src/client/refresh/gl1/gl1_image.c @@ -223,9 +223,9 @@ R_TextureMode(char *string) if (unfiltered2D && glt->type == it_pic) { // exception to that exception: stuff on the r_lerp_list - nolerp = (lerplist== NULL) || (strstr(lerplist, glt->name) == NULL); + nolerp = (lerplist == NULL) || Utils_FilenameFiltered(glt->name, lerplist, ' '); } - else if(nolerplist != NULL && strstr(nolerplist, glt->name) != NULL) + else if (nolerplist != NULL && Utils_FilenameFiltered(glt->name, nolerplist, ' ')) { nolerp = true; } diff --git a/src/client/refresh/gl1/gl1_main.c b/src/client/refresh/gl1/gl1_main.c index 99539352..ae624caa 100644 --- a/src/client/refresh/gl1/gl1_main.c +++ b/src/client/refresh/gl1/gl1_main.c @@ -1229,7 +1229,7 @@ R_Register(void) r_scale8bittextures = ri.Cvar_Get("r_scale8bittextures", "0", CVAR_ARCHIVE); /* don't bilerp characters and crosshairs */ - gl_nolerp_list = ri.Cvar_Get("r_nolerp_list", "pics/conchars.pcx pics/ch1.pcx pics/ch2.pcx pics/ch3.pcx", CVAR_ARCHIVE); + gl_nolerp_list = ri.Cvar_Get("r_nolerp_list", DEFAULT_NOLERP_LIST, CVAR_ARCHIVE); /* textures that should always be filtered, even if r_2D_unfiltered or an unfiltered gl mode is used */ r_lerp_list = ri.Cvar_Get("r_lerp_list", "", CVAR_ARCHIVE); /* don't bilerp any 2D elements */ diff --git a/src/client/refresh/gl3/gl3_image.c b/src/client/refresh/gl3/gl3_image.c index 0857b776..58e45cda 100644 --- a/src/client/refresh/gl3/gl3_image.c +++ b/src/client/refresh/gl3/gl3_image.c @@ -99,9 +99,9 @@ GL3_TextureMode(char *string) if (unfiltered2D && glt->type == it_pic) { // exception to that exception: stuff on the r_lerp_list - nolerp = (lerplist== NULL) || (strstr(lerplist, glt->name) == NULL); + nolerp = (lerplist == NULL) || Utils_FilenameFiltered(glt->name, lerplist, ' '); } - else if(nolerplist != NULL && strstr(nolerplist, glt->name) != NULL) + else if (nolerplist != NULL && Utils_FilenameFiltered(glt->name, nolerplist, ' ')) { nolerp = true; } diff --git a/src/client/refresh/gl3/gl3_main.c b/src/client/refresh/gl3/gl3_main.c index 054e1b3f..b5e57b83 100644 --- a/src/client/refresh/gl3/gl3_main.c +++ b/src/client/refresh/gl3/gl3_main.c @@ -236,7 +236,7 @@ GL3_Register(void) r_validation = ri.Cvar_Get("r_validation", "0", CVAR_ARCHIVE); /* don't bilerp characters and crosshairs */ - gl_nolerp_list = ri.Cvar_Get("r_nolerp_list", "pics/conchars.pcx pics/ch1.pcx pics/ch2.pcx pics/ch3.pcx", CVAR_ARCHIVE); + gl_nolerp_list = ri.Cvar_Get("r_nolerp_list", DEFAULT_NOLERP_LIST, CVAR_ARCHIVE); /* textures that should always be filtered, even if r_2D_unfiltered or an unfiltered gl mode is used */ r_lerp_list = ri.Cvar_Get("r_lerp_list", "", CVAR_ARCHIVE); /* don't bilerp any 2D elements */ diff --git a/src/client/refresh/ref_shared.h b/src/client/refresh/ref_shared.h index ac890aa8..c0389642 100644 --- a/src/client/refresh/ref_shared.h +++ b/src/client/refresh/ref_shared.h @@ -74,7 +74,7 @@ typedef enum } modtype_t; #define MAX_LBM_HEIGHT 480 - +#define DEFAULT_NOLERP_LIST "pics/conchars.* pics/ch1.* pics/ch2. pics/ch3.*" extern void R_Printf(int level, const char* msg, ...) PRINTF_ATTR(2, 3); /* Shared images load */ diff --git a/src/common/header/shared.h b/src/common/header/shared.h index 4edb171b..fb6fd3cf 100644 --- a/src/common/header/shared.h +++ b/src/common/header/shared.h @@ -372,6 +372,9 @@ float frandk(void); float crandk(void); void randk_seed(void); +/* Addition code utilities */ +qboolean Utils_FilenameFiltered(const char *name, const char *filter, char sepator); + /* * ============================================================== * diff --git a/src/common/shared/utils.c b/src/common/shared/utils.c new file mode 100644 index 00000000..e5fc33d5 --- /dev/null +++ b/src/common/shared/utils.c @@ -0,0 +1,137 @@ +/* + * Copyright (C) 1997-2001 Id Software, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or (at + * your option) any later version. + * + * This program 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, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA + * 02111-1307, USA. + * + * ======================================================================= + * + * Additional functions shared between client and renders + * + * ======================================================================= + */ + +#include "../header/shared.h" + +/* + * name: file name + * filter: file name line rule with '*' + * return false for empty filter + */ +static qboolean +Utils_FilenameFiltered_Line(const char *name, const char *filter) +{ + const char *current_filter = filter; + + // skip empty filter + if (!*current_filter) + { + return false; + } + + while (*current_filter) + { + char part_filter[MAX_QPATH]; + const char *name_part; + const char *str_end; + + str_end = strchr(current_filter, '*'); + if (!str_end) + { + if (!strstr(name, current_filter)) + { + // no such part in string + return false; + } + // have such part + break; + } + // copy filter line + if ((str_end - current_filter) >= MAX_QPATH) + { + return false; + } + memcpy(part_filter, current_filter, str_end - current_filter); + part_filter[str_end - current_filter] = 0; + // place part in name + name_part = strstr(name, part_filter); + if (!name_part) + { + // no such part in string + return false; + } + // have such part + name = name_part + strlen(part_filter); + // move to next filter + current_filter = str_end + 1; + } + + return true; +} + +/* + * name: file name + * filter: file names separated by sepator, and '!' for skip file + */ +qboolean +Utils_FilenameFiltered(const char *name, const char *filter, char sepator) +{ + const char *current_filter = filter; + + while (*current_filter) + { + char line_filter[MAX_QPATH]; + const char *str_end; + + str_end = strchr(current_filter, sepator); + // its end of filter + if (!str_end) + { + // check rules inside line + if (Utils_FilenameFiltered_Line(name, current_filter)) + { + return true; + } + return false; + } + // copy filter line + if ((str_end - current_filter) >= MAX_QPATH) + { + return false; + } + memcpy(line_filter, current_filter, str_end - current_filter); + line_filter[str_end - current_filter] = 0; + // check rules inside line + if (*line_filter == '!') + { + // has invert rule + if (Utils_FilenameFiltered_Line(name, line_filter + 1)) + { + return false; + } + } + else + { + if (Utils_FilenameFiltered_Line(name, line_filter)) + { + return true; + } + } + // move to next filter + current_filter = str_end + 1; + } + return false; +}