protected IshtarTestBase() { if (VM.watcher is DefaultWatchDog) { VM.watcher = new TestWatchDog(); } AppVault.CurrentVault ??= new AppVault("<test-app>"); lock (guarder) { if (!isInited) { VeinCore.Init(); IshtarGC.INIT(); FFI.INIT(); _corlib = LoadCorLib(); IshtarCore.INIT_ADDITIONAL_MAPPING(); foreach (var @class in VeinCore.All.OfType <RuntimeIshtarClass>()) { @class.init_vtable(); } // ReSharper disable once VirtualMemberCallInConstructor StartUp(); isInited = true; } } }
void Update() { FFI.Update update = FFI.readNextUpdate(); Debug.Log(string.Format("Update: {0} {1} {2}", update.type, update.id, update.position)); switch (update.type) { case FFI.UpdateType.Connect: sparkles.Add(update.id, Instantiate(sparklePrefab)); break; case FFI.UpdateType.Disconnect: Destroy(sparkles[update.id].gameObject); sparkles.Remove(update.id); break; case FFI.UpdateType.Position: sparkles[update.id].position = update.position; break; default: break; } }
void Update() { if (Input.GetMouseButton(0)) { Vector3 projectedPosition = Camera.main.ScreenToWorldPoint(Input.mousePosition); FFI.sendPositionUpdate(projectedPosition); } }
void Start() { sparkles = new Dictionary <UInt32, Transform>(); FFI.connectToServer("0.0.0.0:12345"); FFI.sendStatusUpdate(FFI.StatusUpdate.Connect); Debug.Log("Start"); }
public static void Main(string[] args) { var result = FFI.add_numbers(1, 3); Console.WriteLine("FFI working: " + result); FFI.execute(); Console.WriteLine("done"); }
public static int Cleanup() { // Unregister all our callbacks from the native API Observer.RemoveCallbackUpdate(UpdateDelegate, null); FFI.UnregisterGlobalFunction("StartListening", StartListeningDelegate); FFI.UnregisterGlobalFunction("StopListening", StopListeningDelegate); // zero is cleanup success return(0); }
/// <summary> /// Function registered with VisRen to be called once per frame, we use it to process our queue messages /// and trigger Lua callbacks when speech recognition is complete. /// See https://developers.virtalis.com/blogs/thread-safety-in-visionary-render-plugins /// </summary> /// <param name="dt"></param> /// <param name="ud"></param> public static void Update(double dt, IntPtr ud) { while (MessageQueue.TryDequeue(out var item)) { FFIVarHandle[] args = { FFI.MakeString(item.Callback), FFI.MakeString(item.Param ?? "") }; FFI.Invoke("__callback", args); } }
public static int Init() { // Create a queue to receive completed speech to text results MessageQueue = new ConcurrentQueue <QueueItem>(); // Configure the recognizer. This requires you to have an active Azure Speech to Text service subscription: // https://azure.microsoft.com/en-gb/services/cognitive-services/speech-to-text var config = SpeechConfig.FromSubscription("YOUR_SUBSCRIPTION_KEY", "YOUR_SUBSCRIPTION_REGION"); Recognizer = new SpeechRecognizer(config); // Add a callback to receive recognized text, and queue it up for a Lua callback called "onSpeech", which should be registered by the caller in Lua Recognizer.Recognized += (s, e) => { if (e.Result.Reason == ResultReason.RecognizedSpeech) { Console.WriteLine("Recognized: " + e.Result.Text); MessageQueue.Enqueue(new QueueItem { Callback = "onSpeech", Param = e.Result.Text }); } }; EventHandler <RecognitionEventArgs> MakeEventFunc(string name) => (object s, RecognitionEventArgs e) => MessageQueue.Enqueue(new QueueItem { Callback = name }); // Register some Lua callbacks for the other events we get from the recognizer Recognizer.SessionStarted += (s, e) => MakeEventFunc("onSpeechSessionStarted"); Recognizer.SessionStopped += (s, e) => MakeEventFunc("onSpeechSessionStopped"); Recognizer.SpeechStartDetected += (s, e) => MakeEventFunc("onSpeechStartDetected"); Recognizer.SpeechEndDetected += (s, e) => MakeEventFunc("onSpeechEndDetected"); // Register our Lua function to enable listening StartListeningDelegate = new FFI.FFIFunction(OnStartListening); FFI.RegisterGlobalFunction("StartListening", StartListeningDelegate, 0, IntPtr.Zero); // Register our Lua function to stop listening StopListeningDelegate = new FFI.FFIFunction(OnStopListening); FFI.RegisterGlobalFunction("StopListening", StopListeningDelegate, 0, IntPtr.Zero); // Register our update function for queue processing UpdateDelegate = new Observer.UpdateFunction(Update); Observer.AddCallbackUpdate(UpdateDelegate, IntPtr.Zero); // zero is init success return(0); }
/// <summary> /// Tries to get the information about an fragmented file with a specific hash value. /// </summary> /// <param name="fileHash"> /// The hash value of the content of the file to get the information for. /// </param> /// <param name="fileInfo"> /// When this method returns, contains the <see cref="IFragmentedFileInfo"/> about the file with the /// specified <paramref name="fileHash"/>, if the operation succeeded, or <see langword="null"/> if the /// operation failed. /// </param> /// <returns> /// <see langword="true"/> if the operation succeeded; otherwise, <see langword="false"/>. /// </returns> /// <remarks> /// The operation succeeds if information about the specified file was published to the distribution network. /// </remarks> /// <exception cref="ObjectDisposedException"> /// This method was called after the <see cref="MockDistributionServiceSubscriber"/> was disposed. /// </exception> public bool TryGetFileInfo(string fileHash, [NotNullWhen(true)] out IFragmentedFileInfo?fileInfo) { EnsureStorageProviderWasNotDisposed(); if (ExistsFile(fileHash)) { fileInfo = new FFI() { Hash = this.fileHash, Size = this.fileSize, FragmentSequence = _fragmentSequence }; return(true); } fileInfo = null; return(false); }
static void Main(string[] args) { FFI.CreateContext("Little Polygon C# Demo", 3 * 320, 3 * 115, ""); // PLAY SOME MUSIC var mus = SDL_mixer.Mix_LoadMUS("song.mid"); if (mus != IntPtr.Zero) { SDL_mixer.Mix_PlayMusic(mus, -1); } // BASIC EVENT LOOP var window = SDL.SDL_GL_GetCurrentWindow(); while (!gDone) { HandleEvents(); FFI.ClearScreen(); SDL.SDL_GL_SwapWindow(window); } FFI.DestroyContext(); }
void OnDestroy() { FFI.sendStatusUpdate(FFI.StatusUpdate.Disconnect); FFI.disconnectFromServer(); Debug.Log("Destroy"); }
public static unsafe int Main(string[] args) { ishtar.Trace.init(); //while (!Debugger.IsAttached) // Thread.Sleep(200); Encoding.RegisterProvider(CodePagesEncodingProvider.Instance); if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows)) { Console.OutputEncoding = Encoding.Unicode; } IshtarCore.INIT(); INIT_VTABLES(); IshtarGC.INIT(); FFI.INIT(); AppVault.CurrentVault = new AppVault("app"); var masterModule = default(IshtarAssembly); var resolver = default(AssemblyResolver); if (AssemblyBundle.IsBundle(out var bundle)) { resolver = AppVault.CurrentVault.GetResolver(); masterModule = bundle.Assemblies.First(); resolver.AddInMemory(bundle); } else { if (args.Length < 1) { return(-1); } var entry = new FileInfo(args.First()); if (!entry.Exists) { return(-2); } AppVault.CurrentVault.WorkDirecotry = entry.Directory; resolver = AppVault.CurrentVault.GetResolver(); masterModule = IshtarAssembly.LoadFromFile(entry); resolver.AddSearchPath(entry.Directory); } var module = resolver.Resolve(masterModule); foreach (var @class in module.class_table.OfType <RuntimeIshtarClass>()) { @class.init_vtable(); VM.ValidateLastError(); } var entry_point = module.GetEntryPoint(); if (entry_point is null) { VM.FastFail(WNE.MISSING_METHOD, $"Entry point in '{module.Name}' module is not defined.", IshtarFrames.EntryPoint); VM.ValidateLastError(); return(-280); } var args_ = stackalloc stackval[1]; var frame = new CallFrame { args = args_, method = entry_point, level = 0 }; {// i don't know why IshtarCore.INIT_ADDITIONAL_MAPPING(); INIT_VTABLES(); } var watcher = Stopwatch.StartNew(); VM.exec_method(frame); if (frame.exception is not null) { Console.ForegroundColor = ConsoleColor.Red; Console.WriteLine($"unhandled exception '{frame.exception.value->decodeClass().Name}' was thrown. \n" + $"{frame.exception.stack_trace}"); Console.ForegroundColor = ConsoleColor.White; } watcher.Stop(); Console.WriteLine($"Elapsed: {watcher.Elapsed}"); return(0); }