Minor update.

This commit is contained in:
genxium 2023-02-14 23:27:21 +08:00
parent f4b303eb91
commit 2d179d0cdf
5 changed files with 101 additions and 36 deletions

View File

@ -461,7 +461,7 @@
"array": [ "array": [
0, 0,
0, 0,
210.4441731196186, 216.50635094610968,
0, 0,
0, 0,
0, 0,

View File

@ -549,7 +549,7 @@
"array": [ "array": [
0, 0,
0, 0,
210.4441731196186, 216.50635094610968,
0, 0,
0, 0,
0, 0,

File diff suppressed because one or more lines are too long

View File

@ -43,6 +43,11 @@ const (
NO_SKILL_HIT = -1 NO_SKILL_HIT = -1
NO_LOCK_VEL = int32(-1) NO_LOCK_VEL = int32(-1)
// Used in preallocated RoomDownsyncFrame to check termination
TERMINATING_BULLET_LOCAL_ID = int32(-1)
TERMINATING_PLAYER_ID = int32(-1)
TERMINATING_RENDER_FRAME_ID = int32(-1)
) )
// These directions are chosen such that when speed is changed to "(speedX+delta, speedY+delta)" for any of them, the direction is unchanged. // These directions are chosen such that when speed is changed to "(speedX+delta, speedY+delta)" for any of them, the direction is unchanged.
@ -1336,6 +1341,39 @@ func NewFireballBullet(bulletLocalId, originatedRenderFrameId, offenderJoinIndex
} }
} }
func NewPlayerDownsync(id, virtualGridX, virtualGridY, dirX, dirY, velX, velY, framesToRecover, framesInChState, activeSkillId, activeSkillHit, framesInvinsible, speed, battleState, characterState, joinIndex, hp, maxHp, colliderRadius int32, inAir, onWall bool, onWallNormX, onWallNormY int32, capturedByInertia bool, bulletTeamId, chCollisionTeamId int32, revivalVirtualGridX, revivalVirtualGridY int32) *PlayerDownsync {
return &PlayerDownsync{
Id: id,
VirtualGridX: virtualGridX,
VirtualGridY: virtualGridY,
DirX: dirX,
DirY: dirY,
VelX: velX,
VelY: velY,
FramesToRecover: framesToRecover,
FramesInChState: framesInChState,
ActiveSkillId: activeSkillId,
ActiveSkillHit: activeSkillHit,
FramesInvinsible: framesInvinsible,
Speed: speed,
BattleState: battleState,
CharacterState: characterState,
JoinIndex: joinIndex,
Hp: hp,
MaxHp: maxHp,
ColliderRadius: colliderRadius,
InAir: inAir,
OnWall: onWall,
OnWallNormX: onWallNormX,
OnWallNormY: onWallNormY,
CapturedByInertia: capturedByInertia,
BulletTeamId: bulletTeamId,
ChCollisionTeamId: chCollisionTeamId,
RevivalVirtualGridX: revivalVirtualGridX,
RevivalVirtualGridY: revivalVirtualGridY,
}
}
func CloneMeleeBullet(blState, framesInBlState int32, dynamicBattleAttr *BulletBattleAttr, staticBulletConfig *BulletConfig, dst *MeleeBullet /* preallocated */) { func CloneMeleeBullet(blState, framesInBlState int32, dynamicBattleAttr *BulletBattleAttr, staticBulletConfig *BulletConfig, dst *MeleeBullet /* preallocated */) {
dst.BlState = blState dst.BlState = blState
dst.FramesInBlState = framesInBlState dst.FramesInBlState = framesInBlState
@ -1363,7 +1401,7 @@ func CloneFireballBullet(blState, framesInBlState, virtualGridX, virtualGridY, d
dst.Bullet = staticBulletConfig // It's OK to just assign the pointer here, static bullet config is meant to be passed this way dst.Bullet = staticBulletConfig // It's OK to just assign the pointer here, static bullet config is meant to be passed this way
} }
func ClonePlayerDownsyncJs(id, virtualGridX, virtualGridY, dirX, dirY, velX, velY, framesToRecover, framesInChState, activeSkillId, activeSkillHit, framesInvinsible, speed, battleState, characterState, joinIndex, hp, maxHp, colliderRadius int32, inAir, onWall bool, onWallNormX, onWallNormY int32, capturedByInertia bool, bulletTeamId, chCollisionTeamId, revivalVirtualGridX, revivalVirtualGridY int32, dst *PlayerDownsync) { func ClonePlayerDownsync(id, virtualGridX, virtualGridY, dirX, dirY, velX, velY, framesToRecover, framesInChState, activeSkillId, activeSkillHit, framesInvinsible, speed, battleState, characterState, joinIndex, hp, maxHp, colliderRadius int32, inAir, onWall bool, onWallNormX, onWallNormY int32, capturedByInertia bool, bulletTeamId, chCollisionTeamId, revivalVirtualGridX, revivalVirtualGridY int32, dst *PlayerDownsync) {
dst.Id = id dst.Id = id
dst.VirtualGridX = virtualGridX dst.VirtualGridX = virtualGridX
dst.VirtualGridY = virtualGridY dst.VirtualGridY = virtualGridY
@ -1393,3 +1431,59 @@ func ClonePlayerDownsyncJs(id, virtualGridX, virtualGridY, dirX, dirY, velX, vel
dst.RevivalVirtualGridX = revivalVirtualGridX dst.RevivalVirtualGridX = revivalVirtualGridX
dst.RevivalVirtualGridY = revivalVirtualGridY dst.RevivalVirtualGridY = revivalVirtualGridY
} }
func CloneRoomDownsyncFrame(id int32, playersArr []*PlayerDownsync, bulletLocalIdCounter int32, meleeBullets []*MeleeBullet, fireballBullets []*FireballBullet, dst *RoomDownsyncFrame) {
dst.Id = id
dst.BulletLocalIdCounter = bulletLocalIdCounter
for i := 0; i < len(playersArr); i++ {
src := playersArr[i]
if nil == src || TERMINATING_PLAYER_ID == src.Id {
break
}
ClonePlayerDownsync(src.Id, src.VirtualGridX, src.VirtualGridY, src.DirX, src.DirY, src.VelX, src.VelY, src.FramesToRecover, src.FramesInChState, src.ActiveSkillId, src.ActiveSkillHit, src.FramesInvinsible, src.Speed, src.BattleState, src.CharacterState, src.JoinIndex, src.Hp, src.MaxHp, src.ColliderRadius, src.InAir, src.OnWall, src.OnWallNormX, src.OnWallNormY, src.CapturedByInertia, src.BulletTeamId, src.ChCollisionTeamId, src.RevivalVirtualGridX, src.RevivalVirtualGridY, dst.PlayersArr[i])
}
for i := 0; i < len(meleeBullets); i++ {
src := meleeBullets[i]
if nil == src || TERMINATING_BULLET_LOCAL_ID == src.BattleAttr.BulletLocalId {
break
}
CloneMeleeBullet(src.BlState, src.FramesInBlState, src.BattleAttr, src.Bullet, dst.MeleeBullets[i])
}
for i := 0; i < len(fireballBullets); i++ {
src := fireballBullets[i]
if nil == src || TERMINATING_BULLET_LOCAL_ID == src.BattleAttr.BulletLocalId {
break
}
CloneFireballBullet(src.BlState, src.FramesInBlState, src.VirtualGridX, src.VirtualGridY, src.DirX, src.DirY, src.VelX, src.VelY, src.Speed, src.BattleAttr, src.Bullet, dst.FireballBullets[i])
}
}
func NewPreallocatedRoomDownsyncFrame(roomCapacity, preallocMeleeBulletCount int, preallocFireballBulletCount int) *RoomDownsyncFrame {
preallocatedPlayers := make([]*PlayerDownsync, roomCapacity)
for i := 0; i < roomCapacity; i++ {
preallocatedPlayer := NewPlayerDownsync(TERMINATING_PLAYER_ID, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, false, false, 0, 0, false, 0, 0, 0, 0)
preallocatedPlayers[i] = preallocatedPlayer
}
preallocatedMeleeBullets := make([]*MeleeBullet, preallocMeleeBulletCount)
for i := 0; i < preallocMeleeBulletCount; i++ {
preallocatedMelee := NewMeleeBullet(TERMINATING_BULLET_LOCAL_ID, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, false, 0, 0, 0, 0, 0)
preallocatedMeleeBullets[i] = preallocatedMelee
}
preallocatedFireballBullets := make([]*FireballBullet, preallocFireballBulletCount)
for i := 0; i < preallocFireballBulletCount; i++ {
preallocatedFireball := NewFireballBullet(TERMINATING_BULLET_LOCAL_ID, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, false, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0)
preallocatedFireballBullets[i] = preallocatedFireball
}
return &RoomDownsyncFrame{
Id: TERMINATING_RENDER_FRAME_ID,
BulletLocalIdCounter: TERMINATING_BULLET_LOCAL_ID,
PlayersArr: preallocatedPlayers,
MeleeBullets: preallocatedMeleeBullets,
FireballBullets: preallocatedFireballBullets,
}
}

View File

@ -43,36 +43,7 @@ func NewBarrierJs(boundary *Polygon2D) *js.Object {
} }
func NewPlayerDownsyncJs(id, virtualGridX, virtualGridY, dirX, dirY, velX, velY, framesToRecover, framesInChState, activeSkillId, activeSkillHit, framesInvinsible, speed, battleState, characterState, joinIndex, hp, maxHp, colliderRadius int32, inAir, onWall bool, onWallNormX, onWallNormY int32, capturedByInertia bool, bulletTeamId, chCollisionTeamId int32, revivalVirtualGridX, revivalVirtualGridY int32) *js.Object { func NewPlayerDownsyncJs(id, virtualGridX, virtualGridY, dirX, dirY, velX, velY, framesToRecover, framesInChState, activeSkillId, activeSkillHit, framesInvinsible, speed, battleState, characterState, joinIndex, hp, maxHp, colliderRadius int32, inAir, onWall bool, onWallNormX, onWallNormY int32, capturedByInertia bool, bulletTeamId, chCollisionTeamId int32, revivalVirtualGridX, revivalVirtualGridY int32) *js.Object {
return js.MakeWrapper(&PlayerDownsync{ return js.MakeWrapper(NewPlayerDownsync(id, virtualGridX, virtualGridY, dirX, dirY, velX, velY, framesToRecover, framesInChState, activeSkillId, activeSkillHit, framesInvinsible, speed, battleState, characterState, joinIndex, hp, maxHp, colliderRadius, inAir, onWall, onWallNormX, onWallNormY, capturedByInertia, bulletTeamId, chCollisionTeamId, revivalVirtualGridX, revivalVirtualGridY))
Id: id,
VirtualGridX: virtualGridX,
VirtualGridY: virtualGridY,
DirX: dirX,
DirY: dirY,
VelX: velX,
VelY: velY,
FramesToRecover: framesToRecover,
FramesInChState: framesInChState,
ActiveSkillId: activeSkillId,
ActiveSkillHit: activeSkillHit,
FramesInvinsible: framesInvinsible,
Speed: speed,
BattleState: battleState,
CharacterState: characterState,
JoinIndex: joinIndex,
Hp: hp,
MaxHp: maxHp,
ColliderRadius: colliderRadius,
InAir: inAir,
OnWall: onWall,
OnWallNormX: onWallNormX,
OnWallNormY: onWallNormY,
CapturedByInertia: capturedByInertia,
BulletTeamId: bulletTeamId,
ChCollisionTeamId: chCollisionTeamId,
RevivalVirtualGridX: revivalVirtualGridX,
RevivalVirtualGridY: revivalVirtualGridY,
})
} }
func NewMeleeBulletJs(bulletLocalId, originatedRenderFrameId, offenderJoinIndex, startupFrames, cancellableStFrame, cancellableEdFrame, activeFrames, hitStunFrames, blockStunFrames, pushbackVelX, pushbackVelY, damage, selfLockVelX, selfLockVelY, hitboxOffsetX, hitboxOffsetY, hitboxSizeX, hitboxSizeY int32, blowUp bool, teamId, blState, framesInBlState, explosionFrames, speciesId int32) *js.Object { func NewMeleeBulletJs(bulletLocalId, originatedRenderFrameId, offenderJoinIndex, startupFrames, cancellableStFrame, cancellableEdFrame, activeFrames, hitStunFrames, blockStunFrames, pushbackVelX, pushbackVelY, damage, selfLockVelX, selfLockVelY, hitboxOffsetX, hitboxOffsetY, hitboxSizeX, hitboxSizeY int32, blowUp bool, teamId, blState, framesInBlState, explosionFrames, speciesId int32) *js.Object {
@ -96,8 +67,8 @@ func NewRoomDownsyncFrameJs(id int32, playersArr []*PlayerDownsync, bulletLocalI
// [WARNING] Avoid using "pb.RoomDownsyncFrame" here, in practive "MakeFullWrapper" doesn't expose the public fields for a "protobuf struct" as expected and requires helper functions like "GetCollisionSpaceObjsJs". // [WARNING] Avoid using "pb.RoomDownsyncFrame" here, in practive "MakeFullWrapper" doesn't expose the public fields for a "protobuf struct" as expected and requires helper functions like "GetCollisionSpaceObjsJs".
return js.MakeFullWrapper(&RoomDownsyncFrame{ return js.MakeFullWrapper(&RoomDownsyncFrame{
Id: id, Id: id,
PlayersArr: playersArr,
BulletLocalIdCounter: bulletLocalIdCounter, BulletLocalIdCounter: bulletLocalIdCounter,
PlayersArr: playersArr,
MeleeBullets: meleeBullets, MeleeBullets: meleeBullets,
FireballBullets: fireballBullets, FireballBullets: fireballBullets,
}) })