Add movement relative to time
Previously movement was based on frames rather than time. I added time_get_dt() function for getting time since last frame and changed rotation speed to use this function. Signed-off-by: Piotr Krygier <piotrkrygier@everyonecancode@xyz>
This commit is contained in:
@@ -1,9 +1,33 @@
|
||||
#include "time_utils.h"
|
||||
#include <stdint.h>
|
||||
#include "SDL3/SDL_timer.h"
|
||||
#include "commons.h"
|
||||
#include "errors_common.h"
|
||||
|
||||
#define NS_TO_S(time) (time/1000000000)
|
||||
double g_last_time = 0.0;
|
||||
|
||||
rse_err_t time_init(void)
|
||||
{
|
||||
g_last_time = NS_TO_S((double)SDL_GetTicksNS());
|
||||
|
||||
return RSE_ERROR_NO_ERROR;
|
||||
}
|
||||
|
||||
double time_get_sec_from_start(void)
|
||||
{
|
||||
return NS_TO_S((double)SDL_GetTicksNS());
|
||||
}
|
||||
|
||||
void time_update(void)
|
||||
{
|
||||
g_last_time = NS_TO_S((double)SDL_GetTicksNS());
|
||||
}
|
||||
|
||||
double time_get_dt(void)
|
||||
{
|
||||
float time = NS_TO_S((double)SDL_GetTicksNS());
|
||||
float dt = time - g_last_time;
|
||||
|
||||
return dt;
|
||||
}
|
||||
|
||||
@@ -12,6 +12,13 @@
|
||||
#ifndef TIME_UTILS_H_
|
||||
#define TIME_UTILS_H_
|
||||
|
||||
#include "commons.h"
|
||||
|
||||
rse_err_t time_init(void);
|
||||
void time_update(void);
|
||||
|
||||
double time_get_sec_from_start(void);
|
||||
|
||||
double time_get_dt(void);
|
||||
|
||||
#endif // !TIME_UTILS_H_
|
||||
|
||||
Reference in New Issue
Block a user