event-based updates round.2
This commit is contained in:
parent
1f0004f274
commit
7c37c06e4c
@ -40,6 +40,7 @@
|
||||
#include "dep/nanovg.c"
|
||||
|
||||
/* macros */
|
||||
#define DTIME 30
|
||||
#include "../../zahnrad.h"
|
||||
|
||||
static void
|
||||
@ -245,6 +246,7 @@ main(int argc, char *argv[])
|
||||
SDL_Window *win;
|
||||
SDL_GLContext glContext;
|
||||
NVGcontext *vg = NULL;
|
||||
int poll = 1;
|
||||
|
||||
/* GUI */
|
||||
struct demo gui;
|
||||
@ -253,7 +255,7 @@ main(int argc, char *argv[])
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
font_path = argv[1];
|
||||
font_height = 14;
|
||||
font_height = 15;
|
||||
|
||||
/* SDL */
|
||||
SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER|SDL_INIT_EVENTS);
|
||||
@ -292,10 +294,17 @@ main(int argc, char *argv[])
|
||||
|
||||
while (running) {
|
||||
/* Input */
|
||||
int ret;
|
||||
SDL_Event evt;
|
||||
uint64_t dt, started = SDL_GetTicks();
|
||||
|
||||
|
||||
zr_input_begin(&gui.ctx.input);
|
||||
while (SDL_PollEvent(&evt)) {
|
||||
if (!poll) {
|
||||
ret = SDL_WaitEvent(&evt);
|
||||
poll = 1;
|
||||
} else ret = SDL_PollEvent(&evt);
|
||||
while (ret) {
|
||||
if (evt.type == SDL_WINDOWEVENT) resize(&evt);
|
||||
else if (evt.type == SDL_QUIT) goto cleanup;
|
||||
else if (evt.type == SDL_KEYUP) key(&gui.ctx.input, &evt, zr_false);
|
||||
@ -306,6 +315,7 @@ main(int argc, char *argv[])
|
||||
else if (evt.type == SDL_TEXTINPUT) text(&gui.ctx.input, &evt);
|
||||
else if (evt.type == SDL_MOUSEWHEEL)
|
||||
zr_input_scroll(&gui.ctx.input,(float)evt.wheel.y);
|
||||
ret = SDL_PollEvent(&evt);
|
||||
}
|
||||
zr_input_end(&gui.ctx.input);
|
||||
|
||||
@ -317,9 +327,8 @@ main(int argc, char *argv[])
|
||||
glClearColor(0.2f, 0.2f, 0.2f, 1.0f);
|
||||
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
|
||||
draw(vg, &gui.ctx, width, height);
|
||||
dt = SDL_GetTicks() - started;
|
||||
/*fprintf(stdout, "%lu\n", dt);*/
|
||||
SDL_GL_SwapWindow(win);
|
||||
poll = ((poll+1) & 4);
|
||||
}
|
||||
|
||||
cleanup:
|
||||
|
@ -769,9 +769,9 @@ main(int argc, char *argv[])
|
||||
if (!poll) {
|
||||
ret = SDL_WaitEvent(&evt);
|
||||
poll = 1;
|
||||
}
|
||||
} else ret = SDL_PollEvent(&evt);
|
||||
|
||||
while (SDL_PollEvent(&evt)) {
|
||||
while (ret) {
|
||||
if (evt.type == SDL_WINDOWEVENT &&
|
||||
evt.window.event == SDL_WINDOWEVENT_RESIZED)
|
||||
glViewport(0, 0, evt.window.data1, evt.window.data2);
|
||||
@ -790,6 +790,7 @@ main(int argc, char *argv[])
|
||||
text(&ctx.input, &evt);
|
||||
else if (evt.type == SDL_MOUSEWHEEL)
|
||||
zr_input_scroll(&ctx.input, evt.wheel.y);
|
||||
ret = SDL_PollEvent(&evt);
|
||||
}
|
||||
zr_input_end(&ctx.input);
|
||||
|
||||
@ -804,12 +805,7 @@ main(int argc, char *argv[])
|
||||
SDL_GetWindowSize(win, &width, &height);
|
||||
draw(vg, &ctx, width, height);
|
||||
SDL_GL_SwapWindow(win);
|
||||
poll = (!((poll+1) & 4));
|
||||
|
||||
/* Timing */
|
||||
dt = SDL_GetTicks() - started;
|
||||
if (dt < DTIME)
|
||||
SDL_Delay(DTIME - dt);
|
||||
poll = ((poll+1) & 4);
|
||||
}
|
||||
|
||||
cleanup:
|
||||
|
@ -830,14 +830,15 @@ main(int argc, char *argv[])
|
||||
|
||||
while (running) {
|
||||
/* Input */
|
||||
int ret;
|
||||
SDL_Event evt;
|
||||
if (!poll) {
|
||||
SDL_WaitEvent(&evt);
|
||||
poll = 1;
|
||||
}
|
||||
|
||||
zr_input_begin(&ctx.input);
|
||||
while (SDL_PollEvent(&evt)) {
|
||||
if (!poll) {
|
||||
ret = SDL_WaitEvent(&evt);
|
||||
poll = 1;
|
||||
} else ret = SDL_PollEvent(&evt);
|
||||
|
||||
while (ret) {
|
||||
if (evt.type == SDL_WINDOWEVENT) resize(&evt);
|
||||
else if (evt.type == SDL_QUIT) goto cleanup;
|
||||
else if (evt.type == SDL_KEYUP) key(&ctx.input, &evt, zr_false);
|
||||
@ -847,6 +848,7 @@ main(int argc, char *argv[])
|
||||
else if (evt.type == SDL_MOUSEMOTION) motion(&ctx.input, &evt);
|
||||
else if (evt.type == SDL_TEXTINPUT) text(&ctx.input, &evt);
|
||||
else if (evt.type == SDL_MOUSEWHEEL) zr_input_scroll(&ctx.input, evt.wheel.y);
|
||||
ret = SDL_PollEvent(&evt);
|
||||
}
|
||||
zr_input_end(&ctx.input);
|
||||
|
||||
@ -858,7 +860,7 @@ main(int argc, char *argv[])
|
||||
glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
|
||||
draw(vg, &ctx, width, height);
|
||||
SDL_GL_SwapWindow(win);
|
||||
poll = (!((poll+1) & 4));
|
||||
poll = ((poll+1) & 4);
|
||||
}
|
||||
|
||||
cleanup:
|
||||
|
@ -647,13 +647,12 @@ main(int argc, char *argv[])
|
||||
SDL_Event evt;
|
||||
started = SDL_GetTicks();
|
||||
|
||||
zr_input_begin(&ctx.input);
|
||||
if (!poll) {
|
||||
ret = SDL_WaitEvent(&evt);
|
||||
poll = 1;
|
||||
}
|
||||
|
||||
zr_input_begin(&ctx.input);
|
||||
while (SDL_PollEvent(&evt)) {
|
||||
} else ret = SDL_PollEvent(&evt);
|
||||
while (ret) {
|
||||
if (evt.type == SDL_WINDOWEVENT) resize(&evt);
|
||||
else if (evt.type == SDL_QUIT) goto cleanup;
|
||||
else if (evt.type == SDL_KEYUP) key(&ctx.input, &evt, zr_false);
|
||||
@ -663,6 +662,7 @@ main(int argc, char *argv[])
|
||||
else if (evt.type == SDL_MOUSEMOTION) motion(&ctx.input, &evt);
|
||||
else if (evt.type == SDL_TEXTINPUT) text(&ctx.input, &evt);
|
||||
else if (evt.type == SDL_MOUSEWHEEL) zr_input_scroll(&ctx.input, evt.wheel.y);
|
||||
ret = SDL_PollEvent(&evt);
|
||||
}
|
||||
zr_input_end(&ctx.input);
|
||||
|
||||
@ -682,12 +682,7 @@ main(int argc, char *argv[])
|
||||
SDL_GetWindowSize(win, &width, &height);
|
||||
draw(vg, &ctx, width, height);
|
||||
SDL_GL_SwapWindow(win);
|
||||
poll = (!((poll+1) & 4));
|
||||
|
||||
/* Timing */
|
||||
dt = SDL_GetTicks() - started;
|
||||
if (dt < DTIME)
|
||||
SDL_Delay(DTIME - dt);
|
||||
poll = ((poll+1) & 4);
|
||||
}
|
||||
|
||||
cleanup:
|
||||
|
Loading…
x
Reference in New Issue
Block a user