mirror of
https://github.com/genxium/DelayNoMore
synced 2025-10-09 00:26:39 +00:00
Fixed fireball rollback mechanism.
This commit is contained in:
@@ -1,37 +1,34 @@
|
||||
cc.Class({
|
||||
extends: cc.Component,
|
||||
extends: cc.Component,
|
||||
|
||||
properties: {
|
||||
mapNode: {
|
||||
type: cc.Node,
|
||||
default: null
|
||||
},
|
||||
speed: {
|
||||
type: cc.Float,
|
||||
default: 500
|
||||
},
|
||||
properties: {
|
||||
mapNode: {
|
||||
type: cc.Node,
|
||||
default: null
|
||||
},
|
||||
|
||||
onLoad () {
|
||||
this.mainCamera = this.mapNode.parent.getChildByName("Main Camera").getComponent(cc.Camera);
|
||||
this.mapScriptIns = this.mapNode.getComponent("Map");
|
||||
speed: {
|
||||
type: cc.Float,
|
||||
default: 500
|
||||
},
|
||||
},
|
||||
|
||||
start() {},
|
||||
onLoad() {
|
||||
this.mainCamera = this.mapNode.parent.getChildByName("Main Camera").getComponent(cc.Camera);
|
||||
this.mapScriptIns = this.mapNode.getComponent("Map");
|
||||
},
|
||||
|
||||
update(dt) {
|
||||
const self = this;
|
||||
if (!self.mainCamera) return;
|
||||
if (!self.mapScriptIns) return;
|
||||
if (!self.mapScriptIns.selfPlayerInfo) return;
|
||||
if (!self.mapScriptIns.playerRichInfoDict) return;
|
||||
const selfPlayerRichInfo = self.mapScriptIns.playerRichInfoDict.get(self.mapScriptIns.selfPlayerInfo.Id);
|
||||
if (!selfPlayerRichInfo) return;
|
||||
const selfPlayerNode = selfPlayerRichInfo.node;
|
||||
if (!selfPlayerNode) return;
|
||||
const pDiff = selfPlayerNode.position.sub(self.mainCamera.node.position);
|
||||
pDiff.normalizeSelf();
|
||||
const newCamPos = self.mainCamera.node.position.add(pDiff.mul(dt*self.speed));
|
||||
self.mainCamera.node.setPosition(newCamPos);
|
||||
}
|
||||
start() {},
|
||||
|
||||
update(dt) {
|
||||
const self = this;
|
||||
if (!self.mainCamera) return;
|
||||
if (!self.mapScriptIns) return;
|
||||
if (!self.mapScriptIns.selfPlayerInfo) return;
|
||||
if (!self.mapScriptIns.playerRichInfoDict) return;
|
||||
const selfPlayerRichInfo = self.mapScriptIns.playerRichInfoDict.get(self.mapScriptIns.selfPlayerInfo.Id);
|
||||
if (!selfPlayerRichInfo) return;
|
||||
const selfPlayerNode = selfPlayerRichInfo.node;
|
||||
if (!selfPlayerNode) return;
|
||||
self.mapNode.setPosition(cc.v2().sub(selfPlayerNode.position));
|
||||
}
|
||||
});
|
||||
|
@@ -1,6 +1,13 @@
|
||||
cc.Class({
|
||||
extends: cc.Component,
|
||||
|
||||
properties: {
|
||||
animNode: {
|
||||
type: cc.Node,
|
||||
default: null
|
||||
},
|
||||
},
|
||||
|
||||
ctor() {
|
||||
this.lastUsed = -1;
|
||||
this.bulletLocalId = -1;
|
||||
@@ -9,28 +16,30 @@ cc.Class({
|
||||
|
||||
setSpecies(speciesName, fireballBullet, rdf) {
|
||||
if (speciesName == this.speciesName) return;
|
||||
this.speciesName = speciesName;
|
||||
this.effAnimNode = this.node.getChildByName(this.speciesName);
|
||||
this.animComp = this.effAnimNode.getComponent(cc.Animation);
|
||||
this.effAnimNode.active = true;
|
||||
for (let k in this.children) {
|
||||
const child = this.children[k];
|
||||
if (!child.active) continue;
|
||||
if (child == effAnimNode || child.name == speciesName) continue;
|
||||
child.active = false;
|
||||
if (null != this.speciesName) {
|
||||
for (let k in this.animNode.children) {
|
||||
const child = this.children[k];
|
||||
if (!child.active) continue;
|
||||
if (child == effAnimNode || child.name == speciesName) continue;
|
||||
child.active = false;
|
||||
}
|
||||
}
|
||||
this.updateAnim(speciesName, fireballBullet, rdf);
|
||||
this.speciesName = speciesName;
|
||||
this.effAnimNode = this.animNode.getChildByName(this.speciesName);
|
||||
this.effAnimNode.active = true;
|
||||
//this.updateAnim(speciesName, fireballBullet, rdf);
|
||||
},
|
||||
|
||||
onLoad() {},
|
||||
|
||||
updateAnim(speciesName, fireballBullet, rdf) {
|
||||
this.animComp = this.effAnimNode.getComponent(cc.Animation);
|
||||
// Update directions
|
||||
if (this.animComp && this.animComp.node) {
|
||||
if (0 > fireballBullet.DirX) {
|
||||
this.effAnimNode.scaleX = (-1.0);
|
||||
this.animNode.scaleX = (-1.0);
|
||||
} else if (0 < fireballBullet.DirX) {
|
||||
this.effAnimNode.scaleX = (1.0);
|
||||
this.animNode.scaleX = (1.0);
|
||||
}
|
||||
}
|
||||
|
||||
|
@@ -413,7 +413,7 @@ cc.Class({
|
||||
window.mapIns = self;
|
||||
window.forceBigEndianFloatingNumDecoding = self.forceBigEndianFloatingNumDecoding;
|
||||
|
||||
self.showCriticalCoordinateLabels = true;
|
||||
self.showCriticalCoordinateLabels = false;
|
||||
|
||||
console.warn("+++++++ Map onLoad()");
|
||||
|
||||
@@ -1095,23 +1095,6 @@ othersForcedDownsyncRenderFrame=${JSON.stringify(othersForcedDownsyncRenderFrame
|
||||
|
||||
_renderFireballBullet(fireballBullet, rdf) {
|
||||
const self = this;
|
||||
let pqNode = self.cachedFireballs.popAny(fireballBullet.Bullet.BulletLocalId);
|
||||
const speciesName = `Fireball${fireballBullet.SpeciesId}`;
|
||||
|
||||
if (null == pqNode) {
|
||||
pqNode = self.cachedFireballs.pop();
|
||||
} else {
|
||||
console.log(`Using a cached fireball node for rendering for bulletLocalId=${fireballBullet.Bullet.BulletLocalId}`);
|
||||
}
|
||||
const cachedFireball = pqNode.value;
|
||||
cachedFireball.setSpecies(speciesName, fireballBullet, rdf);
|
||||
cachedFireball.lastUsed = self.renderFrameId;
|
||||
cachedFireball.bulletLocalId = fireballBullet.Bullet.BulletLocalId;
|
||||
|
||||
const [wx, wy] = gopkgs.VirtualGridToWorldPos(fireballBullet.VirtualGridX, fireballBullet.VirtualGridY);
|
||||
cachedFireball.node.setPosition(cc.v2(wx, wy));
|
||||
|
||||
self.cachedFireballs.push(cachedFireball.lastUsed, cachedFireball, cachedFireball.bulletLocalId);
|
||||
},
|
||||
|
||||
applyRoomDownsyncFrameDynamics(rdf, prevRdf) {
|
||||
@@ -1137,8 +1120,28 @@ othersForcedDownsyncRenderFrame=${JSON.stringify(othersForcedDownsyncRenderFrame
|
||||
const fireballBullets = rdf.FireballBullets;
|
||||
for (let k in fireballBullets) {
|
||||
const fireballBullet = fireballBullets[k];
|
||||
if ((fireballBullet.Bullet.OriginatedRenderFrameId + fireballBullet.Bullet.StartupFrames <= rdf.Id) && (fireballBullet.Bullet.OriginatedRenderFrameId + fireballBullet.Bullet.StartupFrames + fireballBullet.Bullet.ActiveFrames > rdf.Id)) {
|
||||
self._renderFireballBullet(fireballBullet, rdf);
|
||||
if (
|
||||
fireballBullet.Bullet.OriginatedRenderFrameId + fireballBullet.Bullet.StartupFrames <= rdf.Id
|
||||
&&
|
||||
fireballBullet.Bullet.OriginatedRenderFrameId + fireballBullet.Bullet.StartupFrames + fireballBullet.Bullet.ActiveFrames > rdf.Id
|
||||
) {
|
||||
let pqNode = self.cachedFireballs.popAny(fireballBullet.Bullet.BulletLocalId);
|
||||
const speciesName = `Fireball${fireballBullet.SpeciesId}`;
|
||||
const [wx, wy] = gopkgs.VirtualGridToWorldPos(fireballBullet.VirtualGridX, fireballBullet.VirtualGridY);
|
||||
|
||||
if (null == pqNode) {
|
||||
pqNode = self.cachedFireballs.pop();
|
||||
console.log(`@rdf.Id=${rdf.Id}, origRdfId=${fireballBullet.Bullet.OriginatedRenderFrameId}, startupFrames=${fireballBullet.Bullet.StartupFrames}, activeFrames=${fireballBullet.Bullet.ActiveFrames}, using a new fireball node for rendering for bulletLocalId=${fireballBullet.Bullet.BulletLocalId} at wpos=(${wx},${wy})`);
|
||||
} else {
|
||||
console.log(`@rdf.Id=${rdf.Id}, origRdfId=${fireballBullet.Bullet.OriginatedRenderFrameId}, startupFrames=${fireballBullet.Bullet.StartupFrames}, activeFrames=${fireballBullet.Bullet.ActiveFrames}, using a cached fireball node for rendering for bulletLocalId=${fireballBullet.Bullet.BulletLocalId} at wpos=(${wx},${wy})`);
|
||||
}
|
||||
const cachedFireball = pqNode.value;
|
||||
cachedFireball.setSpecies(speciesName, fireballBullet, rdf);
|
||||
cachedFireball.lastUsed = self.renderFrameId;
|
||||
cachedFireball.bulletLocalId = fireballBullet.Bullet.BulletLocalId;
|
||||
cachedFireball.node.setPosition(cc.v2(wx, wy));
|
||||
|
||||
self.cachedFireballs.push(cachedFireball.lastUsed, cachedFireball, fireballBullet.Bullet.BulletLocalId);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1263,7 +1266,12 @@ othersForcedDownsyncRenderFrame=${JSON.stringify(othersForcedDownsyncRenderFrame
|
||||
|
||||
playerDownsyncStr(playerDownsync) {
|
||||
if (null == playerDownsync) return "";
|
||||
return `{${playerDownsync.JoinIndex},${playerDownsync.VirtualGridX},${playerDownsync.VirtualGridY},${playerDownsync.VelX},${playerDownsync.VelY},${playerDownsync.FramesToRecover},${playerDownsync.InAir ? 1 : 0}}`;
|
||||
return `{${playerDownsync.JoinIndex},${playerDownsync.VirtualGridX},${playerDownsync.VirtualGridY},${playerDownsync.VelX},${playerDownsync.VelY},${playerDownsync.FramesToRecover},${playerDownsync.InAir ? 1 : 0},${playerDownsync.OnWall ? 1 : 0}}`;
|
||||
},
|
||||
|
||||
fireballDownsyncStr(fireball) {
|
||||
if (null == fireball) return "";
|
||||
return `{${fireball.Bullet.BulletLocalId},${fireball.Bullet.OriginatedRenderFrameId},${fireball.Bullet.OffenderJoinIndex},${fireball.VirtualGridX},${fireball.VirtualGridY},${fireball.VelX},${fireball.VelY},${fireball.DirX},${fireball.DirY},${fireball.Bullet.HitboxSizeX},${fireball.Bullet.HitboxSizeY}}`;
|
||||
},
|
||||
|
||||
inputFrameDownsyncStr(inputFrameDownsync) {
|
||||
@@ -1292,8 +1300,13 @@ othersForcedDownsyncRenderFrame=${JSON.stringify(othersForcedDownsyncRenderFrame
|
||||
for (let k in rdf.PlayersArr) {
|
||||
playersStrBldr.push(self.playerDownsyncStr(rdf.PlayersArr[k]));
|
||||
}
|
||||
const fireballsStrBldr = [];
|
||||
for (let k in rdf.FireballBullets) {
|
||||
fireballsStrBldr.push(self.fireballDownsyncStr(rdf.FireballBullets[k]));
|
||||
}
|
||||
s.push(`rdfId:${i}
|
||||
players:[${playersStrBldr.join(',')}]
|
||||
fireballs:[${fireballsStrBldr.join(',')}]
|
||||
actuallyUsedinputList:{${self.inputFrameDownsyncStr(actuallyUsedInputClone)}}`);
|
||||
}
|
||||
|
||||
|
@@ -94,7 +94,7 @@ cc.Class({
|
||||
const p2Vpos = gopkgs.WorldToVirtualGridPos(boundaryObjs.playerStartingPositions[1].x, boundaryObjs.playerStartingPositions[1].y);
|
||||
const colliderRadiusV = gopkgs.WorldToVirtualGridPos(12.0, 0);
|
||||
|
||||
const speciesIdList = [1, 4096];
|
||||
const speciesIdList = [4096, 1];
|
||||
const chConfigsOrderedByJoinIndex = gopkgs.GetCharacterConfigsOrderedByJoinIndex(speciesIdList);
|
||||
|
||||
const startRdf = window.pb.protos.RoomDownsyncFrame.create({
|
||||
|
Reference in New Issue
Block a user