Initialize transparent custom cursor samples

This commit is contained in:
ICUMADETHIS committed 2026-11-22 21:24:54 +00:00
1 parent 7f17cad783
commit 362fcfb3b7
3 files changed
+76

No files matched your search

+1
View File
@@ -62,6 +62,7 @@ static float sample(V p, float *r, float *g, float *b) {
float a = ds < -0.8f ? 1 : (0.8f - ds) / 1.6f;
return 0.38f * a;
}
*r = *g = *b = 0;
return 0;
}
+74
View File
@@ -0,0 +1,74 @@
"""The production custom cursor must not depend on uninitialized stack colours.
python tests/cursor_art_check.py --cc path/to/clang
"""
import argparse
from pathlib import Path
import shutil
import struct
import subprocess
import tempfile
ROOT = Path(__file__).resolve().parents[1]
HARNESS = r'''
#include <assert.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#ifdef _WIN32
#include <fcntl.h>
#include <io.h>
#endif
#include "input_wsys.h"
int main(int argc, char **argv) {
assert(argc == 2);
int size = atoi(argv[1]), hot;
assert(size > 0 && size <= 128);
uint32_t *pixels = malloc((size_t)size * size * sizeof *pixels);
assert(pixels);
cursor_art(pixels, size, &hot);
#ifdef _WIN32
assert(_setmode(_fileno(stdout), _O_BINARY) != -1);
#endif
assert(fwrite(&hot, sizeof hot, 1, stdout) == 1);
assert(fwrite(pixels, sizeof *pixels, (size_t)size * size, stdout) == (size_t)size * size);
free(pixels);
return 0;
}
'''
def main():
parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
parser.add_argument('--cc', default=shutil.which('clang') or r'C:\msys64\ucrt64\bin\clang.exe')
args = parser.parse_args()
with tempfile.TemporaryDirectory(prefix='cursor-art-') as temp:
work = Path(temp)
source = work / 'probe.c'
source.write_text(HARNESS, encoding='utf-8')
outputs = {}
for mode in ('zero', 'pattern'):
exe = work / f'{mode}.exe'
subprocess.run([args.cc, '-O2', '-std=gnu11', f'-ftrivial-auto-var-init={mode}',
'-I', str(ROOT / 'runtime'), str(source), str(ROOT / 'runtime/cursor_art.c'),
'-lm', '-o', str(exe)], check=True)
outputs[mode] = {}
for size in (16, 24, 32, 48, 64, 96, 128):
data = subprocess.run([str(exe), str(size)], check=True, capture_output=True).stdout
assert len(data) == 4 + size * size * 4
pixels = struct.unpack(f'<{size * size}I', data[4:])
assert any(p == 0 for p in pixels), 'the cursor must have transparent pixels'
assert any(p >> 24 and p & 0xffffff for p in pixels), 'the cursor must contain visible colour'
outputs[mode][size] = data
differences = []
for size in outputs['zero']:
a, b = outputs['zero'][size], outputs['pattern'][size]
different = sum(a[i:i + 4] != b[i:i + 4] for i in range(4, len(a), 4))
if different or a[:4] != b[:4]:
differences.append((size, different))
print(f'cursor {size}x{size}: {different} pixels differ between zero and pattern stack initialization')
assert not differences, f'cursor pixels depend on uninitialized automatic variables: {differences}'
if __name__ == '__main__':
main()
+1
View File
@@ -67,6 +67,7 @@ TESTS = {
'settings_doc_check': ('.venv', None, [], ''),
'mouse_direct_check': ('.venv', 'cc', ['--cc', '<cc>'], 'compiles its checks with clang'),
'cheats_vm_check': ('.venv', 'cc', ['--cc', '<cc>'], 'compiles runtime/cheats.c into a harness with clang'),
'cursor_art_check': ('.venv', 'cc', ['--cc', '<cc>'], 'compiles the cursor with zero and pattern stack initialization'),
'romfs_shapes_check': ('.venv', 'cc', ['--cc', '<cc>'], 'compiles the production overlay selection helpers'),
'frame_world_check': ('.venv', 'cc', ['--cc', '<cc>'], 'compiles the production world-clock player walk'),
'sync_ahead_check': ('.venv', 'cc', ['--cc', '<cc>'], 'compiles the production sync-ahead wait selection'),