Skip to content

Commit

Permalink
RetroPlayer: Add manager for game controls
Browse files Browse the repository at this point in the history
  • Loading branch information
garbear committed Aug 25, 2017
1 parent 0535232 commit 869506d
Show file tree
Hide file tree
Showing 14 changed files with 233 additions and 72 deletions.
14 changes: 8 additions & 6 deletions xbmc/cores/RetroPlayer/RetroPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
#include "RetroPlayerVideo.h"
#include "addons/AddonManager.h"
#include "cores/DataCacheCore.h"
#include "cores/RetroPlayer/guicontrols/GUIGameControlManager.h"
#include "cores/RetroPlayer/rendering/GUIRenderSettings.h"
#include "cores/RetroPlayer/rendering/RPRenderManager.h"
#include "cores/VideoPlayer/Process/ProcessInfo.h"
Expand Down Expand Up @@ -453,23 +454,24 @@ void CRetroPlayer::FrameMove()

void CRetroPlayer::Render(bool clear, uint32_t alpha /* = 255 */, bool gui /* = true */)
{
RETRO::CGUIRenderSettings &renderSettings = CServiceBroker::GetGameServices().RenderSettings();
CGUIGameControlManager &gameControls = CServiceBroker::GetGameServices().GameControls();

ViewMode viewMode = m_renderManager->GetRenderViewMode();
ESCALINGMETHOD scalingMedthod = m_renderManager->GetScalingMethod();
ViewMode viewMode = m_renderManager->GetRenderViewMode();

if (renderSettings.IsGuiRenderSettingsEnabled())
if (gameControls.IsControlActive())
{
m_renderManager->SetRenderViewMode(renderSettings.GetRenderViewMode());
const CGUIRenderSettings &renderSettings = gameControls.GetRenderSettings();
m_renderManager->SetScalingMethod(renderSettings.GetScalingMethod());
m_renderManager->SetRenderViewMode(renderSettings.GetRenderViewMode());
}

m_renderManager->Render(clear, 0, alpha, gui);

if (renderSettings.IsGuiRenderSettingsEnabled())
if (gameControls.IsControlActive())
{
m_renderManager->SetRenderViewMode(viewMode);
m_renderManager->SetScalingMethod(scalingMedthod);
m_renderManager->SetRenderViewMode(viewMode);
}
}

Expand Down
8 changes: 6 additions & 2 deletions xbmc/cores/RetroPlayer/guicontrols/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
set(SOURCES GUIGameControl.cpp)
set(SOURCES GUIGameControl.cpp
GUIGameControlManager.cpp
)

set(HEADERS GUIGameControl.h)
set(HEADERS GUIGameControl.h
GUIGameControlManager.h
)

core_add_library(retroplayer_guicontrols)
53 changes: 23 additions & 30 deletions xbmc/cores/RetroPlayer/guicontrols/GUIGameControl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
*/

#include "GUIGameControl.h"
#include "cores/RetroPlayer/rendering/GUIRenderSettings.h"
#include "GUIGameControlManager.h"
#include "games/GameServices.h"
#include "guilib/Geometry.h"
#include "guilib/GraphicContext.h"
Expand All @@ -43,14 +43,14 @@ CGUIGameControl::CGUIGameControl(int parentID, int controlID, float posX, float
ControlType = GUICONTROL_GAME;
}

void CGUIGameControl::SetViewMode(const CGUIInfoLabel &viewMode)
void CGUIGameControl::SetVideoFilter(const CGUIInfoLabel &videoFilter)
{
m_viewModeInfo = viewMode;
m_videoFilterInfo = videoFilter;
}

void CGUIGameControl::SetVideoFilter(const CGUIInfoLabel &videoFilter)
void CGUIGameControl::SetViewMode(const CGUIInfoLabel &viewMode)
{
m_videoFilterInfo = videoFilter;
m_viewModeInfo = viewMode;
}

void CGUIGameControl::Process(unsigned int currentTime, CDirtyRegionList &dirtyregions)
Expand Down Expand Up @@ -125,43 +125,36 @@ bool CGUIGameControl::CanFocus() const

