Log in to follow projects

Following a project allows you to receive updates via email. It also lets the owner know that you like them.


Femto Paint

By Oliver Smith

A paint app for my iPad where I can micromanage the UX

35% complete
1 follower 2168 views
About Log (6) Discussion (0)
See more posts

SQLite database for persistent data, plus Unity strikes again

I added a persistent data store to the app in the form of an embedded SQLite database. I think it makes sense to use SQL for anything beyond basic settings. I need to store all the user's projects and settings, image layers, brush settings, etc, etc. SQL makes it easy to do things like update all the objects when I make changes to the schema, sort by date or update time, and query for things arbitrarily. Why reinvent the wheel with some weird custom serialization, I thought?

It was pretty hard to get a SQLite db running, though. There are a few different options, but I kept running into problems like missing interop DLLs and confusion about which platforms they would run on, or really old, mysterious DLLs from random places in GitHub. I ended up installing NuGet for Unity and using sqlite-net because it was just easy to install and worked, unlike the other solutions.

sqlite-net is designed around being an ORM, which I didn't really want, but so far it has worked out well. I did have to hack in support for UniRx reactive properties, but that was pretty easy.

Beyond that, I added continuous saving so whenever you draw, your changes get saved to PNGs on the disk. Then you can reload your project from the gallery. It feels almost like a real app now! Unfortunately, I got Unityed again, because Unity apparently doesn't have any way to read and write 16-bit textures at runtime? I could only get EncodeToPNG() to write 8 bits per channel. EncodeToEXR() can give you a 16-bit lossless file, but LoadImage() won't read it.

So again I ended up going the 3rd party route, and I'm using a fork of a library called pngcs that someone helpfully made to read/write from Unity Texture2Ds. It's unfortunately pretty slow, but it does work. I'll have to figure out a faster solution in the future.

I also got Unityed by the UIToolkit ScrollView being frustratingly half-baked. No real solution there yet, it's just going to have to feel bad for a while.

I'm pretty close to being able to practice art with this thing, I think. Technically I could do it now, but I guess I want undo/redo support, a color picker, and just some basic UI quality-of-life stuff first.