mirror of
https://github.com/felixangell/phi.git
synced 2024-10-05 12:17:20 +03:00
cleanup the gitignore. somehow it filtered out the cmd/ dir. my bad
This commit is contained in:
parent
7e87d7c6dd
commit
9f9e1102ff
7
.gitignore
vendored
7
.gitignore
vendored
@ -1,12 +1,7 @@
|
|||||||
|
|
||||||
tests/
|
tests/
|
||||||
phi-editor
|
|
||||||
phi
|
|
||||||
phi.exe
|
|
||||||
main
|
|
||||||
main.exe
|
|
||||||
fmt.sh
|
|
||||||
.idea/
|
.idea/
|
||||||
|
main
|
||||||
vendor/
|
vendor/
|
||||||
.DS_Store
|
.DS_Store
|
||||||
|
|
||||||
|
116
cmd/phi/main.go
Normal file
116
cmd/phi/main.go
Normal file
@ -0,0 +1,116 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"github.com/felixangell/phi/internal/cfg"
|
||||||
|
"github.com/felixangell/phi/internal/editor"
|
||||||
|
"github.com/felixangell/strife"
|
||||||
|
"log"
|
||||||
|
"runtime"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
runtime.LockOSThread()
|
||||||
|
|
||||||
|
config := cfg.NewDefaultConfig()
|
||||||
|
|
||||||
|
windowConfig := strife.DefaultConfig()
|
||||||
|
windowConfig.Accelerated = config.Render.Accelerated
|
||||||
|
windowConfig.Alias = config.Render.Aliased
|
||||||
|
windowConfig.VerticalSync = config.Render.VerticalSync
|
||||||
|
|
||||||
|
scaledWidth, scaledHeight := calcScaledWindowDimension()
|
||||||
|
window := strife.SetupRenderWindow(scaledWidth, scaledHeight, windowConfig)
|
||||||
|
window.AllowHighDPI()
|
||||||
|
window.SetTitle("Hello world!")
|
||||||
|
window.SetResizable(true)
|
||||||
|
|
||||||
|
editorInst := editor.NewPhiEditor()
|
||||||
|
window.HandleEvents(func(evt strife.StrifeEvent) {
|
||||||
|
switch event := evt.(type) {
|
||||||
|
case *strife.CloseEvent:
|
||||||
|
window.Close()
|
||||||
|
case *strife.WindowResizeEvent:
|
||||||
|
log.Println("window resize is unimplemented: size", event.Width, event.Height)
|
||||||
|
default:
|
||||||
|
editorInst.HandleEvent(evt)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
if err := window.Create(); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
|
editorInst.ApplyConfig(config)
|
||||||
|
|
||||||
|
ctx := window.GetRenderContext()
|
||||||
|
|
||||||
|
// singular render before we enter into the event loop.
|
||||||
|
ctx.Clear()
|
||||||
|
editorInst.Render(ctx)
|
||||||
|
ctx.Display()
|
||||||
|
|
||||||
|
lastDebugRender := time.Now()
|
||||||
|
frames, updates := 0, 0
|
||||||
|
fps, ups := frames, updates
|
||||||
|
for {
|
||||||
|
window.PollEvents()
|
||||||
|
if window.CloseRequested() {
|
||||||
|
break
|
||||||
|
}
|
||||||
|
|
||||||
|
shouldRender := editorInst.Update()
|
||||||
|
|
||||||
|
if shouldRender || config.Render.AlwaysRender {
|
||||||
|
ctx.Clear()
|
||||||
|
editorInst.Render(ctx)
|
||||||
|
|
||||||
|
// this is only printed on each
|
||||||
|
// render...
|
||||||
|
ctx.SetColor(strife.White)
|
||||||
|
ctx.Text(fmt.Sprintf("fps: %d, ups %d", fps, ups), int(scaledWidth-256), int(scaledHeight-128))
|
||||||
|
|
||||||
|
ctx.Display()
|
||||||
|
frames++
|
||||||
|
}
|
||||||
|
updates++
|
||||||
|
|
||||||
|
if time.Now().Sub(lastDebugRender) >= time.Second {
|
||||||
|
lastDebugRender = time.Now()
|
||||||
|
fps, ups = frames, updates
|
||||||
|
frames, updates = 0, 0
|
||||||
|
}
|
||||||
|
|
||||||
|
if config.Render.ThrottleCpuUsage {
|
||||||
|
time.Sleep(time.Duration(config.Render.FrameSleepInterval) * time.Millisecond)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func calcScaledWindowDimension() (int, int) {
|
||||||
|
ww, wh := float32(640.0), float32(360.0)
|
||||||
|
|
||||||
|
dpi, defDpi := strife.GetDisplayDPI(0)
|
||||||
|
|
||||||
|
cfg.ScaleFactor = float64(dpi / defDpi)
|
||||||
|
|
||||||
|
scaledWidth := int((ww * dpi) / defDpi)
|
||||||
|
scaledHeight := int((wh * dpi) / defDpi)
|
||||||
|
return scaledWidth, scaledHeight
|
||||||
|
}
|
||||||
|
|
||||||
|
func getIconSizeForOS() int {
|
||||||
|
size := 16
|
||||||
|
switch runtime.GOOS {
|
||||||
|
case "windows":
|
||||||
|
size = 64
|
||||||
|
case "darwin":
|
||||||
|
size = 512
|
||||||
|
case "linux":
|
||||||
|
size = 96
|
||||||
|
default:
|
||||||
|
log.Println("unrecognized runtime ", runtime.GOOS)
|
||||||
|
}
|
||||||
|
return size
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user