Add time function
Updates to objects should not be done in frame by frame basis, but by time difference. This commit adds time diff function which can be used to tell how much time has passed since last frame.
This commit is contained in:
1 parent
863f502dde
commit
0ef475e57e
3 files changed
+34
-3
No files matched your search
@@ -562,13 +562,13 @@ uint8_t init_vulkan()
|
|||||||
STATUS_CHECK(create_descriptors());
|
STATUS_CHECK(create_descriptors());
|
||||||
|
|
||||||
STATUS_CHECK(create_sync_objects());
|
STATUS_CHECK(create_sync_objects());
|
||||||
|
|
||||||
|
rse_init_time();
|
||||||
return status;
|
return status;
|
||||||
}
|
}
|
||||||
|
|
||||||
void draw_frame()
|
void draw_frame()
|
||||||
{
|
{
|
||||||
vkWaitForFences(g_vulkan_state.device, 1, &g_in_flight_fences[g_vulkan_state.current_frame], VK_TRUE, UINT64_MAX);
|
|
||||||
|
|
||||||
uint32_t image_index = 0U;
|
uint32_t image_index = 0U;
|
||||||
VkResult result = VK_FALSE;
|
VkResult result = VK_FALSE;
|
||||||
VkSubmitInfo submit_info = {};
|
VkSubmitInfo submit_info = {};
|
||||||
@@ -578,6 +578,10 @@ void draw_frame()
|
|||||||
VkPresentInfoKHR present_info = {};
|
VkPresentInfoKHR present_info = {};
|
||||||
VkSwapchainKHR swap_chains[1];
|
VkSwapchainKHR swap_chains[1];
|
||||||
|
|
||||||
|
vkWaitForFences(g_vulkan_state.device, 1, &g_in_flight_fences[g_vulkan_state.current_frame], VK_TRUE, UINT64_MAX);
|
||||||
|
|
||||||
|
rse_update_time();
|
||||||
|
|
||||||
result = vkAcquireNextImageKHR(g_vulkan_state.device, g_vulkan_state.swapchain, UINT64_MAX, g_image_available_semaphores[g_vulkan_state.current_frame],
|
result = vkAcquireNextImageKHR(g_vulkan_state.device, g_vulkan_state.swapchain, UINT64_MAX, g_image_available_semaphores[g_vulkan_state.current_frame],
|
||||||
VK_NULL_HANDLE, &image_index);
|
VK_NULL_HANDLE, &image_index);
|
||||||
|
|
||||||
|
|||||||
@@ -1,3 +1,26 @@
|
|||||||
#include "vulkan_commons.h"
|
#include "vulkan_commons.h"
|
||||||
|
|
||||||
struct rse_vulkan_state_t g_vulkan_state;
|
#include <time.h>
|
||||||
|
|
||||||
|
struct rse_vulkan_state_t g_vulkan_state;
|
||||||
|
|
||||||
|
time_t g_last_frame_time;
|
||||||
|
time_t g_this_frame_time;
|
||||||
|
float g_float_delta_time;
|
||||||
|
|
||||||
|
void rse_init_time()
|
||||||
|
{
|
||||||
|
time(&g_last_frame_time);
|
||||||
|
}
|
||||||
|
|
||||||
|
void rse_update_time()
|
||||||
|
{
|
||||||
|
g_last_frame_time = g_this_frame_time;
|
||||||
|
time(&g_this_frame_time);
|
||||||
|
g_float_delta_time = (float)difftime(g_this_frame_time, g_last_frame_time);
|
||||||
|
}
|
||||||
|
|
||||||
|
float inline rse_get_time_diff()
|
||||||
|
{
|
||||||
|
return g_float_delta_time;
|
||||||
|
}
|
||||||
@@ -79,4 +79,8 @@ struct rse_instance_data_t {
|
|||||||
float scale;
|
float scale;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void rse_init_time();
|
||||||
|
void rse_update_time();
|
||||||
|
float inline rse_get_time_diff();
|
||||||
|
|
||||||
#endif /* RSE_VULKAN_GLOBAL_H */
|
#endif /* RSE_VULKAN_GLOBAL_H */
|
||||||
Reference in new issue
Block a user