2022-11-17 15:39:32 +00:00
|
|
|
const i18n = require('LanguageData');
|
|
|
|
i18n.init(window.language); // languageID should be equal to the one we input in New Language ID input field
|
|
|
|
|
|
|
|
const OnlineMap = require('./Map');
|
|
|
|
|
|
|
|
cc.Class({
|
|
|
|
extends: OnlineMap,
|
|
|
|
|
|
|
|
onDestroy() {
|
|
|
|
console.warn("+++++++ Map onDestroy()");
|
|
|
|
},
|
|
|
|
|
|
|
|
onLoad() {
|
2023-01-21 14:53:41 +00:00
|
|
|
cc.game.setFrameRate(60);
|
2023-01-17 15:29:05 +00:00
|
|
|
cc.view.setOrientation(cc.macro.ORIENTATION_LANDSCAPE);
|
|
|
|
cc.view.enableAutoFullScreen(true);
|
2022-11-17 15:39:32 +00:00
|
|
|
const self = this;
|
|
|
|
window.mapIns = self;
|
2023-01-15 05:11:19 +00:00
|
|
|
self.showCriticalCoordinateLabels = false;
|
2023-01-21 14:53:41 +00:00
|
|
|
self.showNetworkDoctorInfo = true;
|
2022-11-17 15:39:32 +00:00
|
|
|
|
2022-11-19 12:58:07 +00:00
|
|
|
const mapNode = self.node;
|
|
|
|
const canvasNode = mapNode.parent;
|
|
|
|
|
|
|
|
self.mainCameraNode = self.canvasNode.getChildByName("Main Camera");
|
2022-11-17 15:39:32 +00:00
|
|
|
self.mainCamera = self.mainCameraNode.getComponent(cc.Camera);
|
|
|
|
for (let child of self.mainCameraNode.children) {
|
|
|
|
child.setScale(1 / self.mainCamera.zoomRatio);
|
|
|
|
}
|
|
|
|
self.widgetsAboveAllNode = self.mainCameraNode.getChildByName("WidgetsAboveAll");
|
|
|
|
self.mainCameraNode.setPosition(cc.v2());
|
|
|
|
|
|
|
|
/** Init required prefab ended. */
|
|
|
|
|
2022-11-19 12:58:07 +00:00
|
|
|
self.inputFrameUpsyncDelayTolerance = 2;
|
2023-02-15 04:02:07 +00:00
|
|
|
self.collisionMinStep = 8;
|
2022-11-17 15:39:32 +00:00
|
|
|
|
2022-12-01 03:35:56 +00:00
|
|
|
self.renderCacheSize = 1024;
|
2022-12-09 09:22:04 +00:00
|
|
|
self.serverFps = 60;
|
2022-11-19 12:58:07 +00:00
|
|
|
self.rollbackEstimatedDt = 0.016667;
|
|
|
|
self.rollbackEstimatedDtMillis = 16.667;
|
|
|
|
self.rollbackEstimatedDtNanos = 16666666;
|
2022-12-12 11:11:59 +00:00
|
|
|
self.tooFastDtIntervalMillis = 0.5 * self.rollbackEstimatedDtMillis;
|
2022-11-17 15:39:32 +00:00
|
|
|
|
|
|
|
const tiledMapIns = self.node.getComponent(cc.TiledMap);
|
|
|
|
|
2022-11-19 12:58:07 +00:00
|
|
|
const fullPathOfTmxFile = cc.js.formatStr("map/%s/map", "dungeon");
|
2022-11-17 15:39:32 +00:00
|
|
|
cc.loader.loadRes(fullPathOfTmxFile, cc.TiledMapAsset, (err, tmxAsset) => {
|
|
|
|
if (null != err) {
|
|
|
|
console.error(err);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
tiledMapIns.tmxAsset = null;
|
|
|
|
mapNode.removeAllChildren();
|
|
|
|
|
2022-12-11 04:20:42 +00:00
|
|
|
if (self.showCriticalCoordinateLabels) {
|
|
|
|
const drawer = new cc.Node();
|
|
|
|
drawer.setPosition(cc.v2(0, 0))
|
|
|
|
safelyAddChild(self.node, drawer);
|
|
|
|
setLocalZOrder(drawer, 999);
|
|
|
|
const g = drawer.addComponent(cc.Graphics);
|
|
|
|
g.lineWidth = 2;
|
|
|
|
self.g = g;
|
|
|
|
}
|
|
|
|
|
2022-11-17 15:39:32 +00:00
|
|
|
tiledMapIns.tmxAsset = tmxAsset;
|
|
|
|
const newMapSize = tiledMapIns.getMapSize();
|
|
|
|
const newTileSize = tiledMapIns.getTileSize();
|
|
|
|
self.node.setContentSize(newMapSize.width * newTileSize.width, newMapSize.height * newTileSize.height);
|
|
|
|
self.node.setPosition(cc.v2(0, 0));
|
|
|
|
|
2023-01-01 07:43:25 +00:00
|
|
|
self.spaceOffsetX = ((newMapSize.width * newTileSize.width) >> 1);
|
|
|
|
self.spaceOffsetY = ((newMapSize.height * newTileSize.height) >> 1);
|
2022-12-26 07:11:35 +00:00
|
|
|
|
|
|
|
self._resetCurrentMatch();
|
2022-11-17 15:39:32 +00:00
|
|
|
let barrierIdCounter = 0;
|
|
|
|
const boundaryObjs = tileCollisionManager.extractBoundaryObjects(self.node);
|
|
|
|
for (let boundaryObj of boundaryObjs.barriers) {
|
2022-12-26 07:11:35 +00:00
|
|
|
const gopkgsBoundaryAnchor = gopkgs.NewVec2DJs(boundaryObj.anchor.x, boundaryObj.anchor.y);
|
|
|
|
const gopkgsBoundaryPts = Array.from(boundaryObj, p => {
|
|
|
|
return gopkgs.NewVec2DJs(p.x, p.y);
|
|
|
|
});
|
|
|
|
const gopkgsBoundary = gopkgs.NewPolygon2DJs(gopkgsBoundaryAnchor, gopkgsBoundaryPts);
|
|
|
|
const gopkgsBarrier = gopkgs.NewBarrierJs(gopkgsBoundary);
|
2022-11-17 15:39:32 +00:00
|
|
|
|
2022-12-26 07:11:35 +00:00
|
|
|
const newBarrierCollider = gopkgs.GenerateConvexPolygonColliderJs(gopkgsBoundary, self.spaceOffsetX, self.spaceOffsetY, gopkgsBarrier, "Barrier");
|
|
|
|
self.gopkgsCollisionSys.Add(newBarrierCollider);
|
2022-11-17 15:39:32 +00:00
|
|
|
|
2022-12-26 07:11:35 +00:00
|
|
|
// console.log("Created barrier: ", newBarrierCollider);
|
2022-11-17 15:39:32 +00:00
|
|
|
++barrierIdCounter;
|
|
|
|
const collisionBarrierIndex = (self.collisionBarrierIndexPrefix + barrierIdCounter);
|
2022-12-26 07:11:35 +00:00
|
|
|
self.gopkgsCollisionSysMap[collisionBarrierIndex] = newBarrierCollider;
|
2022-11-17 15:39:32 +00:00
|
|
|
}
|
2023-01-04 15:48:00 +00:00
|
|
|
self.initDebugDrawers();
|
2022-11-19 12:58:07 +00:00
|
|
|
|
2023-01-01 07:43:25 +00:00
|
|
|
const p1Vpos = gopkgs.WorldToVirtualGridPos(boundaryObjs.playerStartingPositions[0].x, boundaryObjs.playerStartingPositions[0].y);
|
2023-01-01 12:18:35 +00:00
|
|
|
const p2Vpos = gopkgs.WorldToVirtualGridPos(boundaryObjs.playerStartingPositions[1].x, boundaryObjs.playerStartingPositions[1].y);
|
|
|
|
const colliderRadiusV = gopkgs.WorldToVirtualGridPos(12.0, 0);
|
2023-01-01 07:43:25 +00:00
|
|
|
|
2023-02-15 04:02:07 +00:00
|
|
|
const speciesIdList = [1, 0];
|
2023-01-12 08:09:20 +00:00
|
|
|
const chConfigsOrderedByJoinIndex = gopkgs.GetCharacterConfigsOrderedByJoinIndex(speciesIdList);
|
|
|
|
|
2022-11-25 05:24:03 +00:00
|
|
|
const startRdf = window.pb.protos.RoomDownsyncFrame.create({
|
2022-11-19 12:58:07 +00:00
|
|
|
id: window.MAGIC_ROOM_DOWNSYNC_FRAME_ID.BATTLE_START,
|
2022-12-26 07:11:35 +00:00
|
|
|
playersArr: [
|
|
|
|
window.pb.protos.PlayerDownsync.create({
|
2022-11-19 12:58:07 +00:00
|
|
|
id: 10,
|
2022-11-20 13:07:45 +00:00
|
|
|
joinIndex: 1,
|
2023-01-01 07:43:25 +00:00
|
|
|
virtualGridX: p1Vpos[0],
|
|
|
|
virtualGridY: p1Vpos[1],
|
2023-02-08 08:15:05 +00:00
|
|
|
revivalVirtualGridX: p1Vpos[0],
|
|
|
|
revivalVirtualGridY: p1Vpos[1],
|
2023-01-12 08:09:20 +00:00
|
|
|
speed: chConfigsOrderedByJoinIndex[0].Speed,
|
2023-01-01 12:18:35 +00:00
|
|
|
colliderRadius: colliderRadiusV[0],
|
2022-12-31 07:47:45 +00:00
|
|
|
characterState: window.ATK_CHARACTER_STATE.InAirIdle1NoJump[0],
|
2022-11-23 07:04:32 +00:00
|
|
|
framesToRecover: 0,
|
2023-01-01 12:18:35 +00:00
|
|
|
dirX: +2,
|
|
|
|
dirY: 0,
|
|
|
|
velX: 0,
|
|
|
|
velY: 0,
|
|
|
|
inAir: true,
|
2023-01-12 08:09:20 +00:00
|
|
|
onWall: false,
|
2023-02-08 08:15:05 +00:00
|
|
|
hp: 100,
|
|
|
|
maxHp: 100,
|
2023-01-01 12:18:35 +00:00
|
|
|
}),
|
|
|
|
window.pb.protos.PlayerDownsync.create({
|
|
|
|
id: 11,
|
|
|
|
joinIndex: 2,
|
|
|
|
virtualGridX: p2Vpos[0],
|
|
|
|
virtualGridY: p2Vpos[1],
|
2023-02-08 08:15:05 +00:00
|
|
|
revivalVirtualGridX: p2Vpos[0],
|
|
|
|
revivalVirtualGridY: p2Vpos[1],
|
2023-01-12 08:09:20 +00:00
|
|
|
speed: chConfigsOrderedByJoinIndex[1].Speed,
|
2023-01-01 12:18:35 +00:00
|
|
|
colliderRadius: colliderRadiusV[0],
|
|
|
|
characterState: window.ATK_CHARACTER_STATE.InAirIdle1NoJump[0],
|
|
|
|
framesToRecover: 0,
|
|
|
|
dirX: -2,
|
2022-11-23 14:11:28 +00:00
|
|
|
dirY: 0,
|
2022-12-09 09:22:04 +00:00
|
|
|
velX: 0,
|
|
|
|
velY: 0,
|
|
|
|
inAir: true,
|
2023-01-12 08:09:20 +00:00
|
|
|
onWall: false,
|
2023-02-08 08:15:05 +00:00
|
|
|
hp: 100,
|
|
|
|
maxHp: 100,
|
2022-12-09 09:22:04 +00:00
|
|
|
}),
|
2022-12-31 07:47:45 +00:00
|
|
|
],
|
2023-01-12 08:09:20 +00:00
|
|
|
speciesIdList: speciesIdList,
|
2022-11-25 05:24:03 +00:00
|
|
|
});
|
2022-12-26 07:11:35 +00:00
|
|
|
|
2022-11-19 12:58:07 +00:00
|
|
|
self.selfPlayerInfo = {
|
2022-12-28 10:06:05 +00:00
|
|
|
Id: 10,
|
|
|
|
JoinIndex: 1,
|
2022-11-19 12:58:07 +00:00
|
|
|
};
|
2023-01-23 06:17:52 +00:00
|
|
|
if (cc.sys.isNative) {
|
2023-01-24 12:00:58 +00:00
|
|
|
window.onUdpMessage = (args) => {
|
|
|
|
const len = args.length;
|
|
|
|
const ui8Arr = new Uint8Array(len);
|
|
|
|
for (let i = 0; i < len; i++) {
|
|
|
|
ui8Arr[i] = args.charCodeAt(i);
|
|
|
|
}
|
|
|
|
cc.log(`#1 Js called back by CPP: onUdpMessage: args=${args}, typeof(args)=${typeof (args)}, argslen=${args.length}, ui8Arr=${ui8Arr}`);
|
|
|
|
const echoed = window.pb.protos.HolePunchUpsync.decode(ui8Arr);
|
|
|
|
cc.log(`#2 Js called back by CPP: onUdpMessage: ${JSON.stringify(echoed)}`);
|
|
|
|
};
|
2023-01-23 06:17:52 +00:00
|
|
|
const res1 = DelayNoMore.UdpSession.openUdpSession(8888 + self.selfPlayerInfo.JoinIndex);
|
2023-01-25 10:26:13 +00:00
|
|
|
const holePunchData = window.pb.protos.HolePunchUpsync.encode({
|
2023-01-24 04:00:49 +00:00
|
|
|
boundRoomId: 22,
|
|
|
|
intAuthToken: "foobar",
|
|
|
|
authKey: Math.floor(Math.random() * 65535),
|
|
|
|
}).finish()
|
2023-01-29 14:38:12 +00:00
|
|
|
//const res2 = DelayNoMore.UdpSession.punchToServer("127.0.0.1", 3000, holePunchData, 19999, holePunchData);
|
2023-01-27 14:51:34 +00:00
|
|
|
const res3 = DelayNoMore.UdpSession.upsertPeerUdpAddr([window.pb.protos.PeerUdpAddr.create({
|
|
|
|
ip: "192.168.31.194",
|
|
|
|
port: 6789,
|
|
|
|
authKey: 123456,
|
|
|
|
}), window.pb.protos.PeerUdpAddr.create({
|
|
|
|
ip: "192.168.1.101",
|
|
|
|
port: 8771,
|
|
|
|
authKey: 654321,
|
|
|
|
})], 2, self.selfPlayerInfo.JoinIndex);
|
2023-01-25 03:57:59 +00:00
|
|
|
//const res4 = DelayNoMore.UdpSession.closeUdpSession();
|
2023-01-23 06:17:52 +00:00
|
|
|
}
|
2022-11-19 12:58:07 +00:00
|
|
|
self.onRoomDownsyncFrame(startRdf);
|
|
|
|
|
|
|
|
self.battleState = ALL_BATTLE_STATES.IN_BATTLE;
|
2022-11-17 15:39:32 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
update(dt) {
|
|
|
|
const self = this;
|
|
|
|
if (ALL_BATTLE_STATES.IN_BATTLE == self.battleState) {
|
|
|
|
try {
|
|
|
|
let st = performance.now();
|
|
|
|
let prevSelfInput = null,
|
|
|
|
currSelfInput = null;
|
2023-01-02 12:42:23 +00:00
|
|
|
const noDelayInputFrameId = gopkgs.ConvertToNoDelayInputFrameId(self.renderFrameId); // It's important that "inputDelayFrames == 0" here
|
|
|
|
if (gopkgs.ShouldGenerateInputFrameUpsync(self.renderFrameId)) {
|
2023-01-31 23:27:10 +00:00
|
|
|
const prevAndCurrInputs = self.getOrPrefabInputFrameUpsync(noDelayInputFrameId, true);
|
2022-11-17 15:39:32 +00:00
|
|
|
prevSelfInput = prevAndCurrInputs[0];
|
|
|
|
currSelfInput = prevAndCurrInputs[1];
|
|
|
|
}
|
|
|
|
|
2022-12-26 07:11:35 +00:00
|
|
|
const [prevRdf, rdf] = self.rollbackAndChase(self.renderFrameId, self.renderFrameId + 1, self.gopkgsCollisionSys, self.gopkgsCollisionSysMap, false);
|
2022-11-25 03:20:05 +00:00
|
|
|
self.applyRoomDownsyncFrameDynamics(rdf, prevRdf);
|
2022-12-12 15:17:54 +00:00
|
|
|
self.showDebugBoundaries(rdf);
|
2022-12-12 11:11:59 +00:00
|
|
|
++self.renderFrameId;
|
|
|
|
self.lastRenderFrameIdTriggeredAt = performance.now();
|
2022-11-17 15:39:32 +00:00
|
|
|
let t3 = performance.now();
|
|
|
|
} catch (err) {
|
|
|
|
console.error("Error during Map.update", err);
|
2022-12-11 04:20:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2022-12-26 07:11:35 +00:00
|
|
|
|
2022-11-17 15:39:32 +00:00
|
|
|
});
|