Skip to content

Commit eb4f8b2

Browse files
authored
Merge pull request #3575 from SuperFromND/stage-fix
refactor: Remove gameWidthFloat/Height, make gameWidth/Height floats
2 parents 5d30b8f + 4d926da commit eb4f8b2

5 files changed

Lines changed: 25 additions & 31 deletions

File tree

src/camera.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ func newStageCamera() *stageCamera {
6868
return &stageCamera{verticalfollow: 0.2, tensionvel: 1, tension: 50,
6969
cuthigh: 0, cutlow: math.MinInt32,
7070
localcoord: [2]int32{320, 240},
71-
localscl: float32(sys.gameWidth / 320),
71+
localscl: sys.gameWidth / 320,
7272
topz: 0, botz: 0, ztopscale: 1, zbotscale: 1, depthtoscreen: 1,
7373
startzoom: 1, zoomin: 1, zoomout: 1,
7474
ytensionenable: false, tensionhigh: 0, tensionlow: 0,
@@ -135,14 +135,14 @@ func (c *Camera) Reset() {
135135
c.aspectcorrection = Min(0, (float32(c.localcoord[1])*c.localscl-float32(sys.gameHeight))+Min((float32(sys.gameHeight)-float32(c.localcoord[1])*c.localscl)/2, float32(c.overdrawlow)*c.localscl))
136136
} else if float32(c.localcoord[1])*c.localscl-float32(sys.gameHeight) > 0 {
137137
if c.cuthigh+c.cutlow <= 0 {
138-
c.aspectcorrection = float32(Ceil(float32(c.localcoord[1])*c.localscl) - sys.gameHeight)
138+
c.aspectcorrection = float32(Ceil(float32(c.localcoord[1])*c.localscl)) - sys.gameHeight
139139
} else {
140-
diff := Ceil(float32(c.localcoord[1])*c.localscl) - sys.gameHeight
141-
tmp := Ceil(float32(c.cuthigh)*c.localscl) * diff / (Ceil(float32(c.cuthigh)*c.localscl) + Ceil(float32(c.cutlow)*c.localscl))
142-
if diff-tmp <= c.cutlow {
140+
diff := float32(Ceil(float32(c.localcoord[1])*c.localscl)) - sys.gameHeight
141+
tmp := float32(Ceil(float32(c.cuthigh)*c.localscl)) * diff / float32((Ceil(float32(c.cuthigh)*c.localscl) + Ceil(float32(c.cutlow)*c.localscl)))
142+
if diff-tmp <= float32(c.cutlow) {
143143
c.aspectcorrection = float32(tmp)
144144
} else {
145-
c.aspectcorrection = float32(diff - Ceil(float32(c.cutlow)*c.localscl))
145+
c.aspectcorrection = float32(diff - float32(Ceil(float32(c.cutlow)*c.localscl)))
146146
}
147147
}
148148

src/config.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -371,15 +371,15 @@ func (c *Config) normalize() {
371371
func (c *Config) sysSet() {
372372
if _, ok := sys.cmdFlags["-width"]; ok {
373373
var w, _ = strconv.ParseInt(sys.cmdFlags["-width"], 10, 32)
374-
sys.gameWidth = int32(w)
374+
sys.gameWidth = float32(int32(w))
375375
} else {
376-
sys.gameWidth = c.Video.GameWidth
376+
sys.gameWidth = float32(c.Video.GameWidth)
377377
}
378378
if _, ok := sys.cmdFlags["-height"]; ok {
379379
var h, _ = strconv.ParseInt(sys.cmdFlags["-height"], 10, 32)
380-
sys.gameHeight = int32(h)
380+
sys.gameHeight = float32(int32(h))
381381
} else {
382-
sys.gameHeight = c.Video.GameHeight
382+
sys.gameHeight = float32(c.Video.GameHeight)
383383
}
384384
sys.msaa = c.Video.MSAA
385385
stoki := func(key string) int {

src/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ func realMain() {
194194

195195
// Initialize game and create window
196196
// This is where the window is born!
197-
sys.luaLState = sys.init(sys.gameWidth, sys.gameHeight)
197+
sys.luaLState = sys.init(int32(sys.gameWidth), int32(sys.gameHeight))
198198
//defer sys.shutdown()
199199

200200
// Begin processing game using its lua scripts

src/stage.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -639,11 +639,11 @@ func (bg backGround) draw(pos [2]float32, drawscl, bgscl, stglscl float32,
639639
rect := bg.startrect
640640

641641
startrect0 := float32(rect[0]) - (pos[0])/stgscl[0]*bg.windowdelta[0] +
642-
(sys.gameWidthFloat/2/sclx - float32(bg.notmaskwindow)*(sys.gameWidthFloat/2)*(1/lscl[0]))
642+
(sys.gameWidth/2/sclx - float32(bg.notmaskwindow)*(sys.gameWidth/2)*(1/lscl[0]))
643643
startrect0 *= sys.widthScale * wscl[0]
644644
if !isStage && wscl[0] == 1 {
645645
// Screenpacks X coordinates start from left edge of screen
646-
startrect0 += float32(sys.gameWidthFloat-320) / 2 * sys.widthScale
646+
startrect0 += float32(sys.gameWidth-320) / 2 * sys.widthScale
647647
}
648648

649649
startrect1 := float32(rect[1]) - pos[1]/drawscl/stgscl[1]*bg.windowdelta[1]
@@ -703,7 +703,7 @@ func (bg backGround) draw(pos [2]float32, drawscl, bgscl, stglscl float32,
703703
// Choose render origin: top-left for screenpack/storyboard videos, center for everything else
704704
var rcx float32
705705
if bg._type != BG_Video || isStage {
706-
rcx = sys.gameWidthFloat / 2
706+
rcx = sys.gameWidth / 2
707707
}
708708

709709
bg.anim.Draw(&rect, x-xsoffset, y, sclx, scly,
@@ -1112,7 +1112,7 @@ func loadStage(def string, maindef bool) (*Stage, error) {
11121112
} else if s.hires {
11131113
s.scale[1] *= 2
11141114
}
1115-
s.localscl = sys.gameWidthFloat / float32(s.stageCamera.localcoord[0])
1115+
s.localscl = sys.gameWidth / float32(s.stageCamera.localcoord[0])
11161116
s.stageCamera.localscl = s.localscl
11171117
if s.stageCamera.localcoord[0] != 320 {
11181118
// Update default values to new localcoord. Like characters do

src/system.go

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -64,9 +64,7 @@ type SystemStateVars struct {
6464
envcol_time int32
6565

6666
scrrect [4]int32
67-
gameWidth, gameHeight int32
68-
gameWidthFloat float32 // Float forms used for precise screenpack math
69-
gameHeightFloat float32 // TODO: rework gameWidth/gameHeight as floats instead
67+
gameWidth, gameHeight float32
7068
widthScale, heightScale float32
7169
gameEnd, frameSkip bool
7270
paused, frameStepFlag bool
@@ -356,7 +354,7 @@ type System struct {
356354
}
357355

358356
type drawAspectState struct {
359-
gameWidth, gameHeight int32
357+
gameWidth, gameHeight float32
360358
widthScale, heightScale float32
361359
}
362360

@@ -619,21 +617,17 @@ func (s *System) setGameSize(w, h int32) {
619617

620618
if screenAspect > targetAspect {
621619
// Screen is wider than 4:3 - scale based on height
622-
s.gameWidthFloat = float32(baseHeight) * screenAspect
623-
s.gameWidth = int32(s.gameWidthFloat)
624-
s.gameHeight = baseHeight
625-
s.gameHeightFloat = float32(s.gameHeight)
620+
s.gameWidth = float32(baseHeight) * screenAspect
621+
s.gameHeight = float32(baseHeight)
626622
} else {
627623
// Screen is taller than 4:3 - scale based on width
628-
s.gameWidth = baseWidth
629-
s.gameWidthFloat = float32(baseWidth)
630-
s.gameHeightFloat = float32(baseWidth) / screenAspect
631-
s.gameHeight = int32(s.gameHeightFloat)
624+
s.gameWidth = float32(baseWidth)
625+
s.gameHeight = float32(baseWidth) / screenAspect
632626
}
633627

634628
// Update scale
635-
s.widthScale = float32(s.scrrect[2]) / s.gameWidthFloat
636-
s.heightScale = float32(s.scrrect[3]) / s.gameHeightFloat
629+
s.widthScale = float32(s.scrrect[2]) / s.gameWidth
630+
s.heightScale = float32(s.scrrect[3]) / s.gameHeight
637631
}
638632

639633
// Change aspect ratio at match start
@@ -669,8 +663,8 @@ func (s *System) applyFightAspect() {
669663

670664
// Compute new game dimensions while maintaining the same base height
671665
gameWidth := baseHeight * aspectGame
672-
s.gameWidth = int32(gameWidth)
673-
s.gameHeight = int32(baseHeight)
666+
s.gameWidth = gameWidth
667+
s.gameHeight = baseHeight
674668

675669
// Scale to fit current screen size
676670
s.widthScale = float32(s.scrrect[2]) / float32(s.gameWidth)

0 commit comments

Comments
 (0)