Overview - Build System and the Project Arcitecture

Overview - Build System and the Project Arcitecture


The Build System

Project Arcitecture

Project Structure

graphics
├── CMakeLists.txt
├── engine
│   ├── assets
│   ├── CMakeLists.txt
│   ├── engine.pc.in
│   ├── include
│   └── source
├── external
│   ├── freetype
│   ├── harfbuzz
│   └── ⋅⋅⋅
└── projects
    ├── editor
    └── game

The Bridge Interface

struct bridge {
    void (*mouse_move)(void *userdata, struct window *window, f64 x, f64 y);
    void (*mouse_scroll)(void *userdata, struct window *window, f64 x, f64 y);
    void (*window_resize)(void *userdata, struct window *window, i32 w, i32 h);
    ...
};

struct editor_state {
    struct bridge bridge;
    struct window *window;
    struct font *font;
    .....
};
/* projects/editor/source/editor.c */
editor->bridge = (struct bridge) {
    .mouse_move = mouse_move,
    .mouse_scroll = mouse_scroll,
    .window_resize = window_resize,
};

struct window window_options = {
    WINDOW_DEFAULTS,
    .bridge = &editor->bridge,
};

if (!(rc = window_init(editor->window, window_options))) {
    goto cleanup;
}
/* engine/window.c */
static void __window_mouse_scroll_callback(GLFWwindow *window, f64 x, f64 y) {
    struct window *_window = glfwGetWindowUserPointer(window);
    _window->bridge->mouse_scroll(_window->bridge, _window, x, y);
}

/* projects/editor/source/editor.c */
void mouse_scroll(void *userdata, struct window *window, f64 x, f64 y) {
    struct editor_state *editor = userdata;
    ...
}