TaleSpire Dev Log 115
Let’s get back into the swing of these!
During the Kickstarter I’m using any free time I have to study and make little systems to get familiar with systems we may end up using
Today I’ve mainly been getting familiar with blittable types. The reason for this is that Unity’s DOTS primarily operates on them.
I got interested in how easy it would be to de/serialize such data, given these types can have precise memory layouts specified for them. The that end I was making little BinaryWriter
s and readers that had Write methods that could take any blittable type or array of blittables and handle them correctly.
I’m going to make a dump of some useful links as most of the stuff I was doing was simple enough, but was a good exercise for familiarity. It was the first time I’ve significant use of pointers in c# and it was a very simple and unsurprising experience.
The first handy thing was that the unmanaged constraint is available. Whilst unmanaged types are not the same as blittable types there is a useful overlap. Using this allows us to have signatures like unsafe void Foo<T>(T value) where T : unmanaged
. Also note that sizeof
is defined to work on unmanaged types. It was very easy to write generic methods doing useful stuff with c#, I’m please with it so far.
- Scoped GC pin
- Heap allocate, check out all of Marshal, it’s pretty handy
- more info on blittables
- create a struct from data referenced by pointer
- You can explicitly cast typed pointers to
IntPtr
- Unsafe seems like a handy class until you see that it’s not implemented in mono
- But then you find UnsafeUtility in Unity itself and it’s way better.
memcpy
,malloc
etc are all there
The big disappointment of the day is how quickly one ends up having to reinvent the wheel as most Streams, Buffers, Writers, etc, never expose their buffer or provide overloads taking IntPtr
. The more you poke to work around this the more it feels like you should just make your own. It’s not ideal. Saying that, I have spent most of today in dotnet code rather than Unity’s so I do still need to see what is there.
Until tomorrow, Ciao.