示例#1
0
CInput::CInput()
{
#if defined(WIZ) || defined(GP2X)
    volume_direction = VOLUME_NOCHG;
	volume = 60-VOLUME_CHANGE_RATE;
	WIZ_AdjustVolume(VOLUME_UP);
#endif
	g_pLogFile->ftextOut("Starting the input driver...<br>");
	memset(InputCommand, 0, NUM_INPUTS*MAX_COMMANDS*sizeof(stInputCommand));

	for(size_t c=1 ; c<= NUM_INPUTS ; c++)
		resetControls(c);
	memset(&Event,0,sizeof(Event));
#if !defined(TARGET_OS_IPHONE) && !defined(TARGET_IPHONE_SIMULATOR)
	loadControlconfig(); // we want to have the default settings in all cases
	startJoyDriver(); // not for iPhone for now, could cause trouble (unwanted input events)
#endif
}
示例#2
0
/**
 * \brief	Called every logic cycle. This triggers the events that occur and process them trough various functions
 */
void CInput::pollEvents()
{
	// copy all the input of the last poll to a space for checking pressing or holding a button
	memcpy(last_immediate_keytable, immediate_keytable, KEYTABLE_SIZE*sizeof(char));

	for(int i=0 ; i<MAX_COMMANDS ; i++)
		for(int j=0 ; j<NUM_INPUTS ; j++)
			InputCommand[j][i].lastactive = InputCommand[j][i].active;

	// While there's an event to handle
	while( SDL_PollEvent( &Event ) )
	{
		switch( Event.type )
		{
		case SDL_QUIT:
			g_pLogFile->textOut("SDL: Got quit event!");
			m_exit = true;
			break;
		case SDL_KEYDOWN:
			processKeys(1);
			break;
		case SDL_KEYUP:
			processKeys(0);
			break;
		case SDL_JOYAXISMOTION:
			processJoystickAxis();
			break;
		case SDL_JOYBUTTONDOWN:
			processJoystickButton(1);
			break;
		case SDL_JOYBUTTONUP:
			processJoystickButton(0);
			break;
#ifdef MOUSEWRAPPER
		case SDL_MOUSEBUTTONDOWN:
		case SDL_MOUSEBUTTONUP:
		case SDL_MOUSEMOTION:
			processMouse(Event);
			break;
#endif

		case SDL_VIDEORESIZE:
			CRect newSize(Event.resize.w, Event.resize.h);
			g_pVideoDriver->mp_VideoEngine->resizeDisplayScreen(newSize);
			break;
		}
	}
#ifdef MOUSEWRAPPER
	// Handle mouse emulation layer
	processMouse();
#endif

	for(unsigned int i = 0; i < KEYTABLE_SIZE; ++i)
		firsttime_immediate_keytable[i]
		= !last_immediate_keytable[i] && immediate_keytable[i];

	for(int i=0 ; i<MAX_COMMANDS ; i++)
		for(int j=0 ; j<NUM_INPUTS ; j++)
			InputCommand[j][i].firsttimeactive
			= !InputCommand[j][i].lastactive && InputCommand[j][i].active;

#ifndef MOUSEWRAPPER

	// TODO: I'm not sure, if that should go here...
	// Check, if LALT+ENTER was pressed
	if((getHoldedKey(KALT)) && getPressedKey(KENTER))
	{
		bool value;
		value = g_pVideoDriver->getFullscreen();
		value = !value;
		g_pLogFile->textOut(GREEN,"Fullscreen mode triggered by user!<br>");
		g_pVideoDriver->isFullscreen(value);

		// initialize/activate all drivers
		g_pVideoDriver->stop();
		g_pLogFile->ftextOut("Restarting graphics driver...<br>");
		if ( g_pVideoDriver->applyMode() && g_pVideoDriver->start() )
		{
			g_pLogFile->ftextOut(PURPLE, "Toggled Fullscreen quick shortcut...<br>");
		}
		else
		{
			value = !value;
			g_pLogFile->ftextOut(PURPLE, "Couldn't change the resolution, Rolling back...<br>");
			g_pVideoDriver->applyMode();
			g_pVideoDriver->start();
		}

		if(value) g_pVideoDriver->AddConsoleMsg("Fullscreen enabled");
		else g_pVideoDriver->AddConsoleMsg("Fullscreen disabled");

		g_pInput->flushAll();
	}

	// Check, if LALT+Q or LALT+F4 was pressed
	if(getHoldedKey(KALT) && (getPressedKey(KF4) || getPressedKey(KQ)) )
	{
		g_pLogFile->textOut("User exit request!");
		m_exit = true;
	}
#endif

#if defined(WIZ) || defined(GP2X)
	WIZ_AdjustVolume( volume_direction );
#endif

    // Fix up settings if everything gets messed up
	if (g_pInput->getHoldedKey(KF) &&
		g_pInput->getHoldedKey(KI) &&
		g_pInput->getHoldedKey(KX))
	{
		g_pSettings->loadDefaultGraphicsCfg();
		g_pSettings->saveDrvCfg();
		g_pVideoDriver->stop();
		g_pVideoDriver->start();
	}
}
示例#3
0
文件: sound.c 项目: DusteDdk/Wizznic
void soundRun(SDL_Surface* screen,int state)
{
  //Wiz-Volume control
  #if defined (GP2X) || defined (WIZ)
  if(getButton( C_BTNVOLUP ) )
  {
    resetBtn( C_BTNVOLUP );
    WIZ_AdjustVolume(VOLUME_UP);
  } else if(getButton( C_BTNVOLDOWN ) )
  {
    resetBtn( C_BTNVOLDOWN );
    WIZ_AdjustVolume(VOLUME_DOWN);
  }
  WIZ_ShowVolume(screen);
  #endif

  //Rest of code controls music, we return now if music is not playing.
  if( !setting()->musicVol || setting()->disableMusic ) return;

  if(setting()->userMusic && numUserSongs)
  {
    //Check if we should change track because the track stopped
    if(!Mix_PlayingMusic())
    {
      userSong++;
      if(userSong==numUserSongs)
        userSong=0;

      soundPlayUserSongNum(userSong, lastLoadedSongFn);
    }

    //Change track because player wants to
    if(getButton(C_SHOULDERA))
    {
      resetBtn(C_SHOULDERA);
      userSong++;
      if(userSong==numUserSongs)
        userSong=0;
      soundPlayUserSongNum(userSong, lastLoadedSongFn);
    }
    if(getButton(C_SHOULDERB))
    {
      resetBtn(C_SHOULDERB);
      userSong--;
      if(userSong<0)
        userSong=numUserSongs-1;
      soundPlayUserSongNum(userSong, lastLoadedSongFn);
    }

    //Should we show the song title?
    if(showSNCD>0)
    {
      showSNCD-=getTicks();
      txtWriteCenter(screen, FONTSMALL, lastLoadedSongFn, HSCREENW, HSCREENH+80);
    }

  } else {
    if(showSNCD>0)
    {
      showSNCD-=getTicks();
      txtWriteCenter(screen, FONTSMALL, "Select Music Directory in Options", HSCREENW, HSCREENH+80);
    } else if(getButton(C_SHOULDERA) || getButton(C_SHOULDERB))
    {
      resetBtn(C_SHOULDERA);
      resetBtn(C_SHOULDERB);
      showSNCD=3000;
    }

    if(fadeOut > 0)
    {
      fadeOut -= getTicks();
      if(fadeOut < 0)
      {
        fadeOut=0,
        lastState=state;

        switch(state)
        {
          case STATEPLAY:
            cmState=CMSTATE_GAME;
            Mix_FadeInMusicPos(mus[1], -1, MUSIC_FADETIME,mPos[1]);
          break;
          case STATEMENU:
            cmState=CMSTATE_MENU;
            Mix_FadeInMusicPos(mus[0], -1, MUSIC_FADETIME,mPos[0]);
          break;
        }
      }
    }

    if(lastState!=state && fadeOut == 0 )
    {
        //We won't change the music the menuparts which are logically "ingame".
        if( !( getMenuState() == menuStateFinishedLevel || (getMenuState() == menuStateNextLevel && cmState==CMSTATE_GAME) ) )
        {
          fadeOut = MUSIC_FADETIME+20; //We add an extra frames time to make sure the previous fade was completed.
          Mix_FadeOutMusic(MUSIC_FADETIME);
        }
    }

    switch(lastState)
    {
      case STATEPLAY:
        mPos[1] += (double)getTicks() / 1000.0f;
      break;
      case STATEMENU:
        mPos[0] += (double)getTicks() / 1000.0f;
      break;
    }
  }//In-Game music

}
示例#4
0
/**
 * Process iteration.
 *
 * Called once per game iteration. Updates timing, video, and input
 *
 * @param type Type of loop. Normal, typing, or input configuration
 * @param paletteEffects Palette effects to apply to video output
 * @param effectsStopped Whether the effects should be applied without advancing
 *
 * @return Error code
 */
