rename
This commit is contained in:
1 parent
f0862c88f7
commit
41a7b330aa
6 files changed
+43
-36
No files matched your search
@@ -25,6 +25,10 @@ dialect.yml Single source of truth for the reactive logic.
|
|||||||
components/ SHARED source-of-truth for all components.
|
components/ SHARED source-of-truth for all components.
|
||||||
other/other.swift Shared helpers (otherPrintStderr, otherWriteFile,
|
other/other.swift Shared helpers (otherPrintStderr, otherWriteFile,
|
||||||
otherSetupConsoleLogging, ...)
|
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
|
root/root.swift RootComponent (owns DialectController, registers
|
||||||
effects + shoulds, sets didSetup on setup())
|
effects + shoulds, sets didSetup on setup())
|
||||||
root/rootVM.swift RootVM (ObservableObject / @Published countText)
|
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/render.swift RenderComponent (controller, effects + shoulds)
|
||||||
render/renderVM.swift RenderVM (weak shared; glView, didPrepareGL,
|
render/renderVM.swift RenderVM (weak shared; glView, didPrepareGL,
|
||||||
pixelSize, startTime, timer)
|
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_MODEL_CUBE, RENDER_OPENGL_ATTRS
|
||||||
render/renderConstShader.swift RENDER_SHADER_* GLSL sources (GLSL 150)
|
render/renderConstShader.swift RENDER_SHADER_* GLSL sources (GLSL 150)
|
||||||
render/renderAux.swift renderDraw(vm), renderPixelSize(view)
|
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")
|
game/ver-mac/ macOS app (SPM executable target "ogs-mahjong")
|
||||||
Package.swift SPM manifest (macOS 13+, swift-tools 5.9); C target
|
Package.swift SPM manifest (macOS 13+, swift-tools 5.9); C target
|
||||||
"RaylibBridge" (bridge/) + links Homebrew raylib; the
|
"RaylibBridge" (path src/raybri, publicHeadersPath ".") +
|
||||||
Swift target gets -Xcc -DGL_SILENCE_DEPRECATION
|
links Homebrew raylib; the Swift target excludes raybri
|
||||||
|
and gets -Xcc -DGL_SILENCE_DEPRECATION
|
||||||
Info.plist Bundle id org.opengamestudio.Mahjong, exec ogs-mahjong
|
Info.plist Bundle id org.opengamestudio.Mahjong, exec ogs-mahjong
|
||||||
Resources/AppIcon.icns App icon
|
Resources/AppIcon.icns App icon
|
||||||
Resources/assets/ Bundled glTF assets: cube.gltf (static),
|
Resources/assets/ Bundled glTF assets: cube.gltf (static),
|
||||||
cube_texture.png, cube_normal.png
|
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/
|
src/
|
||||||
GameApp.swift @main SwiftUI App entry
|
GameApp.swift @main SwiftUI App entry
|
||||||
AppDelegate.swift Creates Render/Root components + VMs, calls setup()
|
AppDelegate.swift Creates Render/Root components + VMs, calls setup()
|
||||||
dialect.swift GENERATED — do not hand-edit (see chicken-egg below)
|
dialect.swift GENERATED — do not hand-edit (see chicken-egg below)
|
||||||
other/other.swift -> symlink components/other/other.swift
|
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/render.swift -> symlink components/render/render.swift
|
||||||
render/renderAux.swift -> symlink components/render/renderAux.swift
|
render/renderAux.swift -> symlink components/render/renderAux.swift
|
||||||
render/renderConst.swift -> symlink components/render/renderConst.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/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/render.swift -> ../../../../components/render/render.swift (4 up)
|
||||||
src/render/renderAux.swift -> ../../../../components/render/renderAux.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/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
|
The bridge renders with raylib's rlgl layer into an `NSOpenGLView` — raylib never
|
||||||
creates its own window. `RootView` puts `RenderView` (backed by `RenderGLView`)
|
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` +
|
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
|
(raylib's `LoadModelAnimations` only handles *skinned* meshes, so a plain
|
||||||
node-rotation glTF animation cannot be played by the renderer — hence the cube is
|
node-rotation glTF animation cannot be played by the renderer — hence the cube is
|
||||||
app-driven.) `packageMac` bundles `Resources/assets/` into the app.
|
app-driven.) `packageMac` bundles `Resources/assets/` into the app.
|
||||||
|
|
||||||
Shaders and render constants live in **Swift**, not in C: GLSL sources are
|
Shaders and render constants live in **Swift**, not in C: GLSL sources are
|
||||||
`RENDER_SHADER_*` in `components/render/renderConstShader.swift`, and
|
`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
|
compiles the shaders in place (no storage/`strdup`). `cube_normal.png` drives
|
||||||
tangentless normal mapping via the derivative-based `cotangentFrame`. The
|
tangentless normal mapping via the derivative-based `cotangentFrame`. The
|
||||||
context is OpenGL 3.2 Core (`RENDER_OPENGL_ATTRS`); on Apple Silicon the driver
|
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
|
1. `AppDelegate` creates `RenderComponent` + `RenderVM` and calls
|
||||||
`render.setup()` -> `didSetup` -> `didLaunch` (should) -> `pixelSize = [1, 1]`.
|
`render.setup()` -> `didSetup` -> `didLaunch` (should) -> `pixelSize = [1, 1]`.
|
||||||
2. SwiftUI builds `RenderView` -> `RenderGLView`; `prepareOpenGL()` sets
|
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`.
|
`RenderVM.didPrepareGL = true`, and `renderStartTimer`.
|
||||||
3. `reshape()` / `viewDidChangeBackingProperties()` compute the backing pixel
|
3. `reshape()` / `viewDidChangeBackingProperties()` compute the backing pixel
|
||||||
size via `renderPixelSize` and set `F.reshapePixelSize` /
|
size via `renderPixelSize` and set `F.reshapePixelSize` /
|
||||||
`F.backingPixelSize`. The `pixelSize` shoulds fold these into `F.pixelSize`,
|
`F.backingPixelSize`. The `pixelSize` shoulds fold these into `F.pixelSize`,
|
||||||
whose oneliner stores `RenderVM.pixelSize`.
|
whose oneliner stores `RenderVM.pixelSize`.
|
||||||
4. The timer only sets `needsDisplay` every `1 / RENDER_FPS`. `draw(_:)` forwards
|
4. The timer only sets `needsDisplay` every `1 / RENDER_FPS`. `draw(_:)` forwards
|
||||||
to `renderDraw` (make context current, `sr_resize`, `sr_set_rotation`,
|
to `renderDraw` (make context current, `raybri_resize`, `raybri_set_rotation`,
|
||||||
`sr_render`, `flushBuffer`).
|
`raybri_render`, `flushBuffer`).
|
||||||
5. A button click runs `rootSet(F.didClickIncrement)` -> RootComponent oneliner
|
5. A button click runs `rootSet(F.didClickIncrement)` -> RootComponent oneliner
|
||||||
`renderSet(F.didClickIncrement)` -> `renderLoadCubeModel` (the cube is loaded
|
`renderSet(F.didClickIncrement)` -> `renderLoadCubeModel` (the cube is loaded
|
||||||
on demand, not at startup).
|
on demand, not at startup).
|
||||||
6. `RenderGLView.deinit` sets `F.willDeinit` -> `renderDeinit` (stop timer,
|
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.
|
**GL context rule**: every raylib call must run with the view's context current.
|
||||||
`renderInit`, `renderLoadCubeModel`, `renderDeinit` and `renderDraw` all call
|
`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`,
|
(`RootComponent.singleton`, `RootVM.shared`, `RenderComponent.singleton`,
|
||||||
`RenderVM.shared`) and are accessed from the generated oneliners with
|
`RenderVM.shared`) and are accessed from the generated oneliners with
|
||||||
force-unwrap (`RootVM.shared!.countText = ...`, `RenderVM.shared!.pixelSize = ...`).
|
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).
|
(see the GL context rule above).
|
||||||
|
|
||||||
## Skill: source-file study documents
|
## Skill: source-file study documents
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ static int sr_width = 1;
|
|||||||
static int sr_height = 1;
|
static int sr_height = 1;
|
||||||
|
|
||||||
// Render configuration supplied by the application (see renderConst.swift).
|
// 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).
|
// Cube transform (driven by the application, Euler degrees).
|
||||||
static float sr_rot_x = 0.0f;
|
static float sr_rot_x = 0.0f;
|
||||||
@@ -178,12 +178,12 @@ static void sr_config_shaders(void)
|
|||||||
rlDisableShader();
|
rlDisableShader();
|
||||||
}
|
}
|
||||||
|
|
||||||
void sr_init(
|
void raybri_init(
|
||||||
const char *main_vs,
|
const char *main_vs,
|
||||||
const char *main_fs,
|
const char *main_fs,
|
||||||
const char *shadow_vs,
|
const char *shadow_vs,
|
||||||
const char *shadow_fs,
|
const char *shadow_fs,
|
||||||
sr_config config
|
raybri_config config
|
||||||
) {
|
) {
|
||||||
sr_cfg = config;
|
sr_cfg = config;
|
||||||
|
|
||||||
@@ -201,7 +201,7 @@ void sr_init(
|
|||||||
sr_ready = 1;
|
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;
|
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 (width > 0) sr_width = width;
|
||||||
if (height > 0) sr_height = height;
|
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_x = x_deg;
|
||||||
sr_rot_y = y_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);
|
DrawMesh(model.meshes[0], material, model_mat);
|
||||||
}
|
}
|
||||||
|
|
||||||
void sr_render(void)
|
void raybri_render(void)
|
||||||
{
|
{
|
||||||
if (!sr_ready) return;
|
if (!sr_ready) return;
|
||||||
|
|
||||||
@@ -411,7 +411,7 @@ void sr_render(void)
|
|||||||
sr_render_main_pass();
|
sr_render_main_pass();
|
||||||
}
|
}
|
||||||
|
|
||||||
void sr_shutdown(void)
|
void raybri_shutdown(void)
|
||||||
{
|
{
|
||||||
if (!sr_ready) return;
|
if (!sr_ready) return;
|
||||||
|
|
||||||
|
|||||||
@@ -6,38 +6,38 @@ extern "C" {
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Render configuration, sourced from renderConst.swift.
|
// Render configuration, sourced from renderConst.swift.
|
||||||
typedef struct sr_config {
|
typedef struct raybri_config {
|
||||||
float fov_y; // vertical field of view (degrees)
|
float fov_y; // vertical field of view (degrees)
|
||||||
float near_plane; // camera near plane
|
float near_plane; // camera near plane
|
||||||
float far_plane; // camera far plane
|
float far_plane; // camera far plane
|
||||||
int shadow_size; // shadow map resolution (px)
|
int shadow_size; // shadow map resolution (px)
|
||||||
float ground_size; // ground plane extent
|
float ground_size; // ground plane extent
|
||||||
} sr_config;
|
} raybri_config;
|
||||||
|
|
||||||
// Initialise the OpenGL-backed raylib scene (no raylib window is created).
|
// Initialise the OpenGL-backed raylib scene (no raylib window is created).
|
||||||
// The four shader sources come from renderConstShader.swift.
|
// The four shader sources come from renderConstShader.swift.
|
||||||
void sr_init(
|
void raybri_init(
|
||||||
const char *main_vs,
|
const char *main_vs,
|
||||||
const char *main_fs,
|
const char *main_fs,
|
||||||
const char *shadow_vs,
|
const char *shadow_vs,
|
||||||
const char *shadow_fs,
|
const char *shadow_fs,
|
||||||
sr_config config
|
raybri_config config
|
||||||
);
|
);
|
||||||
|
|
||||||
// Load the textured cube glTF model.
|
// 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.
|
// 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).
|
// 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.
|
// Render one frame.
|
||||||
void sr_render(void);
|
void raybri_render(void);
|
||||||
|
|
||||||
// Release all GPU resources.
|
// Release all GPU resources.
|
||||||
void sr_shutdown(void);
|
void raybri_shutdown(void);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,10 +4,10 @@ import RaylibBridge
|
|||||||
func renderDraw(_ vm: RenderVM) {
|
func renderDraw(_ vm: RenderVM) {
|
||||||
vm.glView.openGLContext?.makeCurrentContext()
|
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)
|
let t = Float(CACurrentMediaTime() - vm.startTime)
|
||||||
sr_set_rotation(t * 6.0, t * 18.0, 0.0)
|
raybri_set_rotation(t * 6.0, t * 18.0, 0.0)
|
||||||
sr_render()
|
raybri_render()
|
||||||
|
|
||||||
vm.glView.openGLContext?.flushBuffer()
|
vm.glView.openGLContext?.flushBuffer()
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import AppKit
|
import AppKit
|
||||||
import RaylibBridge
|
import RaylibBridge
|
||||||
|
|
||||||
let RENDER_CONFIG = sr_config(
|
let RENDER_CONFIG = raybri_config(
|
||||||
fov_y: 45.0,
|
fov_y: 45.0,
|
||||||
near_plane: 0.1,
|
near_plane: 0.1,
|
||||||
far_plane: 1000.0,
|
far_plane: 1000.0,
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ func renderDeinit(_ vm: RenderVM) {
|
|||||||
print("ИГР renderD")
|
print("ИГР renderD")
|
||||||
vm.timer?.invalidate()
|
vm.timer?.invalidate()
|
||||||
vm.glView.openGLContext?.makeCurrentContext()
|
vm.glView.openGLContext?.makeCurrentContext()
|
||||||
sr_shutdown()
|
raybri_shutdown()
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderInit(_ vm: RenderVM) {
|
func renderInit(_ vm: RenderVM) {
|
||||||
@@ -17,7 +17,7 @@ func renderInit(_ vm: RenderVM) {
|
|||||||
vm.glView.openGLContext?.setValues(&swapInterval, for: .swapInterval)
|
vm.glView.openGLContext?.setValues(&swapInterval, for: .swapInterval)
|
||||||
|
|
||||||
// Init Raylib
|
// Init Raylib
|
||||||
sr_init(
|
raybri_init(
|
||||||
RENDER_SHADER_MAIN_VS,
|
RENDER_SHADER_MAIN_VS,
|
||||||
RENDER_SHADER_MAIN_FS,
|
RENDER_SHADER_MAIN_FS,
|
||||||
RENDER_SHADER_SHADOW_VS,
|
RENDER_SHADER_SHADOW_VS,
|
||||||
@@ -29,7 +29,7 @@ func renderInit(_ vm: RenderVM) {
|
|||||||
func renderLoadCubeModel(_ vm: RenderVM) {
|
func renderLoadCubeModel(_ vm: RenderVM) {
|
||||||
let path = Bundle.main.resourceURL!.path + RENDER_MODEL_CUBE
|
let path = Bundle.main.resourceURL!.path + RENDER_MODEL_CUBE
|
||||||
vm.glView.openGLContext?.makeCurrentContext()
|
vm.glView.openGLContext?.makeCurrentContext()
|
||||||
sr_load_model(path)
|
raybri_load_model(path)
|
||||||
}
|
}
|
||||||
|
|
||||||
func renderStartTimer(_ vm: RenderVM) {
|
func renderStartTimer(_ vm: RenderVM) {
|
||||||
|
|||||||
Reference in new issue
Block a user