Sunday, September 13, 2020

Random Thoughts, Some Progress

 Lots of work at work, so not as much time for projects.

Smattering of thoughts:  

  1. Godot doesn't really seem ready for prime-time with c# yet.  Not bad, and we will keep and eye on it.   I'll try to make my libraries in a way that theoretically we could make them agnostic to the engine (probably biggest issue there will be the way the engine does mesh representation), and hopefully as little code as possible on the engine side.
  2. Keeping a close eye on wasmer/wasmtime.   I think I will still need wasmer, since it is .netstandard 2.0.  The Wasmtime restriction to .netstandard 2.1 is a problem with unity (and probably godot).   Though I can run the emissaries as separate processes, I think I want to do that later.  Let's get it working before we go too crazy with a 'scale out' plan, just not preclude ourselves from going that way.  I have very little time to code, so have to make a bee-line to functionality.   We will probably revisit this when Unity changes their .net model, to .net core or possible .net 5 (the .net version to rule them all).  Both of these projects are ticking a long.   I still find wasmer's WAPM projects a powerful missing link, though version pinning and signed downloads of external code would have to happen.
  3. Starting to look at some naked-codeless emissaries, which just have content in them.  It's one option for the emissary, just to hold objects, or to hold references to objects.   I'm refactoring the ldraw code so I can just put lego entities in.  Later these can indirect to an URL rather than needing to be in the emissary--though they will have to match a full checksum when they download--they will then be able to be proxy signed.   Looking at getting an STL loader too.  Then some work on a universal (protobuf based) mesh format.
  4. Very intrigued by Kafka.   I think log based messages might be a giant win over Rabbit/AMQP style pub/sub.   The use-case is that the world server can simply make every client a producer and everyone can be a consumer to see their scenes change.   The interesting thing is that perhaps, if you don't have a complete cache of the scene, you can then traverse the log in the reverse direction back to a fixed low-water mark (which represents having every entity having presented it's status in the log at least once), fully recapitulating the status of the scene.  You have to traverse it backwards since a given entity might report many times, and you don't want to have the scene be remade in order.   Physics will have to be suspended during the repaint.  Also, if  you mark each status with the timestamp of the last previous change, you can make a hash to ignore all but the last status report of every entity (and not have to keep inactive entities in your hash -- if their last-changed is back before the low-water mark.   Also Kafka messages can be done in protobuf (a supported standard).    World server will still need a database to track everything.   Might be easier than the redis idea.  Have to experiment.  I need a skeleton world server.  I'm building a Kafka server to try out.
  5. These log based systems like Kafka (and really like the mongo oplog) are intriguing.  I'm thinking of a way to do the image and mesh caches that use this, where they use a given number of fixed length cache files (likely memory mapped), and the oldest one times out and causes the oldest cached entries to be reloaded into a real file.   This doesn't fix evacuating trivial files or keeping core-files which are constantly used. Trivial files of course will fall out when the logs get rotated.  It's a very powerful scheme for keeping high-integrity databases without needed to do wild random access during setup, or any need to do garbage collection.

Sunday, June 14, 2020

Doing some Rethinking

So, I've been progressing somewhat with Emissaries...   

But, I have been doing a little rethinking.   First, if I go with Unity as the browser platform (as I have), it might make sense to look harder at Wasmer (github), rather than WasmTime (github).   Wasmer is available in .net standard 2.0, which will permit it to run directly in Unity, rather than requiring me to build out the multi-process architecture initially to make it so that I can call WasmTime WebAssembly via a separate Emissary process.   This would be much easier as an initial effort, and would make is possible to have Entities that can directly interact with the browser engine.   I'm also very interested in the WAPM effort, which is the WebAssembly -Package Manager--inspired by NPM.   I think this is basically a linker, possibly even a dynamic-linker.  It's something I thought we'd need sooner rather than later...  Ultimately we want WebAssembly modules to act like shared libraries, so that only one instance of a given module need to be in memory on a given emissary server.

However, an even bigger and more momentous change, I'm starting to look at Godot games engine.   It's not nearly as sophisticated as Unity (Unreal doesn't seem like it's any kind of fit for what I need).   Also, I'm essentially building what Unity calls a "platform".   This isn't something you're really supposed to do in Unity, though since it would be open source and would probably not really be charging money for it (at least directly, I would like to be able to monetize it somewhat---consulting, hosting, or something Patreon-like), I may or may not get into issues.   It also might be something Unity would be interested in sponsoring if this became popular.  You never know.

