time.odin 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196
  1. // machine generated, do not edit
  2. package sokol_time
  3. /*
  4. sokol_time.h -- simple cross-platform time measurement
  5. Project URL: https://github.com/floooh/sokol
  6. Do this:
  7. #define SOKOL_IMPL or
  8. #define SOKOL_TIME_IMPL
  9. before you include this file in *one* C or C++ file to create the
  10. implementation.
  11. Optionally provide the following defines with your own implementations:
  12. SOKOL_ASSERT(c) - your own assert macro (default: assert(c))
  13. SOKOL_TIME_API_DECL - public function declaration prefix (default: extern)
  14. SOKOL_API_DECL - same as SOKOL_TIME_API_DECL
  15. SOKOL_API_IMPL - public function implementation prefix (default: -)
  16. If sokol_time.h is compiled as a DLL, define the following before
  17. including the declaration or implementation:
  18. SOKOL_DLL
  19. On Windows, SOKOL_DLL will define SOKOL_TIME_API_DECL as __declspec(dllexport)
  20. or __declspec(dllimport) as needed.
  21. void stm_setup();
  22. Call once before any other functions to initialize sokol_time
  23. (this calls for instance QueryPerformanceFrequency on Windows)
  24. uint64_t stm_now();
  25. Get current point in time in unspecified 'ticks'. The value that
  26. is returned has no relation to the 'wall-clock' time and is
  27. not in a specific time unit, it is only useful to compute
  28. time differences.
  29. uint64_t stm_diff(uint64_t new, uint64_t old);
  30. Computes the time difference between new and old. This will always
  31. return a positive, non-zero value.
  32. uint64_t stm_since(uint64_t start);
  33. Takes the current time, and returns the elapsed time since start
  34. (this is a shortcut for "stm_diff(stm_now(), start)")
  35. uint64_t stm_laptime(uint64_t* last_time);
  36. This is useful for measuring frame time and other recurring
  37. events. It takes the current time, returns the time difference
  38. to the value in last_time, and stores the current time in
  39. last_time for the next call. If the value in last_time is 0,
  40. the return value will be zero (this usually happens on the
  41. very first call).
  42. uint64_t stm_round_to_common_refresh_rate(uint64_t duration)
  43. This oddly named function takes a measured frame time and
  44. returns the closest "nearby" common display refresh rate frame duration
  45. in ticks. If the input duration isn't close to any common display
  46. refresh rate, the input duration will be returned unchanged as a fallback.
  47. The main purpose of this function is to remove jitter/inaccuracies from
  48. measured frame times, and instead use the display refresh rate as
  49. frame duration.
  50. NOTE: for more robust frame timing, consider using the
  51. sokol_app.h function sapp_frame_duration()
  52. Use the following functions to convert a duration in ticks into
  53. useful time units:
  54. double stm_sec(uint64_t ticks);
  55. double stm_ms(uint64_t ticks);
  56. double stm_us(uint64_t ticks);
  57. double stm_ns(uint64_t ticks);
  58. Converts a tick value into seconds, milliseconds, microseconds
  59. or nanoseconds. Note that not all platforms will have nanosecond
  60. or even microsecond precision.
  61. Uses the following time measurement functions under the hood:
  62. Windows: QueryPerformanceFrequency() / QueryPerformanceCounter()
  63. MacOS/iOS: mach_absolute_time()
  64. emscripten: emscripten_get_now()
  65. Linux+others: clock_gettime(CLOCK_MONOTONIC)
  66. zlib/libpng license
  67. Copyright (c) 2018 Andre Weissflog
  68. This software is provided 'as-is', without any express or implied warranty.
  69. In no event will the authors be held liable for any damages arising from the
  70. use of this software.
  71. Permission is granted to anyone to use this software for any purpose,
  72. including commercial applications, and to alter it and redistribute it
  73. freely, subject to the following restrictions:
  74. 1. The origin of this software must not be misrepresented; you must not
  75. claim that you wrote the original software. If you use this software in a
  76. product, an acknowledgment in the product documentation would be
  77. appreciated but is not required.
  78. 2. Altered source versions must be plainly marked as such, and must not
  79. be misrepresented as being the original software.
  80. 3. This notice may not be removed or altered from any source
  81. distribution.
  82. */
  83. import "core:c"
  84. _ :: c
  85. SOKOL_DEBUG :: #config(SOKOL_DEBUG, ODIN_DEBUG)
  86. DEBUG :: #config(SOKOL_TIME_DEBUG, SOKOL_DEBUG)
  87. USE_GL :: #config(SOKOL_USE_GL, false)
  88. USE_DLL :: #config(SOKOL_DLL, false)
  89. when ODIN_OS == .Windows {
  90. when USE_DLL {
  91. when USE_GL {
  92. when DEBUG { foreign import sokol_time_clib { "../sokol_dll_windows_x64_gl_debug.lib" } }
  93. else { foreign import sokol_time_clib { "../sokol_dll_windows_x64_gl_release.lib" } }
  94. } else {
  95. when DEBUG { foreign import sokol_time_clib { "../sokol_dll_windows_x64_d3d11_debug.lib" } }
  96. else { foreign import sokol_time_clib { "../sokol_dll_windows_x64_d3d11_release.lib" } }
  97. }
  98. } else {
  99. when USE_GL {
  100. when DEBUG { foreign import sokol_time_clib { "sokol_time_windows_x64_gl_debug.lib" } }
  101. else { foreign import sokol_time_clib { "sokol_time_windows_x64_gl_release.lib" } }
  102. } else {
  103. when DEBUG { foreign import sokol_time_clib { "sokol_time_windows_x64_d3d11_debug.lib" } }
  104. else { foreign import sokol_time_clib { "sokol_time_windows_x64_d3d11_release.lib" } }
  105. }
  106. }
  107. } else when ODIN_OS == .Darwin {
  108. when USE_DLL {
  109. when USE_GL && ODIN_ARCH == .arm64 && DEBUG { foreign import sokol_time_clib { "../dylib/sokol_dylib_macos_arm64_gl_debug.dylib" } }
  110. else when USE_GL && ODIN_ARCH == .arm64 && !DEBUG { foreign import sokol_time_clib { "../dylib/sokol_dylib_macos_arm64_gl_release.dylib" } }
  111. else when USE_GL && ODIN_ARCH == .amd64 && DEBUG { foreign import sokol_time_clib { "../dylib/sokol_dylib_macos_x64_gl_debug.dylib" } }
  112. else when USE_GL && ODIN_ARCH == .amd64 && !DEBUG { foreign import sokol_time_clib { "../dylib/sokol_dylib_macos_x64_gl_release.dylib" } }
  113. else when !USE_GL && ODIN_ARCH == .arm64 && DEBUG { foreign import sokol_time_clib { "../dylib/sokol_dylib_macos_arm64_metal_debug.dylib" } }
  114. else when !USE_GL && ODIN_ARCH == .arm64 && !DEBUG { foreign import sokol_time_clib { "../dylib/sokol_dylib_macos_arm64_metal_release.dylib" } }
  115. else when !USE_GL && ODIN_ARCH == .amd64 && DEBUG { foreign import sokol_time_clib { "../dylib/sokol_dylib_macos_x64_metal_debug.dylib" } }
  116. else when !USE_GL && ODIN_ARCH == .amd64 && !DEBUG { foreign import sokol_time_clib { "../dylib/sokol_dylib_macos_x64_metal_release.dylib" } }
  117. } else {
  118. when USE_GL {
  119. when ODIN_ARCH == .arm64 {
  120. when DEBUG { foreign import sokol_time_clib { "sokol_time_macos_arm64_gl_debug.a" } }
  121. else { foreign import sokol_time_clib { "sokol_time_macos_arm64_gl_release.a" } }
  122. } else {
  123. when DEBUG { foreign import sokol_time_clib { "sokol_time_macos_x64_gl_debug.a" } }
  124. else { foreign import sokol_time_clib { "sokol_time_macos_x64_gl_release.a" } }
  125. }
  126. } else {
  127. when ODIN_ARCH == .arm64 {
  128. when DEBUG { foreign import sokol_time_clib { "sokol_time_macos_arm64_metal_debug.a" } }
  129. else { foreign import sokol_time_clib { "sokol_time_macos_arm64_metal_release.a" } }
  130. } else {
  131. when DEBUG { foreign import sokol_time_clib { "sokol_time_macos_x64_metal_debug.a" } }
  132. else { foreign import sokol_time_clib { "sokol_time_macos_x64_metal_release.a" } }
  133. }
  134. }
  135. }
  136. } else when ODIN_OS == .Linux {
  137. when USE_DLL {
  138. when DEBUG { foreign import sokol_time_clib { "sokol_time_linux_x64_gl_debug.so" } }
  139. else { foreign import sokol_time_clib { "sokol_time_linux_x64_gl_release.so" } }
  140. } else {
  141. when DEBUG { foreign import sokol_time_clib { "sokol_time_linux_x64_gl_debug.a" } }
  142. else { foreign import sokol_time_clib { "sokol_time_linux_x64_gl_release.a" } }
  143. }
  144. } else when ODIN_ARCH == .wasm32 || ODIN_ARCH == .wasm64p32 {
  145. // Feed sokol_time_wasm_gl_debug.a or sokol_time_wasm_gl_release.a into emscripten compiler.
  146. foreign import sokol_time_clib { "env.o" }
  147. } else {
  148. #panic("This OS is currently not supported")
  149. }
  150. @(default_calling_convention="c", link_prefix="stm_")
  151. foreign sokol_time_clib {
  152. setup :: proc() ---
  153. now :: proc() -> u64 ---
  154. diff :: proc(new_ticks: u64, old_ticks: u64) -> u64 ---
  155. since :: proc(start_ticks: u64) -> u64 ---
  156. laptime :: proc(last_time: ^u64) -> u64 ---
  157. round_to_common_refresh_rate :: proc(frame_ticks: u64) -> u64 ---
  158. sec :: proc(ticks: u64) -> f64 ---
  159. ms :: proc(ticks: u64) -> f64 ---
  160. us :: proc(ticks: u64) -> f64 ---
  161. ns :: proc(ticks: u64) -> f64 ---
  162. }