From 93451c1113f14e5e6e4eb828267973e98de89e6b Mon Sep 17 00:00:00 2001 From: pouillot Date: Sat, 9 Oct 2010 13:44:52 +0000 Subject: [PATCH] Fixed #176 (read human controls state only once per robots game loop) git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@2849 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: a98c5b029c028ca8b0f75801ee9e210f6b87bd5f Former-commit-id: d527137e23a50f8c5ba864e0871e7f31c86f47c5 --- src/drivers/human/human.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/drivers/human/human.cpp b/src/drivers/human/human.cpp index 0a0a5eda..f5d6503a 100644 --- a/src/drivers/human/human.cpp +++ b/src/drivers/human/human.cpp @@ -69,7 +69,7 @@ static float color[] = {0.0, 0.0, 1.0, 1.0}; bool joyPresent = false; static tCtrlJoyInfo *joyInfo = NULL; static tCtrlMouseInfo *mouseInfo = NULL; -static int masterPlayer = -1; +static int ControlsUpdaterIndex = -1; std::vector HCtx; @@ -98,7 +98,7 @@ static tKeyInfo keyInfo[GFUIK_MAX+1]; static bool firstTime = false; static tdble lastKeyUpdate = -10.0; -void *PrefHdle = NULL; +void *PrefHdle = NULL; // Human drivers names. static std::vector VecNames; @@ -150,9 +150,12 @@ InitFuncPt(int index, void *pt) tRobotItf *itf = (tRobotItf *)pt; const int idx = index - 1; - if (masterPlayer == -1) - masterPlayer = index; + // Choose this driver as the one who will exclusively read the controls state + // (if no other was choosen in this race). + if (ControlsUpdaterIndex < 0) + ControlsUpdaterIndex = index; + // Initialize mouse and joystick controls backend if not already done. if (!firstTime) { firstTime = true; joyInfo = GfctrlJoyInit(); @@ -569,8 +572,9 @@ common_drive(const int index, tCarElt* car, tSituation *s) car->_raceCmd = RM_CMD_PIT_ASKED; } - // Update the controls only once per period for all the players - if (lastKeyUpdate != s->currentTime) { + // Update the controls at most once per "robots time slice" (RCM_MAX_DT_ROBOTS s) + // (i.e. keyboard/joystick/mouse values read for all players simultaneously). + if (lastKeyUpdate != s->currentTime && index == ControlsUpdaterIndex) { updateKeys(); if (joyPresent) {