PageRenderTime 54ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/js/model/Constants.js

http://github.com/onedayitwillmake/RealtimeMultiplayerNodeJs
JavaScript | 68 lines | 47 code | 5 blank | 16 comment | 0 complexity | cc9cb91bd0aeee07e6424bb4e6a4e716 MD5 | raw file
Possible License(s): GPL-2.0, LGPL-2.1, MPL-2.0-no-copyleft-exception, BSD-3-Clause
  1. /**
  2. File:
  3. Constants.js
  4. Created By:
  5. Mario Gonzalez
  6. Project:
  7. RealtimeMultiplayerNodeJS
  8. Abstract:
  9. This class contains Constants used by RealtimeMuliplayerGame
  10. Basic Usage:
  11. [This class is not instantiated! - below is an example of using this class by extending it]
  12. var clientDropWait = RealtimeMultiplayerGame.Constants.CL_DEFAULT_MAXRATE
  13. */
  14. (function () {
  15. RealtimeMultiplayerGame.Constants = {
  16. DEBUG_SETTING: {
  17. SERVER_NETCHANNEL_DEBUG: true,
  18. CLIENT_NETCHANNEL_DEBUG: true
  19. },
  20. SERVER_SETTING: {
  21. CLIENT_ID: 0, // If an object has a client id of zero, that means it is owned by the server
  22. SOCKET_PROTOCOL: "http",
  23. SOCKET_DOMAIN: "localhost",
  24. SOCKET_PORT: 8081,
  25. /** @return {string} */
  26. GET_URI: function () {
  27. return RealtimeMultiplayerGame.Constants.SERVER_SETTING.SOCKET_PROTOCOL
  28. + "://" + RealtimeMultiplayerGame.Constants.SERVER_SETTING.SOCKET_DOMAIN
  29. + ":" + RealtimeMultiplayerGame.Constants.SERVER_SETTING.SOCKET_PORT;
  30. }
  31. },
  32. CLIENT_SETTING: {
  33. INTERP: 75, // How far back to interpolate the client-rendered world
  34. FAKE_LAG: 0, // Used to simulate latency
  35. UPDATE_RATE: Math.round(1000 / 30), // How often to request a world-update from the server
  36. CMD_RATE: Math.round(1000 / 31), // How often a client can send messages to server
  37. MAX_BUFFER: 64,
  38. EXPIRED_ENTITY_CHECK_RATE: 30, // How often we clear out entities that the server says no longer exist. Lower looks better but decreases framerate
  39. MAX_UPDATE_FAILURE_COUNT: 3 // How many times we allow ourselves to fail when getting behind the server time
  40. },
  41. CMDS: {
  42. SERVER_CONNECT: 1 << 1, // Dispatched by the server if it acknowledges a client connection
  43. SERVER_MATCH_START: 1 << 2, // Server broadcast game start
  44. SERVER_END_GAME: 1 << 3, // Server broadcast game over
  45. PLAYER_CONNECT: 1 << 4, // Initial connection to the server, not in game yet
  46. PLAYER_JOINED: 1 << 5, // Player has joined the current game
  47. PLAYER_DISCONNECT: 1 << 6, // Player has disconnected
  48. PLAYER_UPDATE: 1 << 7, // Player is sending sampled input
  49. SERVER_FULL_UPDATE: 1 << 8 // Player is sending sampled input
  50. },
  51. // The client sends this bitmask to the server
  52. // See (Keyboard.js)
  53. INPUT_BITMASK: {
  54. UP: 1 << 0,
  55. DOWN: 1 << 1,
  56. LEFT: 1 << 2,
  57. RIGHT: 1 << 3,
  58. SPACE: 1 << 4,
  59. SHIFT: 1 << 5,
  60. TAB: 1 << 6
  61. }
  62. }
  63. })();