Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"C_Cpp.default.compileCommands": "e:\\Repositories\\WORR\\builddir/compile_commands.json",
"C_Cpp.default.compileCommands": "${workspaceFolder}/builddir-win/compile_commands.json",
"C_Cpp.default.configurationProvider": "mesonbuild.mesonbuild",
"debug.defaultConfiguration": "WORR (Vulkan)"
}
6 changes: 3 additions & 3 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"command": "cmd",
"args": [
"/c",
"if exist builddir\\meson-private\\coredata.dat (meson setup --reconfigure builddir) else (meson setup builddir)"
"if exist builddir-win\\meson-private\\coredata.dat (meson setup --reconfigure builddir-win) else (meson setup builddir-win)"
],
"options": {
"cwd": "${workspaceFolder}"
Expand All @@ -21,7 +21,7 @@
"args": [
"compile",
"-C",
"builddir"
"builddir-win"
],
"dependsOn": [
"meson: setup"
Expand All @@ -38,7 +38,7 @@
"args": [
"tools/refresh_install.py",
"--build-dir",
"builddir",
"builddir-win",
"--install-dir",
".install",
"--base-game",
Expand Down
13 changes: 12 additions & 1 deletion BUILD_QUIRKS.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,18 @@ ERROR: None of values ['c++23'] are supported by the CPP compiler. Possible valu

**Cause:** Meson 1.10.x has a fixed list of supported `cpp_std` values for MSVC. `c++23` isn't in that list, even though VC 2022+ supports it.

**Workaround:** Use `c++latest` instead of `c++23`. Meson accepts it, and MSVC maps it to `/std:c++latest` (C++23 on recent toolchains). The sgame DLL override has been updated to use `cpp_std=c++latest` for MSVC compatibility.
**Workaround:** Use `c++latest` instead of `c++23`. Meson accepts it, and MSVC maps it to `/std:c++latest` (C++23 on recent toolchains). The sgame DLL override uses `cpp_std=c++latest` for MSVC only; on GCC/Clang (Linux/BSD) it uses `c++23` because `c++latest` is not supported there.

## GCC/Clang: c++latest not supported

**Symptom (on Linux):**
```
ERROR: None of values ['c++latest'] are supported by the CPP compiler. Possible values for option "cpp_std" are ['none', 'c++98', ..., 'c++23', 'c++26', ...]
```

**Cause:** `c++latest` is an MSVC-specific value. GCC and Clang support `c++23` (and `c++26`) but not `c++latest`.

**Fix:** `meson.build` selects `cpp_std` per compiler: `c++latest` for MSVC, `c++23` for GCC/Clang.

## MSVC C4576: compound literal in C++ (COLOR_RGBA etc.)

Expand Down
104 changes: 104 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
#!/bin/bash
# WORR build script for Linux
# Uses builddir-linux (Windows builds use builddir-win)
# Usage: ./build.sh [options]
#
# Options:
# --deps Install build dependencies (apt/dnf) before building
# --clean Wipe builddir-linux and reconfigure from scratch
# --stage Run refresh_install.py after build to populate .install/
# -h, --help Show this help

set -e

SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
BUILD_DIR="${SCRIPT_DIR}/builddir-linux"
INSTALL_DIR="${SCRIPT_DIR}/.install"
BASE_GAME="baseq2"

install_deps_apt() {
sudo apt-get install -y meson gcc libc6-dev libsdl3-dev libopenal-dev \
libpng-dev libjpeg-dev zlib1g-dev mesa-common-dev \
libcurl4-gnutls-dev libx11-dev libxi-dev \
libwayland-dev wayland-protocols libdecor-0-dev \
libavcodec-dev libavformat-dev libavutil-dev \
libswresample-dev libswscale-dev
}

install_deps_dnf() {
sudo dnf install -y meson gcc glibc-devel SDL3-devel openal-soft-devel \
libpng-devel libjpeg-turbo-devel zlib-devel mesa-libGL-devel \
libcurl-devel libX11-devel libXi-devel \
wayland-devel wayland-protocols-devel libdecor-devel \
ffmpeg-devel
}

install_deps() {
if command -v dnf &>/dev/null; then
echo "Detected Fedora/RHEL, installing dependencies..."
install_deps_dnf
elif command -v apt-get &>/dev/null; then
echo "Detected Debian/Ubuntu, installing dependencies..."
install_deps_apt
else
echo "Unknown package manager. Please install dependencies manually. See BUILDING.md"
exit 1
fi
}

setup_build() {
cd "$SCRIPT_DIR"
if [[ -n "$CLEAN" ]]; then
echo "Cleaning build directory..."
rm -rf "$BUILD_DIR"
fi
meson setup "$BUILD_DIR"
}

compile() {
cd "$SCRIPT_DIR"
meson compile -C "$BUILD_DIR"
}

stage_install() {
cd "$SCRIPT_DIR"
python3 tools/refresh_install.py \
--build-dir "$BUILD_DIR" \
--install-dir "$INSTALL_DIR" \
--base-game "$BASE_GAME"
}

show_help() {
sed -n '2,15p' "$0" | sed 's/^# \?//'
}

DO_DEPS=
CLEAN=
DO_STAGE=

while [[ $# -gt 0 ]]; do
case "$1" in
--deps) DO_DEPS=1 ;;
--clean) CLEAN=1 ;;
--stage) DO_STAGE=1 ;;
-h|--help) show_help; exit 0 ;;
*) echo "Unknown option: $1"; show_help; exit 1 ;;
esac
shift
done

