---
Kosmora provides a virtualized file system for game assets to be stored within, allowing for improved performance, more efficent memory usage, and a smaller storage footprint.
---
## Documentation
### Overview
Kosmora is a specialized virtual file system (VFS) designed for game development, enabling developers to efficiently manage, load, and access game assets. By abstracting the underlying file system, Kosmora provides a unified interface regardless of where files are physically stored.
### Architecture
```mermaid
graph TD
subgraph VFS["Kosmora Virtual Filesystem"]
VRoot["/"] --> VAudio["/audio/"]
VRoot --> VTextures["/textures/"]
VRoot --> VOther["/.../"]
end
subgraph RFS1["Real Filesystem 1"]
R1["/path/to/your/game/assets/"] --> R1Packages["packages/"]
R1Packages --> R1Audio["my_audio.kpkg"]
R1Packages --> R1Other["other_assets/"]
R1Other --> R1Files["..."]
end
subgraph RFS2["Real Filesystem 2"]
R2["/another/location/for/packages/"] --> R2Files["..."]
end
subgraph RFS3["Real Filesystem 3"]
R3["/home/user/game_data/"] --> R3Textures["game_textures.kpkg"]
R3 --> R3Other["..."]
end
%% Mount Point Mappings
VAudio -- "Mount Point Mapping" --> R1Audio
VTextures -- "Mount Point Mapping" --> R3Textures
%% Add styling
classDef vfs fill:#445544,stroke:#333,stroke-width:2px;
classDef realfs fill:#112233,stroke:#333,stroke-width:1px;
classDef mountpoint fill:#337733,stroke:#333,stroke-width:1px;
class VFS vfs;
class RFS1,RFS2,RFS3 realfs;
class VAudio,VTextures mountpoint;
class R1Audio,R3Textures mountpoint;
```
### Core Components
1. **Virtual Path System** - Provides normalized path handling across all platforms
2. **Mount Registry** - Manages mount points and their mappings to physical locations
3. **Asset Loaders** - Type-specific handlers for loading different asset formats
4. **Package System** - Tools for creating and accessing compressed asset packages (.kpkg files)
5. **Memory Management** - Intelligent caching and memory optimization for loaded assets
### Key Features
#### Unified Access Layer
Kosmora presents a single, consistent interface for accessing game assets regardless of their physical location. This simplifies development by eliminating the need to manage multiple file paths or storage systems.
#### Asset Packaging
The `.kpkg` format allows developers to bundle related assets together, reducing file count and improving load times. These packages can be mounted directly into the virtual filesystem, providing transparent access to their contents.
#### Hot-Reloading Support
Assets can be monitored for changes and automatically reloaded during development, streamlining the iteration process without requiring game restarts.
#### Cross-Platform Compatibility
Kosmora handles platform-specific path differences, ensuring your game's asset loading code works consistently across Windows, macOS, Linux, and more.
#### Memory-Mapped I/O
For supported platforms, Kosmora can use memory-mapped I/O to improve loading performance and reduce memory fragmentation.
#### Asynchronous Loading
Built-in support for async loading operations allows games to load assets in the background without blocking the main thread.
### Installation
Add Kosmora to your `Cargo.toml`:
```toml
[dependencies]
kosmora = "0.4.2"
```
For Nix users, add the following to your `flake.nix`:
```nix
inputs = {
# ...
kosmora.url = "github:kosmora-dev/kosmora";
};
# Then in your outputs:
outputs = { self, nixpkgs, kosmora, ... }: {
# ...
};
```
## Simple Example
Here's a basic example of setting up Kosmora and working with the virtual filesystem:
```rust
use kosmora::{Kosmora, MountOptions};
use std::path::Path;
fn main() -> Result<(), Box