public void HandleInputFromNetwork(byte bPlayerID, Packet pktPacket) { if (pktPacket is InputPacket) { InputKeyFrame ikfInput = (pktPacket as InputPacket).ConvertToKeyFrame(); m_simGameSim.AddInput(bPlayerID, ikfInput); } if (pktPacket is StartCountDownPacket) { StartCountDownPacket scdStartPacket = pktPacket as StartCountDownPacket; //get the game start time if (m_dtmTimeToStartGame == null || m_dtmTimeToStartGame.Ticks > scdStartPacket.m_lGameStartTime) { //set the game start time to the closest time m_dtmTimeToStartGame = scdStartPacket.GameStartTime; } //check if in the lobby state if (m_glsGameState == GameLoopState.LOBBY) { //switch to the count down state SwitchToCountDownState(); } } }
public int AddKeyFrames(InputKeyFrame[] ikfInputsToAdd) { //get latest input InputKeyFrame ikfLastRecievedInput = m_ikfInputBuffer[m_iBufferHead]; //get latest tick int iLatestTick = ikfLastRecievedInput.m_iTick; int iFirstNewKeyFrame = iLatestTick; //loop through new inputs for (int i = ikfInputsToAdd.Length - 1; i >= 0; i--) { //check if this input is newer than the latest input if (ikfInputsToAdd[i].m_iTick > iLatestTick) { //check if this is the last recieved new input if (iFirstNewKeyFrame == iLatestTick) { iFirstNewKeyFrame = ikfInputsToAdd[i].m_iTick; } //add to head of buffer AddKeyframeToEndOfInputBuffer(ikfInputsToAdd[i]); } } return(iFirstNewKeyFrame); }
public void AddKeyframeToEndOfInputBuffer(InputKeyFrame ikfItemToAdd) { //move buffer head m_iBufferHead = HelperFunctions.mod((m_iBufferHead - 1), m_ikfInputBuffer.Count); //set item m_ikfInputBuffer[m_iBufferHead] = ikfItemToAdd; }
public void AddInput(byte bPlayer, InputKeyFrame ikfInput) { //get target input buffer InputBuffer ipbBuffer = m_ipbPlayerInputs[bPlayer]; //add input to buffer ipbBuffer.AddKeyframeToEndOfInputBuffer(ikfInput); m_iLastResolvedTick = Mathf.Min(m_iLastResolvedTick, ikfInput.m_iTick); }