void Movie::AddFrame(FrameType ftype) { if (!IsRecording()) return; if (!av->inited) { if (ftype == FRAME_FADE) return; if (!Setup()) return; } if (ftype == FRAME_FADE && get_keyboard_controller_status()) return; SDL_SemWait(fillReady); if (!MainScreenIsOpenGL()) { SDL_Surface *video = MainScreenSurface(); SDL_BlitSurface(video, &view_rect, temp_surface, NULL); } #ifdef HAVE_OPENGL else { // Read OpenGL frame buffer glReadPixels(view_rect.x, view_rect.y, view_rect.w, view_rect.h, GL_BGRA, GL_UNSIGNED_INT_8_8_8_8_REV, &videobuf.front()); // Copy pixel buffer (which is upside-down) to surface for (int y = 0; y < view_rect.h; y++) memcpy((uint8 *)temp_surface->pixels + temp_surface->pitch * y, &videobuf.front() + view_rect.w * 4 * (view_rect.h - y - 1), view_rect.w * 4); } #endif int audio_bytes_per_frame = audiobuf.size(); Mixer *mx = Mixer::instance(); int old_vol = mx->main_volume; mx->main_volume = 0x100; mx->Mix(&audiobuf.front(), audio_bytes_per_frame / 4, true, true, true); mx->main_volume = old_vol; SDL_SemPost(encodeReady); }
void execute_timer_tasks(uint32 time) { if (tm_func) { if (Movie::instance()->IsRecording()) { tm_func(); return; } uint32 now = time; tm_accum += now - tm_last; tm_last = now; bool first_time = true; while (tm_accum >= tm_period) { tm_accum -= tm_period; if (first_time) { if(get_keyboard_controller_status()) mouse_idle(input_preferences->input_device); first_time = false; } tm_func(); } } }
static void process_event(const SDL_Event &event) { switch (event.type) { case SDL_MOUSEMOTION: if (get_game_state() == _game_in_progress) { mouse_moved(event.motion.xrel, event.motion.yrel); } break; case SDL_MOUSEWHEEL: if (get_game_state() == _game_in_progress) { bool up = (event.wheel.y > 0); #if SDL_VERSION_ATLEAST(2,0,4) if (event.wheel.direction == SDL_MOUSEWHEEL_FLIPPED) up = !up; #endif mouse_scroll(up); } break; case SDL_MOUSEBUTTONDOWN: if (get_game_state() == _game_in_progress) { if (!get_keyboard_controller_status()) { hide_cursor(); validate_world_window(); set_keyboard_controller_status(true); } else { SDL_Event e2; memset(&e2, 0, sizeof(SDL_Event)); e2.type = SDL_KEYDOWN; e2.key.keysym.sym = SDLK_UNKNOWN; e2.key.keysym.scancode = (SDL_Scancode)(AO_SCANCODE_BASE_MOUSE_BUTTON + event.button.button - 1); process_game_key(e2); } } else process_screen_click(event); break; case SDL_JOYBUTTONDOWN: if (get_game_state() == _game_in_progress) { SDL_Event e2; memset(&e2, 0, sizeof(SDL_Event)); e2.type = SDL_KEYDOWN; e2.key.keysym.sym = SDLK_UNKNOWN; e2.key.keysym.scancode = (SDL_Scancode)(AO_SCANCODE_BASE_JOYSTICK_BUTTON + event.button.button); process_game_key(e2); } break; case SDL_KEYDOWN: process_game_key(event); break; case SDL_TEXTINPUT: if (Console::instance()->input_active()) { Console::instance()->textEvent(event); } break; case SDL_QUIT: set_game_state(_quit_game); break; case SDL_WINDOWEVENT: switch (event.window.event) { case SDL_WINDOWEVENT_FOCUS_LOST: if (get_game_state() == _game_in_progress && get_keyboard_controller_status() && !Movie::instance()->IsRecording()) { darken_world_window(); set_keyboard_controller_status(false); show_cursor(); } break; case SDL_WINDOWEVENT_EXPOSED: #if !defined(__APPLE__) && !defined(__MACH__) // double buffering :) #ifdef HAVE_OPENGL if (MainScreenIsOpenGL()) MainScreenSwap(); else #endif update_game_window(); #endif break; } break; } }
uint32 parse_keymap(void) { uint32 flags = 0; if(get_keyboard_controller_status()) { Uint8 *key_map; if (Console::instance()->input_active()) { static Uint8 chat_input_mode_keymap[SDLK_LAST]; memset(&chat_input_mode_keymap, 0, sizeof(chat_input_mode_keymap)); key_map = chat_input_mode_keymap; } else { key_map = SDL_GetKeyState(NULL); } // ZZZ: let mouse code simulate keypresses mouse_buttons_become_keypresses(key_map); joystick_buttons_become_keypresses(key_map); // Parse the keymap key_definition *key = current_key_definitions; for (unsigned i=0; i<NUMBER_OF_STANDARD_KEY_DEFINITIONS; i++, key++) if (key_map[key->offset]) flags |= key->action_flag; // Post-process the keymap struct special_flag_data *special = special_flags; for (unsigned i=0; i<NUMBER_OF_SPECIAL_FLAGS; i++, special++) { if (flags & special->flag) { switch (special->type) { case _double_flag: // If this flag has a double-click flag and has been hit within // DOUBLE_CLICK_PERSISTENCE (but not at MAXIMUM_FLAG_PERSISTENCE), // mask on the double-click flag */ if (special->persistence < MAXIMUM_FLAG_PERSISTENCE && special->persistence > MAXIMUM_FLAG_PERSISTENCE - DOUBLE_CLICK_PERSISTENCE) flags |= special->alternate_flag; break; case _latched_flag: // If this flag is latched and still being held down, mask it out if (special->persistence == MAXIMUM_FLAG_PERSISTENCE) flags &= ~special->flag; break; default: assert(false); break; } special->persistence = MAXIMUM_FLAG_PERSISTENCE; } else special->persistence = FLOOR(special->persistence-1, 0); } bool do_interchange = (local_player->variables.flags & _HEAD_BELOW_MEDIA_BIT) ? (input_preferences->modifiers & _inputmod_interchange_swim_sink) != 0: (input_preferences->modifiers & _inputmod_interchange_run_walk) != 0; // Handle the selected input controller if (input_preferences->input_device != _keyboard_or_game_pad) { _fixed delta_yaw, delta_pitch, delta_velocity; test_mouse(input_preferences->input_device, &flags, &delta_yaw, &delta_pitch, &delta_velocity); flags = mask_in_absolute_positioning_information(flags, delta_yaw, delta_pitch, delta_velocity); if (do_interchange) flags ^= _run_dont_walk; } else { int joyflags = process_joystick_axes(flags, heartbeat_count); if (joyflags != flags) { flags = joyflags; } else { // Modify flags with run/walk and swim/sink if we're using the keyboard if (do_interchange) flags ^= _run_dont_walk; } } if (player_in_terminal_mode(local_player_index)) flags = build_terminal_action_flags((char *)key_map); } // if(get_keyboard_controller_status()) return flags; }