Zero Hour rebuilt from EA's source: x64, Direct3D 11, VS2022/CMake, ~60 original bugs fixed, an AI that builds a base. Bring your own game.
C++ cmakecnccommand-and-conquercppdirectx11game-enginegame-preservationgeneralsrtssage-enginex64zero-hour
#!/usr/bin/env bash
# Copyright 2026 İlyas Akın
# Additional terms under GNU GPL section 7 apply: see LICENSE.md.
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
# Regenerates model_shaders.h. The viewer carries the same shader three ways, so the routes D3
# chooses between can be put on the same frame (w3d_view --shaders glsl|hlsl|hand):
#
# glsl model.vert, model.frag --glslang--> SPIR-V --SDL_shadercross--> MSL
# hlsl model_vs.hlsl, model_ps.hlsl --glslang (HLSL front end)--> SPIR-V --SDL_shadercross--> MSL
# hand model.hand.metal, MSL written by hand (Metal only)
#
# SPIR-V is what SDL's Vulkan backend takes, MSL what its Metal backend takes; SDL_shadercross is
# SPIRV-Cross underneath, set up for SDL's binding rules.
#
# The header is checked in, so building w3d_view needs neither tool. Run this when a shader
# changes, and record the tool versions it prints in the header (it does so itself).
#
# SHADERCROSS_COMMIT=<commit> build_shaders.sh <glslang> <shadercross>
#
# The D-spike measured the pinned versions:
# glslang vulkan-sdk-1.4.357.0 built with ENABLE_HLSL=ON, and SDL_shadercross 1ff05bec built with
# SDLSHADERCROSS_DXC=OFF, both from source.
set -euo pipefail
[ $# -eq 2 ] || { echo "usage: $0 <glslang> <shadercross>"; exit 2; }
glslang="$1"
shadercross="$2"
here="$(cd "$(dirname "$0")" && pwd)"
work="$(mktemp -d "${TMPDIR:-/tmp}/w3d_view_shaders.XXXXXX")"
"$glslang" -V --target-env vulkan1.0 "$here/model.vert" -o "$work/model.vert.spv" > "$work/glslang.log"
"$glslang" -V --target-env vulkan1.0 "$here/model.frag" -o "$work/model.frag.spv" >> "$work/glslang.log"
"$shadercross" "$work/model.vert.spv" -s SPIRV -d MSL -t vertex -e main -o "$work/model.vert.msl"
"$shadercross" "$work/model.frag.spv" -s SPIRV -d MSL -t fragment -e main -o "$work/model.frag.msl"
"$glslang" -D -V -e vsMain -S vert --target-env vulkan1.0 "$here/model_vs.hlsl" -o "$work/model_vs.spv" >> "$work/glslang.log"
"$glslang" -D -V -e psMain -S frag --target-env vulkan1.0 "$here/model_ps.hlsl" -o "$work/model_ps.spv" >> "$work/glslang.log"
"$shadercross" "$work/model_vs.spv" -s SPIRV -d MSL -t vertex -e vsMain -o "$work/model_vs.msl"
"$shadercross" "$work/model_ps.spv" -s SPIRV -d MSL -t fragment -e psMain -o "$work/model_ps.msl"
glslang_version="$("$glslang" --version 2>&1 | sed -n 's/^Glslang Version: //p' | head -1)"
# The CLI has no --version; say which commit it was built from.
shadercross_version="${SHADERCROSS_COMMIT:-unrecorded}"
python3 - "$work" "$here" "$glslang_version" "$shadercross_version" <<'PY'
import os, sys
work, here, glslang_version, shadercross_version = sys.argv[1:5]
def spirv_array(name, path):
data = open(path, 'rb').read()
lines = []
for i in range(0, len(data), 16):
lines.append('\t' + ', '.join('0x%02x' % b for b in data[i:i + 16]) + ',')
return 'static const unsigned char %s[%d] = {\n%s\n};\n' % (name, len(data), '\n'.join(lines))
def text(name, path):
body = open(path).read()
assert ')MSL"' not in body
return 'static const char %s[] = R"MSL(%s)MSL";\n' % (name, body)
# SPIRV-Cross renames an entry point called main, which MSL reserves.
vert_msl = open(os.path.join(work, 'model.vert.msl')).read()
entry = 'main0' if 'main0(' in vert_msl else 'main'
out = []
out.append('// Generated by Tests/w3d_view/shaders/build_shaders.sh - do not edit. Regenerate after changing\n')
out.append('// model.vert, model.frag or model.hand.metal.\n')
out.append('// glslang %s; SDL_shadercross %s\n' % (glslang_version, shadercross_version))
out.append('#pragma once\n\n')
out.append(spirv_array('MODEL_VERT_SPIRV', os.path.join(work, 'model.vert.spv')))
out.append(spirv_array('MODEL_FRAG_SPIRV', os.path.join(work, 'model.frag.spv')))
out.append('\n// SPIRV-Cross (through SDL_shadercross) names both entry points this.\n')
out.append('static const char MODEL_MSL_ENTRY[] = "%s";\n' % entry)
out.append(text('MODEL_VERT_MSL', os.path.join(work, 'model.vert.msl')))
out.append(text('MODEL_FRAG_MSL', os.path.join(work, 'model.frag.msl')))
out.append(spirv_array('MODEL_HLSL_VS_SPIRV', os.path.join(work, 'model_vs.spv')))
out.append(spirv_array('MODEL_HLSL_PS_SPIRV', os.path.join(work, 'model_ps.spv')))
out.append(text('MODEL_HLSL_VS_MSL', os.path.join(work, 'model_vs.msl')))
out.append(text('MODEL_HLSL_PS_MSL', os.path.join(work, 'model_ps.msl')))
out.append(text('MODEL_MSL_HAND', os.path.join(here, 'model.hand.metal')))
open(os.path.join(here, 'model_shaders.h'), 'w').write(''.join(out))
for f in ('model.vert.spv', 'model.frag.spv', 'model.vert.msl', 'model.frag.msl', 'model_vs.spv', 'model_ps.spv', 'model_vs.msl', 'model_ps.msl'):
print('%-16s %6d bytes' % (f, os.path.getsize(os.path.join(work, f))))
print('model.hand.metal %6d bytes' % os.path.getsize(os.path.join(here, 'model.hand.metal')))
PY
echo "wrote $here/model_shaders.h"