From 128cfd6aff4022ef0a1b42f7f3ed28cde66703a1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Sun, 18 Oct 2026 13:17:13 +0300 Subject: [PATCH 01/57] =?UTF-8?q?=D0=BF=D1=83=D1=81=D1=82=D0=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit -- 2.53.0 From e37aa6edab470f9ffb45f9270c75853716466a92 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Sun, 18 Oct 2026 14:23:52 +0300 Subject: [PATCH 02/57] raylib const --- components/raylib/raylibConstShader.swift | 25 +++++++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 components/raylib/raylibConstShader.swift diff --git a/components/raylib/raylibConstShader.swift b/components/raylib/raylibConstShader.swift new file mode 100644 index 0000000..7ce3514 --- /dev/null +++ b/components/raylib/raylibConstShader.swift @@ -0,0 +1,25 @@ +let RAYLIB_SHADER_MAIN_VS = """ + "#version 330\n" + "layout(location = 0) in vec3 vertexPosition;\n" + "layout(location = 1) in vec2 vertexTexCoord;\n" + "layout(location = 2) in vec3 vertexNormal;\n" + "\n" + "uniform mat4 mvp;\n" + "uniform mat4 matModel;\n" + "uniform mat4 u_lightMVP;\n" + "\n" + "out vec3 vWorldPos;\n" + "out vec3 vNormal;\n" + "out vec2 vTexCoord;\n" + "out vec4 vLightClip;\n" + "\n" + "void main()\n" + "{\n" + " vec4 worldPos = matModel * vec4(vertexPosition, 1.0);\n" + " vWorldPos = worldPos.xyz;\n" + " vNormal = normalize(mat3(matModel) * vertexNormal);\n" + " vTexCoord = vertexTexCoord;\n" + " vLightClip = u_lightMVP * vec4(vertexPosition, 1.0);\n" + " gl_Position = mvp * vec4(vertexPosition, 1.0);\n" + "}\n"; +""" -- 2.53.0 From 127277e762ec2f6a3999f9caf009fa48cce1169c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Sun, 18 Oct 2026 14:34:03 +0300 Subject: [PATCH 03/57] main-vs --- components/raylib/raylibConstShader.swift | 46 +++++++++---------- components/root/mac/view/RaylibGLView.swift | 2 +- game/ver-mac/bridge/include/raylib_bridge.h | 3 +- game/ver-mac/bridge/raylib_bridge.c | 32 ++----------- .../src/raylib/raylibConstShader.swift | 1 + 5 files changed, 31 insertions(+), 53 deletions(-) create mode 120000 game/ver-mac/src/raylib/raylibConstShader.swift diff --git a/components/raylib/raylibConstShader.swift b/components/raylib/raylibConstShader.swift index 7ce3514..99af6a9 100644 --- a/components/raylib/raylibConstShader.swift +++ b/components/raylib/raylibConstShader.swift @@ -1,25 +1,25 @@ let RAYLIB_SHADER_MAIN_VS = """ - "#version 330\n" - "layout(location = 0) in vec3 vertexPosition;\n" - "layout(location = 1) in vec2 vertexTexCoord;\n" - "layout(location = 2) in vec3 vertexNormal;\n" - "\n" - "uniform mat4 mvp;\n" - "uniform mat4 matModel;\n" - "uniform mat4 u_lightMVP;\n" - "\n" - "out vec3 vWorldPos;\n" - "out vec3 vNormal;\n" - "out vec2 vTexCoord;\n" - "out vec4 vLightClip;\n" - "\n" - "void main()\n" - "{\n" - " vec4 worldPos = matModel * vec4(vertexPosition, 1.0);\n" - " vWorldPos = worldPos.xyz;\n" - " vNormal = normalize(mat3(matModel) * vertexNormal);\n" - " vTexCoord = vertexTexCoord;\n" - " vLightClip = u_lightMVP * vec4(vertexPosition, 1.0);\n" - " gl_Position = mvp * vec4(vertexPosition, 1.0);\n" - "}\n"; +#version 330 +layout(location = 0) in vec3 vertexPosition; +layout(location = 1) in vec2 vertexTexCoord; +layout(location = 2) in vec3 vertexNormal; + +uniform mat4 mvp; +uniform mat4 matModel; +uniform mat4 u_lightMVP; + +out vec3 vWorldPos; +out vec3 vNormal; +out vec2 vTexCoord; +out vec4 vLightClip; + +void main() +{ + vec4 worldPos = matModel * vec4(vertexPosition, 1.0); + vWorldPos = worldPos.xyz; + vNormal = normalize(mat3(matModel) * vertexNormal); + vTexCoord = vertexTexCoord; + vLightClip = u_lightMVP * vec4(vertexPosition, 1.0); + gl_Position = mvp * vec4(vertexPosition, 1.0); +} """ diff --git a/components/root/mac/view/RaylibGLView.swift b/components/root/mac/view/RaylibGLView.swift index 68d2019..acebf62 100644 --- a/components/root/mac/view/RaylibGLView.swift +++ b/components/root/mac/view/RaylibGLView.swift @@ -57,7 +57,7 @@ final class RaylibGLNSView: NSOpenGLView { context.setValues(&swapInterval, for: .swapInterval) updatePixelSize() - sr_init(pixelWidth, pixelHeight) + sr_init(pixelWidth, pixelHeight, RAYLIB_SHADER_MAIN_VS) loadModel() startTime = CACurrentMediaTime() ready = true diff --git a/game/ver-mac/bridge/include/raylib_bridge.h b/game/ver-mac/bridge/include/raylib_bridge.h index fcaf199..7b1b2f4 100644 --- a/game/ver-mac/bridge/include/raylib_bridge.h +++ b/game/ver-mac/bridge/include/raylib_bridge.h @@ -6,7 +6,8 @@ extern "C" { #endif // Initialise the OpenGL-backed raylib scene (no raylib window is created). -void sr_init(int width, int height); +// main_vs is the main vertex shader source (see raylibConstShader.swift). +void sr_init(int width, int height, const char *main_vs); // Load the textured cube glTF model. void sr_load_model(const char *gltf_path); diff --git a/game/ver-mac/bridge/raylib_bridge.c b/game/ver-mac/bridge/raylib_bridge.c index cf0a6ef..5f3af20 100644 --- a/game/ver-mac/bridge/raylib_bridge.c +++ b/game/ver-mac/bridge/raylib_bridge.c @@ -88,30 +88,6 @@ static Matrix sr_transform(Vector3 pos, float scale, float rx, float ry, float r return MatrixMultiply(MatrixMultiply(mat_scale, mat_rotation), mat_translation); } -static const char *SR_MAIN_VS = - "#version 330\n" - "layout(location = 0) in vec3 vertexPosition;\n" - "layout(location = 1) in vec2 vertexTexCoord;\n" - "layout(location = 2) in vec3 vertexNormal;\n" - "\n" - "uniform mat4 mvp;\n" - "uniform mat4 matModel;\n" - "uniform mat4 u_lightMVP;\n" - "\n" - "out vec3 vWorldPos;\n" - "out vec3 vNormal;\n" - "out vec2 vTexCoord;\n" - "out vec4 vLightClip;\n" - "\n" - "void main()\n" - "{\n" - " vec4 worldPos = matModel * vec4(vertexPosition, 1.0);\n" - " vWorldPos = worldPos.xyz;\n" - " vNormal = normalize(mat3(matModel) * vertexNormal);\n" - " vTexCoord = vertexTexCoord;\n" - " vLightClip = u_lightMVP * vec4(vertexPosition, 1.0);\n" - " gl_Position = mvp * vec4(vertexPosition, 1.0);\n" - "}\n"; static const char *SR_MAIN_FS = "#version 330\n" @@ -224,9 +200,9 @@ static const char *SR_SHADOW_FS = " finalColor = vec4(1.0);\n" "}\n"; -static void sr_load_shaders(void) +static void sr_load_shaders(const char *main_vs) { - sr_main_shader = LoadShaderFromMemory(SR_MAIN_VS, SR_MAIN_FS); + sr_main_shader = LoadShaderFromMemory(main_vs, SR_MAIN_FS); sr_shadow_shader = LoadShaderFromMemory(SR_SHADOW_VS, SR_SHADOW_FS); loc_light_pos = GetShaderLocation(sr_main_shader, "u_lightPos"); @@ -270,7 +246,7 @@ static void sr_build_ground(void) sr_ground_shadow_material.shader = sr_shadow_shader; } -void sr_init(int width, int height) +void sr_init(int width, int height, const char *main_vs) { if (width > 0) sr_width = width; if (height > 0) sr_height = height; @@ -278,7 +254,7 @@ void sr_init(int width, int height) rlLoadExtensions(sr_gl_loader); rlglInit(sr_width, sr_height); - sr_load_shaders(); + sr_load_shaders(main_vs); sr_build_ground(); sr_ready = 1; diff --git a/game/ver-mac/src/raylib/raylibConstShader.swift b/game/ver-mac/src/raylib/raylibConstShader.swift new file mode 120000 index 0000000..f8a6bf6 --- /dev/null +++ b/game/ver-mac/src/raylib/raylibConstShader.swift @@ -0,0 +1 @@ +../../../../components/raylib/raylibConstShader.swift \ No newline at end of file -- 2.53.0 From b1f0b7f63716e45eeb6b07d821721824b66713a6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Sun, 18 Oct 2026 14:51:46 +0300 Subject: [PATCH 04/57] move to const --- components/raylib/raylibConstShader.swift | 114 ++++++++++++++++++ components/root/mac/view/RaylibGLView.swift | 4 +- game/ver-mac/bridge/include/raylib_bridge.h | 6 +- game/ver-mac/bridge/raylib_bridge.c | 124 ++------------------ 4 files changed, 128 insertions(+), 120 deletions(-) diff --git a/components/raylib/raylibConstShader.swift b/components/raylib/raylibConstShader.swift index 99af6a9..c3fbe61 100644 --- a/components/raylib/raylibConstShader.swift +++ b/components/raylib/raylibConstShader.swift @@ -1,3 +1,98 @@ +let RAYLIB_SHADER_MAIN_FS = """ +#version 330 + +in vec3 vWorldPos; +in vec3 vNormal; +in vec2 vTexCoord; +in vec4 vLightClip; + +uniform sampler2D texture0; +uniform sampler2D u_shadowMap; +uniform vec3 u_lightPos; +uniform vec3 u_lightColor; +uniform vec3 u_ambient; +uniform vec3 u_albedoColor; +uniform float u_lightEnabled; +uniform float u_emissive; +uniform float u_shadowBias; +uniform float u_shadowSoftness; +uniform float u_isGround; +uniform vec3 u_gridColor; +uniform vec3 u_cameraPos; +uniform vec3 u_fogColor; +uniform float u_fogStart; +uniform float u_fogEnd; + +out vec4 finalColor; + +bool isPixelInShadowMap(vec3 proj) +{ + return proj.x >= 0.0 && proj.x <= 1.0 && + proj.y >= 0.0 && proj.y <= 1.0 && + proj.z >= 0.0 && proj.z <= 1.0; +} + +float shadowFactor() +{ + vec3 proj = vLightClip.xyz / vLightClip.w; + proj = proj * 0.5 + 0.5; + + if (!isPixelInShadowMap(proj)) return 0.0; + + int radius = int(u_shadowSoftness); + vec2 texel = 1.0 / vec2(textureSize(u_shadowMap, 0)); + float sum = 0.0; + float count = 0.0; + for (int x = -radius; x <= radius; x++) + { + for (int y = -radius; y <= radius; y++) + { + float d = texture(u_shadowMap, proj.xy + vec2(float(x), float(y)) * texel).r; + sum += (proj.z - u_shadowBias > d) ? 1.0 : 0.0; + count += 1.0; + } + } + return sum / count; +} + +void main() +{ + vec4 texel = texture(texture0, vTexCoord); + vec3 albedo = texel.rgb * u_albedoColor; + vec3 N = normalize(vNormal); + + if (u_isGround > 0.5) + { + vec2 uv = vWorldPos.xz; + vec2 gg = abs(fract(uv - 0.5) - 0.5) / fwidth(uv); + float line = min(gg.x, gg.y); + float grid = 1.0 - min(line, 1.0); + albedo = mix(albedo, u_gridColor, grid * 0.7); + } + + vec3 color = albedo * u_ambient; + + if (u_lightEnabled > 0.5) + { + vec3 toLight = u_lightPos - vWorldPos; + float dist = length(toLight); + vec3 L = toLight / max(dist, 0.0001); + float diff = max(dot(N, L), 0.0); + float attenuation = 1.0 / (1.0 + 0.14 * dist + 0.07 * dist * dist); + float shadow = shadowFactor(); + color += albedo * u_lightColor * diff * attenuation * (1.0 - shadow); + } + + color += albedo * u_emissive; + + float fogDist = length(u_cameraPos - vWorldPos); + float fog = clamp((fogDist - u_fogStart) / (u_fogEnd - u_fogStart), 0.0, 1.0); + color = mix(color, u_fogColor, fog); + + finalColor = vec4(color, 1.0); +} +""" + let RAYLIB_SHADER_MAIN_VS = """ #version 330 layout(location = 0) in vec3 vertexPosition; @@ -23,3 +118,22 @@ void main() gl_Position = mvp * vec4(vertexPosition, 1.0); } """ + +let RAYLIB_SHADER_SHADOW_FS = """ +#version 330 +out vec4 finalColor; +void main() +{ + finalColor = vec4(1.0); +} +""" + +let RAYLIB_SHADER_SHADOW_VS = """ +#version 330 +layout(location = 0) in vec3 vertexPosition; +uniform mat4 mvp; +void main() +{ + gl_Position = mvp * vec4(vertexPosition, 1.0); +} +""" diff --git a/components/root/mac/view/RaylibGLView.swift b/components/root/mac/view/RaylibGLView.swift index acebf62..a449299 100644 --- a/components/root/mac/view/RaylibGLView.swift +++ b/components/root/mac/view/RaylibGLView.swift @@ -57,7 +57,9 @@ final class RaylibGLNSView: NSOpenGLView { context.setValues(&swapInterval, for: .swapInterval) updatePixelSize() - sr_init(pixelWidth, pixelHeight, RAYLIB_SHADER_MAIN_VS) + sr_init(pixelWidth, pixelHeight, + RAYLIB_SHADER_MAIN_VS, RAYLIB_SHADER_MAIN_FS, + RAYLIB_SHADER_SHADOW_VS, RAYLIB_SHADER_SHADOW_FS) loadModel() startTime = CACurrentMediaTime() ready = true diff --git a/game/ver-mac/bridge/include/raylib_bridge.h b/game/ver-mac/bridge/include/raylib_bridge.h index 7b1b2f4..cb4d905 100644 --- a/game/ver-mac/bridge/include/raylib_bridge.h +++ b/game/ver-mac/bridge/include/raylib_bridge.h @@ -6,8 +6,10 @@ extern "C" { #endif // Initialise the OpenGL-backed raylib scene (no raylib window is created). -// main_vs is the main vertex shader source (see raylibConstShader.swift). -void sr_init(int width, int height, const char *main_vs); +// The four shader sources come from raylibConstShader.swift. +void sr_init(int width, int height, + const char *main_vs, const char *main_fs, + const char *shadow_vs, const char *shadow_fs); // Load the textured cube glTF model. void sr_load_model(const char *gltf_path); diff --git a/game/ver-mac/bridge/raylib_bridge.c b/game/ver-mac/bridge/raylib_bridge.c index 5f3af20..01bef49 100644 --- a/game/ver-mac/bridge/raylib_bridge.c +++ b/game/ver-mac/bridge/raylib_bridge.c @@ -88,122 +88,11 @@ static Matrix sr_transform(Vector3 pos, float scale, float rx, float ry, float r return MatrixMultiply(MatrixMultiply(mat_scale, mat_rotation), mat_translation); } - -static const char *SR_MAIN_FS = - "#version 330\n" - "\n" - "in vec3 vWorldPos;\n" - "in vec3 vNormal;\n" - "in vec2 vTexCoord;\n" - "in vec4 vLightClip;\n" - "\n" - "uniform sampler2D texture0;\n" - "uniform sampler2D u_shadowMap;\n" - "uniform vec3 u_lightPos;\n" - "uniform vec3 u_lightColor;\n" - "uniform vec3 u_ambient;\n" - "uniform vec3 u_albedoColor;\n" - "uniform float u_lightEnabled;\n" - "uniform float u_emissive;\n" - "uniform float u_shadowBias;\n" - "uniform float u_shadowSoftness;\n" - "uniform float u_isGround;\n" - "uniform vec3 u_gridColor;\n" - "uniform vec3 u_cameraPos;\n" - "uniform vec3 u_fogColor;\n" - "uniform float u_fogStart;\n" - "uniform float u_fogEnd;\n" - "\n" - "out vec4 finalColor;\n" - "\n" - "bool isPixelInShadowMap(vec3 proj)\n" - "{\n" - " return proj.x >= 0.0 && proj.x <= 1.0 &&\n" - " proj.y >= 0.0 && proj.y <= 1.0 &&\n" - " proj.z >= 0.0 && proj.z <= 1.0;\n" - "}\n" - "\n" - "float shadowFactor()\n" - "{\n" - " vec3 proj = vLightClip.xyz / vLightClip.w;\n" - " proj = proj * 0.5 + 0.5;\n" - "\n" - " if (!isPixelInShadowMap(proj)) return 0.0;\n" - "\n" - " int radius = int(u_shadowSoftness);\n" - " vec2 texel = 1.0 / vec2(textureSize(u_shadowMap, 0));\n" - " float sum = 0.0;\n" - " float count = 0.0;\n" - " for (int x = -radius; x <= radius; x++)\n" - " {\n" - " for (int y = -radius; y <= radius; y++)\n" - " {\n" - " float d = texture(u_shadowMap, proj.xy + vec2(float(x), float(y)) * texel).r;\n" - " sum += (proj.z - u_shadowBias > d) ? 1.0 : 0.0;\n" - " count += 1.0;\n" - " }\n" - " }\n" - " return sum / count;\n" - "}\n" - "\n" - "void main()\n" - "{\n" - " vec4 texel = texture(texture0, vTexCoord);\n" - " vec3 albedo = texel.rgb * u_albedoColor;\n" - " vec3 N = normalize(vNormal);\n" - "\n" - " if (u_isGround > 0.5)\n" - " {\n" - " vec2 uv = vWorldPos.xz;\n" - " vec2 gg = abs(fract(uv - 0.5) - 0.5) / fwidth(uv);\n" - " float line = min(gg.x, gg.y);\n" - " float grid = 1.0 - min(line, 1.0);\n" - " albedo = mix(albedo, u_gridColor, grid * 0.7);\n" - " }\n" - "\n" - " vec3 color = albedo * u_ambient;\n" - "\n" - " if (u_lightEnabled > 0.5)\n" - " {\n" - " vec3 toLight = u_lightPos - vWorldPos;\n" - " float dist = length(toLight);\n" - " vec3 L = toLight / max(dist, 0.0001);\n" - " float diff = max(dot(N, L), 0.0);\n" - " float attenuation = 1.0 / (1.0 + 0.14 * dist + 0.07 * dist * dist);\n" - " float shadow = shadowFactor();\n" - " color += albedo * u_lightColor * diff * attenuation * (1.0 - shadow);\n" - " }\n" - "\n" - " color += albedo * u_emissive;\n" - "\n" - " float fogDist = length(u_cameraPos - vWorldPos);\n" - " float fog = clamp((fogDist - u_fogStart) / (u_fogEnd - u_fogStart), 0.0, 1.0);\n" - " color = mix(color, u_fogColor, fog);\n" - "\n" - " finalColor = vec4(color, 1.0);\n" - "}\n"; - -static const char *SR_SHADOW_VS = - "#version 330\n" - "layout(location = 0) in vec3 vertexPosition;\n" - "uniform mat4 mvp;\n" - "void main()\n" - "{\n" - " gl_Position = mvp * vec4(vertexPosition, 1.0);\n" - "}\n"; - -static const char *SR_SHADOW_FS = - "#version 330\n" - "out vec4 finalColor;\n" - "void main()\n" - "{\n" - " finalColor = vec4(1.0);\n" - "}\n"; - -static void sr_load_shaders(const char *main_vs) +static void sr_load_shaders(const char *main_vs, const char *main_fs, + const char *shadow_vs, const char *shadow_fs) { - sr_main_shader = LoadShaderFromMemory(main_vs, SR_MAIN_FS); - sr_shadow_shader = LoadShaderFromMemory(SR_SHADOW_VS, SR_SHADOW_FS); + sr_main_shader = LoadShaderFromMemory(main_vs, main_fs); + sr_shadow_shader = LoadShaderFromMemory(shadow_vs, shadow_fs); loc_light_pos = GetShaderLocation(sr_main_shader, "u_lightPos"); loc_light_color = GetShaderLocation(sr_main_shader, "u_lightColor"); @@ -246,7 +135,8 @@ static void sr_build_ground(void) sr_ground_shadow_material.shader = sr_shadow_shader; } -void sr_init(int width, int height, const char *main_vs) +void sr_init(int width, int height, const char *main_vs, const char *main_fs, + const char *shadow_vs, const char *shadow_fs) { if (width > 0) sr_width = width; if (height > 0) sr_height = height; @@ -254,7 +144,7 @@ void sr_init(int width, int height, const char *main_vs) rlLoadExtensions(sr_gl_loader); rlglInit(sr_width, sr_height); - sr_load_shaders(main_vs); + sr_load_shaders(main_vs, main_fs, shadow_vs, shadow_fs); sr_build_ground(); sr_ready = 1; -- 2.53.0 From 331a95459df15f3425e332798984bc818951cb59 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Sun, 18 Oct 2026 14:58:41 +0300 Subject: [PATCH 05/57] opengl 3.2 --- components/raylib/raylibConstShader.swift | 16 ++++++++-------- components/root/mac/view/RaylibGLView.swift | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/components/raylib/raylibConstShader.swift b/components/raylib/raylibConstShader.swift index c3fbe61..c61c21e 100644 --- a/components/raylib/raylibConstShader.swift +++ b/components/raylib/raylibConstShader.swift @@ -1,5 +1,5 @@ let RAYLIB_SHADER_MAIN_FS = """ -#version 330 +#version 150 in vec3 vWorldPos; in vec3 vNormal; @@ -94,10 +94,10 @@ void main() """ let RAYLIB_SHADER_MAIN_VS = """ -#version 330 -layout(location = 0) in vec3 vertexPosition; -layout(location = 1) in vec2 vertexTexCoord; -layout(location = 2) in vec3 vertexNormal; +#version 150 +in vec3 vertexPosition; +in vec2 vertexTexCoord; +in vec3 vertexNormal; uniform mat4 mvp; uniform mat4 matModel; @@ -120,7 +120,7 @@ void main() """ let RAYLIB_SHADER_SHADOW_FS = """ -#version 330 +#version 150 out vec4 finalColor; void main() { @@ -129,8 +129,8 @@ void main() """ let RAYLIB_SHADER_SHADOW_VS = """ -#version 330 -layout(location = 0) in vec3 vertexPosition; +#version 150 +in vec3 vertexPosition; uniform mat4 mvp; void main() { diff --git a/components/root/mac/view/RaylibGLView.swift b/components/root/mac/view/RaylibGLView.swift index a449299..1d01801 100644 --- a/components/root/mac/view/RaylibGLView.swift +++ b/components/root/mac/view/RaylibGLView.swift @@ -26,7 +26,7 @@ final class RaylibGLNSView: NSOpenGLView { override init(frame frameRect: NSRect) { let attributes: [NSOpenGLPixelFormatAttribute] = [ - UInt32(NSOpenGLPFAOpenGLProfile), UInt32(NSOpenGLProfileVersion4_1Core), + UInt32(NSOpenGLPFAOpenGLProfile), UInt32(NSOpenGLProfileVersion3_2Core), UInt32(NSOpenGLPFAColorSize), 24, UInt32(NSOpenGLPFAAlphaSize), 8, UInt32(NSOpenGLPFADepthSize), 24, @@ -36,7 +36,7 @@ final class RaylibGLNSView: NSOpenGLView { ] guard let format = NSOpenGLPixelFormat(attributes: attributes) else { - fatalError("Unable to create an OpenGL 4.1 core pixel format") + fatalError("Unable to create an OpenGL 3.2 core pixel format") } super.init(frame: frameRect, pixelFormat: format)! -- 2.53.0 From 4ce7b4a10c9d564956390ab70cf04e509fbe6163 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Sun, 18 Oct 2026 22:08:37 +0300 Subject: [PATCH 06/57] no freeze --- components/root/mac/view/RaylibGLView.swift | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/components/root/mac/view/RaylibGLView.swift b/components/root/mac/view/RaylibGLView.swift index 1d01801..e9d4008 100644 --- a/components/root/mac/view/RaylibGLView.swift +++ b/components/root/mac/view/RaylibGLView.swift @@ -69,9 +69,11 @@ final class RaylibGLNSView: NSOpenGLView { private func startRenderTimer() { guard renderTimer == nil else { return } - renderTimer = Timer.scheduledTimer(withTimeInterval: 1.0 / 60.0, repeats: true) { [weak self] _ in + let timer = Timer(timeInterval: 1.0 / 60.0, repeats: true) { [weak self] _ in self?.needsDisplay = true } + RunLoop.main.add(timer, forMode: .common) + renderTimer = timer } private func loadModel() { -- 2.53.0 From 0010ef00a630b0f2c9d7e39e45b22ef446325622 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Mon, 19 Oct 2026 06:21:05 +0300 Subject: [PATCH 07/57] rename raylib dir to render --- .../renderConstShader.swift} | 8 ++++---- components/root/mac/view/RaylibGLView.swift | 4 ++-- game/ver-mac/bridge/include/raylib_bridge.h | 2 +- game/ver-mac/src/raylib/raylibConstShader.swift | 1 - game/ver-mac/src/render/renderConstShader.swift | 1 + 5 files changed, 8 insertions(+), 8 deletions(-) rename components/{raylib/raylibConstShader.swift => render/renderConstShader.swift} (96%) delete mode 120000 game/ver-mac/src/raylib/raylibConstShader.swift create mode 120000 game/ver-mac/src/render/renderConstShader.swift diff --git a/components/raylib/raylibConstShader.swift b/components/render/renderConstShader.swift similarity index 96% rename from components/raylib/raylibConstShader.swift rename to components/render/renderConstShader.swift index c61c21e..97bbb4a 100644 --- a/components/raylib/raylibConstShader.swift +++ b/components/render/renderConstShader.swift @@ -1,4 +1,4 @@ -let RAYLIB_SHADER_MAIN_FS = """ +let RENDER_SHADER_MAIN_FS = """ #version 150 in vec3 vWorldPos; @@ -93,7 +93,7 @@ void main() } """ -let RAYLIB_SHADER_MAIN_VS = """ +let RENDER_SHADER_MAIN_VS = """ #version 150 in vec3 vertexPosition; in vec2 vertexTexCoord; @@ -119,7 +119,7 @@ void main() } """ -let RAYLIB_SHADER_SHADOW_FS = """ +let RENDER_SHADER_SHADOW_FS = """ #version 150 out vec4 finalColor; void main() @@ -128,7 +128,7 @@ void main() } """ -let RAYLIB_SHADER_SHADOW_VS = """ +let RENDER_SHADER_SHADOW_VS = """ #version 150 in vec3 vertexPosition; uniform mat4 mvp; diff --git a/components/root/mac/view/RaylibGLView.swift b/components/root/mac/view/RaylibGLView.swift index e9d4008..7715a6f 100644 --- a/components/root/mac/view/RaylibGLView.swift +++ b/components/root/mac/view/RaylibGLView.swift @@ -58,8 +58,8 @@ final class RaylibGLNSView: NSOpenGLView { updatePixelSize() sr_init(pixelWidth, pixelHeight, - RAYLIB_SHADER_MAIN_VS, RAYLIB_SHADER_MAIN_FS, - RAYLIB_SHADER_SHADOW_VS, RAYLIB_SHADER_SHADOW_FS) + RENDER_SHADER_MAIN_VS, RENDER_SHADER_MAIN_FS, + RENDER_SHADER_SHADOW_VS, RENDER_SHADER_SHADOW_FS) loadModel() startTime = CACurrentMediaTime() ready = true diff --git a/game/ver-mac/bridge/include/raylib_bridge.h b/game/ver-mac/bridge/include/raylib_bridge.h index cb4d905..65be1af 100644 --- a/game/ver-mac/bridge/include/raylib_bridge.h +++ b/game/ver-mac/bridge/include/raylib_bridge.h @@ -6,7 +6,7 @@ extern "C" { #endif // Initialise the OpenGL-backed raylib scene (no raylib window is created). -// The four shader sources come from raylibConstShader.swift. +// The four shader sources come from renderConstShader.swift. void sr_init(int width, int height, const char *main_vs, const char *main_fs, const char *shadow_vs, const char *shadow_fs); diff --git a/game/ver-mac/src/raylib/raylibConstShader.swift b/game/ver-mac/src/raylib/raylibConstShader.swift deleted file mode 120000 index f8a6bf6..0000000 --- a/game/ver-mac/src/raylib/raylibConstShader.swift +++ /dev/null @@ -1 +0,0 @@ -../../../../components/raylib/raylibConstShader.swift \ No newline at end of file diff --git a/game/ver-mac/src/render/renderConstShader.swift b/game/ver-mac/src/render/renderConstShader.swift new file mode 120000 index 0000000..2dcc2d4 --- /dev/null +++ b/game/ver-mac/src/render/renderConstShader.swift @@ -0,0 +1 @@ +../../../../components/render/renderConstShader.swift \ No newline at end of file -- 2.53.0 From fbea0673c146c5c2ad4ced25127944ea2ae24649 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Mon, 19 Oct 2026 06:35:18 +0300 Subject: [PATCH 08/57] rename --- AGENTS.md | 12 ++++++++---- .../mac/view/RenderGLView.swift} | 18 ++---------------- components/render/mac/view/RenderView.swift | 13 +++++++++++++ components/root/mac/view/RootView.swift | 2 +- .../ver-mac/src/render/view/RenderGLView.swift | 1 + game/ver-mac/src/render/view/RenderView.swift | 1 + game/ver-mac/src/root/view/RaylibGLView.swift | 1 - 7 files changed, 26 insertions(+), 22 deletions(-) rename components/{root/mac/view/RaylibGLView.swift => render/mac/view/RenderGLView.swift} (85%) create mode 100644 components/render/mac/view/RenderView.swift create mode 120000 game/ver-mac/src/render/view/RenderGLView.swift create mode 120000 game/ver-mac/src/render/view/RenderView.swift delete mode 120000 game/ver-mac/src/root/view/RaylibGLView.swift diff --git a/AGENTS.md b/AGENTS.md index c387552..2923098 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -44,10 +44,12 @@ game/ver-mac/ macOS app (SPM executable target "ogs-mahjong") AppDelegate.swift Creates RootComponent + RootVM, calls root.setup() dialect.swift GENERATED — do not hand-edit (see chicken-egg below) other/other.swift -> symlink components/other/other.swift + render/renderConstShader.swift -> symlink components/render/renderConstShader.swift + render/view/RenderGLView.swift -> symlink components/render/mac/view/RenderGLView.swift + render/view/RenderView.swift -> symlink components/render/mac/view/RenderView.swift root/root.swift -> symlink components/root/root.swift root/rootVM.swift -> symlink components/root/rootVM.swift root/view/RootView.swift-> symlink components/root/mac/view/RootView.swift - root/view/RaylibGLView.swift -> symlink components/root/mac/view/RaylibGLView.swift ref/swiftraylib Symlink to ../../swiftraylib — the raylib/SwiftUI renderer sample the game will use for 3D rendering. @@ -71,10 +73,12 @@ directories whose files are **relative symlinks** back into `components/`: ``` src/other/other.swift -> ../../../../components/other/other.swift (4 up) +src/render/renderConstShader.swift -> ../../../../components/render/renderConstShader.swift (4 up) src/root/root.swift -> ../../../../components/root/root.swift (4 up) src/root/rootVM.swift -> ../../../../components/root/rootVM.swift (4 up) src/root/view/RootView.swift-> ../../../../../components/root/mac/view/RootView.swift (5 up) -src/root/view/RaylibGLView.swift -> ../../../../../components/root/mac/view/RaylibGLView.swift (5 up) +src/render/view/RenderGLView.swift -> ../../../../../components/render/mac/view/RenderGLView.swift (5 up) +src/render/view/RenderView.swift -> ../../../../../components/render/mac/view/RenderView.swift (5 up) ``` SPM silently **skips** a dangling symlink (no error), so after moving @@ -108,8 +112,8 @@ The 3D scene links against Homebrew **raylib** (`brew install raylib`). The `RaylibBridge` C target and the link step read `RAYLIB_PREFIX` (default `/opt/homebrew`); `util/step/buildMac` auto-detects it via `brew --prefix raylib`. The bridge renders with raylib's rlgl layer into an `NSOpenGLView` — raylib never -creates its own window. `RootView` puts `RaylibGLView` behind the SwiftUI UI in a -`ZStack`. A textured cube is drawn from `Resources/assets` (`cube.gltf` + +creates its own window. `RootView` puts `RenderView` (backed by `RenderGLView`) +behind the SwiftUI UI in a `ZStack`. A textured cube is drawn from `Resources/assets` (`cube.gltf` + `cube_texture.png`); the app rotates it each frame via `sr_set_rotation`. (raylib's `LoadModelAnimations` only handles *skinned* meshes, so a plain node-rotation glTF animation cannot be played by the renderer — hence the cube is diff --git a/components/root/mac/view/RaylibGLView.swift b/components/render/mac/view/RenderGLView.swift similarity index 85% rename from components/root/mac/view/RaylibGLView.swift rename to components/render/mac/view/RenderGLView.swift index 7715a6f..3100500 100644 --- a/components/root/mac/view/RaylibGLView.swift +++ b/components/render/mac/view/RenderGLView.swift @@ -1,23 +1,9 @@ -import SwiftUI import AppKit import QuartzCore import RaylibBridge +import SwiftUI -/// A raylib-driven 3D scene (rendered through rlgl into an NSOpenGLView) that -/// sits behind the SwiftUI interface. -struct RaylibGLView: NSViewRepresentable { - func makeNSView(context: Context) -> RaylibGLNSView { - RaylibGLNSView(frame: .zero) - } - - func updateNSView(_ nsView: RaylibGLNSView, context: Context) {} -} - -/// An OpenGL view whose context is rendered directly by raylib's rlgl layer, -/// without letting raylib create its own window. Mirrors the reference sample -/// (`swiftraylib`), but drives a single cube that is rotated by the application -/// every frame. -final class RaylibGLNSView: NSOpenGLView { +final class RenderGLView: NSOpenGLView { private var renderTimer: Timer? private var ready = false private var pixelWidth: Int32 = 1 diff --git a/components/render/mac/view/RenderView.swift b/components/render/mac/view/RenderView.swift new file mode 100644 index 0000000..be60e19 --- /dev/null +++ b/components/render/mac/view/RenderView.swift @@ -0,0 +1,13 @@ +import AppKit +import QuartzCore +import RaylibBridge +import SwiftUI + +/// Render view for SwiftUI +struct RenderView: NSViewRepresentable { + func makeNSView(context: Context) -> RenderGLView { + RenderGLView(frame: .zero) + } + + func updateNSView(_ nsView: RenderGLView, context: Context) {} +} diff --git a/components/root/mac/view/RootView.swift b/components/root/mac/view/RootView.swift index 5234ae8..034e891 100644 --- a/components/root/mac/view/RootView.swift +++ b/components/root/mac/view/RootView.swift @@ -9,7 +9,7 @@ struct RootView: View { var body: some View { ZStack { - RaylibGLView() + RenderView() .ignoresSafeArea() VStack(spacing: 16) { diff --git a/game/ver-mac/src/render/view/RenderGLView.swift b/game/ver-mac/src/render/view/RenderGLView.swift new file mode 120000 index 0000000..7223ae3 --- /dev/null +++ b/game/ver-mac/src/render/view/RenderGLView.swift @@ -0,0 +1 @@ +../../../../../components/render/mac/view/RenderGLView.swift \ No newline at end of file diff --git a/game/ver-mac/src/render/view/RenderView.swift b/game/ver-mac/src/render/view/RenderView.swift new file mode 120000 index 0000000..754ef01 --- /dev/null +++ b/game/ver-mac/src/render/view/RenderView.swift @@ -0,0 +1 @@ +../../../../../components/render/mac/view/RenderView.swift \ No newline at end of file diff --git a/game/ver-mac/src/root/view/RaylibGLView.swift b/game/ver-mac/src/root/view/RaylibGLView.swift deleted file mode 120000 index c750636..0000000 --- a/game/ver-mac/src/root/view/RaylibGLView.swift +++ /dev/null @@ -1 +0,0 @@ -../../../../../components/root/mac/view/RaylibGLView.swift \ No newline at end of file -- 2.53.0 From fbb02855ee3ec32d21a3c13ef4ec730ca24d6c0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Mon, 19 Oct 2026 06:56:04 +0300 Subject: [PATCH 09/57] render ctx --- components/render/mac/view/RenderGLView.swift | 17 +--- components/render/render.swift | 14 +++ components/render/renderConst.swift | 12 +++ components/render/renderVM.swift | 12 +++ dialect.yml | 23 ++++- game/ver-mac/src/AppDelegate.swift | 4 + game/ver-mac/src/dialect.swift | 97 ++++++++++++++++++- game/ver-mac/src/render/render.swift | 1 + game/ver-mac/src/render/renderConst.swift | 1 + game/ver-mac/src/render/renderVM.swift | 1 + 10 files changed, 167 insertions(+), 15 deletions(-) create mode 100644 components/render/render.swift create mode 100644 components/render/renderConst.swift create mode 100644 components/render/renderVM.swift create mode 120000 game/ver-mac/src/render/render.swift create mode 120000 game/ver-mac/src/render/renderConst.swift create mode 120000 game/ver-mac/src/render/renderVM.swift diff --git a/components/render/mac/view/RenderGLView.swift b/components/render/mac/view/RenderGLView.swift index 3100500..0f9de48 100644 --- a/components/render/mac/view/RenderGLView.swift +++ b/components/render/mac/view/RenderGLView.swift @@ -11,20 +11,11 @@ final class RenderGLView: NSOpenGLView { private var startTime: CFTimeInterval = 0 override init(frame frameRect: NSRect) { - let attributes: [NSOpenGLPixelFormatAttribute] = [ - UInt32(NSOpenGLPFAOpenGLProfile), UInt32(NSOpenGLProfileVersion3_2Core), - UInt32(NSOpenGLPFAColorSize), 24, - UInt32(NSOpenGLPFAAlphaSize), 8, - UInt32(NSOpenGLPFADepthSize), 24, - UInt32(NSOpenGLPFADoubleBuffer), - UInt32(NSOpenGLPFAAccelerated), - 0 - ] - - guard let format = NSOpenGLPixelFormat(attributes: attributes) else { - fatalError("Unable to create an OpenGL 3.2 core pixel format") + guard + let format = NSOpenGLPixelFormat(attributes: RENDER_OPENGL_ATTRS) + else { + fatalError("ERROR Could not create required OpenGL pixel format") } - super.init(frame: frameRect, pixelFormat: format)! wantsBestResolutionOpenGLSurface = true } diff --git a/components/render/render.swift b/components/render/render.swift new file mode 100644 index 0000000..a676446 --- /dev/null +++ b/components/render/render.swift @@ -0,0 +1,14 @@ +class RenderComponent { + let ctrl = DialectController(RenderContext()) + static private(set) weak var singleton: RenderComponent? + + init() { + Self.singleton = self + renderRegisterEffects(ctrl) + renderRegisterShoulds(ctrl) + } + + func setup() { + renderSet(F.didSetup, true) + } +} diff --git a/components/render/renderConst.swift b/components/render/renderConst.swift new file mode 100644 index 0000000..688e4f5 --- /dev/null +++ b/components/render/renderConst.swift @@ -0,0 +1,12 @@ +import AppKit + +let RENDER_OPENGL_ATTRS: [NSOpenGLPixelFormatAttribute] = [ + UInt32(NSOpenGLPFAOpenGLProfile), UInt32(NSOpenGLProfileVersion3_2Core), + UInt32(NSOpenGLPFAColorSize), 24, + UInt32(NSOpenGLPFAAlphaSize), 8, + UInt32(NSOpenGLPFADepthSize), 24, + UInt32(NSOpenGLPFADoubleBuffer), + UInt32(NSOpenGLPFAAccelerated), + 0 +] + diff --git a/components/render/renderVM.swift b/components/render/renderVM.swift new file mode 100644 index 0000000..4fdef75 --- /dev/null +++ b/components/render/renderVM.swift @@ -0,0 +1,12 @@ +import Combine +import Foundation + +final class RenderVM: ObservableObject { + var timer: Timer? + + static private(set) weak var shared: RenderVM? + + init() { + Self.shared = self + } +} diff --git a/dialect.yml b/dialect.yml index fbf003b..8bc568f 100644 --- a/dialect.yml +++ b/dialect.yml @@ -4,10 +4,31 @@ output: game/ver-mac/src/dialect.swift: type: swift +RenderContext: + type: context + fields: + didLaunch: Bool + didSetup: Bool + isReadyToRender: Bool + pixelHeight: Int + pixelWidth: Int + +RenderComponent: + type: component + oneliners: + - isReadyToRender: print("ИГР isRTR: '\(c.isReadyToRender)'") + shoulds: + didLaunch: + 1. Only once during the first setup: + if: + c.recentField == F.didSetup && + c.didLaunch == false + then: + c.didLaunch = true + RootComponent: type: component oneliners: - - countText: print(c.countText) - countText: RootVM.shared!.countText = c.countText shoulds: count: diff --git a/game/ver-mac/src/AppDelegate.swift b/game/ver-mac/src/AppDelegate.swift index 9d214e6..502b8cf 100644 --- a/game/ver-mac/src/AppDelegate.swift +++ b/game/ver-mac/src/AppDelegate.swift @@ -4,6 +4,8 @@ final class AppDelegate: NSObject, NSApplicationDelegate { + let render = RenderComponent() + let renderVM = RenderVM() let root = RootComponent() let rootVM = RootVM() @@ -14,6 +16,8 @@ final class AppDelegate: otherSetupConsoleLogging(root.ctrl, "Root") root.setup() + otherSetupConsoleLogging(render.ctrl, "Render") + render.setup() } func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { diff --git a/game/ver-mac/src/dialect.swift b/game/ver-mac/src/dialect.swift index 4b69471..a3316be 100644 --- a/game/ver-mac/src/dialect.swift +++ b/game/ver-mac/src/dialect.swift @@ -124,8 +124,63 @@ public struct F { public static let didClickIncrement = "didClickIncrement" public static let didLaunch = "didLaunch" public static let didSetup = "didSetup" + public static let isReadyToRender = "isReadyToRender" + public static let pixelHeight = "pixelHeight" + public static let pixelWidth = "pixelWidth" } +public struct RenderContext: DialectContext { + public var didLaunch = Bool() + public var didSetup = Bool() + public var isReadyToRender = Bool() + public var pixelHeight = Int() + public var pixelWidth = Int() + + public var recentField = "" + + public func field(_ name: String) -> T { + if (name == "didLaunch") { + return didLaunch as! T + } + else if (name == "didSetup") { + return didSetup as! T + } + else if (name == "isReadyToRender") { + return isReadyToRender as! T + } + else if (name == "pixelHeight") { + return pixelHeight as! T + } + else if (name == "pixelWidth") { + return pixelWidth as! T + } + + return "unknown-field-name" as! T + } + + public mutating func setField( + _ name: String, + _ value: Any + ) { + if (name == "didLaunch") { + didLaunch = value as! Bool + } + else if (name == "didSetup") { + didSetup = value as! Bool + } + else if (name == "isReadyToRender") { + isReadyToRender = value as! Bool + } + else if (name == "pixelHeight") { + pixelHeight = value as! Int + } + else if (name == "pixelWidth") { + pixelWidth = value as! Int + } + + } +} + public struct RootContext: DialectContext { public var count = Int() public var countText = String() @@ -178,6 +233,13 @@ public struct RootContext: DialectContext { } } +public func renderSet( + _ key: String, + _ value: Any +) { + RenderComponent.singleton!.ctrl.set(key, value) +} + public func rootSet( _ key: String, _ value: Any @@ -185,6 +247,24 @@ public func rootSet( RootComponent.singleton!.ctrl.set(key, value) } +func renderShouldResetDidLaunch(_ c: RenderContext) -> RenderContext { + var c = c + + /* 1. Only once during the first setup */ + if + c.recentField == F.didSetup && + c.didLaunch == false + { + c.didLaunch = true + c.recentField = F.didLaunch + return c + } + + + c.recentField = DIALECT_CONTEXT_RECENT_FIELD_NONE + return c +} + func rootShouldResetCount(_ c: RootContext) -> RootContext { var c = c @@ -256,6 +336,15 @@ func rootShouldResetDidLaunch(_ c: RootContext) -> RootContext { return c } +func renderRegisterShoulds(_ ctrl: DialectController) { + [ + renderShouldResetDidLaunch, + + ].forEach { f in + ctrl.registerFunction { c in f(c as! RenderContext) } + } +} + func rootRegisterShoulds(_ ctrl: DialectController) { [ rootShouldResetCount, @@ -267,9 +356,15 @@ func rootRegisterShoulds(_ ctrl: DialectController) { } } +func renderRegisterEffects(_ ctrl: DialectController) { + let _: RenderContext? = registerOneliners(ctrl, [ + F.isReadyToRender, { (c: RenderContext) in print("ИГР isRTR: '\(c.isReadyToRender)'") }, + + ]) +} + func rootRegisterEffects(_ ctrl: DialectController) { let _: RootContext? = registerOneliners(ctrl, [ - F.countText, { (c: RootContext) in print(c.countText) }, F.countText, { (c: RootContext) in RootVM.shared!.countText = c.countText }, ]) diff --git a/game/ver-mac/src/render/render.swift b/game/ver-mac/src/render/render.swift new file mode 120000 index 0000000..5e4b117 --- /dev/null +++ b/game/ver-mac/src/render/render.swift @@ -0,0 +1 @@ +../../../../components/render/render.swift \ No newline at end of file diff --git a/game/ver-mac/src/render/renderConst.swift b/game/ver-mac/src/render/renderConst.swift new file mode 120000 index 0000000..d953714 --- /dev/null +++ b/game/ver-mac/src/render/renderConst.swift @@ -0,0 +1 @@ +../../../../components/render/renderConst.swift \ No newline at end of file diff --git a/game/ver-mac/src/render/renderVM.swift b/game/ver-mac/src/render/renderVM.swift new file mode 120000 index 0000000..dde0ace --- /dev/null +++ b/game/ver-mac/src/render/renderVM.swift @@ -0,0 +1 @@ +../../../../components/render/renderVM.swift \ No newline at end of file -- 2.53.0 From cc445309e8a6ed5ebb53f0d70fd88845070ec527 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Mon, 19 Oct 2026 07:10:51 +0300 Subject: [PATCH 10/57] some --- components/render/mac/view/RenderGLView.swift | 3 +- components/render/renderConst.swift | 8 +++++ game/ver-mac/bridge/include/raylib_bridge.h | 12 +++++++- game/ver-mac/bridge/raylib_bridge.c | 29 +++++++++---------- 4 files changed, 35 insertions(+), 17 deletions(-) diff --git a/components/render/mac/view/RenderGLView.swift b/components/render/mac/view/RenderGLView.swift index 0f9de48..c4beeeb 100644 --- a/components/render/mac/view/RenderGLView.swift +++ b/components/render/mac/view/RenderGLView.swift @@ -36,7 +36,8 @@ final class RenderGLView: NSOpenGLView { updatePixelSize() sr_init(pixelWidth, pixelHeight, RENDER_SHADER_MAIN_VS, RENDER_SHADER_MAIN_FS, - RENDER_SHADER_SHADOW_VS, RENDER_SHADER_SHADOW_FS) + RENDER_SHADER_SHADOW_VS, RENDER_SHADER_SHADOW_FS, + RENDER_CONFIG) loadModel() startTime = CACurrentMediaTime() ready = true diff --git a/components/render/renderConst.swift b/components/render/renderConst.swift index 688e4f5..752320f 100644 --- a/components/render/renderConst.swift +++ b/components/render/renderConst.swift @@ -1,4 +1,5 @@ import AppKit +import RaylibBridge let RENDER_OPENGL_ATTRS: [NSOpenGLPixelFormatAttribute] = [ UInt32(NSOpenGLPFAOpenGLProfile), UInt32(NSOpenGLProfileVersion3_2Core), @@ -10,3 +11,10 @@ let RENDER_OPENGL_ATTRS: [NSOpenGLPixelFormatAttribute] = [ 0 ] +let RENDER_CONFIG = sr_config( + fov_y: 45.0, + near_plane: 0.1, + far_plane: 1000.0, + shadow_size: 1024, + ground_size: 40.0 +) diff --git a/game/ver-mac/bridge/include/raylib_bridge.h b/game/ver-mac/bridge/include/raylib_bridge.h index 65be1af..91b432e 100644 --- a/game/ver-mac/bridge/include/raylib_bridge.h +++ b/game/ver-mac/bridge/include/raylib_bridge.h @@ -5,11 +5,21 @@ extern "C" { #endif +// Render configuration, sourced from renderConst.swift. +typedef struct sr_config { + float fov_y; // vertical field of view (degrees) + float near_plane; // camera near plane + float far_plane; // camera far plane + int shadow_size; // shadow map resolution (px) + float ground_size; // ground plane extent +} sr_config; + // Initialise the OpenGL-backed raylib scene (no raylib window is created). // The four shader sources come from renderConstShader.swift. void sr_init(int width, int height, const char *main_vs, const char *main_fs, - const char *shadow_vs, const char *shadow_fs); + const char *shadow_vs, const char *shadow_fs, + sr_config config); // Load the textured cube glTF model. void sr_load_model(const char *gltf_path); diff --git a/game/ver-mac/bridge/raylib_bridge.c b/game/ver-mac/bridge/raylib_bridge.c index 01bef49..bd08e9f 100644 --- a/game/ver-mac/bridge/raylib_bridge.c +++ b/game/ver-mac/bridge/raylib_bridge.c @@ -9,15 +9,12 @@ #include #include -#define SR_FOV_Y 45.0f -#define SR_NEAR 0.1f -#define SR_FAR 1000.0f -#define SR_SHADOW_SIZE 1024 -#define SR_GROUND_SIZE 40.0f - static int sr_width = 1; static int sr_height = 1; +// Render configuration supplied by the application (see renderConst.swift). +static sr_config sr_cfg = { 0 }; + // Cube transform (driven by the application, Euler degrees). static float sr_rot_x = 0.0f; static float sr_rot_y = 0.0f; @@ -114,8 +111,8 @@ static void sr_load_shaders(const char *main_vs, const char *main_fs, // Build a framebuffer whose depth attachment is a sampleable TEXTURE (raylib's // LoadRenderTexture() uses a non-sampleable renderbuffer, so we build it by hand). sr_shadow_fbo = rlLoadFramebuffer(); - sr_shadow_color = rlLoadTexture(NULL, SR_SHADOW_SIZE, SR_SHADOW_SIZE, RL_PIXELFORMAT_UNCOMPRESSED_R8G8B8A8, 1); - sr_shadow_depth = rlLoadTextureDepth(SR_SHADOW_SIZE, SR_SHADOW_SIZE, false); + sr_shadow_color = rlLoadTexture(NULL, sr_cfg.shadow_size, sr_cfg.shadow_size, RL_PIXELFORMAT_UNCOMPRESSED_R8G8B8A8, 1); + sr_shadow_depth = rlLoadTextureDepth(sr_cfg.shadow_size, sr_cfg.shadow_size, false); rlEnableFramebuffer(sr_shadow_fbo); rlFramebufferAttach(sr_shadow_fbo, sr_shadow_color, RL_ATTACHMENT_COLOR_CHANNEL0, RL_ATTACHMENT_TEXTURE2D, 0); @@ -127,7 +124,7 @@ static void sr_load_shaders(const char *main_vs, const char *main_fs, static void sr_build_ground(void) { - Mesh ground_mesh = GenMeshPlane(SR_GROUND_SIZE, SR_GROUND_SIZE, 1, 1); + Mesh ground_mesh = GenMeshPlane(sr_cfg.ground_size, sr_cfg.ground_size, 1, 1); sr_ground_model = LoadModelFromMesh(ground_mesh); sr_ground_material = LoadMaterialDefault(); sr_ground_material.shader = sr_main_shader; @@ -136,11 +133,13 @@ static void sr_build_ground(void) } void sr_init(int width, int height, const char *main_vs, const char *main_fs, - const char *shadow_vs, const char *shadow_fs) + const char *shadow_vs, const char *shadow_fs, sr_config config) { if (width > 0) sr_width = width; if (height > 0) sr_height = height; + sr_cfg = config; + rlLoadExtensions(sr_gl_loader); rlglInit(sr_width, sr_height); @@ -196,9 +195,9 @@ static Matrix sr_cube_transform(void) static void sr_render_shadow_pass(void) { - rlViewport(0, 0, SR_SHADOW_SIZE, SR_SHADOW_SIZE); - rlSetFramebufferWidth(SR_SHADOW_SIZE); - rlSetFramebufferHeight(SR_SHADOW_SIZE); + rlViewport(0, 0, sr_cfg.shadow_size, sr_cfg.shadow_size); + rlSetFramebufferWidth(sr_cfg.shadow_size); + rlSetFramebufferHeight(sr_cfg.shadow_size); rlEnableFramebuffer(sr_shadow_fbo); @@ -283,9 +282,9 @@ void sr_render(void) rlLoadIdentity(); float aspect = (float)sr_width / (float)sr_height; - double top = (double)SR_NEAR * tan((double)SR_FOV_Y * 0.5 * DEG2RAD); + double top = (double)sr_cfg.near_plane * tan((double)sr_cfg.fov_y * 0.5 * DEG2RAD); double right = top * (double)aspect; - rlFrustum(-right, right, -top, top, (double)SR_NEAR, (double)SR_FAR); + rlFrustum(-right, right, -top, top, (double)sr_cfg.near_plane, (double)sr_cfg.far_plane); rlMatrixMode(RL_MODELVIEW); rlLoadIdentity(); -- 2.53.0 From 2ef1589d557c5322bd340086fd7091b3e7c4f13f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Mon, 19 Oct 2026 07:14:03 +0300 Subject: [PATCH 11/57] move --- components/render/renderConst.swift | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/components/render/renderConst.swift b/components/render/renderConst.swift index 752320f..fd31c4c 100644 --- a/components/render/renderConst.swift +++ b/components/render/renderConst.swift @@ -1,6 +1,14 @@ import AppKit import RaylibBridge +let RENDER_CONFIG = sr_config( + fov_y: 45.0, + near_plane: 0.1, + far_plane: 1000.0, + shadow_size: 256, + ground_size: 40.0 +) + let RENDER_OPENGL_ATTRS: [NSOpenGLPixelFormatAttribute] = [ UInt32(NSOpenGLPFAOpenGLProfile), UInt32(NSOpenGLProfileVersion3_2Core), UInt32(NSOpenGLPFAColorSize), 24, @@ -10,11 +18,3 @@ let RENDER_OPENGL_ATTRS: [NSOpenGLPixelFormatAttribute] = [ UInt32(NSOpenGLPFAAccelerated), 0 ] - -let RENDER_CONFIG = sr_config( - fov_y: 45.0, - near_plane: 0.1, - far_plane: 1000.0, - shadow_size: 1024, - ground_size: 40.0 -) -- 2.53.0 From df4ac266583dae4442df9f00902e6ad4b14e91e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Mon, 19 Oct 2026 16:07:01 +0300 Subject: [PATCH 12/57] normal map --- components/render/renderConstShader.swift | 23 +++++++++ game/ver-mac/Resources/assets/cube_normal.png | Bin 0 -> 19435 bytes game/ver-mac/bridge/raylib_bridge.c | 47 ++++++++++++++++-- 3 files changed, 67 insertions(+), 3 deletions(-) create mode 100644 game/ver-mac/Resources/assets/cube_normal.png diff --git a/components/render/renderConstShader.swift b/components/render/renderConstShader.swift index 97bbb4a..665feb9 100644 --- a/components/render/renderConstShader.swift +++ b/components/render/renderConstShader.swift @@ -7,6 +7,8 @@ in vec2 vTexCoord; in vec4 vLightClip; uniform sampler2D texture0; +uniform sampler2D u_normalMap; +uniform float u_normalStrength; uniform sampler2D u_shadowMap; uniform vec3 u_lightPos; uniform vec3 u_lightColor; @@ -55,12 +57,33 @@ float shadowFactor() return sum / count; } +mat3 cotangentFrame(vec3 N, vec3 p, vec2 uv) +{ + vec3 dp1 = dFdx(p); + vec3 dp2 = dFdy(p); + vec2 duv1 = dFdx(uv); + vec2 duv2 = dFdy(uv); + vec3 dp2perp = cross(dp2, N); + vec3 dp1perp = cross(N, dp1); + vec3 T = dp2perp * duv1.x + dp1perp * duv2.x; + vec3 B = dp2perp * duv1.y + dp1perp * duv2.y; + float invmax = inversesqrt(max(dot(T, T), dot(B, B))); + return mat3(T * invmax, B * invmax, N); +} + void main() { vec4 texel = texture(texture0, vTexCoord); vec3 albedo = texel.rgb * u_albedoColor; vec3 N = normalize(vNormal); + if (u_normalStrength > 0.0) + { + vec3 nm = texture(u_normalMap, vTexCoord).rgb * 2.0 - 1.0; + nm.xy *= u_normalStrength; + N = normalize(cotangentFrame(N, vWorldPos, vTexCoord) * nm); + } + if (u_isGround > 0.5) { vec2 uv = vWorldPos.xz; diff --git a/game/ver-mac/Resources/assets/cube_normal.png b/game/ver-mac/Resources/assets/cube_normal.png new file mode 100644 index 0000000000000000000000000000000000000000..efa061c7bd4aa3c9904bef1631d5f3e8cddb7746 GIT binary patch literal 19435 zcmb5VWlSZ$6E=E)gR{Wmw&=m#T^D!v#hu07-QC^c;O@@i4vWL$?(X{j{`bR8?uYlo zP18;??WAd%PM>z3iBOc6_=bRo0002KNlA(-|0nzYtNw71|Fv_6H+=sIVq-~VIRLz^6F$p2V(4NnAqbm3p) z`E}o93e`GLQ`PR5OZw}-PZ;Hayd%Q8hY^kce(6i)>GKDG&`$it#*pA4g-E6S)Bg~V zfL^mkNI=^F1b={}?`M)IX#zYSZ34tI+;>z6IDZ@=J)eIy=|X5!qUou|pG*0QnOTw` zT$wiZF`6d?Tb*yluXCsODF)1w?}#=&Fe})Mz69K$#93iBwCd9=C%Km9K?pQKPCO~% zydagBs(%AUYs*H2r92G-J55c_04tW=q@ zgu?C6((j88N6?@|Nho$QJ%lz=VPXUrG$~^57o7sAAcQzmG|6xG8Pq{3Z!&3C5{^?}lQ&E48^BBkyjDC@`3&c) zEr_L#WE=>$sOGk$QFe;C_3dj+lR(U3ZjR;8Z@8%i^(KHxM{QuY-dDmtkng6bi<4-5 z_Q>IyaNZcdd6Sy*MR+r==9w%narzECxe9RiB~hWKI4DICt%`!sj{6#d(fS}F^~NaZ z0k15dR8|AUZbbyes)hj6d=Nl$G*jQ58Ul4TPzp^FN)zEZOU2MVyzapN(;h$?e3#6s z-0}PHM=ZjY+z3J=qGzc#Qegk#W)mM=#{2lwndZ0!j)(2-O|jlqnJ+Cu?}x_GsrjX< zS#}^^md1NW8YwE7CE$1vz7IO`CQ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C zcqSM_%_L<@hh~)tB7lTpqQMpK+7EDLX?__)NE4(K0C;{G{xx0+7%~k&xyVBJO83(% z%@h5aF<&cuCByOcu6^ #include #include +#include static int sr_width = 1; static int sr_height = 1; @@ -27,6 +28,7 @@ static int sr_has_model = 0; static Material sr_cube_material = { 0 }; static Material sr_cube_shadow_material = { 0 }; +static Texture2D sr_cube_normal = { 0 }; static Model sr_ground_model = { 0 }; static Material sr_ground_material = { 0 }; @@ -53,6 +55,8 @@ static int loc_albedo_color = -1; static int loc_shadow_map = -1; static int loc_shadow_bias = -1; static int loc_shadow_softness = -1; +static int loc_normal_map = -1; +static int loc_normal_strength = -1; static int loc_light_mvp = -1; static int loc_is_ground = -1; static int loc_grid_color = -1; @@ -100,6 +104,8 @@ static void sr_load_shaders(const char *main_vs, const char *main_fs, loc_shadow_map = GetShaderLocation(sr_main_shader, "u_shadowMap"); loc_shadow_bias = GetShaderLocation(sr_main_shader, "u_shadowBias"); loc_shadow_softness = GetShaderLocation(sr_main_shader, "u_shadowSoftness"); + loc_normal_map = GetShaderLocation(sr_main_shader, "u_normalMap"); + loc_normal_strength = GetShaderLocation(sr_main_shader, "u_normalStrength"); loc_light_mvp = GetShaderLocation(sr_main_shader, "u_lightMVP"); loc_is_ground = GetShaderLocation(sr_main_shader, "u_isGround"); loc_grid_color = GetShaderLocation(sr_main_shader, "u_gridColor"); @@ -156,6 +162,12 @@ void sr_load_model(const char *gltf_path) sr_model = LoadModel(gltf_path); sr_has_model = (sr_model.meshCount > 0); + // The matching normal map sits next to the glTF; load it separately. + char asset_dir[1024]; + const char *slash = strrchr(gltf_path, '/'); + size_t dir_len = (slash != NULL) ? (size_t)(slash - gltf_path + 1) : 0; + snprintf(asset_dir, sizeof(asset_dir), "%.*s", (int)dir_len, gltf_path); + if (sr_has_model) { int cube_mat_index = (sr_model.materialCount > 0) ? sr_model.meshMaterial[0] : 0; @@ -166,6 +178,15 @@ void sr_load_model(const char *gltf_path) SetTextureFilter(base_tex, TEXTURE_FILTER_BILINEAR); SetTextureWrap(base_tex, TEXTURE_WRAP_CLAMP); + char normal_path[1024]; + snprintf(normal_path, sizeof(normal_path), "%scube_normal.png", asset_dir); + if (FileExists(normal_path)) + { + sr_cube_normal = LoadTexture(normal_path); + SetTextureFilter(sr_cube_normal, TEXTURE_FILTER_BILINEAR); + SetTextureWrap(sr_cube_normal, TEXTURE_WRAP_CLAMP); + } + sr_cube_shadow_material = sr_cube_material; sr_cube_shadow_material.shader = sr_shadow_shader; } @@ -242,14 +263,28 @@ static void sr_set_light_mvp(Matrix model) SetShaderValueMatrix(sr_main_shader, loc_light_mvp, light_mvp); } -static void sr_draw_object(Model model, Material material, Matrix model_mat, float is_ground, float emissive) +static void sr_bind_normal(Texture2D tex) +{ + int unit = 2; + SetShaderValue(sr_main_shader, loc_normal_map, &unit, SHADER_UNIFORM_INT); + rlActiveTextureSlot(2); + if (tex.id > 0) rlEnableTexture(tex.id); + rlActiveTextureSlot(0); +} + +static void sr_draw_object(Model model, Material material, Matrix model_mat, + Texture2D normal, float is_ground, float emissive) { sr_set_light_mvp(model_mat); float albedo[3] = { 1.0f, 1.0f, 1.0f }; + float normal_strength = (normal.id > 0) ? 1.0f : 0.0f; SetShaderValue(sr_main_shader, loc_albedo_color, albedo, SHADER_UNIFORM_VEC3); SetShaderValue(sr_main_shader, loc_emissive, &emissive, SHADER_UNIFORM_FLOAT); SetShaderValue(sr_main_shader, loc_is_ground, &is_ground, SHADER_UNIFORM_FLOAT); + SetShaderValue(sr_main_shader, loc_normal_strength, &normal_strength, SHADER_UNIFORM_FLOAT); + + sr_bind_normal(normal); DrawMesh(model.meshes[0], material, model_mat); } @@ -331,12 +366,12 @@ void sr_render(void) rlActiveTextureSlot(0); // --- Ground (procedural grid floor) --- - sr_draw_object(sr_ground_model, sr_ground_material, MatrixTranslate(0.0f, 0.0f, 0.0f), 1.0f, 0.0f); + sr_draw_object(sr_ground_model, sr_ground_material, MatrixTranslate(0.0f, 0.0f, 0.0f), (Texture2D){ 0 }, 1.0f, 0.0f); // --- Cubes --- if (sr_has_model) { - sr_draw_object(sr_model, sr_cube_material, sr_cube_transform(), 0.0f, 0.0f); + sr_draw_object(sr_model, sr_cube_material, sr_cube_transform(), sr_cube_normal, 0.0f, 0.0f); } // Flush while the projection/modelview matrices are still active, otherwise @@ -364,6 +399,12 @@ void sr_shutdown(void) UnloadModel(sr_ground_model); + if (sr_cube_normal.id > 0) + { + UnloadTexture(sr_cube_normal); + sr_cube_normal.id = 0; + } + if (sr_shadow_color > 0) rlUnloadTexture(sr_shadow_color); if (sr_shadow_depth > 0) rlUnloadTexture(sr_shadow_depth); if (sr_shadow_fbo > 0) rlUnloadFramebuffer(sr_shadow_fbo); -- 2.53.0 From 3d19b2e980d3cd482b1fe88885b0523027c46c9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Mon, 19 Oct 2026 16:13:03 +0300 Subject: [PATCH 13/57] keep gl view in VM --- components/render/mac/view/RenderView.swift | 2 +- components/render/renderVM.swift | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/components/render/mac/view/RenderView.swift b/components/render/mac/view/RenderView.swift index be60e19..c6ebf4e 100644 --- a/components/render/mac/view/RenderView.swift +++ b/components/render/mac/view/RenderView.swift @@ -6,7 +6,7 @@ import SwiftUI /// Render view for SwiftUI struct RenderView: NSViewRepresentable { func makeNSView(context: Context) -> RenderGLView { - RenderGLView(frame: .zero) + RenderVM.shared!.glView } func updateNSView(_ nsView: RenderGLView, context: Context) {} diff --git a/components/render/renderVM.swift b/components/render/renderVM.swift index 4fdef75..e023c3c 100644 --- a/components/render/renderVM.swift +++ b/components/render/renderVM.swift @@ -2,6 +2,7 @@ import Combine import Foundation final class RenderVM: ObservableObject { + let glView = RenderGLView(frame: .zero) var timer: Timer? static private(set) weak var shared: RenderVM? -- 2.53.0 From 1b5c28c8966257ea7db33ba3bd9fde62057321a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Mon, 19 Oct 2026 16:18:27 +0300 Subject: [PATCH 14/57] silence gl warnings --- game/ver-mac/Package.swift | 3 +++ 1 file changed, 3 insertions(+) diff --git a/game/ver-mac/Package.swift b/game/ver-mac/Package.swift index 3d9def7..96e5628 100644 --- a/game/ver-mac/Package.swift +++ b/game/ver-mac/Package.swift @@ -22,6 +22,9 @@ let package = Package( name: "ogs-mahjong", dependencies: ["RaylibBridge"], path: "src", + swiftSettings: [ + .unsafeFlags(["-Xcc", "-DGL_SILENCE_DEPRECATION"]) + ], linkerSettings: [ .unsafeFlags([ "-L", "\(raylibPrefix)/lib", -- 2.53.0 From 8c774edbea8ba9cd8bed79302e03cd16dda3cea9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Mon, 19 Oct 2026 16:27:02 +0300 Subject: [PATCH 15/57] silence raylib info --- game/ver-mac/bridge/raylib_bridge.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/game/ver-mac/bridge/raylib_bridge.c b/game/ver-mac/bridge/raylib_bridge.c index 4951ae0..fb597ae 100644 --- a/game/ver-mac/bridge/raylib_bridge.c +++ b/game/ver-mac/bridge/raylib_bridge.c @@ -146,6 +146,9 @@ void sr_init(int width, int height, const char *main_vs, const char *main_fs, sr_cfg = config; + // raylib's default INFO logging is noisy; keep warnings and errors only. + SetTraceLogLevel(LOG_WARNING); + rlLoadExtensions(sr_gl_loader); rlglInit(sr_width, sr_height); -- 2.53.0 From 24348ba6ad1fdc558c670fb1464149f3008ec59f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Mon, 19 Oct 2026 16:34:19 +0300 Subject: [PATCH 16/57] only update pixel size during rendering --- components/render/mac/view/RenderGLView.swift | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/components/render/mac/view/RenderGLView.swift b/components/render/mac/view/RenderGLView.swift index c4beeeb..323b041 100644 --- a/components/render/mac/view/RenderGLView.swift +++ b/components/render/mac/view/RenderGLView.swift @@ -33,7 +33,6 @@ final class RenderGLView: NSOpenGLView { var swapInterval: Int32 = 1 context.setValues(&swapInterval, for: .swapInterval) - updatePixelSize() sr_init(pixelWidth, pixelHeight, RENDER_SHADER_MAIN_VS, RENDER_SHADER_MAIN_FS, RENDER_SHADER_SHADOW_VS, RENDER_SHADER_SHADOW_FS, @@ -89,17 +88,15 @@ final class RenderGLView: NSOpenGLView { needsDisplay = true } - private func updatePixelSize() { - let backing = convertToBacking(bounds) - pixelWidth = Int32(max(1, backing.width)) - pixelHeight = Int32(max(1, backing.height)) - } - override func draw(_ dirtyRect: NSRect) { guard ready, let context = openGLContext else { return } context.makeCurrentContext() - updatePixelSize() + + // Update pixel size + let backing = convertToBacking(bounds) + pixelWidth = Int32(max(1, backing.width)) + pixelHeight = Int32(max(1, backing.height)) sr_resize(pixelWidth, pixelHeight) -- 2.53.0 From 0da8bfcfa206411a95dab488b5f74835ff6452cb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Mon, 19 Oct 2026 16:48:38 +0300 Subject: [PATCH 17/57] dbg --- components/render/mac/view/RenderGLView.swift | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/components/render/mac/view/RenderGLView.swift b/components/render/mac/view/RenderGLView.swift index 323b041..6eb0f29 100644 --- a/components/render/mac/view/RenderGLView.swift +++ b/components/render/mac/view/RenderGLView.swift @@ -33,6 +33,8 @@ final class RenderGLView: NSOpenGLView { var swapInterval: Int32 = 1 context.setValues(&swapInterval, for: .swapInterval) + otherPrintStderr("RenderGLView prepareOpenGL bounds \(bounds) backing \(convertToBacking(bounds))") + sr_init(pixelWidth, pixelHeight, RENDER_SHADER_MAIN_VS, RENDER_SHADER_MAIN_FS, RENDER_SHADER_SHADOW_VS, RENDER_SHADER_SHADOW_FS, @@ -80,11 +82,13 @@ final class RenderGLView: NSOpenGLView { override func reshape() { super.reshape() + otherPrintStderr("RenderGLView reshape bounds \(bounds) backing \(convertToBacking(bounds))") needsDisplay = true } override func viewDidChangeBackingProperties() { super.viewDidChangeBackingProperties() + otherPrintStderr("RenderGLView viewDidChangeBackingProperties bounds \(bounds) backing \(convertToBacking(bounds))") needsDisplay = true } @@ -95,6 +99,7 @@ final class RenderGLView: NSOpenGLView { // Update pixel size let backing = convertToBacking(bounds) + otherPrintStderr("RenderGLView draw bounds \(bounds) backing \(backing)") pixelWidth = Int32(max(1, backing.width)) pixelHeight = Int32(max(1, backing.height)) -- 2.53.0 From 30476a880ddffaa6bf62e3df75d71c62072e85fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Mon, 19 Oct 2026 17:08:35 +0300 Subject: [PATCH 18/57] recalc --- components/render/mac/view/RenderGLView.swift | 16 ++--- components/render/renderAux.swift | 8 +++ dialect.yml | 11 +++- game/ver-mac/src/dialect.swift | 58 ++++++++++++++----- game/ver-mac/src/render/renderAux.swift | 1 + 5 files changed, 69 insertions(+), 25 deletions(-) create mode 100644 components/render/renderAux.swift create mode 120000 game/ver-mac/src/render/renderAux.swift diff --git a/components/render/mac/view/RenderGLView.swift b/components/render/mac/view/RenderGLView.swift index 6eb0f29..927decd 100644 --- a/components/render/mac/view/RenderGLView.swift +++ b/components/render/mac/view/RenderGLView.swift @@ -6,8 +6,8 @@ import SwiftUI final class RenderGLView: NSOpenGLView { private var renderTimer: Timer? private var ready = false - private var pixelWidth: Int32 = 1 - private var pixelHeight: Int32 = 1 + //private var pixelWidth: Int32 = 1 + //private var pixelHeight: Int32 = 1 private var startTime: CFTimeInterval = 0 override init(frame frameRect: NSRect) { @@ -33,9 +33,7 @@ final class RenderGLView: NSOpenGLView { var swapInterval: Int32 = 1 context.setValues(&swapInterval, for: .swapInterval) - otherPrintStderr("RenderGLView prepareOpenGL bounds \(bounds) backing \(convertToBacking(bounds))") - - sr_init(pixelWidth, pixelHeight, + sr_init(1, 1, RENDER_SHADER_MAIN_VS, RENDER_SHADER_MAIN_FS, RENDER_SHADER_SHADOW_VS, RENDER_SHADER_SHADOW_FS, RENDER_CONFIG) @@ -84,12 +82,14 @@ final class RenderGLView: NSOpenGLView { super.reshape() otherPrintStderr("RenderGLView reshape bounds \(bounds) backing \(convertToBacking(bounds))") needsDisplay = true + renderSet(F.didReshape, true) } override func viewDidChangeBackingProperties() { super.viewDidChangeBackingProperties() otherPrintStderr("RenderGLView viewDidChangeBackingProperties bounds \(bounds) backing \(convertToBacking(bounds))") needsDisplay = true + renderSet(F.didChangeBacking, true) } override func draw(_ dirtyRect: NSRect) { @@ -98,12 +98,14 @@ final class RenderGLView: NSOpenGLView { context.makeCurrentContext() // Update pixel size + let pixelSize = renderPixelSize(self) + /* let backing = convertToBacking(bounds) - otherPrintStderr("RenderGLView draw bounds \(bounds) backing \(backing)") pixelWidth = Int32(max(1, backing.width)) pixelHeight = Int32(max(1, backing.height)) + */ - sr_resize(pixelWidth, pixelHeight) + sr_resize(pixelSize[0], pixelSize[1]) let t = Float(CACurrentMediaTime() - startTime) diff --git a/components/render/renderAux.swift b/components/render/renderAux.swift new file mode 100644 index 0000000..aa38d1b --- /dev/null +++ b/components/render/renderAux.swift @@ -0,0 +1,8 @@ +import AppKit + +func renderPixelSize(_ view: NSView) -> [Int32] { + let backing = view.convertToBacking(view.bounds) + let w = Int32(max(1, backing.width)) + let h = Int32(max(1, backing.height)) + return [w, h] +} diff --git a/dialect.yml b/dialect.yml index 8bc568f..b17a0aa 100644 --- a/dialect.yml +++ b/dialect.yml @@ -7,11 +7,12 @@ output: RenderContext: type: context fields: + didChangeBacking: Bool didLaunch: Bool + didReshape: Bool didSetup: Bool isReadyToRender: Bool - pixelHeight: Int - pixelWidth: Int + pixelSize: [Int32] RenderComponent: type: component @@ -25,6 +26,12 @@ RenderComponent: c.didLaunch == false then: c.didLaunch = true + pixelSize: + 1. Upon launch: + if: + c.recentField == F.didLaunch + then: + c.pixelSize = [1, 1] RootComponent: type: component diff --git a/game/ver-mac/src/dialect.swift b/game/ver-mac/src/dialect.swift index a3316be..c32b3ac 100644 --- a/game/ver-mac/src/dialect.swift +++ b/game/ver-mac/src/dialect.swift @@ -121,38 +121,43 @@ func registerOneliners( public struct F { public static let count = "count" public static let countText = "countText" + public static let didChangeBacking = "didChangeBacking" public static let didClickIncrement = "didClickIncrement" public static let didLaunch = "didLaunch" + public static let didReshape = "didReshape" public static let didSetup = "didSetup" public static let isReadyToRender = "isReadyToRender" - public static let pixelHeight = "pixelHeight" - public static let pixelWidth = "pixelWidth" + public static let pixelSize = "pixelSize" } public struct RenderContext: DialectContext { + public var didChangeBacking = Bool() public var didLaunch = Bool() + public var didReshape = Bool() public var didSetup = Bool() public var isReadyToRender = Bool() - public var pixelHeight = Int() - public var pixelWidth = Int() + public var pixelSize = [Int32]() public var recentField = "" public func field(_ name: String) -> T { - if (name == "didLaunch") { + if (name == "didChangeBacking") { + return didChangeBacking as! T + } + else if (name == "didLaunch") { return didLaunch as! T } + else if (name == "didReshape") { + return didReshape as! T + } else if (name == "didSetup") { return didSetup as! T } else if (name == "isReadyToRender") { return isReadyToRender as! T } - else if (name == "pixelHeight") { - return pixelHeight as! T - } - else if (name == "pixelWidth") { - return pixelWidth as! T + else if (name == "pixelSize") { + return pixelSize as! T } return "unknown-field-name" as! T @@ -162,20 +167,23 @@ public struct RenderContext: DialectContext { _ name: String, _ value: Any ) { - if (name == "didLaunch") { + if (name == "didChangeBacking") { + didChangeBacking = value as! Bool + } + else if (name == "didLaunch") { didLaunch = value as! Bool } + else if (name == "didReshape") { + didReshape = value as! Bool + } else if (name == "didSetup") { didSetup = value as! Bool } else if (name == "isReadyToRender") { isReadyToRender = value as! Bool } - else if (name == "pixelHeight") { - pixelHeight = value as! Int - } - else if (name == "pixelWidth") { - pixelWidth = value as! Int + else if (name == "pixelSize") { + pixelSize = value as! [Int32] } } @@ -265,6 +273,23 @@ func renderShouldResetDidLaunch(_ c: RenderContext) -> RenderContext { return c } +func renderShouldResetPixelSize(_ c: RenderContext) -> RenderContext { + var c = c + + /* 1. Upon launch */ + if + c.recentField == F.didLaunch + { + c.pixelSize = [1, 1] + c.recentField = F.pixelSize + return c + } + + + c.recentField = DIALECT_CONTEXT_RECENT_FIELD_NONE + return c +} + func rootShouldResetCount(_ c: RootContext) -> RootContext { var c = c @@ -339,6 +364,7 @@ func rootShouldResetDidLaunch(_ c: RootContext) -> RootContext { func renderRegisterShoulds(_ ctrl: DialectController) { [ renderShouldResetDidLaunch, + renderShouldResetPixelSize, ].forEach { f in ctrl.registerFunction { c in f(c as! RenderContext) } diff --git a/game/ver-mac/src/render/renderAux.swift b/game/ver-mac/src/render/renderAux.swift new file mode 120000 index 0000000..1975b82 --- /dev/null +++ b/game/ver-mac/src/render/renderAux.swift @@ -0,0 +1 @@ +../../../../components/render/renderAux.swift \ No newline at end of file -- 2.53.0 From 7c8bbe64734d68d89e4840fe3540a370e94b4140 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Mon, 19 Oct 2026 17:12:48 +0300 Subject: [PATCH 19/57] ps --- components/render/mac/view/RenderGLView.swift | 10 ++-- dialect.yml | 14 +++++- game/ver-mac/src/dialect.swift | 46 +++++++++++++------ 3 files changed, 50 insertions(+), 20 deletions(-) diff --git a/components/render/mac/view/RenderGLView.swift b/components/render/mac/view/RenderGLView.swift index 927decd..e770c0c 100644 --- a/components/render/mac/view/RenderGLView.swift +++ b/components/render/mac/view/RenderGLView.swift @@ -80,16 +80,18 @@ final class RenderGLView: NSOpenGLView { override func reshape() { super.reshape() - otherPrintStderr("RenderGLView reshape bounds \(bounds) backing \(convertToBacking(bounds))") needsDisplay = true - renderSet(F.didReshape, true) + + let ps = renderPixelSize(self) + renderSet(F.reshapePixelSize, ps) } override func viewDidChangeBackingProperties() { super.viewDidChangeBackingProperties() - otherPrintStderr("RenderGLView viewDidChangeBackingProperties bounds \(bounds) backing \(convertToBacking(bounds))") needsDisplay = true - renderSet(F.didChangeBacking, true) + + let ps = renderPixelSize(self) + renderSet(F.backingPixelSize, ps) } override func draw(_ dirtyRect: NSRect) { diff --git a/dialect.yml b/dialect.yml index b17a0aa..4fe27a6 100644 --- a/dialect.yml +++ b/dialect.yml @@ -7,12 +7,12 @@ output: RenderContext: type: context fields: - didChangeBacking: Bool + backingPixelSize: [Int32] didLaunch: Bool - didReshape: Bool didSetup: Bool isReadyToRender: Bool pixelSize: [Int32] + reshapePixelSize: [Int32] RenderComponent: type: component @@ -32,6 +32,16 @@ RenderComponent: c.recentField == F.didLaunch then: c.pixelSize = [1, 1] + 2. Upon resize: + if: + c.recentField == F.reshapePixelSize + then: + c.pixelSize = c.reshapePixelSize + 3. Upon DPI change: + if: + c.recentField == F.backingPixelSize + then: + c.pixelSize = c.backingPixelSize RootComponent: type: component diff --git a/game/ver-mac/src/dialect.swift b/game/ver-mac/src/dialect.swift index c32b3ac..d0ddb03 100644 --- a/game/ver-mac/src/dialect.swift +++ b/game/ver-mac/src/dialect.swift @@ -119,37 +119,34 @@ func registerOneliners( // Context field names for static type check public struct F { + public static let backingPixelSize = "backingPixelSize" public static let count = "count" public static let countText = "countText" - public static let didChangeBacking = "didChangeBacking" public static let didClickIncrement = "didClickIncrement" public static let didLaunch = "didLaunch" - public static let didReshape = "didReshape" public static let didSetup = "didSetup" public static let isReadyToRender = "isReadyToRender" public static let pixelSize = "pixelSize" + public static let reshapePixelSize = "reshapePixelSize" } public struct RenderContext: DialectContext { - public var didChangeBacking = Bool() + public var backingPixelSize = [Int32]() public var didLaunch = Bool() - public var didReshape = Bool() public var didSetup = Bool() public var isReadyToRender = Bool() public var pixelSize = [Int32]() + public var reshapePixelSize = [Int32]() public var recentField = "" public func field(_ name: String) -> T { - if (name == "didChangeBacking") { - return didChangeBacking as! T + if (name == "backingPixelSize") { + return backingPixelSize as! T } else if (name == "didLaunch") { return didLaunch as! T } - else if (name == "didReshape") { - return didReshape as! T - } else if (name == "didSetup") { return didSetup as! T } @@ -159,6 +156,9 @@ public struct RenderContext: DialectContext { else if (name == "pixelSize") { return pixelSize as! T } + else if (name == "reshapePixelSize") { + return reshapePixelSize as! T + } return "unknown-field-name" as! T } @@ -167,15 +167,12 @@ public struct RenderContext: DialectContext { _ name: String, _ value: Any ) { - if (name == "didChangeBacking") { - didChangeBacking = value as! Bool + if (name == "backingPixelSize") { + backingPixelSize = value as! [Int32] } else if (name == "didLaunch") { didLaunch = value as! Bool } - else if (name == "didReshape") { - didReshape = value as! Bool - } else if (name == "didSetup") { didSetup = value as! Bool } @@ -185,6 +182,9 @@ public struct RenderContext: DialectContext { else if (name == "pixelSize") { pixelSize = value as! [Int32] } + else if (name == "reshapePixelSize") { + reshapePixelSize = value as! [Int32] + } } } @@ -285,6 +285,24 @@ func renderShouldResetPixelSize(_ c: RenderContext) -> RenderContext { return c } + /* 2. Upon resize */ + if + c.recentField == F.reshapePixelSize + { + c.pixelSize = c.reshapePixelSize + c.recentField = F.pixelSize + return c + } + + /* 3. Upon DPI change */ + if + c.recentField == F.backingPixelSize + { + c.pixelSize = c.backingPixelSize + c.recentField = F.pixelSize + return c + } + c.recentField = DIALECT_CONTEXT_RECENT_FIELD_NONE return c -- 2.53.0 From 12f64c2f03c997efe3de491e1eb3829100cd6a6b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Mon, 19 Oct 2026 17:14:41 +0300 Subject: [PATCH 20/57] some --- components/render/mac/view/RenderGLView.swift | 5 ----- 1 file changed, 5 deletions(-) diff --git a/components/render/mac/view/RenderGLView.swift b/components/render/mac/view/RenderGLView.swift index e770c0c..2910598 100644 --- a/components/render/mac/view/RenderGLView.swift +++ b/components/render/mac/view/RenderGLView.swift @@ -101,11 +101,6 @@ final class RenderGLView: NSOpenGLView { // Update pixel size let pixelSize = renderPixelSize(self) - /* - let backing = convertToBacking(bounds) - pixelWidth = Int32(max(1, backing.width)) - pixelHeight = Int32(max(1, backing.height)) - */ sr_resize(pixelSize[0], pixelSize[1]) -- 2.53.0 From b068b866f0d5f85abdc2e5a7906e7d6bd97c258d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Mon, 19 Oct 2026 17:22:16 +0300 Subject: [PATCH 21/57] pixel size --- components/render/mac/view/RenderGLView.swift | 9 +++------ components/render/renderVM.swift | 1 + dialect.yml | 1 + game/ver-mac/src/dialect.swift | 1 + 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/components/render/mac/view/RenderGLView.swift b/components/render/mac/view/RenderGLView.swift index 2910598..54fc8e1 100644 --- a/components/render/mac/view/RenderGLView.swift +++ b/components/render/mac/view/RenderGLView.swift @@ -6,8 +6,6 @@ import SwiftUI final class RenderGLView: NSOpenGLView { private var renderTimer: Timer? private var ready = false - //private var pixelWidth: Int32 = 1 - //private var pixelHeight: Int32 = 1 private var startTime: CFTimeInterval = 0 override init(frame frameRect: NSRect) { @@ -95,14 +93,13 @@ final class RenderGLView: NSOpenGLView { } override func draw(_ dirtyRect: NSRect) { + let vm = RenderVM.shared! + guard ready, let context = openGLContext else { return } context.makeCurrentContext() - // Update pixel size - let pixelSize = renderPixelSize(self) - - sr_resize(pixelSize[0], pixelSize[1]) + sr_resize(vm.pixelSize[0], vm.pixelSize[1]) let t = Float(CACurrentMediaTime() - startTime) diff --git a/components/render/renderVM.swift b/components/render/renderVM.swift index e023c3c..56ea930 100644 --- a/components/render/renderVM.swift +++ b/components/render/renderVM.swift @@ -3,6 +3,7 @@ import Foundation final class RenderVM: ObservableObject { let glView = RenderGLView(frame: .zero) + var pixelSize = [Int32]() var timer: Timer? static private(set) weak var shared: RenderVM? diff --git a/dialect.yml b/dialect.yml index 4fe27a6..01baf85 100644 --- a/dialect.yml +++ b/dialect.yml @@ -18,6 +18,7 @@ RenderComponent: type: component oneliners: - isReadyToRender: print("ИГР isRTR: '\(c.isReadyToRender)'") + - pixelSize: RenderVM.shared!.pixelSize = c.pixelSize shoulds: didLaunch: 1. Only once during the first setup: diff --git a/game/ver-mac/src/dialect.swift b/game/ver-mac/src/dialect.swift index d0ddb03..12ab592 100644 --- a/game/ver-mac/src/dialect.swift +++ b/game/ver-mac/src/dialect.swift @@ -403,6 +403,7 @@ func rootRegisterShoulds(_ ctrl: DialectController) { func renderRegisterEffects(_ ctrl: DialectController) { let _: RenderContext? = registerOneliners(ctrl, [ F.isReadyToRender, { (c: RenderContext) in print("ИГР isRTR: '\(c.isReadyToRender)'") }, + F.pixelSize, { (c: RenderContext) in RenderVM.shared!.pixelSize = c.pixelSize }, ]) } -- 2.53.0 From fab65fb5ad49bc72d6b7608802284fb4b6dc8460 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Mon, 19 Oct 2026 17:57:54 +0300 Subject: [PATCH 22/57] move timer --- components/render/mac/view/RenderGLView.swift | 17 ++++------------- components/render/renderConst.swift | 2 ++ components/render/renderEffect.swift | 11 +++++++++++ dialect.yml | 2 ++ game/ver-mac/src/dialect.swift | 9 +++++++++ game/ver-mac/src/render/renderEffect.swift | 1 + 6 files changed, 29 insertions(+), 13 deletions(-) create mode 100644 components/render/renderEffect.swift create mode 120000 game/ver-mac/src/render/renderEffect.swift diff --git a/components/render/mac/view/RenderGLView.swift b/components/render/mac/view/RenderGLView.swift index 54fc8e1..ebe1055 100644 --- a/components/render/mac/view/RenderGLView.swift +++ b/components/render/mac/view/RenderGLView.swift @@ -4,7 +4,6 @@ import RaylibBridge import SwiftUI final class RenderGLView: NSOpenGLView { - private var renderTimer: Timer? private var ready = false private var startTime: CFTimeInterval = 0 @@ -24,8 +23,8 @@ final class RenderGLView: NSOpenGLView { override func prepareOpenGL() { super.prepareOpenGL() - guard let context = openGLContext else { return } + context.makeCurrentContext() var swapInterval: Int32 = 1 @@ -39,16 +38,7 @@ final class RenderGLView: NSOpenGLView { startTime = CACurrentMediaTime() ready = true - startRenderTimer() - } - - private func startRenderTimer() { - guard renderTimer == nil else { return } - let timer = Timer(timeInterval: 1.0 / 60.0, repeats: true) { [weak self] _ in - self?.needsDisplay = true - } - RunLoop.main.add(timer, forMode: .common) - renderTimer = timer + renderSet(F.willPrepareGLContext, true) } private func loadModel() { @@ -111,7 +101,8 @@ final class RenderGLView: NSOpenGLView { } deinit { - renderTimer?.invalidate() + print("ИГР RenderGV.deinit") + // TODO: renderTimer?.invalidate() openGLContext?.makeCurrentContext() sr_shutdown() } diff --git a/components/render/renderConst.swift b/components/render/renderConst.swift index fd31c4c..248a7a4 100644 --- a/components/render/renderConst.swift +++ b/components/render/renderConst.swift @@ -9,6 +9,8 @@ let RENDER_CONFIG = sr_config( ground_size: 40.0 ) +let RENDER_FPS = 60.0 + let RENDER_OPENGL_ATTRS: [NSOpenGLPixelFormatAttribute] = [ UInt32(NSOpenGLPFAOpenGLProfile), UInt32(NSOpenGLProfileVersion3_2Core), UInt32(NSOpenGLPFAColorSize), 24, diff --git a/components/render/renderEffect.swift b/components/render/renderEffect.swift new file mode 100644 index 0000000..8f9bbe2 --- /dev/null +++ b/components/render/renderEffect.swift @@ -0,0 +1,11 @@ +import Foundation + +func renderStartTimer(_ vm: RenderVM) { + // Schedule repaints every once in FPS seconds + let timer = Timer(timeInterval: 1.0 / RENDER_FPS, repeats: true) { [weak vm] _ in + vm?.glView.needsDisplay = true + } + vm.timer = timer + // Use .common so that holding buttons in UI does not pause this rendering timer + RunLoop.main.add(timer, forMode: .common) +} diff --git a/dialect.yml b/dialect.yml index 01baf85..e14708c 100644 --- a/dialect.yml +++ b/dialect.yml @@ -13,12 +13,14 @@ RenderContext: isReadyToRender: Bool pixelSize: [Int32] reshapePixelSize: [Int32] + willPrepareGLContext: Bool RenderComponent: type: component oneliners: - isReadyToRender: print("ИГР isRTR: '\(c.isReadyToRender)'") - pixelSize: RenderVM.shared!.pixelSize = c.pixelSize + - willPrepareGLContext: renderStartTimer(RenderVM.shared!) shoulds: didLaunch: 1. Only once during the first setup: diff --git a/game/ver-mac/src/dialect.swift b/game/ver-mac/src/dialect.swift index 12ab592..2437379 100644 --- a/game/ver-mac/src/dialect.swift +++ b/game/ver-mac/src/dialect.swift @@ -128,6 +128,7 @@ public struct F { public static let isReadyToRender = "isReadyToRender" public static let pixelSize = "pixelSize" public static let reshapePixelSize = "reshapePixelSize" + public static let willPrepareGLContext = "willPrepareGLContext" } public struct RenderContext: DialectContext { @@ -137,6 +138,7 @@ public struct RenderContext: DialectContext { public var isReadyToRender = Bool() public var pixelSize = [Int32]() public var reshapePixelSize = [Int32]() + public var willPrepareGLContext = Bool() public var recentField = "" @@ -159,6 +161,9 @@ public struct RenderContext: DialectContext { else if (name == "reshapePixelSize") { return reshapePixelSize as! T } + else if (name == "willPrepareGLContext") { + return willPrepareGLContext as! T + } return "unknown-field-name" as! T } @@ -185,6 +190,9 @@ public struct RenderContext: DialectContext { else if (name == "reshapePixelSize") { reshapePixelSize = value as! [Int32] } + else if (name == "willPrepareGLContext") { + willPrepareGLContext = value as! Bool + } } } @@ -404,6 +412,7 @@ func renderRegisterEffects(_ ctrl: DialectController) { let _: RenderContext? = registerOneliners(ctrl, [ F.isReadyToRender, { (c: RenderContext) in print("ИГР isRTR: '\(c.isReadyToRender)'") }, F.pixelSize, { (c: RenderContext) in RenderVM.shared!.pixelSize = c.pixelSize }, + F.willPrepareGLContext, { (c: RenderContext) in renderStartTimer(RenderVM.shared!) }, ]) } diff --git a/game/ver-mac/src/render/renderEffect.swift b/game/ver-mac/src/render/renderEffect.swift new file mode 120000 index 0000000..d269bb5 --- /dev/null +++ b/game/ver-mac/src/render/renderEffect.swift @@ -0,0 +1 @@ +../../../../components/render/renderEffect.swift \ No newline at end of file -- 2.53.0 From 813490c0eab3e772e494681b6c20c080bc3b8b61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Mon, 19 Oct 2026 18:03:07 +0300 Subject: [PATCH 23/57] som --- components/render/mac/view/RenderGLView.swift | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/components/render/mac/view/RenderGLView.swift b/components/render/mac/view/RenderGLView.swift index ebe1055..54301e5 100644 --- a/components/render/mac/view/RenderGLView.swift +++ b/components/render/mac/view/RenderGLView.swift @@ -42,13 +42,6 @@ final class RenderGLView: NSOpenGLView { } private func loadModel() { - for path in modelCandidates() where FileManager.default.fileExists(atPath: path) { - sr_load_model(path) - return - } - } - - private func modelCandidates() -> [String] { var paths: [String] = [] if let resources = Bundle.main.resourceURL { @@ -63,7 +56,10 @@ final class RenderGLView: NSOpenGLView { paths.append(dir.appendingPathComponent("assets/cube.gltf").path) } - return paths + for path in paths where FileManager.default.fileExists(atPath: path) { + sr_load_model(path) + return + } } override func reshape() { -- 2.53.0 From 4f40b509f6822170208dc7ef8a22c431d17574c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Mon, 19 Oct 2026 18:09:55 +0300 Subject: [PATCH 24/57] dbg --- components/render/mac/view/RenderGLView.swift | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/components/render/mac/view/RenderGLView.swift b/components/render/mac/view/RenderGLView.swift index 54301e5..f39b791 100644 --- a/components/render/mac/view/RenderGLView.swift +++ b/components/render/mac/view/RenderGLView.swift @@ -45,20 +45,27 @@ final class RenderGLView: NSOpenGLView { var paths: [String] = [] if let resources = Bundle.main.resourceURL { + print("ИГР RenderGV.loadM-1 resources: '\(resources.path)'") paths.append(resources.appendingPathComponent("assets/cube.gltf").path) } let cwd = FileManager.default.currentDirectoryPath paths.append("\(cwd)/assets/cube.gltf") + print("ИГР RenderGV.loadM-2 cwd: '\(cwd)'") if let exe = Bundle.main.executableURL { let dir = exe.deletingLastPathComponent() + print("ИГР RenderGV.loadM-2 exedir: '\(dir)'") paths.append(dir.appendingPathComponent("assets/cube.gltf").path) } - for path in paths where FileManager.default.fileExists(atPath: path) { - sr_load_model(path) - return + for path in paths { + print("ИГР RenderGV.loadM-10 path: '\(path)'") + if FileManager.default.fileExists(atPath: path) { + print("ИГР RenderGV.loadM-11 load") + sr_load_model(path) + return + } } } -- 2.53.0 From 5c93de77645c382ee9b8a7fbe7fd7dbb03636aca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Mon, 19 Oct 2026 18:13:27 +0300 Subject: [PATCH 25/57] smaller --- components/render/mac/view/RenderGLView.swift | 28 +++---------------- 1 file changed, 4 insertions(+), 24 deletions(-) diff --git a/components/render/mac/view/RenderGLView.swift b/components/render/mac/view/RenderGLView.swift index f39b791..46f05e5 100644 --- a/components/render/mac/view/RenderGLView.swift +++ b/components/render/mac/view/RenderGLView.swift @@ -42,30 +42,10 @@ final class RenderGLView: NSOpenGLView { } private func loadModel() { - var paths: [String] = [] - - if let resources = Bundle.main.resourceURL { - print("ИГР RenderGV.loadM-1 resources: '\(resources.path)'") - paths.append(resources.appendingPathComponent("assets/cube.gltf").path) - } - - let cwd = FileManager.default.currentDirectoryPath - paths.append("\(cwd)/assets/cube.gltf") - print("ИГР RenderGV.loadM-2 cwd: '\(cwd)'") - - if let exe = Bundle.main.executableURL { - let dir = exe.deletingLastPathComponent() - print("ИГР RenderGV.loadM-2 exedir: '\(dir)'") - paths.append(dir.appendingPathComponent("assets/cube.gltf").path) - } - - for path in paths { - print("ИГР RenderGV.loadM-10 path: '\(path)'") - if FileManager.default.fileExists(atPath: path) { - print("ИГР RenderGV.loadM-11 load") - sr_load_model(path) - return - } + guard let resources = Bundle.main.resourceURL else { return } + let path = resources.appendingPathComponent("assets/cube.gltf").path + if FileManager.default.fileExists(atPath: path) { + sr_load_model(path) } } -- 2.53.0 From cc29a5fc93e0f233b68002aff1c4fab8fc63a455 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Mon, 19 Oct 2026 18:25:35 +0300 Subject: [PATCH 26/57] try to load model on click --- components/render/mac/view/RenderGLView.swift | 10 +--------- components/render/renderConst.swift | 2 ++ components/render/renderEffect.swift | 7 +++++++ dialect.yml | 3 +++ game/ver-mac/src/dialect.swift | 9 +++++++++ 5 files changed, 22 insertions(+), 9 deletions(-) diff --git a/components/render/mac/view/RenderGLView.swift b/components/render/mac/view/RenderGLView.swift index 46f05e5..2c0dc77 100644 --- a/components/render/mac/view/RenderGLView.swift +++ b/components/render/mac/view/RenderGLView.swift @@ -34,21 +34,13 @@ final class RenderGLView: NSOpenGLView { RENDER_SHADER_MAIN_VS, RENDER_SHADER_MAIN_FS, RENDER_SHADER_SHADOW_VS, RENDER_SHADER_SHADOW_FS, RENDER_CONFIG) - loadModel() + //loadModel() startTime = CACurrentMediaTime() ready = true renderSet(F.willPrepareGLContext, true) } - private func loadModel() { - guard let resources = Bundle.main.resourceURL else { return } - let path = resources.appendingPathComponent("assets/cube.gltf").path - if FileManager.default.fileExists(atPath: path) { - sr_load_model(path) - } - } - override func reshape() { super.reshape() needsDisplay = true diff --git a/components/render/renderConst.swift b/components/render/renderConst.swift index 248a7a4..fdf3b6b 100644 --- a/components/render/renderConst.swift +++ b/components/render/renderConst.swift @@ -11,6 +11,8 @@ let RENDER_CONFIG = sr_config( let RENDER_FPS = 60.0 +let RENDER_MODEL_CUBE = "/assets/cube.gltf" + let RENDER_OPENGL_ATTRS: [NSOpenGLPixelFormatAttribute] = [ UInt32(NSOpenGLPFAOpenGLProfile), UInt32(NSOpenGLProfileVersion3_2Core), UInt32(NSOpenGLPFAColorSize), 24, diff --git a/components/render/renderEffect.swift b/components/render/renderEffect.swift index 8f9bbe2..7089dcd 100644 --- a/components/render/renderEffect.swift +++ b/components/render/renderEffect.swift @@ -1,4 +1,11 @@ import Foundation +import RaylibBridge + +func renderLoadCubeModel() { + let path = Bundle.main.resourceURL!.path + RENDER_MODEL_CUBE + print("ИГР renderLCB path: '\(path)'") + sr_load_model(path) +} func renderStartTimer(_ vm: RenderVM) { // Schedule repaints every once in FPS seconds diff --git a/dialect.yml b/dialect.yml index e14708c..4567e19 100644 --- a/dialect.yml +++ b/dialect.yml @@ -8,6 +8,7 @@ RenderContext: type: context fields: backingPixelSize: [Int32] + didClickIncrement: Bool didLaunch: Bool didSetup: Bool isReadyToRender: Bool @@ -18,6 +19,7 @@ RenderContext: RenderComponent: type: component oneliners: + - didClickIncrement: renderLoadCubeModel() - isReadyToRender: print("ИГР isRTR: '\(c.isReadyToRender)'") - pixelSize: RenderVM.shared!.pixelSize = c.pixelSize - willPrepareGLContext: renderStartTimer(RenderVM.shared!) @@ -50,6 +52,7 @@ RootComponent: type: component oneliners: - countText: RootVM.shared!.countText = c.countText + - didClickIncrement: renderSet(F.didClickIncrement, true) shoulds: count: 1. Upon hitting 10 the first time: diff --git a/game/ver-mac/src/dialect.swift b/game/ver-mac/src/dialect.swift index 2437379..b88bdd7 100644 --- a/game/ver-mac/src/dialect.swift +++ b/game/ver-mac/src/dialect.swift @@ -133,6 +133,7 @@ public struct F { } public struct RenderContext: DialectContext { public var backingPixelSize = [Int32]() + public var didClickIncrement = Bool() public var didLaunch = Bool() public var didSetup = Bool() public var isReadyToRender = Bool() @@ -146,6 +147,9 @@ public struct RenderContext: DialectContext { if (name == "backingPixelSize") { return backingPixelSize as! T } + else if (name == "didClickIncrement") { + return didClickIncrement as! T + } else if (name == "didLaunch") { return didLaunch as! T } @@ -175,6 +179,9 @@ public struct RenderContext: DialectContext { if (name == "backingPixelSize") { backingPixelSize = value as! [Int32] } + else if (name == "didClickIncrement") { + didClickIncrement = value as! Bool + } else if (name == "didLaunch") { didLaunch = value as! Bool } @@ -410,6 +417,7 @@ func rootRegisterShoulds(_ ctrl: DialectController) { func renderRegisterEffects(_ ctrl: DialectController) { let _: RenderContext? = registerOneliners(ctrl, [ + F.didClickIncrement, { (c: RenderContext) in renderLoadCubeModel() }, F.isReadyToRender, { (c: RenderContext) in print("ИГР isRTR: '\(c.isReadyToRender)'") }, F.pixelSize, { (c: RenderContext) in RenderVM.shared!.pixelSize = c.pixelSize }, F.willPrepareGLContext, { (c: RenderContext) in renderStartTimer(RenderVM.shared!) }, @@ -420,6 +428,7 @@ func renderRegisterEffects(_ ctrl: DialectController) { func rootRegisterEffects(_ ctrl: DialectController) { let _: RootContext? = registerOneliners(ctrl, [ F.countText, { (c: RootContext) in RootVM.shared!.countText = c.countText }, + F.didClickIncrement, { (c: RootContext) in renderSet(F.didClickIncrement, true) }, ]) } -- 2.53.0 From 4905098d2801da8ac28209bb52e479dae92425d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Mon, 19 Oct 2026 18:32:50 +0300 Subject: [PATCH 27/57] load model on click --- components/render/renderEffect.swift | 4 ++-- dialect.yml | 3 +-- game/ver-mac/src/dialect.swift | 3 +-- 3 files changed, 4 insertions(+), 6 deletions(-) diff --git a/components/render/renderEffect.swift b/components/render/renderEffect.swift index 7089dcd..b1f0f63 100644 --- a/components/render/renderEffect.swift +++ b/components/render/renderEffect.swift @@ -1,9 +1,9 @@ import Foundation import RaylibBridge -func renderLoadCubeModel() { +func renderLoadCubeModel(_ vm: RenderVM) { let path = Bundle.main.resourceURL!.path + RENDER_MODEL_CUBE - print("ИГР renderLCB path: '\(path)'") + vm.glView.openGLContext?.makeCurrentContext() sr_load_model(path) } diff --git a/dialect.yml b/dialect.yml index 4567e19..d6fa57c 100644 --- a/dialect.yml +++ b/dialect.yml @@ -19,8 +19,7 @@ RenderContext: RenderComponent: type: component oneliners: - - didClickIncrement: renderLoadCubeModel() - - isReadyToRender: print("ИГР isRTR: '\(c.isReadyToRender)'") + - didClickIncrement: renderLoadCubeModel(RenderVM.shared!) - pixelSize: RenderVM.shared!.pixelSize = c.pixelSize - willPrepareGLContext: renderStartTimer(RenderVM.shared!) shoulds: diff --git a/game/ver-mac/src/dialect.swift b/game/ver-mac/src/dialect.swift index b88bdd7..9ff171f 100644 --- a/game/ver-mac/src/dialect.swift +++ b/game/ver-mac/src/dialect.swift @@ -417,8 +417,7 @@ func rootRegisterShoulds(_ ctrl: DialectController) { func renderRegisterEffects(_ ctrl: DialectController) { let _: RenderContext? = registerOneliners(ctrl, [ - F.didClickIncrement, { (c: RenderContext) in renderLoadCubeModel() }, - F.isReadyToRender, { (c: RenderContext) in print("ИГР isRTR: '\(c.isReadyToRender)'") }, + F.didClickIncrement, { (c: RenderContext) in renderLoadCubeModel(RenderVM.shared!) }, F.pixelSize, { (c: RenderContext) in RenderVM.shared!.pixelSize = c.pixelSize }, F.willPrepareGLContext, { (c: RenderContext) in renderStartTimer(RenderVM.shared!) }, -- 2.53.0 From 7829cab78be9fc01507d57238a583250a9905b35 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Mon, 19 Oct 2026 18:33:38 +0300 Subject: [PATCH 28/57] no mo --- components/render/mac/view/RenderGLView.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/components/render/mac/view/RenderGLView.swift b/components/render/mac/view/RenderGLView.swift index 2c0dc77..1efb69e 100644 --- a/components/render/mac/view/RenderGLView.swift +++ b/components/render/mac/view/RenderGLView.swift @@ -34,7 +34,6 @@ final class RenderGLView: NSOpenGLView { RENDER_SHADER_MAIN_VS, RENDER_SHADER_MAIN_FS, RENDER_SHADER_SHADOW_VS, RENDER_SHADER_SHADOW_FS, RENDER_CONFIG) - //loadModel() startTime = CACurrentMediaTime() ready = true -- 2.53.0 From 137188e6184c5c75ae3024aa13e10fbd1cb5a412 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Tue, 20 Oct 2026 06:31:26 +0300 Subject: [PATCH 29/57] mv som --- components/render/mac/view/RenderGLView.swift | 21 +++++++------------ components/render/renderEffect.swift | 19 +++++++++++++++++ components/render/renderVM.swift | 1 + dialect.yml | 6 ++++-- game/ver-mac/src/dialect.swift | 20 ++++++++++-------- 5 files changed, 42 insertions(+), 25 deletions(-) diff --git a/components/render/mac/view/RenderGLView.swift b/components/render/mac/view/RenderGLView.swift index 1efb69e..192c47f 100644 --- a/components/render/mac/view/RenderGLView.swift +++ b/components/render/mac/view/RenderGLView.swift @@ -4,7 +4,6 @@ import RaylibBridge import SwiftUI final class RenderGLView: NSOpenGLView { - private var ready = false private var startTime: CFTimeInterval = 0 override init(frame frameRect: NSRect) { @@ -23,21 +22,10 @@ final class RenderGLView: NSOpenGLView { override func prepareOpenGL() { super.prepareOpenGL() - guard let context = openGLContext else { return } - context.makeCurrentContext() - - var swapInterval: Int32 = 1 - context.setValues(&swapInterval, for: .swapInterval) - - sr_init(1, 1, - RENDER_SHADER_MAIN_VS, RENDER_SHADER_MAIN_FS, - RENDER_SHADER_SHADOW_VS, RENDER_SHADER_SHADOW_FS, - RENDER_CONFIG) startTime = CACurrentMediaTime() - ready = true - renderSet(F.willPrepareGLContext, true) + renderSet(F.didPrepareGLContext, true) } override func reshape() { @@ -59,7 +47,12 @@ final class RenderGLView: NSOpenGLView { override func draw(_ dirtyRect: NSRect) { let vm = RenderVM.shared! - guard ready, let context = openGLContext else { return } + guard + vm.didPrepareGLContext, + let context = openGLContext + else { + return + } context.makeCurrentContext() diff --git a/components/render/renderEffect.swift b/components/render/renderEffect.swift index b1f0f63..7e95ae4 100644 --- a/components/render/renderEffect.swift +++ b/components/render/renderEffect.swift @@ -1,6 +1,25 @@ import Foundation import RaylibBridge +func renderInit(_ vm: RenderVM) { + vm.glView.openGLContext?.makeCurrentContext() + + // Enable VSync + var swapInterval: Int32 = 1 + vm.glView.openGLContext?.setValues(&swapInterval, for: .swapInterval) + + // Init Raylib + sr_init( + 1, // Default width + 1, // Default height + RENDER_SHADER_MAIN_VS, + RENDER_SHADER_MAIN_FS, + RENDER_SHADER_SHADOW_VS, + RENDER_SHADER_SHADOW_FS, + RENDER_CONFIG + ) +} + func renderLoadCubeModel(_ vm: RenderVM) { let path = Bundle.main.resourceURL!.path + RENDER_MODEL_CUBE vm.glView.openGLContext?.makeCurrentContext() diff --git a/components/render/renderVM.swift b/components/render/renderVM.swift index 56ea930..dc83843 100644 --- a/components/render/renderVM.swift +++ b/components/render/renderVM.swift @@ -2,6 +2,7 @@ import Combine import Foundation final class RenderVM: ObservableObject { + var didPrepareGLContext = false let glView = RenderGLView(frame: .zero) var pixelSize = [Int32]() var timer: Timer? diff --git a/dialect.yml b/dialect.yml index d6fa57c..a50260f 100644 --- a/dialect.yml +++ b/dialect.yml @@ -10,18 +10,20 @@ RenderContext: backingPixelSize: [Int32] didClickIncrement: Bool didLaunch: Bool + didPrepareGLContext: Bool didSetup: Bool isReadyToRender: Bool pixelSize: [Int32] reshapePixelSize: [Int32] - willPrepareGLContext: Bool RenderComponent: type: component oneliners: - didClickIncrement: renderLoadCubeModel(RenderVM.shared!) - pixelSize: RenderVM.shared!.pixelSize = c.pixelSize - - willPrepareGLContext: renderStartTimer(RenderVM.shared!) + - didPrepareGLContext: renderInit(RenderVM.shared!) + - didPrepareGLContext: RenderVM.shared!.didPrepareGLContext = true + - didPrepareGLContext: renderStartTimer(RenderVM.shared!) shoulds: didLaunch: 1. Only once during the first setup: diff --git a/game/ver-mac/src/dialect.swift b/game/ver-mac/src/dialect.swift index 9ff171f..1bca837 100644 --- a/game/ver-mac/src/dialect.swift +++ b/game/ver-mac/src/dialect.swift @@ -124,22 +124,22 @@ public struct F { public static let countText = "countText" public static let didClickIncrement = "didClickIncrement" public static let didLaunch = "didLaunch" + public static let didPrepareGLContext = "didPrepareGLContext" public static let didSetup = "didSetup" public static let isReadyToRender = "isReadyToRender" public static let pixelSize = "pixelSize" public static let reshapePixelSize = "reshapePixelSize" - public static let willPrepareGLContext = "willPrepareGLContext" } public struct RenderContext: DialectContext { public var backingPixelSize = [Int32]() public var didClickIncrement = Bool() public var didLaunch = Bool() + public var didPrepareGLContext = Bool() public var didSetup = Bool() public var isReadyToRender = Bool() public var pixelSize = [Int32]() public var reshapePixelSize = [Int32]() - public var willPrepareGLContext = Bool() public var recentField = "" @@ -153,6 +153,9 @@ public struct RenderContext: DialectContext { else if (name == "didLaunch") { return didLaunch as! T } + else if (name == "didPrepareGLContext") { + return didPrepareGLContext as! T + } else if (name == "didSetup") { return didSetup as! T } @@ -165,9 +168,6 @@ public struct RenderContext: DialectContext { else if (name == "reshapePixelSize") { return reshapePixelSize as! T } - else if (name == "willPrepareGLContext") { - return willPrepareGLContext as! T - } return "unknown-field-name" as! T } @@ -185,6 +185,9 @@ public struct RenderContext: DialectContext { else if (name == "didLaunch") { didLaunch = value as! Bool } + else if (name == "didPrepareGLContext") { + didPrepareGLContext = value as! Bool + } else if (name == "didSetup") { didSetup = value as! Bool } @@ -197,9 +200,6 @@ public struct RenderContext: DialectContext { else if (name == "reshapePixelSize") { reshapePixelSize = value as! [Int32] } - else if (name == "willPrepareGLContext") { - willPrepareGLContext = value as! Bool - } } } @@ -419,7 +419,9 @@ func renderRegisterEffects(_ ctrl: DialectController) { let _: RenderContext? = registerOneliners(ctrl, [ F.didClickIncrement, { (c: RenderContext) in renderLoadCubeModel(RenderVM.shared!) }, F.pixelSize, { (c: RenderContext) in RenderVM.shared!.pixelSize = c.pixelSize }, - F.willPrepareGLContext, { (c: RenderContext) in renderStartTimer(RenderVM.shared!) }, + F.didPrepareGLContext, { (c: RenderContext) in renderInit(RenderVM.shared!) }, + F.didPrepareGLContext, { (c: RenderContext) in RenderVM.shared!.didPrepareGLContext = true }, + F.didPrepareGLContext, { (c: RenderContext) in renderStartTimer(RenderVM.shared!) }, ]) } -- 2.53.0 From ff4613d8e6d6ac19f9726e9a9aab5b0e1104788a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Tue, 20 Oct 2026 06:50:13 +0300 Subject: [PATCH 30/57] gl view done --- components/render/mac/view/RenderGLView.swift | 34 +++---------------- components/render/renderAux.swift | 12 +++++++ components/render/renderEffect.swift | 13 ++++++- components/render/renderVM.swift | 3 +- dialect.yml | 10 +++--- game/ver-mac/src/dialect.swift | 27 ++++++++++----- 6 files changed, 54 insertions(+), 45 deletions(-) diff --git a/components/render/mac/view/RenderGLView.swift b/components/render/mac/view/RenderGLView.swift index 192c47f..b5b2c3b 100644 --- a/components/render/mac/view/RenderGLView.swift +++ b/components/render/mac/view/RenderGLView.swift @@ -1,11 +1,7 @@ import AppKit -import QuartzCore -import RaylibBridge import SwiftUI final class RenderGLView: NSOpenGLView { - private var startTime: CFTimeInterval = 0 - override init(frame frameRect: NSRect) { guard let format = NSOpenGLPixelFormat(attributes: RENDER_OPENGL_ATTRS) @@ -22,10 +18,7 @@ final class RenderGLView: NSOpenGLView { override func prepareOpenGL() { super.prepareOpenGL() - - startTime = CACurrentMediaTime() - - renderSet(F.didPrepareGLContext, true) + renderSet(F.didPrepareGL, true) } override func reshape() { @@ -46,31 +39,12 @@ final class RenderGLView: NSOpenGLView { override func draw(_ dirtyRect: NSRect) { let vm = RenderVM.shared! - - guard - vm.didPrepareGLContext, - let context = openGLContext - else { - return + if vm.didPrepareGL { + renderDraw(vm) } - - context.makeCurrentContext() - - sr_resize(vm.pixelSize[0], vm.pixelSize[1]) - - let t = Float(CACurrentMediaTime() - startTime) - - sr_set_rotation(t * 6.0, t * 18.0, 0.0) - - sr_render() - - context.flushBuffer() } deinit { - print("ИГР RenderGV.deinit") - // TODO: renderTimer?.invalidate() - openGLContext?.makeCurrentContext() - sr_shutdown() + renderSet(F.willDeinit, true) } } diff --git a/components/render/renderAux.swift b/components/render/renderAux.swift index aa38d1b..d8000c3 100644 --- a/components/render/renderAux.swift +++ b/components/render/renderAux.swift @@ -1,4 +1,16 @@ import AppKit +import RaylibBridge + +func renderDraw(_ vm: RenderVM) { + vm.glView.openGLContext?.makeCurrentContext() + + sr_resize(vm.pixelSize[0], vm.pixelSize[1]) + let t = Float(CACurrentMediaTime() - vm.startTime) + sr_set_rotation(t * 6.0, t * 18.0, 0.0) + sr_render() + + vm.glView.openGLContext?.flushBuffer() +} func renderPixelSize(_ view: NSView) -> [Int32] { let backing = view.convertToBacking(view.bounds) diff --git a/components/render/renderEffect.swift b/components/render/renderEffect.swift index 7e95ae4..4758875 100644 --- a/components/render/renderEffect.swift +++ b/components/render/renderEffect.swift @@ -1,5 +1,13 @@ import Foundation import RaylibBridge +import QuartzCore + +func renderDeinit(_ vm: RenderVM) { + print("ИГР renderD") + vm.timer?.invalidate() + vm.glView.openGLContext?.makeCurrentContext() + sr_shutdown() +} func renderInit(_ vm: RenderVM) { vm.glView.openGLContext?.makeCurrentContext() @@ -27,11 +35,14 @@ func renderLoadCubeModel(_ vm: RenderVM) { } func renderStartTimer(_ vm: RenderVM) { + // Make a time mark for calculating time delta + vm.startTime = CACurrentMediaTime() + // Schedule repaints every once in FPS seconds let timer = Timer(timeInterval: 1.0 / RENDER_FPS, repeats: true) { [weak vm] _ in vm?.glView.needsDisplay = true } vm.timer = timer - // Use .common so that holding buttons in UI does not pause this rendering timer + // .common means holding buttons in UI does not pause this rendering timer RunLoop.main.add(timer, forMode: .common) } diff --git a/components/render/renderVM.swift b/components/render/renderVM.swift index dc83843..f4b6166 100644 --- a/components/render/renderVM.swift +++ b/components/render/renderVM.swift @@ -2,9 +2,10 @@ import Combine import Foundation final class RenderVM: ObservableObject { - var didPrepareGLContext = false + var didPrepareGL = false let glView = RenderGLView(frame: .zero) var pixelSize = [Int32]() + var startTime: CFTimeInterval = 0 var timer: Timer? static private(set) weak var shared: RenderVM? diff --git a/dialect.yml b/dialect.yml index a50260f..38933b7 100644 --- a/dialect.yml +++ b/dialect.yml @@ -10,20 +10,22 @@ RenderContext: backingPixelSize: [Int32] didClickIncrement: Bool didLaunch: Bool - didPrepareGLContext: Bool + didPrepareGL: Bool didSetup: Bool isReadyToRender: Bool pixelSize: [Int32] reshapePixelSize: [Int32] + willDeinit: Bool RenderComponent: type: component oneliners: - didClickIncrement: renderLoadCubeModel(RenderVM.shared!) + - didPrepareGL: renderInit(RenderVM.shared!) + - didPrepareGL: RenderVM.shared!.didPrepareGL = true + - didPrepareGL: renderStartTimer(RenderVM.shared!) - pixelSize: RenderVM.shared!.pixelSize = c.pixelSize - - didPrepareGLContext: renderInit(RenderVM.shared!) - - didPrepareGLContext: RenderVM.shared!.didPrepareGLContext = true - - didPrepareGLContext: renderStartTimer(RenderVM.shared!) + - willDeinit: renderDeinit(RenderVM.shared!) shoulds: didLaunch: 1. Only once during the first setup: diff --git a/game/ver-mac/src/dialect.swift b/game/ver-mac/src/dialect.swift index 1bca837..f0d0729 100644 --- a/game/ver-mac/src/dialect.swift +++ b/game/ver-mac/src/dialect.swift @@ -124,22 +124,24 @@ public struct F { public static let countText = "countText" public static let didClickIncrement = "didClickIncrement" public static let didLaunch = "didLaunch" - public static let didPrepareGLContext = "didPrepareGLContext" + public static let didPrepareGL = "didPrepareGL" public static let didSetup = "didSetup" public static let isReadyToRender = "isReadyToRender" public static let pixelSize = "pixelSize" public static let reshapePixelSize = "reshapePixelSize" + public static let willDeinit = "willDeinit" } public struct RenderContext: DialectContext { public var backingPixelSize = [Int32]() public var didClickIncrement = Bool() public var didLaunch = Bool() - public var didPrepareGLContext = Bool() + public var didPrepareGL = Bool() public var didSetup = Bool() public var isReadyToRender = Bool() public var pixelSize = [Int32]() public var reshapePixelSize = [Int32]() + public var willDeinit = Bool() public var recentField = "" @@ -153,8 +155,8 @@ public struct RenderContext: DialectContext { else if (name == "didLaunch") { return didLaunch as! T } - else if (name == "didPrepareGLContext") { - return didPrepareGLContext as! T + else if (name == "didPrepareGL") { + return didPrepareGL as! T } else if (name == "didSetup") { return didSetup as! T @@ -168,6 +170,9 @@ public struct RenderContext: DialectContext { else if (name == "reshapePixelSize") { return reshapePixelSize as! T } + else if (name == "willDeinit") { + return willDeinit as! T + } return "unknown-field-name" as! T } @@ -185,8 +190,8 @@ public struct RenderContext: DialectContext { else if (name == "didLaunch") { didLaunch = value as! Bool } - else if (name == "didPrepareGLContext") { - didPrepareGLContext = value as! Bool + else if (name == "didPrepareGL") { + didPrepareGL = value as! Bool } else if (name == "didSetup") { didSetup = value as! Bool @@ -200,6 +205,9 @@ public struct RenderContext: DialectContext { else if (name == "reshapePixelSize") { reshapePixelSize = value as! [Int32] } + else if (name == "willDeinit") { + willDeinit = value as! Bool + } } } @@ -418,10 +426,11 @@ func rootRegisterShoulds(_ ctrl: DialectController) { func renderRegisterEffects(_ ctrl: DialectController) { let _: RenderContext? = registerOneliners(ctrl, [ F.didClickIncrement, { (c: RenderContext) in renderLoadCubeModel(RenderVM.shared!) }, + F.didPrepareGL, { (c: RenderContext) in renderInit(RenderVM.shared!) }, + F.didPrepareGL, { (c: RenderContext) in RenderVM.shared!.didPrepareGL = true }, + F.didPrepareGL, { (c: RenderContext) in renderStartTimer(RenderVM.shared!) }, F.pixelSize, { (c: RenderContext) in RenderVM.shared!.pixelSize = c.pixelSize }, - F.didPrepareGLContext, { (c: RenderContext) in renderInit(RenderVM.shared!) }, - F.didPrepareGLContext, { (c: RenderContext) in RenderVM.shared!.didPrepareGLContext = true }, - F.didPrepareGLContext, { (c: RenderContext) in renderStartTimer(RenderVM.shared!) }, + F.willDeinit, { (c: RenderContext) in renderDeinit(RenderVM.shared!) }, ]) } -- 2.53.0 From fa8b1999a86a78a5a52389f3ae43101274e79111 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Tue, 20 Oct 2026 06:50:54 +0300 Subject: [PATCH 31/57] clarify --- components/render/mac/view/RenderGLView.swift | 1 - 1 file changed, 1 deletion(-) diff --git a/components/render/mac/view/RenderGLView.swift b/components/render/mac/view/RenderGLView.swift index b5b2c3b..e4dbd2c 100644 --- a/components/render/mac/view/RenderGLView.swift +++ b/components/render/mac/view/RenderGLView.swift @@ -1,5 +1,4 @@ import AppKit -import SwiftUI final class RenderGLView: NSOpenGLView { override init(frame frameRect: NSRect) { -- 2.53.0 From c978b1daef913f75f1d90cf3285e83cdc2ed3a7b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Tue, 20 Oct 2026 06:51:22 +0300 Subject: [PATCH 32/57] more --- dialect.yml | 1 - game/ver-mac/src/dialect.swift | 8 -------- 2 files changed, 9 deletions(-) diff --git a/dialect.yml b/dialect.yml index 38933b7..9969dad 100644 --- a/dialect.yml +++ b/dialect.yml @@ -12,7 +12,6 @@ RenderContext: didLaunch: Bool didPrepareGL: Bool didSetup: Bool - isReadyToRender: Bool pixelSize: [Int32] reshapePixelSize: [Int32] willDeinit: Bool diff --git a/game/ver-mac/src/dialect.swift b/game/ver-mac/src/dialect.swift index f0d0729..21e24ec 100644 --- a/game/ver-mac/src/dialect.swift +++ b/game/ver-mac/src/dialect.swift @@ -126,7 +126,6 @@ public struct F { public static let didLaunch = "didLaunch" public static let didPrepareGL = "didPrepareGL" public static let didSetup = "didSetup" - public static let isReadyToRender = "isReadyToRender" public static let pixelSize = "pixelSize" public static let reshapePixelSize = "reshapePixelSize" public static let willDeinit = "willDeinit" @@ -138,7 +137,6 @@ public struct RenderContext: DialectContext { public var didLaunch = Bool() public var didPrepareGL = Bool() public var didSetup = Bool() - public var isReadyToRender = Bool() public var pixelSize = [Int32]() public var reshapePixelSize = [Int32]() public var willDeinit = Bool() @@ -161,9 +159,6 @@ public struct RenderContext: DialectContext { else if (name == "didSetup") { return didSetup as! T } - else if (name == "isReadyToRender") { - return isReadyToRender as! T - } else if (name == "pixelSize") { return pixelSize as! T } @@ -196,9 +191,6 @@ public struct RenderContext: DialectContext { else if (name == "didSetup") { didSetup = value as! Bool } - else if (name == "isReadyToRender") { - isReadyToRender = value as! Bool - } else if (name == "pixelSize") { pixelSize = value as! [Int32] } -- 2.53.0 From 66bd192621e5a8e5002db2548ac8c9e756211aa6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Tue, 20 Oct 2026 06:51:59 +0300 Subject: [PATCH 33/57] clarify --- components/render/mac/view/RenderGLView.swift | 2 -- 1 file changed, 2 deletions(-) diff --git a/components/render/mac/view/RenderGLView.swift b/components/render/mac/view/RenderGLView.swift index e4dbd2c..4a56cd9 100644 --- a/components/render/mac/view/RenderGLView.swift +++ b/components/render/mac/view/RenderGLView.swift @@ -23,7 +23,6 @@ final class RenderGLView: NSOpenGLView { override func reshape() { super.reshape() needsDisplay = true - let ps = renderPixelSize(self) renderSet(F.reshapePixelSize, ps) } @@ -31,7 +30,6 @@ final class RenderGLView: NSOpenGLView { override func viewDidChangeBackingProperties() { super.viewDidChangeBackingProperties() needsDisplay = true - let ps = renderPixelSize(self) renderSet(F.backingPixelSize, ps) } -- 2.53.0 From 81ed1d92010fb996ac7e39825cd1a2f4f6452f9d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Tue, 20 Oct 2026 07:01:30 +0300 Subject: [PATCH 34/57] some --- AGENTS.md | 114 +++++++++++++++++++++++++++++-------- game/ver-mac/Package.swift | 2 +- 2 files changed, 92 insertions(+), 24 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 2923098..89c46ba 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -12,9 +12,9 @@ and talk to the engine through generated functions like `rootSet(...)`. Remote: `https://git.opengamestudio.org/mahjong/mahjong` · Version: `2.0.0` -> Current `dialect.yml` is still the "Root / counter" template inherited from the -> dialect example — the Mahjong game logic has not been written yet. The app -> shell, packaging and symlink wiring are in place. +> `dialect.yml` is still the "Root / counter" template with a `Render` context +> bolted on: the Mahjong game logic has not been written yet. The app shell, +> packaging, symlink wiring and the raylib renderer are in place. ## Structure @@ -28,28 +28,47 @@ components/ SHARED source-of-truth for all components. root/root.swift RootComponent (owns DialectController, registers effects + shoulds, sets didSetup on setup()) root/rootVM.swift RootVM (ObservableObject / @Published countText) - root/mac/view/RootView.swift Per-platform SwiftUI view + root/mac/view/RootView.swift SwiftUI view: RenderView in a ZStack + UI + render/render.swift RenderComponent (controller, effects + shoulds) + render/renderVM.swift RenderVM (weak shared; glView, didPrepareGL, + pixelSize, startTime, timer) + render/renderConst.swift RENDER_CONFIG (sr_config), RENDER_FPS, + RENDER_MODEL_CUBE, RENDER_OPENGL_ATTRS + render/renderConstShader.swift RENDER_SHADER_* GLSL sources (GLSL 150) + render/renderAux.swift renderDraw(vm), renderPixelSize(view) + render/renderEffect.swift renderInit, renderLoadCubeModel, + renderStartTimer, renderDeinit + render/mac/view/RenderGLView.swift Thin NSOpenGLView: pixel format, callbacks + -> renderSet(...), draw -> renderDraw + render/mac/view/RenderView.swift NSViewRepresentable wrapper game/ver-mac/ macOS app (SPM executable target "ogs-mahjong") - Package.swift SPM manifest (macOS 13+, swift-tools 5.9); SPM C target - "RaylibBridge" (bridge/) + links Homebrew raylib + Package.swift SPM manifest (macOS 13+, swift-tools 5.9); C target + "RaylibBridge" (bridge/) + links Homebrew raylib; the + Swift target gets -Xcc -DGL_SILENCE_DEPRECATION Info.plist Bundle id org.opengamestudio.Mahjong, exec ogs-mahjong Resources/AppIcon.icns App icon Resources/assets/ Bundled glTF assets: cube.gltf (static), - cube_texture.png - bridge/ C target "RaylibBridge": raylib_bridge.{c,h}. Renders a - rlgl scene (no raylib window) into an NSOpenGLView. + cube_texture.png, cube_normal.png + bridge/ C target "RaylibBridge": raylib_bridge.{c,h} with the + public header in include/. Renders an rlgl scene (no + raylib window) into the NSOpenGLView. src/ GameApp.swift @main SwiftUI App entry - AppDelegate.swift Creates RootComponent + RootVM, calls root.setup() + AppDelegate.swift Creates Render/Root components + VMs, calls setup() dialect.swift GENERATED — do not hand-edit (see chicken-egg below) - other/other.swift -> symlink components/other/other.swift - render/renderConstShader.swift -> symlink components/render/renderConstShader.swift - render/view/RenderGLView.swift -> symlink components/render/mac/view/RenderGLView.swift - render/view/RenderView.swift -> symlink components/render/mac/view/RenderView.swift - root/root.swift -> symlink components/root/root.swift - root/rootVM.swift -> symlink components/root/rootVM.swift - root/view/RootView.swift-> symlink components/root/mac/view/RootView.swift + other/other.swift -> symlink components/other/other.swift + render/render.swift -> symlink components/render/render.swift + render/renderAux.swift -> symlink components/render/renderAux.swift + render/renderConst.swift -> symlink components/render/renderConst.swift + render/renderConstShader.swift -> symlink .../renderConstShader.swift + render/renderEffect.swift -> symlink components/render/renderEffect.swift + render/renderVM.swift -> symlink components/render/renderVM.swift + render/view/RenderGLView.swift -> symlink components/render/mac/view/... + render/view/RenderView.swift -> symlink components/render/mac/view/... + root/root.swift -> symlink components/root/root.swift + root/rootVM.swift -> symlink components/root/rootVM.swift + root/view/RootView.swift -> symlink components/root/mac/view/... ref/swiftraylib Symlink to ../../swiftraylib — the raylib/SwiftUI renderer sample the game will use for 3D rendering. @@ -73,7 +92,12 @@ directories whose files are **relative symlinks** back into `components/`: ``` src/other/other.swift -> ../../../../components/other/other.swift (4 up) +src/render/render.swift -> ../../../../components/render/render.swift (4 up) +src/render/renderAux.swift -> ../../../../components/render/renderAux.swift (4 up) +src/render/renderConst.swift-> ../../../../components/render/renderConst.swift (4 up) src/render/renderConstShader.swift -> ../../../../components/render/renderConstShader.swift (4 up) +src/render/renderEffect.swift -> ../../../../components/render/renderEffect.swift (4 up) +src/render/renderVM.swift -> ../../../../components/render/renderVM.swift (4 up) src/root/root.swift -> ../../../../components/root/root.swift (4 up) src/root/rootVM.swift -> ../../../../components/root/rootVM.swift (4 up) src/root/view/RootView.swift-> ../../../../../components/root/mac/view/RootView.swift (5 up) @@ -114,11 +138,48 @@ The 3D scene links against Homebrew **raylib** (`brew install raylib`). The The bridge renders with raylib's rlgl layer into an `NSOpenGLView` — raylib never creates its own window. `RootView` puts `RenderView` (backed by `RenderGLView`) behind the SwiftUI UI in a `ZStack`. A textured cube is drawn from `Resources/assets` (`cube.gltf` + -`cube_texture.png`); the app rotates it each frame via `sr_set_rotation`. +`cube_texture.png` + `cube_normal.png`); the app rotates it each frame via `sr_set_rotation`. (raylib's `LoadModelAnimations` only handles *skinned* meshes, so a plain node-rotation glTF animation cannot be played by the renderer — hence the cube is app-driven.) `packageMac` bundles `Resources/assets/` into the app. +Shaders and render constants live in **Swift**, not in C: GLSL sources are +`RENDER_SHADER_*` in `components/render/renderConstShader.swift`, and +`RENDER_CONFIG` / `sr_config` tunables are in `renderConst.swift`. `sr_init` +compiles the shaders in place (no storage/`strdup`). `cube_normal.png` drives +tangentless normal mapping via the derivative-based `cotangentFrame`. The +context is OpenGL 3.2 Core (`RENDER_OPENGL_ATTRS`); on Apple Silicon the driver +still reports 4.1/GLSL 4.10. + +## Render architecture + +The `Render` dialect context owns the GL scene. `RenderGLView` is a thin +`NSOpenGLView`; it only translates AppKit callbacks into dialect fields, and the +`render*` files do the actual work. + +1. `AppDelegate` creates `RenderComponent` + `RenderVM` and calls + `render.setup()` -> `didSetup` -> `didLaunch` (should) -> `pixelSize = [1, 1]`. +2. SwiftUI builds `RenderView` -> `RenderGLView`; `prepareOpenGL()` sets + `F.didPrepareGL`. Its oneliners run `renderInit` (`sr_init`), set + `RenderVM.didPrepareGL = true`, and `renderStartTimer`. +3. `reshape()` / `viewDidChangeBackingProperties()` compute the backing pixel + size via `renderPixelSize` and set `F.reshapePixelSize` / + `F.backingPixelSize`. The `pixelSize` shoulds fold these into `F.pixelSize`, + whose oneliner stores `RenderVM.pixelSize`. +4. The timer only sets `needsDisplay` every `1 / RENDER_FPS`. `draw(_:)` forwards + to `renderDraw` (make context current, `sr_resize`, `sr_set_rotation`, + `sr_render`, `flushBuffer`). +5. A button click runs `rootSet(F.didClickIncrement)` -> RootComponent oneliner + `renderSet(F.didClickIncrement)` -> `renderLoadCubeModel` (the cube is loaded + on demand, not at startup). +6. `RenderGLView.deinit` sets `F.willDeinit` -> `renderDeinit` (stop timer, + `sr_shutdown`). + +**GL context rule**: every raylib call must run with the view's context current. +`renderInit`, `renderLoadCubeModel`, `renderDeinit` and `renderDraw` all call +`openGLContext?.makeCurrentContext()` first. Loading a model/texture without it +fails silently with `WARNING: TEXTURE: Failed to load texture`. + ## Build & Run ```bash @@ -161,8 +222,10 @@ The project currently builds in Swift 5 language mode (`util/step/buildMac` has the Swift 6 flag commented out). Enabling `-Xswiftc -swift-version -Xswiftc 6` fails today on the singleton/`@MainActor` concurrency errors (`RootComponent.singleton`, `RootVM.shared` in -`components/root/`, and the `RootVM.shared!.countText = ...` oneliner in the -generated `dialect.swift`). Do not flip it on without addressing those. +`components/root/`, `RenderComponent.singleton`, `RenderVM.shared` in +`components/render/`, and the `RootVM.shared!.countText = ...` / +`RenderVM.shared!.pixelSize = ...` oneliners in the generated `dialect.swift`). +Do not flip it on without addressing those. ## Conventions @@ -171,8 +234,11 @@ generated `dialect.swift`). Do not flip it on without addressing those. - Prefer editing files in `components/` (the real files); the `src/` entries are symlinks. - The generated UI callback plumbing is nonisolated; UI singletons are weak - (`RootComponent.singleton`, `RootVM.shared`) and are accessed from the - generated oneliners with force-unwrap (`RootVM.shared!.countText = ...`). + (`RootComponent.singleton`, `RootVM.shared`, `RenderComponent.singleton`, + `RenderVM.shared`) and are accessed from the generated oneliners with + force-unwrap (`RootVM.shared!.countText = ...`, `RenderVM.shared!.pixelSize = ...`). +- Never call raylib / `sr_*` without making the view's GL context current first + (see the GL context rule above). ## Skill: source-file study documents @@ -184,5 +250,7 @@ fix) — follow the skill in `docs/file-summary.md`. - Write the result to `docs/.html` (e.g. `docs/RaylibGLView.html`) and name the file's Git revision in the header. The file is the source of truth — document the exact revision requested, not the working tree. -- Existing example: `docs/RaylibGLView.html` (single-cube `RaylibGLView.swift`). +- Existing example: `docs/RaylibGLView.html` — documents the historical + single-cube `RaylibGLView.swift`, since split into `RenderGLView.swift` plus + the `render*` files. diff --git a/game/ver-mac/Package.swift b/game/ver-mac/Package.swift index 96e5628..6e176d1 100644 --- a/game/ver-mac/Package.swift +++ b/game/ver-mac/Package.swift @@ -1,6 +1,6 @@ // swift-tools-version: 5.9 -import PackageDescription import Foundation +import PackageDescription let raylibPrefix = ProcessInfo.processInfo.environment["RAYLIB_PREFIX"] ?? "/opt/homebrew" -- 2.53.0 From 8bf6b14c1eaa6ba74b65dcbd64f8f779d0255b06 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Tue, 20 Oct 2026 07:04:13 +0300 Subject: [PATCH 35/57] move h --- AGENTS.md | 5 ++--- game/ver-mac/Package.swift | 2 +- game/ver-mac/bridge/{include => }/raylib_bridge.h | 0 3 files changed, 3 insertions(+), 4 deletions(-) rename game/ver-mac/bridge/{include => }/raylib_bridge.h (100%) diff --git a/AGENTS.md b/AGENTS.md index 89c46ba..3442ff6 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -50,9 +50,8 @@ game/ver-mac/ macOS app (SPM executable target "ogs-mahjong") Resources/AppIcon.icns App icon Resources/assets/ Bundled glTF assets: cube.gltf (static), cube_texture.png, cube_normal.png - bridge/ C target "RaylibBridge": raylib_bridge.{c,h} with the - public header in include/. Renders an rlgl scene (no - raylib window) into the NSOpenGLView. + bridge/ C target "RaylibBridge": raylib_bridge.{c,h}. Renders + an rlgl scene (no raylib window) into the NSOpenGLView. src/ GameApp.swift @main SwiftUI App entry AppDelegate.swift Creates Render/Root components + VMs, calls setup() diff --git a/game/ver-mac/Package.swift b/game/ver-mac/Package.swift index 6e176d1..0e6e4c3 100644 --- a/game/ver-mac/Package.swift +++ b/game/ver-mac/Package.swift @@ -13,7 +13,7 @@ let package = Package( .target( name: "RaylibBridge", path: "bridge", - publicHeadersPath: "include", + publicHeadersPath: ".", cSettings: [ .unsafeFlags(["-I", "\(raylibPrefix)/include"]) ] diff --git a/game/ver-mac/bridge/include/raylib_bridge.h b/game/ver-mac/bridge/raylib_bridge.h similarity index 100% rename from game/ver-mac/bridge/include/raylib_bridge.h rename to game/ver-mac/bridge/raylib_bridge.h -- 2.53.0 From 92e93928ff07eb768b4b013ab5dff16f0e4f55d5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Tue, 20 Oct 2026 16:28:58 +0300 Subject: [PATCH 36/57] reorder --- game/ver-mac/bridge/raylib_bridge.c | 171 +++++++++++++++------------- 1 file changed, 89 insertions(+), 82 deletions(-) diff --git a/game/ver-mac/bridge/raylib_bridge.c b/game/ver-mac/bridge/raylib_bridge.c index fb597ae..95054b6 100644 --- a/game/ver-mac/bridge/raylib_bridge.c +++ b/game/ver-mac/bridge/raylib_bridge.c @@ -217,6 +217,94 @@ static Matrix sr_cube_transform(void) return sr_transform((Vector3){ 0.0f, 1.1f, 0.0f }, 1.0f, sr_rot_x, sr_rot_y, sr_rot_z); } +static void sr_draw_object(Model model, Material material, Matrix model_mat, + Texture2D normal, float is_ground, float emissive); + +static void sr_render_main_pass(void) +{ + // --- Main pass: camera --- + rlViewport(0, 0, sr_width, sr_height); + rlSetFramebufferWidth(sr_width); + rlSetFramebufferHeight(sr_height); + + rlClearColor(24, 26, 34, 255); + rlClearScreenBuffers(); + + rlMatrixMode(RL_PROJECTION); + rlPushMatrix(); + rlLoadIdentity(); + + float aspect = (float)sr_width / (float)sr_height; + double top = (double)sr_cfg.near_plane * tan((double)sr_cfg.fov_y * 0.5 * DEG2RAD); + double right = top * (double)aspect; + rlFrustum(-right, right, -top, top, (double)sr_cfg.near_plane, (double)sr_cfg.far_plane); + + rlMatrixMode(RL_MODELVIEW); + rlLoadIdentity(); + + Vector3 eye = { 0.0f, 2.6f, 5.6f }; + Vector3 target = { 0.0f, 1.0f, 0.0f }; + Vector3 up = { 0.0f, 1.0f, 0.0f }; + + Matrix view = MatrixLookAt(eye, target, up); + rlMultMatrixf(MatrixToFloat(view)); + + rlEnableDepthTest(); + rlEnableBackfaceCulling(); + rlSetCullFace(RL_CULL_FACE_BACK); + + rlEnableShader(sr_main_shader.id); + + Vector3 light_color = { 1.15f, 1.08f, 0.98f }; + Vector3 ambient = { 0.30f, 0.32f, 0.38f }; + Vector3 grid_color = { 0.45f, 0.62f, 0.95f }; + Vector3 fog_color = { 24.0f / 255.0f, 26.0f / 255.0f, 34.0f / 255.0f }; + float light_amount = 1.0f; + float shadow_bias = 0.0025f; + float shadow_softness = 4.0f; + float fog_start = 10.0f; + float fog_end = 34.0f; + + SetShaderValue(sr_main_shader, loc_light_pos, &sr_light_pos, SHADER_UNIFORM_VEC3); + SetShaderValue(sr_main_shader, loc_light_color, &light_color, SHADER_UNIFORM_VEC3); + SetShaderValue(sr_main_shader, loc_ambient, &ambient, SHADER_UNIFORM_VEC3); + SetShaderValue(sr_main_shader, loc_light_enabled, &light_amount, SHADER_UNIFORM_FLOAT); + SetShaderValue(sr_main_shader, loc_shadow_bias, &shadow_bias, SHADER_UNIFORM_FLOAT); + SetShaderValue(sr_main_shader, loc_shadow_softness, &shadow_softness, SHADER_UNIFORM_FLOAT); + SetShaderValue(sr_main_shader, loc_grid_color, &grid_color, SHADER_UNIFORM_VEC3); + SetShaderValue(sr_main_shader, loc_camera_pos, &eye, SHADER_UNIFORM_VEC3); + SetShaderValue(sr_main_shader, loc_fog_color, &fog_color, SHADER_UNIFORM_VEC3); + SetShaderValue(sr_main_shader, loc_fog_start, &fog_start, SHADER_UNIFORM_FLOAT); + SetShaderValue(sr_main_shader, loc_fog_end, &fog_end, SHADER_UNIFORM_FLOAT); + + int shadow_unit = 1; + SetShaderValue(sr_main_shader, loc_shadow_map, &shadow_unit, SHADER_UNIFORM_INT); + rlActiveTextureSlot(1); + rlEnableTexture(sr_shadow_depth); + rlActiveTextureSlot(0); + + // --- Ground (procedural grid floor) --- + sr_draw_object(sr_ground_model, sr_ground_material, MatrixTranslate(0.0f, 0.0f, 0.0f), (Texture2D){ 0 }, 1.0f, 0.0f); + + // --- Cubes --- + if (sr_has_model) + { + sr_draw_object(sr_model, sr_cube_material, sr_cube_transform(), sr_cube_normal, 0.0f, 0.0f); + } + + // Flush while the projection/modelview matrices are still active, otherwise + // rlgl draws the pending batch with the restored (2D) projection. + rlDrawRenderBatchActive(); + + // --- Restore matrices (equivalent to raylib's EndMode3D) --- + rlMatrixMode(RL_PROJECTION); + rlPopMatrix(); + rlMatrixMode(RL_MODELVIEW); + rlLoadIdentity(); + rlDisableDepthTest(); + rlDisableBackfaceCulling(); +} + static void sr_render_shadow_pass(void) { rlViewport(0, 0, sr_cfg.shadow_size, sr_cfg.shadow_size); @@ -306,88 +394,7 @@ void sr_render(void) sr_light_proj = MatrixPerspective(90.0 * DEG2RAD, 1.0, 1.5, 16.0); sr_render_shadow_pass(); - - // --- Main pass: camera --- - rlViewport(0, 0, sr_width, sr_height); - rlSetFramebufferWidth(sr_width); - rlSetFramebufferHeight(sr_height); - - rlClearColor(24, 26, 34, 255); - rlClearScreenBuffers(); - - rlMatrixMode(RL_PROJECTION); - rlPushMatrix(); - rlLoadIdentity(); - - float aspect = (float)sr_width / (float)sr_height; - double top = (double)sr_cfg.near_plane * tan((double)sr_cfg.fov_y * 0.5 * DEG2RAD); - double right = top * (double)aspect; - rlFrustum(-right, right, -top, top, (double)sr_cfg.near_plane, (double)sr_cfg.far_plane); - - rlMatrixMode(RL_MODELVIEW); - rlLoadIdentity(); - - Vector3 eye = { 0.0f, 2.6f, 5.6f }; - Vector3 target = { 0.0f, 1.0f, 0.0f }; - Vector3 up = { 0.0f, 1.0f, 0.0f }; - - Matrix view = MatrixLookAt(eye, target, up); - rlMultMatrixf(MatrixToFloat(view)); - - rlEnableDepthTest(); - rlEnableBackfaceCulling(); - rlSetCullFace(RL_CULL_FACE_BACK); - - rlEnableShader(sr_main_shader.id); - - Vector3 light_color = { 1.15f, 1.08f, 0.98f }; - Vector3 ambient = { 0.30f, 0.32f, 0.38f }; - Vector3 grid_color = { 0.45f, 0.62f, 0.95f }; - Vector3 fog_color = { 24.0f / 255.0f, 26.0f / 255.0f, 34.0f / 255.0f }; - float light_amount = 1.0f; - float shadow_bias = 0.0025f; - float shadow_softness = 4.0f; - float fog_start = 10.0f; - float fog_end = 34.0f; - - SetShaderValue(sr_main_shader, loc_light_pos, &sr_light_pos, SHADER_UNIFORM_VEC3); - SetShaderValue(sr_main_shader, loc_light_color, &light_color, SHADER_UNIFORM_VEC3); - SetShaderValue(sr_main_shader, loc_ambient, &ambient, SHADER_UNIFORM_VEC3); - SetShaderValue(sr_main_shader, loc_light_enabled, &light_amount, SHADER_UNIFORM_FLOAT); - SetShaderValue(sr_main_shader, loc_shadow_bias, &shadow_bias, SHADER_UNIFORM_FLOAT); - SetShaderValue(sr_main_shader, loc_shadow_softness, &shadow_softness, SHADER_UNIFORM_FLOAT); - SetShaderValue(sr_main_shader, loc_grid_color, &grid_color, SHADER_UNIFORM_VEC3); - SetShaderValue(sr_main_shader, loc_camera_pos, &eye, SHADER_UNIFORM_VEC3); - SetShaderValue(sr_main_shader, loc_fog_color, &fog_color, SHADER_UNIFORM_VEC3); - SetShaderValue(sr_main_shader, loc_fog_start, &fog_start, SHADER_UNIFORM_FLOAT); - SetShaderValue(sr_main_shader, loc_fog_end, &fog_end, SHADER_UNIFORM_FLOAT); - - int shadow_unit = 1; - SetShaderValue(sr_main_shader, loc_shadow_map, &shadow_unit, SHADER_UNIFORM_INT); - rlActiveTextureSlot(1); - rlEnableTexture(sr_shadow_depth); - rlActiveTextureSlot(0); - - // --- Ground (procedural grid floor) --- - sr_draw_object(sr_ground_model, sr_ground_material, MatrixTranslate(0.0f, 0.0f, 0.0f), (Texture2D){ 0 }, 1.0f, 0.0f); - - // --- Cubes --- - if (sr_has_model) - { - sr_draw_object(sr_model, sr_cube_material, sr_cube_transform(), sr_cube_normal, 0.0f, 0.0f); - } - - // Flush while the projection/modelview matrices are still active, otherwise - // rlgl draws the pending batch with the restored (2D) projection. - rlDrawRenderBatchActive(); - - // --- Restore matrices (equivalent to raylib's EndMode3D) --- - rlMatrixMode(RL_PROJECTION); - rlPopMatrix(); - rlMatrixMode(RL_MODELVIEW); - rlLoadIdentity(); - rlDisableDepthTest(); - rlDisableBackfaceCulling(); + sr_render_main_pass(); } void sr_shutdown(void) -- 2.53.0 From fdabf2dd0dd1e352c46dd17002832770ff2894e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Tue, 20 Oct 2026 16:36:56 +0300 Subject: [PATCH 37/57] only set const shaders once --- game/ver-mac/bridge/raylib_bridge.c | 70 +++++++++++++++++------------ 1 file changed, 41 insertions(+), 29 deletions(-) diff --git a/game/ver-mac/bridge/raylib_bridge.c b/game/ver-mac/bridge/raylib_bridge.c index 95054b6..fbe8015 100644 --- a/game/ver-mac/bridge/raylib_bridge.c +++ b/game/ver-mac/bridge/raylib_bridge.c @@ -138,6 +138,46 @@ static void sr_build_ground(void) sr_ground_shadow_material.shader = sr_shadow_shader; } +// Uniforms that never change between frames are uploaded once at startup. +// SetShaderValue() is a bare glUniform*(), so the program must be bound. +static void sr_init_main_uniforms(void) +{ + sr_light_pos = (Vector3){ 0.0f, 4.2f, 0.0f }; + + Vector3 light_color = { 1.15f, 1.08f, 0.98f }; + Vector3 ambient = { 0.30f, 0.32f, 0.38f }; + Vector3 grid_color = { 0.45f, 0.62f, 0.95f }; + Vector3 fog_color = { 24.0f / 255.0f, 26.0f / 255.0f, 34.0f / 255.0f }; + Vector3 camera_pos = { 0.0f, 2.6f, 5.6f }; + float albedo[3] = { 1.0f, 1.0f, 1.0f }; + float light_amount = 1.0f; + float shadow_bias = 0.0025f; + float shadow_softness = 4.0f; + float fog_start = 10.0f; + float fog_end = 34.0f; + int shadow_unit = 1; + int normal_unit = 2; + + rlEnableShader(sr_main_shader.id); + + SetShaderValue(sr_main_shader, loc_light_pos, &sr_light_pos, SHADER_UNIFORM_VEC3); + SetShaderValue(sr_main_shader, loc_light_color, &light_color, SHADER_UNIFORM_VEC3); + SetShaderValue(sr_main_shader, loc_ambient, &ambient, SHADER_UNIFORM_VEC3); + SetShaderValue(sr_main_shader, loc_light_enabled, &light_amount, SHADER_UNIFORM_FLOAT); + SetShaderValue(sr_main_shader, loc_shadow_bias, &shadow_bias, SHADER_UNIFORM_FLOAT); + SetShaderValue(sr_main_shader, loc_shadow_softness, &shadow_softness, SHADER_UNIFORM_FLOAT); + SetShaderValue(sr_main_shader, loc_grid_color, &grid_color, SHADER_UNIFORM_VEC3); + SetShaderValue(sr_main_shader, loc_camera_pos, &camera_pos, SHADER_UNIFORM_VEC3); + SetShaderValue(sr_main_shader, loc_fog_color, &fog_color, SHADER_UNIFORM_VEC3); + SetShaderValue(sr_main_shader, loc_fog_start, &fog_start, SHADER_UNIFORM_FLOAT); + SetShaderValue(sr_main_shader, loc_fog_end, &fog_end, SHADER_UNIFORM_FLOAT); + SetShaderValue(sr_main_shader, loc_albedo_color, albedo, SHADER_UNIFORM_VEC3); + SetShaderValue(sr_main_shader, loc_shadow_map, &shadow_unit, SHADER_UNIFORM_INT); + SetShaderValue(sr_main_shader, loc_normal_map, &normal_unit, SHADER_UNIFORM_INT); + + rlDisableShader(); +} + void sr_init(int width, int height, const char *main_vs, const char *main_fs, const char *shadow_vs, const char *shadow_fs, sr_config config) { @@ -153,6 +193,7 @@ void sr_init(int width, int height, const char *main_vs, const char *main_fs, rlglInit(sr_width, sr_height); sr_load_shaders(main_vs, main_fs, shadow_vs, shadow_fs); + sr_init_main_uniforms(); sr_build_ground(); sr_ready = 1; @@ -255,30 +296,6 @@ static void sr_render_main_pass(void) rlEnableShader(sr_main_shader.id); - Vector3 light_color = { 1.15f, 1.08f, 0.98f }; - Vector3 ambient = { 0.30f, 0.32f, 0.38f }; - Vector3 grid_color = { 0.45f, 0.62f, 0.95f }; - Vector3 fog_color = { 24.0f / 255.0f, 26.0f / 255.0f, 34.0f / 255.0f }; - float light_amount = 1.0f; - float shadow_bias = 0.0025f; - float shadow_softness = 4.0f; - float fog_start = 10.0f; - float fog_end = 34.0f; - - SetShaderValue(sr_main_shader, loc_light_pos, &sr_light_pos, SHADER_UNIFORM_VEC3); - SetShaderValue(sr_main_shader, loc_light_color, &light_color, SHADER_UNIFORM_VEC3); - SetShaderValue(sr_main_shader, loc_ambient, &ambient, SHADER_UNIFORM_VEC3); - SetShaderValue(sr_main_shader, loc_light_enabled, &light_amount, SHADER_UNIFORM_FLOAT); - SetShaderValue(sr_main_shader, loc_shadow_bias, &shadow_bias, SHADER_UNIFORM_FLOAT); - SetShaderValue(sr_main_shader, loc_shadow_softness, &shadow_softness, SHADER_UNIFORM_FLOAT); - SetShaderValue(sr_main_shader, loc_grid_color, &grid_color, SHADER_UNIFORM_VEC3); - SetShaderValue(sr_main_shader, loc_camera_pos, &eye, SHADER_UNIFORM_VEC3); - SetShaderValue(sr_main_shader, loc_fog_color, &fog_color, SHADER_UNIFORM_VEC3); - SetShaderValue(sr_main_shader, loc_fog_start, &fog_start, SHADER_UNIFORM_FLOAT); - SetShaderValue(sr_main_shader, loc_fog_end, &fog_end, SHADER_UNIFORM_FLOAT); - - int shadow_unit = 1; - SetShaderValue(sr_main_shader, loc_shadow_map, &shadow_unit, SHADER_UNIFORM_INT); rlActiveTextureSlot(1); rlEnableTexture(sr_shadow_depth); rlActiveTextureSlot(0); @@ -356,8 +373,6 @@ static void sr_set_light_mvp(Matrix model) static void sr_bind_normal(Texture2D tex) { - int unit = 2; - SetShaderValue(sr_main_shader, loc_normal_map, &unit, SHADER_UNIFORM_INT); rlActiveTextureSlot(2); if (tex.id > 0) rlEnableTexture(tex.id); rlActiveTextureSlot(0); @@ -368,9 +383,7 @@ static void sr_draw_object(Model model, Material material, Matrix model_mat, { sr_set_light_mvp(model_mat); - float albedo[3] = { 1.0f, 1.0f, 1.0f }; float normal_strength = (normal.id > 0) ? 1.0f : 0.0f; - SetShaderValue(sr_main_shader, loc_albedo_color, albedo, SHADER_UNIFORM_VEC3); SetShaderValue(sr_main_shader, loc_emissive, &emissive, SHADER_UNIFORM_FLOAT); SetShaderValue(sr_main_shader, loc_is_ground, &is_ground, SHADER_UNIFORM_FLOAT); SetShaderValue(sr_main_shader, loc_normal_strength, &normal_strength, SHADER_UNIFORM_FLOAT); @@ -387,7 +400,6 @@ void sr_render(void) rlDrawRenderBatchActive(); // --- Light (point light above the scene) --- - sr_light_pos = (Vector3){ 0.0f, 4.2f, 0.0f }; Vector3 light_target = (Vector3){ 0.0f, -2.0f, 0.0f }; Vector3 light_up = (Vector3){ 0.0f, 0.0f, -1.0f }; sr_light_view = MatrixLookAt(sr_light_pos, light_target, light_up); -- 2.53.0 From 47e76c622494a2179fba1ea91d11dbaf1a276821 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Tue, 20 Oct 2026 16:40:18 +0300 Subject: [PATCH 38/57] rn --- game/ver-mac/bridge/raylib_bridge.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/game/ver-mac/bridge/raylib_bridge.c b/game/ver-mac/bridge/raylib_bridge.c index fbe8015..91d3f90 100644 --- a/game/ver-mac/bridge/raylib_bridge.c +++ b/game/ver-mac/bridge/raylib_bridge.c @@ -140,7 +140,7 @@ static void sr_build_ground(void) // Uniforms that never change between frames are uploaded once at startup. // SetShaderValue() is a bare glUniform*(), so the program must be bound. -static void sr_init_main_uniforms(void) +static void sr_config_shaders(void) { sr_light_pos = (Vector3){ 0.0f, 4.2f, 0.0f }; @@ -193,7 +193,7 @@ void sr_init(int width, int height, const char *main_vs, const char *main_fs, rlglInit(sr_width, sr_height); sr_load_shaders(main_vs, main_fs, shadow_vs, shadow_fs); - sr_init_main_uniforms(); + sr_config_shaders(); sr_build_ground(); sr_ready = 1; -- 2.53.0 From bf05a2a7eed767edb5150e9d35e30222f3735fa1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Tue, 20 Oct 2026 16:58:08 +0300 Subject: [PATCH 39/57] clarify --- components/render/renderEffect.swift | 2 -- game/ver-mac/bridge/raylib_bridge.c | 16 +++++++++------- game/ver-mac/bridge/raylib_bridge.h | 11 +++++++---- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/components/render/renderEffect.swift b/components/render/renderEffect.swift index 4758875..fffc39e 100644 --- a/components/render/renderEffect.swift +++ b/components/render/renderEffect.swift @@ -18,8 +18,6 @@ func renderInit(_ vm: RenderVM) { // Init Raylib sr_init( - 1, // Default width - 1, // Default height RENDER_SHADER_MAIN_VS, RENDER_SHADER_MAIN_FS, RENDER_SHADER_SHADOW_VS, diff --git a/game/ver-mac/bridge/raylib_bridge.c b/game/ver-mac/bridge/raylib_bridge.c index 91d3f90..5e537f4 100644 --- a/game/ver-mac/bridge/raylib_bridge.c +++ b/game/ver-mac/bridge/raylib_bridge.c @@ -178,19 +178,21 @@ static void sr_config_shaders(void) rlDisableShader(); } -void sr_init(int width, int height, const char *main_vs, const char *main_fs, - const char *shadow_vs, const char *shadow_fs, sr_config config) -{ - if (width > 0) sr_width = width; - if (height > 0) sr_height = height; - +void sr_init( + const char *main_vs, + const char *main_fs, + const char *shadow_vs, + const char *shadow_fs, + sr_config config +) { sr_cfg = config; // raylib's default INFO logging is noisy; keep warnings and errors only. SetTraceLogLevel(LOG_WARNING); rlLoadExtensions(sr_gl_loader); - rlglInit(sr_width, sr_height); + // Init with default 1x1 size + rlglInit(1, 1); sr_load_shaders(main_vs, main_fs, shadow_vs, shadow_fs); sr_config_shaders(); diff --git a/game/ver-mac/bridge/raylib_bridge.h b/game/ver-mac/bridge/raylib_bridge.h index 91b432e..c7482b9 100644 --- a/game/ver-mac/bridge/raylib_bridge.h +++ b/game/ver-mac/bridge/raylib_bridge.h @@ -16,10 +16,13 @@ typedef struct sr_config { // Initialise the OpenGL-backed raylib scene (no raylib window is created). // The four shader sources come from renderConstShader.swift. -void sr_init(int width, int height, - const char *main_vs, const char *main_fs, - const char *shadow_vs, const char *shadow_fs, - sr_config config); +void sr_init( + const char *main_vs, + const char *main_fs, + const char *shadow_vs, + const char *shadow_fs, + sr_config config +); // Load the textured cube glTF model. void sr_load_model(const char *gltf_path); -- 2.53.0 From f0862c88f746861183bc752f7cd2cd948fb834d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Tue, 20 Oct 2026 17:05:01 +0300 Subject: [PATCH 40/57] raybri --- .../bridge/raylib_bridge.c => components/raybri/raybri.c | 4 ++-- .../bridge/raylib_bridge.h => components/raybri/raybri.h | 0 game/ver-mac/Package.swift | 3 ++- game/ver-mac/src/raybri/raybri.c | 1 + game/ver-mac/src/raybri/raybri.h | 1 + 5 files changed, 6 insertions(+), 3 deletions(-) rename game/ver-mac/bridge/raylib_bridge.c => components/raybri/raybri.c (99%) rename game/ver-mac/bridge/raylib_bridge.h => components/raybri/raybri.h (100%) create mode 120000 game/ver-mac/src/raybri/raybri.c create mode 120000 game/ver-mac/src/raybri/raybri.h diff --git a/game/ver-mac/bridge/raylib_bridge.c b/components/raybri/raybri.c similarity index 99% rename from game/ver-mac/bridge/raylib_bridge.c rename to components/raybri/raybri.c index 5e537f4..b6382b1 100644 --- a/game/ver-mac/bridge/raylib_bridge.c +++ b/components/raybri/raybri.c @@ -1,4 +1,4 @@ -#include "raylib_bridge.h" +#include "raybri.h" #include "raylib.h" #include "rlgl.h" @@ -190,7 +190,7 @@ void sr_init( // raylib's default INFO logging is noisy; keep warnings and errors only. SetTraceLogLevel(LOG_WARNING); - rlLoadExtensions(sr_gl_loader); + rlLoadExtensions((void *)sr_gl_loader); // Init with default 1x1 size rlglInit(1, 1); diff --git a/game/ver-mac/bridge/raylib_bridge.h b/components/raybri/raybri.h similarity index 100% rename from game/ver-mac/bridge/raylib_bridge.h rename to components/raybri/raybri.h diff --git a/game/ver-mac/Package.swift b/game/ver-mac/Package.swift index 0e6e4c3..1dff832 100644 --- a/game/ver-mac/Package.swift +++ b/game/ver-mac/Package.swift @@ -12,7 +12,7 @@ let package = Package( targets: [ .target( name: "RaylibBridge", - path: "bridge", + path: "src/raybri", publicHeadersPath: ".", cSettings: [ .unsafeFlags(["-I", "\(raylibPrefix)/include"]) @@ -22,6 +22,7 @@ let package = Package( name: "ogs-mahjong", dependencies: ["RaylibBridge"], path: "src", + exclude: ["raybri"], swiftSettings: [ .unsafeFlags(["-Xcc", "-DGL_SILENCE_DEPRECATION"]) ], diff --git a/game/ver-mac/src/raybri/raybri.c b/game/ver-mac/src/raybri/raybri.c new file mode 120000 index 0000000..52b1940 --- /dev/null +++ b/game/ver-mac/src/raybri/raybri.c @@ -0,0 +1 @@ +../../../../components/raybri/raybri.c \ No newline at end of file diff --git a/game/ver-mac/src/raybri/raybri.h b/game/ver-mac/src/raybri/raybri.h new file mode 120000 index 0000000..daec20f --- /dev/null +++ b/game/ver-mac/src/raybri/raybri.h @@ -0,0 +1 @@ +../../../../components/raybri/raybri.h \ No newline at end of file -- 2.53.0 From 41a7b330aa777153b7fa05804a1323c25ee14047 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Wed, 21 Oct 2026 06:17:17 +0300 Subject: [PATCH 41/57] rename --- AGENTS.md | 31 +++++++++++++++++----------- components/raybri/raybri.c | 16 +++++++------- components/raybri/raybri.h | 18 ++++++++-------- components/render/renderAux.swift | 6 +++--- components/render/renderConst.swift | 2 +- components/render/renderEffect.swift | 6 +++--- 6 files changed, 43 insertions(+), 36 deletions(-) diff --git a/AGENTS.md b/AGENTS.md index 3442ff6..9026946 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -25,6 +25,10 @@ dialect.yml Single source of truth for the reactive logic. components/ SHARED source-of-truth for all components. other/other.swift Shared helpers (otherPrintStderr, otherWriteFile, otherSetupConsoleLogging, ...) + raybri/raybri.h C API of the raylib bridge (raybri_config, raybri_init, + raybri_load_model, raybri_resize, raybri_set_rotation, + raybri_render, raybri_shutdown); extern "C" guards. + raybri/raybri.c Bridge implementation: rlgl scene, shadow pass, shaders. root/root.swift RootComponent (owns DialectController, registers effects + shoulds, sets didSetup on setup()) root/rootVM.swift RootVM (ObservableObject / @Published countText) @@ -32,7 +36,7 @@ components/ SHARED source-of-truth for all components. render/render.swift RenderComponent (controller, effects + shoulds) render/renderVM.swift RenderVM (weak shared; glView, didPrepareGL, pixelSize, startTime, timer) - render/renderConst.swift RENDER_CONFIG (sr_config), RENDER_FPS, + render/renderConst.swift RENDER_CONFIG (raybri_config), RENDER_FPS, RENDER_MODEL_CUBE, RENDER_OPENGL_ATTRS render/renderConstShader.swift RENDER_SHADER_* GLSL sources (GLSL 150) render/renderAux.swift renderDraw(vm), renderPixelSize(view) @@ -44,19 +48,20 @@ components/ SHARED source-of-truth for all components. game/ver-mac/ macOS app (SPM executable target "ogs-mahjong") Package.swift SPM manifest (macOS 13+, swift-tools 5.9); C target - "RaylibBridge" (bridge/) + links Homebrew raylib; the - Swift target gets -Xcc -DGL_SILENCE_DEPRECATION + "RaylibBridge" (path src/raybri, publicHeadersPath ".") + + links Homebrew raylib; the Swift target excludes raybri + and gets -Xcc -DGL_SILENCE_DEPRECATION Info.plist Bundle id org.opengamestudio.Mahjong, exec ogs-mahjong Resources/AppIcon.icns App icon Resources/assets/ Bundled glTF assets: cube.gltf (static), cube_texture.png, cube_normal.png - bridge/ C target "RaylibBridge": raylib_bridge.{c,h}. Renders - an rlgl scene (no raylib window) into the NSOpenGLView. src/ GameApp.swift @main SwiftUI App entry AppDelegate.swift Creates Render/Root components + VMs, calls setup() dialect.swift GENERATED — do not hand-edit (see chicken-egg below) other/other.swift -> symlink components/other/other.swift + raybri/raybri.c -> symlink components/raybri/raybri.c + raybri/raybri.h -> symlink components/raybri/raybri.h render/render.swift -> symlink components/render/render.swift render/renderAux.swift -> symlink components/render/renderAux.swift render/renderConst.swift -> symlink components/render/renderConst.swift @@ -91,6 +96,8 @@ directories whose files are **relative symlinks** back into `components/`: ``` src/other/other.swift -> ../../../../components/other/other.swift (4 up) +src/raybri/raybri.c -> ../../../../components/raybri/raybri.c (4 up) +src/raybri/raybri.h -> ../../../../components/raybri/raybri.h (4 up) src/render/render.swift -> ../../../../components/render/render.swift (4 up) src/render/renderAux.swift -> ../../../../components/render/renderAux.swift (4 up) src/render/renderConst.swift-> ../../../../components/render/renderConst.swift (4 up) @@ -137,14 +144,14 @@ The 3D scene links against Homebrew **raylib** (`brew install raylib`). The The bridge renders with raylib's rlgl layer into an `NSOpenGLView` — raylib never creates its own window. `RootView` puts `RenderView` (backed by `RenderGLView`) behind the SwiftUI UI in a `ZStack`. A textured cube is drawn from `Resources/assets` (`cube.gltf` + -`cube_texture.png` + `cube_normal.png`); the app rotates it each frame via `sr_set_rotation`. +`cube_texture.png` + `cube_normal.png`); the app rotates it each frame via `raybri_set_rotation`. (raylib's `LoadModelAnimations` only handles *skinned* meshes, so a plain node-rotation glTF animation cannot be played by the renderer — hence the cube is app-driven.) `packageMac` bundles `Resources/assets/` into the app. Shaders and render constants live in **Swift**, not in C: GLSL sources are `RENDER_SHADER_*` in `components/render/renderConstShader.swift`, and -`RENDER_CONFIG` / `sr_config` tunables are in `renderConst.swift`. `sr_init` +`RENDER_CONFIG` / `raybri_config` tunables are in `renderConst.swift`. `raybri_init` compiles the shaders in place (no storage/`strdup`). `cube_normal.png` drives tangentless normal mapping via the derivative-based `cotangentFrame`. The context is OpenGL 3.2 Core (`RENDER_OPENGL_ATTRS`); on Apple Silicon the driver @@ -159,20 +166,20 @@ The `Render` dialect context owns the GL scene. `RenderGLView` is a thin 1. `AppDelegate` creates `RenderComponent` + `RenderVM` and calls `render.setup()` -> `didSetup` -> `didLaunch` (should) -> `pixelSize = [1, 1]`. 2. SwiftUI builds `RenderView` -> `RenderGLView`; `prepareOpenGL()` sets - `F.didPrepareGL`. Its oneliners run `renderInit` (`sr_init`), set + `F.didPrepareGL`. Its oneliners run `renderInit` (`raybri_init`), set `RenderVM.didPrepareGL = true`, and `renderStartTimer`. 3. `reshape()` / `viewDidChangeBackingProperties()` compute the backing pixel size via `renderPixelSize` and set `F.reshapePixelSize` / `F.backingPixelSize`. The `pixelSize` shoulds fold these into `F.pixelSize`, whose oneliner stores `RenderVM.pixelSize`. 4. The timer only sets `needsDisplay` every `1 / RENDER_FPS`. `draw(_:)` forwards - to `renderDraw` (make context current, `sr_resize`, `sr_set_rotation`, - `sr_render`, `flushBuffer`). + to `renderDraw` (make context current, `raybri_resize`, `raybri_set_rotation`, + `raybri_render`, `flushBuffer`). 5. A button click runs `rootSet(F.didClickIncrement)` -> RootComponent oneliner `renderSet(F.didClickIncrement)` -> `renderLoadCubeModel` (the cube is loaded on demand, not at startup). 6. `RenderGLView.deinit` sets `F.willDeinit` -> `renderDeinit` (stop timer, - `sr_shutdown`). + `raybri_shutdown`). **GL context rule**: every raylib call must run with the view's context current. `renderInit`, `renderLoadCubeModel`, `renderDeinit` and `renderDraw` all call @@ -236,7 +243,7 @@ Do not flip it on without addressing those. (`RootComponent.singleton`, `RootVM.shared`, `RenderComponent.singleton`, `RenderVM.shared`) and are accessed from the generated oneliners with force-unwrap (`RootVM.shared!.countText = ...`, `RenderVM.shared!.pixelSize = ...`). -- Never call raylib / `sr_*` without making the view's GL context current first +- Never call raylib / `raybri_*` without making the view's GL context current first (see the GL context rule above). ## Skill: source-file study documents diff --git a/components/raybri/raybri.c b/components/raybri/raybri.c index b6382b1..1151cd8 100644 --- a/components/raybri/raybri.c +++ b/components/raybri/raybri.c @@ -14,7 +14,7 @@ static int sr_width = 1; static int sr_height = 1; // Render configuration supplied by the application (see renderConst.swift). -static sr_config sr_cfg = { 0 }; +static raybri_config sr_cfg = { 0 }; // Cube transform (driven by the application, Euler degrees). static float sr_rot_x = 0.0f; @@ -178,12 +178,12 @@ static void sr_config_shaders(void) rlDisableShader(); } -void sr_init( +void raybri_init( const char *main_vs, const char *main_fs, const char *shadow_vs, const char *shadow_fs, - sr_config config + raybri_config config ) { sr_cfg = config; @@ -201,7 +201,7 @@ void sr_init( sr_ready = 1; } -void sr_load_model(const char *gltf_path) +void raybri_load_model(const char *gltf_path) { if (!sr_ready || gltf_path == NULL) return; @@ -242,13 +242,13 @@ void sr_load_model(const char *gltf_path) } } -void sr_resize(int width, int height) +void raybri_resize(int width, int height) { if (width > 0) sr_width = width; if (height > 0) sr_height = height; } -void sr_set_rotation(float x_deg, float y_deg, float z_deg) +void raybri_set_rotation(float x_deg, float y_deg, float z_deg) { sr_rot_x = x_deg; sr_rot_y = y_deg; @@ -395,7 +395,7 @@ static void sr_draw_object(Model model, Material material, Matrix model_mat, DrawMesh(model.meshes[0], material, model_mat); } -void sr_render(void) +void raybri_render(void) { if (!sr_ready) return; @@ -411,7 +411,7 @@ void sr_render(void) sr_render_main_pass(); } -void sr_shutdown(void) +void raybri_shutdown(void) { if (!sr_ready) return; diff --git a/components/raybri/raybri.h b/components/raybri/raybri.h index c7482b9..5493ad3 100644 --- a/components/raybri/raybri.h +++ b/components/raybri/raybri.h @@ -6,38 +6,38 @@ extern "C" { #endif // Render configuration, sourced from renderConst.swift. -typedef struct sr_config { +typedef struct raybri_config { float fov_y; // vertical field of view (degrees) float near_plane; // camera near plane float far_plane; // camera far plane int shadow_size; // shadow map resolution (px) float ground_size; // ground plane extent -} sr_config; +} raybri_config; // Initialise the OpenGL-backed raylib scene (no raylib window is created). // The four shader sources come from renderConstShader.swift. -void sr_init( +void raybri_init( const char *main_vs, const char *main_fs, const char *shadow_vs, const char *shadow_fs, - sr_config config + raybri_config config ); // Load the textured cube glTF model. -void sr_load_model(const char *gltf_path); +void raybri_load_model(const char *gltf_path); // Resize the viewport. -void sr_resize(int width, int height); +void raybri_resize(int width, int height); // Cube rotation, driven by the application (Euler angles, degrees). -void sr_set_rotation(float x_deg, float y_deg, float z_deg); +void raybri_set_rotation(float x_deg, float y_deg, float z_deg); // Render one frame. -void sr_render(void); +void raybri_render(void); // Release all GPU resources. -void sr_shutdown(void); +void raybri_shutdown(void); #ifdef __cplusplus } diff --git a/components/render/renderAux.swift b/components/render/renderAux.swift index d8000c3..e9feeb3 100644 --- a/components/render/renderAux.swift +++ b/components/render/renderAux.swift @@ -4,10 +4,10 @@ import RaylibBridge func renderDraw(_ vm: RenderVM) { vm.glView.openGLContext?.makeCurrentContext() - sr_resize(vm.pixelSize[0], vm.pixelSize[1]) + raybri_resize(vm.pixelSize[0], vm.pixelSize[1]) let t = Float(CACurrentMediaTime() - vm.startTime) - sr_set_rotation(t * 6.0, t * 18.0, 0.0) - sr_render() + raybri_set_rotation(t * 6.0, t * 18.0, 0.0) + raybri_render() vm.glView.openGLContext?.flushBuffer() } diff --git a/components/render/renderConst.swift b/components/render/renderConst.swift index fdf3b6b..d8058cc 100644 --- a/components/render/renderConst.swift +++ b/components/render/renderConst.swift @@ -1,7 +1,7 @@ import AppKit import RaylibBridge -let RENDER_CONFIG = sr_config( +let RENDER_CONFIG = raybri_config( fov_y: 45.0, near_plane: 0.1, far_plane: 1000.0, diff --git a/components/render/renderEffect.swift b/components/render/renderEffect.swift index fffc39e..3ca661a 100644 --- a/components/render/renderEffect.swift +++ b/components/render/renderEffect.swift @@ -6,7 +6,7 @@ func renderDeinit(_ vm: RenderVM) { print("ИГР renderD") vm.timer?.invalidate() vm.glView.openGLContext?.makeCurrentContext() - sr_shutdown() + raybri_shutdown() } func renderInit(_ vm: RenderVM) { @@ -17,7 +17,7 @@ func renderInit(_ vm: RenderVM) { vm.glView.openGLContext?.setValues(&swapInterval, for: .swapInterval) // Init Raylib - sr_init( + raybri_init( RENDER_SHADER_MAIN_VS, RENDER_SHADER_MAIN_FS, RENDER_SHADER_SHADOW_VS, @@ -29,7 +29,7 @@ func renderInit(_ vm: RenderVM) { func renderLoadCubeModel(_ vm: RenderVM) { let path = Bundle.main.resourceURL!.path + RENDER_MODEL_CUBE vm.glView.openGLContext?.makeCurrentContext() - sr_load_model(path) + raybri_load_model(path) } func renderStartTimer(_ vm: RenderVM) { -- 2.53.0 From 59dd5a56f3754431a1780fbbaa2de6b4681f8b10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Wed, 21 Oct 2026 06:35:33 +0300 Subject: [PATCH 42/57] move around --- chkgfx/ver-mac/Info.plist | 26 ++++++++++++ chkgfx/ver-mac/Package.swift | 37 ++++++++++++++++++ chkgfx/ver-mac/res | 1 + game/ver-mac/res | 1 + {game/ver-mac/Resources => res}/AppIcon.icns | Bin .../Resources/assets => res/cube}/cube.gltf | 0 .../assets => res/cube}/cube_normal.png | Bin .../assets => res/cube}/cube_texture.png | Bin 8 files changed, 65 insertions(+) create mode 100644 chkgfx/ver-mac/Info.plist create mode 100644 chkgfx/ver-mac/Package.swift create mode 120000 chkgfx/ver-mac/res create mode 120000 game/ver-mac/res rename {game/ver-mac/Resources => res}/AppIcon.icns (100%) rename {game/ver-mac/Resources/assets => res/cube}/cube.gltf (100%) rename {game/ver-mac/Resources/assets => res/cube}/cube_normal.png (100%) rename {game/ver-mac/Resources/assets => res/cube}/cube_texture.png (100%) diff --git a/chkgfx/ver-mac/Info.plist b/chkgfx/ver-mac/Info.plist new file mode 100644 index 0000000..dc46284 --- /dev/null +++ b/chkgfx/ver-mac/Info.plist @@ -0,0 +1,26 @@ + + + + + CFBundleName + OGS Mahjong + CFBundleDisplayName + OGS Mahjong + CFBundleIdentifier + org.opengamestudio.Mahjong + CFBundleExecutable + ogs-mahjong + CFBundleIconFile + AppIcon + CFBundlePackageType + APPL + CFBundleShortVersionString + 2.0.0 + CFBundleVersion + 1 + LSMinimumSystemVersion + 11.0 + NSHighResolutionCapable + + + diff --git a/chkgfx/ver-mac/Package.swift b/chkgfx/ver-mac/Package.swift new file mode 100644 index 0000000..1dff832 --- /dev/null +++ b/chkgfx/ver-mac/Package.swift @@ -0,0 +1,37 @@ +// swift-tools-version: 5.9 +import Foundation +import PackageDescription + +let raylibPrefix = ProcessInfo.processInfo.environment["RAYLIB_PREFIX"] ?? "/opt/homebrew" + +let package = Package( + name: "OGSMahjong", + platforms: [ + .macOS(.v13) + ], + targets: [ + .target( + name: "RaylibBridge", + path: "src/raybri", + publicHeadersPath: ".", + cSettings: [ + .unsafeFlags(["-I", "\(raylibPrefix)/include"]) + ] + ), + .executableTarget( + name: "ogs-mahjong", + dependencies: ["RaylibBridge"], + path: "src", + exclude: ["raybri"], + swiftSettings: [ + .unsafeFlags(["-Xcc", "-DGL_SILENCE_DEPRECATION"]) + ], + linkerSettings: [ + .unsafeFlags([ + "-L", "\(raylibPrefix)/lib", + "-lraylib" + ]) + ] + ) + ] +) diff --git a/chkgfx/ver-mac/res b/chkgfx/ver-mac/res new file mode 120000 index 0000000..8f3459f --- /dev/null +++ b/chkgfx/ver-mac/res @@ -0,0 +1 @@ +../../res \ No newline at end of file diff --git a/game/ver-mac/res b/game/ver-mac/res new file mode 120000 index 0000000..8f3459f --- /dev/null +++ b/game/ver-mac/res @@ -0,0 +1 @@ +../../res \ No newline at end of file diff --git a/game/ver-mac/Resources/AppIcon.icns b/res/AppIcon.icns similarity index 100% rename from game/ver-mac/Resources/AppIcon.icns rename to res/AppIcon.icns diff --git a/game/ver-mac/Resources/assets/cube.gltf b/res/cube/cube.gltf similarity index 100% rename from game/ver-mac/Resources/assets/cube.gltf rename to res/cube/cube.gltf diff --git a/game/ver-mac/Resources/assets/cube_normal.png b/res/cube/cube_normal.png similarity index 100% rename from game/ver-mac/Resources/assets/cube_normal.png rename to res/cube/cube_normal.png diff --git a/game/ver-mac/Resources/assets/cube_texture.png b/res/cube/cube_texture.png similarity index 100% rename from game/ver-mac/Resources/assets/cube_texture.png rename to res/cube/cube_texture.png -- 2.53.0 From 738a5bffd02928d8cbedc701b9b1c7adacdc81a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Wed, 21 Oct 2026 06:37:43 +0300 Subject: [PATCH 43/57] mo --- components/render/renderConst.swift | 2 +- util/step/packageMac | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/components/render/renderConst.swift b/components/render/renderConst.swift index d8058cc..787b0c5 100644 --- a/components/render/renderConst.swift +++ b/components/render/renderConst.swift @@ -11,7 +11,7 @@ let RENDER_CONFIG = raybri_config( let RENDER_FPS = 60.0 -let RENDER_MODEL_CUBE = "/assets/cube.gltf" +let RENDER_MODEL_CUBE = "/cube/cube.gltf" let RENDER_OPENGL_ATTRS: [NSOpenGLPixelFormatAttribute] = [ UInt32(NSOpenGLPFAOpenGLProfile), UInt32(NSOpenGLProfileVersion3_2Core), diff --git a/util/step/packageMac b/util/step/packageMac index 87ee9ca..43f8340 100755 --- a/util/step/packageMac +++ b/util/step/packageMac @@ -12,7 +12,7 @@ mkdir -p "$APP_DAT/Resources" cp "$SDIR/../game/ver-mac/.build/debug/ogs-mahjong" "$APP_DAT/MacOS/ogs-mahjong" cp "$SDIR/../game/ver-mac/Info.plist" "$APP_DAT/Info.plist" -cp "$SDIR/../game/ver-mac/Resources/AppIcon.icns" "$APP_DAT/Resources/AppIcon.icns" -mkdir -p "$APP_DAT/Resources/assets" -cp "$SDIR/../game/ver-mac/Resources/assets/"* "$APP_DAT/Resources/assets/" +# App resources (icons + glTF assets) live in the repo-level res/ directory, +# symlinked as game/ver-mac/res. +cp -R "$SDIR/../game/ver-mac/res/." "$APP_DAT/Resources/" -- 2.53.0 From 47f9eb904a49d33300f414c23f0db70326b4623b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Wed, 21 Oct 2026 17:35:20 +0300 Subject: [PATCH 44/57] some --- dialect.yml => chkgfx/dialect.yml | 18 +++ chkgfx/ver-mac/Info.plist | 8 +- chkgfx/ver-mac/Package.swift | 4 +- chkgfx/ver-mac/src/AppDelegate.swift | 26 ++++ chkgfx/ver-mac/src/ChkgfxApp.swift | 18 +++ chkgfx/ver-mac/src/chkgfx/chkgfx.swift | 1 + chkgfx/ver-mac/src/chkgfx/chkgfxVM.swift | 1 + .../ver-mac/src/chkgfx/view/ChkgfxView.swift | 1 + chkgfx/ver-mac/src/other/other.swift | 1 + chkgfx/ver-mac/src/raybri/raybri.c | 1 + chkgfx/ver-mac/src/raybri/raybri.h | 1 + chkgfx/ver-mac/src/render/render.swift | 1 + chkgfx/ver-mac/src/render/renderAux.swift | 1 + chkgfx/ver-mac/src/render/renderConst.swift | 1 + .../src/render/renderConstShader.swift | 1 + chkgfx/ver-mac/src/render/renderEffect.swift | 1 + chkgfx/ver-mac/src/render/renderVM.swift | 1 + .../src/render/view/RenderGLView.swift | 1 + .../ver-mac/src/render/view/RenderView.swift | 1 + components/chkgfx/chkgfx.swift | 14 +++ components/chkgfx/chkgfxVM.swift | 9 ++ components/chkgfx/mac/view/ChkgfxView.swift | 20 +++ components/root/mac/view/RootView.swift | 21 ++-- game/dialect.yml | 115 ++++++++++++++++++ game/ver-mac/Info.plist | 2 +- game/ver-mac/src/GameApp.swift | 6 +- game/ver-mac/src/dialect.swift | 73 +++++++++++ util/{build-mac => build-game-mac} | 6 +- util/step/buildMac | 15 +-- util/step/generateDialect | 5 +- 30 files changed, 339 insertions(+), 35 deletions(-) rename dialect.yml => chkgfx/dialect.yml (87%) create mode 100644 chkgfx/ver-mac/src/AppDelegate.swift create mode 100644 chkgfx/ver-mac/src/ChkgfxApp.swift create mode 120000 chkgfx/ver-mac/src/chkgfx/chkgfx.swift create mode 120000 chkgfx/ver-mac/src/chkgfx/chkgfxVM.swift create mode 120000 chkgfx/ver-mac/src/chkgfx/view/ChkgfxView.swift create mode 120000 chkgfx/ver-mac/src/other/other.swift create mode 120000 chkgfx/ver-mac/src/raybri/raybri.c create mode 120000 chkgfx/ver-mac/src/raybri/raybri.h create mode 120000 chkgfx/ver-mac/src/render/render.swift create mode 120000 chkgfx/ver-mac/src/render/renderAux.swift create mode 120000 chkgfx/ver-mac/src/render/renderConst.swift create mode 120000 chkgfx/ver-mac/src/render/renderConstShader.swift create mode 120000 chkgfx/ver-mac/src/render/renderEffect.swift create mode 120000 chkgfx/ver-mac/src/render/renderVM.swift create mode 120000 chkgfx/ver-mac/src/render/view/RenderGLView.swift create mode 120000 chkgfx/ver-mac/src/render/view/RenderView.swift create mode 100644 components/chkgfx/chkgfx.swift create mode 100644 components/chkgfx/chkgfxVM.swift create mode 100644 components/chkgfx/mac/view/ChkgfxView.swift create mode 100644 game/dialect.yml rename util/{build-mac => build-game-mac} (53%) diff --git a/dialect.yml b/chkgfx/dialect.yml similarity index 87% rename from dialect.yml rename to chkgfx/dialect.yml index 9969dad..4fd7a71 100644 --- a/dialect.yml +++ b/chkgfx/dialect.yml @@ -4,6 +4,24 @@ output: game/ver-mac/src/dialect.swift: type: swift +ChkgfxComponent: + type: component + shoulds: + didLaunch: + 1. Only once during the first setup: + if: + c.recentField == F.didSetup && + c.didLaunch == false + then: + c.didLaunch = true + +ChkgfxContext: + type: context + fields: + didClickLoadModel: Bool + didLaunch: Bool + didSetup: Bool + RenderContext: type: context fields: diff --git a/chkgfx/ver-mac/Info.plist b/chkgfx/ver-mac/Info.plist index dc46284..6a160d9 100644 --- a/chkgfx/ver-mac/Info.plist +++ b/chkgfx/ver-mac/Info.plist @@ -3,13 +3,13 @@ CFBundleName - OGS Mahjong + OGS chkgfx CFBundleDisplayName - OGS Mahjong + OGS chkgfx CFBundleIdentifier - org.opengamestudio.Mahjong + org.opengamestudio.chkgfx CFBundleExecutable - ogs-mahjong + ogs-chkgfx CFBundleIconFile AppIcon CFBundlePackageType diff --git a/chkgfx/ver-mac/Package.swift b/chkgfx/ver-mac/Package.swift index 1dff832..3974170 100644 --- a/chkgfx/ver-mac/Package.swift +++ b/chkgfx/ver-mac/Package.swift @@ -5,7 +5,7 @@ import PackageDescription let raylibPrefix = ProcessInfo.processInfo.environment["RAYLIB_PREFIX"] ?? "/opt/homebrew" let package = Package( - name: "OGSMahjong", + name: "OGSChkgfx", platforms: [ .macOS(.v13) ], @@ -19,7 +19,7 @@ let package = Package( ] ), .executableTarget( - name: "ogs-mahjong", + name: "ogs-chkgfx", dependencies: ["RaylibBridge"], path: "src", exclude: ["raybri"], diff --git a/chkgfx/ver-mac/src/AppDelegate.swift b/chkgfx/ver-mac/src/AppDelegate.swift new file mode 100644 index 0000000..1442afc --- /dev/null +++ b/chkgfx/ver-mac/src/AppDelegate.swift @@ -0,0 +1,26 @@ +import AppKit + +final class AppDelegate: + NSObject, + NSApplicationDelegate +{ + let chkgfx = ChkgfxComponent() + let chkgfxVM = ChkgfxVM() + let render = RenderComponent() + let renderVM = RenderVM() + + func applicationDidFinishLaunching(_ notification: Notification) { + // Bring the app to the foreground + NSApp.setActivationPolicy(.regular) + NSApp.activate(ignoringOtherApps: true) + + otherSetupConsoleLogging(chkgfx.ctrl, "Chkgfx") + chkgfx.setup() + otherSetupConsoleLogging(render.ctrl, "Render") + render.setup() + } + + func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { + true + } +} diff --git a/chkgfx/ver-mac/src/ChkgfxApp.swift b/chkgfx/ver-mac/src/ChkgfxApp.swift new file mode 100644 index 0000000..1aeaeff --- /dev/null +++ b/chkgfx/ver-mac/src/ChkgfxApp.swift @@ -0,0 +1,18 @@ +import AppKit +import SwiftUI + +@main +struct ChkgfxApp: App { + @NSApplicationDelegateAdaptor(AppDelegate.self) private var appDelegate + + var body: some Scene { + WindowGroup { + ZStack { + RenderView() + .ignoresSafeArea() + ChkgfxView(appDelegate.rootVM) + } + } + .defaultSize(width: 640, height: 480) + } +} diff --git a/chkgfx/ver-mac/src/chkgfx/chkgfx.swift b/chkgfx/ver-mac/src/chkgfx/chkgfx.swift new file mode 120000 index 0000000..3c6bb5e --- /dev/null +++ b/chkgfx/ver-mac/src/chkgfx/chkgfx.swift @@ -0,0 +1 @@ +../../../../components/chkgfx/chkgfx.swift \ No newline at end of file diff --git a/chkgfx/ver-mac/src/chkgfx/chkgfxVM.swift b/chkgfx/ver-mac/src/chkgfx/chkgfxVM.swift new file mode 120000 index 0000000..cf74ca4 --- /dev/null +++ b/chkgfx/ver-mac/src/chkgfx/chkgfxVM.swift @@ -0,0 +1 @@ +../../../../components/chkgfx/chkgfxVM.swift \ No newline at end of file diff --git a/chkgfx/ver-mac/src/chkgfx/view/ChkgfxView.swift b/chkgfx/ver-mac/src/chkgfx/view/ChkgfxView.swift new file mode 120000 index 0000000..8533e0c --- /dev/null +++ b/chkgfx/ver-mac/src/chkgfx/view/ChkgfxView.swift @@ -0,0 +1 @@ +../../../../../components/chkgfx/mac/view/ChkgfxView.swift \ No newline at end of file diff --git a/chkgfx/ver-mac/src/other/other.swift b/chkgfx/ver-mac/src/other/other.swift new file mode 120000 index 0000000..f91488c --- /dev/null +++ b/chkgfx/ver-mac/src/other/other.swift @@ -0,0 +1 @@ +../../../../components/other/other.swift \ No newline at end of file diff --git a/chkgfx/ver-mac/src/raybri/raybri.c b/chkgfx/ver-mac/src/raybri/raybri.c new file mode 120000 index 0000000..52b1940 --- /dev/null +++ b/chkgfx/ver-mac/src/raybri/raybri.c @@ -0,0 +1 @@ +../../../../components/raybri/raybri.c \ No newline at end of file diff --git a/chkgfx/ver-mac/src/raybri/raybri.h b/chkgfx/ver-mac/src/raybri/raybri.h new file mode 120000 index 0000000..daec20f --- /dev/null +++ b/chkgfx/ver-mac/src/raybri/raybri.h @@ -0,0 +1 @@ +../../../../components/raybri/raybri.h \ No newline at end of file diff --git a/chkgfx/ver-mac/src/render/render.swift b/chkgfx/ver-mac/src/render/render.swift new file mode 120000 index 0000000..5e4b117 --- /dev/null +++ b/chkgfx/ver-mac/src/render/render.swift @@ -0,0 +1 @@ +../../../../components/render/render.swift \ No newline at end of file diff --git a/chkgfx/ver-mac/src/render/renderAux.swift b/chkgfx/ver-mac/src/render/renderAux.swift new file mode 120000 index 0000000..1975b82 --- /dev/null +++ b/chkgfx/ver-mac/src/render/renderAux.swift @@ -0,0 +1 @@ +../../../../components/render/renderAux.swift \ No newline at end of file diff --git a/chkgfx/ver-mac/src/render/renderConst.swift b/chkgfx/ver-mac/src/render/renderConst.swift new file mode 120000 index 0000000..d953714 --- /dev/null +++ b/chkgfx/ver-mac/src/render/renderConst.swift @@ -0,0 +1 @@ +../../../../components/render/renderConst.swift \ No newline at end of file diff --git a/chkgfx/ver-mac/src/render/renderConstShader.swift b/chkgfx/ver-mac/src/render/renderConstShader.swift new file mode 120000 index 0000000..2dcc2d4 --- /dev/null +++ b/chkgfx/ver-mac/src/render/renderConstShader.swift @@ -0,0 +1 @@ +../../../../components/render/renderConstShader.swift \ No newline at end of file diff --git a/chkgfx/ver-mac/src/render/renderEffect.swift b/chkgfx/ver-mac/src/render/renderEffect.swift new file mode 120000 index 0000000..d269bb5 --- /dev/null +++ b/chkgfx/ver-mac/src/render/renderEffect.swift @@ -0,0 +1 @@ +../../../../components/render/renderEffect.swift \ No newline at end of file diff --git a/chkgfx/ver-mac/src/render/renderVM.swift b/chkgfx/ver-mac/src/render/renderVM.swift new file mode 120000 index 0000000..dde0ace --- /dev/null +++ b/chkgfx/ver-mac/src/render/renderVM.swift @@ -0,0 +1 @@ +../../../../components/render/renderVM.swift \ No newline at end of file diff --git a/chkgfx/ver-mac/src/render/view/RenderGLView.swift b/chkgfx/ver-mac/src/render/view/RenderGLView.swift new file mode 120000 index 0000000..7223ae3 --- /dev/null +++ b/chkgfx/ver-mac/src/render/view/RenderGLView.swift @@ -0,0 +1 @@ +../../../../../components/render/mac/view/RenderGLView.swift \ No newline at end of file diff --git a/chkgfx/ver-mac/src/render/view/RenderView.swift b/chkgfx/ver-mac/src/render/view/RenderView.swift new file mode 120000 index 0000000..754ef01 --- /dev/null +++ b/chkgfx/ver-mac/src/render/view/RenderView.swift @@ -0,0 +1 @@ +../../../../../components/render/mac/view/RenderView.swift \ No newline at end of file diff --git a/components/chkgfx/chkgfx.swift b/components/chkgfx/chkgfx.swift new file mode 100644 index 0000000..fada653 --- /dev/null +++ b/components/chkgfx/chkgfx.swift @@ -0,0 +1,14 @@ +class ChkgfxComponent { + let ctrl = DialectController(ChkgfxContext()) + static private(set) weak var singleton: ChkgfxComponent? + + init() { + Self.singleton = self + chkgfxRegisterEffects(ctrl) + chkgfxRegisterShoulds(ctrl) + } + + func setup() { + chkgfxSet(F.didSetup, true) + } +} diff --git a/components/chkgfx/chkgfxVM.swift b/components/chkgfx/chkgfxVM.swift new file mode 100644 index 0000000..aaf0d9f --- /dev/null +++ b/components/chkgfx/chkgfxVM.swift @@ -0,0 +1,9 @@ +import Combine + +final class ChkgfxVM: ObservableObject { + static private(set) weak var shared: ChkgfxVM? + + init() { + Self.shared = self + } +} diff --git a/components/chkgfx/mac/view/ChkgfxView.swift b/components/chkgfx/mac/view/ChkgfxView.swift new file mode 100644 index 0000000..eda0b97 --- /dev/null +++ b/components/chkgfx/mac/view/ChkgfxView.swift @@ -0,0 +1,20 @@ +import SwiftUI + +struct ChkgfxView: View { + @ObservedObject var vm: ChkgfxVM + + init(_ vm: ChkgfxVM) { + self.vm = vm + } + + var body: some View { + VStack(spacing: 16) { + Text("Check graphics") + .font(.largeTitle) + Button("Load model") { + rootSet(F.didClickLoadModel, true) + } + } + .padding(40) + } +} diff --git a/components/root/mac/view/RootView.swift b/components/root/mac/view/RootView.swift index 034e891..b31b123 100644 --- a/components/root/mac/view/RootView.swift +++ b/components/root/mac/view/RootView.swift @@ -8,22 +8,17 @@ struct RootView: View { } var body: some View { - ZStack { - RenderView() - .ignoresSafeArea() + VStack(spacing: 16) { + Text("Hello, World!") + .font(.largeTitle) - VStack(spacing: 16) { - Text("Hello, World!") - .font(.largeTitle) + Text(vm.countText) + .font(.title3.monospacedDigit()) - Text(vm.countText) - .font(.title3.monospacedDigit()) - - Button("Increment") { - rootSet(F.didClickIncrement, true) - } + Button("Increment") { + rootSet(F.didClickIncrement, true) } - .padding(40) } + .padding(40) } } diff --git a/game/dialect.yml b/game/dialect.yml new file mode 100644 index 0000000..4fd7a71 --- /dev/null +++ b/game/dialect.yml @@ -0,0 +1,115 @@ +version: 4 + +output: + game/ver-mac/src/dialect.swift: + type: swift + +ChkgfxComponent: + type: component + shoulds: + didLaunch: + 1. Only once during the first setup: + if: + c.recentField == F.didSetup && + c.didLaunch == false + then: + c.didLaunch = true + +ChkgfxContext: + type: context + fields: + didClickLoadModel: Bool + didLaunch: Bool + didSetup: Bool + +RenderContext: + type: context + fields: + backingPixelSize: [Int32] + didClickIncrement: Bool + didLaunch: Bool + didPrepareGL: Bool + didSetup: Bool + pixelSize: [Int32] + reshapePixelSize: [Int32] + willDeinit: Bool + +RenderComponent: + type: component + oneliners: + - didClickIncrement: renderLoadCubeModel(RenderVM.shared!) + - didPrepareGL: renderInit(RenderVM.shared!) + - didPrepareGL: RenderVM.shared!.didPrepareGL = true + - didPrepareGL: renderStartTimer(RenderVM.shared!) + - pixelSize: RenderVM.shared!.pixelSize = c.pixelSize + - willDeinit: renderDeinit(RenderVM.shared!) + shoulds: + didLaunch: + 1. Only once during the first setup: + if: + c.recentField == F.didSetup && + c.didLaunch == false + then: + c.didLaunch = true + pixelSize: + 1. Upon launch: + if: + c.recentField == F.didLaunch + then: + c.pixelSize = [1, 1] + 2. Upon resize: + if: + c.recentField == F.reshapePixelSize + then: + c.pixelSize = c.reshapePixelSize + 3. Upon DPI change: + if: + c.recentField == F.backingPixelSize + then: + c.pixelSize = c.backingPixelSize + +RootComponent: + type: component + oneliners: + - countText: RootVM.shared!.countText = c.countText + - didClickIncrement: renderSet(F.didClickIncrement, true) + shoulds: + count: + 1. Upon hitting 10 the first time: + if: + c.recentField == F.didClickIncrement && + c.count == 7 + then: + c.count += 10 + 2. Upon each button click: + if: + c.recentField == F.didClickIncrement + then: + c.count += 1 + countText: + 1. Upon each count change: + if: + c.recentField == F.count + then: + c.countText = "Count: '\(c.count)'" + 2. Upon launch: + if: + c.recentField == F.didLaunch + then: + c.countText = "Press the button to count" + didLaunch: + 1. Only once during the first setup: + if: + c.recentField == F.didSetup && + c.didLaunch == false + then: + c.didLaunch = true + +RootContext: + type: context + fields: + count: Int + countText: String + didClickIncrement: Bool + didLaunch: Bool + didSetup: Bool diff --git a/game/ver-mac/Info.plist b/game/ver-mac/Info.plist index dc46284..47d5716 100644 --- a/game/ver-mac/Info.plist +++ b/game/ver-mac/Info.plist @@ -7,7 +7,7 @@ CFBundleDisplayName OGS Mahjong CFBundleIdentifier - org.opengamestudio.Mahjong + org.opengamestudio.mahjong CFBundleExecutable ogs-mahjong CFBundleIconFile diff --git a/game/ver-mac/src/GameApp.swift b/game/ver-mac/src/GameApp.swift index 65825ae..449a921 100644 --- a/game/ver-mac/src/GameApp.swift +++ b/game/ver-mac/src/GameApp.swift @@ -7,7 +7,11 @@ struct GameApp: App { var body: some Scene { WindowGroup { - RootView(appDelegate.rootVM) + ZStack { + RenderView() + .ignoresSafeArea() + RootView(appDelegate.rootVM) + } } .defaultSize(width: 640, height: 480) } diff --git a/game/ver-mac/src/dialect.swift b/game/ver-mac/src/dialect.swift index 21e24ec..8138c9a 100644 --- a/game/ver-mac/src/dialect.swift +++ b/game/ver-mac/src/dialect.swift @@ -123,6 +123,7 @@ public struct F { public static let count = "count" public static let countText = "countText" public static let didClickIncrement = "didClickIncrement" + public static let didClickLoadModel = "didClickLoadModel" public static let didLaunch = "didLaunch" public static let didPrepareGL = "didPrepareGL" public static let didSetup = "didSetup" @@ -131,6 +132,44 @@ public struct F { public static let willDeinit = "willDeinit" } +public struct ChkgfxContext: DialectContext { + public var didClickLoadModel = Bool() + public var didLaunch = Bool() + public var didSetup = Bool() + + public var recentField = "" + + public func field(_ name: String) -> T { + if (name == "didClickLoadModel") { + return didClickLoadModel as! T + } + else if (name == "didLaunch") { + return didLaunch as! T + } + else if (name == "didSetup") { + return didSetup as! T + } + + return "unknown-field-name" as! T + } + + public mutating func setField( + _ name: String, + _ value: Any + ) { + if (name == "didClickLoadModel") { + didClickLoadModel = value as! Bool + } + else if (name == "didLaunch") { + didLaunch = value as! Bool + } + else if (name == "didSetup") { + didSetup = value as! Bool + } + + } +} + public struct RenderContext: DialectContext { public var backingPixelSize = [Int32]() public var didClickIncrement = Bool() @@ -256,6 +295,13 @@ public struct RootContext: DialectContext { } } +public func chkgfxSet( + _ key: String, + _ value: Any +) { + ChkgfxComponent.singleton!.ctrl.set(key, value) +} + public func renderSet( _ key: String, _ value: Any @@ -270,6 +316,24 @@ public func rootSet( RootComponent.singleton!.ctrl.set(key, value) } +func chkgfxShouldResetDidLaunch(_ c: ChkgfxContext) -> ChkgfxContext { + var c = c + + /* 1. Only once during the first setup */ + if + c.recentField == F.didSetup && + c.didLaunch == false + { + c.didLaunch = true + c.recentField = F.didLaunch + return c + } + + + c.recentField = DIALECT_CONTEXT_RECENT_FIELD_NONE + return c +} + func renderShouldResetDidLaunch(_ c: RenderContext) -> RenderContext { var c = c @@ -394,6 +458,15 @@ func rootShouldResetDidLaunch(_ c: RootContext) -> RootContext { return c } +func chkgfxRegisterShoulds(_ ctrl: DialectController) { + [ + chkgfxShouldResetDidLaunch, + + ].forEach { f in + ctrl.registerFunction { c in f(c as! ChkgfxContext) } + } +} + func renderRegisterShoulds(_ ctrl: DialectController) { [ renderShouldResetDidLaunch, diff --git a/util/build-mac b/util/build-game-mac similarity index 53% rename from util/build-mac rename to util/build-game-mac index 872a9f5..ac85d2f 100755 --- a/util/build-mac +++ b/util/build-game-mac @@ -5,6 +5,6 @@ T=$SDIR/step source $SDIR/paths STEP=0 -source $T/generateDialect -source $T/buildMac -source $T/packageMac +source $T/generateDialect game +source $T/buildMac game +#source $T/packageMac game diff --git a/util/step/buildMac b/util/step/buildMac index cee602a..e1d2386 100755 --- a/util/step/buildMac +++ b/util/step/buildMac @@ -1,17 +1,14 @@ #!/bin/bash -e +TARGET=$1 STEP=$((STEP+1)) -echo -e "\n> > > > Step №$STEP. Build for macOS" +echo -e "\n> > > > Step №$STEP. Build '$TARGET' for macOS" -# raylib is required for the 3D scene (used by the RaylibBridge target). -if [[ -z "${RAYLIB_PREFIX:-}" ]] && command -v brew >/dev/null 2>&1; then - RAYLIB_PREFIX="$(HOMEBREW_NO_AUTO_UPDATE=1 brew --prefix raylib 2>/dev/null || true)" -fi if [[ -z "${RAYLIB_PREFIX:-}" ]]; then - RAYLIB_PREFIX=/opt/homebrew + RAYLIB_PREFIX="$(HOMEBREW_NO_AUTO_UPDATE=1 brew --prefix raylib 2>/dev/null)" fi export RAYLIB_PREFIX -echo "> > > > raylib: $RAYLIB_PREFIX" +echo "Raylib: $RAYLIB_PREFIX" -cd $SDIR/../game/ver-mac -swift build # -Xswiftc -swift-version -Xswiftc 6 +cd $SDIR/../$TARGET/ver-mac +swift build diff --git a/util/step/generateDialect b/util/step/generateDialect index 65357f5..5fe5cf4 100755 --- a/util/step/generateDialect +++ b/util/step/generateDialect @@ -1,6 +1,7 @@ #!/bin/bash -e +TARGET=$1 STEP=$((STEP+1)) -echo -e "\n> > > > Step №$STEP. Generate Dialect" +echo -e "\n> > > > Step №$STEP. Generate Dialect for '$TARGET'" -$SDIR/../../dialect/util/run-generator --file=$SDIR/../dialect.yml +$SDIR/../../dialect/util/run-generator --file=$SDIR/../$TARGET/dialect.yml -- 2.53.0 From f3ea773c7957b65d974131e5a6746a5ae1a72dda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Wed, 21 Oct 2026 17:37:21 +0300 Subject: [PATCH 45/57] build game --- chkgfx/dialect.yml | 2 +- game/dialect.yml | 20 +--------- game/ver-mac/src/dialect.swift | 73 ---------------------------------- 3 files changed, 2 insertions(+), 93 deletions(-) diff --git a/chkgfx/dialect.yml b/chkgfx/dialect.yml index 4fd7a71..9990de3 100644 --- a/chkgfx/dialect.yml +++ b/chkgfx/dialect.yml @@ -1,7 +1,7 @@ version: 4 output: - game/ver-mac/src/dialect.swift: + ver-mac/src/dialect.swift: type: swift ChkgfxComponent: diff --git a/game/dialect.yml b/game/dialect.yml index 4fd7a71..8440cfe 100644 --- a/game/dialect.yml +++ b/game/dialect.yml @@ -1,27 +1,9 @@ version: 4 output: - game/ver-mac/src/dialect.swift: + ver-mac/src/dialect.swift: type: swift -ChkgfxComponent: - type: component - shoulds: - didLaunch: - 1. Only once during the first setup: - if: - c.recentField == F.didSetup && - c.didLaunch == false - then: - c.didLaunch = true - -ChkgfxContext: - type: context - fields: - didClickLoadModel: Bool - didLaunch: Bool - didSetup: Bool - RenderContext: type: context fields: diff --git a/game/ver-mac/src/dialect.swift b/game/ver-mac/src/dialect.swift index 8138c9a..21e24ec 100644 --- a/game/ver-mac/src/dialect.swift +++ b/game/ver-mac/src/dialect.swift @@ -123,7 +123,6 @@ public struct F { public static let count = "count" public static let countText = "countText" public static let didClickIncrement = "didClickIncrement" - public static let didClickLoadModel = "didClickLoadModel" public static let didLaunch = "didLaunch" public static let didPrepareGL = "didPrepareGL" public static let didSetup = "didSetup" @@ -132,44 +131,6 @@ public struct F { public static let willDeinit = "willDeinit" } -public struct ChkgfxContext: DialectContext { - public var didClickLoadModel = Bool() - public var didLaunch = Bool() - public var didSetup = Bool() - - public var recentField = "" - - public func field(_ name: String) -> T { - if (name == "didClickLoadModel") { - return didClickLoadModel as! T - } - else if (name == "didLaunch") { - return didLaunch as! T - } - else if (name == "didSetup") { - return didSetup as! T - } - - return "unknown-field-name" as! T - } - - public mutating func setField( - _ name: String, - _ value: Any - ) { - if (name == "didClickLoadModel") { - didClickLoadModel = value as! Bool - } - else if (name == "didLaunch") { - didLaunch = value as! Bool - } - else if (name == "didSetup") { - didSetup = value as! Bool - } - - } -} - public struct RenderContext: DialectContext { public var backingPixelSize = [Int32]() public var didClickIncrement = Bool() @@ -295,13 +256,6 @@ public struct RootContext: DialectContext { } } -public func chkgfxSet( - _ key: String, - _ value: Any -) { - ChkgfxComponent.singleton!.ctrl.set(key, value) -} - public func renderSet( _ key: String, _ value: Any @@ -316,24 +270,6 @@ public func rootSet( RootComponent.singleton!.ctrl.set(key, value) } -func chkgfxShouldResetDidLaunch(_ c: ChkgfxContext) -> ChkgfxContext { - var c = c - - /* 1. Only once during the first setup */ - if - c.recentField == F.didSetup && - c.didLaunch == false - { - c.didLaunch = true - c.recentField = F.didLaunch - return c - } - - - c.recentField = DIALECT_CONTEXT_RECENT_FIELD_NONE - return c -} - func renderShouldResetDidLaunch(_ c: RenderContext) -> RenderContext { var c = c @@ -458,15 +394,6 @@ func rootShouldResetDidLaunch(_ c: RootContext) -> RootContext { return c } -func chkgfxRegisterShoulds(_ ctrl: DialectController) { - [ - chkgfxShouldResetDidLaunch, - - ].forEach { f in - ctrl.registerFunction { c in f(c as! ChkgfxContext) } - } -} - func renderRegisterShoulds(_ ctrl: DialectController) { [ renderShouldResetDidLaunch, -- 2.53.0 From 70386f15b6a6e8350fd7c69ce97927c04ca9ebaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Wed, 21 Oct 2026 17:51:05 +0300 Subject: [PATCH 46/57] scripts --- {chkgfx => ogs-chkgfx}/dialect.yml | 0 {chkgfx => ogs-chkgfx}/ver-mac/Info.plist | 0 {chkgfx => ogs-chkgfx}/ver-mac/Package.swift | 0 {chkgfx => ogs-chkgfx}/ver-mac/res | 0 .../ver-mac/src/AppDelegate.swift | 0 .../ver-mac/src/ChkgfxApp.swift | 0 .../ver-mac/src/chkgfx/chkgfx.swift | 0 .../ver-mac/src/chkgfx/chkgfxVM.swift | 0 .../ver-mac/src/chkgfx/view/ChkgfxView.swift | 0 .../ver-mac/src/other/other.swift | 0 .../ver-mac/src/raybri/raybri.c | 0 .../ver-mac/src/raybri/raybri.h | 0 .../ver-mac/src/render/render.swift | 0 .../ver-mac/src/render/renderAux.swift | 0 .../ver-mac/src/render/renderConst.swift | 0 .../src/render/renderConstShader.swift | 0 .../ver-mac/src/render/renderEffect.swift | 0 .../ver-mac/src/render/renderVM.swift | 0 .../src/render/view/RenderGLView.swift | 0 .../ver-mac/src/render/view/RenderView.swift | 0 {game => ogs-mahjong}/dialect.yml | 0 {game => ogs-mahjong}/ver-mac/Info.plist | 0 {game => ogs-mahjong}/ver-mac/Package.swift | 0 {game => ogs-mahjong}/ver-mac/res | 0 .../ver-mac/src/AppDelegate.swift | 0 .../ver-mac/src/GameApp.swift | 0 .../ver-mac/src/dialect.swift | 0 .../ver-mac/src/other/other.swift | 0 .../ver-mac/src/raybri/raybri.c | 0 .../ver-mac/src/raybri/raybri.h | 0 .../ver-mac/src/render/render.swift | 0 .../ver-mac/src/render/renderAux.swift | 0 .../ver-mac/src/render/renderConst.swift | 0 .../src/render/renderConstShader.swift | 0 .../ver-mac/src/render/renderEffect.swift | 0 .../ver-mac/src/render/renderVM.swift | 0 .../src/render/view/RenderGLView.swift | 0 .../ver-mac/src/render/view/RenderView.swift | 0 .../ver-mac/src/root/root.swift | 0 .../ver-mac/src/root/rootVM.swift | 0 .../ver-mac/src/root/view/RootView.swift | 0 util/build-game-mac | 10 ---------- util/build-ogs-mahjong-mac | 12 ++++++++++++ util/paths | 1 - util/run-mac | 2 +- util/step/packageMac | 19 +++++++++---------- util/step/runMac | 6 ++++-- 47 files changed, 26 insertions(+), 24 deletions(-) rename {chkgfx => ogs-chkgfx}/dialect.yml (100%) rename {chkgfx => ogs-chkgfx}/ver-mac/Info.plist (100%) rename {chkgfx => ogs-chkgfx}/ver-mac/Package.swift (100%) rename {chkgfx => ogs-chkgfx}/ver-mac/res (100%) rename {chkgfx => ogs-chkgfx}/ver-mac/src/AppDelegate.swift (100%) rename {chkgfx => ogs-chkgfx}/ver-mac/src/ChkgfxApp.swift (100%) rename {chkgfx => ogs-chkgfx}/ver-mac/src/chkgfx/chkgfx.swift (100%) rename {chkgfx => ogs-chkgfx}/ver-mac/src/chkgfx/chkgfxVM.swift (100%) rename {chkgfx => ogs-chkgfx}/ver-mac/src/chkgfx/view/ChkgfxView.swift (100%) rename {chkgfx => ogs-chkgfx}/ver-mac/src/other/other.swift (100%) rename {chkgfx => ogs-chkgfx}/ver-mac/src/raybri/raybri.c (100%) rename {chkgfx => ogs-chkgfx}/ver-mac/src/raybri/raybri.h (100%) rename {chkgfx => ogs-chkgfx}/ver-mac/src/render/render.swift (100%) rename {chkgfx => ogs-chkgfx}/ver-mac/src/render/renderAux.swift (100%) rename {chkgfx => ogs-chkgfx}/ver-mac/src/render/renderConst.swift (100%) rename {chkgfx => ogs-chkgfx}/ver-mac/src/render/renderConstShader.swift (100%) rename {chkgfx => ogs-chkgfx}/ver-mac/src/render/renderEffect.swift (100%) rename {chkgfx => ogs-chkgfx}/ver-mac/src/render/renderVM.swift (100%) rename {chkgfx => ogs-chkgfx}/ver-mac/src/render/view/RenderGLView.swift (100%) rename {chkgfx => ogs-chkgfx}/ver-mac/src/render/view/RenderView.swift (100%) rename {game => ogs-mahjong}/dialect.yml (100%) rename {game => ogs-mahjong}/ver-mac/Info.plist (100%) rename {game => ogs-mahjong}/ver-mac/Package.swift (100%) rename {game => ogs-mahjong}/ver-mac/res (100%) rename {game => ogs-mahjong}/ver-mac/src/AppDelegate.swift (100%) rename {game => ogs-mahjong}/ver-mac/src/GameApp.swift (100%) rename {game => ogs-mahjong}/ver-mac/src/dialect.swift (100%) rename {game => ogs-mahjong}/ver-mac/src/other/other.swift (100%) rename {game => ogs-mahjong}/ver-mac/src/raybri/raybri.c (100%) rename {game => ogs-mahjong}/ver-mac/src/raybri/raybri.h (100%) rename {game => ogs-mahjong}/ver-mac/src/render/render.swift (100%) rename {game => ogs-mahjong}/ver-mac/src/render/renderAux.swift (100%) rename {game => ogs-mahjong}/ver-mac/src/render/renderConst.swift (100%) rename {game => ogs-mahjong}/ver-mac/src/render/renderConstShader.swift (100%) rename {game => ogs-mahjong}/ver-mac/src/render/renderEffect.swift (100%) rename {game => ogs-mahjong}/ver-mac/src/render/renderVM.swift (100%) rename {game => ogs-mahjong}/ver-mac/src/render/view/RenderGLView.swift (100%) rename {game => ogs-mahjong}/ver-mac/src/render/view/RenderView.swift (100%) rename {game => ogs-mahjong}/ver-mac/src/root/root.swift (100%) rename {game => ogs-mahjong}/ver-mac/src/root/rootVM.swift (100%) rename {game => ogs-mahjong}/ver-mac/src/root/view/RootView.swift (100%) delete mode 100755 util/build-game-mac create mode 100755 util/build-ogs-mahjong-mac diff --git a/chkgfx/dialect.yml b/ogs-chkgfx/dialect.yml similarity index 100% rename from chkgfx/dialect.yml rename to ogs-chkgfx/dialect.yml diff --git a/chkgfx/ver-mac/Info.plist b/ogs-chkgfx/ver-mac/Info.plist similarity index 100% rename from chkgfx/ver-mac/Info.plist rename to ogs-chkgfx/ver-mac/Info.plist diff --git a/chkgfx/ver-mac/Package.swift b/ogs-chkgfx/ver-mac/Package.swift similarity index 100% rename from chkgfx/ver-mac/Package.swift rename to ogs-chkgfx/ver-mac/Package.swift diff --git a/chkgfx/ver-mac/res b/ogs-chkgfx/ver-mac/res similarity index 100% rename from chkgfx/ver-mac/res rename to ogs-chkgfx/ver-mac/res diff --git a/chkgfx/ver-mac/src/AppDelegate.swift b/ogs-chkgfx/ver-mac/src/AppDelegate.swift similarity index 100% rename from chkgfx/ver-mac/src/AppDelegate.swift rename to ogs-chkgfx/ver-mac/src/AppDelegate.swift diff --git a/chkgfx/ver-mac/src/ChkgfxApp.swift b/ogs-chkgfx/ver-mac/src/ChkgfxApp.swift similarity index 100% rename from chkgfx/ver-mac/src/ChkgfxApp.swift rename to ogs-chkgfx/ver-mac/src/ChkgfxApp.swift diff --git a/chkgfx/ver-mac/src/chkgfx/chkgfx.swift b/ogs-chkgfx/ver-mac/src/chkgfx/chkgfx.swift similarity index 100% rename from chkgfx/ver-mac/src/chkgfx/chkgfx.swift rename to ogs-chkgfx/ver-mac/src/chkgfx/chkgfx.swift diff --git a/chkgfx/ver-mac/src/chkgfx/chkgfxVM.swift b/ogs-chkgfx/ver-mac/src/chkgfx/chkgfxVM.swift similarity index 100% rename from chkgfx/ver-mac/src/chkgfx/chkgfxVM.swift rename to ogs-chkgfx/ver-mac/src/chkgfx/chkgfxVM.swift diff --git a/chkgfx/ver-mac/src/chkgfx/view/ChkgfxView.swift b/ogs-chkgfx/ver-mac/src/chkgfx/view/ChkgfxView.swift similarity index 100% rename from chkgfx/ver-mac/src/chkgfx/view/ChkgfxView.swift rename to ogs-chkgfx/ver-mac/src/chkgfx/view/ChkgfxView.swift diff --git a/chkgfx/ver-mac/src/other/other.swift b/ogs-chkgfx/ver-mac/src/other/other.swift similarity index 100% rename from chkgfx/ver-mac/src/other/other.swift rename to ogs-chkgfx/ver-mac/src/other/other.swift diff --git a/chkgfx/ver-mac/src/raybri/raybri.c b/ogs-chkgfx/ver-mac/src/raybri/raybri.c similarity index 100% rename from chkgfx/ver-mac/src/raybri/raybri.c rename to ogs-chkgfx/ver-mac/src/raybri/raybri.c diff --git a/chkgfx/ver-mac/src/raybri/raybri.h b/ogs-chkgfx/ver-mac/src/raybri/raybri.h similarity index 100% rename from chkgfx/ver-mac/src/raybri/raybri.h rename to ogs-chkgfx/ver-mac/src/raybri/raybri.h diff --git a/chkgfx/ver-mac/src/render/render.swift b/ogs-chkgfx/ver-mac/src/render/render.swift similarity index 100% rename from chkgfx/ver-mac/src/render/render.swift rename to ogs-chkgfx/ver-mac/src/render/render.swift diff --git a/chkgfx/ver-mac/src/render/renderAux.swift b/ogs-chkgfx/ver-mac/src/render/renderAux.swift similarity index 100% rename from chkgfx/ver-mac/src/render/renderAux.swift rename to ogs-chkgfx/ver-mac/src/render/renderAux.swift diff --git a/chkgfx/ver-mac/src/render/renderConst.swift b/ogs-chkgfx/ver-mac/src/render/renderConst.swift similarity index 100% rename from chkgfx/ver-mac/src/render/renderConst.swift rename to ogs-chkgfx/ver-mac/src/render/renderConst.swift diff --git a/chkgfx/ver-mac/src/render/renderConstShader.swift b/ogs-chkgfx/ver-mac/src/render/renderConstShader.swift similarity index 100% rename from chkgfx/ver-mac/src/render/renderConstShader.swift rename to ogs-chkgfx/ver-mac/src/render/renderConstShader.swift diff --git a/chkgfx/ver-mac/src/render/renderEffect.swift b/ogs-chkgfx/ver-mac/src/render/renderEffect.swift similarity index 100% rename from chkgfx/ver-mac/src/render/renderEffect.swift rename to ogs-chkgfx/ver-mac/src/render/renderEffect.swift diff --git a/chkgfx/ver-mac/src/render/renderVM.swift b/ogs-chkgfx/ver-mac/src/render/renderVM.swift similarity index 100% rename from chkgfx/ver-mac/src/render/renderVM.swift rename to ogs-chkgfx/ver-mac/src/render/renderVM.swift diff --git a/chkgfx/ver-mac/src/render/view/RenderGLView.swift b/ogs-chkgfx/ver-mac/src/render/view/RenderGLView.swift similarity index 100% rename from chkgfx/ver-mac/src/render/view/RenderGLView.swift rename to ogs-chkgfx/ver-mac/src/render/view/RenderGLView.swift diff --git a/chkgfx/ver-mac/src/render/view/RenderView.swift b/ogs-chkgfx/ver-mac/src/render/view/RenderView.swift similarity index 100% rename from chkgfx/ver-mac/src/render/view/RenderView.swift rename to ogs-chkgfx/ver-mac/src/render/view/RenderView.swift diff --git a/game/dialect.yml b/ogs-mahjong/dialect.yml similarity index 100% rename from game/dialect.yml rename to ogs-mahjong/dialect.yml diff --git a/game/ver-mac/Info.plist b/ogs-mahjong/ver-mac/Info.plist similarity index 100% rename from game/ver-mac/Info.plist rename to ogs-mahjong/ver-mac/Info.plist diff --git a/game/ver-mac/Package.swift b/ogs-mahjong/ver-mac/Package.swift similarity index 100% rename from game/ver-mac/Package.swift rename to ogs-mahjong/ver-mac/Package.swift diff --git a/game/ver-mac/res b/ogs-mahjong/ver-mac/res similarity index 100% rename from game/ver-mac/res rename to ogs-mahjong/ver-mac/res diff --git a/game/ver-mac/src/AppDelegate.swift b/ogs-mahjong/ver-mac/src/AppDelegate.swift similarity index 100% rename from game/ver-mac/src/AppDelegate.swift rename to ogs-mahjong/ver-mac/src/AppDelegate.swift diff --git a/game/ver-mac/src/GameApp.swift b/ogs-mahjong/ver-mac/src/GameApp.swift similarity index 100% rename from game/ver-mac/src/GameApp.swift rename to ogs-mahjong/ver-mac/src/GameApp.swift diff --git a/game/ver-mac/src/dialect.swift b/ogs-mahjong/ver-mac/src/dialect.swift similarity index 100% rename from game/ver-mac/src/dialect.swift rename to ogs-mahjong/ver-mac/src/dialect.swift diff --git a/game/ver-mac/src/other/other.swift b/ogs-mahjong/ver-mac/src/other/other.swift similarity index 100% rename from game/ver-mac/src/other/other.swift rename to ogs-mahjong/ver-mac/src/other/other.swift diff --git a/game/ver-mac/src/raybri/raybri.c b/ogs-mahjong/ver-mac/src/raybri/raybri.c similarity index 100% rename from game/ver-mac/src/raybri/raybri.c rename to ogs-mahjong/ver-mac/src/raybri/raybri.c diff --git a/game/ver-mac/src/raybri/raybri.h b/ogs-mahjong/ver-mac/src/raybri/raybri.h similarity index 100% rename from game/ver-mac/src/raybri/raybri.h rename to ogs-mahjong/ver-mac/src/raybri/raybri.h diff --git a/game/ver-mac/src/render/render.swift b/ogs-mahjong/ver-mac/src/render/render.swift similarity index 100% rename from game/ver-mac/src/render/render.swift rename to ogs-mahjong/ver-mac/src/render/render.swift diff --git a/game/ver-mac/src/render/renderAux.swift b/ogs-mahjong/ver-mac/src/render/renderAux.swift similarity index 100% rename from game/ver-mac/src/render/renderAux.swift rename to ogs-mahjong/ver-mac/src/render/renderAux.swift diff --git a/game/ver-mac/src/render/renderConst.swift b/ogs-mahjong/ver-mac/src/render/renderConst.swift similarity index 100% rename from game/ver-mac/src/render/renderConst.swift rename to ogs-mahjong/ver-mac/src/render/renderConst.swift diff --git a/game/ver-mac/src/render/renderConstShader.swift b/ogs-mahjong/ver-mac/src/render/renderConstShader.swift similarity index 100% rename from game/ver-mac/src/render/renderConstShader.swift rename to ogs-mahjong/ver-mac/src/render/renderConstShader.swift diff --git a/game/ver-mac/src/render/renderEffect.swift b/ogs-mahjong/ver-mac/src/render/renderEffect.swift similarity index 100% rename from game/ver-mac/src/render/renderEffect.swift rename to ogs-mahjong/ver-mac/src/render/renderEffect.swift diff --git a/game/ver-mac/src/render/renderVM.swift b/ogs-mahjong/ver-mac/src/render/renderVM.swift similarity index 100% rename from game/ver-mac/src/render/renderVM.swift rename to ogs-mahjong/ver-mac/src/render/renderVM.swift diff --git a/game/ver-mac/src/render/view/RenderGLView.swift b/ogs-mahjong/ver-mac/src/render/view/RenderGLView.swift similarity index 100% rename from game/ver-mac/src/render/view/RenderGLView.swift rename to ogs-mahjong/ver-mac/src/render/view/RenderGLView.swift diff --git a/game/ver-mac/src/render/view/RenderView.swift b/ogs-mahjong/ver-mac/src/render/view/RenderView.swift similarity index 100% rename from game/ver-mac/src/render/view/RenderView.swift rename to ogs-mahjong/ver-mac/src/render/view/RenderView.swift diff --git a/game/ver-mac/src/root/root.swift b/ogs-mahjong/ver-mac/src/root/root.swift similarity index 100% rename from game/ver-mac/src/root/root.swift rename to ogs-mahjong/ver-mac/src/root/root.swift diff --git a/game/ver-mac/src/root/rootVM.swift b/ogs-mahjong/ver-mac/src/root/rootVM.swift similarity index 100% rename from game/ver-mac/src/root/rootVM.swift rename to ogs-mahjong/ver-mac/src/root/rootVM.swift diff --git a/game/ver-mac/src/root/view/RootView.swift b/ogs-mahjong/ver-mac/src/root/view/RootView.swift similarity index 100% rename from game/ver-mac/src/root/view/RootView.swift rename to ogs-mahjong/ver-mac/src/root/view/RootView.swift diff --git a/util/build-game-mac b/util/build-game-mac deleted file mode 100755 index ac85d2f..0000000 --- a/util/build-game-mac +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash -e -SDIR=$(cd "$(dirname "$0")" ; pwd -P) - -T=$SDIR/step -source $SDIR/paths - -STEP=0 -source $T/generateDialect game -source $T/buildMac game -#source $T/packageMac game diff --git a/util/build-ogs-mahjong-mac b/util/build-ogs-mahjong-mac new file mode 100755 index 0000000..cc120a9 --- /dev/null +++ b/util/build-ogs-mahjong-mac @@ -0,0 +1,12 @@ +#!/bin/bash -e +SDIR=$(cd "$(dirname "$0")" ; pwd -P) + +T=$SDIR/step +source $SDIR/paths + +TARGET=ogs-mahjong + +STEP=0 +source $T/generateDialect $TARGET +source $T/buildMac $TARGET +source $T/packageMac $TARGET "OGS Mahjong" diff --git a/util/paths b/util/paths index 9b43d63..e69de29 100644 --- a/util/paths +++ b/util/paths @@ -1 +0,0 @@ -APP_MAC="$SDIR/../game/ver-mac/.build/OGS Mahjong.app" diff --git a/util/run-mac b/util/run-mac index 4a795e9..4c66bbf 100755 --- a/util/run-mac +++ b/util/run-mac @@ -5,4 +5,4 @@ T=$SDIR/step source $SDIR/paths STEP=0 -source $T/runMac +source $T/runMac ogs-mahjong "OGS Mahjong" diff --git a/util/step/packageMac b/util/step/packageMac index 43f8340..529a496 100755 --- a/util/step/packageMac +++ b/util/step/packageMac @@ -1,18 +1,17 @@ #!/bin/bash -e -STEP=$((STEP+1)) -echo -e "\n> > > > Step №$STEP. Make an app package for macOS" +TARGET=$1 +APP_NAME=$2 +STEP=$((STEP+1)) +echo -e "\n> > > > Step №$STEP. Make '$APP_NAME' macOS package for '$TARGET'" + +APP_MAC="$SDIR/../$TARGET/ver-mac/.build/$APP_NAME.app" rm -rf "$APP_MAC" APP_DAT="$APP_MAC/Contents" - mkdir -p "$APP_DAT/MacOS" mkdir -p "$APP_DAT/Resources" - -cp "$SDIR/../game/ver-mac/.build/debug/ogs-mahjong" "$APP_DAT/MacOS/ogs-mahjong" -cp "$SDIR/../game/ver-mac/Info.plist" "$APP_DAT/Info.plist" - -# App resources (icons + glTF assets) live in the repo-level res/ directory, -# symlinked as game/ver-mac/res. -cp -R "$SDIR/../game/ver-mac/res/." "$APP_DAT/Resources/" +cp "$SDIR/../$TARGET/ver-mac/.build/debug/$TARGET" "$APP_DAT/MacOS/$TARGET" +cp "$SDIR/../$TARGET/ver-mac/Info.plist" "$APP_DAT/Info.plist" +cp -R "$SDIR/../$TARGET/ver-mac/res/." "$APP_DAT/Resources/" diff --git a/util/step/runMac b/util/step/runMac index 93edc86..93bef6f 100755 --- a/util/step/runMac +++ b/util/step/runMac @@ -1,6 +1,8 @@ #!/bin/bash -e +TARGET=$1 +APP_NAME=$2 STEP=$((STEP+1)) -echo -e "\n> > > > Step №$STEP. Run macOS app" +echo -e "\n> > > > Step №$STEP. Run macOS app for '$TARGET'" -"$APP_MAC/Contents/MacOS/ogs-mahjong" +"$SDIR/../$TARGET/ver-mac/.build/$APP_NAME.app/Contents/MacOS/$TARGET" -- 2.53.0 From 26c6ee37575ac5efb97e764f5c4347938bf47fd7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Wed, 21 Oct 2026 17:52:51 +0300 Subject: [PATCH 47/57] ogs-mahjong target --- util/{run-mac => run-ogs-mahjong-mac} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename util/{run-mac => run-ogs-mahjong-mac} (100%) diff --git a/util/run-mac b/util/run-ogs-mahjong-mac similarity index 100% rename from util/run-mac rename to util/run-ogs-mahjong-mac -- 2.53.0 From 5752c96f12af6f06459ba42d09f76a9b0a623e29 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Wed, 21 Oct 2026 17:59:18 +0300 Subject: [PATCH 48/57] prepare chk --- components/chkgfx/mac/view/ChkgfxView.swift | 3 -- ogs-chkgfx/dialect.yml | 46 --------------------- ogs-chkgfx/ver-mac/Package.swift | 2 +- ogs-chkgfx/ver-mac/res | 1 - ogs-chkgfx/ver-mac/res/AppIcon.icns | 1 + ogs-chkgfx/ver-mac/res/cube | 1 + util/build-ogs-chkgfx-mac | 12 ++++++ util/run-ogs-chkgfx-mac | 8 ++++ 8 files changed, 23 insertions(+), 51 deletions(-) delete mode 120000 ogs-chkgfx/ver-mac/res create mode 120000 ogs-chkgfx/ver-mac/res/AppIcon.icns create mode 120000 ogs-chkgfx/ver-mac/res/cube create mode 100755 util/build-ogs-chkgfx-mac create mode 100755 util/run-ogs-chkgfx-mac diff --git a/components/chkgfx/mac/view/ChkgfxView.swift b/components/chkgfx/mac/view/ChkgfxView.swift index eda0b97..76a1136 100644 --- a/components/chkgfx/mac/view/ChkgfxView.swift +++ b/components/chkgfx/mac/view/ChkgfxView.swift @@ -11,9 +11,6 @@ struct ChkgfxView: View { VStack(spacing: 16) { Text("Check graphics") .font(.largeTitle) - Button("Load model") { - rootSet(F.didClickLoadModel, true) - } } .padding(40) } diff --git a/ogs-chkgfx/dialect.yml b/ogs-chkgfx/dialect.yml index 9990de3..1d28d65 100644 --- a/ogs-chkgfx/dialect.yml +++ b/ogs-chkgfx/dialect.yml @@ -67,49 +67,3 @@ RenderComponent: c.recentField == F.backingPixelSize then: c.pixelSize = c.backingPixelSize - -RootComponent: - type: component - oneliners: - - countText: RootVM.shared!.countText = c.countText - - didClickIncrement: renderSet(F.didClickIncrement, true) - shoulds: - count: - 1. Upon hitting 10 the first time: - if: - c.recentField == F.didClickIncrement && - c.count == 7 - then: - c.count += 10 - 2. Upon each button click: - if: - c.recentField == F.didClickIncrement - then: - c.count += 1 - countText: - 1. Upon each count change: - if: - c.recentField == F.count - then: - c.countText = "Count: '\(c.count)'" - 2. Upon launch: - if: - c.recentField == F.didLaunch - then: - c.countText = "Press the button to count" - didLaunch: - 1. Only once during the first setup: - if: - c.recentField == F.didSetup && - c.didLaunch == false - then: - c.didLaunch = true - -RootContext: - type: context - fields: - count: Int - countText: String - didClickIncrement: Bool - didLaunch: Bool - didSetup: Bool diff --git a/ogs-chkgfx/ver-mac/Package.swift b/ogs-chkgfx/ver-mac/Package.swift index 3974170..33fb0be 100644 --- a/ogs-chkgfx/ver-mac/Package.swift +++ b/ogs-chkgfx/ver-mac/Package.swift @@ -5,7 +5,7 @@ import PackageDescription let raylibPrefix = ProcessInfo.processInfo.environment["RAYLIB_PREFIX"] ?? "/opt/homebrew" let package = Package( - name: "OGSChkgfx", + name: "OGSchkgfx", platforms: [ .macOS(.v13) ], diff --git a/ogs-chkgfx/ver-mac/res b/ogs-chkgfx/ver-mac/res deleted file mode 120000 index 8f3459f..0000000 --- a/ogs-chkgfx/ver-mac/res +++ /dev/null @@ -1 +0,0 @@ -../../res \ No newline at end of file diff --git a/ogs-chkgfx/ver-mac/res/AppIcon.icns b/ogs-chkgfx/ver-mac/res/AppIcon.icns new file mode 120000 index 0000000..7e98160 --- /dev/null +++ b/ogs-chkgfx/ver-mac/res/AppIcon.icns @@ -0,0 +1 @@ +../../../res/AppIcon.icns \ No newline at end of file diff --git a/ogs-chkgfx/ver-mac/res/cube b/ogs-chkgfx/ver-mac/res/cube new file mode 120000 index 0000000..24cd8a9 --- /dev/null +++ b/ogs-chkgfx/ver-mac/res/cube @@ -0,0 +1 @@ +../../../res/cube \ No newline at end of file diff --git a/util/build-ogs-chkgfx-mac b/util/build-ogs-chkgfx-mac new file mode 100755 index 0000000..c9fa789 --- /dev/null +++ b/util/build-ogs-chkgfx-mac @@ -0,0 +1,12 @@ +#!/bin/bash -e +SDIR=$(cd "$(dirname "$0")" ; pwd -P) + +T=$SDIR/step +source $SDIR/paths + +TARGET=ogs-chkgfx + +STEP=0 +source $T/generateDialect $TARGET +source $T/buildMac $TARGET +source $T/packageMac $TARGET "OGS chkgfx" diff --git a/util/run-ogs-chkgfx-mac b/util/run-ogs-chkgfx-mac new file mode 100755 index 0000000..df59791 --- /dev/null +++ b/util/run-ogs-chkgfx-mac @@ -0,0 +1,8 @@ +#!/bin/bash -e +SDIR=$(cd "$(dirname "$0")" ; pwd -P) + +T=$SDIR/step +source $SDIR/paths + +STEP=0 +source $T/runMac ogs-chkgfx "OGS chkgfx" -- 2.53.0 From 5cd125b0ed82dee8a0422978ef7f8f544dd057d1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Wed, 21 Oct 2026 18:00:27 +0300 Subject: [PATCH 49/57] build ch --- components/chkgfx/chkgfx.swift | 2 +- ogs-chkgfx/ver-mac/src/ChkgfxApp.swift | 2 +- ogs-chkgfx/ver-mac/src/dialect.swift | 358 +++++++++++++++++++++++++ 3 files changed, 360 insertions(+), 2 deletions(-) create mode 100644 ogs-chkgfx/ver-mac/src/dialect.swift diff --git a/components/chkgfx/chkgfx.swift b/components/chkgfx/chkgfx.swift index fada653..e994fb0 100644 --- a/components/chkgfx/chkgfx.swift +++ b/components/chkgfx/chkgfx.swift @@ -4,7 +4,7 @@ class ChkgfxComponent { init() { Self.singleton = self - chkgfxRegisterEffects(ctrl) + //chkgfxRegisterEffects(ctrl) chkgfxRegisterShoulds(ctrl) } diff --git a/ogs-chkgfx/ver-mac/src/ChkgfxApp.swift b/ogs-chkgfx/ver-mac/src/ChkgfxApp.swift index 1aeaeff..105f2dc 100644 --- a/ogs-chkgfx/ver-mac/src/ChkgfxApp.swift +++ b/ogs-chkgfx/ver-mac/src/ChkgfxApp.swift @@ -10,7 +10,7 @@ struct ChkgfxApp: App { ZStack { RenderView() .ignoresSafeArea() - ChkgfxView(appDelegate.rootVM) + ChkgfxView(appDelegate.chkgfxVM) } } .defaultSize(width: 640, height: 480) diff --git a/ogs-chkgfx/ver-mac/src/dialect.swift b/ogs-chkgfx/ver-mac/src/dialect.swift new file mode 100644 index 0000000..d76883c --- /dev/null +++ b/ogs-chkgfx/ver-mac/src/dialect.swift @@ -0,0 +1,358 @@ + +// Reusable "none" constant +public let DIALECT_CONTEXT_RECENT_FIELD_NONE = "none" + +// Base protocol for each component's state +public protocol DialectContext { + var recentField: String { get set } + + func field(_ name: String) -> T + func fieldAny(_ name: String) -> Any + mutating func setField(_ name: String, _ value: Any) +} + +// Default implementation of `fieldAny` method for the protocol +public extension DialectContext { + func fieldAny(_ name: String) -> Any { + return field(name) + } +} + +// The engine of the dialect components +public class DialectController { + var callbacks = [(DialectContext) -> Void]() + var context: DialectContext + var functions = [(DialectContext) -> DialectContext]() + var isProcessingQueue = false + var queue = [DialectContext]() + + public init(_ context: DialectContext) { + self.context = context + } + + func executeFunctions() { + let c = queue.removeFirst() + // Keep SSOT: Only allow single field change per should-function + context.recentField = c.recentField + context.setField(c.recentField, c.fieldAny(c.recentField)) + + for f in functions { + let ctx = f(context) + if ctx.recentField != DIALECT_CONTEXT_RECENT_FIELD_NONE { + queue.append(ctx) + } + } + + reportContext() + } + + func processQueue() { + // Prevent recursion. + if isProcessingQueue { + return + } + + isProcessingQueue = true + + while (queue.count > 0) { + executeFunctions() + } + + isProcessingQueue = false + } + + public func registerCallback(_ cb: @escaping (DialectContext) -> Void) { + callbacks.append(cb) + } + + public func registerFieldCallback( + _ fieldName: String, + _ cb: @escaping (DialectContext) -> Void + ) { + callbacks.append({ c in + if c.recentField == fieldName { + cb(c) + } + }) + } + + public func registerFunction(_ f: @escaping (DialectContext) -> DialectContext) { + functions.append(f) + } + + func reportContext() { + for cb in callbacks { + cb(context) + } + } + + public func set( + _ fieldName: String, + _ value: Any + ) { + var c = context + c.setField(fieldName, value) + c.recentField = fieldName + queue.append(c) + processQueue() + } +} + +// Register several oneliner callbacks to a controller +func registerOneliners( + _ ctrl: DialectController, + _ items: [Any] +) -> T? { + let halfCount = items.count / 2 + for i in 0.. Void + ctrl.registerFieldCallback(field) { cc in + let c = cc as! T + callback(c) + } + } + + // A hack for generics to operate + return nil +} + +// Context field names for static type check +public struct F { + public static let backingPixelSize = "backingPixelSize" + public static let didClickIncrement = "didClickIncrement" + public static let didClickLoadModel = "didClickLoadModel" + public static let didLaunch = "didLaunch" + public static let didPrepareGL = "didPrepareGL" + public static let didSetup = "didSetup" + public static let pixelSize = "pixelSize" + public static let reshapePixelSize = "reshapePixelSize" + public static let willDeinit = "willDeinit" + +} +public struct ChkgfxContext: DialectContext { + public var didClickLoadModel = Bool() + public var didLaunch = Bool() + public var didSetup = Bool() + + public var recentField = "" + + public func field(_ name: String) -> T { + if (name == "didClickLoadModel") { + return didClickLoadModel as! T + } + else if (name == "didLaunch") { + return didLaunch as! T + } + else if (name == "didSetup") { + return didSetup as! T + } + + return "unknown-field-name" as! T + } + + public mutating func setField( + _ name: String, + _ value: Any + ) { + if (name == "didClickLoadModel") { + didClickLoadModel = value as! Bool + } + else if (name == "didLaunch") { + didLaunch = value as! Bool + } + else if (name == "didSetup") { + didSetup = value as! Bool + } + + } +} + +public struct RenderContext: DialectContext { + public var backingPixelSize = [Int32]() + public var didClickIncrement = Bool() + public var didLaunch = Bool() + public var didPrepareGL = Bool() + public var didSetup = Bool() + public var pixelSize = [Int32]() + public var reshapePixelSize = [Int32]() + public var willDeinit = Bool() + + public var recentField = "" + + public func field(_ name: String) -> T { + if (name == "backingPixelSize") { + return backingPixelSize as! T + } + else if (name == "didClickIncrement") { + return didClickIncrement as! T + } + else if (name == "didLaunch") { + return didLaunch as! T + } + else if (name == "didPrepareGL") { + return didPrepareGL as! T + } + else if (name == "didSetup") { + return didSetup as! T + } + else if (name == "pixelSize") { + return pixelSize as! T + } + else if (name == "reshapePixelSize") { + return reshapePixelSize as! T + } + else if (name == "willDeinit") { + return willDeinit as! T + } + + return "unknown-field-name" as! T + } + + public mutating func setField( + _ name: String, + _ value: Any + ) { + if (name == "backingPixelSize") { + backingPixelSize = value as! [Int32] + } + else if (name == "didClickIncrement") { + didClickIncrement = value as! Bool + } + else if (name == "didLaunch") { + didLaunch = value as! Bool + } + else if (name == "didPrepareGL") { + didPrepareGL = value as! Bool + } + else if (name == "didSetup") { + didSetup = value as! Bool + } + else if (name == "pixelSize") { + pixelSize = value as! [Int32] + } + else if (name == "reshapePixelSize") { + reshapePixelSize = value as! [Int32] + } + else if (name == "willDeinit") { + willDeinit = value as! Bool + } + + } +} + +public func chkgfxSet( + _ key: String, + _ value: Any +) { + ChkgfxComponent.singleton!.ctrl.set(key, value) +} + +public func renderSet( + _ key: String, + _ value: Any +) { + RenderComponent.singleton!.ctrl.set(key, value) +} + +func chkgfxShouldResetDidLaunch(_ c: ChkgfxContext) -> ChkgfxContext { + var c = c + + /* 1. Only once during the first setup */ + if + c.recentField == F.didSetup && + c.didLaunch == false + { + c.didLaunch = true + c.recentField = F.didLaunch + return c + } + + + c.recentField = DIALECT_CONTEXT_RECENT_FIELD_NONE + return c +} + +func renderShouldResetDidLaunch(_ c: RenderContext) -> RenderContext { + var c = c + + /* 1. Only once during the first setup */ + if + c.recentField == F.didSetup && + c.didLaunch == false + { + c.didLaunch = true + c.recentField = F.didLaunch + return c + } + + + c.recentField = DIALECT_CONTEXT_RECENT_FIELD_NONE + return c +} + +func renderShouldResetPixelSize(_ c: RenderContext) -> RenderContext { + var c = c + + /* 1. Upon launch */ + if + c.recentField == F.didLaunch + { + c.pixelSize = [1, 1] + c.recentField = F.pixelSize + return c + } + + /* 2. Upon resize */ + if + c.recentField == F.reshapePixelSize + { + c.pixelSize = c.reshapePixelSize + c.recentField = F.pixelSize + return c + } + + /* 3. Upon DPI change */ + if + c.recentField == F.backingPixelSize + { + c.pixelSize = c.backingPixelSize + c.recentField = F.pixelSize + return c + } + + + c.recentField = DIALECT_CONTEXT_RECENT_FIELD_NONE + return c +} + +func chkgfxRegisterShoulds(_ ctrl: DialectController) { + [ + chkgfxShouldResetDidLaunch, + + ].forEach { f in + ctrl.registerFunction { c in f(c as! ChkgfxContext) } + } +} + +func renderRegisterShoulds(_ ctrl: DialectController) { + [ + renderShouldResetDidLaunch, + renderShouldResetPixelSize, + + ].forEach { f in + ctrl.registerFunction { c in f(c as! RenderContext) } + } +} + +func renderRegisterEffects(_ ctrl: DialectController) { + let _: RenderContext? = registerOneliners(ctrl, [ + F.didClickIncrement, { (c: RenderContext) in renderLoadCubeModel(RenderVM.shared!) }, + F.didPrepareGL, { (c: RenderContext) in renderInit(RenderVM.shared!) }, + F.didPrepareGL, { (c: RenderContext) in RenderVM.shared!.didPrepareGL = true }, + F.didPrepareGL, { (c: RenderContext) in renderStartTimer(RenderVM.shared!) }, + F.pixelSize, { (c: RenderContext) in RenderVM.shared!.pixelSize = c.pixelSize }, + F.willDeinit, { (c: RenderContext) in renderDeinit(RenderVM.shared!) }, + + ]) +} -- 2.53.0 From e94672e4020adf0b6a38932f364e466d3bfd78de Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Wed, 21 Oct 2026 18:06:32 +0300 Subject: [PATCH 50/57] some --- ogs-chkgfx/dialect.yml | 4 +--- ogs-chkgfx/ver-mac/src/dialect.swift | 22 +++------------------- ogs-mahjong/ver-mac/res | 1 - ogs-mahjong/ver-mac/res/AppIcon.icns | 1 + ogs-mahjong/ver-mac/res/cube | 1 + util/step/packageMac | 2 +- 6 files changed, 7 insertions(+), 24 deletions(-) delete mode 120000 ogs-mahjong/ver-mac/res create mode 120000 ogs-mahjong/ver-mac/res/AppIcon.icns create mode 120000 ogs-mahjong/ver-mac/res/cube diff --git a/ogs-chkgfx/dialect.yml b/ogs-chkgfx/dialect.yml index 1d28d65..074422f 100644 --- a/ogs-chkgfx/dialect.yml +++ b/ogs-chkgfx/dialect.yml @@ -18,7 +18,6 @@ ChkgfxComponent: ChkgfxContext: type: context fields: - didClickLoadModel: Bool didLaunch: Bool didSetup: Bool @@ -26,7 +25,6 @@ RenderContext: type: context fields: backingPixelSize: [Int32] - didClickIncrement: Bool didLaunch: Bool didPrepareGL: Bool didSetup: Bool @@ -37,10 +35,10 @@ RenderContext: RenderComponent: type: component oneliners: - - didClickIncrement: renderLoadCubeModel(RenderVM.shared!) - didPrepareGL: renderInit(RenderVM.shared!) - didPrepareGL: RenderVM.shared!.didPrepareGL = true - didPrepareGL: renderStartTimer(RenderVM.shared!) + - didPrepareGL: renderLoadCubeModel(RenderVM.shared!) - pixelSize: RenderVM.shared!.pixelSize = c.pixelSize - willDeinit: renderDeinit(RenderVM.shared!) shoulds: diff --git a/ogs-chkgfx/ver-mac/src/dialect.swift b/ogs-chkgfx/ver-mac/src/dialect.swift index d76883c..db74862 100644 --- a/ogs-chkgfx/ver-mac/src/dialect.swift +++ b/ogs-chkgfx/ver-mac/src/dialect.swift @@ -120,8 +120,6 @@ func registerOneliners( // Context field names for static type check public struct F { public static let backingPixelSize = "backingPixelSize" - public static let didClickIncrement = "didClickIncrement" - public static let didClickLoadModel = "didClickLoadModel" public static let didLaunch = "didLaunch" public static let didPrepareGL = "didPrepareGL" public static let didSetup = "didSetup" @@ -131,17 +129,13 @@ public struct F { } public struct ChkgfxContext: DialectContext { - public var didClickLoadModel = Bool() public var didLaunch = Bool() public var didSetup = Bool() public var recentField = "" public func field(_ name: String) -> T { - if (name == "didClickLoadModel") { - return didClickLoadModel as! T - } - else if (name == "didLaunch") { + if (name == "didLaunch") { return didLaunch as! T } else if (name == "didSetup") { @@ -155,10 +149,7 @@ public struct ChkgfxContext: DialectContext { _ name: String, _ value: Any ) { - if (name == "didClickLoadModel") { - didClickLoadModel = value as! Bool - } - else if (name == "didLaunch") { + if (name == "didLaunch") { didLaunch = value as! Bool } else if (name == "didSetup") { @@ -170,7 +161,6 @@ public struct ChkgfxContext: DialectContext { public struct RenderContext: DialectContext { public var backingPixelSize = [Int32]() - public var didClickIncrement = Bool() public var didLaunch = Bool() public var didPrepareGL = Bool() public var didSetup = Bool() @@ -184,9 +174,6 @@ public struct RenderContext: DialectContext { if (name == "backingPixelSize") { return backingPixelSize as! T } - else if (name == "didClickIncrement") { - return didClickIncrement as! T - } else if (name == "didLaunch") { return didLaunch as! T } @@ -216,9 +203,6 @@ public struct RenderContext: DialectContext { if (name == "backingPixelSize") { backingPixelSize = value as! [Int32] } - else if (name == "didClickIncrement") { - didClickIncrement = value as! Bool - } else if (name == "didLaunch") { didLaunch = value as! Bool } @@ -347,10 +331,10 @@ func renderRegisterShoulds(_ ctrl: DialectController) { func renderRegisterEffects(_ ctrl: DialectController) { let _: RenderContext? = registerOneliners(ctrl, [ - F.didClickIncrement, { (c: RenderContext) in renderLoadCubeModel(RenderVM.shared!) }, F.didPrepareGL, { (c: RenderContext) in renderInit(RenderVM.shared!) }, F.didPrepareGL, { (c: RenderContext) in RenderVM.shared!.didPrepareGL = true }, F.didPrepareGL, { (c: RenderContext) in renderStartTimer(RenderVM.shared!) }, + F.didPrepareGL, { (c: RenderContext) in renderLoadCubeModel(RenderVM.shared!) }, F.pixelSize, { (c: RenderContext) in RenderVM.shared!.pixelSize = c.pixelSize }, F.willDeinit, { (c: RenderContext) in renderDeinit(RenderVM.shared!) }, diff --git a/ogs-mahjong/ver-mac/res b/ogs-mahjong/ver-mac/res deleted file mode 120000 index 8f3459f..0000000 --- a/ogs-mahjong/ver-mac/res +++ /dev/null @@ -1 +0,0 @@ -../../res \ No newline at end of file diff --git a/ogs-mahjong/ver-mac/res/AppIcon.icns b/ogs-mahjong/ver-mac/res/AppIcon.icns new file mode 120000 index 0000000..7e98160 --- /dev/null +++ b/ogs-mahjong/ver-mac/res/AppIcon.icns @@ -0,0 +1 @@ +../../../res/AppIcon.icns \ No newline at end of file diff --git a/ogs-mahjong/ver-mac/res/cube b/ogs-mahjong/ver-mac/res/cube new file mode 120000 index 0000000..24cd8a9 --- /dev/null +++ b/ogs-mahjong/ver-mac/res/cube @@ -0,0 +1 @@ +../../../res/cube \ No newline at end of file diff --git a/util/step/packageMac b/util/step/packageMac index 529a496..b1dce61 100755 --- a/util/step/packageMac +++ b/util/step/packageMac @@ -14,4 +14,4 @@ mkdir -p "$APP_DAT/MacOS" mkdir -p "$APP_DAT/Resources" cp "$SDIR/../$TARGET/ver-mac/.build/debug/$TARGET" "$APP_DAT/MacOS/$TARGET" cp "$SDIR/../$TARGET/ver-mac/Info.plist" "$APP_DAT/Info.plist" -cp -R "$SDIR/../$TARGET/ver-mac/res/." "$APP_DAT/Resources/" +cp -R "$SDIR/../$TARGET/ver-mac/res/*" "$APP_DAT/Resources/" -- 2.53.0 From cb3167f056957a547097b96224d22e4cfafd606a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Wed, 21 Oct 2026 18:09:11 +0300 Subject: [PATCH 51/57] some --- util/step/packageMac | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/util/step/packageMac b/util/step/packageMac index b1dce61..228dae2 100755 --- a/util/step/packageMac +++ b/util/step/packageMac @@ -12,6 +12,6 @@ rm -rf "$APP_MAC" APP_DAT="$APP_MAC/Contents" mkdir -p "$APP_DAT/MacOS" mkdir -p "$APP_DAT/Resources" -cp "$SDIR/../$TARGET/ver-mac/.build/debug/$TARGET" "$APP_DAT/MacOS/$TARGET" -cp "$SDIR/../$TARGET/ver-mac/Info.plist" "$APP_DAT/Info.plist" -cp -R "$SDIR/../$TARGET/ver-mac/res/*" "$APP_DAT/Resources/" +cp $SDIR/../$TARGET/ver-mac/.build/debug/$TARGET "$APP_DAT/MacOS/$TARGET" +cp $SDIR/../$TARGET/ver-mac/Info.plist "$APP_DAT/Info.plist" +cp -R $SDIR/../$TARGET/ver-mac/res/* "$APP_DAT/Resources/" -- 2.53.0 From 82eb0df7730047b4c5e40972c0b62b8355fc03bb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Wed, 21 Oct 2026 18:14:41 +0300 Subject: [PATCH 52/57] deref sym --- util/step/packageMac | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/util/step/packageMac b/util/step/packageMac index 228dae2..cd1186a 100755 --- a/util/step/packageMac +++ b/util/step/packageMac @@ -14,4 +14,5 @@ mkdir -p "$APP_DAT/MacOS" mkdir -p "$APP_DAT/Resources" cp $SDIR/../$TARGET/ver-mac/.build/debug/$TARGET "$APP_DAT/MacOS/$TARGET" cp $SDIR/../$TARGET/ver-mac/Info.plist "$APP_DAT/Info.plist" -cp -R $SDIR/../$TARGET/ver-mac/res/* "$APP_DAT/Resources/" +# Copy resources with symlink dereferencing +cp -R -L $SDIR/../$TARGET/ver-mac/res/* "$APP_DAT/Resources/" -- 2.53.0 From 8398c07966955e9bed34bafec782073211119479 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Wed, 21 Oct 2026 18:24:34 +0300 Subject: [PATCH 53/57] some --- components/chkgfx/chkgfxAux.swift | 9 +++++++++ components/chkgfx/mac/view/ChkgfxView.swift | 2 +- ogs-chkgfx/ver-mac/src/chkgfx/chkgfxAux.swift | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) create mode 100644 components/chkgfx/chkgfxAux.swift create mode 120000 ogs-chkgfx/ver-mac/src/chkgfx/chkgfxAux.swift diff --git a/components/chkgfx/chkgfxAux.swift b/components/chkgfx/chkgfxAux.swift new file mode 100644 index 0000000..a19d6de --- /dev/null +++ b/components/chkgfx/chkgfxAux.swift @@ -0,0 +1,9 @@ +import AppKit + +func chkgfxOutlineText(_ text: String) -> AttributedString { + var att = AttributedString(text) + att.foregroundColor = .clear + att.strokeColor = .white + att.strokeWidth = 4 + return att +} diff --git a/components/chkgfx/mac/view/ChkgfxView.swift b/components/chkgfx/mac/view/ChkgfxView.swift index 76a1136..59a6d5c 100644 --- a/components/chkgfx/mac/view/ChkgfxView.swift +++ b/components/chkgfx/mac/view/ChkgfxView.swift @@ -9,7 +9,7 @@ struct ChkgfxView: View { var body: some View { VStack(spacing: 16) { - Text("Check graphics") + Text(chkgfxOutlineText("Check graphics")) .font(.largeTitle) } .padding(40) diff --git a/ogs-chkgfx/ver-mac/src/chkgfx/chkgfxAux.swift b/ogs-chkgfx/ver-mac/src/chkgfx/chkgfxAux.swift new file mode 120000 index 0000000..35d4532 --- /dev/null +++ b/ogs-chkgfx/ver-mac/src/chkgfx/chkgfxAux.swift @@ -0,0 +1 @@ +../../../../components/chkgfx/chkgfxAux.swift \ No newline at end of file -- 2.53.0 From d0f079da21f3fa4ccd5e3aefd63b654943cd6f88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Wed, 21 Oct 2026 18:30:17 +0300 Subject: [PATCH 54/57] some --- components/chkgfx/chkgfxAux.swift | 9 --------- components/chkgfx/mac/view/ChkgfxView.swift | 3 ++- ogs-chkgfx/ver-mac/src/chkgfx/chkgfxAux.swift | 1 - 3 files changed, 2 insertions(+), 11 deletions(-) delete mode 100644 components/chkgfx/chkgfxAux.swift delete mode 120000 ogs-chkgfx/ver-mac/src/chkgfx/chkgfxAux.swift diff --git a/components/chkgfx/chkgfxAux.swift b/components/chkgfx/chkgfxAux.swift deleted file mode 100644 index a19d6de..0000000 --- a/components/chkgfx/chkgfxAux.swift +++ /dev/null @@ -1,9 +0,0 @@ -import AppKit - -func chkgfxOutlineText(_ text: String) -> AttributedString { - var att = AttributedString(text) - att.foregroundColor = .clear - att.strokeColor = .white - att.strokeWidth = 4 - return att -} diff --git a/components/chkgfx/mac/view/ChkgfxView.swift b/components/chkgfx/mac/view/ChkgfxView.swift index 59a6d5c..3dc61f2 100644 --- a/components/chkgfx/mac/view/ChkgfxView.swift +++ b/components/chkgfx/mac/view/ChkgfxView.swift @@ -9,8 +9,9 @@ struct ChkgfxView: View { var body: some View { VStack(spacing: 16) { - Text(chkgfxOutlineText("Check graphics")) + Text("Check graphics") .font(.largeTitle) + .foregroundStyle(.white) } .padding(40) } diff --git a/ogs-chkgfx/ver-mac/src/chkgfx/chkgfxAux.swift b/ogs-chkgfx/ver-mac/src/chkgfx/chkgfxAux.swift deleted file mode 120000 index 35d4532..0000000 --- a/ogs-chkgfx/ver-mac/src/chkgfx/chkgfxAux.swift +++ /dev/null @@ -1 +0,0 @@ -../../../../components/chkgfx/chkgfxAux.swift \ No newline at end of file -- 2.53.0 From aad0e284cdf78bca7f7e4e8fb95efb737904f89e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Wed, 21 Oct 2026 18:34:23 +0300 Subject: [PATCH 55/57] done --- components/chkgfx/mac/view/ChkgfxView.swift | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/components/chkgfx/mac/view/ChkgfxView.swift b/components/chkgfx/mac/view/ChkgfxView.swift index 3dc61f2..53693b0 100644 --- a/components/chkgfx/mac/view/ChkgfxView.swift +++ b/components/chkgfx/mac/view/ChkgfxView.swift @@ -9,9 +9,15 @@ struct ChkgfxView: View { var body: some View { VStack(spacing: 16) { - Text("Check graphics") - .font(.largeTitle) - .foregroundStyle(.white) + ZStack { + Text("Check graphics") + .font(.largeTitle) + .foregroundStyle(.white) + .offset(x: 1, y: 1) + Text("Check graphics") + .font(.largeTitle) + .foregroundStyle(.black) + } } .padding(40) } -- 2.53.0 From c74cacd4a61710da9db5b9af23900c079524a319 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Thu, 22 Oct 2026 06:06:51 +0300 Subject: [PATCH 56/57] rm exc --- components/render/mac/view/RenderView.swift | 2 -- 1 file changed, 2 deletions(-) diff --git a/components/render/mac/view/RenderView.swift b/components/render/mac/view/RenderView.swift index c6ebf4e..42a503f 100644 --- a/components/render/mac/view/RenderView.swift +++ b/components/render/mac/view/RenderView.swift @@ -1,6 +1,4 @@ import AppKit -import QuartzCore -import RaylibBridge import SwiftUI /// Render view for SwiftUI -- 2.53.0 From 51f2eb3f743f485f3d9dcd60d1bb9e6337ef1366 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9C=D0=B8=D1=85=D0=B0=D0=B8=D0=BB=20=D0=9A=D0=B0=D0=BF?= =?UTF-8?q?=D0=B5=D0=BB=D1=8C=D0=BA=D0=BE?= Date: Thu, 22 Oct 2026 06:12:21 +0300 Subject: [PATCH 57/57] dm --- README.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..e528e84 --- /dev/null +++ b/README.md @@ -0,0 +1,5 @@ +## Prerequisites + +* macOS + + `brew install raylib` -- 2.53.0