void CGUIGameControl::UpdateInfo(const CGUIListItem *item /* = nullptr */)
{
m_viewMode = -1;
m_scalingMethod = -1;
m_renderSettings.Reset();

if (item)
{
std::string strViewMode = m_viewModeInfo.GetItemLabel(item);
if (StringUtils::IsNaturalNumber(strViewMode))
std::istringstream(std::move(strViewMode)) >> m_viewMode;

std::string strVideoFilter = m_videoFilterInfo.GetItemLabel(item);
if (StringUtils::IsNaturalNumber(strVideoFilter))
std::istringstream(std::move(strVideoFilter)) >> m_scalingMethod;
{
unsigned int scalingMethod;
std::istringstream(std::move(strVideoFilter)) >> scalingMethod;
m_renderSettings.SetScalingMethod(static_cast<ESCALINGMETHOD>(scalingMethod));
}

std::string strViewMode = m_viewModeInfo.GetItemLabel(item);
if (StringUtils::IsNaturalNumber(strViewMode))
{
unsigned int viewMode;
std::istringstream(std::move(strViewMode)) >> viewMode;
m_renderSettings.SetRenderViewMode(static_cast<ViewMode>(viewMode));
}
}
}

void CGUIGameControl::EnableGUIRender()
{
CGUIRenderSettings &renderSettings = CServiceBroker::GetGameServices().RenderSettings();
CGameSettings &gameSettings = CMediaSettings::GetInstance().GetCurrentGameSettings();

renderSettings.EnableGuiRenderSettings(true);

// Set view mode
if (m_viewMode >= 0)
renderSettings.SetRenderViewMode(static_cast<ViewMode>(m_viewMode));
else
renderSettings.SetRenderViewMode(gameSettings.ViewMode());

// Set scaling method
if (m_scalingMethod >= 0)
renderSettings.SetScalingMethod(static_cast<ESCALINGMETHOD>(m_scalingMethod));
else
renderSettings.SetScalingMethod(gameSettings.ScalingMethod());
CGUIGameControlManager &gameControls = CServiceBroker::GetGameServices().GameControls();
gameControls.SetActiveControl(this);
}

void CGUIGameControl::DisableGUIRender()
{
CGUIRenderSettings &renderSettings = CServiceBroker::GetGameServices().RenderSettings();
renderSettings.EnableGuiRenderSettings(false);
CGUIGameControlManager &gameControls = CServiceBroker::GetGameServices().GameControls();
gameControls.ResetActiveControl();
}
10 changes: 6 additions & 4 deletions xbmc/cores/RetroPlayer/guicontrols/GUIGameControl.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*/
#pragma once

#include "cores/RetroPlayer/rendering/GUIRenderSettings.h"
#include "guilib/GUIControl.h"
#include "guilib/GUIInfoTypes.h"

Expand All @@ -35,8 +36,10 @@ class CGUIGameControl : public CGUIControl
CGUIGameControl(int parentID, int controlID, float posX, float posY, float width, float height);
~CGUIGameControl() override = default;

void SetViewMode(const CGUIInfoLabel &viewMode);
void SetVideoFilter(const CGUIInfoLabel &videoFilter);
void SetViewMode(const CGUIInfoLabel &viewMode);

const CGUIRenderSettings &GetRenderSettings() const { return m_renderSettings; }

// implementation of CGUIControl
CGUIGameControl *Clone() const override { return new CGUIGameControl(*this); };
Expand All @@ -50,11 +53,10 @@ class CGUIGameControl : public CGUIControl
void EnableGUIRender();
void DisableGUIRender();

CGUIInfoLabel m_viewModeInfo;
CGUIInfoLabel m_videoFilterInfo;
CGUIInfoLabel m_viewModeInfo;

int m_viewMode = -1;
int m_scalingMethod = -1;
CGUIRenderSettings m_renderSettings;
};

}
Expand Down
50 changes: 50 additions & 0 deletions xbmc/cores/RetroPlayer/guicontrols/GUIGameControlManager.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* Copyright (C) 2017 Team Kodi
* http://kodi.tv
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with XBMC; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/

#include "GUIGameControlManager.h"
#include "GUIGameControl.h"
#include "cores/RetroPlayer/rendering/GUIRenderSettings.h"

using namespace KODI;
using namespace RETRO;

void CGUIGameControlManager::SetActiveControl(CGUIGameControl *control)
{
m_activeControl = control;
}

bool CGUIGameControlManager::IsControlActive() const
{
return m_activeControl != nullptr;
}

void CGUIGameControlManager::ResetActiveControl()
{
m_activeControl = nullptr;
}

const CGUIRenderSettings &CGUIGameControlManager::GetRenderSettings() const
{
if (m_activeControl != nullptr)
return m_activeControl->GetRenderSettings();

static const CGUIRenderSettings defaultSettings;
return defaultSettings;
}
47 changes: 47 additions & 0 deletions xbmc/cores/RetroPlayer/guicontrols/GUIGameControlManager.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Copyright (C) 2017 Team Kodi
* http://kodi.tv
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Program; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/
#pragma once

#include "guilib/GUIControl.h"
#include "guilib/GUIInfoTypes.h"

