Commit 2666bd1b authored by gerstrong@gmail.com's avatar gerstrong@gmail.com

Added Macro for disabling Virtual Gamepad

parent df835a47
......@@ -7,11 +7,18 @@ Project(GsKit)
OPTION(USE_SDL2 "SDL2 support" Yes)
option(USE_PYTHON3 "Use Python3 scripts" yes)
option(USE_VIRTUALPAD "Enable Onscreen Virtual Gamepad support " yes)
set(CMAKE_CXX_STANDARD 14)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
if(USE_VIRTUALPAD)
ADD_DEFINITIONS(-DVIRTUALPAD)
endif(USE_VIRTUALPAD)
IF(WIN32)
ADD_DEFINITIONS(-DWIN32)
ENDIF(WIN32)
......
......@@ -171,14 +171,14 @@ bool CInput::startJoyDriver()
}
else
{
const size_t joyNum = SDL_NumJoysticks();
const auto joyNum = SDL_NumJoysticks();
if( joyNum > 0 )
{
SDL_JoystickEventState(SDL_ENABLE);
gLogging.ftextOut("Detected %i joystick(s).<br>\n", joyNum );
gLogging << "The names of the joysticks are:<br>";
for( size_t i=0; i < joyNum; i++ )
for( auto i=0; i < joyNum; i++ )
{
#if SDL_VERSION_ATLEAST(2, 0, 0)
gLogging.ftextOut(" %s<br>", SDL_JoystickNameForIndex(i));
......@@ -342,6 +342,7 @@ std::string CInput::getEventShortName(int command, unsigned char input)
void CInput::render()
{
#ifdef VIRTUALPAD
if(!gVideoDriver.VGamePadEnabled())
return;
......@@ -359,6 +360,7 @@ void CInput::render()
GsWeakSurface blit(gVideoDriver.getBlitSurface());
mpVirtPad->render(blit);
#endif
}
......@@ -651,6 +653,7 @@ void CInput::transMouseRelCoord(Vector2D<float> &Pos,
void CInput::ponder()
{
#ifdef VIRTUALPAD
if(!mpVirtPad)
return;
......@@ -658,16 +661,19 @@ void CInput::ponder()
return;
mpVirtPad->ponder();
#endif
}
void CInput::flushFingerEvents()
{
#ifdef VIRTUALPAD
if(!mpVirtPad)
return;
mpVirtPad->flush();
#endif
}
......@@ -676,11 +682,13 @@ void CInput::pollEvents()
// Semaphore
SDL_SemWait( pollSem );
#ifdef VIRTUALPAD
if(mpVirtPad && mVPadConfigState)
{
mpVirtPad->processConfig();
return;
}
#endif
if(remapper.mappingInput)
{
......@@ -752,6 +760,7 @@ void CInput::pollEvents()
Vector2D<int> rotPt(Event.tfinger.x*float(activeArea.w),
Event.tfinger.y*float(activeArea.h));
#ifdef VIRTUALPAD
// If Virtual gamepad takes control...
if(gVideoDriver.VGamePadEnabled() && mpVirtPad &&
mpVirtPad->active() )
......@@ -766,6 +775,7 @@ void CInput::pollEvents()
}
}
else
#endif
{
transMouseRelCoord(Pos, Event.tfinger, activeArea, tiltedScreen);
m_EventList.add( new PointingDevEvent( Pos, PDE_BUTTONDOWN ) );
......@@ -777,6 +787,7 @@ void CInput::pollEvents()
case SDL_FINGERUP:
#ifdef VIRTUALPAD
if(gVideoDriver.VGamePadEnabled() && mpVirtPad &&
mpVirtPad->active())
{
......@@ -793,6 +804,7 @@ void CInput::pollEvents()
}
}
else
#endif
{
passSDLEventVec = true;
const Vector2D<int> rotPt(Event.tfinger.x, Event.tfinger.y);
......@@ -810,6 +822,7 @@ void CInput::pollEvents()
Event.tfinger.y*float(activeArea.h));
// If Virtual gamepad takes control...
#ifdef VIRTUALPAD
if(gVideoDriver.VGamePadEnabled() && mpVirtPad &&
mpVirtPad->active() )
{
......@@ -823,6 +836,7 @@ void CInput::pollEvents()
}
}
else
#endif
{
const Vector2D<int> rotPt(Event.tfinger.x, Event.tfinger.y);
transMouseRelCoord(Pos, rotPt, activeArea, tiltedScreen);
......@@ -858,6 +872,7 @@ void CInput::pollEvents()
if(Event.button.button <= 3)
{
#ifdef VIRTUALPAD
// If Virtual gamepad takes control...
if(gVideoDriver.VGamePadEnabled() && mpVirtPad &&
mpVirtPad->active() )
......@@ -873,6 +888,7 @@ void CInput::pollEvents()
}
}
else
#endif
{
const Vector2D<int> rotPt(Event.motion.x, Event.motion.y);
transMouseRelCoord(Pos, Event.motion, activeArea, tiltedScreen);
......@@ -886,6 +902,7 @@ void CInput::pollEvents()
case SDL_MOUSEBUTTONUP:
#ifdef VIRTUALPAD
if(gVideoDriver.VGamePadEnabled() && mpVirtPad &&
mpVirtPad->active())
{
......@@ -900,6 +917,7 @@ void CInput::pollEvents()
}
}
else
#endif
{
passSDLEventVec = true;
const Vector2D<int> rotPt(Event.motion.x, Event.motion.y);
......@@ -1716,9 +1734,9 @@ void CInput::processMouse(SDL_Event& ev) {
case SDL_FINGERMOTION:
//float fdx = ((float)ev.tfinger.dx)/touch->xres;
//float fdy = ((float)ev.tfinger.dy)/touch->yres;
float fdx = ((float)ev.tfinger.dx)/touch->x;
float fdy = ((float)ev.tfinger.dy)/touch->y;
dx = (int)(fdx*w); dy = (int)(fdy*h);
float fdx = (float(ev.tfinger.dx))/touch->x;
float fdy = (float(ev.tfinger.dy))/touch->y;
dx = int(fdx*w); dy = int(fdy*h);
processMouse(x - dx, y - dy, false, ev.tfinger.fingerId);
processMouse(x, y, true, ev.tfinger.fingerId);
break;
......
......@@ -295,6 +295,7 @@ public:
*/
void pushBackButtonEventExtEng();
#ifdef VIRTUALPAD
// One virtual input overlay can be active be processed. This is useful for game to ported on mobile devices
std::unique_ptr<GsVirtualInput> mpVirtPad;
......@@ -306,6 +307,7 @@ public:
{
mVPadConfigState = true;
}
#endif
private:
......@@ -336,7 +338,9 @@ private:
int m_cmdpulse;
short m_joydeadzone;
#ifdef VIRTUALPAD
bool mVPadConfigState = false;
#endif
bool immediate_keytable[KEYTABLE_SIZE];
bool last_immediate_keytable[KEYTABLE_SIZE];
......
......@@ -67,10 +67,12 @@ public:
unsigned short Zoom;
bool mOpengl;
#ifdef VIRTUALPAD
#ifdef ANDROID
bool mVPad = true;
#else
bool mVPad = false;
#endif
#endif
GsRect<int> mAspectCorrection;
......
......@@ -159,7 +159,9 @@ public:
mVidConfig.mAspectCorrection.h = h;
}
#ifdef VIRTUALPAD
bool VGamePadEnabled() { return mVidConfig.mVPad; }
#endif
bool getRefreshSignal() { return m_mustrefresh; }
void setRefreshSignal(const bool value) { m_mustrefresh = value; }
......
......@@ -63,6 +63,7 @@ m_start_level(start_level)
gMenuController.clearMenuStack();
letchooseagain();
#ifdef VIRTUALPAD
gInput.mpVirtPad.reset(new VirtualKeenControl);
if( !gInput.mpVirtPad->init() )
......@@ -71,6 +72,7 @@ m_start_level(start_level)
gLogging.textOut(err);
}
#endif
}
......@@ -644,11 +646,13 @@ void CGameLauncher::pumpEvent(const CEvent *evPtr)
{
gEventManager.add( new OpenMenuEvent(
new SettingsMenu(GsControl::Style::NONE) ) );
}
}
#ifdef VIRTUALPAD
else if( dynamic_cast<const OpenVGamePadSettingsEvent*>(evPtr) )
{
gInput.setInVPadConfigState();
}
#endif
......
......@@ -31,7 +31,9 @@ CPassive::CPassive()
CPassive::~CPassive()
{
#ifdef VIRTUALPAD
gInput.mpVirtPad = nullptr;
#endif
}
......
......@@ -70,7 +70,9 @@ bool CSettings::saveDrvCfg()
CVidConfig &VidConf = gVideoDriver.getVidConfig();
Configuration.SetKeyword("Video", "fullscreen", VidConf.mFullscreen);
Configuration.SetKeyword("Video", "OpenGL", VidConf.mOpengl);
#ifdef VIRTUALPAD
Configuration.SetKeyword("Video", "VirtPad", VidConf.mVPad);
#endif
Configuration.SetKeyword("Video", "ShowCursor", VidConf.mShowCursor);
Configuration.SetKeyword("Video", "TiltedScreen", VidConf.mTiltedScreen);
......@@ -191,7 +193,9 @@ bool CSettings::loadDrvCfg()
Configuration.ReadKeyword("Video", "OpenGL", &VidConf.mOpengl, true);
Configuration.ReadString("Video", "OGLfilter", VidConf.mRenderScQuality, "nearest");
#ifdef VIRTUALPAD
Configuration.ReadKeyword("Video", "VirtPad", &VidConf.mVPad, VidConf.mVPad);
#endif
Configuration.ReadKeyword("Video", "ShowCursor", &VidConf.mShowCursor, true);
Configuration.ReadKeyword("Video", "TiltedScreen", &VidConf.mTiltedScreen, false);
......
......@@ -61,8 +61,10 @@ GameMenu(GsRect<float>(0.15f, 0.20f, 0.65f, 0.55f), style )
#endif
#ifdef VIRTUALPAD
mpVPadSwitch = new Switch( "VirtPad", style );
mpMenuDialog->addControl( mpVPadSwitch, style );
#endif
mpBorderColorSwitch = new Switch( "Border Color", style );
mpMenuDialog->addControl( mpBorderColorSwitch );
......@@ -91,7 +93,9 @@ void CVideoSettings::refresh()
mpShowCursorSwitch->enable( mUsersConf.mShowCursor );
mpTiltScreenSwitch->enable( mUsersConf.mTiltedScreen );
#ifdef VIRTUALPAD
mpVPadSwitch->enable( mUsersConf.mVPad );
#endif
// TODO: find a way to indicate a color
mpBorderColorSwitch->enable( mUsersConf.mBorderColorsEnabled );
......@@ -126,7 +130,9 @@ void CVideoSettings::release()
gTimer.setFPS( 0.0 );
}
#ifdef VIRTUALPAD
mUsersConf.mVPad = mpVPadSwitch->isEnabled();
#endif
mUsersConf.mHorizBorders = mpHorizBordersSelection->getSelection();
......@@ -135,6 +141,7 @@ void CVideoSettings::release()
#if !defined(EMBEDDED)
#ifdef VIRTUALPAD
mUsersConf.mVPad = mpVPadSwitch->isEnabled();
// Disable OpenGL when using Virtual GL
......@@ -142,7 +149,7 @@ void CVideoSettings::release()
{
mUsersConf.mOpengl = false;
}
#endif
const std::string GameResStr = mpGameResSelection->getSelection();
sscanf( GameResStr.c_str(), "%hux%hux", &mUsersConf.mGameRect.w, &mUsersConf.mGameRect.h );
......
......@@ -98,6 +98,7 @@ bool CLevelPlay::loadLevel(const int sprVar, const Uint16 level)
void CLevelPlay::ponder(const float deltaT)
{
#ifdef VIRTUALPAD
#if SDL_VERSION_ATLEAST(2, 0, 0)
if( gVideoDriver.VGamePadEnabled() )
{
......@@ -111,6 +112,7 @@ void CLevelPlay::ponder(const float deltaT)
vkc->mShootButton.invisible = false;
vkc->mStatusButton.invisible = false;
}
#endif
#endif
ponderBase(deltaT);
......
......@@ -125,6 +125,7 @@ bool CPassiveGalaxy::init()
SDL_FillRect( blit, NULL, SDL_MapRGB(blit->format,0,0,0));
gInput.flushAll();
#ifdef VIRTUALPAD
gInput.mpVirtPad.reset(new VirtualKeenControl);
gInput.mpVirtPad->init();
......@@ -132,6 +133,7 @@ bool CPassiveGalaxy::init()
VirtualKeenControl *vkc = dynamic_cast<VirtualKeenControl*>(gInput.mpVirtPad.get());
assert(vkc);
vkc->mDPad.invisible = true;
#endif
#endif
const auto &storyText = gBehaviorEngine.getString("STORY_TEXT");
......@@ -371,10 +373,12 @@ void CPassiveGalaxy::processTitle()
{
gInput.flushAll();
#ifdef VIRTUALPAD
#if SDL_VERSION_ATLEAST(2, 0, 0)
VirtualKeenControl *vkc = dynamic_cast<VirtualKeenControl*>(gInput.mpVirtPad.get());
assert(vkc);
vkc->mDPad.invisible = false;
#endif
#endif
gEventManager.add(new OpenMainMenuEvent());
......@@ -471,10 +475,12 @@ void CPassiveGalaxy::processStarWars()
{
gInput.flushAll();
#ifdef VIRTUALPAD
#if SDL_VERSION_ATLEAST(2, 0, 0)
VirtualKeenControl *vkc = dynamic_cast<VirtualKeenControl*>(gInput.mpVirtPad.get());
assert(vkc);
vkc->mDPad.invisible = false;
#endif
#endif
gEventManager.add(new OpenMainMenuEvent());
......
......@@ -676,6 +676,7 @@ void CPlayGameGalaxy::render()
void CPlayGameGalaxy::processInput()
{
#ifdef VIRTUALPAD
#if SDL_VERSION_ATLEAST(2, 0, 0)
VirtualKeenControl *vkc = dynamic_cast<VirtualKeenControl*>(gInput.mpVirtPad.get());
......@@ -689,6 +690,7 @@ void CPlayGameGalaxy::processInput()
assert(vkc);
vkc->mDPad.invisible = false;
#endif
#endif
}
......
......@@ -79,6 +79,7 @@ void CWorldMap::loadAndPlayMusic()
void CWorldMap::ponder(const float deltaT)
{
#ifdef VIRTUALPAD
if( gVideoDriver.VGamePadEnabled() )
{
VirtualKeenControl *vkc = dynamic_cast<VirtualKeenControl*>(gInput.mpVirtPad.get());
......@@ -87,6 +88,7 @@ void CWorldMap::ponder(const float deltaT)
vkc->mDPad.invisible = false;
vkc->mStartButton.invisible = false;
}
#endif
ponderBase(deltaT);
......
......@@ -461,6 +461,7 @@ void CPlayerWM::processMoving()
if(object) // if we found an object
{
#ifdef VIRTUALPAD
if( gVideoDriver.VGamePadEnabled() )
{
VirtualKeenControl *vkc = dynamic_cast<VirtualKeenControl*>(gInput.mpVirtPad.get());
......@@ -480,6 +481,7 @@ void CPlayerWM::processMoving()
}
#endif
}
#endif
// Try to start a level
if( mPlaycontrol[PA_JUMP] )
......@@ -491,6 +493,7 @@ void CPlayerWM::processMoving()
}
else
{
#ifdef VIRTUALPAD
#if SDL_VERSION_ATLEAST(2, 0, 0)
if( gVideoDriver.VGamePadEnabled() )
{
......@@ -499,6 +502,7 @@ void CPlayerWM::processMoving()
vkc->mStatusButton.invisible = false;
vkc->mStartButton.invisible = true;
}
#endif
#endif
}
......
......@@ -64,8 +64,10 @@ bool CPassiveVort::init()
return false;
}
#ifdef VIRTUALPAD
gInput.mpVirtPad.reset(new VirtualKeenControl);
gInput.mpVirtPad->init();
#endif
gInput.flushAll();
......
......@@ -16,6 +16,7 @@
void CPlayGameVorticon::processInLevel()
{
#ifdef VIRTUALPAD
if( gVideoDriver.VGamePadEnabled() )
{
VirtualKeenControl *vkc = dynamic_cast<VirtualKeenControl*>(gInput.mpVirtPad.get());
......@@ -28,6 +29,7 @@ void CPlayGameVorticon::processInLevel()
vkc->mShootButton.invisible = false;
vkc->mStatusButton.invisible = false;
}
#endif
......
......@@ -101,9 +101,9 @@ void CPlayGameVorticon::setupPlayers()
if(!mpHUDVec.empty())
mpHUDVec.clear();
const int numPlayers = gBehaviorEngine.numPlayers();
const auto numPlayers = gBehaviorEngine.numPlayers();
for (int i=0 ; i<numPlayers ; i++)
for (auto i=0 ; i<numPlayers ; i++)
{
auto &player = m_Player[i];
......@@ -281,6 +281,7 @@ void CPlayGameVorticon::pumpEvent(const CEvent *evPtr)
////
void CPlayGameVorticon::ponder(const float deltaT)
{
#ifdef VIRTUALPAD
VirtualKeenControl *vkc = dynamic_cast<VirtualKeenControl*>(gInput.mpVirtPad.get());
if(!vkc)
......@@ -292,6 +293,7 @@ void CPlayGameVorticon::ponder(const float deltaT)
assert(vkc);
vkc->mDPad.invisible = false;
#endif
if( !mpFinale && !gMenuController.active() ) // Game is not paused, no messages have to be shown and no menu is open
{
......
......@@ -100,6 +100,7 @@ void CPlayGameVorticon::processOnWorldMap()
}
#ifdef VIRTUALPAD
if( gVideoDriver.VGamePadEnabled() )
{
VirtualKeenControl *vkc = dynamic_cast<VirtualKeenControl*>(gInput.mpVirtPad.get());
......@@ -108,6 +109,7 @@ void CPlayGameVorticon::processOnWorldMap()
vkc->mDPad.invisible = false;
vkc->mStartButton.invisible = false;
}
#endif
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment