Skip to content

Commit

Permalink
Merge pull request #2091 from potsmugen/projfix
Browse files Browse the repository at this point in the history
fix: projectile localcoord yaccel, TransformClsn redirection
  • Loading branch information
K4thos authored Oct 26, 2024
2 parents efceb5e + c9a7efe commit 63d2a9b
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 49 deletions.
10 changes: 2 additions & 8 deletions src/bytecode.go
Original file line number Diff line number Diff line change
Expand Up @@ -6549,8 +6549,6 @@ func (sc projectile) Run(c *Char, _ []int32) bool {
if p == nil {
return false
}
p.hitdef.playerNo = sys.workingState.playerNo
p.hitdef.isprojectile = true
}
switch id {
case projectile_postype:
Expand Down Expand Up @@ -6725,11 +6723,6 @@ func (sc projectile) Run(c *Char, _ []int32) bool {
if p.aimg.time != 0 {
p.aimg.setupPalFX()
}
if crun.minus == -2 || crun.minus == -4 {
p.localscl = (320 / crun.localcoord)
} else {
p.localscl = crun.localscl
}
crun.projInit(p, pt, x, y, z, op, rp[0], rp[1], clsnscale)
return false
}
Expand Down Expand Up @@ -11845,8 +11838,9 @@ func (sc transformClsn) Run(c *Char, _ []int32) bool {
if len(exp) > 1 {
crun.clsnScaleMul[1] *= exp[1].evalF(c)
}
crun.updateClsnScale()
case transformClsn_angle:
crun.clsnAngle = exp[0].evalF(c)
crun.clsnAngle += exp[0].evalF(c)
case transformClsn_redirectid:
if rid := sys.playerID(exp[0].evalI(c)); rid != nil {
crun = rid
Expand Down
94 changes: 53 additions & 41 deletions src/char.go
Original file line number Diff line number Diff line change
Expand Up @@ -1717,7 +1717,6 @@ func (p *Projectile) clear() {
aimg: *newAfterImage(),
platformFence: true,
}
p.hitdef.clear(p.localscl)
}

func (p *Projectile) setPos(pos [3]float32) {
Expand Down Expand Up @@ -2076,7 +2075,6 @@ type CharGlobalInfo struct {
wakewakaLength int32
pctype ProjContact
pctime, pcid int32
projidcount int
quotes [MaxQuotes]string
portraitscale float32
constants map[string]float32
Expand Down Expand Up @@ -3275,7 +3273,7 @@ func (c *Char) changeAnimEx(animNo int32, playerNo int, ffx string, alt bool) {
// Update animation local scale
c.animlocalscl = 320 / sys.chars[c.animPN][0].localcoord
// Clsn scale depends on the animation owner's scale, so it must be updated
c.updateClsnBaseScale()
c.updateClsnScale()
if c.hitPause() {
c.curFrame = a.CurrentFrame()
}
Expand Down Expand Up @@ -4945,8 +4943,6 @@ func (c *Char) shadYOff(yv float32, isReflect bool) {
}
}

// --------------------

func (c *Char) hitAdd(h int32) {
c.hitCount += h
c.uniqHitCount += h
Expand All @@ -4971,25 +4967,43 @@ func (c *Char) hitAdd(h int32) {
}
}
}

func (c *Char) newProj() *Projectile {
for i := c.gi().projidcount; i < len(sys.projs[c.playerNo]); i++ {
if sys.projs[c.playerNo][i].id < 0 {
sys.projs[c.playerNo][i].clear()
// Projectile defaults
sys.projs[c.playerNo][i].id = 0
sys.projs[c.playerNo][i].layerno = c.layerNo
sys.projs[c.playerNo][i].palfx = c.getPalfx()
c.gi().projidcount = i
return &sys.projs[c.playerNo][i]
}
}
if i := len(sys.projs[c.playerNo]); i < sys.playerProjectileMax {
sys.projs[c.playerNo] = append(sys.projs[c.playerNo], *newProjectile())
p := &sys.projs[c.playerNo][i]
p.id, p.palfx = 0, c.getPalfx()
return p
}
return nil
var p *Projectile

// Loop through the player's projectile slots to find an inactive one
for i, old := range sys.projs[c.playerNo] {
if old.id < 0 {
p = &sys.projs[c.playerNo][i]
p.clear()
break
}
}

// If no inactive projectile was found, append a new one within the max limit
if p == nil && len(sys.projs[c.playerNo]) < sys.playerProjectileMax {
sys.projs[c.playerNo] = append(sys.projs[c.playerNo], *newProjectile())
p = &sys.projs[c.playerNo][len(sys.projs[c.playerNo])-1]
}

// Set up default values
if p != nil {
if c.minus == -2 || c.minus == -4 {
p.localscl = (320 / c.localcoord)
} else {
p.localscl = c.localscl
}
p.id = 0
p.layerno = c.layerNo
p.palfx = c.getPalfx()
// Initialize projectile Hitdef. Must be placed after localscl is defined
// https://github.com/ikemen-engine/Ikemen-GO/issues/2087
p.hitdef.clear(p.localscl)
p.hitdef.isprojectile = true
p.hitdef.playerNo = sys.workingState.playerNo
}

return p
}

func (c *Char) projInit(p *Projectile, pt PosType, x, y, z float32,
Expand Down Expand Up @@ -5241,17 +5255,16 @@ func (c *Char) setBHeight(bh float32) {
c.setCSF(CSF_bottomheight)
}

func (c *Char) updateClsnBaseScale() {
// Helper parameter
func (c *Char) updateClsnScale() {
// Update base scale
if c.ownclsnscale && c.animPN == c.playerNo {
// Helper parameter. Use own scale instead of animation owner's
c.clsnBaseScale = [...]float32{c.size.xscale, c.size.yscale}
return
}
// Index range checks. Prevents crashing if chars don't have animations
// https://github.com/ikemen-engine/Ikemen-GO/issues/1982
if c.animPN >= 0 && c.animPN < len(sys.chars) && len(sys.chars[c.animPN]) > 0 {
// The char's base Clsn scale
// Based on the animation owner's scale constants
} else if c.animPN >= 0 && c.animPN < len(sys.chars) && len(sys.chars[c.animPN]) > 0 {
// Index range checks. Prevents crashing if chars don't have animations
// https://github.com/ikemen-engine/Ikemen-GO/issues/1982
// The char's base Clsn scale is based on the animation owner's scale constants
c.clsnBaseScale = [...]float32{
sys.chars[c.animPN][0].size.xscale,
sys.chars[c.animPN][0].size.yscale,
Expand All @@ -5260,6 +5273,11 @@ func (c *Char) updateClsnBaseScale() {
// Normally not used. Just a safeguard
c.clsnBaseScale = [...]float32{1.0, 1.0}
}
// Calculate final scale
// Clsn and size box scale used to factor zScale here, but they shouldn't
// Game logic should stay the same regardless of Z scale. Only drawing scale should change
c.clsnScale = [2]float32{c.clsnBaseScale[0] * c.clsnScaleMul[0] * c.animlocalscl, // Facing is not used here
c.clsnBaseScale[1] * c.clsnScaleMul[1] * c.animlocalscl}
}

func (c *Char) widthToSizeBox() {
Expand Down Expand Up @@ -7412,18 +7430,9 @@ func (c *Char) actionRun() {
if c.helperIndex == 0 && c.gi().pctime >= 0 {
c.gi().pctime++
}
c.gi().projidcount = 0
}
c.xScreenBound()
c.zDepthBound()

// Final scale calculations
// Clsn and size box scale used to factor zScale here, but they shouldn't
// Game logic should stay the same regardless of Z scale. Only drawing changes
c.zScale = sys.updateZScale(c.pos[2], c.localscl) // Must be placed after posUpdate()
c.clsnScale = [2]float32{c.clsnBaseScale[0] * c.clsnScaleMul[0] * c.animlocalscl, // No facing here
c.clsnBaseScale[1] * c.clsnScaleMul[1] * c.animlocalscl}

if !c.pauseBool {
for _, tid := range c.targets {
if t := sys.playerID(tid); t != nil && t.bindToId == c.id {
Expand All @@ -7435,7 +7444,7 @@ func (c *Char) actionRun() {
c.acttmp += int8(Btoi(!c.pause() && !c.hitPause())) - int8(Btoi(c.hitPause()))
}
func (c *Char) actionFinish() {
if (c.minus < 1) || c.csf(CSF_destroy) || c.scf(SCF_disabled) {
if c.minus < 1 || c.csf(CSF_destroy) || c.scf(SCF_disabled) {
return
}
if !c.pauseBool {
Expand All @@ -7446,6 +7455,9 @@ func (c *Char) actionFinish() {
c.ghv.frame = false
c.mhv.frame = false
}
// Update Z scale
// Must be placed after posUpdate()
c.zScale = sys.updateZScale(c.pos[2], c.localscl)
c.minus = 1
}
func (c *Char) track() {
Expand Down

0 comments on commit 63d2a9b

Please sign in to comment.