wasm.timer.api.pas 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. {
  2. This file is part of the Free Component Library
  3. Webassembly Timer API - imported functions and structures.
  4. Copyright (c) 2024 by Michael Van Canneyt [email protected]
  5. See the file COPYING.FPC, included in this distribution,
  6. for details about the copyright.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. **********************************************************************}
  11. unit wasm.timer.api;
  12. {$mode ObjFPC}{$H+}
  13. interface
  14. uses
  15. {$IFDEF FPC_DOTTEDUNITS}
  16. System.SysUtils,
  17. {$ELSE}
  18. SysUtils,
  19. {$ENDIF}
  20. wasm.logger.api, wasm.timer.shared;
  21. Type
  22. TWasmTimerTickEvent = Procedure (aTimerID : TWasmTimerID; userdata : pointer; var aContinue : Boolean);
  23. TDomHighResolutionTimeStamp = Double;
  24. PDomHighResolutionTimeStamp = ^TDomHighResolutionTimeStamp;
  25. function __wasm_timer_allocate(ainterval : longint; userdata: pointer) : TWasmTimerID; external TimerExportName name TimerFN_allocate;
  26. procedure __wasm_timer_deallocate(timerid: TWasmTimerID); external TimerExportName name TimerFN_Deallocate;
  27. function __wasm_timer_tick(timerid: TWasmTimerID; userdata : pointer) : boolean;
  28. function __wasm_timer_performance_now(aNow : PDomHighResolutionTimeStamp) : Longint; external TimerExportName name TimerFN_Performance_Now;
  29. procedure __wasmtimer_log(level : TWasmLogLevel; const Msg : String);
  30. procedure __wasmtimer_log(level : TWasmLogLevel; const Fmt : String; Args : Array of const);
  31. var
  32. OnWasmTimerTick : TWasmTimerTickEvent;
  33. WasmTimerLogEnabled : Boolean;
  34. implementation
  35. function __wasm_timer_tick(timerid: TWasmTimerID; userdata : pointer) : boolean;
  36. begin
  37. Result:=True;
  38. if assigned(OnWasmTimerTick) then
  39. OnWasmTimerTick(timerid,userdata,Result)
  40. else
  41. Result:=False;
  42. end;
  43. procedure __wasmtimer_log(level : TWasmLogLevel; const Msg : String);
  44. begin
  45. if not WasmTimerLogEnabled then
  46. exit;
  47. __wasm_log(level,'timer',msg);
  48. end;
  49. procedure __wasmtimer_log(level : TWasmLogLevel; const Fmt : String; Args : Array of const);
  50. begin
  51. if not WasmTimerLogEnabled then
  52. exit;
  53. __wasm_log(level,'timer',fmt,args);
  54. end;
  55. exports __wasm_timer_tick;
  56. end.