But, Godot is MIT license and includes all the sources.   It seems like it's got a good following, and a small but very talented core team.    Exposing the Godot API into wasm might even be something the Godot group would be enthusiastic about--it would be the holy-grail of scripting, not being tied to any particular language--though VRWorlds requires more sandboxing than that.  Perhaps the compromise there is to permit the sandbox to be created, and what APIs are exposed to it are done at creation (some level of WASI and Godot API or VRWorlds APIs can be specified).   As WASI embeddable WebAssembly capable languages start to become more plentiful (again, that's pretty much just Rust, C, C++, and maybe Javascript for now), this might become very attractive.

Godot does support procedural geometry, which we need since we don't really use the games engine to directly manage our content--it gets loaded with the emissaries.

GD script seems appealing.  I really enjoy python (though I  despise JavaScript).    It might even be worthwhile to dispense with c# and just do the interface code in GD and embed wasmer or wasmtime in c++ (theoretically it can also be done dynamically in GD script)--c# is apparently a brand new feature.   I can also put it into the engine myself, since all of the code is on GitHub.   So, I will be soul-searching and learning Godot a bit more.   It's possible that they might grow up together.  Obviously a smaller open-source project is riskier than a big commercial effort like Unity, but perhaps it will turn out somewhat like Blender did.

I can write modules directly in C and C++.   This might permit a lot of the frame-buffer operations I want to do to be very fast as opposed to having to write lots of unsafe pointer code in C#, though it's possible to call C/C++ from C# with interop.

Sunday, May 3, 2020

Emissary Architecture Starting to Take Shape

So, I've been pretty deep in WASM architecture, and the WASI APIs.   I've pretty much gotten to the point where we can launch an emissary and interact with it.    So, now, it's time to actually build out the 3DOM APIs for interacting with the emissary and the message passing loops.   Initially I'm going to start building a Rust Module for this.  I do want to do this with other languages as it becomes practical.   I'd love to be able to do C# and Python, but I don't think they're quite there yet.   I've used mono-wasm to generate c# wasm, and pyodide for Python, but so far they're not particularly oriented to WASI yet and are more intended to run on a website (and interact with a DOM).

I think it will mostly go like this: one exposed setup method from the API layer, which will receive a protobuf buffer.   This will be using 'proto 3' and will be decoded and processed.  This gives us a backward and forward compatible startup.    The startup will register callbacks on the rust side for the message pump to process.   Then the emissary's 'main' basically returns.    A channel is created via grpc to the browser and eventually to the entity/avatar server.  Protobuf packets are passed in via these callback mechanisms.   The emissary runs and then returns and possibly returns one or more protobuf packets.   For now, I don't intend the emissary to have a thread to run when it is not processing a callback.   Initially I'd rather an emissary not be able to do things like mining bitcoin or other such undesirable activity.   The service managing the emissary will probably have a call timeout and will disable it if it doesn't respond in a timely fashion.

This facility kind of makes it hard to directly do gRPC, but at least we can do gRPC-like behavior passing protobufs around.   I can cheat and have a grpc wrapper call which contains a command type and the protobuf  as a raw vector.   The server calls are tricker, as the interior emissary-to-server gRPC calls are theoretically private (and ad-hoc)--so their formats can't be known by this middleware layer which is operating the emissary for the browser.    There are some up-and-coming grpc proxies out there.   Or I will have to do my own, which is just calling methods on the emissary and returning an answer (no actual network involved).   With my WASI layer, I could actually permit the emissary to open a socket, but I don't trust this yet. 

