ci-platforms / darwin amd64 smoke (push) Skipped
GitHub / linux amd64 native GitHub-hosted native CI: success
ci-platforms / windows amd64 smoke (push) Skipped
GitHub / windows amd64 native GitHub-hosted native CI: success
GitHub / darwin arm64 native GitHub-hosted native CI: success
GitHub / darwin amd64 native GitHub-hosted native CI: success
ci / checks (push) Failing after 1h21m34s
ci / native-authoring (push) Skipped
ci-platforms / darwin arm64 smoke (push) Skipped
github-native / gitea-pending (push) Skipped
github-native / darwin amd64 native (push) Skipped
github-native / linux amd64 native (push) Skipped
github-native / windows amd64 native (push) Skipped
github-native / darwin arm64 native (push) Skipped
github-native / gitea-result (push) Skipped
ci / build (amd64, linux, ubuntu-24.04) (push) Successful in 12m4s
ci / release (push) Skipped
Add dockable Art tools, animation and previews, guarded asset workflows, and the Web Asset Studio built on the shared Art Core. Expand English and Russian documentation, interactive Try scenes, examples and editor icons. Add audio waveform navigation, source analysis, guarded previews and a browser Worker mixer. Preserve source changes and recovery with bounded checks, and strengthen native, browser and interoperability CI. Prepare version 0.12.5 and manually built native artifact candidates. Fix the production site image demo build dependency. Reuse immutable scene indices when capturing keyframes. Wait for real Persist save/load completion in component tests. Stabilize browser Game View captures outside pointer hover. Aseprite interchange and persistent Audio EDL recovery remain limited; the artifact workflow does not publish releases or change stable.
85 lines
2.3 KiB
Go
85 lines
2.3 KiB
Go
package pump
|
|
|
|
import (
|
|
"math/bits"
|
|
"syscall"
|
|
"time"
|
|
"unsafe"
|
|
)
|
|
|
|
var perfClock = newPerformanceClock()
|
|
|
|
type performanceClock struct {
|
|
counter uintptr
|
|
frequency int64
|
|
}
|
|
|
|
// Go's Windows monotonic clock uses interrupt time, whose resolution can be
|
|
// coarser than a mix block. QPC measures those blocks without inventing a
|
|
// minimum duration. Keep a Go clock reading as a fallback if QPC fails.
|
|
type mixTimer struct {
|
|
start time.Time
|
|
ticks int64
|
|
qpc bool
|
|
}
|
|
|
|
func newPerformanceClock() performanceClock {
|
|
kernel32 := syscall.NewLazyDLL("kernel32.dll")
|
|
counter := kernel32.NewProc("QueryPerformanceCounter")
|
|
frequencyProc := kernel32.NewProc("QueryPerformanceFrequency")
|
|
if counter.Find() != nil || frequencyProc.Find() != nil {
|
|
return performanceClock{}
|
|
}
|
|
var frequency int64
|
|
ok, _, _ := syscall.SyscallN(frequencyProc.Addr(), uintptr(unsafe.Pointer(&frequency)))
|
|
if ok == 0 || frequency <= 0 {
|
|
return performanceClock{}
|
|
}
|
|
return performanceClock{counter: counter.Addr(), frequency: frequency}
|
|
}
|
|
|
|
func performanceTicks() (int64, bool) {
|
|
var ticks int64
|
|
// SyscallN keeps the pointer alive for the call without forcing a heap
|
|
// allocation for each block, unlike LazyProc.Call.
|
|
ok, _, _ := syscall.SyscallN(perfClock.counter, uintptr(unsafe.Pointer(&ticks)))
|
|
return ticks, ok != 0 && ticks >= 0
|
|
}
|
|
|
|
func startMixTimer() mixTimer {
|
|
t := mixTimer{start: time.Now()}
|
|
if perfClock.frequency > 0 {
|
|
t.ticks, t.qpc = performanceTicks()
|
|
}
|
|
return t
|
|
}
|
|
|
|
func (t mixTimer) elapsed() time.Duration {
|
|
if t.qpc {
|
|
if end, ok := performanceTicks(); ok && end >= t.ticks {
|
|
return counterDuration(end-t.ticks, perfClock.frequency)
|
|
}
|
|
}
|
|
return time.Since(t.start)
|
|
}
|
|
|
|
// counterDuration converts a difference of counter readings, not an absolute
|
|
// uptime, to avoid overflow. Saturate if the elapsed time exceeds Duration.
|
|
func counterDuration(ticks, frequency int64) time.Duration {
|
|
if ticks <= 0 || frequency <= 0 {
|
|
return 0
|
|
}
|
|
const maxDuration = time.Duration(1<<63 - 1)
|
|
seconds := ticks / frequency
|
|
if seconds > int64(maxDuration/time.Second) {
|
|
return maxDuration
|
|
}
|
|
hi, lo := bits.Mul64(uint64(ticks%frequency), uint64(time.Second))
|
|
nanoseconds, _ := bits.Div64(hi, lo, uint64(frequency))
|
|
d := time.Duration(seconds) * time.Second
|
|
if time.Duration(nanoseconds) > maxDuration-d {
|
|
return maxDuration
|
|
}
|
|
return d + time.Duration(nanoseconds)
|
|
}
|