void CheckJoystickCalibration (void) { #if 0//ndef _WIN32 int x1, y1, x2, y2, c; fix t1; if ((gameConfig.nControlType!=CONTROL_JOYSTICK) && (gameConfig.nControlType!=CONTROL_FLIGHTSTICK_PRO) && (gameConfig.nControlType!=CONTROL_THRUSTMASTER_FCS) && (gameConfig.nControlType!=CONTROL_GRAVIS_GAMEPAD) ) return; JoyGetpos (&x1, &y1); t1 = TimerGetFixedSeconds (); while (TimerGetFixedSeconds () < t1 + I2X (1)/100) ; JoyGetpos (&x2, &y2); // If joystick hasn't moved... if ((abs (x2-x1)<30) && (abs (y2-y1)<30)) { if ((abs (x1)>30) || (abs (x2)>30) || (abs (y1)>30) || (abs (y2)>30)) { c = MsgBox (NULL, NULL, 2, TXT_CALIBRATE, TXT_SKIP, TXT_JOYSTICK_NOT_CEN); if (c==0) { JoyDefsCalibrate (); } } } #endif }
void joy_hat_handler (SDL_JoyHatEvent *jhe) { int hat; int hbi; if (jhe->which >= MAX_JOYSTICKS) return; hat = sdlJoysticks [jhe->which].hatMap [jhe->hat] + jhe->which * MAX_BUTTONS_PER_JOYSTICK; //Save last state of the hat-button joyInfo.buttons [hat ].lastState = joyInfo.buttons [hat ].state; joyInfo.buttons [hat+1].lastState = joyInfo.buttons [hat+1].state; joyInfo.buttons [hat+2].lastState = joyInfo.buttons [hat+2].state; joyInfo.buttons [hat+3].lastState = joyInfo.buttons [hat+3].state; //get current state of the hat-button joyInfo.buttons [hat ].state = ((jhe->value & SDL_HAT_UP)>0); joyInfo.buttons [hat+1].state = ((jhe->value & SDL_HAT_RIGHT)>0); joyInfo.buttons [hat+2].state = ((jhe->value & SDL_HAT_DOWN)>0); joyInfo.buttons [hat+3].state = ((jhe->value & SDL_HAT_LEFT)>0); //determine if a hat-button up or down event based on state and lastState for(hbi=0;hbi<4;hbi++) { if( !joyInfo.buttons [hat+hbi].lastState && joyInfo.buttons [hat+hbi].state) //lastState up, current state down { joyInfo.buttons [hat+hbi].xTimeWentDown = TimerGetFixedSeconds(); joyInfo.buttons [hat+hbi].numDowns++; } else if(joyInfo.buttons [hat+hbi].lastState && !joyInfo.buttons [hat+hbi].state) //lastState down, current state up { joyInfo.buttons [hat+hbi].numUps++; } } }
//Repalces joy_handler //Since Windows calls us directly, we have to get our time difference since last time ourselves //while in DOS we got it with the paramter ticks_this_time LRESULT joy_handler32(HWND hWnd, UINT joymsg, UINT wParam, LPARAM lParam) { DWORD time_diff, time_now; static DWORD time_last = 0xffffffff; Button_info *button; int i; int state=0; DWORD value=0; if (!joy_installed) return 1; if (time_last == 0xffffffff) { time_last = TimerGetFixedSeconds(); return 0; } if (joymsg==MM_JOY1MOVE) { JOYINFOEX joy; memset(&joy, 0, sizeof(joy); joy.dwSize = sizeof(joy); joy.dwFlags = JOY_RETURNBUTTONS | JOY_RETURNPOV; if (joyGetPosEx(joystick.joyid, &joy)!=JOYERR_NOERROR) { return 1; } value = joy.dwButtons; }
void KeyFlush() { int i; fix curtime; if (!bInstalled) key_init(); key_data.keyhead = key_data.keytail = 0; //Clear the keyboard buffer for (i=0; i<KEY_BUFFER_SIZE; i++ ) { key_data.keybuffer[i] = 0; key_data.time_pressed[i] = 0; } //use gettimeofday here: curtime = TimerGetFixedSeconds(); for (i=0; i<256; i++ ) { keyd_pressed[i] = 0; key_data.keys[i].state = 1; key_data.keys[i].last_state = 0; key_data.keys[i].timewentdown = curtime; key_data.keys[i].downcount=0; key_data.keys[i].upcount=0; key_data.keys[i].timehelddown = 0; key_data.keys[i].counter = 0; } }
//this should be called regularly to check for redbook restart void songs_check_redbook_repeat() { static fix last_check_time; fix current_time; if (!gameStates.sound.bRedbookPlaying || gameConfig.nRedbookVolume==0) return; current_time = TimerGetFixedSeconds(); if (current_time < last_check_time || (current_time - last_check_time) >= F2_0) { if (!RBAPeekPlayStatus()) { StopTime(); // if title ends, start credit music // if credits music ends, restart it if (gameStates.sound.bRedbookPlaying == REDBOOK_TITLE_TRACK || gameStates.sound.bRedbookPlaying == REDBOOK_CREDITS_TRACK) play_redbook_track(REDBOOK_CREDITS_TRACK,0); else { //songs_goto_next_song(); //new code plays all tracks to end of disk, so if disk has //stopped we must be at end. So start again with level 1 song. PlayLevelSong(1); } StartTime(); } last_check_time = current_time; } }
int ControlsReadJoystick (int *joyAxis) { int rawJoyAxis [JOY_MAX_AXES]; unsigned long channelMasks; int i, bUseJoystick = 0; fix ctime = 0; if (gameStates.limitFPS.bJoystick) ctime = TimerGetFixedSeconds (); for (i = 0; i < 4; i++) joy_sens_mod [i] = 128 - 7 * gameOpts->input.joystick.sensitivity [i]; if (gameStates.limitFPS.bJoystick) { if ((LastReadTime + JOYSTICK_READ_TIME > ctime) && (gameStates.input.nJoyType != CONTROL_THRUSTMASTER_FCS)) { if ((ctime < 0) && (LastReadTime >= 0)) LastReadTime = ctime; bUseJoystick=1; } else if (gameOpts->input.joystick.bUse) { LastReadTime = ctime; if ((channelMasks = JoyReadRawAxis (JOY_ALL_AXIS, rawJoyAxis))) { for (i = 0; i < JOY_MAX_AXES; i++) { #ifndef SDL_INPUT if (channelMasks & (1 << i)) { #endif if ((i == 3) && (gameStates.input.nJoyType == CONTROL_THRUSTMASTER_FCS)) ControlsReadFCS (rawJoyAxis [i]); else joyAxis [i] = ControlsReadJoyAxis (i, rawJoyAxis); #ifndef SDL_INPUT } else joyAxis [i] = 0; #endif } } bUseJoystick = 1; } else { for (i = 0; i < JOY_MAX_AXES; i++) joyAxis [i] = 0; } } else { // LIMIT_JOY_FPS memset (joyAxis, 0, sizeof (joyAxis)); if (gameOpts->input.joystick.bUse) { if ((channelMasks = JoyReadRawAxis (JOY_ALL_AXIS, rawJoyAxis))) { for (i = 0; i < JOY_MAX_AXES; i++) { if (channelMasks & (1 << i)) joyAxis [i] = ControlsReadJoyAxis (i, rawJoyAxis); else joyAxis [i] = 0; } } bUseJoystick = 1; } } return bUseJoystick; }
//--------------------------------------------------------------------------------- //--unused-- int Muzzle_scale=2; void DoMuzzleStuff (int nSegment, CFixVector *pos) { gameData.muzzle.info [gameData.muzzle.queueIndex].createTime = TimerGetFixedSeconds (); gameData.muzzle.info [gameData.muzzle.queueIndex].nSegment = nSegment; gameData.muzzle.info [gameData.muzzle.queueIndex].pos = *pos; if (++gameData.muzzle.queueIndex >= MUZZLE_QUEUE_MAX) gameData.muzzle.queueIndex = 0; }
void SpeedtestFrame(void) { CFixVector view_dir, center_point; gameData.speedtest.nSide=gameData.speedtest.nSegment % MAX_SIDES_PER_SEGMENT; gameData.objs.viewerP->info.position.vPos = SEGMENTS [gameData.speedtest.nSegment].Center (); gameData.objs.viewerP->info.position.vPos[X] += 0x10; gameData.objs.viewerP->info.position.vPos[Y] -= 0x10; gameData.objs.viewerP->info.position.vPos[Z] += 0x17; gameData.objs.viewerP->RelinkToSeg (gameData.speedtest.nSegment); center_point = SEGMENTS [gameData.speedtest.nSegment].SideCenter (gameData.speedtest.nSide); CFixVector::NormalizedDir(view_dir, center_point, gameData.objs.viewerP->info.position.vPos); //gameData.objs.viewerP->info.position.mOrient = CFixMatrix::Create(view_dir, NULL, NULL); gameData.objs.viewerP->info.position.mOrient = CFixMatrix::CreateF(view_dir); if (((gameData.app.nFrameCount - gameData.speedtest.nFrameStart) % 10) == 0) { #if TRACE console.printf (CON_DBG, "."); #endif } gameData.speedtest.nSegment++; if (gameData.speedtest.nSegment > gameData.segs.nLastSegment) { char msg[128]; sprintf(msg, TXT_SPEEDTEST, gameData.app.nFrameCount-gameData.speedtest.nFrameStart, X2F(TimerGetFixedSeconds() - gameData.speedtest.nStartTime), (double) (gameData.app.nFrameCount-gameData.speedtest.nFrameStart) / X2F(TimerGetFixedSeconds() - gameData.speedtest.nStartTime)); #if TRACE console.printf (CON_DBG, "%s", msg); #endif HUDInitMessage(msg); gameData.speedtest.nCount--; if (gameData.speedtest.nCount == 0) gameData.speedtest.bOn = 0; else SpeedtestInit(); } }
void MouseButtonHandler (SDL_MouseButtonEvent *mbe) { // to bad, SDL buttons use a different mapping as descent expects, // this is at least true and tested for the first three buttons int button_remap[11] = { D2_MB_LEFT, D2_MB_MIDDLE, D2_MB_RIGHT, D2_MB_Z_UP, D2_MB_Z_DOWN, D2_MB_PITCH_BACKWARD, D2_MB_PITCH_FORWARD, D2_MB_BANK_LEFT, D2_MB_BANK_RIGHT, D2_MB_HEAD_LEFT, D2_MB_HEAD_RIGHT }; int button = button_remap [mbe->button - 1]; // -1 since SDL seems to start counting at 1 struct tMouseButton *mb = mouseData.buttons + button; fix xCurTime = TimerGetFixedSeconds (); if (mbe->state == SDL_PRESSED) { #if DBG if (button == nDbgButton) nDbgButton = nDbgButton; #endif mb->pressed = 1; mb->xPrevTimeWentDown = mb->xTimeWentDown; mb->xTimeWentDown = xCurTime; mb->numDowns++; if (button == D2_MB_Z_UP) { mouseData.dz += Z_SENSITIVITY; mouseData.z += Z_SENSITIVITY; mb->rotated = 1; } else if (button == D2_MB_Z_DOWN) { mouseData.dz -= Z_SENSITIVITY; mouseData.z -= Z_SENSITIVITY; mb->rotated = 1; } } else { #if DBG if (button == nDbgButton) nDbgButton = nDbgButton; #endif mb->pressed = 0; mb->xTimeHeldDown += xCurTime - mb->xTimeWentDown; mb->numUps++; mouseData.bDoubleClick = xCurTime - mb->xPrevTimeWentDown < I2X (1) / 2; } }
void SpeedtestInit(void) { gameData.speedtest.nStartTime = TimerGetFixedSeconds(); gameData.speedtest.bOn = 1; gameData.speedtest.nSegment = 0; gameData.speedtest.nSide = 0; gameData.speedtest.nFrameStart = gameData.app.nFrameCount; #if TRACE console.printf (CON_DBG, "Starting speedtest. Will be %i frames. Each . = 10 frames.\n", gameData.segs.nLastSegment+1); #endif }
//stop the redbook, so we can read off the CD void songs_stop_redbook(void) { int old_volume = gameConfig.nRedbookVolume*REDBOOK_VOLUME_SCALE/8; fix old_time = TimerGetFixedSeconds(); if (gameStates.sound.bRedbookPlaying) { //fade out volume int new_volume; do { fix t = TimerGetFixedSeconds(); new_volume = fixmuldiv(old_volume,(FADE_TIME - (t-old_time)),FADE_TIME); if (new_volume < 0) new_volume = 0; RBASetVolume(new_volume); } while (new_volume > 0); } RBAStop(); // Stop CD, if playing RBASetVolume(old_volume); //restore volume gameStates.sound.bRedbookPlaying = 0; }
void KeyInit() { Installed=1; xLastKeyPressTime = TimerGetFixedSeconds(); keyd_bufferType = 1; keyd_repeat = 1; // Clear the keyboard array KeyFlush(); atexit(KeyClose); }
void CheckRearView (void) { #define LEAVE_TIME 0x1000 //how long until we decide key is down (Used to be 0x4000) static int nLeaveMode; static fix entryTime; if (Controls [0].rearViewDownCount) { //key/button has gone down Controls [0].rearViewDownCount = 0; if (ToggleRearView () && gameStates.render.bRearView) { nLeaveMode = 0; //means wait for another key entryTime = TimerGetFixedSeconds (); } } else if (Controls [0].rearViewDownState) { if (!nLeaveMode && (TimerGetFixedSeconds () - entryTime) > LEAVE_TIME) nLeaveMode = 1; } else if (nLeaveMode) SetRearView (0); }
fix JoyGetButtonDownTime(int nButton) { fix time = 0; if (!gameStates.input.nJoysticks) return 0; #ifndef FAST_EVENTPOLL if (gameOpts->legacy.bInput) event_poll(SDL_JOYEVENTMASK); //polled in main/KConfig.c:read_bm_all() #endif switch (joyInfo.buttons [nButton].state) { case SDL_PRESSED: time = TimerGetFixedSeconds() - joyInfo.buttons [nButton].xTimeWentDown; joyInfo.buttons [nButton].xTimeWentDown = TimerGetFixedSeconds(); break; case SDL_RELEASED: time = 0; break; } return time; }
void MouseFlush (void) // clears all mouse events... { int i; fix xCurTime; event_poll (SDL_MOUSEEVENTMASK); xCurTime = TimerGetFixedSeconds (); memset (&mouseData, 0, sizeof (mouseData)); for (i = 0; i < MOUSE_MAX_BUTTONS; i++) mouseData.buttons [i].xTimeWentDown = xCurTime; SDL_GetMouseState (&mouseData.x, &mouseData.y); // necessary because polling only gives us the delta. }
int PingPlayer (int i) { if (gameData.app.nGameMode & GM_NETWORK) { if (i >= 0) { pingStats [i].launchTime = TimerGetFixedSeconds (); NetworkSendPing ((ubyte) i); MultiSendMsgQuit (); pingStats [i].sent++; } else { int name_index = 5; if (strlen (gameData.multigame.msg.szMsg) > 5) while (gameData.multigame.msg.szMsg [name_index] == ' ') name_index++; if (strlen (gameData.multigame.msg.szMsg) <= (size_t) name_index) { HUDInitMessage (TXT_PING_NAME); return 1; } for (i = 0; i < gameData.multiplayer.nPlayers; i++) { if ((!strnicmp (gameData.multiplayer.players [i].callsign, &gameData.multigame.msg.szMsg [name_index], strlen (gameData.multigame.msg.szMsg)-name_index)) && (i != gameData.multiplayer.nLocalPlayer) && (gameData.multiplayer.players [i].connected)) { pingStats [i].launchTime = TimerGetFixedSeconds (); NetworkSendPing ((ubyte) i); HUDInitMessage (TXT_PINGING, gameData.multiplayer.players [i].callsign); MultiSendMsgQuit (); return 1; } } } } else {// Modem/Serial ping pingStats [0].launchTime = TimerGetFixedSeconds (); MultiSendModemPing (); HUDInitMessage (TXT_PING_OTHER); MultiSendMsgQuit (); return 1; } return 0; }
int NetworkStartGame (void) { int i, bAutoRun; if (gameStates.multi.nGameType >= IPX_GAME) { Assert (FRAME_INFO_SIZE < DATALIMIT); if (!networkData.bActive) { ExecMessageBox (NULL, NULL, 1, TXT_OK, TXT_IPX_NOT_FOUND); return 0; } } NetworkInit (); ChangePlayerNumTo (0); if (NetworkFindGame ()) { ExecMessageBox (NULL, NULL, 1, TXT_OK, TXT_NET_FULL); return 0; } bAutoRun = InitAutoNetGame (); if (0 > (i = NetworkGetGameParams (bAutoRun))) return 0; gameData.multiplayer.nPlayers = 0; netGame.difficulty = gameStates.app.nDifficultyLevel; netGame.gameMode = mpParams.nGameMode; netGame.gameStatus = NETSTAT_STARTING; netGame.nNumPlayers = 0; netGame.nMaxPlayers = gameData.multiplayer.nMaxPlayers; netGame.nLevel = mpParams.nLevel; netGame.protocolVersion = MULTI_PROTO_VERSION; strcpy (netGame.szGameName, mpParams.szGameName); networkData.nStatus = NETSTAT_STARTING; // Have the network driver initialize whatever data it wants to // store for this netgame. // For mcast4, this randomly chooses a multicast session and port. // Clients subscribe to this address when they call // IpxHandleNetGameAuxData. IpxInitNetGameAuxData (netGame.AuxData); NetworkSetGameMode (netGame.gameMode); d_srand (TimerGetFixedSeconds ()); netGame.nSecurity = d_rand (); // For syncing Netgames with tPlayer packets if (NetworkSelectPlayers (bAutoRun)) { StartNewLevel (netGame.nLevel, 0); ResetAllPlayerTimeouts (); return 1; } else { gameData.app.nGameMode = GM_GAME_OVER; return 0; } }
void key_init() { if (keyboard_init()) Error ("SVGAlib Keyboard Init Failed"); Installed=1; keyboard_seteventhandler (key_handler); xLastKeyPressTime = TimerGetFixedSeconds(); keyd_bufferType = 1; keyd_repeat = 1; // Clear the keyboard array KeyFlush(); atexit(key_close); }
void NetworkHandlePingReturn (ubyte nPlayer) { if ((nPlayer >= gameData.multiplayer.nPlayers) || !pingStats [nPlayer].launchTime) { #if 1 console.printf (CON_DBG, "Got invalid PING RETURN from %s!\n", gameData.multiplayer.players [nPlayer].callsign); #endif return; } xPingReturnTime = TimerGetFixedSeconds (); pingStats [nPlayer].ping = X2I (FixMul (xPingReturnTime - pingStats [nPlayer].launchTime, I2X (1000))); if (!gameStates.render.cockpit.bShowPingStats) HUDInitMessage ("Ping time for %s is %d ms!", gameData.multiplayer.players [nPlayer].callsign, pingStats [nPlayer].ping); pingStats [nPlayer].launchTime = 0; pingStats [nPlayer].received++; }
void NetworkSendSync (void) { int i, j, np; // Randomize their starting locations... d_srand (TimerGetFixedSeconds ()); for (i = 0; i < gameData.multiplayer.nPlayerPositions; i++) { if (gameData.multiplayer.players [i].connected) gameData.multiplayer.players [i].connected = 1; // Get rid of endlevel connect statuses if (IsCoopGame) netGame.locations [i] = i; else { do { np = d_rand () % gameData.multiplayer.nPlayerPositions; for (j = 0; j < i; j++) { if (netGame.locations [j] == np) { np = -1; break; } } } while (np < 0); // np is a location that is not used anywhere else.. netGame.locations [i] = np; } } // Push current data into the sync packet NetworkUpdateNetGame (); netGame.gameStatus = NETSTAT_PLAYING; netGame.nType = PID_SYNC; netGame.nSegmentCheckSum = networkData.nSegmentCheckSum; for (i = 0; i < gameData.multiplayer.nPlayers; i++) { if ((!gameData.multiplayer.players [i].connected) || (i == gameData.multiplayer.nLocalPlayer)) continue; if (gameStates.multi.nGameType >= IPX_GAME) { // Send several times, extras will be ignored SendInternetFullNetGamePacket ( netPlayers.players [i].network.ipx.server, netPlayers.players [i].network.ipx.node); SendNetPlayersPacket ( netPlayers.players [i].network.ipx.server, netPlayers.players [i].network.ipx.node); } } NetworkReadSyncPacket (&netGame, 1); // Read it myself, as if I had sent it }
void joy_button_handler (SDL_JoyButtonEvent *jbe) { int button; if ((jbe->which >= MAX_JOYSTICKS) || (jbe->button > MAX_BUTTONS_PER_JOYSTICK)) return; button = sdlJoysticks [jbe->which].buttonMap [jbe->button] + jbe->which * MAX_BUTTONS_PER_JOYSTICK; joyInfo.buttons [button].state = jbe->state; switch (jbe->type) { case SDL_JOYBUTTONDOWN: joyInfo.buttons [button].xTimeWentDown = TimerGetFixedSeconds(); joyInfo.buttons [button].numDowns++; break; case SDL_JOYBUTTONUP: joyInfo.buttons [button].numUps++; break; } }
// Returns the number of seconds this key has been down since last call. fix KeyDownTime(int scancode) { fix timeDown, time; event_poll(); if ((scancode<0)|| (scancode>255)) return 0; if (!keyd_pressed[scancode]) { timeDown = key_data.keys[scancode].timehelddown; key_data.keys[scancode].timehelddown = 0; } else { time = TimerGetFixedSeconds(); timeDown = time - key_data.keys[scancode].timewentdown; key_data.keys[scancode].timewentdown = time; } return timeDown; }
void KeyInit (void) { int i; if (bInstalled) return; bInstalled = 1; #if UNICODE_KEYS SDL_EnableUNICODE (1); #endif gameStates.input.keys.xLastPressTime = TimerGetFixedSeconds (); gameStates.input.keys.nBufferType = 1; gameStates.input.keys.bRepeat = 1; for(i = 0; i < 256; i++) pszKeyText [i] = keyProperties [i].pszKeyText; // Clear the tKeyboard array KeyFlush (); atexit (KeyClose); }
int j_UpdateState () { int num_processed = 0, i; struct js_event current_event; struct JS_DATA_TYPE joy_data; for (i = 0; i < j_num_buttons; i++) { //changed 6/24/1999 to finally squish the timedown bug - Owen Evans if (j_button[i].state != j_button[i].lastState) { if (j_button[i].state) { j_button[i].downcount++; j_button[i].timedown = TimerGetFixedSeconds(); } } //end changed - OE j_button[i].lastState = j_button[i].state; } for (i = 0; i < 4; i++) { if (j_joystick[i].buffer >= 0) { if (j_joystick[i].version) { while (read (j_joystick[i].buffer, ¤t_event, sizeof (struct js_event)) > 0) { num_processed++; switch (current_event.nType & ~JS_EVENT_INIT) { case JS_EVENT_AXIS: j_axis[j_axes_in_sticks[i] + current_event.number].value = current_event.value; break; case JS_EVENT_BUTTON: j_button[j_buttons_in_sticks[i] + current_event.number].state = current_event.value; break; } } } else { read (j_joystick[i].buffer, &joy_data, JS_RETURN); j_axis[j_axes_in_sticks[i] + 0].value = joy_data.x; j_axis[j_axes_in_sticks[i] + 1].value = joy_data.y; j_button[j_buttons_in_sticks[i] + 0].state = (joy_data.buttons & 0x01); j_button[j_buttons_in_sticks[i] + 1].state = (joy_data.buttons & 0x02) >> 1; } } } return num_processed; }
void key_init() { int i; if (bInstalled) return; bInstalled=1; keydTime_when_last_pressed = TimerGetFixedSeconds(); keyd_bufferType = 1; keyd_repeat = 1; for(i=0; i<256; i++) key_text[i] = key_properties[i].key_text; // Clear the keyboard array KeyFlush(); atexit(key_close); }
// Returns the number of seconds this key has been down since last call. fix KeyDownTime(KEYCODE kcKey) { ULONG timeElapsed; keyboard_handler(); if ((kcKey<0) || (kcKey>127)) return 0; if (keyd_pressed [kcKey]) { fix timeNow = TimerGetFixedSeconds (); timeElapsed = timeNow - g_rgtimeDown [kcKey]; g_rgtimeDown [kcKey] = timeNow; } else { timeElapsed = g_rgtimeElapsed [kcKey]; g_rgtimeElapsed [kcKey] = 0; } return timeElapsed;; }
//------------------------------------------------------------------------------ // Returns how long this button has been down since last call. fix MouseButtonDownTime (int button) { fix timeDown, time; #ifndef FAST_EVENTPOLL if (!bFastPoll) event_poll(SDL_MOUSEEVENTMASK); //polled in main/KConfig.c:read_bm_all() #endif if (!mouseData.buttons [button].pressed) { timeDown = mouseData.buttons [button].xTimeHeldDown; if (!timeDown && mouseData.buttons [button].rotated) timeDown = (fix) (MouseButtonDownCount (button) * gameStates.input.kcPollTime); mouseData.buttons [button].xTimeHeldDown = 0; } else { time = TimerGetFixedSeconds(); timeDown = time - mouseData.buttons [button].xTimeHeldDown; mouseData.buttons [button].xTimeHeldDown = time; } return timeDown; }
void StopTime (void) { if (pfnTIRStop) pfnTIRStop (); if (++gameData.time.nPaused == 1) { fix xTime = TimerGetFixedSeconds (); gameData.time.xSlack = xTime - gameData.time.xLast; if (gameData.time.xSlack < 0) { #if defined (TIMER_TEST) && defined (_DEBUG) Int3 (); //get Matt!!!! #endif gameData.time.xLast = 0; } #if defined (TIMER_TEST) && defined (_DEBUG) gameData.time.xStopped = xTime; #endif } #if defined (TIMER_TEST) && defined (_DEBUG) gameData.time.xStops++; #endif }
//------------------------------------------------------------------------------ // Returns the number of seconds this key has been down since last call. fix KeyDownTime (int scancode) { static fix lastTime = -1; fix timeDown, time, slack = 0; #ifndef FAST_EVENTPOLL if (!bFastPoll) event_poll(SDL_KEYDOWNMASK | SDL_KEYUPMASK); #endif if ((scancode<0)|| (scancode>255)) return 0; if (!gameStates.input.keys.pressed [scancode]) { timeDown = keyData.keys [scancode].timeHeldDown; keyData.keys [scancode].timeHeldDown = 0; } else { QLONG s, ms; time = TimerGetFixedSeconds(); timeDown = time - keyData.keys [scancode].timeWentDown; s = timeDown / 65536; ms = (timeDown & 0xFFFF); ms *= 1000; ms >>= 16; keyData.keys [scancode].timeHeldDown += (int) (s * 1000 + ms); // the following code takes care of clamping in KConfig.c::control_read_all() if (gameStates.input.bKeepSlackTime && (timeDown > gameStates.input.kcPollTime)) { slack = (fix) (timeDown - gameStates.input.kcPollTime); time -= slack + slack / 10; // there is still some slack, so add an extra 10% if (time < lastTime) time = lastTime; timeDown = (fix) gameStates.input.kcPollTime; } keyData.keys [scancode].timeWentDown = time; lastTime = time; if (timeDown && timeDown < gameStates.input.kcPollTime) timeDown = (fix) gameStates.input.kcPollTime; } return timeDown; }
void NetworkSendSync (void) { int i; d_srand (gameStates.app.nRandSeed = TimerGetFixedSeconds ()); // Randomize their starting locations... for (i = 0; i < gameData.multiplayer.nPlayerPositions; i++) if (gameData.multiplayer.players [i].connected) gameData.multiplayer.players [i].connected = 1; // Get rid of endlevel connect statuses if (IsCoopGame) { for (i = 0; i < gameData.multiplayer.nPlayerPositions; i++) *netGame.Locations (i) = i; } else { // randomize player positions int h, j = gameData.multiplayer.nPlayerPositions, posTable [MAX_PLAYERS] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12,13, 14, 15}; for (i = 0; i < gameData.multiplayer.nPlayerPositions; i++) { h = d_rand () % j; // compute random table index *netGame.Locations (i) = posTable [h]; // pick position using random index if (h < --j) posTable [h] = posTable [j]; // remove picked position from position table } } // Push current data into the sync packet NetworkUpdateNetGame (); netGame.m_info.gameStatus = NETSTAT_PLAYING; netGame.m_info.nType = PID_SYNC; netGame.SetSegmentCheckSum (networkData.nSegmentCheckSum); for (i = 0; i < gameData.multiplayer.nPlayers; i++) { if ((!gameData.multiplayer.players [i].connected) || (i == gameData.multiplayer.nLocalPlayer)) continue; if (gameStates.multi.nGameType >= IPX_GAME) { // Send several times, extras will be ignored SendInternetFullNetGamePacket (netPlayers.m_info.players [i].network.ipx.server, netPlayers.m_info.players [i].network.ipx.node); SendNetPlayersPacket (netPlayers.m_info.players [i].network.ipx.server, netPlayers.m_info.players [i].network.ipx.node); } } NetworkProcessSyncPacket (&netGame, 1); // Read it myself, as if I had sent it }