mirror of
https://github.com/AquariaOSE/Aquaria.git
synced 2024-11-25 09:44:02 +00:00
ignore mouse motion events generated by SDL_WarpMouse().
Also fix bug that mouse.change got stuck on a tiny value and constantly
move the camera in editor mode.
This is a continuation of 764d106d50
and seems to fix the
previous issues with SDL2 >= 2.0.17
Also remove some unused vars.
This commit is contained in:
parent
cf6464daa7
commit
a494a3f411
4 changed files with 62 additions and 69 deletions
|
@ -500,7 +500,6 @@ void DSQ::debugMenu()
|
|||
if (core->getShiftState())
|
||||
|
||||
{
|
||||
core->frameOutputMode = false;
|
||||
dsq->game->togglePause(true);
|
||||
std::string s = dsq->getUserInputString(stringbank.get(2012), "");
|
||||
stringToUpper(s);
|
||||
|
@ -4155,12 +4154,6 @@ void DSQ::modifyDt(float &dt)
|
|||
|
||||
gameSpeed.update(dt);
|
||||
dt *= gameSpeed.x;
|
||||
|
||||
if (frameOutputMode)
|
||||
{
|
||||
dt = 1.0f/60.0f;
|
||||
doScreenshot = true;
|
||||
}
|
||||
}
|
||||
|
||||
void DSQ::removeElement(Element *element)
|
||||
|
|
|
@ -135,8 +135,6 @@ GameOver::GameOver() : StateObject()
|
|||
|
||||
void GameOver::applyState()
|
||||
{
|
||||
const bool frameOutputGameOver = false;
|
||||
|
||||
core->sound->fadeMusic(SFT_OUT, 1);
|
||||
|
||||
|
||||
|
@ -147,12 +145,6 @@ void GameOver::applyState()
|
|||
|
||||
core->sound->playSfx("Death");
|
||||
|
||||
if (frameOutputGameOver)
|
||||
{
|
||||
dsq->fpsText->alpha = 0;
|
||||
core->frameOutputMode = true;
|
||||
}
|
||||
|
||||
Quad *q = new Quad;
|
||||
{
|
||||
q->color = 0;
|
||||
|
@ -248,13 +240,6 @@ void GameOver::applyState()
|
|||
}
|
||||
else
|
||||
dsq->title();
|
||||
|
||||
|
||||
|
||||
if (frameOutputGameOver)
|
||||
core->frameOutputMode = false;
|
||||
|
||||
|
||||
}
|
||||
|
||||
void GameOver::removeState()
|
||||
|
|
|
@ -281,6 +281,7 @@ Core::Core(const std::string &filesystem, const std::string& extraDataDir, int n
|
|||
window = NULL;
|
||||
sound = NULL;
|
||||
_extraDataDir = extraDataDir;
|
||||
sdlUserMouseEventID = SDL_RegisterEvents(1);
|
||||
|
||||
if (userDataSubFolder.empty())
|
||||
userDataSubFolder = appName;
|
||||
|
@ -364,8 +365,6 @@ Core::Core(const std::string &filesystem, const std::string& extraDataDir, int n
|
|||
lib_graphics = lib_sound = lib_input = false;
|
||||
mouseConstraint = false;
|
||||
mouseCircle = 0;
|
||||
frameOutputMode = false;
|
||||
updateMouse = true;
|
||||
particlesPaused = false;
|
||||
joystickAsMouse = false;
|
||||
flipMouseButtons = 0;
|
||||
|
@ -677,8 +676,6 @@ void Core::onUpdate(float dt)
|
|||
{
|
||||
if (minimized) return;
|
||||
|
||||
core->mouse.lastPosition = core->mouse.position;
|
||||
|
||||
pollEvents(dt);
|
||||
|
||||
|
||||
|
@ -964,14 +961,20 @@ void Core::resetTimer()
|
|||
|
||||
void Core::setMousePosition(const Vector &p)
|
||||
{
|
||||
core->mouse.position = p;
|
||||
float px = p.x + virtualOffX;
|
||||
float py = p.y;
|
||||
|
||||
SDL_Event ev = { sdlUserMouseEventID };
|
||||
ev.motion.state = 0;
|
||||
SDL_PushEvent(&ev);
|
||||
|
||||
window->warpMouse(
|
||||
px * (float(width)/float(virtualWidth)),
|
||||
py * (float(height)/float(virtualHeight))
|
||||
);
|
||||
|
||||
ev.motion.state = 1;
|
||||
SDL_PushEvent(&ev);
|
||||
}
|
||||
|
||||
// used to update all render objects either uniformly or as part of a time sliced update process
|
||||
|
@ -1274,6 +1277,12 @@ bool Core::doMouseConstraint()
|
|||
void Core::onEvent(const SDL_Event& event)
|
||||
{
|
||||
const bool focus = window->hasFocus();
|
||||
if(event.type == sdlUserMouseEventID)
|
||||
{
|
||||
mouse._enableMotionEvents = event.motion.state;
|
||||
return;
|
||||
}
|
||||
|
||||
switch (event.type)
|
||||
{
|
||||
case SDL_KEYDOWN:
|
||||
|
@ -1312,10 +1321,15 @@ void Core::onEvent(const SDL_Event& event)
|
|||
|
||||
case SDL_MOUSEMOTION:
|
||||
{
|
||||
if (focus && updateMouse)
|
||||
if (focus)
|
||||
{
|
||||
mouse.position.x = ((event.motion.x) * (float(virtualWidth)/float(getWindowWidth()))) - getVirtualOffX();
|
||||
mouse.position.y = event.motion.y * (float(virtualHeight)/float(getWindowHeight()));
|
||||
const float mx = float(virtualWidth)/float(getWindowWidth());
|
||||
const float my = float(virtualHeight)/float(getWindowHeight());
|
||||
|
||||
mouse.position.x = ((event.motion.x) * mx) - getVirtualOffX();
|
||||
mouse.position.y = event.motion.y * my;
|
||||
if(mouse._enableMotionEvents)
|
||||
mouse._wasMoved = true;
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
@ -1324,7 +1338,7 @@ void Core::onEvent(const SDL_Event& event)
|
|||
|
||||
case SDL_MOUSEWHEEL:
|
||||
{
|
||||
if (focus && updateMouse)
|
||||
if (focus)
|
||||
{
|
||||
if (event.wheel.y > 0)
|
||||
mouse.scrollWheelChange = 1;
|
||||
|
@ -1345,7 +1359,7 @@ void Core::onEvent(const SDL_Event& event)
|
|||
#else
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
{
|
||||
if (focus && updateMouse)
|
||||
if (focus)
|
||||
{
|
||||
switch(event.button.button)
|
||||
{
|
||||
|
@ -1362,7 +1376,7 @@ void Core::onEvent(const SDL_Event& event)
|
|||
|
||||
case SDL_MOUSEBUTTONUP:
|
||||
{
|
||||
if (focus && updateMouse)
|
||||
if (focus)
|
||||
{
|
||||
switch(event.button.button)
|
||||
{
|
||||
|
@ -1382,49 +1396,47 @@ void Core::onEvent(const SDL_Event& event)
|
|||
|
||||
void Core::pollEvents(float dt)
|
||||
{
|
||||
bool warpMouse=false;
|
||||
int x, y;
|
||||
unsigned mousestate = SDL_GetMouseState(&x,&y);
|
||||
|
||||
|
||||
|
||||
if (updateMouse)
|
||||
if (mouse.buttonsEnabled)
|
||||
{
|
||||
int x, y;
|
||||
unsigned mousestate = SDL_GetMouseState(&x,&y);
|
||||
mouse.buttons.left = mousestate & SDL_BUTTON(1)?DOWN:UP;
|
||||
mouse.buttons.right = mousestate & SDL_BUTTON(3)?DOWN:UP;
|
||||
mouse.buttons.middle = mousestate & SDL_BUTTON(2)?DOWN:UP;
|
||||
|
||||
if (mouse.buttonsEnabled)
|
||||
for(unsigned i = 0; i < mouseExtraButtons; ++i)
|
||||
mouse.buttons.extra[i] = mousestate & SDL_BUTTON(3+i)?DOWN:UP;
|
||||
|
||||
mouse.pure_buttons = mouse.buttons;
|
||||
mouse.rawButtonMask = mousestate;
|
||||
|
||||
if (flipMouseButtons)
|
||||
{
|
||||
mouse.buttons.left = mousestate & SDL_BUTTON(1)?DOWN:UP;
|
||||
mouse.buttons.right = mousestate & SDL_BUTTON(3)?DOWN:UP;
|
||||
mouse.buttons.middle = mousestate & SDL_BUTTON(2)?DOWN:UP;
|
||||
|
||||
for(unsigned i = 0; i < mouseExtraButtons; ++i)
|
||||
mouse.buttons.extra[i] = mousestate & SDL_BUTTON(3+i)?DOWN:UP;
|
||||
|
||||
mouse.pure_buttons = mouse.buttons;
|
||||
mouse.rawButtonMask = mousestate;
|
||||
|
||||
if (flipMouseButtons)
|
||||
{
|
||||
std::swap(mouse.buttons.left, mouse.buttons.right);
|
||||
}
|
||||
std::swap(mouse.buttons.left, mouse.buttons.right);
|
||||
}
|
||||
else
|
||||
{
|
||||
mouse.buttons.left = mouse.buttons.right = mouse.buttons.middle = UP;
|
||||
}
|
||||
|
||||
mouse.scrollWheelChange = 0;
|
||||
mouse.change = Vector(0,0);
|
||||
mouse.lastPosition = mouse.position;
|
||||
}
|
||||
else
|
||||
{
|
||||
mouse.buttons.left = mouse.buttons.right = mouse.buttons.middle = UP;
|
||||
}
|
||||
|
||||
mouse.scrollWheelChange = 0;
|
||||
mouse.lastPosition = mouse.position;
|
||||
mouse.change = Vector(0, 0);
|
||||
mouse._wasMoved = false;
|
||||
|
||||
// This polls SDL events and causes Core::onEvent() to be called,
|
||||
// which also updates mouse position etc
|
||||
window->handleInput();
|
||||
|
||||
if(updateMouse)
|
||||
if(mouse._wasMoved)
|
||||
{
|
||||
if (doMouseConstraint())
|
||||
if(doMouseConstraint())
|
||||
{
|
||||
setMousePosition(mouse.position);
|
||||
|
||||
window->handleInput();
|
||||
}
|
||||
mouse.change = mouse.position - mouse.lastPosition;
|
||||
}
|
||||
|
||||
|
|
11
BBGE/Core.h
11
BBGE/Core.h
|
@ -89,6 +89,8 @@ struct Mouse
|
|||
{
|
||||
scrollWheelChange = 0;
|
||||
buttonsEnabled = true;
|
||||
_wasMoved = false;
|
||||
_enableMotionEvents = true;
|
||||
}
|
||||
Vector position, lastPosition;
|
||||
MouseButtons buttons;
|
||||
|
@ -96,8 +98,11 @@ struct Mouse
|
|||
unsigned rawButtonMask;
|
||||
Vector change;
|
||||
bool buttonsEnabled;
|
||||
|
||||
int scrollWheelChange;
|
||||
|
||||
// transient; not for use outside of event handling
|
||||
bool _wasMoved;
|
||||
bool _enableMotionEvents;
|
||||
};
|
||||
|
||||
enum FollowCameraLock
|
||||
|
@ -383,9 +388,6 @@ public:
|
|||
bool joystickAsMouse;
|
||||
virtual void prepScreen(bool t){}
|
||||
|
||||
bool updateMouse;
|
||||
bool frameOutputMode;
|
||||
|
||||
ParticleEffect* createParticleEffect(const std::string &name, const Vector &position, int layer, float rotz=0);
|
||||
|
||||
std::string secondaryTexturePath;
|
||||
|
@ -523,6 +525,7 @@ public:
|
|||
Joystick *getJoystickForSourceID(int sourceID);
|
||||
private:
|
||||
std::vector<Joystick*> joysticks;
|
||||
int sdlUserMouseEventID;
|
||||
};
|
||||
|
||||
extern Core *core;
|
||||
|
|
Loading…
Reference in a new issue