How morizerodev/milestro works
Project Type and Purpose
• Milestro is an integration library for Unity that ties into Skia rendering.
• It supports multiple platforms (Windows, Android) and includes provisions for cross-compilation (evident from the cmake configurations and Android-specific instructions).
• Its primary purpose is to provide a Unity plugin that enhances game rendering capabilities using Skia.
Analyzing the File Structure
• Top-Level Directories:
• apps: Contains command-line applications (like the CLI tool in apps/cmd) useful for interfacing or testing.
• ext: Includes external dependencies and plugins, notably the PluginAPI with various headers exposing Unity event and graphics interfaces.
• Contains the Milestro headers that define its public API for common functions, game interfaces, ICU (for international text processing), IO, logging, and Skia integration.
• src: Implements the actual logic corresponding to the headers including game-specific implementations (e.g., skia rendering for canvas, fonts, SVG, text layout, ICU, I/O, and logging).
• tests: Contains unit/integration tests organized by module (ICU, image, readfont), which is critical to validate module components.
• cmake & gradle files: Indicate use of CMake for building the C++ backend parts, and Gradle for some parts of the build (or wrapping native libraries).
Key Components and Their Roles
• Frontend/CLI App (apps): A command-line interface that might be used for maintenance, testing or configuring the engine.
• Plugin API (ext/PluginAPI): A set of interfaces (for rendering, logging, etc.) that Unity interacts with, providing the hook between Unity and Milestro.
• Core Library:
• Common utilities, platform abstraction, encoding, and time functions (in include/Milestro/common and src).
• Game specific logic (in include/Milestro/game and src/game) that likely includes high-level interface functions for interacting with the Unity game loop.
• Skia integration: Provided extensively in include/Milestro/skia and src/skia. This covers Canvas, Fonts, Images, Vector graphics, SVG rendering, and text layout. These are core to the project’s mission of integrating modern rendering features into a game environment.
• ICU integration for international text (found in include/Milestro/icu and src/icu).
• IO and Logging components (organized respectively in include/Milestro/io, include/Milestro/log and their src implementations) maintain runtime diagnostics and file operations.
• Testing Suite:
• Organized tests for each main component confirming that each part behaves as expected.
Relationships and Interactions
• Unity Game (external consumer) ←→ PluginAPI in ext/PluginAPI:
• Unity communicates with Milestro through well-defined interfaces like IUnityGraphics and IUnityLog.
• The Command-line tool (in apps/cmd) leverages the core library to perform certain actions or tests.
• The core engine (compiled from src) ties together functionalities from:
• Skia: Rendering graphics, managing fonts, images, SVG, and text layout.
• ICU: Handling language and cultural text specifics.
• IO and Logging: Managing file I/O and diagnostics.
• Testing modules simulate or invoke various aspects of the Milestro functionalities ensuring robust integrations.
Architectural Patterns and Design Principles
• Modularization: The project is separated into multiple modules (game, skia, icu, io, log). This customer separation supports maintainability, testing, and potential reusability outside of Unity.
• Interface-driven design: The ext/PluginAPI exposes necessary interfaces for Unity, which decouples the implementation in the core from the way Unity interacts with it.
• Cross-platform compilation: The project employs CMake and Gradle, with specific build configurations for Windows and Android, ensuring that multiple build environments are supported.