NvResult CNvThreadingLinux::EventCreate(Handle *puEventHandle, bool bManual, bool bSet) { *puEventHandle = NV_HANDLE_INVALID; CConditionData *pCond = new CConditionData; if (!pCond) { return RESULT_OUT_OF_HANDLES; } pCond->manual = bManual; if (pthread_mutex_init(&pCond->mutex, NULL)) { delete pCond; return RESULT_OUT_OF_HANDLES; } if (pthread_cond_init(&pCond->condition, NULL)) { pthread_mutex_destroy(&pCond->mutex); delete pCond; return RESULT_OUT_OF_HANDLES; } *puEventHandle = (Handle)pCond; if (bSet) { EventSet(*puEventHandle); } else { EventReset(*puEventHandle); } return RESULT_OK; }
void EventPoll(EventHandlers *handlers, Uint32 ticks) { SDL_Event e; handlers->HasResolutionChanged = false; handlers->HasLostFocus = false; KeyPrePoll(&handlers->keyboard); MousePrePoll(&handlers->mouse); JoyPrePoll(&handlers->joysticks); SDL_free(handlers->DropFile); handlers->DropFile = NULL; // Don't process mouse events if focus just regained this cycle // This is to prevent bogus click events outside the window, e.g. in the // title bar bool regainedFocus = false; while (SDL_PollEvent(&e)) { switch (e.type) { case SDL_KEYDOWN: if (e.key.repeat) { break; } KeyOnKeyDown(&handlers->keyboard, e.key.keysym); break; case SDL_KEYUP: KeyOnKeyUp(&handlers->keyboard, e.key.keysym); break; case SDL_TEXTINPUT: strcpy(handlers->keyboard.Typed, e.text.text); break; case SDL_CONTROLLERDEVICEADDED: { const SDL_JoystickID jid = JoyAdded(e.cdevice.which); if (jid == -1) { break; } // If there are players with unset devices, // set this controller to them CA_FOREACH(PlayerData, p, gPlayerDatas) if (p->inputDevice == INPUT_DEVICE_UNSET) { PlayerTrySetInputDevice(p, INPUT_DEVICE_JOYSTICK, jid); LOG(LM_INPUT, LL_INFO, "Joystick %d assigned to player %d", jid, p->UID); break; } CA_FOREACH_END() } break; case SDL_CONTROLLERDEVICEREMOVED: JoyRemoved(e.cdevice.which); // If there was a player using this joystick, // set their input device to nothing CA_FOREACH(PlayerData, p, gPlayerDatas) if (p->inputDevice == INPUT_DEVICE_JOYSTICK && p->deviceIndex == e.cdevice.which) { PlayerTrySetInputDevice(p, INPUT_DEVICE_UNSET, 0); LOG(LM_INPUT, LL_WARN, "Joystick for player %d removed", p->UID); break; } CA_FOREACH_END() break; case SDL_CONTROLLERBUTTONDOWN: JoyOnButtonDown(e.cbutton); break; case SDL_CONTROLLERBUTTONUP: JoyOnButtonUp(e.cbutton); break; case SDL_CONTROLLERAXISMOTION: JoyOnAxis(e.caxis); break; case SDL_MOUSEBUTTONDOWN: if (regainedFocus) break; MouseOnButtonDown(&handlers->mouse, e.button.button); break; case SDL_MOUSEBUTTONUP: if (regainedFocus) break; MouseOnButtonUp(&handlers->mouse, e.button.button); break; case SDL_MOUSEWHEEL: if (regainedFocus) break; MouseOnWheel(&handlers->mouse, e.wheel.x, e.wheel.y); break; case SDL_WINDOWEVENT: switch (e.window.event) { case SDL_WINDOWEVENT_FOCUS_GAINED: regainedFocus = true; MusicSetPlaying(&gSoundDevice, true); break; case SDL_WINDOWEVENT_FOCUS_LOST: if (!gCampaign.IsClient && !ConfigGetBool(&gConfig, "StartServer")) { MusicSetPlaying(&gSoundDevice, false); handlers->HasLostFocus = true; } // Reset input handlers EventReset( handlers, handlers->mouse.cursor, handlers->mouse.trail); break; case SDL_WINDOWEVENT_SIZE_CHANGED: handlers->HasResolutionChanged = true; if (gGraphicsDevice.cachedConfig.IsEditor) { const int scale = ConfigGetInt(&gConfig, "Graphics.ScaleFactor"); GraphicsConfigSet( &gGraphicsDevice.cachedConfig, Vec2iScaleDiv( Vec2iNew(e.window.data1, e.window.data2), scale), false, scale, gGraphicsDevice.cachedConfig.ScaleMode, gGraphicsDevice.cachedConfig.Brightness); GraphicsInitialize(&gGraphicsDevice); } break; default: // do nothing break; } break; case SDL_QUIT: handlers->HasQuit = true; break; case SDL_DROPFILE: handlers->DropFile = e.drop.file; break; default: break; } } KeyPostPoll(&handlers->keyboard, ticks); MousePostPoll(&handlers->mouse, ticks); }