temp
This commit is contained in:
parent
1270ae6817
commit
0b78eb6277
7 changed files with 102 additions and 208 deletions
|
@ -1,12 +1,10 @@
|
|||
import {MessageUserPosition, Point} from "./Websocket/MessageUserPosition";
|
||||
import {PointInterface} from "./Websocket/PointInterface";
|
||||
import {Group} from "./Group";
|
||||
import {Distance} from "./Distance";
|
||||
import {User} from "./User";
|
||||
import {ExSocketInterface} from "_Model/Websocket/ExSocketInterface";
|
||||
import {PositionInterface} from "_Model/PositionInterface";
|
||||
import {Identificable} from "_Model/Websocket/Identificable";
|
||||
import {EntersCallback, LeavesCallback, MovesCallback, Zone} from "_Model/Zone";
|
||||
import {EntersCallback, LeavesCallback, MovesCallback} from "_Model/Zone";
|
||||
import {PositionNotifier} from "./PositionNotifier";
|
||||
import {ViewportInterface} from "_Model/Websocket/ViewportMessage";
|
||||
import {Movable} from "_Model/Movable";
|
||||
|
@ -14,7 +12,7 @@ import {Movable} from "_Model/Movable";
|
|||
export type ConnectCallback = (user: User, group: Group) => void;
|
||||
export type DisconnectCallback = (user: User, group: Group) => void;
|
||||
|
||||
export class World {
|
||||
export class GameRoom {
|
||||
private readonly minDistance: number;
|
||||
private readonly groupRadius: number;
|
||||
|
||||
|
@ -123,7 +121,7 @@ export class World {
|
|||
} else {
|
||||
// If the user is part of a group:
|
||||
// should he leave the group?
|
||||
const distance = World.computeDistanceBetweenPositions(user.getPosition(), user.group.getPosition());
|
||||
const distance = GameRoom.computeDistanceBetweenPositions(user.getPosition(), user.group.getPosition());
|
||||
if (distance > this.groupRadius) {
|
||||
this.leaveGroup(user);
|
||||
}
|
||||
|
@ -199,53 +197,19 @@ export class World {
|
|||
return;
|
||||
}
|
||||
|
||||
const distance = World.computeDistance(user, currentUser); // compute distance between peers.
|
||||
const distance = GameRoom.computeDistance(user, currentUser); // compute distance between peers.
|
||||
|
||||
if(distance <= minimumDistanceFound && distance <= this.minDistance) {
|
||||
minimumDistanceFound = distance;
|
||||
matchingItem = currentUser;
|
||||
}
|
||||
/*if (typeof currentUser.group === 'undefined' || !currentUser.group.isFull()) {
|
||||
// We found a user we can bind to.
|
||||
return;
|
||||
}*/
|
||||
/*
|
||||
if(context.groups.length > 0) {
|
||||
|
||||
context.groups.forEach(group => {
|
||||
if(group.isPartOfGroup(userPosition)) { // Is the user in a group ?
|
||||
if(group.isStillIn(userPosition)) { // Is the user leaving the group ? (is the user at more than max distance of each player)
|
||||
|
||||
// Should we split the group? (is each player reachable from the current player?)
|
||||
// This is needed if
|
||||
// A <==> B <==> C <===> D
|
||||
// becomes A <==> B <=====> C <> D
|
||||
// If C moves right, the distance between B and C is too great and we must form 2 groups
|
||||
|
||||
}
|
||||
} else {
|
||||
// If the user is in no group
|
||||
// Is there someone in a group close enough and with room in the group ?
|
||||
}
|
||||
});
|
||||
|
||||
} else {
|
||||
// Aucun groupe n'existe donc je stock les users assez proches de moi
|
||||
let dist: Distance = {
|
||||
distance: distance,
|
||||
first: userPosition,
|
||||
second: user // TODO: convertir en messageUserPosition
|
||||
}
|
||||
usersToBeGroupedWith.push(dist);
|
||||
}
|
||||
*/
|
||||
});
|
||||
|
||||
this.groups.forEach((group: Group) => {
|
||||
if (group.isFull()) {
|
||||
return;
|
||||
}
|
||||
const distance = World.computeDistanceBetweenPositions(user.getPosition(), group.getPosition());
|
||||
const distance = GameRoom.computeDistanceBetweenPositions(user.getPosition(), group.getPosition());
|
||||
if(distance <= minimumDistanceFound && distance <= this.groupRadius) {
|
||||
minimumDistanceFound = distance;
|
||||
matchingItem = group;
|
||||
|
@ -275,66 +239,7 @@ export class World {
|
|||
return this.itemsState;
|
||||
}
|
||||
|
||||
/*getDistancesBetweenGroupUsers(group: Group): Distance[]
|
||||
{
|
||||
let i = 0;
|
||||
let users = group.getUsers();
|
||||
let distances: Distance[] = [];
|
||||
users.forEach(function(user1, key1) {
|
||||
users.forEach(function(user2, key2) {
|
||||
if(key1 < key2) {
|
||||
distances[i] = {
|
||||
distance: World.computeDistance(user1, user2),
|
||||
first: user1,
|
||||
second: user2
|
||||
};
|
||||
i++;
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
distances.sort(World.compareDistances);
|
||||
|
||||
return distances;
|
||||
}
|
||||
|
||||
filterGroup(distances: Distance[], group: Group): void
|
||||
{
|
||||
let users = group.getUsers();
|
||||
let usersToRemove = false;
|
||||
let groupTmp: MessageUserPosition[] = [];
|
||||
distances.forEach(dist => {
|
||||
if(dist.distance <= World.MIN_DISTANCE) {
|
||||
let users = [dist.first];
|
||||
let usersbis = [dist.second]
|
||||
groupTmp.push(dist.first);
|
||||
groupTmp.push(dist.second);
|
||||
} else {
|
||||
usersToRemove = true;
|
||||
}
|
||||
});
|
||||
|
||||
if(usersToRemove) {
|
||||
// Detecte le ou les users qui se sont fait sortir du groupe
|
||||
let difference = users.filter(x => !groupTmp.includes(x));
|
||||
|
||||
// TODO : Notify users un difference that they have left the group
|
||||
}
|
||||
|
||||
let newgroup = new Group(groupTmp);
|
||||
this.groups.push(newgroup);
|
||||
}
|
||||
|
||||
private static compareDistances(distA: Distance, distB: Distance): number
|
||||
{
|
||||
if (distA.distance < distB.distance) {
|
||||
return -1;
|
||||
}
|
||||
if (distA.distance > distB.distance) {
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}*/
|
||||
|
||||
setViewport(socket : Identificable, viewport: ViewportInterface): Movable[] {
|
||||
const user = this.users.get(socket.userId);
|
||||
if(typeof user === 'undefined') {
|
|
@ -1,7 +1,6 @@
|
|||
import { World, ConnectCallback, DisconnectCallback } from "./World";
|
||||
import { ConnectCallback, DisconnectCallback } from "./GameRoom";
|
||||
import { User } from "./User";
|
||||
import {PositionInterface} from "_Model/PositionInterface";
|
||||
import {uuid} from "uuidv4";
|
||||
import {Movable} from "_Model/Movable";
|
||||
import {PositionNotifier} from "_Model/PositionNotifier";
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue