Refactored backend to use jsexport dynamics.

This commit is contained in:
genxium
2022-12-25 20:17:22 +08:00
parent 8139a00939
commit a85c6f9ad8
16 changed files with 445 additions and 1035 deletions

View File

@@ -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)

View File

@@ -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 {