Created
December 24, 2012 14:02
-
-
Save vgheri/4369353 to your computer and use it in GitHub Desktop.
Second part of the client update loop
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// A single step of the client update loop (a frame) | |
function updateLoopStep() { | |
// Step 1: Clear canvas | |
pongR.canvasContext.clearRect(0, 0, pongR.settings.viewport.width, pongR.settings.viewport.height); | |
// Step 2: Handle user inputs (update internal model) | |
var playerInput = handleClientInputs(pongR.me); | |
if (playerInput !== null) { | |
// Step 3: Send the just processed input batch to the server. | |
sendInput(pongR.game.gameId, pongR.me.user.connectionId, playerInput); | |
} | |
if (!pongR.settings.naive_approach) { | |
interpolateClientMovements(pongR.other); | |
} | |
// Step 3: Draw the new frame in the canvas | |
drawScene(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment