Skip to content

Commit

Permalink
Adjustable framerate
Browse files Browse the repository at this point in the history
resolves #19
  • Loading branch information
SpaiR committed Mar 18, 2022
1 parent 437f1a5 commit fdcc254
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 8 deletions.
1 change: 1 addition & 0 deletions src/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
### Improvements and Fixes
* Added an option to change map size. To do that open a new "Settings" menu, available under the cog button in the top-right corner of the opened map pane;
* It's now possible to interact with the map window without first having to manually tab in. Specifically for: select instance -> change a var -> select another instance;
* Added a preference to adjust the application framerate;
* Minor GUI improvements;
* Fixed attempting to pick/delete item pixel shifted off map does not work.

Expand Down
25 changes: 25 additions & 0 deletions src/app/preferences.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,45 @@ package app

import (
"log"
"math"
"sdmm/app/prefs"
"sdmm/app/ui/cpwsarea/wsprefs"
"sdmm/app/window"
)

func (a *app) makePreferences() wsprefs.Prefs {
p := wsprefs.MakePrefs()
p.Add(wsprefs.GPInterface, a.makePreferenceInterfaceScale())
p.Add(wsprefs.GPInterface, a.makePreferenceInterfaceFps())
p.Add(wsprefs.GPControls, a.makePreferenceControlsAltScrollBehaviour())
p.Add(wsprefs.GPEditor, a.makePreferenceEditorFormat())
p.Add(wsprefs.GPEditor, a.makePreferenceEditorSanitizeVariables())
p.Add(wsprefs.GPEditor, a.makePreferenceEditorNudgeMode())
return p
}

func (a *app) makePreferenceInterfaceFps() wsprefs.IntPref {
p := wsprefs.MakeIntPref()
p.Name = "Fps"
p.Desc = "Controls the application framerate."
p.Label = "##fps"
p.Min = 30
p.Max = math.MaxInt

p.FGet = func() int {
return a.preferencesConfig().Prefs.Interface.Fps
}
p.FSet = func(value int) {
log.Println("[app] preferences changing, [interface#fps] to:", value)
cfg := a.preferencesConfig()
cfg.Prefs.Interface.Fps = value
a.ConfigSaveV(cfg)
window.SetFps(value)
}

return p
}

func (a *app) makePreferenceInterfaceScale() wsprefs.IntPref {
p := wsprefs.MakeIntPref()
p.Name = "Scale"
Expand Down
10 changes: 8 additions & 2 deletions src/app/preferences_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package app
import (
"log"
"sdmm/app/prefs"
"sdmm/app/window"
)

const (
Expand Down Expand Up @@ -40,19 +41,24 @@ func (preferencesConfig) TryMigrate(cfg map[string]interface{}) (result map[stri
}

func (a *app) loadPreferencesConfig() {
a.ConfigRegister(&preferencesConfig{
cfg := &preferencesConfig{
Version: preferencesConfigVersion,

Prefs: prefs.Prefs{
Interface: prefs.Interface{
Scale: 100,
Fps: 60,
},
Editor: prefs.Editor{
SaveFormat: prefs.SaveFormatInitial,
NudgeMode: prefs.SaveNudgeModePixel,
},
},
})
}

a.ConfigRegister(cfg)

window.SetFps(cfg.Prefs.Interface.Fps)
}

func (a *app) preferencesConfig() *preferencesConfig {
Expand Down
1 change: 1 addition & 0 deletions src/app/prefs/prefs.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ type Prefs struct {

type Interface struct {
Scale int
Fps int
}

type Controls struct {
Expand Down
8 changes: 6 additions & 2 deletions src/app/window/process.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,13 @@ import (
"sdmm/platform"
)

func (w *Window) Process() {
ticker := time.NewTicker(time.Second / time.Duration(fps))
var ticker = newTicker(60)

func newTicker(fps int) *time.Ticker {
return time.NewTicker(time.Second / time.Duration(fps))
}

func (w *Window) Process() {
for !w.application.IsClosed() {
// Override window closing behaviour to enforce our checks.
if w.handle.ShouldClose() {
Expand Down
13 changes: 9 additions & 4 deletions src/app/window/window.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ import (
"sdmm/platform"
)

const fps int = 60

// AppLogoTexture is a texture pointer to the application logo.
var AppLogoTexture uint32
var (
// AppLogoTexture is a texture pointer to the application logo.
AppLogoTexture uint32
)

type application interface {
Process()
Expand Down Expand Up @@ -88,6 +88,11 @@ func SetPointSize(ps float32) {
platform.UpdateFontsTexture()
}

func SetFps(value int) {
log.Println("[window] set fps:", value)
ticker = newTicker(value)
}

func (w *Window) setupGlfw() {
runtime.LockOSThread()

Expand Down

0 comments on commit fdcc254

Please sign in to comment.