Skip to content

Commit

Permalink
libretro: controllers are inserted after the Game has loaded.
Browse files Browse the repository at this point in the history
Signed-off-by: Andrea Odetti <mariofutire@gmail.com>
  • Loading branch information
audetto committed Nov 22, 2021
1 parent 0493cad commit 7c81aaf
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 21 deletions.
28 changes: 8 additions & 20 deletions source/frontends/libretro/game.cpp
@@ -1,8 +1,6 @@
#include "StdAfx.h"
#include "frontends/libretro/game.h"
#include "frontends/libretro/retroregistry.h"
#include "frontends/libretro/joypad.h"
#include "frontends/libretro/analog.h"
#include "frontends/libretro/retroframe.h"

#include "Common.h"
Expand Down Expand Up @@ -76,27 +74,17 @@ namespace ra2
myRegistryContext.reset(new RegistryContext(CreateRetroRegistry()));
myFrame.reset(new ra2::RetroFrame());

std::shared_ptr<Paddle> paddle;
switch (ourInputDevices[0])
{
case RETRO_DEVICE_NONE:
break;
case RETRO_DEVICE_JOYPAD:
paddle.reset(new Joypad);
Paddle::setSquaring(false);
break;
case RETRO_DEVICE_ANALOG:
paddle.reset(new Analog);
Paddle::setSquaring(true);
break;
default:
break;
}

myInitialisation.reset(new Initialisation(myFrame, paddle));
SetFrame(myFrame);
myFrame->Initialize();
}

Game::~Game()
{
myFrame->Destroy();
myFrame.reset();
SetFrame(myFrame);
}

retro_usec_t Game::ourFrameTime = 0;

void Game::executeOneFrame()
Expand Down
2 changes: 1 addition & 1 deletion source/frontends/libretro/game.h
Expand Up @@ -17,6 +17,7 @@ namespace ra2
{
public:
Game();
~Game();

bool loadGame(const std::string & path);
bool loadSnapshot(const std::string & path);
Expand All @@ -38,7 +39,6 @@ namespace ra2
std::shared_ptr<LoggerContext> myLoggerContext;
std::shared_ptr<RegistryContext> myRegistryContext;
std::shared_ptr<RetroFrame> myFrame;
std::shared_ptr<Initialisation> myInitialisation;

common2::Speed mySpeed; // fixed speed

Expand Down
18 changes: 18 additions & 0 deletions source/frontends/libretro/libretro.cpp
Expand Up @@ -14,6 +14,8 @@
#include "frontends/libretro/environment.h"
#include "frontends/libretro/rdirectsound.h"
#include "frontends/libretro/retroregistry.h"
#include "frontends/libretro/joypad.h"
#include "frontends/libretro/analog.h"

namespace
{
Expand Down Expand Up @@ -58,6 +60,22 @@ void retro_set_controller_port_device(unsigned port, unsigned device)
if (port == 0)
{
ra2::Game::ourInputDevices[port] = device;

switch (device)
{
case RETRO_DEVICE_NONE:
break;
case RETRO_DEVICE_JOYPAD:
Paddle::instance.reset(new ra2::Joypad);
Paddle::setSquaring(false);
break;
case RETRO_DEVICE_ANALOG:
Paddle::instance.reset(new ra2::Analog);
Paddle::setSquaring(true);
break;
default:
break;
}
}
}

Expand Down

0 comments on commit 7c81aaf

Please sign in to comment.