Skip to content

Commit

Permalink
style: fix code style issues with gofmt
Browse files Browse the repository at this point in the history
  • Loading branch information
lint-action committed Oct 11, 2023
1 parent d047298 commit 02e1fec
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 72 deletions.
16 changes: 8 additions & 8 deletions src/bytecode.go
Original file line number Diff line number Diff line change
Expand Up @@ -3441,7 +3441,7 @@ func (sc palFX) runSub(c *Char, pfd *PalFXDef,
case palFX_invertall:
pfd.invertall = exp[0].evalB(c)
case palFX_invertblend:
pfd.invertblend = Clamp(exp[0].evalI(c),-1,2)
pfd.invertblend = Clamp(exp[0].evalI(c), -1, 2)
default:
return false
}
Expand Down Expand Up @@ -3487,9 +3487,9 @@ func (sc allPalFX) Run(c *Char, _ []int32) bool {
StateControllerBase(sc).run(c, func(id byte, exp []BytecodeExp) bool {
palFX(sc).runSub(c, &sys.allPalFX.PalFXDef, id, exp)
//Forcing 1.1 kind behavior
sys.allPalFX.invertblend = Clamp(sys.allPalFX.invertblend,0,1)
sys.allPalFX.invertblend = Clamp(sys.allPalFX.invertblend, 0, 1)
return true
})
})
return false
}

