Skip to content

Fused Mode

Chadow edited this page Dec 10, 2023 · 8 revisions

Contents

  1. How Does It Works
  2. Usage
    1. Limitations
    2. Adapting Your Game

How Does It Works

The PhysFS homepage and docs page can explain it better than I could, but the gist of it is that using PhysFS we can access various archives (ZIP, 7z, to name the most known) and use them like filesystems, kinda. So we could, for example create a zip file with some files:

my_image.png
sound.wav
data.txt

and load them directly from the virtual filesystem made by PhysFS. On that same premise we'll use it for loading Ruby scripts from a ZIP, and that ZIP file is bundled directly with the executable by tacking it onto the end of it with a command like cat, this way you only need the executable and your assets for you game to run.

Usage

Limitations

First, your game will need to be adapted to some restrictions:

  1. You need a main.rb file, that's your entrypoint and the file that is first run when loading the archive, so make sure it is on the root directory of the archive.
  2. All paths when requiring or loading are relative to the root of the archive, so you'll need to use the load path to load files comfortably. Note that paths that start with "." or ".." are invalid and will raise an error.
  3. You can't load .so files from within the archive yet.

NOTE: while require and load are restricted to the archive only, every other functionality regarding files and such is left intact (except that you can't read and write to files in the archive yet).

Adapting Your Game

As I said before, you'll need to structure your project a determined way for it work correctly when in fused mode, the most straightforward way that I could think of is like this:

.
├── main.rb
└── src
    ├── game_file1.rb
    ├── game_file2.rb
    └── game_file3.rb

in main.rb you'll kickstart your game and add src/ to the load path $: << 'src', then you can require your files like usual.

# main.rb
$: << 'src/'

require 'game_file1'
require 'game_file2'
require 'game_file3'

# Various game dev thingies

Clone this wiki locally