Exemplo n.º 1
0
    public override void Setup(SyncObject syncObject)
    {
        obj  = syncObject;
        node = obj.Node;

        obj.RegisterEventHandler("grab", OnGrab);
        obj.RegisterEventHandler("ungrab", OnUngrab);
        obj.WriteDebugLog("grabbable", $"Registered event handlers");
    }
Exemplo n.º 2
0
    public override void Setup(SyncObject syncObject)
    {
        obj  = syncObject;
        node = obj.Node;

        obj.RegisterEventHandler("collisionStart", OnCollisionStart);
        obj.WriteDebugLog("objectMoveButton", $"Registered event handlers");
    }
Exemplo n.º 3
0
    public void RegisterHandlers()
    {
        // Search event handlers
        foreach (var export in Module.Exports.Where(ex => ex.Kind == WebAssembly.ExternalKind.Function))
        {
            // Event handlers should have names like handle_EVENTNAME
            if (!export.Name.StartsWith("handle_"))
            {
                continue;
            }
            string funcName  = export.Name;
            string eventName = export.Name.Substring("handle_".Length);
            // signature check
            // (event handlers should have signatures "void handle_EVENTNAME(i32 sender)")
            // Because function index space counts imported functions,
            // we have to subtract the number of imported functions before getting a Function from Module.Functions.
            //  See:
            //      https://webassembly.github.io/spec/core/syntax/modules.html#syntax-funcidx
            //      https://webassembly.github.io/spec/core/syntax/modules.html#imports
            var numImportedFuncs = Module.Imports.Count(import => import.Kind == ExternalKind.Function);
            var funcTypeIdx      = Module.Functions[(int)export.Index - numImportedFuncs].Type;
            var funcType         = Module.Types[(int)funcTypeIdx];
            if (funcType.Returns.Count != 0)
            {
                Logger.Error("ObjectWasmRunner", $"{funcName}: An event handler must not have return value.");
                return;
            }
            if (funcType.Parameters.Count != 1 || funcType.Parameters[0] != WebAssemblyValueType.Int32)
            {
                Logger.Error("ObjectWasmRunner", $"{funcName}: An event handler must accept one i32 argument.");
                return;
            }

            // Register as a handler
            // TODO: unregister
            Object.RegisterEventHandler(eventName, (sender, args) => {
                eventArgs          = args;
                insideEventHandler = true;
                CallWasmFuncWithExceptionHandling(funcName, (int)sender);
                insideEventHandler = false;
            });
        }

        // Search "update" function
        WebAssembly.Export updateExport = FindExport("update", WebAssembly.ExternalKind.Function);
        if (updateExport != null)
        {
            // TODO: signature check (update should have "void update(f32 dt)")
            Object.BeforeSync += CallUpdateFunction;
        }
    }
Exemplo n.º 4
0
 public void Setup(SyncObject syncObject)
 {
     syncObject.RegisterEventHandler("clickStart", OnClickStart);
     obj = syncObject;
     ChangeLedState(state);
 }