So, now I actually have to work out exactly what the browser-emissary interaction (which I've been calling the 3DOM api) actually is and how it works.   I've got some prototypes of this that I worked out last summer, but now I have to start building my .proto files to implement it.

Initially there will be no world, and no entity server to work this out.  I'll have the concept of a "system entity", which can simply run inside the loading area (which will eventually will become a mini-world which is served from inside the browser).   Also, eventually we'll have an avatar server, but initially the avatar is mostly just a vr camera FPS rig, with no smarts.    I'll be doing some checkins soon of some of this structure. 

The emissary will have an initial built-in parasitic overhead to have to have a copy of the loading module and the protobuf module.  Eventually I'm sure I'll be able to dynamically link such things so they can be shared between emissaries.   There's an effort for a package manager for webassembly (like npm) called wapm.  Perhaps there can be a package manifest and emissaries can be dynamically loaded.   I am ultimately intending for there to be hundreds, if not tens of thousands of emissaries to exist (in the distant future).   So optimization, sharing, hot-deploy, and versioning will have to be seamless.


Monday, April 13, 2020

Webassembly Madness

Spent a lot of time over the weekend getting webassembly jammed into my brain and tooling up.

I looked hard at mono-wasm (now built into the mainline distribution).   It was generating huge wasm files, so putting lots of code I wasn't explicitly adding into it.  I have to look much harder at this.   It seems like they're making an attempt to get the .net foundation classes implemented (though a lot of the code basically throws a "Not Implemented" error).   Still looks promising.  I'd rather the first gen emissaries be c#.   It's not really focused at WASI and embedding yet.  I think the emphasis is mostly for browser use and the DOM.

Discovered that there's a PyPi module with wasmtime in it, so I can embed that and make a test framework.  Trying to get my hello-world modules working in Rust and establishing the tool-chain for all of that.

They split out the wasmtime .net framework into a new package.  I think perhaps that they utterly redid the API, though it seems much easier to use.   It doesn't have to discover the host-wasi modules via reflection, so I can have a call which sets up which api's are available to each class of emissary (a method call can define each method).

I need to learn webassembly assembler.   It's been a good 40+ years since I did assembler regularly, but this one might end up being the ultimate superset assembler.   It would be interesting to build a real assembler for it (rather than the lisp-like fully regularized syntax it has now).

Sunday, April 5, 2020

2020 Has Eaten My Brains...

Wow.  I've had a busy several months.   I think about this project quite a lot, but have had little time.  The SF conventions that I normally spend coding on this stuff have been cancelled.  Alas Norwescon...

Getting the First Person framework working on the loading deck.   I've got the VR integrated, but needing to get all the movement stuff working.   Unity is having problems with the SteamVR plugin with some of it's more recent versions.   I'm trying to run on 2019.3, but still have to remove several of the integration methods to get it to compile.   I'm going to try to get teleport movement working.  Supposedly Valve is going to write a new version of steamVR (or OpenVR--not exactly sure).  This might limit me to the 2019 version of unity for a while.  I think--rereading all this and updates, that I need to start using the XR framework.

Keeping an eye on Wasmtime.  They're doing good work there.   There's a new nuget preview.  It looks like if you look in the sources though that they're changing and simplifying the calling structure.  It looks like there's going to be a much easier way to integrate the private APIs I need to expose to it via private WASI.  You can just call a method to define a function.  So I can start getting together some classes to autogen the APIs.  It also lets me define different APIs and only load the ones that are appropriate (entities, avatars, and worlds likely have variations in what APIs are present).  And eventually will start to implement the standard WASI interfaces that are appropriate (like file IO, but only to the sandboxed and read-only emissary filesystem).    It's still looking like Rust for the first language for doing Emissaries, though I need to see how other systems are working.   Blazor is going nicely in the dotnet/c# world, but it works rather differently -- There's a CLR interpreter running in webassembly -- I might look into this and see if this is sufficiently well documented to write my own CLR classes for it or if I'll need my own webassembly module (it may be assuming a DOM and other non-embedded things--though eventually, it might be worthwhile having a working DOM).

In the just-fun category, I had an interesting idea.   Someone has an actual firmware VT100 emulator running on a virtual javascript 8080 cpu.   This is not what is conventionally known as a "vt100 emulator".   This truly is running the rom code from a vt100.   It was be possible to build one of these into an emissary (I see some 8080 emulators in rust).   I was originally thing that these emulators would run server-side and expose themselves in the VR environment via a pseudo-serial connection.    So, it would be truly interesting to do this with the other SIMH emulators and Mame and libretro.   These are mostly in C, it might be possible to get them into webassembly.   Mame has some other VT emulators built into them as well as the million other things Mame can do.   I hear rumors that there's an SDL layer that's been ported to webassembly (though probably for a DOM Canvas, but I can probably map that onto a texture).

Next big effort too is to get the various multi-process servers to bidirectionally ping each other and shut down when the browser exits.   There a ping that occurs the when the service comes up to indicate that it's ready.   I also had the thought to have some kind of indicator of presence and health on the loading deck, like a luminous sphere for each server.  Color could indicate load or CPU %.   It was a bit of an epiphany that I could start having simple emissaries that don't really require an external entity server, and can show them onto the loading deck.   Getting all of the pieces together for loading external content is still a ways off.  The initial avatar won't really need any emissaries, until we want to start showing a second-person view.   Though we might eventually show hands and such in first-player view--though that might be initially hardcoded and rely on what is available in SteamVr.

I had a sketch of the necessary emissary APIs, so I will also start fleshing those out.   Those need some practical hammering so we can come up with some nice coherent architecture for that.  Mostly it allows the emissary to manipulate the 3d object which it controls (via hopefully the new Entity framework in Unity).   There has to be a bidirectional message pump between the browser process and the emissaries--the emissary requests a change and the data gets passed to the browser and implemented (or it requests a callback to return info back to the emissary).   I need to see how GRPC has progressed in the last few months.  Perhaps the windows GRPC via named pipe has been implemented in .NET and we can have very fast communication for these message loops.

I'm also seeing lots of nice API documentation on github.  Need to work on that for the new code.

Found a Named Pipe implementation for GRPC.

Thursday, January 23, 2020

Progress with WasmTime

After holidays and bad colds and work trips, I'm starting to make lots of progress with WasmTime and with WASI.    I've started a new emissary common class, which I am getting ready to experiment with.

I am now at the point where I have to figure out how a emissary works inside (things like how to initialize it and call it, and feed it events).   So far, with WasmTime I think I have to generate a single module per webassembly file in memory (likely to change over time as wasmtime is in steady motion).  This of course was far from possible with V8.  I'm hoping that modules are light enough that we can have thousands, if not eventually hundreds of thousands, of these at the same time (though that might be 5 to 10 years from now -- I think computers of the future will be able to cope).

I also have kind of figured out how to handle WASI security.   There are several kinds of emissaries, and they need different APIs, and the concept of the IHost at this point just lets me define one.  So, I will need to put all the APIs together.  I can however put a simple, "Is thing thing on?" check to disallow calls that aren't for that kind of API.

I've started a big spreadsheet to start figuring out the actual methods I need for all of the different APIs.   And since I've expanded the idea of the emissary to basically encompass all most all of the VR business logic (if I can refer to it as such), with be done via an emissary.

And, since it seems like it's first the to gate, initial libraries for webassembly will be done in Rust.  Though I suspect most all languages will get there eventually.

I'm also thinking of possibly using protobuf to pass the initialization and perhaps some of the more complex objects between emissary and processor rather than trying to use regular objects.  I think I now need an Common Emissary Protobuf (and possibly gRPC) library, and likely a separate github repository so they can be git submodules.

I'm also starting to consider the use of rabbitMQ (AMQP) to do more event oriented work.   I can even install rabbit (and erlang) onto a local windows  machine.   I'd have to figure out the demarcation between gRPC and AMQP.  Though likely the AMQP messages will be protobuf.

I'm starting to question the windows-centric deployment of the browser -- this is likely required, though eventually I might be able to do hybrid deployment in docker on windows-10.  This also might be a good solution for browser clustering.   It certainly would be an easier way to deploy the messaging (amqp), and possibly the various non-ui servers (emissaries, and caches).

Wednesday, December 18, 2019

WebAssembly and Blockchain Happenings

I am jazzed by the appearance of CraneLift and WASMTime.

CraneLift is a JIT webassembly compiler, and WASMTime, which is a complete sandboxed environment. However, it appears to be for Non-Web Embedding. Which is what I've been waiting for.

CraneLift will probably be the basis of our toolchain. 

There's also a nuget module for WASMTime that can be called from .net (though I might have to change all my external modules back again to the latest .net core rather than framework 4.8). This might be much simpler than trying to run V8 (via Microsoft ClearScript) -- and much more portable. I also don't feel any great loss from the not having a Javascript environment.

There apparently is a gRPC/protobuf implementation now for  Rust (if the first emissaries need to be written in Rust).

I'm making slow (very-slow) steady progress with the Emissary managers. The browser launches them and they start to do their startup handshakes. However, the next steps, which is mostly being able to log into the various Kudo Servers is going to take some effort. I have the stubs of the new Kudo Authentication engine started.

CraneLift might also let me build server side emissary modules.

I guess I'm going to have to learn Rust after all.


Starting to look at blockchain infrastructure like Corda. The true functioning of the Kudo server is basically a blockchain engine, or at least what it does would benefit from a blockchain journal. A true Kudo (like a game level or a certification) would benefit from blockchain auditing. Nothing much more useless than a blockchain which has an audience of one (like a stand alone system). It's only benefit is being shared far and wide.

I don't think Corda is .net (may be Java/Kotlin). But, it dockerizable, and has an API we can call.

Random Thoughts, Some Progress

 Lots of work at work, so not as much time for projects. Smattering of thoughts:   Godot doesn't really seem ready for prime-time with c...