-
Notifications
You must be signed in to change notification settings - Fork 0
Fused Mode
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.txtand 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.
First, your game will need to be adapted to some restrictions:
- You need a
main.rbfile, 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. - All paths when
requiringorloadingare 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. - You can't load
.sofiles 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).
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.rbin 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