mirror of
https://github.com/genxium/DelayNoMore
synced 2024-12-25 03:08:57 +00:00
Refactored backend to use jsexport dynamics.
This commit is contained in:
parent
8139a00939
commit
a85c6f9ad8
@ -16,13 +16,13 @@ require (
|
||||
github.com/jmoiron/sqlx v0.0.0-20180614180643-0dae4fefe7c0
|
||||
github.com/logrusorgru/aurora v0.0.0-20181002194514-a7b3b318ed4e
|
||||
github.com/robfig/cron v0.0.0-20180505203441-b41be1df6967
|
||||
github.com/solarlune/resolv v0.5.1
|
||||
github.com/thoas/go-funk v0.0.0-20180716193722-1060394a7713
|
||||
go.uber.org/zap v1.9.1
|
||||
google.golang.org/protobuf v1.28.1
|
||||
|
||||
dnmshared v0.0.0
|
||||
jsexport v0.0.0
|
||||
resolv v0.0.0
|
||||
)
|
||||
|
||||
require (
|
||||
@ -50,4 +50,5 @@ require (
|
||||
replace (
|
||||
dnmshared => ../dnmshared
|
||||
jsexport => ../jsexport
|
||||
resolv => ../resolv_tailored
|
||||
)
|
||||
|
@ -5,25 +5,74 @@ import (
|
||||
"jsexport/battle"
|
||||
)
|
||||
|
||||
func toPbRenderFrame(rdf *battle.RoomDownsyncFrame) {
|
||||
if nil == rdf {
|
||||
return nil
|
||||
}
|
||||
ret := &pb.RoomDownsyncFrame{
|
||||
Id: rdf.Id,
|
||||
PlayersArr: make([]pb.PlayerDownsync, len(rdf.PlayersArr)),
|
||||
MeleeBullets: make([]pb.MeleeBullet, len(rdf.MeleeBullets)),
|
||||
}
|
||||
func toPbRoomDownsyncFrame(rdf *battle.RoomDownsyncFrame) *pb.RoomDownsyncFrame {
|
||||
if nil == rdf {
|
||||
return nil
|
||||
}
|
||||
ret := &pb.RoomDownsyncFrame{
|
||||
Id: rdf.Id,
|
||||
PlayersArr: make([]*pb.PlayerDownsync, len(rdf.PlayersArr), len(rdf.PlayersArr)),
|
||||
MeleeBullets: make([]*pb.MeleeBullet, len(rdf.MeleeBullets), len(rdf.MeleeBullets)),
|
||||
}
|
||||
|
||||
for i, last := range rdf.PlayersArr {
|
||||
pbPlayer := &pb.PlayerDownsync{
|
||||
Id: last.Id,
|
||||
VirtualGridX: last.VirtualGridX,
|
||||
VirtualGridY: last.VirtualGridY,
|
||||
DirX: last.DirX,
|
||||
DirY: last.DirY,
|
||||
VelX: last.VelX,
|
||||
VelY: last.VelY,
|
||||
Speed: last.Speed,
|
||||
BattleState: last.BattleState,
|
||||
CharacterState: last.CharacterState,
|
||||
InAir: last.InAir,
|
||||
JoinIndex: last.JoinIndex,
|
||||
ColliderRadius: last.ColliderRadius,
|
||||
Score: last.Score,
|
||||
Removed: last.Removed,
|
||||
}
|
||||
ret.PlayersArr[i] = pbPlayer
|
||||
}
|
||||
|
||||
for i, last := range rdf.MeleeBullets {
|
||||
pbBullet := &pb.MeleeBullet{
|
||||
BattleLocalId: last.BattleLocalId,
|
||||
StartupFrames: last.StartupFrames,
|
||||
ActiveFrames: last.ActiveFrames,
|
||||
RecoveryFrames: last.RecoveryFrames,
|
||||
RecoveryFramesOnBlock: last.RecoveryFramesOnBlock,
|
||||
RecoveryFramesOnHit: last.RecoveryFramesOnHit,
|
||||
HitboxOffset: last.HitboxOffset,
|
||||
HitStunFrames: last.HitStunFrames,
|
||||
BlockStunFrames: last.BlockStunFrames,
|
||||
Pushback: last.Pushback,
|
||||
ReleaseTriggerType: last.ReleaseTriggerType,
|
||||
Damage: last.Damage,
|
||||
|
||||
SelfMoveforwardX: last.SelfMoveforwardX,
|
||||
SelfMoveforwardY: last.SelfMoveforwardY,
|
||||
HitboxSizeX: last.HitboxSizeX,
|
||||
HitboxSizeY: last.HitboxSizeY,
|
||||
|
||||
OffenderJoinIndex: last.OffenderJoinIndex,
|
||||
OffenderPlayerId: last.OffenderPlayerId,
|
||||
}
|
||||
ret.MeleeBullets[i] = pbBullet
|
||||
}
|
||||
|
||||
return ret
|
||||
}
|
||||
|
||||
func toPbPlayers(modelInstances map[int32]*Player, withMetaInfo bool) map[int32]*pb.PlayerDownsync {
|
||||
toRet := make(map[int32]*pb.PlayerDownsync, 0)
|
||||
func toPbPlayers(modelInstances map[int32]*Player, withMetaInfo bool) []*pb.PlayerDownsync {
|
||||
toRet := make([]*pb.PlayerDownsync, len(modelInstances), len(modelInstances))
|
||||
if nil == modelInstances {
|
||||
return toRet
|
||||
}
|
||||
|
||||
for k, last := range modelInstances {
|
||||
toRet[k] = &pb.PlayerDownsync{
|
||||
for _, last := range modelInstances {
|
||||
pbPlayer := &pb.PlayerDownsync{
|
||||
Id: last.Id,
|
||||
VirtualGridX: last.VirtualGridX,
|
||||
VirtualGridY: last.VirtualGridY,
|
||||
@ -41,23 +90,24 @@ func toPbPlayers(modelInstances map[int32]*Player, withMetaInfo bool) map[int32]
|
||||
Removed: last.Removed,
|
||||
}
|
||||
if withMetaInfo {
|
||||
toRet[k].Name = last.Name
|
||||
toRet[k].DisplayName = last.DisplayName
|
||||
toRet[k].Avatar = last.Avatar
|
||||
pbPlayer.Name = last.Name
|
||||
pbPlayer.DisplayName = last.DisplayName
|
||||
pbPlayer.Avatar = last.Avatar
|
||||
}
|
||||
toRet[last.JoinIndex-1] = pbPlayer
|
||||
}
|
||||
|
||||
return toRet
|
||||
}
|
||||
|
||||
func toJsPlayers(modelInstances map[int32]*Player) map[int32]*battle.PlayerDownsync {
|
||||
toRet := make(map[int32]*battle.PlayerDownsync, 0)
|
||||
func toJsPlayers(modelInstances map[int32]*Player) []*battle.PlayerDownsync {
|
||||
toRet := make([]*battle.PlayerDownsync, len(modelInstances), len(modelInstances))
|
||||
if nil == modelInstances {
|
||||
return toRet
|
||||
}
|
||||
|
||||
for k, last := range modelInstances {
|
||||
toRet[k] = &battle.PlayerDownsync{
|
||||
for _, last := range modelInstances {
|
||||
toRet[last.JoinIndex-1] = &battle.PlayerDownsync{
|
||||
Id: last.Id,
|
||||
VirtualGridX: last.VirtualGridX,
|
||||
VirtualGridY: last.VirtualGridY,
|
||||
|
@ -9,13 +9,13 @@ import (
|
||||
"fmt"
|
||||
"github.com/golang/protobuf/proto"
|
||||
"github.com/gorilla/websocket"
|
||||
"github.com/solarlune/resolv"
|
||||
"go.uber.org/zap"
|
||||
"io/ioutil"
|
||||
"jsexport/battle"
|
||||
"math/rand"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"resolv"
|
||||
"strings"
|
||||
"sync"
|
||||
"sync/atomic"
|
||||
@ -284,6 +284,8 @@ func (pR *Room) ChooseStage() error {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
//Logger.Info("parsed tmx:", zap.Any("stageDiscreteW", stageDiscreteW), zap.Any("strToVec2DListMap", strToVec2DListMap), zap.Any("strToPolygon2DListMap", strToPolygon2DListMap))
|
||||
|
||||
pR.StageDiscreteW = stageDiscreteW
|
||||
pR.StageDiscreteH = stageDiscreteH
|
||||
pR.StageTileW = stageTileW
|
||||
@ -352,7 +354,7 @@ func (pR *Room) StartBattle() {
|
||||
pR.CurDynamicsRenderFrameId = 0
|
||||
kickoffFrameJs := &battle.RoomDownsyncFrame{
|
||||
Id: pR.RenderFrameId,
|
||||
Players: toJsPlayers(pR.Players, false),
|
||||
PlayersArr: toJsPlayers(pR.Players),
|
||||
CountdownNanos: pR.BattleDurationNanos,
|
||||
}
|
||||
pR.RenderFrameBuffer.Put(kickoffFrameJs)
|
||||
@ -420,12 +422,8 @@ func (pR *Room) StartBattle() {
|
||||
case PlayerBattleStateIns.DISCONNECTED, PlayerBattleStateIns.LOST, PlayerBattleStateIns.EXPELLED_DURING_GAME, PlayerBattleStateIns.EXPELLED_IN_DISMISSAL:
|
||||
continue
|
||||
}
|
||||
kickoffFrame := &pb.RoomDownsyncFrame{
|
||||
Id: pR.RenderFrameId,
|
||||
Players: toPbPlayers(pR.Players, false),
|
||||
CountdownNanos: pR.BattleDurationNanos,
|
||||
}
|
||||
pR.sendSafely(kickoffFrame, nil, DOWNSYNC_MSG_ACT_BATTLE_START, playerId, true)
|
||||
kickoffFrameJs := pR.RenderFrameBuffer.GetByFrameId(0).(*battle.RoomDownsyncFrame)
|
||||
pR.sendSafely(toPbRoomDownsyncFrame(kickoffFrameJs), nil, DOWNSYNC_MSG_ACT_BATTLE_START, playerId, true)
|
||||
}
|
||||
Logger.Info(fmt.Sprintf("In `battleMainLoop` for roomId=%v sent out kickoffFrame", pR.Id))
|
||||
}
|
||||
@ -594,7 +592,7 @@ func (pR *Room) StopBattleForSettlement() {
|
||||
for playerId, _ := range pR.Players {
|
||||
assembledFrame := pb.RoomDownsyncFrame{
|
||||
Id: pR.RenderFrameId,
|
||||
Players: toPbPlayers(pR.Players, false),
|
||||
PlayersArr: toPbPlayers(pR.Players, false),
|
||||
CountdownNanos: -1, // TODO: Replace this magic constant!
|
||||
}
|
||||
pR.sendSafely(&assembledFrame, nil, DOWNSYNC_MSG_ACT_BATTLE_STOPPED, playerId, true)
|
||||
@ -620,7 +618,7 @@ func (pR *Room) onBattlePrepare(cb BattleStartCbType) {
|
||||
|
||||
battleReadyToStartFrame := &pb.RoomDownsyncFrame{
|
||||
Id: DOWNSYNC_MSG_ACT_BATTLE_READY_TO_START,
|
||||
Players: toPbPlayers(pR.Players, true),
|
||||
PlayersArr: toPbPlayers(pR.Players, true),
|
||||
CountdownNanos: pR.BattleDurationNanos,
|
||||
}
|
||||
|
||||
@ -691,7 +689,8 @@ func (pR *Room) OnDismissed() {
|
||||
pR.WorldToVirtualGridRatio = float64(1000)
|
||||
pR.VirtualGridToWorldRatio = float64(1.0) / pR.WorldToVirtualGridRatio // this is a one-off computation, should avoid division in iterations
|
||||
pR.SpAtkLookupFrames = 5
|
||||
pR.PlayerDefaultSpeed = int32(float64(1) * pR.WorldToVirtualGridRatio) // in virtual grids per frame
|
||||
pR.PlayerDefaultSpeed = int32(float64(1) * pR.WorldToVirtualGridRatio) // in virtual grids per frame
|
||||
pR.CollisionMinStep = (int32(float64(pR.PlayerDefaultSpeed)*pR.VirtualGridToWorldRatio) << 3) // the approx minimum distance a player can move per frame in world coordinate
|
||||
pR.Players = make(map[int32]*Player)
|
||||
pR.PlayersArr = make([]*Player, pR.Capacity)
|
||||
pR.CollisionSysMap = make(map[int32]*resolv.Object)
|
||||
@ -878,7 +877,7 @@ func (pR *Room) onPlayerAdded(playerId int32) {
|
||||
pR.JoinIndexBooleanArr[index] = true
|
||||
|
||||
// Lazily assign the initial position of "Player" for "RoomDownsyncFrame".
|
||||
playerPosList := pR.TmxPointsMap["PlayerStartingPos"]
|
||||
playerPosList := *pR.TmxPointsMap["PlayerStartingPos"]
|
||||
if index > len(playerPosList) {
|
||||
panic(fmt.Sprintf("onPlayerAdded error, index >= len(playerPosList), roomId=%v, playerId=%v, roomState=%v, roomEffectivePlayerCount=%v", pR.Id, playerId, pR.State, pR.EffectivePlayerCount))
|
||||
}
|
||||
@ -928,8 +927,8 @@ func (pR *Room) OnPlayerBattleColliderAcked(playerId int32) bool {
|
||||
switch targetPlayerBattleState {
|
||||
case PlayerBattleStateIns.ADDED_PENDING_BATTLE_COLLIDER_ACK:
|
||||
playerAckedFrame := &pb.RoomDownsyncFrame{
|
||||
Id: pR.RenderFrameId,
|
||||
Players: toPbPlayers(pR.Players, true),
|
||||
Id: pR.RenderFrameId,
|
||||
PlayersArr: toPbPlayers(pR.Players, true),
|
||||
}
|
||||
|
||||
// Broadcast normally added player info to all players in the same room
|
||||
@ -1205,8 +1204,6 @@ func (pR *Room) applyInputFrameDownsyncDynamics(fromRenderFrameId int32, toRende
|
||||
}
|
||||
|
||||
Logger.Debug(fmt.Sprintf("Applying inputFrame dynamics: roomId=%v, room.RenderFrameId=%v, fromRenderFrameId=%v, toRenderFrameId=%v", pR.Id, pR.RenderFrameId, fromRenderFrameId, toRenderFrameId))
|
||||
totPlayerCnt := uint32(pR.Capacity)
|
||||
allConfirmedMask := uint64((1 << totPlayerCnt) - 1)
|
||||
|
||||
for collisionSysRenderFrameId := fromRenderFrameId; collisionSysRenderFrameId < toRenderFrameId; collisionSysRenderFrameId++ {
|
||||
currRenderFrameTmp := pR.RenderFrameBuffer.GetByFrameId(collisionSysRenderFrameId)
|
||||
@ -1215,7 +1212,8 @@ func (pR *Room) applyInputFrameDownsyncDynamics(fromRenderFrameId int32, toRende
|
||||
}
|
||||
currRenderFrame := currRenderFrameTmp.(*battle.RoomDownsyncFrame)
|
||||
delayedInputFrameId := pR.ConvertToInputFrameId(collisionSysRenderFrameId, pR.InputDelayFrames)
|
||||
var delayedInputFrame *pb.InputFrameDownsync = nil
|
||||
var delayedInputList []uint64 = nil
|
||||
var delayedInputListForPrevRenderFrame []uint64 = nil
|
||||
if 0 <= delayedInputFrameId {
|
||||
if delayedInputFrameId > pR.LastAllConfirmedInputFrameId {
|
||||
panic(fmt.Sprintf("delayedInputFrameId=%v is not yet all-confirmed for roomId=%v, this is abnormal because it's to be used for applying dynamics to [fromRenderFrameId:%v, toRenderFrameId:%v) @ collisionSysRenderFrameId=%v! InputsBuffer=%v", delayedInputFrameId, pR.Id, fromRenderFrameId, toRenderFrameId, collisionSysRenderFrameId, pR.InputsBufferString(false)))
|
||||
@ -1224,12 +1222,20 @@ func (pR *Room) applyInputFrameDownsyncDynamics(fromRenderFrameId int32, toRende
|
||||
if nil == tmp {
|
||||
panic(fmt.Sprintf("delayedInputFrameId=%v doesn't exist for roomId=%v, this is abnormal because it's to be used for applying dynamics to [fromRenderFrameId:%v, toRenderFrameId:%v) @ collisionSysRenderFrameId=%v! InputsBuffer=%v", delayedInputFrameId, pR.Id, fromRenderFrameId, toRenderFrameId, collisionSysRenderFrameId, pR.InputsBufferString(false)))
|
||||
}
|
||||
delayedInputFrame = tmp.(*pb.InputFrameDownsync)
|
||||
// [WARNING] It's possible that by now "allConfirmedMask != delayedInputFrame.ConfirmedList && delayedInputFrameId <= pR.LastAllConfirmedInputFrameId", we trust "pR.LastAllConfirmedInputFrameId" as the TOP AUTHORITY.
|
||||
delayedInputFrame.ConfirmedList = allConfirmedMask
|
||||
delayedInputFrame := tmp.(*pb.InputFrameDownsync)
|
||||
delayedInputList = delayedInputFrame.InputList
|
||||
delayedInputFrameIdForPrevRenderFrame := pR.ConvertToInputFrameId(collisionSysRenderFrameId-1, pR.InputDelayFrames)
|
||||
if 0 <= delayedInputFrameIdForPrevRenderFrame {
|
||||
tmp = pR.InputsBuffer.GetByFrameId(delayedInputFrameId)
|
||||
if nil == tmp {
|
||||
panic(fmt.Sprintf("delayedInputFrameIdForPrevRenderFrame=%v doesn't exist for roomId=%v, this is abnormal because it's to be used for applying dynamics to [fromRenderFrameId:%v, toRenderFrameId:%v) @ collisionSysRenderFrameId-1=%v! InputsBuffer=%v", delayedInputFrameIdForPrevRenderFrame, pR.Id, fromRenderFrameId, toRenderFrameId, collisionSysRenderFrameId-1, pR.InputsBufferString(false)))
|
||||
}
|
||||
delayedInputFrameForPrevRenderFrame := tmp.(*pb.InputFrameDownsync)
|
||||
delayedInputListForPrevRenderFrame = delayedInputFrameForPrevRenderFrame.InputList
|
||||
}
|
||||
}
|
||||
|
||||
nextRenderFrame := pR.applyInputFrameDownsyncDynamicsOnSingleRenderFrame(delayedInputFrame, currRenderFrame, pR.CollisionSysMap)
|
||||
nextRenderFrame := battle.ApplyInputFrameDownsyncDynamicsOnSingleRenderFrame(delayedInputList, delayedInputListForPrevRenderFrame, currRenderFrame, pR.Space, pR.CollisionSysMap, pR.GravityX, pR.GravityY, pR.JumpingInitVelY, pR.InputDelayFrames, pR.InputScaleFrames, pR.collisionSpaceOffsetX, pR.collisionSpaceOffsetY, pR.SnapIntoPlatformOverlap, pR.SnapIntoPlatformThreshold, pR.WorldToVirtualGridRatio, pR.VirtualGridToWorldRatio)
|
||||
pR.RenderFrameBuffer.Put(nextRenderFrame)
|
||||
pR.CurDynamicsRenderFrameId++
|
||||
}
|
||||
@ -1240,9 +1246,8 @@ func (pR *Room) refreshColliders(spaceW, spaceH int32) {
|
||||
|
||||
topPadding, bottomPadding, leftPadding, rightPadding := pR.SnapIntoPlatformOverlap, pR.SnapIntoPlatformOverlap, pR.SnapIntoPlatformOverlap, pR.SnapIntoPlatformOverlap
|
||||
|
||||
minStep := (int(float64(pR.PlayerDefaultSpeed)*pR.VirtualGridToWorldRatio) << 3) // the approx minimum distance a player can move per frame in world coordinate
|
||||
pR.Space = resolv.NewSpace(int(spaceW), int(spaceH), minStep, minStep) // allocate a new collision space everytime after a battle is settled
|
||||
jsPlayers := toJsPlayers(pR.Players, false)
|
||||
pR.Space = resolv.NewSpace(int(spaceW), int(spaceH), int(pR.CollisionMinStep), int(pR.CollisionMinStep)) // allocate a new collision space everytime after a battle is settled
|
||||
jsPlayers := toJsPlayers(pR.Players)
|
||||
for _, player := range jsPlayers {
|
||||
wx, wy := battle.VirtualGridToWorldPos(player.VirtualGridX, player.VirtualGridY, pR.VirtualGridToWorldRatio)
|
||||
colliderWidth, colliderHeight := player.ColliderRadius*2, player.ColliderRadius*4
|
||||
@ -1259,7 +1264,7 @@ func (pR *Room) refreshColliders(spaceW, spaceH int32) {
|
||||
pR.PlayersArr[joinIndex-1] = player
|
||||
}
|
||||
|
||||
barrierPolygon2DList := pR.TmxPolygonsMap["Barrier"]
|
||||
barrierPolygon2DList := *pR.TmxPolygonsMap["Barrier"]
|
||||
for _, polygon2DUnaligned := range barrierPolygon2DList {
|
||||
/*
|
||||
// For debug-printing only.
|
||||
@ -1427,14 +1432,14 @@ func (pR *Room) downsyncToSinglePlayer(playerId int32, player *Player, refRender
|
||||
}
|
||||
|
||||
refRenderFrame := tmp.(*battle.RoomDownsyncFrame)
|
||||
for _, player := range pR.PlayersArr {
|
||||
refRenderFrame.Players[player.Id].ColliderRadius = player.ColliderRadius // hardcoded for now
|
||||
for i, player := range pR.PlayersArr {
|
||||
refRenderFrame.PlayersArr[i].ColliderRadius = player.ColliderRadius // hardcoded for now
|
||||
}
|
||||
if shouldResync3 {
|
||||
refRenderFrame.ShouldForceResync = true
|
||||
}
|
||||
refRenderFrame.BackendUnconfirmedMask = unconfirmedMask
|
||||
pR.sendSafely(refRenderFrame, toSendInputFrameDownsyncsSnapshot, DOWNSYNC_MSG_ACT_FORCED_RESYNC, playerId, false)
|
||||
pR.sendSafely(toPbRoomDownsyncFrame(refRenderFrame), toSendInputFrameDownsyncsSnapshot, DOWNSYNC_MSG_ACT_FORCED_RESYNC, playerId, false)
|
||||
//Logger.Warn(fmt.Sprintf("Sent refRenderFrameId=%v & inputFrameIds [%d, %d), for roomId=%v, playerId=%d, playerJoinIndex=%d, renderFrameId=%d, curDynamicsRenderFrameId=%d, playerLastSentInputFrameId=%d: InputsBuffer=%v", refRenderFrameId, toSendInputFrameIdSt, toSendInputFrameIdEd, pR.Id, playerId, player.JoinIndex, pR.RenderFrameId, pR.CurDynamicsRenderFrameId, player.LastSentInputFrameId, pR.InputsBufferString(false)))
|
||||
if shouldResync1 {
|
||||
Logger.Warn(fmt.Sprintf("Sent refRenderFrameId=%v & inputFrameIds [%d, %d), for roomId=%v, playerId=%d, playerJoinIndex=%d, renderFrameId=%d, curDynamicsRenderFrameId=%d, playerLastSentInputFrameId=%d: shouldResync1=%v, shouldResync2=%v, shouldResync3=%v, playerBattleState=%d", refRenderFrameId, toSendInputFrameIdSt, toSendInputFrameIdEd, pR.Id, playerId, player.JoinIndex, pR.RenderFrameId, pR.CurDynamicsRenderFrameId, player.LastSentInputFrameId, shouldResync1, shouldResync2, shouldResync3, playerBattleState))
|
||||
|
@ -960,6 +960,7 @@ type BattleColliderInfo struct {
|
||||
JumpingInitVelY int32 `protobuf:"varint,27,opt,name=jumpingInitVelY,proto3" json:"jumpingInitVelY,omitempty"`
|
||||
GravityX int32 `protobuf:"varint,28,opt,name=gravityX,proto3" json:"gravityX,omitempty"`
|
||||
GravityY int32 `protobuf:"varint,29,opt,name=gravityY,proto3" json:"gravityY,omitempty"`
|
||||
CollisionMinStep int32 `protobuf:"varint,30,opt,name=collisionMinStep,proto3" json:"collisionMinStep,omitempty"`
|
||||
}
|
||||
|
||||
func (x *BattleColliderInfo) Reset() {
|
||||
@ -1197,18 +1198,24 @@ func (x *BattleColliderInfo) GetGravityY() int32 {
|
||||
return 0
|
||||
}
|
||||
|
||||
func (x *BattleColliderInfo) GetCollisionMinStep() int32 {
|
||||
if x != nil {
|
||||
return x.CollisionMinStep
|
||||
}
|
||||
return 0
|
||||
}
|
||||
|
||||
type RoomDownsyncFrame struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
|
||||
Id int32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||
PlayersArr []*PlayerDownsync `protobuf:"bytes,2,rep,name=playersArr,proto3" json:"playersArr,omitempty"`
|
||||
CountdownNanos int64 `protobuf:"varint,3,opt,name=countdownNanos,proto3" json:"countdownNanos,omitempty"`
|
||||
MeleeBullets []*MeleeBullet `protobuf:"bytes,4,rep,name=meleeBullets,proto3" json:"meleeBullets,omitempty"` // I don't know how to mimic inheritance/composition in protobuf by far, thus using an array for each type of bullet as a compromise
|
||||
BackendUnconfirmedMask uint64 `protobuf:"varint,5,opt,name=backendUnconfirmedMask,proto3" json:"backendUnconfirmedMask,omitempty"` // Indexed by "joinIndex", same compression concern as stated in InputFrameDownsync
|
||||
ShouldForceResync bool `protobuf:"varint,6,opt,name=shouldForceResync,proto3" json:"shouldForceResync,omitempty"`
|
||||
Players map[int32]*PlayerDownsync `protobuf:"bytes,99,rep,name=players,proto3" json:"players,omitempty" protobuf_key:"varint,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` // TO BE DEPRECATED
|
||||
Id int32 `protobuf:"varint,1,opt,name=id,proto3" json:"id,omitempty"`
|
||||
PlayersArr []*PlayerDownsync `protobuf:"bytes,2,rep,name=playersArr,proto3" json:"playersArr,omitempty"`
|
||||
CountdownNanos int64 `protobuf:"varint,3,opt,name=countdownNanos,proto3" json:"countdownNanos,omitempty"`
|
||||
MeleeBullets []*MeleeBullet `protobuf:"bytes,4,rep,name=meleeBullets,proto3" json:"meleeBullets,omitempty"` // I don't know how to mimic inheritance/composition in protobuf by far, thus using an array for each type of bullet as a compromise
|
||||
BackendUnconfirmedMask uint64 `protobuf:"varint,5,opt,name=backendUnconfirmedMask,proto3" json:"backendUnconfirmedMask,omitempty"` // Indexed by "joinIndex", same compression concern as stated in InputFrameDownsync
|
||||
ShouldForceResync bool `protobuf:"varint,6,opt,name=shouldForceResync,proto3" json:"shouldForceResync,omitempty"`
|
||||
}
|
||||
|
||||
func (x *RoomDownsyncFrame) Reset() {
|
||||
@ -1285,13 +1292,6 @@ func (x *RoomDownsyncFrame) GetShouldForceResync() bool {
|
||||
return false
|
||||
}
|
||||
|
||||
func (x *RoomDownsyncFrame) GetPlayers() map[int32]*PlayerDownsync {
|
||||
if x != nil {
|
||||
return x.Players
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
var File_room_downsync_frame_proto protoreflect.FileDescriptor
|
||||
|
||||
var file_room_downsync_frame_proto_rawDesc = []byte{
|
||||
@ -1462,7 +1462,7 @@ var file_room_downsync_frame_proto_rawDesc = []byte{
|
||||
0x6c, 0x66, 0x4d, 0x6f, 0x76, 0x65, 0x66, 0x6f, 0x72, 0x77, 0x61, 0x72, 0x64, 0x58, 0x12, 0x2a,
|
||||
0x0a, 0x10, 0x73, 0x65, 0x6c, 0x66, 0x4d, 0x6f, 0x76, 0x65, 0x66, 0x6f, 0x72, 0x77, 0x61, 0x72,
|
||||
0x64, 0x59, 0x18, 0x13, 0x20, 0x01, 0x28, 0x01, 0x52, 0x10, 0x73, 0x65, 0x6c, 0x66, 0x4d, 0x6f,
|
||||
0x76, 0x65, 0x66, 0x6f, 0x72, 0x77, 0x61, 0x72, 0x64, 0x59, 0x22, 0xde, 0x0b, 0x0a, 0x12, 0x42,
|
||||
0x76, 0x65, 0x66, 0x6f, 0x72, 0x77, 0x61, 0x72, 0x64, 0x59, 0x22, 0x8a, 0x0c, 0x0a, 0x12, 0x42,
|
||||
0x61, 0x74, 0x74, 0x6c, 0x65, 0x43, 0x6f, 0x6c, 0x6c, 0x69, 0x64, 0x65, 0x72, 0x49, 0x6e, 0x66,
|
||||
0x6f, 0x12, 0x1c, 0x0a, 0x09, 0x73, 0x74, 0x61, 0x67, 0x65, 0x4e, 0x61, 0x6d, 0x65, 0x18, 0x01,
|
||||
0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x73, 0x74, 0x61, 0x67, 0x65, 0x4e, 0x61, 0x6d, 0x65, 0x12,
|
||||
@ -1551,42 +1551,35 @@ var file_room_downsync_frame_proto_rawDesc = []byte{
|
||||
0x76, 0x69, 0x74, 0x79, 0x58, 0x18, 0x1c, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x67, 0x72, 0x61,
|
||||
0x76, 0x69, 0x74, 0x79, 0x58, 0x12, 0x1a, 0x0a, 0x08, 0x67, 0x72, 0x61, 0x76, 0x69, 0x74, 0x79,
|
||||
0x59, 0x18, 0x1d, 0x20, 0x01, 0x28, 0x05, 0x52, 0x08, 0x67, 0x72, 0x61, 0x76, 0x69, 0x74, 0x79,
|
||||
0x59, 0x1a, 0x58, 0x0a, 0x15, 0x4d, 0x65, 0x6c, 0x65, 0x65, 0x53, 0x6b, 0x69, 0x6c, 0x6c, 0x43,
|
||||
0x6f, 0x6e, 0x66, 0x69, 0x67, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65,
|
||||
0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x29, 0x0a, 0x05,
|
||||
0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x70, 0x72,
|
||||
0x6f, 0x74, 0x6f, 0x73, 0x2e, 0x4d, 0x65, 0x6c, 0x65, 0x65, 0x42, 0x75, 0x6c, 0x6c, 0x65, 0x74,
|
||||
0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0xb8, 0x03, 0x0a, 0x11,
|
||||
0x52, 0x6f, 0x6f, 0x6d, 0x44, 0x6f, 0x77, 0x6e, 0x73, 0x79, 0x6e, 0x63, 0x46, 0x72, 0x61, 0x6d,
|
||||
0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x69,
|
||||
0x64, 0x12, 0x36, 0x0a, 0x0a, 0x70, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x73, 0x41, 0x72, 0x72, 0x18,
|
||||
0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x16, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2e, 0x50,
|
||||
0x6c, 0x61, 0x79, 0x65, 0x72, 0x44, 0x6f, 0x77, 0x6e, 0x73, 0x79, 0x6e, 0x63, 0x52, 0x0a, 0x70,
|
||||
0x6c, 0x61, 0x79, 0x65, 0x72, 0x73, 0x41, 0x72, 0x72, 0x12, 0x26, 0x0a, 0x0e, 0x63, 0x6f, 0x75,
|
||||
0x6e, 0x74, 0x64, 0x6f, 0x77, 0x6e, 0x4e, 0x61, 0x6e, 0x6f, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28,
|
||||
0x03, 0x52, 0x0e, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x64, 0x6f, 0x77, 0x6e, 0x4e, 0x61, 0x6e, 0x6f,
|
||||
0x73, 0x12, 0x37, 0x0a, 0x0c, 0x6d, 0x65, 0x6c, 0x65, 0x65, 0x42, 0x75, 0x6c, 0x6c, 0x65, 0x74,
|
||||
0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73,
|
||||
0x2e, 0x4d, 0x65, 0x6c, 0x65, 0x65, 0x42, 0x75, 0x6c, 0x6c, 0x65, 0x74, 0x52, 0x0c, 0x6d, 0x65,
|
||||
0x6c, 0x65, 0x65, 0x42, 0x75, 0x6c, 0x6c, 0x65, 0x74, 0x73, 0x12, 0x36, 0x0a, 0x16, 0x62, 0x61,
|
||||
0x63, 0x6b, 0x65, 0x6e, 0x64, 0x55, 0x6e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x72, 0x6d, 0x65, 0x64,
|
||||
0x4d, 0x61, 0x73, 0x6b, 0x18, 0x05, 0x20, 0x01, 0x28, 0x04, 0x52, 0x16, 0x62, 0x61, 0x63, 0x6b,
|
||||
0x65, 0x6e, 0x64, 0x55, 0x6e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x72, 0x6d, 0x65, 0x64, 0x4d, 0x61,
|
||||
0x73, 0x6b, 0x12, 0x2c, 0x0a, 0x11, 0x73, 0x68, 0x6f, 0x75, 0x6c, 0x64, 0x46, 0x6f, 0x72, 0x63,
|
||||
0x65, 0x52, 0x65, 0x73, 0x79, 0x6e, 0x63, 0x18, 0x06, 0x20, 0x01, 0x28, 0x08, 0x52, 0x11, 0x73,
|
||||
0x68, 0x6f, 0x75, 0x6c, 0x64, 0x46, 0x6f, 0x72, 0x63, 0x65, 0x52, 0x65, 0x73, 0x79, 0x6e, 0x63,
|
||||
0x12, 0x40, 0x0a, 0x07, 0x70, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x73, 0x18, 0x63, 0x20, 0x03, 0x28,
|
||||
0x0b, 0x32, 0x26, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2e, 0x52, 0x6f, 0x6f, 0x6d, 0x44,
|
||||
0x6f, 0x77, 0x6e, 0x73, 0x79, 0x6e, 0x63, 0x46, 0x72, 0x61, 0x6d, 0x65, 0x2e, 0x50, 0x6c, 0x61,
|
||||
0x79, 0x65, 0x72, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x07, 0x70, 0x6c, 0x61, 0x79, 0x65,
|
||||
0x72, 0x73, 0x1a, 0x52, 0x0a, 0x0c, 0x50, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x73, 0x45, 0x6e, 0x74,
|
||||
0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52,
|
||||
0x03, 0x6b, 0x65, 0x79, 0x12, 0x2c, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20,
|
||||
0x01, 0x28, 0x0b, 0x32, 0x16, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2e, 0x50, 0x6c, 0x61,
|
||||
0x79, 0x65, 0x72, 0x44, 0x6f, 0x77, 0x6e, 0x73, 0x79, 0x6e, 0x63, 0x52, 0x05, 0x76, 0x61, 0x6c,
|
||||
0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x42, 0x13, 0x5a, 0x11, 0x62, 0x61, 0x74, 0x74, 0x6c, 0x65,
|
||||
0x5f, 0x73, 0x72, 0x76, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x62, 0x06, 0x70, 0x72, 0x6f,
|
||||
0x74, 0x6f, 0x33,
|
||||
0x59, 0x12, 0x2a, 0x0a, 0x10, 0x63, 0x6f, 0x6c, 0x6c, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x4d, 0x69,
|
||||
0x6e, 0x53, 0x74, 0x65, 0x70, 0x18, 0x1e, 0x20, 0x01, 0x28, 0x05, 0x52, 0x10, 0x63, 0x6f, 0x6c,
|
||||
0x6c, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x4d, 0x69, 0x6e, 0x53, 0x74, 0x65, 0x70, 0x1a, 0x58, 0x0a,
|
||||
0x15, 0x4d, 0x65, 0x6c, 0x65, 0x65, 0x53, 0x6b, 0x69, 0x6c, 0x6c, 0x43, 0x6f, 0x6e, 0x66, 0x69,
|
||||
0x67, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20,
|
||||
0x01, 0x28, 0x05, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x29, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75,
|
||||
0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73,
|
||||
0x2e, 0x4d, 0x65, 0x6c, 0x65, 0x65, 0x42, 0x75, 0x6c, 0x6c, 0x65, 0x74, 0x52, 0x05, 0x76, 0x61,
|
||||
0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0xa2, 0x02, 0x0a, 0x11, 0x52, 0x6f, 0x6f, 0x6d,
|
||||
0x44, 0x6f, 0x77, 0x6e, 0x73, 0x79, 0x6e, 0x63, 0x46, 0x72, 0x61, 0x6d, 0x65, 0x12, 0x0e, 0x0a,
|
||||
0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x69, 0x64, 0x12, 0x36, 0x0a,
|
||||
0x0a, 0x70, 0x6c, 0x61, 0x79, 0x65, 0x72, 0x73, 0x41, 0x72, 0x72, 0x18, 0x02, 0x20, 0x03, 0x28,
|
||||
0x0b, 0x32, 0x16, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2e, 0x50, 0x6c, 0x61, 0x79, 0x65,
|
||||
0x72, 0x44, 0x6f, 0x77, 0x6e, 0x73, 0x79, 0x6e, 0x63, 0x52, 0x0a, 0x70, 0x6c, 0x61, 0x79, 0x65,
|
||||
0x72, 0x73, 0x41, 0x72, 0x72, 0x12, 0x26, 0x0a, 0x0e, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x64, 0x6f,
|
||||
0x77, 0x6e, 0x4e, 0x61, 0x6e, 0x6f, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x52, 0x0e, 0x63,
|
||||
0x6f, 0x75, 0x6e, 0x74, 0x64, 0x6f, 0x77, 0x6e, 0x4e, 0x61, 0x6e, 0x6f, 0x73, 0x12, 0x37, 0x0a,
|
||||
0x0c, 0x6d, 0x65, 0x6c, 0x65, 0x65, 0x42, 0x75, 0x6c, 0x6c, 0x65, 0x74, 0x73, 0x18, 0x04, 0x20,
|
||||
0x03, 0x28, 0x0b, 0x32, 0x13, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x73, 0x2e, 0x4d, 0x65, 0x6c,
|
||||
0x65, 0x65, 0x42, 0x75, 0x6c, 0x6c, 0x65, 0x74, 0x52, 0x0c, 0x6d, 0x65, 0x6c, 0x65, 0x65, 0x42,
|
||||
0x75, 0x6c, 0x6c, 0x65, 0x74, 0x73, 0x12, 0x36, 0x0a, 0x16, 0x62, 0x61, 0x63, 0x6b, 0x65, 0x6e,
|
||||
0x64, 0x55, 0x6e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x72, 0x6d, 0x65, 0x64, 0x4d, 0x61, 0x73, 0x6b,
|
||||
0x18, 0x05, 0x20, 0x01, 0x28, 0x04, 0x52, 0x16, 0x62, 0x61, 0x63, 0x6b, 0x65, 0x6e, 0x64, 0x55,
|
||||
0x6e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x72, 0x6d, 0x65, 0x64, 0x4d, 0x61, 0x73, 0x6b, 0x12, 0x2c,
|
||||
0x0a, 0x11, 0x73, 0x68, 0x6f, 0x75, 0x6c, 0x64, 0x46, 0x6f, 0x72, 0x63, 0x65, 0x52, 0x65, 0x73,
|
||||
0x79, 0x6e, 0x63, 0x18, 0x06, 0x20, 0x01, 0x28, 0x08, 0x52, 0x11, 0x73, 0x68, 0x6f, 0x75, 0x6c,
|
||||
0x64, 0x46, 0x6f, 0x72, 0x63, 0x65, 0x52, 0x65, 0x73, 0x79, 0x6e, 0x63, 0x42, 0x13, 0x5a, 0x11,
|
||||
0x62, 0x61, 0x74, 0x74, 0x6c, 0x65, 0x5f, 0x73, 0x72, 0x76, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f,
|
||||
0x73, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
@ -1601,7 +1594,7 @@ func file_room_downsync_frame_proto_rawDescGZIP() []byte {
|
||||
return file_room_downsync_frame_proto_rawDescData
|
||||
}
|
||||
|
||||
var file_room_downsync_frame_proto_msgTypes = make([]protoimpl.MessageInfo, 13)
|
||||
var file_room_downsync_frame_proto_msgTypes = make([]protoimpl.MessageInfo, 12)
|
||||
var file_room_downsync_frame_proto_goTypes = []interface{}{
|
||||
(*PlayerDownsync)(nil), // 0: protos.PlayerDownsync
|
||||
(*InputFrameDecoded)(nil), // 1: protos.InputFrameDecoded
|
||||
@ -1615,7 +1608,6 @@ var file_room_downsync_frame_proto_goTypes = []interface{}{
|
||||
(*BattleColliderInfo)(nil), // 9: protos.BattleColliderInfo
|
||||
(*RoomDownsyncFrame)(nil), // 10: protos.RoomDownsyncFrame
|
||||
nil, // 11: protos.BattleColliderInfo.MeleeSkillConfigEntry
|
||||
nil, // 12: protos.RoomDownsyncFrame.PlayersEntry
|
||||
}
|
||||
var file_room_downsync_frame_proto_depIdxs = []int32{
|
||||
2, // 0: protos.WsReq.inputFrameUpsyncBatch:type_name -> protos.InputFrameUpsync
|
||||
@ -1627,14 +1619,12 @@ var file_room_downsync_frame_proto_depIdxs = []int32{
|
||||
11, // 6: protos.BattleColliderInfo.meleeSkillConfig:type_name -> protos.BattleColliderInfo.MeleeSkillConfigEntry
|
||||
0, // 7: protos.RoomDownsyncFrame.playersArr:type_name -> protos.PlayerDownsync
|
||||
8, // 8: protos.RoomDownsyncFrame.meleeBullets:type_name -> protos.MeleeBullet
|
||||
12, // 9: protos.RoomDownsyncFrame.players:type_name -> protos.RoomDownsyncFrame.PlayersEntry
|
||||
8, // 10: protos.BattleColliderInfo.MeleeSkillConfigEntry.value:type_name -> protos.MeleeBullet
|
||||
0, // 11: protos.RoomDownsyncFrame.PlayersEntry.value:type_name -> protos.PlayerDownsync
|
||||
12, // [12:12] is the sub-list for method output_type
|
||||
12, // [12:12] is the sub-list for method input_type
|
||||
12, // [12:12] is the sub-list for extension type_name
|
||||
12, // [12:12] is the sub-list for extension extendee
|
||||
0, // [0:12] is the sub-list for field type_name
|
||||
8, // 9: protos.BattleColliderInfo.MeleeSkillConfigEntry.value:type_name -> protos.MeleeBullet
|
||||
10, // [10:10] is the sub-list for method output_type
|
||||
10, // [10:10] is the sub-list for method input_type
|
||||
10, // [10:10] is the sub-list for extension type_name
|
||||
10, // [10:10] is the sub-list for extension extendee
|
||||
0, // [0:10] is the sub-list for field type_name
|
||||
}
|
||||
|
||||
func init() { file_room_downsync_frame_proto_init() }
|
||||
@ -1782,7 +1772,7 @@ func file_room_downsync_frame_proto_init() {
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: file_room_downsync_frame_proto_rawDesc,
|
||||
NumEnums: 0,
|
||||
NumMessages: 13,
|
||||
NumMessages: 12,
|
||||
NumExtensions: 0,
|
||||
NumServices: 0,
|
||||
},
|
||||
|
@ -240,14 +240,12 @@ func Serve(c *gin.Context) {
|
||||
|
||||
// Construct "battleColliderInfo" to downsync
|
||||
bciFrame := &pb.BattleColliderInfo{
|
||||
BoundRoomId: pRoom.Id,
|
||||
StageName: pRoom.StageName,
|
||||
StrToVec2DListMap: pRoom.StrToVec2DListMap,
|
||||
StrToPolygon2DListMap: pRoom.StrToPolygon2DListMap,
|
||||
StageDiscreteW: pRoom.StageDiscreteW,
|
||||
StageDiscreteH: pRoom.StageDiscreteH,
|
||||
StageTileW: pRoom.StageTileW,
|
||||
StageTileH: pRoom.StageTileH,
|
||||
BoundRoomId: pRoom.Id,
|
||||
StageName: pRoom.StageName,
|
||||
StageDiscreteW: pRoom.StageDiscreteW,
|
||||
StageDiscreteH: pRoom.StageDiscreteH,
|
||||
StageTileW: pRoom.StageTileW,
|
||||
StageTileH: pRoom.StageTileH,
|
||||
|
||||
IntervalToPing: int32(Constants.Ws.IntervalToPing),
|
||||
WillKickIfInactiveFor: int32(Constants.Ws.WillKickIfInactiveFor),
|
||||
@ -273,6 +271,7 @@ func Serve(c *gin.Context) {
|
||||
JumpingInitVelY: pRoom.JumpingInitVelY,
|
||||
GravityX: pRoom.GravityX,
|
||||
GravityY: pRoom.GravityY,
|
||||
CollisionMinStep: pRoom.CollisionMinStep,
|
||||
}
|
||||
|
||||
resp := &pb.WsResp{
|
||||
|
@ -1,3 +1,11 @@
|
||||
module dnmshared
|
||||
|
||||
go 1.18
|
||||
|
||||
require (
|
||||
resolv v0.0.0
|
||||
)
|
||||
|
||||
replace (
|
||||
resolv => ../resolv_tailored
|
||||
)
|
||||
|
@ -1,9 +1,9 @@
|
||||
package dnmshared
|
||||
|
||||
import (
|
||||
. "jsexport/battle"
|
||||
"fmt"
|
||||
"github.com/solarlune/resolv"
|
||||
. "jsexport/battle"
|
||||
"resolv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
|
@ -175,8 +175,8 @@ func (l *TmxLayer) decodeBase64() ([]uint32, error) {
|
||||
return gids, nil
|
||||
}
|
||||
|
||||
type StrToVec2DListMap map[string]([]*Vec2D)
|
||||
type StrToPolygon2DListMap map[string]([]*Polygon2D)
|
||||
type StrToVec2DListMap map[string](*[]*Vec2D)
|
||||
type StrToPolygon2DListMap map[string](*[]*Polygon2D)
|
||||
|
||||
func tmxPolylineToPolygon2D(pTmxMapIns *TmxMap, singleObjInTmxFile *TmxOrTsxObject, targetPolyline *TmxOrTsxPolyline) (*Polygon2D, error) {
|
||||
if nil == targetPolyline {
|
||||
@ -321,19 +321,18 @@ func DeserializeTsxToColliderDict(pTmxMapIns *TmxMap, byteArrOfTsxFile []byte, f
|
||||
theStrToPolygon2DListMap = gidBoundariesMap[globalGid]
|
||||
}
|
||||
|
||||
var pThePolygon2DList []*Polygon2D
|
||||
if _, ok := theStrToPolygon2DListMap[key]; ok {
|
||||
pThePolygon2DList = theStrToPolygon2DListMap[key]
|
||||
} else {
|
||||
pThePolygon2DList = make([]*Polygon2D, 0)
|
||||
theStrToPolygon2DListMap[key] = pThePolygon2DList
|
||||
var pThePolygon2DList *[]*Polygon2D = nil
|
||||
if _, ok := theStrToPolygon2DListMap[key]; !ok {
|
||||
tmp := make([]*Polygon2D, 0)
|
||||
theStrToPolygon2DListMap[key] = &tmp
|
||||
}
|
||||
pThePolygon2DList = theStrToPolygon2DListMap[key]
|
||||
|
||||
thePolygon2DFromPolyline, err := tsxPolylineToOffsetsWrtTileCenter(pTmxMapIns, singleObj, singleObj.Polyline, pTsxIns)
|
||||
if nil != err {
|
||||
panic(err)
|
||||
}
|
||||
pThePolygon2DList = append(pThePolygon2DList, thePolygon2DFromPolyline)
|
||||
*pThePolygon2DList = append(*pThePolygon2DList, thePolygon2DFromPolyline)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
@ -346,11 +345,10 @@ func ParseTmxLayersAndGroups(pTmxMapIns *TmxMap, gidBoundariesMap map[int]StrToP
|
||||
for _, objGroup := range pTmxMapIns.ObjectGroups {
|
||||
switch objGroup.Name {
|
||||
case "PlayerStartingPos":
|
||||
var pTheVec2DListToCache []*Vec2D
|
||||
_, ok := toRetStrToVec2DListMap[objGroup.Name]
|
||||
if false == ok {
|
||||
pTheVec2DListToCache = make([]*Vec2D, 0)
|
||||
toRetStrToVec2DListMap[objGroup.Name] = pTheVec2DListToCache
|
||||
var pTheVec2DListToCache *[]*Vec2D = nil
|
||||
if _, ok := toRetStrToVec2DListMap[objGroup.Name]; !ok {
|
||||
tmp := make([]*Vec2D, 0)
|
||||
toRetStrToVec2DListMap[objGroup.Name] = &tmp
|
||||
}
|
||||
pTheVec2DListToCache = toRetStrToVec2DListMap[objGroup.Name]
|
||||
for _, singleObjInTmxFile := range objGroup.Objects {
|
||||
@ -359,16 +357,16 @@ func ParseTmxLayersAndGroups(pTmxMapIns *TmxMap, gidBoundariesMap map[int]StrToP
|
||||
Y: singleObjInTmxFile.Y,
|
||||
}
|
||||
thePosInWorld := pTmxMapIns.continuousObjLayerOffsetToContinuousMapNodePos(theUntransformedPos)
|
||||
pTheVec2DListToCache = append(pTheVec2DListToCache, &thePosInWorld)
|
||||
*pTheVec2DListToCache = append(*pTheVec2DListToCache, &thePosInWorld)
|
||||
}
|
||||
case "Barrier":
|
||||
// Note that in this case, the "Polygon2D.Anchor" of each "TmxOrTsxObject" is exactly overlapping with "Polygon2D.Points[0]".
|
||||
var pThePolygon2DListToCache []*Polygon2D
|
||||
_, ok := toRetStrToPolygon2DListMap[objGroup.Name]
|
||||
if false == ok {
|
||||
pThePolygon2DListToCache = make([]*Polygon2D, 0)
|
||||
toRetStrToPolygon2DListMap[objGroup.Name] = pThePolygon2DListToCache
|
||||
var pThePolygon2DListToCache *[]*Polygon2D = nil
|
||||
if _, ok := toRetStrToPolygon2DListMap[objGroup.Name]; !ok {
|
||||
tmp := make([]*Polygon2D, 0)
|
||||
toRetStrToPolygon2DListMap[objGroup.Name] = &tmp
|
||||
}
|
||||
pThePolygon2DListToCache = toRetStrToPolygon2DListMap[objGroup.Name]
|
||||
|
||||
for _, singleObjInTmxFile := range objGroup.Objects {
|
||||
if nil == singleObjInTmxFile.Polyline {
|
||||
@ -402,7 +400,7 @@ func ParseTmxLayersAndGroups(pTmxMapIns *TmxMap, gidBoundariesMap map[int]StrToP
|
||||
if nil != err {
|
||||
panic(err)
|
||||
}
|
||||
pThePolygon2DListToCache = append(pThePolygon2DListToCache, thePolygon2DInWorld)
|
||||
*pThePolygon2DListToCache = append(*pThePolygon2DListToCache, thePolygon2DInWorld)
|
||||
}
|
||||
default:
|
||||
}
|
||||
|
File diff suppressed because one or more lines are too long
@ -146,6 +146,7 @@ message BattleColliderInfo {
|
||||
int32 jumpingInitVelY = 27;
|
||||
int32 gravityX = 28;
|
||||
int32 gravityY = 29;
|
||||
int32 collisionMinStep = 30;
|
||||
}
|
||||
|
||||
message RoomDownsyncFrame {
|
||||
@ -155,6 +156,4 @@ message RoomDownsyncFrame {
|
||||
repeated MeleeBullet meleeBullets = 4; // I don't know how to mimic inheritance/composition in protobuf by far, thus using an array for each type of bullet as a compromise
|
||||
uint64 backendUnconfirmedMask = 5; // Indexed by "joinIndex", same compression concern as stated in InputFrameDownsync
|
||||
bool shouldForceResync = 6;
|
||||
|
||||
map<int32, PlayerDownsync> players = 99; // TO BE DEPRECATED
|
||||
}
|
||||
|
@ -141,7 +141,7 @@ cc.Class({
|
||||
|
||||
let previousSelfInput = null,
|
||||
currSelfInput = null;
|
||||
const joinIndex = self.selfPlayerInfo.joinIndex;
|
||||
const joinIndex = self.selfPlayerInfo.joinIndex || self.selfPlayerInfo.JoinIndex;
|
||||
const existingInputFrame = self.recentInputCache.getByFrameId(inputFrameId);
|
||||
const previousInputFrameDownsyncWithPrediction = self.getCachedInputFrameDownsyncWithPrediction(inputFrameId - 1);
|
||||
previousSelfInput = (null == previousInputFrameDownsyncWithPrediction ? null : previousInputFrameDownsyncWithPrediction.inputList[joinIndex - 1]);
|
||||
@ -159,7 +159,7 @@ cc.Class({
|
||||
const prefabbedInputFrameDownsync = window.pb.protos.InputFrameDownsync.create({
|
||||
inputFrameId: self.recentInputCache.edFrameId,
|
||||
inputList: prefabbedInputList,
|
||||
confirmedList: (1 << (self.selfPlayerInfo.joinIndex - 1))
|
||||
confirmedList: (1 << (joinIndex - 1))
|
||||
});
|
||||
|
||||
self.recentInputCache.put(prefabbedInputFrameDownsync);
|
||||
@ -308,11 +308,15 @@ cc.Class({
|
||||
self.selfPlayerInfo = null; // This field is kept for distinguishing "self" and "others".
|
||||
self.recentInputCache = new RingBuffer((self.renderCacheSize >> 1) + 1);
|
||||
|
||||
self.collisionSys = new collisions.Collisions();
|
||||
const spaceW = self.stageDiscreteW * self.stageTileW;
|
||||
const spaceH = self.stageDiscreteH * self.stageTileH;
|
||||
self.spaceOffsetX = (spaceW >> 1);
|
||||
self.spaceOffsetY = (spaceH >> 1);
|
||||
self.gopkgsCollisionSys = gopkgs.NewCollisionSpaceJs(spaceW, spaceH, self.collisionMinStep, self.collisionMinStep);
|
||||
self.gopkgsCollisionSysMap = {}; // [WARNING] Don't use "JavaScript Map" which could cause loss of type information when passing through Golang transpiled functions!
|
||||
|
||||
self.collisionBarrierIndexPrefix = (1 << 16); // For tracking the movements of barriers, though not yet actually used
|
||||
self.collisionBulletIndexPrefix = (1 << 15); // For tracking the movements of bullets
|
||||
self.collisionSysMap = new Map();
|
||||
|
||||
console.log(`collisionSys & collisionSysMap reset`);
|
||||
|
||||
@ -454,21 +458,19 @@ cc.Class({
|
||||
}
|
||||
|
||||
let barrierIdCounter = 0;
|
||||
const refBoundaryObjs = tileCollisionManager.extractBoundaryObjects(self.node).barriers;
|
||||
const boundaryObjs = parsedBattleColliderInfo.strToPolygon2DListMap;
|
||||
for (let k = 0; k < boundaryObjs["Barrier"].eles.length; k++) {
|
||||
let boundaryObj = boundaryObjs["Barrier"].eles[k];
|
||||
const refBoundaryObj = refBoundaryObjs[k];
|
||||
// boundaryObj = refBoundaryObj;
|
||||
const [x0, y0] = [boundaryObj.anchor.x, boundaryObj.anchor.y];
|
||||
const newBarrierCollider = self.collisionSys.createPolygon(x0, y0, Array.from(boundaryObj.points, p => {
|
||||
return [p.x, p.y];
|
||||
}));
|
||||
newBarrierCollider.data = {
|
||||
hardPushback: true
|
||||
};
|
||||
const boundaryObjs = tileCollisionManager.extractBoundaryObjects(self.node);
|
||||
for (let boundaryObj of boundaryObjs.barriers) {
|
||||
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);
|
||||
|
||||
if (self.showCriticalCoordinateLabels) {
|
||||
const newBarrierCollider = gopkgs.GenerateConvexPolygonColliderJs(gopkgsBoundary, self.spaceOffsetX, self.spaceOffsetY, gopkgsBarrier, "Barrier");
|
||||
self.gopkgsCollisionSys.Add(newBarrierCollider);
|
||||
|
||||
if (false && self.showCriticalCoordinateLabels) {
|
||||
for (let i = 0; i < boundaryObj.length; ++i) {
|
||||
const barrierVertLabelNode = new cc.Node();
|
||||
switch (i % 4) {
|
||||
@ -499,12 +501,11 @@ cc.Class({
|
||||
}
|
||||
|
||||
}
|
||||
// console.log("Created barrier: ", newBarrierCollider);
|
||||
++barrierIdCounter;
|
||||
const collisionBarrierIndex = (self.collisionBarrierIndexPrefix + barrierIdCounter);
|
||||
self.collisionSysMap.set(collisionBarrierIndex, newBarrierCollider);
|
||||
// console.log(`Created new barrier collider: ${collisionBarrierIndex}`);
|
||||
self.gopkgsCollisionSysMap[collisionBarrierIndex] = newBarrierCollider;
|
||||
}
|
||||
|
||||
self.selfPlayerInfo = JSON.parse(cc.sys.localStorage.getItem('selfPlayer'));
|
||||
Object.assign(self.selfPlayerInfo, {
|
||||
id: self.selfPlayerInfo.playerId
|
||||
@ -578,8 +579,22 @@ cc.Class({
|
||||
this._inputControlEnabled = false;
|
||||
},
|
||||
|
||||
onRoomDownsyncFrame(rdf, accompaniedInputFrameDownsyncBatch) {
|
||||
onRoomDownsyncFrame(pbRdf /* pb.RoomDownsyncFrame */ , accompaniedInputFrameDownsyncBatch /* pb.InputFrameDownsyncBatch */ ) {
|
||||
const jsPlayersArr = new Array().fill(null);
|
||||
for (let k in pbRdf.playersArr) {
|
||||
const pbPlayer = pbRdf.playersArr[k];
|
||||
const jsPlayer = gopkgs.NewPlayerDownsyncJs(pbPlayer.id, pbPlayer.virtualGridX, pbPlayer.virtualGridY, pbPlayer.dirX, pbPlayer.dirY, pbPlayer.velX, pbPlayer.velY, pbPlayer.speed, pbPlayer.battleState, pbPlayer.characterState, pbPlayer.joinIndex, pbPlayer.hp, pbPlayer.maxHp, pbPlayer.inAir, pbPlayer.colliderRadius);
|
||||
jsPlayersArr[k] = jsPlayer;
|
||||
}
|
||||
const jsMeleeBulletsArr = [];
|
||||
for (let k in pbRdf.meleeBullets) {
|
||||
const pbBullet = pbRdf.meleeBullets[k];
|
||||
const jsBullet = gopkgs.NewMeleeBullet(pbBullet.battleLocalId, pbBullet.startupFrames, pbBullet.activeFrames, pbBullet.recoveryFrames, pbBullet.recoveryFramesOnBlock, pbBullet.recoveryFramesOnHit, pbBullet.hitStunFrames, pbBullet.blockStunFrames, pbBullet.releaseTriggerType, pbBullet.damage, pbBullet.offenderJoinIndex, pbBullet.offenderPlayerId, pbBullet.pushback, pbBullet.hitboxOffset, pbBullet.selfMoveforwardX, pbBullet.selfMoveforwardY, pbBullet.hitboxSizeX, pbBullet.hitboxSizeY);
|
||||
jsMeleeBulletsArr.push(jsBullet);
|
||||
}
|
||||
|
||||
// This function is also applicable to "re-joining".
|
||||
const rdf = gopkgs.NewRoomDownsyncFrameJs(pbRdf.id, jsPlayersArr, jsMeleeBulletsArr);
|
||||
const self = window.mapIns;
|
||||
self.onInputFrameDownsyncBatch(accompaniedInputFrameDownsyncBatch); // Important to do this step before setting IN_BATTLE
|
||||
if (!self.recentRenderCache) {
|
||||
@ -588,14 +603,14 @@ cc.Class({
|
||||
if (ALL_BATTLE_STATES.IN_SETTLEMENT == self.battleState) {
|
||||
return;
|
||||
}
|
||||
const shouldForceDumping1 = (window.MAGIC_ROOM_DOWNSYNC_FRAME_ID.BATTLE_START == rdf.id);
|
||||
let shouldForceDumping2 = (rdf.id >= self.renderFrameId + self.renderFrameIdLagTolerance);
|
||||
let shouldForceResync = rdf.shouldForceResync;
|
||||
const notSelfUnconfirmed = (0 == (rdf.backendUnconfirmedMask & (1 << (self.selfPlayerInfo.joinIndex - 1))));
|
||||
const shouldForceDumping1 = (window.MAGIC_ROOM_DOWNSYNC_FRAME_ID.BATTLE_START == rdf.Id);
|
||||
let shouldForceDumping2 = (rdf.Id >= self.renderFrameId + self.renderFrameIdLagTolerance);
|
||||
let shouldForceResync = rdf.ShouldForceResync;
|
||||
const notSelfUnconfirmed = (0 == (rdf.BackendUnconfirmedMask & (1 << (self.selfPlayerInfo.joinIndex - 1))));
|
||||
if (notSelfUnconfirmed) {
|
||||
shouldForceDumping2 = false;
|
||||
shouldForceResync = false;
|
||||
self.othersForcedDownsyncRenderFrameDict.set(rdf.id, rdf);
|
||||
self.othersForcedDownsyncRenderFrameDict.set(rdf.Id, rdf);
|
||||
}
|
||||
/*
|
||||
TODO
|
||||
@ -616,47 +631,40 @@ cc.Class({
|
||||
}
|
||||
|
||||
// The logic below applies to (window.MAGIC_ROOM_DOWNSYNC_FRAME_ID.BATTLE_START == rdf.id || window.RING_BUFF_NON_CONSECUTIVE_SET == dumpRenderCacheRet)
|
||||
const players = rdf.players;
|
||||
self._initPlayerRichInfoDict(players);
|
||||
self._initPlayerRichInfoDict(rdf.PlayersArr);
|
||||
|
||||
// Show the top status indicators for IN_BATTLE
|
||||
if (self.playersInfoNode) {
|
||||
const playersInfoScriptIns = self.playersInfoNode.getComponent("PlayersInfo");
|
||||
for (let i in players) {
|
||||
playersInfoScriptIns.updateData(players[i]);
|
||||
for (let i in pbRdf.playersArr) {
|
||||
playersInfoScriptIns.updateData(pbRdf.playersArr[i]);
|
||||
}
|
||||
}
|
||||
|
||||
if (shouldForceDumping1 || shouldForceDumping2 || shouldForceResync) {
|
||||
// In fact, not having "window.RING_BUFF_CONSECUTIVE_SET == dumpRenderCacheRet" should already imply that "self.renderFrameId <= rdf.id", but here we double check and log the anomaly
|
||||
|
||||
if (window.MAGIC_ROOM_DOWNSYNC_FRAME_ID.BATTLE_START == rdf.id) {
|
||||
console.log('On battle started! renderFrameId=', rdf.id);
|
||||
} else {
|
||||
self.hideFindingPlayersGUI(rdf);
|
||||
console.warn(`Got resync@localRenderFrameId=${self.renderFrameId} -> rdf.id=${rdf.id} & rdf.backendUnconfirmedMask=${rdf.backendUnconfirmedMask}, @lastAllConfirmedInputFrameId=${self.lastAllConfirmedInputFrameId}, @chaserRenderFrameId=${self.chaserRenderFrameId}, @localRecentInputCache=${mapIns._stringifyRecentInputCache(false)}`);
|
||||
if (window.MAGIC_ROOM_DOWNSYNC_FRAME_ID.BATTLE_START == rdf.Id) {
|
||||
console.log('On battle started! renderFrameId=', rdf.Id);
|
||||
}
|
||||
|
||||
self.renderFrameId = rdf.id;
|
||||
self.renderFrameId = rdf.Id;
|
||||
self.lastRenderFrameIdTriggeredAt = performance.now();
|
||||
// In this case it must be true that "rdf.id > chaserRenderFrameId".
|
||||
self.chaserRenderFrameId = rdf.id;
|
||||
self.chaserRenderFrameId = rdf.Id;
|
||||
|
||||
const canvasNode = self.canvasNode;
|
||||
self.ctrl = canvasNode.getComponent("TouchEventsManager");
|
||||
self.enableInputControls();
|
||||
self.transitToState(ALL_MAP_STATES.VISUAL);
|
||||
self.battleState = ALL_BATTLE_STATES.IN_BATTLE;
|
||||
}
|
||||
|
||||
if (self.countdownToBeginGameNode && self.countdownToBeginGameNode.parent) {
|
||||
self.countdownToBeginGameNode.parent.removeChild(self.countdownToBeginGameNode);
|
||||
}
|
||||
if (self.countdownToBeginGameNode && self.countdownToBeginGameNode.parent) {
|
||||
self.countdownToBeginGameNode.parent.removeChild(self.countdownToBeginGameNode);
|
||||
}
|
||||
|
||||
if (null != self.musicEffectManagerScriptIns) {
|
||||
self.musicEffectManagerScriptIns.playBGM();
|
||||
}
|
||||
} else {
|
||||
console.warn(`Anomaly when onRoomDownsyncFrame is called by rdf=${JSON.stringify(rdf)}, recentRenderCache=${self._stringifyRecentRenderCache(false)}, recentInputCache=${self._stringifyRecentInputCache(false)}`);
|
||||
if (null != self.musicEffectManagerScriptIns) {
|
||||
self.musicEffectManagerScriptIns.playBGM();
|
||||
}
|
||||
|
||||
// [WARNING] Leave all graphical updates in "update(dt)" by "applyRoomDownsyncFrameDynamics"
|
||||
@ -769,14 +777,14 @@ lastAllConfirmedInputFrameId=${self.lastAllConfirmedInputFrameId}`);
|
||||
self.chaserRenderFrameId = renderFrameId1;
|
||||
},
|
||||
|
||||
onPlayerAdded(rdf) {
|
||||
onPlayerAdded(rdf /* pb.RoomDownsyncFrame */ ) {
|
||||
const self = this;
|
||||
// Update the "finding player" GUI and show it if not previously present
|
||||
if (!self.findingPlayerNode.parent) {
|
||||
self.showPopupInCanvas(self.findingPlayerNode);
|
||||
}
|
||||
let findingPlayerScriptIns = self.findingPlayerNode.getComponent("FindingPlayer");
|
||||
findingPlayerScriptIns.updatePlayersInfo(rdf.players);
|
||||
findingPlayerScriptIns.updatePlayersInfo(rdf.playersArr);
|
||||
},
|
||||
|
||||
onBattleStopped() {
|
||||
@ -815,29 +823,37 @@ lastAllConfirmedInputFrameId=${self.lastAllConfirmedInputFrameId}`);
|
||||
const [wx, wy] = self.virtualGridToWorldPos(vx, vy);
|
||||
newPlayerNode.setPosition(wx, wy);
|
||||
playerScriptIns.mapNode = self.node;
|
||||
const halfColliderWidth = playerDownsyncInfo.colliderRadius,
|
||||
halfColliderHeight = playerDownsyncInfo.colliderRadius + playerDownsyncInfo.colliderRadius; // avoid multiplying
|
||||
const colliderRadius = playerDownsyncInfo.colliderRadius || playerDownsyncInfo.ColliderRadius;
|
||||
const halfColliderWidth = colliderRadius,
|
||||
halfColliderHeight = colliderRadius + colliderRadius; // avoid multiplying
|
||||
const colliderWidth = halfColliderWidth + halfColliderWidth,
|
||||
colliderHeight = halfColliderHeight + halfColliderHeight; // avoid multiplying
|
||||
const leftPadding = self.snapIntoPlatformOverlap,
|
||||
rightPadding = self.snapIntoPlatformOverlap,
|
||||
topPadding = self.snapIntoPlatformOverlap,
|
||||
bottomPadding = self.snapIntoPlatformOverlap;
|
||||
const cpos = self.virtualGridToPolygonColliderBLPos(vx, vy, halfColliderWidth, halfColliderHeight, topPadding, bottomPadding, leftPadding, rightPadding); // the collider center is kept having integer coords
|
||||
const pts = [[0, 0], [leftPadding + colliderWidth + rightPadding, 0], [leftPadding + colliderWidth + rightPadding, bottomPadding + colliderHeight + topPadding], [0, bottomPadding + colliderHeight + topPadding]];
|
||||
|
||||
// [WARNING] The animNode "anchor & offset" are tuned to fit in this collider by "ControlledCharacter prefab & AttackingCharacter.js"!
|
||||
const newPlayerCollider = self.collisionSys.createPolygon(cpos[0], cpos[1], pts);
|
||||
const [cx, cy] = gopkgs.WorldToPolygonColliderBLPos(wx, wy, halfColliderWidth, halfColliderHeight, self.snapIntoPlatformOverlap, self.snapIntoPlatformOverlap, self.snapIntoPlatformOverlap, self.snapIntoPlatformOverlap, self.spaceOffsetX, self.spaceOffsetY);
|
||||
const gopkgsBoundaryAnchor = gopkgs.NewVec2DJs(cx, cy);
|
||||
const gopkgsBoundaryPts = [
|
||||
gopkgs.NewVec2DJs(0, 0),
|
||||
gopkgs.NewVec2DJs(self.snapIntoPlatformOverlap + colliderWidth + self.snapIntoPlatformOverlap, 0),
|
||||
gopkgs.NewVec2DJs(self.snapIntoPlatformOverlap + colliderWidth + self.snapIntoPlatformOverlap, self.snapIntoPlatformOverlap + colliderHeight + self.snapIntoPlatformOverlap),
|
||||
gopkgs.NewVec2DJs(0, self.snapIntoPlatformOverlap + colliderHeight + self.snapIntoPlatformOverlap)
|
||||
];
|
||||
const gopkgsBoundary = gopkgs.NewPolygon2DJs(gopkgsBoundaryAnchor, gopkgsBoundaryPts);
|
||||
const newPlayerCollider = gopkgs.GenerateConvexPolygonColliderJs(gopkgsBoundary, self.spaceOffsetX, self.spaceOffsetY, playerDownsyncInfo, "Player");
|
||||
//const newPlayerCollider = gopkgs.GenerateRectColliderJs(wx, wy, colliderWidth, colliderHeight, self.snapIntoPlatformOverlap, self.snapIntoPlatformOverlap, self.snapIntoPlatformOverlap, self.snapIntoPlatformOverlap, self.spaceOffsetX, self.spaceOffsetY, playerDownsyncInfo, "Player");
|
||||
self.gopkgsCollisionSys.Add(newPlayerCollider);
|
||||
const collisionPlayerIndex = self.collisionPlayerIndexPrefix + joinIndex;
|
||||
newPlayerCollider.data = playerDownsyncInfo;
|
||||
self.collisionSysMap.set(collisionPlayerIndex, newPlayerCollider);
|
||||
self.gopkgsCollisionSysMap[collisionPlayerIndex] = newPlayerCollider;
|
||||
|
||||
console.log(`Created new player collider: joinIndex=${joinIndex}, colliderRadius=${playerDownsyncInfo.colliderRadius}`);
|
||||
console.log(`Created new player collider: joinIndex=${joinIndex}, colliderRadius=${playerDownsyncInfo.ColliderRadius}`);
|
||||
|
||||
safelyAddChild(self.node, newPlayerNode);
|
||||
setLocalZOrder(newPlayerNode, 5);
|
||||
|
||||
newPlayerNode.active = true;
|
||||
playerDownsyncInfo.characterState = playerDownsyncInfo.CharacterState;
|
||||
playerDownsyncInfo.dirX = playerDownsyncInfo.DirX;
|
||||
playerDownsyncInfo.dirY = playerDownsyncInfo.DirY;
|
||||
playerDownsyncInfo.framesToRecover = playerDownsyncInfo.FrameToRecover;
|
||||
playerScriptIns.updateCharacterAnim(playerDownsyncInfo, null, true);
|
||||
|
||||
return [newPlayerNode, playerScriptIns];
|
||||
@ -876,12 +892,12 @@ lastAllConfirmedInputFrameId=${self.lastAllConfirmedInputFrameId}`);
|
||||
}
|
||||
if (prevChaserRenderFrameId < nextChaserRenderFrameId) {
|
||||
// Do not execute "rollbackAndChase" when "prevChaserRenderFrameId == nextChaserRenderFrameId", otherwise if "nextChaserRenderFrameId == self.renderFrameId" we'd be wasting computing power once.
|
||||
self.rollbackAndChase(prevChaserRenderFrameId, nextChaserRenderFrameId, self.collisionSys, self.collisionSysMap, true);
|
||||
self.rollbackAndChase(prevChaserRenderFrameId, nextChaserRenderFrameId, self.gopkgsCollisionSys, self.gopkgsCollisionSysMap, true);
|
||||
}
|
||||
let t2 = performance.now();
|
||||
|
||||
// Inside the following "self.rollbackAndChase" actually ROLLS FORWARD w.r.t. the corresponding delayedInputFrame, REGARDLESS OF whether or not "self.chaserRenderFrameId == self.renderFrameId" now.
|
||||
const latestRdfResults = self.rollbackAndChase(self.renderFrameId, self.renderFrameId + 1, self.collisionSys, self.collisionSysMap, false);
|
||||
const latestRdfResults = self.rollbackAndChase(self.renderFrameId, self.renderFrameId + 1, self.gopkgsCollisionSys, self.gopkgsCollisionSysMap, false);
|
||||
let prevRdf = latestRdfResults[0],
|
||||
rdf = latestRdfResults[1];
|
||||
/*
|
||||
@ -1003,10 +1019,9 @@ ${self._stringifyRecentInputAndRenderCacheCorrespondingly()}`);
|
||||
self.findingPlayerNode.parent.removeChild(self.findingPlayerNode);
|
||||
},
|
||||
|
||||
onBattleReadyToStart(rdf) {
|
||||
onBattleReadyToStart(rdf /* pb.RoomDownsyncFrame */ ) {
|
||||
const self = this;
|
||||
const players = rdf.players;
|
||||
self._initPlayerRichInfoDict(players);
|
||||
const players = rdf.playersArr;
|
||||
|
||||
// Show the top status indicators for IN_BATTLE
|
||||
if (self.playersInfoNode) {
|
||||
@ -1035,94 +1050,20 @@ ${self._stringifyRecentInputAndRenderCacheCorrespondingly()}`);
|
||||
|
||||
applyRoomDownsyncFrameDynamics(rdf, prevRdf) {
|
||||
const self = this;
|
||||
for (let [playerId, playerRichInfo] of self.playerRichInfoDict.entries()) {
|
||||
const currPlayerDownsync = rdf.players[playerId];
|
||||
const prevRdfPlayer = (null == prevRdf ? null : prevRdf.players[playerId]);
|
||||
const [wx, wy] = self.virtualGridToWorldPos(currPlayerDownsync.virtualGridX, currPlayerDownsync.virtualGridY);
|
||||
//const justJiggling = (self.jigglingEps1D >= Math.abs(wx - playerRichInfo.node.x) && self.jigglingEps1D >= Math.abs(wy - playerRichInfo.node.y));
|
||||
const playersArr = rdf.PlayersArr;
|
||||
for (let k in playersArr) {
|
||||
const currPlayerDownsync = playersArr[k];
|
||||
const prevRdfPlayer = (null == prevRdf ? null : prevRdf.PlayersArr[k]);
|
||||
const [wx, wy] = self.virtualGridToWorldPos(currPlayerDownsync.VirtualGridX, currPlayerDownsync.VirtualGridY);
|
||||
const playerRichInfo = self.playerRichInfoArr[k];
|
||||
playerRichInfo.node.setPosition(wx, wy);
|
||||
playerRichInfo.scriptIns.updateSpeed(currPlayerDownsync.speed);
|
||||
playerRichInfo.scriptIns.updateSpeed(currPlayerDownsync.Speed);
|
||||
currPlayerDownsync.characterState = currPlayerDownsync.CharacterState;
|
||||
currPlayerDownsync.dirX = currPlayerDownsync.DirX;
|
||||
currPlayerDownsync.dirY = currPlayerDownsync.DirY;
|
||||
currPlayerDownsync.framesToRecover = currPlayerDownsync.FrameToRecover;
|
||||
playerRichInfo.scriptIns.updateCharacterAnim(currPlayerDownsync, prevRdfPlayer, false);
|
||||
}
|
||||
|
||||
// Update countdown
|
||||
self.countdownNanos = self.battleDurationNanos - self.renderFrameId * self.rollbackEstimatedDtNanos;
|
||||
if (self.countdownNanos <= 0) {
|
||||
self.onBattleStopped(self.playerRichInfoDict);
|
||||
}
|
||||
},
|
||||
|
||||
showDebugBoundaries(rdf) {
|
||||
const self = this;
|
||||
const leftPadding = self.snapIntoPlatformOverlap,
|
||||
rightPadding = self.snapIntoPlatformOverlap,
|
||||
topPadding = self.snapIntoPlatformOverlap,
|
||||
bottomPadding = self.snapIntoPlatformOverlap;
|
||||
if (self.showCriticalCoordinateLabels) {
|
||||
let g = self.g;
|
||||
g.clear();
|
||||
|
||||
for (let k in self.collisionSys._bvh._bodies) {
|
||||
const body = self.collisionSys._bvh._bodies[k];
|
||||
if (!body._polygon) continue;
|
||||
if (null != body.data && null != body.data.joinIndex) {
|
||||
// character
|
||||
if (1 == body.data.joinIndex) {
|
||||
g.strokeColor = cc.Color.BLUE;
|
||||
} else {
|
||||
g.strokeColor = cc.Color.RED;
|
||||
}
|
||||
} else {
|
||||
// barrier
|
||||
g.strokeColor = cc.Color.WHITE;
|
||||
}
|
||||
g.moveTo(body.x, body.y);
|
||||
const cnt = body._coords.length;
|
||||
for (let j = 0; j < cnt; j += 2) {
|
||||
const x = body._coords[j],
|
||||
y = body._coords[j + 1];
|
||||
g.lineTo(x, y);
|
||||
}
|
||||
g.lineTo(body.x, body.y);
|
||||
g.stroke();
|
||||
}
|
||||
// For convenience of recovery upon reconnection, active bullets are always created & immediately removed from "collisionSys" within "applyInputFrameDownsyncDynamicsOnSingleRenderFrame"
|
||||
|
||||
for (let k in rdf.meleeBullets) {
|
||||
const meleeBullet = rdf.meleeBullets[k];
|
||||
if (
|
||||
meleeBullet.originatedRenderFrameId + meleeBullet.startupFrames <= rdf.id
|
||||
&&
|
||||
meleeBullet.originatedRenderFrameId + meleeBullet.startupFrames + meleeBullet.activeFrames > rdf.id
|
||||
) {
|
||||
const offender = rdf.players[meleeBullet.offenderPlayerId];
|
||||
if (1 == offender.joinIndex) {
|
||||
g.strokeColor = cc.Color.BLUE;
|
||||
} else {
|
||||
g.strokeColor = cc.Color.RED;
|
||||
}
|
||||
|
||||
let xfac = 1; // By now, straight Punch offset doesn't respect "y-axis"
|
||||
if (0 > offender.dirX) {
|
||||
xfac = -1;
|
||||
}
|
||||
const [offenderWx, offenderWy] = self.virtualGridToWorldPos(offender.virtualGridX, offender.virtualGridY);
|
||||
const bulletWx = offenderWx + xfac * meleeBullet.hitboxOffset;
|
||||
const bulletWy = offenderWy;
|
||||
const halfColliderWidth = meleeBullet.hitboxSize.x * 0.5,
|
||||
halfColliderHeight = meleeBullet.hitboxSize.y * 0.5; // avoid multiplying
|
||||
const bulletCpos = self.worldToPolygonColliderBLPos(bulletWx, bulletWy, halfColliderWidth, halfColliderHeight, topPadding, bottomPadding, leftPadding, rightPadding);
|
||||
const pts = [[0, 0], [leftPadding + meleeBullet.hitboxSize.x + rightPadding, 0], [leftPadding + meleeBullet.hitboxSize.x + rightPadding, bottomPadding + meleeBullet.hitboxSize.y + topPadding], [0, bottomPadding + meleeBullet.hitboxSize.y + topPadding]];
|
||||
|
||||
g.moveTo(bulletCpos[0], bulletCpos[1]);
|
||||
for (let j = 0; j < pts.length; j += 1) {
|
||||
g.lineTo(pts[j][0] + bulletCpos[0], pts[j][1] + bulletCpos[1]);
|
||||
}
|
||||
g.lineTo(bulletCpos[0], bulletCpos[1]);
|
||||
g.stroke();
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
getCachedInputFrameDownsyncWithPrediction(inputFrameId) {
|
||||
@ -1141,373 +1082,7 @@ ${self._stringifyRecentInputAndRenderCacheCorrespondingly()}`);
|
||||
return inputFrameDownsync;
|
||||
},
|
||||
|
||||
// TODO: Write unit-test for this function to compare with its backend counter part
|
||||
applyInputFrameDownsyncDynamicsOnSingleRenderFrame(delayedInputFrame, currRenderFrame, collisionSys, collisionSysMap) {
|
||||
const self = this;
|
||||
const leftPadding = self.snapIntoPlatformOverlap,
|
||||
rightPadding = self.snapIntoPlatformOverlap,
|
||||
topPadding = self.snapIntoPlatformOverlap,
|
||||
bottomPadding = self.snapIntoPlatformOverlap;
|
||||
const nextRenderFramePlayers = {};
|
||||
for (let playerId in currRenderFrame.players) {
|
||||
const currPlayerDownsync = currRenderFrame.players[playerId];
|
||||
nextRenderFramePlayers[playerId] = {
|
||||
id: playerId,
|
||||
virtualGridX: currPlayerDownsync.virtualGridX,
|
||||
virtualGridY: currPlayerDownsync.virtualGridY,
|
||||
dirX: currPlayerDownsync.dirX,
|
||||
dirY: currPlayerDownsync.dirY,
|
||||
velX: currPlayerDownsync.velX,
|
||||
velY: currPlayerDownsync.velY,
|
||||
characterState: currPlayerDownsync.characterState,
|
||||
inAir: true,
|
||||
speed: currPlayerDownsync.speed,
|
||||
battleState: currPlayerDownsync.battleState,
|
||||
score: currPlayerDownsync.score,
|
||||
removed: currPlayerDownsync.removed,
|
||||
joinIndex: currPlayerDownsync.joinIndex,
|
||||
framesToRecover: (0 < currPlayerDownsync.framesToRecover ? currPlayerDownsync.framesToRecover - 1 : 0),
|
||||
hp: currPlayerDownsync.hp,
|
||||
maxHp: currPlayerDownsync.maxHp,
|
||||
};
|
||||
}
|
||||
|
||||
const nextRenderFrameMeleeBullets = [];
|
||||
const effPushbacks = new Array(self.playerRichInfoArr.length);
|
||||
const hardPushbackNorms = new Array(self.playerRichInfoArr.length);
|
||||
|
||||
// 1. Process player inputs
|
||||
/*
|
||||
[WARNING] Player input alone WOULD NOT take "characterState" into any "ATK_CHARACTER_STATE_IN_AIR_SET", only after the calculation of "effPushbacks" do we know exactly whether or not a player is "inAir", the finalize the transition of "thatPlayerInNextFrame.characterState".
|
||||
*/
|
||||
if (null != delayedInputFrame) {
|
||||
const delayedInputFrameForPrevRenderFrame = self.getCachedInputFrameDownsyncWithPrediction(self._convertToInputFrameId(currRenderFrame.id - 1, self.inputDelayFrames));
|
||||
const inputList = delayedInputFrame.inputList;
|
||||
for (let j in self.playerRichInfoArr) {
|
||||
const joinIndex = parseInt(j) + 1;
|
||||
const playerRichInfo = self.playerRichInfoArr[j];
|
||||
const playerId = playerRichInfo.id;
|
||||
const currPlayerDownsync = currRenderFrame.players[playerId];
|
||||
const thatPlayerInNextFrame = nextRenderFramePlayers[playerId];
|
||||
if (0 < thatPlayerInNextFrame.framesToRecover) {
|
||||
// No need to process inputs for this player, but there might be bullet pushbacks on this player
|
||||
continue;
|
||||
}
|
||||
|
||||
const decodedInput = self.ctrl.decodeInput(inputList[joinIndex - 1]);
|
||||
const prevDecodedInput = (null == delayedInputFrameForPrevRenderFrame ? null : self.ctrl.decodeInput(delayedInputFrameForPrevRenderFrame.inputList[joinIndex - 1]));
|
||||
const prevBtnALevel = (null == prevDecodedInput ? 0 : prevDecodedInput.btnALevel);
|
||||
const prevBtnBLevel = (null == prevDecodedInput ? 0 : prevDecodedInput.btnBLevel);
|
||||
if (1 == decodedInput.btnBLevel && 0 == prevBtnBLevel) {
|
||||
const characStateAlreadyInAir = window.ATK_CHARACTER_STATE_IN_AIR_SET.has(thatPlayerInNextFrame.characterState);
|
||||
const characStateIsInterruptWaivable = window.ATK_CHARACTER_STATE_INTERRUPT_WAIVE_SET.has(thatPlayerInNextFrame.characterState);
|
||||
if (
|
||||
!characStateAlreadyInAir
|
||||
&&
|
||||
characStateIsInterruptWaivable
|
||||
) {
|
||||
thatPlayerInNextFrame.velY = self.jumpingInitVelY;
|
||||
if (1 == joinIndex) {
|
||||
console.log(`playerId=${playerId}, joinIndex=${joinIndex} jumped at {renderFrame.id: ${currRenderFrame.id}, virtualX: ${currPlayerDownsync.virtualGridX}, virtualY: ${currPlayerDownsync.virtualGridY}, nextVelX: ${thatPlayerInNextFrame.velX}, nextVelY: ${thatPlayerInNextFrame.velY}}, delayedInputFrame.id=${delayedInputFrame.inputFrameId}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (1 == decodedInput.btnALevel && 0 == prevBtnALevel) {
|
||||
const punchSkillId = 1;
|
||||
const punch = window.pb.protos.MeleeBullet.create(self.meleeSkillConfig[punchSkillId]);
|
||||
thatPlayerInNextFrame.framesToRecover = punch.recoveryFrames;
|
||||
punch.battleLocalId = self.bulletBattleLocalIdCounter++;
|
||||
punch.offenderJoinIndex = joinIndex;
|
||||
punch.offenderPlayerId = playerId;
|
||||
punch.originatedRenderFrameId = currRenderFrame.id;
|
||||
nextRenderFrameMeleeBullets.push(punch);
|
||||
// console.log(`playerId=${playerId}, joinIndex=${joinIndex} triggered a rising-edge of btnA at renderFrame.id=${currRenderFrame.id}, delayedInputFrame.id=${delayedInputFrame.inputFrameId}`);
|
||||
|
||||
thatPlayerInNextFrame.characterState = window.ATK_CHARACTER_STATE.Atk1[0];
|
||||
if (false == currPlayerDownsync.inAir) {
|
||||
thatPlayerInNextFrame.velX = 0; // prohibits simultaneous movement with Atk1 on the ground
|
||||
}
|
||||
} else if (0 == decodedInput.btnALevel && 1 == prevBtnALevel) {
|
||||
// console.log(`playerId=${playerId} triggered a falling-edge of btnA at renderFrame.id=${currRenderFrame.id}, delayedInputFrame.id=${delayedInputFrame.inputFrameId}`);
|
||||
} else {
|
||||
// No bullet trigger, process joystick movement inputs.
|
||||
if (0 != decodedInput.dx || 0 != decodedInput.dy) {
|
||||
// Update directions and thus would eventually update moving animation accordingly
|
||||
thatPlayerInNextFrame.dirX = decodedInput.dx;
|
||||
thatPlayerInNextFrame.dirY = decodedInput.dy;
|
||||
thatPlayerInNextFrame.velX = decodedInput.dx * currPlayerDownsync.speed;
|
||||
thatPlayerInNextFrame.characterState = window.ATK_CHARACTER_STATE.Walking[0];
|
||||
} else {
|
||||
thatPlayerInNextFrame.characterState = window.ATK_CHARACTER_STATE.Idle1[0];
|
||||
thatPlayerInNextFrame.velX = 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 2. Process player movement
|
||||
for (let j in self.playerRichInfoArr) {
|
||||
const joinIndex = parseInt(j) + 1;
|
||||
effPushbacks[joinIndex - 1] = [0.0, 0.0];
|
||||
const playerRichInfo = self.playerRichInfoArr[j];
|
||||
const playerId = playerRichInfo.id;
|
||||
const collisionPlayerIndex = self.collisionPlayerIndexPrefix + joinIndex;
|
||||
const playerCollider = collisionSysMap.get(collisionPlayerIndex);
|
||||
const currPlayerDownsync = currRenderFrame.players[playerId];
|
||||
const thatPlayerInNextFrame = nextRenderFramePlayers[playerId];
|
||||
// Reset playerCollider position from the "virtual grid position"
|
||||
const newVpos = [currPlayerDownsync.virtualGridX + currPlayerDownsync.velX, currPlayerDownsync.virtualGridY + currPlayerDownsync.velY];
|
||||
if (thatPlayerInNextFrame.velY == self.jumpingInitVelY) {
|
||||
// This step can be waived, but putting the jumping inclination here makes it easier to read logs.
|
||||
newVpos[1] += self.jumpingInitVelY;
|
||||
}
|
||||
const halfColliderWidth = self.playerRichInfoArr[j].colliderRadius,
|
||||
halfColliderHeight = self.playerRichInfoArr[j].colliderRadius + self.playerRichInfoArr[j].colliderRadius; // avoid multiplying
|
||||
const newCpos = self.virtualGridToPolygonColliderBLPos(newVpos[0], newVpos[1], halfColliderWidth, halfColliderHeight, topPadding, bottomPadding, leftPadding, rightPadding);
|
||||
playerCollider.x = newCpos[0];
|
||||
playerCollider.y = newCpos[1];
|
||||
|
||||
if (currPlayerDownsync.inAir) {
|
||||
thatPlayerInNextFrame.velX += self.gravityX;
|
||||
thatPlayerInNextFrame.velY += self.gravityY;
|
||||
}
|
||||
}
|
||||
|
||||
// 3. Add bullet colliders into collision system
|
||||
const bulletColliders = new Map(); // Will all be removed at the end of `applyInputFrameDownsyncDynamicsOnSingleRenderFrame` due to the need for being rollback-compatible
|
||||
const removedBulletsAtCurrFrame = new Set();
|
||||
for (let k in currRenderFrame.meleeBullets) {
|
||||
const meleeBullet = currRenderFrame.meleeBullets[k];
|
||||
if (
|
||||
meleeBullet.originatedRenderFrameId + meleeBullet.startupFrames <= currRenderFrame.id
|
||||
&&
|
||||
meleeBullet.originatedRenderFrameId + meleeBullet.startupFrames + meleeBullet.activeFrames > currRenderFrame.id
|
||||
) {
|
||||
const collisionBulletIndex = self.collisionBulletIndexPrefix + meleeBullet.battleLocalId;
|
||||
const collisionOffenderIndex = self.collisionPlayerIndexPrefix + meleeBullet.offenderJoinIndex;
|
||||
const offenderCollider = collisionSysMap.get(collisionOffenderIndex);
|
||||
const offender = currRenderFrame.players[meleeBullet.offenderPlayerId];
|
||||
|
||||
let xfac = 1; // By now, straight Punch offset doesn't respect "y-axis"
|
||||
if (0 > offender.dirX) {
|
||||
xfac = -1;
|
||||
}
|
||||
const [offenderWx, offenderWy] = self.virtualGridToWorldPos(offender.virtualGridX, offender.virtualGridY);
|
||||
const bulletWx = offenderWx + xfac * meleeBullet.hitboxOffset;
|
||||
const bulletWy = offenderWy;
|
||||
const halfColliderWidth = meleeBullet.hitboxSize.x * 0.5,
|
||||
halfColliderHeight = meleeBullet.hitboxSize.y * 0.5;
|
||||
const bulletCpos = self.worldToPolygonColliderBLPos(bulletWx, bulletWy, halfColliderWidth, halfColliderHeight, topPadding, bottomPadding, leftPadding, rightPadding);
|
||||
const pts = [[0, 0], [leftPadding + meleeBullet.hitboxSize.x + rightPadding, 0], [leftPadding + meleeBullet.hitboxSize.x + rightPadding, bottomPadding + meleeBullet.hitboxSize.y + topPadding], [0, bottomPadding + meleeBullet.hitboxSize.y + topPadding]];
|
||||
const newBulletCollider = collisionSys.createPolygon(bulletCpos[0], bulletCpos[1], pts);
|
||||
newBulletCollider.data = meleeBullet;
|
||||
collisionSysMap.set(collisionBulletIndex, newBulletCollider);
|
||||
bulletColliders.set(collisionBulletIndex, newBulletCollider);
|
||||
}
|
||||
}
|
||||
|
||||
// 4. Invoke collision system stepping
|
||||
collisionSys.update();
|
||||
const result = collisionSys.createResult(); // Can I reuse a "self.collisionSysResult" object throughout the whole battle?
|
||||
|
||||
// 5. Calc pushbacks for each player (after its movement) w/o bullets
|
||||
for (let j in self.playerRichInfoArr) {
|
||||
const joinIndex = parseInt(j) + 1;
|
||||
const playerRichInfo = self.playerRichInfoArr[j];
|
||||
const playerId = playerRichInfo.id;
|
||||
const collisionPlayerIndex = self.collisionPlayerIndexPrefix + joinIndex;
|
||||
const playerCollider = collisionSysMap.get(collisionPlayerIndex);
|
||||
const potentials = playerCollider.potentials();
|
||||
hardPushbackNorms[joinIndex - 1] = self.calcHardPushbacksNorms(playerCollider, potentials, result, self.snapIntoPlatformOverlap, effPushbacks[joinIndex - 1]);
|
||||
|
||||
const currPlayerDownsync = currRenderFrame.players[playerId];
|
||||
const thatPlayerInNextFrame = nextRenderFramePlayers[playerId];
|
||||
const halfColliderWidth = self.playerRichInfoArr[j].colliderRadius,
|
||||
halfColliderHeight = self.playerRichInfoArr[j].colliderRadius + self.playerRichInfoArr[j].colliderRadius; // avoid multiplying
|
||||
|
||||
let fallStopping = false;
|
||||
let possiblyFallStoppedOnAnotherPlayer = false;
|
||||
for (const potential of potentials) {
|
||||
let [isBarrier, isAnotherPlayer, isBullet] = [true == potential.data.hardPushback, null != potential.data.joinIndex, null != potential.data.offenderJoinIndex];
|
||||
// ignore bullets for this step
|
||||
if (isBullet) continue;
|
||||
// Test if the player collides with the wall/another player
|
||||
if (!playerCollider.collides(potential, result)) continue;
|
||||
|
||||
const normAlignmentWithGravity = (result.overlap_x * 0 + result.overlap_y * (-1.0));
|
||||
const landedOnGravityPushback = (self.snapIntoPlatformThreshold < normAlignmentWithGravity); // prevents false snapping on the lateral sides
|
||||
let pushback = [result.overlap * result.overlap_x, result.overlap * result.overlap_y];
|
||||
if (landedOnGravityPushback) {
|
||||
// kindly note that one player might land on top of another player
|
||||
pushback = [(result.overlap - self.snapIntoPlatformOverlap) * result.overlap_x, (result.overlap - self.snapIntoPlatformOverlap) * result.overlap_y];
|
||||
thatPlayerInNextFrame.inAir = false;
|
||||
}
|
||||
if (isAnotherPlayer) {
|
||||
/*
|
||||
[WARNING] The "zero overlap collision" might be randomly detected/missed on either frontend or backend, to have deterministic result we added paddings to all sides of a playerCollider. As each velocity component of (velX, velY) being a multiple of 0.5 at any renderFrame, each position component of (x, y) can only be a multiple of 0.5 too, thus whenever a 1-dimensional collision happens between players from [player#1: i*0.5, player#2: j*0.5, not collided yet] to [player#1: (i+k)*0.5, player#2: j*0.5, collided], the overlap becomes (i+k-j)*0.5+2*s, and after snapping subtraction the effPushback magnitude for each player is (i+k-j)*0.5, resulting in 0.5-multiples-position for the next renderFrame.
|
||||
*/
|
||||
pushback = [(result.overlap - self.snapIntoPlatformOverlap * 2) * result.overlap_x, (result.overlap - self.snapIntoPlatformOverlap * 2) * result.overlap_y]; // will overwrite the previous pushback value if "landedOnGravityPushback" is also true
|
||||
}
|
||||
for (let hardPushbackNorm of hardPushbackNorms[joinIndex - 1]) {
|
||||
// remove pushback component on the directions of "hardPushbackNorms[joinIndex-1]" (by now those hardPushbacks are already accounted in "effPushbacks[joinIndex-1]")
|
||||
const projectedMagnitude = pushback[0] * hardPushbackNorm[0] + pushback[1] * hardPushbackNorm[1];
|
||||
if (isBarrier
|
||||
||
|
||||
(isAnotherPlayer && 0 > projectedMagnitude)
|
||||
) {
|
||||
// [WARNING] Pushing by another player is different from pushing by barrier!
|
||||
// Otherwise the player couldn't be pushed by another player to opposite dir of a side wall
|
||||
pushback[0] -= projectedMagnitude * hardPushbackNorm[0];
|
||||
pushback[1] -= projectedMagnitude * hardPushbackNorm[1];
|
||||
}
|
||||
}
|
||||
|
||||
effPushbacks[joinIndex - 1][0] += pushback[0];
|
||||
effPushbacks[joinIndex - 1][1] += pushback[1];
|
||||
// It's not meaningful to log the virtual positions and velocities inside this step.
|
||||
if (currPlayerDownsync.inAir && landedOnGravityPushback) {
|
||||
fallStopping = true;
|
||||
if (isAnotherPlayer) {
|
||||
possiblyFallStoppedOnAnotherPlayer = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (1 == joinIndex) {
|
||||
if (fallStopping) {
|
||||
/*
|
||||
console.info(`playerId=${playerId}, joinIndex=${thatPlayerInNextFrame.joinIndex} fallStopping#1:
|
||||
{renderFrame.id: ${currRenderFrame.id}, possiblyFallStoppedOnAnotherPlayer: ${possiblyFallStoppedOnAnotherPlayer}}
|
||||
playerColliderPos=${self.stringifyColliderCenterInWorld(playerCollider, halfColliderWidth, halfColliderHeight, topPadding, bottomPadding, leftPadding, rightPadding)}, effPushback={${effPushbacks[joinIndex - 1][0].toFixed(3)}, ${effPushbacks[joinIndex - 1][1].toFixed(3)}}, overlayMag=${result.overlap.toFixed(4)}`);
|
||||
*/
|
||||
} else if (currPlayerDownsync.inAir && isBarrier && !landedOnGravityPushback) {
|
||||
/*
|
||||
console.warn(`playerId=${playerId}, joinIndex=${currPlayerDownsync.joinIndex} inAir & pushed back by barrier & not landed:
|
||||
{renderFrame.id: ${currRenderFrame.id}}
|
||||
playerColliderPos=${self.stringifyColliderCenterInWorld(playerCollider, halfColliderWidth, halfColliderHeight, topPadding, bottomPadding, leftPadding, rightPadding)}, effPushback={${effPushbacks[joinIndex - 1][0].toFixed(3)}, ${effPushbacks[joinIndex - 1][1].toFixed(3)}}, overlayMag=${result.overlap.toFixed(4)}, len(hardPushbackNorms)=${hardPushbackNorms.length}`);
|
||||
*/
|
||||
} else if (currPlayerDownsync.inAir && isAnotherPlayer) {
|
||||
console.warn(`playerId=${playerId}, joinIndex=${currPlayerDownsync.joinIndex} inAir and pushed back by another player
|
||||
{renderFrame.id: ${currRenderFrame.id}}
|
||||
playerColliderPos=${self.stringifyColliderCenterInWorld(playerCollider, halfColliderWidth, halfColliderHeight, topPadding, bottomPadding, leftPadding, rightPadding)}, anotherPlayerColliderPos=${self.stringifyColliderCenterInWorld(potential, halfColliderWidth, halfColliderHeight, topPadding, bottomPadding, leftPadding, rightPadding)}, effPushback={${effPushbacks[joinIndex - 1][0].toFixed(3)}, ${effPushbacks[joinIndex - 1][1].toFixed(3)}}, landedOnGravityPushback=${landedOnGravityPushback}, fallStopping=${fallStopping}, overlayMag=${result.overlap.toFixed(4)}, len(hardPushbackNorms)=${hardPushbackNorms.length}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (fallStopping) {
|
||||
thatPlayerInNextFrame.velX = 0;
|
||||
thatPlayerInNextFrame.velY = 0;
|
||||
thatPlayerInNextFrame.characterState = window.ATK_CHARACTER_STATE.Idle1[0];
|
||||
thatPlayerInNextFrame.framesToRecover = 0;
|
||||
}
|
||||
if (currPlayerDownsync.inAir) {
|
||||
thatPlayerInNextFrame.characterState = window.toInAirConjugate(thatPlayerInNextFrame.characterState);
|
||||
}
|
||||
}
|
||||
|
||||
// 6. Check bullet-anything collisions
|
||||
bulletColliders.forEach((bulletCollider, collisionBulletIndex) => {
|
||||
const potentials = bulletCollider.potentials();
|
||||
const offender = currRenderFrame.players[bulletCollider.data.offenderPlayerId];
|
||||
let shouldRemove = false;
|
||||
for (const potential of potentials) {
|
||||
if (null != potential.data && potential.data.joinIndex == bulletCollider.data.offenderJoinIndex) continue;
|
||||
if (!bulletCollider.collides(potential, result)) continue;
|
||||
if (null != potential.data && null != potential.data.joinIndex) {
|
||||
const playerId = potential.data.id;
|
||||
const joinIndex = potential.data.joinIndex;
|
||||
let xfac = 1;
|
||||
if (0 > offender.dirX) {
|
||||
xfac = -1;
|
||||
}
|
||||
// Only for straight punch, there's no y-pushback
|
||||
let bulletPushback = [-xfac * bulletCollider.data.pushback, 0];
|
||||
// console.log(`playerId=${playerId}, joinIndex=${joinIndex} is supposed to be pushed back by meleeBullet for bulletPushback=${JSON.stringify(bulletPushback)} at renderFrame.id=${currRenderFrame.id}`);
|
||||
for (let hardPushbackNorm of hardPushbackNorms[joinIndex - 1]) {
|
||||
const projectedMagnitude = bulletPushback[0] * hardPushbackNorm[0] + bulletPushback[1] * hardPushbackNorm[1];
|
||||
if (0 > projectedMagnitude) {
|
||||
// Otherwise when smashing into a wall the atked player would be pushed into the wall first and only got back in the next renderFrame, not what I want here
|
||||
bulletPushback[0] -= (projectedMagnitude * hardPushbackNorm[0]);
|
||||
bulletPushback[1] -= (projectedMagnitude * hardPushbackNorm[1]);
|
||||
// console.log(`playerId=${playerId}, joinIndex=${joinIndex} reducing bulletPushback=${JSON.stringify(bulletPushback)} by ${JSON.stringify([projectedMagnitude * hardPushbackNorm[0], projectedMagnitude * hardPushbackNorm[1]])} where hardPushbackNorm=${JSON.stringify(hardPushbackNorm)}, projectedMagnitude=${projectedMagnitude} at renderFrame.id=${currRenderFrame.id}`);
|
||||
}
|
||||
}
|
||||
// console.log(`playerId=${playerId}, joinIndex=${joinIndex} is actually pushed back by meleeBullet for bulletPushback=${JSON.stringify(bulletPushback)} at renderFrame.id=${currRenderFrame.id}`);
|
||||
effPushbacks[joinIndex - 1][0] += bulletPushback[0];
|
||||
effPushbacks[joinIndex - 1][1] += bulletPushback[1];
|
||||
const [atkedPlayerInCurFrame, atkedPlayerInNextFrame] = [currRenderFrame.players[potential.data.id], nextRenderFramePlayers[potential.data.id]];
|
||||
atkedPlayerInNextFrame.characterState = window.ATK_CHARACTER_STATE.Atked1[0];
|
||||
if (atkedPlayerInCurFrame.inAir) {
|
||||
atkedPlayerInNextFrame.characterState = window.toInAirConjugate(atkedPlayerInNextFrame.characterState);
|
||||
}
|
||||
const oldFramesToRecover = atkedPlayerInNextFrame.framesToRecover;
|
||||
atkedPlayerInNextFrame.framesToRecover = (oldFramesToRecover > bulletCollider.data.hitStunFrames ? oldFramesToRecover : bulletCollider.data.hitStunFrames); // In case the hit player is already stun, we extend it
|
||||
}
|
||||
shouldRemove = true;
|
||||
}
|
||||
if (shouldRemove) {
|
||||
removedBulletsAtCurrFrame.add(collisionBulletIndex);
|
||||
}
|
||||
});
|
||||
|
||||
// [WARNING] Remove bullets from collisionSys ANYWAY for the convenience of rollback
|
||||
for (let k in currRenderFrame.meleeBullets) {
|
||||
const meleeBullet = currRenderFrame.meleeBullets[k];
|
||||
const collisionBulletIndex = self.collisionBulletIndexPrefix + meleeBullet.battleLocalId;
|
||||
if (collisionSysMap.has(collisionBulletIndex)) {
|
||||
const bulletCollider = collisionSysMap.get(collisionBulletIndex);
|
||||
bulletCollider.remove();
|
||||
collisionSysMap.delete(collisionBulletIndex);
|
||||
}
|
||||
if (removedBulletsAtCurrFrame.has(collisionBulletIndex)) continue;
|
||||
nextRenderFrameMeleeBullets.push(meleeBullet);
|
||||
}
|
||||
|
||||
// 7. Get players out of stuck barriers if there's any
|
||||
for (let j in self.playerRichInfoArr) {
|
||||
const joinIndex = parseInt(j) + 1;
|
||||
const playerId = self.playerRichInfoArr[j].id;
|
||||
const collisionPlayerIndex = self.collisionPlayerIndexPrefix + joinIndex;
|
||||
const playerCollider = collisionSysMap.get(collisionPlayerIndex);
|
||||
// Update "virtual grid position"
|
||||
const currPlayerDownsync = currRenderFrame.players[playerId];
|
||||
const thatPlayerInNextFrame = nextRenderFramePlayers[playerId];
|
||||
const halfColliderWidth = self.playerRichInfoArr[j].colliderRadius,
|
||||
halfColliderHeight = self.playerRichInfoArr[j].colliderRadius + self.playerRichInfoArr[j].colliderRadius; // avoid multiplying
|
||||
const newVpos = self.polygonColliderBLToVirtualGridPos(playerCollider.x - effPushbacks[joinIndex - 1][0], playerCollider.y - effPushbacks[joinIndex - 1][1], halfColliderWidth, halfColliderHeight, topPadding, bottomPadding, leftPadding, rightPadding);
|
||||
thatPlayerInNextFrame.virtualGridX = newVpos[0];
|
||||
thatPlayerInNextFrame.virtualGridY = newVpos[1];
|
||||
|
||||
if (1 == thatPlayerInNextFrame.joinIndex) {
|
||||
if (currPlayerDownsync.inAir && !thatPlayerInNextFrame.inAir) {
|
||||
console.warn(`playerId=${playerId}, joinIndex=${thatPlayerInNextFrame.joinIndex} fallStopping#2:
|
||||
{nextRenderFrame.id: ${currRenderFrame.id + 1}, nextVirtualX: ${thatPlayerInNextFrame.virtualGridX}, nextVirtualY: ${thatPlayerInNextFrame.virtualGridY}, nextVelX: ${thatPlayerInNextFrame.velX}, nextVelY: ${thatPlayerInNextFrame.velY}}
|
||||
calculated from <- playerColliderPos=${self.stringifyColliderCenterInWorld(playerCollider, halfColliderWidth, halfColliderHeight, topPadding, bottomPadding, leftPadding, rightPadding)}, effPushback={${effPushbacks[joinIndex - 1][0].toFixed(3)}, ${effPushbacks[joinIndex - 1][1].toFixed(3)}}`);
|
||||
} else if (!currPlayerDownsync.inAir && thatPlayerInNextFrame.inAir) {
|
||||
console.warn(`playerId=${playerId}, joinIndex=${thatPlayerInNextFrame.joinIndex} took off:
|
||||
{nextRenderFrame.id: ${currRenderFrame.id + 1}, nextVirtualX: ${thatPlayerInNextFrame.virtualGridX}, nextVirtualY: ${thatPlayerInNextFrame.virtualGridY}, nextVelX: ${thatPlayerInNextFrame.velX}, nextVelY: ${thatPlayerInNextFrame.velY}}
|
||||
calculated from <- playerColliderPos=${self.stringifyColliderCenterInWorld(playerCollider, halfColliderWidth, halfColliderHeight, topPadding, bottomPadding, leftPadding, rightPadding)}, effPushback={${effPushbacks[joinIndex - 1][0].toFixed(3)}, ${effPushbacks[joinIndex - 1][1].toFixed(3)}}`);
|
||||
} else if (thatPlayerInNextFrame.inAir && 0 != thatPlayerInNextFrame.velY) {
|
||||
/*
|
||||
console.log(`playerId=${playerId}, joinIndex=${thatPlayerInNextFrame.joinIndex} inAir trajectory:
|
||||
{nextRenderFrame.id: ${currRenderFrame.id + 1}, nextVirtualX: ${thatPlayerInNextFrame.virtualGridX}, nextVirtualY: ${thatPlayerInNextFrame.virtualGridY}, nextVelX: ${thatPlayerInNextFrame.velX}, nextVelY: ${thatPlayerInNextFrame.velY}};
|
||||
calculated from <- playerColliderPos=${self.stringifyColliderCenterInWorld(playerCollider, halfColliderWidth, halfColliderHeight, topPadding, bottomPadding, leftPadding, rightPadding)}, effPushback={${effPushbacks[joinIndex - 1][0].toFixed(3)}, ${effPushbacks[joinIndex - 1][1].toFixed(3)}}`);
|
||||
*/
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return window.pb.protos.RoomDownsyncFrame.create({
|
||||
id: currRenderFrame.id + 1,
|
||||
players: nextRenderFramePlayers,
|
||||
meleeBullets: nextRenderFrameMeleeBullets,
|
||||
});
|
||||
},
|
||||
|
||||
rollbackAndChase(renderFrameIdSt, renderFrameIdEd, collisionSys, collisionSysMap, isChasing) {
|
||||
/*
|
||||
This function eventually calculates a "RoomDownsyncFrame" where "RoomDownsyncFrame.id == renderFrameIdEd" if not interruptted.
|
||||
*/
|
||||
const self = this;
|
||||
let prevLatestRdf = null,
|
||||
latestRdf = null;
|
||||
@ -1522,7 +1097,10 @@ playerColliderPos=${self.stringifyColliderCenterInWorld(playerCollider, halfColl
|
||||
// Shouldn't happen!
|
||||
throw `Failed to get cached delayedInputFrame for i=${i}, j=${j}, renderFrameId=${self.renderFrameId}, lastUpsyncInputFrameId=${self.lastUpsyncInputFrameId}, lastAllConfirmedInputFrameId=${self.lastAllConfirmedInputFrameId}, chaserRenderFrameId=${self.chaserRenderFrameId}; recentRenderCache=${self._stringifyRecentRenderCache(false)}, recentInputCache=${self._stringifyRecentInputCache(false)}`;
|
||||
}
|
||||
const nextRdf = self.applyInputFrameDownsyncDynamicsOnSingleRenderFrame(delayedInputFrame, currRdf, collisionSys, collisionSysMap);
|
||||
|
||||
const jPrev = self._convertToInputFrameId(i - 1, self.inputDelayFrames);
|
||||
const delayedInputFrameForPrevRenderFrame = self.recentInputCache.getByFrameId(jPrev);
|
||||
const nextRdf = gopkgs.ApplyInputFrameDownsyncDynamicsOnSingleRenderFrameJs(delayedInputFrame.inputList, (null == delayedInputFrameForPrevRenderFrame ? null : delayedInputFrameForPrevRenderFrame.inputList), currRdf, collisionSys, collisionSysMap, self.gravityX, self.gravityY, self.jumpingInitVelY, self.inputDelayFrames, self.inputScaleFrames, self.spaceOffsetX, self.spaceOffsetY, self.snapIntoPlatformOverlap, self.snapIntoPlatformThreshold, self.worldToVirtualGridRatio, self.virtualGridToWorldRatio);
|
||||
|
||||
if (true == isChasing) {
|
||||
// [WARNING] Move the cursor "self.chaserRenderFrameId" when "true == isChasing", keep in mind that "self.chaserRenderFrameId" is not monotonic!
|
||||
@ -1538,29 +1116,32 @@ playerColliderPos=${self.stringifyColliderCenterInWorld(playerCollider, halfColl
|
||||
return [prevLatestRdf, latestRdf];
|
||||
},
|
||||
|
||||
_initPlayerRichInfoDict(players) {
|
||||
_initPlayerRichInfoDict(playersArr) {
|
||||
const self = this;
|
||||
for (let k in players) {
|
||||
const playerId = parseInt(k);
|
||||
for (let k in playersArr) {
|
||||
const immediatePlayerInfo = playersArr[k];
|
||||
const playerId = immediatePlayerInfo.id || immediatePlayerInfo.Id;
|
||||
if (self.playerRichInfoDict.has(playerId)) continue; // Skip already put keys
|
||||
const immediatePlayerInfo = players[playerId];
|
||||
self.playerRichInfoDict.set(playerId, immediatePlayerInfo);
|
||||
|
||||
const nodeAndScriptIns = self.spawnPlayerNode(immediatePlayerInfo.joinIndex, immediatePlayerInfo.virtualGridX, immediatePlayerInfo.virtualGridY, immediatePlayerInfo);
|
||||
const joinIndex = immediatePlayerInfo.joinIndex || immediatePlayerInfo.JoinIndex;
|
||||
const vx = immediatePlayerInfo.virtualGridX || immediatePlayerInfo.VirtualGridX;
|
||||
const vy = immediatePlayerInfo.virtualGridY || immediatePlayerInfo.VirtualGridY;
|
||||
const nodeAndScriptIns = self.spawnPlayerNode(joinIndex, vx, vy, immediatePlayerInfo);
|
||||
|
||||
Object.assign(self.playerRichInfoDict.get(playerId), {
|
||||
node: nodeAndScriptIns[0],
|
||||
scriptIns: nodeAndScriptIns[1],
|
||||
});
|
||||
|
||||
if (self.selfPlayerInfo.id == playerId) {
|
||||
self.selfPlayerInfo = Object.assign(self.selfPlayerInfo, immediatePlayerInfo);
|
||||
const selfPlayerId = self.selfPlayerInfo.id || self.selfPlayerInfo.Id;
|
||||
if (selfPlayerId == playerId) {
|
||||
self.selfPlayerInfo.joinIndex = immediatePlayerInfo.joinIndex || immediatePlayerInfo.JoinIndex;
|
||||
nodeAndScriptIns[1].showArrowTipNode();
|
||||
}
|
||||
}
|
||||
self.playerRichInfoArr = new Array(self.playerRichInfoDict.size);
|
||||
self.playerRichInfoDict.forEach((playerRichInfo, playerId) => {
|
||||
self.playerRichInfoArr[playerRichInfo.joinIndex - 1] = playerRichInfo;
|
||||
self.playerRichInfoArr[playerRichInfo.JoinIndex - 1] = playerRichInfo;
|
||||
});
|
||||
},
|
||||
|
||||
@ -1606,13 +1187,8 @@ playerColliderPos=${self.stringifyColliderCenterInWorld(playerCollider, halfColl
|
||||
return s.join('\n');
|
||||
},
|
||||
|
||||
worldToVirtualGridPos(x, y) {
|
||||
// [WARNING] Introduces loss of precision!
|
||||
const self = this;
|
||||
// In JavaScript floating numbers suffer from seemingly non-deterministic arithmetics, and even if certain libs solved this issue by approaches such as fixed-point-number, they might not be used in other libs -- e.g. the "collision libs" we're interested in -- thus couldn't kill all pains.
|
||||
let virtualGridX = Math.round(x * self.worldToVirtualGridRatio);
|
||||
let virtualGridY = Math.round(y * self.worldToVirtualGridRatio);
|
||||
return [virtualGridX, virtualGridY];
|
||||
stringifyColliderCenterInWorld(playerCollider, halfBoundingW, halfBoundingH, topPadding, bottomPadding, leftPadding, rightPadding) {
|
||||
return `{${(playerCollider.x + leftPadding + halfBoundingW).toFixed(2)}, ${(playerCollider.y + bottomPadding + halfBoundingH).toFixed(2)}}`;
|
||||
},
|
||||
|
||||
virtualGridToWorldPos(vx, vy) {
|
||||
@ -1621,44 +1197,44 @@ playerColliderPos=${self.stringifyColliderCenterInWorld(playerCollider, halfColl
|
||||
return [vx * self.virtualGridToWorldRatio, vy * self.virtualGridToWorldRatio];
|
||||
},
|
||||
|
||||
worldToPolygonColliderBLPos(wx, wy, halfBoundingW, halfBoundingH, topPadding, bottomPadding, leftPadding, rightPadding) {
|
||||
return [wx - halfBoundingW - leftPadding, wy - halfBoundingH - bottomPadding];
|
||||
},
|
||||
|
||||
polygonColliderBLToWorldPos(cx, cy, halfBoundingW, halfBoundingH, topPadding, bottomPadding, leftPadding, rightPadding) {
|
||||
return [cx + halfBoundingW + leftPadding, cy + halfBoundingH + bottomPadding];
|
||||
},
|
||||
|
||||
polygonColliderBLToVirtualGridPos(cx, cy, halfBoundingW, halfBoundingH, topPadding, bottomPadding, leftPadding, rightPadding) {
|
||||
showDebugBoundaries(rdf) {
|
||||
const self = this;
|
||||
const [wx, wy] = self.polygonColliderBLToWorldPos(cx, cy, halfBoundingW, halfBoundingH, topPadding, bottomPadding, leftPadding, rightPadding);
|
||||
return self.worldToVirtualGridPos(wx, wy)
|
||||
},
|
||||
const leftPadding = self.snapIntoPlatformOverlap,
|
||||
rightPadding = self.snapIntoPlatformOverlap,
|
||||
topPadding = self.snapIntoPlatformOverlap,
|
||||
bottomPadding = self.snapIntoPlatformOverlap;
|
||||
if (self.showCriticalCoordinateLabels) {
|
||||
let g = self.g;
|
||||
g.clear();
|
||||
|
||||
virtualGridToPolygonColliderBLPos(vx, vy, halfBoundingW, halfBoundingH, topPadding, bottomPadding, leftPadding, rightPadding) {
|
||||
const self = this;
|
||||
const [wx, wy] = self.virtualGridToWorldPos(vx, vy);
|
||||
return self.worldToPolygonColliderBLPos(wx, wy, halfBoundingW, halfBoundingH, topPadding, bottomPadding, leftPadding, rightPadding)
|
||||
},
|
||||
|
||||
stringifyColliderCenterInWorld(playerCollider, halfBoundingW, halfBoundingH, topPadding, bottomPadding, leftPadding, rightPadding) {
|
||||
return `{${(playerCollider.x + leftPadding + halfBoundingW).toFixed(2)}, ${(playerCollider.y + bottomPadding + halfBoundingH).toFixed(2)}}`;
|
||||
},
|
||||
|
||||
calcHardPushbacksNorms(collider, potentials, result, snapIntoPlatformOverlap, effPushback) {
|
||||
const self = this;
|
||||
let ret = [];
|
||||
for (const potential of potentials) {
|
||||
if (null == potential.data || !(true == potential.data.hardPushback)) continue;
|
||||
if (!collider.collides(potential, result)) continue;
|
||||
// ALWAY snap into hardPushbacks!
|
||||
// [overlay_x, overlap_y] is the unit vector that points into the platform
|
||||
const pushback = [(result.overlap - snapIntoPlatformOverlap) * result.overlap_x, (result.overlap - snapIntoPlatformOverlap) * result.overlap_y];
|
||||
ret.push([result.overlap_x, result.overlap_y]);
|
||||
effPushback[0] += pushback[0];
|
||||
effPushback[1] += pushback[1];
|
||||
const collisionSpaceObjs = gopkgs.GetCollisionSpaceObjsJs(self.gopkgsCollisionSys);
|
||||
for (let k in collisionSpaceObjs) {
|
||||
const body = collisionSpaceObjs[k];
|
||||
let padding = 0;
|
||||
if (null != body.Data && null != body.Data.JoinIndex) {
|
||||
// character
|
||||
if (1 == body.Data.JoinIndex) {
|
||||
g.strokeColor = cc.Color.BLUE;
|
||||
} else {
|
||||
g.strokeColor = cc.Color.RED;
|
||||
}
|
||||
padding = self.snapIntoPlatformOverlap;
|
||||
} else {
|
||||
// barrier
|
||||
g.strokeColor = cc.Color.WHITE;
|
||||
}
|
||||
const points = body.Shape.Points;
|
||||
const wpos = [body.X - self.spaceOffsetX, body.Y - self.spaceOffsetY];
|
||||
g.moveTo(wpos[0], wpos[1]);
|
||||
const cnt = points.length;
|
||||
for (let j = 0; j < cnt; j += 1) {
|
||||
const x = wpos[0] + points[j][0],
|
||||
y = wpos[1] + points[j][1];
|
||||
g.lineTo(x, y);
|
||||
}
|
||||
g.lineTo(wpos[0], wpos[1]);
|
||||
g.stroke();
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
},
|
||||
});
|
||||
|
@ -31,6 +31,7 @@ cc.Class({
|
||||
self.inputDelayFrames = 8;
|
||||
self.inputScaleFrames = 2;
|
||||
self.inputFrameUpsyncDelayTolerance = 2;
|
||||
self.collisionMinStep = 8;
|
||||
|
||||
self.renderCacheSize = 1024;
|
||||
self.serverFps = 60;
|
||||
@ -101,15 +102,12 @@ cc.Class({
|
||||
self.node.setContentSize(newMapSize.width * newTileSize.width, newMapSize.height * newTileSize.height);
|
||||
self.node.setPosition(cc.v2(0, 0));
|
||||
|
||||
self._resetCurrentMatch();
|
||||
const spaceW = newMapSize.width * newTileSize.width;
|
||||
const spaceH = newMapSize.height * newTileSize.height;
|
||||
self.spaceOffsetX = (spaceW >> 1);
|
||||
self.spaceOffsetY = (spaceH >> 1);
|
||||
const minStep = 8;
|
||||
self.gopkgsCollisionSys = gopkgs.NewCollisionSpaceJs(spaceW, spaceH, minStep, minStep);
|
||||
self.gopkgsCollisionSysMap = {}; // [WARNING] Don't use "JavaScript Map" which could cause loss of type information when passing through Golang transpiled functions!
|
||||
self.stageDiscreteW = newMapSize.width;
|
||||
self.stageDiscreteH = newMapSize.height;
|
||||
self.stageTileW = newTileSize.width;
|
||||
self.stageTileH = newTileSize.height;
|
||||
|
||||
self._resetCurrentMatch();
|
||||
let barrierIdCounter = 0;
|
||||
const boundaryObjs = tileCollisionManager.extractBoundaryObjects(self.node);
|
||||
for (let boundaryObj of boundaryObjs.barriers) {
|
||||
@ -160,11 +158,41 @@ cc.Class({
|
||||
self.gopkgsCollisionSysMap[collisionBarrierIndex] = newBarrierCollider;
|
||||
}
|
||||
|
||||
const startPlayer1 = gopkgs.NewPlayerDownsyncJs(10, self.worldToVirtualGridPos(boundaryObjs.playerStartingPositions[0].x, boundaryObjs.playerStartingPositions[0].y)[0], self.worldToVirtualGridPos(boundaryObjs.playerStartingPositions[0].x, boundaryObjs.playerStartingPositions[0].y)[1], 0, 0, 0, 0, 1 * self.worldToVirtualGridRatio, 0, window.ATK_CHARACTER_STATE.InAirIdle1[0], 1, 100, 100, true, 12);
|
||||
|
||||
const startPlayer2 = gopkgs.NewPlayerDownsyncJs(11, self.worldToVirtualGridPos(boundaryObjs.playerStartingPositions[1].x, boundaryObjs.playerStartingPositions[1].y)[0], self.worldToVirtualGridPos(boundaryObjs.playerStartingPositions[1].x, boundaryObjs.playerStartingPositions[1].y)[1], 0, 0, 0, 0, 1 * self.worldToVirtualGridRatio, 0, window.ATK_CHARACTER_STATE.InAirIdle1[0], 2, 100, 100, true, 12);
|
||||
|
||||
const startRdf = gopkgs.NewRoomDownsyncFrameJs(window.MAGIC_ROOM_DOWNSYNC_FRAME_ID.BATTLE_START, [startPlayer1, startPlayer2], []);
|
||||
const startRdf = window.pb.protos.RoomDownsyncFrame.create({
|
||||
id: window.MAGIC_ROOM_DOWNSYNC_FRAME_ID.BATTLE_START,
|
||||
playersArr: [
|
||||
window.pb.protos.PlayerDownsync.create({
|
||||
id: 10,
|
||||
joinIndex: 1,
|
||||
virtualGridX: boundaryObjs.playerStartingPositions[0].x * self.worldToVirtualGridRatio,
|
||||
virtualGridY: boundaryObjs.playerStartingPositions[0].y * self.worldToVirtualGridRatio,
|
||||
speed: 1 * self.worldToVirtualGridRatio,
|
||||
colliderRadius: 12,
|
||||
characterState: window.ATK_CHARACTER_STATE.InAirIdle1[0],
|
||||
framesToRecover: 0,
|
||||
dirX: 0,
|
||||
dirY: 0,
|
||||
velX: 0,
|
||||
velY: 0,
|
||||
inAir: true,
|
||||
}),
|
||||
window.pb.protos.PlayerDownsync.create({
|
||||
id: 11,
|
||||
joinIndex: 2,
|
||||
virtualGridX: boundaryObjs.playerStartingPositions[1].x * self.worldToVirtualGridRatio,
|
||||
virtualGridY: boundaryObjs.playerStartingPositions[1].y * self.worldToVirtualGridRatio,
|
||||
speed: 1 * self.worldToVirtualGridRatio,
|
||||
colliderRadius: 12,
|
||||
characterState: window.ATK_CHARACTER_STATE.InAirIdle1[0],
|
||||
framesToRecover: 0,
|
||||
dirX: 0,
|
||||
dirY: 0,
|
||||
velX: 0,
|
||||
velY: 0,
|
||||
inAir: true,
|
||||
}),
|
||||
]
|
||||
});
|
||||
|
||||
self.selfPlayerInfo = {
|
||||
Id: 11,
|
||||
@ -212,231 +240,4 @@ cc.Class({
|
||||
}
|
||||
},
|
||||
|
||||
onRoomDownsyncFrame(rdf, accompaniedInputFrameDownsyncBatch) {
|
||||
// This function is also applicable to "re-joining".
|
||||
const self = window.mapIns;
|
||||
self.onInputFrameDownsyncBatch(accompaniedInputFrameDownsyncBatch); // Important to do this step before setting IN_BATTLE
|
||||
if (!self.recentRenderCache) {
|
||||
return;
|
||||
}
|
||||
if (ALL_BATTLE_STATES.IN_SETTLEMENT == self.battleState) {
|
||||
return;
|
||||
}
|
||||
const shouldForceDumping1 = (window.MAGIC_ROOM_DOWNSYNC_FRAME_ID.BATTLE_START == rdf.Id);
|
||||
let shouldForceDumping2 = (rdf.Id >= self.renderFrameId + self.renderFrameIdLagTolerance);
|
||||
let shouldForceResync = rdf.ShouldForceResync;
|
||||
const notSelfUnconfirmed = (0 == (rdf.BackendUnconfirmedMask & (1 << (self.selfPlayerInfo.joinIndex - 1))));
|
||||
if (notSelfUnconfirmed) {
|
||||
shouldForceDumping2 = false;
|
||||
shouldForceResync = false;
|
||||
self.othersForcedDownsyncRenderFrameDict.set(rdf.Id, rdf);
|
||||
}
|
||||
/*
|
||||
TODO
|
||||
|
||||
If "BackendUnconfirmedMask" is non-all-1 and contains the current player, show a label/button to hint manual reconnection. Note that the continuity of "recentInputCache" is not a good indicator, because due to network delay upon a [type#1 forceConfirmation] a player might just lag in upsync networking and have all consecutive inputFrameIds locally.
|
||||
*/
|
||||
|
||||
const [dumpRenderCacheRet, oldStRenderFrameId, oldEdRenderFrameId] = (shouldForceDumping1 || shouldForceDumping2 || shouldForceResync) ? self.recentRenderCache.setByFrameId(rdf, rdf.id) : [window.RING_BUFF_CONSECUTIVE_SET, null, null];
|
||||
if (window.RING_BUFF_FAILED_TO_SET == dumpRenderCacheRet) {
|
||||
throw `Failed to dump render cache#1 (maybe recentRenderCache too small)! rdf.id=${rdf.id}, lastAllConfirmedInputFrameId=${self.lastAllConfirmedInputFrameId}; recentRenderCache=${self._stringifyRecentRenderCache(false)}, recentInputCache=${self._stringifyRecentInputCache(false)}`;
|
||||
}
|
||||
if (!shouldForceResync && (window.MAGIC_ROOM_DOWNSYNC_FRAME_ID.BATTLE_START < rdf.id && window.RING_BUFF_CONSECUTIVE_SET == dumpRenderCacheRet)) {
|
||||
/*
|
||||
Don't change
|
||||
- chaserRenderFrameId, it's updated only in "rollbackAndChase & onInputFrameDownsyncBatch" (except for when RING_BUFF_NON_CONSECUTIVE_SET)
|
||||
*/
|
||||
return dumpRenderCacheRet;
|
||||
}
|
||||
|
||||
// The logic below applies to (window.MAGIC_ROOM_DOWNSYNC_FRAME_ID.BATTLE_START == rdf.id || window.RING_BUFF_NON_CONSECUTIVE_SET == dumpRenderCacheRet)
|
||||
self._initPlayerRichInfoDict(rdf.PlayersArr);
|
||||
|
||||
if (shouldForceDumping1 || shouldForceDumping2 || shouldForceResync) {
|
||||
// In fact, not having "window.RING_BUFF_CONSECUTIVE_SET == dumpRenderCacheRet" should already imply that "self.renderFrameId <= rdf.id", but here we double check and log the anomaly
|
||||
|
||||
if (window.MAGIC_ROOM_DOWNSYNC_FRAME_ID.BATTLE_START == rdf.Id) {
|
||||
console.log('On battle started! renderFrameId=', rdf.Id);
|
||||
}
|
||||
self.renderFrameId = rdf.Id;
|
||||
self.lastRenderFrameIdTriggeredAt = performance.now();
|
||||
// In this case it must be true that "rdf.id > chaserRenderFrameId".
|
||||
self.chaserRenderFrameId = rdf.Id;
|
||||
|
||||
const canvasNode = self.canvasNode;
|
||||
self.ctrl = canvasNode.getComponent("TouchEventsManager");
|
||||
self.enableInputControls();
|
||||
self.transitToState(ALL_MAP_STATES.VISUAL);
|
||||
self.battleState = ALL_BATTLE_STATES.IN_BATTLE;
|
||||
}
|
||||
// [WARNING] Leave all graphical updates in "update(dt)" by "applyRoomDownsyncFrameDynamics"
|
||||
return dumpRenderCacheRet;
|
||||
},
|
||||
|
||||
rollbackAndChase(renderFrameIdSt, renderFrameIdEd, collisionSys, collisionSysMap, isChasing) {
|
||||
const self = this;
|
||||
let prevLatestRdf = null,
|
||||
latestRdf = null;
|
||||
for (let i = renderFrameIdSt; i < renderFrameIdEd; i++) {
|
||||
const currRdf = self.recentRenderCache.getByFrameId(i); // typed "RoomDownsyncFrame"; [WARNING] When "true == isChasing" and using Firefox, this function could be interruptted by "onRoomDownsyncFrame(rdf)" asynchronously anytime, making this line return "null"!
|
||||
if (null == currRdf) {
|
||||
throw `Couldn't find renderFrame for i=${i} to rollback (are you using Firefox?), self.renderFrameId=${self.renderFrameId}, lastAllConfirmedInputFrameId=${self.lastAllConfirmedInputFrameId}, might've been interruptted by onRoomDownsyncFrame`;
|
||||
}
|
||||
const j = self._convertToInputFrameId(i, self.inputDelayFrames);
|
||||
const delayedInputFrame = self.recentInputCache.getByFrameId(j); // Don't make prediction here, the inputFrameDownsyncs in recentInputCache was already predicted while prefabbing
|
||||
if (null == delayedInputFrame) {
|
||||
// Shouldn't happen!
|
||||
throw `Failed to get cached delayedInputFrame for i=${i}, j=${j}, renderFrameId=${self.renderFrameId}, lastUpsyncInputFrameId=${self.lastUpsyncInputFrameId}, lastAllConfirmedInputFrameId=${self.lastAllConfirmedInputFrameId}, chaserRenderFrameId=${self.chaserRenderFrameId}; recentRenderCache=${self._stringifyRecentRenderCache(false)}, recentInputCache=${self._stringifyRecentInputCache(false)}`;
|
||||
}
|
||||
|
||||
const jPrev = self._convertToInputFrameId(i - 1, self.inputDelayFrames);
|
||||
const delayedInputFrameForPrevRenderFrame = self.recentInputCache.getByFrameId(jPrev);
|
||||
const nextRdf = gopkgs.ApplyInputFrameDownsyncDynamicsOnSingleRenderFrameJs(delayedInputFrame.inputList, (null == delayedInputFrameForPrevRenderFrame ? null : delayedInputFrameForPrevRenderFrame.inputList), currRdf, collisionSys, collisionSysMap, self.gravityX, self.gravityY, self.jumpingInitVelY, self.inputDelayFrames, self.inputScaleFrames, self.spaceOffsetX, self.spaceOffsetY, self.snapIntoPlatformOverlap, self.snapIntoPlatformThreshold, self.worldToVirtualGridRatio, self.virtualGridToWorldRatio);
|
||||
|
||||
if (true == isChasing) {
|
||||
// [WARNING] Move the cursor "self.chaserRenderFrameId" when "true == isChasing", keep in mind that "self.chaserRenderFrameId" is not monotonic!
|
||||
self.chaserRenderFrameId = nextRdf.id;
|
||||
} else if (nextRdf.id == self.chaserRenderFrameId + 1) {
|
||||
self.chaserRenderFrameId = nextRdf.id; // To avoid redundant calculation
|
||||
}
|
||||
self.recentRenderCache.setByFrameId(nextRdf, nextRdf.id);
|
||||
prevLatestRdf = currRdf;
|
||||
latestRdf = nextRdf;
|
||||
}
|
||||
|
||||
return [prevLatestRdf, latestRdf];
|
||||
},
|
||||
|
||||
_initPlayerRichInfoDict(playersArr) {
|
||||
const self = this;
|
||||
for (let k in playersArr) {
|
||||
const immediatePlayerInfo = playersArr[k];
|
||||
const playerId = immediatePlayerInfo.Id;
|
||||
if (self.playerRichInfoDict.has(playerId)) continue; // Skip already put keys
|
||||
self.playerRichInfoDict.set(playerId, immediatePlayerInfo);
|
||||
|
||||
const nodeAndScriptIns = self.spawnPlayerNode(immediatePlayerInfo.JoinIndex, immediatePlayerInfo.VirtualGridX, immediatePlayerInfo.VirtualGridY, immediatePlayerInfo);
|
||||
|
||||
Object.assign(self.playerRichInfoDict.get(playerId), {
|
||||
node: nodeAndScriptIns[0],
|
||||
scriptIns: nodeAndScriptIns[1],
|
||||
});
|
||||
|
||||
if (self.selfPlayerInfo.Id == playerId) {
|
||||
self.selfPlayerInfo = Object.assign(self.selfPlayerInfo, immediatePlayerInfo);
|
||||
nodeAndScriptIns[1].showArrowTipNode();
|
||||
}
|
||||
}
|
||||
self.playerRichInfoArr = new Array(self.playerRichInfoDict.size);
|
||||
self.playerRichInfoDict.forEach((playerRichInfo, playerId) => {
|
||||
self.playerRichInfoArr[playerRichInfo.JoinIndex - 1] = playerRichInfo;
|
||||
});
|
||||
},
|
||||
|
||||
applyRoomDownsyncFrameDynamics(rdf, prevRdf) {
|
||||
const self = this;
|
||||
const playersArr = rdf.PlayersArr;
|
||||
for (let k in playersArr) {
|
||||
const currPlayerDownsync = playersArr[k];
|
||||
const prevRdfPlayer = (null == prevRdf ? null : prevRdf.PlayersArr[k]);
|
||||
const [wx, wy] = self.virtualGridToWorldPos(currPlayerDownsync.VirtualGridX, currPlayerDownsync.VirtualGridY);
|
||||
const playerRichInfo = self.playerRichInfoArr[k];
|
||||
playerRichInfo.node.setPosition(wx, wy);
|
||||
playerRichInfo.scriptIns.updateSpeed(currPlayerDownsync.Speed);
|
||||
currPlayerDownsync.characterState = currPlayerDownsync.CharacterState;
|
||||
currPlayerDownsync.dirX = currPlayerDownsync.DirX;
|
||||
currPlayerDownsync.dirY = currPlayerDownsync.DirY;
|
||||
currPlayerDownsync.framesToRecover = currPlayerDownsync.FrameToRecover;
|
||||
playerRichInfo.scriptIns.updateCharacterAnim(currPlayerDownsync, prevRdfPlayer, false);
|
||||
}
|
||||
},
|
||||
|
||||
spawnPlayerNode(joinIndex, vx, vy, playerDownsyncInfo) {
|
||||
const self = this;
|
||||
const newPlayerNode = cc.instantiate(self.controlledCharacterPrefab)
|
||||
const playerScriptIns = newPlayerNode.getComponent("ControlledCharacter");
|
||||
if (1 == joinIndex) {
|
||||
playerScriptIns.setSpecies("SoldierWaterGhost");
|
||||
} else if (2 == joinIndex) {
|
||||
playerScriptIns.setSpecies("UltramanTiga");
|
||||
}
|
||||
|
||||
const [wx, wy] = self.virtualGridToWorldPos(vx, vy);
|
||||
newPlayerNode.setPosition(wx, wy);
|
||||
playerScriptIns.mapNode = self.node;
|
||||
const halfColliderWidth = playerDownsyncInfo.ColliderRadius,
|
||||
halfColliderHeight = playerDownsyncInfo.ColliderRadius + playerDownsyncInfo.ColliderRadius; // avoid multiplying
|
||||
const colliderWidth = halfColliderWidth + halfColliderWidth,
|
||||
colliderHeight = halfColliderHeight + halfColliderHeight; // avoid multiplying
|
||||
|
||||
const [cx, cy] = gopkgs.WorldToPolygonColliderBLPos(wx, wy, halfColliderWidth, halfColliderHeight, self.snapIntoPlatformOverlap, self.snapIntoPlatformOverlap, self.snapIntoPlatformOverlap, self.snapIntoPlatformOverlap, self.spaceOffsetX, self.spaceOffsetY);
|
||||
const gopkgsBoundaryAnchor = gopkgs.NewVec2DJs(cx, cy);
|
||||
const gopkgsBoundaryPts = [
|
||||
gopkgs.NewVec2DJs(0, 0),
|
||||
gopkgs.NewVec2DJs(self.snapIntoPlatformOverlap + colliderWidth + self.snapIntoPlatformOverlap, 0),
|
||||
gopkgs.NewVec2DJs(self.snapIntoPlatformOverlap + colliderWidth + self.snapIntoPlatformOverlap, self.snapIntoPlatformOverlap + colliderHeight + self.snapIntoPlatformOverlap),
|
||||
gopkgs.NewVec2DJs(0, self.snapIntoPlatformOverlap + colliderHeight + self.snapIntoPlatformOverlap)
|
||||
];
|
||||
const gopkgsBoundary = gopkgs.NewPolygon2DJs(gopkgsBoundaryAnchor, gopkgsBoundaryPts);
|
||||
const newPlayerCollider = gopkgs.GenerateConvexPolygonColliderJs(gopkgsBoundary, self.spaceOffsetX, self.spaceOffsetY, playerDownsyncInfo, "Player");
|
||||
//const newPlayerCollider = gopkgs.GenerateRectColliderJs(wx, wy, colliderWidth, colliderHeight, self.snapIntoPlatformOverlap, self.snapIntoPlatformOverlap, self.snapIntoPlatformOverlap, self.snapIntoPlatformOverlap, self.spaceOffsetX, self.spaceOffsetY, playerDownsyncInfo, "Player");
|
||||
self.gopkgsCollisionSys.Add(newPlayerCollider);
|
||||
const collisionPlayerIndex = self.collisionPlayerIndexPrefix + joinIndex;
|
||||
self.gopkgsCollisionSysMap[collisionPlayerIndex] = newPlayerCollider;
|
||||
|
||||
console.log(`Created new player collider: joinIndex=${joinIndex}, colliderRadius=${playerDownsyncInfo.ColliderRadius}`);
|
||||
|
||||
safelyAddChild(self.node, newPlayerNode);
|
||||
setLocalZOrder(newPlayerNode, 5);
|
||||
|
||||
newPlayerNode.active = true;
|
||||
playerDownsyncInfo.characterState = playerDownsyncInfo.CharacterState;
|
||||
playerDownsyncInfo.dirX = playerDownsyncInfo.DirX;
|
||||
playerDownsyncInfo.dirY = playerDownsyncInfo.DirY;
|
||||
playerDownsyncInfo.framesToRecover = playerDownsyncInfo.FrameToRecover;
|
||||
playerScriptIns.updateCharacterAnim(playerDownsyncInfo, null, true);
|
||||
|
||||
return [newPlayerNode, playerScriptIns];
|
||||
},
|
||||
|
||||
showDebugBoundaries(rdf) {
|
||||
const self = this;
|
||||
const leftPadding = self.snapIntoPlatformOverlap,
|
||||
rightPadding = self.snapIntoPlatformOverlap,
|
||||
topPadding = self.snapIntoPlatformOverlap,
|
||||
bottomPadding = self.snapIntoPlatformOverlap;
|
||||
if (self.showCriticalCoordinateLabels) {
|
||||
let g = self.g;
|
||||
g.clear();
|
||||
|
||||
const collisionSpaceObjs = gopkgs.GetCollisionSpaceObjsJs(self.gopkgsCollisionSys);
|
||||
for (let k in collisionSpaceObjs) {
|
||||
const body = collisionSpaceObjs[k];
|
||||
let padding = 0;
|
||||
if (null != body.Data && null != body.Data.JoinIndex) {
|
||||
// character
|
||||
if (1 == body.Data.JoinIndex) {
|
||||
g.strokeColor = cc.Color.BLUE;
|
||||
} else {
|
||||
g.strokeColor = cc.Color.RED;
|
||||
}
|
||||
padding = self.snapIntoPlatformOverlap;
|
||||
} else {
|
||||
// barrier
|
||||
g.strokeColor = cc.Color.WHITE;
|
||||
}
|
||||
const points = body.Shape.Points;
|
||||
const wpos = [body.X-self.spaceOffsetX, body.Y-self.spaceOffsetY];
|
||||
g.moveTo(wpos[0], wpos[1]);
|
||||
const cnt = points.length;
|
||||
for (let j = 0; j < cnt; j += 1) {
|
||||
const x = wpos[0]+points[j][0],
|
||||
y = wpos[1]+points[j][1];
|
||||
g.lineTo(x, y);
|
||||
}
|
||||
g.lineTo(wpos[0], wpos[1]);
|
||||
g.stroke();
|
||||
}
|
||||
}
|
||||
},
|
||||
});
|
||||
|
@ -4607,6 +4607,7 @@ $root.protos = (function() {
|
||||
* @property {number|null} [jumpingInitVelY] BattleColliderInfo jumpingInitVelY
|
||||
* @property {number|null} [gravityX] BattleColliderInfo gravityX
|
||||
* @property {number|null} [gravityY] BattleColliderInfo gravityY
|
||||
* @property {number|null} [collisionMinStep] BattleColliderInfo collisionMinStep
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -4857,6 +4858,14 @@ $root.protos = (function() {
|
||||
*/
|
||||
BattleColliderInfo.prototype.gravityY = 0;
|
||||
|
||||
/**
|
||||
* BattleColliderInfo collisionMinStep.
|
||||
* @member {number} collisionMinStep
|
||||
* @memberof protos.BattleColliderInfo
|
||||
* @instance
|
||||
*/
|
||||
BattleColliderInfo.prototype.collisionMinStep = 0;
|
||||
|
||||
/**
|
||||
* Creates a new BattleColliderInfo instance using the specified properties.
|
||||
* @function create
|
||||
@ -4942,6 +4951,8 @@ $root.protos = (function() {
|
||||
writer.uint32(/* id 28, wireType 0 =*/224).int32(message.gravityX);
|
||||
if (message.gravityY != null && Object.hasOwnProperty.call(message, "gravityY"))
|
||||
writer.uint32(/* id 29, wireType 0 =*/232).int32(message.gravityY);
|
||||
if (message.collisionMinStep != null && Object.hasOwnProperty.call(message, "collisionMinStep"))
|
||||
writer.uint32(/* id 30, wireType 0 =*/240).int32(message.collisionMinStep);
|
||||
return writer;
|
||||
};
|
||||
|
||||
@ -5111,6 +5122,10 @@ $root.protos = (function() {
|
||||
message.gravityY = reader.int32();
|
||||
break;
|
||||
}
|
||||
case 30: {
|
||||
message.collisionMinStep = reader.int32();
|
||||
break;
|
||||
}
|
||||
default:
|
||||
reader.skipType(tag & 7);
|
||||
break;
|
||||
@ -5244,6 +5259,9 @@ $root.protos = (function() {
|
||||
if (message.gravityY != null && message.hasOwnProperty("gravityY"))
|
||||
if (!$util.isInteger(message.gravityY))
|
||||
return "gravityY: integer expected";
|
||||
if (message.collisionMinStep != null && message.hasOwnProperty("collisionMinStep"))
|
||||
if (!$util.isInteger(message.collisionMinStep))
|
||||
return "collisionMinStep: integer expected";
|
||||
return null;
|
||||
};
|
||||
|
||||
@ -5339,6 +5357,8 @@ $root.protos = (function() {
|
||||
message.gravityX = object.gravityX | 0;
|
||||
if (object.gravityY != null)
|
||||
message.gravityY = object.gravityY | 0;
|
||||
if (object.collisionMinStep != null)
|
||||
message.collisionMinStep = object.collisionMinStep | 0;
|
||||
return message;
|
||||
};
|
||||
|
||||
@ -5394,6 +5414,7 @@ $root.protos = (function() {
|
||||
object.jumpingInitVelY = 0;
|
||||
object.gravityX = 0;
|
||||
object.gravityY = 0;
|
||||
object.collisionMinStep = 0;
|
||||
}
|
||||
if (message.stageName != null && message.hasOwnProperty("stageName"))
|
||||
object.stageName = message.stageName;
|
||||
@ -5463,6 +5484,8 @@ $root.protos = (function() {
|
||||
object.gravityX = message.gravityX;
|
||||
if (message.gravityY != null && message.hasOwnProperty("gravityY"))
|
||||
object.gravityY = message.gravityY;
|
||||
if (message.collisionMinStep != null && message.hasOwnProperty("collisionMinStep"))
|
||||
object.collisionMinStep = message.collisionMinStep;
|
||||
return object;
|
||||
};
|
||||
|
||||
@ -5507,7 +5530,6 @@ $root.protos = (function() {
|
||||
* @property {Array.<protos.MeleeBullet>|null} [meleeBullets] RoomDownsyncFrame meleeBullets
|
||||
* @property {number|Long|null} [backendUnconfirmedMask] RoomDownsyncFrame backendUnconfirmedMask
|
||||
* @property {boolean|null} [shouldForceResync] RoomDownsyncFrame shouldForceResync
|
||||
* @property {Object.<string,protos.PlayerDownsync>|null} [players] RoomDownsyncFrame players
|
||||
*/
|
||||
|
||||
/**
|
||||
@ -5521,7 +5543,6 @@ $root.protos = (function() {
|
||||
function RoomDownsyncFrame(properties) {
|
||||
this.playersArr = [];
|
||||
this.meleeBullets = [];
|
||||
this.players = {};
|
||||
if (properties)
|
||||
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
|
||||
if (properties[keys[i]] != null)
|
||||
@ -5576,14 +5597,6 @@ $root.protos = (function() {
|
||||
*/
|
||||
RoomDownsyncFrame.prototype.shouldForceResync = false;
|
||||
|
||||
/**
|
||||
* RoomDownsyncFrame players.
|
||||
* @member {Object.<string,protos.PlayerDownsync>} players
|
||||
* @memberof protos.RoomDownsyncFrame
|
||||
* @instance
|
||||
*/
|
||||
RoomDownsyncFrame.prototype.players = $util.emptyObject;
|
||||
|
||||
/**
|
||||
* Creates a new RoomDownsyncFrame instance using the specified properties.
|
||||
* @function create
|
||||
@ -5622,11 +5635,6 @@ $root.protos = (function() {
|
||||
writer.uint32(/* id 5, wireType 0 =*/40).uint64(message.backendUnconfirmedMask);
|
||||
if (message.shouldForceResync != null && Object.hasOwnProperty.call(message, "shouldForceResync"))
|
||||
writer.uint32(/* id 6, wireType 0 =*/48).bool(message.shouldForceResync);
|
||||
if (message.players != null && Object.hasOwnProperty.call(message, "players"))
|
||||
for (var keys = Object.keys(message.players), i = 0; i < keys.length; ++i) {
|
||||
writer.uint32(/* id 99, wireType 2 =*/794).fork().uint32(/* id 1, wireType 0 =*/8).int32(keys[i]);
|
||||
$root.protos.PlayerDownsync.encode(message.players[keys[i]], writer.uint32(/* id 2, wireType 2 =*/18).fork()).ldelim().ldelim();
|
||||
}
|
||||
return writer;
|
||||
};
|
||||
|
||||
@ -5657,7 +5665,7 @@ $root.protos = (function() {
|
||||
RoomDownsyncFrame.decode = function decode(reader, length) {
|
||||
if (!(reader instanceof $Reader))
|
||||
reader = $Reader.create(reader);
|
||||
var end = length === undefined ? reader.len : reader.pos + length, message = new $root.protos.RoomDownsyncFrame(), key, value;
|
||||
var end = length === undefined ? reader.len : reader.pos + length, message = new $root.protos.RoomDownsyncFrame();
|
||||
while (reader.pos < end) {
|
||||
var tag = reader.uint32();
|
||||
switch (tag >>> 3) {
|
||||
@ -5689,29 +5697,6 @@ $root.protos = (function() {
|
||||
message.shouldForceResync = reader.bool();
|
||||
break;
|
||||
}
|
||||
case 99: {
|
||||
if (message.players === $util.emptyObject)
|
||||
message.players = {};
|
||||
var end2 = reader.uint32() + reader.pos;
|
||||
key = 0;
|
||||
value = null;
|
||||
while (reader.pos < end2) {
|
||||
var tag2 = reader.uint32();
|
||||
switch (tag2 >>> 3) {
|
||||
case 1:
|
||||
key = reader.int32();
|
||||
break;
|
||||
case 2:
|
||||
value = $root.protos.PlayerDownsync.decode(reader, reader.uint32());
|
||||
break;
|
||||
default:
|
||||
reader.skipType(tag2 & 7);
|
||||
break;
|
||||
}
|
||||
}
|
||||
message.players[key] = value;
|
||||
break;
|
||||
}
|
||||
default:
|
||||
reader.skipType(tag & 7);
|
||||
break;
|
||||
@ -5777,20 +5762,6 @@ $root.protos = (function() {
|
||||
if (message.shouldForceResync != null && message.hasOwnProperty("shouldForceResync"))
|
||||
if (typeof message.shouldForceResync !== "boolean")
|
||||
return "shouldForceResync: boolean expected";
|
||||
if (message.players != null && message.hasOwnProperty("players")) {
|
||||
if (!$util.isObject(message.players))
|
||||
return "players: object expected";
|
||||
var key = Object.keys(message.players);
|
||||
for (var i = 0; i < key.length; ++i) {
|
||||
if (!$util.key32Re.test(key[i]))
|
||||
return "players: integer key{k:int32} expected";
|
||||
{
|
||||
var error = $root.protos.PlayerDownsync.verify(message.players[key[i]]);
|
||||
if (error)
|
||||
return "players." + error;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
@ -5848,16 +5819,6 @@ $root.protos = (function() {
|
||||
message.backendUnconfirmedMask = new $util.LongBits(object.backendUnconfirmedMask.low >>> 0, object.backendUnconfirmedMask.high >>> 0).toNumber(true);
|
||||
if (object.shouldForceResync != null)
|
||||
message.shouldForceResync = Boolean(object.shouldForceResync);
|
||||
if (object.players) {
|
||||
if (typeof object.players !== "object")
|
||||
throw TypeError(".protos.RoomDownsyncFrame.players: object expected");
|
||||
message.players = {};
|
||||
for (var keys = Object.keys(object.players), i = 0; i < keys.length; ++i) {
|
||||
if (typeof object.players[keys[i]] !== "object")
|
||||
throw TypeError(".protos.RoomDownsyncFrame.players: object expected");
|
||||
message.players[keys[i]] = $root.protos.PlayerDownsync.fromObject(object.players[keys[i]]);
|
||||
}
|
||||
}
|
||||
return message;
|
||||
};
|
||||
|
||||
@ -5878,8 +5839,6 @@ $root.protos = (function() {
|
||||
object.playersArr = [];
|
||||
object.meleeBullets = [];
|
||||
}
|
||||
if (options.objects || options.defaults)
|
||||
object.players = {};
|
||||
if (options.defaults) {
|
||||
object.id = 0;
|
||||
if ($util.Long) {
|
||||
@ -5918,12 +5877,6 @@ $root.protos = (function() {
|
||||
object.backendUnconfirmedMask = options.longs === String ? $util.Long.prototype.toString.call(message.backendUnconfirmedMask) : options.longs === Number ? new $util.LongBits(message.backendUnconfirmedMask.low >>> 0, message.backendUnconfirmedMask.high >>> 0).toNumber(true) : message.backendUnconfirmedMask;
|
||||
if (message.shouldForceResync != null && message.hasOwnProperty("shouldForceResync"))
|
||||
object.shouldForceResync = message.shouldForceResync;
|
||||
var keys2;
|
||||
if (message.players && (keys2 = Object.keys(message.players)).length) {
|
||||
object.players = {};
|
||||
for (var j = 0; j < keys2.length; ++j)
|
||||
object.players[keys2[j]] = $root.protos.PlayerDownsync.toObject(message.players[keys2[j]], options);
|
||||
}
|
||||
return object;
|
||||
};
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
package battle
|
||||
|
||||
import (
|
||||
"resolv"
|
||||
"math"
|
||||
"resolv"
|
||||
)
|
||||
|
||||
const (
|
||||
@ -35,7 +35,7 @@ const (
|
||||
ATK_CHARACTER_STATE_INAIR_ATKED1 = int32(6)
|
||||
)
|
||||
|
||||
func ConvertToInputFrameId(renderFrameId int32, inputDelayFrames int32, inputScaleFrames int32) int32 {
|
||||
func ConvertToInputFrameId(renderFrameId int32, inputDelayFrames int32, inputScaleFrames uint32) int32 {
|
||||
if renderFrameId < inputDelayFrames {
|
||||
return 0
|
||||
}
|
||||
@ -281,7 +281,7 @@ func calcHardPushbacksNorms(playerCollider *resolv.Object, playerShape *resolv.C
|
||||
}
|
||||
|
||||
// [WARNING] The params of this method is carefully tuned such that only "battle.RoomDownsyncFrame" is a necessary custom struct.
|
||||
func ApplyInputFrameDownsyncDynamicsOnSingleRenderFrame(delayedInputList, delayedInputListForPrevRenderFrame []uint64, currRenderFrame *RoomDownsyncFrame, collisionSys *resolv.Space, collisionSysMap map[int32]*resolv.Object, gravityX, gravityY, jumpingInitVelY, inputDelayFrames, inputScaleFrames int32, collisionSpaceOffsetX, collisionSpaceOffsetY, snapIntoPlatformOverlap, snapIntoPlatformThreshold, worldToVirtualGridRatio, virtualGridToWorldRatio float64) *RoomDownsyncFrame {
|
||||
func ApplyInputFrameDownsyncDynamicsOnSingleRenderFrame(delayedInputList, delayedInputListForPrevRenderFrame []uint64, currRenderFrame *RoomDownsyncFrame, collisionSys *resolv.Space, collisionSysMap map[int32]*resolv.Object, gravityX, gravityY, jumpingInitVelY, inputDelayFrames int32, inputScaleFrames uint32, collisionSpaceOffsetX, collisionSpaceOffsetY, snapIntoPlatformOverlap, snapIntoPlatformThreshold, worldToVirtualGridRatio, virtualGridToWorldRatio float64) *RoomDownsyncFrame {
|
||||
// [WARNING] On backend this function MUST BE called while "InputsBufferLock" is locked!
|
||||
roomCapacity := len(currRenderFrame.PlayersArr)
|
||||
nextRenderFramePlayers := make([]*PlayerDownsync, roomCapacity)
|
||||
|
@ -1,5 +1,7 @@
|
||||
package battle
|
||||
|
||||
// TODO: Replace all "int32", "int64", "uint32" and "uint64" with just "int" for better performance in JavaScript! Reference https://github.com/gopherjs/gopherjs#performance-tips
|
||||
|
||||
type Vec2D struct {
|
||||
X float64
|
||||
Y float64
|
||||
@ -56,9 +58,7 @@ type MeleeBullet struct {
|
||||
RecoveryFrames int32
|
||||
RecoveryFramesOnBlock int32
|
||||
RecoveryFramesOnHit int32
|
||||
Moveforward *Vec2D
|
||||
HitboxOffset float64
|
||||
HitboxSize *Vec2D
|
||||
OriginatedRenderFrameId int32
|
||||
// for defender
|
||||
HitStunFrames int32
|
||||
@ -68,6 +68,11 @@ type MeleeBullet struct {
|
||||
Damage int32
|
||||
OffenderJoinIndex int32
|
||||
OffenderPlayerId int32
|
||||
|
||||
SelfMoveforwardX float64
|
||||
SelfMoveforwardY float64
|
||||
HitboxSizeX float64
|
||||
HitboxSizeY float64
|
||||
}
|
||||
|
||||
type RoomDownsyncFrame struct {
|
||||
|
@ -1,9 +1,9 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"resolv"
|
||||
"github.com/gopherjs/gopherjs/js"
|
||||
. "jsexport/battle"
|
||||
"resolv"
|
||||
)
|
||||
|
||||
func NewCollisionSpaceJs(spaceW, spaceH, minStepW, minStepH int) *js.Object {
|
||||
@ -50,6 +50,31 @@ func NewPlayerDownsyncJs(id, virtualGridX, virtualGridY, dirX, dirY, velX, velY,
|
||||
})
|
||||
}
|
||||
|
||||
func NewMeleeBulletJs(battleLocalId, startupFrames, activeFrames, recoveryFrames, recoveryFramesOnBlock, recoveryFramesOnHit, hitStunFrames, blockStunFrames, releaseTriggerType, damage, offenderJoinIndex, offenderPlayerId int32, pushback, hitboxOffset, selfMoveforwardX, selfMoveforwardY, hitboxSizeX, hitboxSizeY float64) *js.Object {
|
||||
return js.MakeWrapper(&MeleeBullet{
|
||||
BattleLocalId: battleLocalId,
|
||||
StartupFrames: startupFrames,
|
||||
ActiveFrames: activeFrames,
|
||||
RecoveryFrames: recoveryFrames,
|
||||
RecoveryFramesOnBlock: recoveryFramesOnBlock,
|
||||
RecoveryFramesOnHit: recoveryFramesOnHit,
|
||||
HitboxOffset: hitboxOffset,
|
||||
HitStunFrames: hitStunFrames,
|
||||
BlockStunFrames: blockStunFrames,
|
||||
Pushback: pushback,
|
||||
ReleaseTriggerType: releaseTriggerType,
|
||||
Damage: damage,
|
||||
|
||||
SelfMoveforwardX: selfMoveforwardX,
|
||||
SelfMoveforwardY: selfMoveforwardY,
|
||||
HitboxSizeX: hitboxSizeX,
|
||||
HitboxSizeY: hitboxSizeY,
|
||||
|
||||
OffenderJoinIndex: offenderJoinIndex,
|
||||
OffenderPlayerId: offenderPlayerId,
|
||||
})
|
||||
}
|
||||
|
||||
func NewRoomDownsyncFrameJs(id int32, playersArr []*PlayerDownsync, meleeBullets []*MeleeBullet) *js.Object {
|
||||
// [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{
|
||||
@ -89,7 +114,7 @@ func GenerateConvexPolygonColliderJs(unalignedSrc *Polygon2D, spaceOffsetX, spac
|
||||
return js.MakeFullWrapper(GenerateConvexPolygonCollider(unalignedSrc, spaceOffsetX, spaceOffsetY, data, tag))
|
||||
}
|
||||
|
||||
func ApplyInputFrameDownsyncDynamicsOnSingleRenderFrameJs(delayedInputList, delayedInputListForPrevRenderFrame []uint64, currRenderFrame *RoomDownsyncFrame, collisionSys *resolv.Space, collisionSysMap map[int32]*resolv.Object, gravityX, gravityY, jumpingInitVelY, inputDelayFrames, inputScaleFrames int32, collisionSpaceOffsetX, collisionSpaceOffsetY, snapIntoPlatformOverlap, snapIntoPlatformThreshold, worldToVirtualGridRatio, virtualGridToWorldRatio float64) *js.Object {
|
||||
func ApplyInputFrameDownsyncDynamicsOnSingleRenderFrameJs(delayedInputList, delayedInputListForPrevRenderFrame []uint64, currRenderFrame *RoomDownsyncFrame, collisionSys *resolv.Space, collisionSysMap map[int32]*resolv.Object, gravityX, gravityY, jumpingInitVelY, inputDelayFrames int32, inputScaleFrames uint32, collisionSpaceOffsetX, collisionSpaceOffsetY, snapIntoPlatformOverlap, snapIntoPlatformThreshold, worldToVirtualGridRatio, virtualGridToWorldRatio float64) *js.Object {
|
||||
// We need access to all fields of RoomDownsyncFrame for displaying in frontend
|
||||
return js.MakeFullWrapper(ApplyInputFrameDownsyncDynamicsOnSingleRenderFrame(delayedInputList, delayedInputListForPrevRenderFrame, currRenderFrame, collisionSys, collisionSysMap, gravityX, gravityY, jumpingInitVelY, inputDelayFrames, inputScaleFrames, collisionSpaceOffsetX, collisionSpaceOffsetY, snapIntoPlatformOverlap, snapIntoPlatformThreshold, worldToVirtualGridRatio, virtualGridToWorldRatio))
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user