Skip to content

Commit aa33873

Browse files
authored
Merge pull request #2566 from potsmugen/push2
fix: common FX prefixes; several refactors
2 parents 62f65a6 + 977a5d0 commit aa33873

8 files changed

Lines changed: 331 additions & 262 deletions

File tree

src/anim.go

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package main
22

33
import (
4+
"sort"
45
"strings"
56
)
67

@@ -971,6 +972,9 @@ func (dl *DrawList) add(sd *SprData) {
971972
return
972973
}
973974

975+
// Before: sort every time we add a sprite
976+
// After: add all sprites first then sort before drawing
977+
/*
974978
i, start := 0, 0
975979
for l := len(*dl); l > 0; {
976980
i = start + l>>1
@@ -987,9 +991,24 @@ func (dl *DrawList) add(sd *SprData) {
987991
*dl = append(*dl, nil)
988992
copy((*dl)[i+1:], (*dl)[i:])
989993
(*dl)[i] = sd
994+
*/
995+
996+
// Just append. We will sort everything later in one go
997+
*dl = append(*dl, sd)
990998
}
991999

9921000
func (dl DrawList) draw(cameraX, cameraY, cameraScl float32) {
1001+
// Sort drawing order
1002+
sort.Slice(dl, func(i, j int) bool {
1003+
// If different priority, draw lower priority first
1004+
if dl[i].priority != dl[j].priority {
1005+
return dl[i].priority < dl[j].priority
1006+
}
1007+
// Else draw newer sprite first
1008+
return i > j
1009+
})
1010+
1011+
// Draw the entire list
9931012
for _, s := range dl {
9941013
// Skip blank SprData
9951014
// https://github.com/ikemen-engine/Ikemen-GO/issues/2433
@@ -1083,6 +1102,7 @@ func (sl *ShadowList) add(ss *ShadowSprite) {
10831102
return
10841103
}
10851104

1105+
/*
10861106
i, start := 0, 0
10871107
for l := len(*sl); l > 0; {
10881108
i = start + l>>1
@@ -1099,11 +1119,23 @@ func (sl *ShadowList) add(ss *ShadowSprite) {
10991119
*sl = append(*sl, nil)
11001120
copy((*sl)[i+1:], (*sl)[i:])
11011121
(*sl)[i] = ss
1122+
*/
1123+
1124+
// Just append. We will sort everything later in one go
1125+
*sl = append(*sl, ss)
11021126
}
11031127

11041128
func (sl ShadowList) draw(x, y, scl float32) {
1105-
for _, s := range sl {
1129+
// Sort drawing order
1130+
sort.Slice(sl, func(i, j int) bool {
1131+
if sl[i].priority != sl[j].priority {
1132+
return sl[i].priority < sl[j].priority
1133+
}
1134+
return i > j
1135+
})
11061136

1137+
// Draw the entire list
1138+
for _, s := range sl {
11071139
// Skip blank shadows
11081140
if s == nil || s.anim == nil || s.anim.isBlank() {
11091141
continue

src/bytecode.go

Lines changed: 22 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2990,7 +2990,8 @@ func (be BytecodeExp) run_ex(c *Char, i *int, oc *Char) {
29902990
case OC_ex_ishost:
29912991
sys.bcStack.PushB(c.isHost())
29922992
case OC_ex_jugglepoints:
2993-
*sys.bcStack.Top() = c.jugglePoints(*sys.bcStack.Top())
2993+
v1 := sys.bcStack.Pop()
2994+
sys.bcStack.PushI(c.jugglePoints(v1.ToI()))
29942995
case OC_ex_localcoord_x:
29952996
sys.bcStack.PushF(sys.cgi[c.playerNo].localcoord[0])
29962997
case OC_ex_localcoord_y:
@@ -5519,10 +5520,10 @@ const (
55195520
explod_interpolate_pfx_color
55205521
explod_interpolate_pfx_hue
55215522
explod_interpolation
5522-
explod_redirectid
55235523
explod_animplayerno
55245524
explod_spriteplayerno
55255525
explod_last = iota + palFX_last + 1 - 1
5526+
explod_redirectid
55265527
)
55275528

55285529
func (sc explod) Run(c *Char, _ []int32) bool {
@@ -5902,13 +5903,6 @@ func (sc modifyExplod) Run(c *Char, _ []int32) bool {
59025903

59035904
StateControllerBase(sc).run(c, func(paramID byte, exp []BytecodeExp) bool {
59045905
switch paramID {
5905-
case explod_redirectid:
5906-
if rid := sys.playerID(exp[0].evalI(c)); rid != nil {
5907-
crun = rid
5908-
redirscale = c.localscl / crun.localscl
5909-
} else {
5910-
return false
5911-
}
59125906
case explod_animplayerno:
59135907
pn := int(exp[0].evalI(c)) - 1
59145908
if crun.validatePlayerNo(pn, "animPlayerNo", "modifyExplod") {
@@ -11602,12 +11596,11 @@ func (sc modifySnd) Run(c *Char, _ []int32) bool {
1160211596

1160311597
x := &crun.pos[0]
1160411598
ls := crun.localscl
11599+
var snd *SoundChannel
1160511600
var ch, pri int32 = -1, 0
11601+
var stopgh, stopcs int32 = -1, -1 // Undefined bools
1160611602
var vo, fr float32 = 100, 1.0
11607-
snd := crun.soundChannels.Get(-1)
11608-
stopgh, stopcs := false, false
1160911603
freqMulSet, volumeSet, prioritySet, panSet, loopStartSet, loopEndSet, posSet, lcSet, loopSet := false, false, false, false, false, false, false, false, false
11610-
stopghSet, stopcsSet := false, false
1161111604
var loopstart, loopend, position, lc int = 0, 0, 0, 0
1161211605
var p float32 = 0
1161311606

@@ -11662,12 +11655,13 @@ func (sc modifySnd) Run(c *Char, _ []int32) bool {
1166211655
}
1166311656
lcSet = true
1166411657
case modifySnd_stopongethit:
11665-
stopgh = exp[0].evalB(c)
11658+
stopgh = Btoi(exp[0].evalB(c))
1166611659
case modifySnd_stoponchangestate:
11667-
stopcs = exp[0].evalB(c)
11660+
stopcs = Btoi(exp[0].evalB(c))
1166811661
}
1166911662
return true
1167011663
})
11664+
1167111665
// Grab the correct sound channel now
1167211666
channelCount := 1
1167311667
if ch < 0 {
@@ -11724,11 +11718,11 @@ func (sc modifySnd) Run(c *Char, _ []int32) bool {
1172411718
snd.SetVolume(vo)
1172511719
}
1172611720
// These flags can be updated regardless since there are no calculations involved
11727-
if stopghSet {
11728-
snd.stopOnGetHit = stopgh
11721+
if stopgh >= 0 {
11722+
snd.stopOnGetHit = stopgh != 0
1172911723
}
11730-
if stopcsSet {
11731-
snd.stopOnChangeState = stopcs
11724+
if stopcs >= 0 {
11725+
snd.stopOnChangeState = stopgh != 0
1173211726
}
1173311727
}
1173411728
}
@@ -11986,8 +11980,8 @@ const (
1198611980
text_color
1198711981
text_xshear
1198811982
text_id
11989-
text_redirectid
1199011983
text_last = iota + palFX_last + 1 - 1
11984+
text_redirectid
1199111985
)
1199211986

1199311987
func (sc text) Run(c *Char, _ []int32) bool {
@@ -12041,7 +12035,14 @@ func (sc text) Run(c *Char, _ []int32) bool {
1204112035
fnt = -1
1204212036
}
1204312037
case text_localcoord:
12044-
ts.SetLocalcoord(exp[0].evalF(c), exp[1].evalF(c))
12038+
var x, y float32
12039+
x = exp[0].evalF(c)
12040+
if len(exp) > 1 {
12041+
y = exp[1].evalF(c)
12042+
}
12043+
if x > 0 && y > 0 { // TODO: Maybe this safeguard could be in SetLocalcoord instead
12044+
ts.SetLocalcoord(x, y)
12045+
}
1204512046
case text_bank:
1204612047
ts.bank = exp[0].evalI(c)
1204712048
case text_align:
@@ -12981,30 +12982,7 @@ func (sc targetAdd) Run(c *Char, _ []int32) bool {
1298112982
return true
1298212983
})
1298312984

12984-
// Check if ID exists
12985-
if pid > 0 {
12986-
for i := range sys.chars {
12987-
for j := range sys.chars[i] {
12988-
if sys.chars[i][j].id == pid {
12989-
// Add target to char's "target" list
12990-
// This function already prevents duplicating targets
12991-
crun.addTarget(pid)
12992-
// Add char to target's "targeted by" list
12993-
// Keep juggle points if target already exists
12994-
jug := crun.gi().data.airjuggle
12995-
for _, v := range sys.chars[i][j].ghv.targetedBy {
12996-
if v[0] == crun.id {
12997-
jug = v[1]
12998-
}
12999-
}
13000-
// Remove then readd char to the list with the new juggle points
13001-
sys.chars[i][j].ghv.dropId(crun.id)
13002-
sys.chars[i][j].ghv.targetedBy = append(sys.chars[i][j].ghv.targetedBy, [...]int32{crun.id, jug})
13003-
break
13004-
}
13005-
}
13006-
}
13007-
}
12985+
crun.targetAddSctrl(pid)
1300812986

1300912987
return false
1301012988
}

0 commit comments

Comments
 (0)