Constant Delta Time set to 60 FPS
This commit is contained in:
parent
b3c40d60a3
commit
a0d8da2776
@ -15,7 +15,8 @@ Vec2F32 g_projected_points[POINTS];
|
|||||||
Vec3F32 camera_position = {.x = 0, .y = 0, .z = -5};
|
Vec3F32 camera_position = {.x = 0, .y = 0, .z = -5};
|
||||||
Vec3F32 cube_rotation = {.x = 0, .y = 0, .z = 0};
|
Vec3F32 cube_rotation = {.x = 0, .y = 0, .z = 0};
|
||||||
|
|
||||||
int is_running;
|
s32 is_running;
|
||||||
|
s32 previous_frame_time = 0;
|
||||||
|
|
||||||
// Perspective Projection (perspective divide)
|
// Perspective Projection (perspective divide)
|
||||||
// Formula
|
// Formula
|
||||||
@ -69,6 +70,13 @@ void process_input(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void update(void) {
|
void update(void) {
|
||||||
|
// while(!SDL_TICKS_PASSED(SDL_GetTicks(), previous_frame_time + FRAME_TARGET_TIME)); // NOTE(tijani): SLOWWWW!!!!
|
||||||
|
s32 time_to_wait = FRAME_TARGET_TIME - (SDL_GetTicks() - previous_frame_time);
|
||||||
|
if (time_to_wait > 0 && time_to_wait <= FRAME_TARGET_TIME) {
|
||||||
|
SDL_Delay(time_to_wait);
|
||||||
|
}
|
||||||
|
// previous_frame_time = SDL_GetTicks(); // NOTE(tijani): SLOWWW!!! because it locks the OS into this.
|
||||||
|
|
||||||
cube_rotation.x += 0.01;
|
cube_rotation.x += 0.01;
|
||||||
cube_rotation.y += 0.01;
|
cube_rotation.y += 0.01;
|
||||||
cube_rotation.z += 0.01;
|
cube_rotation.z += 0.01;
|
||||||
|
@ -3,6 +3,9 @@
|
|||||||
|
|
||||||
#include <SDL.h>
|
#include <SDL.h>
|
||||||
|
|
||||||
|
#define FPS 60
|
||||||
|
#define FRAME_TARGET_TIME (1000 / FPS)
|
||||||
|
|
||||||
SDL_Window *window = NULL;
|
SDL_Window *window = NULL;
|
||||||
SDL_Renderer *renderer = NULL;
|
SDL_Renderer *renderer = NULL;
|
||||||
SDL_Texture *colour_buffer_texture = NULL;
|
SDL_Texture *colour_buffer_texture = NULL;
|
||||||
|
Loading…
Reference in New Issue
Block a user