Home /Modules/user-interface/SLFrameClock.sleela

SLFrameClock.sleela

lib/user-interface/SLFrameClock.sleela · 99 line(s) · sleela

<< lib/user-interface/SLFrameClock.sleela
   SLeeLa Standard Library Definition.
   Definition: Defines SLFrameClock — the SLeeLa binding of the SleelaUI Draw
     API's refresh-rate controller. It paces a render loop: a target rate (FPS),
     a per-frame delta time, an elapsed animation clock, a smoothed measured
     rate, a sleep hint so the loop idles instead of busy-spinning, and a
     fixed-timestep accumulator for deterministic field/physics updates
     regardless of frame rate. Every method bottoms out in a `draw*` SLVM
     built-in that calls the genuine frame-clock API.
   
   Typical loop:
       SLFrameClock fc = new SLFrameClock(); fc.create(60.0);
       while (running) {
         double dt = fc.tick();
         update(dt);
         draw(dc); dc.present();
         int ms = fc.sleepHint(); if (ms > 0) host.sleep(ms);
       }
   
   A frame clock is a VM-local handle (-1 = none).
   
   Family: user-interface. Native VM/UI work crosses the explicit `draw*` SLVM
   bridge. >>
#sleela 2.5
material;
class SLFrameClock {
  < ---- Descriptive metadata (version 1.11 nested-friendly accessors) ---- >
  << Eleven catalogued attributes with getter/setter pairs, so a GUI, loader,
     or catalog can read and (where appropriate) override this record.
     Values are faithful to the subject's real origin where publicly known. >>
  String metaVersion = "1.0.0";
  int metaId = 10366;
  String metaAuthor = "Kiro Agent";
  String metaDate = "2026-10-16";
  String metaCopyright = "SLeeLa project";
  String metaTrademark = "none";
  String metaCorporation = "none";
  < metaOrigin: National | <nation> | International | Galactic >
  String metaOrigin = "International";
  String metaBirthDate = "2026-10-07";
  < metaScienceRating: maturity/robustness on a 1..10 scale >
  int metaScienceRating = 9;
  < metaNationalSchedule: a real, citable instrument or "none" >
  String metaNationalSchedule = "none";

  String getMetaVersion() { return metaVersion; }
  void setMetaVersion(String v) { metaVersion = v; }
  int getMetaId() { return metaId; }
  void setMetaId(int v) { metaId = v; }
  String getAuthor() { return metaAuthor; }
  void setAuthor(String v) { metaAuthor = v; }
  String getDate() { return metaDate; }
  void setDate(String v) { metaDate = v; }
  String getCopyright() { return metaCopyright; }
  void setCopyright(String v) { metaCopyright = v; }
  String getTrademark() { return metaTrademark; }
  void setTrademark(String v) { metaTrademark = v; }
  String getCorporation() { return metaCorporation; }
  void setCorporation(String v) { metaCorporation = v; }
  String getOrigin() { return metaOrigin; }
  void setOrigin(String v) { metaOrigin = v; }
  String getBirthDate() { return metaBirthDate; }
  void setBirthDate(String v) { metaBirthDate = v; }
  int getScienceRating() { return metaScienceRating; }
  void setScienceRating(int v) { metaScienceRating = v; }
  String getNationalSchedule() { return metaNationalSchedule; }
  void setNationalSchedule(String v) { metaNationalSchedule = v; }
  < VM-local frame-clock handle (-1 = none) >
  int fc;

  < Create a frame clock with a target refresh rate (0 = unthrottled). >
  void create(double targetFps) { fc = drawClockCreate(targetFps); }
  int handle() { return fc; }
  boolean valid() { return fc >= 0; }
  void destroy() { if (fc >= 0) { drawClockDestroy(fc); fc = -1; } }

  void setFps(double targetFps) { if (fc >= 0) { drawClockSetFps(fc, targetFps); } }
  double fps() { if (fc < 0) { return 0.0; } return drawClockGetFps(fc); }

  < Advance one frame; returns the delta time in seconds since the last tick. >
  double tick() { if (fc < 0) { return 0.0; } return drawClockTick(fc); }

  < Seconds since the clock was created (monotonic animation time). >
  double elapsed() { if (fc < 0) { return 0.0; } return drawClockElapsed(fc); }

  < The smoothed frames-per-second actually being achieved. >
  double measuredFps() { if (fc < 0) { return 0.0; } return drawClockMeasuredFps(fc); }

  < Milliseconds the caller should idle to hit the target rate (0 if behind). >
  int sleepHint() { if (fc < 0) { return 0; } return drawClockSleepHint(fc); }

  < Fixed-timestep drain: after tick(), call repeatedly, running one fixed >
  < `step`-second update each time it returns true, until it returns false. >
  boolean fixedStep(double step) {
    if (fc < 0) { return false; }
    return drawClockFixedStep(fc, step) == 1;
  }
}