Rendu OpenGL avec filtres (net, lissé, xBR, CRT) et settings.ini partagé
- gfx_gl.c/gfx.h : rendu OpenGL 3.3 core à la place de SDL_Renderer, shaders écrits pour le projet : net, lissé (sharp bilinear), xBR (contours, rendu ×4 puis mis à l'échelle), CRT (balayage, masque, courbure). - menu.c/menu.h : réglages dans settings.ini (%APPDATA%\DoubleTroubleRecomp\), clés en anglais, réécriture qui garde commentaires et clés inconnues ; options de ligne de commande valables pour la session seulement ; menu : filtre d'image et synchro verticale. - host_sdl.c : contexte GL, souris recalculée selon le cadrage, options --config --filtre --format43 --vsync --fenetre --set (--echelle et --plein inchangées). - build.bat : dossier du jeu en paramètre ou via TUCKER_CD. - docs/SETTINGS.md : clés, valeurs et options pour le launcher. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
fb630bc999
commit
84977b94aa
7 files changed
+808
-150
No files matched your search
@@ -1,14 +1,20 @@
|
||||
@echo off
|
||||
rem Compile tucker-recomp avec MSVC (Build Tools 2022).
|
||||
rem build.bat -> regenere le C (TUCKER.EXE et INTRO.EXE) puis compile build\tucker.exe et build\tucker_headless.exe
|
||||
rem build.bat nogen -> compile sans regenerer
|
||||
rem build.bat -> regenere le C (TUCKER.EXE et INTRO.EXE) puis compile build\tucker.exe et build\tucker_headless.exe
|
||||
rem build.bat DOSSIER -> idem, avec les executables du jeu pris dans DOSSIER
|
||||
rem build.bat nogen -> compile sans regenerer (C deja genere dans build\gen_tucker et build\gen_intro)
|
||||
rem Dossier du jeu : parametre, sinon variable TUCKER_CD, sinon ..\extracted\iso\TUCKER
|
||||
setlocal
|
||||
set ARG1=%~1
|
||||
cd /d "%~dp0"
|
||||
if not defined VCINSTALLDIR call "C:\Program Files (x86)\Microsoft Visual Studio\2022\BuildTools\VC\Auxiliary\Build\vcvars64.bat" >nul || exit /b 1
|
||||
set SDL=third_party\SDL2-2.32.10
|
||||
set ISO=..\extracted\iso\TUCKER
|
||||
if defined TUCKER_CD set "ISO=%TUCKER_CD%"
|
||||
if not "%ARG1%"=="" if /i not "%ARG1%"=="nogen" set "ISO=%ARG1%"
|
||||
|
||||
if /i not "%1"=="nogen" (
|
||||
if /i not "%ARG1%"=="nogen" (
|
||||
if not exist "%ISO%\TUCKER.EXE" ( echo TUCKER.EXE introuvable dans "%ISO%" & exit /b 1 )
|
||||
python -I tools\recomp.py "%ISO%\TUCKER.EXE" build\gen_tucker tucker F || exit /b 1
|
||||
python -I tools\recomp.py "%ISO%\INTRO.EXE" build\gen_intro intro I || exit /b 1
|
||||
)
|
||||
@@ -16,12 +22,12 @@ if not exist build\obj mkdir build\obj
|
||||
|
||||
set CFLAGS=/nologo /O2 /GS- /W3 /wd4146 /wd4244 /wd4018 /wd4102 /wd4101 /wd4189 /MP /utf-8 /Iruntime /Ibuild\gen_tucker /Ibuild\gen_intro /I%SDL%\include /D_CRT_SECURE_NO_WARNINGS /Fobuild\obj\
|
||||
cl %CFLAGS% /c runtime\cpu.c runtime\fpu.c runtime\loader.c runtime\dos.c runtime\machine.c runtime\audio.c runtime\ail.c runtime\menu.c runtime\overrides.c runtime\main.c build\gen_tucker\*.c build\gen_intro\*.c || exit /b 1
|
||||
cl %CFLAGS% /c runtime\host_headless.c runtime\host_sdl.c || exit /b 1
|
||||
cl %CFLAGS% /c runtime\host_headless.c runtime\host_sdl.c runtime\gfx_gl.c || exit /b 1
|
||||
|
||||
if not exist build\lib mkdir build\lib
|
||||
lib /nologo /OUT:build\lib\jeu.lib build\obj\cpu.obj build\obj\fpu.obj build\obj\loader.obj build\obj\dos.obj build\obj\machine.obj build\obj\audio.obj build\obj\ail.obj build\obj\menu.obj build\obj\overrides.obj build\obj\main.obj build\obj\tucker_*.obj build\obj\intro_*.obj || exit /b 1
|
||||
|
||||
link /nologo /STACK:67108864 /OUT:build\tucker_headless.exe build\obj\host_headless.obj build\lib\jeu.lib || exit /b 1
|
||||
link /nologo /STACK:67108864 /SUBSYSTEM:CONSOLE /OUT:build\tucker.exe build\obj\host_sdl.obj build\lib\jeu.lib %SDL%\lib\x64\SDL2.lib || exit /b 1
|
||||
link /nologo /STACK:67108864 /SUBSYSTEM:CONSOLE /OUT:build\tucker.exe build\obj\host_sdl.obj build\obj\gfx_gl.obj build\lib\jeu.lib %SDL%\lib\x64\SDL2.lib opengl32.lib || exit /b 1
|
||||
copy /y %SDL%\lib\x64\SDL2.dll build\ >nul
|
||||
echo OK : build\tucker.exe et build\tucker_headless.exe
|
||||
@@ -0,0 +1,105 @@
|
||||
# Réglages : `settings.ini` et options de ligne de commande
|
||||
|
||||
Le jeu (`build\tucker.exe`), son menu en jeu (touche **F12**) et le launcher lisent et écrivent **le même fichier**.
|
||||
|
||||
## Emplacement du fichier
|
||||
|
||||
| Système | Chemin par défaut |
|
||||
|---|---|
|
||||
| Windows | `%APPDATA%\DoubleTroubleRecomp\settings.ini` |
|
||||
| Linux / macOS | `$XDG_CONFIG_HOME/DoubleTroubleRecomp/settings.ini`, sinon `~/.config/DoubleTroubleRecomp/settings.ini` |
|
||||
|
||||
`--config FICHIER` remplace ce chemin. Le dossier est créé au premier enregistrement.
|
||||
|
||||
## Format
|
||||
|
||||
- Texte UTF-8, une clé par ligne : `cle=valeur`.
|
||||
- Les sections `[display]` et `[audio]` servent seulement à ranger. Les noms de clés sont uniques, quelle que soit la section.
|
||||
- Les lignes qui commencent par `#` ou `;` sont des commentaires.
|
||||
- Quand le jeu enregistre, il ne réécrit que la valeur de ses propres clés. L'ordre, les commentaires et les clés qu'il ne connaît pas restent intacts. Le launcher peut donc ajouter les siennes (par exemple `hd_pack`, ou une section `[mods]`) sans qu'elles soient effacées.
|
||||
- Une clé absente ou invalide prend sa valeur par défaut. Une valeur numérique hors limites est ramenée dans les limites.
|
||||
- Le jeu enregistre à la fermeture du menu F12 et après un passage en plein écran avec F11.
|
||||
|
||||
Exemple :
|
||||
|
||||
```ini
|
||||
[display]
|
||||
fullscreen=0
|
||||
window_scale=3
|
||||
filter=xbr
|
||||
aspect_43=1
|
||||
vsync=0
|
||||
|
||||
[audio]
|
||||
master_volume=100
|
||||
music_volume=80
|
||||
voice_volume=100
|
||||
sfx_volume=90
|
||||
```
|
||||
|
||||
## Clés
|
||||
|
||||
### `[display]`
|
||||
|
||||
| Clé | Valeurs | Défaut | Effet |
|
||||
|---|---|---|---|
|
||||
| `fullscreen` | `0` / `1` | `0` | Plein écran en résolution du bureau (sans changer de mode vidéo) |
|
||||
| `window_scale` | `1` à `16` | `3` | Fenêtre de `320 × N` sur `240 × N` (ou `200 × N`) pixels. Ramenée à la plus grande taille qui tient sur l'écran |
|
||||
| `filter` | `nearest`, `smooth`, `xbr`, `crt` | `nearest` | Filtre d'image (voir ci-dessous) |
|
||||
| `aspect_43` | `0` / `1` | `1` | `1` : image 320×200 étirée en 4:3, comme sur un écran VGA. `0` : pixels carrés (16:10) |
|
||||
| `vsync` | `0` / `1` | `0` | Synchronisation verticale |
|
||||
|
||||
Filtres :
|
||||
|
||||
- `nearest` : « Net » dans le menu. Pixels bruts, agrandis sans interpolation.
|
||||
- `smooth` : « Lissé ». Agrandissement entier, puis interpolation limitée à la bordure entre deux pixels. L'image reste nette, sans pixels de tailles inégales.
|
||||
- `xbr` : « xBR ». Contours adoucis par détection de contours façon xBR (shader écrit pour ce projet, rendu ×4 puis mis à l'échelle).
|
||||
- `crt` : « CRT ». Écran cathodique simulé : lignes de balayage, masque à grille, légère courbure.
|
||||
|
||||
Les booléens acceptent aussi `true`/`false` et `on`/`off`. Le jeu réécrit toujours `0`/`1`.
|
||||
|
||||
### `[audio]`
|
||||
|
||||
| Clé | Valeurs | Défaut | Effet |
|
||||
|---|---|---|---|
|
||||
| `master_volume` | `0` à `100` | `100` | Volume général |
|
||||
| `music_volume` | `0` à `100` | `100` | Musique |
|
||||
| `voice_volume` | `0` à `100` | `100` | Voix (dialogues, narration de l'intro) |
|
||||
| `sfx_volume` | `0` à `100` | `100` | Bruitages et ambiances |
|
||||
|
||||
Les volumes sont des pourcentages de curseur. Le mixeur applique une courbe quadratique pour que le curseur paraisse régulier à l'oreille.
|
||||
|
||||
## Ligne de commande
|
||||
|
||||
Les options d'affichage valent **pour la session seulement**. Elles ne sont pas écrites dans le fichier, sauf si le joueur change ensuite ce réglage dans le menu F12. Le launcher peut donc imposer une valeur au lancement sans écraser le choix fait en jeu. Pour changer un réglage durablement, il doit écrire dans `settings.ini`.
|
||||
|
||||
| Option | Équivaut à |
|
||||
|---|---|
|
||||
| `--config FICHIER` | Utiliser ce fichier de réglages |
|
||||
| `--plein` | `fullscreen=1` |
|
||||
| `--fenetre` | `fullscreen=0` |
|
||||
| `--echelle N` | `window_scale=N` |
|
||||
| `--filtre NOM` | `filter=NOM` |
|
||||
| `--format43 0\|1` | `aspect_43=0\|1` |
|
||||
| `--vsync 0\|1` | `vsync=0\|1` |
|
||||
| `--set cle=valeur` | N'importe quelle clé du tableau, par exemple `--set music_volume=50` |
|
||||
|
||||
Une option avec une valeur invalide est ignorée, et un message part sur la sortie d'erreur.
|
||||
|
||||
Autres options du jeu, inchangées :
|
||||
|
||||
- `--cd`, `--exe`, `--hd`, `--root`, `--saves` : dossiers et fichiers du jeu ;
|
||||
- `--son` ;
|
||||
- `--sans-intro` ;
|
||||
- `--intro` ;
|
||||
- `-v` : journal détaillé sur la sortie d'erreur, y compris le chemin du fichier de réglages utilisé.
|
||||
|
||||
## Compilation
|
||||
|
||||
`build.bat` accepte le dossier qui contient `TUCKER.EXE` et `INTRO.EXE` :
|
||||
|
||||
```
|
||||
build.bat dossier pris dans TUCKER_CD, sinon ..\extracted\iso\TUCKER
|
||||
build.bat D:\TUCKER dossier donné en paramètre
|
||||
build.bat nogen compile le C déjà généré dans build\gen_tucker et build\gen_intro
|
||||
```
|
||||
@@ -0,0 +1,15 @@
|
||||
/* Rendu OpenGL 3.3 : image du jeu filtrée par shaders (net, lissé, xBR, CRT) + surimpression du menu.
|
||||
* Le contexte GL doit être courant avant gfx_init (créé par l'hôte). Shaders écrits pour ce projet. */
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct { int x, y, w, h; } GfxRect; /* origine en haut à gauche, en pixels de sortie */
|
||||
|
||||
int gfx_init(void); /* 0 si OpenGL 3.3 indisponible ou shader invalide */
|
||||
void gfx_shutdown(void);
|
||||
void gfx_set_game(const uint32_t *argb, int w, int h); /* image du jeu, 0xAARRGGBB */
|
||||
void gfx_set_overlay(const uint32_t *argb, int w, int h); /* surimpression, alpha non prémultiplié */
|
||||
GfxRect gfx_fit(int out_w, int out_h, int aspect_w, int aspect_h); /* plus grand rectangle centré à ce format */
|
||||
/* dessine une image complète (sans échange de tampons) :
|
||||
* game_aspect_h = 240 (4:3) ou 200 (pixels carrés) ; veil 0..1 assombrit tout ; overlay_alpha 0 = pas de surimpression */
|
||||
void gfx_draw(int out_w, int out_h, int filter, int game_aspect_h, float veil, float overlay_alpha);
|
||||
@@ -0,0 +1,348 @@
|
||||
/* Rendu OpenGL 3.3 core (portable vers WebGL 2 / GLES 3 : mêmes shaders, autre en-tête #version).
|
||||
*
|
||||
* Passes :
|
||||
* net : un pixel source = un bloc de pixels de sortie (texelFetch)
|
||||
* lissé : « sharp bilinear » : agrandissement entier puis bilinéaire sur le reste (pas de flou, pas de pixels inégaux)
|
||||
* xBR : détection de contours façon xBR niveau 2, rendue ×4 dans une texture intermédiaire, puis « lissé »
|
||||
* CRT : lignes de balayage dont l'épaisseur dépend de la luminosité, masque à grille, légère courbure
|
||||
* Puis voile (menu) et surimpression. Toutes les couleurs passent par la palette VGA déjà convertie par l'hôte. */
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include <SDL.h>
|
||||
#include <SDL_opengl.h>
|
||||
#include "gfx.h"
|
||||
#include "menu.h"
|
||||
#include "rt.h"
|
||||
|
||||
/* ------------------------------------------------------------------ fonctions GL > 1.1 (chargées à l'exécution) */
|
||||
#define GL_FUNCS \
|
||||
X(PFNGLCREATESHADERPROC, glCreateShader) X(PFNGLSHADERSOURCEPROC, glShaderSource) \
|
||||
X(PFNGLCOMPILESHADERPROC, glCompileShader) X(PFNGLGETSHADERIVPROC, glGetShaderiv) \
|
||||
X(PFNGLGETSHADERINFOLOGPROC, glGetShaderInfoLog) X(PFNGLDELETESHADERPROC, glDeleteShader) \
|
||||
X(PFNGLCREATEPROGRAMPROC, glCreateProgram) X(PFNGLATTACHSHADERPROC, glAttachShader) \
|
||||
X(PFNGLLINKPROGRAMPROC, glLinkProgram) X(PFNGLGETPROGRAMIVPROC, glGetProgramiv) \
|
||||
X(PFNGLGETPROGRAMINFOLOGPROC, glGetProgramInfoLog) X(PFNGLDELETEPROGRAMPROC, glDeleteProgram) \
|
||||
X(PFNGLUSEPROGRAMPROC, glUseProgram) X(PFNGLGETUNIFORMLOCATIONPROC, glGetUniformLocation) \
|
||||
X(PFNGLUNIFORM1IPROC, glUniform1i) X(PFNGLUNIFORM1FPROC, glUniform1f) \
|
||||
X(PFNGLUNIFORM2FPROC, glUniform2f) X(PFNGLUNIFORM4FPROC, glUniform4f) \
|
||||
X(PFNGLGENVERTEXARRAYSPROC, glGenVertexArrays) X(PFNGLBINDVERTEXARRAYPROC, glBindVertexArray) \
|
||||
X(PFNGLDELETEVERTEXARRAYSPROC, glDeleteVertexArrays) X(PFNGLGENFRAMEBUFFERSPROC, glGenFramebuffers) \
|
||||
X(PFNGLBINDFRAMEBUFFERPROC, glBindFramebuffer) X(PFNGLFRAMEBUFFERTEXTURE2DPROC, glFramebufferTexture2D) \
|
||||
X(PFNGLCHECKFRAMEBUFFERSTATUSPROC, glCheckFramebufferStatus) X(PFNGLDELETEFRAMEBUFFERSPROC, glDeleteFramebuffers) \
|
||||
X(PFNGLACTIVETEXTUREPROC, glActiveTexture)
|
||||
|
||||
#define X(type, name) static type p_##name;
|
||||
GL_FUNCS
|
||||
#undef X
|
||||
|
||||
/* ------------------------------------------------------------------ shaders */
|
||||
static const char *VS =
|
||||
"uniform float u_flip;\n"
|
||||
"out vec2 v_uv;\n"
|
||||
"void main() {\n"
|
||||
" vec2 p = vec2(float(gl_VertexID & 1), float(gl_VertexID >> 1)) * 2.0 - 1.0;\n"
|
||||
" v_uv = vec2(p.x * 0.5 + 0.5, 0.5 - p.y * 0.5 * u_flip);\n" /* ligne 0 de la texture en haut de l'écran ; */
|
||||
/* u_flip = -1 pour une texture intermédiaire */
|
||||
" gl_Position = vec4(p, 0.0, 1.0);\n"
|
||||
"}\n";
|
||||
|
||||
#define FS_HEAD \
|
||||
"uniform sampler2D u_src;\n" \
|
||||
"uniform vec2 u_src_size;\n" \
|
||||
"uniform vec2 u_out_size;\n" \
|
||||
"uniform float u_alpha;\n" \
|
||||
"uniform vec4 u_color;\n" \
|
||||
"in vec2 v_uv;\n" \
|
||||
"out vec4 o_color;\n"
|
||||
|
||||
static const char *FS_NEAREST = FS_HEAD
|
||||
"void main() {\n"
|
||||
" ivec2 p = ivec2(clamp(floor(v_uv * u_src_size), vec2(0.0), u_src_size - 1.0));\n"
|
||||
" o_color = vec4(texelFetch(u_src, p, 0).rgb, 1.0);\n"
|
||||
"}\n";
|
||||
|
||||
/* agrandissement entier implicite, interpolation limitée à la bordure entre deux pixels source */
|
||||
static const char *FS_SMOOTH = FS_HEAD
|
||||
"void main() {\n"
|
||||
" vec2 t = v_uv * u_src_size;\n"
|
||||
" vec2 k = max(floor(u_out_size / u_src_size), vec2(1.0));\n"
|
||||
" vec2 c = fract(t) - 0.5;\n"
|
||||
" vec2 r = 0.5 - 0.5 / k;\n"
|
||||
" vec2 f = (c - clamp(c, -r, r)) * k + 0.5;\n"
|
||||
" o_color = vec4(texture(u_src, (floor(t) + f) / u_src_size).rgb, 1.0);\n"
|
||||
"}\n";
|
||||
|
||||
static const char *FS_OVERLAY = FS_HEAD
|
||||
"void main() {\n"
|
||||
" vec4 c = texture(u_src, v_uv);\n"
|
||||
" o_color = vec4(c.rgb, c.a * u_alpha);\n"
|
||||
"}\n";
|
||||
|
||||
static const char *FS_SOLID = FS_HEAD
|
||||
"void main() { o_color = u_color; }\n";
|
||||
|
||||
/* Contours façon xBR (niveau 2) : pour chacun des 4 coins du pixel E, on compare deux sommes pondérées de
|
||||
* différences de couleur le long des deux diagonales ; si le contour traverse le coin, on mélange E avec
|
||||
* le voisin le plus proche, suivant une droite à 45°, ou à 30°/60° quand le contour se prolonge. */
|
||||
static const char *FS_XBR = FS_HEAD
|
||||
"vec3 Y[25];\n"
|
||||
"vec3 P[25];\n"
|
||||
"vec3 yuv(vec3 c) {\n"
|
||||
" return vec3(dot(c, vec3(0.299, 0.587, 0.114)), dot(c, vec3(-0.169, -0.331, 0.5)), dot(c, vec3(0.5, -0.419, -0.081)));\n"
|
||||
"}\n"
|
||||
"float df(int a, int b) { vec3 d = abs(Y[a] - Y[b]); return 48.0 * d.x + 7.0 * d.y + 6.0 * d.z; }\n"
|
||||
"bool eq(int a, int b) { return df(a, b) < 1.5; }\n"
|
||||
"ivec2 AX, AY;\n"
|
||||
"int at(int a, int b) { ivec2 d = a * AX + b * AY; return (d.x + 2) + (d.y + 2) * 5; }\n"
|
||||
"void main() {\n"
|
||||
" vec2 t = v_uv * u_src_size;\n"
|
||||
" ivec2 base = ivec2(floor(t));\n"
|
||||
" vec2 q = fract(t) - 0.5;\n"
|
||||
" vec2 pw = fwidth(t);\n"
|
||||
" float w = max(pw.x, pw.y) * 0.75 + 0.02;\n"
|
||||
" ivec2 mx = ivec2(u_src_size) - 1;\n"
|
||||
" for (int j = -2; j <= 2; j++)\n"
|
||||
" for (int i = -2; i <= 2; i++) {\n"
|
||||
" int k = (i + 2) + (j + 2) * 5;\n"
|
||||
" P[k] = texelFetch(u_src, clamp(base + ivec2(i, j), ivec2(0), mx), 0).rgb;\n"
|
||||
" Y[k] = yuv(P[k]);\n"
|
||||
" }\n"
|
||||
" vec3 res = P[12];\n"
|
||||
" for (int r = 0; r < 4; r++) {\n"
|
||||
" if (r == 0) { AX = ivec2(1, 0); AY = ivec2(0, 1); }\n"
|
||||
" else if (r == 1) { AX = ivec2(0, 1); AY = ivec2(-1, 0); }\n"
|
||||
" else if (r == 2) { AX = ivec2(-1, 0); AY = ivec2(0, -1); }\n"
|
||||
" else { AX = ivec2(0, -1); AY = ivec2(1, 0); }\n"
|
||||
" vec2 fp = vec2(dot(q, vec2(AX)), dot(q, vec2(AY))) + 0.5;\n" /* repère du coin bas-droit */
|
||||
" int E = 12, F = at(1, 0), H = at(0, 1), I = at(1, 1), B = at(0, -1), D = at(-1, 0);\n"
|
||||
" int C = at(1, -1), G = at(-1, 1), F4 = at(2, 0), I4 = at(2, 1), H5 = at(0, 2), I5 = at(1, 2);\n"
|
||||
" bool lv1 = !eq(E, F) && !eq(E, H) &&\n"
|
||||
" ((!eq(F, B) && !eq(H, D)) || (eq(E, I) && !eq(F, I4) && !eq(H, I5)) || eq(E, G) || eq(E, C));\n"
|
||||
" float wd1 = df(E, C) + df(E, G) + df(I, F4) + df(I, H5) + 4.0 * df(H, F);\n"
|
||||
" float wd2 = df(H, D) + df(H, I5) + df(F, I4) + df(F, B) + 4.0 * df(E, I);\n"
|
||||
" bool edr = wd1 < wd2 && lv1;\n"
|
||||
" if (!edr) continue;\n"
|
||||
" bool left = 2.0 * df(F, G) <= df(H, C) && !eq(E, G) && !eq(D, G);\n"
|
||||
" bool up = df(F, G) >= 2.0 * df(H, C) && !eq(E, C) && !eq(B, C);\n"
|
||||
" float a = smoothstep(1.5 - w, 1.5 + w, fp.x + fp.y);\n"
|
||||
" if (left) a = max(a, smoothstep(1.0 - w, 1.0 + w, 0.5 * fp.x + fp.y));\n"
|
||||
" if (up) a = max(a, smoothstep(1.0 - w, 1.0 + w, fp.x + 0.5 * fp.y));\n"
|
||||
" vec3 px = df(E, F) <= df(E, H) ? P[F] : P[H];\n"
|
||||
" res = mix(res, px, a);\n"
|
||||
" }\n"
|
||||
" o_color = vec4(res, 1.0);\n"
|
||||
"}\n";
|
||||
|
||||
/* Écran cathodique : calcul en lumière linéaire, deux lignes source voisines dont le faisceau (gaussien)
|
||||
* s'élargit avec la luminosité, filtrage horizontal doux, masque à grille si la résolution le permet. */
|
||||
static const char *FS_CRT = FS_HEAD
|
||||
"vec3 lin(vec3 c) { return c * c * (c * 0.3 + 0.7); }\n" /* ~gamma 2.4, rapide */
|
||||
"vec3 row(float y, float x) {\n"
|
||||
" float xc = floor(x - 0.5), f = x - 0.5 - xc;\n"
|
||||
" vec3 c = vec3(0.0); float ws = 0.0;\n"
|
||||
" for (int i = -1; i <= 2; i++) {\n"
|
||||
" float d = float(i) - f, wt = exp(-2.5 * d * d);\n"
|
||||
" ivec2 p = ivec2(clamp(xc + float(i), 0.0, u_src_size.x - 1.0), clamp(y, 0.0, u_src_size.y - 1.0));\n"
|
||||
" c += lin(texelFetch(u_src, p, 0).rgb) * wt; ws += wt;\n"
|
||||
" }\n"
|
||||
" return c / ws;\n"
|
||||
"}\n"
|
||||
"vec3 beam(float d, vec3 c) {\n"
|
||||
" vec3 s = mix(vec3(0.27), vec3(0.42), clamp(c * 1.4, 0.0, 1.0));\n"
|
||||
" vec3 z = d / s;\n"
|
||||
" return exp(-0.5 * z * z);\n"
|
||||
"}\n"
|
||||
"void main() {\n"
|
||||
" vec2 c = v_uv * 2.0 - 1.0;\n"
|
||||
" c *= vec2(1.0 + c.y * c.y * 0.025, 1.0 + c.x * c.x * 0.035);\n"
|
||||
" vec2 uv = c * 0.5 + 0.5;\n"
|
||||
" if (uv.x < 0.0 || uv.y < 0.0 || uv.x > 1.0 || uv.y > 1.0) { o_color = vec4(0.0, 0.0, 0.0, 1.0); return; }\n"
|
||||
" vec2 t = uv * u_src_size;\n"
|
||||
" float y = t.y - 0.5, y0 = floor(y), dy = y - y0;\n"
|
||||
" vec3 c0 = row(y0, t.x), c1 = row(y0 + 1.0, t.x);\n"
|
||||
" vec3 col = c0 * beam(dy, c0) + c1 * beam(1.0 - dy, c1);\n"
|
||||
" if (u_out_size.x / u_src_size.x >= 2.5) {\n"
|
||||
" int m = int(mod(gl_FragCoord.x, 3.0));\n"
|
||||
" vec3 mk = vec3(0.78);\n"
|
||||
" mk[m] = 1.22;\n"
|
||||
" col *= mk;\n"
|
||||
" }\n"
|
||||
" col *= 1.35;\n"
|
||||
" vec2 e = smoothstep(vec2(0.0), vec2(0.012), uv) * smoothstep(vec2(0.0), vec2(0.012), 1.0 - uv);\n"
|
||||
" col *= e.x * e.y;\n"
|
||||
" o_color = vec4(sqrt(clamp(col, 0.0, 1.0)), 1.0);\n"
|
||||
"}\n";
|
||||
|
||||
/* ------------------------------------------------------------------ état */
|
||||
enum { PG_NEAREST, PG_SMOOTH, PG_XBR, PG_CRT, PG_OVERLAY, PG_SOLID, PG_COUNT };
|
||||
typedef struct { GLuint id; GLint src, src_size, out_size, alpha, color, flip; } Prog;
|
||||
static float pass_flip = 1.f; /* -1 : la cible est une texture intermédiaire (lue ensuite à l'endroit) */
|
||||
static Prog prog[PG_COUNT];
|
||||
static GLuint vao, tex_game, tex_ovl, tex_xbr, fbo_xbr;
|
||||
static int game_w = 320, game_h = 200;
|
||||
#define XBR_SCALE 4
|
||||
|
||||
static GLuint compile(GLenum type, const char *body) {
|
||||
const char *src[2] = {"#version 330 core\nprecision highp float;\n", body};
|
||||
GLuint s = p_glCreateShader(type);
|
||||
GLint ok = 0;
|
||||
p_glShaderSource(s, 2, src, NULL);
|
||||
p_glCompileShader(s);
|
||||
p_glGetShaderiv(s, GL_COMPILE_STATUS, &ok);
|
||||
if (!ok) {
|
||||
char log[2048];
|
||||
p_glGetShaderInfoLog(s, sizeof log, NULL, log);
|
||||
fprintf(stderr, "[gfx] shader : %s\n", log);
|
||||
p_glDeleteShader(s);
|
||||
return 0;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
static int make_prog(Prog *p, const char *fs) {
|
||||
GLuint v = compile(GL_VERTEX_SHADER, VS), f = compile(GL_FRAGMENT_SHADER, fs);
|
||||
GLint ok = 0;
|
||||
if (!v || !f) return 0;
|
||||
p->id = p_glCreateProgram();
|
||||
p_glAttachShader(p->id, v);
|
||||
p_glAttachShader(p->id, f);
|
||||
p_glLinkProgram(p->id);
|
||||
p_glDeleteShader(v);
|
||||
p_glDeleteShader(f);
|
||||
p_glGetProgramiv(p->id, GL_LINK_STATUS, &ok);
|
||||
if (!ok) {
|
||||
char log[2048];
|
||||
p_glGetProgramInfoLog(p->id, sizeof log, NULL, log);
|
||||
fprintf(stderr, "[gfx] programme : %s\n", log);
|
||||
return 0;
|
||||
}
|
||||
p->src = p_glGetUniformLocation(p->id, "u_src");
|
||||
p->src_size = p_glGetUniformLocation(p->id, "u_src_size");
|
||||
p->out_size = p_glGetUniformLocation(p->id, "u_out_size");
|
||||
p->alpha = p_glGetUniformLocation(p->id, "u_alpha");
|
||||
p->color = p_glGetUniformLocation(p->id, "u_color");
|
||||
p->flip = p_glGetUniformLocation(p->id, "u_flip");
|
||||
return 1;
|
||||
}
|
||||
|
||||
static GLuint make_tex(int w, int h, GLint filter) {
|
||||
GLuint t;
|
||||
glGenTextures(1, &t);
|
||||
glBindTexture(GL_TEXTURE_2D, t);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, filter);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, filter);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
|
||||
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
|
||||
glTexImage2D(GL_TEXTURE_2D, 0, GL_RGBA8, w, h, 0, GL_BGRA, GL_UNSIGNED_BYTE, NULL);
|
||||
return t;
|
||||
}
|
||||
|
||||
int gfx_init(void) {
|
||||
const char *const fs[PG_COUNT] = {FS_NEAREST, FS_SMOOTH, FS_XBR, FS_CRT, FS_OVERLAY, FS_SOLID};
|
||||
int i;
|
||||
#define X(type, name) \
|
||||
if (!(p_##name = (type)SDL_GL_GetProcAddress(#name))) { fprintf(stderr, "[gfx] fonction GL absente : %s\n", #name); return 0; }
|
||||
GL_FUNCS
|
||||
#undef X
|
||||
for (i = 0; i < PG_COUNT; i++)
|
||||
if (!make_prog(&prog[i], fs[i])) { fprintf(stderr, "[gfx] shader %d invalide\n", i); return 0; }
|
||||
p_glGenVertexArrays(1, &vao);
|
||||
tex_game = make_tex(game_w, game_h, GL_LINEAR);
|
||||
tex_ovl = make_tex(MENU_W, MENU_H, GL_LINEAR);
|
||||
tex_xbr = make_tex(game_w * XBR_SCALE, game_h * XBR_SCALE, GL_LINEAR);
|
||||
p_glGenFramebuffers(1, &fbo_xbr);
|
||||
p_glBindFramebuffer(GL_FRAMEBUFFER, fbo_xbr);
|
||||
p_glFramebufferTexture2D(GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, tex_xbr, 0);
|
||||
if (p_glCheckFramebufferStatus(GL_FRAMEBUFFER) != GL_FRAMEBUFFER_COMPLETE) {
|
||||
fprintf(stderr, "[gfx] tampon intermédiaire incomplet\n");
|
||||
return 0;
|
||||
}
|
||||
p_glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
glPixelStorei(GL_UNPACK_ALIGNMENT, 4);
|
||||
if (rt_cfg.verbose) fprintf(stderr, "[gfx] OpenGL %s, %s\n", glGetString(GL_VERSION), glGetString(GL_RENDERER));
|
||||
return 1;
|
||||
}
|
||||
|
||||
void gfx_shutdown(void) {
|
||||
int i;
|
||||
if (!p_glDeleteProgram) return;
|
||||
for (i = 0; i < PG_COUNT; i++) if (prog[i].id) p_glDeleteProgram(prog[i].id);
|
||||
if (fbo_xbr) p_glDeleteFramebuffers(1, &fbo_xbr);
|
||||
if (tex_game) glDeleteTextures(1, &tex_game);
|
||||
if (tex_ovl) glDeleteTextures(1, &tex_ovl);
|
||||
if (tex_xbr) glDeleteTextures(1, &tex_xbr);
|
||||
if (vao) p_glDeleteVertexArrays(1, &vao);
|
||||
}
|
||||
|
||||
void gfx_set_game(const uint32_t *argb, int w, int h) {
|
||||
glBindTexture(GL_TEXTURE_2D, tex_game);
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_BGRA, GL_UNSIGNED_BYTE, argb);
|
||||
}
|
||||
|
||||
void gfx_set_overlay(const uint32_t *argb, int w, int h) {
|
||||
glBindTexture(GL_TEXTURE_2D, tex_ovl);
|
||||
glTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, w, h, GL_BGRA, GL_UNSIGNED_BYTE, argb);
|
||||
}
|
||||
|
||||
GfxRect gfx_fit(int out_w, int out_h, int aw, int ah) {
|
||||
GfxRect r;
|
||||
if ((long long)out_w * ah > (long long)out_h * aw) { r.h = out_h; r.w = (int)((long long)out_h * aw / ah); }
|
||||
else { r.w = out_w; r.h = (int)((long long)out_w * ah / aw); }
|
||||
r.x = (out_w - r.w) / 2;
|
||||
r.y = (out_h - r.h) / 2;
|
||||
return r;
|
||||
}
|
||||
|
||||
/* une passe : texture tex (sw × sh) → rectangle r de la cible courante (hauteur totale out_h) */
|
||||
static void pass(const Prog *p, GLuint tex, int sw, int sh, GfxRect r, int out_h) {
|
||||
glViewport(r.x, out_h - r.y - r.h, r.w, r.h);
|
||||
p_glUseProgram(p->id);
|
||||
p_glActiveTexture(GL_TEXTURE0);
|
||||
glBindTexture(GL_TEXTURE_2D, tex);
|
||||
if (p->src >= 0) p_glUniform1i(p->src, 0);
|
||||
if (p->src_size >= 0) p_glUniform2f(p->src_size, (float)sw, (float)sh);
|
||||
if (p->out_size >= 0) p_glUniform2f(p->out_size, (float)r.w, (float)r.h);
|
||||
if (p->flip >= 0) p_glUniform1f(p->flip, pass_flip);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
}
|
||||
|
||||
void gfx_draw(int out_w, int out_h, int filter, int game_aspect_h, float veil, float overlay_alpha) {
|
||||
GfxRect g = gfx_fit(out_w, out_h, 320, game_aspect_h);
|
||||
p_glBindVertexArray(vao);
|
||||
glDisable(GL_BLEND);
|
||||
p_glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
glViewport(0, 0, out_w, out_h);
|
||||
glClearColor(0, 0, 0, 1);
|
||||
glClear(GL_COLOR_BUFFER_BIT);
|
||||
switch (filter) {
|
||||
case FILTER_SMOOTH: pass(&prog[PG_SMOOTH], tex_game, game_w, game_h, g, out_h); break;
|
||||
case FILTER_CRT: pass(&prog[PG_CRT], tex_game, game_w, game_h, g, out_h); break;
|
||||
case FILTER_XBR: {
|
||||
GfxRect f = {0, 0, game_w * XBR_SCALE, game_h * XBR_SCALE};
|
||||
p_glBindFramebuffer(GL_FRAMEBUFFER, fbo_xbr);
|
||||
pass_flip = -1.f;
|
||||
pass(&prog[PG_XBR], tex_game, game_w, game_h, f, f.h);
|
||||
pass_flip = 1.f;
|
||||
p_glBindFramebuffer(GL_FRAMEBUFFER, 0);
|
||||
pass(&prog[PG_SMOOTH], tex_xbr, f.w, f.h, g, out_h);
|
||||
break;
|
||||
}
|
||||
default: pass(&prog[PG_NEAREST], tex_game, game_w, game_h, g, out_h); break;
|
||||
}
|
||||
if (veil > 0 || overlay_alpha > 0) {
|
||||
glEnable(GL_BLEND);
|
||||
glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA);
|
||||
}
|
||||
if (veil > 0) {
|
||||
GfxRect all = {0, 0, out_w, out_h};
|
||||
p_glUseProgram(prog[PG_SOLID].id);
|
||||
p_glUniform4f(prog[PG_SOLID].color, 6 / 255.f, 3 / 255.f, 18 / 255.f, veil);
|
||||
glViewport(0, 0, all.w, all.h);
|
||||
glDrawArrays(GL_TRIANGLE_STRIP, 0, 4);
|
||||
}
|
||||
if (overlay_alpha > 0) {
|
||||
p_glUseProgram(prog[PG_OVERLAY].id);
|
||||
p_glUniform1f(prog[PG_OVERLAY].alpha, overlay_alpha);
|
||||
pass(&prog[PG_OVERLAY], tex_ovl, MENU_W, MENU_H, gfx_fit(out_w, out_h, 4, 3), out_h);
|
||||
}
|
||||
}
|
||||
+120
-83
@@ -1,9 +1,9 @@
|
||||
/* Hôte SDL2 : fenêtre, temps réel, souris, clavier, menu de réglages.
|
||||
* --echelle N taille de la fenêtre (défaut 3 → 960×720)
|
||||
* --plein démarre en plein écran
|
||||
/* Hôte SDL2 + OpenGL 3.3 : fenêtre, temps réel, souris, clavier, son, menu de réglages.
|
||||
* F12 : menu de réglages (le jeu est en pause) ; F11 ou Alt+Entrée : plein écran ; fermer la fenêtre : quitter.
|
||||
* Réglages enregistrés dans <saves>/reglages.ini ; les options de la ligne de commande priment.
|
||||
* Par défaut l'image 320×200 est affichée au format 4:3 (pixels plus hauts que larges, comme sur un écran VGA). */
|
||||
* Réglages lus et écrits dans settings.ini (%APPDATA%\DoubleTroubleRecomp\ par défaut, ou --config FICHIER),
|
||||
* partagé avec le launcher. Options d'affichage en ligne de commande (valables pour la session, voir docs/SETTINGS.md) :
|
||||
* --echelle N --plein --fenetre --filtre nearest|smooth|xbr|crt --format43 0|1 --vsync 0|1
|
||||
* --set cle=valeur --config FICHIER */
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
@@ -12,16 +12,16 @@
|
||||
#include "cpu.h"
|
||||
#include "rt.h"
|
||||
#include "menu.h"
|
||||
#include "gfx.h"
|
||||
|
||||
int host_quit;
|
||||
static SDL_Window *win;
|
||||
static SDL_Renderer *ren;
|
||||
static SDL_Texture *tex, *ovl; /* image du jeu ; surimpression (menu, bulle d'aide) */
|
||||
static uint32_t *ovl_px;
|
||||
static SDL_GLContext glctx;
|
||||
static uint32_t *ovl_px; /* surimpression : menu ou bulle d'aide */
|
||||
static SDL_AudioDeviceID adev;
|
||||
static uint64_t t0, freq, toast_t0;
|
||||
static int mx = 160, my = 100, mb;
|
||||
static int game_h = 240; /* hauteur logique : 240 (4:3) ou 200 (pixels carrés) */
|
||||
static int game_h = 240; /* format affiché : 240 (4:3) ou 200 (pixels carrés) */
|
||||
static int swallow_esc_up; /* Échap a fermé le menu : son relâchement ne va pas au jeu */
|
||||
static char cfg_path[600];
|
||||
static uint64_t press_until[3]; /* un appui reste visible au moins 80 ms : le jeu lit l'état des boutons à chaque image */
|
||||
@@ -94,62 +94,119 @@ static int max_scale(void) {
|
||||
|
||||
/* applique settings à la fenêtre ; ne redimensionne que si l'échelle ou le format ont changé */
|
||||
static void apply_display(void) {
|
||||
static int done_scale = -1, done_fmt = -1, done_full = -1;
|
||||
static int done_scale = -1, done_fmt = -1, done_full = -1, done_vsync = -1;
|
||||
int full = (SDL_GetWindowFlags(win) & SDL_WINDOW_FULLSCREEN_DESKTOP) != 0;
|
||||
game_h = settings.format_43 ? 240 : 200;
|
||||
if (full != settings.plein_ecran) SDL_SetWindowFullscreen(win, settings.plein_ecran ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
|
||||
if (!settings.plein_ecran && (settings.echelle != done_scale || settings.format_43 != done_fmt || done_full == 1)) {
|
||||
SDL_SetWindowSize(win, 320 * settings.echelle, game_h * settings.echelle);
|
||||
game_h = settings.aspect_43 ? 240 : 200;
|
||||
if (full != settings.fullscreen) SDL_SetWindowFullscreen(win, settings.fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0);
|
||||
if (!settings.fullscreen && (settings.window_scale != done_scale || settings.aspect_43 != done_fmt || done_full == 1)) {
|
||||
SDL_SetWindowSize(win, 320 * settings.window_scale, game_h * settings.window_scale);
|
||||
SDL_SetWindowPosition(win, SDL_WINDOWPOS_CENTERED, SDL_WINDOWPOS_CENTERED);
|
||||
}
|
||||
done_scale = settings.echelle; done_fmt = settings.format_43; done_full = settings.plein_ecran;
|
||||
SDL_SetTextureScaleMode(tex, settings.lissage ? SDL_ScaleModeLinear : SDL_ScaleModeNearest);
|
||||
SDL_RenderSetLogicalSize(ren, 320, game_h);
|
||||
if (settings.vsync != done_vsync) SDL_GL_SetSwapInterval(settings.vsync ? 1 : 0);
|
||||
done_scale = settings.window_scale; done_fmt = settings.aspect_43; done_full = settings.fullscreen;
|
||||
done_vsync = settings.vsync;
|
||||
}
|
||||
|
||||
/* surimpression : repère 4:3 de MENU_W × MENU_H, quel que soit le format du jeu */
|
||||
static void draw_overlay(int alpha) {
|
||||
SDL_RenderSetLogicalSize(ren, MENU_W, MENU_H);
|
||||
SDL_SetTextureAlphaMod(ovl, (Uint8)alpha);
|
||||
SDL_RenderCopy(ren, ovl, NULL, NULL);
|
||||
SDL_RenderSetLogicalSize(ren, 320, game_h);
|
||||
/* taille de la zone de dessin, et rapport pixels de dessin / coordonnées de la souris */
|
||||
static void out_size(int *w, int *h, float *k) {
|
||||
int ww, wh;
|
||||
SDL_GL_GetDrawableSize(win, w, h);
|
||||
SDL_GetWindowSize(win, &ww, &wh);
|
||||
*k = ww > 0 ? (float)*w / (float)ww : 1.f;
|
||||
}
|
||||
|
||||
/* position de la souris (coordonnées fenêtre) → repère d'un rectangle de taille logique lw × lh */
|
||||
static void to_rect(int ex, int ey, GfxRect r, int lw, int lh, int *x, int *y) {
|
||||
int w, h;
|
||||
float k;
|
||||
out_size(&w, &h, &k);
|
||||
*x = r.w > 0 ? (int)((ex * k - r.x) * lw / r.w) : 0;
|
||||
*y = r.h > 0 ? (int)((ey * k - r.y) * lh / r.h) : 0;
|
||||
}
|
||||
|
||||
static void game_mouse(int ex, int ey) {
|
||||
int w, h;
|
||||
float k;
|
||||
out_size(&w, &h, &k);
|
||||
to_rect(ex, ey, gfx_fit(w, h, 320, game_h), 320, 200, &mx, &my);
|
||||
}
|
||||
|
||||
static void menu_mouse_pos(int ex, int ey, int *x, int *y) {
|
||||
int w, h;
|
||||
float k;
|
||||
out_size(&w, &h, &k);
|
||||
to_rect(ex, ey, gfx_fit(w, h, 4, 3), MENU_W, MENU_H, x, y);
|
||||
}
|
||||
|
||||
static void present(float veil, float overlay_alpha) {
|
||||
int w, h;
|
||||
float k;
|
||||
out_size(&w, &h, &k);
|
||||
gfx_draw(w, h, settings.filter, game_h, veil, overlay_alpha);
|
||||
SDL_GL_SwapWindow(win);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ ligne de commande */
|
||||
static void usage_option(const char *opt, const char *val) {
|
||||
fprintf(stderr, "option ignorée : %s %s (voir docs/SETTINGS.md)\n", opt, val ? val : "");
|
||||
}
|
||||
|
||||
static void parse_options(int argc, char **argv) {
|
||||
int i;
|
||||
for (i = 1; i < argc; i++) {
|
||||
const char *a = argv[i], *v = i + 1 < argc ? argv[i + 1] : NULL;
|
||||
if (!strcmp(a, "--plein")) settings_override("fullscreen", "1");
|
||||
else if (!strcmp(a, "--fenetre")) settings_override("fullscreen", "0");
|
||||
else if (!strcmp(a, "--echelle") && v) { if (!settings_override("window_scale", v)) usage_option(a, v); i++; }
|
||||
else if (!strcmp(a, "--filtre") && v) { if (!settings_override("filter", v)) usage_option(a, v); i++; }
|
||||
else if (!strcmp(a, "--format43") && v) { if (!settings_override("aspect_43", v)) usage_option(a, v); i++; }
|
||||
else if (!strcmp(a, "--vsync") && v) { if (!settings_override("vsync", v)) usage_option(a, v); i++; }
|
||||
else if (!strcmp(a, "--set") && v) { /* --set cle=valeur, pour n'importe quelle clé */
|
||||
char kv[128], *eq;
|
||||
snprintf(kv, sizeof kv, "%s", v);
|
||||
eq = strchr(kv, '=');
|
||||
if (eq) *eq = 0;
|
||||
if (!eq || !settings_override(kv, eq + 1)) usage_option(a, v);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ cycle de vie */
|
||||
int host_init(int argc, char **argv) {
|
||||
int i, scale = 0, full = 0;
|
||||
for (i = 1; i < argc; i++) {
|
||||
if (!strcmp(argv[i], "--echelle") && i + 1 < argc) scale = atoi(argv[i + 1]);
|
||||
else if (!strcmp(argv[i], "--plein")) full = 1;
|
||||
}
|
||||
int i;
|
||||
const char *cfg = NULL;
|
||||
for (i = 1; i + 1 < argc; i++) if (!strcmp(argv[i], "--config")) cfg = argv[i + 1];
|
||||
snprintf(cfg_path, sizeof cfg_path, "%s", cfg ? cfg : settings_default_path());
|
||||
settings_defaults();
|
||||
snprintf(cfg_path, sizeof cfg_path, "%s/reglages.ini", rt_cfg.save_dir);
|
||||
settings_load(cfg_path);
|
||||
if (scale >= 1) settings.echelle = scale;
|
||||
if (full) settings.plein_ecran = 1;
|
||||
parse_options(argc, argv);
|
||||
settings_apply_audio();
|
||||
if (rt_cfg.verbose) fprintf(stderr, "[réglages] %s\n", cfg_path);
|
||||
|
||||
SDL_SetMainReady();
|
||||
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER | SDL_INIT_AUDIO) != 0) {
|
||||
fprintf(stderr, "SDL : %s\n", SDL_GetError());
|
||||
return 0;
|
||||
}
|
||||
SDL_SetHint(SDL_HINT_RENDER_SCALE_QUALITY, "0");
|
||||
if (settings.echelle > max_scale()) settings.echelle = max_scale();
|
||||
game_h = settings.format_43 ? 240 : 200;
|
||||
if (settings.window_scale > max_scale()) settings.window_scale = max_scale();
|
||||
game_h = settings.aspect_43 ? 240 : 200;
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MAJOR_VERSION, 3);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_MINOR_VERSION, 3);
|
||||
SDL_GL_SetAttribute(SDL_GL_CONTEXT_PROFILE_MASK, SDL_GL_CONTEXT_PROFILE_CORE);
|
||||
SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);
|
||||
win = SDL_CreateWindow("Bud Tucker in Double Trouble (recomp) — F12 : réglages", SDL_WINDOWPOS_CENTERED,
|
||||
SDL_WINDOWPOS_CENTERED, 320 * settings.echelle, game_h * settings.echelle,
|
||||
SDL_WINDOW_RESIZABLE | (settings.plein_ecran ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0));
|
||||
ren = win ? SDL_CreateRenderer(win, -1, SDL_RENDERER_ACCELERATED) : NULL;
|
||||
if (!ren) { fprintf(stderr, "SDL : %s\n", SDL_GetError()); return 0; }
|
||||
tex = SDL_CreateTexture(ren, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, 320, 200);
|
||||
ovl = SDL_CreateTexture(ren, SDL_PIXELFORMAT_ARGB8888, SDL_TEXTUREACCESS_STREAMING, MENU_W, MENU_H);
|
||||
SDL_WINDOWPOS_CENTERED, 320 * settings.window_scale, game_h * settings.window_scale,
|
||||
SDL_WINDOW_OPENGL | SDL_WINDOW_RESIZABLE | SDL_WINDOW_ALLOW_HIGHDPI |
|
||||
(settings.fullscreen ? SDL_WINDOW_FULLSCREEN_DESKTOP : 0));
|
||||
glctx = win ? SDL_GL_CreateContext(win) : NULL;
|
||||
if (!glctx) { fprintf(stderr, "OpenGL 3.3 indisponible : %s\n", SDL_GetError()); return 0; }
|
||||
if (!gfx_init()) { fprintf(stderr, "initialisation du rendu OpenGL impossible\n"); return 0; }
|
||||
ovl_px = (uint32_t *)malloc((size_t)MENU_W * MENU_H * 4);
|
||||
if (!tex || !ovl || !ovl_px) { fprintf(stderr, "SDL : %s\n", SDL_GetError()); return 0; }
|
||||
SDL_SetTextureBlendMode(ovl, SDL_BLENDMODE_BLEND);
|
||||
SDL_SetTextureScaleMode(ovl, SDL_ScaleModeLinear);
|
||||
if (!ovl_px) return 0;
|
||||
apply_display();
|
||||
menu_draw_toast(ovl_px, "F12 : réglages");
|
||||
SDL_UpdateTexture(ovl, NULL, ovl_px, MENU_W * 4);
|
||||
gfx_set_overlay(ovl_px, MENU_W, MENU_H);
|
||||
SDL_ShowCursor(SDL_DISABLE); /* le jeu dessine son propre curseur */
|
||||
{
|
||||
SDL_AudioSpec want, got;
|
||||
@@ -167,10 +224,9 @@ int host_init(int argc, char **argv) {
|
||||
|
||||
void host_shutdown(void) {
|
||||
if (adev) SDL_CloseAudioDevice(adev);
|
||||
if (ovl) SDL_DestroyTexture(ovl);
|
||||
gfx_shutdown();
|
||||
free(ovl_px);
|
||||
if (tex) SDL_DestroyTexture(tex);
|
||||
if (ren) SDL_DestroyRenderer(ren);
|
||||
if (glctx) SDL_GL_DeleteContext(glctx);
|
||||
if (win) SDL_DestroyWindow(win);
|
||||
SDL_Quit();
|
||||
}
|
||||
@@ -181,30 +237,23 @@ uint64_t host_time_us(void) {
|
||||
|
||||
/* ------------------------------------------------------------------ image */
|
||||
void host_frame(void) {
|
||||
static uint32_t px[320 * 200];
|
||||
uint32_t pal[256];
|
||||
void *pixels;
|
||||
int pitch, x, y, i;
|
||||
const uint8_t *src = M + VGA_BASE;
|
||||
float toast = 0;
|
||||
int i;
|
||||
for (i = 0; i < 256; i++) {
|
||||
uint32_t r = vga_dac[i * 3] & 63, g = vga_dac[i * 3 + 1] & 63, b = vga_dac[i * 3 + 2] & 63;
|
||||
pal[i] = 0xff000000u | (r << 2 | r >> 4) << 16 | (g << 2 | g >> 4) << 8 | (b << 2 | b >> 4);
|
||||
}
|
||||
if (SDL_LockTexture(tex, NULL, &pixels, &pitch) == 0) {
|
||||
const uint8_t *src = M + VGA_BASE;
|
||||
for (y = 0; y < 200; y++) {
|
||||
uint32_t *dst = (uint32_t *)((uint8_t *)pixels + y * pitch);
|
||||
for (x = 0; x < 320; x++) dst[x] = pal[src[y * 320 + x]];
|
||||
}
|
||||
SDL_UnlockTexture(tex);
|
||||
}
|
||||
SDL_SetRenderDrawColor(ren, 0, 0, 0, 255);
|
||||
SDL_RenderClear(ren);
|
||||
SDL_RenderCopy(ren, tex, NULL, NULL);
|
||||
for (i = 0; i < 320 * 200; i++) px[i] = pal[src[i]];
|
||||
gfx_set_game(px, 320, 200);
|
||||
if (toast_t0) { /* bulle « F12 : réglages » : 4 s, puis fondu d'1 s */
|
||||
double t = (double)(SDL_GetPerformanceCounter() - toast_t0) / (double)freq;
|
||||
if (t >= 5.0) toast_t0 = 0;
|
||||
else draw_overlay(t < 4.0 ? 255 : (int)(255 * (5.0 - t)));
|
||||
else toast = t < 4.0 ? 1.f : (float)(5.0 - t);
|
||||
}
|
||||
SDL_RenderPresent(ren);
|
||||
present(0, toast);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------ menu de réglages (modal : le jeu est en pause) */
|
||||
@@ -214,17 +263,9 @@ static int is_fullscreen_key(const SDL_KeyboardEvent *k) {
|
||||
}
|
||||
|
||||
static void menu_render(void) {
|
||||
SDL_Rect game;
|
||||
menu_draw(ovl_px);
|
||||
SDL_UpdateTexture(ovl, NULL, ovl_px, MENU_W * 4);
|
||||
SDL_RenderSetLogicalSize(ren, MENU_W, MENU_H); /* souris du menu dans ce repère */
|
||||
game.x = 0; game.w = MENU_W; game.h = MENU_W * game_h / 320; game.y = (MENU_H - game.h) / 2;
|
||||
SDL_SetRenderDrawColor(ren, 0, 0, 0, 255);
|
||||
SDL_RenderClear(ren);
|
||||
SDL_RenderCopy(ren, tex, NULL, &game); /* dernière image du jeu, figée */
|
||||
SDL_SetTextureAlphaMod(ovl, 255);
|
||||
SDL_RenderCopy(ren, ovl, NULL, NULL);
|
||||
SDL_RenderPresent(ren);
|
||||
gfx_set_overlay(ovl_px, MENU_W, MENU_H);
|
||||
present(0.55f, 1.f); /* dernière image du jeu, figée, sous un voile */
|
||||
}
|
||||
|
||||
static void menu_modal(void) {
|
||||
@@ -235,7 +276,6 @@ static void menu_modal(void) {
|
||||
toast_t0 = 0;
|
||||
host_audio_lock(); audio_hold = 1; host_audio_unlock();
|
||||
SDL_ShowCursor(SDL_ENABLE);
|
||||
SDL_RenderSetLogicalSize(ren, MENU_W, MENU_H);
|
||||
while (open && !host_quit) {
|
||||
int r = 0;
|
||||
while (SDL_PollEvent(&e)) {
|
||||
@@ -244,7 +284,7 @@ static void menu_modal(void) {
|
||||
case SDL_KEYDOWN: {
|
||||
SDL_Scancode s = e.key.keysym.scancode;
|
||||
dirty = 1;
|
||||
if (is_fullscreen_key(&e.key)) { settings.plein_ecran ^= 1; r |= MENU_DISPLAY; break; }
|
||||
if (is_fullscreen_key(&e.key)) { settings.fullscreen ^= 1; r |= MENU_DISPLAY; break; }
|
||||
switch (s) {
|
||||
case SDL_SCANCODE_F12: if (!e.key.repeat) r |= MENU_CLOSE; break;
|
||||
case SDL_SCANCODE_ESCAPE: if (!e.key.repeat) { r |= MENU_CLOSE; swallow_esc_up = 1; } break;
|
||||
@@ -262,11 +302,11 @@ static void menu_modal(void) {
|
||||
break;
|
||||
}
|
||||
case SDL_MOUSEMOTION:
|
||||
pmx = e.motion.x; pmy = e.motion.y;
|
||||
menu_mouse_pos(e.motion.x, e.motion.y, &pmx, &pmy);
|
||||
r |= menu_mouse(pmx, pmy, 0, 0, 0); dirty = 1;
|
||||
break;
|
||||
case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP:
|
||||
pmx = e.button.x; pmy = e.button.y;
|
||||
menu_mouse_pos(e.button.x, e.button.y, &pmx, &pmy);
|
||||
if (e.button.button == SDL_BUTTON_LEFT)
|
||||
r |= menu_mouse(pmx, pmy, e.type == SDL_MOUSEBUTTONDOWN, e.type == SDL_MOUSEBUTTONUP, 0);
|
||||
else if (e.button.button == SDL_BUTTON_RIGHT && e.type == SDL_MOUSEBUTTONDOWN) r |= MENU_CLOSE;
|
||||
@@ -283,11 +323,10 @@ static void menu_modal(void) {
|
||||
if (r & MENU_DISPLAY) apply_display();
|
||||
if (r & MENU_QUIT) host_quit = 1;
|
||||
if (r & MENU_CLOSE) open = 0;
|
||||
if (dirty && open) { SDL_RenderSetLogicalSize(ren, MENU_W, MENU_H); menu_render(); dirty = 0; }
|
||||
if (dirty && open) { menu_render(); dirty = 0; }
|
||||
SDL_Delay(8);
|
||||
}
|
||||
settings_save(cfg_path);
|
||||
SDL_RenderSetLogicalSize(ren, 320, game_h);
|
||||
SDL_ShowCursor(SDL_DISABLE);
|
||||
host_audio_lock(); audio_hold = 0; host_audio_unlock();
|
||||
mb = 0; memset(press_until, 0, sizeof press_until);
|
||||
@@ -300,12 +339,10 @@ void host_pump(void) {
|
||||
while (SDL_PollEvent(&e)) {
|
||||
switch (e.type) {
|
||||
case SDL_QUIT: host_quit = 1; break;
|
||||
case SDL_MOUSEMOTION:
|
||||
mx = e.motion.x; my = e.motion.y * 200 / game_h;
|
||||
break;
|
||||
case SDL_MOUSEMOTION: game_mouse(e.motion.x, e.motion.y); break;
|
||||
case SDL_MOUSEBUTTONDOWN: case SDL_MOUSEBUTTONUP: {
|
||||
int bit = e.button.button == SDL_BUTTON_LEFT ? 1 : e.button.button == SDL_BUTTON_RIGHT ? 2 : 4;
|
||||
mx = e.button.x; my = e.button.y * 200 / game_h;
|
||||
game_mouse(e.button.x, e.button.y);
|
||||
if (e.type == SDL_MOUSEBUTTONDOWN) { mb |= bit; press_until[bit >> 1] = host_time_us() + 80000; }
|
||||
else mb &= ~bit;
|
||||
break;
|
||||
@@ -313,7 +350,7 @@ void host_pump(void) {
|
||||
case SDL_KEYDOWN: case SDL_KEYUP: {
|
||||
uint8_t sc;
|
||||
if (e.type == SDL_KEYDOWN && is_fullscreen_key(&e.key)) {
|
||||
settings.plein_ecran = !(SDL_GetWindowFlags(win) & SDL_WINDOW_FULLSCREEN_DESKTOP);
|
||||
settings.fullscreen = !(SDL_GetWindowFlags(win) & SDL_WINDOW_FULLSCREEN_DESKTOP);
|
||||
apply_display();
|
||||
settings_save(cfg_path);
|
||||
break;
|
||||
|
||||
+192
-53
@@ -1,4 +1,4 @@
|
||||
/* Menu de réglages : modèle (Settings), fichier reglages.ini, navigation et dessin logiciel.
|
||||
/* Menu de réglages : modèle (Settings), fichier settings.ini, navigation et dessin logiciel.
|
||||
* Aucun appel à SDL ici : ce fichier servira tel quel au portage web. */
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
@@ -16,49 +16,119 @@
|
||||
#endif
|
||||
|
||||
Settings settings;
|
||||
const char *const filter_names[FILTER_COUNT] = {"nearest", "smooth", "xbr", "crt"};
|
||||
|
||||
/* ================================================================== réglages */
|
||||
void settings_defaults(void) {
|
||||
int i;
|
||||
for (i = 0; i < VOL_COUNT; i++) settings.vol[i] = 100;
|
||||
settings.plein_ecran = 0;
|
||||
settings.echelle = 3;
|
||||
settings.lissage = 0;
|
||||
settings.format_43 = 1;
|
||||
settings.fullscreen = 0;
|
||||
settings.window_scale = 3;
|
||||
settings.filter = FILTER_NEAREST;
|
||||
settings.aspect_43 = 1;
|
||||
settings.vsync = 0;
|
||||
}
|
||||
|
||||
static int clampi(int v, int lo, int hi) { return v < lo ? lo : v > hi ? hi : v; }
|
||||
|
||||
static const struct { const char *key; int *val; int lo, hi; } ini_keys[] = {
|
||||
{"volume_general", &settings.vol[VOL_GENERAL], 0, 100},
|
||||
{"volume_musique", &settings.vol[VOL_MUSIQUE], 0, 100},
|
||||
{"volume_voix", &settings.vol[VOL_VOIX], 0, 100},
|
||||
{"volume_bruitages", &settings.vol[VOL_BRUITAGES], 0, 100},
|
||||
{"plein_ecran", &settings.plein_ecran, 0, 1},
|
||||
{"echelle", &settings.echelle, 1, 16},
|
||||
{"lissage", &settings.lissage, 0, 1},
|
||||
{"format_43", &settings.format_43, 0, 1},
|
||||
/* une entrée par clé du fichier ; names : valeurs textuelles (sinon entier) */
|
||||
static const struct {
|
||||
const char *section, *key;
|
||||
int *val;
|
||||
int lo, hi;
|
||||
const char *const *names;
|
||||
} keys[] = {
|
||||
{"display", "fullscreen", &settings.fullscreen, 0, 1, NULL},
|
||||
{"display", "window_scale", &settings.window_scale, 1, 16, NULL},
|
||||
{"display", "filter", &settings.filter, 0, FILTER_COUNT - 1, filter_names},
|
||||
{"display", "aspect_43", &settings.aspect_43, 0, 1, NULL},
|
||||
{"display", "vsync", &settings.vsync, 0, 1, NULL},
|
||||
{"audio", "master_volume", &settings.vol[VOL_GENERAL], 0, 100, NULL},
|
||||
{"audio", "music_volume", &settings.vol[VOL_MUSIQUE], 0, 100, NULL},
|
||||
{"audio", "voice_volume", &settings.vol[VOL_VOIX], 0, 100, NULL},
|
||||
{"audio", "sfx_volume", &settings.vol[VOL_BRUITAGES], 0, 100, NULL},
|
||||
};
|
||||
#define N_INI (sizeof ini_keys / sizeof ini_keys[0])
|
||||
#define N_KEYS ((int)(sizeof keys / sizeof keys[0]))
|
||||
|
||||
static int file_val[N_KEYS], override_val[N_KEYS], overridden[N_KEYS];
|
||||
|
||||
static char *trim(char *s) {
|
||||
char *e;
|
||||
while (*s == ' ' || *s == '\t') s++;
|
||||
e = s + strlen(s);
|
||||
while (e > s && (e[-1] == ' ' || e[-1] == '\t' || e[-1] == '\r' || e[-1] == '\n')) *--e = 0;
|
||||
return s;
|
||||
}
|
||||
|
||||
static int find_key(const char *k) {
|
||||
int i;
|
||||
for (i = 0; i < N_KEYS; i++) if (!strcmp(k, keys[i].key)) return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* valeur textuelle → entier borné ; -1 si invalide */
|
||||
static int parse_value(int i, const char *v, int *out) {
|
||||
char *end;
|
||||
long n;
|
||||
if (keys[i].names) {
|
||||
int j;
|
||||
for (j = 0; j <= keys[i].hi; j++) if (!strcmp(v, keys[i].names[j])) { *out = j; return 1; }
|
||||
return 0;
|
||||
}
|
||||
if (!strcmp(v, "true") || !strcmp(v, "on")) { *out = keys[i].hi > 0; return 1; }
|
||||
if (!strcmp(v, "false") || !strcmp(v, "off")) { *out = 0; return 1; }
|
||||
n = strtol(v, &end, 10);
|
||||
if (end == v) return 0;
|
||||
*out = clampi((int)n, keys[i].lo, keys[i].hi);
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void format_value(int i, int v, char *out, size_t n) {
|
||||
if (keys[i].names) snprintf(out, n, "%s", keys[i].names[clampi(v, keys[i].lo, keys[i].hi)]);
|
||||
else snprintf(out, n, "%d", v);
|
||||
}
|
||||
|
||||
const char *settings_default_path(void) {
|
||||
static char path[600];
|
||||
const char *base;
|
||||
#ifdef _WIN32
|
||||
base = getenv("APPDATA");
|
||||
if (base && *base) { snprintf(path, sizeof path, "%s\\DoubleTroubleRecomp\\settings.ini", base); return path; }
|
||||
#else
|
||||
base = getenv("XDG_CONFIG_HOME");
|
||||
if (base && *base) { snprintf(path, sizeof path, "%s/DoubleTroubleRecomp/settings.ini", base); return path; }
|
||||
base = getenv("HOME");
|
||||
if (base && *base) { snprintf(path, sizeof path, "%s/.config/DoubleTroubleRecomp/settings.ini", base); return path; }
|
||||
#endif
|
||||
return "settings.ini";
|
||||
}
|
||||
|
||||
int settings_load(const char *path) {
|
||||
char line[256];
|
||||
char line[512];
|
||||
int i;
|
||||
FILE *f = fopen(path, "r");
|
||||
for (i = 0; i < N_KEYS; i++) file_val[i] = *keys[i].val;
|
||||
if (!f) return 0;
|
||||
while (fgets(line, sizeof line, f)) {
|
||||
char *eq = strchr(line, '='), *k = line, *e;
|
||||
size_t i;
|
||||
if (!eq || line[0] == '#' || line[0] == ';') continue;
|
||||
char *eq = strchr(line, '='), *k = trim(line);
|
||||
int v;
|
||||
if (!eq || *k == '#' || *k == ';' || *k == '[') continue;
|
||||
*eq = 0;
|
||||
while (*k == ' ' || *k == '\t') k++;
|
||||
for (e = eq; e > k && (e[-1] == ' ' || e[-1] == '\t'); e--) e[-1] = 0;
|
||||
for (i = 0; i < N_INI; i++)
|
||||
if (!strcmp(k, ini_keys[i].key)) *ini_keys[i].val = clampi(atoi(eq + 1), ini_keys[i].lo, ini_keys[i].hi);
|
||||
i = find_key(trim(k));
|
||||
if (i >= 0 && parse_value(i, trim(eq + 1), &v)) *keys[i].val = file_val[i] = v;
|
||||
}
|
||||
fclose(f);
|
||||
return 1;
|
||||
}
|
||||
|
||||
int settings_override(const char *key, const char *value) {
|
||||
int i = find_key(key), v;
|
||||
if (i < 0 || !parse_value(i, value, &v)) return 0;
|
||||
*keys[i].val = override_val[i] = v;
|
||||
overridden[i] = 1;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void make_parent_dir(const char *path) {
|
||||
char dir[600];
|
||||
char *s1, *s2;
|
||||
@@ -70,13 +140,76 @@ static void make_parent_dir(const char *path) {
|
||||
MKDIR(dir);
|
||||
}
|
||||
|
||||
/* Réécrit le fichier en conservant commentaires, ordre et clés inconnues (ajoutées par le launcher) :
|
||||
* seules les valeurs des clés connues changent ; les clés absentes sont ajoutées à leur section. */
|
||||
#define MAX_LINES 400
|
||||
int settings_save(const char *path) {
|
||||
size_t i;
|
||||
FILE *f = fopen(path, "w");
|
||||
static char lines[MAX_LINES][512];
|
||||
int n = 0, i, j, written[N_KEYS] = {0};
|
||||
char cur_section[64] = "";
|
||||
FILE *f = fopen(path, "r");
|
||||
if (f) {
|
||||
while (n < MAX_LINES && fgets(lines[n], sizeof lines[n], f)) {
|
||||
char *e = lines[n] + strlen(lines[n]);
|
||||
while (e > lines[n] && (e[-1] == '\n' || e[-1] == '\r')) *--e = 0;
|
||||
n++;
|
||||
}
|
||||
fclose(f);
|
||||
} else {
|
||||
snprintf(lines[n++], sizeof lines[0], "# DoubleTroubleRecomp : réglages partagés par le jeu (menu F12) et le launcher.");
|
||||
snprintf(lines[n++], sizeof lines[0], "# Clés et valeurs : docs/SETTINGS.md");
|
||||
}
|
||||
/* valeur à écrire : celle du joueur, sauf réglage imposé en ligne de commande et inchangé depuis */
|
||||
#define OUT_VAL(i) (overridden[i] && *keys[i].val == override_val[i] ? file_val[i] : *keys[i].val)
|
||||
for (i = 0; i < n; i++) {
|
||||
char tmp[512], *k, *eq;
|
||||
snprintf(tmp, sizeof tmp, "%s", lines[i]);
|
||||
k = trim(tmp);
|
||||
if (*k == '[') { char *e = strchr(k, ']'); if (e) *e = 0; snprintf(cur_section, sizeof cur_section, "%s", k + 1); continue; }
|
||||
if (*k == '#' || *k == ';' || !(eq = strchr(k, '='))) continue;
|
||||
*eq = 0;
|
||||
j = find_key(trim(k));
|
||||
if (j >= 0) {
|
||||
char v[64];
|
||||
format_value(j, OUT_VAL(j), v, sizeof v);
|
||||
snprintf(lines[i], sizeof lines[0], "%s=%s", keys[j].key, v);
|
||||
written[j] = 1;
|
||||
}
|
||||
}
|
||||
/* clés manquantes : à la fin de leur section, ou dans une nouvelle section en fin de fichier */
|
||||
for (j = 0; j < N_KEYS; j++) {
|
||||
int at = -1, in = 0;
|
||||
char v[64];
|
||||
if (written[j]) continue;
|
||||
for (i = 0; i < n; i++) {
|
||||
char tmp[512], *k;
|
||||
snprintf(tmp, sizeof tmp, "%s", lines[i]);
|
||||
k = trim(tmp);
|
||||
if (*k == '[') {
|
||||
char *e = strchr(k, ']');
|
||||
if (e) *e = 0;
|
||||
in = !strcmp(k + 1, keys[j].section);
|
||||
if (in) at = i + 1;
|
||||
} else if (in && *k) at = i + 1;
|
||||
}
|
||||
if (at < 0) {
|
||||
if (n + 2 > MAX_LINES) break;
|
||||
lines[n++][0] = 0;
|
||||
snprintf(lines[n++], sizeof lines[0], "[%s]", keys[j].section);
|
||||
at = n;
|
||||
}
|
||||
if (n + 1 > MAX_LINES) break;
|
||||
memmove(lines[at + 1], lines[at], (size_t)(n - at) * sizeof lines[0]);
|
||||
format_value(j, OUT_VAL(j), v, sizeof v);
|
||||
snprintf(lines[at], sizeof lines[0], "%s=%s", keys[j].key, v);
|
||||
n++;
|
||||
written[j] = 1;
|
||||
}
|
||||
#undef OUT_VAL
|
||||
f = fopen(path, "w");
|
||||
if (!f) { make_parent_dir(path); f = fopen(path, "w"); }
|
||||
if (!f) return 0;
|
||||
fprintf(f, "# Réglages de tucker-recomp (menu F12). Volumes en %%, booléens 0/1.\n");
|
||||
for (i = 0; i < N_INI; i++) fprintf(f, "%s=%d\n", ini_keys[i].key, *ini_keys[i].val);
|
||||
for (i = 0; i < n; i++) fprintf(f, "%s\n", lines[i]);
|
||||
fclose(f);
|
||||
return 1;
|
||||
}
|
||||
@@ -221,21 +354,25 @@ static int text(const MenuFont *f, int x, int y, const char *s, uint32_t rgb, in
|
||||
|
||||
/* ================================================================== modèle du menu */
|
||||
enum { IT_SLIDER, IT_SWITCH, IT_CHOICE, IT_BUTTONS };
|
||||
typedef struct { const char *label; int type; int *val; int lo, hi, step; } Item;
|
||||
typedef struct { const char *label; int type; int *val; int lo, hi, step; const char *const *names; } Item;
|
||||
|
||||
static const char *const filter_labels[FILTER_COUNT] = {"Net", "Lissé", "xBR", "CRT"};
|
||||
|
||||
static Item items[] = {
|
||||
{"Volume général", IT_SLIDER, &settings.vol[VOL_GENERAL], 0, 100, 5},
|
||||
{"Musique", IT_SLIDER, &settings.vol[VOL_MUSIQUE], 0, 100, 5},
|
||||
{"Voix", IT_SLIDER, &settings.vol[VOL_VOIX], 0, 100, 5},
|
||||
{"Bruitages", IT_SLIDER, &settings.vol[VOL_BRUITAGES], 0, 100, 5},
|
||||
{"Plein écran", IT_SWITCH, &settings.plein_ecran, 0, 1, 1},
|
||||
{"Taille de la fenêtre", IT_CHOICE, &settings.echelle, 1, 16, 1},
|
||||
{"Image lissée", IT_SWITCH, &settings.lissage, 0, 1, 1},
|
||||
{"Format d'origine 4:3", IT_SWITCH, &settings.format_43, 0, 1, 1},
|
||||
{NULL, IT_BUTTONS, NULL, 0, 1, 1},
|
||||
{"Volume général", IT_SLIDER, &settings.vol[VOL_GENERAL], 0, 100, 5, NULL},
|
||||
{"Musique", IT_SLIDER, &settings.vol[VOL_MUSIQUE], 0, 100, 5, NULL},
|
||||
{"Voix", IT_SLIDER, &settings.vol[VOL_VOIX], 0, 100, 5, NULL},
|
||||
{"Bruitages", IT_SLIDER, &settings.vol[VOL_BRUITAGES], 0, 100, 5, NULL},
|
||||
{"Plein écran", IT_SWITCH, &settings.fullscreen, 0, 1, 1, NULL},
|
||||
{"Taille de la fenêtre", IT_CHOICE, &settings.window_scale, 1, 16, 1, NULL},
|
||||
{"Filtre d'image", IT_CHOICE, &settings.filter, 0, FILTER_COUNT - 1, 1, filter_labels},
|
||||
{"Format d'origine 4:3", IT_SWITCH, &settings.aspect_43, 0, 1, 1, NULL},
|
||||
{"Synchro verticale", IT_SWITCH, &settings.vsync, 0, 1, 1, NULL},
|
||||
{NULL, IT_BUTTONS, NULL, 0, 1, 1, NULL},
|
||||
};
|
||||
#define N_ITEMS ((int)(sizeof items / sizeof items[0]))
|
||||
#define FIRST_DISPLAY 4
|
||||
#define ITEM_SCALE 5
|
||||
|
||||
static int sel, button, dragging = -1, max_scale = 4, last_mx = -1, last_my = -1;
|
||||
|
||||
@@ -244,7 +381,7 @@ static int sel, button, dragging = -1, max_scale = 4, last_mx = -1, last_my = -1
|
||||
#define PANEL_X1 810
|
||||
#define PANEL_Y0 40
|
||||
#define PANEL_Y1 680
|
||||
#define ROW_H 44
|
||||
#define ROW_H 40
|
||||
#define CTRL_X0 (PANEL_X0 + 330)
|
||||
#define CTRL_X1 (PANEL_X1 - 44)
|
||||
#define SLIDER_X1 (CTRL_X1 - 84)
|
||||
@@ -253,9 +390,9 @@ static int sel, button, dragging = -1, max_scale = 4, last_mx = -1, last_my = -1
|
||||
#define BTN_GAP 24
|
||||
|
||||
static int row_y(int i) {
|
||||
if (i < FIRST_DISPLAY) return 158 + i * ROW_H;
|
||||
if (i < N_ITEMS - 1) return 374 + (i - FIRST_DISPLAY) * ROW_H;
|
||||
return 576;
|
||||
if (i < FIRST_DISPLAY) return 154 + i * ROW_H;
|
||||
if (i < N_ITEMS - 1) return 352 + (i - FIRST_DISPLAY) * ROW_H;
|
||||
return 570;
|
||||
}
|
||||
|
||||
static int button_x(int b) {
|
||||
@@ -263,10 +400,10 @@ static int button_x(int b) {
|
||||
return x0 + b * (BTN_W + BTN_GAP);
|
||||
}
|
||||
|
||||
void menu_open(int max_echelle) {
|
||||
max_scale = max_echelle < 1 ? 1 : max_echelle;
|
||||
items[5].hi = max_scale;
|
||||
settings.echelle = clampi(settings.echelle, 1, max_scale);
|
||||
void menu_open(int max) {
|
||||
max_scale = max < 1 ? 1 : max;
|
||||
items[ITEM_SCALE].hi = max_scale;
|
||||
settings.window_scale = clampi(settings.window_scale, 1, max_scale);
|
||||
sel = 0; button = 0; dragging = -1; last_mx = last_my = -1;
|
||||
}
|
||||
|
||||
@@ -394,26 +531,28 @@ static void draw_choice(int y, const Item *it, int active, int dim) {
|
||||
char buf[24];
|
||||
uint32_t col = dim ? C_MUTED : C_TEXT;
|
||||
int ty = cy - font_normal.height / 2;
|
||||
snprintf(buf, sizeof buf, "×%d", v);
|
||||
if (it->names) snprintf(buf, sizeof buf, "%s", it->names[v]);
|
||||
else snprintf(buf, sizeof buf, "×%d", v);
|
||||
chevron(CTRL_X1 - 142, cy, 14, -1, v > it->lo ? (active ? C_ACCENT : C_MUTED) : C_TRACK, 255);
|
||||
text(&font_normal, CTRL_X1 - 75 - text_width(&font_normal, buf) / 2, ty, buf, col, 255);
|
||||
chevron(CTRL_X1 - 8, cy, 14, 1, v < it->hi ? (active ? C_ACCENT : C_MUTED) : C_TRACK, 255);
|
||||
snprintf(buf, sizeof buf, "%d×%d", 320 * v, (settings.format_43 ? 240 : 200) * v);
|
||||
text(&font_small, CTRL_X1 - 150 - 18 - text_width(&font_small, buf), cy - font_small.height / 2, buf, C_MUTED, 255);
|
||||
if (!it->names) {
|
||||
snprintf(buf, sizeof buf, "%d×%d", 320 * v, (settings.aspect_43 ? 240 : 200) * v);
|
||||
text(&font_small, CTRL_X1 - 150 - 18 - text_width(&font_small, buf), cy - font_small.height / 2, buf, C_MUTED, 255);
|
||||
}
|
||||
}
|
||||
|
||||
void menu_draw(uint32_t *px) {
|
||||
int i, n;
|
||||
int i;
|
||||
fb = px;
|
||||
n = MENU_W * MENU_H;
|
||||
for (i = 0; i < n; i++) px[i] = 0x8c060312u; /* voile sombre sur le jeu */
|
||||
memset(px, 0, (size_t)MENU_W * MENU_H * 4); /* le voile sombre est posé par l'hôte */
|
||||
round_rect(PANEL_X0 + 6, PANEL_Y0 + 10, PANEL_X1 + 6, PANEL_Y1 + 10, 22, 0, 90); /* ombre */
|
||||
round_rect(PANEL_X0, PANEL_Y0, PANEL_X1, PANEL_Y1, 22, C_PANEL, 245);
|
||||
outline_rect(PANEL_X0, PANEL_Y0, PANEL_X1, PANEL_Y1, 22, 2, C_BORDER, 255);
|
||||
text(&font_title, PANEL_X0 + 44, PANEL_Y0 + 26, "Réglages", C_ACCENT, 255);
|
||||
round_rect(PANEL_X0 + 44, 114, PANEL_X1 - 44, 116, 1, C_BORDER, 255);
|
||||
text(&font_small, PANEL_X0 + 44, 128, "SON", C_MUTED, 255);
|
||||
text(&font_small, PANEL_X0 + 44, 344, "AFFICHAGE", C_MUTED, 255);
|
||||
text(&font_small, PANEL_X0 + 44, 326, "AFFICHAGE", C_MUTED, 255);
|
||||
|
||||
for (i = 0; i < N_ITEMS; i++) {
|
||||
const Item *it = &items[i];
|
||||
@@ -435,7 +574,7 @@ void menu_draw(uint32_t *px) {
|
||||
round_rect(PANEL_X0 + 20, y + 10, PANEL_X0 + 24, y + ROW_H - 10, 2, C_ACCENT, 255);
|
||||
}
|
||||
{
|
||||
int dim = i == 5 && settings.plein_ecran;
|
||||
int dim = i == ITEM_SCALE && settings.fullscreen;
|
||||
text(&font_normal, PANEL_X0 + 44, y + (ROW_H - font_normal.height) / 2, it->label,
|
||||
dim ? C_MUTED : C_TEXT, 255);
|
||||
switch (it->type) {
|
||||
|
||||
+17
-9
@@ -1,6 +1,7 @@
|
||||
/* Menu de réglages en surimpression (volumes, affichage) et fichier de réglages.
|
||||
/* Réglages (fichier settings.ini partagé avec le launcher) et menu en surimpression (F12).
|
||||
* Indépendant de SDL : l'hôte fournit les touches et la souris, le menu dessine dans un tampon ARGB
|
||||
* de MENU_W × MENU_H pixels (4:3), que l'hôte affiche par-dessus l'image du jeu. */
|
||||
* de MENU_W × MENU_H pixels (4:3), que l'hôte affiche par-dessus l'image du jeu.
|
||||
* Clés et valeurs du fichier : docs/SETTINGS.md. */
|
||||
#pragma once
|
||||
#include <stdint.h>
|
||||
|
||||
@@ -8,20 +9,27 @@
|
||||
#define MENU_H 720
|
||||
|
||||
enum { VOL_GENERAL, VOL_MUSIQUE, VOL_VOIX, VOL_BRUITAGES, VOL_COUNT };
|
||||
enum { FILTER_NEAREST, FILTER_SMOOTH, FILTER_XBR, FILTER_CRT, FILTER_COUNT };
|
||||
|
||||
typedef struct {
|
||||
int vol[VOL_COUNT]; /* 0..100 % (courbe perceptive appliquée au mixeur) */
|
||||
int plein_ecran; /* 0/1 */
|
||||
int echelle; /* taille de la fenêtre : 320 × echelle */
|
||||
int lissage; /* 0 = pixels nets, 1 = filtrage bilinéaire */
|
||||
int format_43; /* 1 = 320×200 étiré en 4:3 comme sur un écran VGA, 0 = pixels carrés */
|
||||
int fullscreen; /* 0/1 */
|
||||
int window_scale; /* fenêtre de 320 × window_scale pixels de large */
|
||||
int filter; /* FILTER_* */
|
||||
int aspect_43; /* 1 = 320×200 étiré en 4:3 comme sur un écran VGA, 0 = pixels carrés */
|
||||
int vsync; /* 0/1 */
|
||||
} Settings;
|
||||
|
||||
extern Settings settings;
|
||||
extern const char *const filter_names[FILTER_COUNT]; /* valeurs de la clé filter */
|
||||
|
||||
void settings_defaults(void);
|
||||
const char *settings_default_path(void); /* %APPDATA%\DoubleTroubleRecomp\settings.ini, ~/.config/... */
|
||||
int settings_load(const char *path); /* 1 si lu */
|
||||
int settings_save(const char *path);
|
||||
int settings_save(const char *path); /* réécrit les valeurs en gardant le reste du fichier */
|
||||
/* réglage imposé pour cette session (ligne de commande) : n'est pas écrit dans le fichier,
|
||||
* sauf si le joueur le change ensuite dans le menu. 0 si clé ou valeur inconnue. */
|
||||
int settings_override(const char *key, const char *value);
|
||||
void settings_apply_audio(void); /* settings.vol → audio_volume / audio_master */
|
||||
|
||||
typedef enum { MK_UP, MK_DOWN, MK_LEFT, MK_RIGHT, MK_OK, MK_BACK, MK_HOME, MK_END } MenuKey;
|
||||
@@ -29,9 +37,9 @@ typedef enum { MK_UP, MK_DOWN, MK_LEFT, MK_RIGHT, MK_OK, MK_BACK, MK_HOME, MK_EN
|
||||
/* ce que l'hôte doit faire après un événement */
|
||||
enum { MENU_STAY = 0, MENU_CLOSE = 1, MENU_QUIT = 2, MENU_DISPLAY = 4 /* affichage à réappliquer */ };
|
||||
|
||||
void menu_open(int max_echelle);
|
||||
void menu_open(int max_scale);
|
||||
int menu_key(MenuKey k);
|
||||
/* souris en pixels du tampon du menu ; down/up : bouton gauche enfoncé / relâché pendant cet événement */
|
||||
int menu_mouse(int x, int y, int down, int up, int wheel);
|
||||
void menu_draw(uint32_t *px); /* MENU_W × MENU_H, ARGB non prémultiplié */
|
||||
void menu_draw(uint32_t *px); /* MENU_W × MENU_H, ARGB non prémultiplié, fond transparent */
|
||||
void menu_draw_toast(uint32_t *px, const char *text); /* bulle discrète en bas à droite, fond transparent */
|
||||
Reference in new issue
Block a user