This commit is contained in:
Paul 2001-06-28 19:14:44 +00:00
parent fdebc2da27
commit 2668b7ca7a
20 changed files with 352 additions and 41 deletions

View file

@ -10,6 +10,10 @@
#include "system\gstate.h"
#endif
#ifndef __PAD_VIBE_H__
#include "pad\vibe.h"
#endif
/*****************************************************************************/
// Yay! Automatic key-repeat stuff!
@ -25,6 +29,15 @@ u8 PadAlign[6]={0,1,0xFF,0xFF,0xFF,0xFF};
u8 PadMotor[2][2];
int PadRepeatTimers[2][16];
typedef struct
{
int m_vibrationTurnedOn;
u8 m_intensityValue;
} PadVibeData;
static PadVibeData s_padVibeData[2]={{false,0},{false,0}};
int PadVibrationActive[2]={false,false};
u8 PadVibrationIntensityValues[2];
/*****************************************************************************/
// 701
// 6 2
@ -51,6 +64,10 @@ u16 PADAngeDirTable[16]=
/*****************************************************************************/
void VibrationHandler(int _port);
/*****************************************************************************/
void PadInitShock(int Port)
{
int offs,maxID,set;
@ -192,6 +209,7 @@ void ReadController(int Port)
u8 *PadBuf=&PadBuffer[Port][0];
sPadData *Pad=&PadData[Port];
int PortShift=Port<<4;
int intensity;
Pad->IsAnalogue=0;
Pad->Status=PadGetState(PortShift);
@ -232,8 +250,9 @@ int PortShift=Port<<4;
break;
case PsxPadTypeStandard: // Standard Sony PAD controller
// Pad->Motor0=PadMotor[Port][0];
// Pad->Motor1=PadMotor[Port][1];
intensity=s_padVibeData[Port].m_intensityValue;
Pad->Motor0=intensity&1;
Pad->Motor1=intensity&0xff;
Pad2Digital(Pad);
break;
@ -246,8 +265,9 @@ int PortShift=Port<<4;
Pad->IsAnalogue=1;
// Set vibration values ( motor 0 is 0..1, motor 1 is 0..255 )
// Pad->Motor0 = s_vibData[ Port ].CurrentIntensityValue & 1;
// Pad->Motor1 = (s_vibData[ Port ].CurrentIntensityValue >> 1) & 0xff;
intensity=s_padVibeData[Port].m_intensityValue;
Pad->Motor0=intensity&1;
Pad->Motor1=intensity&0xff;
Pad2Digital(Pad);
break;
@ -366,6 +386,9 @@ void PadUpdate()
UpdateRepeats(0);
UpdateRepeats(1);
VibrationHandler(0);
VibrationHandler(1);
}
@ -384,6 +407,41 @@ bool PadIsConnected(int port)
return pad->Status!=PadStateDiscon&&pad->Type;
}
/*****************************************************************************/
void PadSetVibrationIsTurnedOn(int _port,int _status)
{
s_padVibeData[_port].m_vibrationTurnedOn=_status;
}
int PadGetVibrationIsTurnedOn(int _port)
{
return s_padVibeData[_port].m_vibrationTurnedOn;
}
/*----------------------------------------------------------------------
Function: VibrationHandler
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void VibrationHandler(int _port)
{
PadVibeData *pvd;
int i;
pvd=s_padVibeData;
for(i=0;i<2;i++)
{
pvd->m_intensityValue=pvd->m_vibrationTurnedOn?CPadVibrationManager::getCurrentVibrationIntensity(i):0;
pvd++;
}
}
/*****************************************************************************/
int CPadConfig::s_configNumber=-1;

View file

