diff --git a/README.md b/README.md index e528e84..6db0e2d 100644 --- a/README.md +++ b/README.md @@ -3,3 +3,7 @@ * macOS `brew install raylib` + +* iOS + + `brew install xcodegen` diff --git a/components/blue/blue.swift b/components/blue/blue.swift new file mode 100644 index 0000000..1b68227 --- /dev/null +++ b/components/blue/blue.swift @@ -0,0 +1,14 @@ +class BlueComponent { + let ctrl = DialectController(BlueContext()) + static private(set) weak var singleton: BlueComponent? + + init() { + Self.singleton = self + //blueRegisterEffects(ctrl) + blueRegisterShoulds(ctrl) + } + + func setup() { + blueSet(F.didSetup, true) + } +} diff --git a/components/blue/blueVM.swift b/components/blue/blueVM.swift new file mode 100644 index 0000000..a145dbf --- /dev/null +++ b/components/blue/blueVM.swift @@ -0,0 +1,9 @@ +import Combine + +final class BlueVM: ObservableObject { + static private(set) weak var shared: BlueVM? + + init() { + Self.shared = self + } +} diff --git a/components/blue/ios/view/BlueView.swift b/components/blue/ios/view/BlueView.swift new file mode 120000 index 0000000..47a140d --- /dev/null +++ b/components/blue/ios/view/BlueView.swift @@ -0,0 +1 @@ +../../mac/view/BlueView.swift \ No newline at end of file diff --git a/components/blue/mac/view/BlueView.swift b/components/blue/mac/view/BlueView.swift new file mode 100644 index 0000000..e2360f4 --- /dev/null +++ b/components/blue/mac/view/BlueView.swift @@ -0,0 +1,24 @@ +import SwiftUI + +struct BlueView: View { + @ObservedObject var vm: BlueVM + + init(_ vm: BlueVM) { + self.vm = vm + } + + var body: some View { + VStack(spacing: 16) { + ZStack { + Text("Blue") + .font(.largeTitle) + .foregroundStyle(.white) + .offset(x: 1, y: 1) + Text("Blue") + .font(.largeTitle) + .foregroundStyle(.black) + } + } + .padding(40) + } +} diff --git a/components/chkgfx/ios/view/ChkgfxView.swift b/components/chkgfx/ios/view/ChkgfxView.swift new file mode 120000 index 0000000..3a1e13d --- /dev/null +++ b/components/chkgfx/ios/view/ChkgfxView.swift @@ -0,0 +1 @@ +../../mac/view/ChkgfxView.swift \ No newline at end of file diff --git a/components/raybri/raybri.c b/components/raybri/raybri.c index 1151cd8..6593117 100644 --- a/components/raybri/raybri.c +++ b/components/raybri/raybri.c @@ -1,440 +1,29 @@ #include "raybri.h" - -#include "raylib.h" +#include "raybriAux.h" #include "rlgl.h" -#include "raymath.h" -#include -#include -#include -#include -#include +void raybriInit(void) { + //SetTraceLogLevel(LOG_WARNING); -static int sr_width = 1; -static int sr_height = 1; - -// Render configuration supplied by the application (see renderConst.swift). -static raybri_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; -static float sr_rot_z = 0.0f; - -static int sr_ready = 0; - -static Model sr_model = { 0 }; -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 }; -static Material sr_ground_shadow_material = { 0 }; - -static Shader sr_main_shader = { 0 }; -static Shader sr_shadow_shader = { 0 }; - -static int sr_shadow_fbo = 0; -static unsigned int sr_shadow_color = 0; -static unsigned int sr_shadow_depth = 0; - -static Matrix sr_light_view = { 0 }; -static Matrix sr_light_proj = { 0 }; -static Vector3 sr_light_pos = { 0.0f, 0.0f, 0.0f }; - -// Main shader uniform locations -static int loc_light_pos = -1; -static int loc_light_color = -1; -static int loc_ambient = -1; -static int loc_light_enabled = -1; -static int loc_emissive = -1; -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; -static int loc_camera_pos = -1; -static int loc_fog_color = -1; -static int loc_fog_start = -1; -static int loc_fog_end = -1; - -// raylib is built as a static/dynamic library with GLFW baked in, but we never -// call InitWindow(). Instead we render into an OpenGL context owned by the -// macOS app, so we must supply the OpenGL entry point loader ourselves. -static void *sr_gl_loader(const char *name) -{ - static void *handle = NULL; - if (handle == NULL) - { - handle = dlopen("/System/Library/Frameworks/OpenGL.framework/OpenGL", RTLD_LAZY | RTLD_LOCAL); - } - if (handle == NULL) return NULL; - return dlsym(handle, name); -} - -// Compose a model transform exactly like raylib's DrawModel() does, so the -// matrices we feed to DrawMesh() match what rlgl computes internally. -static Matrix sr_transform(Vector3 pos, float scale, float rx, float ry, float rz) -{ - Matrix mat_scale = MatrixScale(scale, scale, scale); - Matrix mat_rotation = MatrixRotateXYZ((Vector3){ rx * DEG2RAD, ry * DEG2RAD, rz * DEG2RAD }); - Matrix mat_translation = MatrixTranslate(pos.x, pos.y, pos.z); - return MatrixMultiply(MatrixMultiply(mat_scale, mat_rotation), mat_translation); -} - -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, 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"); - loc_ambient = GetShaderLocation(sr_main_shader, "u_ambient"); - loc_light_enabled = GetShaderLocation(sr_main_shader, "u_lightEnabled"); - loc_emissive = GetShaderLocation(sr_main_shader, "u_emissive"); - loc_albedo_color = GetShaderLocation(sr_main_shader, "u_albedoColor"); - 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"); - loc_camera_pos = GetShaderLocation(sr_main_shader, "u_cameraPos"); - loc_fog_color = GetShaderLocation(sr_main_shader, "u_fogColor"); - loc_fog_start = GetShaderLocation(sr_main_shader, "u_fogStart"); - loc_fog_end = GetShaderLocation(sr_main_shader, "u_fogEnd"); - - // 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_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); - rlFramebufferAttach(sr_shadow_fbo, sr_shadow_depth, RL_ATTACHMENT_DEPTH, RL_ATTACHMENT_TEXTURE2D, 0); - int shadow_ok = rlFramebufferComplete(sr_shadow_fbo); - fprintf(stderr, "SR: shadow framebuffer %s\n", shadow_ok ? "complete" : "INCOMPLETE"); - rlDisableFramebuffer(); -} - -static void sr_build_ground(void) -{ - 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; - sr_ground_shadow_material = LoadMaterialDefault(); - 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_config_shaders(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 raybri_init( - const char *main_vs, - const char *main_fs, - const char *shadow_vs, - const char *shadow_fs, - raybri_config config -) { - sr_cfg = config; - - // raylib's default INFO logging is noisy; keep warnings and errors only. - SetTraceLogLevel(LOG_WARNING); - - rlLoadExtensions((void *)sr_gl_loader); - // Init with default 1x1 size + // Load OpenGL extensions + rlLoadExtensions((void *)raybriGLLoader); + // Initialize raylib graphics layer with a placeholder 1x1 framebuffer size + // Graphics layer includes default texture, shader, render batch and OpenGL state rlglInit(1, 1); - - sr_load_shaders(main_vs, main_fs, shadow_vs, shadow_fs); - sr_config_shaders(); - sr_build_ground(); - - sr_ready = 1; + // Background is painted in blue + rlClearColor(0, 0, 255, 255); } -void raybri_load_model(const char *gltf_path) -{ - if (!sr_ready || gltf_path == NULL) return; - - 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; - sr_cube_material = sr_model.materials[cube_mat_index]; - sr_cube_material.shader = sr_main_shader; - - Texture2D base_tex = sr_cube_material.maps[MATERIAL_MAP_DIFFUSE].texture; - 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; - } - else - { - fprintf(stderr, "SR: failed to load model: %s\n", gltf_path); - } -} - -void raybri_resize(int width, int height) -{ - if (width > 0) sr_width = width; - if (height > 0) sr_height = height; -} - -void raybri_set_rotation(float x_deg, float y_deg, float z_deg) -{ - sr_rot_x = x_deg; - sr_rot_y = y_deg; - sr_rot_z = z_deg; -} - -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); +void raybriRender(int width, int height) { + // Set the drawing area to the current pixel size + rlViewport(0, 0, width, height); + // Clear color and depth buffers for the next frame 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); - - 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. + // Draw any queued geometry 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); - rlSetFramebufferWidth(sr_cfg.shadow_size); - rlSetFramebufferHeight(sr_cfg.shadow_size); - - rlEnableFramebuffer(sr_shadow_fbo); - - rlClearColor(255, 255, 255, 255); - rlClearScreenBuffers(); - - rlEnableDepthTest(); - rlEnableBackfaceCulling(); - rlSetCullFace(RL_CULL_FACE_FRONT); - - rlMatrixMode(RL_PROJECTION); - rlPushMatrix(); - rlLoadIdentity(); - rlMultMatrixf(MatrixToFloat(sr_light_proj)); - - rlMatrixMode(RL_MODELVIEW); - rlLoadIdentity(); - rlMultMatrixf(MatrixToFloat(sr_light_view)); - - if (sr_has_model) - { - DrawMesh(sr_model.meshes[0], sr_cube_shadow_material, sr_cube_transform()); - } - - rlDrawRenderBatchActive(); - - rlMatrixMode(RL_PROJECTION); - rlPopMatrix(); - - rlSetCullFace(RL_CULL_FACE_BACK); - rlDisableFramebuffer(); - - rlViewport(0, 0, sr_width, sr_height); - rlSetFramebufferWidth(sr_width); - rlSetFramebufferHeight(sr_height); - rlDisableDepthTest(); -} - -static void sr_set_light_mvp(Matrix model) -{ - Matrix light_mvp = MatrixMultiply(MatrixMultiply(model, sr_light_view), sr_light_proj); - SetShaderValueMatrix(sr_main_shader, loc_light_mvp, light_mvp); -} - -static void sr_bind_normal(Texture2D tex) -{ - 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 normal_strength = (normal.id > 0) ? 1.0f : 0.0f; - 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); -} - -void raybri_render(void) -{ - if (!sr_ready) return; - - rlDrawRenderBatchActive(); - - // --- Light (point light above the scene) --- - 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); - sr_light_proj = MatrixPerspective(90.0 * DEG2RAD, 1.0, 1.5, 16.0); - - sr_render_shadow_pass(); - sr_render_main_pass(); -} - -void raybri_shutdown(void) -{ - if (!sr_ready) return; - - if (sr_has_model) - { - UnloadModel(sr_model); - sr_has_model = 0; - } - - 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); - if (sr_main_shader.id > 0) UnloadShader(sr_main_shader); - if (sr_shadow_shader.id > 0) UnloadShader(sr_shadow_shader); - +void raybriShutdown(void) { + // Release rlgl buffers, shaders and textures rlglClose(); - sr_ready = 0; } diff --git a/components/raybri/raybri.h b/components/raybri/raybri.h index 5493ad3..902f706 100644 --- a/components/raybri/raybri.h +++ b/components/raybri/raybri.h @@ -1,46 +1,8 @@ -#ifndef OGS_MAHJONG_RAYLIB_BRIDGE_H -#define OGS_MAHJONG_RAYLIB_BRIDGE_H +#ifndef RAYBRI_H +#define RAYBRI_H -#ifdef __cplusplus -extern "C" { -#endif +void raybriInit(void); +void raybriRender(int width, int height); +void raybriShutdown(void); -// Render configuration, sourced from renderConst.swift. -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 -} raybri_config; - -// Initialise the OpenGL-backed raylib scene (no raylib window is created). -// The four shader sources come from renderConstShader.swift. -void raybri_init( - const char *main_vs, - const char *main_fs, - const char *shadow_vs, - const char *shadow_fs, - raybri_config config -); - -// Load the textured cube glTF model. -void raybri_load_model(const char *gltf_path); - -// Resize the viewport. -void raybri_resize(int width, int height); - -// Cube rotation, driven by the application (Euler angles, degrees). -void raybri_set_rotation(float x_deg, float y_deg, float z_deg); - -// Render one frame. -void raybri_render(void); - -// Release all GPU resources. -void raybri_shutdown(void); - -#ifdef __cplusplus -} -#endif - -#endif +#endif // RAYBRI_H diff --git a/components/raybri/raybriAux.c b/components/raybri/raybriAux.c new file mode 100644 index 0000000..e78ec49 --- /dev/null +++ b/components/raybri/raybriAux.c @@ -0,0 +1,21 @@ +#include +#include "raybriAux.h" +#include "raybriConst.h" +#include + +// raylib is built as a static/dynamic library with GLFW baked in, but we never +// call InitWindow(). Instead we render into an OpenGL context owned by the +// macOS app, so we must supply the OpenGL entry point loader ourselves. +void *raybriGLLoader(const char *name) { + static void *handle = NULL; + + if (handle == NULL) { + handle = dlopen(RAYBRI_MAC_GL, RTLD_LAZY | RTLD_LOCAL); + } + + if (handle == NULL) { + return NULL; + } + + return dlsym(handle, name); +} diff --git a/components/raybri/raybriAux.h b/components/raybri/raybriAux.h new file mode 100644 index 0000000..3e12210 --- /dev/null +++ b/components/raybri/raybriAux.h @@ -0,0 +1,6 @@ +#ifndef RAYBRI_AUX_H +#define RAYBRI_AUX_H + +void *raybriGLLoader(const char *name); + +#endif // RAYBRI_AUX_H diff --git a/components/raybri/raybriConst.c b/components/raybri/raybriConst.c new file mode 100644 index 0000000..bc427dc --- /dev/null +++ b/components/raybri/raybriConst.c @@ -0,0 +1,3 @@ +#include "raybriConst.h" + +const char RAYBRI_MAC_GL[] = "/System/Library/Frameworks/OpenGL.framework/OpenGL"; diff --git a/components/raybri/raybriConst.h b/components/raybri/raybriConst.h new file mode 100644 index 0000000..cde42ee --- /dev/null +++ b/components/raybri/raybriConst.h @@ -0,0 +1,6 @@ +#ifndef RAYBRI_CONST_H +#define RAYBRI_CONST_H + +extern const char RAYBRI_MAC_GL[]; + +#endif // RAYBRI_CONST_H diff --git a/components/render/ios/view/RenderGLView.swift b/components/render/ios/view/RenderGLView.swift new file mode 100644 index 0000000..9580023 --- /dev/null +++ b/components/render/ios/view/RenderGLView.swift @@ -0,0 +1,11 @@ +import UIKit + +final class RenderGLView: UIView { + override init(frame: CGRect) { + super.init(frame: frame) + } + + required init?(coder: NSCoder) { + fatalError("init(coder:) has not been implemented") + } +} diff --git a/components/render/renderAux.swift b/components/render/renderAux.swift index e9feeb3..cd5d82a 100644 --- a/components/render/renderAux.swift +++ b/components/render/renderAux.swift @@ -3,12 +3,7 @@ import RaylibBridge func renderDraw(_ vm: RenderVM) { vm.glView.openGLContext?.makeCurrentContext() - - raybri_resize(vm.pixelSize[0], vm.pixelSize[1]) - let t = Float(CACurrentMediaTime() - vm.startTime) - raybri_set_rotation(t * 6.0, t * 18.0, 0.0) - raybri_render() - + raybriRender(vm.pixelSize[0], vm.pixelSize[1]) vm.glView.openGLContext?.flushBuffer() } diff --git a/components/render/renderConst.swift b/components/render/renderConst.swift index 787b0c5..1abea29 100644 --- a/components/render/renderConst.swift +++ b/components/render/renderConst.swift @@ -1,13 +1,4 @@ import AppKit -import RaylibBridge - -let RENDER_CONFIG = raybri_config( - fov_y: 45.0, - near_plane: 0.1, - far_plane: 1000.0, - shadow_size: 256, - ground_size: 40.0 -) let RENDER_FPS = 60.0 diff --git a/components/render/renderEffect.swift b/components/render/renderEffect.swift index 3ca661a..ad3d568 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() - raybri_shutdown() + raybriShutdown() } func renderInit(_ vm: RenderVM) { @@ -16,20 +16,7 @@ func renderInit(_ vm: RenderVM) { var swapInterval: Int32 = 1 vm.glView.openGLContext?.setValues(&swapInterval, for: .swapInterval) - // Init Raylib - raybri_init( - 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() - raybri_load_model(path) + raybriInit() } func renderStartTimer(_ vm: RenderVM) { diff --git a/ogs-blue/dialect.yml b/ogs-blue/dialect.yml new file mode 100644 index 0000000..8784c03 --- /dev/null +++ b/ogs-blue/dialect.yml @@ -0,0 +1,66 @@ +version: 4 + +output: + ver-mac/src/dialect.swift: + type: swift + +BlueComponent: + type: component + shoulds: + didLaunch: + 1. Only once during the first setup: + if: + c.recentField == F.didSetup && + c.didLaunch == false + then: + c.didLaunch = true + +BlueContext: + type: context + fields: + didLaunch: Bool + didSetup: Bool + +RenderContext: + type: context + fields: + backingPixelSize: [Int32] + didLaunch: Bool + didPrepareGL: Bool + didSetup: Bool + pixelSize: [Int32] + reshapePixelSize: [Int32] + willDeinit: Bool + +RenderComponent: + type: component + oneliners: + - 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 diff --git a/ogs-blue/ver-ios/Assets.xcassets/AppIcon.appiconset/AppIcon.png b/ogs-blue/ver-ios/Assets.xcassets/AppIcon.appiconset/AppIcon.png new file mode 100644 index 0000000..f2520ea Binary files /dev/null and b/ogs-blue/ver-ios/Assets.xcassets/AppIcon.appiconset/AppIcon.png differ diff --git a/ogs-blue/ver-ios/Assets.xcassets/AppIcon.appiconset/Contents.json b/ogs-blue/ver-ios/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..ca34fdb --- /dev/null +++ b/ogs-blue/ver-ios/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,14 @@ +{ + "images" : [ + { + "filename" : "AppIcon.png", + "idiom" : "universal", + "platform" : "ios", + "size" : "1024x1024" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} \ No newline at end of file diff --git a/ogs-blue/ver-ios/Info.plist b/ogs-blue/ver-ios/Info.plist new file mode 100644 index 0000000..7f91849 --- /dev/null +++ b/ogs-blue/ver-ios/Info.plist @@ -0,0 +1,26 @@ + + + + + CFBundleName + OGS blue + CFBundleDisplayName + OGS blue + CFBundleIdentifier + org.opengamestudio.blue + CFBundleExecutable + ogs-blue + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + UILaunchScreen + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + + + diff --git a/ogs-blue/ver-ios/project.yml b/ogs-blue/ver-ios/project.yml new file mode 100644 index 0000000..da9deba --- /dev/null +++ b/ogs-blue/ver-ios/project.yml @@ -0,0 +1,15 @@ +name: OGS blue +options: + bundleIdPrefix: org.opengamestudio +targets: + ogs-blue: + type: application + platform: iOS + deploymentTarget: "15.0" + sources: + - path: Assets.xcassets + - path: src + settings: + base: + PRODUCT_BUNDLE_IDENTIFIER: org.opengamestudio.blue + INFOPLIST_FILE: Info.plist diff --git a/ogs-blue/ver-ios/src/AppDelegate.swift b/ogs-blue/ver-ios/src/AppDelegate.swift new file mode 100644 index 0000000..28fa61b --- /dev/null +++ b/ogs-blue/ver-ios/src/AppDelegate.swift @@ -0,0 +1,19 @@ +import UIKit + +final class AppDelegate: + NSObject, + UIApplicationDelegate +{ + let blue = BlueComponent() + let blueVM = BlueVM() + + func application( + _ application: UIApplication, + didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil + ) -> Bool { + otherSetupConsoleLogging(blue.ctrl, "Blue") + blue.setup() + + return true + } +} diff --git a/ogs-blue/ver-ios/src/BlueApp.swift b/ogs-blue/ver-ios/src/BlueApp.swift new file mode 100644 index 0000000..85682a4 --- /dev/null +++ b/ogs-blue/ver-ios/src/BlueApp.swift @@ -0,0 +1,12 @@ +import SwiftUI + +@main +struct BlueApp: App { + @UIApplicationDelegateAdaptor(AppDelegate.self) private var appDelegate + + var body: some Scene { + WindowGroup { + BlueView(appDelegate.blueVM) + } + } +} diff --git a/ogs-blue/ver-ios/src/blue/blue.swift b/ogs-blue/ver-ios/src/blue/blue.swift new file mode 120000 index 0000000..e4a3541 --- /dev/null +++ b/ogs-blue/ver-ios/src/blue/blue.swift @@ -0,0 +1 @@ +../../../../components/blue/blue.swift \ No newline at end of file diff --git a/ogs-blue/ver-ios/src/blue/blueVM.swift b/ogs-blue/ver-ios/src/blue/blueVM.swift new file mode 120000 index 0000000..60b84cd --- /dev/null +++ b/ogs-blue/ver-ios/src/blue/blueVM.swift @@ -0,0 +1 @@ +../../../../components/blue/blueVM.swift \ No newline at end of file diff --git a/ogs-blue/ver-ios/src/blue/view/BlueView.swift b/ogs-blue/ver-ios/src/blue/view/BlueView.swift new file mode 120000 index 0000000..2ab807f --- /dev/null +++ b/ogs-blue/ver-ios/src/blue/view/BlueView.swift @@ -0,0 +1 @@ +../../../../../components/blue/ios/view/BlueView.swift \ No newline at end of file diff --git a/ogs-blue/ver-ios/src/dialect.swift b/ogs-blue/ver-ios/src/dialect.swift new file mode 120000 index 0000000..a931c95 --- /dev/null +++ b/ogs-blue/ver-ios/src/dialect.swift @@ -0,0 +1 @@ +../../ver-mac/src/dialect.swift \ No newline at end of file diff --git a/ogs-blue/ver-ios/src/other/other.swift b/ogs-blue/ver-ios/src/other/other.swift new file mode 120000 index 0000000..f91488c --- /dev/null +++ b/ogs-blue/ver-ios/src/other/other.swift @@ -0,0 +1 @@ +../../../../components/other/other.swift \ No newline at end of file diff --git a/ogs-blue/ver-ios/src/render/render.swift b/ogs-blue/ver-ios/src/render/render.swift new file mode 120000 index 0000000..5e4b117 --- /dev/null +++ b/ogs-blue/ver-ios/src/render/render.swift @@ -0,0 +1 @@ +../../../../components/render/render.swift \ No newline at end of file diff --git a/ogs-blue/ver-ios/src/render/renderTMPIOS.swift b/ogs-blue/ver-ios/src/render/renderTMPIOS.swift new file mode 100644 index 0000000..da0a587 --- /dev/null +++ b/ogs-blue/ver-ios/src/render/renderTMPIOS.swift @@ -0,0 +1,4 @@ +func renderDeinit(_ vm: RenderVM) { } +func renderInit(_ vm: RenderVM) { } +func renderLoadCubeModel(_ vm: RenderVM) { } +func renderStartTimer(_ vm: RenderVM) { } diff --git a/ogs-blue/ver-ios/src/render/renderVM.swift b/ogs-blue/ver-ios/src/render/renderVM.swift new file mode 120000 index 0000000..dde0ace --- /dev/null +++ b/ogs-blue/ver-ios/src/render/renderVM.swift @@ -0,0 +1 @@ +../../../../components/render/renderVM.swift \ No newline at end of file diff --git a/ogs-blue/ver-ios/src/render/view/RenderGLView.swift b/ogs-blue/ver-ios/src/render/view/RenderGLView.swift new file mode 120000 index 0000000..799f582 --- /dev/null +++ b/ogs-blue/ver-ios/src/render/view/RenderGLView.swift @@ -0,0 +1 @@ +../../../../../components/render/ios/view/RenderGLView.swift \ No newline at end of file diff --git a/ogs-blue/ver-mac/Info.plist b/ogs-blue/ver-mac/Info.plist new file mode 100644 index 0000000..ef6abed --- /dev/null +++ b/ogs-blue/ver-mac/Info.plist @@ -0,0 +1,26 @@ + + + + + CFBundleName + OGS blue + CFBundleDisplayName + OGS blue + CFBundleIdentifier + org.opengamestudio.blue + CFBundleExecutable + ogs-blue + CFBundleIconFile + AppIcon + CFBundlePackageType + APPL + CFBundleShortVersionString + 2.0.0 + CFBundleVersion + 1 + LSMinimumSystemVersion + 11.0 + NSHighResolutionCapable + + + diff --git a/ogs-blue/ver-mac/Package.swift b/ogs-blue/ver-mac/Package.swift new file mode 100644 index 0000000..8ea77e5 --- /dev/null +++ b/ogs-blue/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: "OGSBlue", + platforms: [ + .macOS(.v13) + ], + targets: [ + .target( + name: "RaylibBridge", + path: "src/raybri", + publicHeadersPath: ".", + cSettings: [ + .unsafeFlags(["-I", "\(raylibPrefix)/include"]) + ] + ), + .executableTarget( + name: "ogs-blue", + dependencies: ["RaylibBridge"], + path: "src", + exclude: ["raybri"], + swiftSettings: [ + .unsafeFlags(["-Xcc", "-DGL_SILENCE_DEPRECATION"]) + ], + linkerSettings: [ + .unsafeFlags([ + "-L", "\(raylibPrefix)/lib", + "-lraylib" + ]) + ] + ) + ] +) diff --git a/ogs-blue/ver-mac/res/AppIcon.icns b/ogs-blue/ver-mac/res/AppIcon.icns new file mode 120000 index 0000000..7e98160 --- /dev/null +++ b/ogs-blue/ver-mac/res/AppIcon.icns @@ -0,0 +1 @@ +../../../res/AppIcon.icns \ No newline at end of file diff --git a/ogs-blue/ver-mac/res/cube b/ogs-blue/ver-mac/res/cube new file mode 120000 index 0000000..24cd8a9 --- /dev/null +++ b/ogs-blue/ver-mac/res/cube @@ -0,0 +1 @@ +../../../res/cube \ No newline at end of file diff --git a/ogs-blue/ver-mac/src/AppDelegate.swift b/ogs-blue/ver-mac/src/AppDelegate.swift new file mode 100644 index 0000000..4138293 --- /dev/null +++ b/ogs-blue/ver-mac/src/AppDelegate.swift @@ -0,0 +1,26 @@ +import AppKit + +final class AppDelegate: + NSObject, + NSApplicationDelegate +{ + let blue = BlueComponent() + let blueVM = BlueVM() + let render = RenderComponent() + let renderVM = RenderVM() + + func applicationDidFinishLaunching(_ notification: Notification) { + // Bring the app to the foreground + NSApp.setActivationPolicy(.regular) + NSApp.activate(ignoringOtherApps: true) + + otherSetupConsoleLogging(blue.ctrl, "Blue") + blue.setup() + otherSetupConsoleLogging(render.ctrl, "Render") + render.setup() + } + + func applicationShouldTerminateAfterLastWindowClosed(_ sender: NSApplication) -> Bool { + true + } +} diff --git a/ogs-blue/ver-mac/src/BlueApp.swift b/ogs-blue/ver-mac/src/BlueApp.swift new file mode 100644 index 0000000..67a6d88 --- /dev/null +++ b/ogs-blue/ver-mac/src/BlueApp.swift @@ -0,0 +1,17 @@ +import SwiftUI + +@main +struct BlueApp: App { + @NSApplicationDelegateAdaptor(AppDelegate.self) private var appDelegate + + var body: some Scene { + WindowGroup { + ZStack { + RenderView() + .ignoresSafeArea() + BlueView(appDelegate.blueVM) + } + } + .defaultSize(width: 640, height: 480) + } +} diff --git a/ogs-blue/ver-mac/src/blue/blue.swift b/ogs-blue/ver-mac/src/blue/blue.swift new file mode 120000 index 0000000..e4a3541 --- /dev/null +++ b/ogs-blue/ver-mac/src/blue/blue.swift @@ -0,0 +1 @@ +../../../../components/blue/blue.swift \ No newline at end of file diff --git a/ogs-blue/ver-mac/src/blue/blueVM.swift b/ogs-blue/ver-mac/src/blue/blueVM.swift new file mode 120000 index 0000000..60b84cd --- /dev/null +++ b/ogs-blue/ver-mac/src/blue/blueVM.swift @@ -0,0 +1 @@ +../../../../components/blue/blueVM.swift \ No newline at end of file diff --git a/ogs-blue/ver-mac/src/blue/view/BlueView.swift b/ogs-blue/ver-mac/src/blue/view/BlueView.swift new file mode 120000 index 0000000..de3df9a --- /dev/null +++ b/ogs-blue/ver-mac/src/blue/view/BlueView.swift @@ -0,0 +1 @@ +../../../../../components/blue/mac/view/BlueView.swift \ No newline at end of file diff --git a/ogs-blue/ver-mac/src/dialect.swift b/ogs-blue/ver-mac/src/dialect.swift new file mode 100644 index 0000000..19cbef9 --- /dev/null +++ b/ogs-blue/ver-mac/src/dialect.swift @@ -0,0 +1,341 @@ + +// 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 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 BlueContext: DialectContext { + public var didLaunch = Bool() + public var didSetup = Bool() + + public var recentField = "" + + public func field(_ name: String) -> T { + 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 == "didLaunch") { + didLaunch = value as! Bool + } + else if (name == "didSetup") { + didSetup = value as! Bool + } + + } +} + +public struct RenderContext: DialectContext { + public var backingPixelSize = [Int32]() + 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 == "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 == "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 blueSet( + _ key: String, + _ value: Any +) { + BlueComponent.singleton!.ctrl.set(key, value) +} + +public func renderSet( + _ key: String, + _ value: Any +) { + RenderComponent.singleton!.ctrl.set(key, value) +} + +func blueShouldResetDidLaunch(_ c: BlueContext) -> BlueContext { + 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 blueRegisterShoulds(_ ctrl: DialectController) { + [ + blueShouldResetDidLaunch, + + ].forEach { f in + ctrl.registerFunction { c in f(c as! BlueContext) } + } +} + +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.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!) }, + + ]) +} diff --git a/ogs-blue/ver-mac/src/other/other.swift b/ogs-blue/ver-mac/src/other/other.swift new file mode 120000 index 0000000..f91488c --- /dev/null +++ b/ogs-blue/ver-mac/src/other/other.swift @@ -0,0 +1 @@ +../../../../components/other/other.swift \ No newline at end of file diff --git a/ogs-blue/ver-mac/src/raybri/raybri.c b/ogs-blue/ver-mac/src/raybri/raybri.c new file mode 120000 index 0000000..52b1940 --- /dev/null +++ b/ogs-blue/ver-mac/src/raybri/raybri.c @@ -0,0 +1 @@ +../../../../components/raybri/raybri.c \ No newline at end of file diff --git a/ogs-blue/ver-mac/src/raybri/raybri.h b/ogs-blue/ver-mac/src/raybri/raybri.h new file mode 120000 index 0000000..daec20f --- /dev/null +++ b/ogs-blue/ver-mac/src/raybri/raybri.h @@ -0,0 +1 @@ +../../../../components/raybri/raybri.h \ No newline at end of file diff --git a/ogs-blue/ver-mac/src/raybri/raybriAux.c b/ogs-blue/ver-mac/src/raybri/raybriAux.c new file mode 120000 index 0000000..377245e --- /dev/null +++ b/ogs-blue/ver-mac/src/raybri/raybriAux.c @@ -0,0 +1 @@ +../../../../components/raybri/raybriAux.c \ No newline at end of file diff --git a/ogs-blue/ver-mac/src/raybri/raybriAux.h b/ogs-blue/ver-mac/src/raybri/raybriAux.h new file mode 120000 index 0000000..1033d69 --- /dev/null +++ b/ogs-blue/ver-mac/src/raybri/raybriAux.h @@ -0,0 +1 @@ +../../../../components/raybri/raybriAux.h \ No newline at end of file diff --git a/ogs-blue/ver-mac/src/raybri/raybriConst.c b/ogs-blue/ver-mac/src/raybri/raybriConst.c new file mode 120000 index 0000000..fe840ed --- /dev/null +++ b/ogs-blue/ver-mac/src/raybri/raybriConst.c @@ -0,0 +1 @@ +../../../../components/raybri/raybriConst.c \ No newline at end of file diff --git a/ogs-blue/ver-mac/src/raybri/raybriConst.h b/ogs-blue/ver-mac/src/raybri/raybriConst.h new file mode 120000 index 0000000..7e1b994 --- /dev/null +++ b/ogs-blue/ver-mac/src/raybri/raybriConst.h @@ -0,0 +1 @@ +../../../../components/raybri/raybriConst.h \ No newline at end of file diff --git a/ogs-blue/ver-mac/src/render/render.swift b/ogs-blue/ver-mac/src/render/render.swift new file mode 120000 index 0000000..5e4b117 --- /dev/null +++ b/ogs-blue/ver-mac/src/render/render.swift @@ -0,0 +1 @@ +../../../../components/render/render.swift \ No newline at end of file diff --git a/ogs-blue/ver-mac/src/render/renderAux.swift b/ogs-blue/ver-mac/src/render/renderAux.swift new file mode 120000 index 0000000..1975b82 --- /dev/null +++ b/ogs-blue/ver-mac/src/render/renderAux.swift @@ -0,0 +1 @@ +../../../../components/render/renderAux.swift \ No newline at end of file diff --git a/ogs-blue/ver-mac/src/render/renderConst.swift b/ogs-blue/ver-mac/src/render/renderConst.swift new file mode 120000 index 0000000..d953714 --- /dev/null +++ b/ogs-blue/ver-mac/src/render/renderConst.swift @@ -0,0 +1 @@ +../../../../components/render/renderConst.swift \ No newline at end of file diff --git a/ogs-blue/ver-mac/src/render/renderConstShader.swift b/ogs-blue/ver-mac/src/render/renderConstShader.swift new file mode 120000 index 0000000..2dcc2d4 --- /dev/null +++ b/ogs-blue/ver-mac/src/render/renderConstShader.swift @@ -0,0 +1 @@ +../../../../components/render/renderConstShader.swift \ No newline at end of file diff --git a/ogs-blue/ver-mac/src/render/renderEffect.swift b/ogs-blue/ver-mac/src/render/renderEffect.swift new file mode 120000 index 0000000..d269bb5 --- /dev/null +++ b/ogs-blue/ver-mac/src/render/renderEffect.swift @@ -0,0 +1 @@ +../../../../components/render/renderEffect.swift \ No newline at end of file diff --git a/ogs-blue/ver-mac/src/render/renderVM.swift b/ogs-blue/ver-mac/src/render/renderVM.swift new file mode 120000 index 0000000..dde0ace --- /dev/null +++ b/ogs-blue/ver-mac/src/render/renderVM.swift @@ -0,0 +1 @@ +../../../../components/render/renderVM.swift \ No newline at end of file diff --git a/ogs-blue/ver-mac/src/render/view/RenderGLView.swift b/ogs-blue/ver-mac/src/render/view/RenderGLView.swift new file mode 120000 index 0000000..7223ae3 --- /dev/null +++ b/ogs-blue/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/ogs-blue/ver-mac/src/render/view/RenderView.swift b/ogs-blue/ver-mac/src/render/view/RenderView.swift new file mode 120000 index 0000000..754ef01 --- /dev/null +++ b/ogs-blue/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/ogs-chkgfx/ver-ios/Assets.xcassets/AppIcon.appiconset/AppIcon.png b/ogs-chkgfx/ver-ios/Assets.xcassets/AppIcon.appiconset/AppIcon.png new file mode 100644 index 0000000..f2520ea Binary files /dev/null and b/ogs-chkgfx/ver-ios/Assets.xcassets/AppIcon.appiconset/AppIcon.png differ diff --git a/ogs-chkgfx/ver-ios/Assets.xcassets/AppIcon.appiconset/Contents.json b/ogs-chkgfx/ver-ios/Assets.xcassets/AppIcon.appiconset/Contents.json new file mode 100644 index 0000000..ca34fdb --- /dev/null +++ b/ogs-chkgfx/ver-ios/Assets.xcassets/AppIcon.appiconset/Contents.json @@ -0,0 +1,14 @@ +{ + "images" : [ + { + "filename" : "AppIcon.png", + "idiom" : "universal", + "platform" : "ios", + "size" : "1024x1024" + } + ], + "info" : { + "author" : "xcode", + "version" : 1 + } +} \ No newline at end of file diff --git a/ogs-chkgfx/ver-ios/Info.plist b/ogs-chkgfx/ver-ios/Info.plist new file mode 100644 index 0000000..1b3f948 --- /dev/null +++ b/ogs-chkgfx/ver-ios/Info.plist @@ -0,0 +1,26 @@ + + + + + CFBundleName + OGS chkgfx + CFBundleDisplayName + OGS chkgfx + CFBundleIdentifier + org.opengamestudio.chkgfx + CFBundleExecutable + ogs-chkgfx + CFBundlePackageType + APPL + CFBundleShortVersionString + 1.0 + CFBundleVersion + 1 + UILaunchScreen + + UISupportedInterfaceOrientations + + UIInterfaceOrientationPortrait + + + diff --git a/ogs-chkgfx/ver-ios/project.yml b/ogs-chkgfx/ver-ios/project.yml new file mode 100644 index 0000000..bddd15f --- /dev/null +++ b/ogs-chkgfx/ver-ios/project.yml @@ -0,0 +1,14 @@ +name: OGS chkgfx +options: + bundleIdPrefix: org.opengamestudio +targets: + ogs-chkgfx: + type: application + platform: iOS + deploymentTarget: "15.0" + sources: + - path: Assets.xcassets + - path: src + settings: + base: + INFOPLIST_FILE: Info.plist diff --git a/ogs-chkgfx/ver-ios/src/AppDelegate.swift b/ogs-chkgfx/ver-ios/src/AppDelegate.swift new file mode 100644 index 0000000..5f14539 --- /dev/null +++ b/ogs-chkgfx/ver-ios/src/AppDelegate.swift @@ -0,0 +1,19 @@ +import UIKit + +final class AppDelegate: + NSObject, + UIApplicationDelegate +{ + let chkgfx = ChkgfxComponent() + let chkgfxVM = ChkgfxVM() + + func application( + _ application: UIApplication, + didFinishLaunchingWithOptions launchOptions: [UIApplication.LaunchOptionsKey: Any]? = nil + ) -> Bool { + otherSetupConsoleLogging(chkgfx.ctrl, "Chkgfx") + chkgfx.setup() + + return true + } +} diff --git a/ogs-chkgfx/ver-ios/src/ChkgfxApp.swift b/ogs-chkgfx/ver-ios/src/ChkgfxApp.swift new file mode 100644 index 0000000..7aa819c --- /dev/null +++ b/ogs-chkgfx/ver-ios/src/ChkgfxApp.swift @@ -0,0 +1,12 @@ +import SwiftUI + +@main +struct ChkgfxApp: App { + @UIApplicationDelegateAdaptor(AppDelegate.self) private var appDelegate + + var body: some Scene { + WindowGroup { + ChkgfxView(appDelegate.chkgfxVM) + } + } +} diff --git a/ogs-chkgfx/ver-ios/src/chkgfx/chkgfx.swift b/ogs-chkgfx/ver-ios/src/chkgfx/chkgfx.swift new file mode 120000 index 0000000..3c6bb5e --- /dev/null +++ b/ogs-chkgfx/ver-ios/src/chkgfx/chkgfx.swift @@ -0,0 +1 @@ +../../../../components/chkgfx/chkgfx.swift \ No newline at end of file diff --git a/ogs-chkgfx/ver-ios/src/chkgfx/chkgfxVM.swift b/ogs-chkgfx/ver-ios/src/chkgfx/chkgfxVM.swift new file mode 120000 index 0000000..cf74ca4 --- /dev/null +++ b/ogs-chkgfx/ver-ios/src/chkgfx/chkgfxVM.swift @@ -0,0 +1 @@ +../../../../components/chkgfx/chkgfxVM.swift \ No newline at end of file diff --git a/ogs-chkgfx/ver-ios/src/chkgfx/view/ChkgfxView.swift b/ogs-chkgfx/ver-ios/src/chkgfx/view/ChkgfxView.swift new file mode 120000 index 0000000..6c25613 --- /dev/null +++ b/ogs-chkgfx/ver-ios/src/chkgfx/view/ChkgfxView.swift @@ -0,0 +1 @@ +../../../../../components/chkgfx/ios/view/ChkgfxView.swift \ No newline at end of file diff --git a/ogs-chkgfx/ver-ios/src/dialect.swift b/ogs-chkgfx/ver-ios/src/dialect.swift new file mode 120000 index 0000000..a931c95 --- /dev/null +++ b/ogs-chkgfx/ver-ios/src/dialect.swift @@ -0,0 +1 @@ +../../ver-mac/src/dialect.swift \ No newline at end of file diff --git a/ogs-chkgfx/ver-ios/src/other/other.swift b/ogs-chkgfx/ver-ios/src/other/other.swift new file mode 120000 index 0000000..f91488c --- /dev/null +++ b/ogs-chkgfx/ver-ios/src/other/other.swift @@ -0,0 +1 @@ +../../../../components/other/other.swift \ No newline at end of file diff --git a/ogs-chkgfx/ver-mac/src/ChkgfxApp.swift b/ogs-chkgfx/ver-mac/src/ChkgfxApp.swift index 105f2dc..090c94b 100644 --- a/ogs-chkgfx/ver-mac/src/ChkgfxApp.swift +++ b/ogs-chkgfx/ver-mac/src/ChkgfxApp.swift @@ -1,4 +1,3 @@ -import AppKit import SwiftUI @main diff --git a/ogs-chkgfx/ver-mac/src/raybri/raybriConst.c b/ogs-chkgfx/ver-mac/src/raybri/raybriConst.c new file mode 120000 index 0000000..fe840ed --- /dev/null +++ b/ogs-chkgfx/ver-mac/src/raybri/raybriConst.c @@ -0,0 +1 @@ +../../../../components/raybri/raybriConst.c \ No newline at end of file diff --git a/ogs-chkgfx/ver-mac/src/raybri/raybriConst.h b/ogs-chkgfx/ver-mac/src/raybri/raybriConst.h new file mode 120000 index 0000000..7e1b994 --- /dev/null +++ b/ogs-chkgfx/ver-mac/src/raybri/raybriConst.h @@ -0,0 +1 @@ +../../../../components/raybri/raybriConst.h \ No newline at end of file diff --git a/ogs-mahjong/ver-mac/src/GameApp.swift b/ogs-mahjong/ver-mac/src/MahjongApp.swift similarity index 90% rename from ogs-mahjong/ver-mac/src/GameApp.swift rename to ogs-mahjong/ver-mac/src/MahjongApp.swift index 449a921..3d71dfe 100644 --- a/ogs-mahjong/ver-mac/src/GameApp.swift +++ b/ogs-mahjong/ver-mac/src/MahjongApp.swift @@ -1,8 +1,7 @@ -import AppKit import SwiftUI @main -struct GameApp: App { +struct MahjongApp: App { @NSApplicationDelegateAdaptor(AppDelegate.self) private var appDelegate var body: some Scene { diff --git a/ogs-mahjong/ver-mac/src/raybri/raybriConst.c b/ogs-mahjong/ver-mac/src/raybri/raybriConst.c new file mode 120000 index 0000000..fe840ed --- /dev/null +++ b/ogs-mahjong/ver-mac/src/raybri/raybriConst.c @@ -0,0 +1 @@ +../../../../components/raybri/raybriConst.c \ No newline at end of file diff --git a/ogs-mahjong/ver-mac/src/raybri/raybriConst.h b/ogs-mahjong/ver-mac/src/raybri/raybriConst.h new file mode 120000 index 0000000..7e1b994 --- /dev/null +++ b/ogs-mahjong/ver-mac/src/raybri/raybriConst.h @@ -0,0 +1 @@ +../../../../components/raybri/raybriConst.h \ No newline at end of file diff --git a/util/build-ogs-blue-mac b/util/build-ogs-blue-mac new file mode 100755 index 0000000..6b7d8f3 --- /dev/null +++ b/util/build-ogs-blue-mac @@ -0,0 +1,12 @@ +#!/bin/bash -e +SDIR=$(cd "$(dirname "$0")" ; pwd -P) + +T=$SDIR/step +source $SDIR/paths + +TARGET=ogs-blue + +STEP=0 +source $T/generateDialect $TARGET +source $T/buildMac $TARGET +source $T/packageMac $TARGET "OGS blue" diff --git a/util/prepare-ogs-blue-ios b/util/prepare-ogs-blue-ios new file mode 100755 index 0000000..e523f01 --- /dev/null +++ b/util/prepare-ogs-blue-ios @@ -0,0 +1,11 @@ +#!/bin/bash -e +SDIR=$(cd "$(dirname "$0")" ; pwd -P) + +T=$SDIR/step +source $SDIR/paths + +TARGET=ogs-blue + +STEP=0 +source $T/generateDialect $TARGET +source $T/prepareIOS $TARGET diff --git a/util/prepare-ogs-chkgfx-ios b/util/prepare-ogs-chkgfx-ios new file mode 100755 index 0000000..80c6be5 --- /dev/null +++ b/util/prepare-ogs-chkgfx-ios @@ -0,0 +1,11 @@ +#!/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/prepareIOS $TARGET diff --git a/util/run-ogs-blue-mac b/util/run-ogs-blue-mac new file mode 100755 index 0000000..273ee98 --- /dev/null +++ b/util/run-ogs-blue-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-blue "OGS blue" diff --git a/util/step/prepareIOS b/util/step/prepareIOS new file mode 100755 index 0000000..b1c2e08 --- /dev/null +++ b/util/step/prepareIOS @@ -0,0 +1,9 @@ +#!/bin/bash -e + +TARGET=$1 + +STEP=$((STEP+1)) +echo -e "\n> > > > Step №$STEP. Generate iOS project for '$TARGET'" + +cd $SDIR/../$TARGET/ver-ios +xcodegen