A Persistent File System


  • F

    Over the past couple of months, I have been working on a textured 3D modeler in Fuze4 using drawQuad() with a BSP (binary space partition tree) to cut faces and draw them in far to near order. However most of that time was spent making a drawing program to allow editing of the textures from within that program for immediate feedback of the appearance of the texture on the model.

    It was about 3 weeks ago when I figured out how to RLE (run length encode) the images to a small but variable sized string that I realized I need to be able to save multiple of these variable sized image strings and ultimately the 3D models as-well all in the single persistent file Fuze gives us.

    So, over the past couple of weeks, I have been working to create a real file system that can be used in a Fuze project. Store as many files as you want, make them smaller/bigger no problems. You can even organize them in a folder structure.

    The demo I have made is able to store simple text files in an arbitrary folder hierarchy. No image editor is embedded yet, and there could be bugs I haven't found. I haven't even tested the File Table when it needs more than 1 block (at around 64kb file system size).

    File System.png
    I hope this will be as useful for other Fuze users as it will surely be for me.

    Share Code: N5XQ3RND9L (live)


  • F

    OMG I’ve been waiting for this!



  • This seems to be a useful thing, didn't quite understand what it does, but what I think this will be used to "wallpaper" textures on 3d models? Since we don't have a model editor yet?


  • Fuze Team

    @Mechanical Specifically this allows you to store multiple files in a virtual file system (as Fuze currently only supports one)


  • F

    i am hoping to use it to store attributes of 3d models I'm using to furnish my landscape. I'd like to add multiple save slots too, so hopefully this'll make things easier.


  • F

    @Mechanical As pianofire said, this is a virtual file system, that can be used to save whatever data you want. Ex. save games, level maps, high scores, etc. I am planning on using it myself for saving "wallpaper" textures on 3D models as you say. That is a separate project of mine at the moment.

    I am currently working on an update for this which includes:

    • A fix for a bug where the UI doesn't test for the max filename length (126 bytes). You might corrupt the filesystem if you make a filename too long.
    • Improved UI that lets you quickly scroll more files than fit vertically on the screen.
    • Improved link and unlink which will keep files in directory entrys compact and in a more predictable order for large directories with more than 1 block of filenames.
    • Various spelling errors and typos in the comments

    I hope to resubmit with these changes soon.


  • F

    @Gothon I looked at the code, impressiv, is this the implementation analog to the FAT system on a disk? But how do you store "wallpaper" textures: do you store a lot of data points for texture corners or do you store the images used for the textures itself? Did I miss a command that can save an image? or extract binary data out of an image handle? Sorry, for so many questions, but thats very fascinating. I don't expect an essay, just a few words, if you have a moment. Or additional links: I will have a look at your first Game Jam entry, maybe I should start there. ;-)


  • F

    @spikey

    is this the implementation analog to the FAT system on a disk?

    Yes it works similar to DOS in the way it uses a FAT to track the use of data blocks.

    But how do you store "wallpaper" textures: do you store a lot of data points for texture corners or do you store the images used for the textures itself?

    I am storing the images themselves encoded as a string representing each pixel as 1 ANSI character used as an index to a 126 color palette. Currently the images are all 256x256, however I have managed to compress the string using run length encoding (RLE) so I can represent less detailed images compactly.

    Did I miss a command that can save an image? or extract binary data out of an image handle?

    You did not. Fuze currently has no way of reading pixel data from an image buffer. What I have in my other project allows you to draw the images in regular memory as an array of integers. For memory efficiency I pack 8 pixels of color indexes into a single (64bit) integer which seems to work quite well in the program. After an image has been drawn I can then convert this array into a string for more memory efficiency and saving.


  • F

    @Gothon "draw the images in regular memory as an array of integers": are you referring to uploadImage()? So, you manually add ~256x256=65'536 / 2 (maybe as an average good encoding rate) = 30'000 characters by typing them into your code? and convert them to vectors (colors) to generate the image? - I think I am still missing a point. Recently I had a quick thought about converting a bitmap (as an easy format) to a vector array: to convert something like this to pass it to uploadImage() d6261e38-e0e2-4365-845c-4754b1ea4b9c-grafik.png.
    But that ends up in a lot of typing. I checked your FUZEGJ0103 jump project, but there you use the decent imagebuffer drawQuad() and to draw you use shapes. Ok, I feel like I am pestering you with questions - I will just follow your work with great interest. Congratulations, for that FAT system.


  • F

    @spikey No, I am not using uploadImage(). What I have is a prototype interactive drawing program so there isn't a need to have a big chunck of data in the source code.

    This is simplified but it works something like this:

    Function CPU_Plot(ImArr, Pos, ColIdx)
        int Idx = 256 * Pos.y + Pos.x
        int ByteIdx = Idx % 8
        Idx = Int(Idx / 8)
        ImArr[Idx] = bitFieldInsert(ImArr[Idx], 8 * ByteIdx, 7, ColIdx)
    Return VOID
    
    var Palette = [ white, platinum, lightGrey, silver ]
    
    int ImData[8 * 1024]
    var ImHandle =  CreateImage(256, 256, 0, Image_RGBA)
    
    // Initialize with an 8x8 checkerboard:
    SetDrawTarget(ImHandle)
    For Y = 0 To 8 Loop
        For X = 0 To 8 Loop
            int C = 2 + ((X + Y) % 2)
            CPU_Plot(ImData, {X, Y}, C)
            Plot(X + 1, Y + 1, Palatte[C])
        Repeat
    Repeat
    
    Loop
        SetDrawTarget(FrameBuffer)
        Clear(SkyBlue)
        DrawImage(ImHandle, 100, 100, 2)
        Update()
        // Do Input Handling here
    Repeat
    

    It keeps the data both in main memory and video memory and keeps them synchronized throughout the program so no explicit uploading is needed. Although I do have a function to copy the whole array to the image buffer. I use it occasionally for debugging.


  • F

    @Gothon Thank you for taking your time to share this 👍. I will definitively need some daylight and a tee to absorb this properly.


  • F

    I have re-shared an update. The download code is the same.

    The file system structure is also the same, so if you have pre-existing files, the new code should load them. However you must be careful not to overwrite the project with the new one as that would erase the files and instead only copy-paste the source code.

    This update contains the previously mentioned improvements and a new file/folder copy/paste feature.


Log in to reply