[server] update
This commit is contained in:
@@ -1,26 +1,11 @@
|
|||||||
package ru.m.tankz.server.game;
|
package ru.m.tankz.server.game;
|
||||||
|
|
||||||
import ru.m.tankz.proto.GamesResponse;
|
import ru.m.tankz.proto.core.GameState;
|
||||||
import ru.m.tankz.proto.GameActionType;
|
import ru.m.tankz.proto.core.Game;
|
||||||
import ru.m.tankz.proto.GameActionRequest;
|
|
||||||
import ru.m.tankz.proto.GameObjectType;
|
|
||||||
import ru.m.tankz.proto.GameChangeType;
|
|
||||||
import ru.m.tankz.proto.GameUpdateResponse;
|
|
||||||
import ru.m.tankz.proto.GameChange;
|
|
||||||
import ru.m.tankz.proto.StartGameResponse;
|
|
||||||
import ru.m.tankz.core.Direction;
|
|
||||||
import ru.m.tankz.server.session.Thread;
|
import ru.m.tankz.server.session.Thread;
|
||||||
import ru.m.tankz.config.TankzConfig.DEFAULT;
|
|
||||||
import ru.m.tankz.engine.Engine;
|
import ru.m.tankz.engine.Engine;
|
||||||
import ru.m.tankz.proto.CreateGameResponse;
|
|
||||||
import ru.m.tankz.proto.LeaveGameResponse;
|
|
||||||
import ru.m.tankz.proto.JoinGameResponse;
|
|
||||||
import ru.m.tankz.server.session.Session;
|
import ru.m.tankz.server.session.Session;
|
||||||
import protohx.Message;
|
import protohx.Message;
|
||||||
import ru.m.tankz.proto.Person;
|
|
||||||
import ru.m.tankz.proto.GameState;
|
|
||||||
import ru.m.tankz.proto.Game;
|
|
||||||
import ru.m.tankz.engine.IEngine;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
@@ -58,27 +43,27 @@ class NekoTimer {
|
|||||||
class GameManager {
|
class GameManager {
|
||||||
|
|
||||||
public static var byGameId:Map<Int, GameManager> = new Map<Int, GameManager>();
|
public static var byGameId:Map<Int, GameManager> = new Map<Int, GameManager>();
|
||||||
public static var byPersonId:Map<Int, GameManager> = new Map<Int, GameManager>();
|
public static var byPersonId:Map<String, GameManager> = new Map<String, GameManager>();
|
||||||
public static var subscribers:Map<Int, Bool> = new Map<Int, Bool>();
|
public static var subscribers:Map<Int, Bool> = new Map<Int, Bool>();
|
||||||
|
|
||||||
private static var idCounter:Int = 0;
|
private static var idCounter:Int = 0;
|
||||||
|
|
||||||
public var game(default, null):Game;
|
public var game(default, null):Game;
|
||||||
|
|
||||||
public var engine(default, null):IEngine;
|
public var engine(default, null):Engine;
|
||||||
|
|
||||||
private var timer:NekoTimer;
|
private var timer:NekoTimer;
|
||||||
|
|
||||||
private var changes:Array<GameChange> = new Array<GameChange>();
|
//private var changes:Array<GameChange> = new Array<GameChange>();
|
||||||
|
|
||||||
public function new(person:Person) {
|
public function new(creator:User) {
|
||||||
game = new Game()
|
game = new Game()
|
||||||
.setId(idCounter++)
|
.setId(idCounter++)
|
||||||
.setState(GameState.READY)
|
.setState(GameState.READY)
|
||||||
.setCreator(person);
|
.setCreator(creator);
|
||||||
game.addPersons(person);
|
game.addPlayers(creator);
|
||||||
byGameId.set(game.id, this);
|
byGameId.set(game.id, this);
|
||||||
byPersonId.set(person.id, this);
|
byPersonId.set(creator.uuid, this);
|
||||||
broadcast(new CreateGameResponse().setGame(game));
|
broadcast(new CreateGameResponse().setGame(game));
|
||||||
broadcastGames();
|
broadcastGames();
|
||||||
}
|
}
|
||||||
@@ -96,8 +81,8 @@ class GameManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function broadcast(packet:Message) {
|
public function broadcast(packet:Message) {
|
||||||
for (person in game.persons) {
|
for (player in game.players) {
|
||||||
var session = Session.sessions.get(person.id);
|
var session = Session.sessions.get(player.uuid);
|
||||||
session.send(packet);
|
session.send(packet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ typedef ServerConnection = IConnection<Response, Request>;
|
|||||||
|
|
||||||
class Session {
|
class Session {
|
||||||
|
|
||||||
public static var sessions:Map<Int, Session> = new Map<Int, Session>();
|
public static var sessions:Map<String, Session> = new Map<String, Session>();
|
||||||
|
|
||||||
public var user(default, null):User;
|
public var user(default, null):User;
|
||||||
public var gameId(default, null):Int = -1;
|
public var gameId(default, null):Int = -1;
|
||||||
@@ -84,6 +84,7 @@ class Session {
|
|||||||
user = new User()
|
user = new User()
|
||||||
.setUuid(request.uuid != null ? request.uuid : 'xxx')
|
.setUuid(request.uuid != null ? request.uuid : 'xxx')
|
||||||
.setName(request.name);
|
.setName(request.name);
|
||||||
|
sessions.set(user.uuid, this);
|
||||||
return new LoginResponse().setUser(user);
|
return new LoginResponse().setUser(user);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -5,48 +5,48 @@ enum ThreadHandle {
|
|||||||
|
|
||||||
class Thread {
|
class Thread {
|
||||||
|
|
||||||
var handle : ThreadHandle;
|
var handle:ThreadHandle;
|
||||||
|
|
||||||
function new(h) {
|
function new(h) {
|
||||||
handle = h;
|
handle = h;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Send a message to the thread queue. This message can be readed by using [readMessage].
|
Send a message to the thread queue. This message can be readed by using [readMessage].
|
||||||
**/
|
**/
|
||||||
public function sendMessage( msg : Dynamic ) {
|
public function sendMessage(msg:Dynamic) {
|
||||||
thread_send(handle,msg);
|
thread_send(handle, msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Returns the current thread.
|
Returns the current thread.
|
||||||
**/
|
**/
|
||||||
public static function current() {
|
public static function current() {
|
||||||
return new Thread(thread_current());
|
return new Thread(thread_current());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Creates a new thread that will execute the [callb] function, then exit.
|
Creates a new thread that will execute the [callb] function, then exit.
|
||||||
**/
|
**/
|
||||||
public static function create( callb : Void -> Void ) {
|
public static function create(callb:Void -> Void) {
|
||||||
return new Thread(thread_create(function(_) { return callb(); },null));
|
return new Thread(thread_create(function(_) { return callb(); }, null));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Reads a message from the thread queue. If [block] is true, the function
|
Reads a message from the thread queue. If [block] is true, the function
|
||||||
blocks until a message is available. If [block] is false, the function
|
blocks until a message is available. If [block] is false, the function
|
||||||
returns [null] if no message is available.
|
returns [null] if no message is available.
|
||||||
**/
|
**/
|
||||||
public static function readMessage( block : Bool ) : Dynamic {
|
public static function readMessage(block:Bool):Dynamic {
|
||||||
return thread_read_message(block);
|
return thread_read_message(block);
|
||||||
}
|
}
|
||||||
|
|
||||||
@:keep function __compare(t) {
|
@:keep function __compare(t) {
|
||||||
return untyped __dollar__compare(handle,t.handle);
|
return untyped __dollar__compare(handle, t.handle);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
Starts an OS message loop after [osInitialize] has been done.
|
Starts an OS message loop after [osInitialize] has been done.
|
||||||
In that state, the UI handled by this thread will be updated and
|
In that state, the UI handled by this thread will be updated and
|
||||||
[sync] calls can be performed. The loop returns when [exitLoop] is
|
[sync] calls can be performed. The loop returns when [exitLoop] is
|
||||||
@@ -105,9 +105,8 @@ return untyped __dollar__compare(handle,t.handle);
|
|||||||
static var os_sync = null;
|
static var os_sync = null;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static var thread_create = neko.Lib.load("std","thread_create",2);
|
static var thread_create = neko.Lib.load("std", "thread_create", 2);
|
||||||
static var thread_current = neko.Lib.load("std","thread_current",0);
|
static var thread_current = neko.Lib.load("std", "thread_current", 0);
|
||||||
static var thread_send = neko.Lib.load("std","thread_send",2);
|
static var thread_send = neko.Lib.load("std", "thread_send", 2);
|
||||||
static var thread_read_message = neko.Lib.load("std","thread_read_message",1);
|
static var thread_read_message = neko.Lib.load("std", "thread_read_message", 1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user