namespace KODI
{
namespace RETRO
{
class CGUIGameControl;
class CGUIRenderSettings;

class CGUIGameControlManager
{
public:
CGUIGameControlManager() = default;

void SetActiveControl(CGUIGameControl *control);
bool IsControlActive() const;
void ResetActiveControl();

const CGUIRenderSettings &GetRenderSettings() const;

private:
CGUIGameControl *m_activeControl = nullptr;
};
}
}
3 changes: 2 additions & 1 deletion xbmc/cores/RetroPlayer/rendering/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
set(SOURCES RPRenderManager.cpp
set(SOURCES GUIRenderSettings.cpp
RPRenderManager.cpp
)

set(HEADERS GUIRenderSettings.h
Expand Down
56 changes: 56 additions & 0 deletions xbmc/cores/RetroPlayer/rendering/GUIRenderSettings.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
* Copyright (C) 2017 Team Kodi
* http://kodi.tv
*
* This Program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2, or (at your option)
* any later version.
*
* This Program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this Program; see the file COPYING. If not, see
* <http://www.gnu.org/licenses/>.
*
*/

#include "GUIRenderSettings.h"
#include "settings/GameSettings.h"
#include "settings/MediaSettings.h"

using namespace KODI;
using namespace RETRO;

void CGUIRenderSettings::Reset()
{
m_viewMode = -1;
m_scalingMethod = -1;
}

bool CGUIRenderSettings::operator==(const CGUIRenderSettings &rhs) const
{
return m_viewMode == rhs.m_viewMode &&
m_scalingMethod == rhs.m_scalingMethod;
}

ViewMode CGUIRenderSettings::GetRenderViewMode() const
{
if (HasRenderViewMode())
return static_cast<ViewMode>(m_viewMode);

CGameSettings &gameSettings = CMediaSettings::GetInstance().GetCurrentGameSettings();
return gameSettings.ViewMode();
}

ESCALINGMETHOD CGUIRenderSettings::GetScalingMethod() const
{
if (HasScalingMethod())
return static_cast<ESCALINGMETHOD>(m_scalingMethod);

CGameSettings &gameSettings = CMediaSettings::GetInstance().GetCurrentGameSettings();
return gameSettings.ScalingMethod();
}
24 changes: 15 additions & 9 deletions xbmc/cores/RetroPlayer/rendering/GUIRenderSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,25 @@ namespace RETRO
class CGUIRenderSettings
{
public:
void EnableGuiRenderSettings(bool bEnabled) { m_guiRender = bEnabled; }
bool IsGuiRenderSettingsEnabled() const { return m_guiRender; }
CGUIRenderSettings() { Reset(); }

ViewMode GetRenderViewMode() { return m_viewMode; }
void SetRenderViewMode(ViewMode mode) { m_viewMode = mode; }
void Reset();

ESCALINGMETHOD GetScalingMethod() { return m_scalingMethod; }
void SetScalingMethod(ESCALINGMETHOD method) { m_scalingMethod = method; }
bool operator==(const CGUIRenderSettings &rhs) const;

ViewMode GetRenderViewMode() const;
bool HasRenderViewMode() const { return m_viewMode != -1; }
void SetRenderViewMode(ViewMode mode) { m_viewMode = static_cast<int>(mode); }
void ResetRenderViewMode() { m_viewMode = -1; }

ESCALINGMETHOD GetScalingMethod() const;
bool HasScalingMethod() const { return m_scalingMethod != -1; }
void SetScalingMethod(ESCALINGMETHOD method) { m_scalingMethod = static_cast<int>(method); }
void ResetScalingMethod() { m_scalingMethod = -1; }

private:
bool m_guiRender = false;
ViewMode m_viewMode = ViewModeNormal;
ESCALINGMETHOD m_scalingMethod = VS_SCALINGMETHOD_NEAREST;
int m_viewMode;
int m_scalingMethod;
};
}
}
6 changes: 3 additions & 3 deletions xbmc/cores/RetroPlayer/rendering/IRenderSettingsCallback.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,11 @@ namespace RETRO
virtual bool SupportsRenderFeature(ERENDERFEATURE feature) = 0;
virtual bool SupportsScalingMethod(ESCALINGMETHOD method) = 0;

virtual ViewMode GetRenderViewMode() = 0;
virtual void SetRenderViewMode(ViewMode mode) = 0;

virtual ESCALINGMETHOD GetScalingMethod() = 0;
virtual void SetScalingMethod(ESCALINGMETHOD scalingMethod) = 0;

virtual ViewMode GetRenderViewMode() = 0;
virtual void SetRenderViewMode(ViewMode mode) = 0;
};
}
}
Loading

0 comments on commit 869506d

Please sign in to comment.