PageRenderTime 42ms CodeModel.GetById 20ms app.highlight 4ms RepoModel.GetById 16ms 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
 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
21        SERVER_SETTING: {
22            CLIENT_ID: 0,						// If an object has a client id of zero, that means it is owned by the server
23            SOCKET_PROTOCOL: "http",
24            SOCKET_DOMAIN: "localhost",
25            SOCKET_PORT: 8081,
26
27            /** @return {string} */
28            GET_URI: function () {
29                return  RealtimeMultiplayerGame.Constants.SERVER_SETTING.SOCKET_PROTOCOL
30                    + "://" + RealtimeMultiplayerGame.Constants.SERVER_SETTING.SOCKET_DOMAIN
31                    + ":" + RealtimeMultiplayerGame.Constants.SERVER_SETTING.SOCKET_PORT;
32            }
33        },
34
35        CLIENT_SETTING: {
36            INTERP: 75,						// How far back to interpolate the client-rendered world
37            FAKE_LAG: 0,						// Used to simulate latency
38            UPDATE_RATE: Math.round(1000 / 30), 					// How often to request a world-update from the server
39            CMD_RATE: Math.round(1000 / 31),                  // How often a client can send messages to server
40            MAX_BUFFER: 64,
41            EXPIRED_ENTITY_CHECK_RATE: 30,		// How often we clear out entities that the server says no longer exist. Lower looks better but decreases framerate
42            MAX_UPDATE_FAILURE_COUNT: 3			// How many times we allow ourselves to fail when getting behind the server time
43        },
44
45        CMDS: {
46            SERVER_CONNECT: 1 << 1,			// Dispatched by the server if it acknowledges a client connection
47            SERVER_MATCH_START: 1 << 2,			// Server broadcast game start
48            SERVER_END_GAME: 1 << 3,			// Server broadcast game over
49            PLAYER_CONNECT: 1 << 4,			// Initial connection to the server, not in game yet
50            PLAYER_JOINED: 1 << 5,           // Player has joined the current game
51            PLAYER_DISCONNECT: 1 << 6,           // Player has disconnected
52            PLAYER_UPDATE: 1 << 7,			// Player is sending sampled input
53            SERVER_FULL_UPDATE: 1 << 8			// Player is sending sampled input
54        },
55
56        // The client sends this bitmask to the server
57        // See (Keyboard.js)
58        INPUT_BITMASK: {
59            UP: 1 << 0,
60            DOWN: 1 << 1,
61            LEFT: 1 << 2,
62            RIGHT: 1 << 3,
63            SPACE: 1 << 4,
64            SHIFT: 1 << 5,
65            TAB: 1 << 6
66        }
67    }
68})();