refactor(server): use cpp target instead of neko

This commit is contained in:
2023-01-02 14:36:44 +03:00
parent 1cfc98dd57
commit a39b02bfe7
7 changed files with 70 additions and 14 deletions

View File

@@ -2,12 +2,12 @@ package ru.m.tankz.server;
import haxe.io.Bytes;
import haxework.log.TraceLogger;
import neko.net.ThreadServer;
import cpp.net.ThreadServer;
import ru.m.tankz.bundle.CachedLevelBundle;
import ru.m.tankz.bundle.IConfigBundle;
import ru.m.tankz.bundle.ILevelBundle;
import ru.m.tankz.server.bundle.ServerConfigBundle;
import ru.m.tankz.server.bundle.ServerLevelSource;
import ru.m.tankz.server.bundle.AssetConfigBundle;
import ru.m.tankz.server.bundle.AssetLevelSource;
import ru.m.tankz.server.game.GameManager;
import ru.m.tankz.server.game.IGameManager;
import ru.m.tankz.server.session.GameSession;
@@ -48,8 +48,8 @@ class Server extends ThreadServer<GameSession, Bytes> {
#end
L.d(TAG, 'Running');
L.i(TAG, 'Build: ${CompilationOption.get("build")}');
configBundle = new ServerConfigBundle();
levelBundle = new CachedLevelBundle(new ServerLevelSource());
configBundle = new AssetConfigBundle();
levelBundle = new CachedLevelBundle(new AssetLevelSource());
levelBundle.load();
gameManager = new GameManager();
var host:String = Sys.args().length > 0 ? Sys.args()[0] : "0.0.0.0";

View File

@@ -0,0 +1,23 @@
package ru.m.tankz.server.bundle;
import openfl.Assets;
import ru.m.tankz.bundle.IConfigBundle;
import ru.m.tankz.config.Config;
import ru.m.tankz.Type;
import yaml.Parser;
import yaml.Yaml;
class AssetConfigBundle implements IConfigBundle {
private var _cache:Map<GameType, Config> = new Map();
public function new() {}
public function get(type:GameType):Config {
if (!_cache.exists(type)) {
var source:ConfigSource = Yaml.parse(Assets.getText('config/${type}.yaml'), Parser.options().useObjects());
_cache.set(type, Config.fromSource(type, source));
}
return _cache.get(type);
}
}

View File

@@ -0,0 +1,33 @@
package ru.m.tankz.server.bundle;
import openfl.Assets;
import openfl.utils.AssetType;
import ru.m.tankz.bundle.ILevelBundle;
import ru.m.tankz.config.Config;
import ru.m.tankz.Type;
import ru.m.tankz.util.LevelUtil;
class AssetLevelSource implements ILevelSource {
public function new() {}
public function resolveMeta(id:PackId):LevelPackMeta {
var bytes = Assets.getBytes('level/${id}.zip');
return LevelUtil.getMeta(bytes);
}
public function resolve(id:PackId):LevelPack {
var bytes = Assets.getBytes('level/${id}.zip');
return LevelUtil.unpack(bytes);
}
public function list():Array<PackId> {
var result = [];
for (path in Assets.list(AssetType.BINARY)) {
if (StringTools.startsWith(path, "level")) {
result.push(PackId.fromString(path.split("/").pop().split(".").shift()));
}
}
return result;
}
}