Add pause and fast-forward keys
This commit is contained in:
parent
6b593960b4
commit
c0c028ec12
33
main.c
33
main.c
@ -27,6 +27,8 @@
|
|||||||
|
|
||||||
#define MAX_SHADER_SIZE (8 * 1024)
|
#define MAX_SHADER_SIZE (8 * 1024)
|
||||||
|
|
||||||
|
#define FASTFORWARD_RATE 100
|
||||||
|
|
||||||
#if defined(CPOW_DTHETA) && defined(POWRATE)
|
#if defined(CPOW_DTHETA) && defined(POWRATE)
|
||||||
#error "Cannot define CPOW_DTHETA and POWRATE simulataneously"
|
#error "Cannot define CPOW_DTHETA and POWRATE simulataneously"
|
||||||
#endif
|
#endif
|
||||||
@ -94,6 +96,8 @@ static params_t params = {
|
|||||||
.scale = STARTSCALE,
|
.scale = STARTSCALE,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
static bool paused = false, fastforward = false;
|
||||||
|
|
||||||
static void
|
static void
|
||||||
mouse_button_callback(GLFWwindow *window, int button, int action, int mods)
|
mouse_button_callback(GLFWwindow *window, int button, int action, int mods)
|
||||||
{
|
{
|
||||||
@ -119,6 +123,27 @@ mouse_button_callback(GLFWwindow *window, int button, int action, int mods)
|
|||||||
params.centre.im = zy;
|
params.centre.im = zy;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void
|
||||||
|
key_callback(GLFWwindow *window, int key, int scancode, int action, int mods)
|
||||||
|
{
|
||||||
|
(void)window;
|
||||||
|
(void)scancode;
|
||||||
|
(void)mods;
|
||||||
|
|
||||||
|
switch (key) {
|
||||||
|
case GLFW_KEY_SPACE:
|
||||||
|
if (action == GLFW_PRESS)
|
||||||
|
paused = !paused;
|
||||||
|
break;
|
||||||
|
case GLFW_KEY_F:
|
||||||
|
if (action == GLFW_PRESS)
|
||||||
|
fastforward = true;
|
||||||
|
else if (action == GLFW_RELEASE)
|
||||||
|
fastforward = false;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static VkShaderModule load_shader_module(VkDevice dev, const char *path)
|
static VkShaderModule load_shader_module(VkDevice dev, const char *path)
|
||||||
{
|
{
|
||||||
static char buf[MAX_SHADER_SIZE]
|
static char buf[MAX_SHADER_SIZE]
|
||||||
@ -153,8 +178,9 @@ int main(void)
|
|||||||
mode->width, mode->height, "GPU Fractal", monitor, NULL);
|
mode->width, mode->height, "GPU Fractal", monitor, NULL);
|
||||||
assert(window);
|
assert(window);
|
||||||
|
|
||||||
// Register mouse click callback
|
// Register input callbacks
|
||||||
glfwSetMouseButtonCallback(window, mouse_button_callback);
|
glfwSetMouseButtonCallback(window, mouse_button_callback);
|
||||||
|
glfwSetKeyCallback(window, key_callback);
|
||||||
|
|
||||||
// Initialise Vulkan instance.
|
// Initialise Vulkan instance.
|
||||||
const VkApplicationInfo app_info = {
|
const VkApplicationInfo app_info = {
|
||||||
@ -646,6 +672,10 @@ int main(void)
|
|||||||
result = vkQueuePresentKHR(queue, &present_info);
|
result = vkQueuePresentKHR(queue, &present_info);
|
||||||
assert(result == VK_SUCCESS);
|
assert(result == VK_SUCCESS);
|
||||||
|
|
||||||
|
if (paused)
|
||||||
|
continue;
|
||||||
|
|
||||||
|
for (int i = 0; i < (fastforward ? FASTFORWARD_RATE : 1); ++i) {
|
||||||
#ifdef JULIA_DTHETA
|
#ifdef JULIA_DTHETA
|
||||||
double complex julia = params.julia.re + I * params.julia.im;
|
double complex julia = params.julia.re + I * params.julia.im;
|
||||||
julia *= julia_rotz;
|
julia *= julia_rotz;
|
||||||
@ -667,6 +697,7 @@ int main(void)
|
|||||||
#ifdef POWRATE
|
#ifdef POWRATE
|
||||||
params.zpow += POWRATE;
|
params.zpow += POWRATE;
|
||||||
#endif
|
#endif
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
vkDeviceWaitIdle(dev);
|
vkDeviceWaitIdle(dev);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user