Expand All @@ -3501,7 +3501,7 @@ func (sc bgPalFX) Run(c *Char, _ []int32) bool {
sys.bgPalFX.invertblend = -2
StateControllerBase(sc).run(c, func(id byte, exp []BytecodeExp) bool {
palFX(sc).runSub(c, &sys.bgPalFX.PalFXDef, id, exp)
sys.bgPalFX.invertblend = -3
sys.bgPalFX.invertblend = -3
return true
})
return false
Expand Down Expand Up @@ -3727,7 +3727,7 @@ func (sc explod) Run(c *Char, _ []int32) bool {
if crun.stCgi().ver[0] == 1 && crun.stCgi().ver[1] == 1 && crun.stCgi().ikemenver[0] <= 0 {
e.palfxdef.invertblend = -2
}
palFX(sc).runSub(c, &e.palfxdef, id, exp)
palFX(sc).runSub(c, &e.palfxdef, id, exp)
}
return true
})
Expand Down Expand Up @@ -4140,7 +4140,7 @@ func (sc afterImage) runSub(c *Char, ai *AfterImage,
case afterImage_palinvertall:
ai.setPalInvertall(exp[0].evalB(c))
case afterImage_palinvertblend:
ai.setPalInvertblend(exp[0].evalI(c))
ai.setPalInvertblend(exp[0].evalI(c))
case afterImage_palbright:
ai.setPalBrightR(exp[0].evalI(c))
if len(exp) > 1 {
Expand Down Expand Up @@ -4201,7 +4201,7 @@ func (sc afterImage) Run(c *Char, _ []int32) bool {
//Mugen 1.1 behavior if invertblend param is omitted(Only if char mugenversion = 1.1)
if crun.stCgi().ver[0] == 1 && crun.stCgi().ver[1] == 1 && crun.stCgi().ikemenver[0] <= 0 {
crun.aimg.palfx[0].invertblend = -2
}
}
crun.aimg.time = 1
doOce = true
}
Expand Down Expand Up @@ -7856,7 +7856,7 @@ func (sc modifyBGCtrl) Run(c *Char, _ []int32) bool {
x, y := float32(math.NaN()), float32(math.NaN())
src, dst := [2]int32{IErr, IErr}, [2]int32{IErr, IErr}
add, mul, sinadd, sinmul, sincolor := [3]int32{IErr, IErr, IErr}, [3]int32{IErr, IErr, IErr}, [4]int32{IErr, IErr, IErr, IErr}, [4]int32{IErr, IErr, IErr, IErr}, [2]int32{IErr, IErr}
invall, invblend, color := IErr,IErr, float32(math.NaN())
invall, invblend, color := IErr, IErr, float32(math.NaN())
StateControllerBase(sc).run(c, func(id byte, exp []BytecodeExp) bool {
switch id {
case modifyBGCtrl_id:
Expand Down
12 changes: 6 additions & 6 deletions src/char.go
Original file line number Diff line number Diff line change
Expand Up @@ -860,7 +860,7 @@ func (ai *AfterImage) clear() {
if len(ai.palfx) > 0 {
ai.palfx[0].eColor = 1
ai.palfx[0].eInvertall = false
ai.palfx[0].eInvertblend = 0
ai.palfx[0].eInvertblend = 0
ai.palfx[0].eAdd = [...]int32{30, 30, 30}
ai.palfx[0].eMul = [...]int32{120, 120, 220}
}
Expand Down Expand Up @@ -926,8 +926,8 @@ func (ai *AfterImage) setupPalFX() {
if ai.palfx[0].invertblend <= -2 && ai.palfx[0].eInvertall {
ai.palfx[0].eInvertblend = 3
} else {
ai.palfx[0].eInvertblend = ai.palfx[0].invertblend
}
ai.palfx[0].eInvertblend = ai.palfx[0].invertblend
}
for i := 1; i < len(ai.palfx); i++ {
ai.palfx[i].eColor = ai.palfx[i-1].eColor
ai.palfx[i].eInvertall = ai.palfx[i-1].eInvertall
Expand Down Expand Up @@ -2750,7 +2750,7 @@ func (c *Char) helper(id int32) *Char {
}
func (c *Char) helperByIndex(id int32) *Char {
for j, h := range sys.chars[c.playerNo][1:] {
if ((id - 1) == int32(j)) {
if (id - 1) == int32(j) {
return h
}
}
Expand Down Expand Up @@ -3671,7 +3671,7 @@ func (c *Char) helperInit(h *Char, st int32, pt PosType, x, y float32,
//Mugen 1.1 behavior if invertblend param is omitted(Only if char mugenversion = 1.1)
if h.stCgi().ver[0] == 1 && c.stCgi().ver[1] == 1 && h.stCgi().ikemenver[0] <= 0 {
h.palfx.invertblend = -2
}
}
h.changeStateEx(st, c.playerNo, 0, 1, "")
// Prepare newly created helper so it can be successfully run later via actionRun() in charList.action()
h.actionPrepare()
Expand Down Expand Up @@ -4795,7 +4795,7 @@ func (c *Char) getPalfx() *PalFX {
//Mugen 1.1 behavior if invertblend param is omitted(Only if char mugenversion = 1.1)
if c.stCgi().ver[0] == 1 && c.stCgi().ver[1] == 1 && c.stCgi().ikemenver[0] <= 0 && c.palfx != nil {
c.palfx.PalFXDef.invertblend = -2
}
}
return c.palfx
}
func (c *Char) getPalMap() []int {
Expand Down
4 changes: 2 additions & 2 deletions src/compiler_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -996,7 +996,7 @@ func (c *Compiler) palFXSub(is IniSection,
if err := c.paramValue(is, sc, prefix+"invertblend",
palFX_invertblend, VT_Int, 1, false); err != nil {
return err
}
}
return nil
}
func (c *Compiler) palFX(is IniSection, sc *StateControllerBase, _ int8) (StateController, error) {
Expand Down Expand Up @@ -4148,7 +4148,7 @@ func (c *Compiler) modifyBGCtrl(is IniSection, sc *StateControllerBase, _ int8)
if err := c.paramValue(is, sc, "invertblend",
modifyBGCtrl_invertblend, VT_Int, 1, false); err != nil {
return err
}
}
if err := c.paramValue(is, sc, "color",
modifyBGCtrl_color, VT_Float, 1, false); err != nil {
return err
Expand Down
40 changes: 21 additions & 19 deletions src/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,22 +36,22 @@ type PalFXDef struct {
cycletimeMul int32
cycletimeColor int32
invertall bool
invertblend int32
invertblend int32
}
type PalFX struct {
PalFXDef
remap []int
negType bool
sintime int32
sintime2 int32
sintime3 int32
enable bool
eNegType bool
eInvertall bool
eInvertblend int32
eAdd [3]int32
eMul [3]int32
eColor float32
remap []int
negType bool
sintime int32
sintime2 int32
sintime3 int32
enable bool
eNegType bool
eInvertall bool
eInvertblend int32
eAdd [3]int32
eMul [3]int32
eColor float32
}

func newPalFX() *PalFX { return &PalFX{} }
Expand All @@ -73,7 +73,7 @@ func (pf *PalFX) getSynFx(blending bool) *PalFX {
return pf
}
synth := *pf
synth.synthesize(sys.allPalFX,blending)
synth.synthesize(sys.allPalFX, blending)
return &synth
}
func (pf *PalFX) getFxPal(pal []uint32, neg bool) []uint32 {
Expand Down Expand Up @@ -127,7 +127,7 @@ func (pf *PalFX) getFxPal(pal []uint32, neg bool) []uint32 {
return sys.workpal
}
func (pf *PalFX) getFcPalFx(transNeg bool, blending bool) (neg bool, grayscale float32,
add, mul [3]float32, invblend int32 ) {
add, mul [3]float32, invblend int32) {
p := pf.getSynFx(blending)
if !p.enable {
neg = false
Expand Down Expand Up @@ -203,7 +203,7 @@ func (pf *PalFX) step() {
if pf.invertblend <= -2 && pf.eInvertall {
pf.eInvertblend = 3
} else {
pf.eInvertblend = pf.invertblend
pf.eInvertblend = pf.invertblend
}
pf.eNegType = pf.negType
pf.sinAdd(&pf.eAdd)
Expand All @@ -225,7 +225,7 @@ func (pf *PalFX) step() {
}
}
}
func (pf *PalFX) synthesize(pfx PalFX,blending bool) {
func (pf *PalFX) synthesize(pfx PalFX, blending bool) {
for i, m := range pfx.eMul {
pf.eMul[i] = pf.eMul[i] * m / 256
}
Expand All @@ -238,7 +238,9 @@ func (pf *PalFX) synthesize(pfx PalFX,blending bool) {
if pfx.invertall {
//Char blend inverse
if pfx.invertblend == 1 {
if blending && pf.invertblend > -3 { pf.eInvertall = pf.invertall }
if blending && pf.invertblend > -3 {
pf.eInvertall = pf.invertall
}
switch {
case pf.invertblend == 0:
pf.eInvertblend = 1
Expand All @@ -256,7 +258,7 @@ func (pf *PalFX) synthesize(pfx PalFX,blending bool) {
pf.eInvertblend = -1
case pf.invertblend == -1:
pf.eInvertall = pf.invertall
pf.eInvertblend = 2
pf.eInvertblend = 2
}
}

Expand Down
76 changes: 47 additions & 29 deletions src/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,10 +281,12 @@ func RenderSprite(rp RenderParams) {

if rp.pfx != nil {
blending := false
if rp.trans == -2 || rp.trans == -1 || (rp.trans&0xff > 0 && rp.trans>>10&0xff >= 255) { blending = true }
neg, grayscale, padd, pmul, invblend = rp.pfx.getFcPalFx(false,blending)
if rp.trans == -2 || rp.trans == -1 || (rp.trans&0xff > 0 && rp.trans>>10&0xff >= 255) {
blending = true
}
neg, grayscale, padd, pmul, invblend = rp.pfx.getFcPalFx(false, blending)
//if rp.trans == -2 && invblend < 1 {
//padd[0], padd[1], padd[2] = -padd[0], -padd[1], -padd[2]
//padd[0], padd[1], padd[2] = -padd[0], -padd[1], -padd[2]
//}
}

Expand Down Expand Up @@ -319,12 +321,12 @@ func RenderSprite(rp RenderParams) {
rmTileSub(modelview, rp)

gfx.ReleasePipeline()
}, rp.trans, rp.paltex != nil, invblend, &neg, &padd, &pmul, rp.paltex == nil )
}, rp.trans, rp.paltex != nil, invblend, &neg, &padd, &pmul, rp.paltex == nil)

gfx.DisableScissor()
}

func renderWithBlending(render func(eq BlendEquation, src, dst BlendFunc, a float32), trans int32, correctAlpha bool, invblend int32, neg *bool, acolor *[3]float32, mcolor *[3]float32, isrgba bool ) {
func renderWithBlending(render func(eq BlendEquation, src, dst BlendFunc, a float32), trans int32, correctAlpha bool, invblend int32, neg *bool, acolor *[3]float32, mcolor *[3]float32, isrgba bool) {
blendSourceFactor := BlendSrcAlpha
if !correctAlpha {
blendSourceFactor = BlendOne
Expand All @@ -338,13 +340,21 @@ func renderWithBlending(render func(eq BlendEquation, src, dst BlendFunc, a floa
switch {
//Add blend mode(255,255)
case trans == -1:
if invblend >= 1 && acolor != nil { (*acolor)[0], (*acolor)[1], (*acolor)[2] = -acolor[0], -acolor[1], -acolor[2] }
if invblend == 3 && neg != nil { *neg = false }
if invblend >= 1 && acolor != nil {
(*acolor)[0], (*acolor)[1], (*acolor)[2] = -acolor[0], -acolor[1], -acolor[2]
}
if invblend == 3 && neg != nil {
*neg = false
}
render(Blend, blendSourceFactor, BlendOne, 1)
//Sub blend mode
//Sub blend mode
case trans == -2:
if invblend >= 1 && acolor != nil { (*acolor)[0], (*acolor)[1], (*acolor)[2] = -acolor[0], -acolor[1], -acolor[2] }
if invblend == 3 && neg != nil { *neg = false }
if invblend >= 1 && acolor != nil {
(*acolor)[0], (*acolor)[1], (*acolor)[2] = -acolor[0], -acolor[1], -acolor[2]
}
if invblend == 3 && neg != nil {
*neg = false
}
render(BlendI, BlendOne, BlendOne, 1)
case trans <= 0:
//Add1(128,128)
Expand All @@ -353,44 +363,52 @@ func renderWithBlending(render func(eq BlendEquation, src, dst BlendFunc, a floa
if (invblend >= 2 || invblend <= -1) && acolor != nil && mcolor != nil {
src, dst := trans&0xff, trans>>10&0xff
//Summ of add components
gc := AbsF(acolor[0])+AbsF(acolor[1])+AbsF(acolor[2])
v3,al := MaxF((gc*255)-float32(dst+src),512)/128, (float32(src+dst)/255)
if isrgba { v3 = 1 }
rM,gM,bM := mcolor[0]*al,mcolor[1]*al,mcolor[2]*al
gc := AbsF(acolor[0]) + AbsF(acolor[1]) + AbsF(acolor[2])
v3, al := MaxF((gc*255)-float32(dst+src), 512)/128, (float32(src+dst) / 255)
if isrgba {
v3 = 1
}
rM, gM, bM := mcolor[0]*al, mcolor[1]*al, mcolor[2]*al
(*mcolor)[0], (*mcolor)[1], (*mcolor)[2] = rM, gM, bM
render(BlendAdd, BlendZero, BlendOneMinusSrcAlpha, al)
render(Blend, blendSourceFactor, BlendOne, al*Pow(v3,4))
render(BlendAdd, BlendZero, BlendOneMinusSrcAlpha, al)
render(Blend, blendSourceFactor, BlendOne, al*Pow(v3, 4))
} else {
render(Blend, blendSourceFactor, BlendOneMinusSrcAlpha, float32(trans)/255)
}
}
//None
case trans < 512:
render(BlendAdd, blendSourceFactor, BlendOneMinusSrcAlpha, 1)
//AddAlpha
//AddAlpha
default:
src, dst := trans&0xff, trans>>10&0xff
if dst < 255 {
render(Blend, BlendZero, BlendOneMinusSrcAlpha, 1-float32(dst)/255)
render(Blend, BlendZero, BlendOneMinusSrcAlpha, 1-float32(dst)/255)
}

if src > 0 {
if invblend >= 1 && dst >= 255 {
if invblend >= 2 {
if invblend == 3 && neg != nil { *neg = false }
if acolor != nil { (*acolor)[0], (*acolor)[1], (*acolor)[2] = -acolor[0], -acolor[1], -acolor[2] }
if invblend == 3 && neg != nil {
*neg = false
}
if acolor != nil {
(*acolor)[0], (*acolor)[1], (*acolor)[2] = -acolor[0], -acolor[1], -acolor[2]
}
}
Blend = BlendReverseSubtract
Blend = BlendReverseSubtract
} else {
Blend = BlendAdd
}
if (invblend >= 2 || invblend <= -1) && acolor != nil && mcolor != nil && src < 255 {
//Summ of add components
gc := AbsF(acolor[0])+AbsF(acolor[1])+AbsF(acolor[2])
v3,ml,al := MaxF((gc*255)-float32(dst+src),512)/128,(float32(src)/255), (float32(src+dst)/255)
if isrgba { v3 = 1 }
rM,gM,bM := mcolor[0]*ml,mcolor[1]*ml,mcolor[2]*ml
(*mcolor)[0], (*mcolor)[1], (*mcolor)[2] = rM, gM, bM
render(Blend, blendSourceFactor, BlendOne,al*Pow(v3,3))
gc := AbsF(acolor[0]) + AbsF(acolor[1]) + AbsF(acolor[2])
v3, ml, al := MaxF((gc*255)-float32(dst+src), 512)/128, (float32(src) / 255), (float32(src+dst) / 255)
if isrgba {
v3 = 1
}
rM, gM, bM := mcolor[0]*ml, mcolor[1]*ml, mcolor[2]*ml
(*mcolor)[0], (*mcolor)[1], (*mcolor)[2] = rM, gM, bM
render(Blend, blendSourceFactor, BlendOne, al*Pow(v3, 3))
} else {
render(Blend, blendSourceFactor, BlendOne, float32(src)/255)
}
Expand Down Expand Up @@ -423,5 +441,5 @@ func FillRect(rect [4]int32, color uint32, trans int32) {
gfx.SetUniformF("tint", r, g, b, a)
gfx.RenderQuad()
gfx.ReleasePipeline()
}, trans, true, 0, nil, nil, nil, false )
}, trans, true, 0, nil, nil, nil, false)
}
2 changes: 1 addition & 1 deletion src/script.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ func systemScriptInit(l *lua.LState) {
case "invertall":
a.palfx.invertall = lua.LVAsNumber(value) == 1
case "invertblend":
a.palfx.invertblend = int32(lua.LVAsNumber(value))
a.palfx.invertblend = int32(lua.LVAsNumber(value))
case "color":
a.palfx.color = float32(lua.LVAsNumber(value)) / 256
default:
Expand Down
Loading

0 comments on commit 02e1fec

Please sign in to comment.