- Ivan's patch for forcefeedback
git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@6769 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: 6ed91a21a9ca857bebbcdbaeefb405ff704b1753 Former-commit-id: 90cfa1664c52e41c03eb1356713c64b37b842701
This commit is contained in:
parent
ecca3031fd
commit
0fe87f869c
7 changed files with 125 additions and 2 deletions
|
@ -46,7 +46,9 @@ static void initTrack(int index, tTrack* track, void *carHandle, void **carParmH
|
|||
static void drive_mt(int index, tCarElt* car, tSituation *s);
|
||||
static void drive_at(int index, tCarElt* car, tSituation *s);
|
||||
static void newrace(int index, tCarElt* car, tSituation *s);
|
||||
static void pauserace(int index, tCarElt* car, tSituation *s);
|
||||
static void resumerace(int index, tCarElt* car, tSituation *s);
|
||||
static void endrace(int index, tCarElt* car, tSituation *s);
|
||||
static int pitcmd(int index, tCarElt* car, tSituation *s);
|
||||
|
||||
#ifdef _WIN32
|
||||
|
@ -84,7 +86,9 @@ InitFuncPt(int index, void *pt)
|
|||
itf->rbNewTrack = initTrack; /* give the robot the track view called */
|
||||
/* for every track change or new race */
|
||||
itf->rbNewRace = newrace;
|
||||
itf->rbPauseRace = pauserace;
|
||||
itf->rbResumeRace = resumerace;
|
||||
itf->rbEndRace = endrace;
|
||||
|
||||
/* drive during race */
|
||||
itf->rbDrive = robot.uses_at(index) ? drive_at : drive_mt;
|
||||
|
@ -185,12 +189,24 @@ newrace(int index, tCarElt* car, tSituation *s)
|
|||
}//newrace
|
||||
|
||||
|
||||
void
|
||||
pauserace(int index, tCarElt* car, tSituation *s)
|
||||
{
|
||||
robot.pause_race(index, car, s);
|
||||
}
|
||||
|
||||
void
|
||||
resumerace(int index, tCarElt* car, tSituation *s)
|
||||
{
|
||||
robot.resume_race(index, car, s);
|
||||
}
|
||||
|
||||
void
|
||||
endrace(int index, tCarElt* car, tSituation *s)
|
||||
{
|
||||
robot.end_race(index, car, s);
|
||||
}
|
||||
|
||||
/*
|
||||
* Function
|
||||
*
|
||||
|
|
|
@ -39,7 +39,9 @@ static void initTrack(int index, tTrack* track, void *carHandle, void **carParmH
|
|||
static void drive_mt(int index, tCarElt* car, tSituation *s);
|
||||
static void drive_at(int index, tCarElt* car, tSituation *s);
|
||||
static void newrace(int index, tCarElt* car, tSituation *s);
|
||||
static void pauserace(int index, tCarElt* car, tSituation *s);
|
||||
static void resumerace(int index, tCarElt* car, tSituation *s);
|
||||
static void endrace(int index, tCarElt* car, tSituation *s);
|
||||
static int pitcmd(int index, tCarElt* car, tSituation *s);
|
||||
|
||||
class NetworkHuman: public HumanDriver
|
||||
|
@ -50,7 +52,9 @@ public:
|
|||
void init_track(int index, tTrack* track, void *carHandle,
|
||||
void **carParmHandle, tSituation *s);
|
||||
void new_race(int index, tCarElt* car, tSituation *s);
|
||||
void pause_race(int index, tCarElt* car, tSituation *s);
|
||||
void resume_race(int index, tCarElt* car, tSituation *s);
|
||||
void end_race(int index, tCarElt* car, tSituation *s);
|
||||
void drive_mt(int index, tCarElt* car, tSituation *s);
|
||||
void drive_at(int index, tCarElt* car, tSituation *s);
|
||||
int pit_cmd(int index, tCarElt* car, tSituation *s);
|
||||
|
@ -108,7 +112,9 @@ InitFuncPt(int index, void *pt)
|
|||
itf->rbNewTrack = initTrack; /* give the robot the track view called */
|
||||
/* for every track change or new race */
|
||||
itf->rbNewRace = newrace;
|
||||
itf->rbPauseRace = pauserace;
|
||||
itf->rbResumeRace = resumerace;
|
||||
itf->rbEndRace = endrace;
|
||||
|
||||
/* drive during race */
|
||||
itf->rbDrive = robot.uses_at(index) ? drive_at : drive_mt;
|
||||
|
@ -239,11 +245,21 @@ static void newrace(int index, tCarElt* car, tSituation *s)
|
|||
robot.new_race(index, car, s);
|
||||
}
|
||||
|
||||
static void pauserace(int index, tCarElt* car, tSituation *s)
|
||||
{
|
||||
robot.pause_race(index, car, s);
|
||||
}
|
||||
|
||||
static void resumerace(int index, tCarElt* car, tSituation *s)
|
||||
{
|
||||
robot.resume_race(index, car, s);
|
||||
}
|
||||
|
||||
static void endrace(int index, tCarElt* car, tSituation *s)
|
||||
{
|
||||
robot.end_race(index, car, s);
|
||||
}
|
||||
|
||||
/*
|
||||
* Function
|
||||
*
|
||||
|
@ -324,6 +340,17 @@ void NetworkHuman::new_race(int index, tCarElt* car, tSituation *s)
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Override to handle local/remote drivers.
|
||||
*/
|
||||
void NetworkHuman::pause_race(int index, tCarElt* car, tSituation *s)
|
||||
{
|
||||
if (is_active_index(index))
|
||||
{
|
||||
HumanDriver::pause_race(index, car, s);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Override to handle local/remote drivers.
|
||||
*/
|
||||
|
@ -335,6 +362,17 @@ void NetworkHuman::resume_race(int index, tCarElt* car, tSituation *s)
|
|||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Override to handle local/remote drivers.
|
||||
*/
|
||||
void NetworkHuman::end_race(int index, tCarElt* car, tSituation *s)
|
||||
{
|
||||
if (is_active_index(index))
|
||||
{
|
||||
HumanDriver::end_race(index, car, s);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
* Override to handle local/remote drivers.
|
||||
*/
|
||||
|
|
|
@ -45,6 +45,8 @@ typedef void (*tfRbNewTrack)(int index, tTrack *track, void *carHandle, void **m
|
|||
/** Callback prototype */
|
||||
typedef void (*tfRbNewRace) (int index, tCarElt *car, tSituation *s);
|
||||
/** Callback prototype */
|
||||
typedef void (*tfRbPauseRace) (int index, tCarElt *car, tSituation *s);
|
||||
/** Callback prototype */
|
||||
typedef void (*tfRbResumeRace) (int index, tCarElt *car, tSituation *s);
|
||||
/** Callback prototype */
|
||||
typedef void (*tfRbEndRace) (int index, tCarElt *car, tSituation *s);
|
||||
|
@ -65,6 +67,7 @@ typedef int (*tfRbPitCmd) (int index, tCarElt* car, tSituation *s);
|
|||
typedef struct RobotItf {
|
||||
tfRbNewTrack rbNewTrack; /**< Give the robot the track view. Called for every track change or new race */
|
||||
tfRbNewRace rbNewRace; /**< Start a new race */
|
||||
tfRbPauseRace rbPauseRace; /**< pause current race to ESC menu */
|
||||
tfRbResumeRace rbResumeRace; /**< resume current race from ESC menu */
|
||||
tfRbEndRace rbEndRace; /**< End of the current race */
|
||||
tfRbDrive rbDrive; /**< Drive during race */
|
||||
|
|
|
@ -33,7 +33,9 @@ public:
|
|||
void init_track(int index, tTrack* track, void *carHandle,
|
||||
void **carParmHandle, tSituation *s);
|
||||
void new_race(int index, tCarElt* car, tSituation *s);
|
||||
void pause_race(int index, tCarElt* car, tSituation *s);
|
||||
void resume_race(int index, tCarElt* car, tSituation *s);
|
||||
void end_race(int index, tCarElt* car, tSituation *s);
|
||||
void drive_mt(int index, tCarElt* car, tSituation *s);
|
||||
void drive_at(int index, tCarElt* car, tSituation *s);
|
||||
int pit_cmd(int index, tCarElt* car, tSituation *s);
|
||||
|
|
|
@ -124,6 +124,11 @@ typedef struct HumanContext
|
|||
bool mouseControlUsed;
|
||||
int lightCmd;
|
||||
int dashboardCounter;
|
||||
#if SDL_FORCEFEEDBACK
|
||||
int lastForceFeedbackIndex;
|
||||
int lastForceFeedbackLevel;
|
||||
int lastForceFeedbackDir;
|
||||
#endif
|
||||
|
||||
// simuV4 ...
|
||||
bool useESP;
|
||||
|
@ -753,6 +758,18 @@ void HumanDriver::new_race(int index, tCarElt* car, tSituation *s)
|
|||
#endif
|
||||
}
|
||||
|
||||
void HumanDriver::pause_race(int index, tCarElt* /*car*/, tSituation* /*s*/)
|
||||
{
|
||||
#if SDL_FORCEFEEDBACK
|
||||
const int idx = index - 1;
|
||||
|
||||
//reset force feedback to zero (if set)
|
||||
if(HCtx[idx]->lastForceFeedbackLevel){
|
||||
gfctrlJoyConstantForce(HCtx[idx]->lastForceFeedbackIndex, 0, 0);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/*
|
||||
* Original function: resumerace
|
||||
*
|
||||
|
@ -789,7 +806,36 @@ void HumanDriver::resume_race(int index, tCarElt* car, tSituation *s)
|
|||
}//KEYBOARD
|
||||
|
||||
}//for i
|
||||
|
||||
#if SDL_FORCEFEEDBACK
|
||||
//restore force feedback effect to the wheel (if was set)
|
||||
if(HCtx[idx]->lastForceFeedbackLevel) {
|
||||
if(cmd[CMD_LEFTSTEER].type != GFCTRL_TYPE_KEYBOARD){
|
||||
HCtx[idx]->lastForceFeedbackIndex = int((cmd[CMD_LEFTSTEER].val) / GFCTRL_JOY_NUMBER);
|
||||
gfctrlJoyConstantForce(
|
||||
HCtx[idx]->lastForceFeedbackIndex,
|
||||
HCtx[idx]->lastForceFeedbackLevel,
|
||||
HCtx[idx]->lastForceFeedbackDir );
|
||||
} else {
|
||||
HCtx[idx]->lastForceFeedbackLevel = 0; // forget force feedback level
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void HumanDriver::end_race(int index, tCarElt* /*car*/, tSituation* /*s*/)
|
||||
{
|
||||
#if SDL_FORCEFEEDBACK
|
||||
const int idx = index - 1;
|
||||
|
||||
//reset force feedback to zero (if set)
|
||||
if(HCtx[idx]->lastForceFeedbackLevel){
|
||||
gfctrlJoyConstantForce(HCtx[idx]->lastForceFeedbackIndex, 0, 0);
|
||||
HCtx[idx]->lastForceFeedbackLevel = 0; // forget force feedback level
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Changes from original: none
|
||||
|
@ -1180,7 +1226,13 @@ static void common_drive(const int index, tCarElt* car, tSituation *s)
|
|||
if(cmd[CMD_LEFTSTEER].type != GFCTRL_TYPE_KEYBOARD){
|
||||
// v<- this controller detenction does not make ->v
|
||||
// v<- sense to me ->v
|
||||
gfctrlJoyConstantForce(int((cmd[CMD_LEFTSTEER].val) / GFCTRL_JOY_NUMBER), forceFeedback.updateForce(car, s), 0 );
|
||||
HCtx[idx]->lastForceFeedbackIndex = int((cmd[CMD_LEFTSTEER].val) / GFCTRL_JOY_NUMBER);
|
||||
HCtx[idx]->lastForceFeedbackLevel = forceFeedback.updateForce(car, s);
|
||||
HCtx[idx]->lastForceFeedbackDir = 0;
|
||||
gfctrlJoyConstantForce(
|
||||
HCtx[idx]->lastForceFeedbackIndex,
|
||||
HCtx[idx]->lastForceFeedbackLevel,
|
||||
HCtx[idx]->lastForceFeedbackDir );
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -526,6 +526,7 @@ static tCarElt* reLoadSingleCar( int carindex, int listindex, int modindex, int
|
|||
} else {
|
||||
curRobot->rbNewTrack = NULL;
|
||||
curRobot->rbNewRace = NULL;
|
||||
curRobot->rbPauseRace = NULL;
|
||||
curRobot->rbResumeRace = NULL;
|
||||
curRobot->rbDrive = NULL;
|
||||
curRobot->rbPitCmd = NULL;
|
||||
|
|
|
@ -640,11 +640,22 @@ void ReSituationUpdater::start()
|
|||
|
||||
void ReSituationUpdater::stop()
|
||||
{
|
||||
int i;
|
||||
tRobotItf *robot;
|
||||
tSituation *s = ReInfo->s;
|
||||
|
||||
GfLogInfo("Stopping race engine.\n");
|
||||
|
||||
// Lock the race engine data.
|
||||
ReSituation::self().lock("ReSituationUpdater::stop");
|
||||
|
||||
// Allow robots to run their stop function
|
||||
for (i = 0; i < s->_ncars; i++) {
|
||||
robot = s->cars[i]->robot;
|
||||
if (robot->rbPauseRace)
|
||||
robot->rbPauseRace(robot->index, s->cars[i], s);
|
||||
}
|
||||
|
||||
// Reset the running flags.
|
||||
ReSituation::self().data()->_reRunning = 0;
|
||||
ReSituation::self().data()->s->_raceState |= RM_RACE_PAUSED;
|
||||
|
|
Loading…
Reference in a new issue