Skip to content

Commit 6bad535

Browse files
committed
Fixed handle opening, moved screenshake rumble out of rendering
The controllerRumble function has been cleaned up and now iterates over the map of connected controllers instead of opening handles each time rumble is used. The screenshake rumble functions have been moved into the title and game logic loops.
1 parent cc19611 commit 6bad535

File tree

3 files changed

+23
-9
lines changed

3 files changed

+23
-9
lines changed

desktop_version/src/Graphics.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@
1212
#include "Font.h"
1313
#include "GraphicsUtil.h"
1414
#include "Localization.h"
15-
#include "KeyPoll.h"
1615
#include "Map.h"
1716
#include "Maths.h"
1817
#include "Music.h"
@@ -3185,8 +3184,6 @@ void Graphics::screenshake(void)
31853184
clear();
31863185

31873186
copy_texture(tempShakeTexture, NULL, NULL, 0, NULL, flipmode ? SDL_FLIP_VERTICAL : SDL_FLIP_NONE);
3188-
3189-
key.controllerRumble(0x7FFF,10);
31903187
}
31913188

31923189
void Graphics::updatescreenshake(void)

desktop_version/src/KeyPoll.cpp

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -499,17 +499,23 @@ bool KeyPoll::controllerWantsDown(void)
499499

500500
int KeyPoll::controllerRumble(Uint16 intensity, Uint32 duration_ms)
501501
{
502+
int result = -1;
502503
if (game.rumble)
503504
{
504-
SDL_Event evt;
505-
SDL_GameController *toOpen = SDL_GameControllerOpen(evt.cdevice.which);
506-
return SDL_GameControllerRumble(toOpen,intensity,intensity,duration_ms);
505+
std::map<SDL_JoystickID, SDL_GameController*>::iterator it;
506+
for (it = controllers.begin(); it != controllers.end(); it++)
507+
{
508+
int thisController = SDL_GameControllerRumble(it->second,intensity,intensity,duration_ms);
509+
if (result != 0)
510+
{
511+
result = thisController;
512+
}
513+
}
507514
}
515+
return result; // Returns -1 if rumble is off/no controller supported rumble, 0 if any controller succeeded
508516
}
509517

510518
int KeyPoll::controllerRumbleStop(void)
511519
{
512-
SDL_Event evt;
513-
SDL_GameController *toOpen = SDL_GameControllerOpen(evt.cdevice.which);
514-
return SDL_GameControllerRumble(toOpen,0,0,0);
520+
return controllerRumble(0,0);
515521
}

desktop_version/src/Logic.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
#include "Game.h"
66
#include "GlitchrunnerMode.h"
77
#include "Graphics.h"
8+
#include "KeyPoll.h"
89
#include "Map.h"
910
#include "Music.h"
1011
#include "Network.h"
@@ -40,6 +41,11 @@ void titlelogic(void)
4041
game.createmenu(game.menudest, true);
4142
}
4243
}
44+
45+
if (game.screenshake > 0)
46+
{
47+
key.controllerRumble(0x7FFF,10);
48+
}
4349
}
4450

4551
void maplogic(void)
@@ -173,6 +179,11 @@ void gamelogic(void)
173179
}
174180
}
175181

182+
if (game.screenshake > 0)
183+
{
184+
key.controllerRumble(0x7FFF,10);
185+
}
186+
176187
//Misc
177188
if (map.towermode)
178189
{

0 commit comments

Comments
 (0)