int loop (LoopType type, PaletteEffect* paletteEffects, bool effectsStopped) {

	SDL_Event event;
	int prevTicks, ret;


	// Update tick count
	prevTicks = globalTicks;
	globalTicks = SDL_GetTicks();

	if (globalTicks - prevTicks < 4) {

		// Limit framerate
		SDL_Delay(4 + prevTicks - globalTicks);
		globalTicks = SDL_GetTicks();

	}

	// Show what has been drawn
	video.flip(globalTicks - prevTicks, paletteEffects, effectsStopped);


	// Process system events
	while (SDL_PollEvent(&event)) {

		if (event.type == SDL_QUIT) return E_QUIT;

		ret = controls.update(&event, type);

		if (ret != E_NONE) return ret;

		video.update(&event);

#if defined(WIZ) || defined(GP2X)
		if ((event.type == SDL_JOYBUTTONDOWN) ||
			(event.type == SDL_JOYBUTTONUP)) {

				if (event.jbutton.button ==  GP2X_BUTTON_VOLUP ) {
					if( event.type == SDL_JOYBUTTONDOWN )
						volume_direction = VOLUME_UP;
					else
						volume_direction = VOLUME_NOCHG;
				}
				if (event.jbutton.button ==  GP2X_BUTTON_VOLDOWN ) {
					if( event.type == SDL_JOYBUTTONDOWN )
						volume_direction = VOLUME_DOWN;
					else
						volume_direction = VOLUME_NOCHG;
				}

		}
#endif

	}

	controls.loop();


#if defined(WIZ) || defined(GP2X)
	WIZ_AdjustVolume( volume_direction );
#endif

	return E_NONE;

}
示例#5
0
/**
 * \brief	Called every logic cycle. This triggers the events that occur and process them through various functions
 */
