pimoroni / picosystem

PicoSystem libraries and examples.
MIT License
141 stars 33 forks source link

I ONLY Need File I/O To Finish My Game! #71

Open crait opened 2 years ago

crait commented 2 years ago

Hey, I really like this library a lot. Some of the missing features are okay by me because I am using it as a base to port over some of my game engine code to get some of my games on the PicoSystem, which is a great system!

However, to finish porting my game, Circuit Dude (and maybe Treasure Chasers), I am pretty much all set for everything! I just need simple file I/O working for saving the game's progress and reading the progress into memory (as well as making a directory for them).

It would be cool if you could add some functions such as... bool directory_exists(string path) bool file_exists(string filename) bool create_directory(string path) bool create_file(string filename) bool save_data(string filename, ??) bool read_data(string filename, ??)

My use cases are:

I dunno. Maybe you could also make some functions for reading/saving strings, too, for simple text files.

Anyway, like I said, I only need these to finish my game!! 🤗

Gadgetoid commented 2 years ago

This is a solved problem in the 32blit SDK, and works great on the PicoSystem port too- with a 4MiB save partition- thanks to @daft-freak. However! If we want people using the optimised and opinionated PicoSystem native SDK I think savegame support is kinda essential.

I know it’s officially a “work around it with savegame codes” kinda thing but when the flippin’ MicroPython port can do file IO and C++ can’t… it’s just kinda … wat.

Could we build this out as an optional extension I wonder? A basic savegame lib that uses and respects the same 4MiB portion that 32Blit uses (so we don’t trounce players save games). Or does switching out of XiP to handle saving to flash make this difficult to library-ize? 🤔

Daft-Freak commented 2 years ago

Or does switching out of XiP to handle saving to flash make this difficult to library-ize? thinking

Pico SDK flash erase/write functions handle this for you, you just need to make sure core1 isn't running (at least not from flash) and interrupts are disabled. (storage_write in 32blit-pico/storage.cpp is where this happens for 32blit)

... now I'm going back to 32blit SDK land :smile:

Gadgetoid commented 2 years ago

Pico SDK flash erase/write functions handle this for you

Ah! I should have guessed. Thank you.

I feel bad about stea... uh ... borrowing code from the 32blit SDK! :laughing:

crait commented 2 years ago

Does this mean that this will be implemented, soon-ish? 😊 😅

Gadgetoid commented 2 years ago

Possibly when I get out of Hub75 and Linux kernel driver hell :cry:

Short term fix is to encode your game saves into a catchy phrase or level select code :laughing:

image