| 1637 | |
| 1638 | |
| 1639 | void cClientHandle::Tick(float a_Dt) |
| 1640 | { |
| 1641 | // Handle clients that are waiting for final close while destroyed: |
| 1642 | if (m_State == csDestroyedWaiting) |
| 1643 | { |
| 1644 | m_TicksSinceDestruction += 1; // This field is misused for the timeout counting |
| 1645 | if (m_TicksSinceDestruction > TICKS_BEFORE_CLOSE) |
| 1646 | { |
| 1647 | m_State = csDestroyed; |
| 1648 | } |
| 1649 | return; |
| 1650 | } |
| 1651 | |
| 1652 | // Process received network data: |
| 1653 | AString IncomingData; |
| 1654 | { |
| 1655 | cCSLock Lock(m_CSIncomingData); |
| 1656 | std::swap(IncomingData, m_IncomingData); |
| 1657 | } |
| 1658 | m_Protocol->DataReceived(IncomingData.data(), IncomingData.size()); |
| 1659 | |
| 1660 | m_TimeSinceLastPacket += a_Dt; |
| 1661 | if (m_TimeSinceLastPacket > 30000.f) // 30 seconds time-out |
| 1662 | { |
| 1663 | SendDisconnect("Nooooo!! You timed out! D: Come back!"); |
| 1664 | Destroy(); |
| 1665 | } |
| 1666 | |
| 1667 | if (m_Player == NULL) |
| 1668 | { |
| 1669 | return; |
| 1670 | } |
| 1671 | |
| 1672 | // If the chunk the player's in was just sent, spawn the player: |
| 1673 | if (m_HasSentPlayerChunk && (m_State == csDownloadingWorld)) |
| 1674 | { |
| 1675 | m_Protocol->SendPlayerMoveLook(); |
| 1676 | m_State = csPlaying; |
| 1677 | } |
| 1678 | |
| 1679 | // Send a ping packet: |
| 1680 | cTimer t1; |
| 1681 | if ((m_LastPingTime + cClientHandle::PING_TIME_MS <= t1.GetNowTime())) |
| 1682 | { |
| 1683 | m_PingID++; |
| 1684 | m_PingStartTime = t1.GetNowTime(); |
| 1685 | m_Protocol->SendKeepAlive(m_PingID); |
| 1686 | m_LastPingTime = m_PingStartTime; |
| 1687 | } |
| 1688 | |
| 1689 | // Handle block break animation: |
| 1690 | if (m_BlockDigAnimStage > -1) |
| 1691 | { |
| 1692 | int lastAnimVal = m_BlockDigAnimStage; |
| 1693 | m_BlockDigAnimStage += (int)(m_BlockDigAnimSpeed * a_Dt); |
| 1694 | if (m_BlockDigAnimStage > 9000) |
| 1695 | { |
| 1696 | m_BlockDigAnimStage = 9000; |
nothing calls this directly
no test coverage detected