src/context.c

changeset 141
cd82643bb6d9
parent 128
c36170c76a2b
equal deleted inserted replaced
140:d190fe5315bd 141:cd82643bb6d9
144 144
145 bool asc_loop_next(void) { 145 bool asc_loop_next(void) {
146 // reset mouse motion 146 // reset mouse motion
147 asc_context.input.mouse_xrel = 0; 147 asc_context.input.mouse_xrel = 0;
148 asc_context.input.mouse_yrel = 0; 148 asc_context.input.mouse_yrel = 0;
149
150 // reset key flags
151 for (unsigned int i = 0 ; i < SDL_NUM_SCANCODES ; i++) {
152 asc_clear_flag(asc_context.input.keys[i], ASC_KEY_RELEASE_FLAG|ASC_KEY_PRESS_FLAG);
153 }
149 154
150 // dispatch SDL events 155 // dispatch SDL events
151 SDL_Event event; 156 SDL_Event event;
152 while (SDL_PollEvent(&event)) { 157 while (SDL_PollEvent(&event)) {
153 switch (event.type) { 158 switch (event.type) {
181 asc_context.input.mouse_window = 186 asc_context.input.mouse_window =
182 asc_window_index(event.motion.windowID); 187 asc_window_index(event.motion.windowID);
183 break; 188 break;
184 } 189 }
185 case SDL_KEYDOWN: 190 case SDL_KEYDOWN:
186 asc_context.input.keys[event.key.keysym.scancode] = true; 191 // we only set the down and press flags if the key is not already known to be down
192 if (asc_key_up(event.key.keysym.scancode)) {
193 asc_set_flag(asc_context.input.keys[event.key.keysym.scancode], ASC_KEY_DOWN_FLAG|ASC_KEY_PRESS_FLAG);
194 }
187 break; 195 break;
188 case SDL_KEYUP: 196 case SDL_KEYUP:
189 asc_context.input.keys[event.key.keysym.scancode] = false; 197 // we can directly set the release flag - it will be cleared next round
198 asc_context.input.keys[event.key.keysym.scancode] = ASC_KEY_RELEASE_FLAG;
190 break; 199 break;
191 } 200 }
192 } 201 }
193 202
194 // sync the windows 203 // sync the windows

mercurial