src/context.c

changeset 16
c5dde81b6fb2
parent 15
362b7659dc76
child 28
8acde7d27904
equal deleted inserted replaced
15:362b7659dc76 16:c5dde81b6fb2
79 // destroy the error buffer 79 // destroy the error buffer
80 cxBufferDestroy(&asc_context.error_buffer); 80 cxBufferDestroy(&asc_context.error_buffer);
81 asc_context.flags = 0; 81 asc_context.flags = 0;
82 asc_dprintf("Ascension context destroyed."); 82 asc_dprintf("Ascension context destroyed.");
83 } 83 }
84
85 static void asc_event_window_resized(Uint32 id, Sint32 width, Sint32 height) {
86 for (unsigned int i = 0 ; i < ASC_MAX_WINDOWS ; i++) {
87 if (asc_context.windows[i].id == id) {
88 asc_context.windows[i].dimensions.width = width;
89 asc_context.windows[i].dimensions.height = height;
90 asc_mat4f_ortho(asc_context.windows[i].projection, 0, (float) width, (float) height, 0);
91 return;
92 }
93 }
94 }
95
96 bool asc_loop_next(void) {
97 // dispatch SDL events
98 SDL_Event event;
99 while (SDL_PollEvent(&event)) {
100 switch (event.type) {
101 case SDL_QUIT:
102 asc_set_flag(&asc_context.flags, ASC_FLAG_QUIT);
103 break;
104 case SDL_WINDOWEVENT: {
105 if (event.window.event == SDL_WINDOWEVENT_RESIZED)
106 asc_event_window_resized(
107 event.window.windowID,
108 event.window.data1,
109 event.window.data2
110 );
111 break;
112 }
113 case SDL_KEYDOWN:
114 // TODO: remove this code and implement key press map instead
115 if (event.key.keysym.sym == SDLK_ESCAPE)
116 return false;
117 break;
118 case SDL_KEYUP:
119 // TODO: implement key press map
120 break;
121 }
122 }
123
124 // sync the windows
125 for (unsigned int i = 0 ; i < ASC_MAX_WINDOWS ; i++) {
126 if (asc_context.windows[i].id > 0) {
127 asc_window_sync(&asc_context.windows[i]);
128 }
129 }
130
131 // compute frame time
132 static Uint32 ticks;
133 Uint32 ticks_elapsed = SDL_GetTicks() - ticks;
134 ticks = SDL_GetTicks();
135 asc_context.elapsed_millis = ticks_elapsed;
136 asc_context.elapsed = (float) ticks_elapsed / 1000.0f;
137
138 return !asc_test_flag(asc_context.flags, ASC_FLAG_QUIT);
139 }

mercurial