Skip to content

Instantly share code, notes, and snippets.

@JensenDied
Created November 14, 2012 02:57
Show Gist options
  • Save JensenDied/4070002 to your computer and use it in GitHub Desktop.
Save JensenDied/4070002 to your computer and use it in GitHub Desktop.
Helbreath Client / Player Speed Issues
// Pointing out the exact bad code that causes various speed discrepancies between players in Helbreath
int CMapData::iObjectFrameCounter(char * cPlayerName, short sViewPointX, short sViewPointY) {
/* Snip */
// dwFrameTime = expected frame time + delay
dwFrameTime = m_stFrame[m_pData[dX][dY].m_sOwnerType][m_pData[dX][dY].m_cOwnerAction].m_sFrameTime + iDelay
// if (time since last frame update > expected frame time)
if ((dwTime - m_pData[dX][dY].m_dwOwnerTime) > dwFrameTime) {
// For slow people: Skip up to 3 frames if this actually happens
if ((dwTime - m_pData[dX][dY].m_dwOwnerTime) >= (dwFrameTime +dwFrameTime)) {
iSkipFrame = ((dwTime - m_pData[dX][dY].m_dwOwnerTime)/dwFrameTime);
if (iSkipFrame > 3) iSkipFrame = 3;
m_pData[dX][dY].m_cOwnerFrame += iSkipFrame;
} else {
// Update frame if just one frame
m_pData[dX][dY].m_cOwnerFrame++;
}
// Set last action time to current time (NOT ADJUSTED FOR ABSOLUTE TIME)
m_pData[dX][dY].m_dwOwnerTime = dwTime;
/* Snip */
}
@JensenDied
Copy link
Author

The frame skip also needs to be addressed, the branching isn't necessary and creates weird complexity without adding value.

  • Remove it - simple, slowdowns will in-fact slow down.
  • Use as a multiplier against dwFrameTime - May be slightly inaccurate due to delay sources expiring.
  • Look at the larger non-posted picture and possibly loop over the frame advancement for the larger set of things to rapidly advance to an accurate image of what the server thinks is happening.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment