From 91a9f20af7948bd48368c4db2fe6b94b6a335b9a Mon Sep 17 00:00:00 2001 From: Indev Date: Tue, 24 Sep 2024 00:08:48 +0300 Subject: [PATCH 01/66] Skip map marker in vres_GetMap --- src/w_wad.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/w_wad.c b/src/w_wad.c index 5e2f4ce10..118c5011f 100644 --- a/src/w_wad.c +++ b/src/w_wad.c @@ -2169,8 +2169,16 @@ virtres_t* vres_GetMap(lumpnum_t lumpnum) if (vsizecache[realentry] == 0) continue; vlumps[i].size = vsizecache[realentry]; + + const char *name = (fileinfo + realentry)->name; + if (strlen(name) == 5 && memcmp(name, "MAP", 3) == 0) + { + numlumps--; // We skip map marker, so 1 of entries becomes empty + continue; // This will skip i++ so we will write to same entry + } + // Play it safe with the name in this case. - memcpy(vlumps[i].name, (fileinfo + realentry)->name, 8); + memcpy(vlumps[i].name, name, 8); vlumps[i].name[8] = '\0'; vlumps[i].data = Z_Malloc(vlumps[i].size, PU_LEVEL, NULL); // This is memory inefficient, sorry about that. memcpy(vlumps[i].data, wadData + LONG((fileinfo + realentry)->filepos), vlumps[i].size); @@ -2196,8 +2204,17 @@ virtres_t* vres_GetMap(lumpnum_t lumpnum) vlumps = Z_Malloc(sizeof(virtlump_t)*numlumps, PU_LEVEL, NULL); for (i = 0; i < numlumps; i++, lumpnum++) { + // Check if it is map marker. It is not always first lump sadly, so we need to expect it anywhere + const char *name = W_CheckNameForNum(lumpnum); + if (strlen(name) == 5 && memcmp(name, "MAP", 3) == 0) + { + --i; // Decrement so on next iteration we write on same i, so we don't leave corrupted vlumps entry + numlumps--; // Just so we don't try to access the leftover vlumps entry + continue; + } + vlumps[i].size = W_LumpLength(lumpnum); - memcpy(vlumps[i].name, W_CheckNameForNum(lumpnum), 8); + memcpy(vlumps[i].name, name, 8); vlumps[i].name[8] = '\0'; vlumps[i].data = W_CacheLumpNum(lumpnum, PU_LEVEL); } From e1a65add5d86798fe4c506fe249e141e38491c6e Mon Sep 17 00:00:00 2001 From: Indev Date: Mon, 30 Sep 2024 10:35:27 +0300 Subject: [PATCH 02/66] Put all text input logic into separate file and use it for all text input fields --- src/Android.mk | 1 + src/CMakeLists.txt | 1104 ++++++++++++++++++++++---------------------- src/Makefile | 1 + src/console.c | 395 ++-------------- src/lua_script.c | 9 +- src/m_menu.c | 295 ++++++------ src/m_menu.h | 4 + src/m_textinput.c | 306 ++++++++++++ src/m_textinput.h | 23 + src/v_video.c | 29 +- src/v_video.h | 9 +- 11 files changed, 1108 insertions(+), 1068 deletions(-) create mode 100644 src/m_textinput.c create mode 100644 src/m_textinput.h diff --git a/src/Android.mk b/src/Android.mk index 035d48887..1d0603e6f 100644 --- a/src/Android.mk +++ b/src/Android.mk @@ -28,6 +28,7 @@ LOCAL_SRC_FILES := am_map.c \ m_cheat.c \ m_fixed.c \ m_menu.c \ + m_textinput.c \ m_misc.c \ m_queue.c \ m_random.c \ diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 258ff882c..adce10023 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,551 +1,553 @@ -# SRB2 Core - -# Core sources -set(SRB2_CORE_SOURCES - am_map.c - b_bot.c - command.c - comptime.c - console.c - d_clisrv.c - d_main.c - d_net.c - d_netcmd.c - d_netfil.c - d_protocol.c - dehacked.c - f_finale.c - f_wipe.c - filesrch.c - g_game.c - g_input.c - hu_stuff.c - i_tcp.c - info.c - lzf.c - m_aatree.c - m_anigif.c - m_argv.c - m_bbox.c - m_cheat.c - m_cond.c - m_fixed.c - m_menu.c - m_misc.c - m_perfstats.c - m_queue.c - m_random.c - md5.c - mserv.c - http-mserv.c - qs22j.c - s_sound.c - screen.c - sounds.c - st_stuff.c - #string.c - tables.c - v_video.c - w_wad.c - y_inter.c - z_zone.c -) - -set(SRB2_CORE_HEADERS - am_map.h - b_bot.h - byteptr.h - command.h - console.h - d_clisrv.h - d_event.h - d_main.h - d_net.h - d_netcmd.h - d_netfil.h - d_player.h - d_protocol.h - d_think.h - d_ticcmd.h - dehacked.h - doomdata.h - doomdef.h - doomstat.h - doomtype.h - endian.h - f_finale.h - fastcmp.h - filesrch.h - g_game.h - g_input.h - g_state.h - hu_stuff.h - i_joy.h - i_net.h - i_sound.h - i_system.h - i_tcp.h - i_time.h - i_video.h - info.h - keys.h - lzf.h - m_aatree.h - m_anigif.h - m_argv.h - m_bbox.h - m_cheat.h - m_cond.h - m_dllist.h - m_fixed.h - m_menu.h - m_misc.h - m_queue.h - m_perfstats.h - m_random.h - m_swap.h - md5.h - mserv.h - qs22j.h - s_sound.h - screen.h - sounds.h - st_stuff.h - tables.h - v_video.h - w_wad.h - y_inter.h - z_zone.h - - config.h.in -) - -set(SRB2_CORE_RENDER_SOURCES - r_bsp.c - r_data.c - r_draw.c - r_fps.c - r_main.c - r_patch.c - r_plane.c - r_segs.c - r_sky.c - r_splats.c - r_things.c - - r_bsp.h - r_data.h - r_defs.h - r_draw.h - r_fps.h - r_local.h - r_main.h - r_patch - r_plane.h - r_segs.h - r_sky.h - r_splats.h - r_state.h - r_things.h -) - -set(SRB2_CORE_GAME_SOURCES - p_ceilng.c - p_enemy.c - p_floor.c - p_inter.c - p_lights.c - p_map.c - p_maputl.c - p_mobj.c - p_polyobj.c - p_saveg.c - p_setup.c - p_sight.c - p_slopes.c - p_spec.c - p_telept.c - p_tick.c - p_user.c - k_director.c - k_kart.c - i_time.c - - p_local.h - p_maputl.h - p_mobj.h - p_polyobj.h - p_pspr.h - p_saveg.h - p_setup.h - p_slopes.h - p_spec.h - p_tick.h - k_director.h - k_kart.h -) - -if(NOT (CMAKE_CXX_COMPILER_ID MATCHES "Clang")) - set(SRB2_CORE_SOURCES ${SRB2_CORE_SOURCES} string.c) -endif() - -prepend_sources(SRB2_CORE_SOURCES) -prepend_sources(SRB2_CORE_HEADERS) -prepend_sources(SRB2_CORE_RENDER_SOURCES) -prepend_sources(SRB2_CORE_GAME_SOURCES) - -set(SRB2_CORE_HEADERS ${SRB2_CORE_HEADERS} ${CMAKE_CURRENT_BINARY_DIR}/config.h) -source_group("Main" FILES ${SRB2_CORE_SOURCES} ${SRB2_CORE_HEADERS}) -source_group("Renderer" FILES ${SRB2_CORE_RENDER_SOURCES}) -source_group("Game" FILES ${SRB2_CORE_GAME_SOURCES}) - -### Configuration -set(SRB2_CONFIG_HAVE_BLUA ON CACHE BOOL - "Enable Lua interpreter support") -set(SRB2_CONFIG_HAVE_PNG ON CACHE BOOL - "Enable PNG support. Depends on zlib, so will be disabled if you don't enable that too.") -set(SRB2_CONFIG_HAVE_ZLIB ON CACHE BOOL - "Enable zlib support.") -set(SRB2_CONFIG_HAVE_GME ON CACHE BOOL - "Enable GME support.") -set(SRB2_CONFIG_HAVE_OPENMPT ON CACHE BOOL - "Enable OpenMPT support.") -set(SRB2_CONFIG_HAVE_DISCORDRPC OFF CACHE BOOL - "Enable Discord rich presence support.") -set(SRB2_CONFIG_HAVE_CURL ON CACHE BOOL - "Enable curl support, used for downloading files via HTTP.") -set(SRB2_CONFIG_HWRENDER ON CACHE BOOL - "Enable hardware rendering through OpenGL.") -set(SRB2_CONFIG_STATIC_OPENGL OFF CACHE BOOL - "Use statically linked OpenGL. NOT RECOMMENDED.") -set(SRB2_CONFIG_USE_FBO_OGL ON CACHE BOOL - "Enable OpenGL FBO Downsampling support.") - -### use internal libraries? -if(${CMAKE_SYSTEM} MATCHES "Windows") ###set on Windows only - set(SRB2_CONFIG_USE_INTERNAL_LIBRARIES OFF CACHE BOOL - "Use SRB2Kart's internal copies of required dependencies (SDL2, PNG, zlib, GME, OpenMPT).") -endif() - -if(${SRB2_CONFIG_HAVE_BLUA}) - add_definitions(-DHAVE_BLUA) - set(SRB2_LUA_SOURCES - lua_baselib.c - lua_blockmaplib.c - lua_consolelib.c - lua_hooklib.c - lua_hudlib.c - lua_hudlib_drawlist.c - lua_infolib.c - lua_maplib.c - lua_mathlib.c - lua_mobjlib.c - lua_playerlib.c - lua_script.c - lua_skinlib.c - lua_thinkerlib.c - lua_udatalib.c - lua_glib.c - ) - set(SRB2_LUA_HEADERS - lua_hook.h - lua_hud.h - lua_hudlib_drawlist.h - lua_libs.h - lua_script.h - lua_udatalib.h - lua_glib.h - ) - - prepend_sources(SRB2_LUA_SOURCES) - prepend_sources(SRB2_LUA_HEADERS) - - source_group("LUA" FILES ${SRB2_LUA_SOURCES} ${SRB2_LUA_HEADERS}) - - set(SRB2_BLUA_SOURCES - blua/lapi.c - blua/lauxlib.c - blua/lbaselib.c - blua/ldblib.c - blua/lcode.c - blua/ldebug.c - blua/ldo.c - blua/ldump.c - blua/lfunc.c - blua/lgc.c - blua/linit.c - blua/liolib.c - blua/llex.c - blua/lmem.c - blua/lobject.c - blua/lopcodes.c - blua/lparser.c - blua/lstate.c - blua/lstring.c - blua/lstrlib.c - blua/ltable.c - blua/ltablib.c - blua/ltm.c - blua/lundump.c - blua/lvm.c - blua/lzio.c - ) - set(SRB2_BLUA_HEADERS - blua/lapi.h - blua/lauxlib.h - blua/lcode.h - blua/ldebug.h - blua/ldo.h - blua/lfunc.h - blua/lgc.h - blua/llex.h - blua/llimits.h - blua/lmem.h - blua/lobject.h - blua/lopcodes.h - blua/lparser.h - blua/lstate.h - blua/lstring.h - blua/ltable.h - blua/ltm.h - blua/lua.h - blua/luaconf.h - blua/lualib.h - blua/lundump.h - blua/lvm.h - blua/lzio.h - ) - - prepend_sources(SRB2_BLUA_SOURCES) - prepend_sources(SRB2_BLUA_HEADERS) - - source_group("LUA\\Interpreter" FILES ${SRB2_BLUA_SOURCES} ${SRB2_BLUA_HEADERS}) -endif() - -if(${SRB2_CONFIG_HAVE_GME}) - if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) - set(GME_FOUND ON) - set(GME_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/gme/include) - if(${SRB2_SYSTEM_BITS} EQUAL 64) - set(GME_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/gme/win64 -lgme") - else() # 32-bit - set(GME_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/gme/win32 -lgme") - endif() - else() - find_package(GME) - endif() - if(${GME_FOUND}) - set(SRB2_HAVE_GME ON) - add_definitions(-DHAVE_LIBGME) - else() - message(WARNING "You have specified that GME is available but it was not found.") - endif() -endif() - -if(${SRB2_CONFIG_HAVE_DISCORDRPC}) - if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) - set(DISCORDRPC_FOUND ON) - if(${SRB2_SYSTEM_BITS} EQUAL 64) - set(DISCORDRPC_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/discord-rpc/win64-dynamic/include) - set(DISCORDRPC_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/discord-rpc/win64-dynamic/lib -ldiscord-rpc") - else() # 32-bit - set(DISCORDRPC_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/discord-rpc/win32-dynamic/include) - set(DISCORDRPC_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/discord-rpc/win32-dynamic/lib -ldiscord-rpc") - endif() - else() - find_package(DiscordRPC) - endif() - if(${DISCORDRPC_FOUND}) - set(SRB2_HAVE_DISCORDRPC ON) - add_definitions(-DHAVE_DISCORDRPC) - add_definitions(-DUSE_STUN) - set(SRB2_DISCORDRPC_SOURCES discord.c stun.c) - set(SRB2_DISCORDRPC_HEADERS discord.h stun.h) - prepend_sources(SRB2_DISCORDRPC_SOURCES) - prepend_sources(SRB2_DISCORDRPC_HEADERS) - source_group("Discord Rich Presence" FILES ${SRB2_DISCORDRPC_SOURCES} ${SRB2_DISCORDRPC_HEADERS}) - else() - message(WARNING "You have specified that Discord Rich Presence is available but it was not found.") - endif() -endif() - -if(${SRB2_CONFIG_HAVE_OPENMPT}) - if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) - set(OPENMPT_FOUND ON) - set(OPENMPT_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/libopenmpt/inc) - if(${SRB2_SYSTEM_BITS} EQUAL 64) - set(OPENMPT_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/libopenmpt/lib/x86_64/mingw -lopenmpt") - else() # 32-bit - set(OPENMPT_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/libopenmpt/lib/x86/mingw -lopenmpt") - endif() - else() - find_package(OPENMPT) - endif() - if(${OPENMPT_FOUND}) - set(SRB2_HAVE_OPENMPT ON) - add_definitions(-DHAVE_OPENMPT) - else() - message(WARNING "You have specified that OpenMPT is available but it was not found.") - endif() -endif() - -if(${SRB2_CONFIG_HAVE_ZLIB}) - if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) - set(ZLIB_FOUND ON) - set(ZLIB_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/zlib) - if(${SRB2_SYSTEM_BITS} EQUAL 64) - set(ZLIB_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/zlib/win32 -lz64") - else() # 32-bit - set(ZLIB_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/zlib/win32 -lz32") - endif() - else() - find_package(ZLIB) - endif() - if(${ZLIB_FOUND}) - set(SRB2_HAVE_ZLIB ON) - add_definitions(-DHAVE_ZLIB) - else() - message(WARNING "You have specified that ZLIB is available but it was not found. SRB2Kart may not compile correctly.") - endif() -endif() - -if(${SRB2_CONFIG_HAVE_PNG} AND ${SRB2_CONFIG_HAVE_ZLIB}) - if (${ZLIB_FOUND}) - if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) - set(PNG_FOUND ON) - set(PNG_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/libpng-src) - if(${SRB2_SYSTEM_BITS} EQUAL 64) - set(PNG_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/libpng-src/projects -lpng64") - else() # 32-bit - set(PNG_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/libpng-src/projects -lpng32") - endif() - else() - find_package(PNG) - endif() - if(${PNG_FOUND}) - set(SRB2_HAVE_PNG ON) - add_definitions(-DHAVE_PNG) - add_definitions(-D_LARGEFILE64_SOURCE) - set(SRB2_PNG_SOURCES apng.c) - set(SRB2_PNG_HEADERS apng.h) - prepend_sources(SRB2_PNG_SOURCES) - prepend_sources(SRB2_PNG_HEADERS) - source_group("Main" FILES ${SRB2_CORE_SOURCES} ${SRB2_CORE_HEADERS} - ${SRB2_PNG_SOURCES} ${SRB2_PNG_HEADERS}) - else() - message(WARNING "You have specified that PNG is available but it was not found. SRB2Kart may not compile correctly.") - endif() - endif() -endif() - -if(${SRB2_CONFIG_HAVE_CURL}) - if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) - set(CURL_FOUND ON) - set(CURL_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/curl/include) - if(${SRB2_SYSTEM_BITS} EQUAL 64) - set(CURL_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/curl/lib64 -lcurl") - else() # 32-bit - set(CURL_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/curl/lib32 -lcurl") - endif() - else() - find_package(CURL) - endif() - if(${CURL_FOUND}) - set(SRB2_HAVE_CURL ON) - add_definitions(-DHAVE_CURL) - else() - message(WARNING "You have specified that CURL is available but it was not found. SRB2Kart may not compile correctly.") - endif() -endif() - -if(${SRB2_CONFIG_HWRENDER}) - add_definitions(-DHWRENDER) - set(SRB2_HWRENDER_SOURCES - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_batching.c - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_shaders.c - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_bsp.c - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_cache.c - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_clip.c - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_draw.c - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_main.c - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md2.c - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md2load.c - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md3load.c - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_model.c - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/u_list.c - ) - - set (SRB2_HWRENDER_HEADERS - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_batching.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_shaders.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_clip.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_data.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_defs.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_dll.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_drv.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_glob.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_main.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md2.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md2load.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md3load.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_model.h - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/u_list.h - ) - - set(SRB2_R_OPENGL_SOURCES - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/r_opengl/r_opengl.c - ) - - set(SRB2_R_OPENGL_HEADERS - ${CMAKE_CURRENT_SOURCE_DIR}/hardware/r_opengl/r_opengl.h - ) - -endif() - -if(${SRB2_CONFIG_HWRENDER} AND ${SRB2_CONFIG_STATIC_OPENGL}) - find_package(OpenGL) - if(${OPENGL_FOUND}) - add_definitions(-DHWRENDER) - add_definitions(-DSTATIC_OPENGL) - else() - message(WARNING "You have specified static opengl but opengl was not found. Not setting HWRENDER.") - endif() -endif() - -if(${SRB2_CONFIG_HWRENDER}) - if(${SRB2_CONFIG_USE_FBO_OGL}) - set(SRB2_USE_FBO_OGL ON) - add_definitions(-DUSE_FBO_OGL) - endif() -endif() - -# Targets - -# Compatibility flag with later versions of GCC -# We should really fix our code to not need this -if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") - set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} -mno-ms-bitfields) -endif() - -if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") - set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} -Wno-absolute-value) -endif() - -add_definitions(-DCMAKECONFIG) - -#add_library(SRB2Core STATIC -# ${SRB2_CORE_SOURCES} -# ${SRB2_CORE_HEADERS} -# ${SRB2_CORE_RENDER_SOURCES} -# ${SRB2_CORE_GAME_SOURCES} -# ${SRB2_LUA_SOURCES} -# ${SRB2_LUA_HEADERS} -# ${SRB2_BLUA_SOURCES} -# ${SRB2_BLUA_HEADERS} -#) - -add_subdirectory(sdl) - -if(NOT ${SRB2_SDL2_AVAILABLE} AND NOT ${SRB2_WIN32_AVAILABLE}) - message(FATAL_ERROR "There are no targets available to build an SRB2Kart executable. :(") -endif() +# SRB2 Core + +# Core sources +set(SRB2_CORE_SOURCES + am_map.c + b_bot.c + command.c + comptime.c + console.c + d_clisrv.c + d_main.c + d_net.c + d_netcmd.c + d_netfil.c + d_protocol.c + dehacked.c + f_finale.c + f_wipe.c + filesrch.c + g_game.c + g_input.c + hu_stuff.c + i_tcp.c + info.c + lzf.c + m_aatree.c + m_anigif.c + m_argv.c + m_bbox.c + m_cheat.c + m_cond.c + m_fixed.c + m_menu.c + m_textinput.c + m_misc.c + m_perfstats.c + m_queue.c + m_random.c + md5.c + mserv.c + http-mserv.c + qs22j.c + s_sound.c + screen.c + sounds.c + st_stuff.c + #string.c + tables.c + v_video.c + w_wad.c + y_inter.c + z_zone.c +) + +set(SRB2_CORE_HEADERS + am_map.h + b_bot.h + byteptr.h + command.h + console.h + d_clisrv.h + d_event.h + d_main.h + d_net.h + d_netcmd.h + d_netfil.h + d_player.h + d_protocol.h + d_think.h + d_ticcmd.h + dehacked.h + doomdata.h + doomdef.h + doomstat.h + doomtype.h + endian.h + f_finale.h + fastcmp.h + filesrch.h + g_game.h + g_input.h + g_state.h + hu_stuff.h + i_joy.h + i_net.h + i_sound.h + i_system.h + i_tcp.h + i_time.h + i_video.h + info.h + keys.h + lzf.h + m_aatree.h + m_anigif.h + m_argv.h + m_bbox.h + m_cheat.h + m_cond.h + m_dllist.h + m_fixed.h + m_menu.h + m_textinput.h + m_misc.h + m_queue.h + m_perfstats.h + m_random.h + m_swap.h + md5.h + mserv.h + qs22j.h + s_sound.h + screen.h + sounds.h + st_stuff.h + tables.h + v_video.h + w_wad.h + y_inter.h + z_zone.h + + config.h.in +) + +set(SRB2_CORE_RENDER_SOURCES + r_bsp.c + r_data.c + r_draw.c + r_fps.c + r_main.c + r_patch.c + r_plane.c + r_segs.c + r_sky.c + r_splats.c + r_things.c + + r_bsp.h + r_data.h + r_defs.h + r_draw.h + r_fps.h + r_local.h + r_main.h + r_patch + r_plane.h + r_segs.h + r_sky.h + r_splats.h + r_state.h + r_things.h +) + +set(SRB2_CORE_GAME_SOURCES + p_ceilng.c + p_enemy.c + p_floor.c + p_inter.c + p_lights.c + p_map.c + p_maputl.c + p_mobj.c + p_polyobj.c + p_saveg.c + p_setup.c + p_sight.c + p_slopes.c + p_spec.c + p_telept.c + p_tick.c + p_user.c + k_director.c + k_kart.c + i_time.c + + p_local.h + p_maputl.h + p_mobj.h + p_polyobj.h + p_pspr.h + p_saveg.h + p_setup.h + p_slopes.h + p_spec.h + p_tick.h + k_director.h + k_kart.h +) + +if(NOT (CMAKE_CXX_COMPILER_ID MATCHES "Clang")) + set(SRB2_CORE_SOURCES ${SRB2_CORE_SOURCES} string.c) +endif() + +prepend_sources(SRB2_CORE_SOURCES) +prepend_sources(SRB2_CORE_HEADERS) +prepend_sources(SRB2_CORE_RENDER_SOURCES) +prepend_sources(SRB2_CORE_GAME_SOURCES) + +set(SRB2_CORE_HEADERS ${SRB2_CORE_HEADERS} ${CMAKE_CURRENT_BINARY_DIR}/config.h) +source_group("Main" FILES ${SRB2_CORE_SOURCES} ${SRB2_CORE_HEADERS}) +source_group("Renderer" FILES ${SRB2_CORE_RENDER_SOURCES}) +source_group("Game" FILES ${SRB2_CORE_GAME_SOURCES}) + +### Configuration +set(SRB2_CONFIG_HAVE_BLUA ON CACHE BOOL + "Enable Lua interpreter support") +set(SRB2_CONFIG_HAVE_PNG ON CACHE BOOL + "Enable PNG support. Depends on zlib, so will be disabled if you don't enable that too.") +set(SRB2_CONFIG_HAVE_ZLIB ON CACHE BOOL + "Enable zlib support.") +set(SRB2_CONFIG_HAVE_GME ON CACHE BOOL + "Enable GME support.") +set(SRB2_CONFIG_HAVE_OPENMPT ON CACHE BOOL + "Enable OpenMPT support.") +set(SRB2_CONFIG_HAVE_DISCORDRPC OFF CACHE BOOL + "Enable Discord rich presence support.") +set(SRB2_CONFIG_HAVE_CURL ON CACHE BOOL + "Enable curl support, used for downloading files via HTTP.") +set(SRB2_CONFIG_HWRENDER ON CACHE BOOL + "Enable hardware rendering through OpenGL.") +set(SRB2_CONFIG_STATIC_OPENGL OFF CACHE BOOL + "Use statically linked OpenGL. NOT RECOMMENDED.") +set(SRB2_CONFIG_USE_FBO_OGL ON CACHE BOOL + "Enable OpenGL FBO Downsampling support.") + +### use internal libraries? +if(${CMAKE_SYSTEM} MATCHES "Windows") ###set on Windows only + set(SRB2_CONFIG_USE_INTERNAL_LIBRARIES OFF CACHE BOOL + "Use SRB2Kart's internal copies of required dependencies (SDL2, PNG, zlib, GME, OpenMPT).") +endif() + +if(${SRB2_CONFIG_HAVE_BLUA}) + add_definitions(-DHAVE_BLUA) + set(SRB2_LUA_SOURCES + lua_baselib.c + lua_blockmaplib.c + lua_consolelib.c + lua_hooklib.c + lua_hudlib.c + lua_hudlib_drawlist.c + lua_infolib.c + lua_maplib.c + lua_mathlib.c + lua_mobjlib.c + lua_playerlib.c + lua_script.c + lua_skinlib.c + lua_thinkerlib.c + lua_udatalib.c + lua_glib.c + ) + set(SRB2_LUA_HEADERS + lua_hook.h + lua_hud.h + lua_hudlib_drawlist.h + lua_libs.h + lua_script.h + lua_udatalib.h + lua_glib.h + ) + + prepend_sources(SRB2_LUA_SOURCES) + prepend_sources(SRB2_LUA_HEADERS) + + source_group("LUA" FILES ${SRB2_LUA_SOURCES} ${SRB2_LUA_HEADERS}) + + set(SRB2_BLUA_SOURCES + blua/lapi.c + blua/lauxlib.c + blua/lbaselib.c + blua/ldblib.c + blua/lcode.c + blua/ldebug.c + blua/ldo.c + blua/ldump.c + blua/lfunc.c + blua/lgc.c + blua/linit.c + blua/liolib.c + blua/llex.c + blua/lmem.c + blua/lobject.c + blua/lopcodes.c + blua/lparser.c + blua/lstate.c + blua/lstring.c + blua/lstrlib.c + blua/ltable.c + blua/ltablib.c + blua/ltm.c + blua/lundump.c + blua/lvm.c + blua/lzio.c + ) + set(SRB2_BLUA_HEADERS + blua/lapi.h + blua/lauxlib.h + blua/lcode.h + blua/ldebug.h + blua/ldo.h + blua/lfunc.h + blua/lgc.h + blua/llex.h + blua/llimits.h + blua/lmem.h + blua/lobject.h + blua/lopcodes.h + blua/lparser.h + blua/lstate.h + blua/lstring.h + blua/ltable.h + blua/ltm.h + blua/lua.h + blua/luaconf.h + blua/lualib.h + blua/lundump.h + blua/lvm.h + blua/lzio.h + ) + + prepend_sources(SRB2_BLUA_SOURCES) + prepend_sources(SRB2_BLUA_HEADERS) + + source_group("LUA\\Interpreter" FILES ${SRB2_BLUA_SOURCES} ${SRB2_BLUA_HEADERS}) +endif() + +if(${SRB2_CONFIG_HAVE_GME}) + if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) + set(GME_FOUND ON) + set(GME_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/gme/include) + if(${SRB2_SYSTEM_BITS} EQUAL 64) + set(GME_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/gme/win64 -lgme") + else() # 32-bit + set(GME_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/gme/win32 -lgme") + endif() + else() + find_package(GME) + endif() + if(${GME_FOUND}) + set(SRB2_HAVE_GME ON) + add_definitions(-DHAVE_LIBGME) + else() + message(WARNING "You have specified that GME is available but it was not found.") + endif() +endif() + +if(${SRB2_CONFIG_HAVE_DISCORDRPC}) + if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) + set(DISCORDRPC_FOUND ON) + if(${SRB2_SYSTEM_BITS} EQUAL 64) + set(DISCORDRPC_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/discord-rpc/win64-dynamic/include) + set(DISCORDRPC_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/discord-rpc/win64-dynamic/lib -ldiscord-rpc") + else() # 32-bit + set(DISCORDRPC_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/discord-rpc/win32-dynamic/include) + set(DISCORDRPC_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/discord-rpc/win32-dynamic/lib -ldiscord-rpc") + endif() + else() + find_package(DiscordRPC) + endif() + if(${DISCORDRPC_FOUND}) + set(SRB2_HAVE_DISCORDRPC ON) + add_definitions(-DHAVE_DISCORDRPC) + add_definitions(-DUSE_STUN) + set(SRB2_DISCORDRPC_SOURCES discord.c stun.c) + set(SRB2_DISCORDRPC_HEADERS discord.h stun.h) + prepend_sources(SRB2_DISCORDRPC_SOURCES) + prepend_sources(SRB2_DISCORDRPC_HEADERS) + source_group("Discord Rich Presence" FILES ${SRB2_DISCORDRPC_SOURCES} ${SRB2_DISCORDRPC_HEADERS}) + else() + message(WARNING "You have specified that Discord Rich Presence is available but it was not found.") + endif() +endif() + +if(${SRB2_CONFIG_HAVE_OPENMPT}) + if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) + set(OPENMPT_FOUND ON) + set(OPENMPT_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/libopenmpt/inc) + if(${SRB2_SYSTEM_BITS} EQUAL 64) + set(OPENMPT_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/libopenmpt/lib/x86_64/mingw -lopenmpt") + else() # 32-bit + set(OPENMPT_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/libopenmpt/lib/x86/mingw -lopenmpt") + endif() + else() + find_package(OPENMPT) + endif() + if(${OPENMPT_FOUND}) + set(SRB2_HAVE_OPENMPT ON) + add_definitions(-DHAVE_OPENMPT) + else() + message(WARNING "You have specified that OpenMPT is available but it was not found.") + endif() +endif() + +if(${SRB2_CONFIG_HAVE_ZLIB}) + if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) + set(ZLIB_FOUND ON) + set(ZLIB_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/zlib) + if(${SRB2_SYSTEM_BITS} EQUAL 64) + set(ZLIB_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/zlib/win32 -lz64") + else() # 32-bit + set(ZLIB_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/zlib/win32 -lz32") + endif() + else() + find_package(ZLIB) + endif() + if(${ZLIB_FOUND}) + set(SRB2_HAVE_ZLIB ON) + add_definitions(-DHAVE_ZLIB) + else() + message(WARNING "You have specified that ZLIB is available but it was not found. SRB2Kart may not compile correctly.") + endif() +endif() + +if(${SRB2_CONFIG_HAVE_PNG} AND ${SRB2_CONFIG_HAVE_ZLIB}) + if (${ZLIB_FOUND}) + if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) + set(PNG_FOUND ON) + set(PNG_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/libpng-src) + if(${SRB2_SYSTEM_BITS} EQUAL 64) + set(PNG_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/libpng-src/projects -lpng64") + else() # 32-bit + set(PNG_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/libpng-src/projects -lpng32") + endif() + else() + find_package(PNG) + endif() + if(${PNG_FOUND}) + set(SRB2_HAVE_PNG ON) + add_definitions(-DHAVE_PNG) + add_definitions(-D_LARGEFILE64_SOURCE) + set(SRB2_PNG_SOURCES apng.c) + set(SRB2_PNG_HEADERS apng.h) + prepend_sources(SRB2_PNG_SOURCES) + prepend_sources(SRB2_PNG_HEADERS) + source_group("Main" FILES ${SRB2_CORE_SOURCES} ${SRB2_CORE_HEADERS} + ${SRB2_PNG_SOURCES} ${SRB2_PNG_HEADERS}) + else() + message(WARNING "You have specified that PNG is available but it was not found. SRB2Kart may not compile correctly.") + endif() + endif() +endif() + +if(${SRB2_CONFIG_HAVE_CURL}) + if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES}) + set(CURL_FOUND ON) + set(CURL_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/curl/include) + if(${SRB2_SYSTEM_BITS} EQUAL 64) + set(CURL_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/curl/lib64 -lcurl") + else() # 32-bit + set(CURL_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/curl/lib32 -lcurl") + endif() + else() + find_package(CURL) + endif() + if(${CURL_FOUND}) + set(SRB2_HAVE_CURL ON) + add_definitions(-DHAVE_CURL) + else() + message(WARNING "You have specified that CURL is available but it was not found. SRB2Kart may not compile correctly.") + endif() +endif() + +if(${SRB2_CONFIG_HWRENDER}) + add_definitions(-DHWRENDER) + set(SRB2_HWRENDER_SOURCES + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_batching.c + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_shaders.c + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_bsp.c + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_cache.c + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_clip.c + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_draw.c + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_main.c + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md2.c + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md2load.c + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md3load.c + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_model.c + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/u_list.c + ) + + set (SRB2_HWRENDER_HEADERS + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_batching.h + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_shaders.h + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_clip.h + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_data.h + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_defs.h + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_dll.h + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_drv.h + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_glob.h + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_main.h + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md2.h + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md2load.h + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_md3load.h + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/hw_model.h + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/u_list.h + ) + + set(SRB2_R_OPENGL_SOURCES + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/r_opengl/r_opengl.c + ) + + set(SRB2_R_OPENGL_HEADERS + ${CMAKE_CURRENT_SOURCE_DIR}/hardware/r_opengl/r_opengl.h + ) + +endif() + +if(${SRB2_CONFIG_HWRENDER} AND ${SRB2_CONFIG_STATIC_OPENGL}) + find_package(OpenGL) + if(${OPENGL_FOUND}) + add_definitions(-DHWRENDER) + add_definitions(-DSTATIC_OPENGL) + else() + message(WARNING "You have specified static opengl but opengl was not found. Not setting HWRENDER.") + endif() +endif() + +if(${SRB2_CONFIG_HWRENDER}) + if(${SRB2_CONFIG_USE_FBO_OGL}) + set(SRB2_USE_FBO_OGL ON) + add_definitions(-DUSE_FBO_OGL) + endif() +endif() + +# Targets + +# Compatibility flag with later versions of GCC +# We should really fix our code to not need this +if ("${CMAKE_CXX_COMPILER_ID}" STREQUAL "GNU") + set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} -mno-ms-bitfields) +endif() + +if (CMAKE_CXX_COMPILER_ID MATCHES "Clang") + set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} -Wno-absolute-value) +endif() + +add_definitions(-DCMAKECONFIG) + +#add_library(SRB2Core STATIC +# ${SRB2_CORE_SOURCES} +# ${SRB2_CORE_HEADERS} +# ${SRB2_CORE_RENDER_SOURCES} +# ${SRB2_CORE_GAME_SOURCES} +# ${SRB2_LUA_SOURCES} +# ${SRB2_LUA_HEADERS} +# ${SRB2_BLUA_SOURCES} +# ${SRB2_BLUA_HEADERS} +#) + +add_subdirectory(sdl) + +if(NOT ${SRB2_SDL2_AVAILABLE} AND NOT ${SRB2_WIN32_AVAILABLE}) + message(FATAL_ERROR "There are no targets available to build an SRB2Kart executable. :(") +endif() diff --git a/src/Makefile b/src/Makefile index 4668518b9..e7fb4d60b 100644 --- a/src/Makefile +++ b/src/Makefile @@ -529,6 +529,7 @@ OBJS:=$(i_main_o) \ $(OBJDIR)/m_fixed.o \ $(OBJDIR)/m_menu.o \ $(OBJDIR)/m_misc.o \ + $(OBJDIR)/m_textinput.o \ $(OBJDIR)/m_perfstats.o \ $(OBJDIR)/m_random.o \ $(OBJDIR)/m_queue.o \ diff --git a/src/console.c b/src/console.c index 5c2e04eb3..dbeb2b42b 100644 --- a/src/console.c +++ b/src/console.c @@ -32,6 +32,7 @@ #include "i_threads.h" #include "d_main.h" #include "m_menu.h" +#include "m_textinput.h" #include "filesrch.h" #ifdef HWRENDER @@ -97,9 +98,7 @@ static char inputlines[32][CON_MAXPROMPTCHARS]; // hold last 32 prompt lines static INT32 inputline; // current input line number static INT32 inputhist; // line number of history input line to restore -static size_t input_cur; // position of cursor in line -static size_t input_sel; // position of selection marker (I.E.: anything between this and input_cur is "selected") -static size_t input_len; // length of current line, used to bound cursor and such +static textinput_t input; // notice: input does NOT include the "$" at the start of the line. - 11/3/16 // protos. @@ -458,7 +457,8 @@ static void CON_InputInit(void) // prepare the first prompt line memset(inputlines, 0, sizeof (inputlines)); inputline = 0; - input_cur = input_sel = input_len = 0; + + M_TextInputInit(&input, inputlines[inputline], CON_MAXPROMPTCHARS); Unlock_state(); } @@ -802,178 +802,6 @@ void CON_Ticker(void) Unlock_state(); } -// -// ---- -// -// Shortcuts for adding and deleting characters, strings, and sections -// Necessary due to moving cursor -// - -static void CON_InputClear(void) -{ - Lock_state(); - - memset(inputlines[inputline], 0, CON_MAXPROMPTCHARS); - input_cur = input_sel = input_len = 0; - - Unlock_state(); -} - -static void CON_InputSetString(const char *c) -{ - Lock_state(); - - memset(inputlines[inputline], 0, CON_MAXPROMPTCHARS); - strcpy(inputlines[inputline], c); - input_cur = input_sel = input_len = strlen(c); - - Unlock_state(); -} - -static void CON_InputAddString(const char *c) -{ - size_t csize = strlen(c); - - Lock_state(); - - if (input_len + csize > CON_MAXPROMPTCHARS-1) - { - Unlock_state(); - return; - } - if (input_cur != input_len) - memmove(&inputlines[inputline][input_cur+csize], &inputlines[inputline][input_cur], input_len-input_cur); - memcpy(&inputlines[inputline][input_cur], c, csize); - input_len += csize; - input_sel = (input_cur += csize); - - Unlock_state(); -} - -static void CON_InputDel(size_t start, size_t end) -{ - size_t len; - - Lock_state(); - - len = (end - start); - - if (end != input_len) - memmove(&inputlines[inputline][start], &inputlines[inputline][end], input_len-end); - memset(&inputlines[inputline][input_len - len], 0, len); - - input_len -= len; - - if (input_sel >= end) - input_sel -= len; - else if (input_sel > start) - input_sel = start; - - if (input_cur >= end) - input_cur -= len; - else if (input_cur > start) - input_cur = start; - - Unlock_state(); -} - -static void CON_InputDelSelection(void) -{ - size_t start, end; - - Lock_state(); - - if (input_cur > input_sel) - { - start = input_sel; - end = input_cur; - } - else - { - start = input_cur; - end = input_sel; - } - - CON_InputDel(start, end); - - input_sel = input_cur = start; - - Unlock_state(); -} - -static void CON_ToWordEnd(boolean move_sel) -{ - Lock_state(); - - // Skip spaces - while (input_cur < input_len && isspace(inputlines[inputline][input_cur])) - ++input_cur; - - // Skip word - while (input_cur < input_len && !isspace(inputlines[inputline][input_cur])) - ++input_cur; - - if (move_sel) input_sel = input_cur; - - Unlock_state(); -} - -static void CON_ToWordBegin(boolean move_sel) -{ - Lock_state(); - - // Hack, always move back 1 character if possible so if we press ctrl-left at a word beginning - // we move to previous word - if (input_cur) --input_cur; - - // Skip spaces - while (input_cur && isspace(inputlines[inputline][input_cur])) - --input_cur; - - // Skip word - while (input_cur && !isspace(inputlines[inputline][input_cur])) - --input_cur; - - // Unless we reached beginning of line, we're pointing at a space before word, so move cursor - // forward to fix that - if (input_cur) ++input_cur; - - if (move_sel) input_sel = input_cur; - - Unlock_state(); -} - -static void CON_InputAddChar(char c) -{ - if (input_len >= CON_MAXPROMPTCHARS-1) - return; - - Lock_state(); - - if (input_cur != input_len) - memmove(&inputlines[inputline][input_cur+1], &inputlines[inputline][input_cur], input_len-input_cur); - inputlines[inputline][input_cur++] = c; - inputlines[inputline][++input_len] = 0; - input_sel = input_cur; - - Unlock_state(); -} - -static void CON_InputDelChar(void) -{ - if (!input_cur) - return; - - Lock_state(); - - if (input_cur != input_len) - memmove(&inputlines[inputline][input_cur-1], &inputlines[inputline][input_cur], input_len-input_cur); - inputlines[inputline][--input_len] = 0; - input_sel = --input_cur; - - Unlock_state(); -} - // // ---- // @@ -1054,6 +882,10 @@ boolean CON_Responder(event_t *ev) } } + Lock_state(); + M_TextInputHandle(&input, key); + Unlock_state(); + // Always eat ctrl/shift/alt if console open, so the menu doesn't get ideas if (key == KEY_LSHIFT || key == KEY_RSHIFT || key == KEY_LCTRL || key == KEY_RCTRL @@ -1069,9 +901,9 @@ boolean CON_Responder(event_t *ev) if (!completion[0]) { - if (!input_len || input_len >= 40 || strchr(inputlines[inputline], ' ')) + if (!input.length || input.length >= 40 || strchr(input.buffer, ' ')) return true; - strcpy(completion, inputlines[inputline]); + strcpy(completion, input.buffer); comskips = varskips = 0; } @@ -1092,74 +924,9 @@ boolean CON_Responder(event_t *ev) return true; } - if (key == 'x' || key == 'X') - { - if (input_sel > input_cur) - I_ClipboardCopy(&inputlines[inputline][input_cur], input_sel-input_cur); - else - I_ClipboardCopy(&inputlines[inputline][input_sel], input_cur-input_sel); - CON_InputDelSelection(); + // Those are already handled in M_TextInputHandle, but they do extra logic... Maybe textinput_t should have some sort of callbacks? + if (key == 'x' || key == 'X' || key == 'v' || key == 'V') completion[0] = 0; - return true; - } - else if (key == 'c' || key == 'C') - { - if (input_sel > input_cur) - I_ClipboardCopy(&inputlines[inputline][input_cur], input_sel-input_cur); - else - I_ClipboardCopy(&inputlines[inputline][input_sel], input_cur-input_sel); - return true; - } - else if (key == 'v' || key == 'V') - { - const char *paste = I_ClipboardPaste(); - if (input_sel != input_cur) - CON_InputDelSelection(); - if (paste != NULL) - CON_InputAddString(paste); - completion[0] = 0; - return true; - } - else if (key == 'w' || key == 'W') - { - size_t word_start, word_end, i; - word_end = i = input_cur; - - // Unless we're pointing at the beginning of line, decrement i so we only start - // removing symbols that come before the cursor - if (i) --i; - - // We might be pointing to spaces, skip them first - while (i && isspace(inputlines[inputline][i])) - --i; - - // Now skip the "word" - while (i && !isspace(inputlines[inputline][i])) - --i; - - // Unless we reached beginning of line, i is pointing at first space that was found - // before word start, and we don't want to remove it - if (i) ++i; - - word_start = i; - - if (word_start != word_end) - CON_InputDel(word_start, word_end); - - return true; - } - else if (key == KEY_RIGHTARROW) - CON_ToWordEnd(!shiftdown); - else if (key == KEY_LEFTARROW) - CON_ToWordBegin(!shiftdown); - - // Select all - if (key == 'a' || key == 'A') - { - input_sel = 0; - input_cur = input_len; - return true; - } // ...why shouldn't it eat the key? if it doesn't, it just means you // can control Sonic from the console, which is silly @@ -1174,9 +941,9 @@ boolean CON_Responder(event_t *ev) // remember typing for several completions (a-la-4dos) if (!completion[0]) { - if (!input_len || input_len >= 40 || strchr(inputlines[inputline], ' ')) + if (!input.length || input.length >= 40 || strchr(input.buffer, ' ')) return true; - strcpy(completion, inputlines[inputline]); + strcpy(completion, input.buffer); comskips = varskips = 0; } else @@ -1207,7 +974,11 @@ boolean CON_Responder(event_t *ev) cmd = CV_CompleteVar(completion, varskips); if (cmd) - CON_InputSetString(va("%s ", cmd)); + { + Lock_state(); + M_TextInputSetString(&input, va("%s ", cmd)); + Unlock_state(); + } else { if (comskips > 0) @@ -1233,37 +1004,6 @@ boolean CON_Responder(event_t *ev) return true; } - if (key == KEY_LEFTARROW) - { - if (input_cur != 0) - --input_cur; - if (!shiftdown) - input_sel = input_cur; - return true; - } - else if (key == KEY_RIGHTARROW) - { - if (input_cur < input_len) - ++input_cur; - if (!shiftdown) - input_sel = input_cur; - return true; - } - else if (key == KEY_HOME) - { - input_cur = 0; - if (!shiftdown) - input_sel = input_cur; - return true; - } - else if (key == KEY_END) - { - input_cur = input_len; - if (!shiftdown) - input_sel = input_cur; - return true; - } - // At this point we're messing with input // Clear completion completion[0] = 0; @@ -1271,45 +1011,29 @@ boolean CON_Responder(event_t *ev) // command enter if (key == KEY_ENTER) { - if (!input_len) + if (!input.length) return true; // push the command - COM_BufAddText(inputlines[inputline]); + COM_BufAddText(input.buffer); COM_BufAddText("\n"); CONS_Printf("\x86""%c""\x80""%s\n", CON_PROMPTCHAR, inputlines[inputline]); + Lock_state(); + // Only add command to history if it differs from previous one - if (strcmp(inputlines[inputline], inputlines[(inputline-1) & 31])) + if (strcmp(input.buffer, inputlines[(inputline-1) & 31])) + { inputline = (inputline+1) & 31; + M_TextInputInit(&input, inputlines[inputline], CON_MAXPROMPTCHARS); + } inputhist = inputline; - CON_InputClear(); + M_TextInputClear(&input); - return true; - } + Unlock_state(); - // backspace and delete command prompt - if (input_sel != input_cur) - { - if (key == KEY_BACKSPACE || key == KEY_DEL) - { - CON_InputDelSelection(); - return true; - } - } - else if (key == KEY_BACKSPACE) - { - CON_InputDelChar(); - return true; - } - else if (key == KEY_DEL) - { - if (input_cur == input_len) - return true; - ++input_cur; - CON_InputDelChar(); return true; } @@ -1326,7 +1050,9 @@ boolean CON_Responder(event_t *ev) if (inputhist == inputline) inputhist = (inputline + 1) & 31; - CON_InputSetString(inputlines[inputhist]); + Lock_state(); + M_TextInputSetString(&input, inputlines[inputhist]); + Unlock_state(); return true; } @@ -1340,41 +1066,16 @@ boolean CON_Responder(event_t *ev) while (inputhist != inputline && !inputlines[inputhist][0]); // back to currentline + Lock_state(); if (inputhist == inputline) - CON_InputClear(); + M_TextInputClear(&input); else - CON_InputSetString(inputlines[inputhist]); + M_TextInputSetString(&input, inputlines[inputhist]); + Unlock_state(); + return true; } - // allow people to use keypad in console (good for typing IP addresses) - Calum - if (key >= KEY_KEYPAD7 && key <= KEY_KPADDEL) - { - char keypad_translation[] = {'7','8','9','-', - '4','5','6','+', - '1','2','3', - '0','.'}; - - key = keypad_translation[key - KEY_KEYPAD7]; - } - else if (key == KEY_KPADSLASH) - key = '/'; - - // same capslock code as hu_stuff.c's HU_responder. Check there for details. - key = CON_ShiftChar(key); - - // enter a char into the command prompt - if (key < 32 || key > 127) - return true; - - // add key to cmd line here - if (key >= 'A' && key <= 'Z' && !(shiftdown ^ capslock)) //this is only really necessary for dedicated servers - key = key + 'a' - 'A'; - - if (input_sel != input_cur) - CON_InputDelSelection(); - CON_InputAddChar(key); - return true; } @@ -1656,16 +1357,16 @@ static void CON_DrawInput(void) clen = con_width-13; - if (input_len <= clen) + if (input.length <= clen) { c = 0; - clen = input_len; + clen = input.length; } else // input line scrolls left if it gets too long { clen -= 2; // There will always be some extra truncation -- but where is what we'll find out - if (input_cur <= clen/2) + if (input.cursor <= clen/2) { // Close enough to right edge to show all c = 0; @@ -1676,15 +1377,15 @@ static void CON_DrawInput(void) { // Cursor in the middle (or right side) of input // Move over for the ellipsis - c = input_cur - (clen/2) + 2; + c = input.cursor - (clen/2) + 2; x += charwidth*2; lellip = 1; - if (c + clen >= input_len) + if (c + clen >= input.length) { // Cursor in the right side of input // We were too far over, so move back - c = input_len - clen; + c = input.length - clen; } else { @@ -1698,7 +1399,7 @@ static void CON_DrawInput(void) if (lellip) { x -= charwidth*3; - if (input_sel < c) + if (input.select < c) V_DrawFill(x, y, charwidth*3, (10 * con_scalefactor), 107 | V_NOSCALESTART); for (i = 0; i < 3; ++i, x += charwidth) V_DrawCharacter(x, y, '.' | cv_constextsize.value | V_GRAYMAP | V_NOSCALESTART, !cv_allcaps.value); @@ -1708,7 +1409,7 @@ static void CON_DrawInput(void) for (cend = c + clen; c < cend; ++c, x += charwidth) { - if ((input_sel > c && input_cur <= c) || (input_sel <= c && input_cur > c)) + if ((input.select > c && input.cursor <= c) || (input.select <= c && input.cursor > c)) { V_DrawFill(x, y, charwidth, (10 * con_scalefactor), 107 | V_NOSCALESTART); V_DrawCharacter(x, y, p[c] | cv_constextsize.value | V_YELLOWMAP | V_NOSCALESTART, !cv_allcaps.value); @@ -1716,14 +1417,14 @@ static void CON_DrawInput(void) else V_DrawCharacter(x, y, p[c] | cv_constextsize.value | V_NOSCALESTART, !cv_allcaps.value); - if (c == input_cur && con_tick >= 4) + if (c == input.cursor && con_tick >= 4) V_DrawCharacter(x, y + (con_scalefactor*2), '_' | cv_constextsize.value | V_NOSCALESTART, !cv_allcaps.value); } - if (cend == input_cur && con_tick >= 4) + if (cend == input.cursor && con_tick >= 4) V_DrawCharacter(x, y + (con_scalefactor*2), '_' | cv_constextsize.value | V_NOSCALESTART, !cv_allcaps.value); if (rellip) { - if (input_sel > cend) + if (input.select > cend) V_DrawFill(x, y, charwidth*3, (10 * con_scalefactor), 107 | V_NOSCALESTART); for (i = 0; i < 3; ++i, x += charwidth) V_DrawCharacter(x, y, '.' | cv_constextsize.value | V_GRAYMAP | V_NOSCALESTART, !cv_allcaps.value); diff --git a/src/lua_script.c b/src/lua_script.c index 9d5bef4a7..e1bf03f4c 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -1589,8 +1589,13 @@ void LUA_Step(void) { if (!gL) return; - lua_settop(gL, 0); - lua_gc(gL, LUA_GCSTEP, 1); + + if (lua_gettop(gL) != 0) + { + CONS_Alert(CONS_WARNING, "Eek, there is garbage on lua stack!\n"); + lua_settop(gL, 0); + lua_gc(gL, LUA_GCSTEP, 1); + } } void LUA_Archive(void) diff --git a/src/m_menu.c b/src/m_menu.c index c42c923e2..cc8bf39a6 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -30,6 +30,7 @@ #include "g_game.h" #include "g_input.h" #include "m_argv.h" +#include "m_textinput.h" // Data. #include "sounds.h" @@ -159,6 +160,9 @@ boolean fromlevelselect = false; boolean menu_text_input = false; +char menu_text_input_buf[MAXSTRINGLENGTH]; +static textinput_t menuinput; + static INT32 coolalphatimer = 9; typedef enum @@ -245,6 +249,7 @@ menu_t SR_MainDef, SR_UnlockChecklistDef; // Misc. Main Menu static void M_Options(INT32 choice); +static void M_Multiplayer(INT32 choice); static void M_LocalSkinMenu(INT32 choice); static void M_LocalSkinChange(INT32 choice); static void M_Manual(INT32 choice); @@ -591,7 +596,7 @@ static menuitem_t MainMenu[] = { {IT_SUBMENU|IT_STRING, NULL, "Extras", &SR_MainDef, 76}, {IT_CALL |IT_STRING, NULL, "Time Attack", M_TimeAttack, 84}, - {IT_SUBMENU|IT_STRING, NULL, "Multiplayer", &MP_MainDef, 92}, + {IT_CALL |IT_STRING, NULL, "Multiplayer", M_Multiplayer, 92}, {IT_CALL |IT_STRING, NULL, "Options", M_Options, 100}, {IT_CALL |IT_STRING, NULL, "Addons", M_Addons, 108}, {IT_CALL |IT_STRING, NULL, "Quit Game", M_QuitSRB2, 116}, @@ -3502,46 +3507,15 @@ static void M_ChangeCvar(INT32 choice) static boolean M_ChangeStringCvar(INT32 choice) { consvar_t *cv = (consvar_t *)currentMenu->menuitems[itemOn].itemaction; - char buf[MAXSTRINGLENGTH]; - size_t len; - choice = M_ShiftChar(choice); - - switch (choice) + if (M_TextInputHandle(&menuinput, choice)) { - case KEY_BACKSPACE: - len = strlen(cv->string); - if (len > 0) - { - S_StartSound(NULL,sfx_menu1); // Tails - M_Memcpy(buf, cv->string, len); - buf[len-1] = 0; - CV_Set(cv, buf); - } - return true; - case KEY_DEL: - if (cv->string[0]) - { - S_StartSound(NULL,sfx_menu1); // Tails - CV_Set(cv, ""); - } - return true; - default: - if ((cv_keyboardlayout.value != 3 && choice >= 32 && choice <= 127) || (cv_keyboardlayout.value == 3 && choice >= 32 && choice <= 141)) - { - len = strlen(cv->string); - if (len < MAXSTRINGLENGTH - 1) - { - S_StartSound(NULL,sfx_menu1); // Tails - M_Memcpy(buf, cv->string, len); - buf[len++] = (char)choice; - buf[len] = 0; - CV_Set(cv, buf); - } - return true; - } - break; + S_StartSound(NULL,sfx_menu1); // Tails + CV_Set(cv, menuinput.buffer); + + return true; } + return false; } @@ -3569,6 +3543,19 @@ static void M_NextOpt(void) else itemOn++; } while (oldItemOn != itemOn && (currentMenu->menuitems[itemOn].status & IT_TYPE) == IT_SPACE); + + if (itemOn < currentMenu->numitems && (currentMenu->menuitems[itemOn].status & IT_CVARTYPE) == IT_CV_STRING) + { + consvar_t *cv = (consvar_t *)currentMenu->menuitems[itemOn].itemaction; + + // Just in case + memset(menu_text_input_buf, 0, sizeof menu_text_input_buf); + M_TextInputInit(&menuinput, menu_text_input_buf, sizeof menu_text_input_buf); + + M_TextInputSetString(&menuinput, cv->string); + + CONS_Printf("Set input string to %s\n", cv->string); + } } static void M_PrevOpt(void) @@ -3942,7 +3929,6 @@ boolean M_Responder(event_t *ev) if ((currentMenu->menuitems[itemOn].status & IT_CVARTYPE) == IT_CV_STRING) { menu_text_input = true; - ch = M_ShiftChar(ch); if (M_ChangeStringCvar(ch)) return true; else @@ -4942,6 +4928,28 @@ void M_DrawTextBoxFlags(INT32 x, INT32 y, INT32 width, INT32 boxlines, INT32 fla V_DrawFill(x+5, y+5, width*8+6, boxlines*8+6, 239|flags); } +void M_DrawTextInput(INT32 x, INT32 y, textinput_t *input, INT32 flags) +{ + V_DrawString(x, y, V_ALLOWLOWERCASE|flags, input->buffer); + + // draw text cursor for name + if (input->length && skullAnimCounter < 4) // blink cursor + V_DrawCharacter(x+V_SubStringWidth(input->buffer, input->cursor, V_ALLOWLOWERCASE), y+3, '_'|flags, false); + + // draw selection + if (input->select != input->cursor) + { + size_t start = min(input->select, input->cursor); + size_t end = max(input->select, input->cursor); + + size_t len = end - start; + + INT32 startx = V_SubStringWidth(input->buffer, start, V_ALLOWLOWERCASE); + + V_DrawFill(x+startx, y, V_SubStringWidth(input->buffer+start, len, V_ALLOWLOWERCASE), 8, 103|V_TRANSLUCENT|flags); + } +} + // horizontally centered text static void M_CentreText(INT32 y, const char *string) { @@ -5143,7 +5151,7 @@ static void M_DrawGenericMenu(void) break; case IT_CV_STRING: M_DrawTextBox(x, y + 4, MAXSTRINGLENGTH, 1); - V_DrawString(x + 8, y + 12, V_ALLOWLOWERCASE, cv->string); + V_DrawString(x + 8, y + 12, V_ALLOWLOWERCASE, menuinput.buffer); if (skullAnimCounter < 4 && i == itemOn) V_DrawCharacter(x + 8 + V_StringWidth(cv->string, 0), y + 12, '_' | 0x80, false); @@ -6648,11 +6656,11 @@ I_mutex replayquerymutex; #define MAXREPLAYQUERY 40 -char replayqueryinput[MAXREPLAYQUERY+1]; // The input typed -size_t replayquerypos = 0; // Position in input window +static char replayqueryinput_buffer[MAXREPLAYQUERY+1]; // The input typed +static textinput_t replayqueryinput; -size_t replayqueryfound = 0; // Number of checked replay entries -size_t replayquerycheck = 0; // Index of next replay entry to check in demolist_all +static size_t replayqueryfound = 0; // Number of checked replay entries +static size_t replayquerycheck = 0; // Index of next replay entry to check in demolist_all #define DF_ENCORE 0x40 static INT16 replayScrollTitle = 0; @@ -6707,8 +6715,8 @@ static void LoadReplayNames(void) static void ResetReplayQuery(void) { - memset(replayqueryinput, 0, MAXREPLAYQUERY); - replayquerypos = 0; + memset(replayqueryinput_buffer, 0, MAXREPLAYQUERY); + M_TextInputInit(&replayqueryinput, replayqueryinput_buffer, MAXREPLAYQUERY); replayqueryfound = 0; replayquerycheck = 0; @@ -6732,7 +6740,7 @@ static void M_HutCheckReplays(size_t maxnum) return; // If we don't have any query, just copy all demos and consider them checked - if (replayquerypos == 0) + if (replayqueryinput.length == 0) { // Mark as done replayqueryfound = replayquerycheck = sizedirmenu; @@ -6756,7 +6764,7 @@ static void M_HutCheckReplays(size_t maxnum) case MD_NOTLOADED: case MD_OUTDATED: case MD_LOADED: - if (demolist_all[replayquerycheck].title[0] && strcasestr(demolist_all[replayquerycheck].title, replayqueryinput) != NULL) + if (demolist_all[replayquerycheck].title[0] && strcasestr(demolist_all[replayquerycheck].title, replayqueryinput.buffer) != NULL) AddCheckedReplay(); // It matches, add it! else replayquerycheck++; // Doesn't match, moving on... @@ -6855,41 +6863,23 @@ void M_ReplayHut(INT32 choice) static boolean M_HandleReplayHutQuery(INT32 choice) { - switch (choice) + // Yea gonna copy buffer and check if it changed, thats better than checking for specific keys i think + char tmp[MAXREPLAYQUERY+1]; + memcpy(tmp, replayqueryinput_buffer, MAXREPLAYQUERY+1); + + if (M_TextInputHandle(&replayqueryinput, choice)) { - case KEY_BACKSPACE: - if (replayquerypos == 0) - break; - - S_StartSound(NULL,sfx_menu1); - - replayquerypos--; - replayqueryinput[replayquerypos] = 0; + S_StartSound(NULL,sfx_menu1); + // Restart search only if we actually modified input and not just moved in it + if (memcmp(tmp, replayqueryinput_buffer, MAXREPLAYQUERY+1)) + { preparefilemenu(false, true); dir_on[menudepthleft] = 0; PrepReplayList(false); + } - return true; - - default: - if (choice < 32 || choice > 127) - break; - - if (replayquerypos < MAXREPLAYQUERY) - { - S_StartSound(NULL,sfx_menu1); - - replayqueryinput[replayquerypos] = choice; - replayqueryinput[replayquerypos+1] = 0; - ++replayquerypos; - - preparefilemenu(false, true); - dir_on[menudepthleft] = 0; - PrepReplayList(false); - } - - return true; + return true; } return false; @@ -7320,15 +7310,11 @@ static void M_DrawReplayHut(void) // Draw search query M_DrawTextBoxFlags(x, 200 - 22, MAXREPLAYQUERY, 1, V_SNAPTOBOTTOM); - if (replayquerypos) - V_DrawString(x + 8, 200 - 14, V_ALLOWLOWERCASE|V_SNAPTOBOTTOM, replayqueryinput); + if (replayqueryinput.length) + M_DrawTextInput(x + 8, 200 - 14, &replayqueryinput, V_SNAPTOBOTTOM); else V_DrawString(x + 8, 200 - 14, V_ALLOWLOWERCASE|V_SNAPTOBOTTOM, "\x86Type to search..."); - // draw text cursor for name - if (replayquerypos && skullAnimCounter < 4) // blink cursor - V_DrawCharacter(x + 8 + V_StringWidth(replayqueryinput, V_ALLOWLOWERCASE), 200 - 14, '_'|V_SNAPTOBOTTOM, false); - if (replaynamesloaded && replayquerycheck < sizedirmenu) V_DrawString(x + 8, 200 - 30, V_ALLOWLOWERCASE|V_SNAPTOBOTTOM, va("Searching %u/%u...", (unsigned)replayquerycheck, (unsigned)sizedirmenu)); } @@ -8906,9 +8892,11 @@ void M_DrawTimeAttackMenu(void) if (currentMenu->menuitems[i].status & IT_CV_STRING) { M_DrawTextBox(x + 32, y - 8, MAXPLAYERNAME, 1); - V_DrawString(x + 40, y, V_ALLOWLOWERCASE, cv->string); - if (itemOn == i && skullAnimCounter < 4) // blink cursor - V_DrawCharacter(x + 40 + V_StringWidth(cv->string, V_ALLOWLOWERCASE), y, '_',false); + + if (itemOn != i) + V_DrawString(x + 40, y, V_ALLOWLOWERCASE, cv->string); + else + M_DrawTextInput(x + 40, y, &menuinput, 0); } else { @@ -10185,7 +10173,19 @@ static void M_StartServerMenu(INT32 choice) // ============== static char setupm_ip[28]; +static textinput_t setupm_input_ip; #endif + +void M_Multiplayer(INT32 choice) +{ + (void)choice; +#ifndef NONET + memset(setupm_ip, 0, 28); + M_TextInputInit(&setupm_input_ip, setupm_ip, 28); +#endif + M_SetupNextMenu(&MP_MainDef); +} + static UINT8 setupm_pselect = 1; // Draw the funky Connect IP menu. Tails 11-19-2002 @@ -10219,12 +10219,10 @@ Update the maxplayers label... V_DrawFill(x+5, y+4+5, /*16*8 + 6,*/ BASEVIDWIDTH - 2*(x+5), 8+6, 239); // draw name string - V_DrawString(x+8,y+12, V_ALLOWLOWERCASE, setupm_ip); - - // draw text cursor for name - if (itemOn == 9 - && skullAnimCounter < 4) //blink cursor - V_DrawCharacter(x+8+V_StringWidth(setupm_ip, V_ALLOWLOWERCASE),y+12,'_',false); + if (itemOn != 9) + V_DrawString(x+8,y+12, V_ALLOWLOWERCASE, setupm_ip); + else + M_DrawTextInput(x+8, y+12, &setupm_input_ip, 0); #endif // character bar, ripped off the color bar :V @@ -10412,7 +10410,6 @@ static void M_ConnectLastServer(INT32 choice) // Tails 11-19-2002 static void M_HandleConnectIP(INT32 choice) { - size_t l; boolean exitmenu = false; // exit to previous menu and send name change switch (choice) @@ -10437,41 +10434,21 @@ static void M_HandleConnectIP(INT32 choice) exitmenu = true; break; + case KEY_LEFTARROW: + case KEY_RIGHTARROW: case KEY_BACKSPACE: - if ((l = strlen(setupm_ip)) != 0) - { - S_StartSound(NULL,sfx_menu1); // Tails - setupm_ip[l-1] = 0; - } - break; - case KEY_DEL: - if (setupm_ip[0]) - { + if (M_TextInputHandle(&setupm_input_ip, choice)) S_StartSound(NULL,sfx_menu1); // Tails - setupm_ip[0] = 0; - } break; default: - l = strlen(setupm_ip); - if (l >= 28-1) - break; - // Rudimentary number and period enforcing - also allows letters so hostnames can be used instead - if ((choice >= '-' && choice <= ':') || (choice >= 'A' && choice <= 'Z') || (choice >= 'a' && choice <= 'z')) + if ((choice >= '-' && choice <= ':') || (choice >= 'A' && choice <= 'Z') || (choice >= 'a' && choice <= 'z') + || (choice >= 199 && choice <= 211 && choice != 202 && choice != 206)) //numpad too! { - S_StartSound(NULL,sfx_menu1); // Tails - setupm_ip[l] = (char)choice; - setupm_ip[l+1] = 0; - } - else if (choice >= 199 && choice <= 211 && choice != 202 && choice != 206) //numpad too! - { - char keypad_translation[] = {'7','8','9','-','4','5','6','+','1','2','3','0','.'}; - choice = keypad_translation[choice - 199]; - S_StartSound(NULL,sfx_menu1); // Tails - setupm_ip[l] = (char)choice; - setupm_ip[l+1] = 0; + if (M_TextInputHandle(&setupm_input_ip, choice)) + S_StartSound(NULL,sfx_menu1); // Tails } break; } @@ -10496,14 +10473,15 @@ static state_t *multi_state; // this is set before entering the MultiPlayer setup menu, // for either player 1 or 2 -static char setupm_name[MAXPLAYERNAME+1]; -static player_t *setupm_player; -static consvar_t *setupm_cvskin; -static consvar_t *setupm_cvcolor; -static consvar_t *setupm_cvname; -static UINT8 setupm_skinxpos; -static INT32 setupm_fakeskin; -static INT32 setupm_fakecolor; +static char setupm_name[MAXPLAYERNAME+1]; +static textinput_t setupm_input; +static player_t *setupm_player; +static consvar_t *setupm_cvskin; +static consvar_t *setupm_cvcolor; +static consvar_t *setupm_cvname; +static UINT8 setupm_skinxpos; +static INT32 setupm_fakeskin; +static INT32 setupm_fakecolor; //variables used for other skin select menus static UINT8 setupm_skinypos; @@ -10579,11 +10557,11 @@ static void M_DrawSetupMultiPlayerMenu(void) } M_DrawTextBox(mx + 32, my - 8 + nameboxaddy, MAXPLAYERNAME, 1); - V_DrawString(mx + 40, my + nameboxaddy, V_ALLOWLOWERCASE, setupm_name); - // draw text cursor for name - if (!itemOn && skullAnimCounter < 4) // blink cursor - V_DrawCharacter(mx + 40 + V_StringWidth(setupm_name, V_ALLOWLOWERCASE), my + nameboxaddy, '_', false); + if (itemOn != 0) + V_DrawString(mx + 40, my + nameboxaddy, V_ALLOWLOWERCASE, setupm_input.buffer); + else + M_DrawTextInput(mx + 40, my + nameboxaddy, &setupm_input, 0); // draw skin string st = V_StringWidth(skins[setupm_fakeskin].realname, 0); @@ -11182,7 +11160,6 @@ static void M_DrawSetupMultiPlayerMenu(void) // Handle 1P/2P MP Setup static void M_HandleSetupMultiPlayer(INT32 choice) { - size_t l; boolean exitmenu = false; // exit to previous menu and send name change if ((choice == gamecontrol[gc_fire][0] || choice == gamecontrol[gc_fire][1]) && itemOn == 2) @@ -11304,7 +11281,12 @@ static void M_HandleSetupMultiPlayer(INT32 choice) break; case KEY_LEFTARROW: - if (cv_skinselectmenu.value == SKINMENUTYPE_2D && itemOn == 1) + if (itemOn == 0) + { + M_TextInputHandle(&setupm_input, choice); + S_StartSound(NULL,sfx_menu1); // Tails + } + else if (cv_skinselectmenu.value == SKINMENUTYPE_2D && itemOn == 1) { if (setupm_skinlockedselect) { @@ -11358,7 +11340,12 @@ static void M_HandleSetupMultiPlayer(INT32 choice) break; case KEY_RIGHTARROW: - if (cv_skinselectmenu.value == SKINMENUTYPE_2D && itemOn == 1) + if (itemOn == 0) + { + M_TextInputHandle(&setupm_input, choice); + S_StartSound(NULL,sfx_menu1); // Tails + } + else if (cv_skinselectmenu.value == SKINMENUTYPE_2D && itemOn == 1) { if (setupm_skinlockedselect) { @@ -11389,7 +11376,7 @@ static void M_HandleSetupMultiPlayer(INT32 choice) } else if (cv_skinselectmenu.value == SKINMENUTYPE_EXTENDED){ if (setupm_skinselect >= ((setupm_skinypos-1)+SKINGRIDHEIGHT)*8+24 && setupm_skinypos < (ROUNDSKINSUPTO8/8)-SKINGRIDHEIGHT+24) - setupm_skinypos++; + setupm_skinypos++; } } else @@ -11427,11 +11414,8 @@ static void M_HandleSetupMultiPlayer(INT32 choice) BREAKWHENLOCKED if (itemOn == 0) { - if ((l = strlen(setupm_name))!=0) - { - S_StartSound(NULL,sfx_menu1); // Tails - setupm_name[l-1] =0; - } + M_TextInputHandle(&setupm_input, choice); + S_StartSound(NULL,sfx_menu1); // Tails } else if ((cv_skinselectmenu.value == SKINMENUTYPE_GRID || cv_skinselectmenu.value == SKINMENUTYPE_EXTENDED) && itemOn == 1) { @@ -11456,10 +11440,10 @@ static void M_HandleSetupMultiPlayer(INT32 choice) case KEY_DEL: if (cv_skinselectmenu.value) BREAKWHENLOCKED - if (itemOn == 0 && (l = strlen(setupm_name))!=0) + if (itemOn == 0) { + M_TextInputHandle(&setupm_input, choice); S_StartSound(NULL,sfx_menu1); // Tails - setupm_name[0] = 0; } break; @@ -11496,17 +11480,10 @@ static void M_HandleSetupMultiPlayer(INT32 choice) break; default: - if (choice < 32 || choice > 127) - break; if (itemOn == 0) { - l = strlen(setupm_name); - if (l < MAXPLAYERNAME) - { + if (M_TextInputHandle(&setupm_input, choice)) S_StartSound(NULL,sfx_menu1); // Tails - setupm_name[l] =(char)choice; - setupm_name[l+1] =0; - } } break; } @@ -11571,7 +11548,9 @@ static void M_SetupMultiPlayer(INT32 choice) multi_state = cv_skinselectspin.value == SKINSELECTSPIN_PAIN ? &states[S_KART_PAIN] : &states[mobjinfo[MT_PLAYER].seestate]; multi_tics = multi_state->tics*FRACUNIT; - strcpy(setupm_name, cv_playername.string); + + M_TextInputInit(&setupm_input, setupm_name, sizeof(setupm_name)); + M_TextInputSetString(&setupm_input, cv_playername.string); // set for player 1 setupm_player = &players[consoleplayer]; @@ -11613,7 +11592,9 @@ static void M_SetupMultiPlayer2(INT32 choice) multi_state = cv_skinselectspin.value == SKINSELECTSPIN_PAIN ? &states[S_KART_PAIN] : &states[mobjinfo[MT_PLAYER].seestate]; multi_tics = multi_state->tics*FRACUNIT; - strcpy (setupm_name, cv_playername2.string); + + M_TextInputInit(&setupm_input, setupm_name, sizeof(setupm_name)); + M_TextInputSetString(&setupm_input, cv_playername2.string); // set for splitscreen secondary player setupm_player = &players[displayplayers[1]]; @@ -11654,7 +11635,9 @@ static void M_SetupMultiPlayer3(INT32 choice) multi_state = cv_skinselectspin.value == SKINSELECTSPIN_PAIN ? &states[S_KART_PAIN] : &states[mobjinfo[MT_PLAYER].seestate]; multi_tics = multi_state->tics; - strcpy(setupm_name, cv_playername3.string); + + M_TextInputInit(&setupm_input, setupm_name, sizeof(setupm_name)); + M_TextInputSetString(&setupm_input, cv_playername3.string); // set for splitscreen third player setupm_player = &players[displayplayers[2]]; @@ -11695,7 +11678,9 @@ static void M_SetupMultiPlayer4(INT32 choice) multi_state = cv_skinselectspin.value == SKINSELECTSPIN_PAIN ? &states[S_KART_PAIN] : &states[mobjinfo[MT_PLAYER].seestate]; multi_tics = multi_state->tics; - strcpy(setupm_name, cv_playername4.string); + + M_TextInputInit(&setupm_input, setupm_name, sizeof(setupm_name)); + M_TextInputSetString(&setupm_input, cv_playername4.string); // set for splitscreen fourth player setupm_player = &players[displayplayers[3]]; diff --git a/src/m_menu.h b/src/m_menu.h index bd0cd0e69..486b5b869 100644 --- a/src/m_menu.h +++ b/src/m_menu.h @@ -64,6 +64,10 @@ void M_DrawTextBox(INT32 x, INT32 y, INT32 width, INT32 boxlines); // Same but with extra flags applied void M_DrawTextBoxFlags(INT32 x, INT32 y, INT32 width, INT32 boxlines, INT32 flags); +// Draw text input +typedef struct textinput_s textinput_t; +void M_DrawTextInput(INT32 x, INT32 y, textinput_t *input, INT32 flags); + // Used in d_netcmd to restart time attack void M_ModeAttackRetry(INT32 choice); diff --git a/src/m_textinput.c b/src/m_textinput.c new file mode 100644 index 000000000..48ef7d203 --- /dev/null +++ b/src/m_textinput.c @@ -0,0 +1,306 @@ +#include "m_textinput.h" +#include "i_system.h" +#include "keys.h" +#include "console.h" + +static void M_TextInputDel(textinput_t *input, size_t start, size_t end) +{ + size_t len; + + len = (end - start); + + if (end != input->length) + memmove(&input->buffer[start], &input->buffer[end], input->length-end); + memset(&input->buffer[input->length - len], 0, len); + + input->length -= len; + + if (input->select >= end) + input->select -= len; + else if (input->select > start) + input->select = start; + + if (input->cursor >= end) + input->cursor -= len; + else if (input->cursor > start) + input->cursor = start; +} + +static void M_TextInputDelSelection(textinput_t *input) +{ + size_t start, end; + + if (input->cursor > input->select) + { + start = input->select; + end = input->cursor; + } + else + { + start = input->cursor; + end = input->select; + } + + M_TextInputDel(input, start, end); + + input->select = input->cursor = start; +} + +static void M_TextInputAddString(textinput_t *input, const char *c) +{ + size_t csize = strlen(c); + + if (input->length + csize > input->buffer_size-1) + return; + + if (input->cursor != input->length) + memmove(&input->buffer[input->cursor+csize], &input->buffer[input->cursor], input->length-input->cursor); + memcpy(&input->buffer[input->cursor], c, csize); + input->length += csize; + input->select = (input->cursor += csize); +} + +static void M_TextInputAddChar(textinput_t *input, char c) +{ + if (input->length >= input->buffer_size-1) + return; + + if (input->cursor != input->length) + memmove(&input->buffer[input->cursor+1], &input->buffer[input->cursor], input->length-input->cursor); + input->buffer[input->cursor++] = c; + input->buffer[++input->length] = 0; + input->select = input->cursor; +} + +static void M_TextInputDelChar(textinput_t *input) +{ + if (!input->cursor) + return; + + if (input->cursor != input->length) + memmove(&input->buffer[input->cursor-1], &input->buffer[input->cursor], input->length-input->cursor); + input->buffer[--input->length] = 0; + input->select = --input->cursor; +} + +static void M_TextInputToWordEnd(textinput_t *input, boolean move_sel) +{ + // Skip spaces + while (input->cursor < input->length && isspace(input->buffer[input->cursor])) + ++input->cursor; + + // Skip word + while (input->cursor < input->length && !isspace(input->buffer[input->cursor])) + ++input->cursor; + + if (move_sel) input->select = input->cursor; +} + +static void M_TextInputToWordBegin(textinput_t *input, boolean move_sel) +{ + // Hack, always move back 1 character if possible so if we press ctrl-left at a word beginning + // we move to previous word + if (input->cursor) --input->cursor; + + // Skip spaces + while (input->cursor && isspace(input->buffer[input->cursor])) + --input->cursor; + + // Skip word + while (input->cursor && !isspace(input->buffer[input->cursor])) + --input->cursor; + + // Unless we reached beginning of line, we're pointing at a space before word, so move cursor + // forward to fix that + if (input->cursor) ++input->cursor; + + if (move_sel) input->select = input->cursor; +} + +void M_TextInputInit(textinput_t *input, char *buffer, size_t buffer_size) +{ + input->buffer = buffer; + input->buffer_size = buffer_size; + + M_TextInputClear(input); +} + +void M_TextInputClear(textinput_t *input) +{ + input->cursor = 0; + input->select = 0; + input->length = 0; +} + +void M_TextInputSetString(textinput_t *input, const char *c) +{ + memset(input->buffer, 0, input->buffer_size); + strcpy(input->buffer, c); + input->cursor = input->select = input->length = strlen(c); +} + +boolean M_TextInputHandle(textinput_t *input, INT32 key) +{ + if (key == KEY_LSHIFT || key == KEY_RSHIFT + || key == KEY_LCTRL || key == KEY_RCTRL + || key == KEY_LALT || key == KEY_RALT) + return false; + + if ((cv_keyboardlayout.value != 3 && ctrldown) || (cv_keyboardlayout.value == 3 && ctrldown && !altdown)) + { + if (key == 'x' || key == 'X') + { + if (input->select > input->cursor) + I_ClipboardCopy(&input->buffer[input->cursor], input->select-input->cursor); + else + I_ClipboardCopy(&input->buffer[input->select], input->cursor-input->select); + M_TextInputDelSelection(input); + return true; + } + else if (key == 'c' || key == 'C') + { + if (input->select > input->cursor) + I_ClipboardCopy(&input->buffer[input->cursor], input->select-input->cursor); + else + I_ClipboardCopy(&input->buffer[input->select], input->cursor-input->select); + return true; + } + else if (key == 'v' || key == 'V') + { + const char *paste = I_ClipboardPaste(); + if (input->select != input->cursor) + M_TextInputDelSelection(input); + if (paste != NULL) + M_TextInputAddString(input, paste); + return true; + } + else if (key == 'w' || key == 'W') + { + size_t word_start, word_end, i; + word_end = i = input->cursor; + + // Unless we're pointing at the beginning of line, decrement i so we only start + // removing symbols that come before the cursor + if (i) --i; + + // We might be pointing to spaces, skip them first + while (i && isspace(input->buffer[i])) + --i; + + // Now skip the "word" + while (i && !isspace(input->buffer[i])) + --i; + + // Unless we reached beginning of line, i is pointing at first space that was found + // before word start, and we don't want to remove it + if (i) ++i; + + word_start = i; + + if (word_start != word_end) + M_TextInputDel(input, word_start, word_end); + + return true; + } + else if (key == KEY_RIGHTARROW) + M_TextInputToWordEnd(input, !shiftdown); + else if (key == KEY_LEFTARROW) + M_TextInputToWordBegin(input, !shiftdown); + + // Select all + if (key == 'a' || key == 'A') + { + input->select = 0; + input->cursor = input->length; + return true; + } + + // ...why shouldn't it eat the key? if it doesn't, it just means you + // can control Sonic from the console, which is silly + return true; + } + + if (key == KEY_LEFTARROW) + { + if (input->cursor != 0) + --input->cursor; + if (!shiftdown) + input->select = input->cursor; + return true; + } + else if (key == KEY_RIGHTARROW) + { + if (input->cursor < input->length) + ++input->cursor; + if (!shiftdown) + input->select = input->cursor; + return true; + } + else if (key == KEY_HOME) + { + input->cursor = 0; + if (!shiftdown) + input->select = input->cursor; + return true; + } + else if (key == KEY_END) + { + input->cursor = input->length; + if (!shiftdown) + input->select = input->cursor; + return true; + } + + // backspace and delete command prompt + if (input->select != input->cursor) + { + if (key == KEY_BACKSPACE || key == KEY_DEL) + { + M_TextInputDelSelection(input); + return true; + } + } + else if (key == KEY_BACKSPACE) + { + M_TextInputDelChar(input); + return true; + } + else if (key == KEY_DEL) + { + if (input->cursor == input->length) + return true; + ++input->cursor; + M_TextInputDelChar(input); + return true; + } + + // allow people to use keypad in console (good for typing IP addresses) - Calum + if (key >= KEY_KEYPAD7 && key <= KEY_KPADDEL) + { + char keypad_translation[] = {'7','8','9','-', + '4','5','6','+', + '1','2','3', + '0','.'}; + + key = keypad_translation[key - KEY_KEYPAD7]; + } + else if (key == KEY_KPADSLASH) + key = '/'; + + // same capslock code as hu_stuff.c's HU_responder. Check there for details. + key = CON_ShiftChar(key); + + // enter a char into the command prompt + if (key < 32 || key > 127) + return false; + + // add key to cmd line here + if (key >= 'A' && key <= 'Z' && !(shiftdown ^ capslock)) //this is only really necessary for dedicated servers + key = key + 'a' - 'A'; + + if (input->select != input->cursor) + M_TextInputDelSelection(input); + M_TextInputAddChar(input, key); + + return true; +} diff --git a/src/m_textinput.h b/src/m_textinput.h new file mode 100644 index 000000000..aad5e94ab --- /dev/null +++ b/src/m_textinput.h @@ -0,0 +1,23 @@ +#ifndef __M_TEXTINPUT__ +#define __M_TEXTINPUT__ + +#include "doomtype.h" + +typedef struct textinput_s { + size_t cursor; + size_t select; + size_t length; + + char *buffer; + size_t buffer_size; +} textinput_t; + +void M_TextInputInit(textinput_t *input, char *buffer, size_t buffer_size); + +void M_TextInputClear(textinput_t *input); + +void M_TextInputSetString(textinput_t *input, const char *c); + +boolean M_TextInputHandle(textinput_t *input, INT32 key); + +#endif diff --git a/src/v_video.c b/src/v_video.c index 5746d963e..492a75004 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -2845,11 +2845,14 @@ INT32 V_LevelNameHeight(const char *string) // // Find string width from hu_font chars // -INT32 V_StringWidth(const char *string, INT32 option) +INT32 V_SubStringWidth(const char *string, INT32 length, INT32 option) { INT32 c, w = 0; INT32 spacewidth = 4, charwidth = 0; - size_t i; + ssize_t i; + + if (length < 0) + length = strlen(string); switch (option & V_SPACINGMASK) { @@ -2865,7 +2868,7 @@ INT32 V_StringWidth(const char *string, INT32 option) break; } - for (i = 0; i < strlen(string); i++) + for (i = 0; string[i] && i < length; i++) { c = string[i]; if ((UINT8)c >= 0x80 && (UINT8)c <= 0x8F) //color parsing! -Inuyasha 2.16.09 @@ -2884,11 +2887,14 @@ INT32 V_StringWidth(const char *string, INT32 option) // // Find string width from hu_font chars, 0.5x scale // -INT32 V_SmallStringWidth(const char *string, INT32 option) +INT32 V_SmallSubStringWidth(const char *string, INT32 length, INT32 option) { INT32 c, w = 0; INT32 spacewidth = 2, charwidth = 0; - size_t i; + ssize_t i; + + if (length < 0) + length = strlen(string); switch (option & V_SPACINGMASK) { @@ -2904,7 +2910,7 @@ INT32 V_SmallStringWidth(const char *string, INT32 option) break; } - for (i = 0; i < strlen(string); i++) + for (i = 0; string[i] && i < length; i++) { c = string[i]; if ((UINT8)c >= 0x80 && (UINT8)c <= 0x8F) //color parsing! -Inuyasha 2.16.09 @@ -2923,12 +2929,15 @@ INT32 V_SmallStringWidth(const char *string, INT32 option) // // Find string width from tny_font chars // -INT32 V_ThinStringWidth(const char *string, INT32 option) +INT32 V_ThinSubStringWidth(const char *string, INT32 length, INT32 option) { INT32 c, w = 0; INT32 spacewidth = 2, charwidth = 0; boolean lowercase = (option & V_ALLOWLOWERCASE); - size_t i; + ssize_t i; + + if (length < 0) + length = strlen(string); switch (option & V_SPACINGMASK) { @@ -2945,7 +2954,7 @@ INT32 V_ThinStringWidth(const char *string, INT32 option) break; } - for (i = 0; i < strlen(string); i++) + for (i = 0; string[i] && i < length; i++) { c = string[i]; if ((UINT8)c >= 0x80 && (UINT8)c <= 0x8F) //color parsing! -Inuyasha 2.16.09 @@ -2963,7 +2972,7 @@ INT32 V_ThinStringWidth(const char *string, INT32 option) else { w += (charwidth ? charwidth - : ((option & V_6WIDTHSPACE && i < strlen(string)-1) ? max(1, SHORT(tny_font[c]->width)-1) // Reuse this flag for the alternate bunched-up spacing + : ((option & V_6WIDTHSPACE && i < length-1) ? max(1, SHORT(tny_font[c]->width)-1) // Reuse this flag for the alternate bunched-up spacing : SHORT(tny_font[c]->width))); } } diff --git a/src/v_video.h b/src/v_video.h index b1d10af6a..0dae04aaa 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -237,11 +237,14 @@ void V_DrawCreditString(fixed_t x, fixed_t y, INT32 option, const char *string); INT32 V_CreditStringWidth(const char *string); // Find string width from hu_font chars -INT32 V_StringWidth(const char *string, INT32 option); +INT32 V_SubStringWidth(const char *string, INT32 length, INT32 option); +#define V_StringWidth(string, option) V_SubStringWidth(string, -1, option) // Find string width from hu_font chars, 0.5x scale -INT32 V_SmallStringWidth(const char *string, INT32 option); +INT32 V_SmallSubStringWidth(const char *string, INT32 length, INT32 option); +#define V_SmallStringWidth(string, option) V_SmallSubStringWidth(string, -1, option) // Find string width from tny_font chars -INT32 V_ThinStringWidth(const char *string, INT32 option); +INT32 V_ThinSubStringWidth(const char *string, INT32 length, INT32 option); +#define V_ThinStringWidth(string, option) V_ThinSubStringWidth(string, -1, option) char V_GetSkincolorChar(INT32 color); From e2367d26d195bbf3b080cb310f24d4ab9a3e136b Mon Sep 17 00:00:00 2001 From: Indev Date: Mon, 30 Sep 2024 12:08:21 +0300 Subject: [PATCH 03/66] Use same keyboardlayout code as in chat for textinput, also add a null terminator after ctrl-v just in case string is not always zeroed out already --- src/m_textinput.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/m_textinput.c b/src/m_textinput.c index 48ef7d203..8b608cc9a 100644 --- a/src/m_textinput.c +++ b/src/m_textinput.c @@ -58,6 +58,7 @@ static void M_TextInputAddString(textinput_t *input, const char *c) memcpy(&input->buffer[input->cursor], c, csize); input->length += csize; input->select = (input->cursor += csize); + input->buffer[input->length] = 0; } static void M_TextInputAddChar(textinput_t *input, char c) @@ -288,7 +289,7 @@ boolean M_TextInputHandle(textinput_t *input, INT32 key) key = '/'; // same capslock code as hu_stuff.c's HU_responder. Check there for details. - key = CON_ShiftChar(key); + key = cv_keyboardlayout.value == 3 ? CON_ShitAndAltGrChar(key) : CON_ShiftChar(key); // enter a char into the command prompt if (key < 32 || key > 127) From ff2b28ac73e88101132a5602a55b2030bdbc0b55 Mon Sep 17 00:00:00 2001 From: Indev Date: Mon, 30 Sep 2024 12:13:25 +0300 Subject: [PATCH 04/66] Use m_textinput for chat too --- src/hu_stuff.c | 395 ++++++++++++++++++------------------------------- 1 file changed, 140 insertions(+), 255 deletions(-) diff --git a/src/hu_stuff.c b/src/hu_stuff.c index ba6bb72bc..b864e14b6 100644 --- a/src/hu_stuff.c +++ b/src/hu_stuff.c @@ -49,6 +49,8 @@ #include "s_sound.h" // song credits #include "k_kart.h" +#include "m_textinput.h" + #ifdef HWRENDER #include "hardware/hw_main.h" #endif @@ -86,8 +88,8 @@ patch_t *frameslash; // framerate stuff. Used in screen.c static player_t *plr; boolean chat_on; // entering a chat message? -static char w_chat[HU_MAXMSGLEN + 1]; -static size_t c_input = 0; // let's try to make the chat input less shitty. +static char w_chat_buf[HU_MAXMSGLEN + 1]; +static textinput_t w_chat; static boolean headsupactive = false; boolean hu_showscores; // draw rankings static char hu_tick; @@ -1143,71 +1145,6 @@ static void Got_Saycmd(UINT8 **p, INT32 playernum) #endif } -// Handles key input and string input -// -static inline boolean HU_keyInChatString(char *s, char ch) -{ - size_t l; - - if ((ch >= HU_FONTSTART && ch <= HU_FONTEND && hu_font[ch-HU_FONTSTART]) - || ch == ' ') // Allow spaces, of course - { - l = strlen(s); - if (l < HU_MAXMSGLEN - 1) - { - if (c_input >= strlen(s)) // don't do anything complicated - { - s[l++] = ch; - s[l]=0; - } - else - { - // move everything past c_input for new characters: - size_t m = HU_MAXMSGLEN-1; - while (m>=c_input) - { - if (s[m]) - s[m+1] = (s[m]); - if (m == 0) // prevent overflow - break; - m--; - } - s[c_input] = ch; // and replace this. - } - c_input++; - return true; - } - return false; - } - else if (ch == KEY_BACKSPACE) - { - size_t i = c_input; - - if (c_input <= 0) - return false; - - if (!s[i-1]) - return false; - - if (i >= strlen(s)-1) - { - s[strlen(s)-1] = 0; - c_input--; - return false; - } - - for (; (i < HU_MAXMSGLEN); i++) - { - s[i-1] = s[i]; - } - c_input--; - } - else if (ch != KEY_ENTER) - return false; // did not eat key - - return true; // ate the key -} - #endif // @@ -1280,9 +1217,9 @@ static boolean HU_clearChatSpaces(void) char c; // current character we're iterating. boolean nothingbutspaces = true; - for (; i < strlen(w_chat); i++) // iterate through message and eradicate all spaces that don't belong. + for (; i < strlen(w_chat_buf); i++) // iterate through message and eradicate all spaces that don't belong. { - c = w_chat[i]; + c = w_chat_buf[i]; if (!c) break; // if there's nothing, it's safe to assume our message has ended, so let's not waste any more time here. @@ -1294,128 +1231,110 @@ static boolean HU_clearChatSpaces(void) return nothingbutspaces; } -// -// -static void HU_queueChatChar(INT32 c) +static void HU_SendChatMessage(void) { - // send automaticly the message (no more chat char) - if (c == KEY_ENTER) + char buf[2 + HU_MAXMSGLEN + 1]; + char *msg = &buf[2]; + size_t ci = 2; + INT32 target = 0; + char c; + + if (HU_clearChatSpaces()) // Avoids being able to send empty messages, or something. + return; // If this returns true, that means our message was NOTHING but spaces, so don't send it period. + + do { + c = w_chat_buf[-2+ci++]; + if (!c || (c >= ' ' && !(c & 0x80))) // copy printable characters and terminating '\0' only. + buf[ci-1]=c; + } while (c); + + M_TextInputClear(&w_chat); + + // last minute mute check + if (CHAT_MUTE) { - char buf[2 + HU_MAXMSGLEN + 1]; - char *msg = &buf[2]; - size_t i; - size_t ci = 2; - INT32 target = 0; + HU_AddChatText(va("%s>ERROR: The chat is muted. You can't say anything.", "\x85"), false); + return; + } - if (HU_clearChatSpaces()) // Avoids being able to send empty messages, or something. - return; // If this returns true, that means our message was NOTHING but spaces, so don't send it period. + if (strlen(msg) > 4 && strnicmp(msg, "/pm", 3) == 0) // used /pm + { + INT32 spc = 1; // used if nodenum[1] is a space. + char *nodenum = (char*) malloc(3); + const char *newmsg; - do { - c = w_chat[-2+ci++]; - if (!c || (c >= ' ' && !(c & 0x80))) // copy printable characters and terminating '\0' only. - buf[ci-1]=c; - } while (c); - i = 0; - for (;(iERROR: The chat is muted. You can't say anything.", "\x85"), false); + HU_AddChatText(va("%sCannot send sayto in Say-Team.", "\x85"), false); return; } - if (strlen(msg) > 4 && strnicmp(msg, "/pm", 3) == 0) // used /pm + memcpy(nodenum, msg+3, 2); + nodenum[2] = '\0'; + + // check for undesirable characters in our "number" + if (((nodenum[0] < '0') || (nodenum[0] > '9')) || ((nodenum[1] < '0') || (nodenum[1] > '9'))) { - INT32 spc = 1; // used if nodenum[1] is a space. - char *nodenum = (char*) malloc(3); - const char *newmsg; - - // what we're gonna do now is check if the node exists - // with that logic, characters 4 and 5 are our numbers: - - // teamtalk can't send PMs, just don't send it, else everyone would be able to see it, and no one wants to see your sex RP sicko. - if (teamtalk) - { - HU_AddChatText(va("%sCannot send sayto in Say-Team.", "\x85"), false); - return; - } - - memcpy(nodenum, msg+3, 2); - nodenum[2] = '\0'; - - // check for undesirable characters in our "number" - if (((nodenum[0] < '0') || (nodenum[0] > '9')) || ((nodenum[1] < '0') || (nodenum[1] > '9'))) - { - // check if nodenum[1] is a space - if (nodenum[1] == ' ') - spc = 0; - // let it slide - else - { - HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm \'.", false); - free(nodenum); - return; - } - } - // I'm very bad at C, I swear I am, additional checks eww! - if (spc != 0) - { - if (msg[5] != ' ') - { - HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm \'.", false); - free(nodenum); - return; - } - } - - target = atoi((const char*) nodenum); // turn that into a number - free(nodenum); - //CONS_Printf("%d\n", target); - - // check for target player, if it doesn't exist then we can't send the message! - if (target < MAXPLAYERS && playeringame[target]) // player exists - target++; // even though playernums are from 0 to 31, target is 1 to 32, so up that by 1 to have it work! + // check if nodenum[1] is a space + if (nodenum[1] == ' ') + spc = 0; + // let it slide else { - HU_AddChatText(va("\x82NOTICE: \x80Player %d does not exist.", target), false); // same + HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm \'.", false); + free(nodenum); return; } - - // we need to get rid of the /pm - newmsg = msg+5+spc; - strlcpy(msg, newmsg, HU_MAXMSGLEN + 1); } - if (ci > 3) // don't send target+flags+empty message. + // I'm very bad at C, I swear I am, additional checks eww! + if (spc != 0) { - if (teamtalk) - buf[0] = -1; // target - else - buf[0] = target; - - buf[1] = 0; // flags - SendNetXCmd(XD_SAY, buf, 2 + strlen(&buf[2]) + 1); + if (msg[5] != ' ') + { + HU_AddChatText("\x82NOTICE: \x80Invalid command format. Correct format is \'/pm \'.", false); + free(nodenum); + return; + } } - return; + + target = atoi((const char*) nodenum); // turn that into a number + free(nodenum); + //CONS_Printf("%d\n", target); + + // check for target player, if it doesn't exist then we can't send the message! + if (target < MAXPLAYERS && playeringame[target]) // player exists + target++; // even though playernums are from 0 to 31, target is 1 to 32, so up that by 1 to have it work! + else + { + HU_AddChatText(va("\x82NOTICE: \x80Player %d does not exist.", target), false); // same + return; + } + + // we need to get rid of the /pm + newmsg = msg+5+spc; + strlcpy(msg, newmsg, HU_MAXMSGLEN + 1); + } + if (ci > 3) // don't send target+flags+empty message. + { + if (teamtalk) + buf[0] = -1; // target + else + buf[0] = target; + + buf[1] = 0; // flags + SendNetXCmd(XD_SAY, buf, 2 + strlen(&buf[2]) + 1); } } #endif void HU_clearChatChars(void) { - size_t i = 0; - for (;idata1 != gamecontrol[gc_talkkey][1])) return false; - c = cv_keyboardlayout.value == 3 ? CON_ShitAndAltGrChar(c) : CON_ShiftChar(c); + M_TextInputHandle(&w_chat, c); - // pasting. pasting is cool. chat is a bit limited, though :( - if (((c == 'v' || c == 'V') && ctrldown) && !CHAT_MUTE) - { - const char *paste = I_ClipboardPaste(); - size_t chatlen; - size_t pastelen; - - // create a dummy string real quickly - - if (paste == NULL) - return true; - - chatlen = strlen(w_chat); - pastelen = strlen(paste); - if (chatlen+pastelen > HU_MAXMSGLEN) - return true; // we can't paste this!! - - if (c_input >= strlen(w_chat)) // add it at the end of the string. - { - memcpy(&w_chat[chatlen], paste, pastelen); // copy all of that. - c_input += pastelen; - /*size_t i = 0; - for (;i= c_input) - { - if (w_chat[i]) - w_chat[i+pastelen] = w_chat[i]; - if (i == 0) // prevent overflow - break; - i--; - } - memcpy(&w_chat[c_input], paste, pastelen); // copy all of that. - c_input += pastelen; - return true; - } - } - - if (!CHAT_MUTE && HU_keyInChatString(w_chat,c)) - { - HU_queueChatChar(c); - } if (c == KEY_ENTER) { chat_on = false; - c_input = 0; // reset input cursor chat_scrollmedown = true; // you hit enter, so you might wanna autoscroll to see what you just sent. :) + HU_SendChatMessage(); } else if (c == KEY_ESCAPE || ((c == gamecontrol[gc_talkkey][0] || c == gamecontrol[gc_talkkey][1] @@ -1561,7 +1433,6 @@ boolean HU_Responder(event_t *ev) && c >= KEY_MOUSE1)) // If it's not a keyboard key, then the chat button is used as a toggle. { chat_on = false; - c_input = 0; // reset input cursor } else if ((c == KEY_UPARROW || c == KEY_MOUSEWHEELUP) && chat_scroll > 0 && !OLDCHAT) // CHAT SCROLLING YAYS! { @@ -1575,10 +1446,6 @@ boolean HU_Responder(event_t *ev) justscrolleddown = true; chat_scrolltime = 4; } - else if (c == KEY_LEFTARROW && c_input != 0 && !OLDCHAT) // i said go back - c_input--; - else if (c == KEY_RIGHTARROW && c_input < strlen(w_chat) && !OLDCHAT) // don't need to check for admin or w/e here since the chat won't ever contain anything if it's muted. - c_input++; return true; } #endif @@ -1932,8 +1799,9 @@ static void HU_DrawChat(void) INT32 charwidth = 4, charheight = 6; INT32 boxw = cv_chatwidth.value; INT32 t = 0, c = 0, y = chaty - (typelines*charheight); - UINT32 i = 0, saylen = strlen(w_chat); // You learn new things everyday! + UINT32 i = 0, saylen = strlen(w_chat_buf); // You learn new things everyday! INT32 cflag = 0; + size_t select_start = 0, select_end = 0; const char *ntalk = "Say: ", *ttalk = "Team: "; const char *talk = ntalk; const char *mute = "Chat has been muted."; @@ -1995,13 +1863,19 @@ static void HU_DrawChat(void) i = 0; typelines = 1; - if ((strlen(w_chat) == 0 || c_input == 0) && hu_tick < 4) - V_DrawChatCharacter(chatx + 2 + c, y+1, '_' |V_SNAPTOBOTTOM|V_SNAPTOLEFT|t, !cv_allcaps.value, NULL); + if ((w_chat.cursor == 0 || w_chat.length == 0) && hu_tick < 4) + V_DrawChatCharacter(chatx+2+c+charwidth*w_chat.cursor, y+1, '_'|V_SNAPTOBOTTOM|V_SNAPTOLEFT|t, !cv_allcaps.value, NULL); - while (w_chat[i]) + if (w_chat.select != w_chat.cursor) + { + select_start = min(w_chat.select, w_chat.cursor); + select_end = max(w_chat.select, w_chat.cursor); + } + + while (w_chat_buf[i]) { boolean skippedline = false; - if (c_input == (i+1)) + if (w_chat.cursor == (i+1)) { INT32 cursorx = (c+charwidth < boxw-charwidth) ? (chatx + 2 + c+charwidth) : (chatx+1); // we may have to go down. INT32 cursory = (cursorx != chatx+1) ? (y) : (y+charheight); @@ -2016,10 +1890,14 @@ static void HU_DrawChat(void) } //Hurdler: isn't it better like that? - if (w_chat[i] < HU_FONTSTART) - ++i; - else - V_DrawChatCharacter(chatx + c + 2, y, w_chat[i++] | V_SNAPTOBOTTOM|V_SNAPTOLEFT | t, !cv_allcaps.value, NULL); + if (w_chat_buf[i] >= HU_FONTSTART) + V_DrawChatCharacter(chatx + c + 2, y, w_chat_buf[i] | V_SNAPTOBOTTOM|V_SNAPTOLEFT | t, !cv_allcaps.value, NULL); + + // Draw selection + if (i >= select_start && i < select_end) + V_DrawFill(chatx + c + 2, y-1, charwidth, charheight, 103|V_TRANSLUCENT|V_SNAPTOBOTTOM|V_SNAPTOLEFT|t); + + ++i; c += charwidth; if (c > boxw-(charwidth*2) && !skippedline) @@ -2031,7 +1909,7 @@ static void HU_DrawChat(void) } // handle /pm list. It's messy, horrible and I don't care. - if (strnicmp(w_chat, "/pm", 3) == 0 && vid.width >= 400 && !teamtalk) // 320x200 unsupported kthxbai + if (strnicmp(w_chat_buf, "/pm", 3) == 0 && vid.width >= 400 && !teamtalk) // 320x200 unsupported kthxbai { INT32 count = 0; INT32 p_dispy = chaty - charheight -1; @@ -2051,38 +1929,38 @@ static void HU_DrawChat(void) { // filter: (code needs optimization pls help I'm bad with C) - if (w_chat[3]) + if (w_chat_buf[3]) { char *nodenum; UINT32 n; - // right, that's half important: (w_chat[4] may be a space since /pm0 msg is perfectly acceptable!) - if ( ( ((w_chat[3] != 0) && ((w_chat[3] < '0') || (w_chat[3] > '9'))) || ((w_chat[4] != 0) && (((w_chat[4] < '0') || (w_chat[4] > '9'))))) && (w_chat[4] != ' ')) + // right, that's half important: (w_chat_buf[4] may be a space since /pm0 msg is perfectly acceptable!) + if ( ( ((w_chat_buf[3] != 0) && ((w_chat_buf[3] < '0') || (w_chat_buf[3] > '9'))) || ((w_chat_buf[4] != 0) && (((w_chat_buf[4] < '0') || (w_chat_buf[4] > '9'))))) && (w_chat_buf[4] != ' ')) break; nodenum = (char*) malloc(3); - memcpy(nodenum, w_chat+3, 2); + memcpy(nodenum, w_chat_buf+3, 2); nodenum[2] = '\0'; n = atoi((const char*) nodenum); // turn that into a number free(nodenum); // special cases: - if ((n == 0) && !(w_chat[4] == '0')) + if ((n == 0) && !(w_chat_buf[4] == '0')) { if (!(i<10)) continue; } - else if ((n == 1) && !(w_chat[3] == '0')) + else if ((n == 1) && !(w_chat_buf[3] == '0')) { if (!((i == 1) || ((i >= 10) && (i <= 19)))) continue; } - else if ((n == 2) && !(w_chat[3] == '0')) + else if ((n == 2) && !(w_chat_buf[3] == '0')) { if (!((i == 2) || ((i >= 20) && (i <= 29)))) continue; } - else if ((n == 3) && !(w_chat[3] == '0')) + else if ((n == 3) && !(w_chat_buf[3] == '0')) { if (!((i == 3) || ((i >= 30) && (i <= 31)))) continue; @@ -2121,6 +1999,7 @@ static void HU_DrawChat_Old(void) size_t i = 0; const char *ntalk = "Say: ", *ttalk = "Say-Team: "; const char *talk = ntalk; + size_t select_start = 0, select_end = 0; INT32 charwidth = 8 * con_scalefactor; //SHORT(hu_font['A'-HU_FONTSTART]->width) * con_scalefactor; INT32 charheight = 8 * con_scalefactor; //SHORT(hu_font['A'-HU_FONTSTART]->height) * con_scalefactor; if (teamtalk) @@ -2149,14 +2028,19 @@ static void HU_DrawChat_Old(void) c += charwidth; } - if ((strlen(w_chat) == 0 || c_input == 0) && hu_tick < 4) - V_DrawCharacter(HU_INPUTX+c, y+2*con_scalefactor, '_' |cv_constextsize.value | V_NOSCALESTART|t, !cv_allcaps.value); + if ((w_chat.cursor == 0 || w_chat.length == 0) && hu_tick < 4) + V_DrawCharacter(HU_INPUTX+c+charwidth*w_chat.cursor, y+2*con_scalefactor, '_'|cv_constextsize.value|V_NOSCALESTART|t, !cv_allcaps.value); + + if (w_chat.select != w_chat.cursor) + { + select_start = min(w_chat.select, w_chat.cursor); + select_end = max(w_chat.select, w_chat.cursor); + } i = 0; - while (w_chat[i]) + while (w_chat_buf[i]) { - - if (c_input == (i+1) && hu_tick < 4) + if (w_chat.cursor == (i+1) && hu_tick < 4) { INT32 cursorx = (HU_INPUTX+c+charwidth < vid.width) ? (HU_INPUTX + c + charwidth) : (HU_INPUTX); // we may have to go down. INT32 cursory = (cursorx != HU_INPUTX) ? (y) : (y+charheight); @@ -2164,17 +2048,18 @@ static void HU_DrawChat_Old(void) } //Hurdler: isn't it better like that? - if (w_chat[i] < HU_FONTSTART) - { - ++i; - //charwidth = 4 * con_scalefactor; - } - else + if (w_chat_buf[i] >= HU_FONTSTART) { //charwidth = SHORT(hu_font[w_chat[i]-HU_FONTSTART]->width) * con_scalefactor; - V_DrawCharacter(HU_INPUTX + c, y, w_chat[i++] | cv_constextsize.value | V_NOSCALESTART | t, !cv_allcaps.value); + V_DrawCharacter(HU_INPUTX + c, y, w_chat_buf[i] | cv_constextsize.value | V_NOSCALESTART | t, !cv_allcaps.value); } + // Draw selection + if (i >= select_start && i < select_end) + V_DrawFill(HU_INPUTX + c, y, charwidth, charheight, 103|V_TRANSLUCENT|cv_constextsize.value|V_NOSCALESTART|t); + + ++i; + c += charwidth; if (c >= vid.width) { From 0deff73a460c89431566e1b931fb482df7d62a1a Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 30 Sep 2024 05:17:44 +0200 Subject: [PATCH 05/66] make a function for the music level start stuff --- src/k_kart.c | 10 ++-------- src/p_user.c | 5 +---- src/s_sound.c | 23 +++++++++++++++++++---- src/s_sound.h | 1 + 4 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/k_kart.c b/src/k_kart.c index 44497b0f2..fcb373782 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -5361,11 +5361,8 @@ void K_KartPlayerThink(player_t *player, ticcmd_t *cmd) K_UpdateInvincibilitySounds(player); // Also thanks, VAda! // Plays the music after the starting countdown. - if (P_IsLocalPlayer(player) && leveltime == (starttime + (TICRATE/2))) - { - S_ChangeMusic(mapmusname, mapmusflags, true); - S_ShowMusicCredit(); - } + if (P_IsLocalPlayer(player)) + M_Start(); } void K_KartPlayerAfterThink(player_t *player) @@ -6553,10 +6550,7 @@ void K_MoveKartPlayer(player_t *player, boolean onground) if ((leveltime == starttime-(3*TICRATE)) || (leveltime == starttime-(2*TICRATE)) || (leveltime == starttime-TICRATE)) S_StartSound(NULL, sfx_s3ka7); if (leveltime == starttime) - { S_StartSound(NULL, sfx_s3kad); - S_StopMusic(); // The GO! sound stops the level start ambience - } } // Start charging once you're given the opportunity. diff --git a/src/p_user.c b/src/p_user.c index a9b1b6b72..a6e4791e6 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -742,10 +742,7 @@ void P_RestoreMusic(player_t *player) if (P_EndingMusic(player)) return; - // Event - Level Start - if (leveltime < (starttime + (TICRATE/2))) - S_ChangeMusicInternal((encoremode ? "estart" : "kstart"), false); //S_StopMusic(); - else // see also where time overs are handled - search for "lives = 2" in this file + if (leveltime > (starttime + (TICRATE/2))) { INT32 wantedmus = 0; // 0 is level music, 1 is invincibility, 2 is grow diff --git a/src/s_sound.c b/src/s_sound.c index ec5ebf00d..855026111 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -2169,13 +2169,28 @@ void S_Start(void) mapmusresume = 0; } - //if (cv_resetmusic.value) // Starting ambience should always be restarted - S_StopMusic(); + S_StopMusic(); if (leveltime < (starttime + (TICRATE/2))) // SRB2Kart - S_ChangeMusicEx((encoremode ? "estart" : "kstart"), 0, false, mapmusposition, 0, 0); - else + S_ChangeMusicInternal((encoremode ? "estart" : "kstart"), false); //S_StopMusic(); + //S_ChangeMusicEx((encoremode ? "estart" : "kstart"), 0, false, mapmusposition, 0, 0); +} + +void M_Start(void) +{ + if (leveltime > (starttime + (TICRATE/2))) + return; + + // The GO! sound stops the level start ambience + if (leveltime == starttime) + S_StopMusic(); + + // Plays the music after the starting countdown. + if (leveltime == (starttime + (TICRATE/2))) + { S_ChangeMusicEx(mapmusname, mapmusflags, true, mapmusposition, 0, 0); + S_ShowMusicCredit(); + } } void S_RestartMusic(void) diff --git a/src/s_sound.h b/src/s_sound.h index 6f4d03f09..75c59dbc8 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -101,6 +101,7 @@ void S_InitSfxChannels(INT32 sfxVolume); void S_StopSounds(void); void S_ClearSfx(void); void S_Start(void); +void M_Start(void); // Stops music and restarts it from same position. Used for instant applying changes to amiga filters. void S_RestartMusic(void); From 0d150e4b08c1a923cc290f1f91e831a016708d9d Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 30 Sep 2024 06:28:02 +0200 Subject: [PATCH 06/66] add some basics of what i wanna have for music stuff - basic keepmusic implementation (currently checks for if the song changes instead of the map, idk if i keep this, since this allows certain maps to change the music on start, ex abstract avenue or wandering balls) - Toggle to ignore any kind of music change during the level (includes intermission music, depends on how custom intermission music works) -toggle to start map music instantly on levelload and skip the intro fanfare (also skips any linedef executed sound so some map intros dont interfere with this) --- src/p_spec.c | 7 +++++++ src/p_user.c | 3 +++ src/s_sound.c | 49 ++++++++++++++++++++++++++++++++++++++++++++++++- 3 files changed, 58 insertions(+), 1 deletion(-) diff --git a/src/p_spec.c b/src/p_spec.c index 7066058fa..0fbd16ee4 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -2127,6 +2127,9 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) break; case 413: // Change music + //if (ignoremusicchanges) + //return; + // console player only unless NOCLIMB is set if ((line->flags & ML_NOCLIMB) || (mo && mo->player && P_IsLocalPlayer(mo->player))) { @@ -2209,6 +2212,10 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) { INT32 sfxnum; + //dont play any funky sound intros that may interfere with the music + //if (cv_skipintromusic.value && (leveltime < (starttime + (TICRATE/2)))) + //return; + sfxnum = sides[line->sidenum[0]].toptexture; //P_AproxDistance(line->dx, line->dy)>>FRACBITS; if (sfxnum == sfx_None) diff --git a/src/p_user.c b/src/p_user.c index a6e4791e6..f5de9b704 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -650,6 +650,9 @@ boolean P_EndingMusic(player_t *player) INT32 bestlocalpos; player_t *bestlocalplayer; + //if (!ignoremusicchanges) + //return false; + if (!P_IsLocalPlayer(player)) // Only applies to a local player return false; diff --git a/src/s_sound.c b/src/s_sound.c index 855026111..a7845ce24 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -2149,6 +2149,28 @@ boolean S_FadeOutStopMusic(UINT32 ms) return I_FadeSong(0, ms, &S_StopMusic); } + +static boolean S_KeepMusic(const char *mapmusicname) +{ + //if (!cv_keepmusic.value) + //return false; + + // should i compare songs or maps? + // comparing songs makes this alot easier honestly + static char oldmusname[7] = ""; + + if (strcmp(music_name, mapmusicname) != 0) + return false; + + if (strcmp(oldmusname, mapmusicname) == 0) + return true; + + strncpy(oldmusname, mapmusicname, 7); + oldmusname[6] = '\0'; + + return false; +} + /// ------------------------ /// Init & Others /// ------------------------ @@ -2169,6 +2191,16 @@ void S_Start(void) mapmusresume = 0; } + if (S_KeepMusic(mapmusname)) + return; + + /*if (cv_skipintromusic.value) + { + S_StopMusic(); + S_ChangeMusicEx(mapmusname, mapmusflags, true, mapmusposition, 0, 0); + return; + }*/ + S_StopMusic(); if (leveltime < (starttime + (TICRATE/2))) // SRB2Kart @@ -2178,7 +2210,21 @@ void S_Start(void) void M_Start(void) { - if (leveltime > (starttime + (TICRATE/2))) + // need to be after race starts so "certain" maps don´t break Zzz... + //ignoremusicchanges = cv_ignoremusicchanges.value && (leveltime > (starttime + (TICRATE/2))); + + //no need to constantly run this after race has started + //but let it run atleast half a tic after map music started to let shit update lmao + if (leveltime > (starttime + TICRATE)) + return; + + /*if (cv_skipintromusic.value && leveltime == (starttime + (TICRATE/2))) + { + S_ShowMusicCredit(); + return; + }*/ + + if (S_KeepMusic(mapmusname)) return; // The GO! sound stops the level start ambience @@ -2193,6 +2239,7 @@ void M_Start(void) } } + void S_RestartMusic(void) { S_StopMusic(); From e958e43b4976092932c2b1f85476ac2152ab5d52 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 30 Sep 2024 06:31:43 +0200 Subject: [PATCH 07/66] update comments a little --- src/s_sound.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/s_sound.c b/src/s_sound.c index a7845ce24..829a6a6da 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -2156,7 +2156,6 @@ static boolean S_KeepMusic(const char *mapmusicname) //return false; // should i compare songs or maps? - // comparing songs makes this alot easier honestly static char oldmusname[7] = ""; if (strcmp(music_name, mapmusicname) != 0) @@ -2201,6 +2200,8 @@ void S_Start(void) return; }*/ + // Starting ambience should always be restarted + // lug: but not when we keep the map music lol S_StopMusic(); if (leveltime < (starttime + (TICRATE/2))) // SRB2Kart From 07f9756bc83466d3163aa94c4a635532e8a4e91c Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 30 Sep 2024 06:38:29 +0200 Subject: [PATCH 08/66] forgor about encore music --- src/p_spec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/p_spec.c b/src/p_spec.c index 0fbd16ee4..8c1e9b5da 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -2127,7 +2127,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) break; case 413: // Change music - //if (ignoremusicchanges) + //if (ignoremusicchanges && (leveltime < (starttime + (TICRATE/2)))) //why check for starttime? cause encore music Zzz... //return; // console player only unless NOCLIMB is set From 42d957e21bcc876845d5887ce614647bd65db84c Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 30 Sep 2024 11:45:33 +0200 Subject: [PATCH 09/66] change how keepmusic works compare map and encore instead of the music itself --- src/g_game.c | 1 + src/s_sound.c | 47 ++++++++++++++++++++++++++++++++++++++++------- src/s_sound.h | 2 ++ 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index f6b7d562c..d4d358431 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -4368,6 +4368,7 @@ void G_InitNew(UINT8 pencoremode, const char *mapname, boolean resetplayer, bool else { LUAh_MapChange(gamemap); + S_KeepMusic(); G_DoLoadLevel(resetplayer); } diff --git a/src/s_sound.c b/src/s_sound.c index 829a6a6da..169dee2a0 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -2149,8 +2149,7 @@ boolean S_FadeOutStopMusic(UINT32 ms) return I_FadeSong(0, ms, &S_StopMusic); } - -static boolean S_KeepMusic(const char *mapmusicname) +/*static boolean S_KeepMusic(void) { //if (!cv_keepmusic.value) //return false; @@ -2158,16 +2157,50 @@ static boolean S_KeepMusic(const char *mapmusicname) // should i compare songs or maps? static char oldmusname[7] = ""; - if (strcmp(music_name, mapmusicname) != 0) + if (strcmp(music_name, mapmusname) != 0) return false; - if (strcmp(oldmusname, mapmusicname) == 0) + if (strcmp(oldmusname, mapmusname) == 0) return true; - strncpy(oldmusname, mapmusicname, 7); + strncpy(oldmusname, mapmusname, 7); oldmusname[6] = '\0'; return false; +}*/ + +static INT16 oldmap = 0; +static INT32 oldencore = 0; +static boolean keepmusic = false; + +void S_KeepMusic(void) +{ + //if (!cv_keepmusic.value) + //return false; + + //this one compares map and encoremode instead of the music itself + //makes tunes work and stuff + + keepmusic = false; + + //dont keep the intro "sound" lmao + if (strcmp(music_name, (encoremode ? "estart" : "kstart")) == 0) + return; + + if (oldencore != cv_kartencore.value) + { + oldencore = cv_kartencore.value; + return; + } + + // we on the same map? keep it + if (oldmap == gamemap) + { + keepmusic = true; + return; + } + + oldmap = gamemap; } /// ------------------------ @@ -2190,7 +2223,7 @@ void S_Start(void) mapmusresume = 0; } - if (S_KeepMusic(mapmusname)) + if (keepmusic) return; /*if (cv_skipintromusic.value) @@ -2225,7 +2258,7 @@ void M_Start(void) return; }*/ - if (S_KeepMusic(mapmusname)) + if (keepmusic) return; // The GO! sound stops the level start ambience diff --git a/src/s_sound.h b/src/s_sound.h index 75c59dbc8..687054ee1 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -103,6 +103,8 @@ void S_ClearSfx(void); void S_Start(void); void M_Start(void); +void S_KeepMusic(void); + // Stops music and restarts it from same position. Used for instant applying changes to amiga filters. void S_RestartMusic(void); From f363663b3ebbe8c7a752cfcd4324f000611d851a Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 30 Sep 2024 12:50:49 +0200 Subject: [PATCH 10/66] fix up everything and make stuff work i hope lmao --- src/p_spec.c | 16 +++++++++--- src/p_user.c | 4 +-- src/s_sound.c | 69 +++++++++++++++++++++++++-------------------------- src/s_sound.h | 7 ++++++ 4 files changed, 55 insertions(+), 41 deletions(-) diff --git a/src/p_spec.c b/src/p_spec.c index 8c1e9b5da..762540622 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -99,6 +99,8 @@ typedef struct thinker_t **thinkers; } thinkerlist_t; +static boolean fromlapexec = false; + static void P_SearchForDisableLinedefs(void); static void P_SpawnScrollers(void); static void P_SpawnFriction(void); @@ -1340,6 +1342,7 @@ boolean P_RunTriggerLinedef(line_t *triggerline, mobj_t *actor, sector_t *caller fixed_t dist = P_AproxDistance(triggerline->dx, triggerline->dy)>>FRACBITS; size_t i, linecnt, sectori; INT16 specialtype = triggerline->special; + fromlapexec = false; ///////////////////////////////////////////////// // Distance-checking/sector trigger conditions // @@ -1461,6 +1464,8 @@ boolean P_RunTriggerLinedef(line_t *triggerline, mobj_t *actor, sector_t *caller if (lap != (sides[triggerline->sidenum[0]].textureoffset >> FRACBITS)) return false; } + + fromlapexec = true; } // If we were not triggered by a sector type especially for the purpose, // a Linedef Executor linedef trigger is not handling sector triggers properly, return. @@ -2127,8 +2132,11 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) break; case 413: // Change music - //if (ignoremusicchanges && (leveltime < (starttime + (TICRATE/2)))) //why check for starttime? cause encore music Zzz... - //return; + if (keepmusic && (leveltime < (starttime + TICRATE))) //why check for starttime? cause encore music Zzz... + return; + + if (ignoremusicchanges && !fromlapexec) // keep lap music intanct tho + return; // console player only unless NOCLIMB is set if ((line->flags & ML_NOCLIMB) || (mo && mo->player && P_IsLocalPlayer(mo->player))) @@ -2213,8 +2221,8 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) INT32 sfxnum; //dont play any funky sound intros that may interfere with the music - //if (cv_skipintromusic.value && (leveltime < (starttime + (TICRATE/2)))) - //return; + if (cv_skipintromusic.value && (leveltime < (starttime + (TICRATE/2)))) + return; sfxnum = sides[line->sidenum[0]].toptexture; //P_AproxDistance(line->dx, line->dy)>>FRACBITS; diff --git a/src/p_user.c b/src/p_user.c index f5de9b704..093143e95 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -650,8 +650,8 @@ boolean P_EndingMusic(player_t *player) INT32 bestlocalpos; player_t *bestlocalplayer; - //if (!ignoremusicchanges) - //return false; + if (ignoremusicchanges) + return false; if (!P_IsLocalPlayer(player)) // Only applies to a local player return false; diff --git a/src/s_sound.c b/src/s_sound.c index 169dee2a0..0380a2788 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -117,6 +117,14 @@ consvar_t cv_resume = {"resume", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0 consvar_t cv_fading = {"fading", "Off", CV_SAVE|CV_CALL, CV_OnOff, Bird_menu_Onchange, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_birdmusic = {"birdmusicstuff", "No", CV_SAVE|CV_CALL, CV_YesNo, Bird_menu_Onchange, 0, NULL, NULL, 0, 0, NULL}; + +consvar_t cv_keepmusic = {"keepmusic", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_skipintromusic = {"skipintromusic", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; +consvar_t cv_ignoremusicchanges = {"ignoremusicchanges", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; + +boolean ignoremusicchanges = false; +boolean keepmusic = false; + #ifdef HAVE_OPENMPT openmpt_module *openmpt_mhandle = NULL; @@ -294,6 +302,10 @@ void S_RegisterSoundStuff(void) CV_RegisterVar(&cv_fading); CV_RegisterVar(&cv_birdmusic); + CV_RegisterVar(&cv_keepmusic); + CV_RegisterVar(&cv_skipintromusic); + CV_RegisterVar(&cv_ignoremusicchanges); + COM_AddCommand("tunes", Command_Tunes_f); COM_AddCommand("restartaudio", Command_RestartAudio_f); COM_AddCommand("restartmusic", Command_RestartMusic_f); @@ -2170,36 +2182,21 @@ boolean S_FadeOutStopMusic(UINT32 ms) }*/ static INT16 oldmap = 0; -static INT32 oldencore = 0; -static boolean keepmusic = false; +static boolean oldencore = 0; void S_KeepMusic(void) { - //if (!cv_keepmusic.value) - //return false; + if (!cv_keepmusic.value) + { + keepmusic = false; + return; + } //this one compares map and encoremode instead of the music itself //makes tunes work and stuff + keepmusic = (strcmp(music_name, (encoremode ? "estart" : "kstart")) != 0 && oldmap == gamemap && oldencore == encoremode); // we on the same map and intro sound aint playin? keep it - keepmusic = false; - - //dont keep the intro "sound" lmao - if (strcmp(music_name, (encoremode ? "estart" : "kstart")) == 0) - return; - - if (oldencore != cv_kartencore.value) - { - oldencore = cv_kartencore.value; - return; - } - - // we on the same map? keep it - if (oldmap == gamemap) - { - keepmusic = true; - return; - } - + oldencore = encoremode; oldmap = gamemap; } @@ -2226,18 +2223,18 @@ void S_Start(void) if (keepmusic) return; - /*if (cv_skipintromusic.value) + if (cv_skipintromusic.value) { S_StopMusic(); S_ChangeMusicEx(mapmusname, mapmusflags, true, mapmusposition, 0, 0); return; - }*/ + } // Starting ambience should always be restarted // lug: but not when we keep the map music lol S_StopMusic(); - if (leveltime < (starttime + (TICRATE/2))) // SRB2Kart + if (leveltime < starttime) // SRB2Kart S_ChangeMusicInternal((encoremode ? "estart" : "kstart"), false); //S_StopMusic(); //S_ChangeMusicEx((encoremode ? "estart" : "kstart"), 0, false, mapmusposition, 0, 0); } @@ -2245,28 +2242,30 @@ void S_Start(void) void M_Start(void) { // need to be after race starts so "certain" maps don´t break Zzz... - //ignoremusicchanges = cv_ignoremusicchanges.value && (leveltime > (starttime + (TICRATE/2))); + ignoremusicchanges = cv_ignoremusicchanges.value && (leveltime > (starttime + (TICRATE/2))); //no need to constantly run this after race has started //but let it run atleast half a tic after map music started to let shit update lmao if (leveltime > (starttime + TICRATE)) return; - /*if (cv_skipintromusic.value && leveltime == (starttime + (TICRATE/2))) - { - S_ShowMusicCredit(); - return; - }*/ - if (keepmusic) return; + if (cv_skipintromusic.value) + { + if (leveltime == (starttime + (TICRATE/2))) + S_ShowMusicCredit(); + return; + } + // The GO! sound stops the level start ambience if (leveltime == starttime) S_StopMusic(); - + else if (leveltime < starttime) // SRB2Kart + S_ChangeMusicInternal((encoremode ? "estart" : "kstart"), false); // Plays the music after the starting countdown. - if (leveltime == (starttime + (TICRATE/2))) + else if (leveltime == (starttime + (TICRATE/2))) { S_ChangeMusicEx(mapmusname, mapmusflags, true, mapmusposition, 0, 0); S_ShowMusicCredit(); diff --git a/src/s_sound.h b/src/s_sound.h index 687054ee1..2367d7729 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -67,6 +67,13 @@ extern consvar_t cv_resume; extern consvar_t cv_fading; extern consvar_t cv_birdmusic; +extern consvar_t cv_keepmusic; +extern consvar_t cv_skipintromusic; +extern consvar_t cv_ignoremusicchanges; + +extern boolean ignoremusicchanges; +extern boolean keepmusic; + extern consvar_t precachesound; typedef enum From b4b206f57565954f4bbd2b3074fe5c007d11cb56 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 30 Sep 2024 13:05:44 +0200 Subject: [PATCH 11/66] encoremusic... --- src/p_spec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/p_spec.c b/src/p_spec.c index 762540622..decea017d 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -2135,7 +2135,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) if (keepmusic && (leveltime < (starttime + TICRATE))) //why check for starttime? cause encore music Zzz... return; - if (ignoremusicchanges && !fromlapexec) // keep lap music intanct tho + if (ignoremusicchanges && (leveltime < (starttime + TICRATE) && !fromlapexec)) // keep lap music intanct tho return; // console player only unless NOCLIMB is set From 7fa21e9aeaee811a8b6b11a0943448ef2fd3c566 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 30 Sep 2024 15:41:19 +0200 Subject: [PATCH 12/66] work around custom vote theme music + rename a bunch of stuff please help me --- src/g_game.c | 2 +- src/k_kart.c | 4 ++-- src/p_setup.c | 2 +- src/p_spec.c | 6 +++--- src/s_sound.c | 60 +++++++++++++++++++++++++++++++++++++++++---------- src/s_sound.h | 7 +++--- 6 files changed, 60 insertions(+), 21 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index d4d358431..29e65a002 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -4368,7 +4368,7 @@ void G_InitNew(UINT8 pencoremode, const char *mapname, boolean resetplayer, bool else { LUAh_MapChange(gamemap); - S_KeepMusic(); + S_CheckMap(); G_DoLoadLevel(resetplayer); } diff --git a/src/k_kart.c b/src/k_kart.c index fcb373782..1a586943f 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -5360,9 +5360,9 @@ void K_KartPlayerThink(player_t *player, ticcmd_t *cmd) // Handle invincibility sfx K_UpdateInvincibilitySounds(player); // Also thanks, VAda! - // Plays the music after the starting countdown. + // Plays the music during and after the starting countdown. if (P_IsLocalPlayer(player)) - M_Start(); + S_StartMapMusic(); } void K_KartPlayerAfterThink(player_t *player) diff --git a/src/p_setup.c b/src/p_setup.c index 17d050dc4..672b1b347 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -2683,7 +2683,7 @@ boolean P_SetupLevel(boolean skipprecip, boolean reloadinggamestate) // As oddly named as this is, this handles music only. // We should be fine starting it here. if (!reloadinggamestate) - S_Start(); + S_InitMapMusic(); levelfadecol = (encoremode && !ranspecialwipe ? 122 : 120); diff --git a/src/p_spec.c b/src/p_spec.c index decea017d..058fe9413 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -2118,12 +2118,12 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) return; if (bot) - P_Teleport(bot, dest->x, dest->y, dest->z, (line->flags & ML_NOCLIMB) ? mo->angle : dest->angle, (line->flags & ML_BLOCKMONSTERS) == 0, (line->flags & ML_EFFECT4) == ML_EFFECT4); + P_Teleport(bot, dest->x, dest->y, dest->z, (line->flags & ML_NOCLIMB) ? mo->angle : dest->angle, (line->flags & ML_BLOCKMONSTERS) == 0, (line->flags & ML_EFFECT4) == ML_EFFECT4); if (line->flags & ML_BLOCKMONSTERS) - P_Teleport(mo, dest->x, dest->y, dest->z, (line->flags & ML_NOCLIMB) ? mo->angle : dest->angle, false, (line->flags & ML_EFFECT4) == ML_EFFECT4); + P_Teleport(mo, dest->x, dest->y, dest->z, (line->flags & ML_NOCLIMB) ? mo->angle : dest->angle, false, (line->flags & ML_EFFECT4) == ML_EFFECT4); else { - P_Teleport(mo, dest->x, dest->y, dest->z, (line->flags & ML_NOCLIMB) ? mo->angle : dest->angle, true, (line->flags & ML_EFFECT4) == ML_EFFECT4); + P_Teleport(mo, dest->x, dest->y, dest->z, (line->flags & ML_NOCLIMB) ? mo->angle : dest->angle, true, (line->flags & ML_EFFECT4) == ML_EFFECT4); // Play the 'bowrwoosh!' sound S_StartSound(dest, sfx_mixup); } diff --git a/src/s_sound.c b/src/s_sound.c index 0380a2788..f8b0619eb 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -11,6 +11,7 @@ /// \file s_sound.c /// \brief System-independent sound and music routines +#include "d_netcmd.h" #include "doomdef.h" #include "doomstat.h" #include "command.h" @@ -124,6 +125,7 @@ consvar_t cv_ignoremusicchanges = {"ignoremusicchanges", "No", CV_SAVE, CV_YesNo boolean ignoremusicchanges = false; boolean keepmusic = false; +static void S_CheckEventMus(const char *newmus); #ifdef HAVE_OPENMPT openmpt_module *openmpt_mhandle = NULL; @@ -1973,6 +1975,8 @@ void S_ChangeMusicEx(const char *mmusic, UINT16 mflags, boolean looping, UINT32 strncpy(newmusic, mmusic, 6); + S_CheckEventMus(newmusic); + if (LUAh_MusicChange(music_name, newmusic, &mflags, &looping, &position, &prefadems, &fadeinms)) return; @@ -2161,6 +2165,10 @@ boolean S_FadeOutStopMusic(UINT32 ms) return I_FadeSong(0, ms, &S_StopMusic); } +/// ------------------------ +/// Init & Others +/// ------------------------ + /*static boolean S_KeepMusic(void) { //if (!cv_keepmusic.value) @@ -2183,8 +2191,45 @@ boolean S_FadeOutStopMusic(UINT32 ms) static INT16 oldmap = 0; static boolean oldencore = 0; +static boolean skipmusic = false; -void S_KeepMusic(void) +static const char *musicexception_list[16] = { + "vote", "voteea", "voteeb", "racent", "krwin", + "krok", "krlose", "krfail", "kbwin", "kbok", + "kblose", "kstart", "estart", "wait2j", "CHRSHP", + "CHRSHF" +}; + +//checks for any kind of event music like intermission, vote etc. +//always runs when musicchange gets invoked +static void S_CheckEventMus(const char *newmus) +{ + //if (leveltime > (starttime + (TICRATE/2))) + //return; + + skipmusic = false; + + if (!cv_keepmusic.value) + { + return; + } + + //this one compares map and encoremode instead of the music itself + //makes tunes work and stuff + for (int i = 0; i < 16; i++) + if (strcmp(music_name, musicexception_list[i]) == 0 || strcmp(newmus, musicexception_list[i]) == 0) + { + skipmusic = true; + break; + } + + //CONS_Printf("musname = %s\n", music_name); + //CONS_Printf("newmus = %s\n", newmus); + //CONS_Printf("newmus = %d\n", skipmusic); +} + +//check if map and encoremode has changed +void S_CheckMap(void) { if (!cv_keepmusic.value) { @@ -2192,24 +2237,18 @@ void S_KeepMusic(void) return; } - //this one compares map and encoremode instead of the music itself - //makes tunes work and stuff - keepmusic = (strcmp(music_name, (encoremode ? "estart" : "kstart")) != 0 && oldmap == gamemap && oldencore == encoremode); // we on the same map and intro sound aint playin? keep it + keepmusic = (!skipmusic && oldmap == gamemap && oldencore == encoremode); oldencore = encoremode; oldmap = gamemap; } -/// ------------------------ -/// Init & Others -/// ------------------------ - // // Per level startup code. // Kills playing sounds at start of level, // determines music if any, changes music. // -void S_Start(void) +void S_InitMapMusic(void) { if (mapmusflags & MUSIC_RELOADRESET) { @@ -2239,7 +2278,7 @@ void S_Start(void) //S_ChangeMusicEx((encoremode ? "estart" : "kstart"), 0, false, mapmusposition, 0, 0); } -void M_Start(void) +void S_StartMapMusic(void) { // need to be after race starts so "certain" maps don´t break Zzz... ignoremusicchanges = cv_ignoremusicchanges.value && (leveltime > (starttime + (TICRATE/2))); @@ -2272,7 +2311,6 @@ void M_Start(void) } } - void S_RestartMusic(void) { S_StopMusic(); diff --git a/src/s_sound.h b/src/s_sound.h index 2367d7729..0c576bfc1 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -107,10 +107,11 @@ void S_InitSfxChannels(INT32 sfxVolume); // void S_StopSounds(void); void S_ClearSfx(void); -void S_Start(void); -void M_Start(void); -void S_KeepMusic(void); +void S_InitMapMusic(void); +void S_StartMapMusic(void); + +void S_CheckMap(void); // Stops music and restarts it from same position. Used for instant applying changes to amiga filters. void S_RestartMusic(void); From 2ee29630fb3b30868ee73a3e63bdf0c827e094f4 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 30 Sep 2024 16:19:54 +0200 Subject: [PATCH 13/66] fix encore music again lol --- src/p_spec.c | 2 +- src/p_user.c | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/src/p_spec.c b/src/p_spec.c index 058fe9413..f09562f4d 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -2135,7 +2135,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) if (keepmusic && (leveltime < (starttime + TICRATE))) //why check for starttime? cause encore music Zzz... return; - if (ignoremusicchanges && (leveltime < (starttime + TICRATE) && !fromlapexec)) // keep lap music intanct tho + if (ignoremusicchanges && (leveltime > (starttime + TICRATE) && !fromlapexec)) // keep lap music intanct tho return; // console player only unless NOCLIMB is set diff --git a/src/p_user.c b/src/p_user.c index 093143e95..a6e4791e6 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -650,9 +650,6 @@ boolean P_EndingMusic(player_t *player) INT32 bestlocalpos; player_t *bestlocalplayer; - if (ignoremusicchanges) - return false; - if (!P_IsLocalPlayer(player)) // Only applies to a local player return false; From 67435ebf9ee9384abacc53c5c4d7fccf6f851f0b Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 30 Sep 2024 16:27:56 +0200 Subject: [PATCH 14/66] work around encore music again S_InitMapMusic would play before the level actually started thus playing a smol bit of non encore music in encore --- src/s_sound.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/s_sound.c b/src/s_sound.c index f8b0619eb..2970bce63 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -2262,17 +2262,13 @@ void S_InitMapMusic(void) if (keepmusic) return; - if (cv_skipintromusic.value) - { - S_StopMusic(); - S_ChangeMusicEx(mapmusname, mapmusflags, true, mapmusposition, 0, 0); - return; - } - // Starting ambience should always be restarted // lug: but not when we keep the map music lol S_StopMusic(); + if (cv_skipintromusic.value) + return; + if (leveltime < starttime) // SRB2Kart S_ChangeMusicInternal((encoremode ? "estart" : "kstart"), false); //S_StopMusic(); //S_ChangeMusicEx((encoremode ? "estart" : "kstart"), 0, false, mapmusposition, 0, 0); @@ -2293,6 +2289,8 @@ void S_StartMapMusic(void) if (cv_skipintromusic.value) { + if (leveltime == 0) + S_ChangeMusicEx(mapmusname, mapmusflags, true, mapmusposition, 0, 0); if (leveltime == (starttime + (TICRATE/2))) S_ShowMusicCredit(); return; From d06b8ac398d7fad39f9175ece8b79ca54e1925d6 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 30 Sep 2024 16:32:03 +0200 Subject: [PATCH 15/66] cleanup + comments --- src/p_spec.c | 2 +- src/s_sound.c | 23 +++++++---------------- src/s_sound.h | 2 -- 3 files changed, 8 insertions(+), 19 deletions(-) diff --git a/src/p_spec.c b/src/p_spec.c index f09562f4d..e7d937a91 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -2135,7 +2135,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) if (keepmusic && (leveltime < (starttime + TICRATE))) //why check for starttime? cause encore music Zzz... return; - if (ignoremusicchanges && (leveltime > (starttime + TICRATE) && !fromlapexec)) // keep lap music intanct tho + if (cv_ignoremusicchanges.value && (leveltime > (starttime + TICRATE) && !fromlapexec)) // keep lap music intanct tho return; // console player only unless NOCLIMB is set diff --git a/src/s_sound.c b/src/s_sound.c index 2970bce63..4ac8a9860 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -123,7 +123,6 @@ consvar_t cv_keepmusic = {"keepmusic", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, N consvar_t cv_skipintromusic = {"skipintromusic", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_ignoremusicchanges = {"ignoremusicchanges", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; -boolean ignoremusicchanges = false; boolean keepmusic = false; static void S_CheckEventMus(const char *newmus); @@ -2204,9 +2203,6 @@ static const char *musicexception_list[16] = { //always runs when musicchange gets invoked static void S_CheckEventMus(const char *newmus) { - //if (leveltime > (starttime + (TICRATE/2))) - //return; - skipmusic = false; if (!cv_keepmusic.value) @@ -2214,8 +2210,7 @@ static void S_CheckEventMus(const char *newmus) return; } - //this one compares map and encoremode instead of the music itself - //makes tunes work and stuff + for (int i = 0; i < 16; i++) if (strcmp(music_name, musicexception_list[i]) == 0 || strcmp(newmus, musicexception_list[i]) == 0) { @@ -2228,7 +2223,8 @@ static void S_CheckEventMus(const char *newmus) //CONS_Printf("newmus = %d\n", skipmusic); } -//check if map and encoremode has changed +//this one compares map and encoremode instead of the music itself +//makes tunes work and stuff void S_CheckMap(void) { if (!cv_keepmusic.value) @@ -2276,9 +2272,6 @@ void S_InitMapMusic(void) void S_StartMapMusic(void) { - // need to be after race starts so "certain" maps don´t break Zzz... - ignoremusicchanges = cv_ignoremusicchanges.value && (leveltime > (starttime + (TICRATE/2))); - //no need to constantly run this after race has started //but let it run atleast half a tic after map music started to let shit update lmao if (leveltime > (starttime + TICRATE)) @@ -2289,20 +2282,18 @@ void S_StartMapMusic(void) if (cv_skipintromusic.value) { - if (leveltime == 0) + if (leveltime == 0) // dumb but i dont need this to be spammed honestly S_ChangeMusicEx(mapmusname, mapmusflags, true, mapmusposition, 0, 0); if (leveltime == (starttime + (TICRATE/2))) S_ShowMusicCredit(); return; } - // The GO! sound stops the level start ambience - if (leveltime == starttime) + if (leveltime == starttime) // The GO! sound stops the level start ambience S_StopMusic(); else if (leveltime < starttime) // SRB2Kart - S_ChangeMusicInternal((encoremode ? "estart" : "kstart"), false); - // Plays the music after the starting countdown. - else if (leveltime == (starttime + (TICRATE/2))) + S_ChangeMusicInternal((encoremode ? "estart" : "kstart"), false); // yes this will be spammed otherwise encore and some stuff WILL overwrite it + else if (leveltime == (starttime + (TICRATE/2))) // Plays the music after the starting countdown. { S_ChangeMusicEx(mapmusname, mapmusflags, true, mapmusposition, 0, 0); S_ShowMusicCredit(); diff --git a/src/s_sound.h b/src/s_sound.h index 0c576bfc1..9d53cc357 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -70,8 +70,6 @@ extern consvar_t cv_birdmusic; extern consvar_t cv_keepmusic; extern consvar_t cv_skipintromusic; extern consvar_t cv_ignoremusicchanges; - -extern boolean ignoremusicchanges; extern boolean keepmusic; extern consvar_t precachesound; From 6b0d67ac36746398f4d840607598fd12429a5404 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 30 Sep 2024 16:33:29 +0200 Subject: [PATCH 16/66] more --- src/s_sound.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/s_sound.c b/src/s_sound.c index 4ac8a9860..33767a885 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -2210,9 +2210,8 @@ static void S_CheckEventMus(const char *newmus) return; } - for (int i = 0; i < 16; i++) - if (strcmp(music_name, musicexception_list[i]) == 0 || strcmp(newmus, musicexception_list[i]) == 0) + if (strcmp(music_name, musicexception_list[i]) == 0 || strcmp(newmus, musicexception_list[i]) == 0) // weird? sure! but were lucky enough newmus reflects whats being replaced { skipmusic = true; break; From 3a951576ee498641a0b46e3193e298984c88ada9 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 1 Oct 2024 14:42:20 +0200 Subject: [PATCH 17/66] use stricmp for this --- src/s_sound.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/s_sound.c b/src/s_sound.c index 33767a885..0eedb57ec 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -2206,12 +2206,10 @@ static void S_CheckEventMus(const char *newmus) skipmusic = false; if (!cv_keepmusic.value) - { return; - } for (int i = 0; i < 16; i++) - if (strcmp(music_name, musicexception_list[i]) == 0 || strcmp(newmus, musicexception_list[i]) == 0) // weird? sure! but were lucky enough newmus reflects whats being replaced + if (stricmp(music_name, musicexception_list[i]) == 0 || stricmp(newmus, musicexception_list[i]) == 0) // weird? sure! but were lucky enough newmus reflects whats being replaced { skipmusic = true; break; From 3db6770dfdd650f796f8f46b836067512ce5fa30 Mon Sep 17 00:00:00 2001 From: Indev Date: Tue, 1 Oct 2024 16:24:14 +0300 Subject: [PATCH 18/66] Fix IT_CV_STRING crashing game in M_DrawGenericMenu --- src/m_menu.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index cc8bf39a6..30d0ee0b2 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -5151,10 +5151,12 @@ static void M_DrawGenericMenu(void) break; case IT_CV_STRING: M_DrawTextBox(x, y + 4, MAXSTRINGLENGTH, 1); - V_DrawString(x + 8, y + 12, V_ALLOWLOWERCASE, menuinput.buffer); - if (skullAnimCounter < 4 && i == itemOn) - V_DrawCharacter(x + 8 + V_StringWidth(cv->string, 0), y + 12, - '_' | 0x80, false); + + if (itemOn == i) + M_DrawTextInput(x + 8, y + 12, &menuinput, 0); + else + V_DrawString(x + 8, y + 12, V_ALLOWLOWERCASE, cv->string); + y += 16; break; default: From 9abf2bca75bd5f938f7de44aaa1ee1bbd21e57b7 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 1 Oct 2024 15:46:09 +0200 Subject: [PATCH 19/66] fix some stuff --- src/p_spec.c | 6 +++--- src/p_user.c | 4 +++- src/s_sound.c | 17 ++++++++--------- src/s_sound.h | 1 + 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/src/p_spec.c b/src/p_spec.c index e7d937a91..6146f422a 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -2132,10 +2132,10 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) break; case 413: // Change music - if (keepmusic && (leveltime < (starttime + TICRATE))) //why check for starttime? cause encore music Zzz... + if (keepmusic && (leveltime <= MUSICSTARTTIME)) //why check for starttime? cause encore music Zzz... return; - if (cv_ignoremusicchanges.value && (leveltime > (starttime + TICRATE) && !fromlapexec)) // keep lap music intanct tho + if (cv_ignoremusicchanges.value && (leveltime >= MUSICSTARTTIME) && !fromlapexec) // keep lap music intanct tho return; // console player only unless NOCLIMB is set @@ -2221,7 +2221,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) INT32 sfxnum; //dont play any funky sound intros that may interfere with the music - if (cv_skipintromusic.value && (leveltime < (starttime + (TICRATE/2)))) + if (cv_skipintromusic.value && (leveltime < MUSICSTARTTIME)) return; sfxnum = sides[line->sidenum[0]].toptexture; //P_AproxDistance(line->dx, line->dy)>>FRACBITS; diff --git a/src/p_user.c b/src/p_user.c index a6e4791e6..ac1537eb0 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -742,7 +742,9 @@ void P_RestoreMusic(player_t *player) if (P_EndingMusic(player)) return; - if (leveltime > (starttime + (TICRATE/2))) + if (leveltime < MUSICSTARTTIME) + S_StartMapMusic(); + else // see also where time overs are handled - search for "lives = 2" in this file { INT32 wantedmus = 0; // 0 is level music, 1 is invincibility, 2 is grow diff --git a/src/s_sound.c b/src/s_sound.c index 0eedb57ec..7aab19db9 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -2262,7 +2262,7 @@ void S_InitMapMusic(void) if (cv_skipintromusic.value) return; - if (leveltime < starttime) // SRB2Kart + if (leveltime < MUSICSTARTTIME) // SRB2Kart S_ChangeMusicInternal((encoremode ? "estart" : "kstart"), false); //S_StopMusic(); //S_ChangeMusicEx((encoremode ? "estart" : "kstart"), 0, false, mapmusposition, 0, 0); } @@ -2270,8 +2270,7 @@ void S_InitMapMusic(void) void S_StartMapMusic(void) { //no need to constantly run this after race has started - //but let it run atleast half a tic after map music started to let shit update lmao - if (leveltime > (starttime + TICRATE)) + if (leveltime > MUSICSTARTTIME) return; if (keepmusic) @@ -2279,18 +2278,18 @@ void S_StartMapMusic(void) if (cv_skipintromusic.value) { - if (leveltime == 0) // dumb but i dont need this to be spammed honestly + if (leveltime < starttime) // dumb but i dont need this to be spammed honestly S_ChangeMusicEx(mapmusname, mapmusflags, true, mapmusposition, 0, 0); - if (leveltime == (starttime + (TICRATE/2))) + if (leveltime == MUSICSTARTTIME) S_ShowMusicCredit(); return; } - if (leveltime == starttime) // The GO! sound stops the level start ambience - S_StopMusic(); - else if (leveltime < starttime) // SRB2Kart + if (leveltime < starttime) // SRB2Kart S_ChangeMusicInternal((encoremode ? "estart" : "kstart"), false); // yes this will be spammed otherwise encore and some stuff WILL overwrite it - else if (leveltime == (starttime + (TICRATE/2))) // Plays the music after the starting countdown. + else if (leveltime == starttime) // The GO! sound stops the level start ambience + S_StopMusic(); + else if (leveltime == MUSICSTARTTIME) // Plays the music after the starting countdown. { S_ChangeMusicEx(mapmusname, mapmusflags, true, mapmusposition, 0, 0); S_ShowMusicCredit(); diff --git a/src/s_sound.h b/src/s_sound.h index 9d53cc357..39b61b49d 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -71,6 +71,7 @@ extern consvar_t cv_keepmusic; extern consvar_t cv_skipintromusic; extern consvar_t cv_ignoremusicchanges; extern boolean keepmusic; +#define MUSICSTARTTIME (starttime + (TICRATE/2)) extern consvar_t precachesound; From a90ffff320a109a9fecae6f2f31502d50d65c5c0 Mon Sep 17 00:00:00 2001 From: Indev Date: Tue, 1 Oct 2024 16:49:59 +0300 Subject: [PATCH 20/66] Fix (hopefully) all other menu types that use IT_CV_STRING --- src/m_menu.c | 71 ++++++++++++++++++++++++++++++++++------------------ 1 file changed, 46 insertions(+), 25 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 30d0ee0b2..da58348d8 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -3532,18 +3532,9 @@ static void M_ResetCvars(void) } } -static void M_NextOpt(void) +// If current menu item is IT_CV_STRING, setup menuinput +static void M_CheckStringItem(void) { - INT16 oldItemOn = itemOn; // prevent infinite loop - - do - { - if (itemOn + 1 > currentMenu->numitems - 1) - itemOn = 0; - else - itemOn++; - } while (oldItemOn != itemOn && (currentMenu->menuitems[itemOn].status & IT_TYPE) == IT_SPACE); - if (itemOn < currentMenu->numitems && (currentMenu->menuitems[itemOn].status & IT_CVARTYPE) == IT_CV_STRING) { consvar_t *cv = (consvar_t *)currentMenu->menuitems[itemOn].itemaction; @@ -3558,6 +3549,21 @@ static void M_NextOpt(void) } } +static void M_NextOpt(void) +{ + INT16 oldItemOn = itemOn; // prevent infinite loop + + do + { + if (itemOn + 1 > currentMenu->numitems - 1) + itemOn = 0; + else + itemOn++; + } while (oldItemOn != itemOn && (currentMenu->menuitems[itemOn].status & IT_TYPE) == IT_SPACE); + + M_CheckStringItem(); +} + static void M_PrevOpt(void) { INT16 oldItemOn = itemOn; // prevent infinite loop @@ -3569,6 +3575,8 @@ static void M_PrevOpt(void) else itemOn--; } while (oldItemOn != itemOn && (currentMenu->menuitems[itemOn].status & IT_TYPE) == IT_SPACE); + + M_CheckStringItem(); } // lock out further input in a tic when important buttons are pressed @@ -4589,6 +4597,8 @@ void M_SetupNextMenu(menu_t *menudef) } } } + + M_CheckStringItem(); } // @@ -4930,11 +4940,16 @@ void M_DrawTextBoxFlags(INT32 x, INT32 y, INT32 width, INT32 boxlines, INT32 fla void M_DrawTextInput(INT32 x, INT32 y, textinput_t *input, INT32 flags) { + INT32 skullx = x; + V_DrawString(x, y, V_ALLOWLOWERCASE|flags, input->buffer); // draw text cursor for name - if (input->length && skullAnimCounter < 4) // blink cursor - V_DrawCharacter(x+V_SubStringWidth(input->buffer, input->cursor, V_ALLOWLOWERCASE), y+3, '_'|flags, false); + if (input->length) + skullx = x+V_SubStringWidth(input->buffer, input->cursor, V_ALLOWLOWERCASE); + + if (skullAnimCounter < 4) // blink cursor + V_DrawCharacter(skullx, y+3, '_'|flags, false); // draw selection if (input->select != input->cursor) @@ -5340,10 +5355,12 @@ static void M_DrawGenericScrollMenu(void) if (y + 12 > (currentMenu->y + 2*scrollareaheight)) break; M_DrawTextBox(x, y + 4, MAXSTRINGLENGTH, 1); - V_DrawString(x + 8, y + 12, lowercase, cv->string); - if (skullAnimCounter < 4 && i == itemOn) - V_DrawCharacter(x + 8 + V_StringWidth(cv->string, 0), y + 12, - '_' | 0x80, false); + + if (itemOn == i) + M_DrawTextInput(x + 8, y + 12, &menuinput, 0); + else + V_DrawString(x + 8, y + 12, lowercase, cv->string); + break; default: V_DrawRightAlignedString(BASEVIDWIDTH - x, y, @@ -5479,10 +5496,12 @@ static void M_DrawCenteredMenu(void) break; case IT_CV_STRING: M_DrawTextBox(x, y + 4, MAXSTRINGLENGTH, 1); - V_DrawString(x + 8, y + 12, V_ALLOWLOWERCASE, cv->string); - if (skullAnimCounter < 4 && i == itemOn) - V_DrawCharacter(x + 8 + V_StringWidth(cv->string, 0), y + 12, - '_' | 0x80, false); + + if (itemOn == i) + M_DrawTextInput(x + 8, y + 12, &menuinput, 0); + else + V_DrawString(x + 8, y + 12, V_ALLOWLOWERCASE, cv->string); + y += 16; break; default: @@ -12866,10 +12885,12 @@ static void M_DrawColorMenu(void) if (y + 12 > (currentMenu->y + 2*scrollareaheight)) break; M_DrawTextBox(x, y + 4, MAXSTRINGLENGTH, 1); - V_DrawString(x + 8, y + 12, V_ALLOWLOWERCASE, cv->string); - if (skullAnimCounter < 4 && i == itemOn) - V_DrawCharacter(x + 8 + V_StringWidth(cv->string, 0), y + 12, - '_' | 0x80, false); + + if (itemOn == i) + M_DrawTextInput(x + 8, y + 12, &menuinput, 0); + else + V_DrawString(x + 8, y + 12, V_ALLOWLOWERCASE, cv->string); + y += 16; break; default: From fb71da3627d9a9becaf10e1bf16e57fb49d3b5c0 Mon Sep 17 00:00:00 2001 From: Indev Date: Tue, 1 Oct 2024 16:50:44 +0300 Subject: [PATCH 21/66] Remove debug print --- src/m_menu.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index da58348d8..355be3cd2 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -3544,8 +3544,6 @@ static void M_CheckStringItem(void) M_TextInputInit(&menuinput, menu_text_input_buf, sizeof menu_text_input_buf); M_TextInputSetString(&menuinput, cv->string); - - CONS_Printf("Set input string to %s\n", cv->string); } } From 12d65460622c58745d5add88254d74f7705d6776 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 1 Oct 2024 16:02:39 +0200 Subject: [PATCH 22/66] dumb special case for wandering balls Zzz... --- src/p_spec.c | 2 +- src/s_sound.c | 7 +++++-- src/s_sound.h | 1 + 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/p_spec.c b/src/p_spec.c index 6146f422a..dc7743446 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -2221,7 +2221,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) INT32 sfxnum; //dont play any funky sound intros that may interfere with the music - if (cv_skipintromusic.value && (leveltime < MUSICSTARTTIME)) + if (skipintromus && (leveltime < MUSICSTARTTIME)) return; sfxnum = sides[line->sidenum[0]].toptexture; //P_AproxDistance(line->dx, line->dy)>>FRACBITS; diff --git a/src/s_sound.c b/src/s_sound.c index 7aab19db9..8728db343 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -2191,6 +2191,7 @@ boolean S_FadeOutStopMusic(UINT32 ms) static INT16 oldmap = 0; static boolean oldencore = 0; static boolean skipmusic = false; +boolean skipintromus = false; static const char *musicexception_list[16] = { "vote", "voteea", "voteeb", "racent", "krwin", @@ -2243,6 +2244,8 @@ void S_CheckMap(void) // void S_InitMapMusic(void) { + skipintromus = cv_skipintromusic.value && stricmp(G_BuildMapTitle(gamemap), "Wandering Falls") != 0; + if (mapmusflags & MUSIC_RELOADRESET) { strncpy(mapmusname, mapheaderinfo[gamemap-1]->musname, 7); @@ -2259,7 +2262,7 @@ void S_InitMapMusic(void) // lug: but not when we keep the map music lol S_StopMusic(); - if (cv_skipintromusic.value) + if (skipintromus) return; if (leveltime < MUSICSTARTTIME) // SRB2Kart @@ -2276,7 +2279,7 @@ void S_StartMapMusic(void) if (keepmusic) return; - if (cv_skipintromusic.value) + if (skipintromus) { if (leveltime < starttime) // dumb but i dont need this to be spammed honestly S_ChangeMusicEx(mapmusname, mapmusflags, true, mapmusposition, 0, 0); diff --git a/src/s_sound.h b/src/s_sound.h index 39b61b49d..e31040eac 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -71,6 +71,7 @@ extern consvar_t cv_keepmusic; extern consvar_t cv_skipintromusic; extern consvar_t cv_ignoremusicchanges; extern boolean keepmusic; +extern boolean skipintromus; #define MUSICSTARTTIME (starttime + (TICRATE/2)) extern consvar_t precachesound; From b985ce06a2b36bf2689cde4dae58cc14faa4f6e6 Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 1 Oct 2024 16:03:48 +0200 Subject: [PATCH 23/66] lol --- src/s_sound.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/s_sound.c b/src/s_sound.c index 8728db343..7505c622e 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -2244,7 +2244,7 @@ void S_CheckMap(void) // void S_InitMapMusic(void) { - skipintromus = cv_skipintromusic.value && stricmp(G_BuildMapTitle(gamemap), "Wandering Falls") != 0; + skipintromus = cv_skipintromusic.value && stricmp(G_BuildMapTitle(gamemap), "Wandering Falls") != 0; // thanks diggle! if (mapmusflags & MUSIC_RELOADRESET) { From bdb39fcd8d29d5e3fd8043f61952b9db05f740bb Mon Sep 17 00:00:00 2001 From: Alug Date: Tue, 1 Oct 2024 17:57:45 +0200 Subject: [PATCH 24/66] dont leak pls --- src/s_sound.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/s_sound.c b/src/s_sound.c index 7505c622e..aa266c5a1 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -2244,7 +2244,10 @@ void S_CheckMap(void) // void S_InitMapMusic(void) { - skipintromus = cv_skipintromusic.value && stricmp(G_BuildMapTitle(gamemap), "Wandering Falls") != 0; // thanks diggle! + char *maptitle = G_BuildMapTitle(gamemap); + skipintromus = cv_skipintromusic.value && stricmp(maptitle, "Wandering Falls") != 0; // thanks diggle! + if (maptitle) + Z_Free(maptitle); if (mapmusflags & MUSIC_RELOADRESET) { From 2e8769496f20806949d2faa22cb4911a274339e0 Mon Sep 17 00:00:00 2001 From: Indev Date: Tue, 1 Oct 2024 20:39:04 +0300 Subject: [PATCH 25/66] Use textinput_t for replay save prompt too --- src/g_game.c | 36 +++++++++---------------- src/g_game.h | 2 ++ src/st_stuff.c | 73 +++++++++++++++++++++++++++++++++++++++++++------- src/v_video.c | 39 +++++++++++++++++++++++++++ src/v_video.h | 3 +++ 5 files changed, 119 insertions(+), 34 deletions(-) diff --git a/src/g_game.c b/src/g_game.c index 8311d7cbc..709a34415 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -6368,8 +6368,18 @@ void G_BeginRecording(void) // Full replay title demo_p += 64; { + char demotitlename[65]; char *title = G_BuildMapTitle(gamemap); - snprintf(demo.titlename, 64, "%s - %s", title, modeattacking ? "Time Attack" : connectedservername); + + // Print to a separate temp buffer instead of demo.titlename, so we can use it in M_TextInputSetString + snprintf(demotitlename, 64, "%s - %s", title, modeattacking ? "Time Attack" : connectedservername); + + // Init just in case it isn't initialized already + M_TextInputInit(&demo.titlenameinput, demo.titlename, sizeof(demo.titlename)); + + // This will indirectly assign to demo.titlename too + M_TextInputSetString(&demo.titlenameinput, demotitlename); + Z_Free(title); } @@ -8359,7 +8369,6 @@ void G_SaveDemo(void) boolean G_DemoTitleResponder(event_t *ev) { - size_t len; INT32 ch; if (ev->type != ev_keydown) @@ -8380,28 +8389,7 @@ boolean G_DemoTitleResponder(event_t *ev) return true; } - if ((ch >= HU_FONTSTART && ch <= HU_FONTEND && hu_font[ch-HU_FONTSTART]) - || ch == ' ') // Allow spaces, of course - { - len = strlen(demo.titlename); - if (len < 64) - { - demo.titlename[len+1] = 0; - demo.titlename[len] = cv_keyboardlayout.value == 3 ? CON_ShitAndAltGrChar(ch) : CON_ShiftChar(ch); - } - } - else if (ch == KEY_BACKSPACE) - { - if (shiftdown) - memset(demo.titlename, 0, sizeof(demo.titlename)); - else - { - len = strlen(demo.titlename); - - if (len > 0) - demo.titlename[len-1] = 0; - } - } + M_TextInputHandle(&demo.titlenameinput, ch); return true; } diff --git a/src/g_game.h b/src/g_game.h index 14decd858..aaafa233c 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -17,6 +17,7 @@ #include "doomdef.h" #include "doomstat.h" #include "d_event.h" +#include "m_textinput.h" extern char gamedatafilename[64]; extern char timeattackfolder[64]; @@ -44,6 +45,7 @@ extern consvar_t cv_recordmultiplayerdemos, cv_netdemosyncquality, cv_maxdemosiz // Publicly-accessible demo vars struct demovars_s { char titlename[65]; + textinput_t titlenameinput; boolean recording, playback, timing; UINT16 version; // Current file format of the demo being played boolean title; // Title Screen demo can be cancelled by any key diff --git a/src/st_stuff.c b/src/st_stuff.c index aa5e07ed6..83222e64f 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -808,25 +808,78 @@ static void ST_overlayDrawer(void) } } -void ST_DrawDemoTitleEntry(void) +static void ST_DrawTextInput(INT32 x, INT32 y, textinput_t *input, INT32 flags) { static UINT8 skullAnimCounter = 0; - char *nametodraw; + static const INT32 MAXINPUTWIDTH = (MAXSTRINGLENGTH-1)*8; - skullAnimCounter++; + if (renderisnewtic) + skullAnimCounter++; skullAnimCounter %= 8; - nametodraw = demo.titlename; - while (V_StringWidth(nametodraw, 0) > MAXSTRINGLENGTH*8 - 8) - nametodraw++; + char nametodraw[MAXSTRINGLENGTH*2+1] = {0}; + size_t drawstart = 0; + + INT32 skullx = x; + + while (V_SubStringWidth(input->buffer+drawstart, input->cursor-drawstart, V_ALLOWLOWERCASE) > MAXINPUTWIDTH) + ++drawstart; + + memcpy(nametodraw, input->buffer+drawstart, V_SubStringLengthToFit(input->buffer+drawstart, MAXINPUTWIDTH+8, V_ALLOWLOWERCASE)+1); + + if (input->length) + skullx += V_SubStringWidth(nametodraw, input->cursor-drawstart, V_ALLOWLOWERCASE); + + V_DrawString(x, y, V_ALLOWLOWERCASE|flags, nametodraw); + + // draw text cursor for name + if (skullAnimCounter < 4) // blink cursor + V_DrawCharacter(skullx, y+3, '_'|flags, false); + + // draw selection + if (input->select != input->cursor) + { + size_t start = min(input->select, input->cursor); + size_t end = max(input->select, input->cursor); + + INT32 startx = 0; + INT32 width = 0; + + // I couldn't figure out one formula so here's bunch of separate cases + if (start < drawstart && end > drawstart + MAXSTRINGLENGTH) // Selection covers whole visible portion of demo name + { + startx = 0; + width = V_StringWidth(nametodraw, V_ALLOWLOWERCASE); + } + else if (start < drawstart) // Only left side of selection is off visible part + { + startx = 0; + size_t len = (end - start) - (drawstart - start); + width = V_SubStringWidth(nametodraw, len, V_ALLOWLOWERCASE); + } + else if (end > drawstart + MAXSTRINGLENGTH) // Only right side of selection is off visible part + { + startx = V_SubStringWidth(nametodraw, start-drawstart, V_ALLOWLOWERCASE); + width = V_StringWidth(nametodraw+(start-drawstart), V_ALLOWLOWERCASE); + } + else // All selection is on visible part + { + startx = V_SubStringWidth(nametodraw, start-drawstart, V_ALLOWLOWERCASE); + width = V_SubStringWidth(nametodraw+(start-drawstart), end-start, V_ALLOWLOWERCASE); + } + + V_DrawFill(x+startx, y, width, 8, 103|V_TRANSLUCENT|flags); + } +} + +void ST_DrawDemoTitleEntry(void) +{ #define x (BASEVIDWIDTH/2 - 139) #define y (BASEVIDHEIGHT/2) M_DrawTextBox(x, y + 4, MAXSTRINGLENGTH, 1); - V_DrawString(x + 8, y + 12, V_ALLOWLOWERCASE, nametodraw); - if (skullAnimCounter < 4) - V_DrawCharacter(x + 8 + V_StringWidth(nametodraw, 0), y + 12, - '_' | 0x80, false); + + ST_DrawTextInput(x + 8, y + 12, &demo.titlenameinput, 0); M_DrawTextBox(x + 30, y - 24, 26, 1); V_DrawString(x + 38, y - 16, V_ALLOWLOWERCASE, "Enter the name of the replay."); diff --git a/src/v_video.c b/src/v_video.c index 492a75004..e7bc81a27 100644 --- a/src/v_video.c +++ b/src/v_video.c @@ -2981,6 +2981,45 @@ INT32 V_ThinSubStringWidth(const char *string, INT32 length, INT32 option) return w; } +// +// Find maximum length for substring taken from current string to fit into given width +// +INT32 V_SubStringLengthToFit(const char *string, INT32 width, INT32 option) +{ + INT32 c, w = 0; + INT32 spacewidth = 4, charwidth = 0; + INT32 i; + + switch (option & V_SPACINGMASK) + { + case V_MONOSPACE: + spacewidth = 8; + /* FALLTHRU */ + case V_OLDSPACING: + charwidth = 8; + break; + case V_6WIDTHSPACE: + spacewidth = 6; + default: + break; + } + + for (i = 0; string[i] && w < width; i++) + { + c = string[i]; + if ((UINT8)c >= 0x80 && (UINT8)c <= 0x8F) //color parsing! -Inuyasha 2.16.09 + continue; + + c = toupper(c) - HU_FONTSTART; + if (c < 0 || c >= HU_FONTSIZE || !hu_font[c]) + w += spacewidth; + else + w += (charwidth ? charwidth : SHORT(hu_font[c]->width)); + } + + return max(i-1, 0); +} + char V_GetSkincolorChar(INT32 color) { char cstart = 0x80; diff --git a/src/v_video.h b/src/v_video.h index 0dae04aaa..bc1e8c546 100644 --- a/src/v_video.h +++ b/src/v_video.h @@ -246,6 +246,9 @@ INT32 V_SmallSubStringWidth(const char *string, INT32 length, INT32 option); INT32 V_ThinSubStringWidth(const char *string, INT32 length, INT32 option); #define V_ThinStringWidth(string, option) V_ThinSubStringWidth(string, -1, option) +// Find maximum length for substring taken from current string to fit into given width +INT32 V_SubStringLengthToFit(const char *string, INT32 width, INT32 option); + char V_GetSkincolorChar(INT32 color); void V_DoPostProcessor(INT32 view, postimg_t type, INT32 param); From fb0765a5f381fc8eeedc612bbc5ecc4771da06d9 Mon Sep 17 00:00:00 2001 From: Indev Date: Tue, 1 Oct 2024 20:55:27 +0300 Subject: [PATCH 26/66] Fix selection in replay save prompt --- src/st_stuff.c | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/src/st_stuff.c b/src/st_stuff.c index 83222e64f..dd6bd5f6b 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -820,13 +820,17 @@ static void ST_DrawTextInput(INT32 x, INT32 y, textinput_t *input, INT32 flags) char nametodraw[MAXSTRINGLENGTH*2+1] = {0}; size_t drawstart = 0; + size_t drawend = 0; // Only used for selection INT32 skullx = x; while (V_SubStringWidth(input->buffer+drawstart, input->cursor-drawstart, V_ALLOWLOWERCASE) > MAXINPUTWIDTH) ++drawstart; - memcpy(nametodraw, input->buffer+drawstart, V_SubStringLengthToFit(input->buffer+drawstart, MAXINPUTWIDTH+8, V_ALLOWLOWERCASE)+1); + size_t drawlength = V_SubStringLengthToFit(input->buffer+drawstart, MAXINPUTWIDTH+8, V_ALLOWLOWERCASE)+1; + drawend = drawstart + drawlength; + + memcpy(nametodraw, input->buffer+drawstart, drawlength); if (input->length) skullx += V_SubStringWidth(nametodraw, input->cursor-drawstart, V_ALLOWLOWERCASE); @@ -847,21 +851,21 @@ static void ST_DrawTextInput(INT32 x, INT32 y, textinput_t *input, INT32 flags) INT32 width = 0; // I couldn't figure out one formula so here's bunch of separate cases - if (start < drawstart && end > drawstart + MAXSTRINGLENGTH) // Selection covers whole visible portion of demo name + if (start < drawstart && end > drawend) // Selection covers whole visible portion of demo name { - startx = 0; - width = V_StringWidth(nametodraw, V_ALLOWLOWERCASE); + startx = -2; + width = V_StringWidth(nametodraw, V_ALLOWLOWERCASE)+4; } else if (start < drawstart) // Only left side of selection is off visible part { - startx = 0; + startx = -2; size_t len = (end - start) - (drawstart - start); - width = V_SubStringWidth(nametodraw, len, V_ALLOWLOWERCASE); + width = V_SubStringWidth(nametodraw, len, V_ALLOWLOWERCASE)+2; } - else if (end > drawstart + MAXSTRINGLENGTH) // Only right side of selection is off visible part + else if (end > drawend) // Only right side of selection is off visible part { startx = V_SubStringWidth(nametodraw, start-drawstart, V_ALLOWLOWERCASE); - width = V_StringWidth(nametodraw+(start-drawstart), V_ALLOWLOWERCASE); + width = V_StringWidth(nametodraw+(start-drawstart), V_ALLOWLOWERCASE)+2; } else // All selection is on visible part { From f32c34653476da6ecc2fbcf48d0c6460d98b6276 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 5 Oct 2024 06:56:21 +0200 Subject: [PATCH 27/66] this needs gamestate check sometimes the title music kept playing --- src/s_sound.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/s_sound.c b/src/s_sound.c index aa266c5a1..6016b028b 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -2231,7 +2231,7 @@ void S_CheckMap(void) return; } - keepmusic = (!skipmusic && oldmap == gamemap && oldencore == encoremode); + keepmusic = (!skipmusic && gamestate == GS_LEVEL && oldmap == gamemap && oldencore == encoremode); oldencore = encoremode; oldmap = gamemap; From 0b3e7240a8594c72341f8fa662fb39028cd2e3cd Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 6 Oct 2024 12:07:17 +0200 Subject: [PATCH 28/66] use saturn packet to determine if client can receive gamestate before the server always assumed every client cant receive the gamestate using the vanilla consistency check for everyone. aswell as before the first resynch it tried to send the gamestate resend packets to everyone --- src/Makefile | 12 ++++++------ src/d_clisrv.c | 46 +++++++++++++++++++--------------------------- src/doomdef.h | 6 +++--- 3 files changed, 28 insertions(+), 36 deletions(-) diff --git a/src/Makefile b/src/Makefile index 4668518b9..87226a60b 100644 --- a/src/Makefile +++ b/src/Makefile @@ -213,9 +213,9 @@ DOSATURNSYNCH=1 ifndef NOSATURNJOIN DOSATURNJOIN=1 endif -#ifndef NOSATURNPAK -#DOSATURNPAK=1 -#endif +ifndef NOSATURNPAK +DOSATURNPAK=1 +endif endif endif @@ -404,9 +404,9 @@ OPTS+=-DDOSATURNSYNCH ifndef NOSATURNJOIN OPTS+=-DDOSATURNJOIN endif -#ifndef NOSATURNPAK -#OPTS+=-DDOSATURNPAK -#endif +ifndef NOSATURNPAK +OPTS+=-DDOSATURNPAK +endif endif endif diff --git a/src/d_clisrv.c b/src/d_clisrv.c index f9110bb2d..ac0dfad34 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5394,6 +5394,7 @@ static void HandlePacketFromPlayer(SINT8 node) && !resendingsavegame[node] && savegameresendcooldown[node] <= I_GetTime() && !SV_ResendingSavegameToAnyone())) { +#ifndef SATURNPAK // we need to send this so the client can tell us if it can receive the savegame netbuffer->packettype = PT_WILLRESENDGAMESTATE; HSendPacket(node, true, 0, 0); @@ -5405,6 +5406,21 @@ static void HandlePacketFromPlayer(SINT8 node) SV_RequireResynch(node); resendingsavegame[node] = false; } +#else + if (can_receive_gamestate[node]) + { + // Tell the client we are about to resend them the gamestate + netbuffer->packettype = PT_WILLRESENDGAMESTATE; + HSendPacket(node, true, 0, 0); + + resendingsavegame[node] = true; + } + else + { + SV_RequireResynch(node); + resendingsavegame[node] = false; + } +#endif if ((!can_receive_gamestate[node] && cv_resynchattempts.value && resynch_score[node] <= (unsigned)cv_resynchattempts.value*250) || (can_receive_gamestate[node] && (gamestate_resend_counter[node] < cv_gamestateattempts.value))) { @@ -5584,31 +5600,6 @@ static void HandlePacketFromPlayer(SINT8 node) else buf[1] = KICK_MSG_PLAYER_QUIT; SendNetXCmd(XD_KICK, &buf, 2); - //nodetoplayer[node] = -1; - - /*if (nodetoplayer2[node] != -1 && nodetoplayer2[node] >= 0 - && playeringame[(UINT8)nodetoplayer2[node]]) - { - buf[0] = nodetoplayer2[node]; - SendNetXCmd(XD_KICK, &buf, 2); - nodetoplayer2[node] = -1; - } - - if (nodetoplayer3[node] != -1 && nodetoplayer3[node] >= 0 - && playeringame[(UINT8)nodetoplayer3[node]]) - { - buf[0] = nodetoplayer3[node]; - SendNetXCmd(XD_KICK, &buf, 2); - nodetoplayer3[node] = -1; - } - - if (nodetoplayer4[node] != -1 && nodetoplayer4[node] >= 0 - && playeringame[(UINT8)nodetoplayer4[node]]) - { - buf[0] = nodetoplayer4[node]; - SendNetXCmd(XD_KICK, &buf, 2); - nodetoplayer4[node] = -1; - }*/ } Net_CloseConnection(node); nodeingame[node] = false; @@ -5799,6 +5790,7 @@ static void HandlePacketFromPlayer(SINT8 node) case PT_ISSATURN: //CONS_Printf("hi im on saturn%d\n", node); is_client_saturn[node] = true; + can_receive_gamestate[node] = true; break; #endif default: @@ -6634,7 +6626,7 @@ void NetKeepAlive(void) #ifdef MASTERSERVER MasterClient_Ticker(); #endif - + #ifdef HOLEPUNCH if (netgame && serverrunning) { @@ -6745,7 +6737,7 @@ void NetUpdate(void) CL_SendClientCmd(); // send it GetPackets(); // get packet from client or from server - + // client send the command after a receive of the server // the server send before because in single player is beter diff --git a/src/doomdef.h b/src/doomdef.h index bdc82a0ca..361cd92d1 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -585,9 +585,9 @@ extern const char *compdate, *comptime, *comprevision, *compbranch; /// Server detection for if a connecting client is on Saturn. /// For stuff like extra synching, etc. -//#ifdef DOSATURNPAK -//#define SATURNPAK -//#endif +#ifdef DOSATURNPAK +#define SATURNPAK +#endif //-- <( ̄︶ ̄)> __ #endif From fc39a0dedf51ceab5e9de841d6b93f3e6b398c6f Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 6 Oct 2024 12:12:59 +0200 Subject: [PATCH 29/66] make the debug print a little better --- src/d_clisrv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index ac0dfad34..8a9a5417c 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5788,7 +5788,7 @@ static void HandlePacketFromPlayer(SINT8 node) #endif #ifdef SATURNPAK case PT_ISSATURN: - //CONS_Printf("hi im on saturn%d\n", node); + //CONS_Printf("hi im on saturn [node = %d]\n", node); is_client_saturn[node] = true; can_receive_gamestate[node] = true; break; From 5cb207edfabacd34ccec7ad430e6eb3678acfc28 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 6 Oct 2024 12:14:32 +0200 Subject: [PATCH 30/66] add debfile prints whenever gamestate counter changes --- src/d_clisrv.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 8a9a5417c..97ad460d6 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5385,7 +5385,10 @@ static void HandlePacketFromPlayer(SINT8 node) #ifdef SATURNSYNCH // this decreases by one point at twice the cooldown time (ex cooldown of 2 seconds means, this counter decreases by one every 4 seconds), pretty much there to prevent a resynch loop if ((gamestate_resend_counter[node] != 0) && (I_GetTime() % ((max(cv_resynchcooldown.value, 1) * TICRATE) *2) == 0)) + { gamestate_resend_counter[node]--; + DEBFILE(va("gamestate counter %d for node %d\n", gamestate_resend_counter[node], netconsole)); + } // Check player consistancy during the level if (((!can_receive_gamestate[node]) && realstart <= gametic && realstart > gametic - TICQUEUE+1 && gamestate == GS_LEVEL @@ -5427,7 +5430,7 @@ static void HandlePacketFromPlayer(SINT8 node) if (can_receive_gamestate[node] && resendingsavegame[node]) { gamestate_resend_counter[node]++; - DEBFILE(va("gamestate counter %d for player %d\n", gamestate_resend_counter[node], netconsole)); + DEBFILE(va("gamestate counter %d for node %d\n", gamestate_resend_counter[node], netconsole)); } if (cv_blamecfail.value) @@ -5451,6 +5454,7 @@ static void HandlePacketFromPlayer(SINT8 node) netconsole, realstart, consistancy[realstart%TICQUEUE], SHORT(netbuffer->u.clientpak.consistancy))); gamestate_resend_counter[node] = 0; + DEBFILE(va("gamestate counter %d for node %d\n", gamestate_resend_counter[node], netconsole)); break; } } From 4877c81728149b75571e4fd3902b327d146ccde1 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 6 Oct 2024 12:32:57 +0200 Subject: [PATCH 31/66] comment this out for now so v7 clients dont use vanilla resynch system keep sending PT_WILLRESENDGAMESTATE packets to everyone for now saturnpak will still mark the right clients so they will use the right consistency check without having to desynch first --- src/d_clisrv.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 97ad460d6..996afbf7a 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5397,7 +5397,7 @@ static void HandlePacketFromPlayer(SINT8 node) && !resendingsavegame[node] && savegameresendcooldown[node] <= I_GetTime() && !SV_ResendingSavegameToAnyone())) { -#ifndef SATURNPAK +//#ifndef SATURNPAK // we need to send this so the client can tell us if it can receive the savegame netbuffer->packettype = PT_WILLRESENDGAMESTATE; HSendPacket(node, true, 0, 0); @@ -5409,7 +5409,7 @@ static void HandlePacketFromPlayer(SINT8 node) SV_RequireResynch(node); resendingsavegame[node] = false; } -#else +/*#else if (can_receive_gamestate[node]) { // Tell the client we are about to resend them the gamestate @@ -5423,7 +5423,7 @@ static void HandlePacketFromPlayer(SINT8 node) SV_RequireResynch(node); resendingsavegame[node] = false; } -#endif +#endif*/ if ((!can_receive_gamestate[node] && cv_resynchattempts.value && resynch_score[node] <= (unsigned)cv_resynchattempts.value*250) || (can_receive_gamestate[node] && (gamestate_resend_counter[node] < cv_gamestateattempts.value))) { From 7d65b5369ff5f3e61bbc66b5069b1ab0e946dd71 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 6 Oct 2024 12:34:51 +0200 Subject: [PATCH 32/66] add some brackets lul --- src/d_clisrv.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 996afbf7a..c58491cfa 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5397,7 +5397,7 @@ static void HandlePacketFromPlayer(SINT8 node) && !resendingsavegame[node] && savegameresendcooldown[node] <= I_GetTime() && !SV_ResendingSavegameToAnyone())) { -//#ifndef SATURNPAK +//#ifndef SATURNPAK // lug: keep this behaviour for v7.1 atleast // we need to send this so the client can tell us if it can receive the savegame netbuffer->packettype = PT_WILLRESENDGAMESTATE; HSendPacket(node, true, 0, 0); @@ -5425,7 +5425,7 @@ static void HandlePacketFromPlayer(SINT8 node) } #endif*/ - if ((!can_receive_gamestate[node] && cv_resynchattempts.value && resynch_score[node] <= (unsigned)cv_resynchattempts.value*250) || (can_receive_gamestate[node] && (gamestate_resend_counter[node] < cv_gamestateattempts.value))) + if ((!can_receive_gamestate[node] && (cv_resynchattempts.value && resynch_score[node] <= (unsigned)cv_resynchattempts.value*250)) || (can_receive_gamestate[node] && (gamestate_resend_counter[node] < cv_gamestateattempts.value))) { if (can_receive_gamestate[node] && resendingsavegame[node]) { @@ -5466,7 +5466,7 @@ static void HandlePacketFromPlayer(SINT8 node) if (realstart <= gametic && realstart > gametic - TICQUEUE+1 && gamestate == GS_LEVEL && consistancy[realstart%TICQUEUE] != SHORT(netbuffer->u.clientpak.consistancy)) { - SV_RequireResynch(node); + SV_RequireResynch(node); if (cv_resynchattempts.value && resynch_score[node] <= (unsigned)cv_resynchattempts.value*250) { From 297af069cb3fd3059cc8f7160f14a1c6f5eafe23 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 7 Oct 2024 12:41:59 +0200 Subject: [PATCH 33/66] doubt anyone wants this also psure this will cause some weird issues somewhere idk --- src/p_spec.c | 10 +++++----- src/s_sound.c | 4 ++-- src/s_sound.h | 2 +- 3 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/p_spec.c b/src/p_spec.c index 710e76fd7..67d8cb617 100644 --- a/src/p_spec.c +++ b/src/p_spec.c @@ -99,7 +99,7 @@ typedef struct thinker_t **thinkers; } thinkerlist_t; -static boolean fromlapexec = false; +//static boolean fromlapexec = false; static void P_SearchForDisableLinedefs(void); static void P_SpawnScrollers(void); @@ -1342,7 +1342,7 @@ boolean P_RunTriggerLinedef(line_t *triggerline, mobj_t *actor, sector_t *caller fixed_t dist = P_AproxDistance(triggerline->dx, triggerline->dy)>>FRACBITS; size_t i, linecnt, sectori; INT16 specialtype = triggerline->special; - fromlapexec = false; + //fromlapexec = false; ///////////////////////////////////////////////// // Distance-checking/sector trigger conditions // @@ -1465,7 +1465,7 @@ boolean P_RunTriggerLinedef(line_t *triggerline, mobj_t *actor, sector_t *caller return false; } - fromlapexec = true; + //fromlapexec = true; } // If we were not triggered by a sector type especially for the purpose, // a Linedef Executor linedef trigger is not handling sector triggers properly, return. @@ -2135,8 +2135,8 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec) if (keepmusic && (leveltime <= MUSICSTARTTIME)) //why check for starttime? cause encore music Zzz... return; - if (cv_ignoremusicchanges.value && (leveltime >= MUSICSTARTTIME) && !fromlapexec) // keep lap music intanct tho - return; + //if (cv_ignoremusicchanges.value && (leveltime >= MUSICSTARTTIME) && !fromlapexec) // keep lap music intanct tho + //return; // console player only unless NOCLIMB is set if ((line->flags & ML_NOCLIMB) || (mo && mo->player && P_IsLocalPlayer(mo->player))) diff --git a/src/s_sound.c b/src/s_sound.c index 6016b028b..c68e4d8e1 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -121,7 +121,7 @@ consvar_t cv_birdmusic = {"birdmusicstuff", "No", CV_SAVE|CV_CALL, CV_YesNo, Bir consvar_t cv_keepmusic = {"keepmusic", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; consvar_t cv_skipintromusic = {"skipintromusic", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; -consvar_t cv_ignoremusicchanges = {"ignoremusicchanges", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; +//consvar_t cv_ignoremusicchanges = {"ignoremusicchanges", "No", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL}; boolean keepmusic = false; static void S_CheckEventMus(const char *newmus); @@ -305,7 +305,7 @@ void S_RegisterSoundStuff(void) CV_RegisterVar(&cv_keepmusic); CV_RegisterVar(&cv_skipintromusic); - CV_RegisterVar(&cv_ignoremusicchanges); + //CV_RegisterVar(&cv_ignoremusicchanges); COM_AddCommand("tunes", Command_Tunes_f); COM_AddCommand("restartaudio", Command_RestartAudio_f); diff --git a/src/s_sound.h b/src/s_sound.h index e31040eac..5232ef5c1 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -69,7 +69,7 @@ extern consvar_t cv_birdmusic; extern consvar_t cv_keepmusic; extern consvar_t cv_skipintromusic; -extern consvar_t cv_ignoremusicchanges; +//extern consvar_t cv_ignoremusicchanges; extern boolean keepmusic; extern boolean skipintromus; #define MUSICSTARTTIME (starttime + (TICRATE/2)) From e8351d44b6d25b019bcd4df2ce68b253dbf5101b Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 7 Oct 2024 12:45:03 +0200 Subject: [PATCH 34/66] add crap to menu --- src/m_menu.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/m_menu.c b/src/m_menu.c index 2bfb3e1f1..0f92ccedf 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1667,7 +1667,10 @@ static menuitem_t OP_SoundAdvancedMenu[] = {IT_STRING | IT_CVAR, NULL, "Grow Music", &cv_growmusic, 117}, {IT_STRING | IT_CVAR, NULL, "Invulnerability Music", &cv_supermusic, 127}, - {IT_STRING | IT_CVAR, NULL, "Audio Buffer Size", &cv_audbuffersize, 147}, + {IT_STRING | IT_CVAR, NULL, "Keep Map Music", &cv_keepmusic, 139}, + {IT_STRING | IT_CVAR, NULL, "Skip Intro Music", &cv_skipintromusic, 149}, + + {IT_STRING | IT_CVAR, NULL, "Audio Buffer Size", &cv_audbuffersize, 157}, }; static const char* OP_SoundAdvancedTooltips[] = @@ -1685,6 +1688,8 @@ static const char* OP_SoundAdvancedTooltips[] = NULL, "Should the Grow music be on or off?", "Should the Invulnerability music be on or off?", + "Should music be kept when restarting the map?", + "Should the Intro fanfare be skipped\nand map music be played on map start?", "Size of the Audio Buffer\nreducing it will result in less sound latency\nbut may cause issues such as crackling or distorted Sound.", }; From f3a18a0655179fc294b3b6f320295d0dd20839a7 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 7 Oct 2024 12:48:29 +0200 Subject: [PATCH 35/66] false --- src/s_sound.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/s_sound.c b/src/s_sound.c index c68e4d8e1..5019213fb 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -2189,7 +2189,7 @@ boolean S_FadeOutStopMusic(UINT32 ms) }*/ static INT16 oldmap = 0; -static boolean oldencore = 0; +static boolean oldencore = false; static boolean skipmusic = false; boolean skipintromus = false; From 8b915f9ac1cbed7698b130a1db7e4d8e6a12b0fc Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 7 Oct 2024 12:53:25 +0200 Subject: [PATCH 36/66] make this less ugly --- src/m_menu.c | 23 ++++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 0f92ccedf..0aa2d3e93 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -1653,24 +1653,25 @@ static const char* OP_SoundTooltips[] = static menuitem_t OP_SoundAdvancedMenu[] = { #ifdef HAVE_OPENMPT - {IT_HEADER, NULL, "Tracker Module Options", NULL, 10}, + {IT_HEADER, NULL, "Tracker Module Options", NULL, 0}, - {IT_STRING | IT_CVAR, NULL, "Instrument Filter", &cv_modfilter, 22}, - {IT_STRING | IT_CVAR, NULL, "Amiga Resampler", &cv_amigafilter, 42}, + {IT_STRING | IT_CVAR, NULL, "Instrument Filter", &cv_modfilter, 20}, + {IT_STRING | IT_CVAR, NULL, "Amiga Resampler", &cv_amigafilter, 30}, #if OPENMPT_API_VERSION_MAJOR < 1 && OPENMPT_API_VERSION_MINOR > 4 - {IT_STRING | IT_CVAR, NULL, "Amiga Type", &cv_amigatype, 62}, + {IT_STRING | IT_CVAR, NULL, "Amiga Type", &cv_amigatype, 40}, #endif - {IT_STRING | IT_CVAR, NULL, "Stereo Seperation", &cv_stereosep, 82}, + {IT_STRING | IT_CVAR, NULL, "Stereo Seperation", &cv_stereosep, 50}, #endif - {IT_HEADER, NULL, "Misc", NULL, 105}, - {IT_STRING | IT_CVAR, NULL, "Grow Music", &cv_growmusic, 117}, - {IT_STRING | IT_CVAR, NULL, "Invulnerability Music", &cv_supermusic, 127}, + {IT_HEADER, NULL, "Misc", NULL, 70}, - {IT_STRING | IT_CVAR, NULL, "Keep Map Music", &cv_keepmusic, 139}, - {IT_STRING | IT_CVAR, NULL, "Skip Intro Music", &cv_skipintromusic, 149}, + {IT_STRING | IT_CVAR, NULL, "Grow Music", &cv_growmusic, 90}, + {IT_STRING | IT_CVAR, NULL, "Invulnerability Music", &cv_supermusic, 100}, - {IT_STRING | IT_CVAR, NULL, "Audio Buffer Size", &cv_audbuffersize, 157}, + {IT_STRING | IT_CVAR, NULL, "Keep Map Music", &cv_keepmusic, 120}, + {IT_STRING | IT_CVAR, NULL, "Skip Intro Music", &cv_skipintromusic, 130}, + + {IT_STRING | IT_CVAR, NULL, "Audio Buffer Size", &cv_audbuffersize, 150}, }; static const char* OP_SoundAdvancedTooltips[] = From 63c1372c34d13b34e654f340f8cd0ae0fad67ab9 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 7 Oct 2024 12:57:55 +0200 Subject: [PATCH 37/66] keep debug print for now --- src/d_clisrv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index a4049db9c..09813198a 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5792,7 +5792,7 @@ static void HandlePacketFromPlayer(SINT8 node) #endif #ifdef SATURNPAK case PT_ISSATURN: - //CONS_Printf("hi im on saturn [node = %d]\n", node); + CONS_Printf("hi im on saturn node = %d\n", node); is_client_saturn[node] = true; can_receive_gamestate[node] = true; break; From c51d33fa6efb9efa5573e9a8f8b362deb3bf06e6 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 12 Oct 2024 20:19:44 +0200 Subject: [PATCH 38/66] save 1 G_BuildMapTitle call kek --- src/s_sound.c | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/s_sound.c b/src/s_sound.c index 5019213fb..b36783d41 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -2244,10 +2244,15 @@ void S_CheckMap(void) // void S_InitMapMusic(void) { - char *maptitle = G_BuildMapTitle(gamemap); - skipintromus = cv_skipintromusic.value && stricmp(maptitle, "Wandering Falls") != 0; // thanks diggle! - if (maptitle) - Z_Free(maptitle); + if (!cv_skipintromusic.value) + skipintromus = false; + else + { + char *maptitle = G_BuildMapTitle(gamemap); + skipintromus = cv_skipintromusic.value && stricmp(maptitle, "Wandering Falls") != 0; // thanks diggle! + if (maptitle) + Z_Free(maptitle); + } if (mapmusflags & MUSIC_RELOADRESET) { From 55248e7fcf5e79fca5d8b7d3aef2de6c42c9bb1d Mon Sep 17 00:00:00 2001 From: Indev Date: Sun, 19 May 2024 13:45:34 +0300 Subject: [PATCH 39/66] Attempt to fix a lua panic when unarchiveing extvars (print error to console instead. Not sure if it would be safe for game to read from save afterwards though) --- src/lua_script.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/lua_script.c b/src/lua_script.c index 9d5bef4a7..c6df314d4 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -1460,7 +1460,13 @@ static void UnArchiveExtVars(void *pointer) for (i = 0; i < field_count; i++) { READSTRING(save_p, field); - UnArchiveValue(TABLESINDEX); + + if (UnArchiveValue(TABLESINDEX) == 1) + { + CONS_Alert(CONS_ERROR, "Unexpected end marker when reading ExtVars (field '%s')\n", field); + break; + } + lua_setfield(gL, -2, field); } From 210d6ac8ac38b2c0c300b87f8e5f764355b08646 Mon Sep 17 00:00:00 2001 From: Indev Date: Sat, 4 May 2024 17:25:37 +0300 Subject: [PATCH 40/66] Add few checks to prevent game crashing if netgame archive becomes corrupted --- src/lua_script.c | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/lua_script.c b/src/lua_script.c index c6df314d4..8015e75f3 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -1333,6 +1333,9 @@ static UINT8 UnArchiveValue(int TABLESINDEX) break; case ARCH_TEND: return 1; + default: + CONS_Alert(CONS_ERROR, "Unknown value type unarchived, save is corrupted!\n"); + return 1; } return 0; } @@ -1530,12 +1533,29 @@ static void UnArchiveTables(void) for (i = 1; i <= n; i++) { lua_rawgeti(gL, TABLESINDEX, i); + + if (!lua_istable(gL, -1)) + { + CONS_Alert(CONS_ERROR, "Value in tables list #%d is not a table! (corrupted save?)\n", i); + continue; + } + while (true) { if (UnArchiveValue(TABLESINDEX) == 1) // read key break; - if (UnArchiveValue(TABLESINDEX) == 2) // read value + + UINT8 ret = UnArchiveValue(TABLESINDEX); + + if (ret == 1) + { + CONS_Alert(CONS_ERROR, "Unexpected end of save reached (Corrupted save?)\n"); + lua_pop(gL, 1); // Pop key + break; + } + else if (ret == 2) // read value n++; + if (lua_isnil(gL, -2)) // if key is nil (if a function etc was accidentally saved) { CONS_Alert(CONS_ERROR, "A nil key in table %d was found! (Invalid key type or corrupted save?)\n", i); From d00014ea599c542d3ba94137ee94826da62936b6 Mon Sep 17 00:00:00 2001 From: Indev Date: Sat, 4 May 2024 18:14:34 +0300 Subject: [PATCH 41/66] If corrupted save received, leave netgame --- src/lua_script.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/lua_script.c b/src/lua_script.c index 8015e75f3..f65f49f92 100644 --- a/src/lua_script.c +++ b/src/lua_script.c @@ -22,6 +22,8 @@ #include "p_saveg.h" #include "p_local.h" #include "p_slopes.h" // for P_SlopeById +#include "s_sound.h" +#include "m_menu.h" #ifdef LUA_ALLOW_BYTECODE #include "d_netfil.h" // for LUA_DumpFile #endif @@ -1335,6 +1337,9 @@ static UINT8 UnArchiveValue(int TABLESINDEX) return 1; default: CONS_Alert(CONS_ERROR, "Unknown value type unarchived, save is corrupted!\n"); + G_SetExitGameFlag(); + S_StartSound(NULL, sfx_syfail); // he he he + M_StartMessage(M_GetText("Corrupted save received\nPress ESC\n"), NULL, MM_NOTHING); return 1; } return 0; From 02bbb38606983badaa6cc046f6ce2b5fd5b6fed0 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 12 Oct 2024 23:10:01 +0200 Subject: [PATCH 42/66] Fix insane TTY input latency https://git.do.srb2.org/STJr/SRB2/-/merge_requests/2360 --- src/sdl/i_system.c | 79 ++++++++++++++++++++++++++-------------------- 1 file changed, 45 insertions(+), 34 deletions(-) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 0815ee968..66e0819dc 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -111,6 +111,7 @@ typedef LPVOID (WINAPI *p_MapViewOfFile) (HANDLE, DWORD, DWORD, DWORD, SIZE_T); #endif #if defined (__unix__) || (defined (UNIXCOMMON) && !defined (__APPLE__)) +#include #include #include #define NEWSIGNALHANDLER @@ -698,50 +699,60 @@ void I_GetConsoleEvents(void) // we use this when sending back commands event_t ev = {0,0,0,0}; char key = 0; - ssize_t d; + struct pollfd pfd = + { + .fd = STDIN_FILENO, + .events = POLLIN, + .revents = 0, + }; if (!consolevent) return; - ev.type = ev_console; - ev.data1 = 0; - if (read(STDIN_FILENO, &key, 1) == -1 || !key) - return; + for (;;) + { + if (poll(&pfd, 1, 0) < 1 || !(pfd.revents & POLLIN)) + return; - // we have something - // backspace? - // NOTE TTimo testing a lot of values .. seems it's the only way to get it to work everywhere - if ((key == tty_erase) || (key == 127) || (key == 8)) - { - if (tty_con.cursor > 0) + ev.type = ev_console; + ev.data1 = 0; + if (read(STDIN_FILENO, &key, 1) == -1 || !key) + return; + + // we have something + // backspace? + // NOTE TTimo testing a lot of values .. seems it's the only way to get it to work everywhere + if ((key == tty_erase) || (key == 127) || (key == 8)) { - tty_con.cursor--; - tty_con.buffer[tty_con.cursor] = '\0'; - tty_Back(); + if (tty_con.cursor > 0) + { + tty_con.cursor--; + tty_con.buffer[tty_con.cursor] = '\0'; + tty_Back(); + } + ev.data1 = KEY_BACKSPACE; } - ev.data1 = KEY_BACKSPACE; - } - else if (key < ' ') // check if this is a control char - { - if (key == '\n') + else if (key < ' ') // check if this is a control char { - tty_Clear(); - tty_con.cursor = 0; - ev.data1 = KEY_ENTER; + if (key == '\n') + { + tty_Clear(); + tty_con.cursor = 0; + ev.data1 = KEY_ENTER; + } + else continue; } - else return; + else if (tty_con.cursor < sizeof(tty_con.buffer)) + { + // push regular character + ev.data1 = tty_con.buffer[tty_con.cursor] = key; + tty_con.cursor++; + // print the current line (this is differential) + write(STDOUT_FILENO, &key, 1); + } + if (ev.data1) D_PostEvent(&ev); + //tty_FlushIn(); } - else if (tty_con.cursor < sizeof (tty_con.buffer)) - { - // push regular character - ev.data1 = tty_con.buffer[tty_con.cursor] = key; - tty_con.cursor++; - // print the current line (this is differential) - d = write(STDOUT_FILENO, &key, 1); - } - if (ev.data1) D_PostEvent(&ev); - //tty_FlushIn(); - (void)d; } #elif defined (_WIN32) From 081dcc021b2029ff825ac1995b9f5c198146f74f Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 12 Oct 2024 23:21:05 +0200 Subject: [PATCH 43/66] fix tty converting everything to lowercase --- src/console.c | 1 - src/m_textinput.c | 4 ---- 2 files changed, 5 deletions(-) diff --git a/src/console.c b/src/console.c index dbeb2b42b..9781078fa 100644 --- a/src/console.c +++ b/src/console.c @@ -898,7 +898,6 @@ boolean CON_Responder(event_t *ev) // show all cvars/commands that match what we have inputted if (key == KEY_TAB) { - if (!completion[0]) { if (!input.length || input.length >= 40 || strchr(input.buffer, ' ')) diff --git a/src/m_textinput.c b/src/m_textinput.c index 8b608cc9a..a73511f77 100644 --- a/src/m_textinput.c +++ b/src/m_textinput.c @@ -295,10 +295,6 @@ boolean M_TextInputHandle(textinput_t *input, INT32 key) if (key < 32 || key > 127) return false; - // add key to cmd line here - if (key >= 'A' && key <= 'Z' && !(shiftdown ^ capslock)) //this is only really necessary for dedicated servers - key = key + 'a' - 'A'; - if (input->select != input->cursor) M_TextInputDelSelection(input); M_TextInputAddChar(input, key); From d7ed91af1d2dbd5f84ea4ed2ebec57f7066dec0d Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 12 Oct 2024 23:26:07 +0200 Subject: [PATCH 44/66] Refactor TTY input handling https://git.do.srb2.org/STJr/SRB2/-/merge_requests/2451#b2f76b3273f1780347c35ec752bcde560c5f73a5 --- src/sdl/i_system.c | 98 +++++++++++++++++++++------------------------- 1 file changed, 44 insertions(+), 54 deletions(-) diff --git a/src/sdl/i_system.c b/src/sdl/i_system.c index 66e0819dc..f999d8684 100644 --- a/src/sdl/i_system.c +++ b/src/sdl/i_system.c @@ -545,10 +545,9 @@ typedef struct feild_t tty_con; -// when printing general stuff to stdout stderr (Sys_Printf) -// we need to disable the tty console stuff -// this increments so we can recursively disable -static INT32 ttycon_hide = 0; +// lock to prevent clearing partial lines, since not everything +// printed ends on a newline. +static boolean ttycon_ateol = true; // some key codes that the terminal may be using // TTimo NOTE: I'm not sure how relevant this is static INT32 tty_erase; @@ -576,63 +575,31 @@ static inline void tty_FlushIn(void) // TTimo NOTE: it seems on some terminals just sending '\b' is not enough // so for now, in any case we send "\b \b" .. yeah well .. // (there may be a way to find out if '\b' alone would work though) +// Hanicef NOTE: using \b this way is unreliable because of terminal state, +// it's better to use \r to reset the cursor to the beginning of the +// line and clear from there. static void tty_Back(void) { - char key; - ssize_t d; - key = '\b'; - d = write(STDOUT_FILENO, &key, 1); - key = ' '; - d = write(STDOUT_FILENO, &key, 1); - key = '\b'; - d = write(STDOUT_FILENO, &key, 1); - (void)d; + write(STDOUT_FILENO, "\r", 1); + if (tty_con.cursor>0) + { + write(STDOUT_FILENO, tty_con.buffer, tty_con.cursor); + } + write(STDOUT_FILENO, " \b", 2); } static void tty_Clear(void) { size_t i; + write(STDOUT_FILENO, "\r", 1); if (tty_con.cursor>0) { for (i=0; i0); - ttycon_hide--; - if (ttycon_hide == 0 && tty_con.cursor) - { - for (i=0; i 0) { LPVOID blank = malloc(oldLength); - if (!blank) return; + if (!blank) + { + free(txt); + return; + } memset(blank, ' ', oldLength); // Blank out. oldLines = malloc(oldLength*sizeof(TCHAR)); if (!oldLines) { + free(txt); free(blank); return; } @@ -1039,18 +1026,20 @@ void I_OutputMsg(const char *fmt, ...) } #else #ifdef HAVE_TERMIOS - if (consolevent) + if (consolevent && ttycon_ateol) { - tty_Hide(); + tty_Clear(); + ttycon_ateol = false; } #endif if (!framebuffer) fprintf(stderr, "%s", txt); #ifdef HAVE_TERMIOS - if (consolevent) + if (consolevent && txt[len-1] == '\n') { - tty_Show(); + write(STDOUT_FILENO, tty_con.buffer, tty_con.cursor); + ttycon_ateol = true; } #endif @@ -1059,6 +1048,7 @@ void I_OutputMsg(const char *fmt, ...) fflush(stderr); #endif + free(txt); } // From f01d2a0ba6aebf8a21caa1aaef85bf116d950289 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 12 Oct 2024 23:29:11 +0200 Subject: [PATCH 45/66] print saturnpak print into debfile instead of console --- src/d_clisrv.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/d_clisrv.c b/src/d_clisrv.c index 89aa24b13..f230ab190 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -5792,7 +5792,7 @@ static void HandlePacketFromPlayer(SINT8 node) #endif #ifdef SATURNPAK case PT_ISSATURN: - CONS_Printf("hi im on saturn node = %d\n", node); + DEBFILE(va("hi im on saturn! node = %d\n", node)); is_client_saturn[node] = true; can_receive_gamestate[node] = true; break; From b58fcf331c4350aa1c7b8fe905622b45dbc6fee1 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 13 Oct 2024 00:40:37 +0200 Subject: [PATCH 46/66] ignore keepmusic when called from P_RestoreMusic most of the sound handling just calls this and this may just stop the music entirely on some occasions so just ignore keepmusic for that --- src/k_kart.c | 2 +- src/p_user.c | 2 +- src/s_sound.c | 6 +++--- src/s_sound.h | 2 +- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/k_kart.c b/src/k_kart.c index 8c6356fdf..f71ceb049 100644 --- a/src/k_kart.c +++ b/src/k_kart.c @@ -5361,7 +5361,7 @@ void K_KartPlayerThink(player_t *player, ticcmd_t *cmd) // Plays the music during and after the starting countdown. if (P_IsLocalPlayer(player)) - S_StartMapMusic(); + S_StartMapMusic(false); } void K_KartPlayerAfterThink(player_t *player) diff --git a/src/p_user.c b/src/p_user.c index 643e03e9b..7612b17e6 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -743,7 +743,7 @@ void P_RestoreMusic(player_t *player) return; if (leveltime < MUSICSTARTTIME) - S_StartMapMusic(); + S_StartMapMusic(true); else // see also where time overs are handled - search for "lives = 2" in this file { INT32 wantedmus = 0; // 0 is level music, 1 is invincibility, 2 is grow diff --git a/src/s_sound.c b/src/s_sound.c index 5e171b6d4..868bccc77 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -2276,18 +2276,18 @@ void S_InitMapMusic(void) //S_ChangeMusicEx((encoremode ? "estart" : "kstart"), 0, false, mapmusposition, 0, 0); } -void S_StartMapMusic(void) +void S_StartMapMusic(boolean restore) { //no need to constantly run this after race has started if (leveltime > MUSICSTARTTIME) return; - if (keepmusic) + if (keepmusic && !restore) // make sure this doesent kill the music when its called from P_RestoreMusic in some cases return; if (skipintromus) { - if (leveltime < starttime) // dumb but i dont need this to be spammed honestly + if (leveltime < starttime) S_ChangeMusicEx(mapmusname, mapmusflags, true, mapmusposition, 0, 0); if (leveltime == MUSICSTARTTIME) S_ShowMusicCredit(); diff --git a/src/s_sound.h b/src/s_sound.h index a22763449..887cdd878 100644 --- a/src/s_sound.h +++ b/src/s_sound.h @@ -110,7 +110,7 @@ void S_StopSounds(void); void S_ClearSfx(void); void S_InitMapMusic(void); -void S_StartMapMusic(void); +void S_StartMapMusic(boolean restore); void S_CheckMap(void); From 3f12ebb2bd461303297ae72dfd6543becdee7b07 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 13 Oct 2024 01:11:48 +0200 Subject: [PATCH 47/66] only interp cam during pause for replay freecam to not jitter during pause --- src/r_main.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/r_main.c b/src/r_main.c index 618899c72..ef1560470 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -1359,7 +1359,7 @@ void R_SkyboxFrame(player_t *player) // newview->sin = FINESINE(viewangle>>ANGLETOFINESHIFT); // newview->cos = FINECOSINE(viewangle>>ANGLETOFINESHIFT); - R_InterpolateView(R_UsingFrameInterpolation() ? demo.playback ? rendertimefrac_unpaused : rendertimefrac : FRACUNIT, false); + R_InterpolateView(R_UsingFrameInterpolation() ? (demo.playback && demo.freecam) ? rendertimefrac_unpaused : rendertimefrac : FRACUNIT, false); } static void @@ -1380,7 +1380,7 @@ R_SetupCommonFrame else newview->sector = R_PointInSubsector(newview->x, newview->y)->sector; - R_InterpolateView(R_UsingFrameInterpolation() ? demo.playback ? rendertimefrac_unpaused : rendertimefrac : FRACUNIT, false); + R_InterpolateView(R_UsingFrameInterpolation() ? (demo.playback && demo.freecam) ? rendertimefrac_unpaused : rendertimefrac : FRACUNIT, false); } void R_SetupFrame(player_t *player, boolean skybox) From 262a84aac6478f81cbee5720bfef7dd00cd5f151 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 13 Oct 2024 02:28:07 +0200 Subject: [PATCH 48/66] fix ogl shearing no clue wtf kart was doing here lmao --- src/hardware/hw_defs.h | 2 +- src/hardware/hw_main.c | 42 ++++++++++++++++++-------------- src/hardware/r_opengl/r_opengl.c | 2 +- 3 files changed, 26 insertions(+), 20 deletions(-) diff --git a/src/hardware/hw_defs.h b/src/hardware/hw_defs.h index 7d2d17532..dc8d44ca8 100644 --- a/src/hardware/hw_defs.h +++ b/src/hardware/hw_defs.h @@ -156,7 +156,7 @@ typedef struct boolean mirrorflip; // Encore Mode with Flipcam #endif boolean shearing; // 14042019 - angle_t viewaiming; // 17052019 + float viewaiming; // 17052019 } FTransform; // Transformed vector, as passed to HWR API diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index db9846c07..5d243d4c3 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -309,9 +309,10 @@ FTransform atransform; // Float variants of viewx, viewy, viewz, etc. static float gr_viewx, gr_viewy, gr_viewz; float gr_viewsin, gr_viewcos; +static float gr_viewludsin, gr_viewludcos; static angle_t gr_aimingangle; -static float gr_viewludsin, gr_viewludcos; +static void HWR_SetTransformAiming(FTransform *trans); // ========================================================================== // Visual portals (attr. Hannu Hanhi) @@ -5130,15 +5131,12 @@ void HWR_DrawSkyBackground(float fpov) //04/01/2000: Hurdler: added for T&L // It should replace all other gr_viewxxx when finished - if (!atransform.shearing) - dometransform.anglex = (float)(aimingangle>>ANGLETOFINESHIFT)*(360.0f/(float)FINEANGLES); + HWR_SetTransformAiming(&dometransform); dometransform.angley = (float)((viewangle-ANGLE_270)>>ANGLETOFINESHIFT)*(360.0f/(float)FINEANGLES); dometransform.flip = atransform.flip; dometransform.mirror = atransform.mirror; dometransform.mirrorflip = atransform.mirrorflip; - dometransform.shearing = atransform.shearing; - dometransform.viewaiming = atransform.viewaiming; dometransform.scalex = 1; dometransform.scaley = (float)vid.width/vid.height; @@ -5199,6 +5197,25 @@ void HWR_SetViewSize(void) HWD.pfnFlushScreenTextures(); } +// Set view aiming, for the sky dome, the skybox, +// and the normal view, all with a single function. +static void HWR_SetTransformAiming(FTransform *trans) +{ + if (cv_grshearing.value) + { + fixed_t fixedaiming = AIMINGTODY(aimingangle); + trans->viewaiming = FIXED_TO_FLOAT(fixedaiming); + trans->shearing = true; + gr_aimingangle = 0; + } + else + { + trans->shearing = false; + gr_aimingangle = aimingangle; + } + trans->anglex = (float)(gr_aimingangle>>ANGLETOFINESHIFT)*(360.0f/(float)FINEANGLES); +} + void HWR_SetTransform(float fpov, player_t *player) { postimg_t *postprocessor = &postimgtype[0]; @@ -5221,23 +5238,12 @@ void HWR_SetTransform(float fpov, player_t *player) atransform.scaley = (float)vid.width/vid.height; atransform.scalez = 1; - // 14042019 - gr_aimingangle = aimingangle; - atransform.shearing = false; - atransform.viewaiming = aimingangle; - - if (cv_grshearing.value) - { - gr_aimingangle = 0; - atransform.shearing = true; - } + HWR_SetTransformAiming(&atransform); + atransform.angley = (float)(viewangle>>ANGLETOFINESHIFT)*(360.0f/(float)FINEANGLES); gr_viewludsin = FIXED_TO_FLOAT(FINECOSINE(gr_aimingangle>>ANGLETOFINESHIFT)); gr_viewludcos = FIXED_TO_FLOAT(-FINESINE(gr_aimingangle>>ANGLETOFINESHIFT)); - atransform.anglex = (float)(gr_aimingangle>>ANGLETOFINESHIFT)*(360.0f/(float)FINEANGLES); - atransform.angley = (float)(viewangle>>ANGLETOFINESHIFT)*(360.0f/(float)FINEANGLES); - atransform.fovxangle = fpov; // Tails atransform.fovyangle = fpov; // Tails HWR_RollTransform(&atransform, viewroll); diff --git a/src/hardware/r_opengl/r_opengl.c b/src/hardware/r_opengl/r_opengl.c index abfbfdd25..4be4d4c27 100644 --- a/src/hardware/r_opengl/r_opengl.c +++ b/src/hardware/r_opengl/r_opengl.c @@ -2984,7 +2984,7 @@ EXPORT void HWRAPI(SetTransform) (FTransform *stransform) // https://zdoom.org/wiki/Y-shearing if (shearing) { - float dy = FIXED_TO_FLOAT(AIMINGTODY((stransform->viewaiming)) * 2)* ((float)vid.width / vid.height) / ((float)BASEVIDWIDTH / BASEVIDHEIGHT); //screen_width/BASEVIDWIDTH; + float dy = stransform->viewaiming * 2; if (stransform->flip || stransform->mirrorflip) dy *= -1.0f; pglTranslatef(0.0f, -dy/BASEVIDHEIGHT, 0.0f); From 7f6ce1f299c25070d09e6434203b9ec8cc7c327d Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 13 Oct 2024 02:46:04 +0200 Subject: [PATCH 49/66] this uhhh actually makes things crash lol --- src/r_things.c | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/src/r_things.c b/src/r_things.c index 31c3dcbe4..56dfb8d76 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -609,6 +609,7 @@ void R_DrawMaskedColumn(column_t *column) dc_yh = mfloorclip[dc_x]-1; if (dc_yl <= mceilingclip[dc_x]) dc_yl = mceilingclip[dc_x]+1; + if (dc_yl < 0) dc_yl = 0; if (dc_yh >= vid.height) @@ -625,6 +626,10 @@ void R_DrawMaskedColumn(column_t *column) // quick fix... something more proper should be done!!! if (ylookup[dc_yl]) colfunc(); +#ifdef PARANOIA + else + I_Error("R_DrawMaskedColumn: Invalid ylookup for dc_yl %d", dc->yl); +#endif } column = (column_t *)((UINT8 *)column + column->length + 4); } @@ -837,14 +842,6 @@ static void R_DrawVisSprite(vissprite_t *vis) if (vis->x2 >= vid.width) vis->x2 = vid.width-1; - // Something is occasionally setting 1px-wide sprites whose frac is exactly the width of the sprite, causing crashes due to - // accessing invalid column info. Until the cause is found, let's try to correct those manually... - { - fixed_t temp = ((frac + vis->xiscale*(vis->x2-vis->x1))>>FRACBITS) - SHORT(patch->width); - if (temp > 0) - vis->x2 -= temp; - } - localcolfunc = (vis->vflip) ? R_DrawFlippedMaskedColumn : R_DrawMaskedColumn; lengthcol = patch->height; From d37505ff06f37716f879f047e4488b9a8f1eccf0 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 13 Oct 2024 02:58:46 +0200 Subject: [PATCH 50/66] this should be SHORT --- src/r_things.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/r_things.c b/src/r_things.c index 56dfb8d76..3f96ed419 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -843,13 +843,14 @@ static void R_DrawVisSprite(vissprite_t *vis) vis->x2 = vid.width-1; localcolfunc = (vis->vflip) ? R_DrawFlippedMaskedColumn : R_DrawMaskedColumn; - lengthcol = patch->height; + lengthcol = SHORT(patch->height); // Split drawing loops for paper and non-paper to reduce conditional checks per sprite if (vis->scalestep) { fixed_t horzscale = FixedMul(vis->spritexscale, this_scale); fixed_t scalestep = FixedMul(vis->scalestep, vis->spriteyscale); + pwidth = SHORT(patch->width); // Papersprite drawing loop From a19c4dc5e5cf6e62de8a566ccd944c38cca12b67 Mon Sep 17 00:00:00 2001 From: Indev Date: Sun, 13 Oct 2024 15:09:10 +0300 Subject: [PATCH 51/66] Fix game crashing when using P_DoPlayerExit on player without mobj --- src/p_user.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/p_user.c b/src/p_user.c index 7612b17e6..7c57fb107 100644 --- a/src/p_user.c +++ b/src/p_user.c @@ -1249,7 +1249,7 @@ void P_DoPlayerExit(player_t *player) player->exiting = raceexittime+2; K_KartUpdatePosition(player); - if (cv_kartvoices.value) + if (!P_MobjWasRemoved(player->mo) && cv_kartvoices.value) { if (P_IsLocalPlayer(player)) { From 4cf4d49f482c03e7826c23ab94253fd89a2453e3 Mon Sep 17 00:00:00 2001 From: Indev Date: Sun, 13 Oct 2024 15:37:29 +0300 Subject: [PATCH 52/66] Fix error handler staying on lua stack after lua commands being called --- src/lua_consolelib.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/lua_consolelib.c b/src/lua_consolelib.c index 3e70ce008..f2fb03dc6 100644 --- a/src/lua_consolelib.c +++ b/src/lua_consolelib.c @@ -81,6 +81,9 @@ void Got_Luacmd(UINT8 **cp, INT32 playernum) lua_pushstring(gL, buf); } LUA_Call(gL, (int)argc, 0, 1); // argc is 1-based, so this will cover the player we passed too. + + lua_pop(gL, 1); // Pop LUA_GetErrorMessage (lua_pcall doesn't pop it) + return; deny: @@ -143,7 +146,7 @@ void COM_Lua_f(void) if (netgame && !( flags & COM_LOCAL ))/* don't send local commands */ { // Send the command through the network UINT8 argc; - lua_pop(gL, 1); // pop command info table + lua_pop(gL, 2); // pop command info table and LUA_GetErrorMessage if (flags & COM_ADMIN && !server && !IsPlayerAdmin(playernum)) // flag 1: only server/admin can use this command. { @@ -182,6 +185,8 @@ void COM_Lua_f(void) for (i = 1; i < COM_Argc(); i++) lua_pushstring(gL, COM_Argv(i)); LUA_Call(gL, (int)COM_Argc(), 0, 1); // COM_Argc is 1-based, so this will cover the player we passed too. + + lua_pop(gL, 1); // Pop LUA_GetErrorMessage (lua_pcall doesn't pop it) } // Wrapper for COM_AddCommand From 38f3e48aed20ca2168143e72b995430582644ba6 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 13 Oct 2024 23:07:32 +0200 Subject: [PATCH 53/66] only do this in software renderer doesent work even with pal rendering in ogl --- src/d_main.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/d_main.c b/src/d_main.c index 996d879e3..1dfe3eafa 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -568,7 +568,7 @@ static boolean D_Display(void) V_DrawScaledPatch(viewwindowx + (BASEVIDWIDTH - SHORT(patch->width))/2, py, V_SNAPTOTOP, patch); } - if (demo.rewinding) + if (rendermode == render_soft && demo.rewinding) V_DrawFadeScreen(TC_RAINBOW, (leveltime & 0x20) ? SKINCOLOR_PASTEL : SKINCOLOR_MOONSLAM); // vid size change is now finished if it was on... From 1daac9a124b6fea2ed9592c45879d8748878a509 Mon Sep 17 00:00:00 2001 From: Alug Date: Mon, 14 Oct 2024 22:15:27 +0200 Subject: [PATCH 54/66] revert all the cam things for now here Dont wanna deal with this shit for 7.1 anymore --- src/r_main.c | 122 +++++++++++++++++++++++++++------------------------ 1 file changed, 65 insertions(+), 57 deletions(-) diff --git a/src/r_main.c b/src/r_main.c index ef1560470..75ff41126 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -1356,30 +1356,6 @@ void R_SkyboxFrame(player_t *player) else newview->sector = R_PointInSubsector(newview->x, newview->y)->sector; - // newview->sin = FINESINE(viewangle>>ANGLETOFINESHIFT); - // newview->cos = FINECOSINE(viewangle>>ANGLETOFINESHIFT); - - R_InterpolateView(R_UsingFrameInterpolation() ? (demo.playback && demo.freecam) ? rendertimefrac_unpaused : rendertimefrac : FRACUNIT, false); -} - -static void -R_SetupCommonFrame -( player_t * player, - subsector_t * subsector) -{ - newview->player = player; - - newview->x += quake.x; - newview->y += quake.y; - newview->z += quake.z; - - newview->roll = R_ViewRollAngle(player); - - if (subsector) - newview->sector = subsector->sector; - else - newview->sector = R_PointInSubsector(newview->x, newview->y)->sector; - R_InterpolateView(R_UsingFrameInterpolation() ? (demo.playback && demo.freecam) ? rendertimefrac_unpaused : rendertimefrac : FRACUNIT, false); } @@ -1388,33 +1364,50 @@ void R_SetupFrame(player_t *player, boolean skybox) camera_t *thiscam; boolean chasecam = false; -#define SETUPCAM(num, var, context)\ - thiscam = &camera[num];\ - chasecam = (var.value != 0);\ - R_SetViewContext(context);\ - if (thiscam->reset)\ - {\ - R_ResetViewInterpolation(num+1);\ - thiscam->reset = false;\ - } - if (splitscreen > 2 && player == &players[displayplayers[3]]) { - SETUPCAM(3, cv_chasecam4, VIEWCONTEXT_PLAYER4) + thiscam = &camera[3]; + chasecam = (cv_chasecam4.value != 0); + R_SetViewContext(VIEWCONTEXT_PLAYER4); + if (thiscam->reset) + { + R_ResetViewInterpolation(4); + thiscam->reset = false; + } } else if (splitscreen > 1 && player == &players[displayplayers[2]]) { - SETUPCAM(2, cv_chasecam3, VIEWCONTEXT_PLAYER3) + thiscam = &camera[2]; + chasecam = (cv_chasecam3.value != 0); + R_SetViewContext(VIEWCONTEXT_PLAYER3); + if (thiscam->reset) + { + R_ResetViewInterpolation(3); + thiscam->reset = false; + } } else if (splitscreen && player == &players[displayplayers[1]]) { - SETUPCAM(1, cv_chasecam2, VIEWCONTEXT_PLAYER2) + thiscam = &camera[1]; + chasecam = (cv_chasecam2.value != 0); + R_SetViewContext(VIEWCONTEXT_PLAYER2); + if (thiscam->reset) + { + R_ResetViewInterpolation(2); + thiscam->reset = false; + } } else { - SETUPCAM(0, cv_chasecam, VIEWCONTEXT_PLAYER1) + thiscam = &camera[0]; + chasecam = (cv_chasecam.value != 0); + R_SetViewContext(VIEWCONTEXT_PLAYER1); + if (thiscam->reset) + { + R_ResetViewInterpolation(1); + thiscam->reset = false; + } } -#undef SETUPCAM if (player->spectator) // no spectator chasecam chasecam = false; // force chasecam off @@ -1435,38 +1428,24 @@ void R_SetupFrame(player_t *player, boolean skybox) { viewmobj = player->awayviewmobj; // should be a MT_ALTVIEWMAN I_Assert(viewmobj != NULL); - - newview->x = viewmobj->x; - newview->y = viewmobj->y; newview->z = viewmobj->z + 20*FRACUNIT; - newview->aim = player->awayviewaiming; newview->angle = viewmobj->angle; - - R_SetupCommonFrame(player, viewmobj->subsector); } else if (!player->spectator && (thiscam && chasecam)) // use outside cam view { viewmobj = NULL; - - newview->x = thiscam->x; - newview->y = thiscam->y; newview->z = thiscam->z + (thiscam->height>>1); - newview->aim = thiscam->aiming; newview->angle = thiscam->angle; - - R_SetupCommonFrame(player, thiscam->subsector); } else // use the player's eyes view { + newview->z = player->viewz; + viewmobj = player->mo; I_Assert(viewmobj != NULL); - newview->x = viewmobj->x; - newview->y = viewmobj->y; - newview->z = player->viewz; - newview->aim = player->aiming; newview->angle = viewmobj->angle; @@ -1491,9 +1470,38 @@ void R_SetupFrame(player_t *player, boolean skybox) } } } - - R_SetupCommonFrame(player, viewmobj->subsector); } + newview->roll = R_ViewRollAngle(player); + newview->z += quake.z; + + newview->player = player; + + if ((thiscam && chasecam) && !player->awayviewtics && !player->spectator) + { + newview->x = thiscam->x; + newview->y = thiscam->y; + newview->x += quake.x; + newview->y += quake.y; + + if (thiscam->subsector && thiscam->subsector->sector) + newview->sector = thiscam->subsector->sector; + else + newview->sector = R_PointInSubsector(newview->x, newview->y)->sector; + } + else + { + newview->x = viewmobj->x; + newview->y = viewmobj->y; + newview->x += quake.x; + newview->y += quake.y; + + if (!P_MobjWasRemoved(viewmobj) && viewmobj->subsector && thiscam && thiscam->subsector->sector) + newview->sector = viewmobj->subsector->sector; + else + newview->sector = R_PointInSubsector(newview->x, newview->y)->sector; + } + + R_InterpolateView(R_UsingFrameInterpolation() ? (demo.playback && demo.freecam) ? rendertimefrac_unpaused : rendertimefrac : FRACUNIT, false); } #define ANGLED_PORTALS From d3e2875c94ac4cec114f2f98e07383d1842b12c7 Mon Sep 17 00:00:00 2001 From: Alug Date: Wed, 16 Oct 2024 12:57:27 +0200 Subject: [PATCH 55/66] =?UTF-8?q?those=20can=20be=20registered=20in=20l?= =?UTF-8?q?=C3=B6=C3=B6p?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/d_netcmd.c | 31 ++++++------------------------- 1 file changed, 6 insertions(+), 25 deletions(-) diff --git a/src/d_netcmd.c b/src/d_netcmd.c index ceaa38e2b..e54251125 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -978,7 +978,6 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_audbuffersize); // m_menu.c - //CV_RegisterVar(&cv_compactscoreboard); CV_RegisterVar(&cv_chatheight); CV_RegisterVar(&cv_chatwidth); CV_RegisterVar(&cv_chattime); @@ -1090,20 +1089,12 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_controlperkey); CV_RegisterVar(&cv_turnsmooth); - CV_RegisterVar(&cv_rumble[0]); - CV_RegisterVar(&cv_rumble[1]); - CV_RegisterVar(&cv_rumble[2]); - CV_RegisterVar(&cv_rumble[3]); - - CV_RegisterVar(&cv_gamepadled[0]); - CV_RegisterVar(&cv_gamepadled[1]); - CV_RegisterVar(&cv_gamepadled[2]); - CV_RegisterVar(&cv_gamepadled[3]); - - CV_RegisterVar(&cv_ledpowerup[0]); - CV_RegisterVar(&cv_ledpowerup[1]); - CV_RegisterVar(&cv_ledpowerup[2]); - CV_RegisterVar(&cv_ledpowerup[3]); + for (i = 0; i < MAXSPLITSCREENPLAYERS; i++) + { + CV_RegisterVar(&cv_rumble[i]); + CV_RegisterVar(&cv_gamepadled[i]); + CV_RegisterVar(&cv_ledpowerup[i]); + } CV_RegisterVar(&cv_usemouse); CV_RegisterVar(&cv_usemouse2); @@ -1207,26 +1198,16 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_speed); CV_RegisterVar(&cv_opflags); CV_RegisterVar(&cv_mapthingnum); - //CV_RegisterVar(&cv_grid); - //CV_RegisterVar(&cv_snapto); // add cheat commands COM_AddCommand("noclip", Command_CheatNoClip_f); COM_AddCommand("god", Command_CheatGod_f); COM_AddCommand("notarget", Command_CheatNoTarget_f); - /*COM_AddCommand("getallemeralds", Command_Getallemeralds_f); - COM_AddCommand("resetemeralds", Command_Resetemeralds_f); - COM_AddCommand("setrings", Command_Setrings_f); - COM_AddCommand("setlives", Command_Setlives_f); - COM_AddCommand("setcontinues", Command_Setcontinues_f);*/ COM_AddCommand("devmode", Command_Devmode_f); COM_AddCommand("savecheckpoint", Command_Savecheckpoint_f); COM_AddCommand("scale", Command_Scale_f); COM_AddCommand("gravflip", Command_Gravflip_f); COM_AddCommand("hurtme", Command_Hurtme_f); - /*COM_AddCommand("jumptoaxis", Command_JumpToAxis_f); - COM_AddCommand("charability", Command_Charability_f); - COM_AddCommand("charspeed", Command_Charspeed_f);*/ COM_AddCommand("teleport", Command_Teleport_f); COM_AddCommand("rteleport", Command_RTeleport_f); COM_AddCommand("skynum", Command_Skynum_f); From afca521fe5b40f1628ebe15900a295c502aba219 Mon Sep 17 00:00:00 2001 From: Alug Date: Thu, 17 Oct 2024 22:54:44 +0200 Subject: [PATCH 56/66] dont run director if theres only one player ingame idk if this is good lol --- src/g_game.h | 12 ++---------- src/k_director.c | 17 ++++++++++++++++- src/st_stuff.c | 2 +- 3 files changed, 19 insertions(+), 12 deletions(-) diff --git a/src/g_game.h b/src/g_game.h index aaafa233c..b00bf1343 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -419,19 +419,9 @@ void G_SetGamestate(gamestate_t newstate); // Gamedata record shit void G_AllocMainRecordData(INT16 i); -//void G_AllocNightsRecordData(INT16 i); void G_ClearRecords(void); -//UINT32 G_GetBestScore(INT16 map); tic_t G_GetBestTime(INT16 map); -//tic_t G_GetBestLap(INT16 map); -//UINT16 G_GetBestRings(INT16 map); -//UINT32 G_GetBestNightsScore(INT16 map, UINT8 mare); -//tic_t G_GetBestNightsTime(INT16 map, UINT8 mare); -//UINT8 G_GetBestNightsGrade(INT16 map, UINT8 mare); - -//void G_AddTempNightsRecords(UINT32 pscore, tic_t ptime, UINT8 mare); -//void G_SetNightsRecords(void); FUNCMATH INT32 G_TicsToHours(tic_t tics); FUNCMATH INT32 G_TicsToMinutes(tic_t tics, boolean full); @@ -439,6 +429,8 @@ FUNCMATH INT32 G_TicsToSeconds(tic_t tics); FUNCMATH INT32 G_TicsToCentiseconds(tic_t tics); FUNCMATH INT32 G_TicsToMilliseconds(tic_t tics); +boolean K_DirectorIsPlayerAlone(void); // idk where else to put this lol + // Don't split up TOL handling INT16 G_TOLFlag(INT32 pgametype); diff --git a/src/k_director.c b/src/k_director.c index 3c5938713..1bbe438b9 100644 --- a/src/k_director.c +++ b/src/k_director.c @@ -38,6 +38,21 @@ struct directorinfo INT32 boredom[MAXPLAYERS]; // how long has a given position had no credible attackers? } directorinfo; +boolean K_DirectorIsPlayerAlone(void) +{ + UINT8 pingame = 0; + + // Gotta check how many players are active at this moment. + for (UINT8 i = 0; i < MAXPLAYERS; i++) + { + if (!playeringame[i] || players[i].spectator) + continue; + pingame++; + } + + return (pingame <= 1); +} + static inline boolean race_rules(void) { return gametype == GT_RACE; @@ -50,7 +65,7 @@ static fixed_t ScaleFromMap(fixed_t n, fixed_t scale) static boolean K_DirectorIsEnabled(void) { - return cv_director.value && !splitscreen && (gamestate == GS_LEVEL && (((stplyr && !stplyr->spectator) && (!playeringame[consoleplayer] || players[consoleplayer].spectator)) || (demo.playback && !demo.freecam && (!demo.title || !modeattacking)))); + return cv_director.value && !splitscreen && (gamestate == GS_LEVEL && (((stplyr && !stplyr->spectator) && (!playeringame[consoleplayer] || players[consoleplayer].spectator)) || (demo.playback && !demo.freecam && (!demo.title || !modeattacking))) && !K_DirectorIsPlayerAlone()); } void K_InitDirector(void) diff --git a/src/st_stuff.c b/src/st_stuff.c index dd6bd5f6b..8b15e711a 100644 --- a/src/st_stuff.c +++ b/src/st_stuff.c @@ -664,7 +664,7 @@ static void ST_overlayDrawer(void) if (!hu_showscores) // hide the following if TAB is held { - if (cv_showdirectorhud.value && ((demo.playback && !demo.freecam && (!demo.title || !modeattacking)) || !P_IsLocalPlayer(stplyr)) && !splitscreen) + if (cv_showdirectorhud.value && !splitscreen && ((demo.playback && !demo.freecam && (!demo.title || !modeattacking)) || !P_IsLocalPlayer(stplyr)) && !K_DirectorIsPlayerAlone()) { char directortext[20] = {0}; From 7a6f43bece9dfbc22022f6605bc5c09fc252f6f5 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 18 Oct 2024 20:34:00 +0200 Subject: [PATCH 57/66] dont show encore toggle text in record attack menu dont think you can even record attack in encore hmm --- src/m_menu.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/m_menu.c b/src/m_menu.c index 101afbd8d..94b5f8f3b 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -9991,16 +9991,19 @@ static void M_DrawLevelSelectOnly(boolean leftfade, boolean rightfade) patch_t *PictureOfLevel; INT32 x, y, w, i, oldval, trans, dupadjust = ((vid.width/vid.dupx) - BASEVIDWIDTH)>>1; - char encoretoggle[32] = {0}; - const char *item1 = gamecontrol[gc_fire][0] != 0 ? G_KeynumToString(gamecontrol[gc_fire][0]) : NULL; - const char *item2 = gamecontrol[gc_fire][1] != 0 ? G_KeynumToString(gamecontrol[gc_fire][1]) : NULL; + if (levellistmode != LLM_RECORDATTACK) // so it doesent show in record attack menu + { + char encoretoggle[32] = {0}; + const char *item1 = gamecontrol[gc_fire][0] != 0 ? G_KeynumToString(gamecontrol[gc_fire][0]) : NULL; + const char *item2 = gamecontrol[gc_fire][1] != 0 ? G_KeynumToString(gamecontrol[gc_fire][1]) : NULL; - if (item1 != NULL && item2 != NULL) - snprintf(encoretoggle, 32, "%s/%s: Toggle Encore", item1, item2); - else - snprintf(encoretoggle, 32, "%s: Toggle Encore", item1 != NULL ? item1 : item2 != NULL ? item2 : "Item"); + if (item1 != NULL && item2 != NULL) + snprintf(encoretoggle, 32, "%s/%s: Toggle Encore", item1, item2); + else + snprintf(encoretoggle, 32, "%s: Toggle Encore", item1 != NULL ? item1 : item2 != NULL ? item2 : "Item"); - V_DrawThinString(1, BASEVIDHEIGHT-8-1, V_SNAPTOLEFT|V_SNAPTOBOTTOM|V_TRANSLUCENT|V_ALLOWLOWERCASE, encoretoggle); + V_DrawThinString(1, BASEVIDHEIGHT-8-1, V_SNAPTOLEFT|V_SNAPTOBOTTOM|V_TRANSLUCENT|V_ALLOWLOWERCASE, encoretoggle); + } // A 160x100 image of the level as entry MAPxxP if (cv_nextmap.value) From fbe97556de4a2b8366af60a1a44b63cc1f934e62 Mon Sep 17 00:00:00 2001 From: Alug Date: Fri, 18 Oct 2024 20:36:16 +0200 Subject: [PATCH 58/66] change versionstring also remove the fbo one, its honestly not necessary anymore --- src/doomdef.h | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/doomdef.h b/src/doomdef.h index ff53c8c8e..046cd6897 100644 --- a/src/doomdef.h +++ b/src/doomdef.h @@ -127,13 +127,8 @@ extern char logfilename[1024]; #else #define VERSION 1 // Game version #define SUBVERSION 6 // more precise version number -#ifndef USE_FBO_OGL -#define VERSIONSTRING "Saturn v7" -#define VERSIONSTRINGW L"Saturn v7" -#else -#define VERSIONSTRING "Saturn v7 - FBO " -#define VERSIONSTRINGW L"Saturn v7 - FBO" -#endif +#define VERSIONSTRING "Saturn v7.1" +#define VERSIONSTRINGW L"Saturn v7.1" // Hey! If you change this, add 1 to the MODVERSION below! Otherwise we can't force updates! // And change CMakeLists.txt (not src/, but in root), for CMake users! // AND appveyor.yml, for the build bots! From 0af52ba3ae2a7f42d194fa71a2616dd714d16107 Mon Sep 17 00:00:00 2001 From: Alug Date: Sat, 19 Oct 2024 21:14:45 +0200 Subject: [PATCH 59/66] dont need to always check this 16 times if we already know theres more than one player ingame --- src/k_director.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/k_director.c b/src/k_director.c index 1bbe438b9..fc6e211f6 100644 --- a/src/k_director.c +++ b/src/k_director.c @@ -47,7 +47,11 @@ boolean K_DirectorIsPlayerAlone(void) { if (!playeringame[i] || players[i].spectator) continue; + pingame++; + + if (pingame >= 2) // we dont need to check further + break; } return (pingame <= 1); From d30c96e8cbcc56c55e96d161731642b3c15a3127 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 20 Oct 2024 00:21:48 +0200 Subject: [PATCH 60/66] fix a maybe-uninitialized warning --- src/r_things.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/r_things.c b/src/r_things.c index 3f96ed419..7c1b7d9b5 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -2448,8 +2448,8 @@ static boolean R_CheckSpriteVisible(vissprite_t *spr, INT32 x1, INT32 x2) INT16 sz = spr->sz; INT16 szt = spr->szt; - fixed_t texturemid, yscale, scalestep = spr->scalestep; - INT32 height; + fixed_t texturemid = 0, yscale = 0, scalestep = spr->scalestep; // "= 0" pleases the compiler + INT32 height = 0; if (scalestep) { From 86ed1b709e7e6e5448081001625c28bdc443bb8e Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 20 Oct 2024 02:01:02 +0200 Subject: [PATCH 61/66] fix some rendering issues and crashes in software renderer - Increase MINZ from 4 fracunits to 16 - R_StoreWallRange: do not render textures with holes - fix off-by-one error in R_ProjectSprite - Avoid rendering unused left/right edges of screen while rolling - Clamp patch column post drawing bounds - Vissprites: set dc.texheight - Add null check for column in R_DrawMaskedColumn --- src/r_draw.c | 1 + src/r_draw.h | 1 + src/r_draw8.c | 107 ++++++++++++++++++++++++++++++++++++++++++++++--- src/r_main.c | 2 +- src/r_segs.c | 20 ++++++--- src/r_things.c | 81 +++++++++++++++++++++++-------------- src/r_things.h | 4 ++ 7 files changed, 174 insertions(+), 42 deletions(-) diff --git a/src/r_draw.c b/src/r_draw.c index fa19a6ac2..faa9ba638 100644 --- a/src/r_draw.c +++ b/src/r_draw.c @@ -78,6 +78,7 @@ fixed_t dc_iscale, dc_texturemid; UINT8 dc_hires; // under MSVC boolean is a byte, while on other systems, it a bit, // soo lets make it a byte on all system for the ASM code UINT8 *dc_source; +INT32 dc_sourcelength; // ----------------------- // translucency stuff here diff --git a/src/r_draw.h b/src/r_draw.h index 58775fe1d..7dbeda7c9 100644 --- a/src/r_draw.h +++ b/src/r_draw.h @@ -62,6 +62,7 @@ extern lighttable_t *ds_colormap; extern fixed_t ds_xfrac, ds_yfrac, ds_xstep, ds_ystep; extern INT32 ds_waterofs, ds_bgofs; extern UINT8 *ds_source; // start of a 64*64 tile image +extern INT32 dc_sourcelength; extern UINT8 *ds_transmap; extern INT32 ds_bgofs; diff --git a/src/r_draw8.c b/src/r_draw8.c index 6aabdb6dd..bf3b9740d 100644 --- a/src/r_draw8.c +++ b/src/r_draw8.c @@ -28,6 +28,8 @@ void R_DrawColumn_8(void) register UINT8 *dest; register fixed_t frac; fixed_t fracstep; + INT32 npow2min; + INT32 npow2max; count = dc_yh - dc_yl; @@ -51,13 +53,26 @@ void R_DrawColumn_8(void) fracstep = dc_iscale; frac = (dc_texturemid + FixedMul((dc_yl << FRACBITS) - centeryfrac, fracstep))*(!dc_hires); - // Inner loop that does the actual texture mapping, e.g. a DDA-like scaling. // This is as fast as it gets. { register const UINT8 *source = dc_source; register const lighttable_t *colormap = dc_colormap; register INT32 heightmask = dc_texheight-1; + + if (dc_sourcelength <= 0) + { + // Note: we need to unconditionally clamp in npow2 draw loop to avoid a CPU branch + // This is to just render it effectively the identity function. + npow2min = INT32_MIN; + npow2max = INT32_MAX; + } + else + { + npow2min = -1; + npow2max = dc_sourcelength; + } + if (dc_texheight & heightmask) // not a power of 2 -- killough { heightmask++; @@ -74,7 +89,10 @@ void R_DrawColumn_8(void) // Re-map color indices from wall texture column // using a lighting/special effects LUT. // heightmask is the Tutti-Frutti fix - *dest = colormap[source[frac>>FRACBITS]]; + + // -1 is the lower clamp bound because column posts have a "safe" byte before the real data + // and a few bytes after as well + *dest = colormap[source[CLAMP(frac>>FRACBITS, npow2min, npow2max)]]; dest += vid.width; // Avoid overflow. @@ -115,6 +133,8 @@ void R_Draw2sMultiPatchColumn_8(void) register UINT8 *dest; register fixed_t frac; fixed_t fracstep; + INT32 npow2min; + INT32 npow2max; count = dc_yh - dc_yl; @@ -147,6 +167,20 @@ void R_Draw2sMultiPatchColumn_8(void) register const lighttable_t *colormap = dc_colormap; register INT32 heightmask = dc_texheight-1; register UINT8 val; + + if (dc_sourcelength <= 0) + { + // Note: we need to unconditionally clamp in npow2 draw loop to avoid a CPU branch + // This is to just render it effectively the identity function. + npow2min = INT32_MIN; + npow2max = INT32_MAX; + } + else + { + npow2min = -1; + npow2max = dc_sourcelength; + } + if (dc_texheight & heightmask) // not a power of 2 -- killough { heightmask++; @@ -163,7 +197,10 @@ void R_Draw2sMultiPatchColumn_8(void) // Re-map color indices from wall texture column // using a lighting/special effects LUT. // heightmask is the Tutti-Frutti fix - val = source[frac>>FRACBITS]; + + // -1 is the lower clamp bound because column posts have a "safe" byte before the real data + // and a few bytes after as well + val = source[CLAMP(frac>>FRACBITS, npow2min, npow2max)]; if (val != TRANSPARENTPIXEL) { @@ -223,6 +260,8 @@ void R_Draw2sMultiPatchTranslucentColumn_8(void) register UINT8 *dest; register fixed_t frac; fixed_t fracstep; + INT32 npow2min; + INT32 npow2max; count = dc_yh - dc_yl; @@ -256,6 +295,20 @@ void R_Draw2sMultiPatchTranslucentColumn_8(void) register const lighttable_t *colormap = dc_colormap; register INT32 heightmask = dc_texheight-1; register UINT8 val; + + if (dc_sourcelength <= 0) + { + // Note: we need to unconditionally clamp in npow2 draw loop to avoid a CPU branch + // This is to just render it effectively the identity function. + npow2min = INT32_MIN; + npow2max = INT32_MAX; + } + else + { + npow2min = -1; + npow2max = dc_sourcelength; + } + if (dc_texheight & heightmask) // not a power of 2 -- killough { heightmask++; @@ -272,7 +325,10 @@ void R_Draw2sMultiPatchTranslucentColumn_8(void) // Re-map color indices from wall texture column // using a lighting/special effects LUT. // heightmask is the Tutti-Frutti fix - val = source[frac>>FRACBITS]; + + // -1 is the lower clamp bound because column posts have a "safe" byte before the real data + // and a few bytes after as well + val = source[CLAMP(frac>>FRACBITS, npow2min, npow2max)]; if (val != TRANSPARENTPIXEL) { @@ -376,6 +432,8 @@ void R_DrawTranslucentColumn_8(void) register INT32 count; register UINT8 *dest; register fixed_t frac, fracstep; + INT32 npow2min; + INT32 npow2max; count = dc_yh - dc_yl + 1; @@ -403,6 +461,20 @@ void R_DrawTranslucentColumn_8(void) register const UINT8 *transmap = dc_transmap; register const lighttable_t *colormap = dc_colormap; register INT32 heightmask = dc_texheight - 1; + + if (dc_sourcelength <= 0) + { + // Note: we need to unconditionally clamp in npow2 draw loop to avoid a CPU branch + // This is to just render it effectively the identity function. + npow2min = INT32_MIN; + npow2max = INT32_MAX; + } + else + { + npow2min = -1; + npow2max = dc_sourcelength; + } + if (dc_texheight & heightmask) { heightmask++; @@ -420,7 +492,11 @@ void R_DrawTranslucentColumn_8(void) // Re-map color indices from wall texture column // using a lighting/special effects LUT. // heightmask is the Tutti-Frutti fix - *dest = *(transmap + (colormap[source[frac>>FRACBITS]]<<8) + (*dest)); + + // -1 is the lower clamp bound because column posts have a "safe" byte before the real data + // and a few bytes after as well + *dest = *(transmap + (colormap[source[CLAMP(frac>>FRACBITS, npow2min, npow2max)]]<<8) + (*dest)); + dest += vid.width; if ((frac += fracstep) >= heightmask) @@ -458,6 +534,8 @@ void R_DrawTranslatedTranslucentColumn_8(void) register INT32 count; register UINT8 *dest; register fixed_t frac, fracstep; + INT32 npow2min; + INT32 npow2max; count = dc_yh - dc_yl + 1; @@ -477,6 +555,20 @@ void R_DrawTranslatedTranslucentColumn_8(void) // This is as fast as it gets. { register INT32 heightmask = dc_texheight - 1; + + if (dc_sourcelength <= 0) + { + // Note: we need to unconditionally clamp in npow2 draw loop to avoid a CPU branch + // This is to just render it effectively the identity function. + npow2min = INT32_MIN; + npow2max = INT32_MAX; + } + else + { + npow2min = -1; + npow2max = dc_sourcelength; + } + if (dc_texheight & heightmask) { heightmask++; @@ -494,7 +586,10 @@ void R_DrawTranslatedTranslucentColumn_8(void) // Re-map color indices from wall texture column // using a lighting/special effects LUT. // heightmask is the Tutti-Frutti fix - *dest = *(dc_transmap + (dc_colormap[dc_translation[dc_source[frac>>FRACBITS]]]<<8) + (*dest)); + + // -1 is the lower clamp bound because column posts have a "safe" byte before the real data + // and a few bytes after as well + *dest = *(dc_transmap + (dc_colormap[dc_translation[dc_source[CLAMP(frac>>FRACBITS, npow2min, npow2max)]]]<<8) + (*dest)); dest += vid.width; if ((frac += fracstep) >= heightmask) diff --git a/src/r_main.c b/src/r_main.c index 75ff41126..2f7ecfb6e 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -1706,7 +1706,7 @@ void R_RenderPlayerView(player_t *player) else { portalclipstart = 0; - portalclipend = viewwidth-1; + portalclipend = viewwidth; R_ClearClipSegs(); } R_ClearDrawSegs(); diff --git a/src/r_segs.c b/src/r_segs.c index e89a10780..452351aa3 100644 --- a/src/r_segs.c +++ b/src/r_segs.c @@ -275,6 +275,7 @@ static void R_Render2sidedMultiPatchColumn(column_t *column) if (dc_yl <= dc_yh && dc_yh < vid.height && dc_yh > 0) { dc_source = (UINT8 *)column + 3; + dc_sourcelength = 0; if (colfunc == wallcolfunc) twosmultipatchfunc(); @@ -1446,6 +1447,7 @@ static void R_RenderSegLoop (void) dc_texturemid = rw_midtexturemid; dc_source = R_GetColumn(midtexture,texturecolumn); dc_texheight = textureheight[midtexture]>>FRACBITS; + dc_sourcelength = 0; colfunc(); // dont draw anything more for this column, since @@ -1493,6 +1495,7 @@ static void R_RenderSegLoop (void) dc_texturemid = rw_toptexturemid; dc_source = R_GetColumn(toptexture,texturecolumn); dc_texheight = textureheight[toptexture]>>FRACBITS; + dc_sourcelength = 0; colfunc(); ceilingclip[rw_x] = (INT16)mid; } @@ -1530,6 +1533,7 @@ static void R_RenderSegLoop (void) dc_source = R_GetColumn(bottomtexture, texturecolumn); dc_texheight = textureheight[bottomtexture]>>FRACBITS; + dc_sourcelength = 0; colfunc(); floorclip[rw_x] = (INT16)mid; } @@ -1605,6 +1609,12 @@ static INT64 R_CalcSegDist(seg_t* seg, INT64 x2, INT64 y2) } } +static inline INT32 get_flat_tex (INT32 texnum) +{ + texnum = R_GetTextureNum(texnum); + return textures[texnum]->holes ? 0 : texnum; // R_DrawWallColumn cannot render holey textures +} + // // R_StoreWallRange // A wall segment will be drawn @@ -1862,7 +1872,7 @@ void R_StoreWallRange(INT32 start, INT32 stop) { fixed_t texheight; // single sided line - midtexture = R_GetTextureNum(sidedef->midtexture); + midtexture = get_flat_tex(sidedef->midtexture); texheight = textureheight[midtexture]; // a single sided line is terminal, so it must mark ends markfloor = markceiling = true; @@ -2045,15 +2055,15 @@ void R_StoreWallRange(INT32 start, INT32 stop) { // Special case... use offsets from 2nd side but only if it has a texture. side_t *def = &sides[linedef->sidenum[1]]; - toptexture = R_GetTextureNum(def->toptexture); + toptexture = get_flat_tex(def->toptexture); if (!toptexture) //Second side has no texture, use the first side's instead. - toptexture = R_GetTextureNum(sidedef->toptexture); + toptexture = get_flat_tex(sidedef->toptexture); texheight = textureheight[toptexture]; } else { - toptexture = R_GetTextureNum(sidedef->toptexture); + toptexture = get_flat_tex(sidedef->toptexture); texheight = textureheight[toptexture]; } if (!(linedef->flags & ML_EFFECT1)) { // Ignore slopes for lower/upper textures unless flag is checked @@ -2078,7 +2088,7 @@ void R_StoreWallRange(INT32 start, INT32 stop) if (worldlow > worldbottom || worldlowslope > worldbottomslope) // Only if VISIBLE!!! { // bottom texture - bottomtexture = R_GetTextureNum(sidedef->bottomtexture); + bottomtexture = get_flat_tex(sidedef->bottomtexture); if (!(linedef->flags & ML_EFFECT1)) { // Ignore slopes for lower/upper textures unless flag is checked if (linedef->flags & ML_DONTPEGBOTTOM) diff --git a/src/r_things.c b/src/r_things.c index 7c1b7d9b5..a5c09dc13 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -43,7 +43,7 @@ CV_PossibleValue_t Forceskin_cons_t[MAXSKINS+2]; static void R_InitSkins(void); -#define MINZ (FRACUNIT*4) +#define MINZ (FRACUNIT*16) #define BASEYCENTER (BASEVIDHEIGHT/2) typedef struct @@ -583,6 +583,9 @@ void R_DrawMaskedColumn(column_t *column) basetexturemid = dc_texturemid; + if (!column || column == 0) + return; + for (; column->topdelta != 0xff ;) { // calculate unclipped screen coordinates @@ -618,6 +621,7 @@ void R_DrawMaskedColumn(column_t *column) if (dc_yl <= dc_yh && dc_yh > 0 && column->length != 0) { dc_source = (UINT8 *)column + 3; + dc_sourcelength = column->length; dc_texturemid = basetexturemid - (topdelta< 0 && column->length != 0) { dc_source = ZZ_Alloc(column->length); + dc_sourcelength = column->length; for (s = (UINT8 *)column+2+column->length, d = dc_source; d < dc_source+column->length; --s) *d++ = *s; dc_texturemid = basetexturemid - (topdelta<texturemid; - dc_texheight = 0; + dc_texheight = SHORT(patch->height); frac = vis->startfrac; windowtop = windowbottom = sprbotscreen = INT32_MAX; @@ -808,8 +813,10 @@ static void R_DrawVisSprite(vissprite_t *vis) this_scale = FixedMul(this_scale, ((skin_t *)vis->mobj->localskin)->highresscale); else if (vis->mobj->skin && ((skin_t *)vis->mobj->skin)->flags & SF_HIRES) this_scale = FixedMul(this_scale, ((skin_t *)vis->mobj->skin)->highresscale); + if (this_scale <= 0) this_scale = 1; + if (this_scale != FRACUNIT) { if (!vis->isScaled) @@ -875,12 +882,10 @@ static void R_DrawVisSprite(vissprite_t *vis) } else { - pwidth = SHORT(patch->width); - // Non-paper drawing loop for (dc_x = vis->x1; dc_x <= vis->x2; dc_x++, frac += vis->xiscale) - { - texturecolumn = CLAMP(frac >> FRACBITS, 0, pwidth - 1); + { + texturecolumn = CLAMP(frac >> FRACBITS, 0, SHORT(patch->width) - 1); column = (column_t *)((UINT8 *)patch + LONG(patch->columnofs[texturecolumn])); localcolfunc (column); @@ -926,7 +931,7 @@ static void R_DrawPrecipitationVisSprite(vissprite_t *vis) dc_iscale = FixedDiv(FRACUNIT, vis->scale); dc_texturemid = FixedDiv(vis->texturemid, this_scale); - dc_texheight = 0; + dc_texheight = SHORT(patch->height); frac = vis->startfrac; spryscale = vis->scale; @@ -941,7 +946,14 @@ static void R_DrawPrecipitationVisSprite(vissprite_t *vis) for (dc_x = vis->x1; dc_x <= vis->x2; dc_x++, frac += vis->xiscale) { - texturecolumn = CLAMP(frac >> FRACBITS, 0, SHORT(patch->width) - 1); + texturecolumn = frac>>FRACBITS; + + if (texturecolumn < 0 || texturecolumn >= patch->width) + { + CONS_Debug(DBG_RENDER, "R_DrawPrecipitationSpriteRange: bad texturecolumn\n"); + break; + } + column = (column_t *)((UINT8 *)patch + LONG(patch->columnofs[texturecolumn])); R_DrawMaskedColumn(column); @@ -1110,6 +1122,7 @@ static void R_ProjectSprite(mobj_t *thing) fixed_t xscale, yscale, sortscale; //added : 02-02-98 : aaargll..if I were a math-guy!!! INT32 x1, x2; + INT32 x1test = 0, x2test = 0; spritedef_t *sprdef; spriteframe_t *sprframe; @@ -1512,6 +1525,11 @@ static void R_ProjectSprite(mobj_t *thing) //x1 = (centerxfrac + FixedMul(tx,xscale))>>FRACBITS; x1 = centerx + (FixedMul(tx,xscale) / FRACUNIT); + x1test = (centerxfrac + FixedMul(tx,xscale))>>FRACBITS; + + if (x1test > viewwidth) + x1test = 0; + // off the right side? if (x1 > viewwidth) return; @@ -1520,6 +1538,11 @@ static void R_ProjectSprite(mobj_t *thing) //x2 = ((centerxfrac + FixedMul(tx,xscale))>>FRACBITS); x2--; x2 = (centerx + (FixedMul(tx,xscale) / FRACUNIT)) - 1; + x2test = ((centerxfrac + FixedMul(tx,xscale))>>FRACBITS) - 1; + + if (x2test < 0) + x2test = 0; + // off the left side if (x2 < 0) return; @@ -1528,9 +1551,15 @@ static void R_ProjectSprite(mobj_t *thing) // PORTAL SPRITE CLIPPING if (portalrender && portalclipline) { - if (x2 < portalclipstart || x1 > portalclipend) + if (x2 < portalclipstart || x1 >= portalclipend) return; + if (x2test < portalclipstart || x1test >= portalclipend) + { + x1test = 0; + x2test = 0; + } + if (P_PointOnLineSide(interp.x, interp.y, portalclipline) != 0) return; } @@ -1621,17 +1650,11 @@ static void R_ProjectSprite(mobj_t *thing) vis->mobj = thing; // Easy access! Tails 06-07-2002 - vis->x1 = x1 < 0 ? 0 : x1; - vis->x2 = x2 >= viewwidth ? viewwidth-1 : x2; + vis->x1 = x1 < portalclipstart ? portalclipstart : x1; + vis->x2 = x2 >= portalclipend ? portalclipend-1 : x2; - // PORTAL SEMI-CLIPPING - if (portalrender && portalclipline) - { - if (vis->x1 < portalclipstart) - vis->x1 = portalclipstart; - if (vis->x2 > portalclipend) - vis->x2 = portalclipend; - } + vis->x1test = x1test < portalclipstart ? portalclipstart : x1test; + vis->x2test = x2test >= portalclipend ? portalclipend-1 : x2test; vis->sector = thing->subsector->sector; vis->szt = (INT16)((centeryfrac - FixedMul(vis->gzt - viewz, sortscale))>>FRACBITS); @@ -1658,6 +1681,7 @@ static void R_ProjectSprite(mobj_t *thing) { vis->startfrac = spr_width-1; vis->xiscale = -iscale; + vis->xiscaletest = -vis->xiscaletest; } else { @@ -1665,10 +1689,13 @@ static void R_ProjectSprite(mobj_t *thing) vis->xiscale = iscale; } + vis->startfractest = vis->startfrac; + if (vis->x1 > x1) { vis->startfrac += FixedDiv(vis->xiscale, this_scale) * (vis->x1 - x1); vis->scale += FixedMul(scalestep, spriteyscale) * (vis->x1 - x1); + vis->startfractest += FixedDiv(vis->xiscaletest, this_scale) * (vis->x1test - x1test); } //Fab: lumppat is the lump number of the patch to use, this is different @@ -1841,7 +1868,7 @@ static void R_ProjectPrecipitationSprite(precipmobj_t *thing) // PORTAL SPRITE CLIPPING if (portalrender && portalclipline) { - if (x2 < portalclipstart || x1 > portalclipend) + if (x2 < portalclipstart || x1 >= portalclipend) return; if (P_PointOnLineSide(interp.x, interp.y, portalclipline) != 0) @@ -1875,17 +1902,11 @@ static void R_ProjectPrecipitationSprite(precipmobj_t *thing) vis->scalestep = 0; vis->paperdistance = 0; - vis->x1 = x1 < 0 ? 0 : x1; - vis->x2 = x2 >= viewwidth ? viewwidth-1 : x2; + vis->x1 = x1 < portalclipstart ? portalclipstart : x1; + vis->x2 = x2 >= portalclipend ? portalclipend-1 : x2; - // PORTAL SEMI-CLIPPING - if (portalrender && portalclipline) - { - if (vis->x1 < portalclipstart) - vis->x1 = portalclipstart; - if (vis->x2 > portalclipend) - vis->x2 = portalclipend; - } + vis->x1test = 0; + vis->x2test = 0; vis->xscale = xscale; //SoM: 4/17/2000 vis->sector = thing->subsector->sector; diff --git a/src/r_things.h b/src/r_things.h index 0e99c490c..ce0f9f841 100644 --- a/src/r_things.h +++ b/src/r_things.h @@ -55,6 +55,7 @@ extern fixed_t sprtopscreen; extern fixed_t sprbotscreen; extern fixed_t windowtop; extern fixed_t windowbottom; +extern INT32 lengthcol; fixed_t R_GetShadowZ(mobj_t *thing, pslope_t **shadowslope); @@ -142,6 +143,9 @@ typedef struct vissprite_s mobj_t *mobj; // for easy access INT32 x1, x2; + INT32 x1test, x2test; + fixed_t xiscaletest; + fixed_t startfractest; fixed_t gx, gy; // for line side calculation fixed_t gz, gzt; // global bottom/top for silhouette clipping From 7076c35521bdd1d7b9e73d94e94839824b036b88 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 20 Oct 2024 04:14:54 +0200 Subject: [PATCH 62/66] HWR_RenderPlane can be static --- src/hardware/hw_main.c | 2 +- src/hardware/hw_main.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/hardware/hw_main.c b/src/hardware/hw_main.c index 5d243d4c3..741e29814 100644 --- a/src/hardware/hw_main.c +++ b/src/hardware/hw_main.c @@ -652,7 +652,7 @@ static FUINT HWR_CalcSlopeLight(FUINT lightnum, pslope_t *slope) // HWR_RenderPlane // Render a floor or ceiling convex polygon -void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, boolean isceiling, fixed_t fixedheight, FBITFIELD PolyFlags, INT32 lightlevel, lumpnum_t lumpnum, sector_t *FOFsector, UINT8 alpha, extracolormap_t *planecolormap) +static void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, boolean isceiling, fixed_t fixedheight, FBITFIELD PolyFlags, INT32 lightlevel, lumpnum_t lumpnum, sector_t *FOFsector, UINT8 alpha, extracolormap_t *planecolormap) { FSurfaceInfo Surf; FOutVector *v3d; diff --git a/src/hardware/hw_main.h b/src/hardware/hw_main.h index bd6258ef4..2abb6dda6 100644 --- a/src/hardware/hw_main.h +++ b/src/hardware/hw_main.h @@ -116,7 +116,7 @@ void HWR_MakeScreenFinalTexture(void); void HWR_DrawScreenFinalTexture(INT32 width, INT32 height); // hw_main.c: Planes -void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, boolean isceiling, fixed_t fixedheight, FBITFIELD PolyFlags, INT32 lightlevel, lumpnum_t lumpnum, sector_t *FOFsector, UINT8 alpha, extracolormap_t *planecolormap); +//void HWR_RenderPlane(subsector_t *subsector, extrasubsector_t *xsub, boolean isceiling, fixed_t fixedheight, FBITFIELD PolyFlags, INT32 lightlevel, lumpnum_t lumpnum, sector_t *FOFsector, UINT8 alpha, extracolormap_t *planecolormap); void HWR_AddTransparentFloor(lumpnum_t lumpnum, extrasubsector_t *xsub, boolean isceiling, fixed_t fixedheight, INT32 lightlevel, INT32 alpha, sector_t *FOFSector, FBITFIELD blend, boolean fogplane, extracolormap_t *planecolormap); void HWR_RenderPolyObjectPlane(polyobj_t *polysector, boolean isceiling, fixed_t fixedheight, FBITFIELD blendmode, UINT8 lightlevel, lumpnum_t lumpnum, sector_t *FOFsector, UINT8 alpha, extracolormap_t *planecolormap); From c6fbf405bf06bba7cf30fdea4fcc68d1285a4bcc Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 20 Oct 2024 15:16:37 +0200 Subject: [PATCH 63/66] optimize R_PointOnSegSide its only used for 2 rendering functions, so being potentially inaccurate is not that dangerous and the speedup in some instances might be worth the tradeoff --- src/r_main.c | 23 ----------------------- src/r_main.h | 13 ++++++++++++- 2 files changed, 12 insertions(+), 24 deletions(-) diff --git a/src/r_main.c b/src/r_main.c index 2f7ecfb6e..4d79fda92 100644 --- a/src/r_main.c +++ b/src/r_main.c @@ -325,29 +325,6 @@ PUREFUNC INT32 R_PointOnSide(fixed_t x, fixed_t y, const node_t *restrict node) (~mask & (FixedMul(y, node->dx>>FRACBITS) >= FixedMul(node->dy>>FRACBITS, x))); } -// killough 5/2/98: reformatted -PUREFUNC INT32 R_PointOnSegSide(fixed_t x, fixed_t y, const seg_t *line) -{ - fixed_t lx = line->v1->x; - fixed_t ly = line->v1->y; - fixed_t ldx = line->v2->x - lx; - fixed_t ldy = line->v2->y - ly; - - if (!ldx) - return x <= lx ? ldy > 0 : ldy < 0; - - if (!ldy) - return y <= ly ? ldx < 0 : ldx > 0; - - x -= lx; - y -= ly; - - // Try to quickly decide by looking at sign bits. - if ((ldy ^ ldx ^ x ^ y) < 0) - return (ldy ^ x) < 0; // (left is negative) - return FixedMul(y, ldx>>FRACBITS) >= FixedMul(ldy>>FRACBITS, x); -} - // // R_PointToAngle // To get a global angle from cartesian coordinates, diff --git a/src/r_main.h b/src/r_main.h index 2d7503ea7..0bfa8bfa5 100644 --- a/src/r_main.h +++ b/src/r_main.h @@ -73,7 +73,18 @@ extern lighttable_t *zlight[LIGHTLEVELS][MAXLIGHTZ]; // Utility functions. INT32 R_PointOnSide(fixed_t x, fixed_t y, const node_t *node); -INT32 R_PointOnSegSide(fixed_t x, fixed_t y, const seg_t *line); + +FUNCINLINE static ATTRINLINE PUREFUNC INT32 R_PointOnSegSide(fixed_t x, fixed_t y, const seg_t *line) +{ + fixed_t lx = line->v1->x; + fixed_t ly = line->v1->y; + fixed_t ldx = line->v2->x - lx; + fixed_t ldy = line->v2->y - ly; + + // heavily optimized version of R_PointOnSide, stolen from GZDoom. + return (INT64)(y - ly) * ldx + (INT64)(lx - x) * ldy > 0; +} + angle_t R_PointToAngle(fixed_t x, fixed_t y); angle_t R_PointToAngle64(INT64 x, INT64 y); angle_t R_PointToAngle2(fixed_t px2, fixed_t py2, fixed_t px1, fixed_t py1); From 2c665fef6f5b177b09790abfb9b076cc792e49e1 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 20 Oct 2024 15:21:42 +0200 Subject: [PATCH 64/66] remove this again --- src/r_things.c | 27 --------------------------- src/r_things.h | 3 --- 2 files changed, 30 deletions(-) diff --git a/src/r_things.c b/src/r_things.c index a5c09dc13..61fdef8dc 100644 --- a/src/r_things.c +++ b/src/r_things.c @@ -1122,7 +1122,6 @@ static void R_ProjectSprite(mobj_t *thing) fixed_t xscale, yscale, sortscale; //added : 02-02-98 : aaargll..if I were a math-guy!!! INT32 x1, x2; - INT32 x1test = 0, x2test = 0; spritedef_t *sprdef; spriteframe_t *sprframe; @@ -1525,11 +1524,6 @@ static void R_ProjectSprite(mobj_t *thing) //x1 = (centerxfrac + FixedMul(tx,xscale))>>FRACBITS; x1 = centerx + (FixedMul(tx,xscale) / FRACUNIT); - x1test = (centerxfrac + FixedMul(tx,xscale))>>FRACBITS; - - if (x1test > viewwidth) - x1test = 0; - // off the right side? if (x1 > viewwidth) return; @@ -1538,11 +1532,6 @@ static void R_ProjectSprite(mobj_t *thing) //x2 = ((centerxfrac + FixedMul(tx,xscale))>>FRACBITS); x2--; x2 = (centerx + (FixedMul(tx,xscale) / FRACUNIT)) - 1; - x2test = ((centerxfrac + FixedMul(tx,xscale))>>FRACBITS) - 1; - - if (x2test < 0) - x2test = 0; - // off the left side if (x2 < 0) return; @@ -1554,12 +1543,6 @@ static void R_ProjectSprite(mobj_t *thing) if (x2 < portalclipstart || x1 >= portalclipend) return; - if (x2test < portalclipstart || x1test >= portalclipend) - { - x1test = 0; - x2test = 0; - } - if (P_PointOnLineSide(interp.x, interp.y, portalclipline) != 0) return; } @@ -1653,9 +1636,6 @@ static void R_ProjectSprite(mobj_t *thing) vis->x1 = x1 < portalclipstart ? portalclipstart : x1; vis->x2 = x2 >= portalclipend ? portalclipend-1 : x2; - vis->x1test = x1test < portalclipstart ? portalclipstart : x1test; - vis->x2test = x2test >= portalclipend ? portalclipend-1 : x2test; - vis->sector = thing->subsector->sector; vis->szt = (INT16)((centeryfrac - FixedMul(vis->gzt - viewz, sortscale))>>FRACBITS); vis->sz = (INT16)((centeryfrac - FixedMul(vis->gz - viewz, sortscale))>>FRACBITS); @@ -1681,7 +1661,6 @@ static void R_ProjectSprite(mobj_t *thing) { vis->startfrac = spr_width-1; vis->xiscale = -iscale; - vis->xiscaletest = -vis->xiscaletest; } else { @@ -1689,13 +1668,10 @@ static void R_ProjectSprite(mobj_t *thing) vis->xiscale = iscale; } - vis->startfractest = vis->startfrac; - if (vis->x1 > x1) { vis->startfrac += FixedDiv(vis->xiscale, this_scale) * (vis->x1 - x1); vis->scale += FixedMul(scalestep, spriteyscale) * (vis->x1 - x1); - vis->startfractest += FixedDiv(vis->xiscaletest, this_scale) * (vis->x1test - x1test); } //Fab: lumppat is the lump number of the patch to use, this is different @@ -1905,9 +1881,6 @@ static void R_ProjectPrecipitationSprite(precipmobj_t *thing) vis->x1 = x1 < portalclipstart ? portalclipstart : x1; vis->x2 = x2 >= portalclipend ? portalclipend-1 : x2; - vis->x1test = 0; - vis->x2test = 0; - vis->xscale = xscale; //SoM: 4/17/2000 vis->sector = thing->subsector->sector; vis->szt = (INT16)((centeryfrac - FixedMul(vis->gzt - viewz, yscale))>>FRACBITS); diff --git a/src/r_things.h b/src/r_things.h index ce0f9f841..898cc7ecd 100644 --- a/src/r_things.h +++ b/src/r_things.h @@ -143,9 +143,6 @@ typedef struct vissprite_s mobj_t *mobj; // for easy access INT32 x1, x2; - INT32 x1test, x2test; - fixed_t xiscaletest; - fixed_t startfractest; fixed_t gx, gy; // for line side calculation fixed_t gz, gzt; // global bottom/top for silhouette clipping From de1b801bdaec9e6cfde830e7807f08dde7b58498 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 20 Oct 2024 15:59:31 +0200 Subject: [PATCH 65/66] try to take some registers for span drawers too --- src/r_draw8.c | 57 ++++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/src/r_draw8.c b/src/r_draw8.c index bf3b9740d..3c7562beb 100644 --- a/src/r_draw8.c +++ b/src/r_draw8.c @@ -681,14 +681,14 @@ void R_DrawSpan_8 (void) fixed_t xposition; fixed_t yposition; fixed_t xstep, ystep; - UINT32 bit; + register UINT32 bit; UINT8 *source; UINT8 *colormap; - UINT8 *dest; + register UINT8 *dest; const UINT8 *deststop = screens[0] + vid.rowbytes * vid.height; - size_t count = (ds_x2 - ds_x1 + 1); + register size_t count = (ds_x2 - ds_x1 + 1); size_t i; xposition = ds_xfrac; yposition = ds_yfrac; @@ -776,13 +776,13 @@ void R_DrawTiltedSpan_8(void) UINT8 *source; UINT8 *colormap; - UINT8 *dest; + register UINT8 *dest; double startz, startu, startv; double izstep, uzstep, vzstep; double endz, endu, endv; UINT32 stepu, stepv; - UINT32 bit; + register UINT32 bit; iz = ds_szp->z + ds_szp->y*(centery-ds_y) + ds_szp->x*(ds_x1-centerx); @@ -917,13 +917,13 @@ void R_DrawTiltedTranslucentSpan_8(void) UINT8 *source; UINT8 *colormap; - UINT8 *dest; + register UINT8 *dest; double startz, startu, startv; double izstep, uzstep, vzstep; double endz, endu, endv; UINT32 stepu, stepv; - UINT32 bit; + register UINT32 bit; iz = ds_szp->z + ds_szp->y*(centery-ds_y) + ds_szp->x*(ds_x1-centerx); @@ -1059,14 +1059,14 @@ void R_DrawTiltedTranslucentWaterSpan_8(void) UINT8 *source; UINT8 *colormap; - UINT8 *dest; + register UINT8 *dest; UINT8 *dsrc; double startz, startu, startv; double izstep, uzstep, vzstep; double endz, endu, endv; UINT32 stepu, stepv; - UINT32 bit; + register UINT32 bit; iz = ds_szp->z + ds_szp->y*(centery-ds_y) + ds_szp->x*(ds_x1-centerx); @@ -1200,7 +1200,7 @@ void R_DrawTiltedSplat_8(void) UINT8 *source; UINT8 *colormap; - UINT8 *dest; + register UINT8 *dest; UINT8 val; @@ -1208,7 +1208,7 @@ void R_DrawTiltedSplat_8(void) double izstep, uzstep, vzstep; double endz, endu, endv; UINT32 stepu, stepv; - UINT32 bit; + register UINT32 bit; iz = ds_szp->z + ds_szp->y*(centery-ds_y) + ds_szp->x*(ds_x1-centerx); @@ -1352,13 +1352,13 @@ void R_DrawSplat_8 (void) UINT32 xposition; UINT32 yposition; UINT32 xstep, ystep; - UINT32 bit; + register UINT32 bit; UINT8 *source; UINT8 *colormap; - UINT8 *dest; + register UINT8 *dest; - size_t count; + register size_t count; size_t i; UINT32 val; @@ -1422,13 +1422,13 @@ void R_DrawTranslucentSplat_8 (void) UINT32 xposition; UINT32 yposition; UINT32 xstep, ystep; - UINT32 bit; + register UINT32 bit; UINT8 *source; UINT8 *colormap; - UINT8 *dest; + register UINT8 *dest; - size_t count; + register size_t count; size_t i; UINT8 val; @@ -1487,14 +1487,14 @@ void R_DrawTranslucentSpan_8 (void) fixed_t xposition; fixed_t yposition; fixed_t xstep, ystep; - UINT32 bit; + register UINT32 bit; UINT8 *source; UINT8 *colormap; - UINT8 *dest; + register UINT8 *dest; const UINT8 *deststop = screens[0] + vid.rowbytes * vid.height; - size_t count = (ds_x2 - ds_x1 + 1); + register size_t count = (ds_x2 - ds_x1 + 1); size_t i; xposition = ds_xfrac; yposition = ds_yfrac; @@ -1546,14 +1546,14 @@ void R_DrawTranslucentWaterSpan_8(void) UINT32 xposition; UINT32 yposition; UINT32 xstep, ystep; - UINT32 bit; + register UINT32 bit; UINT8 *source; UINT8 *colormap; - UINT8 *dest; + register UINT8 *dest; UINT8 *dsrc; - size_t count; + register size_t count; size_t i; // SoM: we only need 6 bits for the integer part (0 thru 63) so the rest @@ -1605,9 +1605,9 @@ void R_DrawTranslucentWaterSpan_8(void) void R_DrawFogSpan_8(void) { UINT8 *colormap; - UINT8 *dest; + register UINT8 *dest; - size_t count; + register size_t count; colormap = ds_colormap; //dest = ylookup[ds_y] + columnofs[ds_x1]; @@ -1638,8 +1638,8 @@ void R_DrawFogSpan_8(void) */ void R_DrawFogColumn_8(void) { - INT32 count; - UINT8 *dest; + register INT32 count; + register UINT8 *dest; count = dc_yh - dc_yl; @@ -1674,7 +1674,8 @@ void R_DrawFogColumn_8(void) */ void R_DrawColumnShadowed_8(void) { - INT32 count, realyh, i, height, bheight = 0, solid = 0; + register INT32 count; + INT32 realyh, i, height, bheight = 0, solid = 0; realyh = dc_yh; From 81d415c5ba9bc62b7344f5e10d0573e70c975ae9 Mon Sep 17 00:00:00 2001 From: Alug Date: Sun, 20 Oct 2024 16:25:12 +0200 Subject: [PATCH 66/66] attempt to optimize some p_maputl stuff --- src/p_maputl.c | 91 +++++++++++++++----------------------------------- 1 file changed, 27 insertions(+), 64 deletions(-) diff --git a/src/p_maputl.c b/src/p_maputl.c index 3c91dc922..f2fc0867e 100644 --- a/src/p_maputl.c +++ b/src/p_maputl.c @@ -35,33 +35,23 @@ void P_ClosestPointOnLine(fixed_t x, fixed_t y, line_t *line, vertex_t *result) fixed_t dy = line->dy; // Determine t (the length of the vector from �Line[0]� to �p�) - fixed_t cx, cy; - fixed_t vx, vy; fixed_t magnitude; fixed_t t; - //Sub (p, &Line[0], &c); - cx = x - startx; - cy = y - starty; - - //Sub (&Line[1], &Line[0], &V); - vx = dx; - vy = dy; - //Normalize (&V, &V); magnitude = R_PointToDist2(line->v2->x, line->v2->y, startx, starty); - vx = FixedDiv(vx, magnitude); - vy = FixedDiv(vy, magnitude); + dx = FixedDiv(dx, magnitude); + dy = FixedDiv(dy, magnitude); - t = (FixedMul(vx, cx) + FixedMul(vy, cy)); + t = (FixedMul(dx, (x - startx)) + FixedMul(dy, (y - starty))); // Return the point between �Line[0]� and �Line[1]� - vx = FixedMul(vx, t); - vy = FixedMul(vy, t); + dx = FixedMul(dx, t); + dy = FixedMul(dy, t); //Add (&Line[0], &V, out); - result->x = startx + vx; - result->y = starty + vy; + result->x = startx + dx; + result->y = starty + dy; return; } @@ -79,28 +69,15 @@ void P_ClosestPointOnLine3D(fixed_t x, fixed_t y, fixed_t z, line_t *line, verte fixed_t dz = line->v2->z - line->v1->z; // Determine t (the length of the vector from �Line[0]� to �p�) - fixed_t cx, cy, cz; - fixed_t vx, vy, vz; fixed_t magnitude; fixed_t t; - //Sub (p, &Line[0], &c); - cx = x - startx; - cy = y - starty; - cz = z - startz; - - //Sub (&Line[1], &Line[0], &V); - vx = dx; - vy = dy; - vz = dz; - - //Normalize (&V, &V); magnitude = R_PointToDist2(0, line->v2->z, R_PointToDist2(line->v2->x, line->v2->y, startx, starty), startz); - vx = FixedDiv(vx, magnitude); - vy = FixedDiv(vy, magnitude); - vz = FixedDiv(vz, magnitude); + dx = FixedDiv(dx, magnitude); + dy = FixedDiv(dy, magnitude); + dz = FixedDiv(dz, magnitude); - t = (FixedMul(vx, cx) + FixedMul(vy, cy) + FixedMul(vz, cz)); + t = (FixedMul(dx, (x - startx)) + FixedMul(dy, (y - starty)) + FixedMul(dz, (z - startz))); // Set closest point to the end if it extends past -Red if (t <= 0) @@ -119,14 +96,14 @@ void P_ClosestPointOnLine3D(fixed_t x, fixed_t y, fixed_t z, line_t *line, verte } // Return the point between �Line[0]� and �Line[1]� - vx = FixedMul(vx, t); - vy = FixedMul(vy, t); - vz = FixedMul(vz, t); + dx = FixedMul(dx, t); + dy = FixedMul(dy, t); + dz = FixedMul(dz, t); //Add (&Line[0], &V, out); - result->x = startx + vx; - result->y = starty + vy; - result->z = startz + vz; + result->x = startx + dx; + result->y = starty + dy; + result->z = startz + dz; return; } @@ -136,21 +113,16 @@ void P_ClosestPointOnLine3D(fixed_t x, fixed_t y, fixed_t z, line_t *line, verte // INT32 P_PointOnLineSide(fixed_t x, fixed_t y, const line_t *line) { - fixed_t dx, dy, left, right; - if (!line->dx) return x <= line->v1->x ? line->dy > 0 : line->dy < 0; if (!line->dy) return y <= line->v1->y ? line->dx < 0 : line->dx > 0; - dx = (x - line->v1->x); - dy = (y - line->v1->y); + x -= line->v1->x; + y -= line->v1->y; - left = FixedMul(line->dy>>FRACBITS, dx); - right = FixedMul(dy, line->dx>>FRACBITS); - - return right < left ? 0 : 1; + return FixedMul(y, line->dx>>FRACBITS) < FixedMul(line->dy>>FRACBITS, x) ? 0 : 1; } // @@ -210,28 +182,22 @@ INT32 P_BoxOnLineSide(fixed_t *tmbox, const line_t *ld) // static INT32 P_PointOnDivlineSide(fixed_t x, fixed_t y, divline_t *line) { - fixed_t dx, dy, left, right; - if (!line->dx) return x <= line->x ? line->dy > 0 : line->dy < 0; if (!line->dy) return y <= line->y ? line->dx < 0 : line->dx > 0; - dx = (x - line->x); - dy = (y - line->y); + x -= line->x; + y -= line->y; // try to quickly decide by looking at sign bits - if ((line->dy ^ line->dx ^ dx ^ dy) & 0x80000000) - return ((line->dy ^ dx) & 0x80000000) ? 1 : 0; + if ((line->dy ^ line->dx ^ x ^ y) & 0x80000000) + return ((line->dy ^ x) & 0x80000000) ? 1 : 0; - left = FixedMul(line->dy>>8, dx>>8); - right = FixedMul(dy>>8, line->dx>>8); - - return right < left ? 0 : 1; + return FixedMul(y>>8, line->dx>>8) < FixedMul(line->dy>>8, x>>8) ? 0 : 1; } - // // P_MakeDivline // @@ -250,17 +216,14 @@ void P_MakeDivline(line_t *li, divline_t *dl) // fixed_t P_InterceptVector(divline_t *v2, divline_t *v1) { - fixed_t frac, num, den; + fixed_t den; den = FixedMul(v1->dy>>8, v2->dx) - FixedMul(v1->dx>>8, v2->dy); if (!den) return 0; - num = FixedMul((v1->x - v2->x)>>8, v1->dy) + FixedMul((v2->y - v1->y)>>8, v1->dx); - frac = FixedDiv(num, den); - - return frac; + return (FixedDiv(FixedMul((v1->x - v2->x)>>8, v1->dy) + FixedMul((v2->y - v1->y)>>8, v1->dx), den)); } //