void CInput::pollEvents()
{
    // Semaphore
    SDL_SemWait( pollSem );

    if(remapper.mappingInput)
    {
        readNewEvent();
        SDL_SemPost( pollSem );
        return;
    }

    Vector2D<float> Pos;
#if SDL_VERSION_ATLEAST(2, 0, 0)

#else
    GsRect<Uint16> Res(SDL_GetVideoSurface()->w, SDL_GetVideoSurface()->h);
#endif

	// copy all the input of the last poll to a space for checking pressing or holding a button
	memcpy(last_immediate_keytable, immediate_keytable, KEYTABLE_SIZE*sizeof(char));

	for(int i=0 ; i<MAX_COMMANDS ; i++)
		for(int j=0 ; j<NUM_INPUTS ; j++)
			InputCommand[j][i].lastactive = InputCommand[j][i].active;


    GsRect<Uint16> activeArea = gVideoDriver.mpVideoEngine->getAspectCorrRect();

    auto &dispRect = gVideoDriver.getVidConfig().m_DisplayRect;


#if SDL_VERSION_ATLEAST(2, 0, 0)
#else
    //if( !gVideoDriver.isOpenGL() )
    {
        activeArea.x = 0;
        activeArea.y = 0;
    }
#endif



	// While there's an event to handle
	while( SDL_PollEvent( &Event ) )
	{
        bool passSDLEventVec = true;

		switch( Event.type )
		{
		case SDL_QUIT:
			gLogging.textOut("SDL: Got quit event!");
			m_exit = true;
            gDreamsForceClose = 1;

			break;
        case SDL_KEYDOWN:
            passSDLEventVec = processKeys(1);
			break;
		case SDL_KEYUP:
            passSDLEventVec = processKeys(0);
            break;
		case SDL_JOYAXISMOTION:
            passSDLEventVec = true;
			processJoystickAxis();
			break;
		case SDL_JOYBUTTONDOWN:
            passSDLEventVec = true;
			processJoystickButton(1);
			break;
		case SDL_JOYBUTTONUP:
            passSDLEventVec = true;
			processJoystickButton(0);
			break;

		case SDL_JOYHATMOTION:
            passSDLEventVec = true;
			processJoystickHat();
			break;

#if SDL_VERSION_ATLEAST(2, 0, 0)
		case SDL_FINGERDOWN:
		case SDL_FINGERUP:
		case SDL_FINGERMOTION:
			processMouse(Event);
			break;

        case SDL_WINDOWEVENT:
            if(Event.window.event == SDL_WINDOWEVENT_RESIZED)
            {
                gVideoDriver.mpVideoEngine->resizeDisplayScreen(
                        GsRect<Uint16>(Event.window.data1,
                                      Event.window.data2) );
                dispRect.w = Event.window.data1;
                dispRect.h = Event.window.data2;
            }
            break;
#else
		case SDL_VIDEORESIZE:
            gVideoDriver.mpVideoEngine->resizeDisplayScreen(
					GsRect<Uint16>(Event.resize.w, Event.resize.h) );
            dispRect.w = Event.resize.w;
            dispRect.h = Event.resize.h;
			break;
#endif

		case SDL_MOUSEBUTTONDOWN:

            // If Virtual gamepad takes control...
            if(mpVirtPad && mpVirtPad->active())
            {                                                
                if(Event.button.button <= 3)
                {
                    transMouseRelCoord(Pos, Event.motion, activeArea);
                    mpVirtPad->mouseDown(Pos);
                }
            }
            else
            {
                if(Event.button.button <= 3)
                {
                    transMouseRelCoord(Pos, Event.motion, activeArea);
                    m_EventList.add( new PointingDevEvent( Pos, PDE_BUTTONDOWN ) );
                    gPointDevice.mPointingState.mActionButton = 1;
                    gPointDevice.mPointingState.mPos = Pos;
                }
                else if(Event.button.button == 4) // scroll up
                {
                    gEventManager.add( new MouseWheelEvent( Vector2D<float>(0.0, -1.0) ) );
                }
                else if(Event.button.button == 5) // scroll down
                {
                    gEventManager.add( new MouseWheelEvent( Vector2D<float>(0.0, 1.0) ) );
                }
            }

			break;

		case SDL_MOUSEBUTTONUP:
            if(mpVirtPad && mpVirtPad->active())
            {
                transMouseRelCoord(Pos, Event.motion, activeArea);
                mpVirtPad->mouseUp(Pos);
            }
            else
            {
                passSDLEventVec = true;
                transMouseRelCoord(Pos, Event.motion, activeArea);
                m_EventList.add( new PointingDevEvent( Pos, PDE_BUTTONUP ) );
                gPointDevice.mPointingState.mActionButton = 0;
                gPointDevice.mPointingState.mPos = Pos;
            }

			break;

		case SDL_MOUSEMOTION:
            transMouseRelCoord(Pos, Event.motion, activeArea);
            m_EventList.add( new PointingDevEvent( Pos, PDE_MOVED ) );
            gPointDevice.mPointingState.mPos = Pos;
			break;
		}

        if(passSDLEventVec)
        {
            mSDLEventVec.push_back(Event);
        }
        else
        {
            mBackEventBuffer.push_back(Event);
        }
	}
#ifdef MOUSEWRAPPER
	// Handle mouse emulation layer
	processMouse();
#endif

	for(unsigned int i = 0; i < KEYTABLE_SIZE; ++i)
		firsttime_immediate_keytable[i]
		= !last_immediate_keytable[i] && immediate_keytable[i];

	for(int i=0 ; i<MAX_COMMANDS ; i++)
		for(int j=0 ; j<NUM_INPUTS ; j++)
			InputCommand[j][i].firsttimeactive
			= !InputCommand[j][i].lastactive && InputCommand[j][i].active;

#ifndef MOUSEWRAPPER

	// TODO: I'm not sure, if that should go here...
	// Check, if LALT+ENTER was pressed
	if((getHoldedKey(KALT)) && getPressedKey(KENTER))
	{
		bool value;
        value = gVideoDriver.getFullscreen();
		value = !value;
		gLogging.textOut(GREEN,"Fullscreen mode triggered by user!<br>");
        gVideoDriver.isFullscreen(value);

		// initialize/activate all drivers
		gLogging.ftextOut("Restarting graphics driver...<br>");
        if ( gVideoDriver.applyMode() && gVideoDriver.start() )
		{
			gLogging.ftextOut(PURPLE, "Toggled Fullscreen quick shortcut...<br>");
		}
		else
		{
			value = !value;
			gLogging.ftextOut(PURPLE, "Couldn't change the resolution, Rolling back...<br>");
            gVideoDriver.applyMode();
            gVideoDriver.start();
		}

		gInput.flushAll();
	}

	// Check, if LALT+Q or LALT+F4 was pressed
	if(getHoldedKey(KALT) && (getPressedKey(KF4) || getPressedKey(KQ)) )
	{
		gLogging.textOut("User exit request!");
		m_exit = true;
        gDreamsForceClose = 1;
	}
#endif

#if defined(WIZ) || defined(GP2X)
	WIZ_AdjustVolume( volume_direction );
#endif

    SDL_SemPost( pollSem );
}