내 구현을 살펴 권장하지만, 노드와 "multiplayering"의 일반적인 개념을 가리켜 야합니다.
가장 간단한 방법은 클라이언트와 서버 모두에서 플레이어 (엔티티)가 포함 된 연관 배열을 만드는 것입니다. 그런 다음 클라이언트 측에서 {action: "move", target:[32, 100]}
과 같은 명령을 보내고이 명령을 서버 로직 (실제 게임이 실행되는 곳)으로 처리하십시오. 당신이 액세스 할 수 있도록 플레이어 객체 또는 아이디를 할당해야합니다 on connection
각 소켓에 좋아 :에서 다음
{
timestamp: game.delta,
players: {
1: {x: 32, y: 100},
2: {x: 14, y: 11}
}
}
를 실행 한 다음, 다음
var lastPlayerID = 0;
var players = {};
server.on("connection", function(socket) {
var newcommer = new Player({id: lastPlayerID});
players[lastPlayerID] = newcommer;
socket.player = newcommer; // or lastPlayerID
lastPlayerID++;
socket.onMessage = function(message) {
this.player.doSomething();
}
});
각각의 사용자가 연결된 모든 플레이어에게 스냅 샷을 보낼 수 100ms로 말을하자 클라이언트 쪽에서 데이터를 받고 이전 값에서 새 값으로 보간합니다.
// duration in this simplified example is snapshot sending interval in [ms]
Player.prototype.interpolateTo = function(data, duration) {
if(typeof data.x != "undefined") {
// step needed to get `destination x` within `duration` miliseconds
this.stepValues.x = Math.abs(data.x - this.x)/duration;
this.target.x = data.x;
}
// ...
}
// step you call for each game loop iteration
Player.prototype.step = function(delta) {
if(this.x < this.target.x) {
this.x += delta * this.stepValues.x
}
}
최대 20 개의 객체가있는 반 아케이드 게임에 충분한 알고리즘입니다. 스냅 샷의 간격을 줄이면 더 많은 대상을 가진 전략 게임에 거의 적합합니다. 당신의 주적은 대역폭 사용을 최소화하여 패킷의 크기를 최소화 할 수 있습니다. 예를 들어 BiSON, LZW에 대해 읽고 마지막 스냅 샷 이후 변경되지 않은 데이터를 보내지 마십시오.
내 평판은 내가 모든 링크를 게시 할 수 없습니다, 그래서 여기를 첨부 :
http://pastebin.com/Kh3wvF1D
일반 소개 글렌 Fiedler는에 의해 개념을 멀티 플레이어하기 :
http://gafferongames.com/networking-for-game-programmers/what-every-programmer-needs-to-know-about-game-networking/
퀘이크의 일부 멀티 플레이어 기술 : 이것은 i에 대한 단서를 제공합니다. nterpolation 및 추정 (예측)
http://fabiensanglard.net/quakeSource/quakeSourcePrediction.php
지연 보상 및 일반 최적화에 대한 밸브의 기사 :
https://developer.valvesoftware.com/wiki/Latency_Compensating_Methods_in_Client/Server_In-game_Protocol_Design_and_Optimization
제국의 시대
멀티 기술 :
,
http://zoo.cs.yale.edu/classes/cs538/readings/papers/terrano_1500arch.pdf#search=%22Real%20time%20strategy%20networking%20lockstep%22
당신은 또한 지식의 큰 더미의 이보의 Wetzel는 Mapple.js에 대한 대역폭 사용
http://rezoner.net/minimizing-bandwidth-usage-in-html5-games-using-websocket,299
+1을 최적화하는 방법에 대한 내 기사를 읽을 수 있습니다.
https://github.com/BonsaiDen/Maple.js
Stackoverflow에 오신 것을 환영합니다! 아주 좋은 대답, 이런 식으로 계속하고 담당자의 부족은 아주 오래 문제가해서는 안됩니다. :) – RedRiderX
그런 자세한 설명을 주셔서 감사합니다 :) – Henryz