I am writing a SmileBASIC interpreter, SmileBASIC being a modified version of basic that ran on the official licensed games Petit Computer (DSi) and SmileBASIC (3ds). I need a way to get time in order to recreate the WAIT (number) function, which takes in a number and stops for that amount of time in 1/60ths seconds. It doesn't actually wait, though, it throttles more like, so I need a way to measure when 1/60th of a second has passed, and not add the time it took to execute other running code to that.
I did this with <chrono>, but every time I make a specific completely unrelated string array larger than a couple of strings it returns a constant -2 million something, it's just not working correctly. Is there a good alternative, or does anyone know why it's acting this way?
I did this with <chrono>, but every time I make a specific completely unrelated string array larger than a couple of strings it returns a constant -2 million something, it's just not working correctly. Is there a good alternative, or does anyone know why it's acting this way?
Code:
...
#include <chrono>
...
//Outside my main loop
auto SBStartTime = Clock::now();
//This function returns how long the program has been running in 1/60ths of seconds
long long int getTime(){
auto t2 = Clock::now();
return std::chrono::duration_cast<std::chrono::nanoseconds>(t2-SBStartTime).count() / 16666666.6667;
}
Last edited by jamieyello,