diff --git a/.gitignore b/.gitignore
index 3090417dd..7023aaa80 100644
--- a/.gitignore
+++ b/.gitignore
@@ -13,11 +13,11 @@ Win32_LIB_ASM_Release
*.dgb
*.debug
*.debug.txt
-/bin/VC10/
-/objs/VC10/
*.user
*.db
*.opendb
/.vs
/debian
/assets/debian
+/make
+/bin
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 5d2d4a7e6..6f901d3d7 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,4 +1,4 @@
-cmake_minimum_required(VERSION 3.0)
+cmake_minimum_required(VERSION 3.13)
# Enable CCache early
set(SRB2_USE_CCACHE OFF CACHE BOOL "Use CCache")
@@ -34,12 +34,11 @@ set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} "${CMAKE_SOURCE_DIR}/cmake/Modules/")
### Useful functions
-# Prepend sources with current source directory
-function(prepend_sources SOURCE_FILES)
- foreach(SOURCE_FILE ${${SOURCE_FILES}})
- set(MODIFIED ${MODIFIED} ${CMAKE_CURRENT_SOURCE_DIR}/${SOURCE_FILE})
- endforeach()
- set(${SOURCE_FILES} ${MODIFIED} PARENT_SCOPE)
+# Add sources from Sourcefile
+function(target_sourcefile type)
+ file(STRINGS Sourcefile list
+ REGEX "[-0-9A-Za-z_]+\.${type}")
+ target_sources(SRB2SDL2 PRIVATE ${list})
endfunction()
# Macro to add OSX framework
diff --git a/Makefile b/Makefile
new file mode 100644
index 000000000..7ee12d837
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,8 @@
+ifdef SILENT
+MAKEFLAGS+=--no-print-directory
+endif
+
+all :
+
+% ::
+ @$(MAKE) -C src $(MAKECMDGOALS)
diff --git a/appveyor.yml b/appveyor.yml
index e94a709cd..d5f76c344 100644
--- a/appveyor.yml
+++ b/appveyor.yml
@@ -99,16 +99,11 @@ build_script:
- cmd: mingw32-make.exe %SRB2_MFLAGS% ERRORMODE=1 -k
after_build:
-- if [%X86_64%] == [1] (
- set "BUILD_PATH=bin\Mingw64\Release"
- ) else (
- set "BUILD_PATH=bin\Mingw\Release"
- )
- if [%X86_64%] == [1] ( set "CONFIGURATION=%CONFIGURATION%64" )
- ccache -s
- set BUILD_ARCHIVE=%REPO%-%GITSHORT%-%CONFIGURATION%.7z
- set BUILDSARCHIVE=%REPO%-%CONFIGURATION%.7z
-- cmd: 7z a %BUILD_ARCHIVE% %BUILD_PATH% -xr!.gitignore
+- cmd: 7z a %BUILD_ARCHIVE% bin -xr!.gitignore
- appveyor PushArtifact %BUILD_ARCHIVE%
#- cmd: copy %BUILD_ARCHIVE% %BUILDSARCHIVE%
#- appveyor PushArtifact %BUILDSARCHIVE%
diff --git a/bin/FreeBSD/Debug/.gitignore b/bin/FreeBSD/Debug/.gitignore
deleted file mode 100644
index 42c6dc2c6..000000000
--- a/bin/FreeBSD/Debug/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# DON'T REMOVE
-# This keeps the folder from disappearing
diff --git a/bin/FreeBSD/Release/.gitignore b/bin/FreeBSD/Release/.gitignore
deleted file mode 100644
index 42c6dc2c6..000000000
--- a/bin/FreeBSD/Release/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# DON'T REMOVE
-# This keeps the folder from disappearing
diff --git a/bin/Linux/Debug/.gitignore b/bin/Linux/Debug/.gitignore
deleted file mode 100644
index 56dee6f95..000000000
--- a/bin/Linux/Debug/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-/lsdlsrb2
diff --git a/bin/Linux/Release/.gitignore b/bin/Linux/Release/.gitignore
deleted file mode 100644
index 5b5c54a54..000000000
--- a/bin/Linux/Release/.gitignore
+++ /dev/null
@@ -1,3 +0,0 @@
-/lsdlsrb2
-/pnd
-/*.mo
diff --git a/bin/Linux64/Debug/.gitignore b/bin/Linux64/Debug/.gitignore
deleted file mode 100644
index 56dee6f95..000000000
--- a/bin/Linux64/Debug/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-/lsdlsrb2
diff --git a/bin/Linux64/Release/.gitignore b/bin/Linux64/Release/.gitignore
deleted file mode 100644
index 56dee6f95..000000000
--- a/bin/Linux64/Release/.gitignore
+++ /dev/null
@@ -1 +0,0 @@
-/lsdlsrb2
diff --git a/bin/Mingw/Debug/.gitignore b/bin/Mingw/Debug/.gitignore
deleted file mode 100644
index 834f313e3..000000000
--- a/bin/Mingw/Debug/.gitignore
+++ /dev/null
@@ -1,3 +0,0 @@
-*.exe
-*.mo
-r_opengl.dll
diff --git a/bin/Mingw/Release/.gitignore b/bin/Mingw/Release/.gitignore
deleted file mode 100644
index 3458ff764..000000000
--- a/bin/Mingw/Release/.gitignore
+++ /dev/null
@@ -1,4 +0,0 @@
-*.exe
-*.mo
-r_opengl.dll
-*.bat
diff --git a/bin/Mingw64/Debug/.gitignore b/bin/Mingw64/Debug/.gitignore
deleted file mode 100644
index e431dca5d..000000000
--- a/bin/Mingw64/Debug/.gitignore
+++ /dev/null
@@ -1,3 +0,0 @@
-/srb2sdl.exe
-/srb2win.exe
-/r_opengl.dll
diff --git a/bin/Mingw64/Release/.gitignore b/bin/Mingw64/Release/.gitignore
deleted file mode 100644
index e431dca5d..000000000
--- a/bin/Mingw64/Release/.gitignore
+++ /dev/null
@@ -1,3 +0,0 @@
-/srb2sdl.exe
-/srb2win.exe
-/r_opengl.dll
diff --git a/bin/SDL/Debug/.gitignore b/bin/SDL/Debug/.gitignore
deleted file mode 100644
index 42c6dc2c6..000000000
--- a/bin/SDL/Debug/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# DON'T REMOVE
-# This keeps the folder from disappearing
diff --git a/bin/SDL/Release/.gitignore b/bin/SDL/Release/.gitignore
deleted file mode 100644
index 42c6dc2c6..000000000
--- a/bin/SDL/Release/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# DON'T REMOVE
-# This keeps the folder from disappearing
diff --git a/bin/VC/.gitignore b/bin/VC/.gitignore
deleted file mode 100644
index e52f825b2..000000000
--- a/bin/VC/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-/Release
-/Debug
diff --git a/bin/VC9/.gitignore b/bin/VC9/.gitignore
deleted file mode 100644
index 205fe45de..000000000
--- a/bin/VC9/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-/Win32
-/x64
diff --git a/bin/dummy/.gitignore b/bin/dummy/.gitignore
deleted file mode 100644
index 42c6dc2c6..000000000
--- a/bin/dummy/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# DON'T REMOVE
-# This keeps the folder from disappearing
diff --git a/dep/.gitignore b/dep/.gitignore
deleted file mode 100644
index fb941664f..000000000
--- a/dep/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-#All folders
-*.d
diff --git a/dep/FreeBSD/SDL/Debug/.gitignore b/dep/FreeBSD/SDL/Debug/.gitignore
deleted file mode 100644
index 42c6dc2c6..000000000
--- a/dep/FreeBSD/SDL/Debug/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# DON'T REMOVE
-# This keeps the folder from disappearing
diff --git a/dep/FreeBSD/SDL/Release/.gitignore b/dep/FreeBSD/SDL/Release/.gitignore
deleted file mode 100644
index 42c6dc2c6..000000000
--- a/dep/FreeBSD/SDL/Release/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# DON'T REMOVE
-# This keeps the folder from disappearing
diff --git a/dep/Linux/SDL/Debug/.gitignore b/dep/Linux/SDL/Debug/.gitignore
deleted file mode 100644
index 42c6dc2c6..000000000
--- a/dep/Linux/SDL/Debug/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# DON'T REMOVE
-# This keeps the folder from disappearing
diff --git a/dep/Linux/SDL/Release/.gitignore b/dep/Linux/SDL/Release/.gitignore
deleted file mode 100644
index 42c6dc2c6..000000000
--- a/dep/Linux/SDL/Release/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# DON'T REMOVE
-# This keeps the folder from disappearing
diff --git a/dep/Linux64/SDL/Debug/.gitignore b/dep/Linux64/SDL/Debug/.gitignore
deleted file mode 100644
index 42c6dc2c6..000000000
--- a/dep/Linux64/SDL/Debug/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# DON'T REMOVE
-# This keeps the folder from disappearing
diff --git a/dep/Linux64/SDL/Release/.gitignore b/dep/Linux64/SDL/Release/.gitignore
deleted file mode 100644
index 42c6dc2c6..000000000
--- a/dep/Linux64/SDL/Release/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# DON'T REMOVE
-# This keeps the folder from disappearing
diff --git a/dep/MasterClient/.gitignore b/dep/MasterClient/.gitignore
deleted file mode 100644
index 42c6dc2c6..000000000
--- a/dep/MasterClient/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# DON'T REMOVE
-# This keeps the folder from disappearing
diff --git a/dep/MasterServer/.gitignore b/dep/MasterServer/.gitignore
deleted file mode 100644
index 42c6dc2c6..000000000
--- a/dep/MasterServer/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# DON'T REMOVE
-# This keeps the folder from disappearing
diff --git a/dep/Mingw/Debug/.gitignore b/dep/Mingw/Debug/.gitignore
deleted file mode 100644
index 42c6dc2c6..000000000
--- a/dep/Mingw/Debug/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# DON'T REMOVE
-# This keeps the folder from disappearing
diff --git a/dep/Mingw/Release/.gitignore b/dep/Mingw/Release/.gitignore
deleted file mode 100644
index 42c6dc2c6..000000000
--- a/dep/Mingw/Release/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# DON'T REMOVE
-# This keeps the folder from disappearing
diff --git a/dep/Mingw/SDL/Debug/.gitignore b/dep/Mingw/SDL/Debug/.gitignore
deleted file mode 100644
index 42c6dc2c6..000000000
--- a/dep/Mingw/SDL/Debug/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# DON'T REMOVE
-# This keeps the folder from disappearing
diff --git a/dep/Mingw/SDL/Release/.gitignore b/dep/Mingw/SDL/Release/.gitignore
deleted file mode 100644
index 42c6dc2c6..000000000
--- a/dep/Mingw/SDL/Release/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# DON'T REMOVE
-# This keeps the folder from disappearing
diff --git a/dep/Mingw64/Debug/.gitignore b/dep/Mingw64/Debug/.gitignore
deleted file mode 100644
index 42c6dc2c6..000000000
--- a/dep/Mingw64/Debug/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# DON'T REMOVE
-# This keeps the folder from disappearing
diff --git a/dep/Mingw64/Release/.gitignore b/dep/Mingw64/Release/.gitignore
deleted file mode 100644
index 42c6dc2c6..000000000
--- a/dep/Mingw64/Release/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# DON'T REMOVE
-# This keeps the folder from disappearing
diff --git a/dep/Mingw64/SDL/Debug/.gitignore b/dep/Mingw64/SDL/Debug/.gitignore
deleted file mode 100644
index 42c6dc2c6..000000000
--- a/dep/Mingw64/SDL/Debug/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# DON'T REMOVE
-# This keeps the folder from disappearing
diff --git a/dep/Mingw64/SDL/Release/.gitignore b/dep/Mingw64/SDL/Release/.gitignore
deleted file mode 100644
index 42c6dc2c6..000000000
--- a/dep/Mingw64/SDL/Release/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# DON'T REMOVE
-# This keeps the folder from disappearing
diff --git a/dep/SDL/Release/.gitignore b/dep/SDL/Release/.gitignore
deleted file mode 100644
index 42c6dc2c6..000000000
--- a/dep/SDL/Release/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# DON'T REMOVE
-# This keeps the folder from disappearing
diff --git a/dep/VC/.gitignore b/dep/VC/.gitignore
deleted file mode 100644
index 42c6dc2c6..000000000
--- a/dep/VC/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# DON'T REMOVE
-# This keeps the folder from disappearing
diff --git a/dep/VC9/.gitignore b/dep/VC9/.gitignore
deleted file mode 100644
index 42c6dc2c6..000000000
--- a/dep/VC9/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# DON'T REMOVE
-# This keeps the folder from disappearing
diff --git a/dep/cygwin/Debug/.gitignore b/dep/cygwin/Debug/.gitignore
deleted file mode 100644
index 42c6dc2c6..000000000
--- a/dep/cygwin/Debug/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# DON'T REMOVE
-# This keeps the folder from disappearing
diff --git a/dep/cygwin/Release/.gitignore b/dep/cygwin/Release/.gitignore
deleted file mode 100644
index 42c6dc2c6..000000000
--- a/dep/cygwin/Release/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# DON'T REMOVE
-# This keeps the folder from disappearing
diff --git a/dep/dummy/.gitignore b/dep/dummy/.gitignore
deleted file mode 100644
index 42c6dc2c6..000000000
--- a/dep/dummy/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# DON'T REMOVE
-# This keeps the folder from disappearing
diff --git a/objs/.gitignore b/objs/.gitignore
deleted file mode 100644
index 35ecd6def..000000000
--- a/objs/.gitignore
+++ /dev/null
@@ -1,8 +0,0 @@
-#All folders
-SRB2.res
-depend.dep
-depend.ped
-*.o
-#VC9 folder only
-/VC9/Win32
-/VC9/x64
diff --git a/objs/FreeBSD/SDL/Debug/.gitignore b/objs/FreeBSD/SDL/Debug/.gitignore
deleted file mode 100644
index 42c6dc2c6..000000000
--- a/objs/FreeBSD/SDL/Debug/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# DON'T REMOVE
-# This keeps the folder from disappearing
diff --git a/objs/FreeBSD/SDL/Release/.gitignore b/objs/FreeBSD/SDL/Release/.gitignore
deleted file mode 100644
index 42c6dc2c6..000000000
--- a/objs/FreeBSD/SDL/Release/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# DON'T REMOVE
-# This keeps the folder from disappearing
diff --git a/objs/Linux/SDL/Debug/.gitignore b/objs/Linux/SDL/Debug/.gitignore
deleted file mode 100644
index 42c6dc2c6..000000000
--- a/objs/Linux/SDL/Debug/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# DON'T REMOVE
-# This keeps the folder from disappearing
diff --git a/objs/Linux/SDL/Release/.gitignore b/objs/Linux/SDL/Release/.gitignore
deleted file mode 100644
index 42c6dc2c6..000000000
--- a/objs/Linux/SDL/Release/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# DON'T REMOVE
-# This keeps the folder from disappearing
diff --git a/objs/Linux64/SDL/Debug/.gitignore b/objs/Linux64/SDL/Debug/.gitignore
deleted file mode 100644
index 42c6dc2c6..000000000
--- a/objs/Linux64/SDL/Debug/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# DON'T REMOVE
-# This keeps the folder from disappearing
diff --git a/objs/Linux64/SDL/Release/.gitignore b/objs/Linux64/SDL/Release/.gitignore
deleted file mode 100644
index 42c6dc2c6..000000000
--- a/objs/Linux64/SDL/Release/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# DON'T REMOVE
-# This keeps the folder from disappearing
diff --git a/objs/MasterClient/.gitignore b/objs/MasterClient/.gitignore
deleted file mode 100644
index 42c6dc2c6..000000000
--- a/objs/MasterClient/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# DON'T REMOVE
-# This keeps the folder from disappearing
diff --git a/objs/MasterServer/.gitignore b/objs/MasterServer/.gitignore
deleted file mode 100644
index 42c6dc2c6..000000000
--- a/objs/MasterServer/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# DON'T REMOVE
-# This keeps the folder from disappearing
diff --git a/objs/Mingw/Debug/.gitignore b/objs/Mingw/Debug/.gitignore
deleted file mode 100644
index 42c6dc2c6..000000000
--- a/objs/Mingw/Debug/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# DON'T REMOVE
-# This keeps the folder from disappearing
diff --git a/objs/Mingw/Release/.gitignore b/objs/Mingw/Release/.gitignore
deleted file mode 100644
index 42c6dc2c6..000000000
--- a/objs/Mingw/Release/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# DON'T REMOVE
-# This keeps the folder from disappearing
diff --git a/objs/Mingw/SDL/Debug/.gitignore b/objs/Mingw/SDL/Debug/.gitignore
deleted file mode 100644
index 42c6dc2c6..000000000
--- a/objs/Mingw/SDL/Debug/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# DON'T REMOVE
-# This keeps the folder from disappearing
diff --git a/objs/Mingw/SDL/Release/.gitignore b/objs/Mingw/SDL/Release/.gitignore
deleted file mode 100644
index 42c6dc2c6..000000000
--- a/objs/Mingw/SDL/Release/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# DON'T REMOVE
-# This keeps the folder from disappearing
diff --git a/objs/Mingw64/Debug/.gitignore b/objs/Mingw64/Debug/.gitignore
deleted file mode 100644
index 42c6dc2c6..000000000
--- a/objs/Mingw64/Debug/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# DON'T REMOVE
-# This keeps the folder from disappearing
diff --git a/objs/Mingw64/Release/.gitignore b/objs/Mingw64/Release/.gitignore
deleted file mode 100644
index 42c6dc2c6..000000000
--- a/objs/Mingw64/Release/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# DON'T REMOVE
-# This keeps the folder from disappearing
diff --git a/objs/Mingw64/SDL/Debug/.gitignore b/objs/Mingw64/SDL/Debug/.gitignore
deleted file mode 100644
index 42c6dc2c6..000000000
--- a/objs/Mingw64/SDL/Debug/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# DON'T REMOVE
-# This keeps the folder from disappearing
diff --git a/objs/Mingw64/SDL/Release/.gitignore b/objs/Mingw64/SDL/Release/.gitignore
deleted file mode 100644
index 42c6dc2c6..000000000
--- a/objs/Mingw64/SDL/Release/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# DON'T REMOVE
-# This keeps the folder from disappearing
diff --git a/objs/SDL/Release/.gitignore b/objs/SDL/Release/.gitignore
deleted file mode 100644
index 42c6dc2c6..000000000
--- a/objs/SDL/Release/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# DON'T REMOVE
-# This keeps the folder from disappearing
diff --git a/objs/VC/.gitignore b/objs/VC/.gitignore
deleted file mode 100644
index 42c6dc2c6..000000000
--- a/objs/VC/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# DON'T REMOVE
-# This keeps the folder from disappearing
diff --git a/objs/VC9/.gitignore b/objs/VC9/.gitignore
deleted file mode 100644
index 42c6dc2c6..000000000
--- a/objs/VC9/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# DON'T REMOVE
-# This keeps the folder from disappearing
diff --git a/objs/cygwin/Debug/.gitignore b/objs/cygwin/Debug/.gitignore
deleted file mode 100644
index 42c6dc2c6..000000000
--- a/objs/cygwin/Debug/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# DON'T REMOVE
-# This keeps the folder from disappearing
diff --git a/objs/cygwin/Release/.gitignore b/objs/cygwin/Release/.gitignore
deleted file mode 100644
index 42c6dc2c6..000000000
--- a/objs/cygwin/Release/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# DON'T REMOVE
-# This keeps the folder from disappearing
diff --git a/objs/dummy/.gitignore b/objs/dummy/.gitignore
deleted file mode 100644
index 42c6dc2c6..000000000
--- a/objs/dummy/.gitignore
+++ /dev/null
@@ -1,2 +0,0 @@
-# DON'T REMOVE
-# This keeps the folder from disappearing
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index e639ae14d..4c125c4b8 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -1,241 +1,14 @@
# SRB2 Core
+add_executable(SRB2SDL2 MACOSX_BUNDLE WIN32)
+
# 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
- dehacked.c
- deh_soc.c
- deh_lua.c
- deh_tables.c
- f_finale.c
- f_wipe.c
- filesrch.c
- g_demo.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_easing.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
- 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
-)
+target_sourcefile(c)
+target_sources(SRB2SDL2 PRIVATE comptime.c md5.c config.h)
-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_think.h
- d_ticcmd.h
- dehacked.h
- deh_soc.h
- deh_lua.h
- deh_tables.h
- doomdata.h
- doomdef.h
- doomstat.h
- doomtype.h
- endian.h
- f_finale.h
- fastcmp.h
- filesrch.h
- g_demo.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_video.h
- info.h
- keys.h
- libdivide.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_easing.h
- m_fixed.h
- m_menu.h
- m_misc.h
- m_perfstats.h
- m_queue.h
- m_random.h
- m_swap.h
- md5.h
- mserv.h
- p5prof.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_main.c
- r_plane.c
- r_segs.c
- r_skins.c
- r_sky.c
- r_splats.c
- r_things.c
- r_textures.c
- r_patch.c
- r_patchrotation.c
- r_picformats.c
- r_portal.c
-
- r_bsp.h
- r_data.h
- r_defs.h
- r_draw.h
- r_local.h
- r_main.h
- r_plane.h
- r_segs.h
- r_skins.h
- r_sky.h
- r_splats.h
- r_state.h
- r_things.h
- r_textures.h
- r_patch.h
- r_patchrotation.h
- r_picformats.h
- r_portal.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
- taglist.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
- taglist.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})
-
-
-set(SRB2_ASM_SOURCES
- ${CMAKE_CURRENT_SOURCE_DIR}/vid_copy.s
-)
-
-set(SRB2_NASM_SOURCES
- ${CMAKE_CURRENT_SOURCE_DIR}/tmap_mmx.nas
- ${CMAKE_CURRENT_SOURCE_DIR}/tmap.nas
-)
-
-if(MSVC)
- list(APPEND SRB2_NASM_SOURCES ${CMAKE_CURRENT_SOURCE_DIR}/tmap_vc.nas)
-endif()
-
-set(SRB2_NASM_OBJECTS
- ${CMAKE_CURRENT_BINARY_DIR}/tmap_mmx.obj
- ${CMAKE_CURRENT_BINARY_DIR}/tmap.obj
-)
-
-if(MSVC)
- list(APPEND SRB2_NASM_OBJECTS ${CMAKE_CURRENT_BINARY_DIR}/tmap_vc.obj)
-endif()
-
-source_group("Assembly" FILES ${SRB2_ASM_SOURCES} ${SRB2_NASM_SOURCES})
+set(SRB2_ASM_SOURCES vid_copy.s)
+set(SRB2_NASM_SOURCES tmap_mmx.nas tmap.nas)
### Configuration
set(SRB2_CONFIG_HAVE_PNG ON CACHE BOOL
@@ -271,93 +44,7 @@ if(${CMAKE_SYSTEM} MATCHES "Windows") ###set on Windows only
"Use SRB2's internal copies of required dependencies (SDL2, PNG, zlib, GME, OpenMPT).")
endif()
-set(SRB2_LUA_SOURCES
- lua_baselib.c
- lua_blockmaplib.c
- lua_consolelib.c
- lua_hooklib.c
- lua_hudlib.c
- lua_infolib.c
- lua_maplib.c
- lua_taglib.c
- lua_mathlib.c
- lua_mobjlib.c
- lua_playerlib.c
- lua_polyobjlib.c
- lua_inputlib.c
- lua_script.c
- lua_skinlib.c
- lua_thinkerlib.c
-)
-set(SRB2_LUA_HEADERS
- lua_hook.h
- lua_hud.h
- lua_libs.h
- lua_script.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/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})
+add_subdirectory(blua)
if(${SRB2_CONFIG_HAVE_GME})
if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES})
@@ -373,7 +60,7 @@ if(${SRB2_CONFIG_HAVE_GME})
endif()
if(${GME_FOUND})
set(SRB2_HAVE_GME ON)
- add_definitions(-DHAVE_LIBGME)
+ target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_LIBGME)
else()
message(WARNING "You have specified that GME is available but it was not found.")
endif()
@@ -393,7 +80,7 @@ if(${SRB2_CONFIG_HAVE_OPENMPT})
endif()
if(${OPENMPT_FOUND})
set(SRB2_HAVE_OPENMPT ON)
- add_definitions(-DHAVE_OPENMPT)
+ target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_OPENMPT)
else()
message(WARNING "You have specified that OpenMPT is available but it was not found.")
endif()
@@ -416,8 +103,7 @@ if(${SRB2_CONFIG_HAVE_MIXERX})
endif()
if(${MIXERX_FOUND})
set(SRB2_HAVE_MIXERX ON)
- set(SRB2_SDL2_SOUNDIMPL mixer_sound.c)
- add_definitions(-DHAVE_MIXERX)
+ target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_MIXERX)
else()
message(WARNING "You have specified that SDL Mixer X is available but it was not found.")
endif()
@@ -437,7 +123,7 @@ if(${SRB2_CONFIG_HAVE_ZLIB})
endif()
if(${ZLIB_FOUND})
set(SRB2_HAVE_ZLIB ON)
- add_definitions(-DHAVE_ZLIB)
+ target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_ZLIB)
else()
message(WARNING "You have specified that ZLIB is available but it was not found. SRB2 may not compile correctly.")
endif()
@@ -458,14 +144,9 @@ if(${SRB2_CONFIG_HAVE_PNG} AND ${SRB2_CONFIG_HAVE_ZLIB})
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})
+ target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_PNG)
+ target_compile_definitions(SRB2SDL2 PRIVATE -D_LARGEFILE64_SOURCE)
+ target_sources(SRB2SDL2 PRIVATE apng.c)
else()
message(WARNING "You have specified that PNG is available but it was not found. SRB2 may not compile correctly.")
endif()
@@ -486,7 +167,7 @@ if(${SRB2_CONFIG_HAVE_CURL})
endif()
if(${CURL_FOUND})
set(SRB2_HAVE_CURL ON)
- add_definitions(-DHAVE_CURL)
+ target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_CURL)
else()
message(WARNING "You have specified that CURL is available but it was not found. SRB2 may not compile correctly.")
endif()
@@ -494,59 +175,19 @@ endif()
if(${SRB2_CONFIG_HAVE_THREADS})
set(SRB2_HAVE_THREADS ON)
- set(SRB2_CORE_HEADERS ${SRB2_CORE_HEADERS} ${CMAKE_CURRENT_SOURCE_DIR}/i_threads.h)
- add_definitions(-DHAVE_THREADS)
+ target_compile_definitions(SRB2SDL2 PRIVATE -DHAVE_THREADS)
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_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_light.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_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_light.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
- )
-
+ target_compile_definitions(SRB2SDL2 PRIVATE -DHWRENDER)
+ add_subdirectory(hardware)
endif()
if(${SRB2_CONFIG_HWRENDER} AND ${SRB2_CONFIG_STATIC_OPENGL})
find_package(OpenGL)
if(${OPENGL_FOUND})
- add_definitions(-DHWRENDER)
- add_definitions(-DSTATIC_OPENGL)
+ target_compile_definitions(SRB2SDL2 PRIVATE -DHWRENDER)
+ target_compile_definitions(SRB2SDL2 PRIVATE -DSTATIC_OPENGL)
else()
message(WARNING "You have specified static opengl but opengl was not found. Not setting HWRENDER.")
endif()
@@ -567,12 +208,16 @@ if(${SRB2_CONFIG_USEASM})
set(CMAKE_ASM_NASM_FLAGS "${SRB2_ASM_FLAGS}" CACHE STRING "Flags used by the assembler during all build types.")
enable_language(ASM_NASM)
endif()
+
set(SRB2_USEASM ON)
- add_definitions(-DUSEASM)
+ target_compile_definitions(SRB2SDL2 PRIVATE -DUSEASM)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -msse3 -mfpmath=sse")
+
+ target_sources(SRB2SDL2 PRIVATE ${SRB2_ASM_SOURCES}
+ ${SRB2_NASM_SOURCES})
else()
set(SRB2_USEASM OFF)
- add_definitions(-DNONX86 -DNORUSEASM)
+ target_compile_definitions(SRB2SDL2 PRIVATE -DNONX86 -DNORUSEASM)
endif()
# Targets
@@ -610,7 +255,7 @@ endif()
set(CMAKE_C_FLAGS ${CMAKE_C_FLAGS} -Wno-trigraphs)
-add_definitions(-DCMAKECONFIG)
+target_compile_definitions(SRB2SDL2 PRIVATE -DCMAKECONFIG)
#add_library(SRB2Core STATIC
# ${SRB2_CORE_SOURCES}
diff --git a/src/Makefile b/src/Makefile
index 1d3551ce2..90776b812 100644
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,822 +1,414 @@
-
-# GNU Make makefile for SRB2
-#############################################################################
-# Copyright (C) 1998-2000 by DooM Legacy Team.
-# Copyright (C) 2003-2021 by Sonic Team Junior.
+# GNU Makefile for SRB2
+# the poly3 Makefile adapted over and over...
+#
+# Copyright 1998-2000 DooM Legacy Team.
+# Copyright 2020-2021 James R.
+# Copyright 2003-2021 Sonic Team Junior.
#
# This program is free software distributed under the
# terms of the GNU General Public License, version 2.
# See the 'LICENSE' file for more details.
#
-# -DLINUX -> use for the GNU/Linux specific
-# -D_WINDOWS -> use for the Win32/DirectX specific
-# -DHAVE_SDL -> use for the SDL interface
+# Special targets:
#
-# Sets:
-# Compile the SDL/Mingw version with 'make MINGW=1'
-# Compile the SDL/Linux version with 'make LINUX=1'
-# Compile the SDL/Solaris version with 'make SOLARIS=1'
-# Compile the SDL/FreeBSD version with 'gmake FREEBSD=1'
-# Compile the SDL/Cygwin version with 'make CYGWIN32=1'
-# Compile the SDL/other version try with 'make SDL=1'
+# clean - remove executables and objects for this build
+# cleandep - remove dependency files for this build
+# distclean - remove entire executable, object and
+# dependency file directory structure.
+# dump - disassemble executable
+# info - print settings
#
-# 'Targets':
-# clean
-# Remove all object files
-# cleandep
-# Remove dependency files
-# distclean
-# Remove autogenerated files
-# dll
-# compile primary HW render DLL/SO
-# all_dll
-# compile all HW render and 3D sound DLLs for the set
-# opengl_dll
-# Pure Mingw only, compile OpenGL HW render DLL
-# ds3d_dll
-# Pure Mingw only, compile DirectX DirectSound HW sound DLL
-# fmod_dll
-# Pure Mingw only, compile FMOD HW sound DLL
-# openal_dll
-# Pure Mingw only, compile OpenAL HW sound DLL
-# fmod_so
-# Non-Mingw, compile FMOD HW sound SO
-# openal_so
-# Non-Mingw, compile OpenAL HW sound SO
+# This Makefile can automatically detect the host system
+# as well as the compiler version. If system or compiler
+# version cannot be detected, you may need to set a flag
+# manually.
#
+# On Windows machines, 32-bit Windows is always targetted.
#
-# Addon:
-# To Cross-Compile, CC=gcc-version make * PREFIX=
-# Compile with GCC 2.97 version, add 'GCC29=1'
-# Compile with GCC 4.0x version, add 'GCC40=1'
-# Compile with GCC 4.1x version, add 'GCC41=1'
-# Compile with GCC 4.2x version, add 'GCC42=1'
-# Compile with GCC 4.3x version, add 'GCC43=1'
-# Compile with GCC 4.4x version, add 'GCC44=1'
-# Compile with GCC 4.5x version, add 'GCC45=1'
-# Compile with GCC 4.6x version, add 'GCC46=1'
-# Compile a profile version, add 'PROFILEMODE=1'
-# Compile a debug version, add 'DEBUGMODE=1'
-# Compile with less warnings, add 'RELAXWARNINGS=1'
-# Generate compiler errors for most compiler warnings, add 'ERRORMODE=1'
-# Compile without NASM's tmap.nas, add 'NOASM=1'
-# Compile without 3D hardware support, add 'NOHW=1'
-# Compile with GDBstubs, add 'RDB=1'
-# Compile without PNG, add 'NOPNG=1'
-# Compile without zlib, add 'NOZLIB=1'
+# Platform/system flags:
#
-# Addon for SDL:
-# To Cross-Compile, add 'SDL_CONFIG=/usr/*/bin/sdl-config'
-# Compile without SDL_Mixer, add 'NOMIXER=1'
-# Compile without SDL_Mixer_X, add 'NOMIXERX=1' (Win32 only)
-# Compile without GME, add 'NOGME=1'
-# Compile without BSD API, add 'NONET=1'
-# Compile without IPX/SPX, add 'NOIPX=1'
-# Compile Mingw/SDL with S_DS3S, add 'DS3D=1'
-# Compile without libopenmpt, add 'NOOPENMPT=1'
-# Compile with S_FMOD3D, add 'FMOD=1' (WIP)
-# Compile with S_OPENAL, add 'OPENAL=1' (WIP)
-# To link with the whole SDL_Image lib to load Icons, add 'SDL_IMAGE=1' but it isn't not realy needed
-# To link with SDLMain to hide console or make on a console-less binary, add 'SDLMAIN=1'
+# LINUX=1, LINUX64=1
+# MINGW=1, MINGW64=1 - Windows (MinGW toolchain)
+# UNIX=1 - Generic Unix like system
+# FREEBSD=1
+# SDL=1 - Use SDL backend. SDL is the only backend though
+# and thus, always enabled.
#
-#############################################################################
+# A list of supported GCC versions can be found in
+# Makefile.d/detect.mk -- search 'gcc_versions'.
+#
+# Feature flags:
+#
+# Safe to use online
+# ------------------
+# NO_IPV6=1 - Disable IPv6 address support.
+# NOHW=1 - Disable OpenGL renderer.
+# ZDEBUG=1 - Enable more detailed memory debugging
+# HAVE_MINIUPNPC=1 - Enable automated port forwarding.
+# Already enabled by default for 32-bit
+# Windows.
+# NOASM=1 - Disable hand optimized assembly code for the
+# Software renderer.
+# NOPNG=1 - Disable PNG graphics support. (TODO: double
+# check netplay compatible.)
+# NOCURL=1 - Disable libcurl--HTTP capability.
+# NOGME=1 - Disable game music emu, retro VGM support.
+# NOOPENMPT=1 - Disable module (tracker) music support.
+# NOMIXER=1 - Disable SDL Mixer (audio playback).
+# NOMIXERX=1 - Forgo SDL Mixer X--revert to standard SDL
+# Mixer. Mixer X is the default for Windows
+# builds.
+# HAVE_MIXERX=1 - Enable SDL Mixer X. Outside of Windows
+# builds, SDL Mixer X is not the default.
+# NOTHREADS=1 - Disable multithreading.
+#
+# Netplay incompatible
+# --------------------
+# NONET=1 - Disable online capability.
+# NOMD5=1 - Disable MD5 checksum (validation tool).
+# NOPOSTPROCESSING=1 - ?
+# MOBJCONSISTANCY=1 - ??
+# PACKETDROP=1 - ??
+# DEBUGMODE=1 - Enable various debugging capabilities.
+# Also disables optimizations.
+# NOZLIB=1 - Disable some compression capability. Implies
+# NOPNG=1.
+#
+# Development flags:
+#
+# VALGRIND=1 - Enable Valgrind memory debugging support.
+# PROFILEMODE=1 - Enable performance profiling (gprof).
+#
+# General flags for building:
+#
+# STATIC=1 - Use static linking.
+# DISTCC=1
+# CCACHE=1
+# UPX= - UPX command to use for compressing final
+# executable.
+# WINDOWSHELL=1 - Use Windows commands.
+# PREFIX= - Prefix to many commands, for cross compiling.
+# YASM=1 - Use Yasm instead of NASM assembler.
+# STABS=1 - ?
+# ECHO=1 - Print out each command in the build process.
+# NOECHOFILENAMES=1 - Don't print out each that is being
+# worked on.
+# SILENT=1 - Print absolutely nothing except errors.
+# RELAXWARNINGS=1 - Use less compiler warnings/errors.
+# ERRORMODE=1 - Treat most compiler warnings as errors.
+# NOCASTALIGNWARN=1 - ?
+# NOLDWARNING=1 - ?
+# NOSDLMAIN=1 - ?
+# SDLMAIN=1 - ?
+#
+# Library configuration flags:
+# Everything here is an override.
+#
+# PNG_PKGCONFIG= - libpng-config command.
+# PNG_CFLAGS=, PNG_LDFLAGS=
+#
+# CURLCONFIG= - curl-config command.
+# CURL_CFLAGS=, CURL_LDFLAGS=
+#
+# VALGRIND_PKGCONFIG= - pkg-config package name.
+# VALGRIND_CFLAGS=, VALGRIND_LDFLAGS=
+#
+# LIBGME_PKGCONFIG=, LIBGME_CFLAGS=, LIBGME_LDFLAGS=
-,=,
+# LIBOPENMPT_PKGCONFIG=
+# LIBOPENMPT_CFLAGS=, LIBOPENMPT_LDFLAGS=
+#
+# ZLIB_PKGCONFIG=, ZLIB_CFLAGS=, ZLIB_LDFLAGS=
+#
+# SDL_PKGCONFIG=
+# SDL_CONFIG= - sdl-config command.
+# SDL_CFLAGS=, SDL_LDFLAGS=
-ifeq (,$(filter-out cleandep clean distclean,$(or $(MAKECMDGOALS),all)))
-CLEANONLY=1
-else ifndef SILENT
-echo=@echo "$(1)"
-ifndef MAKE_RESTARTS
-print=$(info $(1))
-endif
+clean_targets=cleandep clean distclean info
+
+.PHONY : $(clean_targets) all
+
+goals:=$(or $(MAKECMDGOALS),all)
+cleanonly:=$(filter $(clean_targets),$(goals))
+destructive:=$(filter-out info,$(cleanonly))
+
+ifndef cleanonly
+include Makefile.d/old.mk
endif
-ALL_SYSTEMS=\
- PANDORA\
- LINUX64\
- MINGW64\
- HAIKU\
- DUMMY\
- MINGW\
- UNIX\
- LINUX\
- SOLARIS\
- FREEBSD\
- MACOSX\
- SDL\
+include Makefile.d/util.mk
-# check for user specified system
-ifeq (,$(filter $(ALL_SYSTEMS),$(.VARIABLES)))
-ifeq ($(OS),Windows_NT) # all windows are Windows_NT...
-
- $(call print,Detected a Windows system$(,) compiling for 32-bit MinGW SDL2...)
-
- # go for a 32-bit sdl mingw exe by default
- MINGW=1
- WINDOWSHELL=1
-
-else # if you on the *nix
-
- system:=$(shell uname -s)
-
- ifeq ($(system),Linux)
- new_system=LINUX
- else
-
- $(error \
- Could not automatically detect your system,\
- try specifying a system manually)
-
- endif
-
- ifeq ($(shell getconf LONG_BIT),64)
- system+=64-bit
- new_system:=$(new_system)64
- endif
-
- $(call print,Detected $(system) ($(new_system))...)
- $(new_system)=1
-
-endif
-endif
-
-
-# SRB2 data files
-D_DIR?=../bin/Resources
-D_FILES=$(D_DIR)/srb2.pk3 \
- $(D_DIR)/player.dta \
- $(D_DIR)/zones.pk3 \
- $(D_DIR)/music.dta \
-
-PKG_CONFIG?=pkg-config
-
-ifdef PANDORA
-LINUX=1
-endif
-
-ifdef LINUX64
-LINUX=1
-NONX86=1
-# LINUX64 does not imply X86_64=1; could mean ARM64 or Itanium
-endif
-
-ifdef MINGW64
-MINGW=1
-NONX86=1
-NOASM=1
-# MINGW64 should not necessarily imply X86_64=1, but we make that assumption elsewhere
-# Once that changes, remove this
-X86_64=1
-endif #ifdef MINGW64
-
-ifdef HAIKU
-SDL=1
-endif
-
-include Makefile.cfg
-
-ifdef DUMMY
-NOPNG=1
-NOZLIB=1
-NONET=1
-NOHW=1
-NOASM=1
-NOIPX=1
-EXENAME?=srb2dummy
-OBJS=$(OBJDIR)/i_video.o
-LIBS=-lm
-endif
-
-ifdef HAIKU
-NOIPX=1
-NOASM=1
-ifndef NONET
-LIBS=-lnetwork
-endif
-CFLAGS+=-DUNIXCOMMON
-PNG_CFLAGS?=
-PNG_LDFLAGS?=-lpng
-endif
-
-ifdef PANDORA
-NONX86=1
-NOHW=1
-endif
-
-ifndef NOOPENMPT
-HAVE_OPENMPT=1
-endif
-
-ifdef MINGW
-include win32/Makefile.cfg
-endif #ifdef MINGW
-
-ifdef UNIX
-UNIXCOMMON=1
-endif
-
-ifdef LINUX
-UNIXCOMMON=1
-ifndef NOGME
-HAVE_LIBGME=1
-endif
-endif
-
-ifdef SOLARIS
-UNIXCOMMON=1
-endif
-
-ifdef FREEBSD
-UNIXCOMMON=1
-endif
-
-ifdef MACOSX
-UNIXCOMMON=1
-endif
-
-ifdef SDL
- include sdl/Makefile.cfg
-endif #ifdef SDL
-
-ifdef DISTCC
- CC:=distcc $(CC)
-endif
-
-ifdef CCACHE
- CC:=ccache $(CC)
-endif
-
-MSGFMT?=msgfmt
-
-ifdef WINDOWSHELL
- COMPTIME=-..\comptime.bat
-else
- COMPTIME=-../comptime.sh
-endif
-
-ifndef ECHO
- NASM:=@$(NASM)
- REMOVE:=@$(REMOVE)
- CC:=@$(CC)
- CXX:=@$(CXX)
- OBJCOPY:=@$(OBJCOPY)
- OBJDUMP:=@$(OBJDUMP)
- STRIP:=@$(STRIP)
- WINDRES:=@$(WINDRES)
- MKDIR:=@$(MKDIR)
- GZIP:=@$(GZIP)
- MSGFMT:=@$(MSGFMT)
- UPX:=@$(UPX)
- UPX_OPTS+=-q
- COMPTIME:=@$(COMPTIME)
-endif
-
-ifdef NONET
- OPTS+=-DNONET
- NOCURL=1
-else
-ifdef NO_IPV6
- OPTS+=-DNO_IPV6
-endif
-endif
-
-ifdef NOHW
- OPTS+=-DNOHW
-else
- OPTS+=-DHWRENDER
- OBJS+=$(OBJDIR)/hw_bsp.o $(OBJDIR)/hw_draw.o $(OBJDIR)/hw_light.o \
- $(OBJDIR)/hw_main.o $(OBJDIR)/hw_clip.o $(OBJDIR)/hw_md2.o $(OBJDIR)/hw_cache.o \
- $(OBJDIR)/hw_md2load.o $(OBJDIR)/hw_md3load.o $(OBJDIR)/hw_model.o $(OBJDIR)/u_list.o $(OBJDIR)/hw_batching.o
-endif
-
-OPTS += -DCOMPVERSION
-
-ifndef NONX86
-ifndef GCC29
- ARCHOPTS?=-msse3 -mfpmath=sse
-else
- ARCHOPTS?=-mpentium
-endif
-else
-ifdef X86_64
- ARCHOPTS?=-march=nocona
-endif
-endif
-
-ifndef NOASM
-ifndef NONX86
- OBJS+=$(OBJDIR)/tmap.o $(OBJDIR)/tmap_mmx.o
- OPTS+=-DUSEASM
-endif
-endif
-
-ifndef NOPNG
-OPTS+=-DHAVE_PNG
-
-ifdef PNG_PKGCONFIG
-PNG_CFLAGS?=$(shell $(PKG_CONFIG) $(PNG_PKGCONFIG) --cflags)
-PNG_LDFLAGS?=$(shell $(PKG_CONFIG) $(PNG_PKGCONFIG) --libs)
-else
ifdef PREFIX
-PNG_CONFIG?=$(PREFIX)-libpng-config
+CC:=$(PREFIX)-gcc
+endif
+
+OBJDUMP_OPTS?=--wide --source --line-numbers
+
+OBJCOPY:=$(call Prefix,objcopy)
+OBJDUMP:=$(call Prefix,objdump)
+WINDRES:=$(call Prefix,windres)
+
+ifdef YASM
+NASM?=yasm
else
-PNG_CONFIG?=libpng-config
+NASM?=nasm
endif
-ifdef PNG_STATIC
-PNG_CFLAGS?=$(shell $(PNG_CONFIG) --static --cflags)
-PNG_LDFLAGS?=$(shell $(PNG_CONFIG) --static --ldflags)
-else
-PNG_CFLAGS?=$(shell $(PNG_CONFIG) --cflags)
-PNG_LDFLAGS?=$(shell $(PNG_CONFIG) --ldflags)
-endif
-endif
-
-ifdef LINUX
-PNG_CFLAGS+=-D_LARGEFILE64_SOURCE
-endif
-
-LIBS+=$(PNG_LDFLAGS)
-CFLAGS+=$(PNG_CFLAGS)
-
-OBJS+=$(OBJDIR)/apng.o
-endif
-
-ifdef HAVE_LIBGME
-OPTS+=-DHAVE_LIBGME
-
-LIBGME_PKGCONFIG?=libgme
-LIBGME_CFLAGS?=$(shell $(PKG_CONFIG) $(LIBGME_PKGCONFIG) --cflags)
-LIBGME_LDFLAGS?=$(shell $(PKG_CONFIG) $(LIBGME_PKGCONFIG) --libs)
-
-LIBS+=$(LIBGME_LDFLAGS)
-CFLAGS+=$(LIBGME_CFLAGS)
-endif
-
-ifdef HAVE_OPENMPT
-OPTS+=-DHAVE_OPENMPT
-
-LIBOPENMPT_PKGCONFIG?=libopenmpt
-LIBOPENMPT_CFLAGS?=$(shell $(PKG_CONFIG) $(LIBOPENMPT_PKGCONFIG) --cflags)
-LIBOPENMPT_LDFLAGS?=$(shell $(PKG_CONFIG) $(LIBOPENMPT_PKGCONFIG) --libs)
-
-LIBS+=$(LIBOPENMPT_LDFLAGS)
-CFLAGS+=$(LIBOPENMPT_CFLAGS)
-endif
-
-ifndef NOZLIB
-OPTS+=-DHAVE_ZLIB
-ZLIB_PKGCONFIG?=zlib
-ZLIB_CFLAGS?=$(shell $(PKG_CONFIG) $(ZLIB_PKGCONFIG) --cflags)
-ZLIB_LDFLAGS?=$(shell $(PKG_CONFIG) $(ZLIB_PKGCONFIG) --libs)
-
-LIBS+=$(ZLIB_LDFLAGS)
-CFLAGS+=$(ZLIB_CFLAGS)
-else
-NOPNG=1
-endif
-
-ifndef NOCURL
-OPTS+=-DHAVE_CURL
-CURLCONFIG?=curl-config
-CURL_CFLAGS?=$(shell $(CURLCONFIG) --cflags)
-CURL_LDFLAGS?=$(shell $(CURLCONFIG) --libs)
-
-LIBS+=$(CURL_LDFLAGS)
-CFLAGS+=$(CURL_CFLAGS)
-endif
-
-ifdef STATIC
-LIBS:=-static $(LIBS)
-endif
-
-ifdef HAVE_MINIUPNPC
-ifdef NONET
-HAVE_MINIUPNPC=''
-else
-LIBS+=-lminiupnpc
-ifdef MINGW
-LIBS+=-lws2_32 -liphlpapi
-endif
-CFLAGS+=-DHAVE_MINIUPNPC
-endif
-endif
-
-include blua/Makefile.cfg
-
-ifdef NOMD5
- OPTS+=-DNOMD5
-else
- OBJS:=$(OBJDIR)/md5.o $(OBJS)
-endif
-
-ifdef NOPOSTPROCESSING
- OPTS+=-DNOPOSTPROCESSING
-endif
-
- OPTS:=-fno-exceptions $(OPTS)
-
-ifdef MOBJCONSISTANCY
- OPTS+=-DMOBJCONSISTANCY
-endif
-
-ifdef PACKETDROP
- OPTS+=-DPACKETDROP
-endif
-
-ifdef DEBUGMODE
-
- # build with debugging information
- WINDRESFLAGS = -D_DEBUG
-ifdef GCC48
- CFLAGS+=-Og
-else
- CFLAGS+=-O0
-endif
- CFLAGS+= -Wall -DPARANOIA -DRANGECHECK -DPACKETDROP
-else
-
-
- # build a normal optimised version
- WINDRESFLAGS = -DNDEBUG
- CFLAGS+=-O3
-endif
- CFLAGS+=-g $(OPTS) $(ARCHOPTS) $(WINDRESFLAGS)
-
ifdef YASM
ifdef STABS
- NASMOPTS?= -g stabs
+NASMOPTS?=-g stabs
else
- NASMOPTS?= -g dwarf2
+NASMOPTS?=-g dwarf2
endif
else
- NASMOPTS?= -g
+NASMOPTS?=-g
endif
-ifdef PROFILEMODE
- # build with profiling information
- CFLAGS+=-pg
- LDFLAGS+=-pg
+GZIP?=gzip
+GZIP_OPTS?=-9 -f -n
+ifdef WINDOWSHELL
+GZIP_OPTS+=--rsyncable
endif
-ifdef ZDEBUG
- CPPFLAGS+=-DZDEBUG
+UPX_OPTS?=--best --preserve-build-id
+ifndef ECHO
+UPX_OPTS+=-qq
endif
-OPTS+=$(CPPFLAGS)
+include Makefile.d/detect.mk
-# default EXENAME if all else fails
+# make would try to remove the implicitly made directories
+.PRECIOUS : %/ comptime.c
+
+sources:=
+makedir:=../make
+
+# -DCOMPVERSION: flag to use comptime.h
+opts:=-DCOMPVERSION -g
+libs:=
+
+nasm_format:=
+
+# This is a list of variables names, of which if defined,
+# also defines the name as a macro to the compiler.
+passthru_opts:=
+
+include Makefile.d/platform.mk
+include Makefile.d/features.mk
+include Makefile.d/versions.mk
+
+ifdef DEBUGMODE
+makedir:=$(makedir)/debug
+endif
+
+depdir:=$(makedir)/deps
+objdir:=$(makedir)/objs
+
+# very sophisticated dependency
+sources+=\
+ $(call List,Sourcefile)\
+ $(call List,blua/Sourcefile)\
+
+depends:=$(basename $(filter %.c %.s,$(sources)))
+objects:=$(basename $(filter %.c %.s %.nas,$(sources)))
+
+depends:=$(depends:%=$(depdir)/%.d)
+
+# comptime.o added directly to objects instead of thru
+# sources because comptime.c includes comptime.h, but
+# comptime.h may not exist yet. It's a headache so this is
+# easier.
+objects:=$(objects:=.o) comptime.o
+
+# windows resource file
+rc_file:=$(basename $(filter %.rc,$(sources)))
+ifdef rc_file
+objects+=$(rc_file:=.res)
+endif
+
+objects:=$(addprefix $(objdir)/,$(objects))
+
+ifdef DEBUGMODE
+bin:=../bin/debug
+else
+bin:=../bin
+endif
+
+# default EXENAME (usually set by platform)
EXENAME?=srb2
DBGNAME?=$(EXENAME).debug
-# $(OBJDIR)/dstrings.o \
+exe:=$(bin)/$(EXENAME)
+dbg:=$(bin)/$(DBGNAME)
-# not too sophisticated dependency
-OBJS:=$(i_main_o) \
- $(OBJDIR)/string.o \
- $(OBJDIR)/d_main.o \
- $(OBJDIR)/d_clisrv.o \
- $(OBJDIR)/d_net.o \
- $(OBJDIR)/d_netfil.o \
- $(OBJDIR)/d_netcmd.o \
- $(OBJDIR)/dehacked.o \
- $(OBJDIR)/deh_soc.o \
- $(OBJDIR)/deh_lua.o \
- $(OBJDIR)/deh_tables.o \
- $(OBJDIR)/z_zone.o \
- $(OBJDIR)/f_finale.o \
- $(OBJDIR)/f_wipe.o \
- $(OBJDIR)/g_demo.o \
- $(OBJDIR)/g_game.o \
- $(OBJDIR)/g_input.o \
- $(OBJDIR)/am_map.o \
- $(OBJDIR)/command.o \
- $(OBJDIR)/console.o \
- $(OBJDIR)/hu_stuff.o \
- $(OBJDIR)/y_inter.o \
- $(OBJDIR)/st_stuff.o \
- $(OBJDIR)/m_aatree.o \
- $(OBJDIR)/m_anigif.o \
- $(OBJDIR)/m_argv.o \
- $(OBJDIR)/m_bbox.o \
- $(OBJDIR)/m_cheat.o \
- $(OBJDIR)/m_cond.o \
- $(OBJDIR)/m_easing.o \
- $(OBJDIR)/m_fixed.o \
- $(OBJDIR)/m_menu.o \
- $(OBJDIR)/m_misc.o \
- $(OBJDIR)/m_perfstats.o \
- $(OBJDIR)/m_random.o \
- $(OBJDIR)/m_queue.o \
- $(OBJDIR)/info.o \
- $(OBJDIR)/p_ceilng.o \
- $(OBJDIR)/p_enemy.o \
- $(OBJDIR)/p_floor.o \
- $(OBJDIR)/p_inter.o \
- $(OBJDIR)/p_lights.o \
- $(OBJDIR)/p_map.o \
- $(OBJDIR)/p_maputl.o \
- $(OBJDIR)/p_mobj.o \
- $(OBJDIR)/p_polyobj.o\
- $(OBJDIR)/p_saveg.o \
- $(OBJDIR)/p_setup.o \
- $(OBJDIR)/p_sight.o \
- $(OBJDIR)/p_spec.o \
- $(OBJDIR)/p_telept.o \
- $(OBJDIR)/p_tick.o \
- $(OBJDIR)/p_user.o \
- $(OBJDIR)/p_slopes.o \
- $(OBJDIR)/tables.o \
- $(OBJDIR)/r_bsp.o \
- $(OBJDIR)/r_data.o \
- $(OBJDIR)/r_draw.o \
- $(OBJDIR)/r_main.o \
- $(OBJDIR)/r_plane.o \
- $(OBJDIR)/r_segs.o \
- $(OBJDIR)/r_skins.o \
- $(OBJDIR)/r_sky.o \
- $(OBJDIR)/r_splats.o \
- $(OBJDIR)/r_things.o \
- $(OBJDIR)/r_textures.o \
- $(OBJDIR)/r_patch.o \
- $(OBJDIR)/r_patchrotation.o \
- $(OBJDIR)/r_picformats.o \
- $(OBJDIR)/r_portal.o \
- $(OBJDIR)/screen.o \
- $(OBJDIR)/taglist.o \
- $(OBJDIR)/v_video.o \
- $(OBJDIR)/s_sound.o \
- $(OBJDIR)/sounds.o \
- $(OBJDIR)/w_wad.o \
- $(OBJDIR)/filesrch.o \
- $(OBJDIR)/mserv.o \
- $(OBJDIR)/http-mserv.o\
- $(OBJDIR)/i_tcp.o \
- $(OBJDIR)/lzf.o \
- $(OBJDIR)/vid_copy.o \
- $(OBJDIR)/b_bot.o \
- $(i_net_o) \
- $(i_system_o) \
- $(i_sound_o) \
- $(OBJS)
+build_done==== Build is done, look for \
+ $( $@
+ $(.)$(GZIP) $(GZIP_OPTS) $@
-ifdef SDL
-all: $(BIN)/$(EXENAME)
-endif
-
-ifdef DUMMY
-all: $(BIN)/$(EXENAME)
-endif
-
-cleandep:
- $(REMOVE) $(DEPS)
- $(REMOVE) comptime.h
-
-clean:
- $(REMOVE) *~ *.flc
- $(REMOVE) $(OBJDIR)/*.o
-
-distclean: clean cleandep
-
-ifdef MINGW
- $(REMOVE) $(OBJDIR)/*.res
-endif
-
-ifdef CYGWIN32
- $(REMOVE) $(OBJDIR)/*.res
-endif
-
-#make a big srb2.s that is the disasm of the exe (dos only ?)
-asm:
- $(CC) $(LDFLAGS) $(OBJS) -o $(OBJDIR)/tmp.exe $(LIBS)
- $(OBJDUMP) -d $(OBJDIR)/tmp.exe --no-show-raw-insn > srb2.s
- $(REMOVE) $(OBJDIR)/tmp.exe
-
-# executable
-$(BIN)/$(EXENAME): $(POS) $(OBJS)
- -$(MKDIR) $(BIN)
- $(call echo,Linking $(EXENAME)...)
- $(LD) $(LDFLAGS) $(OBJS) -o $(BIN)/$(EXENAME) $(LIBS)
-ifndef VALGRIND
-ifndef NOOBJDUMP
- $(call echo,Dumping debugging info)
- $(OBJDUMP) $(OBJDUMP_OPTS) $(BIN)/$(EXENAME) > $(BIN)/$(DBGNAME).txt
+# '::' means run unconditionally
+# this really updates comptime.h
+comptime.c ::
ifdef WINDOWSHELL
- -$(GZIP) $(GZIP_OPTS) $(BIN)/$(DBGNAME).txt
+ $(.)..\comptime.bat .
else
- -$(GZIP) $(GZIP_OPT2) $(BIN)/$(DBGNAME).txt
-endif
+ $(.)../comptime.sh .
endif
-# mac os x lsdlsrb2 does not like objcopy
-ifndef MACOSX
- $(OBJCOPY) $(BIN)/$(EXENAME) $(BIN)/$(DBGNAME)
- $(OBJCOPY) --strip-debug $(BIN)/$(EXENAME)
- -$(OBJCOPY) --add-gnu-debuglink=$(BIN)/$(DBGNAME) $(BIN)/$(EXENAME)
-endif
-ifndef NOUPX
- -$(UPX) $(UPX_OPTS) $(BIN)/$(EXENAME)
-endif
-endif
- $(call echo,Build is done$(,) please look for $(EXENAME) in $(BIN)$(,) (checking for post steps))
+# I wish I could make dependencies out of rc files :(
+$(objdir)/win32/Srb2win.res : \
+ win32/afxres.h win32/resource.h
-reobjdump:
- $(call echo,Redumping debugging info)
- $(OBJDUMP) $(OBJDUMP_OPTS) $(BIN)/$(DBGNAME) > $(BIN)/$(DBGNAME).txt
-ifdef WINDOWSHELL
- -$(GZIP) $(GZIP_OPTS) $(BIN)/$(DBGNAME).txt
-else
- -$(GZIP) $(GZIP_OPT2) $(BIN)/$(DBGNAME).txt
-endif
-
-$(OBJDIR):
- -$(MKDIR) $(OBJDIR)
-
-ifdef SDL
-ifdef MINGW
-$(OBJDIR)/r_opengl.o: hardware/r_opengl/r_opengl.c hardware/r_opengl/r_opengl.h \
- doomdef.h doomtype.h g_state.h m_swap.h hardware/hw_drv.h screen.h \
- command.h hardware/hw_data.h hardware/hw_defs.h \
- hardware/hw_md2.h hardware/hw_glob.h hardware/hw_main.h hardware/hw_clip.h \
- hardware/hw_md2load.h hardware/hw_md3load.h hardware/hw_model.h hardware/u_list.h \
- am_map.h d_event.h d_player.h p_pspr.h m_fixed.h tables.h info.h d_think.h \
- p_mobj.h doomdata.h d_ticcmd.h r_defs.h hardware/hw_dll.h
- $(echoName)
- $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@
-else
-$(OBJDIR)/r_opengl.o: hardware/r_opengl/r_opengl.c hardware/r_opengl/r_opengl.h \
- doomdef.h doomtype.h g_state.h m_swap.h hardware/hw_drv.h screen.h \
- command.h hardware/hw_data.h hardware/hw_defs.h \
- hardware/hw_md2.h hardware/hw_glob.h hardware/hw_main.h hardware/hw_clip.h \
- hardware/hw_md2load.h hardware/hw_md3load.h hardware/hw_model.h hardware/u_list.h \
- am_map.h d_event.h d_player.h p_pspr.h m_fixed.h tables.h info.h d_think.h \
- p_mobj.h doomdata.h d_ticcmd.h r_defs.h hardware/hw_dll.h
- $(echoName)
- $(CC) $(CFLAGS) $(WFLAGS) -I/usr/X11R6/include -c $< -o $@
-endif
-endif
-
-#dependecy made by gcc itself !
-ifndef DUMMY
-ifndef CLEANONLY
-$(call print,Checking dependency files...)
--include $(DEPS)
-endif
-endif
-
-undefine deps_rule
-
-# windows makes it too hard !
+# dependency recipe template
+# 1: source file suffix
+# 2: extra flags to gcc
+define _recipe =
+$(depdir)/%.d : %.$(1) | $$$$(@D)/
ifndef WINDOWSHELL
-ifdef echoName
-define deps_rule =
- @printf "%-20.20s\r" $<
-
-endef
+ifdef Echo_name
+ @printf '%-20.20s\r' $$<
endif
endif
-
-define deps_rule +=
- $(CC) $(CFLAGS) -M -MF $@ -MT $(OBJDIR)/$(<:.c=.o) $<
+ $(.)$(cc) -MM -MF $$@ -MT $(objdir)/$$(*F).o $(2) $$<
endef
-$(DEPDIR)/%.d: %.c
- $(deps_rule)
+$(eval $(call _recipe,c))
+$(eval $(call _recipe,s,$(asflags)))
-$(DEPDIR)/%.d: $(INTERFACE)/%.c
- $(deps_rule)
+# compiling recipe template
+# 1: target file suffix
+# 2: source file suffix
+# 3: compile command
+define _recipe =
+$(objdir)/%.$(1) : %.$(2) | $$$$(@D)/
+ $(call Echo_name,$$<)
+ $(.)$(3)
+endef
-$(DEPDIR)/%.d: hardware/%.c
- $(deps_rule)
+$(eval $(call _recipe,o,c,$(cc) -c -o $$@ $$<))
+$(eval $(call _recipe,o,nas,$(nasm) -o $$@ $$<))
+$(eval $(call _recipe,o,s,$(cc) $(asflags) -c -o $$@ $$<))
+$(eval $(call _recipe,res,rc,$(windres) -i $$< -o $$@))
-$(DEPDIR)/%.d: blua/%.c
- $(deps_rule)
+_rm=$(.)$(rmrf) $(call Windows_path,$(1))
-ifdef VALGRIND
-$(OBJDIR)/z_zone.o: z_zone.c
- $(echoName)
- $(CC) $(CFLAGS) $(WFLAGS) -DHAVE_VALGRIND $(VALGRIND_CFLAGS) -c $< -o $@
-endif
+cleandep :
+ $(call _rm,$(depends) comptime.h)
-$(OBJDIR)/comptime.o::
-ifdef echoName
- @echo -- comptime.c ...
-endif
- $(COMPTIME) .
- $(CC) $(CFLAGS) $(WFLAGS) -c comptime.c -o $@
+clean :
+ $(call _rm,$(exe) $(dbg) $(dbg).txt $(objects))
-$(BIN)/%.mo: locale/%.po
- -$(MKDIR) $(BIN)
- $(echoName)
- $(MSGFMT) -f -o $@ $<
+distclean :
+ $(call _rm,../bin ../objs ../deps ../make comptime.h)
-$(OBJDIR)/%.o: %.c
- $(echoName)
- $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@
-
-$(OBJDIR)/%.o: $(INTERFACE)/%.c
- $(echoName)
- $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@
-
-ifdef MACOSX
-$(OBJDIR)/%.o: sdl/macosx/%.c
- $(echoName)
- $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@
-endif
-
-$(OBJDIR)/%.o: hardware/%.c
- $(echoName)
- $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@
-
-$(OBJDIR)/%.o: blua/%.c
- $(echoName)
- $(CC) $(CFLAGS) $(LUA_CFLAGS) $(WFLAGS) -c $< -o $@
-
-$(OBJDIR)/%.o: %.nas
- $(echoName)
- $(NASM) $(NASMOPTS) -o $@ -f $(NASMFORMAT) $<
-
-$(OBJDIR)/vid_copy.o: vid_copy.s asm_defs.inc
- $(echoName)
- $(CC) $(OPTS) $(ASFLAGS) -x assembler-with-cpp -c $< -o $@
-
-$(OBJDIR)/%.o: %.s
- $(echoName)
- $(CC) $(OPTS) -x assembler-with-cpp -c $< -o $@
-
-$(OBJDIR)/SRB2.res: win32/Srb2win.rc win32/afxres.h win32/resource.h
- $(echoName)
- $(WINDRES) -i $< -O rc $(WINDRESFLAGS) --include-dir=win32 -o $@ -O coff
-
-
-ifdef SDL
-
-ifdef MINGW
-$(OBJDIR)/win_dbg.o: win32/win_dbg.c
- $(echoName)
- $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@
-endif
-
-ifdef STATICHS
-$(OBJDIR)/s_openal.o: hardware/s_openal/s_openal.c hardware/hw3dsdrv.h \
- hardware/hw_dll.h
- $(echoName)
- $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@
-
-$(OBJDIR)/s_fmod.o: hardware/s_fmod/s_fmod.c hardware/hw3dsdrv.h \
- hardware/hw_dll.h
- $(echoName)
- $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@
-
-ifdef MINGW
-$(OBJDIR)/s_ds3d.o: hardware/s_ds3d/s_ds3d.c hardware/hw3dsdrv.h \
- hardware/hw_dll.h
- $(echoName)
- $(CC) $(CFLAGS) $(WFLAGS) -c $< -o $@
-endif
+info:
+ifdef WINDOWSHELL
+ @REM
else
-
-$(OBJDIR)/s_fmod.o: hardware/s_fmod/s_fmod.c hardware/hw3dsdrv.h \
- hardware/hw_dll.h
- $(echoName)
- $(CC) $(ARCHOPTS) -Os -o $(OBJDIR)/s_fmod.o -DHW3SOUND -DUNIXCOMMON -shared -nostartfiles -c hardware/s_fmod/s_fmod.c
-
-$(OBJDIR)/s_openal.o: hardware/s_openal/s_openal.c hardware/hw3dsdrv.h \
- hardware/hw_dll.h
- $(echoName)
- $(CC) $(ARCHOPTS) -Os -o $(OBJDIR)/s_openal.o -DHW3SOUND -DUNIXCOMMON -shared -nostartfiles -c hardware/s_openal/s_openal.c
+ @:
endif
-endif
-
-#############################################################
-#
-#############################################################
diff --git a/src/Makefile.cfg b/src/Makefile.cfg
deleted file mode 100644
index 90dce0073..000000000
--- a/src/Makefile.cfg
+++ /dev/null
@@ -1,478 +0,0 @@
-# vim: ft=make
-#
-# Makefile.cfg for SRB2
-#
-
-#
-# GNU compiler & tools' flags
-# and other things
-#
-
-# See the following variable don't start with 'GCC'. This is
-# to avoid a false positive with the version detection...
-
-SUPPORTED_GCC_VERSIONS:=\
- 101 102\
- 91 92 93\
- 81 82 83 84\
- 71 72 73 74 75\
- 61 62 63 64\
- 51 52 53 54 55\
- 40 41 42 43 44 45 46 47 48 49
-
-LATEST_GCC_VERSION=10.2
-
-# gcc or g++
-ifdef PREFIX
- CC=$(PREFIX)-gcc
- CXX=$(PREFIX)-g++
- OBJCOPY=$(PREFIX)-objcopy
- OBJDUMP=$(PREFIX)-objdump
- STRIP=$(PREFIX)-strip
- WINDRES=$(PREFIX)-windres
-else
- OBJCOPY=objcopy
- OBJDUMP=objdump
- STRIP=strip
- WINDRES=windres
-endif
-
-# because Apple screws with us on this
-# need to get bintools from homebrew
-ifdef MACOSX
- CC=clang
- CXX=clang
- OBJCOPY=gobjcopy
- OBJDUMP=gobjdump
-endif
-
-# Automatically set version flag, but not if one was manually set
-# And don't bother if this is a clean only run
-ifeq (,$(filter GCC% CLEANONLY,$(.VARIABLES)))
- version:=$(shell $(CC) --version)
- # check if this is in fact GCC
- ifneq (,$(or $(findstring gcc,$(version)),$(findstring GCC,$(version))))
- version:=$(shell $(CC) -dumpversion)
-
- # Turn version into words of major, minor
- v:=$(subst ., ,$(version))
- # concat. major minor
- v:=$(word 1,$(v))$(word 2,$(v))
-
- # If this version is not in the list, default to the latest supported
- ifeq (,$(filter $(v),$(SUPPORTED_GCC_VERSIONS)))
- define line =
- Your compiler version, GCC $(version), is not supported by the Makefile.
- The Makefile will assume GCC $(LATEST_GCC_VERSION).))
- endef
- $(call print,$(line))
- GCC$(subst .,,$(LATEST_GCC_VERSION))=1
- else
- $(call print,Detected GCC $(version) (GCC$(v)))
- GCC$(v)=1
- endif
- endif
-endif
-
-ifdef GCC102
-GCC101=1
-endif
-
-ifdef GCC101
-GCC93=1
-endif
-
-ifdef GCC93
-GCC92=1
-endif
-
-ifdef GCC92
-GCC91=1
-endif
-
-ifdef GCC91
-GCC84=1
-endif
-
-ifdef GCC84
-GCC83=1
-endif
-
-ifdef GCC83
-GCC82=1
-endif
-
-ifdef GCC82
-GCC81=1
-endif
-
-ifdef GCC81
-GCC75=1
-endif
-
-ifdef GCC75
-GCC74=1
-endif
-
-ifdef GCC74
-GCC73=1
-endif
-
-ifdef GCC73
-GCC72=1
-endif
-
-ifdef GCC72
-GCC71=1
-endif
-
-ifdef GCC71
-GCC64=1
-endif
-
-ifdef GCC64
-GCC63=1
-endif
-
-ifdef GCC63
-GCC62=1
-endif
-
-ifdef GCC62
-GCC61=1
-endif
-
-ifdef GCC61
-GCC55=1
-endif
-
-ifdef GCC55
-GCC54=1
-endif
-
-ifdef GCC54
-GCC53=1
-endif
-
-ifdef GCC53
-GCC52=1
-endif
-
-ifdef GCC52
-GCC51=1
-endif
-
-ifdef GCC51
-GCC49=1
-endif
-
-ifdef GCC49
-GCC48=1
-endif
-
-ifdef GCC48
-GCC47=1
-endif
-
-ifdef GCC47
-GCC46=1
-endif
-
-ifdef GCC46
-GCC45=1
-endif
-
-ifdef GCC45
-GCC44=1
-endif
-
-ifdef GCC44
-GCC43=1
-endif
-
-ifdef GCC43
-GCC42=1
-endif
-
-ifdef GCC42
-GCC41=1
-endif
-
-ifdef GCC41
-GCC40=1
-VCHELP=1
-endif
-
-ifdef GCC295
-GCC29=1
-endif
-
-OLDWFLAGS:=$(WFLAGS)
-# -W -Wno-unused
-WFLAGS=-Wall -Wno-trigraphs
-ifndef GCC295
-#WFLAGS+=-Wno-packed
-endif
-ifndef RELAXWARNINGS
- WFLAGS+=-W
-#WFLAGS+=-Wno-sign-compare
-ifndef GCC295
- WFLAGS+=-Wno-div-by-zero
-endif
-#WFLAGS+=-Wsystem-headers
-WFLAGS+=-Wfloat-equal
-#WFLAGS+=-Wtraditional
-ifdef VCHELP
- WFLAGS+=-Wdeclaration-after-statement
- WFLAGS+=-Wno-error=declaration-after-statement
-endif
- WFLAGS+=-Wundef
-ifndef GCC295
- WFLAGS+=-Wendif-labels
-endif
-ifdef GCC41
- WFLAGS+=-Wshadow
-endif
-#WFLAGS+=-Wlarger-than-%len%
- WFLAGS+=-Wpointer-arith -Wbad-function-cast
-ifdef GCC45
-#WFLAGS+=-Wc++-compat
-endif
- WFLAGS+=-Wcast-qual
-ifndef NOCASTALIGNWARN
- WFLAGS+=-Wcast-align
-endif
- WFLAGS+=-Wwrite-strings
-ifndef ERRORMODE
-#WFLAGS+=-Wconversion
-ifdef GCC43
- #WFLAGS+=-Wno-sign-conversion
-endif
-endif
- WFLAGS+=-Wsign-compare
-ifdef GCC91
- WFLAGS+=-Wno-error=address-of-packed-member
-endif
-ifdef GCC45
- WFLAGS+=-Wlogical-op
-endif
- WFLAGS+=-Waggregate-return
-ifdef HAIKU
-ifdef GCC41
- #WFLAGS+=-Wno-attributes
-endif
-endif
-#WFLAGS+=-Wstrict-prototypes
-ifdef GCC40
- WFLAGS+=-Wold-style-definition
-endif
- WFLAGS+=-Wmissing-prototypes -Wmissing-declarations
-ifdef GCC40
- WFLAGS+=-Wmissing-field-initializers
-endif
- WFLAGS+=-Wmissing-noreturn
-#WFLAGS+=-Wmissing-format-attribute
-#WFLAGS+=-Wno-multichar
-#WFLAGS+=-Wno-deprecated-declarations
-#WFLAGS+=-Wpacked
-#WFLAGS+=-Wpadded
-#WFLAGS+=-Wredundant-decls
- WFLAGS+=-Wnested-externs
-#WFLAGS+=-Wunreachable-code
- WFLAGS+=-Winline
-ifdef GCC43
- WFLAGS+=-funit-at-a-time
- WFLAGS+=-Wlogical-op
-endif
-ifndef GCC295
- WFLAGS+=-Wdisabled-optimization
-endif
-endif
-WFLAGS+=-Wformat-y2k
-ifdef GCC71
-WFLAGS+=-Wno-error=format-overflow=2
-endif
-WFLAGS+=-Wformat-security
-ifndef GCC29
-#WFLAGS+=-Winit-self
-endif
-ifdef GCC46
-WFLAGS+=-Wno-suggest-attribute=noreturn
-endif
-
-ifdef NOLDWARNING
-LDFLAGS+=-Wl,--as-needed
-endif
-
-ifdef ERRORMODE
-WFLAGS+=-Werror
-endif
-
-WFLAGS+=$(OLDWFLAGS)
-
-ifdef GCC43
- #WFLAGS+=-Wno-error=clobbered
-endif
-ifdef GCC44
- WFLAGS+=-Wno-error=array-bounds
-endif
-ifdef GCC46
- WFLAGS+=-Wno-error=suggest-attribute=noreturn
-endif
-ifdef GCC54
- WFLAGS+=-Wno-logical-op -Wno-error=logical-op
-endif
-ifdef GCC61
- WFLAGS+=-Wno-tautological-compare -Wno-error=tautological-compare
-endif
-ifdef GCC71
- WFLAGS+=-Wimplicit-fallthrough=4
-endif
-ifdef GCC81
- WFLAGS+=-Wno-error=format-overflow
- WFLAGS+=-Wno-error=stringop-truncation
- WFLAGS+=-Wno-error=stringop-overflow
- WFLAGS+=-Wno-format-overflow
- WFLAGS+=-Wno-stringop-truncation
- WFLAGS+=-Wno-stringop-overflow
- WFLAGS+=-Wno-error=multistatement-macros
-endif
-
-
-#indicate platform and what interface use with
-ifndef LINUX
-ifndef FREEBSD
-ifndef CYGWIN32
-ifndef MINGW
-ifndef MINGW64
-ifndef SDL
-ifndef DUMMY
-$(error No interface or platform flag defined)
-endif
-endif
-endif
-endif
-endif
-endif
-endif
-
-#determine the interface directory (where you put all i_*.c)
-i_net_o=$(OBJDIR)/i_net.o
-i_system_o=$(OBJDIR)/i_system.o
-i_sound_o=$(OBJDIR)/i_sound.o
-i_main_o=$(OBJDIR)/i_main.o
-#set OBJDIR and BIN's starting place
-OBJDIR=../objs
-BIN=../bin
-DEPDIR=../dep
-#Nasm ASM and rm
-ifdef YASM
-NASM?=yasm
-else
-NASM?=nasm
-endif
-REMOVE?=rm -f
-MKDIR?=mkdir -p
-GZIP?=gzip
-GZIP_OPTS?=-9 -f -n
-GZIP_OPT2=$(GZIP_OPTS) --rsyncable
-UPX?=upx
-UPX_OPTS?=--best --preserve-build-id
-ifndef ECHO
-UPX_OPTS+=-q
-endif
-
-#Interface Setup
-ifdef DUMMY
- INTERFACE=dummy
- OBJDIR:=$(OBJDIR)/dummy
- BIN:=$(BIN)/dummy
- DEPDIR:=$(DEPDIR)/dummy
-else
-ifdef LINUX
- NASMFORMAT=elf -DLINUX
- SDL=1
-ifdef LINUX64
- OBJDIR:=$(OBJDIR)/Linux64
- BIN:=$(BIN)/Linux64
- DEPDIR:=$(DEPDIR)/Linux64
-else
- OBJDIR:=$(OBJDIR)/Linux
- BIN:=$(BIN)/Linux
- DEPDIR:=$(DEPDIR)/Linux
-endif
-else
-ifdef FREEBSD
- INTERFACE=sdl
- NASMFORMAT=elf -DLINUX
- SDL=1
-
- OBJDIR:=$(OBJDIR)/FreeBSD
- BIN:=$(BIN)/FreeBSD
- DEPDIR:=$(DEPDIR)/Linux
-else
-ifdef SOLARIS
- INTERFACE=sdl
- NASMFORMAT=elf -DLINUX
- SDL=1
-
- OBJDIR:=$(OBJDIR)/Solaris
- BIN:=$(BIN)/Solaris
- DEPDIR:=$(DEPDIR)/Solaris
-else
-ifdef CYGWIN32
- INTERFACE=sdl
- NASMFORMAT=win32
- SDL=1
-
- OBJDIR:=$(OBJDIR)/cygwin
- BIN:=$(BIN)/Cygwin
- DEPDIR:=$(DEPDIR)/Cygwin
-else
-ifdef MINGW64
- #NASMFORMAT=win64
- SDL=1
- OBJDIR:=$(OBJDIR)/Mingw64
- BIN:=$(BIN)/Mingw64
- DEPDIR:=$(DEPDIR)/Mingw64
-else
-ifdef MINGW
- NASMFORMAT=win32
- SDL=1
- OBJDIR:=$(OBJDIR)/Mingw
- BIN:=$(BIN)/Mingw
- DEPDIR:=$(DEPDIR)/Mingw
-endif
-endif
-endif
-endif
-endif
-endif
-endif
-
-ifdef ARCHNAME
- OBJDIR:=$(OBJDIR)/$(ARCHNAME)
- BIN:=$(BIN)/$(ARCHNAME)
- DEPDIR:=$(DEPDIR)/$(ARCHNAME)
-endif
-
-OBJDUMP_OPTS?=--wide --source --line-numbers
-LD=$(CC)
-
-ifdef SDL
- INTERFACE=sdl
- OBJDIR:=$(OBJDIR)/SDL
- DEPDIR:=$(DEPDIR)/SDL
-endif
-
-ifndef DUMMY
-ifdef DEBUGMODE
- OBJDIR:=$(OBJDIR)/Debug
- BIN:=$(BIN)/Debug
- DEPDIR:=$(DEPDIR)/Debug
-else
- OBJDIR:=$(OBJDIR)/Release
- BIN:=$(BIN)/Release
- DEPDIR:=$(DEPDIR)/Release
-endif
-endif
diff --git a/src/Makefile.d/detect.mk b/src/Makefile.d/detect.mk
new file mode 100644
index 000000000..3edf0dad4
--- /dev/null
+++ b/src/Makefile.d/detect.mk
@@ -0,0 +1,107 @@
+#
+# Detect the host system and compiler version.
+#
+
+# Previously featured:\
+ PANDORA\
+ HAIKU\
+ DUMMY\
+ DJGPPDOS\
+ SOLARIS\
+ MACOSX\
+
+all_systems:=\
+ LINUX64\
+ MINGW64\
+ MINGW\
+ UNIX\
+ LINUX\
+ FREEBSD\
+ SDL\
+
+# check for user specified system
+ifeq (,$(filter $(all_systems),$(.VARIABLES)))
+ifeq ($(OS),Windows_NT) # all windows are Windows_NT...
+
+_m=Detected a Windows system,\
+ compiling for 32-bit MinGW SDL...)
+$(call Print,$(_m))
+
+# go for a 32-bit sdl mingw exe by default
+MINGW:=1
+# cmd.exe uses native Windows semicolon delimited PATH
+ifneq (,$(findstring ;,$(PATH)))
+WINDOWSHELL:=1
+endif
+
+else # if you on the *nix
+
+system:=$(shell uname -s)
+
+ifeq ($(system),Linux)
+new_system:=LINUX
+else
+
+$(error \
+ Could not automatically detect your system,\
+ try specifying a system manually)
+
+endif
+
+ifeq ($(shell getconf LONG_BIT),64)
+system+=64-bit
+new_system:=$(new_system)64
+endif
+
+$(call Print,Detected $(system) ($(new_system))...)
+$(new_system):=1
+
+endif
+endif
+
+# This must have high to low order.
+gcc_versions:=\
+ 102 101\
+ 93 92 91\
+ 84 83 82 81\
+ 75 74 73 72 71\
+ 64 63 62 61\
+ 55 54 53 52 51\
+ 49 48 47 46 45 44 43 42 41 40
+
+latest_gcc_version:=10.2
+
+# Automatically set version flag, but not if one was
+# manually set. And don't bother if this is a clean only
+# run.
+ifeq (,$(call Wildvar,GCC% destructive))
+version:=$(shell $(CC) --version)
+
+# check if this is in fact GCC
+ifneq (,$(or $(findstring gcc,$(version)),\
+ $(findstring GCC,$(version))))
+
+version:=$(shell $(CC) -dumpversion)
+
+# Turn version into words of major, minor
+v:=$(subst ., ,$(version))
+# concat. major minor
+v:=$(word 1,$(v))$(word 2,$(v))
+
+# If this version is not in the list,
+# default to the latest supported
+ifeq (,$(filter $(v),$(gcc_versions)))
+define line =
+Your compiler version, GCC $(version), \
+is not supported by the Makefile.
+The Makefile will assume GCC $(latest_gcc_version).
+endef
+$(call Print,$(line))
+GCC$(subst .,,$(latest_gcc_version)):=1
+else
+$(call Print,Detected GCC $(version) (GCC$(v)))
+GCC$(v):=1
+endif
+
+endif
+endif
diff --git a/src/Makefile.d/features.mk b/src/Makefile.d/features.mk
new file mode 100644
index 000000000..46194390d
--- /dev/null
+++ b/src/Makefile.d/features.mk
@@ -0,0 +1,75 @@
+#
+# Makefile for feature flags.
+#
+
+passthru_opts+=\
+ NONET NO_IPV6 NOHW NOMD5 NOPOSTPROCESSING\
+ MOBJCONSISTANCY PACKETDROP ZDEBUG\
+ HAVE_MINIUPNPC\
+
+# build with debugging information
+ifdef DEBUGMODE
+PACKETDROP=1
+opts+=-DPARANOIA -DRANGECHECK
+endif
+
+ifndef NOHW
+opts+=-DHWRENDER
+sources+=$(call List,hardware/Sourcefile)
+endif
+
+ifndef NOASM
+ifndef NONX86
+sources+=tmap.nas tmap_mmx.nas
+opts+=-DUSEASM
+endif
+endif
+
+ifndef NOMD5
+sources+=md5.c
+endif
+
+ifndef NOZLIB
+ifndef NOPNG
+ifdef PNG_PKGCONFIG
+$(eval $(call Use_pkg_config,PNG_PKGCONFIG))
+else
+PNG_CONFIG?=$(call Prefix,libpng-config)
+$(eval $(call Configure,PNG,$(PNG_CONFIG) \
+ $(if $(PNG_STATIC),--static),,--ldflags))
+endif
+ifdef LINUX
+opts+=-D_LARGFILE64_SOURCE
+endif
+opts+=-DHAVE_PNG
+sources+=apng.c
+endif
+endif
+
+ifndef NONET
+ifndef NOCURL
+CURLCONFIG?=curl-config
+$(eval $(call Configure,CURL,$(CURLCONFIG)))
+opts+=-DHAVE_CURL
+endif
+endif
+
+ifdef HAVE_MINIUPNPC
+libs+=-lminiupnpc
+endif
+
+# (Valgrind is a memory debugger.)
+ifdef VALGRIND
+VALGRIND_PKGCONFIG?=valgrind
+$(eval $(call Use_pkg_config,VALGRIND))
+ZDEBUG=1
+opts+=-DHAVE_VALGRIND
+endif
+
+default_packages:=\
+ GME/libgme/LIBGME\
+ OPENMPT/libopenmpt/LIBOPENMPT\
+ ZLIB/zlib\
+
+$(foreach p,$(default_packages),\
+ $(eval $(call Check_pkg_config,$(p))))
diff --git a/src/Makefile.d/nix.mk b/src/Makefile.d/nix.mk
new file mode 100644
index 000000000..6642a6bcc
--- /dev/null
+++ b/src/Makefile.d/nix.mk
@@ -0,0 +1,42 @@
+#
+# Makefile options for unices (linux, bsd...)
+#
+
+EXENAME?=lsdl2srb2
+
+opts+=-DUNIXCOMMON -DLUA_USE_POSIX
+# Use -rdynamic so a backtrace log shows function names
+# instead of addresses
+libs+=-lm -rdynamic
+
+ifndef nasm_format
+nasm_format:=elf -DLINUX
+endif
+
+ifndef NOHW
+opts+=-I/usr/X11R6/include
+libs+=-L/usr/X11R6/lib
+endif
+
+SDL=1
+
+# In common usage.
+ifdef LINUX
+libs+=-lrt
+passthru_opts+=NOTERMIOS
+endif
+
+# Tested by Steel, as of release 2.2.8.
+ifdef FREEBSD
+opts+=-I/usr/X11R6/include -DLINUX -DFREEBSD
+libs+=-L/usr/X11R6/lib -lipx -lkvm
+endif
+
+# FIXME: UNTESTED
+#ifdef SOLARIS
+#NOIPX=1
+#NOASM=1
+#opts+=-I/usr/local/include -I/opt/sfw/include \
+# -DSOLARIS -DINADDR_NONE=INADDR_ANY -DBSD_COMP
+#libs+=-L/opt/sfw/lib -lsocket -lnsl
+#endif
diff --git a/src/Makefile.d/old.mk b/src/Makefile.d/old.mk
new file mode 100644
index 000000000..ec9b6d776
--- /dev/null
+++ b/src/Makefile.d/old.mk
@@ -0,0 +1,16 @@
+#
+# Warn about old build directories and offer to purge.
+#
+
+_old:=$(wildcard $(addprefix ../bin/,FreeBSD Linux \
+ Linux64 Mingw Mingw64 SDL dummy) ../objs ../dep)
+
+ifdef _old
+$(foreach v,$(_old),$(info $(abspath $(v))))
+$(info )
+$(info These directories are no longer\
+ required and should be removed.)
+$(info You may remove them manually or\
+ by using 'make distclean')
+$(error )
+endif
diff --git a/src/Makefile.d/platform.mk b/src/Makefile.d/platform.mk
new file mode 100644
index 000000000..fad4be191
--- /dev/null
+++ b/src/Makefile.d/platform.mk
@@ -0,0 +1,69 @@
+#
+# Platform specific options.
+#
+
+PKG_CONFIG?=pkg-config
+
+ifdef WINDOWSHELL
+rmrf=-2>NUL DEL /S /Q
+mkdir=-2>NUL MD
+cat=TYPE
+else
+rmrf=rm -rf
+mkdir=mkdir -p
+cat=cat
+endif
+
+ifdef LINUX64
+LINUX=1
+endif
+
+ifdef MINGW64
+MINGW=1
+endif
+
+ifdef LINUX
+UNIX=1
+ifdef LINUX64
+NONX86=1
+# LINUX64 does not imply X86_64=1;
+# could mean ARM64 or Itanium
+platform=linux/64
+else
+platform=linux
+endif
+else ifdef FREEBSD
+UNIX=1
+platform=freebsd
+else ifdef SOLARIS # FIXME: UNTESTED
+UNIX=1
+platform=solaris
+else ifdef CYGWIN32 # FIXME: UNTESTED
+nasm_format=win32
+platform=cygwin
+else ifdef MINGW
+ifdef MINGW64
+NONX86=1
+NOASM=1
+# MINGW64 should not necessarily imply X86_64=1,
+# but we make that assumption elsewhere
+# Once that changes, remove this
+X86_64=1
+platform=mingw/64
+else
+platform=mingw
+endif
+include Makefile.d/win32.mk
+endif
+
+ifdef platform
+makedir:=$(makedir)/$(platform)
+endif
+
+ifdef UNIX
+include Makefile.d/nix.mk
+endif
+
+ifdef SDL
+include Makefile.d/sdl.mk
+endif
diff --git a/src/Makefile.d/sdl.mk b/src/Makefile.d/sdl.mk
new file mode 100644
index 000000000..99ca624e6
--- /dev/null
+++ b/src/Makefile.d/sdl.mk
@@ -0,0 +1,79 @@
+#
+# Makefile options for SDL2 backend.
+#
+
+#
+# SDL...., *looks at Alam*, THIS IS A MESS!
+#
+# ...a little bird flexes its muscles...
+#
+
+makedir:=$(makedir)/SDL
+
+sources+=$(call List,sdl/Sourcefile)
+opts+=-DDIRECTFULLSCREEN -DHAVE_SDL
+
+# FIXME: UNTESTED
+#ifdef PANDORA
+#include sdl/SRB2Pandora/Makefile.cfg
+#endif #ifdef PANDORA
+
+# FIXME: UNTESTED
+#ifdef CYGWIN32
+#include sdl/MakeCYG.cfg
+#endif #ifdef CYGWIN32
+
+ifndef NOHW
+sources+=sdl/ogl_sdl.c
+endif
+
+ifdef NOMIXER
+sources+=sdl/sdl_sound.c
+else
+opts+=-DHAVE_MIXER
+sources+=sdl/mixer_sound.c
+
+ ifdef HAVE_MIXERX
+ opts+=-DHAVE_MIXERX
+ libs+=-lSDL2_mixer_ext
+ else
+ libs+=-lSDL2_mixer
+ endif
+endif
+
+ifndef NOTHREADS
+opts+=-DHAVE_THREADS
+sources+=sdl/i_threads.c
+endif
+
+ifdef SDL_PKGCONFIG
+$(eval $(call Use_pkg_config,SDL))
+else
+SDL_CONFIG?=$(call Prefix,sdl2-config)
+SDL_CFLAGS?=$(shell $(SDL_CONFIG) --cflags)
+SDL_LDFLAGS?=$(shell $(SDL_CONFIG) \
+ $(if $(STATIC),--static-libs,--libs))
+$(eval $(call Propogate_flags,SDL))
+endif
+
+# use the x86 asm code
+ifndef CYGWIN32
+ifndef NOASM
+USEASM=1
+endif
+endif
+
+ifdef MINGW
+ifndef NOSDLMAIN
+SDLMAIN=1
+endif
+endif
+
+ifdef SDLMAIN
+opts+=-DSDLMAIN
+else
+ifdef MINGW
+opts+=-Umain
+libs+=-mconsole
+endif
+endif
diff --git a/src/Makefile.d/util.mk b/src/Makefile.d/util.mk
new file mode 100644
index 000000000..bda68df13
--- /dev/null
+++ b/src/Makefile.d/util.mk
@@ -0,0 +1,93 @@
+#
+# Utility macros for the rest of the Makefiles.
+#
+
+Ifnot=$(if $(1),$(3),$(2))
+Ifndef=$(call Ifnot,$($(1)),$(2),$(3))
+
+# Match and expand a list of variables by pattern.
+Wildvar=$(foreach v,$(filter $(1),$(.VARIABLES)),$($(v)))
+
+# Read a list of words from file and prepend each with the
+# directory of the file.
+_cat=$(shell $(cat) $(call Windows_path,$(1)))
+List=$(addprefix $(dir $(1)),$(call _cat,$(1)))
+
+# Convert path separators to backslash on Windows.
+Windows_path=$(if $(WINDOWSHELL),$(subst /,\,$(1)),$(1))
+
+define Propogate_flags =
+opts+=$$($(1)_CFLAGS)
+libs+=$$($(1)_LDFLAGS)
+endef
+
+# Set library's _CFLAGS and _LDFLAGS from some command.
+# Automatically propogates the flags too.
+# 1: variable prefix (e.g. CURL)
+# 2: start of command (e.g. curl-config)
+# --- optional ----
+# 3: CFLAGS command arguments, default '--cflags'
+# 4: LDFLAGS command arguments, default '--libs'
+# 5: common command arguments at the end of command
+define Configure =
+$(1)_CFLAGS?=$$(shell $(2) $(or $(3),--cflags) $(5))
+$(1)_LDFLAGS?=$$(shell $(2) $(or $(4),--libs) $(5))
+$(call Propogate_flags,$(1))
+endef
+
+# Configure library with pkg-config. The package name is
+# taken from a _PKGCONFIG variable.
+# 1: variable prefix
+#
+# LIBGME_PKGCONFIG=libgme
+# $(eval $(call Use_pkg_config,LIBGME))
+define Use_pkg_config =
+$(call Configure,$(1),$(PKG_CONFIG),,,$($(1)_PKGCONFIG))
+endef
+
+# Check disabling flag and configure package in one step
+# according to delimited argument.
+# (There is only one argument, but it split by slash.)
+# 1/: short form library name (uppercase). This is
+# prefixed with 'NO' and 'HAVE_'. E.g. NOGME, HAVE_GME
+# /2: package name (e.g. libgme)
+# /3: variable prefix
+#
+# The following example would check if NOGME is not
+# defined before attempting to define LIBGME_CFLAGS and
+# LIBGME_LDFLAGS as with Use_pkg_config.
+#
+# $(eval $(call Check_pkg_config,GME/libgme/LIBGME))
+define Check_pkg_config =
+_p:=$(subst /, ,$(1))
+_v1:=$$(word 1,$$(_p))
+_v2:=$$(or $$(word 3,$$(_p)),$$(_v1))
+ifndef NO$$(_v1)
+$$(_v2)_PKGCONFIG?=$$(word 2,$$(_p))
+$$(eval $$(call Use_pkg_config,$$(_v2)))
+opts+=-DHAVE_$$(_v1)
+endif
+endef
+
+# $(call Prefix,gcc)
+Prefix=$(if $(PREFIX),$(PREFIX)-)$(1)
+
+Echo=
+Echo_name=
+Print=
+
+ifndef SILENT
+Echo=@echo $(1)
+ifndef ECHO
+ifndef NOECHOFILENAMES
+Echo_name=$(call Echo,-- $(1) ...)
+endif
+endif
+ifndef MAKE_RESTARTS
+ifndef destructive
+Print=$(info $(1))
+endif
+endif
+endif
+
+.=$(call Ifndef,ECHO,@)
diff --git a/src/Makefile.d/versions.mk b/src/Makefile.d/versions.mk
new file mode 100644
index 000000000..d7d0c3dd1
--- /dev/null
+++ b/src/Makefile.d/versions.mk
@@ -0,0 +1,177 @@
+#
+# Flags to put a sock in GCC!
+#
+
+# See the versions list in detect.mk
+# This will define all version flags going backward.
+# Yes, it's magic.
+define _predecessor =
+ifdef GCC$(firstword $(1))
+GCC$(lastword $(1)):=1
+endif
+endef
+_n:=$(words $(gcc_versions))
+$(foreach v,$(join $(wordlist 2,$(_n),- $(gcc_versions)),\
+ $(addprefix =,$(wordlist 2,$(_n),$(gcc_versions)))),\
+ $(and $(findstring =,$(v)),\
+ $(eval $(call _predecessor,$(subst =, ,$(v))))))
+
+# -W -Wno-unused
+WFLAGS:=-Wall -Wno-trigraphs
+ifndef GCC295
+#WFLAGS+=-Wno-packed
+endif
+ifndef RELAXWARNINGS
+ WFLAGS+=-W
+#WFLAGS+=-Wno-sign-compare
+ifndef GCC295
+ WFLAGS+=-Wno-div-by-zero
+endif
+#WFLAGS+=-Wsystem-headers
+WFLAGS+=-Wfloat-equal
+#WFLAGS+=-Wtraditional
+ WFLAGS+=-Wundef
+ifndef GCC295
+ WFLAGS+=-Wendif-labels
+endif
+ifdef GCC41
+ WFLAGS+=-Wdeclaration-after-statement
+ WFLAGS+=-Wno-error=declaration-after-statement
+ WFLAGS+=-Wshadow
+endif
+#WFLAGS+=-Wlarger-than-%len%
+ WFLAGS+=-Wpointer-arith -Wbad-function-cast
+ifdef GCC45
+#WFLAGS+=-Wc++-compat
+endif
+ WFLAGS+=-Wcast-qual
+ifndef NOCASTALIGNWARN
+ WFLAGS+=-Wcast-align
+endif
+ WFLAGS+=-Wwrite-strings
+ifndef ERRORMODE
+#WFLAGS+=-Wconversion
+ifdef GCC43
+ #WFLAGS+=-Wno-sign-conversion
+endif
+endif
+ WFLAGS+=-Wsign-compare
+ifdef GCC91
+ WFLAGS+=-Wno-error=address-of-packed-member
+endif
+ifdef GCC45
+ WFLAGS+=-Wlogical-op
+endif
+ WFLAGS+=-Waggregate-return
+ifdef HAIKU
+ifdef GCC41
+ #WFLAGS+=-Wno-attributes
+endif
+endif
+#WFLAGS+=-Wstrict-prototypes
+ifdef GCC40
+ WFLAGS+=-Wold-style-definition
+endif
+ WFLAGS+=-Wmissing-prototypes -Wmissing-declarations
+ifdef GCC40
+ WFLAGS+=-Wmissing-field-initializers
+endif
+ WFLAGS+=-Wmissing-noreturn
+#WFLAGS+=-Wmissing-format-attribute
+#WFLAGS+=-Wno-multichar
+#WFLAGS+=-Wno-deprecated-declarations
+#WFLAGS+=-Wpacked
+#WFLAGS+=-Wpadded
+#WFLAGS+=-Wredundant-decls
+ WFLAGS+=-Wnested-externs
+#WFLAGS+=-Wunreachable-code
+ WFLAGS+=-Winline
+ifdef GCC43
+ WFLAGS+=-funit-at-a-time
+ WFLAGS+=-Wlogical-op
+endif
+ifndef GCC295
+ WFLAGS+=-Wdisabled-optimization
+endif
+endif
+WFLAGS+=-Wformat-y2k
+ifdef GCC71
+WFLAGS+=-Wno-error=format-overflow=2
+endif
+WFLAGS+=-Wformat-security
+ifndef GCC29
+#WFLAGS+=-Winit-self
+endif
+ifdef GCC46
+WFLAGS+=-Wno-suggest-attribute=noreturn
+endif
+
+ifdef NOLDWARNING
+LDFLAGS+=-Wl,--as-needed
+endif
+
+ifdef ERRORMODE
+WFLAGS+=-Werror
+endif
+
+ifdef GCC43
+ #WFLAGS+=-Wno-error=clobbered
+endif
+ifdef GCC44
+ WFLAGS+=-Wno-error=array-bounds
+endif
+ifdef GCC46
+ WFLAGS+=-Wno-error=suggest-attribute=noreturn
+endif
+ifdef GCC54
+ WFLAGS+=-Wno-logical-op -Wno-error=logical-op
+endif
+ifdef GCC61
+ WFLAGS+=-Wno-tautological-compare -Wno-error=tautological-compare
+endif
+ifdef GCC71
+ WFLAGS+=-Wimplicit-fallthrough=4
+endif
+ifdef GCC81
+ WFLAGS+=-Wno-error=format-overflow
+ WFLAGS+=-Wno-error=stringop-truncation
+ WFLAGS+=-Wno-error=stringop-overflow
+ WFLAGS+=-Wno-format-overflow
+ WFLAGS+=-Wno-stringop-truncation
+ WFLAGS+=-Wno-stringop-overflow
+ WFLAGS+=-Wno-error=multistatement-macros
+endif
+
+ifdef NONX86
+ ifdef X86_64 # yeah that SEEMS contradictory
+ opts+=-march=nocona
+ endif
+else
+ ifndef GCC29
+ opts+=-msse3 -mfpmath=sse
+ else
+ opts+=-mpentium
+ endif
+endif
+
+ifdef DEBUGMODE
+ifdef GCC48
+opts+=-Og
+else
+opts+=O0
+endif
+endif
+
+ifdef VALGRIND
+ifdef GCC46
+WFLAGS+=-Wno-error=unused-but-set-variable
+WFLAGS+=-Wno-unused-but-set-variable
+endif
+endif
+
+# Lua
+ifdef GCC43
+ifndef GCC44
+WFLAGS+=-Wno-logical-op
+endif
+endif
diff --git a/src/Makefile.d/win32.mk b/src/Makefile.d/win32.mk
new file mode 100644
index 000000000..0c671b268
--- /dev/null
+++ b/src/Makefile.d/win32.mk
@@ -0,0 +1,99 @@
+#
+# Mingw, if you don't know, that's Win32/Win64
+#
+
+ifndef MINGW64
+EXENAME?=srb2win.exe
+else
+EXENAME?=srb2win64.exe
+endif
+
+sources+=win32/Srb2win.rc
+opts+=-DSTDC_HEADERS
+libs+=-ladvapi32 -lkernel32 -lmsvcrt -luser32
+
+nasm_format:=win32
+
+SDL=1
+
+ifndef NOHW
+opts+=-DUSE_WGL_SWAP
+endif
+
+ifdef MINGW64
+libs+=-lws2_32
+else
+ifdef NO_IPV6
+libs+=-lwsock32
+else
+libs+=-lws2_32
+endif
+endif
+
+ifndef NONET
+ifndef MINGW64 # miniupnc is broken with MINGW64
+opts+=-I../libs -DSTATIC_MINIUPNPC
+libs+=-L../libs/miniupnpc/mingw$(32) -lws2_32 -liphlpapi
+endif
+endif
+
+ifndef MINGW64
+32=32
+x86=x86
+i686=i686
+else
+32=64
+x86=x86_64
+i686=x86_64
+endif
+
+mingw:=$(i686)-w64-mingw32
+
+define _set =
+$(1)_CFLAGS?=$($(1)_opts)
+$(1)_LDFLAGS?=$($(1)_libs)
+endef
+
+lib:=../libs/gme
+LIBGME_opts:=-I$(lib)/include
+LIBGME_libs:=-L$(lib)/win$(32) -lgme
+$(eval $(call _set,LIBGME))
+
+lib:=../libs/libopenmpt
+LIBOPENMPT_opts:=-I$(lib)/inc
+LIBOPENMPT_libs:=-L$(lib)/lib/$(x86)/mingw -lopenmpt
+$(eval $(call _set,LIBOPENMPT))
+
+ifndef NOMIXERX
+HAVE_MIXERX=1
+lib:=../libs/SDLMixerX/$(mingw)
+else
+lib:=../libs/SDL2_mixer/$(mingw)
+endif
+
+mixer_opts:=-I$(lib)/include/SDL2
+mixer_libs:=-L$(lib)/lib
+
+lib:=../libs/SDL2/$(mingw)
+SDL_opts:=-I$(lib)/include/SDL2\
+ $(mixer_opts) -Dmain=SDL_main
+SDL_libs:=-L$(lib)/lib $(mixer_libs)\
+ -lmingw32 -lSDL2main -lSDL2 -mwindows
+$(eval $(call _set,SDL))
+
+lib:=../libs/zlib
+ZLIB_opts:=-I$(lib)
+ZLIB_libs:=-L$(lib)/win32 -lz$(32)
+$(eval $(call _set,ZLIB))
+
+ifndef PNG_CONFIG
+lib:=../libs/libpng-src
+PNG_opts:=-I$(lib)
+PNG_libs:=-L$(lib)/projects -lpng$(32)
+$(eval $(call _set,PNG))
+endif
+
+lib:=../libs/curl
+CURL_opts:=-I$(lib)/include
+CURL_libs:=-L$(lib)/lib$(32) -lcurl
+$(eval $(call _set,CURL))
diff --git a/src/Sourcefile b/src/Sourcefile
new file mode 100644
index 000000000..983dadaf0
--- /dev/null
+++ b/src/Sourcefile
@@ -0,0 +1,98 @@
+string.c
+d_main.c
+d_clisrv.c
+d_net.c
+d_netfil.c
+d_netcmd.c
+dehacked.c
+deh_soc.c
+deh_lua.c
+deh_tables.c
+z_zone.c
+f_finale.c
+f_wipe.c
+g_demo.c
+g_game.c
+g_input.c
+am_map.c
+command.c
+console.c
+hu_stuff.c
+y_inter.c
+st_stuff.c
+m_aatree.c
+m_anigif.c
+m_argv.c
+m_bbox.c
+m_cheat.c
+m_cond.c
+m_easing.c
+m_fixed.c
+m_menu.c
+m_misc.c
+m_perfstats.c
+m_random.c
+m_queue.c
+info.c
+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_spec.c
+p_telept.c
+p_tick.c
+p_user.c
+p_slopes.c
+tables.c
+r_bsp.c
+r_data.c
+r_draw.c
+r_main.c
+r_plane.c
+r_segs.c
+r_skins.c
+r_sky.c
+r_splats.c
+r_things.c
+r_textures.c
+r_patch.c
+r_patchrotation.c
+r_picformats.c
+r_portal.c
+screen.c
+taglist.c
+v_video.c
+s_sound.c
+sounds.c
+w_wad.c
+filesrch.c
+mserv.c
+http-mserv.c
+i_tcp.c
+lzf.c
+vid_copy.s
+b_bot.c
+lua_script.c
+lua_baselib.c
+lua_mathlib.c
+lua_hooklib.c
+lua_consolelib.c
+lua_infolib.c
+lua_mobjlib.c
+lua_playerlib.c
+lua_skinlib.c
+lua_thinkerlib.c
+lua_maplib.c
+lua_taglib.c
+lua_polyobjlib.c
+lua_blockmaplib.c
+lua_hudlib.c
+lua_inputlib.c
diff --git a/src/b_bot.c b/src/b_bot.c
index dc250e643..c61e56f5f 100644
--- a/src/b_bot.c
+++ b/src/b_bot.c
@@ -87,7 +87,7 @@ static void B_BuildTailsTiccmd(mobj_t *sonic, mobj_t *tails, ticcmd_t *cmd)
ang = R_PointToAngle2(tails->x, tails->y, sonic->x, sonic->y);
// Lua can handle it!
- if (LUAh_BotAI(sonic, tails, cmd))
+ if (LUA_HookBotAI(sonic, tails, cmd))
return;
// We can't follow Sonic if he's not around!
@@ -385,7 +385,7 @@ void B_BuildTiccmd(player_t *player, ticcmd_t *cmd)
CV_SetValue(&cv_analog[1], false);
// Let Lua scripts build ticcmds
- if (LUAh_BotTiccmd(player, cmd))
+ if (LUA_HookTiccmd(player, cmd, HOOK(BotTiccmd)))
return;
// Make sure we have a valid main character to follow
@@ -493,7 +493,7 @@ boolean B_CheckRespawn(player_t *player)
// B_RespawnBot doesn't do anything if the condition above this isn't met
{
- UINT8 shouldForce = LUAh_BotRespawn(sonic, tails);
+ UINT8 shouldForce = LUA_Hook2Mobj(sonic, tails, MOBJ_HOOK(BotRespawn));
if (P_MobjWasRemoved(sonic) || P_MobjWasRemoved(tails))
return (shouldForce == 1); // mobj was removed
diff --git a/src/blua/CMakeLists.txt b/src/blua/CMakeLists.txt
new file mode 100644
index 000000000..4e9c67d2f
--- /dev/null
+++ b/src/blua/CMakeLists.txt
@@ -0,0 +1 @@
+target_sourcefile(c)
diff --git a/src/blua/Makefile.cfg b/src/blua/Makefile.cfg
deleted file mode 100644
index 4536628ba..000000000
--- a/src/blua/Makefile.cfg
+++ /dev/null
@@ -1,54 +0,0 @@
-ifdef UNIXCOMMON
-LUA_CFLAGS+=-DLUA_USE_POSIX
-endif
-ifdef LINUX
-LUA_CFLAGS+=-DLUA_USE_POSIX
-endif
-ifdef GCC43
-ifndef GCC44
-WFLAGS+=-Wno-logical-op
-endif
-endif
-
-OBJS:=$(OBJS) \
- $(OBJDIR)/lapi.o \
- $(OBJDIR)/lbaselib.o \
- $(OBJDIR)/ldo.o \
- $(OBJDIR)/lfunc.o \
- $(OBJDIR)/linit.o \
- $(OBJDIR)/liolib.o \
- $(OBJDIR)/llex.o \
- $(OBJDIR)/lmem.o \
- $(OBJDIR)/lobject.o \
- $(OBJDIR)/lstate.o \
- $(OBJDIR)/lstrlib.o \
- $(OBJDIR)/ltablib.o \
- $(OBJDIR)/lundump.o \
- $(OBJDIR)/lzio.o \
- $(OBJDIR)/lauxlib.o \
- $(OBJDIR)/lcode.o \
- $(OBJDIR)/ldebug.o \
- $(OBJDIR)/ldump.o \
- $(OBJDIR)/lgc.o \
- $(OBJDIR)/lopcodes.o \
- $(OBJDIR)/lparser.o \
- $(OBJDIR)/lstring.o \
- $(OBJDIR)/ltable.o \
- $(OBJDIR)/ltm.o \
- $(OBJDIR)/lvm.o \
- $(OBJDIR)/lua_script.o \
- $(OBJDIR)/lua_baselib.o \
- $(OBJDIR)/lua_mathlib.o \
- $(OBJDIR)/lua_hooklib.o \
- $(OBJDIR)/lua_consolelib.o \
- $(OBJDIR)/lua_infolib.o \
- $(OBJDIR)/lua_mobjlib.o \
- $(OBJDIR)/lua_playerlib.o \
- $(OBJDIR)/lua_skinlib.o \
- $(OBJDIR)/lua_thinkerlib.o \
- $(OBJDIR)/lua_maplib.o \
- $(OBJDIR)/lua_taglib.o \
- $(OBJDIR)/lua_polyobjlib.o \
- $(OBJDIR)/lua_blockmaplib.o \
- $(OBJDIR)/lua_hudlib.o \
- $(OBJDIR)/lua_inputlib.o
diff --git a/src/blua/Sourcefile b/src/blua/Sourcefile
new file mode 100644
index 000000000..f99c89c8d
--- /dev/null
+++ b/src/blua/Sourcefile
@@ -0,0 +1,25 @@
+lapi.c
+lbaselib.c
+ldo.c
+lfunc.c
+linit.c
+liolib.c
+llex.c
+lmem.c
+lobject.c
+lstate.c
+lstrlib.c
+ltablib.c
+lundump.c
+lzio.c
+lauxlib.c
+lcode.c
+ldebug.c
+ldump.c
+lgc.c
+lopcodes.c
+lparser.c
+lstring.c
+ltable.c
+ltm.c
+lvm.c
diff --git a/src/d_clisrv.c b/src/d_clisrv.c
index d5bcdb747..5fdd8280e 100644
--- a/src/d_clisrv.c
+++ b/src/d_clisrv.c
@@ -2536,14 +2536,14 @@ void CL_RemovePlayer(INT32 playernum, kickreason_t reason)
}
}
- LUAh_PlayerQuit(&players[playernum], reason); // Lua hook for player quitting
+ LUA_HookPlayerQuit(&players[playernum], reason); // Lua hook for player quitting
// don't look through someone's view who isn't there
if (playernum == displayplayer)
{
// Call ViewpointSwitch hooks here.
// The viewpoint was forcibly changed.
- LUAh_ViewpointSwitch(&players[consoleplayer], &players[consoleplayer], true);
+ LUA_HookViewpointSwitch(&players[consoleplayer], &players[consoleplayer], true);
displayplayer = consoleplayer;
}
@@ -3023,7 +3023,7 @@ static void Got_KickCmd(UINT8 **p, INT32 playernum)
if (pnum == consoleplayer)
{
- LUAh_GameQuit(false);
+ LUA_HookBool(false, HOOK(GameQuit));
#ifdef DUMPCONSISTENCY
if (msg == KICK_MSG_CON_FAIL) SV_SavedGame();
#endif
@@ -3443,7 +3443,7 @@ static void Got_AddPlayer(UINT8 **p, INT32 playernum)
COM_BufAddText(va("sayto %d %s\n", newplayernum, motd));
if (!rejoined)
- LUAh_PlayerJoin(newplayernum);
+ LUA_HookInt(newplayernum, HOOK(PlayerJoin));
}
static boolean SV_AddWaitingPlayers(const char *name, const char *name2)
@@ -3723,7 +3723,7 @@ static void HandleConnect(SINT8 node)
static void HandleShutdown(SINT8 node)
{
(void)node;
- LUAh_GameQuit(false);
+ LUA_HookBool(false, HOOK(GameQuit));
D_QuitNetGame();
CL_Reset();
D_StartTitle();
@@ -3738,7 +3738,7 @@ static void HandleShutdown(SINT8 node)
static void HandleTimeout(SINT8 node)
{
(void)node;
- LUAh_GameQuit(false);
+ LUA_HookBool(false, HOOK(GameQuit));
D_QuitNetGame();
CL_Reset();
D_StartTitle();
diff --git a/src/d_netcmd.c b/src/d_netcmd.c
index 68deb8b34..0a7172b12 100644
--- a/src/d_netcmd.c
+++ b/src/d_netcmd.c
@@ -2117,7 +2117,7 @@ static void Got_Mapcmd(UINT8 **cp, INT32 playernum)
}
mapnumber = M_MapNumber(mapname[3], mapname[4]);
- LUAh_MapChange(mapnumber);
+ LUA_HookInt(mapnumber, HOOK(MapChange));
G_InitNew(ultimatemode, mapname, resetplayer, skipprecutscene, FLS);
if (demoplayback && !timingdemo)
@@ -2702,7 +2702,7 @@ static void Got_Teamchange(UINT8 **cp, INT32 playernum)
}
// Don't switch team, just go away, please, go awaayyyy, aaauuauugghhhghgh
- if (!LUAh_TeamSwitch(&players[playernum], NetPacket.packet.newteam, players[playernum].spectator, NetPacket.packet.autobalance, NetPacket.packet.scrambled))
+ if (!LUA_HookTeamSwitch(&players[playernum], NetPacket.packet.newteam, players[playernum].spectator, NetPacket.packet.autobalance, NetPacket.packet.scrambled))
return;
//no status changes after hidetime
@@ -2863,7 +2863,7 @@ static void Got_Teamchange(UINT8 **cp, INT32 playernum)
// Call ViewpointSwitch hooks here.
// The viewpoint was forcibly changed.
if (displayplayer != consoleplayer) // You're already viewing yourself. No big deal.
- LUAh_ViewpointSwitch(&players[consoleplayer], &players[consoleplayer], true);
+ LUA_HookViewpointSwitch(&players[consoleplayer], &players[consoleplayer], true);
displayplayer = consoleplayer;
}
@@ -3626,7 +3626,7 @@ static void Command_Playintro_f(void)
*/
FUNCNORETURN static ATTRNORETURN void Command_Quit_f(void)
{
- LUAh_GameQuit(true);
+ LUA_HookBool(true, HOOK(GameQuit));
I_Quit();
}
@@ -4288,7 +4288,7 @@ void Command_ExitGame_f(void)
{
INT32 i;
- LUAh_GameQuit(false);
+ LUA_HookBool(false, HOOK(GameQuit));
D_QuitNetGame();
CL_Reset();
diff --git a/src/doomtype.h b/src/doomtype.h
index 900a5eca6..3a57d90e8 100644
--- a/src/doomtype.h
+++ b/src/doomtype.h
@@ -356,6 +356,8 @@ typedef UINT32 tic_t;
#define UINT2RGBA(a) (UINT32)((a&0xff)<<24)|((a&0xff00)<<8)|((a&0xff0000)>>8)|(((UINT32)a&0xff000000)>>24)
#endif
+#define TOSTR(x) #x
+
/* preprocessor dumb and needs second macro to expand input */
#define WSTRING2(s) L ## s
#define WSTRING(s) WSTRING2 (s)
diff --git a/src/g_demo.c b/src/g_demo.c
index 7793e0272..701f930e5 100644
--- a/src/g_demo.c
+++ b/src/g_demo.c
@@ -1968,7 +1968,7 @@ void G_DoPlayDemo(char *defdemoname)
// Set skin
SetPlayerSkin(0, skin);
- LUAh_MapChange(gamemap);
+ LUA_HookInt(gamemap, HOOK(MapChange));
displayplayer = consoleplayer = 0;
memset(playeringame,0,sizeof(playeringame));
playeringame[0] = true;
diff --git a/src/g_game.c b/src/g_game.c
index 9f2d05ff0..0643350b6 100644
--- a/src/g_game.c
+++ b/src/g_game.c
@@ -1663,7 +1663,7 @@ void G_BuildTiccmd(ticcmd_t *cmd, INT32 realtics, UINT8 ssplayer)
cmd->angleturn = orighookangle;
- LUAh_PlayerCmd(player, cmd);
+ LUA_HookTiccmd(player, cmd, HOOK(PlayerCmd));
extra = cmd->angleturn - orighookangle;
cmd->angleturn = origangle + extra;
@@ -1672,7 +1672,7 @@ void G_BuildTiccmd(ticcmd_t *cmd, INT32 realtics, UINT8 ssplayer)
// Send leveltime when this tic was generated to the server for control lag calculations.
// Only do this when in a level. Also do this after the hook, so that it can't overwrite this.
- cmd->latency = (leveltime & 0xFF);
+ cmd->latency = (leveltime & 0xFF);
}
//Reset away view if a command is given.
@@ -1681,7 +1681,7 @@ void G_BuildTiccmd(ticcmd_t *cmd, INT32 realtics, UINT8 ssplayer)
{
// Call ViewpointSwitch hooks here.
// The viewpoint was forcibly changed.
- LUAh_ViewpointSwitch(player, &players[consoleplayer], true);
+ LUA_HookViewpointSwitch(player, &players[consoleplayer], true);
displayplayer = consoleplayer;
}
@@ -2055,7 +2055,7 @@ boolean G_Responder(event_t *ev)
continue;
// Call ViewpointSwitch hooks here.
- canSwitchView = LUAh_ViewpointSwitch(&players[consoleplayer], &players[displayplayer], false);
+ canSwitchView = LUA_HookViewpointSwitch(&players[consoleplayer], &players[displayplayer], false);
if (canSwitchView == 1) // Set viewpoint to this player
break;
else if (canSwitchView == 2) // Skip this player
@@ -2185,8 +2185,8 @@ boolean G_Responder(event_t *ev)
//
boolean G_LuaResponder(event_t *ev)
{
- return (ev->type == ev_keydown && LUAh_KeyDown(ev->data1)) ||
- (ev->type == ev_keyup && LUAh_KeyUp(ev->data1));
+ return (ev->type == ev_keydown && LUA_HookKey(ev->data1, HOOK(KeyDown))) ||
+ (ev->type == ev_keyup && LUA_HookKey(ev->data1, HOOK(KeyUp)));
}
//
@@ -2776,7 +2776,7 @@ void G_SpawnPlayer(INT32 playernum)
P_SpawnPlayer(playernum);
G_MovePlayerToSpawnOrStarpost(playernum);
- LUAh_PlayerSpawn(&players[playernum]); // Lua hook for player spawning :)
+ LUA_HookPlayer(&players[playernum], HOOK(PlayerSpawn)); // Lua hook for player spawning :)
}
void G_MovePlayerToSpawnOrStarpost(INT32 playernum)
@@ -3178,7 +3178,7 @@ void G_DoReborn(INT32 playernum)
}
else
{
- LUAh_MapChange(gamemap);
+ LUA_HookInt(gamemap, HOOK(MapChange));
titlecardforreload = true;
G_DoLoadLevel(true);
titlecardforreload = false;
diff --git a/src/hardware/CMakeLists.txt b/src/hardware/CMakeLists.txt
new file mode 100644
index 000000000..4e9c67d2f
--- /dev/null
+++ b/src/hardware/CMakeLists.txt
@@ -0,0 +1 @@
+target_sourcefile(c)
diff --git a/src/hardware/Sourcefile b/src/hardware/Sourcefile
new file mode 100644
index 000000000..1c05de76c
--- /dev/null
+++ b/src/hardware/Sourcefile
@@ -0,0 +1,13 @@
+hw_bsp.c
+hw_draw.c
+hw_light.c
+hw_main.c
+hw_clip.c
+hw_md2.c
+hw_cache.c
+hw_md2load.c
+hw_md3load.c
+hw_model.c
+u_list.c
+hw_batching.c
+r_opengl/r_opengl.c
diff --git a/src/hu_stuff.c b/src/hu_stuff.c
index 0c073866e..e0eaf8fb1 100644
--- a/src/hu_stuff.c
+++ b/src/hu_stuff.c
@@ -686,7 +686,7 @@ static void Got_Saycmd(UINT8 **p, INT32 playernum)
// run the lua hook even if we were supposed to eat the msg, netgame consistency goes first.
- if (LUAh_PlayerMsg(playernum, target, flags, msg))
+ if (LUA_HookPlayerMsg(playernum, target, flags, msg))
return;
if (spam_eatmsg)
diff --git a/src/lua_hook.h b/src/lua_hook.h
index 22f81074d..223b83c61 100644
--- a/src/lua_hook.h
+++ b/src/lua_hook.h
@@ -12,117 +12,122 @@
#include "r_defs.h"
#include "d_player.h"
+#include "s_sound.h"
-enum hook {
- hook_NetVars=0,
- hook_MapChange,
- hook_MapLoad,
- hook_PlayerJoin,
- hook_PreThinkFrame,
- hook_ThinkFrame,
- hook_PostThinkFrame,
- hook_MobjSpawn,
- hook_MobjCollide,
- hook_MobjLineCollide,
- hook_MobjMoveCollide,
- hook_TouchSpecial,
- hook_MobjFuse,
- hook_MobjThinker,
- hook_BossThinker,
- hook_ShouldDamage,
- hook_MobjDamage,
- hook_MobjDeath,
- hook_BossDeath,
- hook_MobjRemoved,
- hook_JumpSpecial,
- hook_AbilitySpecial,
- hook_SpinSpecial,
- hook_JumpSpinSpecial,
- hook_BotTiccmd,
- hook_BotAI,
- hook_BotRespawn,
- hook_LinedefExecute,
- hook_PlayerMsg,
- hook_HurtMsg,
- hook_PlayerSpawn,
- hook_ShieldSpawn,
- hook_ShieldSpecial,
- hook_MobjMoveBlocked,
- hook_MapThingSpawn,
- hook_FollowMobj,
- hook_PlayerCanDamage,
- hook_PlayerQuit,
- hook_IntermissionThinker,
- hook_TeamSwitch,
- hook_ViewpointSwitch,
- hook_SeenPlayer,
- hook_PlayerThink,
- hook_ShouldJingleContinue,
- hook_GameQuit,
- hook_PlayerCmd,
- hook_MusicChange,
- hook_PlayerHeight,
- hook_PlayerCanEnterSpinGaps,
- hook_KeyDown,
- hook_KeyUp,
+/*
+Do you know what an 'X Macro' is? Such a macro is called over each element of
+a list and expands the input. I use it for the hook lists because both an enum
+and array of hook names need to be kept in order. The X Macro handles this
+automatically.
+*/
- hook_MAX // last hook
-};
-extern const char *const hookNames[];
+#define MOBJ_HOOK_LIST(X) \
+ X (MobjSpawn),/* P_SpawnMobj */\
+ X (MobjCollide),/* PIT_CheckThing */\
+ X (MobjLineCollide),/* ditto */\
+ X (MobjMoveCollide),/* tritto */\
+ X (TouchSpecial),/* P_TouchSpecialThing */\
+ X (MobjFuse),/* when mobj->fuse runs out */\
+ X (MobjThinker),/* P_MobjThinker, P_SceneryThinker */\
+ X (BossThinker),/* P_GenericBossThinker */\
+ X (ShouldDamage),/* P_DamageMobj (Should mobj take damage?) */\
+ X (MobjDamage),/* P_DamageMobj (Mobj actually takes damage!) */\
+ X (MobjDeath),/* P_KillMobj */\
+ X (BossDeath),/* A_BossDeath */\
+ X (MobjRemoved),/* P_RemoveMobj */\
+ X (BotRespawn),/* B_CheckRespawn */\
+ X (MobjMoveBlocked),/* P_XYMovement (when movement is blocked) */\
+ X (MapThingSpawn),/* P_SpawnMapThing */\
+ X (FollowMobj),/* P_PlayerAfterThink Smiles mobj-following */\
+
+#define HOOK_LIST(X) \
+ X (NetVars),/* add to archive table (netsave) */\
+ X (MapChange),/* (before map load) */\
+ X (MapLoad),\
+ X (PlayerJoin),/* Got_AddPlayer */\
+ X (PreThinkFrame)/* frame (before mobj and player thinkers) */,\
+ X (ThinkFrame),/* frame (after mobj and player thinkers) */\
+ X (PostThinkFrame),/* frame (at end of tick, ie after overlays, precipitation, specials) */\
+ X (JumpSpecial),/* P_DoJumpStuff (Any-jumping) */\
+ X (AbilitySpecial),/* P_DoJumpStuff (Double-jumping) */\
+ X (SpinSpecial),/* P_DoSpinAbility (Spin button effect) */\
+ X (JumpSpinSpecial),/* P_DoJumpStuff (Spin button effect (mid-air)) */\
+ X (BotTiccmd),/* B_BuildTiccmd */\
+ X (PlayerMsg),/* chat messages */\
+ X (HurtMsg),/* imhurttin */\
+ X (PlayerSpawn),/* G_SpawnPlayer */\
+ X (ShieldSpawn),/* P_SpawnShieldOrb */\
+ X (ShieldSpecial),/* shield abilities */\
+ X (PlayerCanDamage),/* P_PlayerCanDamage */\
+ X (PlayerQuit),\
+ X (IntermissionThinker),/* Y_Ticker */\
+ X (TeamSwitch),/* team switching in... uh... *what* speak, spit it the fuck out */\
+ X (ViewpointSwitch),/* spy mode (no trickstabs) */\
+ X (SeenPlayer),/* MT_NAMECHECK */\
+ X (PlayerThink),/* P_PlayerThink */\
+ X (GameQuit),\
+ X (PlayerCmd),/* building the player's ticcmd struct (Ported from SRB2Kart) */\
+ X (MusicChange),\
+ X (PlayerHeight),/* override player height */\
+ X (PlayerCanEnterSpinGaps),\
+ X (KeyDown),\
+ X (KeyUp),\
+
+#define STRING_HOOK_LIST(X) \
+ X (BotAI),/* B_BuildTailsTiccmd by skin name */\
+ X (LinedefExecute),\
+ X (ShouldJingleContinue),/* should jingle of the given music continue playing */\
+
+/*
+I chose to access the hook enums through a macro as well. This could provide
+a hint to lookup the macro's definition instead of the enum's definition.
+(Since each enumeration is not defined in the source code, but by the list
+macros above, it is not greppable.) The name passed to the macro can also be
+grepped and found in the lists above.
+*/
+
+#define MOBJ_HOOK(name) mobjhook_ ## name
+#define HOOK(name) hook_ ## name
+#define STRING_HOOK(name) stringhook_ ## name
+
+enum { MOBJ_HOOK_LIST (MOBJ_HOOK) MOBJ_HOOK(MAX) };
+enum { HOOK_LIST (HOOK) HOOK(MAX) };
+enum { STRING_HOOK_LIST (STRING_HOOK) STRING_HOOK(MAX) };
+
+/* dead simple, LUA_HOOK(GameQuit) */
+#define LUA_HOOK(type) LUA_HookVoid(HOOK(type))
extern boolean hook_cmd_running;
-void LUAh_MapChange(INT16 mapnumber); // Hook for map change (before load)
-void LUAh_MapLoad(void); // Hook for map load
-void LUAh_PlayerJoin(int playernum); // Hook for Got_AddPlayer
-void LUAh_PreThinkFrame(void); // Hook for frame (before mobj and player thinkers)
-void LUAh_ThinkFrame(void); // Hook for frame (after mobj and player thinkers)
-void LUAh_PostThinkFrame(void); // Hook for frame (at end of tick, ie after overlays, precipitation, specials)
-boolean LUAh_MobjHook(mobj_t *mo, enum hook which);
-boolean LUAh_PlayerHook(player_t *plr, enum hook which);
-#define LUAh_MobjSpawn(mo) LUAh_MobjHook(mo, hook_MobjSpawn) // Hook for P_SpawnMobj by mobj type
-UINT8 LUAh_MobjCollideHook(mobj_t *thing1, mobj_t *thing2, enum hook which);
-UINT8 LUAh_MobjLineCollideHook(mobj_t *thing, line_t *line, enum hook which);
-#define LUAh_MobjCollide(thing1, thing2) LUAh_MobjCollideHook(thing1, thing2, hook_MobjCollide) // Hook for PIT_CheckThing by (thing) mobj type
-#define LUAh_MobjLineCollide(thing, line) LUAh_MobjLineCollideHook(thing, line, hook_MobjLineCollide) // Hook for PIT_CheckThing by (thing) mobj type
-#define LUAh_MobjMoveCollide(thing1, thing2) LUAh_MobjCollideHook(thing1, thing2, hook_MobjMoveCollide) // Hook for PIT_CheckThing by (tmthing) mobj type
-boolean LUAh_TouchSpecial(mobj_t *special, mobj_t *toucher); // Hook for P_TouchSpecialThing by mobj type
-#define LUAh_MobjFuse(mo) LUAh_MobjHook(mo, hook_MobjFuse) // Hook for mobj->fuse == 0 by mobj type
-boolean LUAh_MobjThinker(mobj_t *mo); // Hook for P_MobjThinker or P_SceneryThinker by mobj type
-#define LUAh_BossThinker(mo) LUAh_MobjHook(mo, hook_BossThinker) // Hook for P_GenericBossThinker by mobj type
-UINT8 LUAh_ShouldDamage(mobj_t *target, mobj_t *inflictor, mobj_t *source, INT32 damage, UINT8 damagetype); // Hook for P_DamageMobj by mobj type (Should mobj take damage?)
-boolean LUAh_MobjDamage(mobj_t *target, mobj_t *inflictor, mobj_t *source, INT32 damage, UINT8 damagetype); // Hook for P_DamageMobj by mobj type (Mobj actually takes damage!)
-boolean LUAh_MobjDeath(mobj_t *target, mobj_t *inflictor, mobj_t *source, UINT8 damagetype); // Hook for P_KillMobj by mobj type
-#define LUAh_BossDeath(mo) LUAh_MobjHook(mo, hook_BossDeath) // Hook for A_BossDeath by mobj type
-#define LUAh_MobjRemoved(mo) LUAh_MobjHook(mo, hook_MobjRemoved) // Hook for P_RemoveMobj by mobj type
-#define LUAh_JumpSpecial(player) LUAh_PlayerHook(player, hook_JumpSpecial) // Hook for P_DoJumpStuff (Any-jumping)
-#define LUAh_AbilitySpecial(player) LUAh_PlayerHook(player, hook_AbilitySpecial) // Hook for P_DoJumpStuff (Double-jumping)
-#define LUAh_SpinSpecial(player) LUAh_PlayerHook(player, hook_SpinSpecial) // Hook for P_DoSpinAbility (Spin button effect)
-#define LUAh_JumpSpinSpecial(player) LUAh_PlayerHook(player, hook_JumpSpinSpecial) // Hook for P_DoJumpStuff (Spin button effect (mid-air))
-boolean LUAh_BotTiccmd(player_t *bot, ticcmd_t *cmd); // Hook for B_BuildTiccmd
-boolean LUAh_BotAI(mobj_t *sonic, mobj_t *tails, ticcmd_t *cmd); // Hook for B_BuildTailsTiccmd by skin name
-boolean LUAh_BotRespawn(mobj_t *sonic, mobj_t *tails); // Hook for B_CheckRespawn
-boolean LUAh_LinedefExecute(line_t *line, mobj_t *mo, sector_t *sector); // Hook for linedef executors
-boolean LUAh_PlayerMsg(int source, int target, int flags, char *msg); // Hook for chat messages
-boolean LUAh_HurtMsg(player_t *player, mobj_t *inflictor, mobj_t *source, UINT8 damagetype); // Hook for hurt messages
-#define LUAh_PlayerSpawn(player) LUAh_PlayerHook(player, hook_PlayerSpawn) // Hook for G_SpawnPlayer
-#define LUAh_ShieldSpawn(player) LUAh_PlayerHook(player, hook_ShieldSpawn) // Hook for P_SpawnShieldOrb
-#define LUAh_ShieldSpecial(player) LUAh_PlayerHook(player, hook_ShieldSpecial) // Hook for shield abilities
-#define LUAh_MobjMoveBlocked(mo) LUAh_MobjHook(mo, hook_MobjMoveBlocked) // Hook for P_XYMovement (when movement is blocked)
-boolean LUAh_MapThingSpawn(mobj_t *mo, mapthing_t *mthing); // Hook for P_SpawnMapThing by mobj type
-boolean LUAh_FollowMobj(player_t *player, mobj_t *mobj); // Hook for P_PlayerAfterThink Smiles mobj-following
-UINT8 LUAh_PlayerCanDamage(player_t *player, mobj_t *mobj); // Hook for P_PlayerCanDamage
-void LUAh_PlayerQuit(player_t *plr, kickreason_t reason); // Hook for player quitting
-void LUAh_IntermissionThinker(boolean stagefailed); // Hook for Y_Ticker
-boolean LUAh_TeamSwitch(player_t *player, int newteam, boolean fromspectators, boolean tryingautobalance, boolean tryingscramble); // Hook for team switching in... uh....
-UINT8 LUAh_ViewpointSwitch(player_t *player, player_t *newdisplayplayer, boolean forced); // Hook for spy mode
-boolean LUAh_SeenPlayer(player_t *player, player_t *seenfriend); // Hook for MT_NAMECHECK
-#define LUAh_PlayerThink(player) LUAh_PlayerHook(player, hook_PlayerThink) // Hook for P_PlayerThink
-boolean LUAh_ShouldJingleContinue(player_t *player, const char *musname); // Hook for whether a jingle of the given music should continue playing
-void LUAh_GameQuit(boolean quitting); // Hook for game quitting
-boolean LUAh_PlayerCmd(player_t *player, ticcmd_t *cmd); // Hook for building player's ticcmd struct (Ported from SRB2Kart)
-boolean LUAh_MusicChange(const char *oldname, char *newname, UINT16 *mflags, boolean *looping, UINT32 *position, UINT32 *prefadems, UINT32 *fadeinms); // Hook for music changes
-fixed_t LUAh_PlayerHeight(player_t *player);
-UINT8 LUAh_PlayerCanEnterSpinGaps(player_t *player);
-boolean LUAh_KeyDown(INT32 keycode); // Hooks for key events
-boolean LUAh_KeyUp(INT32 keycode);
+void LUA_HookVoid(int hook);
+
+int LUA_HookMobj(mobj_t *, int hook);
+int LUA_Hook2Mobj(mobj_t *, mobj_t *, int hook);
+void LUA_HookInt(INT32 integer, int hook);
+void LUA_HookBool(boolean value, int hook);
+int LUA_HookPlayer(player_t *, int hook);
+int LUA_HookTiccmd(player_t *, ticcmd_t *, int hook);
+int LUA_HookKey(INT32 keycode, int hook); // Hooks for key events
+
+void LUA_HookThinkFrame(void);
+int LUA_HookMobjLineCollide(mobj_t *, line_t *);
+int LUA_HookTouchSpecial(mobj_t *special, mobj_t *toucher);
+int LUA_HookShouldDamage(mobj_t *target, mobj_t *inflictor, mobj_t *source, INT32 damage, UINT8 damagetype);
+int LUA_HookMobjDamage(mobj_t *target, mobj_t *inflictor, mobj_t *source, INT32 damage, UINT8 damagetype);
+int LUA_HookMobjDeath(mobj_t *target, mobj_t *inflictor, mobj_t *source, UINT8 damagetype);
+int LUA_HookBotAI(mobj_t *sonic, mobj_t *tails, ticcmd_t *cmd);
+void LUA_HookLinedefExecute(line_t *, mobj_t *, sector_t *);
+int LUA_HookPlayerMsg(int source, int target, int flags, char *msg);
+int LUA_HookHurtMsg(player_t *, mobj_t *inflictor, mobj_t *source, UINT8 damagetype);
+int LUA_HookMapThingSpawn(mobj_t *, mapthing_t *);
+int LUA_HookFollowMobj(player_t *, mobj_t *);
+int LUA_HookPlayerCanDamage(player_t *, mobj_t *);
+void LUA_HookPlayerQuit(player_t *, kickreason_t);
+int LUA_HookTeamSwitch(player_t *, int newteam, boolean fromspectators, boolean tryingautobalance, boolean tryingscramble);
+int LUA_HookViewpointSwitch(player_t *player, player_t *newdisplayplayer, boolean forced);
+int LUA_HookSeenPlayer(player_t *player, player_t *seenfriend);
+int LUA_HookShouldJingleContinue(player_t *, const char *musname);
+int LUA_HookPlayerCmd(player_t *, ticcmd_t *);
+int LUA_HookMusicChange(const char *oldname, struct MusicChange *);
+fixed_t LUA_HookPlayerHeight(player_t *player);
+int LUA_HookPlayerCanEnterSpinGaps(player_t *player);
diff --git a/src/lua_hooklib.c b/src/lua_hooklib.c
index 08226311e..d1b0d3bdd 100644
--- a/src/lua_hooklib.c
+++ b/src/lua_hooklib.c
@@ -27,2112 +27,1075 @@
#include "d_netcmd.h" // for cv_perfstats
#include "i_system.h" // I_GetPreciseTime
-static UINT8 hooksAvailable[(hook_MAX/8)+1];
+/* =========================================================================
+ ABSTRACTION
+ ========================================================================= */
-const char *const hookNames[hook_MAX+1] = {
- "NetVars",
- "MapChange",
- "MapLoad",
- "PlayerJoin",
- "PreThinkFrame",
- "ThinkFrame",
- "PostThinkFrame",
- "MobjSpawn",
- "MobjCollide",
- "MobjLineCollide",
- "MobjMoveCollide",
- "TouchSpecial",
- "MobjFuse",
- "MobjThinker",
- "BossThinker",
- "ShouldDamage",
- "MobjDamage",
- "MobjDeath",
- "BossDeath",
- "MobjRemoved",
- "JumpSpecial",
- "AbilitySpecial",
- "SpinSpecial",
- "JumpSpinSpecial",
- "BotTiccmd",
- "BotAI",
- "BotRespawn",
- "LinedefExecute",
- "PlayerMsg",
- "HurtMsg",
- "PlayerSpawn",
- "ShieldSpawn",
- "ShieldSpecial",
- "MobjMoveBlocked",
- "MapThingSpawn",
- "FollowMobj",
- "PlayerCanDamage",
- "PlayerQuit",
- "IntermissionThinker",
- "TeamSwitch",
- "ViewpointSwitch",
- "SeenPlayer",
- "PlayerThink",
- "ShouldJingleContinue",
- "GameQuit",
- "PlayerCmd",
- "MusicChange",
- "PlayerHeight",
- "PlayerCanEnterSpinGaps",
- "KeyDown",
- "KeyUp",
- NULL
+static const char * const mobjHookNames[] = { MOBJ_HOOK_LIST (TOSTR) NULL };
+static const char * const hookNames[] = { HOOK_LIST (TOSTR) NULL };
+
+static const char * const stringHookNames[] = {
+ STRING_HOOK_LIST (TOSTR) NULL
};
-// Hook metadata
-struct hook_s
+typedef struct {
+ int numHooks;
+ int *ids;
+} hook_t;
+
+typedef struct {
+ int numGeneric;
+ int ref;
+} stringhook_t;
+
+static hook_t hookIds[HOOK(MAX)];
+static hook_t mobjHookIds[NUMMOBJTYPES][MOBJ_HOOK(MAX)];
+
+// Lua tables are used to lookup string hook ids.
+static stringhook_t stringHooks[STRING_HOOK(MAX)];
+
+// This will be indexed by hook id, the value of which fetches the registry.
+static int * hookRefs;
+
+// After a hook errors once, don't print the error again.
+static UINT8 * hooksErrored;
+
+static int errorRef;
+
+static boolean mobj_hook_available(int hook_type, mobjtype_t mobj_type)
{
- struct hook_s *next;
- enum hook type;
- UINT16 id;
- union {
- mobjtype_t mt;
- char *str;
- } s;
- boolean error;
-};
-typedef struct hook_s* hook_p;
+ return
+ (
+ mobjHookIds [MT_NULL] [hook_type].numHooks > 0 ||
+ mobjHookIds[mobj_type][hook_type].numHooks > 0
+ );
+}
-#define FMT_HOOKID "hook_%d"
+static int hook_in_list
+(
+ const char * const name,
+ const char * const * const list
+){
+ int type;
-// For each mobj type, a linked list to its thinker and collision hooks.
-// That way, we don't have to iterate through all the hooks.
-// We could do that with all other mobj hooks, but it would probably just be
-// a waste of memory since they are only called occasionally. Probably...
-static hook_p mobjthinkerhooks[NUMMOBJTYPES];
-static hook_p mobjcollidehooks[NUMMOBJTYPES];
+ for (type = 0; list[type] != NULL; ++type)
+ {
+ if (strcmp(name, list[type]) == 0)
+ break;
+ }
-// For each mobj type, a linked list for other mobj hooks
-static hook_p mobjhooks[NUMMOBJTYPES];
+ return type;
+}
-// A linked list for player hooks
-static hook_p playerhooks;
-
-// A linked list for linedef executor hooks
-static hook_p linedefexecutorhooks;
-
-// For other hooks, a unique linked list
-hook_p roothook;
-
-static void PushHook(lua_State *L, hook_p hookp)
+static void get_table(lua_State *L)
{
- lua_pushfstring(L, FMT_HOOKID, hookp->id);
- lua_gettable(L, LUA_REGISTRYINDEX);
+ lua_pushvalue(L, -1);
+ lua_rawget(L, -3);
+
+ if (lua_isnil(L, -1))
+ {
+ lua_pop(L, 1);
+ lua_createtable(L, 1, 0);
+ lua_pushvalue(L, -2);
+ lua_pushvalue(L, -2);
+ lua_rawset(L, -5);
+ }
+
+ lua_remove(L, -2);
+}
+
+static void add_hook_to_table(lua_State *L, int id, int n)
+{
+ lua_pushnumber(L, id);
+ lua_rawseti(L, -2, n);
+}
+
+static void add_string_hook(lua_State *L, int type, int id)
+{
+ stringhook_t * hook = &stringHooks[type];
+
+ char * string = NULL;
+
+ switch (type)
+ {
+ case STRING_HOOK(BotAI):
+ case STRING_HOOK(ShouldJingleContinue):
+ if (lua_isstring(L, 3))
+ { // lowercase copy
+ string = Z_StrDup(lua_tostring(L, 3));
+ strlwr(string);
+ }
+ break;
+
+ case STRING_HOOK(LinedefExecute):
+ string = Z_StrDup(luaL_checkstring(L, 3));
+ strupr(string);
+ break;
+ }
+
+ if (hook->ref > 0)
+ lua_getref(L, hook->ref);
+ else
+ {
+ lua_newtable(L);
+ lua_pushvalue(L, -1);
+ hook->ref = luaL_ref(L, LUA_REGISTRYINDEX);
+ }
+
+ if (string)
+ {
+ lua_pushstring(L, string);
+ get_table(L);
+ add_hook_to_table(L, id, 1 + lua_objlen(L, -1));
+ }
+ else
+ add_hook_to_table(L, id, ++hook->numGeneric);
+}
+
+static void add_hook(hook_t *map, int id)
+{
+ Z_Realloc(map->ids, (map->numHooks + 1) * sizeof *map->ids,
+ PU_STATIC, &map->ids);
+ map->ids[map->numHooks++] = id;
+}
+
+static void add_mobj_hook(lua_State *L, int hook_type, int id)
+{
+ mobjtype_t mobj_type = luaL_optnumber(L, 3, MT_NULL);
+
+ luaL_argcheck(L, mobj_type < NUMMOBJTYPES, 3, "invalid mobjtype_t");
+
+ add_hook(&mobjHookIds[mobj_type][hook_type], id);
}
// Takes hook, function, and additional arguments (mobj type to act on, etc.)
static int lib_addHook(lua_State *L)
{
- static struct hook_s hook = {NULL, 0, 0, {0}, false};
- static UINT32 nextid;
- hook_p hookp, *lastp;
+ static int nextid;
- hook.type = luaL_checkoption(L, 1, NULL, hookNames);
- lua_remove(L, 1);
-
- luaL_checktype(L, 1, LUA_TFUNCTION);
+ const char * name;
+ int type;
if (!lua_lumploading)
return luaL_error(L, "This function cannot be called from within a hook or coroutine!");
- switch(hook.type)
+ name = luaL_checkstring(L, 1);
+ luaL_checktype(L, 2, LUA_TFUNCTION);
+
+ /* this is a very special case */
+ if (( type = hook_in_list(name, stringHookNames) ) < STRING_HOOK(MAX))
{
- // Take a mobjtype enum which this hook is specifically for.
- case hook_MobjSpawn:
- case hook_MobjCollide:
- case hook_MobjLineCollide:
- case hook_MobjMoveCollide:
- case hook_TouchSpecial:
- case hook_MobjFuse:
- case hook_MobjThinker:
- case hook_BossThinker:
- case hook_ShouldDamage:
- case hook_MobjDamage:
- case hook_MobjDeath:
- case hook_BossDeath:
- case hook_MobjRemoved:
- case hook_HurtMsg:
- case hook_MobjMoveBlocked:
- case hook_MapThingSpawn:
- case hook_FollowMobj:
- hook.s.mt = MT_NULL;
- if (lua_isnumber(L, 2))
- hook.s.mt = lua_tonumber(L, 2);
- luaL_argcheck(L, hook.s.mt < NUMMOBJTYPES, 2, "invalid mobjtype_t");
- break;
- case hook_BotAI:
- case hook_ShouldJingleContinue:
- hook.s.str = NULL;
- if (lua_isstring(L, 2))
- { // lowercase copy
- hook.s.str = Z_StrDup(lua_tostring(L, 2));
- strlwr(hook.s.str);
- }
- break;
- case hook_LinedefExecute: // Linedef executor functions
- hook.s.str = Z_StrDup(luaL_checkstring(L, 2));
- strupr(hook.s.str);
- break;
- default:
- break;
+ add_string_hook(L, type, nextid);
}
- lua_settop(L, 1); // lua stack contains only the function now.
-
- hooksAvailable[hook.type/8] |= 1<<(hook.type%8);
-
- // set hook.id to the highest id + 1
- hook.id = nextid++;
-
- // Special cases for some hook types (see the comments above mobjthinkerhooks declaration)
- switch(hook.type)
+ else if (( type = hook_in_list(name, mobjHookNames) ) < MOBJ_HOOK(MAX))
{
- case hook_MobjThinker:
- lastp = &mobjthinkerhooks[hook.s.mt];
- break;
- case hook_MobjCollide:
- case hook_MobjLineCollide:
- case hook_MobjMoveCollide:
- lastp = &mobjcollidehooks[hook.s.mt];
- break;
- case hook_MobjSpawn:
- case hook_TouchSpecial:
- case hook_MobjFuse:
- case hook_BossThinker:
- case hook_ShouldDamage:
- case hook_MobjDamage:
- case hook_MobjDeath:
- case hook_BossDeath:
- case hook_MobjRemoved:
- case hook_MobjMoveBlocked:
- case hook_MapThingSpawn:
- case hook_FollowMobj:
- lastp = &mobjhooks[hook.s.mt];
- break;
- case hook_JumpSpecial:
- case hook_AbilitySpecial:
- case hook_SpinSpecial:
- case hook_JumpSpinSpecial:
- case hook_PlayerSpawn:
- case hook_PlayerCanDamage:
- case hook_TeamSwitch:
- case hook_ViewpointSwitch:
- case hook_SeenPlayer:
- case hook_ShieldSpawn:
- case hook_ShieldSpecial:
- case hook_PlayerThink:
- case hook_PlayerHeight:
- case hook_PlayerCanEnterSpinGaps:
- lastp = &playerhooks;
- break;
- case hook_LinedefExecute:
- lastp = &linedefexecutorhooks;
- break;
- default:
- lastp = &roothook;
- break;
+ add_mobj_hook(L, type, nextid);
+ }
+ else if (( type = hook_in_list(name, hookNames) ) < HOOK(MAX))
+ {
+ add_hook(&hookIds[type], nextid);
+ }
+ else
+ {
+ return luaL_argerror(L, 1, lua_pushfstring(L, "invalid hook " LUA_QS, name));
}
- // iterate the hook metadata structs
- // set lastp to the last hook struct's "next" pointer.
- for (hookp = *lastp; hookp; hookp = hookp->next)
- lastp = &hookp->next;
- // allocate a permanent memory struct to stuff hook.
- hookp = ZZ_Alloc(sizeof(struct hook_s));
- memcpy(hookp, &hook, sizeof(struct hook_s));
- // tack it onto the end of the linked list.
- *lastp = hookp;
+ if (!(nextid & 7))
+ {
+ Z_Realloc(hooksErrored,
+ BIT_ARRAY_SIZE (nextid + 1) * sizeof *hooksErrored,
+ PU_STATIC, &hooksErrored);
+ hooksErrored[nextid >> 3] = 0;
+ }
+
+ Z_Realloc(hookRefs, (nextid + 1) * sizeof *hookRefs, PU_STATIC, &hookRefs);
// set the hook function in the registry.
- lua_pushfstring(L, FMT_HOOKID, hook.id);
- lua_pushvalue(L, 1);
- lua_settable(L, LUA_REGISTRYINDEX);
+ lua_pushvalue(L, 2);/* the function */
+ hookRefs[nextid++] = luaL_ref(L, LUA_REGISTRYINDEX);
+
return 0;
}
int LUA_HookLib(lua_State *L)
{
- memset(hooksAvailable,0,sizeof(UINT8[(hook_MAX/8)+1]));
- roothook = NULL;
+ lua_pushcfunction(L, LUA_GetErrorMessage);
+ errorRef = luaL_ref(L, LUA_REGISTRYINDEX);
+
lua_register(L, "addHook", lib_addHook);
+
return 0;
}
-boolean LUAh_MobjHook(mobj_t *mo, enum hook which)
+typedef struct Hook_State Hook_State;
+typedef void (*Hook_Callback)(Hook_State *);
+
+struct Hook_State {
+ INT32 status;/* return status to calling function */
+ void * userdata;
+ int hook_type;
+ mobjtype_t mobj_type;/* >0 if mobj hook */
+ const char * string;/* used to fetch table, ran first if set */
+ int top;/* index of last argument passed to hook */
+ int id;/* id to fetch ref */
+ int values;/* num arguments passed to hook */
+ int results;/* num values returned by hook */
+ Hook_Callback results_handler;/* callback when hook successfully returns */
+};
+
+enum {
+ EINDEX = 1,/* error handler */
+ SINDEX = 2,/* string itself is pushed in case of string hook */
+};
+
+static void push_error_handler(void)
{
- hook_p hookp;
- boolean hooked = false;
- if (!gL || !(hooksAvailable[which/8] & (1<<(which%8))))
- return false;
+ lua_getref(gL, errorRef);
+}
- I_Assert(mo->type < NUMMOBJTYPES);
-
- if (!(mobjhooks[MT_NULL] || mobjhooks[mo->type]))
- return false;
+/* repush hook string */
+static void push_string(void)
+{
+ lua_pushvalue(gL, SINDEX);
+}
+static boolean start_hook_stack(void)
+{
lua_settop(gL, 0);
- lua_pushcfunction(gL, LUA_GetErrorMessage);
+ push_error_handler();
+ return true;
+}
- // Look for all generic mobj hooks
- for (hookp = mobjhooks[MT_NULL]; hookp; hookp = hookp->next)
+static boolean init_hook_type
+(
+ Hook_State * hook,
+ int status,
+ int hook_type,
+ mobjtype_t mobj_type,
+ const char * string,
+ int nonzero
+){
+ hook->status = status;
+
+ if (nonzero)
{
- if (hookp->type != which)
- continue;
+ hook->hook_type = hook_type;
+ hook->mobj_type = mobj_type;
+ hook->string = string;
+ return start_hook_stack();
+ }
+ else
+ return false;
+}
- ps_lua_mobjhooks++;
- if (lua_gettop(gL) == 1)
- LUA_PushUserdata(gL, mo, META_MOBJ);
- PushHook(gL, hookp);
- lua_pushvalue(gL, -2);
- if (lua_pcall(gL, 1, 1, 1)) {
- if (!hookp->error || cv_debug & DBG_LUA)
- CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
- lua_pop(gL, 1);
- hookp->error = true;
- continue;
+static boolean prepare_hook
+(
+ Hook_State * hook,
+ int default_status,
+ int hook_type
+){
+ return init_hook_type(hook, default_status,
+ hook_type, 0, NULL,
+ hookIds[hook_type].numHooks);
+}
+
+static boolean prepare_mobj_hook
+(
+ Hook_State * hook,
+ int default_status,
+ int hook_type,
+ mobjtype_t mobj_type
+){
+ return init_hook_type(hook, default_status,
+ hook_type, mobj_type, NULL,
+ mobj_hook_available(hook_type, mobj_type));
+}
+
+static boolean prepare_string_hook
+(
+ Hook_State * hook,
+ int default_status,
+ int hook_type,
+ const char * string
+){
+ if (init_hook_type(hook, default_status,
+ hook_type, 0, string,
+ stringHooks[hook_type].ref))
+ {
+ lua_pushstring(gL, string);
+ return true;
+ }
+ else
+ return false;
+}
+
+static void init_hook_call
+(
+ Hook_State * hook,
+ int values,
+ int results,
+ Hook_Callback results_handler
+){
+ hook->top = lua_gettop(gL);
+ hook->values = values;
+ hook->results = results;
+ hook->results_handler = results_handler;
+}
+
+static void get_hook(Hook_State *hook, const int *ids, int n)
+{
+ hook->id = ids[n];
+ lua_getref(gL, hookRefs[hook->id]);
+}
+
+static void get_hook_from_table(Hook_State *hook, int n)
+{
+ lua_rawgeti(gL, -1, n);
+ hook->id = lua_tonumber(gL, -1);
+ lua_pop(gL, 1);
+ lua_getref(gL, hookRefs[hook->id]);
+}
+
+static int call_single_hook_no_copy(Hook_State *hook)
+{
+ if (lua_pcall(gL, hook->values, hook->results, EINDEX) == 0)
+ {
+ if (hook->results > 0)
+ {
+ (*hook->results_handler)(hook);
+ lua_pop(gL, hook->results);
+ }
+ }
+ else
+ {
+ /* print the error message once */
+ if (cv_debug & DBG_LUA || !in_bit_array(hooksErrored, hook->id))
+ {
+ CONS_Alert(CONS_WARNING, "%s\n", lua_tostring(gL, -1));
+ set_bit_array(hooksErrored, hook->id);
}
- if (lua_toboolean(gL, -1))
- hooked = true;
lua_pop(gL, 1);
}
- for (hookp = mobjhooks[mo->type]; hookp; hookp = hookp->next)
- {
- if (hookp->type != which)
- continue;
+ return 1;
+}
- ps_lua_mobjhooks++;
- if (lua_gettop(gL) == 1)
- LUA_PushUserdata(gL, mo, META_MOBJ);
- PushHook(gL, hookp);
- lua_pushvalue(gL, -2);
- if (lua_pcall(gL, 1, 1, 1)) {
- if (!hookp->error || cv_debug & DBG_LUA)
- CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
- lua_pop(gL, 1);
- hookp->error = true;
- continue;
- }
+static int call_single_hook(Hook_State *hook)
+{
+ int i;
+
+ for (i = -(hook->values) + 1; i <= 0; ++i)
+ lua_pushvalue(gL, hook->top + i);
+
+ return call_single_hook_no_copy(hook);
+}
+
+static int call_hook_table_for(Hook_State *hook, int n)
+{
+ int k;
+
+ for (k = 1; k <= n; ++k)
+ {
+ get_hook_from_table(hook, k);
+ call_single_hook(hook);
+ }
+
+ return n;
+}
+
+static int call_hook_table(Hook_State *hook)
+{
+ return call_hook_table_for(hook, lua_objlen(gL, -1));
+}
+
+static int call_mapped(Hook_State *hook, const hook_t *map)
+{
+ int k;
+
+ for (k = 0; k < map->numHooks; ++k)
+ {
+ get_hook(hook, map->ids, k);
+ call_single_hook(hook);
+ }
+
+ return map->numHooks;
+}
+
+static int call_string_hooks(Hook_State *hook)
+{
+ const stringhook_t *map = &stringHooks[hook->hook_type];
+
+ int calls = 0;
+
+ lua_getref(gL, map->ref);
+
+ /* call generic string hooks first */
+ calls += call_hook_table_for(hook, map->numGeneric);
+
+ push_string();
+ lua_rawget(gL, -2);
+ calls += call_hook_table(hook);
+
+ return calls;
+}
+
+static int call_mobj_type_hooks(Hook_State *hook, mobjtype_t mobj_type)
+{
+ return call_mapped(hook, &mobjHookIds[mobj_type][hook->hook_type]);
+}
+
+static int call_hooks
+(
+ Hook_State * hook,
+ int values,
+ int results,
+ Hook_Callback results_handler
+){
+ int calls = 0;
+
+ init_hook_call(hook, values, results, results_handler);
+
+ if (hook->string)
+ {
+ calls += call_string_hooks(hook);
+ }
+ else if (hook->mobj_type > 0)
+ {
+ /* call generic mobj hooks first */
+ calls += call_mobj_type_hooks(hook, MT_NULL);
+ calls += call_mobj_type_hooks(hook, hook->mobj_type);
+
+ ps_lua_mobjhooks += calls;
+ }
+ else
+ calls += call_mapped(hook, &hookIds[hook->hook_type]);
+
+ lua_settop(gL, 0);
+
+ return calls;
+}
+
+/* =========================================================================
+ COMMON RESULT HANDLERS
+ ========================================================================= */
+
+#define res_none NULL
+
+static void res_true(Hook_State *hook)
+{
+ if (lua_toboolean(gL, -1))
+ hook->status = true;
+}
+
+static void res_false(Hook_State *hook)
+{
+ if (!lua_isnil(gL, -1) && !lua_toboolean(gL, -1))
+ hook->status = false;
+}
+
+static void res_force(Hook_State *hook)
+{
+ if (!lua_isnil(gL, -1))
+ {
if (lua_toboolean(gL, -1))
- hooked = true;
- lua_pop(gL, 1);
+ hook->status = 1; // Force yes
+ else
+ hook->status = 2; // Force no
}
-
- lua_settop(gL, 0);
- return hooked;
}
-boolean LUAh_PlayerHook(player_t *plr, enum hook which)
+/* =========================================================================
+ GENERALISED HOOKS
+ ========================================================================= */
+
+int LUA_HookMobj(mobj_t *mobj, int hook_type)
{
- hook_p hookp;
- boolean hooked = false;
- if (!gL || !(hooksAvailable[which/8] & (1<<(which%8))))
- return false;
-
- lua_settop(gL, 0);
- lua_pushcfunction(gL, LUA_GetErrorMessage);
-
- for (hookp = playerhooks; hookp; hookp = hookp->next)
+ Hook_State hook;
+ if (prepare_mobj_hook(&hook, false, hook_type, mobj->type))
{
- if (hookp->type != which)
- continue;
-
- ps_lua_mobjhooks++;
- if (lua_gettop(gL) == 1)
- LUA_PushUserdata(gL, plr, META_PLAYER);
- PushHook(gL, hookp);
- lua_pushvalue(gL, -2);
- if (lua_pcall(gL, 1, 1, 1)) {
- if (!hookp->error || cv_debug & DBG_LUA)
- CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
- lua_pop(gL, 1);
- hookp->error = true;
- continue;
- }
- if (lua_toboolean(gL, -1))
- hooked = true;
- lua_pop(gL, 1);
+ LUA_PushUserdata(gL, mobj, META_MOBJ);
+ call_hooks(&hook, 1, 1, res_true);
}
-
- lua_settop(gL, 0);
- return hooked;
+ return hook.status;
}
-// Hook for map change (before load)
-void LUAh_MapChange(INT16 mapnumber)
+int LUA_Hook2Mobj(mobj_t *t1, mobj_t *t2, int hook_type)
{
- hook_p hookp;
- if (!gL || !(hooksAvailable[hook_MapChange/8] & (1<<(hook_MapChange%8))))
- return;
-
- lua_settop(gL, 0);
- lua_pushcfunction(gL, LUA_GetErrorMessage);
- lua_pushinteger(gL, mapnumber);
-
- for (hookp = roothook; hookp; hookp = hookp->next)
+ Hook_State hook;
+ if (prepare_mobj_hook(&hook, 0, hook_type, t1->type))
{
- if (hookp->type != hook_MapChange)
- continue;
-
- PushHook(gL, hookp);
- lua_pushvalue(gL, -2);
- if (lua_pcall(gL, 1, 0, 1)) {
- CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
- lua_pop(gL, 1);
- }
+ LUA_PushUserdata(gL, t1, META_MOBJ);
+ LUA_PushUserdata(gL, t2, META_MOBJ);
+ call_hooks(&hook, 2, 1, res_force);
}
-
- lua_settop(gL, 0);
+ return hook.status;
}
-// Hook for map load
-void LUAh_MapLoad(void)
+void LUA_HookVoid(int type)
{
- hook_p hookp;
- if (!gL || !(hooksAvailable[hook_MapLoad/8] & (1<<(hook_MapLoad%8))))
- return;
+ Hook_State hook;
+ if (prepare_hook(&hook, 0, type))
+ call_hooks(&hook, 0, 0, res_none);
+}
- lua_settop(gL, 0);
- lua_pushcfunction(gL, LUA_GetErrorMessage);
- lua_pushinteger(gL, gamemap);
-
- for (hookp = roothook; hookp; hookp = hookp->next)
+void LUA_HookInt(INT32 number, int hook_type)
+{
+ Hook_State hook;
+ if (prepare_hook(&hook, 0, hook_type))
{
- if (hookp->type != hook_MapLoad)
- continue;
-
- PushHook(gL, hookp);
- lua_pushvalue(gL, -2);
- if (lua_pcall(gL, 1, 0, 1)) {
- CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
- lua_pop(gL, 1);
- }
+ lua_pushinteger(gL, number);
+ call_hooks(&hook, 1, 0, res_none);
}
-
- lua_settop(gL, 0);
}
-// Hook for Got_AddPlayer
-void LUAh_PlayerJoin(int playernum)
+void LUA_HookBool(boolean value, int hook_type)
{
- hook_p hookp;
- if (!gL || !(hooksAvailable[hook_PlayerJoin/8] & (1<<(hook_PlayerJoin%8))))
- return;
-
- lua_settop(gL, 0);
- lua_pushcfunction(gL, LUA_GetErrorMessage);
- lua_pushinteger(gL, playernum);
-
- for (hookp = roothook; hookp; hookp = hookp->next)
+ Hook_State hook;
+ if (prepare_hook(&hook, 0, hook_type))
{
- if (hookp->type != hook_PlayerJoin)
- continue;
-
- PushHook(gL, hookp);
- lua_pushvalue(gL, -2);
- if (lua_pcall(gL, 1, 0, 1)) {
- CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
- lua_pop(gL, 1);
- }
+ lua_pushboolean(gL, value);
+ call_hooks(&hook, 1, 0, res_none);
}
-
- lua_settop(gL, 0);
}
-// Hook for frame (before mobj and player thinkers)
-void LUAh_PreThinkFrame(void)
+int LUA_HookPlayer(player_t *player, int hook_type)
{
- hook_p hookp;
- if (!gL || !(hooksAvailable[hook_PreThinkFrame/8] & (1<<(hook_PreThinkFrame%8))))
- return;
-
- lua_pushcfunction(gL, LUA_GetErrorMessage);
-
- for (hookp = roothook; hookp; hookp = hookp->next)
+ Hook_State hook;
+ if (prepare_hook(&hook, false, hook_type))
{
- if (hookp->type != hook_PreThinkFrame)
- continue;
-
- PushHook(gL, hookp);
- if (lua_pcall(gL, 0, 0, 1)) {
- if (!hookp->error || cv_debug & DBG_LUA)
- CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
- lua_pop(gL, 1);
- hookp->error = true;
- }
+ LUA_PushUserdata(gL, player, META_PLAYER);
+ call_hooks(&hook, 1, 1, res_true);
}
-
- lua_pop(gL, 1); // Pop error handler
+ return hook.status;
}
-// Hook for frame (after mobj and player thinkers)
-void LUAh_ThinkFrame(void)
+int LUA_HookTiccmd(player_t *player, ticcmd_t *cmd, int hook_type)
{
- hook_p hookp;
+ Hook_State hook;
+ if (prepare_hook(&hook, false, hook_type))
+ {
+ LUA_PushUserdata(gL, player, META_PLAYER);
+ LUA_PushUserdata(gL, cmd, META_TICCMD);
+
+ if (hook_type == HOOK(PlayerCmd))
+ hook_cmd_running = true;
+
+ call_hooks(&hook, 2, 1, res_true);
+
+ if (hook_type == HOOK(PlayerCmd))
+ hook_cmd_running = false;
+ }
+ return hook.status;
+}
+
+int LUA_HookKey(INT32 keycode, int hook_type)
+{
+ Hook_State hook;
+ if (prepare_hook(&hook, false, hook_type))
+ {
+ lua_pushinteger(gL, keycode);
+ call_hooks(&hook, 1, 1, res_true);
+ }
+ return hook.status;
+}
+
+/* =========================================================================
+ SPECIALIZED HOOKS
+ ========================================================================= */
+
+void LUA_HookThinkFrame(void)
+{
+ const int type = HOOK(ThinkFrame);
+
// variables used by perf stats
int hook_index = 0;
precise_t time_taken = 0;
- if (!gL || !(hooksAvailable[hook_ThinkFrame/8] & (1<<(hook_ThinkFrame%8))))
- return;
- lua_pushcfunction(gL, LUA_GetErrorMessage);
+ Hook_State hook;
- for (hookp = roothook; hookp; hookp = hookp->next)
+ const hook_t * map = &hookIds[type];
+ int k;
+
+ if (prepare_hook(&hook, 0, type))
{
- if (hookp->type != hook_ThinkFrame)
- continue;
+ init_hook_call(&hook, 0, 0, res_none);
- if (cv_perfstats.value == 3)
- time_taken = I_GetPreciseTime();
- PushHook(gL, hookp);
- if (lua_pcall(gL, 0, 0, 1)) {
- if (!hookp->error || cv_debug & DBG_LUA)
- CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
- lua_pop(gL, 1);
- hookp->error = true;
- }
- if (cv_perfstats.value == 3)
+ for (k = 0; k < map->numHooks; ++k)
{
- lua_Debug ar;
- time_taken = I_GetPreciseTime() - time_taken;
- // we need the function, let's just retrieve it again
- PushHook(gL, hookp);
- lua_getinfo(gL, ">S", &ar);
- PS_SetThinkFrameHookInfo(hook_index, time_taken, ar.short_src);
- hook_index++;
- }
- }
+ get_hook(&hook, map->ids, k);
- lua_pop(gL, 1); // Pop error handler
-}
-
-// Hook for frame (at end of tick, ie after overlays, precipitation, specials)
-void LUAh_PostThinkFrame(void)
-{
- hook_p hookp;
- if (!gL || !(hooksAvailable[hook_PostThinkFrame/8] & (1<<(hook_PostThinkFrame%8))))
- return;
-
- lua_pushcfunction(gL, LUA_GetErrorMessage);
-
- for (hookp = roothook; hookp; hookp = hookp->next)
- {
- if (hookp->type != hook_PostThinkFrame)
- continue;
-
- PushHook(gL, hookp);
- if (lua_pcall(gL, 0, 0, 1)) {
- if (!hookp->error || cv_debug & DBG_LUA)
- CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
- lua_pop(gL, 1);
- hookp->error = true;
- }
- }
-
- lua_pop(gL, 1); // Pop error handler
-}
-
-// Hook for mobj collisions
-UINT8 LUAh_MobjCollideHook(mobj_t *thing1, mobj_t *thing2, enum hook which)
-{
- hook_p hookp;
- UINT8 shouldCollide = 0; // 0 = default, 1 = force yes, 2 = force no.
- if (!gL || !(hooksAvailable[which/8] & (1<<(which%8))))
- return 0;
-
- I_Assert(thing1->type < NUMMOBJTYPES);
-
- if (!(mobjcollidehooks[MT_NULL] || mobjcollidehooks[thing1->type]))
- return 0;
-
- lua_settop(gL, 0);
- lua_pushcfunction(gL, LUA_GetErrorMessage);
-
- // Look for all generic mobj collision hooks
- for (hookp = mobjcollidehooks[MT_NULL]; hookp; hookp = hookp->next)
- {
- if (hookp->type != which)
- continue;
-
- ps_lua_mobjhooks++;
- if (lua_gettop(gL) == 1)
- {
- LUA_PushUserdata(gL, thing1, META_MOBJ);
- LUA_PushUserdata(gL, thing2, META_MOBJ);
- }
- PushHook(gL, hookp);
- lua_pushvalue(gL, -3);
- lua_pushvalue(gL, -3);
- if (lua_pcall(gL, 2, 1, 1)) {
- if (!hookp->error || cv_debug & DBG_LUA)
- CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
- lua_pop(gL, 1);
- hookp->error = true;
- continue;
- }
- if (!lua_isnil(gL, -1))
- { // if nil, leave shouldCollide = 0.
- if (lua_toboolean(gL, -1))
- shouldCollide = 1; // Force yes
- else
- shouldCollide = 2; // Force no
- }
- lua_pop(gL, 1);
- }
-
- for (hookp = mobjcollidehooks[thing1->type]; hookp; hookp = hookp->next)
- {
- if (hookp->type != which)
- continue;
-
- ps_lua_mobjhooks++;
- if (lua_gettop(gL) == 1)
- {
- LUA_PushUserdata(gL, thing1, META_MOBJ);
- LUA_PushUserdata(gL, thing2, META_MOBJ);
- }
- PushHook(gL, hookp);
- lua_pushvalue(gL, -3);
- lua_pushvalue(gL, -3);
- if (lua_pcall(gL, 2, 1, 1)) {
- if (!hookp->error || cv_debug & DBG_LUA)
- CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
- lua_pop(gL, 1);
- hookp->error = true;
- continue;
- }
- if (!lua_isnil(gL, -1))
- { // if nil, leave shouldCollide = 0.
- if (lua_toboolean(gL, -1))
- shouldCollide = 1; // Force yes
- else
- shouldCollide = 2; // Force no
- }
- lua_pop(gL, 1);
- }
-
- lua_settop(gL, 0);
- return shouldCollide;
-}
-
-UINT8 LUAh_MobjLineCollideHook(mobj_t *thing, line_t *line, enum hook which)
-{
- hook_p hookp;
- UINT8 shouldCollide = 0; // 0 = default, 1 = force yes, 2 = force no.
- if (!gL || !(hooksAvailable[which/8] & (1<<(which%8))))
- return 0;
-
- I_Assert(thing->type < NUMMOBJTYPES);
-
- if (!(mobjcollidehooks[MT_NULL] || mobjcollidehooks[thing->type]))
- return 0;
-
- lua_settop(gL, 0);
- lua_pushcfunction(gL, LUA_GetErrorMessage);
-
- // Look for all generic mobj collision hooks
- for (hookp = mobjcollidehooks[MT_NULL]; hookp; hookp = hookp->next)
- {
- if (hookp->type != which)
- continue;
-
- ps_lua_mobjhooks++;
- if (lua_gettop(gL) == 1)
- {
- LUA_PushUserdata(gL, thing, META_MOBJ);
- LUA_PushUserdata(gL, line, META_LINE);
- }
- PushHook(gL, hookp);
- lua_pushvalue(gL, -3);
- lua_pushvalue(gL, -3);
- if (lua_pcall(gL, 2, 1, 1)) {
- if (!hookp->error || cv_debug & DBG_LUA)
- CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
- lua_pop(gL, 1);
- hookp->error = true;
- continue;
- }
- if (!lua_isnil(gL, -1))
- { // if nil, leave shouldCollide = 0.
- if (lua_toboolean(gL, -1))
- shouldCollide = 1; // Force yes
- else
- shouldCollide = 2; // Force no
- }
- lua_pop(gL, 1);
- }
-
- for (hookp = mobjcollidehooks[thing->type]; hookp; hookp = hookp->next)
- {
- if (hookp->type != which)
- continue;
-
- ps_lua_mobjhooks++;
- if (lua_gettop(gL) == 1)
- {
- LUA_PushUserdata(gL, thing, META_MOBJ);
- LUA_PushUserdata(gL, line, META_LINE);
- }
- PushHook(gL, hookp);
- lua_pushvalue(gL, -3);
- lua_pushvalue(gL, -3);
- if (lua_pcall(gL, 2, 1, 1)) {
- if (!hookp->error || cv_debug & DBG_LUA)
- CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
- lua_pop(gL, 1);
- hookp->error = true;
- continue;
- }
- if (!lua_isnil(gL, -1))
- { // if nil, leave shouldCollide = 0.
- if (lua_toboolean(gL, -1))
- shouldCollide = 1; // Force yes
- else
- shouldCollide = 2; // Force no
- }
- lua_pop(gL, 1);
- }
-
- lua_settop(gL, 0);
- return shouldCollide;
-}
-
-// Hook for mobj thinkers
-boolean LUAh_MobjThinker(mobj_t *mo)
-{
- hook_p hookp;
- boolean hooked = false;
- if (!gL || !(hooksAvailable[hook_MobjThinker/8] & (1<<(hook_MobjThinker%8))))
- return false;
-
- I_Assert(mo->type < NUMMOBJTYPES);
-
- if (!(mobjthinkerhooks[MT_NULL] || mobjthinkerhooks[mo->type]))
- return false;
-
- lua_settop(gL, 0);
- lua_pushcfunction(gL, LUA_GetErrorMessage);
-
- // Look for all generic mobj thinker hooks
- for (hookp = mobjthinkerhooks[MT_NULL]; hookp; hookp = hookp->next)
- {
- ps_lua_mobjhooks++;
- if (lua_gettop(gL) == 1)
- LUA_PushUserdata(gL, mo, META_MOBJ);
- PushHook(gL, hookp);
- lua_pushvalue(gL, -2);
- if (lua_pcall(gL, 1, 1, 1)) {
- if (!hookp->error || cv_debug & DBG_LUA)
- CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
- lua_pop(gL, 1);
- hookp->error = true;
- continue;
- }
- if (lua_toboolean(gL, -1))
- hooked = true;
- lua_pop(gL, 1);
- }
-
- for (hookp = mobjthinkerhooks[mo->type]; hookp; hookp = hookp->next)
- {
- ps_lua_mobjhooks++;
- if (lua_gettop(gL) == 1)
- LUA_PushUserdata(gL, mo, META_MOBJ);
- PushHook(gL, hookp);
- lua_pushvalue(gL, -2);
- if (lua_pcall(gL, 1, 1, 1)) {
- if (!hookp->error || cv_debug & DBG_LUA)
- CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
- lua_pop(gL, 1);
- hookp->error = true;
- continue;
- }
- if (lua_toboolean(gL, -1))
- hooked = true;
- lua_pop(gL, 1);
- }
-
- lua_settop(gL, 0);
- return hooked;
-}
-
-// Hook for P_TouchSpecialThing by mobj type
-boolean LUAh_TouchSpecial(mobj_t *special, mobj_t *toucher)
-{
- hook_p hookp;
- boolean hooked = false;
- if (!gL || !(hooksAvailable[hook_TouchSpecial/8] & (1<<(hook_TouchSpecial%8))))
- return false;
-
- I_Assert(special->type < NUMMOBJTYPES);
-
- if (!(mobjhooks[MT_NULL] || mobjhooks[special->type]))
- return false;
-
- lua_settop(gL, 0);
- lua_pushcfunction(gL, LUA_GetErrorMessage);
-
- // Look for all generic touch special hooks
- for (hookp = mobjhooks[MT_NULL]; hookp; hookp = hookp->next)
- {
- if (hookp->type != hook_TouchSpecial)
- continue;
-
- ps_lua_mobjhooks++;
- if (lua_gettop(gL) == 1)
- {
- LUA_PushUserdata(gL, special, META_MOBJ);
- LUA_PushUserdata(gL, toucher, META_MOBJ);
- }
- PushHook(gL, hookp);
- lua_pushvalue(gL, -3);
- lua_pushvalue(gL, -3);
- if (lua_pcall(gL, 2, 1, 1)) {
- if (!hookp->error || cv_debug & DBG_LUA)
- CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
- lua_pop(gL, 1);
- hookp->error = true;
- continue;
- }
- if (lua_toboolean(gL, -1))
- hooked = true;
- lua_pop(gL, 1);
- }
-
- for (hookp = mobjhooks[special->type]; hookp; hookp = hookp->next)
- {
- if (hookp->type != hook_TouchSpecial)
- continue;
-
- ps_lua_mobjhooks++;
- if (lua_gettop(gL) == 1)
- {
- LUA_PushUserdata(gL, special, META_MOBJ);
- LUA_PushUserdata(gL, toucher, META_MOBJ);
- }
- PushHook(gL, hookp);
- lua_pushvalue(gL, -3);
- lua_pushvalue(gL, -3);
- if (lua_pcall(gL, 2, 1, 1)) {
- if (!hookp->error || cv_debug & DBG_LUA)
- CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
- lua_pop(gL, 1);
- hookp->error = true;
- continue;
- }
- if (lua_toboolean(gL, -1))
- hooked = true;
- lua_pop(gL, 1);
- }
-
- lua_settop(gL, 0);
- return hooked;
-}
-
-// Hook for P_DamageMobj by mobj type (Should mobj take damage?)
-UINT8 LUAh_ShouldDamage(mobj_t *target, mobj_t *inflictor, mobj_t *source, INT32 damage, UINT8 damagetype)
-{
- hook_p hookp;
- UINT8 shouldDamage = 0; // 0 = default, 1 = force yes, 2 = force no.
- if (!gL || !(hooksAvailable[hook_ShouldDamage/8] & (1<<(hook_ShouldDamage%8))))
- return 0;
-
- I_Assert(target->type < NUMMOBJTYPES);
-
- if (!(mobjhooks[MT_NULL] || mobjhooks[target->type]))
- return 0;
-
- lua_settop(gL, 0);
- lua_pushcfunction(gL, LUA_GetErrorMessage);
-
- // Look for all generic should damage hooks
- for (hookp = mobjhooks[MT_NULL]; hookp; hookp = hookp->next)
- {
- if (hookp->type != hook_ShouldDamage)
- continue;
-
- ps_lua_mobjhooks++;
- if (lua_gettop(gL) == 1)
- {
- LUA_PushUserdata(gL, target, META_MOBJ);
- LUA_PushUserdata(gL, inflictor, META_MOBJ);
- LUA_PushUserdata(gL, source, META_MOBJ);
- lua_pushinteger(gL, damage);
- lua_pushinteger(gL, damagetype);
- }
- PushHook(gL, hookp);
- lua_pushvalue(gL, -6);
- lua_pushvalue(gL, -6);
- lua_pushvalue(gL, -6);
- lua_pushvalue(gL, -6);
- lua_pushvalue(gL, -6);
- if (lua_pcall(gL, 5, 1, 1)) {
- if (!hookp->error || cv_debug & DBG_LUA)
- CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
- lua_pop(gL, 1);
- hookp->error = true;
- continue;
- }
- if (!lua_isnil(gL, -1))
- {
- if (lua_toboolean(gL, -1))
- shouldDamage = 1; // Force yes
- else
- shouldDamage = 2; // Force no
- }
- lua_pop(gL, 1);
- }
-
- for (hookp = mobjhooks[target->type]; hookp; hookp = hookp->next)
- {
- if (hookp->type != hook_ShouldDamage)
- continue;
- ps_lua_mobjhooks++;
- if (lua_gettop(gL) == 1)
- {
- LUA_PushUserdata(gL, target, META_MOBJ);
- LUA_PushUserdata(gL, inflictor, META_MOBJ);
- LUA_PushUserdata(gL, source, META_MOBJ);
- lua_pushinteger(gL, damage);
- lua_pushinteger(gL, damagetype);
- }
- PushHook(gL, hookp);
- lua_pushvalue(gL, -6);
- lua_pushvalue(gL, -6);
- lua_pushvalue(gL, -6);
- lua_pushvalue(gL, -6);
- lua_pushvalue(gL, -6);
- if (lua_pcall(gL, 5, 1, 1)) {
- if (!hookp->error || cv_debug & DBG_LUA)
- CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
- lua_pop(gL, 1);
- hookp->error = true;
- continue;
- }
- if (!lua_isnil(gL, -1))
- {
- if (lua_toboolean(gL, -1))
- shouldDamage = 1; // Force yes
- else
- shouldDamage = 2; // Force no
- }
- lua_pop(gL, 1);
- }
-
- lua_settop(gL, 0);
- return shouldDamage;
-}
-
-// Hook for P_DamageMobj by mobj type (Mobj actually takes damage!)
-boolean LUAh_MobjDamage(mobj_t *target, mobj_t *inflictor, mobj_t *source, INT32 damage, UINT8 damagetype)
-{
- hook_p hookp;
- boolean hooked = false;
- if (!gL || !(hooksAvailable[hook_MobjDamage/8] & (1<<(hook_MobjDamage%8))))
- return false;
-
- I_Assert(target->type < NUMMOBJTYPES);
-
- if (!(mobjhooks[MT_NULL] || mobjhooks[target->type]))
- return false;
-
- lua_settop(gL, 0);
- lua_pushcfunction(gL, LUA_GetErrorMessage);
-
- // Look for all generic mobj damage hooks
- for (hookp = mobjhooks[MT_NULL]; hookp; hookp = hookp->next)
- {
- if (hookp->type != hook_MobjDamage)
- continue;
-
- ps_lua_mobjhooks++;
- if (lua_gettop(gL) == 1)
- {
- LUA_PushUserdata(gL, target, META_MOBJ);
- LUA_PushUserdata(gL, inflictor, META_MOBJ);
- LUA_PushUserdata(gL, source, META_MOBJ);
- lua_pushinteger(gL, damage);
- lua_pushinteger(gL, damagetype);
- }
- PushHook(gL, hookp);
- lua_pushvalue(gL, -6);
- lua_pushvalue(gL, -6);
- lua_pushvalue(gL, -6);
- lua_pushvalue(gL, -6);
- lua_pushvalue(gL, -6);
- if (lua_pcall(gL, 5, 1, 1)) {
- if (!hookp->error || cv_debug & DBG_LUA)
- CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
- lua_pop(gL, 1);
- hookp->error = true;
- continue;
- }
- if (lua_toboolean(gL, -1))
- hooked = true;
- lua_pop(gL, 1);
- }
-
- for (hookp = mobjhooks[target->type]; hookp; hookp = hookp->next)
- {
- if (hookp->type != hook_MobjDamage)
- continue;
-
- ps_lua_mobjhooks++;
- if (lua_gettop(gL) == 1)
- {
- LUA_PushUserdata(gL, target, META_MOBJ);
- LUA_PushUserdata(gL, inflictor, META_MOBJ);
- LUA_PushUserdata(gL, source, META_MOBJ);
- lua_pushinteger(gL, damage);
- lua_pushinteger(gL, damagetype);
- }
- PushHook(gL, hookp);
- lua_pushvalue(gL, -6);
- lua_pushvalue(gL, -6);
- lua_pushvalue(gL, -6);
- lua_pushvalue(gL, -6);
- lua_pushvalue(gL, -6);
- if (lua_pcall(gL, 5, 1, 1)) {
- if (!hookp->error || cv_debug & DBG_LUA)
- CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
- lua_pop(gL, 1);
- hookp->error = true;
- continue;
- }
- if (lua_toboolean(gL, -1))
- hooked = true;
- lua_pop(gL, 1);
- }
-
- lua_settop(gL, 0);
- return hooked;
-}
-
-// Hook for P_KillMobj by mobj type
-boolean LUAh_MobjDeath(mobj_t *target, mobj_t *inflictor, mobj_t *source, UINT8 damagetype)
-{
- hook_p hookp;
- boolean hooked = false;
- if (!gL || !(hooksAvailable[hook_MobjDeath/8] & (1<<(hook_MobjDeath%8))))
- return false;
-
- I_Assert(target->type < NUMMOBJTYPES);
-
- if (!(mobjhooks[MT_NULL] || mobjhooks[target->type]))
- return false;
-
- lua_settop(gL, 0);
- lua_pushcfunction(gL, LUA_GetErrorMessage);
-
- // Look for all generic mobj death hooks
- for (hookp = mobjhooks[MT_NULL]; hookp; hookp = hookp->next)
- {
- if (hookp->type != hook_MobjDeath)
- continue;
-
- ps_lua_mobjhooks++;
- if (lua_gettop(gL) == 1)
- {
- LUA_PushUserdata(gL, target, META_MOBJ);
- LUA_PushUserdata(gL, inflictor, META_MOBJ);
- LUA_PushUserdata(gL, source, META_MOBJ);
- lua_pushinteger(gL, damagetype);
- }
- PushHook(gL, hookp);
- lua_pushvalue(gL, -5);
- lua_pushvalue(gL, -5);
- lua_pushvalue(gL, -5);
- lua_pushvalue(gL, -5);
- if (lua_pcall(gL, 4, 1, 1)) {
- if (!hookp->error || cv_debug & DBG_LUA)
- CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
- lua_pop(gL, 1);
- hookp->error = true;
- continue;
- }
- if (lua_toboolean(gL, -1))
- hooked = true;
- lua_pop(gL, 1);
- }
-
- for (hookp = mobjhooks[target->type]; hookp; hookp = hookp->next)
- {
- if (hookp->type != hook_MobjDeath)
- continue;
-
- ps_lua_mobjhooks++;
- if (lua_gettop(gL) == 1)
- {
- LUA_PushUserdata(gL, target, META_MOBJ);
- LUA_PushUserdata(gL, inflictor, META_MOBJ);
- LUA_PushUserdata(gL, source, META_MOBJ);
- lua_pushinteger(gL, damagetype);
- }
- PushHook(gL, hookp);
- lua_pushvalue(gL, -5);
- lua_pushvalue(gL, -5);
- lua_pushvalue(gL, -5);
- lua_pushvalue(gL, -5);
- if (lua_pcall(gL, 4, 1, 1)) {
- if (!hookp->error || cv_debug & DBG_LUA)
- CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
- lua_pop(gL, 1);
- hookp->error = true;
- continue;
- }
- if (lua_toboolean(gL, -1))
- hooked = true;
- lua_pop(gL, 1);
- }
-
- lua_settop(gL, 0);
- return hooked;
-}
-
-// Hook for B_BuildTiccmd
-boolean LUAh_BotTiccmd(player_t *bot, ticcmd_t *cmd)
-{
- hook_p hookp;
- boolean hooked = false;
- if (!gL || !(hooksAvailable[hook_BotTiccmd/8] & (1<<(hook_BotTiccmd%8))))
- return false;
-
- lua_settop(gL, 0);
- lua_pushcfunction(gL, LUA_GetErrorMessage);
-
- for (hookp = roothook; hookp; hookp = hookp->next)
- {
- if (hookp->type != hook_BotTiccmd)
- continue;
-
- if (lua_gettop(gL) == 1)
- {
- LUA_PushUserdata(gL, bot, META_PLAYER);
- LUA_PushUserdata(gL, cmd, META_TICCMD);
- }
- PushHook(gL, hookp);
- lua_pushvalue(gL, -3);
- lua_pushvalue(gL, -3);
- if (lua_pcall(gL, 2, 1, 1)) {
- if (!hookp->error || cv_debug & DBG_LUA)
- CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
- lua_pop(gL, 1);
- hookp->error = true;
- continue;
- }
- if (lua_toboolean(gL, -1))
- hooked = true;
- lua_pop(gL, 1);
- }
-
- lua_settop(gL, 0);
- return hooked;
-}
-
-// Hook for B_BuildTailsTiccmd by skin name
-boolean LUAh_BotAI(mobj_t *sonic, mobj_t *tails, ticcmd_t *cmd)
-{
- hook_p hookp;
- boolean hooked = false;
- if (!gL || !(hooksAvailable[hook_BotAI/8] & (1<<(hook_BotAI%8))))
- return false;
-
- lua_settop(gL, 0);
- lua_pushcfunction(gL, LUA_GetErrorMessage);
-
- for (hookp = roothook; hookp; hookp = hookp->next)
- {
- if (hookp->type != hook_BotAI
- || (hookp->s.str && strcmp(hookp->s.str, ((skin_t*)tails->skin)->name)))
- continue;
-
- if (lua_gettop(gL) == 1)
- {
- LUA_PushUserdata(gL, sonic, META_MOBJ);
- LUA_PushUserdata(gL, tails, META_MOBJ);
- }
- PushHook(gL, hookp);
- lua_pushvalue(gL, -3);
- lua_pushvalue(gL, -3);
- if (lua_pcall(gL, 2, 8, 1)) {
- if (!hookp->error || cv_debug & DBG_LUA)
- CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
- lua_pop(gL, 1);
- hookp->error = true;
- continue;
- }
-
- // This turns forward, backward, left, right, jump, and spin into a proper ticcmd for tails.
- if (lua_istable(gL, 2+1)) {
- boolean forward=false, backward=false, left=false, right=false, strafeleft=false, straferight=false, jump=false, spin=false;
-#define CHECKFIELD(field) \
- lua_getfield(gL, 2+1, #field);\
- if (lua_toboolean(gL, -1))\
- field = true;\
- lua_pop(gL, 1);
-
- CHECKFIELD(forward)
- CHECKFIELD(backward)
- CHECKFIELD(left)
- CHECKFIELD(right)
- CHECKFIELD(strafeleft)
- CHECKFIELD(straferight)
- CHECKFIELD(jump)
- CHECKFIELD(spin)
-#undef CHECKFIELD
- B_KeysToTiccmd(tails, cmd, forward, backward, left, right, strafeleft, straferight, jump, spin);
- } else
- B_KeysToTiccmd(tails, cmd, lua_toboolean(gL, 2+1), lua_toboolean(gL, 2+2), lua_toboolean(gL, 2+3), lua_toboolean(gL, 2+4), lua_toboolean(gL, 2+5), lua_toboolean(gL, 2+6), lua_toboolean(gL, 2+7), lua_toboolean(gL, 2+8));
-
- lua_pop(gL, 8);
- hooked = true;
- }
-
- lua_settop(gL, 0);
- return hooked;
-}
-
-// Hook for B_CheckRespawn
-boolean LUAh_BotRespawn(mobj_t *sonic, mobj_t *tails)
-{
- hook_p hookp;
- UINT8 shouldRespawn = 0; // 0 = default, 1 = force yes, 2 = force no.
- if (!gL || !(hooksAvailable[hook_BotRespawn/8] & (1<<(hook_BotRespawn%8))))
- return false;
-
- lua_settop(gL, 0);
- lua_pushcfunction(gL, LUA_GetErrorMessage);
-
- for (hookp = roothook; hookp; hookp = hookp->next)
- {
- if (hookp->type != hook_BotRespawn)
- continue;
-
- if (lua_gettop(gL) == 1)
- {
- LUA_PushUserdata(gL, sonic, META_MOBJ);
- LUA_PushUserdata(gL, tails, META_MOBJ);
- }
- PushHook(gL, hookp);
- lua_pushvalue(gL, -3);
- lua_pushvalue(gL, -3);
- if (lua_pcall(gL, 2, 1, 1)) {
- if (!hookp->error || cv_debug & DBG_LUA)
- CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
- lua_pop(gL, 1);
- hookp->error = true;
- continue;
- }
- if (!lua_isnil(gL, -1))
- {
- if (lua_toboolean(gL, -1))
- shouldRespawn = 1; // Force yes
- else
- shouldRespawn = 2; // Force no
- }
- lua_pop(gL, 1);
- }
-
- lua_settop(gL, 0);
- return shouldRespawn;
-}
-
-// Hook for linedef executors
-boolean LUAh_LinedefExecute(line_t *line, mobj_t *mo, sector_t *sector)
-{
- hook_p hookp;
- boolean hooked = false;
- if (!gL || !(hooksAvailable[hook_LinedefExecute/8] & (1<<(hook_LinedefExecute%8))))
- return 0;
-
- lua_settop(gL, 0);
- lua_pushcfunction(gL, LUA_GetErrorMessage);
-
- for (hookp = linedefexecutorhooks; hookp; hookp = hookp->next)
- {
- if (strcmp(hookp->s.str, line->stringargs[0]))
- continue;
-
- ps_lua_mobjhooks++;
- if (lua_gettop(gL) == 1)
- {
- LUA_PushUserdata(gL, line, META_LINE);
- LUA_PushUserdata(gL, mo, META_MOBJ);
- LUA_PushUserdata(gL, sector, META_SECTOR);
- }
- PushHook(gL, hookp);
- lua_pushvalue(gL, -4);
- lua_pushvalue(gL, -4);
- lua_pushvalue(gL, -4);
- if (lua_pcall(gL, 3, 0, 1)) {
- CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
- lua_pop(gL, 1);
- }
- hooked = true;
- }
-
- lua_settop(gL, 0);
- return hooked;
-}
-
-
-boolean LUAh_PlayerMsg(int source, int target, int flags, char *msg)
-{
- hook_p hookp;
- boolean hooked = false;
- if (!gL || !(hooksAvailable[hook_PlayerMsg/8] & (1<<(hook_PlayerMsg%8))))
- return false;
-
- lua_settop(gL, 0);
- lua_pushcfunction(gL, LUA_GetErrorMessage);
-
- for (hookp = roothook; hookp; hookp = hookp->next)
- {
- if (hookp->type != hook_PlayerMsg)
- continue;
-
- if (lua_gettop(gL) == 1)
- {
- LUA_PushUserdata(gL, &players[source], META_PLAYER); // Source player
- if (flags & 2 /*HU_CSAY*/) { // csay TODO: make HU_CSAY accessible outside hu_stuff.c
- lua_pushinteger(gL, 3); // type
- lua_pushnil(gL); // target
- } else if (target == -1) { // sayteam
- lua_pushinteger(gL, 1); // type
- lua_pushnil(gL); // target
- } else if (target == 0) { // say
- lua_pushinteger(gL, 0); // type
- lua_pushnil(gL); // target
- } else { // sayto
- lua_pushinteger(gL, 2); // type
- LUA_PushUserdata(gL, &players[target-1], META_PLAYER); // target
+ if (cv_perfstats.value == 3)
+ {
+ lua_pushvalue(gL, -1);/* need the function again */
+ time_taken = I_GetPreciseTime();
}
- lua_pushstring(gL, msg); // msg
- }
- PushHook(gL, hookp);
- lua_pushvalue(gL, -5);
- lua_pushvalue(gL, -5);
- lua_pushvalue(gL, -5);
- lua_pushvalue(gL, -5);
- if (lua_pcall(gL, 4, 1, 1)) {
- if (!hookp->error || cv_debug & DBG_LUA)
- CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
- lua_pop(gL, 1);
- hookp->error = true;
- continue;
- }
- if (lua_toboolean(gL, -1))
- hooked = true;
- lua_pop(gL, 1);
- }
- lua_settop(gL, 0);
- return hooked;
+ call_single_hook(&hook);
+
+ if (cv_perfstats.value == 3)
+ {
+ lua_Debug ar;
+ time_taken = I_GetPreciseTime() - time_taken;
+ lua_getinfo(gL, ">S", &ar);
+ PS_SetThinkFrameHookInfo(hook_index, time_taken, ar.short_src);
+ hook_index++;
+ }
+ }
+
+ lua_settop(gL, 0);
+ }
}
-
-// Hook for hurt messages
-boolean LUAh_HurtMsg(player_t *player, mobj_t *inflictor, mobj_t *source, UINT8 damagetype)
+int LUA_HookMobjLineCollide(mobj_t *mobj, line_t *line)
{
- hook_p hookp;
- boolean hooked = false;
- if (!gL || !(hooksAvailable[hook_HurtMsg/8] & (1<<(hook_HurtMsg%8))))
- return false;
-
- lua_settop(gL, 0);
- lua_pushcfunction(gL, LUA_GetErrorMessage);
-
- for (hookp = roothook; hookp; hookp = hookp->next)
+ Hook_State hook;
+ if (prepare_mobj_hook(&hook, 0, MOBJ_HOOK(MobjLineCollide), mobj->type))
{
- if (hookp->type != hook_HurtMsg
- || (hookp->s.mt && !(inflictor && hookp->s.mt == inflictor->type)))
- continue;
+ LUA_PushUserdata(gL, mobj, META_MOBJ);
+ LUA_PushUserdata(gL, line, META_LINE);
+ call_hooks(&hook, 2, 1, res_force);
+ }
+ return hook.status;
+}
- if (lua_gettop(gL) == 1)
+int LUA_HookTouchSpecial(mobj_t *special, mobj_t *toucher)
+{
+ Hook_State hook;
+ if (prepare_mobj_hook(&hook, false, MOBJ_HOOK(TouchSpecial), special->type))
+ {
+ LUA_PushUserdata(gL, special, META_MOBJ);
+ LUA_PushUserdata(gL, toucher, META_MOBJ);
+ call_hooks(&hook, 2, 1, res_true);
+ }
+ return hook.status;
+}
+
+static int damage_hook
+(
+ mobj_t *target,
+ mobj_t *inflictor,
+ mobj_t *source,
+ INT32 damage,
+ UINT8 damagetype,
+ int hook_type,
+ int values,
+ Hook_Callback results_handler
+){
+ Hook_State hook;
+ if (prepare_mobj_hook(&hook, 0, hook_type, target->type))
+ {
+ LUA_PushUserdata(gL, target, META_MOBJ);
+ LUA_PushUserdata(gL, inflictor, META_MOBJ);
+ LUA_PushUserdata(gL, source, META_MOBJ);
+ if (values == 5)
+ lua_pushinteger(gL, damage);
+ lua_pushinteger(gL, damagetype);
+ call_hooks(&hook, values, 1, results_handler);
+ }
+ return hook.status;
+}
+
+int LUA_HookShouldDamage(mobj_t *target, mobj_t *inflictor, mobj_t *source, INT32 damage, UINT8 damagetype)
+{
+ return damage_hook(target, inflictor, source, damage, damagetype,
+ MOBJ_HOOK(ShouldDamage), 5, res_force);
+}
+
+int LUA_HookMobjDamage(mobj_t *target, mobj_t *inflictor, mobj_t *source, INT32 damage, UINT8 damagetype)
+{
+ return damage_hook(target, inflictor, source, damage, damagetype,
+ MOBJ_HOOK(MobjDamage), 5, res_true);
+}
+
+int LUA_HookMobjDeath(mobj_t *target, mobj_t *inflictor, mobj_t *source, UINT8 damagetype)
+{
+ return damage_hook(target, inflictor, source, 0, damagetype,
+ MOBJ_HOOK(MobjDeath), 4, res_true);
+}
+
+typedef struct {
+ mobj_t * tails;
+ ticcmd_t * cmd;
+} BotAI_State;
+
+static boolean checkbotkey(const char *field)
+{
+ return lua_toboolean(gL, -1) && strcmp(lua_tostring(gL, -2), field) == 0;
+}
+
+static void res_botai(Hook_State *hook)
+{
+ BotAI_State *botai = hook->userdata;
+
+ int k[8];
+
+ int fields = 0;
+
+ // This turns forward, backward, left, right, jump, and spin into a proper ticcmd for tails.
+ if (lua_istable(gL, -8)) {
+ lua_pushnil(gL); // key
+ while (lua_next(gL, -9)) {
+#define CHECK(n, f) (checkbotkey(f) ? (k[(n)-1] = 1) : 0)
+ if (
+ CHECK(1, "forward") || CHECK(2, "backward") ||
+ CHECK(3, "left") || CHECK(4, "right") ||
+ CHECK(5, "strafeleft") || CHECK(6, "straferight") ||
+ CHECK(7, "jump") || CHECK(8, "spin")
+ ){
+ if (8 <= ++fields)
+ {
+ lua_pop(gL, 2); // pop key and value
+ break;
+ }
+ }
+
+ lua_pop(gL, 1); // pop value
+#undef CHECK
+ }
+ } else {
+ while (fields < 8)
{
- LUA_PushUserdata(gL, player, META_PLAYER);
- LUA_PushUserdata(gL, inflictor, META_MOBJ);
- LUA_PushUserdata(gL, source, META_MOBJ);
- lua_pushinteger(gL, damagetype);
+ k[fields] = lua_toboolean(gL, -8 + fields);
+ fields++;
}
- PushHook(gL, hookp);
- lua_pushvalue(gL, -5);
- lua_pushvalue(gL, -5);
- lua_pushvalue(gL, -5);
- lua_pushvalue(gL, -5);
- if (lua_pcall(gL, 4, 1, 1)) {
- if (!hookp->error || cv_debug & DBG_LUA)
- CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
- lua_pop(gL, 1);
- hookp->error = true;
- continue;
- }
- if (lua_toboolean(gL, -1))
- hooked = true;
- lua_pop(gL, 1);
}
- lua_settop(gL, 0);
- return hooked;
+ B_KeysToTiccmd(botai->tails, botai->cmd,
+ k[0],k[1],k[2],k[3],k[4],k[5],k[6],k[7]);
+
+ hook->status = true;
}
-void LUAh_NetArchiveHook(lua_CFunction archFunc)
+int LUA_HookBotAI(mobj_t *sonic, mobj_t *tails, ticcmd_t *cmd)
{
- hook_p hookp;
- int errorhandlerindex;
- if (!gL || !(hooksAvailable[hook_NetVars/8] & (1<<(hook_NetVars%8))))
- return;
+ const char *skin = ((skin_t *)tails->skin)->name;
- // stack: tables
- I_Assert(lua_gettop(gL) > 0);
- I_Assert(lua_istable(gL, -1));
+ Hook_State hook;
+ BotAI_State botai;
- lua_pushcfunction(gL, LUA_GetErrorMessage);
- errorhandlerindex = lua_gettop(gL);
-
- // tables becomes an upvalue of archFunc
- lua_pushvalue(gL, -2);
- lua_pushcclosure(gL, archFunc, 1);
- // stack: tables, archFunc
-
- for (hookp = roothook; hookp; hookp = hookp->next)
+ if (prepare_string_hook(&hook, false, STRING_HOOK(BotAI), skin))
{
- if (hookp->type != hook_NetVars)
- continue;
+ LUA_PushUserdata(gL, sonic, META_MOBJ);
+ LUA_PushUserdata(gL, tails, META_MOBJ);
- PushHook(gL, hookp);
- lua_pushvalue(gL, -2); // archFunc
- if (lua_pcall(gL, 1, 0, errorhandlerindex)) {
- CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
- lua_pop(gL, 1);
- }
+ botai.tails = tails;
+ botai.cmd = cmd;
+
+ hook.userdata = &botai;
+
+ call_hooks(&hook, 2, 8, res_botai);
}
- lua_pop(gL, 2); // Pop archFunc and error handler
- // stack: tables
+ return hook.status;
}
-boolean LUAh_MapThingSpawn(mobj_t *mo, mapthing_t *mthing)
+void LUA_HookLinedefExecute(line_t *line, mobj_t *mo, sector_t *sector)
{
- hook_p hookp;
- boolean hooked = false;
- if (!gL || !(hooksAvailable[hook_MapThingSpawn/8] & (1<<(hook_MapThingSpawn%8))))
- return false;
-
- if (!(mobjhooks[MT_NULL] || mobjhooks[mo->type]))
- return false;
-
- lua_settop(gL, 0);
- lua_pushcfunction(gL, LUA_GetErrorMessage);
-
- // Look for all generic mobj map thing spawn hooks
- for (hookp = mobjhooks[MT_NULL]; hookp; hookp = hookp->next)
+ Hook_State hook;
+ if (prepare_string_hook
+ (&hook, 0, STRING_HOOK(LinedefExecute), line->stringargs[0]))
{
- if (hookp->type != hook_MapThingSpawn)
- continue;
-
- ps_lua_mobjhooks++;
- if (lua_gettop(gL) == 1)
- {
- LUA_PushUserdata(gL, mo, META_MOBJ);
- LUA_PushUserdata(gL, mthing, META_MAPTHING);
- }
- PushHook(gL, hookp);
- lua_pushvalue(gL, -3);
- lua_pushvalue(gL, -3);
- if (lua_pcall(gL, 2, 1, 1)) {
- if (!hookp->error || cv_debug & DBG_LUA)
- CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
- lua_pop(gL, 1);
- hookp->error = true;
- continue;
- }
- if (lua_toboolean(gL, -1))
- hooked = true;
- lua_pop(gL, 1);
+ LUA_PushUserdata(gL, line, META_LINE);
+ LUA_PushUserdata(gL, mo, META_MOBJ);
+ LUA_PushUserdata(gL, sector, META_SECTOR);
+ ps_lua_mobjhooks += call_hooks(&hook, 3, 0, res_none);
}
-
- for (hookp = mobjhooks[mo->type]; hookp; hookp = hookp->next)
- {
- if (hookp->type != hook_MapThingSpawn)
- continue;
-
- ps_lua_mobjhooks++;
- if (lua_gettop(gL) == 1)
- {
- LUA_PushUserdata(gL, mo, META_MOBJ);
- LUA_PushUserdata(gL, mthing, META_MAPTHING);
- }
- PushHook(gL, hookp);
- lua_pushvalue(gL, -3);
- lua_pushvalue(gL, -3);
- if (lua_pcall(gL, 2, 1, 1)) {
- if (!hookp->error || cv_debug & DBG_LUA)
- CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
- lua_pop(gL, 1);
- hookp->error = true;
- continue;
- }
- if (lua_toboolean(gL, -1))
- hooked = true;
- lua_pop(gL, 1);
- }
-
- lua_settop(gL, 0);
- return hooked;
}
-// Hook for P_PlayerAfterThink Smiles mobj-following
-boolean LUAh_FollowMobj(player_t *player, mobj_t *mobj)
+int LUA_HookPlayerMsg(int source, int target, int flags, char *msg)
{
- hook_p hookp;
- boolean hooked = false;
- if (!gL || !(hooksAvailable[hook_FollowMobj/8] & (1<<(hook_FollowMobj%8))))
- return 0;
-
- if (!(mobjhooks[MT_NULL] || mobjhooks[mobj->type]))
- return 0;
-
- lua_settop(gL, 0);
- lua_pushcfunction(gL, LUA_GetErrorMessage);
-
- // Look for all generic mobj follow item hooks
- for (hookp = mobjhooks[MT_NULL]; hookp; hookp = hookp->next)
+ Hook_State hook;
+ if (prepare_hook(&hook, false, HOOK(PlayerMsg)))
{
- if (hookp->type != hook_FollowMobj)
- continue;
-
- ps_lua_mobjhooks++;
- if (lua_gettop(gL) == 1)
- {
- LUA_PushUserdata(gL, player, META_PLAYER);
- LUA_PushUserdata(gL, mobj, META_MOBJ);
+ LUA_PushUserdata(gL, &players[source], META_PLAYER); // Source player
+ if (flags & 2 /*HU_CSAY*/) { // csay TODO: make HU_CSAY accessible outside hu_stuff.c
+ lua_pushinteger(gL, 3); // type
+ lua_pushnil(gL); // target
+ } else if (target == -1) { // sayteam
+ lua_pushinteger(gL, 1); // type
+ lua_pushnil(gL); // target
+ } else if (target == 0) { // say
+ lua_pushinteger(gL, 0); // type
+ lua_pushnil(gL); // target
+ } else { // sayto
+ lua_pushinteger(gL, 2); // type
+ LUA_PushUserdata(gL, &players[target-1], META_PLAYER); // target
}
- PushHook(gL, hookp);
- lua_pushvalue(gL, -3);
- lua_pushvalue(gL, -3);
- if (lua_pcall(gL, 2, 1, 1)) {
- if (!hookp->error || cv_debug & DBG_LUA)
- CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
- lua_pop(gL, 1);
- hookp->error = true;
- continue;
- }
- if (lua_toboolean(gL, -1))
- hooked = true;
- lua_pop(gL, 1);
+ lua_pushstring(gL, msg); // msg
+ call_hooks(&hook, 4, 1, res_true);
}
-
- for (hookp = mobjhooks[mobj->type]; hookp; hookp = hookp->next)
- {
- if (hookp->type != hook_FollowMobj)
- continue;
-
- ps_lua_mobjhooks++;
- if (lua_gettop(gL) == 1)
- {
- LUA_PushUserdata(gL, player, META_PLAYER);
- LUA_PushUserdata(gL, mobj, META_MOBJ);
- }
- PushHook(gL, hookp);
- lua_pushvalue(gL, -3);
- lua_pushvalue(gL, -3);
- if (lua_pcall(gL, 2, 1, 1)) {
- if (!hookp->error || cv_debug & DBG_LUA)
- CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
- lua_pop(gL, 1);
- hookp->error = true;
- continue;
- }
- if (lua_toboolean(gL, -1))
- hooked = true;
- lua_pop(gL, 1);
- }
-
- lua_settop(gL, 0);
- return hooked;
+ return hook.status;
}
-// Hook for P_PlayerCanDamage
-UINT8 LUAh_PlayerCanDamage(player_t *player, mobj_t *mobj)
+int LUA_HookHurtMsg(player_t *player, mobj_t *inflictor, mobj_t *source, UINT8 damagetype)
{
- hook_p hookp;
- UINT8 shouldCollide = 0; // 0 = default, 1 = force yes, 2 = force no.
- if (!gL || !(hooksAvailable[hook_PlayerCanDamage/8] & (1<<(hook_PlayerCanDamage%8))))
- return 0;
-
- lua_settop(gL, 0);
- lua_pushcfunction(gL, LUA_GetErrorMessage);
-
- for (hookp = playerhooks; hookp; hookp = hookp->next)
+ Hook_State hook;
+ if (prepare_hook(&hook, false, HOOK(HurtMsg)))
{
- if (hookp->type != hook_PlayerCanDamage)
- continue;
-
- ps_lua_mobjhooks++;
- if (lua_gettop(gL) == 1)
- {
- LUA_PushUserdata(gL, player, META_PLAYER);
- LUA_PushUserdata(gL, mobj, META_MOBJ);
- }
- PushHook(gL, hookp);
- lua_pushvalue(gL, -3);
- lua_pushvalue(gL, -3);
- if (lua_pcall(gL, 2, 1, 1)) {
- if (!hookp->error || cv_debug & DBG_LUA)
- CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
- lua_pop(gL, 1);
- hookp->error = true;
- continue;
- }
- if (!lua_isnil(gL, -1))
- { // if nil, leave shouldCollide = 0.
- if (lua_toboolean(gL, -1))
- shouldCollide = 1; // Force yes
- else
- shouldCollide = 2; // Force no
- }
- lua_pop(gL, 1);
+ LUA_PushUserdata(gL, player, META_PLAYER);
+ LUA_PushUserdata(gL, inflictor, META_MOBJ);
+ LUA_PushUserdata(gL, source, META_MOBJ);
+ lua_pushinteger(gL, damagetype);
+ call_hooks(&hook, 4, 1, res_true);
}
-
- lua_settop(gL, 0);
- return shouldCollide;
+ return hook.status;
}
-void LUAh_PlayerQuit(player_t *plr, kickreason_t reason)
+void LUA_HookNetArchive(lua_CFunction archFunc)
{
- hook_p hookp;
- if (!gL || !(hooksAvailable[hook_PlayerQuit/8] & (1<<(hook_PlayerQuit%8))))
- return;
-
- lua_settop(gL, 0);
- lua_pushcfunction(gL, LUA_GetErrorMessage);
-
- for (hookp = roothook; hookp; hookp = hookp->next)
+ const hook_t * map = &hookIds[HOOK(NetVars)];
+ Hook_State hook;
+ /* this is a remarkable case where the stack isn't reset */
+ if (map->numHooks > 0)
{
- if (hookp->type != hook_PlayerQuit)
- continue;
+ // stack: tables
+ I_Assert(lua_gettop(gL) > 0);
+ I_Assert(lua_istable(gL, -1));
- if (lua_gettop(gL) == 1)
- {
- LUA_PushUserdata(gL, plr, META_PLAYER); // Player that quit
- lua_pushinteger(gL, reason); // Reason for quitting
- }
- PushHook(gL, hookp);
- lua_pushvalue(gL, -3);
- lua_pushvalue(gL, -3);
- if (lua_pcall(gL, 2, 0, 1)) {
- CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
- lua_pop(gL, 1);
- }
+ push_error_handler();
+ lua_insert(gL, EINDEX);
+
+ // tables becomes an upvalue of archFunc
+ lua_pushvalue(gL, -1);
+ lua_pushcclosure(gL, archFunc, 1);
+ // stack: tables, archFunc
+
+ init_hook_call(&hook, 1, 0, res_none);
+ call_mapped(&hook, map);
+
+ lua_pop(gL, 1); // pop archFunc
+ lua_remove(gL, EINDEX); // pop error handler
+ // stack: tables
}
-
- lua_settop(gL, 0);
}
-// Hook for Y_Ticker
-void LUAh_IntermissionThinker(boolean failedstage)
+int LUA_HookMapThingSpawn(mobj_t *mobj, mapthing_t *mthing)
{
- hook_p hookp;
- if (!gL || !(hooksAvailable[hook_IntermissionThinker/8] & (1<<(hook_IntermissionThinker%8))))
- return;
-
- lua_pushcfunction(gL, LUA_GetErrorMessage);
-
- for (hookp = roothook; hookp; hookp = hookp->next)
+ Hook_State hook;
+ if (prepare_mobj_hook(&hook, false, MOBJ_HOOK(MapThingSpawn), mobj->type))
{
- if (hookp->type != hook_IntermissionThinker)
- continue;
-
- lua_pushboolean(gL, failedstage); // stagefailed
-
- PushHook(gL, hookp);
- lua_pushvalue(gL, -2); // stagefailed
- if (lua_pcall(gL, 1, 0, 1)) {
- if (!hookp->error || cv_debug & DBG_LUA)
- CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
- lua_pop(gL, 1);
- hookp->error = true;
- }
+ LUA_PushUserdata(gL, mobj, META_MOBJ);
+ LUA_PushUserdata(gL, mthing, META_MAPTHING);
+ call_hooks(&hook, 2, 1, res_true);
}
-
- lua_pop(gL, 1); // Pop error handler
+ return hook.status;
}
-// Hook for team switching
-// It's just an edit of LUAh_ViewpointSwitch.
-boolean LUAh_TeamSwitch(player_t *player, int newteam, boolean fromspectators, boolean tryingautobalance, boolean tryingscramble)
+int LUA_HookFollowMobj(player_t *player, mobj_t *mobj)
{
- hook_p hookp;
- boolean canSwitchTeam = true;
- if (!gL || !(hooksAvailable[hook_TeamSwitch/8] & (1<<(hook_TeamSwitch%8))))
- return true;
-
- lua_settop(gL, 0);
- lua_pushcfunction(gL, LUA_GetErrorMessage);
-
- for (hookp = playerhooks; hookp; hookp = hookp->next)
+ Hook_State hook;
+ if (prepare_mobj_hook(&hook, false, MOBJ_HOOK(FollowMobj), mobj->type))
{
- if (hookp->type != hook_TeamSwitch)
- continue;
-
- if (lua_gettop(gL) == 1)
- {
- LUA_PushUserdata(gL, player, META_PLAYER);
- lua_pushinteger(gL, newteam);
- lua_pushboolean(gL, fromspectators);
- lua_pushboolean(gL, tryingautobalance);
- lua_pushboolean(gL, tryingscramble);
- }
- PushHook(gL, hookp);
- lua_pushvalue(gL, -6);
- lua_pushvalue(gL, -6);
- lua_pushvalue(gL, -6);
- lua_pushvalue(gL, -6);
- lua_pushvalue(gL, -6);
- if (lua_pcall(gL, 5, 1, 1)) {
- if (!hookp->error || cv_debug & DBG_LUA)
- CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
- lua_pop(gL, 1);
- hookp->error = true;
- continue;
- }
- if (!lua_isnil(gL, -1) && !lua_toboolean(gL, -1))
- canSwitchTeam = false; // Can't switch team
- lua_pop(gL, 1);
+ LUA_PushUserdata(gL, player, META_PLAYER);
+ LUA_PushUserdata(gL, mobj, META_MOBJ);
+ call_hooks(&hook, 2, 1, res_true);
}
-
- lua_settop(gL, 0);
- return canSwitchTeam;
+ return hook.status;
}
-// Hook for spy mode
-UINT8 LUAh_ViewpointSwitch(player_t *player, player_t *newdisplayplayer, boolean forced)
+int LUA_HookPlayerCanDamage(player_t *player, mobj_t *mobj)
{
- hook_p hookp;
- UINT8 canSwitchView = 0; // 0 = default, 1 = force yes, 2 = force no.
- if (!gL || !(hooksAvailable[hook_ViewpointSwitch/8] & (1<<(hook_ViewpointSwitch%8))))
- return 0;
-
- lua_settop(gL, 0);
- lua_pushcfunction(gL, LUA_GetErrorMessage);
-
- hud_running = true; // local hook
-
- for (hookp = playerhooks; hookp; hookp = hookp->next)
+ Hook_State hook;
+ if (prepare_hook(&hook, 0, HOOK(PlayerCanDamage)))
{
- if (hookp->type != hook_ViewpointSwitch)
- continue;
-
- if (lua_gettop(gL) == 1)
- {
- LUA_PushUserdata(gL, player, META_PLAYER);
- LUA_PushUserdata(gL, newdisplayplayer, META_PLAYER);
- lua_pushboolean(gL, forced);
- }
- PushHook(gL, hookp);
- lua_pushvalue(gL, -4);
- lua_pushvalue(gL, -4);
- lua_pushvalue(gL, -4);
- if (lua_pcall(gL, 3, 1, 1)) {
- if (!hookp->error || cv_debug & DBG_LUA)
- CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
- lua_pop(gL, 1);
- hookp->error = true;
- continue;
- }
- if (!lua_isnil(gL, -1))
- { // if nil, leave canSwitchView = 0.
- if (lua_toboolean(gL, -1))
- canSwitchView = 1; // Force viewpoint switch
- else
- canSwitchView = 2; // Skip viewpoint switch
- }
- lua_pop(gL, 1);
+ LUA_PushUserdata(gL, player, META_PLAYER);
+ LUA_PushUserdata(gL, mobj, META_MOBJ);
+ call_hooks(&hook, 2, 1, res_force);
}
-
- lua_settop(gL, 0);
-
- hud_running = false;
-
- return canSwitchView;
+ return hook.status;
}
-// Hook for MT_NAMECHECK
-boolean LUAh_SeenPlayer(player_t *player, player_t *seenfriend)
+void LUA_HookPlayerQuit(player_t *plr, kickreason_t reason)
{
- hook_p hookp;
- boolean hasSeenPlayer = true;
- if (!gL || !(hooksAvailable[hook_SeenPlayer/8] & (1<<(hook_SeenPlayer%8))))
- return true;
-
- lua_settop(gL, 0);
- lua_pushcfunction(gL, LUA_GetErrorMessage);
-
- hud_running = true; // local hook
-
- for (hookp = playerhooks; hookp; hookp = hookp->next)
+ Hook_State hook;
+ if (prepare_hook(&hook, 0, HOOK(PlayerQuit)))
{
- if (hookp->type != hook_SeenPlayer)
- continue;
-
- if (lua_gettop(gL) == 1)
- {
- LUA_PushUserdata(gL, player, META_PLAYER);
- LUA_PushUserdata(gL, seenfriend, META_PLAYER);
- }
- PushHook(gL, hookp);
- lua_pushvalue(gL, -3);
- lua_pushvalue(gL, -3);
- if (lua_pcall(gL, 2, 1, 1)) {
- if (!hookp->error || cv_debug & DBG_LUA)
- CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
- lua_pop(gL, 1);
- hookp->error = true;
- continue;
- }
- if (!lua_isnil(gL, -1) && !lua_toboolean(gL, -1))
- hasSeenPlayer = false; // Hasn't seen player
- lua_pop(gL, 1);
+ LUA_PushUserdata(gL, plr, META_PLAYER); // Player that quit
+ lua_pushinteger(gL, reason); // Reason for quitting
+ call_hooks(&hook, 2, 0, res_none);
}
-
- lua_settop(gL, 0);
-
- hud_running = false;
-
- return hasSeenPlayer;
}
-boolean LUAh_ShouldJingleContinue(player_t *player, const char *musname)
+int LUA_HookTeamSwitch(player_t *player, int newteam, boolean fromspectators, boolean tryingautobalance, boolean tryingscramble)
{
- hook_p hookp;
- boolean keepplaying = false;
- if (!gL || !(hooksAvailable[hook_ShouldJingleContinue/8] & (1<<(hook_ShouldJingleContinue%8))))
- return true;
-
- lua_settop(gL, 0);
- lua_pushcfunction(gL, LUA_GetErrorMessage);
-
- hud_running = true; // local hook
-
- for (hookp = roothook; hookp; hookp = hookp->next)
+ Hook_State hook;
+ if (prepare_hook(&hook, true, HOOK(TeamSwitch)))
{
- if (hookp->type != hook_ShouldJingleContinue
- || (hookp->s.str && strcmp(hookp->s.str, musname)))
- continue;
-
- if (lua_gettop(gL) == 1)
- {
- LUA_PushUserdata(gL, player, META_PLAYER);
- lua_pushstring(gL, musname);
- }
- PushHook(gL, hookp);
- lua_pushvalue(gL, -3);
- lua_pushvalue(gL, -3);
- if (lua_pcall(gL, 2, 1, 1)) {
- if (!hookp->error || cv_debug & DBG_LUA)
- CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
- lua_pop(gL, 1);
- hookp->error = true;
- continue;
- }
- if (!lua_isnil(gL, -1) && lua_toboolean(gL, -1))
- keepplaying = true; // Keep playing this boolean
- lua_pop(gL, 1);
+ LUA_PushUserdata(gL, player, META_PLAYER);
+ lua_pushinteger(gL, newteam);
+ lua_pushboolean(gL, fromspectators);
+ lua_pushboolean(gL, tryingautobalance);
+ lua_pushboolean(gL, tryingscramble);
+ call_hooks(&hook, 5, 1, res_false);
}
-
- lua_settop(gL, 0);
-
- hud_running = false;
-
- return keepplaying;
+ return hook.status;
}
-// Hook for game quitting
-void LUAh_GameQuit(boolean quitting)
+int LUA_HookViewpointSwitch(player_t *player, player_t *newdisplayplayer, boolean forced)
{
- hook_p hookp;
- if (!gL || !(hooksAvailable[hook_GameQuit/8] & (1<<(hook_GameQuit%8))))
- return;
-
- lua_pushcfunction(gL, LUA_GetErrorMessage);
-
- for (hookp = roothook; hookp; hookp = hookp->next)
+ Hook_State hook;
+ if (prepare_hook(&hook, 0, HOOK(ViewpointSwitch)))
{
- if (hookp->type != hook_GameQuit)
- continue;
+ LUA_PushUserdata(gL, player, META_PLAYER);
+ LUA_PushUserdata(gL, newdisplayplayer, META_PLAYER);
+ lua_pushboolean(gL, forced);
- PushHook(gL, hookp);
- lua_pushboolean(gL, quitting);
- if (lua_pcall(gL, 1, 0, 1)) {
- if (!hookp->error || cv_debug & DBG_LUA)
- CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
- lua_pop(gL, 1);
- hookp->error = true;
- }
+ hud_running = true; // local hook
+ call_hooks(&hook, 3, 1, res_force);
+ hud_running = false;
}
-
- lua_pop(gL, 1); // Pop error handler
+ return hook.status;
+}
+
+int LUA_HookSeenPlayer(player_t *player, player_t *seenfriend)
+{
+ Hook_State hook;
+ if (prepare_hook(&hook, true, HOOK(SeenPlayer)))
+ {
+ LUA_PushUserdata(gL, player, META_PLAYER);
+ LUA_PushUserdata(gL, seenfriend, META_PLAYER);
+
+ hud_running = true; // local hook
+ call_hooks(&hook, 2, 1, res_false);
+ hud_running = false;
+ }
+ return hook.status;
+}
+
+int LUA_HookShouldJingleContinue(player_t *player, const char *musname)
+{
+ Hook_State hook;
+ if (prepare_string_hook
+ (&hook, false, STRING_HOOK(ShouldJingleContinue), musname))
+ {
+ LUA_PushUserdata(gL, player, META_PLAYER);
+ push_string();
+
+ hud_running = true; // local hook
+ call_hooks(&hook, 2, 1, res_true);
+ hud_running = false;
+ }
+ return hook.status;
}
-// Hook for building player's ticcmd struct (Ported from SRB2Kart)
boolean hook_cmd_running = false;
-boolean LUAh_PlayerCmd(player_t *player, ticcmd_t *cmd)
+
+static void update_music_name(struct MusicChange *musicchange)
{
- hook_p hookp;
- boolean hooked = false;
- if (!gL || !(hooksAvailable[hook_PlayerCmd/8] & (1<<(hook_PlayerCmd%8))))
- return false;
+ size_t length;
+ const char * new = lua_tolstring(gL, -6, &length);
- lua_settop(gL, 0);
- lua_pushcfunction(gL, LUA_GetErrorMessage);
-
- hook_cmd_running = true;
- for (hookp = roothook; hookp; hookp = hookp->next)
+ if (length < 7)
{
- if (hookp->type != hook_PlayerCmd)
- continue;
+ strcpy(musicchange->newname, new);
+ lua_pushvalue(gL, -6);/* may as well keep it for next call */
+ }
+ else
+ {
+ memcpy(musicchange->newname, new, 6);
+ musicchange->newname[6] = '\0';
+ lua_pushlstring(gL, new, 6);
+ }
- if (lua_gettop(gL) == 1)
+ lua_replace(gL, -7);
+}
+
+static void res_musicchange(Hook_State *hook)
+{
+ struct MusicChange *musicchange = hook->userdata;
+
+ // output 1: true, false, or string musicname override
+ if (lua_isstring(gL, -6))
+ update_music_name(musicchange);
+ else if (lua_isboolean(gL, -6) && lua_toboolean(gL, -6))
+ hook->status = true;
+
+ // output 2: mflags override
+ if (lua_isnumber(gL, -5))
+ *musicchange->mflags = lua_tonumber(gL, -5);
+ // output 3: looping override
+ if (lua_isboolean(gL, -4))
+ *musicchange->looping = lua_toboolean(gL, -4);
+ // output 4: position override
+ if (lua_isnumber(gL, -3))
+ *musicchange->position = lua_tonumber(gL, -3);
+ // output 5: prefadems override
+ if (lua_isnumber(gL, -2))
+ *musicchange->prefadems = lua_tonumber(gL, -2);
+ // output 6: fadeinms override
+ if (lua_isnumber(gL, -1))
+ *musicchange->fadeinms = lua_tonumber(gL, -1);
+}
+
+int LUA_HookMusicChange(const char *oldname, struct MusicChange *param)
+{
+ const int type = HOOK(MusicChange);
+ const hook_t * map = &hookIds[type];
+
+ Hook_State hook;
+
+ int k;
+
+ if (prepare_hook(&hook, false, type))
+ {
+ init_hook_call(&hook, 7, 6, res_musicchange);
+ hook.userdata = param;
+
+ lua_pushstring(gL, oldname);/* the only constant value */
+ lua_pushstring(gL, param->newname);/* semi constant */
+
+ for (k = 0; k <= map->numHooks; ++k)
{
- LUA_PushUserdata(gL, player, META_PLAYER);
- LUA_PushUserdata(gL, cmd, META_TICCMD);
+ get_hook(&hook, map->ids, k);
+
+ lua_pushvalue(gL, -3);
+ lua_pushvalue(gL, -3);
+ lua_pushinteger(gL, *param->mflags);
+ lua_pushboolean(gL, *param->looping);
+ lua_pushinteger(gL, *param->position);
+ lua_pushinteger(gL, *param->prefadems);
+ lua_pushinteger(gL, *param->fadeinms);
+
+ call_single_hook_no_copy(&hook);
}
- PushHook(gL, hookp);
- lua_pushvalue(gL, -3);
- lua_pushvalue(gL, -3);
- if (lua_pcall(gL, 2, 1, 1)) {
- if (!hookp->error || cv_debug & DBG_LUA)
- CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
- lua_pop(gL, 1);
- hookp->error = true;
- continue;
- }
- if (lua_toboolean(gL, -1))
- hooked = true;
- lua_pop(gL, 1);
+
+ lua_settop(gL, 0);
}
- lua_settop(gL, 0);
- hook_cmd_running = false;
- return hooked;
+ return hook.status;
}
-// Hook for music changes
-boolean LUAh_MusicChange(const char *oldname, char *newname, UINT16 *mflags, boolean *looping,
- UINT32 *position, UINT32 *prefadems, UINT32 *fadeinms)
+static void res_playerheight(Hook_State *hook)
{
- hook_p hookp;
- boolean hooked = false;
-
- if (!gL || !(hooksAvailable[hook_MusicChange/8] & (1<<(hook_MusicChange%8))))
- return false;
-
- lua_settop(gL, 0);
- lua_pushcfunction(gL, LUA_GetErrorMessage);
-
- for (hookp = roothook; hookp; hookp = hookp->next)
- if (hookp->type == hook_MusicChange)
- {
- PushHook(gL, hookp);
- lua_pushstring(gL, oldname);
- lua_pushstring(gL, newname);
- lua_pushinteger(gL, *mflags);
- lua_pushboolean(gL, *looping);
- lua_pushinteger(gL, *position);
- lua_pushinteger(gL, *prefadems);
- lua_pushinteger(gL, *fadeinms);
- if (lua_pcall(gL, 7, 6, 1)) {
- CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
- lua_pop(gL, 1);
- continue;
- }
-
- // output 1: true, false, or string musicname override
- if (lua_isboolean(gL, -6) && lua_toboolean(gL, -6))
- hooked = true;
- else if (lua_isstring(gL, -6))
- strncpy(newname, lua_tostring(gL, -6), 7);
- // output 2: mflags override
- if (lua_isnumber(gL, -5))
- *mflags = lua_tonumber(gL, -5);
- // output 3: looping override
- if (lua_isboolean(gL, -4))
- *looping = lua_toboolean(gL, -4);
- // output 4: position override
- if (lua_isnumber(gL, -3))
- *position = lua_tonumber(gL, -3);
- // output 5: prefadems override
- if (lua_isnumber(gL, -2))
- *prefadems = lua_tonumber(gL, -2);
- // output 6: fadeinms override
- if (lua_isnumber(gL, -1))
- *fadeinms = lua_tonumber(gL, -1);
-
- lua_pop(gL, 7); // Pop returned values and error handler
- }
-
- lua_settop(gL, 0);
- newname[6] = 0;
- return hooked;
-}
-
-// Hook for determining player height
-fixed_t LUAh_PlayerHeight(player_t *player)
-{
- hook_p hookp;
- fixed_t newheight = -1;
- if (!gL || !(hooksAvailable[hook_PlayerHeight/8] & (1<<(hook_PlayerHeight%8))))
- return newheight;
-
- lua_settop(gL, 0);
- lua_pushcfunction(gL, LUA_GetErrorMessage);
-
- for (hookp = playerhooks; hookp; hookp = hookp->next)
+ if (!lua_isnil(gL, -1))
{
- if (hookp->type != hook_PlayerHeight)
- continue;
-
- ps_lua_mobjhooks++;
- if (lua_gettop(gL) == 1)
- LUA_PushUserdata(gL, player, META_PLAYER);
- PushHook(gL, hookp);
- lua_pushvalue(gL, -2);
- if (lua_pcall(gL, 1, 1, 1)) {
- if (!hookp->error || cv_debug & DBG_LUA)
- CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
- lua_pop(gL, 1);
- hookp->error = true;
- continue;
- }
- if (!lua_isnil(gL, -1))
- {
- fixed_t returnedheight = lua_tonumber(gL, -1);
- // 0 height has... strange results, but it's not problematic like negative heights are.
- // when an object's height is set to a negative number directly with lua, it's forced to 0 instead.
- // here, I think it's better to ignore negatives so that they don't replace any results of previous hooks!
- if (returnedheight >= 0)
- newheight = returnedheight;
- }
- lua_pop(gL, 1);
+ fixed_t returnedheight = lua_tonumber(gL, -1);
+ // 0 height has... strange results, but it's not problematic like negative heights are.
+ // when an object's height is set to a negative number directly with lua, it's forced to 0 instead.
+ // here, I think it's better to ignore negatives so that they don't replace any results of previous hooks!
+ if (returnedheight >= 0)
+ hook->status = returnedheight;
}
-
- lua_settop(gL, 0);
- return newheight;
}
-// Hook for determining whether players are allowed passage through spin gaps
-UINT8 LUAh_PlayerCanEnterSpinGaps(player_t *player)
+fixed_t LUA_HookPlayerHeight(player_t *player)
{
- hook_p hookp;
- UINT8 canEnter = 0; // 0 = default, 1 = force yes, 2 = force no.
- if (!gL || !(hooksAvailable[hook_PlayerCanEnterSpinGaps/8] & (1<<(hook_PlayerCanEnterSpinGaps%8))))
- return 0;
-
- lua_settop(gL, 0);
- lua_pushcfunction(gL, LUA_GetErrorMessage);
-
- for (hookp = playerhooks; hookp; hookp = hookp->next)
+ Hook_State hook;
+ if (prepare_hook(&hook, -1, HOOK(PlayerHeight)))
{
- if (hookp->type != hook_PlayerCanEnterSpinGaps)
- continue;
-
- ps_lua_mobjhooks++;
- if (lua_gettop(gL) == 1)
- LUA_PushUserdata(gL, player, META_PLAYER);
- PushHook(gL, hookp);
- lua_pushvalue(gL, -2);
- if (lua_pcall(gL, 1, 1, 1)) {
- if (!hookp->error || cv_debug & DBG_LUA)
- CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
- lua_pop(gL, 1);
- hookp->error = true;
- continue;
- }
- if (!lua_isnil(gL, -1))
- { // if nil, leave canEnter = 0.
- if (lua_toboolean(gL, -1))
- canEnter = 1; // Force yes
- else
- canEnter = 2; // Force no
- }
- lua_pop(gL, 1);
+ LUA_PushUserdata(gL, player, META_PLAYER);
+ call_hooks(&hook, 1, 1, res_playerheight);
}
-
- lua_settop(gL, 0);
- return canEnter;
+ return hook.status;
}
-// Hook for key press
-boolean LUAh_KeyDown(INT32 keycode)
+int LUA_HookPlayerCanEnterSpinGaps(player_t *player)
{
- hook_p hookp;
- boolean override = false;
- if (!gL || !(hooksAvailable[hook_KeyDown/8] & (1<<(hook_KeyDown%8))))
- return false;
-
- lua_settop(gL, 0);
- lua_pushcfunction(gL, LUA_GetErrorMessage);
-
- for (hookp = roothook; hookp; hookp = hookp->next)
+ Hook_State hook;
+ if (prepare_hook(&hook, 0, HOOK(PlayerCanEnterSpinGaps)))
{
- if (hookp->type != hook_KeyDown)
- continue;
-
- PushHook(gL, hookp);
- lua_pushinteger(gL, keycode);
- if (lua_pcall(gL, 1, 1, 1)) {
- if (!hookp->error || cv_debug & DBG_LUA)
- CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
- lua_pop(gL, 1);
- hookp->error = true;
- continue;
- }
- if (lua_toboolean(gL, -1))
- override = true;
- lua_pop(gL, 1);
+ LUA_PushUserdata(gL, player, META_PLAYER);
+ call_hooks(&hook, 1, 1, res_force);
}
-
- lua_settop(gL, 0);
-
- return override;
-}
-
-// Hook for key release
-boolean LUAh_KeyUp(INT32 keycode)
-{
- hook_p hookp;
- boolean override = false;
- if (!gL || !(hooksAvailable[hook_KeyUp/8] & (1<<(hook_KeyUp%8))))
- return false;
-
- lua_settop(gL, 0);
- lua_pushcfunction(gL, LUA_GetErrorMessage);
-
- for (hookp = roothook; hookp; hookp = hookp->next)
- {
- if (hookp->type != hook_KeyUp)
- continue;
-
- PushHook(gL, hookp);
- lua_pushinteger(gL, keycode);
- if (lua_pcall(gL, 1, 1, 1)) {
- if (!hookp->error || cv_debug & DBG_LUA)
- CONS_Alert(CONS_WARNING,"%s\n",lua_tostring(gL, -1));
- lua_pop(gL, 1);
- hookp->error = true;
- continue;
- }
- if (lua_toboolean(gL, -1))
- override = true;
- lua_pop(gL, 1);
- }
-
- lua_settop(gL, 0);
-
- return override;
+ return hook.status;
}
diff --git a/src/lua_inputlib.c b/src/lua_inputlib.c
index 217202222..71eb1033f 100644
--- a/src/lua_inputlib.c
+++ b/src/lua_inputlib.c
@@ -117,7 +117,7 @@ static int lib_setMouseGrab(lua_State *L)
return 0;
}
-static boolean lib_getCursorPosition(lua_State *L)
+static int lib_getCursorPosition(lua_State *L)
{
int x, y;
I_GetCursorPosition(&x, &y);
diff --git a/src/lua_script.c b/src/lua_script.c
index 3074b159b..6faff8729 100644
--- a/src/lua_script.c
+++ b/src/lua_script.c
@@ -1658,7 +1658,7 @@ void LUA_Archive(void)
WRITEUINT32(save_p, UINT32_MAX); // end of mobjs marker, replaces mobjnum.
- LUAh_NetArchiveHook(NetArchive); // call the NetArchive hook in archive mode
+ LUA_HookNetArchive(NetArchive); // call the NetArchive hook in archive mode
ArchiveTables();
if (gL)
@@ -1693,7 +1693,7 @@ void LUA_UnArchive(void)
}
} while(mobjnum != UINT32_MAX); // repeat until end of mobjs marker.
- LUAh_NetArchiveHook(NetUnArchive); // call the NetArchive hook in unarchive mode
+ LUA_HookNetArchive(NetUnArchive); // call the NetArchive hook in unarchive mode
UnArchiveTables();
if (gL)
diff --git a/src/lua_script.h b/src/lua_script.h
index a9c8762ad..e88256941 100644
--- a/src/lua_script.h
+++ b/src/lua_script.h
@@ -59,7 +59,7 @@ void Got_Luacmd(UINT8 **cp, INT32 playernum); // lua_consolelib.c
void LUA_CVarChanged(void *cvar); // lua_consolelib.c
int Lua_optoption(lua_State *L, int narg,
const char *def, const char *const lst[]);
-void LUAh_NetArchiveHook(lua_CFunction archFunc);
+void LUA_HookNetArchive(lua_CFunction archFunc);
void LUA_PushTaggableObjectArray
( lua_State *L,
diff --git a/src/m_menu.c b/src/m_menu.c
index 525e9cbdd..db2aa09c6 100644
--- a/src/m_menu.c
+++ b/src/m_menu.c
@@ -7040,7 +7040,7 @@ static void M_SelectableClearMenus(INT32 choice)
static void M_UltimateCheat(INT32 choice)
{
(void)choice;
- LUAh_GameQuit(true);
+ LUA_HookBool(true, HOOK(GameQuit));
I_Quit();
}
@@ -13509,7 +13509,7 @@ void M_QuitResponse(INT32 ch)
if (ch != 'y' && ch != KEY_ENTER)
return;
- LUAh_GameQuit(true);
+ LUA_HookBool(true, HOOK(GameQuit));
if (!(netgame || cv_debug))
{
S_ResetCaptions();
diff --git a/src/p_enemy.c b/src/p_enemy.c
index 69ddbcee6..7db2ace39 100644
--- a/src/p_enemy.c
+++ b/src/p_enemy.c
@@ -3962,7 +3962,7 @@ void A_BossDeath(mobj_t *mo)
}
bossjustdie:
- if (LUAh_BossDeath(mo))
+ if (LUA_HookMobj(mo, MOBJ_HOOK(BossDeath)))
return;
else if (P_MobjWasRemoved(mo))
return;
diff --git a/src/p_inter.c b/src/p_inter.c
index af67bb80d..7e43c46a8 100644
--- a/src/p_inter.c
+++ b/src/p_inter.c
@@ -365,7 +365,7 @@ void P_TouchSpecialThing(mobj_t *special, mobj_t *toucher, boolean heightcheck)
if (special->flags & (MF_ENEMY|MF_BOSS) && special->flags2 & MF2_FRET)
return;
- if (LUAh_TouchSpecial(special, toucher) || P_MobjWasRemoved(special))
+ if (LUA_HookTouchSpecial(special, toucher) || P_MobjWasRemoved(special))
return;
// 0 = none, 1 = elemental pierce, 2 = bubble bounce
@@ -1939,7 +1939,7 @@ static void P_HitDeathMessages(player_t *player, mobj_t *inflictor, mobj_t *sour
if (!netgame)
return; // Presumably it's obvious what's happening in splitscreen.
- if (LUAh_HurtMsg(player, inflictor, source, damagetype))
+ if (LUA_HookHurtMsg(player, inflictor, source, damagetype))
return;
deadtarget = (player->mo->health <= 0);
@@ -2413,7 +2413,7 @@ void P_KillMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source, UINT8 damaget
target->flags2 &= ~(MF2_SKULLFLY|MF2_NIGHTSPULL);
target->health = 0; // This makes it easy to check if something's dead elsewhere.
- if (LUAh_MobjDeath(target, inflictor, source, damagetype) || P_MobjWasRemoved(target))
+ if (LUA_HookMobjDeath(target, inflictor, source, damagetype) || P_MobjWasRemoved(target))
return;
// Let EVERYONE know what happened to a player! 01-29-2002 Tails
@@ -3548,7 +3548,7 @@ boolean P_DamageMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source, INT32 da
// Everything above here can't be forced.
if (!metalrecording)
{
- UINT8 shouldForce = LUAh_ShouldDamage(target, inflictor, source, damage, damagetype);
+ UINT8 shouldForce = LUA_HookShouldDamage(target, inflictor, source, damage, damagetype);
if (P_MobjWasRemoved(target))
return (shouldForce == 1); // mobj was removed
if (shouldForce == 1)
@@ -3589,7 +3589,7 @@ boolean P_DamageMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source, INT32 da
if (!force && target->flags2 & MF2_FRET) // Currently flashing from being hit
return false;
- if (LUAh_MobjDamage(target, inflictor, source, damage, damagetype) || P_MobjWasRemoved(target))
+ if (LUA_HookMobjDamage(target, inflictor, source, damage, damagetype) || P_MobjWasRemoved(target))
return true;
if (target->health > 1)
@@ -3639,7 +3639,7 @@ boolean P_DamageMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source, INT32 da
|| (G_GametypeHasTeams() && player->ctfteam == source->player->ctfteam)))
return false; // Don't run eachother over in special stages and team games and such
}
- if (LUAh_MobjDamage(target, inflictor, source, damage, damagetype))
+ if (LUA_HookMobjDamage(target, inflictor, source, damage, damagetype))
return true;
P_NiGHTSDamage(target, source); // -5s :(
return true;
@@ -3693,13 +3693,13 @@ boolean P_DamageMobj(mobj_t *target, mobj_t *inflictor, mobj_t *source, INT32 da
if (force
|| (inflictor && inflictor->flags & MF_MISSILE && inflictor->flags2 & MF2_SUPERFIRE)) // Super Sonic is stunned!
{
- if (!LUAh_MobjDamage(target, inflictor, source, damage, damagetype))
+ if (!LUA_HookMobjDamage(target, inflictor, source, damage, damagetype))
P_SuperDamage(player, inflictor, source, damage);
return true;
}
return false;
}
- else if (LUAh_MobjDamage(target, inflictor, source, damage, damagetype))
+ else if (LUA_HookMobjDamage(target, inflictor, source, damage, damagetype))
return true;
else if (player->powers[pw_shield] || (player->bot && player->bot != 3 && !ultimatemode)) //If One-Hit Shield
{
diff --git a/src/p_map.c b/src/p_map.c
index 5533478e5..e55bebb9a 100644
--- a/src/p_map.c
+++ b/src/p_map.c
@@ -754,7 +754,7 @@ static boolean PIT_CheckThing(mobj_t *thing)
return true; // underneath
// REX HAS SEEN YOU
- if (!LUAh_SeenPlayer(tmthing->target->player, thing->player))
+ if (!LUA_HookSeenPlayer(tmthing->target->player, thing->player))
return false;
seenplayer = thing->player;
@@ -943,7 +943,7 @@ static boolean PIT_CheckThing(mobj_t *thing)
}
{
- UINT8 shouldCollide = LUAh_MobjCollide(thing, tmthing); // checks hook for thing's type
+ UINT8 shouldCollide = LUA_Hook2Mobj(thing, tmthing, MOBJ_HOOK(MobjCollide)); // checks hook for thing's type
if (P_MobjWasRemoved(tmthing) || P_MobjWasRemoved(thing))
return true; // one of them was removed???
if (shouldCollide == 1)
@@ -951,7 +951,7 @@ static boolean PIT_CheckThing(mobj_t *thing)
else if (shouldCollide == 2)
return true; // force no collide
- shouldCollide = LUAh_MobjMoveCollide(tmthing, thing); // checks hook for tmthing's type
+ shouldCollide = LUA_Hook2Mobj(tmthing, thing, MOBJ_HOOK(MobjMoveCollide)); // checks hook for tmthing's type
if (P_MobjWasRemoved(tmthing) || P_MobjWasRemoved(thing))
return true; // one of them was removed???
if (shouldCollide == 1)
@@ -1935,7 +1935,7 @@ static boolean PIT_CheckLine(line_t *ld)
blockingline = ld;
{
- UINT8 shouldCollide = LUAh_MobjLineCollide(tmthing, blockingline); // checks hook for thing's type
+ UINT8 shouldCollide = LUA_HookMobjLineCollide(tmthing, blockingline); // checks hook for thing's type
if (P_MobjWasRemoved(tmthing))
return true; // one of them was removed???
if (shouldCollide == 1)
diff --git a/src/p_mobj.c b/src/p_mobj.c
index fb917fffa..4924ec053 100644
--- a/src/p_mobj.c
+++ b/src/p_mobj.c
@@ -1843,7 +1843,7 @@ void P_XYMovement(mobj_t *mo)
if (player)
B_MoveBlocked(player);
- if (LUAh_MobjMoveBlocked(mo))
+ if (LUA_HookMobj(mo, MOBJ_HOOK(MobjMoveBlocked)))
{
if (P_MobjWasRemoved(mo))
return;
@@ -7507,7 +7507,7 @@ static void P_RosySceneryThink(mobj_t *mobj)
static void P_MobjSceneryThink(mobj_t *mobj)
{
- if (LUAh_MobjThinker(mobj))
+ if (LUA_HookMobj(mobj, MOBJ_HOOK(MobjThinker)))
return;
if (P_MobjWasRemoved(mobj))
return;
@@ -7855,7 +7855,7 @@ static void P_MobjSceneryThink(mobj_t *mobj)
if (!mobj->fuse)
{
- if (!LUAh_MobjFuse(mobj))
+ if (!LUA_HookMobj(mobj, MOBJ_HOOK(MobjFuse)))
P_RemoveMobj(mobj);
return;
}
@@ -7914,7 +7914,7 @@ static void P_MobjSceneryThink(mobj_t *mobj)
mobj->fuse--;
if (!mobj->fuse)
{
- if (!LUAh_MobjFuse(mobj))
+ if (!LUA_HookMobj(mobj, MOBJ_HOOK(MobjFuse)))
P_RemoveMobj(mobj);
return;
}
@@ -7943,7 +7943,7 @@ static boolean P_MobjPushableThink(mobj_t *mobj)
static boolean P_MobjBossThink(mobj_t *mobj)
{
- if (LUAh_BossThinker(mobj))
+ if (LUA_HookMobj(mobj, MOBJ_HOOK(BossThinker)))
{
if (P_MobjWasRemoved(mobj))
return false;
@@ -9870,7 +9870,7 @@ static boolean P_FuseThink(mobj_t *mobj)
if (mobj->fuse)
return true;
- if (LUAh_MobjFuse(mobj) || P_MobjWasRemoved(mobj))
+ if (LUA_HookMobj(mobj, MOBJ_HOOK(MobjFuse)) || P_MobjWasRemoved(mobj))
;
else if (mobj->info->flags & MF_MONITOR)
{
@@ -10046,13 +10046,13 @@ void P_MobjThinker(mobj_t *mobj)
// Check for a Lua thinker first
if (!mobj->player)
{
- if (LUAh_MobjThinker(mobj) || P_MobjWasRemoved(mobj))
+ if (LUA_HookMobj(mobj, MOBJ_HOOK(MobjThinker)) || P_MobjWasRemoved(mobj))
return;
}
else if (!mobj->player->spectator)
{
// You cannot short-circuit the player thinker like you can other thinkers.
- LUAh_MobjThinker(mobj);
+ LUA_HookMobj(mobj, MOBJ_HOOK(MobjThinker));
if (P_MobjWasRemoved(mobj))
return;
}
@@ -10520,7 +10520,7 @@ mobj_t *P_SpawnMobj(fixed_t x, fixed_t y, fixed_t z, mobjtype_t type)
// DANGER! This can cause P_SpawnMobj to return NULL!
// Avoid using P_RemoveMobj on the newly created mobj in "MobjSpawn" Lua hooks!
- if (LUAh_MobjSpawn(mobj))
+ if (LUA_HookMobj(mobj, MOBJ_HOOK(MobjSpawn)))
{
if (P_MobjWasRemoved(mobj))
return NULL;
@@ -10907,7 +10907,7 @@ void P_RemoveMobj(mobj_t *mobj)
return; // something already removing this mobj.
mobj->thinker.function.acp1 = (actionf_p1)P_RemoveThinkerDelayed; // shh. no recursing.
- LUAh_MobjRemoved(mobj);
+ LUA_HookMobj(mobj, MOBJ_HOOK(MobjRemoved));
mobj->thinker.function.acp1 = (actionf_p1)P_MobjThinker; // needed for P_UnsetThingPosition, etc. to work.
// Rings only, please!
@@ -12569,7 +12569,7 @@ static boolean P_SetupBooster(mapthing_t* mthing, mobj_t* mobj, boolean strong)
static boolean P_SetupSpawnedMapThing(mapthing_t *mthing, mobj_t *mobj, boolean *doangle)
{
- boolean override = LUAh_MapThingSpawn(mobj, mthing);
+ boolean override = LUA_HookMapThingSpawn(mobj, mthing);
if (P_MobjWasRemoved(mobj))
return false;
diff --git a/src/p_setup.c b/src/p_setup.c
index db44e4be0..498759b73 100644
--- a/src/p_setup.c
+++ b/src/p_setup.c
@@ -65,7 +65,7 @@
#include "md5.h" // map MD5
-// for LUAh_MapLoad
+// for MapLoad hook
#include "lua_script.h"
#include "lua_hook.h"
@@ -4370,7 +4370,7 @@ boolean P_LoadLevel(boolean fromnetsave, boolean reloadinggamestate)
}
P_PreTicker(2);
P_MapStart(); // just in case MapLoad modifies tmthing
- LUAh_MapLoad();
+ LUA_HookInt(gamemap, HOOK(MapLoad));
P_MapEnd(); // just in case MapLoad modifies tmthing
}
diff --git a/src/p_spec.c b/src/p_spec.c
index 742fd544b..4b566acfb 100644
--- a/src/p_spec.c
+++ b/src/p_spec.c
@@ -35,7 +35,7 @@
#include "v_video.h" // V_AUTOFADEOUT|V_ALLOWLOWERCASE
#include "m_misc.h"
#include "m_cond.h" //unlock triggers
-#include "lua_hook.h" // LUAh_LinedefExecute
+#include "lua_hook.h" // LUA_HookLinedefExecute
#include "f_finale.h" // control text prompt
#include "r_skins.h" // skins
@@ -3134,7 +3134,7 @@ static void P_ProcessLineSpecial(line_t *line, mobj_t *mo, sector_t *callsec)
case 443: // Calls a named Lua function
if (line->stringargs[0])
- LUAh_LinedefExecute(line, mo, callsec);
+ LUA_HookLinedefExecute(line, mo, callsec);
else
CONS_Alert(CONS_WARNING, "Linedef %s is missing the hook name of the Lua function to call! (This should be given in arg0str)\n", sizeu1(line-lines));
break;
diff --git a/src/p_tick.c b/src/p_tick.c
index 9f00ef8dc..d7357eb82 100644
--- a/src/p_tick.c
+++ b/src/p_tick.c
@@ -656,7 +656,7 @@ void P_Ticker(boolean run)
ps_lua_mobjhooks = 0;
ps_checkposition_calls = 0;
- LUAh_PreThinkFrame();
+ LUA_HOOK(PreThinkFrame);
ps_playerthink_time = I_GetPreciseTime();
for (i = 0; i < MAXPLAYERS; i++)
@@ -687,7 +687,7 @@ void P_Ticker(boolean run)
P_PlayerAfterThink(&players[i]);
ps_lua_thinkframe_time = I_GetPreciseTime();
- LUAh_ThinkFrame();
+ LUA_HookThinkFrame();
ps_lua_thinkframe_time = I_GetPreciseTime() - ps_lua_thinkframe_time;
}
@@ -760,7 +760,7 @@ void P_Ticker(boolean run)
if (modeattacking)
G_GhostTicker();
- LUAh_PostThinkFrame();
+ LUA_HOOK(PostThinkFrame);
}
P_MapEnd();
@@ -783,7 +783,7 @@ void P_PreTicker(INT32 frames)
{
P_MapStart();
- LUAh_PreThinkFrame();
+ LUA_HOOK(PreThinkFrame);
for (i = 0; i < MAXPLAYERS; i++)
if (playeringame[i] && players[i].mo && !P_MobjWasRemoved(players[i].mo))
@@ -810,7 +810,7 @@ void P_PreTicker(INT32 frames)
if (playeringame[i] && players[i].mo && !P_MobjWasRemoved(players[i].mo))
P_PlayerAfterThink(&players[i]);
- LUAh_ThinkFrame();
+ LUA_HookThinkFrame();
// Run shield positioning
P_RunShields();
@@ -819,7 +819,7 @@ void P_PreTicker(INT32 frames)
P_UpdateSpecials();
P_RespawnSpecials();
- LUAh_PostThinkFrame();
+ LUA_HOOK(PostThinkFrame);
P_MapEnd();
}
diff --git a/src/p_user.c b/src/p_user.c
index e3a962394..dadc23193 100644
--- a/src/p_user.c
+++ b/src/p_user.c
@@ -1111,7 +1111,7 @@ boolean P_PlayerCanDamage(player_t *player, mobj_t *thing)
return false;
{
- UINT8 shouldCollide = LUAh_PlayerCanDamage(player, thing);
+ UINT8 shouldCollide = LUA_HookPlayerCanDamage(player, thing);
if (P_MobjWasRemoved(thing))
return false; // removed???
if (shouldCollide == 1)
@@ -1594,7 +1594,7 @@ boolean P_EvaluateMusicStatus(UINT16 status, const char *musname)
break;
case JT_OTHER: // Other state
- result = LUAh_ShouldJingleContinue(&players[i], musname);
+ result = LUA_HookShouldJingleContinue(&players[i], musname);
break;
case JT_NONE: // Null state
@@ -1860,7 +1860,7 @@ void P_SpawnShieldOrb(player_t *player)
I_Error("P_SpawnShieldOrb: player->mo is NULL!\n");
#endif
- if (LUAh_ShieldSpawn(player))
+ if (LUA_HookPlayer(player, HOOK(ShieldSpawn)))
return;
if (player->powers[pw_shield] & SH_FORCE)
@@ -4583,7 +4583,7 @@ static void P_DoSpinAbility(player_t *player, ticcmd_t *cmd)
if (cmd->buttons & BT_SPIN)
{
- if (LUAh_SpinSpecial(player))
+ if (LUA_HookPlayer(player, HOOK(SpinSpecial)))
return;
}
@@ -5055,7 +5055,7 @@ static boolean P_PlayerShieldThink(player_t *player, ticcmd_t *cmd, mobj_t *lock
}
}
}
- if ((!(player->charflags & SF_NOSHIELDABILITY)) && (cmd->buttons & BT_SPIN && !LUAh_ShieldSpecial(player))) // Spin button effects
+ if ((!(player->charflags & SF_NOSHIELDABILITY)) && (cmd->buttons & BT_SPIN && !LUA_HookPlayer(player, HOOK(ShieldSpecial)))) // Spin button effects
{
// Force stop
if ((player->powers[pw_shield] & ~(SH_FORCEHP|SH_STACK)) == SH_FORCE)
@@ -5179,7 +5179,7 @@ static void P_DoJumpStuff(player_t *player, ticcmd_t *cmd)
// and you don't have a shield, do it!
P_DoSuperTransformation(player, false);
}
- else if (!LUAh_JumpSpinSpecial(player))
+ else if (!LUA_HookPlayer(player, HOOK(JumpSpinSpecial)))
switch (player->charability)
{
case CA_THOK:
@@ -5252,7 +5252,7 @@ static void P_DoJumpStuff(player_t *player, ticcmd_t *cmd)
if (cmd->buttons & BT_JUMP && !player->exiting && !P_PlayerInPain(player))
{
- if (LUAh_JumpSpecial(player))
+ if (LUA_HookPlayer(player, HOOK(JumpSpecial)))
;
// all situations below this require jump button not to be pressed already
else if (player->pflags & PF_JUMPDOWN)
@@ -5287,7 +5287,7 @@ static void P_DoJumpStuff(player_t *player, ticcmd_t *cmd)
}*/
else if (player->pflags & PF_JUMPED)
{
- if (!LUAh_AbilitySpecial(player))
+ if (!LUA_HookPlayer(player, HOOK(AbilitySpecial)))
switch (player->charability)
{
case CA_THOK:
@@ -5480,7 +5480,7 @@ static void P_DoJumpStuff(player_t *player, ticcmd_t *cmd)
}
else if (player->pflags & PF_THOKKED)
{
- if (!LUAh_AbilitySpecial(player))
+ if (!LUA_HookPlayer(player, HOOK(AbilitySpecial)))
switch (player->charability)
{
case CA_FLY:
@@ -5503,7 +5503,7 @@ static void P_DoJumpStuff(player_t *player, ticcmd_t *cmd)
break;
}
}
- else if ((!(player->charflags & SF_NOSHIELDABILITY)) && ((player->powers[pw_shield] & SH_NOSTACK) == SH_WHIRLWIND && !player->powers[pw_super] && !LUAh_ShieldSpecial(player)))
+ else if ((!(player->charflags & SF_NOSHIELDABILITY)) && ((player->powers[pw_shield] & SH_NOSTACK) == SH_WHIRLWIND && !player->powers[pw_super] && !LUA_HookPlayer(player, HOOK(ShieldSpecial))))
P_DoJumpShield(player);
}
@@ -8654,7 +8654,7 @@ void P_MovePlayer(player_t *player)
{
boolean atspinheight = false;
fixed_t oldheight = player->mo->height;
- fixed_t luaheight = LUAh_PlayerHeight(player);
+ fixed_t luaheight = LUA_HookPlayerHeight(player);
if (luaheight != -1)
{
@@ -10516,7 +10516,7 @@ boolean P_SpectatorJoinGame(player_t *player)
else
changeto = (P_RandomFixed() & 1) + 1;
- if (!LUAh_TeamSwitch(player, changeto, true, false, false))
+ if (!LUA_HookTeamSwitch(player, changeto, true, false, false))
return false;
if (player->mo)
@@ -10533,7 +10533,7 @@ boolean P_SpectatorJoinGame(player_t *player)
{
// Call ViewpointSwitch hooks here.
// The viewpoint was forcibly changed.
- LUAh_ViewpointSwitch(player, &players[consoleplayer], true);
+ LUA_HookViewpointSwitch(player, &players[consoleplayer], true);
displayplayer = consoleplayer;
}
@@ -10551,7 +10551,7 @@ boolean P_SpectatorJoinGame(player_t *player)
// respawn in place and sit there for the rest of the round.
if (!((gametyperules & GTR_HIDEFROZEN) && leveltime > (hidetime * TICRATE)))
{
- if (!LUAh_TeamSwitch(player, 3, true, false, false))
+ if (!LUA_HookTeamSwitch(player, 3, true, false, false))
return false;
if (player->mo)
{
@@ -10578,7 +10578,7 @@ boolean P_SpectatorJoinGame(player_t *player)
{
// Call ViewpointSwitch hooks here.
// The viewpoint was forcibly changed.
- LUAh_ViewpointSwitch(player, &players[consoleplayer], true);
+ LUA_HookViewpointSwitch(player, &players[consoleplayer], true);
displayplayer = consoleplayer;
}
@@ -11507,7 +11507,7 @@ void P_PlayerThink(player_t *player)
}
if (player->playerstate == PST_REBORN)
{
- LUAh_PlayerThink(player);
+ LUA_HookPlayer(player, HOOK(PlayerThink));
return;
}
}
@@ -11609,7 +11609,7 @@ void P_PlayerThink(player_t *player)
if (player->playerstate == PST_DEAD)
{
- LUAh_PlayerThink(player);
+ LUA_HookPlayer(player, HOOK(PlayerThink));
return;
}
}
@@ -11730,7 +11730,7 @@ void P_PlayerThink(player_t *player)
{
player->mo->flags2 &= ~MF2_SHADOW;
P_DeathThink(player);
- LUAh_PlayerThink(player);
+ LUA_HookPlayer(player, HOOK(PlayerThink));
return;
}
@@ -11772,7 +11772,7 @@ void P_PlayerThink(player_t *player)
{
if (P_SpectatorJoinGame(player))
{
- LUAh_PlayerThink(player);
+ LUA_HookPlayer(player, HOOK(PlayerThink));
return; // player->mo was removed.
}
}
@@ -11877,7 +11877,7 @@ void P_PlayerThink(player_t *player)
if (!player->mo)
{
- LUAh_PlayerThink(player);
+ LUA_HookPlayer(player, HOOK(PlayerThink));
return; // P_MovePlayer removed player->mo.
}
@@ -12331,7 +12331,7 @@ void P_PlayerThink(player_t *player)
}
#undef dashmode
- LUAh_PlayerThink(player);
+ LUA_HookPlayer(player, HOOK(PlayerThink));
/*
// Colormap verification
@@ -12900,7 +12900,7 @@ void P_PlayerAfterThink(player_t *player)
if (player->followmobj)
{
- if (LUAh_FollowMobj(player, player->followmobj) || P_MobjWasRemoved(player->followmobj))
+ if (LUA_HookFollowMobj(player, player->followmobj) || P_MobjWasRemoved(player->followmobj))
{;}
else
{
@@ -12979,7 +12979,7 @@ boolean P_PlayerFullbright(player_t *player)
// returns true if the player can enter a sector that they could not if standing at their skin's full height
boolean P_PlayerCanEnterSpinGaps(player_t *player)
{
- UINT8 canEnter = LUAh_PlayerCanEnterSpinGaps(player);
+ UINT8 canEnter = LUA_HookPlayerCanEnterSpinGaps(player);
if (canEnter == 1)
return true;
else if (canEnter == 2)
diff --git a/src/s_sound.c b/src/s_sound.c
index 1bb48565a..30f242369 100644
--- a/src/s_sound.c
+++ b/src/s_sound.c
@@ -2238,6 +2238,16 @@ static void S_ChangeMusicToQueue(void)
void S_ChangeMusicEx(const char *mmusic, UINT16 mflags, boolean looping, UINT32 position, UINT32 prefadems, UINT32 fadeinms)
{
char newmusic[7];
+
+ struct MusicChange hook_param = {
+ newmusic,
+ &mflags,
+ &looping,
+ &position,
+ &prefadems,
+ &fadeinms
+ };
+
boolean currentmidi = (I_SongType() == MU_MID || I_SongType() == MU_MID_EX);
boolean midipref = cv_musicpref.value;
@@ -2245,7 +2255,7 @@ void S_ChangeMusicEx(const char *mmusic, UINT16 mflags, boolean looping, UINT32
return;
strncpy(newmusic, mmusic, 7);
- if (LUAh_MusicChange(music_name, newmusic, &mflags, &looping, &position, &prefadems, &fadeinms))
+ if (LUA_HookMusicChange(music_name, &hook_param))
return;
newmusic[6] = 0;
diff --git a/src/s_sound.h b/src/s_sound.h
index 4e03e3c9e..8fcb816d9 100644
--- a/src/s_sound.h
+++ b/src/s_sound.h
@@ -265,6 +265,16 @@ boolean S_RecallMusic(UINT16 status, boolean fromfirst);
// Music Playback
//
+/* this is for the sake of the hook */
+struct MusicChange {
+ char * newname;
+ UINT16 * mflags;
+ boolean * looping;
+ UINT32 * position;
+ UINT32 * prefadems;
+ UINT32 * fadeinms;
+};
+
// Start music track, arbitrary, given its name, and set whether looping
// note: music flags 12 bits for tracknum (gme, other formats with more than one track)
// 13-15 aren't used yet
diff --git a/src/sdl/CMakeLists.txt b/src/sdl/CMakeLists.txt
index a7f015c86..4f19d93df 100644
--- a/src/sdl/CMakeLists.txt
+++ b/src/sdl/CMakeLists.txt
@@ -21,46 +21,25 @@ if(${SRB2_CONFIG_SDL2_USEMIXER})
endif()
if(${SDL2_MIXER_FOUND})
set(SRB2_HAVE_MIXER ON)
- set(SRB2_SDL2_SOUNDIMPL mixer_sound.c)
+ target_sources(SRB2SDL2 PRIVATE mixer_sound.c)
else()
message(WARNING "You specified that SDL2_mixer is available, but it was not found. Falling back to sdl sound.")
- set(SRB2_SDL2_SOUNDIMPL sdl_sound.c)
+ target_sources(SRB2SDL2 PRIVATE sdl_sound.c)
endif()
elseif(${MIXERX_FOUND})
- set(SRB2_SDL2_SOUNDIMPL mixer_sound.c)
+ target_sources(SRB2SDL2 PRIVATE mixer_sound.c)
else()
- set(SRB2_SDL2_SOUNDIMPL sdl_sound.c)
+ target_sources(SRB2SDL2 PRIVATE sdl_sound.c)
endif()
-set(SRB2_SDL2_SOURCES
- dosstr.c
- endtxt.c
- hwsym_sdl.c
- i_main.c
- i_net.c
- i_system.c
- i_ttf.c
- i_video.c
- #IMG_xpm.c
- ogl_sdl.c
+target_sourcefile(c)
- ${SRB2_SDL2_SOUNDIMPL}
-)
-
-set(SRB2_SDL2_HEADERS
- endtxt.h
- hwsym_sdl.h
- i_ttf.h
- ogl_sdl.h
- sdlmain.h
-)
+target_sources(SRB2SDL2 PRIVATE ogl_sdl.c)
if(${SRB2_CONFIG_HAVE_THREADS})
- set(SRB2_SDL2_SOURCES ${SRB2_SDL2_SOURCES} i_threads.c)
+ target_sources(SRB2SDL2 PRIVATE i_threads.c)
endif()
-source_group("Interface Code" FILES ${SRB2_SDL2_SOURCES} ${SRB2_SDL2_HEADERS})
-
# Dependency
if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES})
set(SDL2_FOUND ON)
@@ -76,79 +55,29 @@ else()
endif()
if(${SDL2_FOUND})
- set(SRB2_SDL2_TOTAL_SOURCES
- ${SRB2_CORE_SOURCES}
- ${SRB2_CORE_HEADERS}
- ${SRB2_PNG_SOURCES}
- ${SRB2_PNG_HEADERS}
- ${SRB2_CORE_RENDER_SOURCES}
- ${SRB2_CORE_GAME_SOURCES}
- ${SRB2_LUA_SOURCES}
- ${SRB2_LUA_HEADERS}
- ${SRB2_BLUA_SOURCES}
- ${SRB2_BLUA_HEADERS}
- ${SRB2_SDL2_SOURCES}
- ${SRB2_SDL2_HEADERS}
- )
-
- source_group("Main" FILES ${SRB2_CORE_SOURCES} ${SRB2_CORE_HEADERS}
- ${SRB2_PNG_SOURCES} ${SRB2_PNG_HEADERS})
- source_group("Renderer" FILES ${SRB2_CORE_RENDER_SOURCES})
- source_group("Game" FILES ${SRB2_CORE_GAME_SOURCES})
- source_group("Assembly" FILES ${SRB2_ASM_SOURCES} ${SRB2_NASM_SOURCES})
- source_group("LUA" FILES ${SRB2_LUA_SOURCES} ${SRB2_LUA_HEADERS})
- source_group("LUA\\Interpreter" FILES ${SRB2_BLUA_SOURCES} ${SRB2_BLUA_HEADERS})
-
- if(${SRB2_CONFIG_HWRENDER})
- set(SRB2_SDL2_TOTAL_SOURCES ${SRB2_SDL2_TOTAL_SOURCES}
- ${SRB2_HWRENDER_SOURCES}
- ${SRB2_HWRENDER_HEADERS}
- ${SRB2_R_OPENGL_SOURCES}
- ${SRB2_R_OPENGL_HEADERS}
- )
-
- source_group("Hardware" FILES ${SRB2_HWRENDER_SOURCES} ${SRB2_HWRENDER_HEADERS})
- source_group("Hardware\\OpenGL Renderer" FILES ${SRB2_R_OPENGL_SOURCES} ${SRB2_R_OPENGL_HEADERS})
- endif()
-
if(${SRB2_USEASM})
- set(SRB2_SDL2_TOTAL_SOURCES ${SRB2_SDL2_TOTAL_SOURCES}
- ${SRB2_NASM_SOURCES}
- )
- if(MSVC)
- set(SRB2_SDL2_TOTAL_SOURCES ${SRB2_SDL2_TOTAL_SOURCES}
- ${SRB2_NASM_OBJECTS}
- )
- set_source_files_properties(${SRB2_NASM_OBJECTS} PROPERTIES GENERATED ON)
- else()
- list(APPEND SRB2_SDL2_TOTAL_SOURCES ${SRB2_ASM_SOURCES})
- set_source_files_properties(${SRB2_ASM_SOURCES} PROPERTIES LANGUAGE C)
- set_source_files_properties(${SRB2_ASM_SOURCES} PROPERTIES COMPILE_FLAGS "-x assembler-with-cpp")
- endif()
+ set_source_files_properties(${SRB2_ASM_SOURCES} PROPERTIES LANGUAGE C)
+ set_source_files_properties(${SRB2_ASM_SOURCES} PROPERTIES COMPILE_FLAGS "-x assembler-with-cpp")
endif()
if(${CMAKE_SYSTEM} MATCHES Windows)
- set(SRB2_SDL2_TOTAL_SOURCES ${SRB2_SDL2_TOTAL_SOURCES}
- ${CMAKE_SOURCE_DIR}/src/win32/win_dbg.c
- ${CMAKE_SOURCE_DIR}/src/win32/Srb2win.rc
- )
+ target_sources(SRB2SDL2 PRIVATE
+ ../win32/win_dbg.c
+ ../win32/Srb2win.rc)
endif()
if(${CMAKE_SYSTEM} MATCHES Darwin)
set(MACOSX_BUNDLE_ICON_FILE Srb2mac.icns)
set_source_files_properties(macosx/Srb2mac.icns PROPERTIES MACOSX_PACKAGE_LOCATION "Resources")
- set(SRB2_SDL2_MAC_SOURCES
+ target_sources(SRB2SDL2 PRIVATE
macosx/mac_alert.c
macosx/mac_alert.h
macosx/mac_resources.c
macosx/mac_resources.h
macosx/Srb2mac.icns
)
- source_group("Interface Code\\OSX Compatibility" FILES ${SRB2_SDL2_MAC_SOURCES})
- set(SRB2_SDL2_TOTAL_SOURCES ${SRB2_SDL2_TOTAL_SOURCES} ${SRB2_SDL2_MAC_SOURCES})
endif()
- add_executable(SRB2SDL2 MACOSX_BUNDLE WIN32 ${SRB2_SDL2_TOTAL_SOURCES})
if(${CMAKE_SYSTEM} MATCHES Windows)
set_target_properties(SRB2SDL2 PROPERTIES OUTPUT_NAME srb2win)
elseif(${CMAKE_SYSTEM} MATCHES Linux)
@@ -205,18 +134,6 @@ if(${SDL2_FOUND})
set(ASM_ASSEMBLER_OBJFORMAT ${CMAKE_ASM_NASM_OBJECT_FORMAT})
set_source_files_properties(${SRB2_NASM_SOURCES} LANGUAGE ASM_NASM)
endif()
-
- if(MSVC)
- # using assembler with msvc doesn't work, must do it manually
- foreach(ASMFILE ${SRB2_NASM_SOURCES})
- get_filename_component(ASMFILE_NAME ${ASMFILE} NAME_WE)
- set(ASMFILE_NAME ${ASMFILE_NAME}.obj)
- add_custom_command(TARGET SRB2SDL2 PRE_LINK
- COMMAND ${ASM_ASSEMBLER_TEMP} ARGS -f ${ASM_ASSEMBLER_OBJFORMAT} -o ${CMAKE_CURRENT_BINARY_DIR}/${ASMFILE_NAME} ${ASMFILE}
- COMMENT "assemble ${ASMFILE_NAME}."
- )
- endforeach()
- endif()
endif()
set_target_properties(SRB2SDL2 PROPERTIES VERSION ${SRB2_VERSION})
@@ -230,31 +147,6 @@ if(${SDL2_FOUND})
)
endif()
- if(MSVC)
- if(${SRB2_CONFIG_USE_INTERNAL_LIBRARIES})
- set(SDL2_MAIN_FOUND ON)
- if(${SRB2_SYSTEM_BITS} EQUAL 64)
- set(SDL2_MAIN_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/SDL2/x86_64-w64-mingw32/include/SDL2)
- set(SDL2_MAIN_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/SDL2/x86_64-w64-mingw32/lib -lSDL2main")
- else() # 32-bit
- set(SDL2_MAIN_INCLUDE_DIRS ${CMAKE_SOURCE_DIR}/libs/SDL2/i686-w64-mingw32/include/SDL2)
- set(SDL2_MAIN_LIBRARIES "-L${CMAKE_SOURCE_DIR}/libs/SDL2/i686-w64-mingw32/lib -lSDL2main")
- endif()
- else()
- find_package(SDL2_MAIN REQUIRED)
- endif()
- target_link_libraries(SRB2SDL2 PRIVATE
- ${SDL2_MAIN_LIBRARIES}
- )
- target_compile_options(SRB2SDL2 PRIVATE
- /Umain
- /D_CRT_SECURE_NO_WARNINGS # something about string functions.
- /D_CRT_NONSTDC_NO_DEPRECATE
- /DSDLMAIN
- /D_WINSOCK_DEPRECATED_NO_WARNINGS # Don't care
- )
- endif()
-
target_include_directories(SRB2SDL2 PRIVATE
${SDL2_INCLUDE_DIRS}
${SDL2_MIXER_INCLUDE_DIRS}
diff --git a/src/sdl/MakeNIX.cfg b/src/sdl/MakeNIX.cfg
deleted file mode 100644
index c2f3ff0b6..000000000
--- a/src/sdl/MakeNIX.cfg
+++ /dev/null
@@ -1,76 +0,0 @@
-#
-# sdl/makeNIX.cfg for SRB2/?nix
-#
-
-#Valgrind support
-ifdef VALGRIND
-VALGRIND_PKGCONFIG?=valgrind
-VALGRIND_CFLAGS?=$(shell $(PKG_CONFIG) $(VALGRIND_PKGCONFIG) --cflags)
-VALGRIND_LDFLAGS?=$(shell $(PKG_CONFIG) $(VALGRIND_PKGCONFIG) --libs)
-ZDEBUG=1
-LIBS+=$(VALGRIND_LDFLAGS)
-ifdef GCC46
-WFLAGS+=-Wno-error=unused-but-set-variable
-WFLAGS+=-Wno-unused-but-set-variable
-endif
-endif
-
-#
-#here is GNU/Linux and other
-#
- OPTS=-DUNIXCOMMON
-
-#Use -rdynamic so a backtrace log shows function names instead of addresses
- LDFLAGS+=-rdynamic
-
- #LDFLAGS = -L/usr/local/lib
- LIBS=-lm
-ifdef LINUX
- LIBS+=-lrt
-ifdef NOTERMIOS
- OPTS+=-DNOTERMIOS
-endif
-endif
-
-ifdef LINUX64
- OPTS+=-DLINUX64
-endif
-
-#
-#here is Solaris
-#
-ifdef SOLARIS
- NOIPX=1
- NOASM=1
- OPTS+=-DSOLARIS -DINADDR_NONE=INADDR_ANY -DBSD_COMP
- OPTS+=-I/usr/local/include -I/opt/sfw/include
- LDFLAGS+=-L/opt/sfw/lib
- LIBS+=-lsocket -lnsl
-endif
-
-#
-#here is FreeBSD
-#
-ifdef FREEBSD
- OPTS+=-DLINUX -DFREEBSD -I/usr/X11R6/include
- SDL_CONFIG?=sdl11-config
- LDFLAGS+=-L/usr/X11R6/lib
- LIBS+=-lipx -lkvm
-endif
-
-#
-#here is Mac OS X
-#
-ifdef MACOSX
- OBJS+=$(OBJDIR)/mac_resources.o
- OBJS+=$(OBJDIR)/mac_alert.o
- LIBS+=-framework CoreFoundation
-endif
-
-ifndef NOHW
- OPTS+=-I/usr/X11R6/include
- LDFLAGS+=-L/usr/X11R6/lib
-endif
-
- # name of the exefile
- EXENAME?=lsdl2srb2
diff --git a/src/sdl/Makefile.cfg b/src/sdl/Makefile.cfg
deleted file mode 100644
index 45d0d6ba7..000000000
--- a/src/sdl/Makefile.cfg
+++ /dev/null
@@ -1,125 +0,0 @@
-#
-# sdl/makefile.cfg for SRB2/SDL
-#
-
-#
-#SDL...., *looks at Alam*, THIS IS A MESS!
-#
-
-ifdef UNIXCOMMON
-include sdl/MakeNIX.cfg
-endif
-
-ifdef PANDORA
-include sdl/SRB2Pandora/Makefile.cfg
-endif #ifdef PANDORA
-
-ifdef CYGWIN32
-include sdl/MakeCYG.cfg
-endif #ifdef CYGWIN32
-
-ifdef SDL_PKGCONFIG
-SDL_CFLAGS?=$(shell $(PKG_CONFIG) $(SDL_PKGCONFIG) --cflags)
-SDL_LDFLAGS?=$(shell $(PKG_CONFIG) $(SDL_PKGCONFIG) --libs)
-else
-ifdef PREFIX
- SDL_CONFIG?=$(PREFIX)-sdl2-config
-else
- SDL_CONFIG?=sdl2-config
-endif
-
-ifdef STATIC
- SDL_CFLAGS?=$(shell $(SDL_CONFIG) --cflags)
- SDL_LDFLAGS?=$(shell $(SDL_CONFIG) --static-libs)
-else
- SDL_CFLAGS?=$(shell $(SDL_CONFIG) --cflags)
- SDL_LDFLAGS?=$(shell $(SDL_CONFIG) --libs)
-endif
-endif
-
-
- #use the x86 asm code
-ifndef CYGWIN32
-ifndef NOASM
- USEASM=1
-endif
-endif
-
- OBJS+=$(OBJDIR)/i_video.o $(OBJDIR)/dosstr.o $(OBJDIR)/endtxt.o $(OBJDIR)/hwsym_sdl.o
-
- OPTS+=-DDIRECTFULLSCREEN -DHAVE_SDL
-
-ifndef NOHW
- OBJS+=$(OBJDIR)/r_opengl.o $(OBJDIR)/ogl_sdl.o
-endif
-
-ifdef NOMIXER
- i_sound_o=$(OBJDIR)/sdl_sound.o
-else
- i_sound_o=$(OBJDIR)/mixer_sound.o
- OPTS+=-DHAVE_MIXER
-ifdef HAVE_MIXERX
- OPTS+=-DHAVE_MIXERX
- SDL_LDFLAGS+=-lSDL2_mixer_ext
-else
- SDL_LDFLAGS+=-lSDL2_mixer
-endif
-endif
-
-ifndef NOTHREADS
- OPTS+=-DHAVE_THREADS
- OBJS+=$(OBJDIR)/i_threads.o
-endif
-
-ifdef SDL_TTF
- OPTS+=-DHAVE_TTF
- SDL_LDFLAGS+=-lSDL2_ttf -lfreetype -lz
- OBJS+=$(OBJDIR)/i_ttf.o
-endif
-
-ifdef SDL_IMAGE
- OPTS+=-DHAVE_IMAGE
- SDL_LDFLAGS+=-lSDL2_image
-endif
-
-ifdef SDL_NET
- OPTS+=-DHAVE_SDLNET
- SDL_LDFLAGS+=-lSDL2_net
-endif
-
-ifdef MINGW
-ifndef NOSDLMAIN
- SDLMAIN=1
-endif
-endif
-
-ifdef SDLMAIN
- OPTS+=-DSDLMAIN
-else
-ifdef MINGW
- SDL_CFLAGS+=-Umain
- SDL_LDFLAGS+=-mconsole
-endif
-endif
-
-ifndef NOHW
-ifdef OPENAL
-ifdef MINGW
- LIBS:=-lopenal32 $(LIBS)
-else
- LIBS:=-lopenal $(LIBS)
-endif
-else
-ifdef MINGW
-ifdef DS3D
- LIBS:=-ldsound -luuid $(LIBS)
-endif
-endif
-endif
-endif
-
-CFLAGS+=$(SDL_CFLAGS)
-LIBS:=$(SDL_LDFLAGS) $(LIBS)
-ifdef STATIC
- LIBS+=$(shell $(SDL_CONFIG) --static-libs)
-endif
diff --git a/src/sdl/Sourcefile b/src/sdl/Sourcefile
new file mode 100644
index 000000000..82d5ce073
--- /dev/null
+++ b/src/sdl/Sourcefile
@@ -0,0 +1,7 @@
+i_net.c
+i_system.c
+i_main.c
+i_video.c
+dosstr.c
+endtxt.c
+hwsym_sdl.c
diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c
index c387e5a18..819589eaf 100644
--- a/src/sdl/i_video.c
+++ b/src/sdl/i_video.c
@@ -407,7 +407,7 @@ void I_UpdateMouseGrab(void)
boolean I_GetMouseGrab(void)
{
- return SDL_GetWindowGrab(window);
+ return (boolean)SDL_GetWindowGrab(window);
}
void I_SetMouseGrab(boolean grab)
@@ -1070,7 +1070,7 @@ void I_GetEvent(void)
M_SetupJoystickMenu(0);
break;
case SDL_QUIT:
- LUAh_GameQuit(true);
+ LUA_HookBool(true, HOOK(GameQuit));
I_Quit();
break;
}
diff --git a/src/win32/Makefile.cfg b/src/win32/Makefile.cfg
deleted file mode 100644
index 702ae3765..000000000
--- a/src/win32/Makefile.cfg
+++ /dev/null
@@ -1,136 +0,0 @@
-#
-# win32/Makefile.cfg for SRB2/Minwgw
-#
-
-#
-#Mingw, if you don't know, that's Win32/Win64
-#
-
-ifdef MINGW64
- HAVE_LIBGME=1
- LIBGME_CFLAGS=-I../libs/gme/include
- LIBGME_LDFLAGS=-L../libs/gme/win64 -lgme
-ifdef HAVE_OPENMPT
- LIBOPENMPT_CFLAGS?=-I../libs/libopenmpt/inc
- LIBOPENMPT_LDFLAGS?=-L../libs/libopenmpt/lib/x86_64/mingw -lopenmpt
-endif
-ifndef NOMIXERX
- HAVE_MIXERX=1
- SDL_CFLAGS?=-I../libs/SDL2/x86_64-w64-mingw32/include/SDL2 -I../libs/SDLMixerX/x86_64-w64-mingw32/include/SDL2 -Dmain=SDL_main
- SDL_LDFLAGS?=-L../libs/SDL2/x86_64-w64-mingw32/lib -L../libs/SDLMixerX/x86_64-w64-mingw32/lib -lmingw32 -lSDL2main -lSDL2 -mwindows
-else
- SDL_CFLAGS?=-I../libs/SDL2/x86_64-w64-mingw32/include/SDL2 -I../libs/SDL2_mixer/x86_64-w64-mingw32/include/SDL2 -Dmain=SDL_main
- SDL_LDFLAGS?=-L../libs/SDL2/x86_64-w64-mingw32/lib -L../libs/SDL2_mixer/x86_64-w64-mingw32/lib -lmingw32 -lSDL2main -lSDL2 -mwindows
-endif
-else
- HAVE_LIBGME=1
- LIBGME_CFLAGS=-I../libs/gme/include
- LIBGME_LDFLAGS=-L../libs/gme/win32 -lgme
-ifdef HAVE_OPENMPT
- LIBOPENMPT_CFLAGS?=-I../libs/libopenmpt/inc
- LIBOPENMPT_LDFLAGS?=-L../libs/libopenmpt/lib/x86/mingw -lopenmpt
-endif
-ifndef NOMIXERX
- HAVE_MIXERX=1
- SDL_CFLAGS?=-I../libs/SDL2/i686-w64-mingw32/include/SDL2 -I../libs/SDLMixerX/i686-w64-mingw32/include/SDL2 -Dmain=SDL_main
- SDL_LDFLAGS?=-L../libs/SDL2/i686-w64-mingw32/lib -L../libs/SDLMixerX/i686-w64-mingw32/lib -lmingw32 -lSDL2main -lSDL2 -mwindows
-else
- SDL_CFLAGS?=-I../libs/SDL2/i686-w64-mingw32/include/SDL2 -I../libs/SDL2_mixer/i686-w64-mingw32/include/SDL2 -Dmain=SDL_main
- SDL_LDFLAGS?=-L../libs/SDL2/i686-w64-mingw32/lib -L../libs/SDL2_mixer/i686-w64-mingw32/lib -lmingw32 -lSDL2main -lSDL2 -mwindows
-endif
-endif
-
-ifndef NOASM
- USEASM=1
-endif
-
-ifndef NONET
-ifndef MINGW64 #miniupnc is broken with MINGW64
- HAVE_MINIUPNPC=1
-endif
-endif
-
- OPTS=-DSTDC_HEADERS
-
-ifndef GCC44
- #OPTS+=-mms-bitfields
-endif
-
- LIBS+=-ladvapi32 -lkernel32 -lmsvcrt -luser32
-ifdef MINGW64
- LIBS+=-lws2_32
-else
-ifdef NO_IPV6
- LIBS+=-lwsock32
-else
- LIBS+=-lws2_32
-endif
-endif
-
- # name of the exefile
- EXENAME?=srb2win.exe
-
-ifdef SDL
- i_system_o+=$(OBJDIR)/SRB2.res
- #i_main_o+=$(OBJDIR)/win_dbg.o
-ifndef NOHW
- OPTS+=-DUSE_WGL_SWAP
-endif
-endif
-
-
-ZLIB_CFLAGS?=-I../libs/zlib
-ifdef MINGW64
-ZLIB_LDFLAGS?=-L../libs/zlib/win32 -lz64
-else
-ZLIB_LDFLAGS?=-L../libs/zlib/win32 -lz32
-endif
-
-ifndef NOPNG
-ifndef PNG_CONFIG
- PNG_CFLAGS?=-I../libs/libpng-src
-ifdef MINGW64
- PNG_LDFLAGS?=-L../libs/libpng-src/projects -lpng64
-else
- PNG_LDFLAGS?=-L../libs/libpng-src/projects -lpng32
-endif #MINGW64
-endif #PNG_CONFIG
-endif #NOPNG
-
-ifdef GETTEXT
-ifndef CCBS
- MSGFMT?=../libs/gettext/bin32/msgfmt.exe
-endif
-ifdef MINGW64
- CPPFLAGS+=-I../libs/gettext/include64
- LDFLAGS+=-L../libs/gettext/lib64
- LIBS+=-lmingwex
-else
- CPPFLAGS+=-I../libs/gettext/include32
- LDFLAGS+=-L../libs/gettext/lib32
- STATIC_GETTEXT=1
-endif #MINGW64
-ifdef STATIC_GETTEXT
- LIBS+=-lasprintf -lintl
-else
- LIBS+=-lintl.dll
-endif #STATIC_GETTEXT
-endif #GETTEXT
-
-ifdef HAVE_MINIUPNPC
- CPPFLAGS+=-I../libs/ -DSTATIC_MINIUPNPC
-ifdef MINGW64
- LDFLAGS+=-L../libs/miniupnpc/mingw64
-else
- LDFLAGS+=-L../libs/miniupnpc/mingw32
-endif #MINGW64
-endif
-
-ifndef NOCURL
- CURL_CFLAGS+=-I../libs/curl/include
-ifdef MINGW64
- CURL_LDFLAGS+=-L../libs/curl/lib64 -lcurl
-else
- CURL_LDFLAGS+=-L../libs/curl/lib32 -lcurl
-endif #MINGW64
-endif
diff --git a/src/y_inter.c b/src/y_inter.c
index 6d3ec2cb5..6d876d7bd 100644
--- a/src/y_inter.c
+++ b/src/y_inter.c
@@ -1021,7 +1021,8 @@ void Y_Ticker(void)
if (paused || P_AutoPause())
return;
- LUAh_IntermissionThinker(intertype == int_spec && stagefailed);
+ LUA_HookBool(intertype == int_spec && stagefailed,
+ HOOK(IntermissionThinker));
intertic++;