plane icon Welcome to Microsoft Flight Simulator’s SDK Q&A Platform!

You have questions regarding the SDK? DevMode Tools? SimConnect? You would like to submit an idea for future improvements, seek help or exchange knowledge? You’re in the right place.


Please take a moment to read the platform’s guidelines before you get started!


question

JohnLDowson avatar image
JohnLDowson asked JohnLDowson commented

How to get a timestamp (or tick count) in a WASM module?

Is there a method to get a timestamp or tick-count in a WASM module (standalone) to millisecond resolution?
I get a runtime error when trying to use clock():

WASM: Error ERR_ILLEGAL_C_IMPORT: env:clock is not a whitelisted C import, nor a valid webassembly import.

and GetTickCount() doesn't seem to be available either.

Thanks in Advance.

wasm
2 comments
10 |10000

Up to 5 attachments (including images) can be used with a maximum of 4.8 MiB each and 23.8 MiB total.

Simbol avatar image Simbol commented ·
Use the simulator seconds counter...


Raul

0 Likes 0 ·
JohnLDowson avatar image JohnLDowson Simbol commented ·
Need milliseconds....
0 Likes 0 ·

1 Answer

·
davux3 avatar image
davux3 answered JohnLDowson commented

Try this:

auto now_miliseconds = std::chrono::duration_cast<std::chrono::milliseconds>(std::chrono::system_clock::now().time_since_epoch()).count();

1 comment
10 |10000

Up to 5 attachments (including images) can be used with a maximum of 4.8 MiB each and 23.8 MiB total.

JohnLDowson avatar image JohnLDowson commented ·
Works perfectly - thanks!
1 Like 1 ·

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 5 attachments (including images) can be used with a maximum of 19.1 MiB each and 23.8 MiB total.