diff --git a/.gitmodules b/.gitmodules index c9a30c95db8e256b9939de77864822afdb2afb9c..128c4868451f6d3914161f7068382a1d93299f8e 100644 --- a/.gitmodules +++ b/.gitmodules @@ -10,7 +10,3 @@ path = vendor/opusfile url = https://github.com/xiph/opusfile.git branch = master -[submodule "vendor/librw"] - path = vendor/librw - url = https://github.com/aap/librw.git - branch = master diff --git a/premake5.lua b/premake5.lua index 9bb2f52bd3376a0a5d55b26caaa060eb45d50e73..9ef7c6151f1dcdf26625717e0eab3e47bed0ef9a 100644 --- a/premake5.lua +++ b/premake5.lua @@ -1,477 +1,479 @@ -newoption { - trigger = "glfwdir64", - value = "PATH", - description = "Directory of glfw", - default = "vendor/glfw-3.3.2.bin.WIN64", -} - -newoption { - trigger = "glfwdir32", - value = "PATH", - description = "Directory of glfw", - default = "vendor/glfw-3.3.2.bin.WIN32", -} - -newoption { - trigger = "with-asan", - description = "Build with address sanitizer" -} - -newoption { - trigger = "with-librw", - description = "Build and use librw from this solution" -} - -newoption { - trigger = "with-opus", - description = "Build with opus" -} - -newoption { - trigger = "with-lto", - description = "Build with link time optimization" -} - -newoption { - trigger = "no-git-hash", - description = "Don't print git commit hash into binary" -} - -newoption { - trigger = "no-full-paths", - description = "Don't print full paths into binary" -} - -require("autoconf") - -if(_OPTIONS["with-librw"]) then - Librw = "vendor/librw" -else - Librw = os.getenv("LIBRW") or "vendor/librw" -end - -function getsys(a) - if a == 'windows' then - return 'win' - end - return a -end - -function getarch(a) - if a == 'x86_64' then - return 'amd64' - elseif a == 'ARM' then - return 'arm' - elseif a == 'ARM64' then - return 'arm64' - end - return a -end - -workspace "reVC" - language "C++" - configurations { "Debug", "Release" } - startproject "reVC" - location "build" - symbols "Full" - staticruntime "off" - - if _OPTIONS["with-asan"] then - buildoptions { "-fsanitize=address -g3 -fno-omit-frame-pointer" } - linkoptions { "-fsanitize=address" } - end - - filter { "system:windows" } - configurations { "Vanilla" } - platforms { - "win-x86-RW34_d3d8-mss", - "win-x86-librw_d3d9-mss", - "win-x86-librw_gl3_glfw-mss", - "win-x86-RW34_d3d8-oal", - "win-x86-librw_d3d9-oal", - "win-x86-librw_gl3_glfw-oal", - "win-amd64-librw_d3d9-oal", - "win-amd64-librw_gl3_glfw-oal", - } - - filter { "system:linux" } - platforms { - "linux-x86-librw_gl3_glfw-oal", - "linux-amd64-librw_gl3_glfw-oal", - "linux-arm-librw_gl3_glfw-oal", - "linux-arm64-librw_gl3_glfw-oal", - } - - filter { "system:bsd" } - platforms { - "bsd-x86-librw_gl3_glfw-oal", - "bsd-amd64-librw_gl3_glfw-oal", - "bsd-arm-librw_gl3_glfw-oal", - "bsd-arm64-librw_gl3_glfw-oal" - } - - filter { "system:macosx" } - platforms { - "macosx-arm64-librw_gl3_glfw-oal", - "macosx-amd64-librw_gl3_glfw-oal", - } - - filter "configurations:Debug" - defines { "DEBUG" } - - filter "configurations:not Debug" - defines { "NDEBUG" } - optimize "Speed" - if(_OPTIONS["with-lto"]) then - flags { "LinkTimeOptimization" } - end - - filter { "platforms:win*" } - system "windows" - - filter { "platforms:linux*" } - system "linux" - - filter { "platforms:bsd*" } - system "bsd" - - filter { "platforms:macosx*" } - system "macosx" - - filter { "platforms:*x86*" } - architecture "x86" - - filter { "platforms:*amd64*" } - architecture "amd64" - - filter { "platforms:*arm*" } - architecture "ARM" - - filter { "platforms:macosx-arm64-*", "files:**.cpp"} - buildoptions { "-target", "arm64-apple-macos11", "-std=gnu++14" } - - filter { "platforms:macosx-arm64-*", "files:**.c"} - buildoptions { "-target", "arm64-apple-macos11" } - - filter { "platforms:macosx-amd64-*", "files:**.cpp"} - buildoptions { "-target", "x86_64-apple-macos10.12", "-std=gnu++14" } - - filter { "platforms:macosx-amd64-*", "files:**.c"} - buildoptions { "-target", "x86_64-apple-macos10.12" } - - filter { "platforms:*librw_d3d9*" } - defines { "RW_D3D9" } - if(not _OPTIONS["with-librw"]) then - libdirs { path.join(Librw, "lib/win-%{getarch(cfg.architecture)}-d3d9/%{cfg.buildcfg}") } - end - - filter "platforms:*librw_gl3_glfw*" - defines { "RW_GL3" } - if(not _OPTIONS["with-librw"]) then - libdirs { path.join(Librw, "lib/%{getsys(cfg.system)}-%{getarch(cfg.architecture)}-gl3/%{cfg.buildcfg}") } - end - - filter "platforms:*x86-librw_gl3_glfw*" - includedirs { path.join(_OPTIONS["glfwdir32"], "include") } - - filter "platforms:*amd64-librw_gl3_glfw*" - includedirs { path.join(_OPTIONS["glfwdir64"], "include") } - - filter {} - - function setpaths (gamepath, exepath) - if (gamepath) then - postbuildcommands { - '{COPYFILE} "%{cfg.buildtarget.abspath}" "' .. gamepath .. '%{cfg.buildtarget.name}"' - } - debugdir (gamepath) - if (exepath) then - -- Used VS variable $(TargetFileName) because it doesn't accept premake tokens. Does debugcommand even work outside VS?? - debugcommand (gamepath .. "$(TargetFileName)") - dir, file = exepath:match'(.*/)(.*)' - debugdir (gamepath .. (dir or "")) - end - end - end - -if(_OPTIONS["with-librw"]) then -project "librw" - kind "StaticLib" - targetname "rw" - targetdir(path.join(Librw, "lib/%{cfg.platform}/%{cfg.buildcfg}")) - files { path.join(Librw, "src/*.*") } - files { path.join(Librw, "src/*/*.*") } - files { path.join(Librw, "src/gl/*/*.*") } - - filter { "platforms:*x86*" } - architecture "x86" - - filter { "platforms:*amd64*" } - architecture "amd64" - - filter "platforms:win*" - defines { "_CRT_SECURE_NO_WARNINGS", "_CRT_NONSTDC_NO_DEPRECATE" } - staticruntime "on" - buildoptions { "/Zc:sizedDealloc-" } - - filter "platforms:bsd*" - includedirs { "/usr/local/include" } - libdirs { "/usr/local/lib" } - - -- Support MacPorts and Homebrew - filter "platforms:macosx-arm64-*" - includedirs { "/opt/local/include" } - includedirs {"/opt/homebrew/include" } - libdirs { "/opt/local/lib" } - libdirs { "/opt/homebrew/lib" } - - filter "platforms:macosx-amd64-*" - includedirs { "/opt/local/include" } - includedirs {"/usr/local/include" } - libdirs { "/opt/local/lib" } - libdirs { "/usr/local/lib" } - - filter "platforms:*gl3_glfw*" - staticruntime "off" - - filter "platforms:*RW34*" - flags { "ExcludeFromBuild" } - filter {} -end - -local function addSrcFiles( prefix ) - return prefix .. "/*cpp", prefix .. "/*.h", prefix .. "/*.c", prefix .. "/*.ico", prefix .. "/*.rc" -end - -project "reVC" - kind "WindowedApp" - targetname "reVC" - targetdir "bin/%{cfg.platform}/%{cfg.buildcfg}" - - if(_OPTIONS["with-librw"]) then - dependson "librw" - end - - files { addSrcFiles("src") } - files { addSrcFiles("src/animation") } - files { addSrcFiles("src/audio") } - files { addSrcFiles("src/audio/eax") } - files { addSrcFiles("src/audio/oal") } - files { addSrcFiles("src/buildings") } - files { addSrcFiles("src/collision") } - files { addSrcFiles("src/control") } - files { addSrcFiles("src/core") } - files { addSrcFiles("src/entities") } - files { addSrcFiles("src/math") } - files { addSrcFiles("src/modelinfo") } - files { addSrcFiles("src/objects") } - files { addSrcFiles("src/peds") } - files { addSrcFiles("src/renderer") } - files { addSrcFiles("src/rw") } - files { addSrcFiles("src/save") } - files { addSrcFiles("src/skel") } - files { addSrcFiles("src/skel/glfw") } - files { addSrcFiles("src/text") } - files { addSrcFiles("src/vehicles") } - files { addSrcFiles("src/weapons") } - files { addSrcFiles("src/extras") } - if(not _OPTIONS["no-git-hash"]) then - files { "src/extras/GitSHA1.cpp" } -- this won't be in repo in first build - else - removefiles { "src/extras/GitSHA1.cpp" } -- but it will be everytime after - end - - includedirs { "src" } - includedirs { "src/animation" } - includedirs { "src/audio" } - includedirs { "src/audio/eax" } - includedirs { "src/audio/oal" } - includedirs { "src/buildings" } - includedirs { "src/collision" } - includedirs { "src/control" } - includedirs { "src/core" } - includedirs { "src/entities" } - includedirs { "src/math" } - includedirs { "src/modelinfo" } - includedirs { "src/objects" } - includedirs { "src/peds" } - includedirs { "src/renderer" } - includedirs { "src/rw" } - includedirs { "src/save/" } - includedirs { "src/skel/" } - includedirs { "src/skel/glfw" } - includedirs { "src/text" } - includedirs { "src/vehicles" } - includedirs { "src/weapons" } - includedirs { "src/extras" } - - if(not _OPTIONS["no-git-hash"]) then - defines { "USE_OUR_VERSIONING" } - end - - if _OPTIONS["with-opus"] then - includedirs { "vendor/ogg/include" } - includedirs { "vendor/opus/include" } - includedirs { "vendor/opusfile/include" } - end - - filter "configurations:Vanilla" - defines { "VANILLA_DEFINES" } - - filter "platforms:*mss" - defines { "AUDIO_MSS" } - includedirs { "vendor/milessdk/include" } - libdirs { "vendor/milessdk/lib" } - - if _OPTIONS["with-opus"] then - filter "platforms:win*" - libdirs { "vendor/ogg/win32/VS2015/Win32/%{cfg.buildcfg}" } - libdirs { "vendor/opus/win32/VS2015/Win32/%{cfg.buildcfg}" } - libdirs { "vendor/opusfile/win32/VS2015/Win32/Release-NoHTTP" } - filter {} - defines { "AUDIO_OPUS" } - end - - filter "platforms:*oal" - defines { "AUDIO_OAL" } - - filter {} - if(os.getenv("GTA_VC_RE_DIR")) then - setpaths(os.getenv("GTA_VC_RE_DIR") .. "/", "%(cfg.buildtarget.name)") - end - - filter "platforms:win*" - files { addSrcFiles("src/skel/win") } - includedirs { "src/skel/win" } - buildoptions { "/Zc:sizedDealloc-" } - linkoptions "/SAFESEH:NO" - characterset ("MBCS") - targetextension ".exe" - if(_OPTIONS["no-full-paths"]) then - usefullpaths "off" - linkoptions "/PDBALTPATH:%_PDB%" - end - if(_OPTIONS["with-librw"]) then - -- external librw is dynamic - staticruntime "on" - end - if(not _OPTIONS["no-git-hash"]) then - prebuildcommands { '"%{prj.location}..\\printHash.bat" "%{prj.location}..\\src\\extras\\GitSHA1.cpp"' } - end - - filter "platforms:not win*" - if(not _OPTIONS["no-git-hash"]) then - prebuildcommands { '"%{prj.location}/../printHash.sh" "%{prj.location}/../src/extras/GitSHA1.cpp"' } - end - - filter "platforms:win*glfw*" - staticruntime "off" - - filter "platforms:*glfw*" - premake.modules.autoconf.parameters = "-lglfw -lX11" - autoconfigure { - -- iterates all configs and runs on them - ["dontWrite"] = function (cfg) - check_symbol_exists(cfg, "haveX11", "glfwGetX11Display", { "X11/Xlib.h", "X11/XKBlib.h", "GLFW/glfw3.h", "GLFW/glfw3native.h" }, "GLFW_EXPOSE_NATIVE_X11") - if cfg.autoconf["haveX11"] ~= nil and cfg.autoconf["haveX11"] == 1 then - table.insert(cfg.links, "X11") - table.insert(cfg.defines, "GET_KEYBOARD_INPUT_FROM_X11") - end - end - } - - filter "platforms:win*oal" - includedirs { "vendor/openal-soft/include" } - includedirs { "vendor/libsndfile/include" } - includedirs { "vendor/mpg123/include" } - - filter "platforms:win-x86*oal" - libdirs { "vendor/mpg123/lib/Win32" } - libdirs { "vendor/libsndfile/lib/Win32" } - libdirs { "vendor/openal-soft/libs/Win32" } - - filter "platforms:win-amd64*oal" - libdirs { "vendor/mpg123/lib/Win64" } - libdirs { "vendor/libsndfile/lib/Win64" } - libdirs { "vendor/openal-soft/libs/Win64" } - - filter "platforms:linux*oal" - links { "openal", "mpg123", "sndfile", "pthread" } - - filter "platforms:bsd*oal" - links { "openal", "mpg123", "sndfile", "pthread" } - - filter "platforms:macosx*oal" - links { "openal", "mpg123", "sndfile", "pthread" } - - filter "platforms:macosx-arm64-*oal" - includedirs { "/opt/homebrew/opt/openal-soft/include" } - libdirs { "/opt/homebrew/opt/openal-soft/lib" } - - filter "platforms:macosx-amd64-*oal" - includedirs { "/usr/local/opt/openal-soft/include" } - libdirs { "/usr/local/opt/openal-soft/lib" } - - if _OPTIONS["with-opus"] then - filter {} - links { "libogg" } - links { "opus" } - links { "opusfile" } - end - - filter "platforms:*RW34*" - includedirs { "sdk/rwsdk/include/d3d8" } - libdirs { "sdk/rwsdk/lib/d3d8/release" } - links { "rwcore", "rpworld", "rpmatfx", "rpskin", "rphanim", "rtbmp", "rtquat", "rtanim", "rtcharse", "rpanisot" } - defines { "RWLIBS" } - linkoptions "/SECTION:_rwcseg,ER!W /MERGE:_rwcseg=.text" - - filter "platforms:*librw*" - defines { "LIBRW" } - files { addSrcFiles("src/fakerw") } - includedirs { "src/fakerw" } - includedirs { Librw } - if(_OPTIONS["with-librw"]) then - libdirs { "vendor/librw/lib/%{cfg.platform}/%{cfg.buildcfg}" } - end - links { "rw" } - - filter "platforms:*d3d9*" - defines { "USE_D3D9" } - links { "d3d9" } - - filter "platforms:*x86*d3d*" - includedirs { "sdk/dx8sdk/include" } - libdirs { "sdk/dx8sdk/lib" } - - filter "platforms:win-x86*gl3_glfw*" - libdirs { path.join(_OPTIONS["glfwdir32"], "lib-" .. string.gsub(_ACTION or '', "vs", "vc")) } - links { "opengl32", "glfw3" } - - filter "platforms:win-amd64*gl3_glfw*" - libdirs { path.join(_OPTIONS["glfwdir64"], "lib-" .. string.gsub(_ACTION or '', "vs", "vc")) } - links { "opengl32", "glfw3" } - - filter "platforms:linux*gl3_glfw*" - links { "GL", "glfw" } - - filter "platforms:bsd*gl3_glfw*" - links { "GL", "glfw", "sysinfo" } - includedirs { "/usr/local/include" } - libdirs { "/usr/local/lib" } - - filter "platforms:macosx-arm64-*gl3_glfw*" - links { "glfw" } - linkoptions { "-framework OpenGL" } - includedirs { "/opt/local/include" } - includedirs {"/opt/homebrew/include" } - libdirs { "/opt/local/lib" } - libdirs { "/opt/homebrew/lib" } - - filter "platforms:macosx-amd64-*gl3_glfw*" - links { "glfw" } - linkoptions { "-framework OpenGL" } - includedirs { "/opt/local/include" } - includedirs {"/usr/local/include" } - libdirs { "/opt/local/lib" } - libdirs { "/usr/local/lib" } +newoption { + trigger = "glfwdir64", + value = "PATH", + description = "Directory of glfw", + default = "vendor/glfw-3.3.2.bin.WIN64", +} + +newoption { + trigger = "glfwdir32", + value = "PATH", + description = "Directory of glfw", + default = "vendor/glfw-3.3.2.bin.WIN32", +} + +newoption { + trigger = "with-asan", + description = "Build with address sanitizer" +} + +newoption { + trigger = "with-librw", + description = "Build and use librw from this solution" +} + +newoption { + trigger = "with-opus", + description = "Build with opus" +} + +newoption { + trigger = "with-lto", + description = "Build with link time optimization" +} + +newoption { + trigger = "no-git-hash", + description = "Don't print git commit hash into binary" +} + +newoption { + trigger = "no-full-paths", + description = "Don't print full paths into binary" +} + +require("autoconf") + +if(_OPTIONS["with-librw"]) then + Librw = "vendor/librw" +else + Librw = os.getenv("LIBRW") or "vendor/librw" +end + +function getsys(a) + if a == 'windows' then + return 'win' + end + return a +end + +function getarch(a) + if a == 'x86_64' then + return 'amd64' + elseif a == 'ARM' then + return 'arm' + elseif a == 'ARM64' then + return 'arm64' + end + return a +end + +workspace "reVC" + language "C++" + configurations { "Debug", "Release" } + startproject "reVC" + location "build" + symbols "Full" + staticruntime "off" + + if _OPTIONS["with-asan"] then + buildoptions { "-fsanitize=address -g3 -fno-omit-frame-pointer" } + linkoptions { "-fsanitize=address" } + end + + filter { "system:windows" } + configurations { "Vanilla" } + platforms { + "win-x86-RW34_d3d8-mss", + "win-x86-librw_d3d9-mss", + "win-x86-librw_gl3_glfw-mss", + "win-x86-RW34_d3d8-oal", + "win-x86-librw_d3d9-oal", + "win-x86-librw_gl3_glfw-oal", + "win-amd64-librw_d3d9-oal", + "win-amd64-librw_gl3_glfw-oal", + } + + filter { "system:linux" } + platforms { + "linux-x86-librw_gl3_glfw-oal", + "linux-amd64-librw_gl3_glfw-oal", + "linux-arm-librw_gl3_glfw-oal", + "linux-arm64-librw_gl3_glfw-oal", + } + + filter { "system:bsd" } + platforms { + "bsd-x86-librw_gl3_glfw-oal", + "bsd-amd64-librw_gl3_glfw-oal", + "bsd-arm-librw_gl3_glfw-oal", + "bsd-arm64-librw_gl3_glfw-oal" + } + + filter { "system:macosx" } + platforms { + "macosx-arm64-librw_gl3_glfw-oal", + "macosx-amd64-librw_gl3_glfw-oal", + } + + filter "configurations:Debug" + defines { "DEBUG" } + + filter "configurations:not Debug" + defines { "NDEBUG" } + optimize "Speed" + if(_OPTIONS["with-lto"]) then + flags { "LinkTimeOptimization" } + end + + filter { "platforms:win*" } + system "windows" + + filter { "platforms:linux*" } + system "linux" + + filter { "platforms:bsd*" } + system "bsd" + + filter { "platforms:macosx*" } + system "macosx" + + filter { "platforms:*x86*" } + architecture "x86" + + filter { "platforms:*amd64*" } + architecture "amd64" + + filter { "platforms:*arm*" } + architecture "ARM" + + filter { "platforms:macosx-arm64-*", "files:**.cpp"} + buildoptions { "-target", "arm64-apple-macos11", "-std=gnu++14" } + + filter { "platforms:macosx-arm64-*", "files:**.c"} + buildoptions { "-target", "arm64-apple-macos11" } + + filter { "platforms:macosx-amd64-*", "files:**.cpp"} + buildoptions { "-target", "x86_64-apple-macos10.12", "-std=gnu++14" } + + filter { "platforms:macosx-amd64-*", "files:**.c"} + buildoptions { "-target", "x86_64-apple-macos10.12" } + + filter { "platforms:*librw_d3d9*" } + defines { "RW_D3D9" } + if(not _OPTIONS["with-librw"]) then + libdirs { path.join(Librw, "lib/win-%{getarch(cfg.architecture)}-d3d9/%{cfg.buildcfg}") } + end + + filter "platforms:*librw_gl3_glfw*" + defines { "RW_GL3" } + if(not _OPTIONS["with-librw"]) then + libdirs { path.join(Librw, "lib/%{getsys(cfg.system)}-%{getarch(cfg.architecture)}-gl3/%{cfg.buildcfg}") } + end + + filter "platforms:*x86-librw_gl3_glfw*" + includedirs { path.join(_OPTIONS["glfwdir32"], "include") } + + filter "platforms:*amd64-librw_gl3_glfw*" + includedirs { path.join(_OPTIONS["glfwdir64"], "include") } + + filter {} + + function setpaths (gamepath, exepath) + if (gamepath) then + postbuildcommands { + '{COPYFILE} "%{cfg.buildtarget.abspath}" "' .. gamepath .. '%{cfg.buildtarget.name}"' + } + debugdir (gamepath) + if (exepath) then + -- Used VS variable $(TargetFileName) because it doesn't accept premake tokens. Does debugcommand even work outside VS?? + debugcommand (gamepath .. "$(TargetFileName)") + dir, file = exepath:match'(.*/)(.*)' + debugdir (gamepath .. (dir or "")) + end + end + end + +if(_OPTIONS["with-librw"]) then +project "librw" + kind "StaticLib" + targetname "rw" + targetdir(path.join(Librw, "lib/%{cfg.platform}/%{cfg.buildcfg}")) + files { path.join(Librw, "src/*.*") } + files { path.join(Librw, "src/*/*.*") } + files { path.join(Librw, "src/gl/*/*.*") } + + filter { "platforms:*x86*" } + architecture "x86" + + filter { "platforms:*amd64*" } + architecture "amd64" + + filter "platforms:win*" + defines { "_CRT_SECURE_NO_WARNINGS", "_CRT_NONSTDC_NO_DEPRECATE" } + staticruntime "on" + buildoptions { "/Zc:sizedDealloc-" } + + filter "platforms:bsd*" + includedirs { "/usr/local/include" } + libdirs { "/usr/local/lib" } + + -- Support MacPorts and Homebrew + filter "platforms:macosx-arm64-*" + includedirs { "/opt/local/include" } + includedirs {"/opt/homebrew/include" } + libdirs { "/opt/local/lib" } + libdirs { "/opt/homebrew/lib" } + + filter "platforms:macosx-amd64-*" + includedirs { "/opt/local/include" } + includedirs {"/usr/local/include" } + libdirs { "/opt/local/lib" } + libdirs { "/usr/local/lib" } + + filter "platforms:*gl3_glfw*" + staticruntime "off" + + filter "platforms:*RW34*" + flags { "ExcludeFromBuild" } + filter {} +end + +local function addSrcFiles( prefix ) + return prefix .. "/*cpp", prefix .. "/*.h", prefix .. "/*.c", prefix .. "/*.ico", prefix .. "/*.rc" +end + +project "reVC" + kind "WindowedApp" + targetname "reVC" + targetdir "bin/%{cfg.platform}/%{cfg.buildcfg}" + + if(_OPTIONS["with-librw"]) then + dependson "librw" + end + + files { addSrcFiles("src") } + files { addSrcFiles("src/animation") } + files { addSrcFiles("src/audio") } + files { addSrcFiles("src/audio/eax") } + files { addSrcFiles("src/audio/oal") } + files { addSrcFiles("src/buildings") } + files { addSrcFiles("src/collision") } + files { addSrcFiles("src/control") } + files { addSrcFiles("src/core") } + files { addSrcFiles("src/entities") } + files { addSrcFiles("src/math") } + files { addSrcFiles("src/modelinfo") } + files { addSrcFiles("src/objects") } + files { addSrcFiles("src/peds") } + files { addSrcFiles("src/renderer") } + files { addSrcFiles("src/rw") } + files { addSrcFiles("src/save") } + files { addSrcFiles("src/skel") } + files { addSrcFiles("src/skel/glfw") } + files { addSrcFiles("src/text") } + files { addSrcFiles("src/vehicles") } + files { addSrcFiles("src/weapons") } + files { addSrcFiles("src/extras") } + files { addSrcFiles("src/sandbox") } + if(not _OPTIONS["no-git-hash"]) then + files { "src/extras/GitSHA1.cpp" } -- this won't be in repo in first build + else + removefiles { "src/extras/GitSHA1.cpp" } -- but it will be everytime after + end + + includedirs { "src" } + includedirs { "src/animation" } + includedirs { "src/audio" } + includedirs { "src/audio/eax" } + includedirs { "src/audio/oal" } + includedirs { "src/buildings" } + includedirs { "src/collision" } + includedirs { "src/control" } + includedirs { "src/core" } + includedirs { "src/entities" } + includedirs { "src/math" } + includedirs { "src/modelinfo" } + includedirs { "src/objects" } + includedirs { "src/peds" } + includedirs { "src/renderer" } + includedirs { "src/rw" } + includedirs { "src/sandbox" } + includedirs { "src/save/" } + includedirs { "src/skel/" } + includedirs { "src/skel/glfw" } + includedirs { "src/text" } + includedirs { "src/vehicles" } + includedirs { "src/weapons" } + includedirs { "src/extras" } + + if(not _OPTIONS["no-git-hash"]) then + defines { "USE_OUR_VERSIONING" } + end + + if _OPTIONS["with-opus"] then + includedirs { "vendor/ogg/include" } + includedirs { "vendor/opus/include" } + includedirs { "vendor/opusfile/include" } + end + + filter "configurations:Vanilla" + defines { "VANILLA_DEFINES" } + + filter "platforms:*mss" + defines { "AUDIO_MSS" } + includedirs { "vendor/milessdk/include" } + libdirs { "vendor/milessdk/lib" } + + if _OPTIONS["with-opus"] then + filter "platforms:win*" + libdirs { "vendor/ogg/win32/VS2015/Win32/%{cfg.buildcfg}" } + libdirs { "vendor/opus/win32/VS2015/Win32/%{cfg.buildcfg}" } + libdirs { "vendor/opusfile/win32/VS2015/Win32/Release-NoHTTP" } + filter {} + defines { "AUDIO_OPUS" } + end + + filter "platforms:*oal" + defines { "AUDIO_OAL" } + + filter {} + if(os.getenv("GTA_VC_RE_DIR")) then + setpaths(os.getenv("GTA_VC_RE_DIR") .. "/", "%(cfg.buildtarget.name)") + end + + filter "platforms:win*" + files { addSrcFiles("src/skel/win") } + includedirs { "src/skel/win" } + buildoptions { "/Zc:sizedDealloc-" } + linkoptions "/SAFESEH:NO" + characterset ("MBCS") + targetextension ".exe" + if(_OPTIONS["no-full-paths"]) then + usefullpaths "off" + linkoptions "/PDBALTPATH:%_PDB%" + end + if(_OPTIONS["with-librw"]) then + -- external librw is dynamic + staticruntime "on" + end + if(not _OPTIONS["no-git-hash"]) then + prebuildcommands { '"%{prj.location}..\\printHash.bat" "%{prj.location}..\\src\\extras\\GitSHA1.cpp"' } + end + + filter "platforms:not win*" + if(not _OPTIONS["no-git-hash"]) then + prebuildcommands { '"%{prj.location}/../printHash.sh" "%{prj.location}/../src/extras/GitSHA1.cpp"' } + end + + filter "platforms:win*glfw*" + staticruntime "off" + + filter "platforms:*glfw*" + premake.modules.autoconf.parameters = "-lglfw -lX11" + autoconfigure { + -- iterates all configs and runs on them + ["dontWrite"] = function (cfg) + check_symbol_exists(cfg, "haveX11", "glfwGetX11Display", { "X11/Xlib.h", "X11/XKBlib.h", "GLFW/glfw3.h", "GLFW/glfw3native.h" }, "GLFW_EXPOSE_NATIVE_X11") + if cfg.autoconf["haveX11"] ~= nil and cfg.autoconf["haveX11"] == 1 then + table.insert(cfg.links, "X11") + table.insert(cfg.defines, "GET_KEYBOARD_INPUT_FROM_X11") + end + end + } + + filter "platforms:win*oal" + includedirs { "vendor/openal-soft/include" } + includedirs { "vendor/libsndfile/include" } + includedirs { "vendor/mpg123/include" } + + filter "platforms:win-x86*oal" + libdirs { "vendor/mpg123/lib/Win32" } + libdirs { "vendor/libsndfile/lib/Win32" } + libdirs { "vendor/openal-soft/libs/Win32" } + + filter "platforms:win-amd64*oal" + libdirs { "vendor/mpg123/lib/Win64" } + libdirs { "vendor/libsndfile/lib/Win64" } + libdirs { "vendor/openal-soft/libs/Win64" } + + filter "platforms:linux*oal" + links { "openal", "mpg123", "sndfile", "pthread" } + + filter "platforms:bsd*oal" + links { "openal", "mpg123", "sndfile", "pthread" } + + filter "platforms:macosx*oal" + links { "openal", "mpg123", "sndfile", "pthread" } + + filter "platforms:macosx-arm64-*oal" + includedirs { "/opt/homebrew/opt/openal-soft/include" } + libdirs { "/opt/homebrew/opt/openal-soft/lib" } + + filter "platforms:macosx-amd64-*oal" + includedirs { "/usr/local/opt/openal-soft/include" } + libdirs { "/usr/local/opt/openal-soft/lib" } + + if _OPTIONS["with-opus"] then + filter {} + links { "libogg" } + links { "opus" } + links { "opusfile" } + end + + filter "platforms:*RW34*" + includedirs { "sdk/rwsdk/include/d3d8" } + libdirs { "sdk/rwsdk/lib/d3d8/release" } + links { "rwcore", "rpworld", "rpmatfx", "rpskin", "rphanim", "rtbmp", "rtquat", "rtanim", "rtcharse", "rpanisot" } + defines { "RWLIBS" } + linkoptions "/SECTION:_rwcseg,ER!W /MERGE:_rwcseg=.text" + + filter "platforms:*librw*" + defines { "LIBRW" } + files { addSrcFiles("src/fakerw") } + includedirs { "src/fakerw" } + includedirs { Librw } + if(_OPTIONS["with-librw"]) then + libdirs { "vendor/librw/lib/%{cfg.platform}/%{cfg.buildcfg}" } + end + links { "rw" } + + filter "platforms:*d3d9*" + defines { "USE_D3D9" } + links { "d3d9" } + + filter "platforms:*x86*d3d*" + includedirs { "sdk/dx8sdk/include" } + libdirs { "sdk/dx8sdk/lib" } + + filter "platforms:win-x86*gl3_glfw*" + libdirs { path.join(_OPTIONS["glfwdir32"], "lib-" .. string.gsub(_ACTION or '', "vs", "vc")) } + links { "opengl32", "glfw3" } + + filter "platforms:win-amd64*gl3_glfw*" + libdirs { path.join(_OPTIONS["glfwdir64"], "lib-" .. string.gsub(_ACTION or '', "vs", "vc")) } + links { "opengl32", "glfw3" } + + filter "platforms:linux*gl3_glfw*" + links { "GL", "glfw" } + + filter "platforms:bsd*gl3_glfw*" + links { "GL", "glfw", "sysinfo" } + includedirs { "/usr/local/include" } + libdirs { "/usr/local/lib" } + + filter "platforms:macosx-arm64-*gl3_glfw*" + links { "glfw" } + linkoptions { "-framework OpenGL" } + includedirs { "/opt/local/include" } + includedirs {"/opt/homebrew/include" } + libdirs { "/opt/local/lib" } + libdirs { "/opt/homebrew/lib" } + + filter "platforms:macosx-amd64-*gl3_glfw*" + links { "glfw" } + linkoptions { "-framework OpenGL" } + includedirs { "/opt/local/include" } + includedirs {"/usr/local/include" } + libdirs { "/opt/local/lib" } + libdirs { "/usr/local/lib" } diff --git a/src/audio/MusicManager.cpp b/src/audio/MusicManager.cpp index c97b9c245a5b17f258f154b6452eaa4422e74e63..e890293f163b1abadf404e1fd1ce32811b7e2b63 100644 --- a/src/audio/MusicManager.cpp +++ b/src/audio/MusicManager.cpp @@ -20,6 +20,9 @@ #include "Weather.h" #include "DMAudio.h" #include "GenericGameStorage.h" +#ifdef __EMSCRIPTEN__ +#include +#endif #if !defined FIX_BUGS && (defined RADIO_SCROLL_TO_PREV_STATION || defined RADIO_OFF_TEXT) static_assert(false, "R*'s radio implementation is quite buggy, RADIO_SCROLL_TO_PREV_STATION and RADIO_OFF_TEXT won't work without FIX_BUGS"); @@ -551,6 +554,26 @@ cMusicManager::ServiceGameMode() } } } +#endif +#ifdef __EMSCRIPTEN__ + // The wheel: up is the next station, down the previous, one step at a time however fast it spins. + static uint32 lastWheelTune = 0; + bool wheelUp = CPad::GetPad(0)->GetMouseWheelUpJustDown(), wheelDown = CPad::GetPad(0)->GetMouseWheelDownJustDown(); + if (wheelUp || wheelDown) { + uint32 now = CTimer::GetTimeInMillisecondsPauseMode(); + if (!CPad::GetPad(0)->ArePlayerControlsDisabled() && now - lastWheelTune >= 120 && + !UsesPoliceRadio(vehicle) && !UsesTaxiRadio(vehicle)) { + lastWheelTune = now; + gNumRetunePresses += wheelUp ? 1 : -1; + gRetuneCounter = 20; + RadioStaticCounter = 0; + int track = gNumRetunePresses + vehicle->m_nRadioStation; + while(track < 0) track += NUM_RADIOS + 1; + while(track >= NUM_RADIOS + 1) track -= NUM_RADIOS + 1; + // Going down, the station no browser has is stepped over here; going up, the code below does it. + if(wheelDown && !DMAudio.IsMP3RadioChannelAvailable() && track == USERTRACK) gNumRetunePresses--; + } + } else #endif if (CPad::GetPad(0)->ChangeStationJustDown()) { @@ -560,7 +583,7 @@ cMusicManager::ServiceGameMode() RadioStaticCounter = 0; } } -#ifdef RADIO_SCROLL_TO_PREV_STATION +#if defined RADIO_SCROLL_TO_PREV_STATION && !defined __EMSCRIPTEN__ else if(!CPad::GetPad(0)->ArePlayerControlsDisabled() && (CPad::GetPad(0)->GetMouseWheelDownJustDown() || CPad::GetPad(0)->GetMouseWheelUpJustDown())) { if(!UsesPoliceRadio(vehicle) && !UsesTaxiRadio(vehicle)) { int scrollNext = ControlsManager.GetControllerKeyAssociatedWithAction(VEHICLE_CHANGE_RADIO_STATION, MOUSE); @@ -956,7 +979,12 @@ cMusicManager::ServiceTrack(CVehicle *veh, CPed *ped) m_nPlayingTrack = m_nNextTrack; m_bVerifyNextTrackStartedToPlay = FALSE; m_bTrackChangeStarted = FALSE; +#ifdef __EMSCRIPTEN__ + // A stream starts slowly here: tuning on meanwhile must not be undone by the older one finally playing. + if (veh && m_nPlayingTrack == m_nFrontendTrack) { +#else if (veh) { +#endif #ifdef FIX_BUGS if (m_nPlayingTrack >= STREAMED_SOUND_CITY_AMBIENT && m_nPlayingTrack <= STREAMED_SOUND_AMBSIL_AMBIENT) veh->m_nRadioStation = RADIO_OFF; @@ -1308,6 +1336,16 @@ cMusicManager::DisplayRadioStationName() track = GetCarTuning(); // gStreamedSound or veh->m_nRadioStation would also work, but these don't cover police/taxi radios #else track = m_nFrontendTrack; +#endif +#ifdef __EMSCRIPTEN__ + // The page shows the station with its logo instead of a line of text (index.html, radio strip). + // m_nFrontendTrack lags a frame behind a retune, which flashed the previous logo. + if (gNumRetunePresses == 0) track = GetCarTuning(); + if (track == USERTRACK && !SampleManager.IsMP3RadioChannelAvailable()) return; + if (track == RADIO_OFF && (!m_bRadioStreamReady || !m_bGameplayAllowsRadio)) return; + if (track >= 0 && track <= RADIO_OFF) + EM_ASM({ if (Module.vcRadio !== $0) { Module.vcRadio = $0; Module.vcRadioSeq = (Module.vcRadioSeq || 0) + 1; } }, track); + return; #endif wchar* string = nil; switch (track) { @@ -1385,6 +1423,9 @@ cMusicManager::DisplayRadioStationName() bool8 cMusicManager::UsesPoliceRadio(CVehicle *veh) { +#ifdef ONLINE + return FALSE; +#endif switch (veh->GetModelIndex()) { case MI_VCNMAV: @@ -1403,6 +1444,9 @@ cMusicManager::UsesPoliceRadio(CVehicle *veh) bool8 cMusicManager::UsesTaxiRadio(CVehicle *veh) { +#ifdef ONLINE + return FALSE; +#endif if (veh->GetModelIndex() != MI_KAUFMAN) return FALSE; return CTheScripts::bPlayerHasMetDebbieHarry; } diff --git a/src/audio/oal/stream.cpp b/src/audio/oal/stream.cpp index 3789573e68be92361ff4eb4a190c1d7da2042552..03164a439a0f969630c4add02144639e67a5fc24 100644 --- a/src/audio/oal/stream.cpp +++ b/src/audio/oal/stream.cpp @@ -45,6 +45,7 @@ std::queue> gStreamsToClose; #ifndef _WIN32 #include "crossplatform.h" +#include "WebFile.h" #endif /* @@ -241,7 +242,7 @@ class CWavFile : public IDecoder public: CWavFile(const char* path) : m_bIsOpen(false), m_DataStartOffset(0), m_nSampleCount(0), m_nSamplesPerBlock(0), m_pAdpcmBuffer(nil), m_ppPcmBuffers(nil), m_pAdpcmDecoders(nil) { - m_pFile = fopen(path, "rb"); + m_pFile = WebFileOpen(path, "rb"); if (!m_pFile) return; #define CLOSE_ON_ERROR(op)\ @@ -502,8 +503,22 @@ public: #ifdef AUDIO_OAL_USE_MPG123 +#ifdef __EMSCRIPTEN__ +// Radio stations are "live": tuning in seeks deep into the file. An exact seek decodes +// every frame from the start, which in the browser means downloading all of them; +// fuzzy seeking jumps straight to the estimated byte offset. +#define MP3_DECODER_FLAGS (MPG123_SEEKBUFFER | MPG123_GAPLESS | MPG123_FUZZY) +#else +#define MP3_DECODER_FLAGS (MPG123_SEEKBUFFER | MPG123_GAPLESS) +#endif + class CMP3File : public IDecoder { +#ifdef __EMSCRIPTEN__ + static ssize_t file_read(void* fh, void* buf, size_t size) { return fread(buf, 1, size, (FILE*)fh); } + static off_t file_seek(void* fh, off_t pos, int seekType) { fseek((FILE*)fh, pos, seekType); return ftell((FILE*)fh); } + static void file_close(void* fh) { fclose((FILE*)fh); } +#endif protected: mpg123_handle *m_pMH; bool m_bOpened; @@ -530,7 +545,7 @@ public: m_pMH = mpg123_new(nil, nil); if ( m_pMH ) { - mpg123_param(m_pMH, MPG123_FLAGS, MPG123_SEEKBUFFER | MPG123_GAPLESS, 0.0); + mpg123_param(m_pMH, MPG123_FLAGS, MP3_DECODER_FLAGS, 0.0); m_bOpened = true; m_bFileNotOpenedYet = true; @@ -548,8 +563,17 @@ public: long rate = 0; int channels = 0; int encoding = 0; +#ifdef __EMSCRIPTEN__ + // The big files are not in the browser's file system, so mpg123 reads them through a FILE*. + // Estimate seek targets: a precise seek reads the whole file up to the target over the network. + mpg123_param(m_pMH, MPG123_ADD_FLAGS, MPG123_FUZZY | MPG123_SEEKBUFFER, 0.0); + FILE *f = WebFileOpen(m_pPath, "rb"); + m_bOpened = f && mpg123_replace_reader_handle(m_pMH, file_read, file_seek, file_close) == MPG123_OK + && mpg123_open_handle(m_pMH, f) == MPG123_OK && mpg123_getformat(m_pMH, &rate, &channels, &encoding) == MPG123_OK; +#else m_bOpened = mpg123_open(m_pMH, m_pPath) == MPG123_OK && mpg123_getformat(m_pMH, &rate, &channels, &encoding) == MPG123_OK; +#endif m_nRate = rate; m_nChannels = channels; @@ -650,7 +674,7 @@ public: m_pMH = mpg123_new(nil, nil); if (m_pMH) { - mpg123_param(m_pMH, MPG123_FLAGS, MPG123_SEEKBUFFER | MPG123_GAPLESS, 0.0); + mpg123_param(m_pMH, MPG123_FLAGS, MP3_DECODER_FLAGS, 0.0); m_bOpened = true; m_bFileNotOpenedYet = true; @@ -671,7 +695,7 @@ public: int channels = 0; int encoding = 0; - FILE *f = fopen(m_pPath, "rb"); + FILE *f = WebFileOpen(m_pPath, "rb"); m_bOpened = f && mpg123_replace_reader_handle(m_pMH, r_read, r_seek, r_close) == MPG123_OK && mpg123_open_handle(m_pMH, f) == MPG123_OK && mpg123_getformat(m_pMH, &rate, &channels, &encoding) == MPG123_OK; @@ -790,7 +814,7 @@ public: CVbFile(const char* path, uint32 nSampleRate = 32000, uint8 nChannels = 2) : m_nSampleRate(nSampleRate), m_nChannels(nChannels), m_pVagDecoders(nil), m_ppVagBuffers(nil), m_ppPcmBuffers(nil), m_FileSize(0), m_nNumberOfBlocks(0), m_bBlockRead(false), m_LineInBlock(0), m_CurrentBlock(0) { - m_pFile = fopen(path, "rb"); + m_pFile = WebFileOpen(path, "rb"); if (!m_pFile) return; fseek(m_pFile, 0, SEEK_END); @@ -1681,6 +1705,9 @@ void CStream::Update() { if ( !IsOpened() ) return; + + if ( !WebStreamsReady() ) + return; if ( !HasSource() ) return; @@ -1717,6 +1744,11 @@ void CStream::Update() //alSourcef(m_pAlSources[1], AL_ROLLOFF_FACTOR, 0.0f); alGetSourcei(m_pAlSources[1], AL_BUFFERS_QUEUED, &totalBuffers[1]); alGetSourcei(m_pAlSources[1], AL_BUFFERS_PROCESSED, &buffersProcessed[1]); +#ifdef __EMSCRIPTEN__ + // One thread: the audio clock never advances while this spins, so the tab would hang. + // Take the pairs both sides finished; the rest comes next frame. + buffersProcessed[0] = buffersProcessed[1] = Min(buffersProcessed[0], buffersProcessed[1]); +#endif } while (buffersProcessed[0] != buffersProcessed[1]); assert(buffersProcessed[0] == buffersProcessed[1]); diff --git a/src/audio/sampman_oal.cpp b/src/audio/sampman_oal.cpp index 9cf308324d776c21550fae8b9dc7688a6786eaa1..b594700d96f1339e1e47baaa968387fd675b866f 100644 --- a/src/audio/sampman_oal.cpp +++ b/src/audio/sampman_oal.cpp @@ -47,6 +47,7 @@ #include "MusicManager.h" #include "Frontend.h" #include "Timer.h" +#include "WebFile.h" #ifdef AUDIO_OAL_USE_OPUS #include #endif @@ -164,6 +165,20 @@ add_providers() { SampleManager.SetNum3DProvidersAvailable(0); +#ifdef __EMSCRIPTEN__ + // Web Audio is a single default device without the enumeration extension. + providers[0].id = nil; + strcpy(providers[0].name, "OPENAL SOFT"); + providers[0].sources = MAXCHANNELS; + providers[0].bSupportsFx = false; + SampleManager.Set3DProviderName(0, providers[0].name); + SampleManager.SetNum3DProvidersAvailable(1); + for(int j = 1; j < MAXPROVIDERS; j++) + SampleManager.Set3DProviderName(j, NULL); + defaultProvider = 0; + return; +#endif + static ALDeviceList DeviceList; ALDeviceList *pDeviceList = &DeviceList; @@ -1701,9 +1716,18 @@ cSampleManager::StopChannel(uint32 nChannel) aChannel[nChannel].Stop(); } +#ifdef __EMSCRIPTEN__ +// A radio station starts once its data is here, so changing station never freezes the game. +static bool radioPending = false; +static uint32 radioPendingFile, radioPendingPos; +#endif void cSampleManager::PreloadStreamedFile(uint32 nFile, uint8 nStream) -{ +{ +#ifdef __EMSCRIPTEN__ + if ( nStream == 0 ) + radioPending = false; +#endif ASSERT( nStream < MAX_STREAMS ); if ( nFile < TOTAL_STREAMED_SOUNDS ) @@ -1748,16 +1772,40 @@ cSampleManager::StartPreloadedStreamedFile(uint8 nStream) } } +#ifdef __EMSCRIPTEN__ + +static bool +RadioPrefetch(uint32 nFile, uint32 nPos) +{ + double fraction = nStreamLength[nFile] ? (double)nPos / nStreamLength[nFile] : 0.0; + return WebFilePrefetch(StreamedNameTable[nFile], fraction); +} +#endif + bool8 cSampleManager::StartStreamedFile(uint32 nFile, uint32 nPos, uint8 nStream) { uint32 i = 0; uint32 position = nPos; char filename[MAX_PATH]; - + if ( nFile >= TOTAL_STREAMED_SOUNDS ) return FALSE; +#ifdef __EMSCRIPTEN__ + if ( nStream == 0 ) { + radioPending = false; + if ( nFile != STREAMED_SOUND_RADIO_MP3_PLAYER && !RadioPrefetch(nFile, nPos) ) { + aStream[nStream]->Close(); + _bIsMp3Active = FALSE; + radioPending = true; + radioPendingFile = nFile; + radioPendingPos = nPos; + return TRUE; + } + } +#endif + aStream[nStream]->Close(); if ( nFile == STREAMED_SOUND_RADIO_MP3_PLAYER ) @@ -1909,9 +1957,13 @@ cSampleManager::StopStreamedFile(uint8 nStream) ASSERT( nStream < MAX_STREAMS ); CStream *stream = aStream[nStream]; - + stream->Close(); +#ifdef __EMSCRIPTEN__ + if ( nStream == 0 ) + radioPending = false; +#endif if ( nStream == 0 ) _bIsMp3Active = FALSE; } @@ -1920,6 +1972,11 @@ int32 cSampleManager::GetStreamedFilePosition(uint8 nStream) { ASSERT( nStream < MAX_STREAMS ); + +#ifdef __EMSCRIPTEN__ + if ( nStream == 0 && radioPending ) + return radioPendingPos; +#endif CStream *stream = aStream[nStream]; @@ -1993,6 +2050,11 @@ bool8 cSampleManager::IsStreamPlaying(uint8 nStream) { ASSERT( nStream < MAX_STREAMS ); + +#ifdef __EMSCRIPTEN__ + if ( nStream == 0 && radioPending ) + return TRUE; +#endif CStream *stream = aStream[nStream]; @@ -2008,6 +2070,10 @@ cSampleManager::IsStreamPlaying(uint8 nStream) void cSampleManager::Service(void) { +#ifdef __EMSCRIPTEN__ + if ( radioPending && RadioPrefetch(radioPendingFile, radioPendingPos) ) + StartStreamedFile(radioPendingFile, radioPendingPos, 0); +#endif for ( int32 i = 0; i < MAX_STREAMS; i++ ) { CStream *stream = aStream[i]; @@ -2032,7 +2098,7 @@ cSampleManager::InitialiseSampleBanks(void) if ( fpSampleDescHandle == NULL ) return FALSE; #ifndef OPUS_SFX - fpSampleDataHandle = fcaseopen(SampleBankDataFilename, "rb"); + fpSampleDataHandle = WebFileOpen(SampleBankDataFilename, "rb"); if ( fpSampleDataHandle == NULL ) { fclose(fpSampleDescHandle); diff --git a/src/collision/Collision.cpp b/src/collision/Collision.cpp index f39f3f35ed3519f13056ab0e9653fe465384fc01..cd29d70e70e2143669de443b3a1df1029672f72b 100644 --- a/src/collision/Collision.cpp +++ b/src/collision/Collision.cpp @@ -151,8 +151,10 @@ CCollision::LoadCollisionScreen(eLevelName level) }; // Why twice? +#ifndef ONLINE // the load takes a moment here: a flash of picture only disorients the driver LoadingIslandScreen(levelNames[level]); LoadingIslandScreen(levelNames[level]); +#endif } // diff --git a/src/control/CarCtrl.cpp b/src/control/CarCtrl.cpp index 6742ccfeb5792cb18d80a7889c3a4746921318bf..ead11068eeda0a26db0d86c34aaeb2bf54c2e551 100644 --- a/src/control/CarCtrl.cpp +++ b/src/control/CarCtrl.cpp @@ -80,7 +80,11 @@ #define ONSCREEN_DESPAWN_RANGE (120.0f) #define MINIMAL_DISTANCE_TO_SPAWN_ONSCREEN (100.0f) #define REQUEST_ONSCREEN_DISTANCE ((ONSCREEN_DESPAWN_RANGE + MINIMAL_DISTANCE_TO_SPAWN_ONSCREEN) / 2) +#ifdef ONLINE +#define OFFSCREEN_DESPAWN_RANGE (75.0f) // busier streets: cars out of view live longer and start further out +#else #define OFFSCREEN_DESPAWN_RANGE (40.0f) +#endif #define EXTENDED_RANGE_DESPAWN_MULTIPLIER (1.5f) bool CCarCtrl::bMadDriversCheat; diff --git a/src/control/GameLogic.cpp b/src/control/GameLogic.cpp index 63c685d16f53d3e9aaa6445e1cc4e3be674c8f1c..712a8571ce7c6f58d1d07df49209d654235d19e4 100644 --- a/src/control/GameLogic.cpp +++ b/src/control/GameLogic.cpp @@ -47,6 +47,10 @@ CVector CGameLogic::ShortCutDropOffForMission; float CGameLogic::ShortCutDropOffOrientationForMission; bool CGameLogic::MissionDropOffReadyToBeUsed; +int CGameLogic::ms_deathFadeMs = 0x800; +int CGameLogic::ms_deathRespawnMs = 0x1000; +float CGameLogic::ms_deathFadeSeconds = 2.0f; + #define SHORTCUT_TAXI_COST (9) #define TOTAL_BUSTED_AUDIO (28) @@ -129,18 +133,18 @@ CGameLogic::Update() break; case WBSTATE_WASTED: #ifdef MISSION_REPLAY - if ((CTimer::GetTimeInMilliseconds() - pPlayerInfo.m_nWBTime > AddExtraDeathDelay() + 0x800) && (CTimer::GetPreviousTimeInMilliseconds() - pPlayerInfo.m_nWBTime <= AddExtraDeathDelay() + 0x800)) { + if ((CTimer::GetTimeInMilliseconds() - pPlayerInfo.m_nWBTime > AddExtraDeathDelay() + ms_deathFadeMs) && (CTimer::GetPreviousTimeInMilliseconds() - pPlayerInfo.m_nWBTime <= AddExtraDeathDelay() + ms_deathFadeMs)) { #else - if ((CTimer::GetTimeInMilliseconds() - pPlayerInfo.m_nWBTime > 0x800) && (CTimer::GetPreviousTimeInMilliseconds() - pPlayerInfo.m_nWBTime <= 0x800)) { + if ((CTimer::GetTimeInMilliseconds() - pPlayerInfo.m_nWBTime > ms_deathFadeMs) && (CTimer::GetPreviousTimeInMilliseconds() - pPlayerInfo.m_nWBTime <= ms_deathFadeMs)) { #endif - TheCamera.SetFadeColour(200, 200, 200); - TheCamera.Fade(2.0f, FADE_OUT); + TheCamera.SetFadeColour(0, 0, 0); + TheCamera.Fade(ms_deathFadeSeconds, FADE_OUT); } #ifdef MISSION_REPLAY - if (CTimer::GetTimeInMilliseconds() - pPlayerInfo.m_nWBTime >= AddExtraDeathDelay() + 0x1000) { + if (CTimer::GetTimeInMilliseconds() - pPlayerInfo.m_nWBTime >= AddExtraDeathDelay() + ms_deathRespawnMs) { #else - if (CTimer::GetTimeInMilliseconds() - pPlayerInfo.m_nWBTime >= 0x1000) { + if (CTimer::GetTimeInMilliseconds() - pPlayerInfo.m_nWBTime >= ms_deathRespawnMs) { #endif pPlayerInfo.m_WBState = WBSTATE_PLAYING; if (pPlayerInfo.m_bGetOutOfHospitalFree) { @@ -171,10 +175,19 @@ CGameLogic::Update() CRestart::FindClosestHospitalRestartPoint(pPlayerInfo.GetPos(), &vecRestartPos, &fRestartFloat); CRestart::OverrideHospitalLevel = LEVEL_GENERIC; CRestart::OverridePoliceStationLevel = LEVEL_GENERIC; +#ifdef ONLINE + // The clock does not jump, and models stay loaded: throwing them away is what made coming back slow. + RestorePlayerStuffDuringResurrection(pPlayerInfo.m_pPed, vecRestartPos, fRestartFloat); + CTimer::Stop(); + CStreaming::LoadSceneCollision(pPlayerInfo.GetPos()); + CStreaming::LoadScene(pPlayerInfo.GetPos()); + CTimer::Update(); +#else PassTime(720); RestorePlayerStuffDuringResurrection(pPlayerInfo.m_pPed, vecRestartPos, fRestartFloat); AfterDeathArrestSetUpShortCutTaxi(); SortOutStreamingAndMemory(pPlayerInfo.GetPos()); +#endif TheCamera.m_fCamShakeForce = 0.0f; TheCamera.SetMotionBlur(0, 0, 0, 0, MOTION_BLUR_NONE); CPad::GetPad(0)->StopShaking(0); @@ -183,8 +196,8 @@ CGameLogic::Update() CCarCtrl::CountDownToCarsAtStart = 10; CPad::GetPad(CWorld::PlayerInFocus)->DisablePlayerControls = PLAYERCONTROL_ENABLED; if (CRestart::bFadeInAfterNextDeath) { - TheCamera.SetFadeColour(200, 200, 200); - TheCamera.Fade(4.0f, FADE_IN); + TheCamera.SetFadeColour(0, 0, 0); + TheCamera.Fade(ms_deathFadeSeconds, FADE_IN); } else CRestart::bFadeInAfterNextDeath = true; } diff --git a/src/control/GameLogic.h b/src/control/GameLogic.h index 9b774cc790ef7c28e248011d1644ebd9e8a79ba0..26931a82a7a94570468ef88910e68d7ce7b60e48 100644 --- a/src/control/GameLogic.h +++ b/src/control/GameLogic.h @@ -5,6 +5,9 @@ class CAutomobile; class CGameLogic { public: + static int ms_deathFadeMs; + static int ms_deathRespawnMs; + static float ms_deathFadeSeconds; enum { SHORTCUT_NONE = 0, SHORTCUT_INIT, diff --git a/src/control/Restart.cpp b/src/control/Restart.cpp index af38537dc65e9b8a4a7ce63fbfdc01fd1c22a14b..8294bee91dbe3ab8a46973cf8c261a61be768961 100644 --- a/src/control/Restart.cpp +++ b/src/control/Restart.cpp @@ -1,6 +1,9 @@ #include "common.h" #include "Restart.h" +#ifdef ONLINE +#include "OnlineSpawn.h" +#endif #include "SaveBuf.h" #include "Zones.h" #include "PathFind.h" @@ -75,6 +78,10 @@ CRestart::CancelOverrideRestart() void CRestart::FindClosestHospitalRestartPoint(const CVector &pos, CVector *outPos, float *outHeading) { +#ifdef ONLINE + COnlineSpawn::Pick(outPos, outHeading); + return; +#endif if (bOverrideRestart) { *outPos = OverridePosition; *outHeading = OverrideHeading; @@ -122,6 +129,10 @@ CRestart::FindClosestHospitalRestartPoint(const CVector &pos, CVector *outPos, f void CRestart::FindClosestPoliceRestartPoint(const CVector &pos, CVector *outPos, float *outHeading) { +#ifdef ONLINE + COnlineSpawn::Pick(outPos, outHeading); + return; +#endif if (bOverrideRestart) { *outPos = OverridePosition; *outHeading = OverrideHeading; diff --git a/src/control/Script.cpp b/src/control/Script.cpp index a2dd8512080120407a7ed1c189bb0f0492ede990..0483ea04dc0e94d6e481df8b85f07055a9deb3ee 100644 --- a/src/control/Script.cpp +++ b/src/control/Script.cpp @@ -725,7 +725,11 @@ void CRunningScript::Init() } #ifdef USE_DEBUG_SCRIPT_LOADER +#ifdef ONLINE +int CTheScripts::ScriptToLoad = 1; // free roam, no story missions +#else int CTheScripts::ScriptToLoad = 0; +#endif int CTheScripts::OpenScript() { diff --git a/src/control/Script6.cpp b/src/control/Script6.cpp index 8af32f57179dad32e01c9b87cacf3883509755d9..d3c4f0062c30e4d4a04a3a095539ffb717059d4d 100644 --- a/src/control/Script6.cpp +++ b/src/control/Script6.cpp @@ -1735,6 +1735,9 @@ int8 CRunningScript::ProcessCommands1100To1199(int32 command) pos.z = CWorld::FindGroundZForCoord(pos.x, pos.y) + PICKUP_PLACEMENT_OFFSET; CPickups::GetActualPickupIndex(CollectNextParameterWithoutIncreasingPC(m_nIp)); ScriptParams[0] = CPickups::GenerateNewOne(pos, MI_PICKUP_REVENUE, PICKUP_ASSET_REVENUE, ScriptParams[3], ScriptParams[4]); +#ifdef ONLINE + CPickups::RemovePickUp(ScriptParams[0]); // no property game in free roam +#endif StoreParameters(&m_nIp, 1); return 0; } diff --git a/src/control/Script7.cpp b/src/control/Script7.cpp index 71099cc42edb6664dc3c6c960b51f33edc82a04c..7fc31fd35d1ea1aafaeb7f2076cea84d860c9223 100644 --- a/src/control/Script7.cpp +++ b/src/control/Script7.cpp @@ -769,6 +769,9 @@ int8 CRunningScript::ProcessCommands1300To1399(int32 command) // TheText.Get(key); CPickups::GetActualPickupIndex(CollectNextParameterWithoutIncreasingPC(m_nIp)); ScriptParams[0] = CPickups::GenerateNewOne(pos, MI_PICKUP_PROPERTY, PICKUP_PROPERTY_LOCKED, 0, 0, false, key); +#ifdef ONLINE + CPickups::RemovePickUp(ScriptParams[0]); // no property game in free roam +#endif StoreParameters(&m_nIp, 1); return 0; } @@ -784,6 +787,9 @@ int8 CRunningScript::ProcessCommands1300To1399(int32 command) // TheText.Get(key); CPickups::GetActualPickupIndex(CollectNextParameterWithoutIncreasingPC(m_nIp)); ScriptParams[0] = CPickups::GenerateNewOne(pos, MI_PICKUP_PROPERTY_FORSALE, PICKUP_PROPERTY_FORSALE, ScriptParams[3], 0, false, key); +#ifdef ONLINE + CPickups::RemovePickUp(ScriptParams[0]); // no property game in free roam +#endif StoreParameters(&m_nIp, 1); return 0; } diff --git a/src/core/Cam.cpp b/src/core/Cam.cpp index cd6e38f4796e18779594d97e2157818d9f5d7a2f..c2d735f27883df71c25cc53fd778cffbeafaae32 100644 --- a/src/core/Cam.cpp +++ b/src/core/Cam.cpp @@ -1,4 +1,7 @@ #include "common.h" +#ifdef ONLINE +#include "OnlineNet.h" +#endif #include "main.h" #include "Draw.h" @@ -1346,6 +1349,9 @@ void CCam::Process_FollowPedWithMouse(const CVector &CameraTarget, float TargetOrientation, float, float) { FOV = DefaultFOV; +#ifdef ONLINE + FOV = COnlineNet::AimFov(DefaultFOV); +#endif if(!CamTargetEntity->IsPed()) return; @@ -1431,6 +1437,9 @@ CCam::Process_FollowPedWithMouse(const CVector &CameraTarget, float TargetOrient CamDist = fBaseDist + Cos(Min(Alpha*fFalloff, HALFPI))*fAngleDist; else CamDist = fBaseDist + Cos(Alpha)*fAngleDist; +#ifdef ONLINE + CamDist *= COnlineNet::AimDistance(); +#endif if(TheCamera.m_bUseTransitionBeta) Beta = m_fTransitionBeta; diff --git a/src/core/Camera.cpp b/src/core/Camera.cpp index e7cd65a0814b72edcf70c5db3beb672dfe690c93..631d83390d6ee16133336d8556fcb876d45cdc41 100644 --- a/src/core/Camera.cpp +++ b/src/core/Camera.cpp @@ -33,6 +33,7 @@ #include "Debug.h" #include "GenericGameStorage.h" #include "Camera.h" +bool gHidePlayerForPhoto = false; // online: tools/thumbs.ts photographs vehicles enum { @@ -1752,7 +1753,7 @@ CCamera::CamControl(void) Cams[ActiveCam].Mode == CCam::MODE_FLYBY) FindPlayerPed()->bIsVisible = false; else - FindPlayerPed()->bIsVisible = true; + FindPlayerPed()->bIsVisible = !gHidePlayerForPhoto; bool switchedFromObbe = false; if(!canUseObbeCam && WhoIsInControlOfTheCamera == CAMCONTROL_OBBE){ diff --git a/src/core/CdStreamPosix.cpp b/src/core/CdStreamPosix.cpp index bc9129eb5ad70fad62804d385f5a405d305c8065..14cc372ef734915da4c6401c970c34ef94857ccf 100644 --- a/src/core/CdStreamPosix.cpp +++ b/src/core/CdStreamPosix.cpp @@ -1,4 +1,4 @@ -#ifndef _WIN32 +#if !defined _WIN32 && !defined __EMSCRIPTEN__ #include "common.h" #include "crossplatform.h" #include diff --git a/src/core/Directory.cpp b/src/core/Directory.cpp index 0534406599ab705ab20093b976be81e52f3abe73..463eaea178051b128e387dc48e4f2781e69e3c89 100644 --- a/src/core/Directory.cpp +++ b/src/core/Directory.cpp @@ -22,6 +22,8 @@ CDirectory::ReadDirFile(const char *filename) DirectoryInfo dirinfo; fd = CFileMgr::OpenFile(filename, "rb"); + if(fd == 0) + return; // not shipped (the web build leaves out cutscenes) while(CFileMgr::Read(fd, (char*)&dirinfo, sizeof(dirinfo))) AddItem(dirinfo); CFileMgr::CloseFile(fd); diff --git a/src/core/FileLoader.cpp b/src/core/FileLoader.cpp index dbf2cad955ac2c0343263377fbab22c944810b16..19c402b5567d08d55fd1a2b819b060465e449e85 100644 --- a/src/core/FileLoader.cpp +++ b/src/core/FileLoader.cpp @@ -491,7 +491,9 @@ bool CFileLoader::StartLoadClumpFile(RwStream *stream, uint32 id) { if(RwStreamFindChunk(stream, rwID_CLUMP, nil, nil)){ +#ifndef __EMSCRIPTEN__ printf("Start loading %s\n", CModelInfo::GetModelInfo(id)->GetModelName()); +#endif return RpClumpGtaStreamRead1(stream); }else{ printf("FAILED\n"); @@ -505,7 +507,9 @@ CFileLoader::FinishLoadClumpFile(RwStream *stream, uint32 id) RpClump *clump; CClumpModelInfo *mi; +#ifndef __EMSCRIPTEN__ printf("Finish loading %s\n", CModelInfo::GetModelInfo(id)->GetModelName()); +#endif clump = RpClumpGtaStreamRead2(stream); if(clump){ diff --git a/src/core/Frontend.cpp b/src/core/Frontend.cpp index 875bb76bb28447741abceda323174f2538db0197..e7360832fd8873415a9b46f2d8e9301ca86d3d3e 100644 --- a/src/core/Frontend.cpp +++ b/src/core/Frontend.cpp @@ -2,6 +2,18 @@ #define WITHWINDOWS #define WITHDINPUT #include "common.h" +#ifdef __EMSCRIPTEN__ +#include +// The language follows the browser until the player picks another one in the menu. +static int +BrowserLanguage(void) +{ + return EM_ASM_INT({ + const l = (navigator.language || "").slice(0, 2).toLowerCase(); + return l === "fr" ? 1 : l === "de" ? 2 : l === "it" ? 3 : l === "tr" ? 4 : 0; + }); +} +#endif #ifndef PS2_MENU #include "crossplatform.h" #include "platform.h" @@ -486,7 +498,7 @@ CMenuManager::CMenuManager() #endif m_PrefsVsync = 0; m_PrefsVsyncDisp = 1; - m_PrefsFrameLimiter = 1; + m_PrefsFrameLimiter = 0; m_PrefsLanguage = 0; field_54 = 0; m_PrefsAllowNastyGame = 1; @@ -3187,6 +3199,14 @@ CMenuManager::LoadSettings() m_lastWorking3DAudioProvider = m_nPrefsAudio3DProviderIndex; +#ifdef __EMSCRIPTEN__ + m_PrefsLanguage = EM_ASM_INT({ + try { const v = localStorage.getItem("vcLang"); if (v !== null) return +v; } catch (e) {} + return -1; + }); + if (m_PrefsLanguage < 0) + m_PrefsLanguage = BrowserLanguage(); +#endif if (m_PrefsLanguage == prevLang) m_bLanguageLoaded = false; else { @@ -3221,6 +3241,12 @@ CMenuManager::LoadSettings() void CMenuManager::SaveSettings() { +#ifdef __EMSCRIPTEN__ + if (m_PrefsLanguage != BrowserLanguage()) + EM_ASM({ try { localStorage.setItem("vcLang", String($0)); } catch (e) {} }, (int)m_PrefsLanguage); + else + EM_ASM({ try { localStorage.removeItem("vcLang"); } catch (e) {} }); +#endif #ifndef LOAD_INI_SETTINGS static char RubbishString[48] = "stuffmorestuffevenmorestuff etc"; #ifdef BIND_VEHICLE_FIREWEAPON @@ -5854,6 +5880,62 @@ CMenuManager::PrintMap(void) } CRadar::DrawBlips(); +#ifdef ONLINE + // The legend sits in the empty bars on both sides of the map, so the whole map stays visible. + // (On a 4:3 screen there is no room beside the map and the original centred box is used.) + float legendLeftEdge = m_fMapCenterX - m_fMapSize; + float legendRightEdge = m_fMapCenterX + m_fMapSize; + bool legendBesideMap = legendLeftEdge > SCREEN_SCALE_X(150.0f); + if (m_PrefsShowLegends && legendBesideMap) { + CFont::SetBackGroundOnlyTextOff(); + CFont::SetRightJustifyOff(); + CFont::SetCentreOff(); + CFont::SetJustifyOff(); + CFont::SetWrapx(SCREEN_WIDTH); + CFont::SetDropShadowPosition(0); + CFont::SetFontStyle(FONT_LOCALE(FONT_STANDARD)); + if (m_PrefsLanguage == LANGUAGE_AMERICAN) + CFont::SetScale(SCREEN_SCALE_X(0.5f), SCREEN_SCALE_Y(0.55f)); + else + CFont::SetScale(SCREEN_SCALE_X(0.42f), SCREEN_SCALE_Y(0.55f)); + + int total = CRadar::MapLegendCounter; + int firstColumn = (total + 1) / 2; + float pad = MENU_X(6.0f); + float rowH = MENU_Y(19.0f); + float top = MENU_Y(85.0f); + for (int column = 0; column < 2; column++) { + int from = column == 0 ? 0 : firstColumn; + int to = column == 0 ? firstColumn : total; + float left = column == 0 ? MENU_X(45.0f) : legendRightEdge + pad; + float right = column == 0 ? legendLeftEdge - pad : SCREEN_WIDTH - pad; + float bottom = top + (to - from + 2) * rowH; + CSprite2d::DrawRect(CRect(left, top, right, bottom), CRGBA(0, 0, 0, FadeIn(190))); + if (column == 0) { + CFont::SetFontStyle(FONT_LOCALE(FONT_HEADING)); + CFont::SetColor(CRGBA(LABEL_COLOR.r, LABEL_COLOR.g, LABEL_COLOR.b, FadeIn(255))); + CFont::SetScale(SCREEN_SCALE_X(0.5f), SCREEN_SCALE_Y(0.75f)); + CFont::PrintString(left + MENU_X(8.0f), top + MENU_Y(2.0f), TheText.Get("FE_MLG")); + CFont::SetFontStyle(FONT_LOCALE(FONT_STANDARD)); + if (m_PrefsLanguage == LANGUAGE_AMERICAN) + CFont::SetScale(SCREEN_SCALE_X(0.5f), SCREEN_SCALE_Y(0.55f)); + else + CFont::SetScale(SCREEN_SCALE_X(0.42f), SCREEN_SCALE_Y(0.55f)); + } + CFont::SetColor(CRGBA(225, 225, 225, FadeIn(255))); + CFont::SetWrapx(right - MENU_X(4.0f)); + // Icons are drawn at once, text is queued: empty the queue so both use their own render state. + CFont::DrawFonts(); + CSprite2d::InitPerFrame(); + RwRenderStateSet(rwRENDERSTATEVERTEXALPHAENABLE, (void*)TRUE); + float y = top + MENU_Y(24.0f); + for (int i = from; i < to; i++) { + CRadar::DrawLegend(left + MENU_X(8.0f), y, CRadar::MapLegendList[i]); + y += rowH; + } + } + } else +#endif if (m_PrefsShowLegends) { CFont::SetWrapx(MENU_X_RIGHT_ALIGNED(40.0f)); CFont::SetRightJustifyWrap(MENU_X_LEFT_ALIGNED(84.0f)); diff --git a/src/core/Game.cpp b/src/core/Game.cpp index 77c8965f7e3f112863d48784afe9e24f453391bd..271bb02ddc6f1fbd641a03da91aa8d51854b448e 100644 --- a/src/core/Game.cpp +++ b/src/core/Game.cpp @@ -95,6 +95,9 @@ #ifdef USE_TEXTURE_POOL #include "TexturePools.h" #endif +#ifdef ONLINE +#include "Online.h" +#endif eLevelName CGame::currLevel; int32 CGame::currArea; @@ -525,6 +528,9 @@ bool CGame::Initialise(const char* datFile) CSceneEdit::Initialise(); #endif +#ifdef ONLINE + COnline::Init(); +#endif LoadingScreen("Loading the Game", "Load scripts", nil); PUSH_MEMID(MEMID_SCRIPT); CTheScripts::Init(); @@ -693,6 +699,9 @@ void CGame::ReInitGameObjectVariables(void) gPhoneInfo.Initialise(); PUSH_MEMID(MEMID_SCRIPT); +#ifdef ONLINE + COnline::Reset(); +#endif CTheScripts::Init(); CGangs::Initialise(); POP_MEMID(); @@ -941,6 +950,9 @@ void CGame::Process(void) CSpecialFX::Update(); CRopes::Update(); CTimeCycle::Update(); +#ifdef ONLINE + COnline::Process(); +#endif if (CReplay::ShouldStandardCameraBeProcessed()) TheCamera.Process(); CCullZones::Update(); diff --git a/src/core/MenuScreensCustom.cpp b/src/core/MenuScreensCustom.cpp index ca3db5817800c40a0f60980f66f990226595b3a6..b2b08dd588c2a5b1e4c68347e8dfc4e818c2f9d6 100644 --- a/src/core/MenuScreensCustom.cpp +++ b/src/core/MenuScreensCustom.cpp @@ -410,12 +410,16 @@ CMenuScreenCustom aScreens[] = { { "FEH_AUD", MENUPAGE_OPTIONS, nil, nil, MENUACTION_MUSICVOLUME, "FEA_MUS", {nil, SAVESLOT_NONE, MENUPAGE_SOUND_SETTINGS}, 40, 76, MENUALIGN_LEFT, MENUACTION_SFXVOLUME, "FEA_SFX", {nil, SAVESLOT_NONE, MENUPAGE_SOUND_SETTINGS}, 0, 0, MENUALIGN_LEFT, +#ifndef ONLINE // nothing to set in a browser MENUACTION_MP3VOLUMEBOOST, "FEA_MPB", {nil, SAVESLOT_NONE, MENUPAGE_SOUND_SETTINGS}, 0, 0, MENUALIGN_LEFT, +#endif #ifdef EXTERNAL_3D_SOUND MENUACTION_AUDIOHW, "FEA_3DH", {nil, SAVESLOT_NONE, MENUPAGE_SOUND_SETTINGS}, 0, 0, MENUALIGN_LEFT, MENUACTION_SPEAKERCONF, "FEA_SPK", {nil, SAVESLOT_NONE, MENUPAGE_SOUND_SETTINGS}, 0, 0, MENUALIGN_LEFT, #endif +#ifndef ONLINE // nothing to set in a browser MENUACTION_DYNAMICACOUSTIC, "FET_DAM", {nil, SAVESLOT_NONE, MENUPAGE_SOUND_SETTINGS}, 0, 0, MENUALIGN_LEFT, +#endif MENUACTION_RADIO, "FEA_RSS", {nil, SAVESLOT_NONE, MENUPAGE_SOUND_SETTINGS}, 0, 0, MENUALIGN_LEFT, #ifdef EXTERNAL_3D_SOUND MENUACTION_RESTOREDEF, "FET_DEF", {nil, SAVESLOT_NONE, MENUPAGE_SOUND_SETTINGS}, 320, 367, MENUALIGN_CENTER, @@ -460,12 +464,18 @@ CMenuScreenCustom aScreens[] = { MENUACTION_BRIGHTNESS, "FED_BRI", { nil, SAVESLOT_NONE, MENUPAGE_DISPLAY_SETTINGS }, 0, 0, MENUALIGN_LEFT, MENUACTION_DRAWDIST, "FEM_LOD", { nil, SAVESLOT_NONE, MENUPAGE_DISPLAY_SETTINGS }, 0, 0, MENUALIGN_LEFT, DENSITY_SLIDERS +#ifndef ONLINE // nothing to set in a browser CUTSCENE_BORDERS_TOGGLE +#endif +#ifndef ONLINE // nothing to set in a browser FREE_CAM_TOGGLE +#endif MENUACTION_LEGENDS, "MAP_LEG", { nil, SAVESLOT_NONE, MENUPAGE_DISPLAY_SETTINGS }, 0, 0, MENUALIGN_LEFT, MENUACTION_RADARMODE, "FED_RDR", { nil, SAVESLOT_NONE, MENUPAGE_DISPLAY_SETTINGS }, 0, 0, MENUALIGN_LEFT, MENUACTION_HUD, "FED_HUD", { nil, SAVESLOT_NONE, MENUPAGE_DISPLAY_SETTINGS }, 0, 0, MENUALIGN_LEFT, +#ifndef ONLINE // nothing to set in a browser MENUACTION_SUBTITLES, "FED_SUB", { nil, SAVESLOT_NONE, MENUPAGE_DISPLAY_SETTINGS }, 0, 0, MENUALIGN_LEFT, +#endif MENUACTION_CFO_DYNAMIC, "FET_DEF", { new CCFODynamic(nil, nil, nil, nil, RestoreDefDisplay) }, 320, 0, MENUALIGN_CENTER, MENUACTION_GOBACK, "FEDS_TB", { nil, SAVESLOT_NONE, MENUPAGE_NONE}, 320, 0, MENUALIGN_CENTER, }, @@ -629,7 +639,9 @@ CMenuScreenCustom aScreens[] = { MENUACTION_CHANGEMENU, "FET_AGS", {nil, SAVESLOT_NONE, MENUPAGE_CONTROLLER_SETTINGS}, 0, 0, MENUALIGN_CENTER, #endif #ifdef DETECT_JOYSTICK_MENU +#ifndef ONLINE // nothing to set in a browser MENUACTION_CHANGEMENU, "FEC_JOD", {nil, SAVESLOT_NONE, MENUPAGE_DETECT_JOYSTICK}, 0, 0, MENUALIGN_CENTER, +#endif #endif MENUACTION_CHANGEMENU, "FEC_MOU", {nil, SAVESLOT_NONE, MENUPAGE_MOUSE_CONTROLS}, 0, 0, MENUALIGN_CENTER, MENUACTION_RESTOREDEF, "FET_DEF", {nil, SAVESLOT_NONE, MENUPAGE_CONTROLLER_PC}, 320, 0, MENUALIGN_CENTER, @@ -649,7 +661,9 @@ CMenuScreenCustom aScreens[] = { MENUACTION_CHANGEMENU, "FET_GFX", {nil, SAVESLOT_NONE, MENUPAGE_GRAPHICS_SETTINGS}, 0, 0, MENUALIGN_CENTER, #endif MENUACTION_CHANGEMENU, "FEO_LAN", {nil, SAVESLOT_NONE, MENUPAGE_LANGUAGE_SETTINGS}, 0, 0, MENUALIGN_CENTER, +#ifndef ONLINE // nothing to set in a browser MENUACTION_PLAYERSETUP, "FET_PS", {nil, SAVESLOT_NONE, MENUPAGE_SKIN_SELECT}, 0, 0, MENUALIGN_CENTER, +#endif MENUACTION_GOBACK, "FEDS_TB", {nil, SAVESLOT_NONE, 0}, 0, 0, MENUALIGN_CENTER, }, @@ -676,7 +690,9 @@ CMenuScreenCustom aScreens[] = { MENUACTION_MOUSESENS, "FEC_MSH", {nil, SAVESLOT_NONE, MENUPAGE_MOUSE_CONTROLS}, 40, 170, MENUALIGN_LEFT, MENUACTION_INVVERT, "FEC_IVV", {nil, SAVESLOT_NONE, MENUPAGE_MOUSE_CONTROLS}, 0, 0, MENUALIGN_LEFT, #ifndef GAMEPAD_MENU +#ifndef ONLINE // nothing to set in a browser INVERT_PAD_SELECTOR +#endif #endif MENUACTION_MOUSESTEER, "FET_MST", {nil, SAVESLOT_NONE, MENUPAGE_MOUSE_CONTROLS}, 0, 0, MENUALIGN_LEFT, MENUACTION_GOBACK, "FEDS_TB", {nil, SAVESLOT_NONE, 0}, 320, 0, MENUALIGN_CENTER, @@ -686,12 +702,20 @@ CMenuScreenCustom aScreens[] = { // MENUPAGE_PAUSE_MENU = 32 { "FET_PAU", MENUPAGE_DISABLED, nil, nil, MENUACTION_RESUME, "FEP_RES", {nil, SAVESLOT_NONE, 0}, 320, 120, MENUALIGN_CENTER, +#ifndef ONLINE // no story pages in the online pause menu MENUACTION_CHANGEMENU, "FEH_SGA", {nil, SAVESLOT_NONE, MENUPAGE_NEW_GAME}, 0, 0, MENUALIGN_CENTER, +#endif MENUACTION_CHANGEMENU, "FEH_MAP", {nil, SAVESLOT_NONE, MENUPAGE_MAP}, 0, 0, MENUALIGN_CENTER, +#ifndef ONLINE // no story pages in the online pause menu MENUACTION_CHANGEMENU, "FEP_STA", {nil, SAVESLOT_NONE, MENUPAGE_STATS}, 0, 0, MENUALIGN_CENTER, +#endif +#ifndef ONLINE // no story pages in the online pause menu MENUACTION_CHANGEMENU, "FEH_BRI", {nil, SAVESLOT_NONE, MENUPAGE_BRIEFS}, 0, 0, MENUALIGN_CENTER, +#endif MENUACTION_CHANGEMENU, "FET_OPT", {nil, SAVESLOT_NONE, MENUPAGE_OPTIONS}, 0, 0, MENUALIGN_CENTER, +#ifndef ONLINE // a browser tab has nothing to quit to MENUACTION_CHANGEMENU, "FEP_QUI", {nil, SAVESLOT_NONE, MENUPAGE_EXIT}, 0, 0, MENUALIGN_CENTER, +#endif }, // MENUPAGE_NONE = 33 @@ -769,24 +793,42 @@ CMenuScreenCustom aScreens[] = { { "FET_GFX", MENUPAGE_OPTIONS, new CCustomScreenLayout({40, 78, 25, true, true}), GraphicsGoBack, #ifndef GTA_HANDHELD +#ifndef ONLINE // nothing to set in a browser MENUACTION_SCREENRES, "FED_RES", { nil, SAVESLOT_NONE, MENUPAGE_GRAPHICS_SETTINGS }, 0, 0, MENUALIGN_LEFT, #endif +#endif +#ifndef ONLINE // nothing to set in a browser MENUACTION_WIDESCREEN, "FED_WIS", { nil, SAVESLOT_NONE, MENUPAGE_GRAPHICS_SETTINGS }, 0, 0, MENUALIGN_LEFT, +#endif +#ifndef ONLINE // nothing to set in a browser VIDEOMODE_SELECTOR +#endif #ifdef LEGACY_MENU_OPTIONS +#ifndef ONLINE // nothing to set in a browser MENUACTION_FRAMESYNC, "FEM_VSC", {nil, SAVESLOT_NONE, MENUPAGE_GRAPHICS_SETTINGS}, 0, 0, MENUALIGN_LEFT, #endif +#endif +#ifndef ONLINE // nothing to set in a browser MENUACTION_FRAMELIMIT, "FEM_FRM", { nil, SAVESLOT_NONE, MENUPAGE_GRAPHICS_SETTINGS }, 0, 0, MENUALIGN_LEFT, +#endif +#ifndef ONLINE // nothing to set in a browser MULTISAMPLING_SELECTOR +#endif +#ifndef ONLINE // nothing to set in a browser ISLAND_LOADING_SELECTOR +#endif +#ifndef ONLINE // nothing to set in a browser DUALPASS_SELECTOR +#endif #ifdef EXTENDED_COLOURFILTER POSTFX_SELECTORS #elif defined LEGACY_MENU_OPTIONS MENUACTION_TRAILS, "FED_TRA", { nil, SAVESLOT_NONE, MENUPAGE_GRAPHICS_SETTINGS }, 0, 0, MENUALIGN_LEFT, #endif // re3.cpp inserts here pipeline selectors if neo/neo.txd exists and EXTENDED_PIPELINES defined +#ifndef ONLINE // nothing to set in a browser MENUACTION_CFO_DYNAMIC, "FET_DEF", { new CCFODynamic(nil, nil, nil, nil, RestoreDefGraphics) }, 320, 0, MENUALIGN_CENTER, +#endif MENUACTION_GOBACK, "FEDS_TB", {nil, SAVESLOT_NONE, MENUPAGE_NONE}, 320, 0, MENUALIGN_CENTER, }, #endif diff --git a/src/core/Pad.cpp b/src/core/Pad.cpp index e75510e5423cf0a32e22f18a67022dec3c521f06..59b890a6e3b807a6ac5010a44ac0f5e5d0d1c547 100644 --- a/src/core/Pad.cpp +++ b/src/core/Pad.cpp @@ -1,5 +1,8 @@ #define WITHDINPUT #include "common.h" +#ifdef __EMSCRIPTEN__ +#include +#endif #include "crossplatform.h" #include "platform.h" #ifdef XINPUT @@ -866,6 +869,9 @@ CMouseControllerState CMousePointerStateHelper::GetMouseSetUp() // It seems there is no way to get number of buttons on mouse, so assign all buttons if we have mouse. double xpos = 1.0f, ypos; glfwGetCursorPos(PSGLOBAL(window), &xpos, &ypos); +#ifdef __EMSCRIPTEN__ + xpos = 1.0f; // a page has no cursor position until the mouse moves, which would leave every mouse button unbound +#endif if (xpos != 0.f) { state.MMB = true; @@ -921,13 +927,20 @@ void CPad::UpdateMouse() NewMouseControllerState = PCTempMouseControllerState; } } +#else +#ifdef __EMSCRIPTEN__ + // A captured mouse is ours whatever the stale focus and enter/leave flags say. + if ( (IsForegroundApp() && PSGLOBAL(cursorIsInWindow)) || EM_ASM_INT({ return document.pointerLockElement ? 1 : 0; }) ) #else if ( IsForegroundApp() && PSGLOBAL(cursorIsInWindow) ) +#endif { double xpos = 1.0f, ypos; glfwGetCursorPos(PSGLOBAL(window), &xpos, &ypos); +#ifndef __EMSCRIPTEN__ // a captured mouse sits at 0 until it moves, and its buttons must work there too if (xpos == 0.f) return; +#endif int32 signX = 1; int32 signy = 1; @@ -942,8 +955,27 @@ void CPad::UpdateMouse() PCTempMouseControllerState.Clear(); - PCTempMouseControllerState.x = (float)(signX * (xpos - PSGLOBAL(lastMousePos.x))); - PCTempMouseControllerState.y = (float)(signy * (ypos - PSGLOBAL(lastMousePos.y))); + float dx = (float)(xpos - PSGLOBAL(lastMousePos.x)); + float dy = (float)(ypos - PSGLOBAL(lastMousePos.y)); +#ifdef __EMSCRIPTEN__ + // The browser cannot move the cursor back to the centre, so the first reading after the + // menu or after the pointer lock starts is a jump from wherever the old position was. + if (Abs(dx) > 150.0f || Abs(dy) > 150.0f) + dx = dy = 0.0f; + // The look area of the touch controls. + if (!FrontEndMenuManager.m_bMenuActive && EM_ASM_INT({ return Module.vcTouch ? 1 : 0; })) + dx = dy = 0.0f; + // While the mouse is not captured it belongs to the page: no look, no buttons, no wheel. + bool mouseFree = !FrontEndMenuManager.m_bMenuActive && EM_ASM_INT({ return !Module.vcTouch && !document.pointerLockElement ? 1 : 0; }); + if (mouseFree) dx = dy = 0.0f; + // The first readings after the pointer lock returns are not real movement. + if (!FrontEndMenuManager.m_bMenuActive && EM_ASM_INT({ return performance.now() < (Module.vcLookHold || 0) ? 1 : 0; })) + dx = dy = 0.0f; + dx += (float)EM_ASM_DOUBLE({ const v = Module.vcLookX || 0; Module.vcLookX = 0; return v; }); + dy += (float)EM_ASM_DOUBLE({ const v = Module.vcLookY || 0; Module.vcLookY = 0; return v; }); +#endif + PCTempMouseControllerState.x = signX * dx; + PCTempMouseControllerState.y = signy * dy; PCTempMouseControllerState.LMB = glfwGetMouseButton(PSGLOBAL(window), GLFW_MOUSE_BUTTON_LEFT); PCTempMouseControllerState.RMB = glfwGetMouseButton(PSGLOBAL(window), GLFW_MOUSE_BUTTON_RIGHT); PCTempMouseControllerState.MMB = glfwGetMouseButton(PSGLOBAL(window), GLFW_MOUSE_BUTTON_MIDDLE); @@ -954,6 +986,14 @@ void CPad::UpdateMouse() PCTempMouseControllerState.WHEELUP = 1; else if (PSGLOBAL(mouseWheel) < 0) PCTempMouseControllerState.WHEELDN = 1; +#ifdef __EMSCRIPTEN__ + if (mouseFree) { + float lx = PCTempMouseControllerState.x, ly = PCTempMouseControllerState.y; + PCTempMouseControllerState.Clear(); + PCTempMouseControllerState.x = lx; + PCTempMouseControllerState.y = ly; + } +#endif PSGLOBAL(lastMousePos.x) = xpos; PSGLOBAL(lastMousePos.y) = ypos; @@ -962,6 +1002,14 @@ void CPad::UpdateMouse() OldMouseControllerState = NewMouseControllerState; NewMouseControllerState = PCTempMouseControllerState; } +#ifdef __EMSCRIPTEN__ + else + { + // The cursor is over a page menu: the last movement must not repeat every frame. + OldMouseControllerState = NewMouseControllerState; + NewMouseControllerState.Clear(); + } +#endif #endif } @@ -1102,6 +1150,32 @@ void CPad::StartShake_Train(float fX, float fY) } #ifdef GTA_PS2_STUFF +#ifdef ONLINE +#define ArmourCheat(...) ((void)0) +#define BlowUpCarsCheat(...) ((void)0) +#define ChangePlayerCheat(...) ((void)0) +#define ChittyChittyBangBangCheat(...) ((void)0) +#define CloudyWeatherCheat(...) ((void)0) +#define EverybodyAttacksPlayerCheat(...) ((void)0) +#define ExtraSunnyWeatherCheat(...) ((void)0) +#define FastTimeCheat(...) ((void)0) +#define FastWeatherCheat(...) ((void)0) +#define FoggyWeatherCheat(...) ((void)0) +#define HealthCheat(...) ((void)0) +#define MayhemCheat(...) ((void)0) +#define MoneyCheat(...) ((void)0) +#define RainyWeatherCheat(...) ((void)0) +#define SlowTimeCheat(...) ((void)0) +#define StrongGripCheat(...) ((void)0) +#define SunnyWeatherCheat(...) ((void)0) +#define VehicleCheat(...) ((void)0) +#define WantedLevelDownCheat(...) ((void)0) +#define WantedLevelUpCheat(...) ((void)0) +#define WeaponCheat1(...) ((void)0) +#define WeaponCheat2(...) ((void)0) +#define WeaponCheat3(...) ((void)0) +#define WeaponsForAllCheat(...) ((void)0) +#endif void CPad::AddToCheatString(char c) { for ( int32 i = ARRAY_SIZE(CheatString) - 2; i >= 0; i-- ) @@ -1200,6 +1274,32 @@ void CPad::AddToCheatString(char c) #undef _CHEATCMP } +#ifdef ONLINE +#undef ArmourCheat +#undef BlowUpCarsCheat +#undef ChangePlayerCheat +#undef ChittyChittyBangBangCheat +#undef CloudyWeatherCheat +#undef EverybodyAttacksPlayerCheat +#undef ExtraSunnyWeatherCheat +#undef FastTimeCheat +#undef FastWeatherCheat +#undef FoggyWeatherCheat +#undef HealthCheat +#undef MayhemCheat +#undef MoneyCheat +#undef RainyWeatherCheat +#undef SlowTimeCheat +#undef StrongGripCheat +#undef SunnyWeatherCheat +#undef VehicleCheat +#undef WantedLevelDownCheat +#undef WantedLevelUpCheat +#undef WeaponCheat1 +#undef WeaponCheat2 +#undef WeaponCheat3 +#undef WeaponsForAllCheat +#endif #endif int Cheat_strncmp(char* sourceStr, char* origCheatStr) @@ -2839,6 +2939,9 @@ bool CPad::CycleCameraModeDownJustDown(void) bool CPad::ChangeStationJustDown(void) { +#ifdef ONLINE + return false; +#endif if ( ArePlayerControlsDisabled() ) return false; diff --git a/src/core/PlayerInfo.cpp b/src/core/PlayerInfo.cpp index 36d05b822bae852c05dabdedf228866f48b9ac3f..d6596be10fb871fcd22e547216fc9526198486e8 100644 --- a/src/core/PlayerInfo.cpp +++ b/src/core/PlayerInfo.cpp @@ -765,7 +765,9 @@ CPlayerInfo::KillPlayer() m_WBState = WBSTATE_WASTED; m_nWBTime = CTimer::GetTimeInMilliseconds(); CDarkel::ResetOnPlayerDeath(); +#ifndef ONLINE // the page shows who did it CMessages::AddBigMessage(TheText.Get("DEAD"), 4000, 2); +#endif CStats::TimesDied++; } diff --git a/src/core/Radar.cpp b/src/core/Radar.cpp index 4e15559d6694f6a4888b6bf1392be5bb9959ce0e..ce2b3f0afaa2f05b6a7f6e1d089b344f7156f6ee 100644 --- a/src/core/Radar.cpp +++ b/src/core/Radar.cpp @@ -6,6 +6,11 @@ #include "RwHelper.h" #include "Radar.h" + +float gRadarScale = 1.0f; +#if defined(ONLINE) && defined(__EMSCRIPTEN__) +#include +#endif #include "Camera.h" #include "Hud.h" #include "World.h" @@ -726,6 +731,9 @@ void CRadar::DrawRadarMap() void CRadar::DrawRadarMask() { +#ifdef ONLINE + return; // square minimap: the map sections are already clipped to the square +#endif CVector2D corners[4] = { CVector2D(1.0f, -1.0f), CVector2D(1.0f, 1.0f), @@ -972,6 +980,14 @@ float CRadar::LimitRadarPoint(CVector2D &point) if (FrontEndMenuManager.m_bMenuMapActive) return dist; +#ifdef ONLINE + float edge = Max(Abs(point.x), Abs(point.y)); + if (edge > 1.0f) { + point.x /= edge; + point.y /= edge; + } + return edge > 1.0f ? edge : Min(dist, 1.0f); +#endif if (dist > 1.0f) { invdist = 1.0f / dist; point.x *= invdist; @@ -1513,6 +1529,10 @@ CRadar::ToggleTargetMarker(float x, float y) ms_RadarTrace[nextBlip].m_eBlipDisplay = BLIP_DISPLAY_BLIP_ONLY; ms_RadarTrace[nextBlip].m_eRadarSprite = RADAR_SPRITE_WAYPOINT; TargetMarkerId = CRadar::GetNewUniqueBlipIndex(nextBlip); +#if defined(ONLINE) && defined(__EMSCRIPTEN__) + // The page shows the marker's world position and tells the server (used to choose spawn areas). + EM_ASM({ if(Module.vcMarker) Module.vcMarker($0, $1); }, x, y); +#endif } else { ClearBlip(TargetMarkerId); TargetMarkerId = -1; diff --git a/src/core/Radar.h b/src/core/Radar.h index afb37fe40eda64e435ef7b577d3a71aa7e918462..d054c714d66063f40a9252ee593479772d262690 100644 --- a/src/core/Radar.h +++ b/src/core/Radar.h @@ -167,8 +167,9 @@ struct sRadarTraceSave #define RADAR_WIDTH (82.0f) #define RADAR_HEIGHT (82.0f) */ -#define RADAR_WIDTH ((CDraw::ms_bFixRadar) ? (82.0f) : (94.0f)) -#define RADAR_HEIGHT ((CDraw::ms_bFixRadar) ? (82.0f) : (76.0f)) +extern float gRadarScale; // online: from net.json +#define RADAR_WIDTH (gRadarScale * ((CDraw::ms_bFixRadar) ? (82.0f) : (94.0f))) +#define RADAR_HEIGHT (gRadarScale * ((CDraw::ms_bFixRadar) ? (82.0f) : (76.0f))) #else /* broken since forever, someone tried to fix size for 640x512(PAL) @@ -179,8 +180,9 @@ struct sRadarTraceSave int y = 82 * (640.0/512.0)/(640.0/480.0); int x = y * (640.0/512.0); */ -#define RADAR_WIDTH (94.0f) -#define RADAR_HEIGHT (76.0f) +extern float gRadarScale; // online: from net.json +#define RADAR_WIDTH (gRadarScale * 94.0f) +#define RADAR_HEIGHT (gRadarScale * 76.0f) #endif class CRadar diff --git a/src/core/Streaming.cpp b/src/core/Streaming.cpp index 6d980e1804ab185250fd408bbc95766fa54ccfaf..7a73b7aee88e4e8905013edf4575b73162ab39a0 100644 --- a/src/core/Streaming.cpp +++ b/src/core/Streaming.cpp @@ -1,4 +1,7 @@ #include "common.h" +#ifdef __EMSCRIPTEN__ +#include +#endif #include "General.h" #include "Pad.h" @@ -237,6 +240,15 @@ CStreaming::Init2(void) desiredNumVehiclesLoaded = 25; debug("Memory allocated to Streaming is %zuMB", ms_memoryAvailable/MB); // original modifier was %d #endif +#ifdef __EMSCRIPTEN__ + // A browser has room: models stay loaded instead of being thrown away and fetched again, which + // is what stalls frames. Phones keep less, so the tab is not killed for its memory. + { + bool phone = EM_ASM_INT({ return matchMedia("(pointer: coarse)").matches ? 1 : 0; }); + ms_memoryAvailable = (phone ? 110 : 256) * MB; + desiredNumVehiclesLoaded = phone ? 30 : MAXVEHICLESLOADED; + } +#endif #undef MB #endif @@ -1803,11 +1815,15 @@ CStreaming::StreamZoneModels(const CVector &pos) int newMI = CPopulation::ms_pPedGroups[ms_currentPedGrp].models[j]; if(newMI != oldMI){ RequestModel(newMI, STREAMFLAGS_DEPENDENCY); +#ifndef __EMSCRIPTEN__ debug("Request Ped %s\n", CModelInfo::GetModelInfo(newMI)->GetModelName()); +#endif if(ms_numPedsLoaded == MAXZONEPEDSLOADED){ SetModelIsDeletable(oldMI); SetModelTxdIsDeletable(oldMI); +#ifndef __EMSCRIPTEN__ debug("Remove Ped %s\n", CModelInfo::GetModelInfo(oldMI)->GetModelName()); +#endif }else ms_numPedsLoaded++; timeBeforeNextLoad = 300; diff --git a/src/core/SurfaceTable.cpp b/src/core/SurfaceTable.cpp index c4b184bfa40a7a975016a285352a3b9400be8dff..b3b7190e68debc9438ef0fff83802fa7811ed1db 100644 --- a/src/core/SurfaceTable.cpp +++ b/src/core/SurfaceTable.cpp @@ -7,6 +7,9 @@ #include "SurfaceTable.h" float CSurfaceTable::ms_aAdhesiveLimitTable[NUMADHESIVEGROUPS][NUMADHESIVEGROUPS]; +float CSurfaceTable::ms_sandGripScale = 1.0f; +float CSurfaceTable::ms_sandDragScale = 1.0f; +float CSurfaceTable::ms_bikeGripScale = 1.0f; void CSurfaceTable::Initialise(Const char *filename) @@ -146,7 +149,12 @@ CSurfaceTable::GetWetMultiplier(uint8 surfaceType) float CSurfaceTable::GetAdhesiveLimit(CColPoint &colpoint) { - return ms_aAdhesiveLimitTable[GetAdhesionGroup(colpoint.surfaceB)][GetAdhesionGroup(colpoint.surfaceA)]; + int groupB = GetAdhesionGroup(colpoint.surfaceB); + int groupA = GetAdhesionGroup(colpoint.surfaceA); + float limit = ms_aAdhesiveLimitTable[groupB][groupA]; + if(groupA == ADHESIVE_SAND || groupB == ADHESIVE_SAND) + limit *= ms_sandGripScale; + return limit; } bool diff --git a/src/core/SurfaceTable.h b/src/core/SurfaceTable.h index 8ff43106e86dd4b04957a8cc42517b9d41439e27..f96f6f8301afb46611bab2abfda8e56208abd272 100644 --- a/src/core/SurfaceTable.h +++ b/src/core/SurfaceTable.h @@ -93,6 +93,9 @@ class CSurfaceTable { static float ms_aAdhesiveLimitTable[NUMADHESIVEGROUPS][NUMADHESIVEGROUPS]; public: + static float ms_sandGripScale; + static float ms_sandDragScale; + static float ms_bikeGripScale; static void Initialise(Const char *filename); static int GetAdhesionGroup(uint8 surfaceType); static float GetWetMultiplier(uint8 surfaceType); diff --git a/src/core/World.cpp b/src/core/World.cpp index 549c2cc063bf627fb92f89bc4e86dcdd91fb898d..9ce08e4687a6a4a1508a7ffb5e50456007901efd 100644 --- a/src/core/World.cpp +++ b/src/core/World.cpp @@ -37,7 +37,16 @@ uint8 CWorld::PlayerInFocus; CPlayerInfo CWorld::Players[NUMPLAYERS]; bool CWorld::bNoMoreCollisionTorque; CEntity *CWorld::pIgnoreEntity; +#ifdef ONLINE +#include "OnlineNet.h" +#define REMOTE_TARGET(e) (CWorld::bIncludeRemotePlayers && (e)->IsPed() && COnlineNet::IsRemotePlayer(e)) +#else +#define REMOTE_TARGET(e) false +#endif bool CWorld::bIncludeDeadPeds; +#ifdef ONLINE +bool CWorld::bIncludeRemotePlayers; +#endif bool CWorld::bSecondShift; bool CWorld::bForceProcessControl; bool CWorld::bProcessCutsceneOnly; @@ -352,14 +361,14 @@ CWorld::ProcessLineOfSightSectorList(CPtrList &list, const CColLine &line, CColP for(node = list.first; node; node = node->next) { e = (CEntity *)node->item; - if(e->m_scanCode != GetCurrentScanCode() && e != pIgnoreEntity && (e->bUsesCollision || deadPeds || bikers) && + if(e->m_scanCode != GetCurrentScanCode() && e != pIgnoreEntity && (e->bUsesCollision || deadPeds || bikers || REMOTE_TARGET(e)) && !(ignoreSomeObjects && CameraToIgnoreThisObject(e))) { colmodel = nil; tyreDist = mindist; e->m_scanCode = GetCurrentScanCode(); if(e->IsPed()) { - if(e->bUsesCollision || deadPeds && ((CPed *)e)->m_nPedState == PED_DEAD || bikers && ((CPed*)e)->InVehicle() && (((CPed*)e)->m_pMyVehicle->IsBike() || ((CPed*)e)->m_pMyVehicle->IsBoat())) { + if(e->bUsesCollision || REMOTE_TARGET(e) || deadPeds && ((CPed *)e)->m_nPedState == PED_DEAD || bikers && ((CPed*)e)->InVehicle() && (((CPed*)e)->m_pMyVehicle->IsBike() || ((CPed*)e)->m_pMyVehicle->IsBoat())) { colmodel = ((CPedModelInfo *)CModelInfo::GetModelInfo(e->GetModelIndex()))->AnimatePedColModelSkinned(e->GetClump()); } else colmodel = nil; diff --git a/src/core/World.h b/src/core/World.h index 81eb5d4c059f4326756259d19674e874fbec1b46..93d0035e6941d12f7b21a0592849f43319a1346b 100644 --- a/src/core/World.h +++ b/src/core/World.h @@ -61,6 +61,9 @@ public: static CPlayerInfo Players[NUMPLAYERS]; static CEntity *pIgnoreEntity; static bool bIncludeDeadPeds; +#ifdef ONLINE + static bool bIncludeRemotePlayers; +#endif static bool bNoMoreCollisionTorque; static bool bSecondShift; static bool bForceProcessControl; diff --git a/src/core/config.h b/src/core/config.h index 8943223b14de24d90e71bc7e4f941b4f90f0ad4d..0b1c8262b5566ea2343f08d682f6cc509b325afb 100644 --- a/src/core/config.h +++ b/src/core/config.h @@ -277,6 +277,7 @@ enum Config { # define TIMEBARS // print debug timers #endif +#define ONLINE // browser multiplayer free roam on the beach (src/online), no story #define FIX_BUGS // fixes bugs that we've came across during reversing. You can undefine this only on release builds. #define MORE_LANGUAGES // Add more translations to the game #define COMPATIBLE_SAVES // this allows changing structs while keeping saves compatible, and keeps saves compatible between platforms @@ -450,7 +451,9 @@ static_assert(false, "SUPPORT_XBOX_SCRIPT and SUPPORT_MOBILE_SCRIPT are mutually #define PAUSE_RADIO_IN_FRONTEND // pause radio when game is paused #define ATTACH_RELEASING_SOUNDS_TO_ENTITIES // sounds would follow ped and vehicles coordinates if not being queued otherwise #define USE_TIME_SCALE_FOR_AUDIO // slow down/speed up sounds according to the speed of the game +#ifndef __EMSCRIPTEN__ // the browser build has no threads #define MULTITHREADED_AUDIO // for streams. requires C++11 or later +#endif #ifdef AUDIO_OPUS #define AUDIO_OAL_USE_OPUS // enable support of opus files diff --git a/src/core/main.cpp b/src/core/main.cpp index e84c6eebf0d209f6ec43bd1338dad43393ed705b..d3c2fecc0d5ebd29966e589c11c579f64cf37665 100644 --- a/src/core/main.cpp +++ b/src/core/main.cpp @@ -56,6 +56,7 @@ #include "FileMgr.h" #include "Text.h" #include "RpAnimBlend.h" +#include "../online/OnlineNet.h" #include "Frontend.h" #include "AnimViewer.h" #include "Script.h" @@ -634,6 +635,18 @@ GetLevelSplashScreen(int level) return splashScreens[level]; } +// The splash pictures are 4:3. On a wider screen they keep their shape and sit in the middle, +// with black on both sides, instead of being stretched. +static CRect +SplashRect(void) +{ + float w = SCREEN_HEIGHT * (4.0f / 3.0f); + if(w >= SCREEN_WIDTH) + return CRect(0.0f, 0.0f, SCREEN_WIDTH, SCREEN_HEIGHT); + float left = (SCREEN_WIDTH - w) / 2.0f; + return CRect(left, 0.0f, left + w, SCREEN_HEIGHT); +} + void ResetLoadingScreenBar() { @@ -667,7 +680,7 @@ LoadingScreen(const char *str1, const char *str2, const char *splashscreen) CFont::InitPerFrame(); DefinedState(); RwRenderStateSet(rwRENDERSTATETEXTUREADDRESS, (void*)rwTEXTUREADDRESSCLAMP); - splash->Draw(CRect(0.0f, 0.0f, SCREEN_WIDTH, SCREEN_HEIGHT), CRGBA(255, 255, 255, 255)); + splash->Draw(SplashRect(), CRGBA(255, 255, 255, 255)); if(str1){ NumberOfChunksLoaded += 1; @@ -742,7 +755,7 @@ LoadingIslandScreen(const char *levelName) CRGBA col = CRGBA(255, 255, 255, 255); CRGBA col2 = CRGBA(0, 0, 0, 255); CSprite2d::DrawRect(CRect(0.0f, 0.0f, SCREEN_WIDTH, SCREEN_HEIGHT), col2); - splash->Draw(CRect(0.0f, 0.0f, SCREEN_WIDTH, SCREEN_HEIGHT), col, col, col, col); + splash->Draw(SplashRect(), col, col, col, col); CFont::DrawFonts(); DoRWStuffEndOfFrame(); } @@ -1473,6 +1486,9 @@ Render2dStuff(void) else #endif CHud::Draw(); +#ifdef ONLINE + COnlineNet::DrawBubbles(); +#endif CSpecialFX::Render2DFXs(); CUserDisplay::OnscnTimer.ProcessForDisplay(); @@ -1567,10 +1583,12 @@ Idle(void *arg) { // This is from SA, but it's nice for windowed mode #if defined(GTA_PC) && !defined(RW_GL3) + { RwV2d pos; pos.x = SCREEN_WIDTH / 2.0f; pos.y = SCREEN_HEIGHT / 2.0f; RsMouseSetPos(&pos); + } #endif tbStartTimer(0, "CnstrRenderList"); diff --git a/src/core/re3.cpp b/src/core/re3.cpp index b9cfc34da047eec649974260261d0e757175a52f..14f316715e100b9c932148ccd96860fd894338df 100644 --- a/src/core/re3.cpp +++ b/src/core/re3.cpp @@ -195,6 +195,21 @@ CustomFrontendOptionsPopulate(void) #include "ini.h" mINI::INIFile ini("reVC.ini"); + +#ifdef __EMSCRIPTEN__ +#include +// The browser's files vanish with the page: the settings are kept in its storage. +// The page puts them back before the game starts (index.html, restoreSettings). +static void +KeepSettings(void) +{ + EM_ASM({ + try { localStorage.setItem("vcSettings", FS.readFile("reVC.ini", { encoding: "utf8" })); } catch (e) {} + }); +} +#else +static void KeepSettings(void) {} +#endif mINI::INIStructure cfg; bool ReadIniIfExists(const char *cat, const char *key, uint32 *out) @@ -477,6 +492,7 @@ void SaveINIControllerSettings() StoreIni("Controller", "PadButtonsInited", ControlsManager.ms_padButtonsInited); ini.write(cfg); + KeepSettings(); } bool LoadINISettings() @@ -680,6 +696,7 @@ void SaveINISettings() #endif ini.write(cfg); + KeepSettings(); } #endif diff --git a/src/peds/Ped.cpp b/src/peds/Ped.cpp index 6cbe74841d4416c5d62e63a7521c14f42702bf21..cf2b7c429a5e49a13ff0d1da1e1d932743efc933 100644 --- a/src/peds/Ped.cpp +++ b/src/peds/Ped.cpp @@ -27,6 +27,10 @@ #include "CarCtrl.h" #include "Garages.h" #include "WaterLevel.h" + +float CPed::ms_swimEnterDepth = 0.0f; +float CPed::ms_swimDepth = 0.0f; +float CPed::ms_swimLift = 0.0f; #include "Timecycle.h" #include "ParticleObject.h" #include "Floater.h" @@ -280,6 +284,7 @@ CPed::CPed(uint32 pedType) : m_pedIK(this) bHasBeenPhotographed = false; bIsDrowning = false; + bIsSwimming = false; bDrownsInWater = true; bWaitForLeaderToComeCloser = false; bHeldHostageInCar = false; @@ -1678,6 +1683,26 @@ CPed::ProcessBuoyancy(void) } } } +#ifdef ONLINE + // The player swims: held at the surface, moving with the normal controls and animations, never drowning. + bIsSwimming = false; + if (ms_swimEnterDepth > 0.0f && IsPlayer() && !DyingOrDead() && !bInVehicle + && mod_Buoyancy.m_waterlevel > GetPosition().z + ms_swimEnterDepth) { + if (m_vecMoveSpeed.z < -0.1f) + DMAudio.PlayOneShot(m_audioEntityId, SOUND_SPLASH, 0.0f); + bIsSwimming = true; + bTryingToReachDryLand = false; + bIsDrowning = false; + if (bIsInTheAir || m_nPedState == PED_FALL) { + RpAnimBlendClumpSetBlendDeltas(GetClump(), ASSOC_PARTIAL, -1000.0f); + bIsInTheAir = false; + SetPedState(PED_IDLE); + } + bIsStanding = true; + m_vecMoveSpeed.z = (mod_Buoyancy.m_waterlevel - ms_swimDepth - GetPosition().z) * ms_swimLift; + return; + } +#endif float speedMult = 0.0f; if (buoyancyImpulse.z / m_fMass > GRAVITY * CTimer::GetTimeStep() || mod_Buoyancy.m_waterlevel > GetPosition().z + 0.6f) { diff --git a/src/peds/Ped.h b/src/peds/Ped.h index 26cdf03f60bdfe3fdbf479c11f272f0a5798fcbb..14e7a182041fb23de0ef1e0b0bb1747ad581780a 100644 --- a/src/peds/Ped.h +++ b/src/peds/Ped.h @@ -367,6 +367,9 @@ class CVehicle; class CPed : public CPhysical { public: + static float ms_swimEnterDepth; // how far under the surface the ped must be before swimming starts; 0 = no swimming + static float ms_swimDepth; // where the swimmer's centre is held under the surface + static float ms_swimLift; // how fast it is brought there #ifdef USE_CUTSCENE_SHADOW_FOR_PED class CCutsceneShadow *m_pRTShadow; #endif @@ -466,6 +469,7 @@ public: uint32 bHasBeenPhotographed : 1; // uint32 bIsDrowning : 1; + uint32 bIsSwimming : 1; uint32 bDrownsInWater : 1; uint32 bWaitForLeaderToComeCloser : 1; uint32 bHeldHostageInCar : 1; diff --git a/src/peds/PedFight.cpp b/src/peds/PedFight.cpp index 43ded57a35026d69594c97b07aa19261ce55b087..8edc30a48b14e6dfd6394d41146e394fb2dd8bd6 100644 --- a/src/peds/PedFight.cpp +++ b/src/peds/PedFight.cpp @@ -25,6 +25,9 @@ #include "Bike.h" #include "Glass.h" #include "SpecialFX.h" +#ifdef ONLINE +#include "../online/OnlineNet.h" +#endif uint16 nPlayerInComboMove; RpClump* flyingClumpTemp; @@ -2652,6 +2655,10 @@ CPed::ClearInvestigateEvent(void) bool CPed::InflictDamage(CEntity *damagedBy, eWeaponType method, float damage, ePedPieceTypes pedPiece, uint8 direction) { +#ifdef ONLINE + // Another player's health lives on that player's own machine. + if(COnlineNet::RemoteHit(this, damagedBy, method, damage)) return false; +#endif CPlayerPed *player = FindPlayerPed(); float dieDelta = 4.0f; float dieSpeed = 0.0f; diff --git a/src/peds/PlayerPed.cpp b/src/peds/PlayerPed.cpp index b3fe0ff03266802cdc1435a4f8798938c3dbf7c0..deb2b77465a6b62829134c3de00434188e971d55 100644 --- a/src/peds/PlayerPed.cpp +++ b/src/peds/PlayerPed.cpp @@ -1267,8 +1267,11 @@ CPlayerPed::ProcessPlayerWeapon(CPad *padUsed) if (!m_pFire) { eWeaponType weapon = GetWeapon()->m_eWeaponType; if (weapon == WEAPONTYPE_ROCKETLAUNCHER || weapon == WEAPONTYPE_SNIPERRIFLE || - weapon == WEAPONTYPE_LASERSCOPE || weapon == WEAPONTYPE_M4 || + weapon == WEAPONTYPE_LASERSCOPE || +#ifndef ONLINE + weapon == WEAPONTYPE_M4 || weapon == WEAPONTYPE_RUGER || weapon == WEAPONTYPE_M60 || +#endif weapon == WEAPONTYPE_CAMERA) { if (padUsed->TargetJustDown() || TheCamera.m_bJustJumpedOutOf1stPersonBecauseOfTarget) { diff --git a/src/renderer/Hud.cpp b/src/renderer/Hud.cpp index d7d8050fbb3150eb46fd84c7a93d356d31761ebe..377207253480f5cf014e10d38950a692e16a35d1 100644 --- a/src/renderer/Hud.cpp +++ b/src/renderer/Hud.cpp @@ -48,6 +48,11 @@ CRGBA MONEY_COLOR(0, 207, 133, 255); CRGBA AMMO_COLOR(255, 150, 225, 255); CRGBA HEALTH_COLOR(255, 150, 225, 255); CRGBA ARMOUR_COLOR(185, 185, 185, 255); +#ifdef ONLINE +#define WANTED_STARS_Y 65.0f // health is a bar under the map, so the stars close the gap it left +#else +#define WANTED_STARS_Y 87.0f +#endif CRGBA NOTWANTED_COLOR(27, 89, 130, 255); CRGBA WANTED_COLOR_FLASH(62, 141, 181, 255); CRGBA WANTED_COLOR(97, 194, 247, 255); @@ -553,7 +558,11 @@ void CHud::Draw() m_LastTimeEnergyLost = CWorld::Players[CWorld::PlayerInFocus].m_nTimeLastHealthLoss; } +#ifdef ONLINE + if (false) { // health and armour are bars under the minimap +#else if (m_EnergyLostState != FADED_OUT) { +#endif CFont::SetBackgroundOff(); CFont::SetScale(SCREEN_SCALE_X(HUD_TEXT_SCALE_X), SCREEN_SCALE_Y(HUD_TEXT_SCALE_Y)); CFont::SetJustifyOff(); @@ -649,18 +658,21 @@ void CHud::Draw() WANTED_COLOR.a = alpha; CFont::SetColor(WANTED_COLOR); - CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(110.0f + 23.0f * i), SCREEN_SCALE_Y(87.0f), sPrintIcon); + CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(110.0f + 23.0f * i), SCREEN_SCALE_Y(WANTED_STARS_Y), sPrintIcon); } else if (playerPed->m_pWanted->m_nMinWantedLevel > i && FRAMECOUNTER & 4) { WANTED_COLOR_FLASH.a = alpha; CFont::SetColor(WANTED_COLOR_FLASH); - CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(110.0f + 23.0f * i), SCREEN_SCALE_Y(87.0f), sPrintIcon); + CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(110.0f + 23.0f * i), SCREEN_SCALE_Y(WANTED_STARS_Y), sPrintIcon); - } else if (playerPed->m_pWanted->GetWantedLevel() <= i) { + } +#ifndef ONLINE + else if (playerPed->m_pWanted->GetWantedLevel() <= i) { NOTWANTED_COLOR.a = alpha; CFont::SetColor(NOTWANTED_COLOR); - CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(110.0f + 23.0f * i), SCREEN_SCALE_Y(87.0f), sPrintIcon); + CFont::PrintString(SCREEN_SCALE_FROM_RIGHT(110.0f + 23.0f * i), SCREEN_SCALE_Y(WANTED_STARS_Y), sPrintIcon); } +#endif } } } @@ -1063,8 +1075,27 @@ void CHud::Draw() !m_HideRadar && (m_ItemToFlash == ITEM_RADAR && FRAMECOUNTER & 8 || m_ItemToFlash != ITEM_RADAR)) { RwRenderStateSet(rwRENDERSTATETEXTUREFILTER, (void*)rwFILTERNEAREST); +#ifdef ONLINE + { + // Square minimap with health and armour bars under it. + float l = SCREEN_SCALE_X_FIX(RADAR_LEFT), r = l + SCREEN_SCALE_X(RADAR_WIDTH); + float b = SCREEN_SCALE_FROM_BOTTOM(RADAR_BOTTOM), t = b - SCREEN_SCALE_Y(RADAR_HEIGHT); + float gap = SCREEN_SCALE_Y(3.0f), barH = SCREEN_SCALE_Y(6.0f), mid = (l + r) / 2.0f; + CSprite2d::DrawRect(CRect(l - gap, t - gap, r + gap, b + 2.0f * gap + barH), CRGBA(0, 0, 0, 200)); + float health = Clamp(playerPed->m_fHealth / 100.0f, 0.0f, 1.0f), armour = Clamp(playerPed->m_fArmour / 100.0f, 0.0f, 1.0f); + CRect hb(l, b + gap, mid - gap / 2.0f, b + gap + barH), ab(mid + gap / 2.0f, b + gap, r, b + gap + barH); + CSprite2d::DrawRect(hb, CRGBA(30, 70, 40, 255)); + CSprite2d::DrawRect(CRect(hb.left, hb.top, hb.left + (hb.right - hb.left) * health, hb.bottom), health < 0.25f ? CRGBA(200, 40, 40, 255) : CRGBA(80, 190, 90, 255)); + CSprite2d::DrawRect(ab, CRGBA(25, 55, 90, 255)); + CSprite2d::DrawRect(CRect(ab.left, ab.top, ab.left + (ab.right - ab.left) * armour, ab.bottom), CRGBA(80, 160, 230, 255)); + } +#endif CRadar::DrawMap(); +#ifdef ONLINE + if (false) { // no round disc +#else if (FrontEndMenuManager.m_PrefsRadarMode != 1) { +#endif CRect rect(0.0f, 0.0f, SCREEN_SCALE_X(RADAR_WIDTH), SCREEN_SCALE_Y(RADAR_HEIGHT)); rect.Translate(SCREEN_SCALE_X_FIX(RADAR_LEFT), SCREEN_SCALE_FROM_BOTTOM(RADAR_BOTTOM + RADAR_HEIGHT)); diff --git a/src/renderer/Timecycle.h b/src/renderer/Timecycle.h index da911b75431432cd728589a2a0ef096b44e36103..8145b0efee55e1d9df835c08ad068ec72b763e5d 100644 --- a/src/renderer/Timecycle.h +++ b/src/renderer/Timecycle.h @@ -161,6 +161,7 @@ public: static float GetLightOnGroundBrightness(void) { return m_fCurrentLightsOnGroundBrightness; } static float GetFarClip(void) { return m_fCurrentFarClip; } static float GetFogStart(void) { return m_fCurrentFogStart; } + static void SetFarClipAndFog(float farClip, float fogStart) { m_fCurrentFarClip = farClip; m_fCurrentFogStart = fogStart; } static int32 GetLowCloudsRed(void) { return m_nCurrentLowCloudsRed; } static int32 GetLowCloudsGreen(void) { return m_nCurrentLowCloudsGreen; } diff --git a/src/rw/TexRead.cpp b/src/rw/TexRead.cpp index 1f96180bcc7f1fc37e191d0b42b2ca7fdcdc4c42..4b2b915448f038ffbe37c9abe43d327793d4acbb 100644 --- a/src/rw/TexRead.cpp +++ b/src/rw/TexRead.cpp @@ -293,7 +293,10 @@ CanVideoCardDoDXT(void) { #ifdef LIBRW // TODO -#ifdef RW_OPENGL +#if defined RW_OPENGL && defined __EMSCRIPTEN__ + // WebGL takes the PC textures as they are, so there is nothing to convert. + return rw::gl3::gl3Caps.dxtSupported; +#elif defined RW_OPENGL return false; #else return true; diff --git a/src/skel/glfw/glfw.cpp b/src/skel/glfw/glfw.cpp index f1f97ee314f7ebde24f51832fe50ca846c7af84c..c7d5b032812f1c5bd9d0f4eda79506fb76a914fb 100644 --- a/src/skel/glfw/glfw.cpp +++ b/src/skel/glfw/glfw.cpp @@ -14,8 +14,12 @@ DWORD _dwOperatingSystemVersion; long _dwOperatingSystemVersion; #ifndef __SWITCH__ #ifndef __APPLE__ +#ifndef __EMSCRIPTEN__ #include #else +#include +#endif +#else #include #include #endif @@ -43,6 +47,7 @@ long _dwOperatingSystemVersion; #include "Timer.h" #include "DMAudio.h" #include "ControllerConfig.h" +#include "../../online/OnlineNet.h" #include "Frontend.h" #include "Game.h" #include "PCSave.h" @@ -194,6 +199,8 @@ psCameraBeginUpdate(RwCamera *camera) /* ***************************************************************************** */ +void resizeCB(GLFWwindow* window, int width, int height); + void psCameraShowRaster(RwCamera *camera) { @@ -206,6 +213,30 @@ psCameraShowRaster(RwCamera *camera) else RwCameraShowRaster(camera, PSGLOBAL(window), rwRASTERFLIPDONTWAIT); +#ifdef __EMSCRIPTEN__ + // The page needs to know when the game's own menu is up: it must not take Enter, T, Q or B then. + EM_ASM({ Module.vcMenuActive = !!$0; Module.vcFrames = (Module.vcFrames || 0) + 1; }, FrontEndMenuManager.m_bMenuActive ? 1 : 0); + COnlineNet::PumpOutbox(); + + // The page resizes the canvas with the browser window; the game follows (menus and world). + { + static int lastW, lastH; + int w = EM_ASM_INT({ return Module.canvas.clientWidth; }); + int h = EM_ASM_INT({ return Module.canvas.clientHeight; }); + if(w > 0 && h > 0 && (w != lastW || h != lastH)){ + bool first = lastW == 0; + lastW = w; + lastH = h; + if(!first || w != RsGlobal.maximumWidth || h != RsGlobal.maximumHeight){ + glfwSetWindowSize(PSGLOBAL(window), w, h); + resizeCB(PSGLOBAL(window), w, h); + } + } + } + + // Every finished frame hands control back to the browser so it can present it. + emscripten_sleep(0); +#endif return; } @@ -258,7 +289,7 @@ double psTimer(void) { struct timespec start; -#if defined(CLOCK_MONOTONIC_RAW) +#if defined(CLOCK_MONOTONIC_RAW) && !defined(__EMSCRIPTEN__) // the browser only has CLOCK_MONOTONIC clock_gettime(CLOCK_MONOTONIC_RAW, &start); #elif defined(CLOCK_MONOTONIC_FAST) clock_gettime(CLOCK_MONOTONIC_FAST, &start); @@ -555,6 +586,8 @@ psInitialize(void) #elif defined (__SWITCH__) svcGetInfo(&_dwMemAvailPhys, InfoType_UsedMemorySize, CUR_PROCESS_HANDLE, 0); debug("Physical memory size %llu\n", _dwMemAvailPhys); +#elif defined (__EMSCRIPTEN__) + _dwMemAvailPhys = 2048ull << 20; // browsers give us up to the wasm memory limit #else #ifndef __APPLE__ struct sysinfo systemInfo; @@ -865,6 +898,12 @@ psSelectDevice() } } +#ifdef __EMSCRIPTEN__ + // The browser has no exclusive modes: the game always runs in the page canvas. + FrontEndMenuManager.m_nPrefsWindowed = 1; + if(bestFsMode < 0) + bestFsMode = bestWndMode; +#endif if(bestFsMode < 0){ printf("WARNING: Cannot find desired video mode, selecting device cancelled\n"); return FALSE; @@ -879,6 +918,13 @@ psSelectDevice() #endif RwEngineGetVideoModeInfo(&vm, GcurSelVM); +#ifdef __EMSCRIPTEN__ + // The browser reports no real monitor modes: the game renders at the canvas size + // in CSS pixels (the shell pins devicePixelRatio to 1, so that is the drawing buffer). + vm.width = EM_ASM_INT({ return Module.canvas.clientWidth; }); + vm.height = EM_ASM_INT({ return Module.canvas.clientHeight; }); + vm.depth = 32; +#endif #ifdef IMPROVED_VIDEOMODE if (FrontEndMenuManager.m_nPrefsWindowed) @@ -2261,6 +2307,11 @@ main(int argc, char *argv[]) { if(!WindowIconified) RsEventHandler(rsFRONTENDIDLE, nil); +#ifdef ONLINE + // Joining is instant: press "new game" for the player as soon as the menu is up. + if (FrontEndMenuManager.m_bMenuActive && !FrontEndMenuManager.m_bShutDownFrontEndRequested) + FrontEndMenuManager.DoSettingsBeforeStartingAGame(); +#endif #ifdef PS2_MENU if ( !FrontEndMenuManager.m_bMenuActive || TheMemoryCard.m_bWantToLoad ) diff --git a/src/skel/skeleton.cpp b/src/skel/skeleton.cpp index 2bb23460592398afcf0c872ad9eced8bcc9c3615..715a7b58af249505cec70a7a0b4b1ffb94bccf6a 100644 --- a/src/skel/skeleton.cpp +++ b/src/skel/skeleton.cpp @@ -397,7 +397,7 @@ RsInitialize(void) */ RwBool result; - RsGlobal.appName = RWSTRING("GTA: Vice City"); + RsGlobal.appName = RWSTRING("Vice City Online"); RsGlobal.maximumWidth = DEFAULT_SCREEN_WIDTH; RsGlobal.maximumHeight = DEFAULT_SCREEN_HEIGHT; RsGlobal.width = DEFAULT_SCREEN_WIDTH; diff --git a/src/skel/win/win.cpp b/src/skel/win/win.cpp index c49f0ab96c54c81fa2e5c45004f8d72c653e1f17..fac723d3e6bc5c0ef5df7d00b36b764eb83081e2 100644 --- a/src/skel/win/win.cpp +++ b/src/skel/win/win.cpp @@ -1355,7 +1355,13 @@ InitApplication(HANDLE instance) RwBool IsForegroundApp() { +#ifdef FIX_BUGS + // ForegroundApp starts TRUE and only drops on deactivation, so a window started in the + // background read the desktop mouse through DirectInput. Ask Windows instead. + return !!ForegroundApp && GetForegroundWindow() == PSGLOBAL(window); +#else return !!ForegroundApp; +#endif } UINT GetBestRefreshRate(UINT width, UINT height, UINT depth) diff --git a/src/text/Text.cpp b/src/text/Text.cpp index 1369d1db61ecba254fe1665dc23a9c3d34cbdb1f..ee06865d868f185830c4e4ab8af6a90d94b001ec 100644 --- a/src/text/Text.cpp +++ b/src/text/Text.cpp @@ -51,7 +51,11 @@ CText::Load(void) sprintf(filename, "ITALIAN.GXT"); break; case CMenuManager::LANGUAGE_SPANISH: +#ifdef ONLINE + sprintf(filename, "TURKISH.GXT"); +#else sprintf(filename, "SPANISH.GXT"); +#endif break; #ifdef MORE_LANGUAGES case CMenuManager::LANGUAGE_POLISH: @@ -108,6 +112,13 @@ CText::Unload(void) wchar* CText::Get(const char *key) { +#ifdef ONLINE + // The Spanish slot of the language menu holds the Turkish text here. + if(strcmp(key, "FEL_SPA") == 0){ + static wchar turkish[] = { 'T','u','r','k','c','e',0 }; + return turkish; + } +#endif uint8 result = false; #if defined (FIX_BUGS) || defined(FIX_BUGS_64) wchar *outstr = keyArray.Search(key, data.chars, &result); @@ -255,7 +266,11 @@ CText::LoadMissionText(char *MissionTableName) sprintf(filename, "ITALIAN.GXT"); break; case CMenuManager::LANGUAGE_SPANISH: +#ifdef ONLINE + sprintf(filename, "TURKISH.GXT"); +#else sprintf(filename, "SPANISH.GXT"); +#endif break; #ifdef MORE_LANGUAGES case CMenuManager::LANGUAGE_POLISH: diff --git a/src/vehicles/Automobile.cpp b/src/vehicles/Automobile.cpp index 815b2534c81ab38ccb941cbdf23e3bad035620a2..fd06d97af2221a1ec8354e017f3949dee5a1c062 100644 --- a/src/vehicles/Automobile.cpp +++ b/src/vehicles/Automobile.cpp @@ -244,7 +244,7 @@ CAutomobile::SetModelIndex(uint32 id) SetupModelNodes(); } -#define SAND_SLOWDOWN (0.01f) +#define SAND_SLOWDOWN (0.01f*CSurfaceTable::ms_sandDragScale) float CAR_BALANCE_MULT = 0.3f; float HELI_ROTOR_DOTPROD_LIMIT = 0.95f; CVector vecSeaSparrowGunPos(-0.5f, 2.4f, -0.785f); diff --git a/src/vehicles/Bike.cpp b/src/vehicles/Bike.cpp index a65b64d293ae44c51b7dd165f7eba289627c686e..0455500a6414d37fa0153b9bf34ecf141275cc53 100644 --- a/src/vehicles/Bike.cpp +++ b/src/vehicles/Bike.cpp @@ -196,7 +196,7 @@ CBike::SetModelIndex(uint32 id) SetupModelNodes(); } -#define SAND_SLOWDOWN (0.02f) +#define SAND_SLOWDOWN (0.02f*CSurfaceTable::ms_sandDragScale) CVector vecTestResistance(0.9995f, 0.9f, 0.95f); float fDAxisX = 1.0f; float fDAxisXExtra = 100.0f; @@ -777,6 +777,7 @@ CBike::ProcessControl(void) float traction = 0.004f * m_fTraction; traction *= pHandling->fTractionMultiplier / 4.0f; + traction *= CSurfaceTable::ms_bikeGripScale; // Turn wheel if(GetStatus() == STATUS_PLAYER || !bIsStanding || bIsBeingPickedUp){ diff --git a/src/vehicles/Vehicle.cpp b/src/vehicles/Vehicle.cpp index d1054191ca835bd76d7d7160c82e79af79ed6589..b72b65d4a48970516510ca404b291e51b72fa37c 100644 --- a/src/vehicles/Vehicle.cpp +++ b/src/vehicles/Vehicle.cpp @@ -173,6 +173,9 @@ CVehicle::CVehicle(uint8 CreatedBy) m_nRadioStation = CGeneral::GetRandomNumber() % NUM_RADIOS; break; } +#ifdef ONLINE + m_nRadioStation = RADIO_OFF; +#endif m_pCurGroundEntity = nil; m_bRainAudioCounter = 0; m_bRainSamplesCounter = 0; @@ -784,9 +787,8 @@ CVehicle::ProcessWheel(CVector &wheelFwd, CVector &wheelRight, CVector &wheelCon static bool bBraking; static bool bDriving; -#ifdef FIX_SIGNIFICANT_BUGS + // Never reset in the original: after the first skid of any car, every car kept the skidding grip for good. bAlreadySkidding = false; -#endif // how much force we want to apply in these axes float fwd = 0.0f; @@ -941,9 +943,8 @@ CVehicle::ProcessBikeWheel(CVector &wheelFwd, CVector &wheelRight, CVector &whee static bool bDriving; static bool bReversing; -#ifdef FIX_SIGNIFICANT_BUGS + // Never reset in the original: after the first skid of any bike, every bike kept the skidding grip for good. bAlreadySkidding = false; -#endif // how much force we want to apply in these axes float fwd = 0.0f; diff --git a/src/weapons/Weapon.cpp b/src/weapons/Weapon.cpp index 2d219e2d5c2e427feed9717b8422687ad1c0da13..be797360e5ebd8c84b6bdf55a1ecd8f3a1294d1a 100644 --- a/src/weapons/Weapon.cpp +++ b/src/weapons/Weapon.cpp @@ -3274,7 +3274,14 @@ CPed::IsPedDoingDriveByShooting(void) bool CWeapon::ProcessLineOfSight(CVector const &point1, CVector const &point2, CColPoint &point, CEntity *&entity, eWeaponType type, CEntity *shooter, bool checkBuildings, bool checkVehicles, bool checkPeds, bool checkObjects, bool checkDummies, bool ignoreSeeThrough, bool ignoreSomeObjects) { +#ifdef ONLINE + CWorld::bIncludeRemotePlayers = true; + bool hit = CWorld::ProcessLineOfSight(point1, point2, point, entity, checkBuildings, checkVehicles, checkPeds, checkObjects, checkDummies, false, ignoreSomeObjects, true); + CWorld::bIncludeRemotePlayers = false; + return hit; +#else return CWorld::ProcessLineOfSight(point1, point2, point, entity, checkBuildings, checkVehicles, checkPeds, checkObjects, checkDummies, false, ignoreSomeObjects, true); +#endif }