From 02e1fec485dc8fe22d68594ce6b64ba522bcb0a5 Mon Sep 17 00:00:00 2001 From: Lint Action Date: Wed, 11 Oct 2023 04:14:09 +0000 Subject: [PATCH] style: fix code style issues with gofmt --- src/bytecode.go | 16 ++++----- src/char.go | 12 +++---- src/compiler_functions.go | 4 +-- src/image.go | 40 +++++++++++---------- src/render.go | 76 ++++++++++++++++++++++++--------------- src/script.go | 2 +- src/stage.go | 14 ++++---- 7 files changed, 92 insertions(+), 72 deletions(-) diff --git a/src/bytecode.go b/src/bytecode.go index 9b1d727dc..d89bb7bcd 100644 --- a/src/bytecode.go +++ b/src/bytecode.go @@ -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 } @@ -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 } @@ -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 @@ -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 }) @@ -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 { @@ -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 } @@ -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: diff --git a/src/char.go b/src/char.go index 2285047c9..e6ac6b0b3 100644 --- a/src/char.go +++ b/src/char.go @@ -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} } @@ -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 @@ -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 } } @@ -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() @@ -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 { diff --git a/src/compiler_functions.go b/src/compiler_functions.go index a360f1dea..1efe52adc 100644 --- a/src/compiler_functions.go +++ b/src/compiler_functions.go @@ -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) { @@ -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 diff --git a/src/image.go b/src/image.go index 251d218fb..fef781153 100644 --- a/src/image.go +++ b/src/image.go @@ -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{} } @@ -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 { @@ -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 @@ -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) @@ -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 } @@ -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 @@ -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 } } diff --git a/src/render.go b/src/render.go index 90ce76459..bf7e3b9fc 100644 --- a/src/render.go +++ b/src/render.go @@ -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] //} } @@ -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 @@ -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) @@ -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) } @@ -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) } diff --git a/src/script.go b/src/script.go index e0d11c5f5..6fe45790e 100644 --- a/src/script.go +++ b/src/script.go @@ -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: diff --git a/src/stage.go b/src/stage.go index b459d627b..d046e5ef6 100644 --- a/src/stage.go +++ b/src/stage.go @@ -457,7 +457,7 @@ type bgCtrl struct { sinmul [4]int32 sincolor [2]int32 invall bool - invblend int32 + invblend int32 color float32 positionlink bool idx int @@ -491,7 +491,7 @@ func (bgc *bgCtrl) read(is IniSection, idx int) { bgc.sinmul = [4]int32{0, 0, 0, 0} bgc.sincolor = [2]int32{0, 0} bgc.invall = false - bgc.invblend = 0 + bgc.invblend = 0 bgc.color = 1 case "posset": bgc._type = BT_PosSet @@ -554,7 +554,7 @@ func (bgc *bgCtrl) read(is IniSection, idx int) { } if is.ReadI32("invertblend", &bgc.invblend) { bgc.invblend = bgc.invblend - } + } if is.ReadF32("color", &bgc.color) { bgc.color = bgc.color / 256 } @@ -1120,7 +1120,7 @@ func (s *Stage) runBgCtrl(bgc *bgCtrl) { bgc.bg[i].palfx.sincolor = bgc.sincolor[0] / 256 bgc.bg[i].palfx.cycletimeColor = bgc.sincolor[1] bgc.bg[i].palfx.invertall = bgc.invall - bgc.bg[i].palfx.invertblend = bgc.invblend + bgc.bg[i].palfx.invertblend = bgc.invblend bgc.bg[i].palfx.color = bgc.color } case BT_PosSet: @@ -1258,9 +1258,9 @@ func (s *Stage) action() { // b.palfx.synthesize(sys.bgPalFX) b.palfx.eAdd = sys.bgPalFX.eAdd b.palfx.eMul = sys.bgPalFX.eMul - b.palfx.eColor = sys.bgPalFX.eColor + b.palfx.eColor = sys.bgPalFX.eColor b.palfx.eInvertall = sys.bgPalFX.eInvertall - b.palfx.eInvertblend = sys.bgPalFX.eInvertblend + b.palfx.eInvertblend = sys.bgPalFX.eInvertblend b.palfx.eNegType = sys.bgPalFX.eNegType } if b.active && !paused { @@ -1436,7 +1436,7 @@ func (s *Stage) modifyBGCtrl(id int32, t, v [3]int32, x, y float32, src, dst [2] } if invblend != IErr { s.bgc[i].invblend = invblend - } + } if !math.IsNaN(float64(color)) { s.bgc[i].color = color / 256 }