echo "Building WORR in $SCRIPT_DIR"
echo "----------------------------"

[[ -n "$DO_DEPS" ]] && install_deps
setup_build
compile

if [[ -n "$DO_STAGE" ]]; then
stage_install
echo ""
echo "Staged build in $INSTALL_DIR"
fi

echo ""
echo "Build complete. Binaries are in $BUILD_DIR"
11 changes: 11 additions & 0 deletions inc/renderer/renderer_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,17 @@ with this program; if not, write to the Free Software Foundation, Inc.,
#endif
#endif

/* When building the renderer DLL, ensure struct member names are not macro-expanded
* by shared.h (HAVE_MEMCCPY/HAVE_STRCHRNUL), which would rename Q_memccpy→memccpy etc. */
#if defined(RENDERER_DLL)
#ifdef Q_memccpy
#undef Q_memccpy
#endif
#ifdef Q_strchrnul
#undef Q_strchrnul
#endif
#endif

typedef struct renderer_import_s {
void (*Com_LPrintf)(print_type_t type, const char *fmt, ...);
void (*Com_Error)(error_type_t type, const char *fmt, ...);
Expand Down
5 changes: 5 additions & 0 deletions inc/shared/atomic.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,11 @@ with this program; if not, write to the Free Software Foundation, Inc.,
typedef volatile int atomic_int;
#define atomic_load(p) (*(p))
#define atomic_store(p, v) (*(p) = (v))
#elif defined(__cplusplus)
#include <atomic>
typedef std::atomic<int> atomic_int;
#define atomic_load(p) ((p)->load())
#define atomic_store(p, v) ((p)->store(v))
#else
#include <stdatomic.h>
#endif
2 changes: 2 additions & 0 deletions inc/shared/shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -510,13 +510,15 @@ static inline float smoothstep(float edge0, float edge1, float x)
return t * t * (3.0f - 2.0f * t);
}

#if !defined(NOMINMAX)
#ifndef max
#define max(a,b) ((a)>(b)?(a):(b))
#endif

#ifndef min
#define min(a,b) ((a)<(b)?(a):(b))
#endif
#endif

#define frand() ((int32_t)Q_rand() * 0x1p-32f + 0.5f)
#define crand() ((int32_t)Q_rand() * 0x1p-31f)
Expand Down
19 changes: 16 additions & 3 deletions meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,6 @@ if cpp.get_argument_syntax() == 'gcc'
if x86
client_cpp_args += cpp.get_supported_arguments(['-msse2', '-mfpmath=sse'])
endif

