mirror of
https://github.com/genxium/DelayNoMore
synced 2025-10-09 00:26:39 +00:00
Added necessary js type exposure to jsexport.
This commit is contained in:
@@ -22,19 +22,20 @@ func RectCenterStr(body *resolv.Object, halfBoundingW, halfBoundingH, topPadding
|
||||
return fmt.Sprintf("{%.2f, %.2f}", body.X+leftPadding+halfBoundingW-spaceOffsetX, body.Y+bottomPadding+halfBoundingH-spaceOffsetY)
|
||||
}
|
||||
|
||||
func GenerateRectCollider(wx, wy, w, h, topPadding, bottomPadding, leftPadding, rightPadding, spaceOffsetX, spaceOffsetY float64, tag string) *resolv.Object {
|
||||
func GenerateRectCollider(wx, wy, w, h, topPadding, bottomPadding, leftPadding, rightPadding, spaceOffsetX, spaceOffsetY float64, data interface{}, tag string) *resolv.Object {
|
||||
blX, blY := WorldToPolygonColliderBLPos(wx, wy, w*0.5, h*0.5, topPadding, bottomPadding, leftPadding, rightPadding, spaceOffsetX, spaceOffsetY)
|
||||
return generateRectColliderInCollisionSpace(blX, blY, leftPadding+w+rightPadding, bottomPadding+h+topPadding, tag)
|
||||
return generateRectColliderInCollisionSpace(blX, blY, leftPadding+w+rightPadding, bottomPadding+h+topPadding, data, tag)
|
||||
}
|
||||
|
||||
func generateRectColliderInCollisionSpace(blX, blY, w, h float64, tag string) *resolv.Object {
|
||||
func generateRectColliderInCollisionSpace(blX, blY, w, h float64, data interface{}, tag string) *resolv.Object {
|
||||
collider := resolv.NewObject(blX, blY, w, h, tag) // Unlike its frontend counter part, the position of a "resolv.Object" must be specified by "bottom-left point" because "w" and "h" must be positive, see "resolv.Object.BoundsToSpace" for details
|
||||
shape := resolv.NewRectangle(0, 0, w, h)
|
||||
collider.SetShape(shape)
|
||||
collider.Data = data
|
||||
return collider
|
||||
}
|
||||
|
||||
func GenerateConvexPolygonCollider(unalignedSrc *Polygon2D, spaceOffsetX, spaceOffsetY float64, tag string) *resolv.Object {
|
||||
func GenerateConvexPolygonCollider(unalignedSrc *Polygon2D, spaceOffsetX, spaceOffsetY float64, data interface{}, tag string) *resolv.Object {
|
||||
aligned := AlignPolygon2DToBoundingBox(unalignedSrc)
|
||||
var w, h float64 = 0, 0
|
||||
|
||||
@@ -60,6 +61,7 @@ func GenerateConvexPolygonCollider(unalignedSrc *Polygon2D, spaceOffsetX, spaceO
|
||||
|
||||
collider := resolv.NewObject(aligned.Anchor.X+spaceOffsetX, aligned.Anchor.Y+spaceOffsetY, w, h, tag)
|
||||
collider.SetShape(shape)
|
||||
collider.Data = data
|
||||
|
||||
return collider
|
||||
}
|
||||
|
@@ -1,5 +1,11 @@
|
||||
package dnmshared
|
||||
|
||||
const (
|
||||
RING_BUFF_CONSECUTIVE_SET = int32(0)
|
||||
RING_BUFF_NON_CONSECUTIVE_SET = int32(1)
|
||||
RING_BUFF_FAILED_TO_SET = int32(2)
|
||||
)
|
||||
|
||||
type RingBuffer struct {
|
||||
Ed int32 // write index, open index
|
||||
St int32 // read index, closed index
|
||||
@@ -48,15 +54,15 @@ func (rb *RingBuffer) Pop() interface{} {
|
||||
return pItem
|
||||
}
|
||||
|
||||
func (rb *RingBuffer) GetByOffset(offsetFromSt int32) interface{} {
|
||||
if 0 == rb.Cnt {
|
||||
return nil
|
||||
func (rb *RingBuffer) GetArrIdxByOffset(offsetFromSt int32) int32 {
|
||||
if 0 == rb.Cnt || 0 > offsetFromSt {
|
||||
return -1
|
||||
}
|
||||
arrIdx := rb.St + offsetFromSt
|
||||
if rb.St < rb.Ed {
|
||||
// case#1: 0...st...ed...N-1
|
||||
if rb.St <= arrIdx && arrIdx < rb.Ed {
|
||||
return rb.Eles[arrIdx]
|
||||
return arrIdx
|
||||
}
|
||||
} else {
|
||||
// if rb.St >= rb.Ed
|
||||
@@ -65,11 +71,19 @@ func (rb *RingBuffer) GetByOffset(offsetFromSt int32) interface{} {
|
||||
arrIdx -= rb.N
|
||||
}
|
||||
if arrIdx >= rb.St || arrIdx < rb.Ed {
|
||||
return rb.Eles[arrIdx]
|
||||
return arrIdx
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
return -1
|
||||
}
|
||||
|
||||
func (rb *RingBuffer) GetByOffset(offsetFromSt int32) interface{} {
|
||||
arrIdx := rb.GetArrIdxByOffset(offsetFromSt)
|
||||
if -1 == arrIdx {
|
||||
return nil
|
||||
}
|
||||
return rb.Eles[arrIdx]
|
||||
}
|
||||
|
||||
func (rb *RingBuffer) GetByFrameId(frameId int32) interface{} {
|
||||
@@ -78,3 +92,33 @@ func (rb *RingBuffer) GetByFrameId(frameId int32) interface{} {
|
||||
}
|
||||
return rb.GetByOffset(frameId - rb.StFrameId)
|
||||
}
|
||||
|
||||
// [WARNING] During a battle, frontend could receive non-consecutive frames (either renderFrame or inputFrame) due to resync, the buffer should handle these frames properly.
|
||||
func (rb *RingBuffer) SetByFrameId(pItem interface{}, frameId int32) (int32, int32, int32) {
|
||||
oldStFrameId, oldEdFrameId := rb.StFrameId, rb.EdFrameId
|
||||
if frameId < oldStFrameId {
|
||||
return RING_BUFF_FAILED_TO_SET, oldStFrameId, oldEdFrameId
|
||||
}
|
||||
// By now "rb.StFrameId <= frameId"
|
||||
if oldEdFrameId > frameId {
|
||||
arrIdx := rb.GetArrIdxByOffset(frameId - rb.StFrameId)
|
||||
if -1 != arrIdx {
|
||||
rb.Eles[arrIdx] = pItem
|
||||
return RING_BUFF_CONSECUTIVE_SET, oldStFrameId, oldEdFrameId
|
||||
}
|
||||
}
|
||||
|
||||
// By now "rb.EdFrameId <= frameId"
|
||||
ret := RING_BUFF_CONSECUTIVE_SET
|
||||
if oldEdFrameId < frameId {
|
||||
rb.St, rb.Ed = 0, 0
|
||||
rb.StFrameId, rb.EdFrameId = frameId, frameId
|
||||
rb.Cnt = 0
|
||||
ret = RING_BUFF_NON_CONSECUTIVE_SET
|
||||
}
|
||||
|
||||
// By now "rb.EdFrameId == frameId"
|
||||
rb.Put(pItem)
|
||||
|
||||
return ret, oldStFrameId, oldEdFrameId
|
||||
}
|
||||
|
Reference in New Issue
Block a user