#61 Remote map chunk storage and equesting working, waiting for renderer

This commit is contained in:
Danielv123 committed 2017-12-10 20:55:53 +01:00
1 parent 8fce9a2cfe
commit eba982836c
3 files changed
+40 -5

No files matched your search

+27 -3
View File
@@ -614,16 +614,40 @@ class slaveMapper {
constructor(instanceID, socket) {
this.instanceID = instanceID;
this.socket = socket;
}
getChunk(x,y){
this.socket.on("sendChunk", function(data){
mapRequesters[data.requesterID].socket.emit("displayChunk", data)
});
}
}
var mapRequesters = {};
class mapRequester {
constructor(requesterID, socket, instanceID){
this.requesterID = requesterID;
this.socket = socket;
this.instanceID = instanceID;
this.socket.on("requestChunk", loc => {
loc.requesterID = this.requesterID;
let instanceID = loc.instanceID || this.instanceID;
if(slaveMappers[instanceID] && typeof loc.x == "number" && typeof loc.y == "number"){
slaveMappers[instanceID].socket.emit("getChunk", loc)
}
});
}
}
io.on('connection', function (socket) {
socket.emit('hello', { hello: 'world' });
socket.on('registerSlaveMapper', function (data) {
console.log(data);
slaveMappers[data.instanceID] = new slaveMapper(data.instanceID, socket);
console.log("SOCKET registered map provider for "+data.instanceID);
});
socket.on('registerMapRequester', function(data){
// data {instanceID:""}
let requesterID = Math.random().toString();
mapRequesters[requesterID] = new mapRequester(requesterID, socket, data.instanceID);
console.log("SOCKET registered map requester for "+data.instanceID);
});
});
+4 -1
View File
@@ -21,7 +21,10 @@ class remoteMap {
this.socket.emit("registerSlaveMapper", {instanceID: this.config.unique});
});
this.socket.on("getChunk", req => {
this.chunkMap.getChunk(req.x, req.y).then(chunk => {
chunk.requesterID = req.requesterID;
this.socket.emit("sendChunk", chunk);
});
});
this.messageInterface("/silent-command game.print('"+moduleConfig.name+" version "+moduleConfig.version+" enabled')");
+9 -1
View File
@@ -1,5 +1,13 @@
var socket = io.connect('http://localhost:8080');
socket.on('hello', function (data) {
console.log(data);
socket.emit('registerSlaveMappper', { instanceID: 'data' });
socket.emit("registerMapRequester", {instanceID: '1611985668'});
socket.on("displayChunk", function(chunk){
console.log(chunk)
});
});
function requestChunk(x,y){
socket.emit('requestChunk', {x:x, y:y, instanceID: '1611985668'});
}