client_cpp_warn_args = [
'-Wformat-security',
'-Wno-microsoft-anon-tag',
Expand All @@ -666,11 +665,14 @@ endif

game_cpp_args = [
'-DHAVE_CONFIG_H',
'-DQ2PROTO_CONFIG_H="common/q2proto_config.h"',
'-DNO_FMT_SOURCE',
'-DNOMINMAX',
]

game_c_args = [
'-DHAVE_CONFIG_H',
'-DQ2PROTO_CONFIG_H="common/q2proto_config.h"',
]

game_link_args = []
Expand Down Expand Up @@ -999,7 +1001,12 @@ if openal.found()
client_src += [ 'src/client/sound/al.cpp', 'src/client/sound/qal.cpp', 'inc/common/jsmn.h' ]
client_deps += openal
config.set10('USE_OPENAL', true)
# Work around OpenAL protected symbol linker error on Fedora/glibc
if not win32 and cpp.get_argument_syntax() == 'gcc'
client_cpp_args += cpp.get_supported_arguments(['-mno-direct-extern-access'])
endif
endif
client_link_args = exe_link_args

# require FFmpeg >= 5.1.3
ffmpeg_defaults = [
Expand Down Expand Up @@ -1205,7 +1212,11 @@ renderer_vk_rtx_lib = []
if get_option('external-renderers')
renderer_engine_src = []

libm = cc.find_library('m', required: false)
renderer_deps = []
if libm.found()
renderer_deps += libm
endif
if zlib.found()
renderer_deps += zlib
endif
Expand Down Expand Up @@ -1284,7 +1295,7 @@ executable('worr', common_src, client_src, renderer_engine_src,
include_directories: ['inc', 'q2proto/inc'],
gnu_symbol_visibility: 'hidden',
win_subsystem: win_subsystem_client,
link_args: exe_link_args,
link_args: client_link_args,
link_with: q2proto_lib,
c_args: ['-DUSE_CLIENT=1', '-DUSE_REF=REF_GL', engine_args],
cpp_args: client_cpp_args,
Expand Down Expand Up @@ -1343,6 +1354,8 @@ cgame_defines = [
'-DRENDERER_DLL',
]

# MSVC: use c++latest (c++23 not in Meson's MSVC list). GCC/Clang: use c++23 (c++latest unsupported).
sgame_cpp_std = cpp.get_id() == 'msvc' ? 'c++latest' : 'c++23'
sgame_dll = shared_library('sgame' + cpu, sgame_src,
name_prefix: '',
gnu_symbol_visibility: 'hidden',
Expand All @@ -1354,7 +1367,7 @@ sgame_dll = shared_library('sgame' + cpu, sgame_src,
install: true,
install_dir: libdir / get_option('base-game'),
install_tag: 'runtime',
override_options: ['b_vscrt=from_buildtype', 'cpp_std=c++latest'],
override_options: ['b_vscrt=from_buildtype', 'cpp_std=' + sgame_cpp_std],
)

cgame_all_src = cgame_src + ui_src + [
Expand Down
1 change: 1 addition & 0 deletions src/client/font.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#define NOMINMAX
#include "client/font.h"

#include <algorithm>
Expand Down
11 changes: 10 additions & 1 deletion src/client/renderer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -489,6 +489,15 @@ static int R_Q_atoi(const char *s)
return Q_atoi(s);
}

static char *R_Q_strchrnul(const char *s, int c)
{
#ifdef HAVE_STRCHRNUL
return const_cast<char *>(strchrnul(s, c));
#else
return Q_strchrnul(s, c);
#endif
}

void R_ClearDebugLines(void)
{
if (re.ClearDebugLines) {
Expand Down Expand Up @@ -741,7 +750,7 @@ static renderer_import_t R_BuildRendererImports(void)
.Q_strcasecmp = Q_strcasecmp,
.Q_strncasecmp = Q_strncasecmp,
.Q_strcasestr = Q_strcasestr,
.Q_strchrnul = Q_strchrnul,
.Q_strchrnul = R_Q_strchrnul,
.Q_strlcpy = Q_strlcpy,
.Q_strlcat = Q_strlcat,
.Q_concat_array = Q_concat_array,
Expand Down
4 changes: 2 additions & 2 deletions src/client/sound/qal.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ typedef struct {
const alfunction_t *functions;
} alsection_t;

#define QALC_FN(x) { "alc"#x, &qalc##x, alc##x }
#define QAL_FN(x) { "al"#x, &qal##x, al##x }
#define QALC_FN(x) { "alc"#x, &qalc##x, (void*)(uintptr_t)(alc##x) }
#define QAL_FN(x) { "al"#x, &qal##x, (void*)(uintptr_t)(al##x) }

#if defined(__clang__)
#pragma clang diagnostic push
Expand Down
3 changes: 3 additions & 0 deletions src/game/bgame/q_std.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@
#include <type_traits>
#include <algorithm>
#include <array>

using std::min;
using std::max;
#include <string_view>
#include <string>
#include <numeric>
Expand Down
2 changes: 1 addition & 1 deletion src/game/cgame/cg_entities.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2131,7 +2131,7 @@ void CL_CalcViewValues(void)

// Smooth out view height over 100ms
float viewheight_lerp = (cl.time - cl.viewheight_change_time);
viewheight_lerp = 100 - min(viewheight_lerp, 100);
viewheight_lerp = 100 - min(viewheight_lerp, 100.0f);
viewheight = cl.current_viewheight + (float)(cl.prev_viewheight - cl.current_viewheight) * viewheight_lerp * 0.01f;

cl.refdef.vieworg[2] += viewheight;
Expand Down
5 changes: 5 additions & 0 deletions src/game/cgame/cg_entity_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@

#pragma once

#include <algorithm>

#include "client/cgame_entity.h"

using std::min;
using std::max;
#include "common/zone.h"
#include "cg_client_defs.h"

Expand Down
4 changes: 4 additions & 0 deletions src/game/cgame/cg_ui_sys.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ with this program; if not, write to the Free Software Foundation, Inc.,

#include "client/cgame_ui.h"
#include "common/common.h"

#include <algorithm>
using std::min;
using std::max;
#include "common/error.h"
#include "common/files.h"

Expand Down
4 changes: 4 additions & 0 deletions src/game/cgame/ui/ui_internal.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#pragma once

#include <algorithm>
#include <functional>
#include <memory>
#include <string>
Expand Down Expand Up @@ -69,6 +70,9 @@ void UI_SetClipboardData(const char *text);

namespace ui {

using std::min;
using std::max;

enum class Sound {
NotHandled,
Silent,
Expand Down
2 changes: 1 addition & 1 deletion src/game/sgame/gameplay/g_ai_new.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1090,7 +1090,7 @@ bool M_CalculatePitchToFire(gentity_t* self, const Vector3& target, const Vector
}
}

if (!isinf(best_dist)) {
if (!std::isinf(best_dist)) {
pitched_aim[PITCH] = best_pitch;
aim = AngleVectors(pitched_aim).forward;
return true;
Expand Down
Loading