@ -93,12 +93,12 @@ u16 PadGetPadAngle(u16 Pad, s16 angleAdjust);
bool PadIsConnected(int port);
bool PAD_IsRumbling( int port );
void PAD_SetVibrationEnvelope( int Port, int count, const VIBE_DATA * data, int ferocity=255 );
void PadSetVibrationIsTurnedOn(int _port,int _status);
int PadGetVibrationIsTurnedOn(int _port);
/*****************************************************************************/
class CPadConfig
{
public:

View file

@ -18,6 +18,10 @@
#include "pad\vibe.h"
#ifndef __UTILS_HEADER__
#include "utils\utils.h"
#endif
/* Std Lib
------- */
@ -41,13 +45,137 @@
Vars
---- */
s16 s_vibe_short[]= { 64,128,255,255,255,255,128, 64,-1 };
s16 s_vibe_medium[]= { 64,128,255,255,255,255,255,255,255,255,255,255,255,255, 64,128,-1 };
s16 s_vibe_long[]= { 64,128,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,255,128, 64,-1 };
s16 s_vibe_long_strobey[]= { 64, 64, 64, 64,128,128,128,128,255,255,255,255,128,128,128,128, 64, 64, 64, 64,128,128,128,128,255,255,255,255,128,128,128,128, 64, 64, 64, 64,128,128,128,128,255,255,255,255,128,128,128,128, 64, 64, 64, 64,-1 };
s16 s_vibe_coral_blower_suck[]= { 20, 40, 15, 50, 30, 40,-1 };
s16 s_vibe_chop[]= { 255,255,255,200,200,200,-1 };
s16 *CPadVibrationManager::s_vibeData[VIBE_MAX_TYPES]=
{
s_vibe_short, // VIBE_SHORT
s_vibe_medium, // VIBE_MEDIUM
s_vibe_long, // VIBE_LONG
s_vibe_long_strobey, // VIBE_LONG_STROBEY
s_vibe_coral_blower_suck, // VIBE_CORAL_BLOWER_SUCK
s_vibe_chop, // VIBE_CHOP
};
CPadVibrationManager::VIBE_CONTROL CPadVibrationManager::s_vibeControls[2][MAX_VIBES_PER_PAD];
u8 CPadVibrationManager::s_currentIntensityValues[2];
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CPadVibrationManager::init()
{
int i,j;
for(i=0;i<2;i++)
{
for(j=0;j<MAX_VIBES_PER_PAD;j++)
{
s_vibeControls[i][j].m_active=false;
}
s_currentIntensityValues[i]=0;
}
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CPadVibrationManager::think(int _frames)
{
u8 *intensity;
int tempIntensity;
int i,j,f;
VIBE_CONTROL *vc;
intensity=s_currentIntensityValues;
for(i=0;i<2;i++)
{
*intensity=0;
tempIntensity=0;
vc=s_vibeControls[i];
for(j=0;j<MAX_VIBES_PER_PAD;j++)
{
if(vc->m_active)
{
int amount=-1;
for(f=0;f<_frames;f++)
{
if(*vc->m_vibeData==-1)
{
vc->m_active=false;
amount=-1;
break;
}
else
{
amount=*(vc->m_vibeData++);
}
}
if(amount!=-1)
{
tempIntensity+=(amount*vc->m_ferocity)>>8;
}
}
vc++;
}
if(tempIntensity>254)
{
tempIntensity=254;
}
*intensity=tempIntensity;
intensity++;
}
}
/*----------------------------------------------------------------------
Function:
Purpose:
Params:
Returns:
---------------------------------------------------------------------- */
void CPadVibrationManager::setVibration(int _port,VIBE_TYPE _type,u8 _ferocity)
{
VIBE_CONTROL *vc;
int i;
int foundSlot=false;
// Look for a spare slot
vc=s_vibeControls[_port];
for(i=0;i<MAX_VIBES_PER_PAD;i++)
{
if(!vc->m_active)
{
foundSlot=true;
break;
}
vc++;
}
// No more slots so re-use one
if(!foundSlot)
{
// Could probly find a better way to choose a spare slot, but shouldn't need to..
vc=&s_vibeControls[_port][getRndRange(MAX_VIBES_PER_PAD)];
}
// Fill in details
vc->m_active=true;
vc->m_vibeData=s_vibeData[_type];
vc->m_ferocity=_ferocity;
}
/*===========================================================================
end */

View file

@ -37,7 +37,22 @@
class CPadVibrationManager
{
public:
void init();
typedef enum
{
VIBE_SHORT,
VIBE_MEDIUM,
VIBE_LONG,
VIBE_LONG_STROBEY,
VIBE_CORAL_BLOWER_SUCK,
VIBE_CHOP,
VIBE_MAX_TYPES
} VIBE_TYPE;
static void init();
static void think(int _frames);
static void setVibration(int _port,VIBE_TYPE _type,u8 _ferocity=255);
static u8 getCurrentVibrationIntensity(int _port) {return s_currentIntensityValues[_port];}
private:
enum
@ -53,8 +68,11 @@ private:
} VIBE_CONTROL;
VIBE_CONTROLS m_vibeControls[2][MAX_VIBES_PER_PAD];
}
static s16 *s_vibeData[VIBE_MAX_TYPES];
static VIBE_CONTROL s_vibeControls[2][MAX_VIBES_PER_PAD];
static u8 s_currentIntensityValues[2];
};
/*----------------------------------------------------------------------